Build-Depend on automake 1.11 or later.
[wmaker-crm.git] / WPrefs.app / Focus.c
blob9a5fa8d099de60185efd700fc8961aa50f3c8801
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,
20 * USA.
23 #include "WPrefs.h"
25 typedef struct _Panel {
26 WMBox *box;
28 char *sectionName;
30 char *description;
32 CallbackRec callbacks;
34 WMWidget *parent;
36 WMFrame *kfocF;
37 WMButton *kfocB[2];
39 WMFrame *cfocF;
40 WMButton *autB;
41 WMButton *manB;
43 WMFrame *raisF;
44 WMButton *raisB[5];
45 WMTextField *raisT;
46 WMLabel *raisL;
48 WMFrame *optF;
49 WMButton *ignB;
50 WMButton *newB;
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"));
118 static void storeData(_Panel * panel)
120 char *str;
121 int i;
123 if (WMGetButtonSelected(panel->kfocB[1]))
124 str = "sloppy";
125 else
126 str = "manual";
128 SetStringForKey(str, "FocusMode");
130 if (WMGetButtonSelected(panel->manB)) {
131 SetStringForKey("manual", "ColormapMode");
132 } else {
133 SetStringForKey("auto", "ColormapMode");
136 str = WMGetTextFieldText(panel->raisT);
137 if (sscanf(str, "%i", &i) != 1)
138 i = 0;
139 SetIntegerForKey(i, "RaiseDelay");
141 SetBoolForKey(WMGetButtonSelected(panel->ignB), "IgnoreFocusClick");
142 SetBoolForKey(WMGetButtonSelected(panel->newB), "AutoFocus");
145 static void pushDelayButton(WMWidget * w, void *data)
147 _Panel *panel = (_Panel *) data;
149 panel->raiseDelaySelected = 1;
150 if (w == panel->raisB[0]) {
151 WMSetTextFieldText(panel->raisT, "OFF");
152 } else if (w == panel->raisB[1]) {
153 WMSetTextFieldText(panel->raisT, "10");
154 } else if (w == panel->raisB[2]) {
155 WMSetTextFieldText(panel->raisT, "100");
156 } else if (w == panel->raisB[3]) {
157 WMSetTextFieldText(panel->raisT, "350");
158 } else if (w == panel->raisB[4]) {
159 WMSetTextFieldText(panel->raisT, "800");
163 static void raiseTextChanged(void *observerData, WMNotification * notification)
165 _Panel *panel = (_Panel *) observerData;
166 int i;
168 if (panel->raiseDelaySelected) {
169 for (i = 0; i < 5; i++) {
170 WMSetButtonSelected(panel->raisB[i], False);
172 panel->raiseDelaySelected = 0;
176 static void createPanel(Panel * p)
178 _Panel *panel = (_Panel *) p;
179 WMScreen *scr = WMWidgetScreen(panel->parent);
180 int i;
181 char *buf1, *buf2;
182 WMPixmap *icon;
183 WMColor *color;
184 WMFont *font;
186 panel->box = WMCreateBox(panel->parent);
187 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
189 /***************** Input Focus Mode *****************/
190 panel->kfocF = WMCreateFrame(panel->box);
191 WMResizeWidget(panel->kfocF, 240, 130);
192 WMMoveWidget(panel->kfocF, 15, 15);
193 WMSetFrameTitle(panel->kfocF, _("Input Focus Mode"));
196 WMBox *box = WMCreateBox(panel->kfocF);
197 WMSetViewExpandsToParent(WMWidgetView(box), 10, 15, 10, 10);
198 WMSetBoxHorizontal(box, False);
200 panel->kfocB[0] = WMCreateRadioButton(box);
201 WMSetButtonText(panel->kfocB[0], _("Manual: Click on the window to set "
202 "keyboard input focus."));
203 WMAddBoxSubview(box, WMWidgetView(panel->kfocB[0]), True, True, 20, 0, 0);
205 panel->kfocB[1] = WMCreateRadioButton(box);
206 WMGroupButtons(panel->kfocB[0], panel->kfocB[1]);
207 WMSetButtonText(panel->kfocB[1], _("Auto: Set keyboard input focus to "
208 "the window under the mouse pointer."));
209 WMAddBoxSubview(box, WMWidgetView(panel->kfocB[1]), True, True, 20, 0, 0);
211 WMMapSubwidgets(box);
212 WMMapWidget(box);
215 /***************** Colormap Installation Mode ****************/
217 panel->cfocF = WMCreateFrame(panel->box);
218 WMResizeWidget(panel->cfocF, 240, 70);
219 WMMoveWidget(panel->cfocF, 15, 150);
220 WMSetFrameTitle(panel->cfocF, _("Install colormap in the window..."));
222 panel->manB = WMCreateRadioButton(panel->cfocF);
223 WMResizeWidget(panel->manB, 225, 20);
224 WMMoveWidget(panel->manB, 10, 18);
225 WMSetButtonText(panel->manB, _("...that has the input focus."));
227 panel->autB = WMCreateRadioButton(panel->cfocF);
228 WMResizeWidget(panel->autB, 225, 20);
229 WMMoveWidget(panel->autB, 10, 43);
230 WMSetButtonText(panel->autB, _("...that's under the mouse pointer."));
231 WMGroupButtons(panel->manB, panel->autB);
233 WMMapSubwidgets(panel->cfocF);
235 /***************** Automatic window raise delay *****************/
236 panel->raisF = WMCreateFrame(panel->box);
237 WMResizeWidget(panel->raisF, 245, 70);
238 WMMoveWidget(panel->raisF, 265, 15);
239 WMSetFrameTitle(panel->raisF, _("Automatic Window Raise Delay"));
241 buf1 = wmalloc(strlen(DELAY_ICON) + 1);
242 buf2 = wmalloc(strlen(DELAY_ICON_S) + 1);
244 for (i = 0; i < 5; i++) {
245 char *path;
247 panel->raisB[i] = WMCreateCustomButton(panel->raisF, WBBStateChangeMask);
248 WMResizeWidget(panel->raisB[i], 25, 25);
249 WMMoveWidget(panel->raisB[i], 10 + (30 * i), 25);
250 WMSetButtonBordered(panel->raisB[i], False);
251 WMSetButtonImagePosition(panel->raisB[i], WIPImageOnly);
252 WMSetButtonAction(panel->raisB[i], pushDelayButton, panel);
253 if (i > 0)
254 WMGroupButtons(panel->raisB[0], panel->raisB[i]);
255 sprintf(buf1, DELAY_ICON, i);
256 sprintf(buf2, DELAY_ICON_S, i);
257 path = LocateImage(buf1);
258 if (path) {
259 icon = WMCreatePixmapFromFile(scr, path);
260 if (icon) {
261 WMSetButtonImage(panel->raisB[i], icon);
262 WMReleasePixmap(icon);
263 } else {
264 wwarning(_("could not load icon file %s"), path);
266 wfree(path);
268 path = LocateImage(buf2);
269 if (path) {
270 icon = WMCreatePixmapFromFile(scr, path);
271 if (icon) {
272 WMSetButtonAltImage(panel->raisB[i], icon);
273 WMReleasePixmap(icon);
274 } else {
275 wwarning(_("could not load icon file %s"), path);
277 wfree(path);
280 wfree(buf1);
281 wfree(buf2);
283 panel->raisT = WMCreateTextField(panel->raisF);
284 WMResizeWidget(panel->raisT, 36, 20);
285 WMMoveWidget(panel->raisT, 165, 30);
286 WMAddNotificationObserver(raiseTextChanged, panel, WMTextDidChangeNotification, panel->raisT);
288 color = WMDarkGrayColor(scr);
289 font = WMSystemFontOfSize(scr, 10);
291 panel->raisL = WMCreateLabel(panel->raisF);
292 WMResizeWidget(panel->raisL, 36, 16);
293 WMMoveWidget(panel->raisL, 205, 35);
294 WMSetLabelText(panel->raisL, _("msec"));
295 WMSetLabelTextColor(panel->raisL, color);
296 WMSetLabelFont(panel->raisL, font);
298 WMReleaseColor(color);
299 WMReleaseFont(font);
301 WMMapSubwidgets(panel->raisF);
303 /***************** Options ****************/
304 panel->optF = WMCreateFrame(panel->box);
305 WMResizeWidget(panel->optF, 245, 125);
306 WMMoveWidget(panel->optF, 265, 95);
308 panel->ignB = WMCreateSwitchButton(panel->optF);
309 WMResizeWidget(panel->ignB, 225, 50);
310 WMMoveWidget(panel->ignB, 10, 10);
311 WMSetButtonText(panel->ignB, _("Do not let applications receive " "the click used to focus windows."));
313 panel->newB = WMCreateSwitchButton(panel->optF);
314 WMResizeWidget(panel->newB, 225, 35);
315 WMMoveWidget(panel->newB, 10, 70);
316 WMSetButtonText(panel->newB, _("Automatically focus new windows."));
318 WMMapSubwidgets(panel->optF);
320 WMRealizeWidget(panel->box);
321 WMMapSubwidgets(panel->box);
323 showData(panel);
326 Panel *InitFocus(WMScreen * scr, WMWindow * win)
328 _Panel *panel;
330 panel = wmalloc(sizeof(_Panel));
331 memset(panel, 0, sizeof(_Panel));
333 panel->sectionName = _("Window Focus Preferences");
335 panel->description = _("Keyboard focus switching policy, colormap switching\n"
336 "policy for 8bpp displays and other related options.");
338 panel->parent = win;
340 panel->callbacks.createWidgets = createPanel;
341 panel->callbacks.updateDomain = storeData;
343 AddSection(panel, ICON_FILE);
345 return panel;