added sorting
[wmaker-crm.git] / WPrefs.app / Focus.c
bloba89658584d3fccb0ba35ea4485f76bf417bccc7f
1 /* Focus.c- input and colormap focus stuff
2 *
3 * WPrefs - Window Maker Preferences Program
4 *
5 * Copyright (c) 1998 Alfredo K. Kojima
6 *
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.
24 #include "WPrefs.h"
26 typedef struct _Panel {
27 WMFrame *frame;
29 char *sectionName;
31 char *description;
33 CallbackRec callbacks;
35 WMWindow *win;
37 WMFrame *kfocF;
38 WMPopUpButton *kfocP;
39 WMLabel *kfocL;
41 WMFrame *cfocF;
42 WMButton *autB;
43 WMButton *manB;
45 WMFrame *raisF;
46 WMButton *raisB[5];
47 WMTextField *raisT;
48 WMLabel *raisL;
50 WMFrame *optF;
51 WMButton *ignB;
52 WMButton *newB;
54 char raiseDelaySelected;
55 } _Panel;
59 #define ICON_FILE "windowfocus"
61 #define DELAY_ICON "timer%i"
62 #define DELAY_ICON_S "timer%is"
64 static void changeFocusMode(WMWidget *w, void *data);
66 static void
67 showData(_Panel *panel)
69 char *str;
70 int i;
71 char buffer[32];
73 str = GetStringForKey("FocusMode");
74 if (!str)
75 str = "manual";
76 if (strcasecmp(str, "manual")==0 || strcasecmp(str, "clicktofocus")==0)
77 WMSetPopUpButtonSelectedItem(panel->kfocP, 0);
78 else if (strcasecmp(str, "auto")==0 || strcasecmp(str, "focusfollowsmouse")==0)
79 WMSetPopUpButtonSelectedItem(panel->kfocP, 1);
80 else if (strcasecmp(str, "semiauto")==0 || strcasecmp(str, "sloppy")==0)
81 WMSetPopUpButtonSelectedItem(panel->kfocP, 2);
82 else {
83 wwarning(_("bad option value %s for option FocusMode. Using default Manual"),
84 str);
85 WMSetPopUpButtonSelectedItem(panel->kfocP, 0);
87 changeFocusMode(panel->kfocP, panel);
89 /**/
90 str = GetStringForKey("ColormapMode");
91 if (!str)
92 str = "auto";
93 if (strcasecmp(str, "manual")==0 || strcasecmp(str, "clicktofocus")==0) {
94 WMPerformButtonClick(panel->manB);
95 } else if (strcasecmp(str, "auto")==0 || strcasecmp(str, "focusfollowsmouse")==0) {
96 WMPerformButtonClick(panel->autB);
97 } else {
98 wwarning(_("bad option value %s for option ColormapMode. Using default Auto"),
99 str);
100 WMPerformButtonClick(panel->manB);
103 /**/
104 i = GetIntegerForKey("RaiseDelay");
105 sprintf(buffer, "%i", i);
106 WMSetTextFieldText(panel->raisT, buffer);
108 switch (i) {
109 case 0:
110 WMPerformButtonClick(panel->raisB[0]);
111 break;
112 case 10:
113 WMPerformButtonClick(panel->raisB[1]);
114 break;
115 case 100:
116 WMPerformButtonClick(panel->raisB[2]);
117 break;
118 case 350:
119 WMPerformButtonClick(panel->raisB[3]);
120 break;
121 case 800:
122 WMPerformButtonClick(panel->raisB[4]);
123 break;
126 /**/
127 WMSetButtonSelected(panel->ignB, GetBoolForKey("IgnoreFocusClick"));
129 WMSetButtonSelected(panel->newB, GetBoolForKey("AutoFocus"));
134 static void
135 storeData(_Panel *panel)
137 char *str;
138 int i;
140 switch (WMGetPopUpButtonSelectedItem(panel->kfocP)) {
141 case 1:
142 str = "auto";
143 break;
144 case 2:
145 str = "sloppy";
146 break;
147 default:
148 str = "manual";
149 break;
151 SetStringForKey(str, "FocusMode");
153 if (WMGetButtonSelected(panel->manB)) {
154 SetStringForKey("manual", "ColormapMode");
155 } else {
156 SetStringForKey("auto", "ColormapMode");
159 str = WMGetTextFieldText(panel->raisT);
160 if (sscanf(str, "%i", &i)!=1)
161 i = 0;
162 SetIntegerForKey(i, "RaiseDelay");
164 SetBoolForKey(WMGetButtonSelected(panel->ignB), "IgnoreFocusClick");
165 SetBoolForKey(WMGetButtonSelected(panel->newB), "AutoFocus");
169 static void
170 pushDelayButton(WMWidget *w, void *data)
172 _Panel *panel = (_Panel*)data;
174 panel->raiseDelaySelected = 1;
175 if (w == panel->raisB[0]) {
176 WMSetTextFieldText(panel->raisT, "OFF");
177 } else if (w == panel->raisB[1]) {
178 WMSetTextFieldText(panel->raisT, "10");
179 } else if (w == panel->raisB[2]) {
180 WMSetTextFieldText(panel->raisT, "100");
181 } else if (w == panel->raisB[3]) {
182 WMSetTextFieldText(panel->raisT, "350");
183 } else if (w == panel->raisB[4]) {
184 WMSetTextFieldText(panel->raisT, "800");
189 static void
190 changeFocusMode(WMWidget *w, void *data)
192 _Panel *panel = (_Panel*)data;
194 switch (WMGetPopUpButtonSelectedItem(w)) {
195 case 0:
196 WMSetLabelText(panel->kfocL, _("Click on the window to set\n"\
197 "keyboard input focus."));
198 break;
199 case 1:
200 WMSetLabelText(panel->kfocL, _("Set keyboard input focus to\n"\
201 "the window under the mouse pointer,\n"\
202 "including the root window."));
203 break;
204 case 2:
205 WMSetLabelText(panel->kfocL, _("Set keyboard input focus to\n"\
206 "the window under the mouse pointer,\n"\
207 "except the root window."));
208 break;
213 static void
214 raiseTextChanged(void *observerData, WMNotification *notification)
216 _Panel *panel = (_Panel*)observerData;
217 int i;
219 if (panel->raiseDelaySelected) {
220 for (i=0; i<5; i++) {
221 WMSetButtonSelected(panel->raisB[i], False);
223 panel->raiseDelaySelected = 0;
230 static void
231 createPanel(Panel *p)
233 _Panel *panel = (_Panel*)p;
234 WMScreen *scr = WMWidgetScreen(panel->win);
235 int i;
236 char *buf1, *buf2;
237 WMPixmap *icon;
238 WMColor *color;
239 WMFont *font;
241 panel->frame = WMCreateFrame(panel->win);
242 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
243 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
245 /***************** Input Focus Mode *****************/
246 panel->kfocF = WMCreateFrame(panel->frame);
247 WMResizeWidget(panel->kfocF, 240, 130);
248 WMMoveWidget(panel->kfocF, 15, 15);
249 WMSetFrameTitle(panel->kfocF, _("Input Focus Mode"));
251 panel->kfocP = WMCreatePopUpButton(panel->kfocF);
252 WMResizeWidget(panel->kfocP, 210, 20);
253 WMMoveWidget(panel->kfocP, 15, 30);
254 WMAddPopUpButtonItem(panel->kfocP, _("Click window to focus"));
255 WMAddPopUpButtonItem(panel->kfocP, _("Focus follows mouse"));
256 WMAddPopUpButtonItem(panel->kfocP, _("\"Sloppy\" focus"));
257 WMSetPopUpButtonAction(panel->kfocP, changeFocusMode, panel);
259 panel->kfocL = WMCreateLabel(panel->kfocF);
260 WMResizeWidget(panel->kfocL, 211, 68);
261 WMMoveWidget(panel->kfocL, 15, 55);
262 WMSetLabelTextAlignment(panel->kfocL, WACenter);
264 WMMapSubwidgets(panel->kfocF);
266 /***************** Colormap Installation Mode ****************/
268 panel->cfocF = WMCreateFrame(panel->frame);
269 WMResizeWidget(panel->cfocF, 240, 70);
270 WMMoveWidget(panel->cfocF, 15, 150);
271 WMSetFrameTitle(panel->cfocF, _("Install colormap in the window..."));
273 panel->manB = WMCreateRadioButton(panel->cfocF);
274 WMResizeWidget(panel->manB, 220, 20);
275 WMMoveWidget(panel->manB, 15, 18);
276 WMSetButtonText(panel->manB, _("...that has the input focus."));
278 panel->autB = WMCreateRadioButton(panel->cfocF);
279 WMResizeWidget(panel->autB, 220, 20);
280 WMMoveWidget(panel->autB, 15, 40);
281 WMSetButtonText(panel->autB, _("...that is under the mouse pointer."));
282 WMGroupButtons(panel->manB, panel->autB);
284 WMMapSubwidgets(panel->cfocF);
286 /***************** Automatic window raise delay *****************/
287 panel->raisF = WMCreateFrame(panel->frame);
288 WMResizeWidget(panel->raisF, 245, 70);
289 WMMoveWidget(panel->raisF, 265, 15);
290 WMSetFrameTitle(panel->raisF, _("Automatic Window Raise Delay"));
292 buf1 = wmalloc(strlen(DELAY_ICON)+1);
293 buf2 = wmalloc(strlen(DELAY_ICON_S)+1);
295 for (i = 0; i < 5; i++) {
296 char *path;
298 panel->raisB[i] = WMCreateCustomButton(panel->raisF,
299 WBBStateChangeMask);
300 WMResizeWidget(panel->raisB[i], 25, 25);
301 WMMoveWidget(panel->raisB[i], 10+(30*i), 25);
302 WMSetButtonBordered(panel->raisB[i], False);
303 WMSetButtonImagePosition(panel->raisB[i], WIPImageOnly);
304 WMSetButtonAction(panel->raisB[i], pushDelayButton, panel);
305 if (i>0)
306 WMGroupButtons(panel->raisB[0], panel->raisB[i]);
307 sprintf(buf1, DELAY_ICON, i);
308 sprintf(buf2, DELAY_ICON_S, i);
309 path = LocateImage(buf1);
310 if (path) {
311 icon = WMCreatePixmapFromFile(scr, path);
312 if (icon) {
313 WMSetButtonImage(panel->raisB[i], icon);
314 WMReleasePixmap(icon);
315 } else {
316 wwarning(_("could not load icon file %s"), path);
318 free(path);
320 path = LocateImage(buf2);
321 if (path) {
322 icon = WMCreatePixmapFromFile(scr, path);
323 if (icon) {
324 WMSetButtonAltImage(panel->raisB[i], icon);
325 WMReleasePixmap(icon);
326 } else {
327 wwarning(_("could not load icon file %s"), path);
329 free(path);
332 free(buf1);
333 free(buf2);
335 panel->raisT = WMCreateTextField(panel->raisF);
336 WMResizeWidget(panel->raisT, 36, 20);
337 WMMoveWidget(panel->raisT, 165, 30);
338 WMAddNotificationObserver(raiseTextChanged, panel,
339 WMTextDidChangeNotification, panel->raisT);
341 color = WMDarkGrayColor(scr);
342 font = WMSystemFontOfSize(scr, 10);
344 panel->raisL = WMCreateLabel(panel->raisF);
345 WMResizeWidget(panel->raisL, 36, 16);
346 WMMoveWidget(panel->raisL, 205, 35);
347 WMSetLabelText(panel->raisL, _("msec"));
348 WMSetLabelTextColor(panel->raisL, color);
349 WMSetLabelFont(panel->raisL, font);
351 WMReleaseColor(color);
352 WMReleaseFont(font);
354 WMMapSubwidgets(panel->raisF);
356 /***************** Options ****************/
357 panel->optF = WMCreateFrame(panel->frame);
358 WMResizeWidget(panel->optF, 245, 125);
359 WMMoveWidget(panel->optF, 265, 95);
361 panel->ignB = WMCreateSwitchButton(panel->optF);
362 WMResizeWidget(panel->ignB, 210, 50);
363 WMMoveWidget(panel->ignB, 15, 10);
364 WMSetButtonText(panel->ignB, _("Do not let applications receive the "\
365 "click used to focus windows."));
367 panel->newB = WMCreateSwitchButton(panel->optF);
368 WMResizeWidget(panel->newB, 210, 35);
369 WMMoveWidget(panel->newB, 15, 70);
370 WMSetButtonText(panel->newB, _("Automatically focus new windows."));
372 WMMapSubwidgets(panel->optF);
375 WMRealizeWidget(panel->frame);
376 WMMapSubwidgets(panel->frame);
378 showData(panel);
383 Panel*
384 InitFocus(WMScreen *scr, WMWindow *win)
386 _Panel *panel;
388 panel = wmalloc(sizeof(_Panel));
389 memset(panel, 0, sizeof(_Panel));
391 panel->sectionName = _("Window Focus Preferences");
393 panel->description = _("Keyboard focus switching policy, colormap switching\n"
394 "policy for 8bpp displays and other related options.");
396 panel->win = win;
398 panel->callbacks.createWidgets = createPanel;
399 panel->callbacks.updateDomain = storeData;
401 AddSection(panel, ICON_FILE);
403 return panel;