1 /* Focus.c- input and colormap focus stuff
3 * WPrefs - Window Maker 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
{
33 CallbackRec callbacks
;
54 char raiseDelaySelected
;
59 #define ICON_FILE "windowfocus"
61 #define DELAY_ICON "timer%i"
62 #define DELAY_ICON_S "timer%is"
64 static void changeFocusMode(WMWidget
*w
, void *data
);
67 showData(_Panel
*panel
)
73 str
= GetStringForKey("FocusMode");
76 if (strcasecmp(str
, "manual")==0 || strcasecmp(str
, "clicktofocus")==0)
77 WMSetPopUpButtonSelectedItem(panel
->kfocP
, 0);
78 else if (strcasecmp(str
, "auto")==0 || strcasecmp(str
, "focusfollowsmouse")==0)
79 WMSetPopUpButtonSelectedItem(panel
->kfocP
, 1);
80 else if (strcasecmp(str
, "semiauto")==0 || strcasecmp(str
, "sloppy")==0)
81 WMSetPopUpButtonSelectedItem(panel
->kfocP
, 2);
83 wwarning(_("bad option value %s for option FocusMode. Using default Manual"),
85 WMSetPopUpButtonSelectedItem(panel
->kfocP
, 0);
87 changeFocusMode(panel
->kfocP
, panel
);
90 str
= GetStringForKey("ColormapMode");
93 if (strcasecmp(str
, "manual")==0 || strcasecmp(str
, "clicktofocus")==0) {
94 WMPerformButtonClick(panel
->manB
);
95 } else if (strcasecmp(str
, "auto")==0 || strcasecmp(str
, "focusfollowsmouse")==0) {
96 WMPerformButtonClick(panel
->autB
);
98 wwarning(_("bad option value %s for option ColormapMode. Using default Auto"),
100 WMPerformButtonClick(panel
->manB
);
104 i
= GetIntegerForKey("RaiseDelay");
105 sprintf(buffer
, "%i", i
);
106 WMSetTextFieldText(panel
->raisT
, buffer
);
110 WMPerformButtonClick(panel
->raisB
[0]);
113 WMPerformButtonClick(panel
->raisB
[1]);
116 WMPerformButtonClick(panel
->raisB
[2]);
119 WMPerformButtonClick(panel
->raisB
[3]);
122 WMPerformButtonClick(panel
->raisB
[4]);
127 WMSetButtonSelected(panel
->ignB
, GetBoolForKey("IgnoreFocusClick"));
129 WMSetButtonSelected(panel
->newB
, GetBoolForKey("AutoFocus"));
135 storeData(_Panel
*panel
)
140 switch (WMGetPopUpButtonSelectedItem(panel
->kfocP
)) {
151 SetStringForKey(str
, "FocusMode");
153 if (WMGetButtonSelected(panel
->manB
)) {
154 SetStringForKey("manual", "ColormapMode");
156 SetStringForKey("auto", "ColormapMode");
159 str
= WMGetTextFieldText(panel
->raisT
);
160 if (sscanf(str
, "%i", &i
)!=1)
162 SetIntegerForKey(i
, "RaiseDelay");
164 SetBoolForKey(WMGetButtonSelected(panel
->ignB
), "IgnoreFocusClick");
165 SetBoolForKey(WMGetButtonSelected(panel
->newB
), "AutoFocus");
170 pushDelayButton(WMWidget
*w
, void *data
)
172 _Panel
*panel
= (_Panel
*)data
;
174 panel
->raiseDelaySelected
= 1;
175 if (w
== panel
->raisB
[0]) {
176 WMSetTextFieldText(panel
->raisT
, "OFF");
177 } else if (w
== panel
->raisB
[1]) {
178 WMSetTextFieldText(panel
->raisT
, "10");
179 } else if (w
== panel
->raisB
[2]) {
180 WMSetTextFieldText(panel
->raisT
, "100");
181 } else if (w
== panel
->raisB
[3]) {
182 WMSetTextFieldText(panel
->raisT
, "350");
183 } else if (w
== panel
->raisB
[4]) {
184 WMSetTextFieldText(panel
->raisT
, "800");
190 changeFocusMode(WMWidget
*w
, void *data
)
192 _Panel
*panel
= (_Panel
*)data
;
194 switch (WMGetPopUpButtonSelectedItem(w
)) {
196 WMSetLabelText(panel
->kfocL
, _("Click on the window to set\n"\
197 "keyboard input focus."));
200 WMSetLabelText(panel
->kfocL
, _("Set keyboard input focus to\n"\
201 "the window under the mouse pointer,\n"\
202 "including the root window."));
205 WMSetLabelText(panel
->kfocL
, _("Set keyboard input focus to\n"\
206 "the window under the mouse pointer,\n"\
207 "except the root window."));
214 raiseTextChanged(void *observerData
, WMNotification
*notification
)
216 _Panel
*panel
= (_Panel
*)observerData
;
219 if (panel
->raiseDelaySelected
) {
220 for (i
=0; i
<5; i
++) {
221 WMSetButtonSelected(panel
->raisB
[i
], False
);
223 panel
->raiseDelaySelected
= 0;
231 createPanel(Panel
*p
)
233 _Panel
*panel
= (_Panel
*)p
;
234 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
241 panel
->box
= WMCreateBox(panel
->parent
);
242 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
244 /***************** Input Focus Mode *****************/
245 panel
->kfocF
= WMCreateFrame(panel
->box
);
246 WMResizeWidget(panel
->kfocF
, 240, 130);
247 WMMoveWidget(panel
->kfocF
, 15, 15);
248 WMSetFrameTitle(panel
->kfocF
, _("Input Focus Mode"));
250 panel
->kfocP
= WMCreatePopUpButton(panel
->kfocF
);
251 WMResizeWidget(panel
->kfocP
, 210, 20);
252 WMMoveWidget(panel
->kfocP
, 15, 30);
253 WMAddPopUpButtonItem(panel
->kfocP
, _("Click window to focus"));
254 WMAddPopUpButtonItem(panel
->kfocP
, _("Focus follows mouse"));
255 WMAddPopUpButtonItem(panel
->kfocP
, _("\"Sloppy\" focus"));
256 WMSetPopUpButtonAction(panel
->kfocP
, changeFocusMode
, panel
);
258 panel
->kfocL
= WMCreateLabel(panel
->kfocF
);
259 WMResizeWidget(panel
->kfocL
, 211, 68);
260 WMMoveWidget(panel
->kfocL
, 15, 55);
261 WMSetLabelTextAlignment(panel
->kfocL
, WACenter
);
263 WMMapSubwidgets(panel
->kfocF
);
265 /***************** Colormap Installation Mode ****************/
267 panel
->cfocF
= WMCreateFrame(panel
->box
);
268 WMResizeWidget(panel
->cfocF
, 240, 70);
269 WMMoveWidget(panel
->cfocF
, 15, 150);
270 WMSetFrameTitle(panel
->cfocF
, _("Install colormap in the window..."));
272 panel
->manB
= WMCreateRadioButton(panel
->cfocF
);
273 WMResizeWidget(panel
->manB
, 220, 20);
274 WMMoveWidget(panel
->manB
, 15, 18);
275 WMSetButtonText(panel
->manB
, _("...that has the input focus."));
277 panel
->autB
= WMCreateRadioButton(panel
->cfocF
);
278 WMResizeWidget(panel
->autB
, 220, 20);
279 WMMoveWidget(panel
->autB
, 15, 40);
280 WMSetButtonText(panel
->autB
, _("...that is under the mouse pointer."));
281 WMGroupButtons(panel
->manB
, panel
->autB
);
283 WMMapSubwidgets(panel
->cfocF
);
285 /***************** Automatic window raise delay *****************/
286 panel
->raisF
= WMCreateFrame(panel
->box
);
287 WMResizeWidget(panel
->raisF
, 245, 70);
288 WMMoveWidget(panel
->raisF
, 265, 15);
289 WMSetFrameTitle(panel
->raisF
, _("Automatic Window Raise Delay"));
291 buf1
= wmalloc(strlen(DELAY_ICON
)+1);
292 buf2
= wmalloc(strlen(DELAY_ICON_S
)+1);
294 for (i
= 0; i
< 5; i
++) {
297 panel
->raisB
[i
] = WMCreateCustomButton(panel
->raisF
,
299 WMResizeWidget(panel
->raisB
[i
], 25, 25);
300 WMMoveWidget(panel
->raisB
[i
], 10+(30*i
), 25);
301 WMSetButtonBordered(panel
->raisB
[i
], False
);
302 WMSetButtonImagePosition(panel
->raisB
[i
], WIPImageOnly
);
303 WMSetButtonAction(panel
->raisB
[i
], pushDelayButton
, panel
);
305 WMGroupButtons(panel
->raisB
[0], panel
->raisB
[i
]);
306 sprintf(buf1
, DELAY_ICON
, i
);
307 sprintf(buf2
, DELAY_ICON_S
, i
);
308 path
= LocateImage(buf1
);
310 icon
= WMCreatePixmapFromFile(scr
, path
);
312 WMSetButtonImage(panel
->raisB
[i
], icon
);
313 WMReleasePixmap(icon
);
315 wwarning(_("could not load icon file %s"), path
);
319 path
= LocateImage(buf2
);
321 icon
= WMCreatePixmapFromFile(scr
, path
);
323 WMSetButtonAltImage(panel
->raisB
[i
], icon
);
324 WMReleasePixmap(icon
);
326 wwarning(_("could not load icon file %s"), path
);
334 panel
->raisT
= WMCreateTextField(panel
->raisF
);
335 WMResizeWidget(panel
->raisT
, 36, 20);
336 WMMoveWidget(panel
->raisT
, 165, 30);
337 WMAddNotificationObserver(raiseTextChanged
, panel
,
338 WMTextDidChangeNotification
, panel
->raisT
);
340 color
= WMDarkGrayColor(scr
);
341 font
= WMSystemFontOfSize(scr
, 10);
343 panel
->raisL
= WMCreateLabel(panel
->raisF
);
344 WMResizeWidget(panel
->raisL
, 36, 16);
345 WMMoveWidget(panel
->raisL
, 205, 35);
346 WMSetLabelText(panel
->raisL
, _("msec"));
347 WMSetLabelTextColor(panel
->raisL
, color
);
348 WMSetLabelFont(panel
->raisL
, font
);
350 WMReleaseColor(color
);
353 WMMapSubwidgets(panel
->raisF
);
355 /***************** Options ****************/
356 panel
->optF
= WMCreateFrame(panel
->box
);
357 WMResizeWidget(panel
->optF
, 245, 125);
358 WMMoveWidget(panel
->optF
, 265, 95);
360 panel
->ignB
= WMCreateSwitchButton(panel
->optF
);
361 WMResizeWidget(panel
->ignB
, 210, 50);
362 WMMoveWidget(panel
->ignB
, 15, 10);
363 WMSetButtonText(panel
->ignB
, _("Do not let applications receive\n"
364 "the click used to focus windows."));
366 panel
->newB
= WMCreateSwitchButton(panel
->optF
);
367 WMResizeWidget(panel
->newB
, 210, 35);
368 WMMoveWidget(panel
->newB
, 15, 70);
369 WMSetButtonText(panel
->newB
, _("Automatically focus new\nwindows."));
371 WMMapSubwidgets(panel
->optF
);
374 WMRealizeWidget(panel
->box
);
375 WMMapSubwidgets(panel
->box
);
383 InitFocus(WMScreen
*scr
, WMWindow
*win
)
387 panel
= wmalloc(sizeof(_Panel
));
388 memset(panel
, 0, sizeof(_Panel
));
390 panel
->sectionName
= _("Window Focus Preferences");
392 panel
->description
= _("Keyboard focus switching policy, colormap switching\n"
393 "policy for 8bpp displays and other related options.");
397 panel
->callbacks
.createWidgets
= createPanel
;
398 panel
->callbacks
.updateDomain
= storeData
;
400 AddSection(panel
, ICON_FILE
);