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
;
51 char raiseDelaySelected
;
54 #define ICON_FILE "windowfocus"
56 #define DELAY_ICON "timer%i"
57 #define DELAY_ICON_S "timer%is"
59 static void showData(_Panel
* panel
)
65 str
= GetStringForKey("FocusMode");
68 if (strcasecmp(str
, "manual") == 0 || strcasecmp(str
, "clicktofocus") == 0)
69 WMSetButtonSelected(panel
->kfocB
[0], 1);
70 else if (strcasecmp(str
, "auto") == 0 || strcasecmp(str
, "semiauto") == 0
71 || strcasecmp(str
, "sloppy") == 0)
72 WMSetButtonSelected(panel
->kfocB
[1], 1);
74 wwarning(_("bad option value %s for option FocusMode. Using default Manual"), str
);
75 WMSetButtonSelected(panel
->kfocB
[0], 1);
78 /**/ str
= GetStringForKey("ColormapMode");
81 if (strcasecmp(str
, "manual") == 0 || strcasecmp(str
, "clicktofocus") == 0) {
82 WMPerformButtonClick(panel
->manB
);
83 } else if (strcasecmp(str
, "auto") == 0 || strcasecmp(str
, "focusfollowsmouse") == 0) {
84 WMPerformButtonClick(panel
->autB
);
86 wwarning(_("bad option value %s for option ColormapMode. Using default Auto"), str
);
87 WMPerformButtonClick(panel
->manB
);
90 /**/ i
= GetIntegerForKey("RaiseDelay");
91 sprintf(buffer
, "%i", i
);
92 WMSetTextFieldText(panel
->raisT
, buffer
);
96 WMPerformButtonClick(panel
->raisB
[0]);
99 WMPerformButtonClick(panel
->raisB
[1]);
102 WMPerformButtonClick(panel
->raisB
[2]);
105 WMPerformButtonClick(panel
->raisB
[3]);
108 WMPerformButtonClick(panel
->raisB
[4]);
112 /**/ WMSetButtonSelected(panel
->ignB
, GetBoolForKey("IgnoreFocusClick"));
114 WMSetButtonSelected(panel
->newB
, GetBoolForKey("AutoFocus"));
117 static void storeData(_Panel
* panel
)
122 if (WMGetButtonSelected(panel
->kfocB
[1]))
127 SetStringForKey(str
, "FocusMode");
129 if (WMGetButtonSelected(panel
->manB
)) {
130 SetStringForKey("manual", "ColormapMode");
132 SetStringForKey("auto", "ColormapMode");
135 str
= WMGetTextFieldText(panel
->raisT
);
136 if (sscanf(str
, "%i", &i
) != 1)
138 SetIntegerForKey(i
, "RaiseDelay");
140 SetBoolForKey(WMGetButtonSelected(panel
->ignB
), "IgnoreFocusClick");
141 SetBoolForKey(WMGetButtonSelected(panel
->newB
), "AutoFocus");
144 static void pushDelayButton(WMWidget
* w
, void *data
)
146 _Panel
*panel
= (_Panel
*) data
;
148 panel
->raiseDelaySelected
= 1;
149 if (w
== panel
->raisB
[0]) {
150 WMSetTextFieldText(panel
->raisT
, "OFF");
151 } else if (w
== panel
->raisB
[1]) {
152 WMSetTextFieldText(panel
->raisT
, "10");
153 } else if (w
== panel
->raisB
[2]) {
154 WMSetTextFieldText(panel
->raisT
, "100");
155 } else if (w
== panel
->raisB
[3]) {
156 WMSetTextFieldText(panel
->raisT
, "350");
157 } else if (w
== panel
->raisB
[4]) {
158 WMSetTextFieldText(panel
->raisT
, "800");
162 static void raiseTextChanged(void *observerData
, WMNotification
* notification
)
164 _Panel
*panel
= (_Panel
*) observerData
;
167 if (panel
->raiseDelaySelected
) {
168 for (i
= 0; i
< 5; i
++) {
169 WMSetButtonSelected(panel
->raisB
[i
], False
);
171 panel
->raiseDelaySelected
= 0;
175 static void createPanel(Panel
* p
)
177 _Panel
*panel
= (_Panel
*) p
;
178 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
185 panel
->box
= WMCreateBox(panel
->parent
);
186 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
188 /***************** Input Focus Mode *****************/
189 panel
->kfocF
= WMCreateFrame(panel
->box
);
190 WMResizeWidget(panel
->kfocF
, 240, 130);
191 WMMoveWidget(panel
->kfocF
, 15, 15);
192 WMSetFrameTitle(panel
->kfocF
, _("Input Focus Mode"));
195 WMBox
*box
= WMCreateBox(panel
->kfocF
);
196 WMSetViewExpandsToParent(WMWidgetView(box
), 10, 15, 10, 10);
197 WMSetBoxHorizontal(box
, False
);
199 panel
->kfocB
[0] = WMCreateRadioButton(box
);
200 WMSetButtonText(panel
->kfocB
[0], _("Manual: Click on the window to set "
201 "keyboard input focus."));
202 WMAddBoxSubview(box
, WMWidgetView(panel
->kfocB
[0]), True
, True
, 20, 0, 0);
204 panel
->kfocB
[1] = WMCreateRadioButton(box
);
205 WMGroupButtons(panel
->kfocB
[0], panel
->kfocB
[1]);
206 WMSetButtonText(panel
->kfocB
[1], _("Auto: Set keyboard input focus to "
207 "the window under the mouse pointer."));
208 WMAddBoxSubview(box
, WMWidgetView(panel
->kfocB
[1]), True
, True
, 20, 0, 0);
210 WMMapSubwidgets(box
);
214 /***************** Colormap Installation Mode ****************/
216 panel
->cfocF
= WMCreateFrame(panel
->box
);
217 WMResizeWidget(panel
->cfocF
, 240, 70);
218 WMMoveWidget(panel
->cfocF
, 15, 150);
219 WMSetFrameTitle(panel
->cfocF
, _("Install colormap in the window..."));
221 panel
->manB
= WMCreateRadioButton(panel
->cfocF
);
222 WMResizeWidget(panel
->manB
, 225, 20);
223 WMMoveWidget(panel
->manB
, 10, 18);
224 WMSetButtonText(panel
->manB
, _("...that has the input focus."));
226 panel
->autB
= WMCreateRadioButton(panel
->cfocF
);
227 WMResizeWidget(panel
->autB
, 225, 20);
228 WMMoveWidget(panel
->autB
, 10, 43);
229 WMSetButtonText(panel
->autB
, _("...that's under the mouse pointer."));
230 WMGroupButtons(panel
->manB
, panel
->autB
);
232 WMMapSubwidgets(panel
->cfocF
);
234 /***************** Automatic window raise delay *****************/
235 panel
->raisF
= WMCreateFrame(panel
->box
);
236 WMResizeWidget(panel
->raisF
, 245, 70);
237 WMMoveWidget(panel
->raisF
, 265, 15);
238 WMSetFrameTitle(panel
->raisF
, _("Automatic Window Raise Delay"));
240 buf1
= wmalloc(strlen(DELAY_ICON
) + 1);
241 buf2
= wmalloc(strlen(DELAY_ICON_S
) + 1);
243 for (i
= 0; i
< 5; i
++) {
246 panel
->raisB
[i
] = WMCreateCustomButton(panel
->raisF
, WBBStateChangeMask
);
247 WMResizeWidget(panel
->raisB
[i
], 25, 25);
248 WMMoveWidget(panel
->raisB
[i
], 10 + (30 * i
), 25);
249 WMSetButtonBordered(panel
->raisB
[i
], False
);
250 WMSetButtonImagePosition(panel
->raisB
[i
], WIPImageOnly
);
251 WMSetButtonAction(panel
->raisB
[i
], pushDelayButton
, panel
);
253 WMGroupButtons(panel
->raisB
[0], panel
->raisB
[i
]);
254 sprintf(buf1
, DELAY_ICON
, i
);
255 sprintf(buf2
, DELAY_ICON_S
, i
);
256 path
= LocateImage(buf1
);
258 icon
= WMCreatePixmapFromFile(scr
, path
);
260 WMSetButtonImage(panel
->raisB
[i
], icon
);
261 WMReleasePixmap(icon
);
263 wwarning(_("could not load icon file %s"), path
);
267 path
= LocateImage(buf2
);
269 icon
= WMCreatePixmapFromFile(scr
, path
);
271 WMSetButtonAltImage(panel
->raisB
[i
], icon
);
272 WMReleasePixmap(icon
);
274 wwarning(_("could not load icon file %s"), path
);
282 panel
->raisT
= WMCreateTextField(panel
->raisF
);
283 WMResizeWidget(panel
->raisT
, 36, 20);
284 WMMoveWidget(panel
->raisT
, 165, 30);
285 WMAddNotificationObserver(raiseTextChanged
, panel
, WMTextDidChangeNotification
, panel
->raisT
);
287 color
= WMDarkGrayColor(scr
);
288 font
= WMSystemFontOfSize(scr
, 10);
290 panel
->raisL
= WMCreateLabel(panel
->raisF
);
291 WMResizeWidget(panel
->raisL
, 36, 16);
292 WMMoveWidget(panel
->raisL
, 205, 35);
293 WMSetLabelText(panel
->raisL
, _("msec"));
294 WMSetLabelTextColor(panel
->raisL
, color
);
295 WMSetLabelFont(panel
->raisL
, font
);
297 WMReleaseColor(color
);
300 WMMapSubwidgets(panel
->raisF
);
302 /***************** Options ****************/
303 panel
->optF
= WMCreateFrame(panel
->box
);
304 WMResizeWidget(panel
->optF
, 245, 125);
305 WMMoveWidget(panel
->optF
, 265, 95);
307 panel
->ignB
= WMCreateSwitchButton(panel
->optF
);
308 WMResizeWidget(panel
->ignB
, 225, 50);
309 WMMoveWidget(panel
->ignB
, 10, 10);
310 WMSetButtonText(panel
->ignB
, _("Do not let applications receive " "the click used to focus windows."));
312 panel
->newB
= WMCreateSwitchButton(panel
->optF
);
313 WMResizeWidget(panel
->newB
, 225, 35);
314 WMMoveWidget(panel
->newB
, 10, 70);
315 WMSetButtonText(panel
->newB
, _("Automatically focus new windows."));
317 WMMapSubwidgets(panel
->optF
);
319 WMRealizeWidget(panel
->box
);
320 WMMapSubwidgets(panel
->box
);
325 Panel
*InitFocus(WMScreen
* scr
, WMWindow
* win
)
329 panel
= wmalloc(sizeof(_Panel
));
331 panel
->sectionName
= _("Window Focus Preferences");
332 panel
->description
= _("Keyboard focus switching policy and related options.");
335 panel
->callbacks
.createWidgets
= createPanel
;
336 panel
->callbacks
.updateDomain
= storeData
;
338 AddSection(panel
, ICON_FILE
);