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 from the window..."));
228 WMSetBalloonTextForView(_("This option is for screens that can display only a limited number\n"
229 "of colors at a time, so they use an indexed table of colors (called\n"
230 "a ColorMap) that each application customizes for its needs, and\n"
231 "WindowMaker will set the global ColorMap dynamically from the\n"
232 "active application.\n"
233 "You can know the capability of your screen in WindowMaker's info\n"
234 "panel as the 'visual'."),
235 WMWidgetView(panel
->cfocF
));
237 panel
->manB
= WMCreateRadioButton(panel
->cfocF
);
238 WMResizeWidget(panel
->manB
, 226, 24);
239 WMMoveWidget(panel
->manB
, 9, 18);
240 WMSetButtonText(panel
->manB
, _("...that has the input focus"));
242 panel
->autB
= WMCreateRadioButton(panel
->cfocF
);
243 WMResizeWidget(panel
->autB
, 226, 24);
244 WMMoveWidget(panel
->autB
, 9, 43);
245 WMSetButtonText(panel
->autB
, _("...that's under the mouse pointer"));
246 WMGroupButtons(panel
->manB
, panel
->autB
);
248 WMMapSubwidgets(panel
->cfocF
);
250 /***************** Automatic window raise delay *****************/
251 panel
->raisF
= WMCreateFrame(panel
->box
);
252 WMResizeWidget(panel
->raisF
, 245, 68);
253 WMMoveWidget(panel
->raisF
, 265, 10);
254 WMSetFrameTitle(panel
->raisF
, _("Automatic Window Raise Delay"));
256 buf1
= wmalloc(strlen(DELAY_ICON
) + 1);
257 buf2
= wmalloc(strlen(DELAY_ICON_S
) + 1);
259 for (i
= 0; i
< 5; i
++) {
262 panel
->raisB
[i
] = WMCreateCustomButton(panel
->raisF
, WBBStateChangeMask
);
263 WMResizeWidget(panel
->raisB
[i
], 25, 25);
264 WMMoveWidget(panel
->raisB
[i
], 12 + (30 * i
), 25);
265 WMSetButtonBordered(panel
->raisB
[i
], False
);
266 WMSetButtonImagePosition(panel
->raisB
[i
], WIPImageOnly
);
267 WMSetButtonAction(panel
->raisB
[i
], pushDelayButton
, panel
);
269 WMGroupButtons(panel
->raisB
[0], panel
->raisB
[i
]);
270 sprintf(buf1
, DELAY_ICON
, i
);
271 sprintf(buf2
, DELAY_ICON_S
, i
);
272 path
= LocateImage(buf1
);
274 icon
= WMCreatePixmapFromFile(scr
, path
);
276 WMSetButtonImage(panel
->raisB
[i
], icon
);
277 WMReleasePixmap(icon
);
279 wwarning(_("could not load icon file %s"), path
);
283 path
= LocateImage(buf2
);
285 icon
= WMCreatePixmapFromFile(scr
, path
);
287 WMSetButtonAltImage(panel
->raisB
[i
], icon
);
288 WMReleasePixmap(icon
);
290 wwarning(_("could not load icon file %s"), path
);
298 panel
->raisT
= WMCreateTextField(panel
->raisF
);
299 WMResizeWidget(panel
->raisT
, 36, 20);
300 WMMoveWidget(panel
->raisT
, 165, 28);
301 WMAddNotificationObserver(raiseTextChanged
, panel
, WMTextDidChangeNotification
, panel
->raisT
);
303 color
= WMDarkGrayColor(scr
);
304 font
= WMSystemFontOfSize(scr
, 10);
306 panel
->raisL
= WMCreateLabel(panel
->raisF
);
307 WMResizeWidget(panel
->raisL
, 36, 16);
308 WMMoveWidget(panel
->raisL
, 205, 32);
309 WMSetLabelText(panel
->raisL
, _("ms"));
310 WMSetLabelTextColor(panel
->raisL
, color
);
311 WMSetLabelFont(panel
->raisL
, font
);
313 WMReleaseColor(color
);
316 WMMapSubwidgets(panel
->raisF
);
318 /***************** Options ****************/
319 panel
->optF
= WMCreateFrame(panel
->box
);
320 WMResizeWidget(panel
->optF
, 245, 132);
321 WMMoveWidget(panel
->optF
, 265, 88);
323 panel
->ignB
= WMCreateSwitchButton(panel
->optF
);
324 WMResizeWidget(panel
->ignB
, 228, 50-2);
325 WMMoveWidget(panel
->ignB
, 10, 4);
326 WMSetButtonText(panel
->ignB
, _("Do not let applications receive the click used to focus windows"));
328 panel
->newB
= WMCreateSwitchButton(panel
->optF
);
329 WMResizeWidget(panel
->newB
, 228, 35);
330 WMMoveWidget(panel
->newB
, 10, 52);
331 WMSetButtonText(panel
->newB
, _("Automatically focus new windows"));
333 panel
->craisB
= WMCreateSwitchButton(panel
->optF
);
334 WMResizeWidget(panel
->craisB
, 228, 36);
335 WMMoveWidget(panel
->craisB
, 10, 87);
336 WMSetButtonText(panel
->craisB
, _("Raise window when switching focus with keyboard"));
338 WMMapSubwidgets(panel
->optF
);
340 WMRealizeWidget(panel
->box
);
341 WMMapSubwidgets(panel
->box
);
346 Panel
*InitFocus(WMWidget
*parent
)
350 panel
= wmalloc(sizeof(_Panel
));
352 panel
->sectionName
= _("Window Focus Preferences");
353 panel
->description
= _("Keyboard focus switching policy and related options.");
354 panel
->parent
= parent
;
356 panel
->callbacks
.createWidgets
= createPanel
;
357 panel
->callbacks
.updateDomain
= storeData
;
359 AddSection(panel
, ICON_FILE
);