- Check whether libXft is at least version 2.1.2 else refuse to compile.
[wmaker-crm.git] / WPrefs.app / Focus.c
blob3fbf1cda6dcb189df79eb481674a37c37bb4281a
1 /* Focus.c- input and colormap focus stuff
2 *
3 * WPrefs - Window Maker Preferences Program
4 *
5 * Copyright (c) 1998-2003 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 WMBox *box;
29 char *sectionName;
31 char *description;
33 CallbackRec callbacks;
35 WMWidget *parent;
37 WMFrame *kfocF;
38 WMButton *kfocB[2];
40 WMFrame *cfocF;
41 WMButton *autB;
42 WMButton *manB;
44 WMFrame *raisF;
45 WMButton *raisB[5];
46 WMTextField *raisT;
47 WMLabel *raisL;
49 WMFrame *optF;
50 WMButton *ignB;
51 WMButton *newB;
53 char raiseDelaySelected;
54 } _Panel;
58 #define ICON_FILE "windowfocus"
60 #define DELAY_ICON "timer%i"
61 #define DELAY_ICON_S "timer%is"
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 WMSetButtonSelected(panel->kfocB[0], 1);
76 else if (strcasecmp(str, "auto")==0 || strcasecmp(str, "semiauto")==0
77 || strcasecmp(str, "sloppy")==0)
78 WMSetButtonSelected(panel->kfocB[1], 1);
79 else {
80 wwarning(_("bad option value %s for option FocusMode. Using default Manual"),
81 str);
82 WMSetButtonSelected(panel->kfocB[0], 1);
85 /**/
86 str = GetStringForKey("ColormapMode");
87 if (!str)
88 str = "auto";
89 if (strcasecmp(str, "manual")==0 || strcasecmp(str, "clicktofocus")==0) {
90 WMPerformButtonClick(panel->manB);
91 } else if (strcasecmp(str, "auto")==0 || strcasecmp(str, "focusfollowsmouse")==0) {
92 WMPerformButtonClick(panel->autB);
93 } else {
94 wwarning(_("bad option value %s for option ColormapMode. Using default Auto"),
95 str);
96 WMPerformButtonClick(panel->manB);
99 /**/
100 i = GetIntegerForKey("RaiseDelay");
101 sprintf(buffer, "%i", i);
102 WMSetTextFieldText(panel->raisT, buffer);
104 switch (i) {
105 case 0:
106 WMPerformButtonClick(panel->raisB[0]);
107 break;
108 case 10:
109 WMPerformButtonClick(panel->raisB[1]);
110 break;
111 case 100:
112 WMPerformButtonClick(panel->raisB[2]);
113 break;
114 case 350:
115 WMPerformButtonClick(panel->raisB[3]);
116 break;
117 case 800:
118 WMPerformButtonClick(panel->raisB[4]);
119 break;
122 /**/
123 WMSetButtonSelected(panel->ignB, GetBoolForKey("IgnoreFocusClick"));
125 WMSetButtonSelected(panel->newB, GetBoolForKey("AutoFocus"));
130 static void
131 storeData(_Panel *panel)
133 char *str;
134 int i;
136 if (WMGetButtonSelected(panel->kfocB[1]))
137 str = "sloppy";
138 else
139 str = "manual";
141 SetStringForKey(str, "FocusMode");
143 if (WMGetButtonSelected(panel->manB)) {
144 SetStringForKey("manual", "ColormapMode");
145 } else {
146 SetStringForKey("auto", "ColormapMode");
149 str = WMGetTextFieldText(panel->raisT);
150 if (sscanf(str, "%i", &i)!=1)
151 i = 0;
152 SetIntegerForKey(i, "RaiseDelay");
154 SetBoolForKey(WMGetButtonSelected(panel->ignB), "IgnoreFocusClick");
155 SetBoolForKey(WMGetButtonSelected(panel->newB), "AutoFocus");
159 static void
160 pushDelayButton(WMWidget *w, void *data)
162 _Panel *panel = (_Panel*)data;
164 panel->raiseDelaySelected = 1;
165 if (w == panel->raisB[0]) {
166 WMSetTextFieldText(panel->raisT, "OFF");
167 } else if (w == panel->raisB[1]) {
168 WMSetTextFieldText(panel->raisT, "10");
169 } else if (w == panel->raisB[2]) {
170 WMSetTextFieldText(panel->raisT, "100");
171 } else if (w == panel->raisB[3]) {
172 WMSetTextFieldText(panel->raisT, "350");
173 } else if (w == panel->raisB[4]) {
174 WMSetTextFieldText(panel->raisT, "800");
179 static void
180 raiseTextChanged(void *observerData, WMNotification *notification)
182 _Panel *panel = (_Panel*)observerData;
183 int i;
185 if (panel->raiseDelaySelected) {
186 for (i=0; i<5; i++) {
187 WMSetButtonSelected(panel->raisB[i], False);
189 panel->raiseDelaySelected = 0;
196 static void
197 createPanel(Panel *p)
199 _Panel *panel = (_Panel*)p;
200 WMScreen *scr = WMWidgetScreen(panel->parent);
201 int i;
202 char *buf1, *buf2;
203 WMPixmap *icon;
204 WMColor *color;
205 WMFont *font;
207 panel->box = WMCreateBox(panel->parent);
208 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
210 /***************** Input Focus Mode *****************/
211 panel->kfocF = WMCreateFrame(panel->box);
212 WMResizeWidget(panel->kfocF, 240, 130);
213 WMMoveWidget(panel->kfocF, 15, 15);
214 WMSetFrameTitle(panel->kfocF, _("Input Focus Mode"));
217 WMBox *box = WMCreateBox(panel->kfocF);
218 WMSetViewExpandsToParent(WMWidgetView(box), 10, 15, 10, 10);
219 WMSetBoxHorizontal(box, False);
221 panel->kfocB[0] = WMCreateRadioButton(box);
222 WMSetButtonText(panel->kfocB[0], _("Manual: Click on the window to set "\
223 "keyboard input focus"));
224 WMAddBoxSubview(box, WMWidgetView(panel->kfocB[0]), True, True,
225 20, 0, 0);
227 panel->kfocB[1] = WMCreateRadioButton(box);
228 WMGroupButtons(panel->kfocB[0], panel->kfocB[1]);
229 WMSetButtonText(panel->kfocB[1], _("Auto: Set keyboard input focus to "\
230 "the window under the mouse pointer"));
231 WMAddBoxSubview(box, WMWidgetView(panel->kfocB[1]), True, True,
232 20, 0, 0);
234 WMMapSubwidgets(box);
235 WMMapWidget(box);
238 /***************** Colormap Installation Mode ****************/
240 panel->cfocF = WMCreateFrame(panel->box);
241 WMResizeWidget(panel->cfocF, 240, 70);
242 WMMoveWidget(panel->cfocF, 15, 150);
243 WMSetFrameTitle(panel->cfocF, _("Install colormap in the window..."));
245 panel->manB = WMCreateRadioButton(panel->cfocF);
246 WMResizeWidget(panel->manB, 225, 20);
247 WMMoveWidget(panel->manB, 10, 18);
248 WMSetButtonText(panel->manB, _("...that has the input focus."));
250 panel->autB = WMCreateRadioButton(panel->cfocF);
251 WMResizeWidget(panel->autB, 225, 20);
252 WMMoveWidget(panel->autB, 10, 43);
253 WMSetButtonText(panel->autB, _("...that is under the mouse pointer."));
254 WMGroupButtons(panel->manB, panel->autB);
256 WMMapSubwidgets(panel->cfocF);
258 /***************** Automatic window raise delay *****************/
259 panel->raisF = WMCreateFrame(panel->box);
260 WMResizeWidget(panel->raisF, 245, 70);
261 WMMoveWidget(panel->raisF, 265, 15);
262 WMSetFrameTitle(panel->raisF, _("Automatic Window Raise Delay"));
264 buf1 = wmalloc(strlen(DELAY_ICON)+1);
265 buf2 = wmalloc(strlen(DELAY_ICON_S)+1);
267 for (i = 0; i < 5; i++) {
268 char *path;
270 panel->raisB[i] = WMCreateCustomButton(panel->raisF,
271 WBBStateChangeMask);
272 WMResizeWidget(panel->raisB[i], 25, 25);
273 WMMoveWidget(panel->raisB[i], 10+(30*i), 25);
274 WMSetButtonBordered(panel->raisB[i], False);
275 WMSetButtonImagePosition(panel->raisB[i], WIPImageOnly);
276 WMSetButtonAction(panel->raisB[i], pushDelayButton, panel);
277 if (i>0)
278 WMGroupButtons(panel->raisB[0], panel->raisB[i]);
279 sprintf(buf1, DELAY_ICON, i);
280 sprintf(buf2, DELAY_ICON_S, i);
281 path = LocateImage(buf1);
282 if (path) {
283 icon = WMCreatePixmapFromFile(scr, path);
284 if (icon) {
285 WMSetButtonImage(panel->raisB[i], icon);
286 WMReleasePixmap(icon);
287 } else {
288 wwarning(_("could not load icon file %s"), path);
290 wfree(path);
292 path = LocateImage(buf2);
293 if (path) {
294 icon = WMCreatePixmapFromFile(scr, path);
295 if (icon) {
296 WMSetButtonAltImage(panel->raisB[i], icon);
297 WMReleasePixmap(icon);
298 } else {
299 wwarning(_("could not load icon file %s"), path);
301 wfree(path);
304 wfree(buf1);
305 wfree(buf2);
307 panel->raisT = WMCreateTextField(panel->raisF);
308 WMResizeWidget(panel->raisT, 36, 20);
309 WMMoveWidget(panel->raisT, 165, 30);
310 WMAddNotificationObserver(raiseTextChanged, panel,
311 WMTextDidChangeNotification, panel->raisT);
313 color = WMDarkGrayColor(scr);
314 font = WMSystemFontOfSize(scr, 10);
316 panel->raisL = WMCreateLabel(panel->raisF);
317 WMResizeWidget(panel->raisL, 36, 16);
318 WMMoveWidget(panel->raisL, 205, 35);
319 WMSetLabelText(panel->raisL, _("msec"));
320 WMSetLabelTextColor(panel->raisL, color);
321 WMSetLabelFont(panel->raisL, font);
323 WMReleaseColor(color);
324 WMReleaseFont(font);
326 WMMapSubwidgets(panel->raisF);
328 /***************** Options ****************/
329 panel->optF = WMCreateFrame(panel->box);
330 WMResizeWidget(panel->optF, 245, 125);
331 WMMoveWidget(panel->optF, 265, 95);
333 panel->ignB = WMCreateSwitchButton(panel->optF);
334 WMResizeWidget(panel->ignB, 225, 50);
335 WMMoveWidget(panel->ignB, 10, 10);
336 WMSetButtonText(panel->ignB, _("Do not let applications receive "
337 "the click used to focus windows."));
339 panel->newB = WMCreateSwitchButton(panel->optF);
340 WMResizeWidget(panel->newB, 225, 35);
341 WMMoveWidget(panel->newB, 10, 70);
342 WMSetButtonText(panel->newB, _("Automatically focus new windows."));
344 WMMapSubwidgets(panel->optF);
347 WMRealizeWidget(panel->box);
348 WMMapSubwidgets(panel->box);
350 showData(panel);
355 Panel*
356 InitFocus(WMScreen *scr, WMWindow *win)
358 _Panel *panel;
360 panel = wmalloc(sizeof(_Panel));
361 memset(panel, 0, sizeof(_Panel));
363 panel->sectionName = _("Window Focus Preferences");
365 panel->description = _("Keyboard focus switching policy, colormap switching\n"
366 "policy for 8bpp displays and other related options.");
368 panel->parent = win;
370 panel->callbacks.createWidgets = createPanel;
371 panel->callbacks.updateDomain = storeData;
373 AddSection(panel, ICON_FILE);
375 return panel;