0.51.1 pre snapshot. Be careful, it may be buggy. It fixes some bugs though.
[wmaker-crm.git] / WPrefs.app / Focus.c
blob75aed5a233daff9cc00d88a0a6673d9df1b9d18d
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 CallbackRec callbacks;
33 WMWindow *win;
35 WMFrame *kfocF;
36 WMPopUpButton *kfocP;
37 WMLabel *kfocL;
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;
57 #define ICON_FILE "windowfocus"
59 #define DELAY_ICON "timer%i"
60 #define DELAY_ICON_S "timer%is"
62 static void changeFocusMode(WMWidget *w, void *data);
64 static void
65 showData(_Panel *panel)
67 char *str;
68 int i;
69 char buffer[32];
71 str = GetStringForKey("FocusMode");
72 if (!str)
73 str = "manual";
74 if (strcasecmp(str, "manual")==0 || strcasecmp(str, "clicktofocus")==0)
75 WMSetPopUpButtonSelectedItem(panel->kfocP, 0);
76 else if (strcasecmp(str, "auto")==0 || strcasecmp(str, "focusfollowsmouse")==0)
77 WMSetPopUpButtonSelectedItem(panel->kfocP, 1);
78 else if (strcasecmp(str, "semiauto")==0 || strcasecmp(str, "sloppy")==0)
79 WMSetPopUpButtonSelectedItem(panel->kfocP, 2);
80 else {
81 wwarning(_("bad option value %s for option FocusMode. Using default Manual"),
82 str);
83 WMSetPopUpButtonSelectedItem(panel->kfocP, 0);
85 changeFocusMode(panel->kfocP, panel);
87 /**/
88 str = GetStringForKey("ColormapMode");
89 if (!str)
90 str = "auto";
91 if (strcasecmp(str, "manual")==0 || strcasecmp(str, "clicktofocus")==0) {
92 WMPerformButtonClick(panel->manB);
93 } else if (strcasecmp(str, "auto")==0 || strcasecmp(str, "focusfollowsmouse")==0) {
94 WMPerformButtonClick(panel->autB);
95 } else {
96 wwarning(_("bad option value %s for option ColormapMode. Using default Auto"),
97 str);
98 WMPerformButtonClick(panel->manB);
101 /**/
102 i = GetIntegerForKey("RaiseDelay");
103 sprintf(buffer, "%i", i);
104 WMSetTextFieldText(panel->raisT, buffer);
106 switch (i) {
107 case 0:
108 WMPerformButtonClick(panel->raisB[0]);
109 break;
110 case 10:
111 WMPerformButtonClick(panel->raisB[1]);
112 break;
113 case 100:
114 WMPerformButtonClick(panel->raisB[2]);
115 break;
116 case 350:
117 WMPerformButtonClick(panel->raisB[3]);
118 break;
119 case 800:
120 WMPerformButtonClick(panel->raisB[4]);
121 break;
124 /**/
125 WMSetButtonSelected(panel->ignB, GetBoolForKey("IgnoreFocusClick"));
127 WMSetButtonSelected(panel->newB, GetBoolForKey("AutoFocus"));
132 static void
133 storeData(_Panel *panel)
135 char *str;
136 int i;
138 switch (WMGetPopUpButtonSelectedItem(panel->kfocP)) {
139 case 1:
140 str = "auto";
141 break;
142 case 2:
143 str = "sloppy";
144 break;
145 default:
146 str = "manual";
147 break;
149 SetStringForKey(str, "FocusMode");
151 if (WMGetButtonSelected(panel->manB)) {
152 SetStringForKey("manual", "ColormapMode");
153 } else {
154 SetStringForKey("auto", "ColormapMode");
157 str = WMGetTextFieldText(panel->raisT);
158 if (sscanf(str, "%i", &i)!=1)
159 i = 0;
160 SetIntegerForKey(i, "RaiseDelay");
162 SetBoolForKey(WMGetButtonSelected(panel->ignB), "IgnoreFocusClick");
163 SetBoolForKey(WMGetButtonSelected(panel->newB), "AutoFocus");
167 static void
168 pushDelayButton(WMWidget *w, void *data)
170 _Panel *panel = (_Panel*)data;
172 panel->raiseDelaySelected = 1;
173 if (w == panel->raisB[0]) {
174 WMSetTextFieldText(panel->raisT, "OFF");
175 } else if (w == panel->raisB[1]) {
176 WMSetTextFieldText(panel->raisT, "10");
177 } else if (w == panel->raisB[2]) {
178 WMSetTextFieldText(panel->raisT, "100");
179 } else if (w == panel->raisB[3]) {
180 WMSetTextFieldText(panel->raisT, "350");
181 } else if (w == panel->raisB[4]) {
182 WMSetTextFieldText(panel->raisT, "800");
187 static void
188 changeFocusMode(WMWidget *w, void *data)
190 _Panel *panel = (_Panel*)data;
192 switch (WMGetPopUpButtonSelectedItem(w)) {
193 case 0:
194 WMSetLabelText(panel->kfocL, _("Click on the window to set\n"\
195 "keyboard input focus."));
196 break;
197 case 1:
198 WMSetLabelText(panel->kfocL, _("Set keyboard input focus to\n"\
199 "the window under the mouse pointer,\n"\
200 "including the root window."));
201 break;
202 case 2:
203 WMSetLabelText(panel->kfocL, _("Set keyboard input focus to\n"\
204 "the window under the mouse pointer,\n"\
205 "except the root window."));
206 break;
211 static void
212 raiseTextChanged(void *observerData, WMNotification *notification)
214 _Panel *panel = (_Panel*)observerData;
215 int i;
217 if (panel->raiseDelaySelected) {
218 for (i=0; i<5; i++) {
219 WMSetButtonSelected(panel->raisB[i], False);
221 panel->raiseDelaySelected = 0;
228 static void
229 createPanel(Panel *p)
231 _Panel *panel = (_Panel*)p;
232 WMScreen *scr = WMWidgetScreen(panel->win);
233 int i;
234 char *buf1, *buf2;
235 WMPixmap *icon;
236 WMColor *color;
237 WMFont *font;
239 panel->frame = WMCreateFrame(panel->win);
240 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
241 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
243 /***************** Input Focus Mode *****************/
244 panel->kfocF = WMCreateFrame(panel->frame);
245 WMResizeWidget(panel->kfocF, 240, 130);
246 WMMoveWidget(panel->kfocF, 15, 15);
247 WMSetFrameTitle(panel->kfocF, _("Input Focus Mode"));
249 panel->kfocP = WMCreatePopUpButton(panel->kfocF);
250 WMResizeWidget(panel->kfocP, 210, 20);
251 WMMoveWidget(panel->kfocP, 15, 30);
252 WMAddPopUpButtonItem(panel->kfocP, _("Click window to focus"));
253 WMAddPopUpButtonItem(panel->kfocP, _("Focus follows mouse"));
254 WMAddPopUpButtonItem(panel->kfocP, _("\"Sloppy\" focus"));
255 WMSetPopUpButtonAction(panel->kfocP, changeFocusMode, panel);
257 panel->kfocL = WMCreateLabel(panel->kfocF);
258 WMResizeWidget(panel->kfocL, 211, 68);
259 WMMoveWidget(panel->kfocL, 15, 55);
260 WMSetLabelTextAlignment(panel->kfocL, WACenter);
262 WMMapSubwidgets(panel->kfocF);
264 /***************** Colormap Installation Mode ****************/
266 panel->cfocF = WMCreateFrame(panel->frame);
267 WMResizeWidget(panel->cfocF, 240, 70);
268 WMMoveWidget(panel->cfocF, 15, 150);
269 WMSetFrameTitle(panel->cfocF, _("Install colormap in the window..."));
271 panel->manB = WMCreateRadioButton(panel->cfocF);
272 WMResizeWidget(panel->manB, 220, 20);
273 WMMoveWidget(panel->manB, 15, 18);
274 WMSetButtonText(panel->manB, _("...that has the input focus."));
276 panel->autB = WMCreateRadioButton(panel->cfocF);
277 WMResizeWidget(panel->autB, 220, 20);
278 WMMoveWidget(panel->autB, 15, 40);
279 WMSetButtonText(panel->autB, _("...that is under the mouse pointer."));
280 WMGroupButtons(panel->manB, panel->autB);
282 WMMapSubwidgets(panel->cfocF);
284 /***************** Automatic window raise delay *****************/
285 panel->raisF = WMCreateFrame(panel->frame);
286 WMResizeWidget(panel->raisF, 245, 70);
287 WMMoveWidget(panel->raisF, 265, 15);
288 WMSetFrameTitle(panel->raisF, _("Automatic Window Raise Delay"));
290 buf1 = wmalloc(strlen(DELAY_ICON)+1);
291 buf2 = wmalloc(strlen(DELAY_ICON_S)+1);
293 for (i = 0; i < 5; i++) {
294 char *path;
296 panel->raisB[i] = WMCreateCustomButton(panel->raisF,
297 WBBStateChangeMask);
298 WMResizeWidget(panel->raisB[i], 25, 25);
299 WMMoveWidget(panel->raisB[i], 10+(30*i), 25);
300 WMSetButtonBordered(panel->raisB[i], False);
301 WMSetButtonImagePosition(panel->raisB[i], WIPImageOnly);
302 WMSetButtonAction(panel->raisB[i], pushDelayButton, panel);
303 if (i>0)
304 WMGroupButtons(panel->raisB[0], panel->raisB[i]);
305 sprintf(buf1, DELAY_ICON, i);
306 sprintf(buf2, DELAY_ICON_S, i);
307 path = LocateImage(buf1);
308 if (path) {
309 icon = WMCreatePixmapFromFile(scr, path);
310 if (icon) {
311 WMSetButtonImage(panel->raisB[i], icon);
312 WMReleasePixmap(icon);
313 } else {
314 wwarning(_("could not load icon file %s"), path);
316 free(path);
318 path = LocateImage(buf2);
319 if (path) {
320 icon = WMCreatePixmapFromFile(scr, path);
321 if (icon) {
322 WMSetButtonAltImage(panel->raisB[i], icon);
323 WMReleasePixmap(icon);
324 } else {
325 wwarning(_("could not load icon file %s"), path);
327 free(path);
330 free(buf1);
331 free(buf2);
333 panel->raisT = WMCreateTextField(panel->raisF);
334 WMResizeWidget(panel->raisT, 36, 20);
335 WMMoveWidget(panel->raisT, 165, 30);
336 WMAddNotificationObserver(raiseTextChanged, panel,
337 WMTextDidChangeNotification, panel->raisT);
339 color = WMDarkGrayColor(scr);
340 font = WMSystemFontOfSize(scr, 10);
342 panel->raisL = WMCreateLabel(panel->raisF);
343 WMResizeWidget(panel->raisL, 36, 16);
344 WMMoveWidget(panel->raisL, 205, 35);
345 WMSetLabelText(panel->raisL, _("msec"));
346 WMSetLabelTextColor(panel->raisL, color);
347 WMSetLabelFont(panel->raisL, font);
349 WMReleaseColor(color);
350 WMReleaseFont(font);
352 WMMapSubwidgets(panel->raisF);
354 /***************** Options ****************/
355 panel->optF = WMCreateFrame(panel->frame);
356 WMResizeWidget(panel->optF, 245, 125);
357 WMMoveWidget(panel->optF, 265, 95);
359 panel->ignB = WMCreateSwitchButton(panel->optF);
360 WMResizeWidget(panel->ignB, 210, 50);
361 WMMoveWidget(panel->ignB, 15, 10);
362 WMSetButtonText(panel->ignB, _("Do not let applications receive the "\
363 "click used to focus windows."));
365 panel->newB = WMCreateSwitchButton(panel->optF);
366 WMResizeWidget(panel->newB, 210, 35);
367 WMMoveWidget(panel->newB, 15, 70);
368 WMSetButtonText(panel->newB, _("Automatically focus new windows."));
370 WMMapSubwidgets(panel->optF);
373 WMRealizeWidget(panel->frame);
374 WMMapSubwidgets(panel->frame);
376 showData(panel);
381 Panel*
382 InitFocus(WMScreen *scr, WMWindow *win)
384 _Panel *panel;
386 panel = wmalloc(sizeof(_Panel));
387 memset(panel, 0, sizeof(_Panel));
389 panel->sectionName = _("Window Focus Preferences");
391 panel->win = win;
393 panel->callbacks.createWidgets = createPanel;
394 panel->callbacks.updateDomain = storeData;
396 AddSection(panel, ICON_FILE);
398 return panel;