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
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
{
33 CallbackRec callbacks
;
53 char raiseDelaySelected
;
58 #define ICON_FILE "windowfocus"
60 #define DELAY_ICON "timer%i"
61 #define DELAY_ICON_S "timer%is"
65 showData(_Panel
*panel
)
71 str
= GetStringForKey("FocusMode");
74 if (strcasecmp(str
, "manual")==0 || strcasecmp(str
, "clicktofocus")==0)
75 WMSetButtonSelected(panel
->kfocB
[0], 1);
76 else if (strcasecmp(str
, "auto")==0 || strcasecmp(str
, "semiauto")==0
77 || strcasecmp(str
, "sloppy")==0)
78 WMSetButtonSelected(panel
->kfocB
[1], 1);
80 wwarning(_("bad option value %s for option FocusMode. Using default Manual"),
82 WMSetButtonSelected(panel
->kfocB
[0], 1);
86 str
= GetStringForKey("ColormapMode");
89 if (strcasecmp(str
, "manual")==0 || strcasecmp(str
, "clicktofocus")==0) {
90 WMPerformButtonClick(panel
->manB
);
91 } else if (strcasecmp(str
, "auto")==0 || strcasecmp(str
, "focusfollowsmouse")==0) {
92 WMPerformButtonClick(panel
->autB
);
94 wwarning(_("bad option value %s for option ColormapMode. Using default Auto"),
96 WMPerformButtonClick(panel
->manB
);
100 i
= GetIntegerForKey("RaiseDelay");
101 sprintf(buffer
, "%i", i
);
102 WMSetTextFieldText(panel
->raisT
, buffer
);
106 WMPerformButtonClick(panel
->raisB
[0]);
109 WMPerformButtonClick(panel
->raisB
[1]);
112 WMPerformButtonClick(panel
->raisB
[2]);
115 WMPerformButtonClick(panel
->raisB
[3]);
118 WMPerformButtonClick(panel
->raisB
[4]);
123 WMSetButtonSelected(panel
->ignB
, GetBoolForKey("IgnoreFocusClick"));
125 WMSetButtonSelected(panel
->newB
, GetBoolForKey("AutoFocus"));
131 storeData(_Panel
*panel
)
136 if (WMGetButtonSelected(panel
->kfocB
[1]))
141 SetStringForKey(str
, "FocusMode");
143 if (WMGetButtonSelected(panel
->manB
)) {
144 SetStringForKey("manual", "ColormapMode");
146 SetStringForKey("auto", "ColormapMode");
149 str
= WMGetTextFieldText(panel
->raisT
);
150 if (sscanf(str
, "%i", &i
)!=1)
152 SetIntegerForKey(i
, "RaiseDelay");
154 SetBoolForKey(WMGetButtonSelected(panel
->ignB
), "IgnoreFocusClick");
155 SetBoolForKey(WMGetButtonSelected(panel
->newB
), "AutoFocus");
160 pushDelayButton(WMWidget
*w
, void *data
)
162 _Panel
*panel
= (_Panel
*)data
;
164 panel
->raiseDelaySelected
= 1;
165 if (w
== panel
->raisB
[0]) {
166 WMSetTextFieldText(panel
->raisT
, "OFF");
167 } else if (w
== panel
->raisB
[1]) {
168 WMSetTextFieldText(panel
->raisT
, "10");
169 } else if (w
== panel
->raisB
[2]) {
170 WMSetTextFieldText(panel
->raisT
, "100");
171 } else if (w
== panel
->raisB
[3]) {
172 WMSetTextFieldText(panel
->raisT
, "350");
173 } else if (w
== panel
->raisB
[4]) {
174 WMSetTextFieldText(panel
->raisT
, "800");
180 raiseTextChanged(void *observerData
, WMNotification
*notification
)
182 _Panel
*panel
= (_Panel
*)observerData
;
185 if (panel
->raiseDelaySelected
) {
186 for (i
=0; i
<5; i
++) {
187 WMSetButtonSelected(panel
->raisB
[i
], False
);
189 panel
->raiseDelaySelected
= 0;
197 createPanel(Panel
*p
)
199 _Panel
*panel
= (_Panel
*)p
;
200 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
207 panel
->box
= WMCreateBox(panel
->parent
);
208 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
210 /***************** Input Focus Mode *****************/
211 panel
->kfocF
= WMCreateFrame(panel
->box
);
212 WMResizeWidget(panel
->kfocF
, 240, 130);
213 WMMoveWidget(panel
->kfocF
, 15, 15);
214 WMSetFrameTitle(panel
->kfocF
, _("Input Focus Mode"));
217 WMBox
*box
= WMCreateBox(panel
->kfocF
);
218 WMSetViewExpandsToParent(WMWidgetView(box
), 10, 15, 10, 10);
219 WMSetBoxHorizontal(box
, False
);
221 panel
->kfocB
[0] = WMCreateRadioButton(box
);
222 WMSetButtonText(panel
->kfocB
[0], _("Manual: Click on the window to set "\
223 "keyboard input focus."));
224 WMAddBoxSubview(box
, WMWidgetView(panel
->kfocB
[0]), True
, True
,
227 panel
->kfocB
[1] = WMCreateRadioButton(box
);
228 WMGroupButtons(panel
->kfocB
[0], panel
->kfocB
[1]);
229 WMSetButtonText(panel
->kfocB
[1], _("Auto: Set keyboard input focus to "\
230 "the window under the mouse pointer."));
231 WMAddBoxSubview(box
, WMWidgetView(panel
->kfocB
[1]), True
, True
,
234 WMMapSubwidgets(box
);
238 /***************** Colormap Installation Mode ****************/
240 panel
->cfocF
= WMCreateFrame(panel
->box
);
241 WMResizeWidget(panel
->cfocF
, 240, 70);
242 WMMoveWidget(panel
->cfocF
, 15, 150);
243 WMSetFrameTitle(panel
->cfocF
, _("Install colormap in the window..."));
245 panel
->manB
= WMCreateRadioButton(panel
->cfocF
);
246 WMResizeWidget(panel
->manB
, 225, 20);
247 WMMoveWidget(panel
->manB
, 10, 18);
248 WMSetButtonText(panel
->manB
, _("...that has the input focus."));
250 panel
->autB
= WMCreateRadioButton(panel
->cfocF
);
251 WMResizeWidget(panel
->autB
, 225, 20);
252 WMMoveWidget(panel
->autB
, 10, 43);
253 WMSetButtonText(panel
->autB
, _("...that's under the mouse pointer."));
254 WMGroupButtons(panel
->manB
, panel
->autB
);
256 WMMapSubwidgets(panel
->cfocF
);
258 /***************** Automatic window raise delay *****************/
259 panel
->raisF
= WMCreateFrame(panel
->box
);
260 WMResizeWidget(panel
->raisF
, 245, 70);
261 WMMoveWidget(panel
->raisF
, 265, 15);
262 WMSetFrameTitle(panel
->raisF
, _("Automatic Window Raise Delay"));
264 buf1
= wmalloc(strlen(DELAY_ICON
)+1);
265 buf2
= wmalloc(strlen(DELAY_ICON_S
)+1);
267 for (i
= 0; i
< 5; i
++) {
270 panel
->raisB
[i
] = WMCreateCustomButton(panel
->raisF
,
272 WMResizeWidget(panel
->raisB
[i
], 25, 25);
273 WMMoveWidget(panel
->raisB
[i
], 10+(30*i
), 25);
274 WMSetButtonBordered(panel
->raisB
[i
], False
);
275 WMSetButtonImagePosition(panel
->raisB
[i
], WIPImageOnly
);
276 WMSetButtonAction(panel
->raisB
[i
], pushDelayButton
, panel
);
278 WMGroupButtons(panel
->raisB
[0], panel
->raisB
[i
]);
279 sprintf(buf1
, DELAY_ICON
, i
);
280 sprintf(buf2
, DELAY_ICON_S
, i
);
281 path
= LocateImage(buf1
);
283 icon
= WMCreatePixmapFromFile(scr
, path
);
285 WMSetButtonImage(panel
->raisB
[i
], icon
);
286 WMReleasePixmap(icon
);
288 wwarning(_("could not load icon file %s"), path
);
292 path
= LocateImage(buf2
);
294 icon
= WMCreatePixmapFromFile(scr
, path
);
296 WMSetButtonAltImage(panel
->raisB
[i
], icon
);
297 WMReleasePixmap(icon
);
299 wwarning(_("could not load icon file %s"), path
);
307 panel
->raisT
= WMCreateTextField(panel
->raisF
);
308 WMResizeWidget(panel
->raisT
, 36, 20);
309 WMMoveWidget(panel
->raisT
, 165, 30);
310 WMAddNotificationObserver(raiseTextChanged
, panel
,
311 WMTextDidChangeNotification
, panel
->raisT
);
313 color
= WMDarkGrayColor(scr
);
314 font
= WMSystemFontOfSize(scr
, 10);
316 panel
->raisL
= WMCreateLabel(panel
->raisF
);
317 WMResizeWidget(panel
->raisL
, 36, 16);
318 WMMoveWidget(panel
->raisL
, 205, 35);
319 WMSetLabelText(panel
->raisL
, _("msec"));
320 WMSetLabelTextColor(panel
->raisL
, color
);
321 WMSetLabelFont(panel
->raisL
, font
);
323 WMReleaseColor(color
);
326 WMMapSubwidgets(panel
->raisF
);
328 /***************** Options ****************/
329 panel
->optF
= WMCreateFrame(panel
->box
);
330 WMResizeWidget(panel
->optF
, 245, 125);
331 WMMoveWidget(panel
->optF
, 265, 95);
333 panel
->ignB
= WMCreateSwitchButton(panel
->optF
);
334 WMResizeWidget(panel
->ignB
, 225, 50);
335 WMMoveWidget(panel
->ignB
, 10, 10);
336 WMSetButtonText(panel
->ignB
, _("Do not let applications receive "
337 "the click used to focus windows."));
339 panel
->newB
= WMCreateSwitchButton(panel
->optF
);
340 WMResizeWidget(panel
->newB
, 225, 35);
341 WMMoveWidget(panel
->newB
, 10, 70);
342 WMSetButtonText(panel
->newB
, _("Automatically focus new windows."));
344 WMMapSubwidgets(panel
->optF
);
347 WMRealizeWidget(panel
->box
);
348 WMMapSubwidgets(panel
->box
);
356 InitFocus(WMScreen
*scr
, WMWindow
*win
)
360 panel
= wmalloc(sizeof(_Panel
));
361 memset(panel
, 0, sizeof(_Panel
));
363 panel
->sectionName
= _("Window Focus Preferences");
365 panel
->description
= _("Keyboard focus switching policy, colormap switching\n"
366 "policy for 8bpp displays and other related options.");
370 panel
->callbacks
.createWidgets
= createPanel
;
371 panel
->callbacks
.updateDomain
= storeData
;
373 AddSection(panel
, ICON_FILE
);