wrlib: add support for release 5.1.0 of the libgif
[wmaker-crm.git] / WPrefs.app / WindowHandling.c
blob4a8f1bc2361654620a98ac7edf4f5f378d32b9e4
1 /* WindowHandling.c- options for handling windows
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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "WPrefs.h"
24 typedef struct _Panel {
25 WMBox *box;
27 char *sectionName;
29 char *description;
31 CallbackRec callbacks;
33 WMWidget *parent;
35 WMFrame *placF;
36 WMPopUpButton *placP;
37 WMLabel *porigL;
38 WMLabel *porigvL;
39 WMFrame *porigF;
40 WMLabel *porigW;
42 WMSlider *vsli;
43 WMSlider *hsli;
45 WMFrame *resF;
46 WMSlider *resS;
47 WMLabel *resL;
48 WMButton *resaB;
49 WMButton *resrB;
51 WMFrame *maxiF;
52 WMButton *miconB;
53 WMButton *mdockB;
55 WMLabel *resizeL;
56 WMLabel *resizeTextL;
57 WMSlider *resizeS;
59 WMFrame *opaqF;
60 WMButton *opaqB;
61 WMButton *opaqresizeB;
62 WMButton *opaqkeybB;
64 WMFrame *dragmaxF;
65 WMPopUpButton *dragmaxP;
66 } _Panel;
68 #define ICON_FILE "whandling"
70 #define OPAQUE_MOVE_PIXMAP "opaque"
72 #define NON_OPAQUE_MOVE_PIXMAP "nonopaque"
74 #define OPAQUE_RESIZE_PIXMAP "opaqueresize"
76 #define NON_OPAQUE_RESIZE_PIXMAP "noopaqueresize"
78 #define THUMB_SIZE 16
80 static const char *const placements[] = {
81 "auto",
82 "random",
83 "manual",
84 "cascade",
85 "smart",
86 "center"
89 static const char *const dragMaximizedWindowOptions[] = {
90 "Move",
91 "RestoreGeometry",
92 "Unmaximize",
93 "NoMove"
96 static void sliderCallback(WMWidget * w, void *data)
98 _Panel *panel = (_Panel *) data;
99 int x, y, rx, ry;
100 char buffer[64];
101 int swidth = WMGetSliderMaxValue(panel->hsli);
102 int sheight = WMGetSliderMaxValue(panel->vsli);
104 /* Parameter not used, but tell the compiler that it is ok */
105 (void) w;
107 x = WMGetSliderValue(panel->hsli);
108 y = WMGetSliderValue(panel->vsli);
110 rx = x * (WMWidgetWidth(panel->porigF) - 3) / swidth + 2;
111 ry = y * (WMWidgetHeight(panel->porigF) - 3) / sheight + 2;
112 WMMoveWidget(panel->porigW, rx, ry);
114 sprintf(buffer, "(%i,%i)", x, y);
115 WMSetLabelText(panel->porigvL, buffer);
118 static void resistanceCallback(WMWidget * w, void *data)
120 _Panel *panel = (_Panel *) data;
121 char buffer[64];
122 int i;
124 /* Parameter not used, but tell the compiler that it is ok */
125 (void) w;
127 i = WMGetSliderValue(panel->resS);
129 if (i == 0)
130 WMSetLabelText(panel->resL, _("OFF"));
131 else {
132 sprintf(buffer, "%i", i);
133 WMSetLabelText(panel->resL, buffer);
137 static void resizeCallback(WMWidget * w, void *data)
139 _Panel *panel = (_Panel *) data;
140 char buffer[64];
141 int i;
143 /* Parameter not used, but tell the compiler that it is ok */
144 (void) w;
146 i = WMGetSliderValue(panel->resizeS);
148 if (i == 0)
149 WMSetLabelText(panel->resizeL, _("OFF"));
150 else {
151 sprintf(buffer, "%i", i);
152 WMSetLabelText(panel->resizeL, buffer);
156 static int getPlacement(const char *str)
158 if (!str)
159 return 0;
161 if (strcasecmp(str, "auto") == 0)
162 return 0;
163 else if (strcasecmp(str, "random") == 0)
164 return 1;
165 else if (strcasecmp(str, "manual") == 0)
166 return 2;
167 else if (strcasecmp(str, "cascade") == 0)
168 return 3;
169 else if (strcasecmp(str, "smart") == 0)
170 return 4;
171 else if (strcasecmp(str, "center") == 0)
172 return 5;
173 else
174 wwarning(_("bad option value %s in WindowPlacement. Using default value"), str);
175 return 0;
178 static int getDragMaximizedWindow(const char *str)
180 if (!str)
181 return 0;
183 if (strcasecmp(str, "Move") == 0)
184 return 0;
185 else if (strcasecmp(str, "RestoreGeometry") == 0)
186 return 1;
187 else if (strcasecmp(str, "Unmaximize") == 0)
188 return 2;
189 else if (strcasecmp(str, "NoMove") == 0)
190 return 3;
191 else
192 wwarning(_("bad option value %s in WindowPlacement. Using default value"), str);
193 return 0;
197 static void showData(_Panel * panel)
199 char *str;
200 WMPropList *arr;
201 int x, y;
203 str = GetStringForKey("WindowPlacement");
205 WMSetPopUpButtonSelectedItem(panel->placP, getPlacement(str));
207 arr = GetObjectForKey("WindowPlaceOrigin");
209 x = 0;
210 y = 0;
211 if (arr && (!WMIsPLArray(arr) || WMGetPropListItemCount(arr) != 2)) {
212 wwarning(_("invalid data in option WindowPlaceOrigin. Using default (0,0)"));
213 } else {
214 if (arr) {
215 x = atoi(WMGetFromPLString(WMGetFromPLArray(arr, 0)));
216 y = atoi(WMGetFromPLString(WMGetFromPLArray(arr, 1)));
220 WMSetSliderValue(panel->hsli, x);
221 WMSetSliderValue(panel->vsli, y);
223 sliderCallback(NULL, panel);
225 x = GetIntegerForKey("EdgeResistance");
226 WMSetSliderValue(panel->resS, x);
227 resistanceCallback(NULL, panel);
229 str = GetStringForKey("DragMaximizedWindow");
230 WMSetPopUpButtonSelectedItem(panel->dragmaxP, getDragMaximizedWindow(str));
232 x = GetIntegerForKey("ResizeIncrement");
233 WMSetSliderValue(panel->resizeS, x);
234 resizeCallback(NULL, panel);
236 WMSetButtonSelected(panel->opaqB, GetBoolForKey("OpaqueMove"));
237 WMSetButtonSelected(panel->opaqresizeB, GetBoolForKey("OpaqueResize"));
238 WMSetButtonSelected(panel->opaqkeybB, GetBoolForKey("OpaqueMoveResizeKeyboard"));
240 WMSetButtonSelected(panel->miconB, GetBoolForKey("NoWindowOverIcons"));
241 WMSetButtonSelected(panel->mdockB, GetBoolForKey("NoWindowOverDock"));
243 if (GetBoolForKey("Attraction"))
244 WMPerformButtonClick(panel->resrB);
245 else
246 WMPerformButtonClick(panel->resaB);
249 static void storeData(_Panel * panel)
251 WMPropList *arr;
252 WMPropList *x, *y;
253 char buf[16];
255 SetBoolForKey(WMGetButtonSelected(panel->miconB), "NoWindowOverIcons");
256 SetBoolForKey(WMGetButtonSelected(panel->mdockB), "NoWindowOverDock");
258 SetBoolForKey(WMGetButtonSelected(panel->opaqB), "OpaqueMove");
259 SetBoolForKey(WMGetButtonSelected(panel->opaqresizeB), "OpaqueResize");
260 SetBoolForKey(WMGetButtonSelected(panel->opaqkeybB), "OpaqueMoveResizeKeyboard");
262 SetStringForKey(placements[WMGetPopUpButtonSelectedItem(panel->placP)], "WindowPlacement");
263 sprintf(buf, "%i", WMGetSliderValue(panel->hsli));
264 x = WMCreatePLString(buf);
265 sprintf(buf, "%i", WMGetSliderValue(panel->vsli));
266 y = WMCreatePLString(buf);
267 arr = WMCreatePLArray(x, y, NULL);
268 WMReleasePropList(x);
269 WMReleasePropList(y);
270 SetObjectForKey(arr, "WindowPlaceOrigin");
272 SetIntegerForKey(WMGetSliderValue(panel->resS), "EdgeResistance");
274 SetStringForKey(dragMaximizedWindowOptions[WMGetPopUpButtonSelectedItem(panel->dragmaxP)],
275 "DragMaximizedWindow");
277 SetIntegerForKey(WMGetSliderValue(panel->resizeS), "ResizeIncrement");
278 SetBoolForKey(WMGetButtonSelected(panel->resrB), "Attraction");
280 WMReleasePropList(arr);
283 static void createPanel(Panel * p)
285 _Panel *panel = (Panel *) p;
286 WMScreen *scr = WMWidgetScreen(panel->parent);
287 WMColor *color;
288 WMPixmap *pixmap;
289 int width, height;
290 int swidth, sheight;
291 char *path;
292 WMBox *hbox;
294 panel->box = WMCreateBox(panel->parent);
295 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
296 WMSetBoxHorizontal(panel->box, False);
297 WMSetBoxBorderWidth(panel->box, 8);
299 hbox = WMCreateBox(panel->box);
300 WMSetBoxHorizontal(hbox, True);
301 WMAddBoxSubview(panel->box, WMWidgetView(hbox), False, True, 110, 0, 10);
303 /************** Window Placement ***************/
304 panel->placF = WMCreateFrame(hbox);
305 WMMapWidget(panel->placF);
306 WMAddBoxSubview(hbox, WMWidgetView(panel->placF), True, True, 100, 0, 10);
308 WMSetFrameTitle(panel->placF, _("Window Placement"));
309 WMSetBalloonTextForView(_("How to place windows when they are first put\n"
310 "on screen."), WMWidgetView(panel->placF));
312 panel->placP = WMCreatePopUpButton(panel->placF);
313 WMResizeWidget(panel->placP, 105, 20);
314 WMMoveWidget(panel->placP, 10, 20);
315 WMAddPopUpButtonItem(panel->placP, _("Automatic"));
316 WMAddPopUpButtonItem(panel->placP, _("Random"));
317 WMAddPopUpButtonItem(panel->placP, _("Manual"));
318 WMAddPopUpButtonItem(panel->placP, _("Cascade"));
319 WMAddPopUpButtonItem(panel->placP, _("Smart"));
320 WMAddPopUpButtonItem(panel->placP, _("Center"));
322 panel->porigL = WMCreateLabel(panel->placF);
323 WMResizeWidget(panel->porigL, 110, 32);
324 WMMoveWidget(panel->porigL, 3, 45);
325 WMSetLabelTextAlignment(panel->porigL, WACenter);
326 WMSetLabelText(panel->porigL, _("Placement Origin"));
328 panel->porigvL = WMCreateLabel(panel->placF);
329 WMResizeWidget(panel->porigvL, 80, 20);
330 WMMoveWidget(panel->porigvL, 18, 75);
331 WMSetLabelTextAlignment(panel->porigvL, WACenter);
333 color = WMCreateRGBColor(scr, 0x5100, 0x5100, 0x7100, True);
334 panel->porigF = WMCreateFrame(panel->placF);
335 WMSetWidgetBackgroundColor(panel->porigF, color);
336 WMReleaseColor(color);
337 WMSetFrameRelief(panel->porigF, WRSunken);
339 swidth = WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr)));
340 sheight = HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr)));
342 if (sheight > swidth) {
343 width = 70 * swidth / sheight;
344 if (width > 195)
345 width = 195;
346 height = 195 * sheight / swidth;
347 } else {
348 height = 195 * sheight / swidth;
349 if (height > 70)
350 height = 70;
351 width = 70 * swidth / sheight;
353 WMResizeWidget(panel->porigF, width, height);
354 WMMoveWidget(panel->porigF, 125 + (195 - width) / 2, 20 + (70 - height) / 2);
356 panel->porigW = WMCreateLabel(panel->porigF);
357 WMResizeWidget(panel->porigW, THUMB_SIZE, THUMB_SIZE);
358 WMMoveWidget(panel->porigW, 2, 2);
359 WMSetLabelRelief(panel->porigW, WRRaised);
361 panel->hsli = WMCreateSlider(panel->placF);
362 WMResizeWidget(panel->hsli, width, 12);
363 WMMoveWidget(panel->hsli, 125 + (195 - width) / 2, 20 + (70 - height) / 2 + height + 2);
364 WMSetSliderAction(panel->hsli, sliderCallback, panel);
365 WMSetSliderMinValue(panel->hsli, 0);
366 WMSetSliderMaxValue(panel->hsli, swidth);
368 panel->vsli = WMCreateSlider(panel->placF);
369 WMResizeWidget(panel->vsli, 12, height);
370 WMMoveWidget(panel->vsli, 125 + (195 - width) / 2 + width + 2, 20 + (70 - height) / 2);
371 WMSetSliderAction(panel->vsli, sliderCallback, panel);
372 WMSetSliderMinValue(panel->vsli, 0);
373 WMSetSliderMaxValue(panel->vsli, sheight);
375 WMMapSubwidgets(panel->porigF);
377 WMMapSubwidgets(panel->placF);
379 /************** Opaque Move, Resize ***************/
380 panel->opaqF = WMCreateFrame(hbox);
381 WMMapWidget(panel->opaqF);
382 WMAddBoxSubview(hbox, WMWidgetView(panel->opaqF), False, True, 150, 0, 0);
384 WMSetFrameTitle(panel->opaqF, _("Opaque Move/Resize"));
385 WMSetBalloonTextForView(_("Whether the window contents or only a frame should\n"
386 "be displayed during a move or resize.\n"),
387 WMWidgetView(panel->opaqF));
389 panel->opaqB = WMCreateButton(panel->opaqF, WBTToggle);
390 WMResizeWidget(panel->opaqB, 54, 54);
391 WMMoveWidget(panel->opaqB, 14, 20);
392 WMSetButtonImagePosition(panel->opaqB, WIPImageOnly);
394 path = LocateImage(NON_OPAQUE_MOVE_PIXMAP);
395 if (path) {
396 pixmap = WMCreatePixmapFromFile(scr, path);
397 if (pixmap) {
398 WMSetButtonImage(panel->opaqB, pixmap);
399 WMReleasePixmap(pixmap);
400 } else {
401 wwarning(_("could not load icon %s"), path);
403 wfree(path);
406 path = LocateImage(OPAQUE_MOVE_PIXMAP);
407 if (path) {
408 pixmap = WMCreatePixmapFromFile(scr, path);
409 if (pixmap) {
410 WMSetButtonAltImage(panel->opaqB, pixmap);
411 WMReleasePixmap(pixmap);
412 } else {
413 wwarning(_("could not load icon %s"), path);
415 wfree(path);
420 panel->opaqresizeB = WMCreateButton(panel->opaqF, WBTToggle);
421 WMResizeWidget(panel->opaqresizeB, 54, 54);
422 WMMoveWidget(panel->opaqresizeB, 82, 20);
423 WMSetButtonImagePosition(panel->opaqresizeB, WIPImageOnly);
425 path = LocateImage(NON_OPAQUE_RESIZE_PIXMAP);
426 if (path) {
427 pixmap = WMCreatePixmapFromFile(scr, path);
428 if (pixmap) {
429 WMSetButtonImage(panel->opaqresizeB, pixmap);
430 WMReleasePixmap(pixmap);
431 } else {
432 wwarning(_("could not load icon %s"), path);
434 wfree(path);
437 path = LocateImage(OPAQUE_RESIZE_PIXMAP);
438 if (path) {
439 pixmap = WMCreatePixmapFromFile(scr, path);
440 if (pixmap) {
441 WMSetButtonAltImage(panel->opaqresizeB, pixmap);
442 WMReleasePixmap(pixmap);
443 } else {
444 wwarning(_("could not load icon %s"), path);
446 wfree(path);
449 panel->opaqkeybB = WMCreateSwitchButton(panel->opaqF);
450 WMResizeWidget(panel->opaqkeybB, 122, 25);
451 WMMoveWidget(panel->opaqkeybB, 14, 79);
452 WMSetButtonText(panel->opaqkeybB, _("by keyboard"));
454 WMMapSubwidgets(panel->opaqF);
457 /**************** Account for Icon/Dock ***************/
458 panel->maxiF = WMCreateFrame(panel->box);
459 WMResizeWidget(panel->maxiF, 205, 100);
460 WMMoveWidget(panel->maxiF, 307, 125);
461 WMSetFrameTitle(panel->maxiF, _("When maximizing..."));
463 panel->miconB = WMCreateSwitchButton(panel->maxiF);
464 WMResizeWidget(panel->miconB, 190, 30);
465 WMMoveWidget(panel->miconB, 10, 14);
466 WMSetButtonText(panel->miconB, _("...do not cover icons"));
468 panel->mdockB = WMCreateSwitchButton(panel->maxiF);
469 WMResizeWidget(panel->mdockB, 190, 30);
470 WMMoveWidget(panel->mdockB, 10, 39);
472 WMSetButtonText(panel->mdockB, _("...do not cover dock"));
474 panel->resizeS = WMCreateSlider(panel->maxiF);
475 WMResizeWidget(panel->resizeS, 50, 15);
476 WMMoveWidget(panel->resizeS, 10, 74);
477 WMSetSliderMinValue(panel->resizeS, 0);
478 WMSetSliderMaxValue(panel->resizeS, 100);
479 WMSetSliderAction(panel->resizeS, resizeCallback, panel);
481 panel->resizeL = WMCreateLabel(panel->maxiF);
482 WMResizeWidget(panel->resizeL, 30, 15);
483 WMMoveWidget(panel->resizeL, 60, 74);
485 panel->resizeTextL = WMCreateLabel(panel->maxiF);
486 WMSetLabelText(panel->resizeTextL, _("Mod+Wheel\nresize increment"));
487 WMResizeWidget(panel->resizeTextL, 110, 30);
488 WMMoveWidget(panel->resizeTextL, 90, 66);
490 WMMapSubwidgets(panel->maxiF);
492 /**************** Edge Resistance ****************/
493 panel->resF = WMCreateFrame(panel->box);
494 WMResizeWidget(panel->resF, 289, 47);
495 WMMoveWidget(panel->resF, 8, 125);
496 WMSetFrameTitle(panel->resF, _("Edge Resistance"));
498 WMSetBalloonTextForView(_("Edge resistance will make windows `resist'\n"
499 "being moved further for the defined threshold\n"
500 "when moved against other windows or the edges\n"
501 "of the screen."), WMWidgetView(panel->resF));
503 panel->resS = WMCreateSlider(panel->resF);
504 WMResizeWidget(panel->resS, 80, 15);
505 WMMoveWidget(panel->resS, 10, 20);
506 WMSetSliderMinValue(panel->resS, 0);
507 WMSetSliderMaxValue(panel->resS, 80);
508 WMSetSliderAction(panel->resS, resistanceCallback, panel);
510 panel->resL = WMCreateLabel(panel->resF);
511 WMResizeWidget(panel->resL, 30, 15);
512 WMMoveWidget(panel->resL, 95, 22);
514 panel->resaB = WMCreateRadioButton(panel->resF);
515 WMMoveWidget(panel->resaB, 130, 15);
516 WMResizeWidget(panel->resaB, 70, 27);
517 WMSetButtonText(panel->resaB, _("Resist"));
519 panel->resrB = WMCreateRadioButton(panel->resF);
520 WMMoveWidget(panel->resrB, 200, 15);
521 WMResizeWidget(panel->resrB, 70, 27);
522 WMSetButtonText(panel->resrB, _("Attract"));
523 WMGroupButtons(panel->resrB, panel->resaB);
525 WMMapSubwidgets(panel->resF);
527 /**************** Dragging a Maximized Window ****************/
528 panel->dragmaxF = WMCreateFrame(panel->box);
529 WMResizeWidget(panel->dragmaxF, 289, 46);
530 WMMoveWidget(panel->dragmaxF, 8, 179);
531 WMSetFrameTitle(panel->dragmaxF, _("When dragging a maximized window..."));
533 panel->dragmaxP = WMCreatePopUpButton(panel->dragmaxF);
534 WMResizeWidget(panel->dragmaxP, 269, 20);
535 WMMoveWidget(panel->dragmaxP, 10, 20);
536 WMAddPopUpButtonItem(panel->dragmaxP, _("...change position (normal behavior)"));
537 WMAddPopUpButtonItem(panel->dragmaxP, _("...restore unmaximized geometry"));
538 WMAddPopUpButtonItem(panel->dragmaxP, _("...consider the window unmaximized"));
539 WMAddPopUpButtonItem(panel->dragmaxP, _("...do not move the window"));
541 WMMapSubwidgets(panel->dragmaxF);
543 WMRealizeWidget(panel->box);
544 WMMapSubwidgets(panel->box);
546 /* show the config data */
547 showData(panel);
550 static void undo(_Panel * panel)
552 showData(panel);
555 Panel *InitWindowHandling(WMWidget *parent)
557 _Panel *panel;
559 panel = wmalloc(sizeof(_Panel));
561 panel->sectionName = _("Window Handling Preferences");
563 panel->description = _("Window handling options. Initial placement style\n"
564 "edge resistance, opaque move etc.");
566 panel->parent = parent;
568 panel->callbacks.createWidgets = createPanel;
569 panel->callbacks.updateDomain = storeData;
570 panel->callbacks.undoChanges = undo;
572 AddSection(panel, ICON_FILE);
574 return panel;