1 /* Focus.c- input and colormap focus stuff
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 1998-2003 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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 typedef struct _Panel
{
31 CallbackRec callbacks
;
52 char raiseDelaySelected
;
55 #define ICON_FILE "windowfocus"
57 #define DELAY_ICON "timer%i"
58 #define DELAY_ICON_S "timer%is"
60 static void showData(_Panel
* panel
)
66 str
= GetStringForKey("FocusMode");
69 if (strcasecmp(str
, "manual") == 0 || strcasecmp(str
, "clicktofocus") == 0)
70 WMSetButtonSelected(panel
->kfocB
[0], 1);
71 else if (strcasecmp(str
, "auto") == 0 || strcasecmp(str
, "semiauto") == 0
72 || strcasecmp(str
, "sloppy") == 0)
73 WMSetButtonSelected(panel
->kfocB
[1], 1);
75 wwarning(_("bad option value %s for option FocusMode. Using default Manual"), str
);
76 WMSetButtonSelected(panel
->kfocB
[0], 1);
79 /**/ str
= GetStringForKey("ColormapMode");
82 if (strcasecmp(str
, "manual") == 0 || strcasecmp(str
, "clicktofocus") == 0) {
83 WMPerformButtonClick(panel
->manB
);
84 } else if (strcasecmp(str
, "auto") == 0 || strcasecmp(str
, "focusfollowsmouse") == 0) {
85 WMPerformButtonClick(panel
->autB
);
87 wwarning(_("bad option value %s for option ColormapMode. Using default Auto"), str
);
88 WMPerformButtonClick(panel
->manB
);
91 /**/ i
= GetIntegerForKey("RaiseDelay");
92 sprintf(buffer
, "%i", i
);
93 WMSetTextFieldText(panel
->raisT
, buffer
);
97 WMPerformButtonClick(panel
->raisB
[0]);
100 WMPerformButtonClick(panel
->raisB
[1]);
103 WMPerformButtonClick(panel
->raisB
[2]);
106 WMPerformButtonClick(panel
->raisB
[3]);
109 WMPerformButtonClick(panel
->raisB
[4]);
113 /**/ WMSetButtonSelected(panel
->ignB
, GetBoolForKey("IgnoreFocusClick"));
115 WMSetButtonSelected(panel
->newB
, GetBoolForKey("AutoFocus"));
116 WMSetButtonSelected(panel
->craisB
, GetBoolForKey("CirculateRaise"));
119 static void storeData(_Panel
* panel
)
124 if (WMGetButtonSelected(panel
->kfocB
[1]))
129 SetStringForKey(str
, "FocusMode");
131 if (WMGetButtonSelected(panel
->manB
)) {
132 SetStringForKey("manual", "ColormapMode");
134 SetStringForKey("auto", "ColormapMode");
137 str
= WMGetTextFieldText(panel
->raisT
);
138 if (sscanf(str
, "%i", &i
) != 1)
140 SetIntegerForKey(i
, "RaiseDelay");
143 SetBoolForKey(WMGetButtonSelected(panel
->ignB
), "IgnoreFocusClick");
144 SetBoolForKey(WMGetButtonSelected(panel
->newB
), "AutoFocus");
145 SetBoolForKey(WMGetButtonSelected(panel
->craisB
), "CirculateRaise");
148 static void pushDelayButton(WMWidget
* w
, void *data
)
150 _Panel
*panel
= (_Panel
*) data
;
152 panel
->raiseDelaySelected
= 1;
153 if (w
== panel
->raisB
[0]) {
154 WMSetTextFieldText(panel
->raisT
, _("OFF"));
155 } else if (w
== panel
->raisB
[1]) {
156 WMSetTextFieldText(panel
->raisT
, "10");
157 } else if (w
== panel
->raisB
[2]) {
158 WMSetTextFieldText(panel
->raisT
, "100");
159 } else if (w
== panel
->raisB
[3]) {
160 WMSetTextFieldText(panel
->raisT
, "350");
161 } else if (w
== panel
->raisB
[4]) {
162 WMSetTextFieldText(panel
->raisT
, "800");
166 static void raiseTextChanged(void *observerData
, WMNotification
* notification
)
168 _Panel
*panel
= (_Panel
*) observerData
;
171 /* Parameter not used, but tell the compiler that it is ok */
174 if (panel
->raiseDelaySelected
) {
175 for (i
= 0; i
< 5; i
++) {
176 WMSetButtonSelected(panel
->raisB
[i
], False
);
178 panel
->raiseDelaySelected
= 0;
182 static void createPanel(Panel
* p
)
184 _Panel
*panel
= (_Panel
*) p
;
185 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
192 panel
->box
= WMCreateBox(panel
->parent
);
193 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
195 /***************** Input Focus Mode *****************/
196 panel
->kfocF
= WMCreateFrame(panel
->box
);
197 WMResizeWidget(panel
->kfocF
, 240, 125);
198 WMMoveWidget(panel
->kfocF
, 15, 10);
199 WMSetFrameTitle(panel
->kfocF
, _("Input Focus Mode"));
202 WMBox
*box
= WMCreateBox(panel
->kfocF
);
203 WMSetViewExpandsToParent(WMWidgetView(box
), 10, 15, 10, 10);
204 WMSetBoxHorizontal(box
, False
);
206 panel
->kfocB
[0] = WMCreateRadioButton(box
);
207 WMSetButtonText(panel
->kfocB
[0], _("Manual: Click on the window to set "
208 "keyboard input focus."));
209 WMAddBoxSubview(box
, WMWidgetView(panel
->kfocB
[0]), True
, True
, 20, 0, 0);
211 panel
->kfocB
[1] = WMCreateRadioButton(box
);
212 WMGroupButtons(panel
->kfocB
[0], panel
->kfocB
[1]);
213 WMSetButtonText(panel
->kfocB
[1], _("Auto: Set keyboard input focus to "
214 "the window under the mouse pointer."));
215 WMAddBoxSubview(box
, WMWidgetView(panel
->kfocB
[1]), True
, True
, 20, 0, 0);
217 WMMapSubwidgets(box
);
221 /***************** Colormap Installation Mode ****************/
223 panel
->cfocF
= WMCreateFrame(panel
->box
);
224 WMResizeWidget(panel
->cfocF
, 240, 77);
225 WMMoveWidget(panel
->cfocF
, 15, 143);
226 WMSetFrameTitle(panel
->cfocF
, _("Install colormap in the window..."));
228 panel
->manB
= WMCreateRadioButton(panel
->cfocF
);
229 WMResizeWidget(panel
->manB
, 225, 20);
230 WMMoveWidget(panel
->manB
, 10, 20);
231 WMSetButtonText(panel
->manB
, _("...that has the input focus."));
233 panel
->autB
= WMCreateRadioButton(panel
->cfocF
);
234 WMResizeWidget(panel
->autB
, 225, 20);
235 WMMoveWidget(panel
->autB
, 10, 45);
236 WMSetButtonText(panel
->autB
, _("...that's under the mouse pointer."));
237 WMGroupButtons(panel
->manB
, panel
->autB
);
239 WMMapSubwidgets(panel
->cfocF
);
241 /***************** Automatic window raise delay *****************/
242 panel
->raisF
= WMCreateFrame(panel
->box
);
243 WMResizeWidget(panel
->raisF
, 245, 68);
244 WMMoveWidget(panel
->raisF
, 265, 10);
245 WMSetFrameTitle(panel
->raisF
, _("Automatic Window Raise Delay"));
247 buf1
= wmalloc(strlen(DELAY_ICON
) + 1);
248 buf2
= wmalloc(strlen(DELAY_ICON_S
) + 1);
250 for (i
= 0; i
< 5; i
++) {
253 panel
->raisB
[i
] = WMCreateCustomButton(panel
->raisF
, WBBStateChangeMask
);
254 WMResizeWidget(panel
->raisB
[i
], 25, 25);
255 WMMoveWidget(panel
->raisB
[i
], 12 + (30 * i
), 25);
256 WMSetButtonBordered(panel
->raisB
[i
], False
);
257 WMSetButtonImagePosition(panel
->raisB
[i
], WIPImageOnly
);
258 WMSetButtonAction(panel
->raisB
[i
], pushDelayButton
, panel
);
260 WMGroupButtons(panel
->raisB
[0], panel
->raisB
[i
]);
261 sprintf(buf1
, DELAY_ICON
, i
);
262 sprintf(buf2
, DELAY_ICON_S
, i
);
263 path
= LocateImage(buf1
);
265 icon
= WMCreatePixmapFromFile(scr
, path
);
267 WMSetButtonImage(panel
->raisB
[i
], icon
);
268 WMReleasePixmap(icon
);
270 wwarning(_("could not load icon file %s"), path
);
274 path
= LocateImage(buf2
);
276 icon
= WMCreatePixmapFromFile(scr
, path
);
278 WMSetButtonAltImage(panel
->raisB
[i
], icon
);
279 WMReleasePixmap(icon
);
281 wwarning(_("could not load icon file %s"), path
);
289 panel
->raisT
= WMCreateTextField(panel
->raisF
);
290 WMResizeWidget(panel
->raisT
, 36, 20);
291 WMMoveWidget(panel
->raisT
, 165, 28);
292 WMAddNotificationObserver(raiseTextChanged
, panel
, WMTextDidChangeNotification
, panel
->raisT
);
294 color
= WMDarkGrayColor(scr
);
295 font
= WMSystemFontOfSize(scr
, 10);
297 panel
->raisL
= WMCreateLabel(panel
->raisF
);
298 WMResizeWidget(panel
->raisL
, 36, 16);
299 WMMoveWidget(panel
->raisL
, 205, 32);
300 WMSetLabelText(panel
->raisL
, _("msec"));
301 WMSetLabelTextColor(panel
->raisL
, color
);
302 WMSetLabelFont(panel
->raisL
, font
);
304 WMReleaseColor(color
);
307 WMMapSubwidgets(panel
->raisF
);
309 /***************** Options ****************/
310 panel
->optF
= WMCreateFrame(panel
->box
);
311 WMResizeWidget(panel
->optF
, 245, 132);
312 WMMoveWidget(panel
->optF
, 265, 88);
314 panel
->ignB
= WMCreateSwitchButton(panel
->optF
);
315 WMResizeWidget(panel
->ignB
, 225, 50);
316 WMMoveWidget(panel
->ignB
, 10, 4);
317 WMSetButtonText(panel
->ignB
, _("Do not let applications receive " "the click used to focus windows."));
319 panel
->newB
= WMCreateSwitchButton(panel
->optF
);
320 WMResizeWidget(panel
->newB
, 225, 35);
321 WMMoveWidget(panel
->newB
, 10, 49);
322 WMSetButtonText(panel
->newB
, _("Automatically focus new windows."));
324 panel
->craisB
= WMCreateSwitchButton(panel
->optF
);
325 WMResizeWidget(panel
->craisB
, 225, 36);
326 WMMoveWidget(panel
->craisB
, 10, 85);
327 WMSetButtonText(panel
->craisB
, _("Raise window when switching\nfocus with keyboard."));
329 WMMapSubwidgets(panel
->optF
);
331 WMRealizeWidget(panel
->box
);
332 WMMapSubwidgets(panel
->box
);
337 Panel
*InitFocus(WMWidget
*parent
)
341 panel
= wmalloc(sizeof(_Panel
));
343 panel
->sectionName
= _("Window Focus Preferences");
344 panel
->description
= _("Keyboard focus switching policy and related options.");
345 panel
->parent
= parent
;
347 panel
->callbacks
.createWidgets
= createPanel
;
348 panel
->callbacks
.updateDomain
= storeData
;
350 AddSection(panel
, ICON_FILE
);