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
;
53 char raiseDelaySelected
;
58 #define ICON_FILE "windowfocus"
60 #define DELAY_ICON "timer%i"
61 #define DELAY_ICON_S "timer%is"
63 static void changeFocusMode(WMWidget
*w
, void *data
);
66 showData(_Panel
*panel
)
72 str
= GetStringForKey("FocusMode");
75 if (strcasecmp(str
, "manual")==0 || strcasecmp(str
, "clicktofocus")==0)
76 WMSetButtonSelected(panel
->kfocB
[0], 1);
77 else if (strcasecmp(str
, "auto")==0 || strcasecmp(str
, "semiauto")==0
78 || strcasecmp(str
, "sloppy")==0)
79 WMSetButtonSelected(panel
->kfocB
[1], 1);
81 wwarning(_("bad option value %s for option FocusMode. Using default Manual"),
83 WMSetButtonSelected(panel
->kfocB
[0], 1);
87 str
= GetStringForKey("ColormapMode");
90 if (strcasecmp(str
, "manual")==0 || strcasecmp(str
, "clicktofocus")==0) {
91 WMPerformButtonClick(panel
->manB
);
92 } else if (strcasecmp(str
, "auto")==0 || strcasecmp(str
, "focusfollowsmouse")==0) {
93 WMPerformButtonClick(panel
->autB
);
95 wwarning(_("bad option value %s for option ColormapMode. Using default Auto"),
97 WMPerformButtonClick(panel
->manB
);
101 i
= GetIntegerForKey("RaiseDelay");
102 sprintf(buffer
, "%i", i
);
103 WMSetTextFieldText(panel
->raisT
, buffer
);
107 WMPerformButtonClick(panel
->raisB
[0]);
110 WMPerformButtonClick(panel
->raisB
[1]);
113 WMPerformButtonClick(panel
->raisB
[2]);
116 WMPerformButtonClick(panel
->raisB
[3]);
119 WMPerformButtonClick(panel
->raisB
[4]);
124 WMSetButtonSelected(panel
->ignB
, GetBoolForKey("IgnoreFocusClick"));
126 WMSetButtonSelected(panel
->newB
, GetBoolForKey("AutoFocus"));
132 storeData(_Panel
*panel
)
137 if (WMGetButtonSelected(panel
->kfocB
[1]))
142 SetStringForKey(str
, "FocusMode");
144 if (WMGetButtonSelected(panel
->manB
)) {
145 SetStringForKey("manual", "ColormapMode");
147 SetStringForKey("auto", "ColormapMode");
150 str
= WMGetTextFieldText(panel
->raisT
);
151 if (sscanf(str
, "%i", &i
)!=1)
153 SetIntegerForKey(i
, "RaiseDelay");
155 SetBoolForKey(WMGetButtonSelected(panel
->ignB
), "IgnoreFocusClick");
156 SetBoolForKey(WMGetButtonSelected(panel
->newB
), "AutoFocus");
161 pushDelayButton(WMWidget
*w
, void *data
)
163 _Panel
*panel
= (_Panel
*)data
;
165 panel
->raiseDelaySelected
= 1;
166 if (w
== panel
->raisB
[0]) {
167 WMSetTextFieldText(panel
->raisT
, "OFF");
168 } else if (w
== panel
->raisB
[1]) {
169 WMSetTextFieldText(panel
->raisT
, "10");
170 } else if (w
== panel
->raisB
[2]) {
171 WMSetTextFieldText(panel
->raisT
, "100");
172 } else if (w
== panel
->raisB
[3]) {
173 WMSetTextFieldText(panel
->raisT
, "350");
174 } else if (w
== panel
->raisB
[4]) {
175 WMSetTextFieldText(panel
->raisT
, "800");
181 raiseTextChanged(void *observerData
, WMNotification
*notification
)
183 _Panel
*panel
= (_Panel
*)observerData
;
186 if (panel
->raiseDelaySelected
) {
187 for (i
=0; i
<5; i
++) {
188 WMSetButtonSelected(panel
->raisB
[i
], False
);
190 panel
->raiseDelaySelected
= 0;
198 createPanel(Panel
*p
)
200 _Panel
*panel
= (_Panel
*)p
;
201 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
208 panel
->box
= WMCreateBox(panel
->parent
);
209 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
211 /***************** Input Focus Mode *****************/
212 panel
->kfocF
= WMCreateFrame(panel
->box
);
213 WMResizeWidget(panel
->kfocF
, 240, 130);
214 WMMoveWidget(panel
->kfocF
, 15, 15);
215 WMSetFrameTitle(panel
->kfocF
, _("Input Focus Mode"));
218 WMBox
*box
= WMCreateBox(panel
->kfocF
);
219 WMSetViewExpandsToParent(WMWidgetView(box
), 10, 15, 10, 10);
220 WMSetBoxHorizontal(box
, False
);
222 panel
->kfocB
[0] = WMCreateRadioButton(box
);
223 WMSetButtonText(panel
->kfocB
[0], _("Manual: Click on the window to set "\
224 "keyboard input focus"));
225 WMAddBoxSubview(box
, WMWidgetView(panel
->kfocB
[0]), True
, True
,
228 panel
->kfocB
[1] = WMCreateRadioButton(box
);
229 WMGroupButtons(panel
->kfocB
[0], panel
->kfocB
[1]);
230 WMSetButtonText(panel
->kfocB
[1], _("Auto: Set keyboard input focus to "\
231 "the window under the mouse pointer"));
232 WMAddBoxSubview(box
, WMWidgetView(panel
->kfocB
[1]), True
, True
,
235 WMMapSubwidgets(box
);
239 /***************** Colormap Installation Mode ****************/
241 panel
->cfocF
= WMCreateFrame(panel
->box
);
242 WMResizeWidget(panel
->cfocF
, 240, 70);
243 WMMoveWidget(panel
->cfocF
, 15, 150);
244 WMSetFrameTitle(panel
->cfocF
, _("Install colormap in the window..."));
246 panel
->manB
= WMCreateRadioButton(panel
->cfocF
);
247 WMResizeWidget(panel
->manB
, 220, 20);
248 WMMoveWidget(panel
->manB
, 15, 18);
249 WMSetButtonText(panel
->manB
, _("...that has the input focus."));
251 panel
->autB
= WMCreateRadioButton(panel
->cfocF
);
252 WMResizeWidget(panel
->autB
, 220, 20);
253 WMMoveWidget(panel
->autB
, 15, 40);
254 WMSetButtonText(panel
->autB
, _("...that is under the mouse pointer."));
255 WMGroupButtons(panel
->manB
, panel
->autB
);
257 WMMapSubwidgets(panel
->cfocF
);
259 /***************** Automatic window raise delay *****************/
260 panel
->raisF
= WMCreateFrame(panel
->box
);
261 WMResizeWidget(panel
->raisF
, 245, 70);
262 WMMoveWidget(panel
->raisF
, 265, 15);
263 WMSetFrameTitle(panel
->raisF
, _("Automatic Window Raise Delay"));
265 buf1
= wmalloc(strlen(DELAY_ICON
)+1);
266 buf2
= wmalloc(strlen(DELAY_ICON_S
)+1);
268 for (i
= 0; i
< 5; i
++) {
271 panel
->raisB
[i
] = WMCreateCustomButton(panel
->raisF
,
273 WMResizeWidget(panel
->raisB
[i
], 25, 25);
274 WMMoveWidget(panel
->raisB
[i
], 10+(30*i
), 25);
275 WMSetButtonBordered(panel
->raisB
[i
], False
);
276 WMSetButtonImagePosition(panel
->raisB
[i
], WIPImageOnly
);
277 WMSetButtonAction(panel
->raisB
[i
], pushDelayButton
, panel
);
279 WMGroupButtons(panel
->raisB
[0], panel
->raisB
[i
]);
280 sprintf(buf1
, DELAY_ICON
, i
);
281 sprintf(buf2
, DELAY_ICON_S
, i
);
282 path
= LocateImage(buf1
);
284 icon
= WMCreatePixmapFromFile(scr
, path
);
286 WMSetButtonImage(panel
->raisB
[i
], icon
);
287 WMReleasePixmap(icon
);
289 wwarning(_("could not load icon file %s"), path
);
293 path
= LocateImage(buf2
);
295 icon
= WMCreatePixmapFromFile(scr
, path
);
297 WMSetButtonAltImage(panel
->raisB
[i
], icon
);
298 WMReleasePixmap(icon
);
300 wwarning(_("could not load icon file %s"), path
);
308 panel
->raisT
= WMCreateTextField(panel
->raisF
);
309 WMResizeWidget(panel
->raisT
, 36, 20);
310 WMMoveWidget(panel
->raisT
, 165, 30);
311 WMAddNotificationObserver(raiseTextChanged
, panel
,
312 WMTextDidChangeNotification
, panel
->raisT
);
314 color
= WMDarkGrayColor(scr
);
315 font
= WMSystemFontOfSize(scr
, 10);
317 panel
->raisL
= WMCreateLabel(panel
->raisF
);
318 WMResizeWidget(panel
->raisL
, 36, 16);
319 WMMoveWidget(panel
->raisL
, 205, 35);
320 WMSetLabelText(panel
->raisL
, _("msec"));
321 WMSetLabelTextColor(panel
->raisL
, color
);
322 WMSetLabelFont(panel
->raisL
, font
);
324 WMReleaseColor(color
);
327 WMMapSubwidgets(panel
->raisF
);
329 /***************** Options ****************/
330 panel
->optF
= WMCreateFrame(panel
->box
);
331 WMResizeWidget(panel
->optF
, 245, 125);
332 WMMoveWidget(panel
->optF
, 265, 95);
334 panel
->ignB
= WMCreateSwitchButton(panel
->optF
);
335 WMResizeWidget(panel
->ignB
, 210, 50);
336 WMMoveWidget(panel
->ignB
, 15, 10);
337 WMSetButtonText(panel
->ignB
, _("Do not let applications receive\n"
338 "the click used to focus windows."));
340 panel
->newB
= WMCreateSwitchButton(panel
->optF
);
341 WMResizeWidget(panel
->newB
, 210, 35);
342 WMMoveWidget(panel
->newB
, 15, 70);
343 WMSetButtonText(panel
->newB
, _("Automatically focus new\nwindows."));
345 WMMapSubwidgets(panel
->optF
);
348 WMRealizeWidget(panel
->box
);
349 WMMapSubwidgets(panel
->box
);
357 InitFocus(WMScreen
*scr
, WMWindow
*win
)
361 panel
= wmalloc(sizeof(_Panel
));
362 memset(panel
, 0, sizeof(_Panel
));
364 panel
->sectionName
= _("Window Focus Preferences");
366 panel
->description
= _("Keyboard focus switching policy, colormap switching\n"
367 "policy for 8bpp displays and other related options.");
371 panel
->callbacks
.createWidgets
= createPanel
;
372 panel
->callbacks
.updateDomain
= storeData
;
374 AddSection(panel
, ICON_FILE
);