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");
142 SetBoolForKey(WMGetButtonSelected(panel
->ignB
), "IgnoreFocusClick");
143 SetBoolForKey(WMGetButtonSelected(panel
->newB
), "AutoFocus");
144 SetBoolForKey(WMGetButtonSelected(panel
->craisB
), "CirculateRaise");
147 static void pushDelayButton(WMWidget
* w
, void *data
)
149 _Panel
*panel
= (_Panel
*) data
;
151 panel
->raiseDelaySelected
= 1;
152 if (w
== panel
->raisB
[0]) {
153 WMSetTextFieldText(panel
->raisT
, "OFF");
154 } else if (w
== panel
->raisB
[1]) {
155 WMSetTextFieldText(panel
->raisT
, "10");
156 } else if (w
== panel
->raisB
[2]) {
157 WMSetTextFieldText(panel
->raisT
, "100");
158 } else if (w
== panel
->raisB
[3]) {
159 WMSetTextFieldText(panel
->raisT
, "350");
160 } else if (w
== panel
->raisB
[4]) {
161 WMSetTextFieldText(panel
->raisT
, "800");
165 static void raiseTextChanged(void *observerData
, WMNotification
* notification
)
167 _Panel
*panel
= (_Panel
*) observerData
;
170 if (panel
->raiseDelaySelected
) {
171 for (i
= 0; i
< 5; i
++) {
172 WMSetButtonSelected(panel
->raisB
[i
], False
);
174 panel
->raiseDelaySelected
= 0;
178 static void createPanel(Panel
* p
)
180 _Panel
*panel
= (_Panel
*) p
;
181 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
188 panel
->box
= WMCreateBox(panel
->parent
);
189 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
191 /***************** Input Focus Mode *****************/
192 panel
->kfocF
= WMCreateFrame(panel
->box
);
193 WMResizeWidget(panel
->kfocF
, 240, 125);
194 WMMoveWidget(panel
->kfocF
, 15, 10);
195 WMSetFrameTitle(panel
->kfocF
, _("Input Focus Mode"));
198 WMBox
*box
= WMCreateBox(panel
->kfocF
);
199 WMSetViewExpandsToParent(WMWidgetView(box
), 10, 15, 10, 10);
200 WMSetBoxHorizontal(box
, False
);
202 panel
->kfocB
[0] = WMCreateRadioButton(box
);
203 WMSetButtonText(panel
->kfocB
[0], _("Manual: Click on the window to set "
204 "keyboard input focus."));
205 WMAddBoxSubview(box
, WMWidgetView(panel
->kfocB
[0]), True
, True
, 20, 0, 0);
207 panel
->kfocB
[1] = WMCreateRadioButton(box
);
208 WMGroupButtons(panel
->kfocB
[0], panel
->kfocB
[1]);
209 WMSetButtonText(panel
->kfocB
[1], _("Auto: Set keyboard input focus to "
210 "the window under the mouse pointer."));
211 WMAddBoxSubview(box
, WMWidgetView(panel
->kfocB
[1]), True
, True
, 20, 0, 0);
213 WMMapSubwidgets(box
);
217 /***************** Colormap Installation Mode ****************/
219 panel
->cfocF
= WMCreateFrame(panel
->box
);
220 WMResizeWidget(panel
->cfocF
, 240, 77);
221 WMMoveWidget(panel
->cfocF
, 15, 143);
222 WMSetFrameTitle(panel
->cfocF
, _("Install colormap in the window..."));
224 panel
->manB
= WMCreateRadioButton(panel
->cfocF
);
225 WMResizeWidget(panel
->manB
, 225, 20);
226 WMMoveWidget(panel
->manB
, 10, 20);
227 WMSetButtonText(panel
->manB
, _("...that has the input focus."));
229 panel
->autB
= WMCreateRadioButton(panel
->cfocF
);
230 WMResizeWidget(panel
->autB
, 225, 20);
231 WMMoveWidget(panel
->autB
, 10, 45);
232 WMSetButtonText(panel
->autB
, _("...that's under the mouse pointer."));
233 WMGroupButtons(panel
->manB
, panel
->autB
);
235 WMMapSubwidgets(panel
->cfocF
);
237 /***************** Automatic window raise delay *****************/
238 panel
->raisF
= WMCreateFrame(panel
->box
);
239 WMResizeWidget(panel
->raisF
, 245, 68);
240 WMMoveWidget(panel
->raisF
, 265, 10);
241 WMSetFrameTitle(panel
->raisF
, _("Automatic Window Raise Delay"));
243 buf1
= wmalloc(strlen(DELAY_ICON
) + 1);
244 buf2
= wmalloc(strlen(DELAY_ICON_S
) + 1);
246 for (i
= 0; i
< 5; i
++) {
249 panel
->raisB
[i
] = WMCreateCustomButton(panel
->raisF
, WBBStateChangeMask
);
250 WMResizeWidget(panel
->raisB
[i
], 25, 25);
251 WMMoveWidget(panel
->raisB
[i
], 12 + (30 * i
), 25);
252 WMSetButtonBordered(panel
->raisB
[i
], False
);
253 WMSetButtonImagePosition(panel
->raisB
[i
], WIPImageOnly
);
254 WMSetButtonAction(panel
->raisB
[i
], pushDelayButton
, panel
);
256 WMGroupButtons(panel
->raisB
[0], panel
->raisB
[i
]);
257 sprintf(buf1
, DELAY_ICON
, i
);
258 sprintf(buf2
, DELAY_ICON_S
, i
);
259 path
= LocateImage(buf1
);
261 icon
= WMCreatePixmapFromFile(scr
, path
);
263 WMSetButtonImage(panel
->raisB
[i
], icon
);
264 WMReleasePixmap(icon
);
266 wwarning(_("could not load icon file %s"), path
);
270 path
= LocateImage(buf2
);
272 icon
= WMCreatePixmapFromFile(scr
, path
);
274 WMSetButtonAltImage(panel
->raisB
[i
], icon
);
275 WMReleasePixmap(icon
);
277 wwarning(_("could not load icon file %s"), path
);
285 panel
->raisT
= WMCreateTextField(panel
->raisF
);
286 WMResizeWidget(panel
->raisT
, 36, 20);
287 WMMoveWidget(panel
->raisT
, 165, 28);
288 WMAddNotificationObserver(raiseTextChanged
, panel
, WMTextDidChangeNotification
, panel
->raisT
);
290 color
= WMDarkGrayColor(scr
);
291 font
= WMSystemFontOfSize(scr
, 10);
293 panel
->raisL
= WMCreateLabel(panel
->raisF
);
294 WMResizeWidget(panel
->raisL
, 36, 16);
295 WMMoveWidget(panel
->raisL
, 205, 32);
296 WMSetLabelText(panel
->raisL
, _("msec"));
297 WMSetLabelTextColor(panel
->raisL
, color
);
298 WMSetLabelFont(panel
->raisL
, font
);
300 WMReleaseColor(color
);
303 WMMapSubwidgets(panel
->raisF
);
305 /***************** Options ****************/
306 panel
->optF
= WMCreateFrame(panel
->box
);
307 WMResizeWidget(panel
->optF
, 245, 132);
308 WMMoveWidget(panel
->optF
, 265, 88);
310 panel
->ignB
= WMCreateSwitchButton(panel
->optF
);
311 WMResizeWidget(panel
->ignB
, 225, 50);
312 WMMoveWidget(panel
->ignB
, 10, 4);
313 WMSetButtonText(panel
->ignB
, _("Do not let applications receive " "the click used to focus windows."));
315 panel
->newB
= WMCreateSwitchButton(panel
->optF
);
316 WMResizeWidget(panel
->newB
, 225, 35);
317 WMMoveWidget(panel
->newB
, 10, 49);
318 WMSetButtonText(panel
->newB
, _("Automatically focus new windows."));
320 panel
->craisB
= WMCreateSwitchButton(panel
->optF
);
321 WMResizeWidget(panel
->craisB
, 225, 36);
322 WMMoveWidget(panel
->craisB
, 10, 85);
323 WMSetButtonText(panel
->craisB
, _("Raise window when switching\nfocus with keyboard."));
325 WMMapSubwidgets(panel
->optF
);
327 WMRealizeWidget(panel
->box
);
328 WMMapSubwidgets(panel
->box
);
333 Panel
*InitFocus(WMScreen
* scr
, WMWindow
* win
)
337 panel
= wmalloc(sizeof(_Panel
));
339 panel
->sectionName
= _("Window Focus Preferences");
340 panel
->description
= _("Keyboard focus switching policy and related options.");
343 panel
->callbacks
.createWidgets
= createPanel
;
344 panel
->callbacks
.updateDomain
= storeData
;
346 AddSection(panel
, ICON_FILE
);