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
{
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");
74 if (strcasecmp(str
, "manual")==0 || strcasecmp(str
, "clicktofocus")==0)
75 WMSetPopUpButtonSelectedItem(panel
->kfocP
, 0);
76 else if (strcasecmp(str
, "auto")==0 || strcasecmp(str
, "focusfollowsmouse")==0)
77 WMSetPopUpButtonSelectedItem(panel
->kfocP
, 1);
78 else if (strcasecmp(str
, "semiauto")==0 || strcasecmp(str
, "sloppy")==0)
79 WMSetPopUpButtonSelectedItem(panel
->kfocP
, 2);
81 wwarning(_("bad option value %s for option FocusMode. Using default Manual"),
83 WMSetPopUpButtonSelectedItem(panel
->kfocP
, 0);
85 changeFocusMode(panel
->kfocP
, panel
);
88 str
= GetStringForKey("ColormapMode");
91 if (strcasecmp(str
, "manual")==0 || strcasecmp(str
, "clicktofocus")==0) {
92 WMPerformButtonClick(panel
->manB
);
93 } else if (strcasecmp(str
, "auto")==0 || strcasecmp(str
, "focusfollowsmouse")==0) {
94 WMPerformButtonClick(panel
->autB
);
96 wwarning(_("bad option value %s for option ColormapMode. Using default Auto"),
98 WMPerformButtonClick(panel
->manB
);
102 i
= GetIntegerForKey("RaiseDelay");
103 sprintf(buffer
, "%i", i
);
104 WMSetTextFieldText(panel
->raisT
, buffer
);
108 WMPerformButtonClick(panel
->raisB
[0]);
111 WMPerformButtonClick(panel
->raisB
[1]);
114 WMPerformButtonClick(panel
->raisB
[2]);
117 WMPerformButtonClick(panel
->raisB
[3]);
120 WMPerformButtonClick(panel
->raisB
[4]);
125 WMSetButtonSelected(panel
->ignB
, GetBoolForKey("IgnoreFocusClick"));
127 WMSetButtonSelected(panel
->newB
, GetBoolForKey("AutoFocus"));
133 storeData(_Panel
*panel
)
138 switch (WMGetPopUpButtonSelectedItem(panel
->kfocP
)) {
149 SetStringForKey(str
, "FocusMode");
151 if (WMGetButtonSelected(panel
->manB
)) {
152 SetStringForKey("manual", "ColormapMode");
154 SetStringForKey("auto", "ColormapMode");
157 str
= WMGetTextFieldText(panel
->raisT
);
158 if (sscanf(str
, "%i", &i
)!=1)
160 SetIntegerForKey(i
, "RaiseDelay");
162 SetBoolForKey(WMGetButtonSelected(panel
->ignB
), "IgnoreFocusClick");
163 SetBoolForKey(WMGetButtonSelected(panel
->newB
), "AutoFocus");
168 pushDelayButton(WMWidget
*w
, void *data
)
170 _Panel
*panel
= (_Panel
*)data
;
172 panel
->raiseDelaySelected
= 1;
173 if (w
== panel
->raisB
[0]) {
174 WMSetTextFieldText(panel
->raisT
, "OFF");
175 } else if (w
== panel
->raisB
[1]) {
176 WMSetTextFieldText(panel
->raisT
, "10");
177 } else if (w
== panel
->raisB
[2]) {
178 WMSetTextFieldText(panel
->raisT
, "100");
179 } else if (w
== panel
->raisB
[3]) {
180 WMSetTextFieldText(panel
->raisT
, "350");
181 } else if (w
== panel
->raisB
[4]) {
182 WMSetTextFieldText(panel
->raisT
, "800");
188 changeFocusMode(WMWidget
*w
, void *data
)
190 _Panel
*panel
= (_Panel
*)data
;
192 switch (WMGetPopUpButtonSelectedItem(w
)) {
194 WMSetLabelText(panel
->kfocL
, _("Click on the window to set\n"\
195 "keyboard input focus."));
198 WMSetLabelText(panel
->kfocL
, _("Set keyboard input focus to\n"\
199 "the window under the mouse pointer,\n"\
200 "including the root window."));
203 WMSetLabelText(panel
->kfocL
, _("Set keyboard input focus to\n"\
204 "the window under the mouse pointer,\n"\
205 "except the root window."));
212 raiseTextChanged(void *observerData
, WMNotification
*notification
)
214 _Panel
*panel
= (_Panel
*)observerData
;
217 if (panel
->raiseDelaySelected
) {
218 for (i
=0; i
<5; i
++) {
219 WMSetButtonSelected(panel
->raisB
[i
], False
);
221 panel
->raiseDelaySelected
= 0;
229 createPanel(Panel
*p
)
231 _Panel
*panel
= (_Panel
*)p
;
232 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
239 panel
->frame
= WMCreateFrame(panel
->win
);
240 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
241 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
243 /***************** Input Focus Mode *****************/
244 panel
->kfocF
= WMCreateFrame(panel
->frame
);
245 WMResizeWidget(panel
->kfocF
, 240, 130);
246 WMMoveWidget(panel
->kfocF
, 15, 15);
247 WMSetFrameTitle(panel
->kfocF
, _("Input Focus Mode"));
249 panel
->kfocP
= WMCreatePopUpButton(panel
->kfocF
);
250 WMResizeWidget(panel
->kfocP
, 210, 20);
251 WMMoveWidget(panel
->kfocP
, 15, 30);
252 WMAddPopUpButtonItem(panel
->kfocP
, _("Click window to focus"));
253 WMAddPopUpButtonItem(panel
->kfocP
, _("Focus follows mouse"));
254 WMAddPopUpButtonItem(panel
->kfocP
, _("\"Sloppy\" focus"));
255 WMSetPopUpButtonAction(panel
->kfocP
, changeFocusMode
, panel
);
257 panel
->kfocL
= WMCreateLabel(panel
->kfocF
);
258 WMResizeWidget(panel
->kfocL
, 211, 68);
259 WMMoveWidget(panel
->kfocL
, 15, 55);
260 WMSetLabelTextAlignment(panel
->kfocL
, WACenter
);
262 WMMapSubwidgets(panel
->kfocF
);
264 /***************** Colormap Installation Mode ****************/
266 panel
->cfocF
= WMCreateFrame(panel
->frame
);
267 WMResizeWidget(panel
->cfocF
, 240, 70);
268 WMMoveWidget(panel
->cfocF
, 15, 150);
269 WMSetFrameTitle(panel
->cfocF
, _("Install colormap in the window..."));
271 panel
->manB
= WMCreateRadioButton(panel
->cfocF
);
272 WMResizeWidget(panel
->manB
, 220, 20);
273 WMMoveWidget(panel
->manB
, 15, 18);
274 WMSetButtonText(panel
->manB
, _("...that has the input focus."));
276 panel
->autB
= WMCreateRadioButton(panel
->cfocF
);
277 WMResizeWidget(panel
->autB
, 220, 20);
278 WMMoveWidget(panel
->autB
, 15, 40);
279 WMSetButtonText(panel
->autB
, _("...that is under the mouse pointer."));
280 WMGroupButtons(panel
->manB
, panel
->autB
);
282 WMMapSubwidgets(panel
->cfocF
);
284 /***************** Automatic window raise delay *****************/
285 panel
->raisF
= WMCreateFrame(panel
->frame
);
286 WMResizeWidget(panel
->raisF
, 245, 70);
287 WMMoveWidget(panel
->raisF
, 265, 15);
288 WMSetFrameTitle(panel
->raisF
, _("Automatic Window Raise Delay"));
290 buf1
= wmalloc(strlen(DELAY_ICON
)+1);
291 buf2
= wmalloc(strlen(DELAY_ICON_S
)+1);
293 for (i
= 0; i
< 5; i
++) {
296 panel
->raisB
[i
] = WMCreateCustomButton(panel
->raisF
,
298 WMResizeWidget(panel
->raisB
[i
], 25, 25);
299 WMMoveWidget(panel
->raisB
[i
], 10+(30*i
), 25);
300 WMSetButtonBordered(panel
->raisB
[i
], False
);
301 WMSetButtonImagePosition(panel
->raisB
[i
], WIPImageOnly
);
302 WMSetButtonAction(panel
->raisB
[i
], pushDelayButton
, panel
);
304 WMGroupButtons(panel
->raisB
[0], panel
->raisB
[i
]);
305 sprintf(buf1
, DELAY_ICON
, i
);
306 sprintf(buf2
, DELAY_ICON_S
, i
);
307 path
= LocateImage(buf1
);
309 icon
= WMCreatePixmapFromFile(scr
, path
);
311 WMSetButtonImage(panel
->raisB
[i
], icon
);
312 WMReleasePixmap(icon
);
314 wwarning(_("could not load icon file %s"), path
);
318 path
= LocateImage(buf2
);
320 icon
= WMCreatePixmapFromFile(scr
, path
);
322 WMSetButtonAltImage(panel
->raisB
[i
], icon
);
323 WMReleasePixmap(icon
);
325 wwarning(_("could not load icon file %s"), path
);
333 panel
->raisT
= WMCreateTextField(panel
->raisF
);
334 WMResizeWidget(panel
->raisT
, 36, 20);
335 WMMoveWidget(panel
->raisT
, 165, 30);
336 WMAddNotificationObserver(raiseTextChanged
, panel
,
337 WMTextDidChangeNotification
, panel
->raisT
);
339 color
= WMDarkGrayColor(scr
);
340 font
= WMSystemFontOfSize(scr
, 10);
342 panel
->raisL
= WMCreateLabel(panel
->raisF
);
343 WMResizeWidget(panel
->raisL
, 36, 16);
344 WMMoveWidget(panel
->raisL
, 205, 35);
345 WMSetLabelText(panel
->raisL
, _("msec"));
346 WMSetLabelTextColor(panel
->raisL
, color
);
347 WMSetLabelFont(panel
->raisL
, font
);
349 WMReleaseColor(color
);
352 WMMapSubwidgets(panel
->raisF
);
354 /***************** Options ****************/
355 panel
->optF
= WMCreateFrame(panel
->frame
);
356 WMResizeWidget(panel
->optF
, 245, 125);
357 WMMoveWidget(panel
->optF
, 265, 95);
359 panel
->ignB
= WMCreateSwitchButton(panel
->optF
);
360 WMResizeWidget(panel
->ignB
, 210, 50);
361 WMMoveWidget(panel
->ignB
, 15, 10);
362 WMSetButtonText(panel
->ignB
, _("Do not let applications receive the "\
363 "click used to focus windows."));
365 panel
->newB
= WMCreateSwitchButton(panel
->optF
);
366 WMResizeWidget(panel
->newB
, 210, 35);
367 WMMoveWidget(panel
->newB
, 15, 70);
368 WMSetButtonText(panel
->newB
, _("Automatically focus new windows."));
370 WMMapSubwidgets(panel
->optF
);
373 WMRealizeWidget(panel
->frame
);
374 WMMapSubwidgets(panel
->frame
);
382 InitFocus(WMScreen
*scr
, WMWindow
*win
)
386 panel
= wmalloc(sizeof(_Panel
));
387 memset(panel
, 0, sizeof(_Panel
));
389 panel
->sectionName
= _("Window Focus Preferences");
393 panel
->callbacks
.createWidgets
= createPanel
;
394 panel
->callbacks
.updateDomain
= storeData
;
396 AddSection(panel
, ICON_FILE
);