8a37af5826d7a2e9a57ed62de6e0e17c8d124e1e
[wmaker-crm.git] / WPrefs.app / Focus.c
blob8a37af5826d7a2e9a57ed62de6e0e17c8d124e1e
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.
22 #include "WPrefs.h"
24 typedef struct _Panel {
25 WMBox *box;
27 char *sectionName;
29 char *description;
31 CallbackRec callbacks;
33 WMWidget *parent;
35 WMFrame *kfocF;
36 WMButton *kfocB[2];
38 WMFrame *cfocF;
39 WMButton *autB;
40 WMButton *manB;
42 WMFrame *raisF;
43 WMButton *raisB[5];
44 WMTextField *raisT;
45 WMLabel *raisL;
47 WMFrame *optF;
48 WMButton *ignB;
49 WMButton *newB;
51 char raiseDelaySelected;
52 } _Panel;
54 #define ICON_FILE "windowfocus"
56 #define DELAY_ICON "timer%i"
57 #define DELAY_ICON_S "timer%is"
59 static void showData(_Panel * panel)
61 char *str;
62 int i;
63 char buffer[32];
65 str = GetStringForKey("FocusMode");
66 if (!str)
67 str = "manual";
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);
73 else {
74 wwarning(_("bad option value %s for option FocusMode. Using default Manual"), str);
75 WMSetButtonSelected(panel->kfocB[0], 1);
78 /**/ str = GetStringForKey("ColormapMode");
79 if (!str)
80 str = "auto";
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);
85 } else {
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);
94 switch (i) {
95 case 0:
96 WMPerformButtonClick(panel->raisB[0]);
97 break;
98 case 10:
99 WMPerformButtonClick(panel->raisB[1]);
100 break;
101 case 100:
102 WMPerformButtonClick(panel->raisB[2]);
103 break;
104 case 350:
105 WMPerformButtonClick(panel->raisB[3]);
106 break;
107 case 800:
108 WMPerformButtonClick(panel->raisB[4]);
109 break;
112 /**/ WMSetButtonSelected(panel->ignB, GetBoolForKey("IgnoreFocusClick"));
114 WMSetButtonSelected(panel->newB, GetBoolForKey("AutoFocus"));
117 static void storeData(_Panel * panel)
119 char *str;
120 int i;
122 if (WMGetButtonSelected(panel->kfocB[1]))
123 str = "sloppy";
124 else
125 str = "manual";
127 SetStringForKey(str, "FocusMode");
129 if (WMGetButtonSelected(panel->manB)) {
130 SetStringForKey("manual", "ColormapMode");
131 } else {
132 SetStringForKey("auto", "ColormapMode");
135 str = WMGetTextFieldText(panel->raisT);
136 if (sscanf(str, "%i", &i) != 1)
137 i = 0;
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;
165 int i;
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);
179 int i;
180 char *buf1, *buf2;
181 WMPixmap *icon;
182 WMColor *color;
183 WMFont *font;
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);
211 WMMapWidget(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++) {
244 char *path;
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);
252 if (i > 0)
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);
257 if (path) {
258 icon = WMCreatePixmapFromFile(scr, path);
259 if (icon) {
260 WMSetButtonImage(panel->raisB[i], icon);
261 WMReleasePixmap(icon);
262 } else {
263 wwarning(_("could not load icon file %s"), path);
265 wfree(path);
267 path = LocateImage(buf2);
268 if (path) {
269 icon = WMCreatePixmapFromFile(scr, path);
270 if (icon) {
271 WMSetButtonAltImage(panel->raisB[i], icon);
272 WMReleasePixmap(icon);
273 } else {
274 wwarning(_("could not load icon file %s"), path);
276 wfree(path);
279 wfree(buf1);
280 wfree(buf2);
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);
298 WMReleaseFont(font);
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);
322 showData(panel);
325 Panel *InitFocus(WMScreen * scr, WMWindow * win)
327 _Panel *panel;
329 panel = wmalloc(sizeof(_Panel));
331 panel->sectionName = _("Window Focus Preferences");
332 panel->description = _("Keyboard focus switching policy and related options.");
333 panel->parent = win;
335 panel->callbacks.createWidgets = createPanel;
336 panel->callbacks.updateDomain = storeData;
338 AddSection(panel, ICON_FILE);
340 return panel;