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
->win
);
241 panel
->frame
= WMCreateFrame(panel
->win
);
242 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
243 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
245 /***************** Input Focus Mode *****************/
246 panel
->kfocF
= WMCreateFrame(panel
->frame
);
247 WMResizeWidget(panel
->kfocF
, 240, 130);
248 WMMoveWidget(panel
->kfocF
, 15, 15);
249 WMSetFrameTitle(panel
->kfocF
, _("Input Focus Mode"));
251 panel
->kfocP
= WMCreatePopUpButton(panel
->kfocF
);
252 WMResizeWidget(panel
->kfocP
, 210, 20);
253 WMMoveWidget(panel
->kfocP
, 15, 30);
254 WMAddPopUpButtonItem(panel
->kfocP
, _("Click window to focus"));
255 WMAddPopUpButtonItem(panel
->kfocP
, _("Focus follows mouse"));
256 WMAddPopUpButtonItem(panel
->kfocP
, _("\"Sloppy\" focus"));
257 WMSetPopUpButtonAction(panel
->kfocP
, changeFocusMode
, panel
);
259 panel
->kfocL
= WMCreateLabel(panel
->kfocF
);
260 WMResizeWidget(panel
->kfocL
, 211, 68);
261 WMMoveWidget(panel
->kfocL
, 15, 55);
262 WMSetLabelTextAlignment(panel
->kfocL
, WACenter
);
264 WMMapSubwidgets(panel
->kfocF
);
266 /***************** Colormap Installation Mode ****************/
268 panel
->cfocF
= WMCreateFrame(panel
->frame
);
269 WMResizeWidget(panel
->cfocF
, 240, 70);
270 WMMoveWidget(panel
->cfocF
, 15, 150);
271 WMSetFrameTitle(panel
->cfocF
, _("Install colormap in the window..."));
273 panel
->manB
= WMCreateRadioButton(panel
->cfocF
);
274 WMResizeWidget(panel
->manB
, 220, 20);
275 WMMoveWidget(panel
->manB
, 15, 18);
276 WMSetButtonText(panel
->manB
, _("...that has the input focus."));
278 panel
->autB
= WMCreateRadioButton(panel
->cfocF
);
279 WMResizeWidget(panel
->autB
, 220, 20);
280 WMMoveWidget(panel
->autB
, 15, 40);
281 WMSetButtonText(panel
->autB
, _("...that is under the mouse pointer."));
282 WMGroupButtons(panel
->manB
, panel
->autB
);
284 WMMapSubwidgets(panel
->cfocF
);
286 /***************** Automatic window raise delay *****************/
287 panel
->raisF
= WMCreateFrame(panel
->frame
);
288 WMResizeWidget(panel
->raisF
, 245, 70);
289 WMMoveWidget(panel
->raisF
, 265, 15);
290 WMSetFrameTitle(panel
->raisF
, _("Automatic Window Raise Delay"));
292 buf1
= wmalloc(strlen(DELAY_ICON
)+1);
293 buf2
= wmalloc(strlen(DELAY_ICON_S
)+1);
295 for (i
= 0; i
< 5; i
++) {
298 panel
->raisB
[i
] = WMCreateCustomButton(panel
->raisF
,
300 WMResizeWidget(panel
->raisB
[i
], 25, 25);
301 WMMoveWidget(panel
->raisB
[i
], 10+(30*i
), 25);
302 WMSetButtonBordered(panel
->raisB
[i
], False
);
303 WMSetButtonImagePosition(panel
->raisB
[i
], WIPImageOnly
);
304 WMSetButtonAction(panel
->raisB
[i
], pushDelayButton
, panel
);
306 WMGroupButtons(panel
->raisB
[0], panel
->raisB
[i
]);
307 sprintf(buf1
, DELAY_ICON
, i
);
308 sprintf(buf2
, DELAY_ICON_S
, i
);
309 path
= LocateImage(buf1
);
311 icon
= WMCreatePixmapFromFile(scr
, path
);
313 WMSetButtonImage(panel
->raisB
[i
], icon
);
314 WMReleasePixmap(icon
);
316 wwarning(_("could not load icon file %s"), path
);
320 path
= LocateImage(buf2
);
322 icon
= WMCreatePixmapFromFile(scr
, path
);
324 WMSetButtonAltImage(panel
->raisB
[i
], icon
);
325 WMReleasePixmap(icon
);
327 wwarning(_("could not load icon file %s"), path
);
335 panel
->raisT
= WMCreateTextField(panel
->raisF
);
336 WMResizeWidget(panel
->raisT
, 36, 20);
337 WMMoveWidget(panel
->raisT
, 165, 30);
338 WMAddNotificationObserver(raiseTextChanged
, panel
,
339 WMTextDidChangeNotification
, panel
->raisT
);
341 color
= WMDarkGrayColor(scr
);
342 font
= WMSystemFontOfSize(scr
, 10);
344 panel
->raisL
= WMCreateLabel(panel
->raisF
);
345 WMResizeWidget(panel
->raisL
, 36, 16);
346 WMMoveWidget(panel
->raisL
, 205, 35);
347 WMSetLabelText(panel
->raisL
, _("msec"));
348 WMSetLabelTextColor(panel
->raisL
, color
);
349 WMSetLabelFont(panel
->raisL
, font
);
351 WMReleaseColor(color
);
354 WMMapSubwidgets(panel
->raisF
);
356 /***************** Options ****************/
357 panel
->optF
= WMCreateFrame(panel
->frame
);
358 WMResizeWidget(panel
->optF
, 245, 125);
359 WMMoveWidget(panel
->optF
, 265, 95);
361 panel
->ignB
= WMCreateSwitchButton(panel
->optF
);
362 WMResizeWidget(panel
->ignB
, 210, 50);
363 WMMoveWidget(panel
->ignB
, 15, 10);
364 WMSetButtonText(panel
->ignB
, _("Do not let applications receive the "\
365 "click used to focus windows."));
367 panel
->newB
= WMCreateSwitchButton(panel
->optF
);
368 WMResizeWidget(panel
->newB
, 210, 35);
369 WMMoveWidget(panel
->newB
, 15, 70);
370 WMSetButtonText(panel
->newB
, _("Automatically focus new windows."));
372 WMMapSubwidgets(panel
->optF
);
375 WMRealizeWidget(panel
->frame
);
376 WMMapSubwidgets(panel
->frame
);
384 InitFocus(WMScreen
*scr
, WMWindow
*win
)
388 panel
= wmalloc(sizeof(_Panel
));
389 memset(panel
, 0, sizeof(_Panel
));
391 panel
->sectionName
= _("Window Focus Preferences");
393 panel
->description
= _("Keyboard focus switching policy, colormap switching\n"
394 "policy for 8bpp displays and other related options.");
398 panel
->callbacks
.createWidgets
= createPanel
;
399 panel
->callbacks
.updateDomain
= storeData
;
401 AddSection(panel
, ICON_FILE
);