Updating to version 0.20.2
[wmaker-crm.git] / WPrefs.app / Focus.c
blobdc51450dfd3e1384681ae45550253024c48f65e2
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 (strcasecmp(str, "manual")==0 || strcasecmp(str, "clicktofocus")==0)
73 WMSetPopUpButtonSelectedItem(panel->kfocP, 0);
74 else if (strcasecmp(str, "auto")==0 || strcasecmp(str, "focusfollowsmouse")==0)
75 WMSetPopUpButtonSelectedItem(panel->kfocP, 1);
76 else if (strcasecmp(str, "semiauto")==0 || strcasecmp(str, "sloppy")==0)
77 WMSetPopUpButtonSelectedItem(panel->kfocP, 2);
78 else {
79 wwarning(_("bad option value %s for option FocusMode. Using default Manual"),
80 str);
81 WMSetPopUpButtonSelectedItem(panel->kfocP, 0);
83 changeFocusMode(panel->kfocP, panel);
85 /**/
86 str = GetStringForKey("ColormapMode");
87 if (strcasecmp(str, "manual")==0 || strcasecmp(str, "clicktofocus")==0) {
88 WMPerformButtonClick(panel->manB);
89 } else if (strcasecmp(str, "auto")==0 || strcasecmp(str, "focusfollowsmouse")==0) {
90 WMPerformButtonClick(panel->autB);
91 } else {
92 wwarning(_("bad option value %s for option ColormapMode. Using default Manual"),
93 str);
94 WMPerformButtonClick(panel->manB);
97 /**/
98 i = GetIntegerForKey("RaiseDelay");
99 sprintf(buffer, "%i", i);
100 WMSetTextFieldText(panel->raisT, buffer);
102 switch (i) {
103 case 0:
104 WMPerformButtonClick(panel->raisB[0]);
105 break;
106 case 10:
107 WMPerformButtonClick(panel->raisB[1]);
108 break;
109 case 100:
110 WMPerformButtonClick(panel->raisB[2]);
111 break;
112 case 350:
113 WMPerformButtonClick(panel->raisB[3]);
114 break;
115 case 800:
116 WMPerformButtonClick(panel->raisB[4]);
117 break;
120 /**/
121 WMSetButtonSelected(panel->ignB, GetBoolForKey("IgnoreFocusClick"));
123 WMSetButtonSelected(panel->newB, GetBoolForKey("AutoFocus"));
128 static void
129 storeData(_Panel *panel)
131 char *str;
132 int i;
134 switch (WMGetPopUpButtonSelectedItem(panel->kfocP)) {
135 case 1:
136 str = "auto";
137 break;
138 case 2:
139 str = "sloppy";
140 break;
141 default:
142 str = "manual";
143 break;
145 SetStringForKey(str, "FocusMode");
147 if (WMGetButtonSelected(panel->manB)) {
148 SetStringForKey("manual", "ColormapMode");
149 } else {
150 SetStringForKey("auto", "ColormapMode");
153 str = WMGetTextFieldText(panel->raisT);
154 if (sscanf(str, "%i", &i)!=1)
155 i = 0;
156 SetIntegerForKey(i, "RaiseDelay");
158 SetBoolForKey(WMGetButtonSelected(panel->ignB), "IgnoreFocusClick");
159 SetBoolForKey(WMGetButtonSelected(panel->newB), "AutoFocus");
163 static void
164 pushDelayButton(WMWidget *w, void *data)
166 _Panel *panel = (_Panel*)data;
168 panel->raiseDelaySelected = 1;
169 if (w == panel->raisB[0]) {
170 WMSetTextFieldText(panel->raisT, "OFF");
171 } else if (w == panel->raisB[1]) {
172 WMSetTextFieldText(panel->raisT, "10");
173 } else if (w == panel->raisB[2]) {
174 WMSetTextFieldText(panel->raisT, "100");
175 } else if (w == panel->raisB[3]) {
176 WMSetTextFieldText(panel->raisT, "350");
177 } else if (w == panel->raisB[4]) {
178 WMSetTextFieldText(panel->raisT, "800");
183 static void
184 changeFocusMode(WMWidget *w, void *data)
186 _Panel *panel = (_Panel*)data;
188 switch (WMGetPopUpButtonSelectedItem(w)) {
189 case 0:
190 WMSetLabelText(panel->kfocL, _("Click on the window to set\n"\
191 "keyboard input focus."));
192 break;
193 case 1:
194 WMSetLabelText(panel->kfocL, _("Set keyboard input focus to\n"\
195 "the window under the mouse pointer,\n"\
196 "including the root window."));
197 break;
198 case 2:
199 WMSetLabelText(panel->kfocL, _("Set keyboard input focus to\n"\
200 "the window under the mouse pointer,\n"\
201 "except the root window."));
202 break;
207 static void
208 raiseTextChanged(void *observerData, WMNotification *notification)
210 _Panel *panel = (_Panel*)observerData;
211 int i;
213 if (panel->raiseDelaySelected) {
214 for (i=0; i<5; i++) {
215 WMSetButtonSelected(panel->raisB[i], False);
217 panel->raiseDelaySelected = 0;
224 static void
225 createPanel(Panel *p)
227 _Panel *panel = (_Panel*)p;
228 WMScreen *scr = WMWidgetScreen(panel->win);
229 int i;
230 char *buf1, *buf2;
231 WMPixmap *icon;
232 WMColor *color;
233 WMFont *font;
235 panel->frame = WMCreateFrame(panel->win);
236 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
237 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
239 /***************** Input Focus Mode *****************/
240 panel->kfocF = WMCreateFrame(panel->frame);
241 WMResizeWidget(panel->kfocF, 240, 130);
242 WMMoveWidget(panel->kfocF, 15, 15);
243 WMSetFrameTitle(panel->kfocF, _("Input Focus Mode"));
245 panel->kfocP = WMCreatePopUpButton(panel->kfocF);
246 WMResizeWidget(panel->kfocP, 210, 20);
247 WMMoveWidget(panel->kfocP, 15, 30);
248 WMAddPopUpButtonItem(panel->kfocP, _("Click window to focus"));
249 WMAddPopUpButtonItem(panel->kfocP, _("Focus follows mouse"));
250 WMAddPopUpButtonItem(panel->kfocP, _("\"Sloppy\" focus"));
251 WMSetPopUpButtonAction(panel->kfocP, changeFocusMode, panel);
253 panel->kfocL = WMCreateLabel(panel->kfocF);
254 WMResizeWidget(panel->kfocL, 211, 68);
255 WMMoveWidget(panel->kfocL, 15, 55);
256 WMSetLabelTextAlignment(panel->kfocL, WACenter);
258 WMMapSubwidgets(panel->kfocF);
260 /***************** Colormap Installation Mode ****************/
262 panel->cfocF = WMCreateFrame(panel->frame);
263 WMResizeWidget(panel->cfocF, 240, 70);
264 WMMoveWidget(panel->cfocF, 15, 150);
265 WMSetFrameTitle(panel->cfocF, _("Install colormap in the window..."));
267 panel->manB = WMCreateRadioButton(panel->cfocF);
268 WMResizeWidget(panel->manB, 220, 20);
269 WMMoveWidget(panel->manB, 15, 18);
270 WMSetButtonText(panel->manB, _("...that has the input focus."));
272 panel->autB = WMCreateRadioButton(panel->cfocF);
273 WMResizeWidget(panel->autB, 220, 20);
274 WMMoveWidget(panel->autB, 15, 40);
275 WMSetButtonText(panel->autB, _("...that is under the mouse pointer."));
276 WMGroupButtons(panel->manB, panel->autB);
278 WMMapSubwidgets(panel->cfocF);
280 /***************** Automatic window raise delay *****************/
281 panel->raisF = WMCreateFrame(panel->frame);
282 WMResizeWidget(panel->raisF, 245, 70);
283 WMMoveWidget(panel->raisF, 265, 15);
284 WMSetFrameTitle(panel->raisF, _("Automatic Window Raise Delay"));
286 buf1 = wmalloc(strlen(DELAY_ICON)+1);
287 buf2 = wmalloc(strlen(DELAY_ICON_S)+1);
289 for (i = 0; i < 5; i++) {
290 char *path;
292 panel->raisB[i] = WMCreateCustomButton(panel->raisF,
293 WBBStateChangeMask);
294 WMResizeWidget(panel->raisB[i], 25, 25);
295 WMMoveWidget(panel->raisB[i], 10+(30*i), 25);
296 WMSetButtonBordered(panel->raisB[i], False);
297 WMSetButtonImagePosition(panel->raisB[i], WIPImageOnly);
298 WMSetButtonAction(panel->raisB[i], pushDelayButton, panel);
299 if (i>0)
300 WMGroupButtons(panel->raisB[0], panel->raisB[i]);
301 sprintf(buf1, DELAY_ICON, i);
302 sprintf(buf2, DELAY_ICON_S, i);
303 path = LocateImage(buf1);
304 if (path) {
305 icon = WMCreatePixmapFromFile(scr, path);
306 if (icon) {
307 WMSetButtonImage(panel->raisB[i], icon);
308 WMReleasePixmap(icon);
309 } else {
310 wwarning(_("could not load icon file %s"), path);
312 free(path);
314 path = LocateImage(buf2);
315 if (path) {
316 icon = WMCreatePixmapFromFile(scr, path);
317 if (icon) {
318 WMSetButtonAltImage(panel->raisB[i], icon);
319 WMReleasePixmap(icon);
320 } else {
321 wwarning(_("could not load icon file %s"), path);
323 free(path);
326 free(buf1);
327 free(buf2);
329 panel->raisT = WMCreateTextField(panel->raisF);
330 WMResizeWidget(panel->raisT, 36, 20);
331 WMMoveWidget(panel->raisT, 165, 30);
332 WMAddNotificationObserver(raiseTextChanged, panel,
333 WMTextDidChangeNotification, panel->raisT);
335 color = WMDarkGrayColor(scr);
336 font = WMSystemFontOfSize(scr, 10);
338 panel->raisL = WMCreateLabel(panel->raisF);
339 WMResizeWidget(panel->raisL, 36, 16);
340 WMMoveWidget(panel->raisL, 205, 35);
341 WMSetLabelText(panel->raisL, _("msec"));
342 WMSetLabelTextColor(panel->raisL, color);
343 WMSetLabelFont(panel->raisL, font);
345 WMReleaseColor(color);
346 WMReleaseFont(font);
348 WMMapSubwidgets(panel->raisF);
350 /***************** Options ****************/
351 panel->optF = WMCreateFrame(panel->frame);
352 WMResizeWidget(panel->optF, 245, 125);
353 WMMoveWidget(panel->optF, 265, 95);
355 panel->ignB = WMCreateSwitchButton(panel->optF);
356 WMResizeWidget(panel->ignB, 210, 50);
357 WMMoveWidget(panel->ignB, 15, 10);
358 WMSetButtonText(panel->ignB, _("Do not let aplications receive the "\
359 "click used to focus windows."));
361 panel->newB = WMCreateSwitchButton(panel->optF);
362 WMResizeWidget(panel->newB, 210, 35);
363 WMMoveWidget(panel->newB, 15, 70);
364 WMSetButtonText(panel->newB, _("Automatically focus new windows."));
366 WMMapSubwidgets(panel->optF);
369 WMRealizeWidget(panel->frame);
370 WMMapSubwidgets(panel->frame);
372 showData(panel);
377 Panel*
378 InitFocus(WMScreen *scr, WMWindow *win)
380 _Panel *panel;
382 panel = wmalloc(sizeof(_Panel));
383 memset(panel, 0, sizeof(_Panel));
385 panel->sectionName = _("Window Focus Preferences");
387 panel->win = win;
389 panel->callbacks.createWidgets = createPanel;
390 panel->callbacks.updateDomain = storeData;
392 AddSection(panel, ICON_FILE);
394 return panel;