Add checkpatch.pl, stolen from the linux kernel
[wmaker-crm.git] / WPrefs.app / Focus.c
blob3ee8ec94a0b78ac7b048558098cdda0cb14a001a
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;
50 WMButton *craisB;
52 char raiseDelaySelected;
53 } _Panel;
55 #define ICON_FILE "windowfocus"
57 #define DELAY_ICON "timer%i"
58 #define DELAY_ICON_S "timer%is"
60 static void showData(_Panel * panel)
62 char *str;
63 int i;
64 char buffer[32];
66 str = GetStringForKey("FocusMode");
67 if (!str)
68 str = "manual";
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);
74 else {
75 wwarning(_("bad option value %s for option FocusMode. Using default Manual"), str);
76 WMSetButtonSelected(panel->kfocB[0], 1);
79 /**/ str = GetStringForKey("ColormapMode");
80 if (!str)
81 str = "auto";
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);
86 } else {
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);
95 switch (i) {
96 case 0:
97 WMPerformButtonClick(panel->raisB[0]);
98 break;
99 case 10:
100 WMPerformButtonClick(panel->raisB[1]);
101 break;
102 case 100:
103 WMPerformButtonClick(panel->raisB[2]);
104 break;
105 case 350:
106 WMPerformButtonClick(panel->raisB[3]);
107 break;
108 case 800:
109 WMPerformButtonClick(panel->raisB[4]);
110 break;
113 /**/ WMSetButtonSelected(panel->ignB, GetBoolForKey("IgnoreFocusClick"));
115 WMSetButtonSelected(panel->newB, GetBoolForKey("AutoFocus"));
116 WMSetButtonSelected(panel->craisB, GetBoolForKey("CirculateRaise"));
119 static void storeData(_Panel * panel)
121 char *str;
122 int i;
124 if (WMGetButtonSelected(panel->kfocB[1]))
125 str = "sloppy";
126 else
127 str = "manual";
129 SetStringForKey(str, "FocusMode");
131 if (WMGetButtonSelected(panel->manB)) {
132 SetStringForKey("manual", "ColormapMode");
133 } else {
134 SetStringForKey("auto", "ColormapMode");
137 str = WMGetTextFieldText(panel->raisT);
138 if (sscanf(str, "%i", &i) != 1)
139 i = 0;
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;
168 int i;
170 /* Parameter not used, but tell the compiler that it is ok */
171 (void) notification;
173 if (panel->raiseDelaySelected) {
174 for (i = 0; i < 5; i++) {
175 WMSetButtonSelected(panel->raisB[i], False);
177 panel->raiseDelaySelected = 0;
181 static void createPanel(Panel * p)
183 _Panel *panel = (_Panel *) p;
184 WMScreen *scr = WMWidgetScreen(panel->parent);
185 int i;
186 char *buf1, *buf2;
187 WMPixmap *icon;
188 WMColor *color;
189 WMFont *font;
191 panel->box = WMCreateBox(panel->parent);
192 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
194 /***************** Input Focus Mode *****************/
195 panel->kfocF = WMCreateFrame(panel->box);
196 WMResizeWidget(panel->kfocF, 240, 125);
197 WMMoveWidget(panel->kfocF, 15, 10);
198 WMSetFrameTitle(panel->kfocF, _("Input Focus Mode"));
201 WMBox *box = WMCreateBox(panel->kfocF);
202 WMSetViewExpandsToParent(WMWidgetView(box), 10, 15, 10, 10);
203 WMSetBoxHorizontal(box, False);
205 panel->kfocB[0] = WMCreateRadioButton(box);
206 WMSetButtonText(panel->kfocB[0], _("Manual: Click on the window to set "
207 "keyboard input focus."));
208 WMAddBoxSubview(box, WMWidgetView(panel->kfocB[0]), True, True, 20, 0, 0);
210 panel->kfocB[1] = WMCreateRadioButton(box);
211 WMGroupButtons(panel->kfocB[0], panel->kfocB[1]);
212 WMSetButtonText(panel->kfocB[1], _("Auto: Set keyboard input focus to "
213 "the window under the mouse pointer."));
214 WMAddBoxSubview(box, WMWidgetView(panel->kfocB[1]), True, True, 20, 0, 0);
216 WMMapSubwidgets(box);
217 WMMapWidget(box);
220 /***************** Colormap Installation Mode ****************/
222 panel->cfocF = WMCreateFrame(panel->box);
223 WMResizeWidget(panel->cfocF, 240, 77);
224 WMMoveWidget(panel->cfocF, 15, 143);
225 WMSetFrameTitle(panel->cfocF, _("Install colormap in the window..."));
227 panel->manB = WMCreateRadioButton(panel->cfocF);
228 WMResizeWidget(panel->manB, 225, 20);
229 WMMoveWidget(panel->manB, 10, 20);
230 WMSetButtonText(panel->manB, _("...that has the input focus."));
232 panel->autB = WMCreateRadioButton(panel->cfocF);
233 WMResizeWidget(panel->autB, 225, 20);
234 WMMoveWidget(panel->autB, 10, 45);
235 WMSetButtonText(panel->autB, _("...that's under the mouse pointer."));
236 WMGroupButtons(panel->manB, panel->autB);
238 WMMapSubwidgets(panel->cfocF);
240 /***************** Automatic window raise delay *****************/
241 panel->raisF = WMCreateFrame(panel->box);
242 WMResizeWidget(panel->raisF, 245, 68);
243 WMMoveWidget(panel->raisF, 265, 10);
244 WMSetFrameTitle(panel->raisF, _("Automatic Window Raise Delay"));
246 buf1 = wmalloc(strlen(DELAY_ICON) + 1);
247 buf2 = wmalloc(strlen(DELAY_ICON_S) + 1);
249 for (i = 0; i < 5; i++) {
250 char *path;
252 panel->raisB[i] = WMCreateCustomButton(panel->raisF, WBBStateChangeMask);
253 WMResizeWidget(panel->raisB[i], 25, 25);
254 WMMoveWidget(panel->raisB[i], 12 + (30 * i), 25);
255 WMSetButtonBordered(panel->raisB[i], False);
256 WMSetButtonImagePosition(panel->raisB[i], WIPImageOnly);
257 WMSetButtonAction(panel->raisB[i], pushDelayButton, panel);
258 if (i > 0)
259 WMGroupButtons(panel->raisB[0], panel->raisB[i]);
260 sprintf(buf1, DELAY_ICON, i);
261 sprintf(buf2, DELAY_ICON_S, i);
262 path = LocateImage(buf1);
263 if (path) {
264 icon = WMCreatePixmapFromFile(scr, path);
265 if (icon) {
266 WMSetButtonImage(panel->raisB[i], icon);
267 WMReleasePixmap(icon);
268 } else {
269 wwarning(_("could not load icon file %s"), path);
271 wfree(path);
273 path = LocateImage(buf2);
274 if (path) {
275 icon = WMCreatePixmapFromFile(scr, path);
276 if (icon) {
277 WMSetButtonAltImage(panel->raisB[i], icon);
278 WMReleasePixmap(icon);
279 } else {
280 wwarning(_("could not load icon file %s"), path);
282 wfree(path);
285 wfree(buf1);
286 wfree(buf2);
288 panel->raisT = WMCreateTextField(panel->raisF);
289 WMResizeWidget(panel->raisT, 36, 20);
290 WMMoveWidget(panel->raisT, 165, 28);
291 WMAddNotificationObserver(raiseTextChanged, panel, WMTextDidChangeNotification, panel->raisT);
293 color = WMDarkGrayColor(scr);
294 font = WMSystemFontOfSize(scr, 10);
296 panel->raisL = WMCreateLabel(panel->raisF);
297 WMResizeWidget(panel->raisL, 36, 16);
298 WMMoveWidget(panel->raisL, 205, 32);
299 WMSetLabelText(panel->raisL, _("msec"));
300 WMSetLabelTextColor(panel->raisL, color);
301 WMSetLabelFont(panel->raisL, font);
303 WMReleaseColor(color);
304 WMReleaseFont(font);
306 WMMapSubwidgets(panel->raisF);
308 /***************** Options ****************/
309 panel->optF = WMCreateFrame(panel->box);
310 WMResizeWidget(panel->optF, 245, 132);
311 WMMoveWidget(panel->optF, 265, 88);
313 panel->ignB = WMCreateSwitchButton(panel->optF);
314 WMResizeWidget(panel->ignB, 225, 50);
315 WMMoveWidget(panel->ignB, 10, 4);
316 WMSetButtonText(panel->ignB, _("Do not let applications receive " "the click used to focus windows."));
318 panel->newB = WMCreateSwitchButton(panel->optF);
319 WMResizeWidget(panel->newB, 225, 35);
320 WMMoveWidget(panel->newB, 10, 49);
321 WMSetButtonText(panel->newB, _("Automatically focus new windows."));
323 panel->craisB = WMCreateSwitchButton(panel->optF);
324 WMResizeWidget(panel->craisB, 225, 36);
325 WMMoveWidget(panel->craisB, 10, 85);
326 WMSetButtonText(panel->craisB, _("Raise window when switching\nfocus with keyboard."));
328 WMMapSubwidgets(panel->optF);
330 WMRealizeWidget(panel->box);
331 WMMapSubwidgets(panel->box);
333 showData(panel);
336 Panel *InitFocus(WMWidget *parent)
338 _Panel *panel;
340 panel = wmalloc(sizeof(_Panel));
342 panel->sectionName = _("Window Focus Preferences");
343 panel->description = _("Keyboard focus switching policy and related options.");
344 panel->parent = parent;
346 panel->callbacks.createWidgets = createPanel;
347 panel->callbacks.updateDomain = storeData;
349 AddSection(panel, ICON_FILE);
351 return panel;