1 /* Focus.c- input and colormap focus stuff
3 * WPrefs - WindowMaker Preferences Program
5 * Copyright (c) 1998 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
26 typedef struct _Panel
{
31 CallbackRec callbacks
;
52 char raiseDelaySelected
;
57 #define ICON_FILE "windowfocus"
59 #define DELAY_ICON "timer%i"
60 #define DELAY_ICON_S "timer%is"
62 static void changeFocusMode(WMWidget
*w
, void *data
);
65 showData(_Panel
*panel
)
71 str
= GetStringForKey("FocusMode");
72 if (strcasecmp(str
, "manual")==0 || strcasecmp(str
, "clicktofocus")==0)
73 WMSetPopUpButtonSelectedItem(panel
->kfocP
, 0);
74 else if (strcasecmp(str
, "auto")==0 || strcasecmp(str
, "focusfollowsmouse")==0)
75 WMSetPopUpButtonSelectedItem(panel
->kfocP
, 1);
76 else if (strcasecmp(str
, "semiauto")==0 || strcasecmp(str
, "sloppy")==0)
77 WMSetPopUpButtonSelectedItem(panel
->kfocP
, 2);
79 wwarning(_("bad option value %s for option FocusMode. Using default Manual"),
81 WMSetPopUpButtonSelectedItem(panel
->kfocP
, 0);
83 changeFocusMode(panel
->kfocP
, panel
);
86 str
= GetStringForKey("ColormapMode");
87 if (strcasecmp(str
, "manual")==0 || strcasecmp(str
, "clicktofocus")==0) {
88 WMPerformButtonClick(panel
->manB
);
89 } else if (strcasecmp(str
, "auto")==0 || strcasecmp(str
, "focusfollowsmouse")==0) {
90 WMPerformButtonClick(panel
->autB
);
92 wwarning(_("bad option value %s for option ColormapMode. Using default Manual"),
94 WMPerformButtonClick(panel
->manB
);
98 i
= GetIntegerForKey("RaiseDelay");
99 sprintf(buffer
, "%i", i
);
100 WMSetTextFieldText(panel
->raisT
, buffer
);
104 WMPerformButtonClick(panel
->raisB
[0]);
107 WMPerformButtonClick(panel
->raisB
[1]);
110 WMPerformButtonClick(panel
->raisB
[2]);
113 WMPerformButtonClick(panel
->raisB
[3]);
116 WMPerformButtonClick(panel
->raisB
[4]);
121 WMSetButtonSelected(panel
->ignB
, GetBoolForKey("IgnoreFocusClick"));
123 WMSetButtonSelected(panel
->newB
, GetBoolForKey("AutoFocus"));
129 storeData(_Panel
*panel
)
134 switch (WMGetPopUpButtonSelectedItem(panel
->kfocP
)) {
145 SetStringForKey(str
, "FocusMode");
147 if (WMGetButtonSelected(panel
->manB
)) {
148 SetStringForKey("manual", "ColormapMode");
150 SetStringForKey("auto", "ColormapMode");
153 str
= WMGetTextFieldText(panel
->raisT
);
154 if (sscanf(str
, "%i", &i
)!=1)
156 SetIntegerForKey(i
, "RaiseDelay");
158 SetBoolForKey(WMGetButtonSelected(panel
->ignB
), "IgnoreFocusClick");
159 SetBoolForKey(WMGetButtonSelected(panel
->newB
), "AutoFocus");
164 pushDelayButton(WMWidget
*w
, void *data
)
166 _Panel
*panel
= (_Panel
*)data
;
168 panel
->raiseDelaySelected
= 1;
169 if (w
== panel
->raisB
[0]) {
170 WMSetTextFieldText(panel
->raisT
, "OFF");
171 } else if (w
== panel
->raisB
[1]) {
172 WMSetTextFieldText(panel
->raisT
, "10");
173 } else if (w
== panel
->raisB
[2]) {
174 WMSetTextFieldText(panel
->raisT
, "100");
175 } else if (w
== panel
->raisB
[3]) {
176 WMSetTextFieldText(panel
->raisT
, "350");
177 } else if (w
== panel
->raisB
[4]) {
178 WMSetTextFieldText(panel
->raisT
, "800");
184 changeFocusMode(WMWidget
*w
, void *data
)
186 _Panel
*panel
= (_Panel
*)data
;
188 switch (WMGetPopUpButtonSelectedItem(w
)) {
190 WMSetLabelText(panel
->kfocL
, _("Click on the window to set\n"\
191 "keyboard input focus."));
194 WMSetLabelText(panel
->kfocL
, _("Set keyboard input focus to\n"\
195 "the window under the mouse pointer,\n"\
196 "including the root window."));
199 WMSetLabelText(panel
->kfocL
, _("Set keyboard input focus to\n"\
200 "the window under the mouse pointer,\n"\
201 "except the root window."));
208 raiseTextChanged(void *observerData
, WMNotification
*notification
)
210 _Panel
*panel
= (_Panel
*)observerData
;
213 if (panel
->raiseDelaySelected
) {
214 for (i
=0; i
<5; i
++) {
215 WMSetButtonSelected(panel
->raisB
[i
], False
);
217 panel
->raiseDelaySelected
= 0;
225 createPanel(Panel
*p
)
227 _Panel
*panel
= (_Panel
*)p
;
228 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
235 panel
->frame
= WMCreateFrame(panel
->win
);
236 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
237 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
239 /***************** Input Focus Mode *****************/
240 panel
->kfocF
= WMCreateFrame(panel
->frame
);
241 WMResizeWidget(panel
->kfocF
, 240, 130);
242 WMMoveWidget(panel
->kfocF
, 15, 15);
243 WMSetFrameTitle(panel
->kfocF
, _("Input Focus Mode"));
245 panel
->kfocP
= WMCreatePopUpButton(panel
->kfocF
);
246 WMResizeWidget(panel
->kfocP
, 210, 20);
247 WMMoveWidget(panel
->kfocP
, 15, 30);
248 WMAddPopUpButtonItem(panel
->kfocP
, _("Click window to focus"));
249 WMAddPopUpButtonItem(panel
->kfocP
, _("Focus follows mouse"));
250 WMAddPopUpButtonItem(panel
->kfocP
, _("\"Sloppy\" focus"));
251 WMSetPopUpButtonAction(panel
->kfocP
, changeFocusMode
, panel
);
253 panel
->kfocL
= WMCreateLabel(panel
->kfocF
);
254 WMResizeWidget(panel
->kfocL
, 211, 68);
255 WMMoveWidget(panel
->kfocL
, 15, 55);
256 WMSetLabelTextAlignment(panel
->kfocL
, WACenter
);
258 WMMapSubwidgets(panel
->kfocF
);
260 /***************** Colormap Installation Mode ****************/
262 panel
->cfocF
= WMCreateFrame(panel
->frame
);
263 WMResizeWidget(panel
->cfocF
, 240, 70);
264 WMMoveWidget(panel
->cfocF
, 15, 150);
265 WMSetFrameTitle(panel
->cfocF
, _("Install colormap in the window..."));
267 panel
->manB
= WMCreateRadioButton(panel
->cfocF
);
268 WMResizeWidget(panel
->manB
, 220, 20);
269 WMMoveWidget(panel
->manB
, 15, 18);
270 WMSetButtonText(panel
->manB
, _("...that has the input focus."));
272 panel
->autB
= WMCreateRadioButton(panel
->cfocF
);
273 WMResizeWidget(panel
->autB
, 220, 20);
274 WMMoveWidget(panel
->autB
, 15, 40);
275 WMSetButtonText(panel
->autB
, _("...that is under the mouse pointer."));
276 WMGroupButtons(panel
->manB
, panel
->autB
);
278 WMMapSubwidgets(panel
->cfocF
);
280 /***************** Automatic window raise delay *****************/
281 panel
->raisF
= WMCreateFrame(panel
->frame
);
282 WMResizeWidget(panel
->raisF
, 245, 70);
283 WMMoveWidget(panel
->raisF
, 265, 15);
284 WMSetFrameTitle(panel
->raisF
, _("Automatic Window Raise Delay"));
286 buf1
= wmalloc(strlen(DELAY_ICON
)+1);
287 buf2
= wmalloc(strlen(DELAY_ICON_S
)+1);
289 for (i
= 0; i
< 5; i
++) {
292 panel
->raisB
[i
] = WMCreateCustomButton(panel
->raisF
,
294 WMResizeWidget(panel
->raisB
[i
], 25, 25);
295 WMMoveWidget(panel
->raisB
[i
], 10+(30*i
), 25);
296 WMSetButtonBordered(panel
->raisB
[i
], False
);
297 WMSetButtonImagePosition(panel
->raisB
[i
], WIPImageOnly
);
298 WMSetButtonAction(panel
->raisB
[i
], pushDelayButton
, panel
);
300 WMGroupButtons(panel
->raisB
[0], panel
->raisB
[i
]);
301 sprintf(buf1
, DELAY_ICON
, i
);
302 sprintf(buf2
, DELAY_ICON_S
, i
);
303 path
= LocateImage(buf1
);
305 icon
= WMCreatePixmapFromFile(scr
, path
);
307 WMSetButtonImage(panel
->raisB
[i
], icon
);
308 WMReleasePixmap(icon
);
310 wwarning(_("could not load icon file %s"), path
);
314 path
= LocateImage(buf2
);
316 icon
= WMCreatePixmapFromFile(scr
, path
);
318 WMSetButtonAltImage(panel
->raisB
[i
], icon
);
319 WMReleasePixmap(icon
);
321 wwarning(_("could not load icon file %s"), path
);
329 panel
->raisT
= WMCreateTextField(panel
->raisF
);
330 WMResizeWidget(panel
->raisT
, 36, 20);
331 WMMoveWidget(panel
->raisT
, 165, 30);
332 WMAddNotificationObserver(raiseTextChanged
, panel
,
333 WMTextDidChangeNotification
, panel
->raisT
);
335 color
= WMDarkGrayColor(scr
);
336 font
= WMSystemFontOfSize(scr
, 10);
338 panel
->raisL
= WMCreateLabel(panel
->raisF
);
339 WMResizeWidget(panel
->raisL
, 36, 16);
340 WMMoveWidget(panel
->raisL
, 205, 35);
341 WMSetLabelText(panel
->raisL
, _("msec"));
342 WMSetLabelTextColor(panel
->raisL
, color
);
343 WMSetLabelFont(panel
->raisL
, font
);
345 WMReleaseColor(color
);
348 WMMapSubwidgets(panel
->raisF
);
350 /***************** Options ****************/
351 panel
->optF
= WMCreateFrame(panel
->frame
);
352 WMResizeWidget(panel
->optF
, 245, 125);
353 WMMoveWidget(panel
->optF
, 265, 95);
355 panel
->ignB
= WMCreateSwitchButton(panel
->optF
);
356 WMResizeWidget(panel
->ignB
, 210, 50);
357 WMMoveWidget(panel
->ignB
, 15, 10);
358 WMSetButtonText(panel
->ignB
, _("Do not let aplications receive the "\
359 "click used to focus windows."));
361 panel
->newB
= WMCreateSwitchButton(panel
->optF
);
362 WMResizeWidget(panel
->newB
, 210, 35);
363 WMMoveWidget(panel
->newB
, 15, 70);
364 WMSetButtonText(panel
->newB
, _("Automatically focus new windows."));
366 WMMapSubwidgets(panel
->optF
);
369 WMRealizeWidget(panel
->frame
);
370 WMMapSubwidgets(panel
->frame
);
378 InitFocus(WMScreen
*scr
, WMWindow
*win
)
382 panel
= wmalloc(sizeof(_Panel
));
383 memset(panel
, 0, sizeof(_Panel
));
385 panel
->sectionName
= _("Window Focus Preferences");
389 panel
->callbacks
.createWidgets
= createPanel
;
390 panel
->callbacks
.updateDomain
= storeData
;
392 AddSection(panel
, ICON_FILE
);