WPrefs: More moving around of options and tweaks to layout
[wmaker-crm.git] / WPrefs.app / WindowHandling.c
blobf89344df26f5c06c3512a2b987cb134e7c2b1a6c
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 *tranF;
65 WMButton *tranB;
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 char *placements[] = {
81 "auto",
82 "random",
83 "manual",
84 "cascade",
85 "smart",
86 "center"
89 static void sliderCallback(WMWidget * w, void *data)
91 _Panel *panel = (_Panel *) data;
92 int x, y, rx, ry;
93 char buffer[64];
94 int swidth = WMGetSliderMaxValue(panel->hsli);
95 int sheight = WMGetSliderMaxValue(panel->vsli);
97 x = WMGetSliderValue(panel->hsli);
98 y = WMGetSliderValue(panel->vsli);
100 rx = x * (WMWidgetWidth(panel->porigF) - 3) / swidth + 2;
101 ry = y * (WMWidgetHeight(panel->porigF) - 3) / sheight + 2;
102 WMMoveWidget(panel->porigW, rx, ry);
104 sprintf(buffer, "(%i,%i)", x, y);
105 WMSetLabelText(panel->porigvL, buffer);
108 static void resistanceCallback(WMWidget * w, void *data)
110 _Panel *panel = (_Panel *) data;
111 char buffer[64];
112 int i;
114 i = WMGetSliderValue(panel->resS);
116 if (i == 0)
117 WMSetLabelText(panel->resL, "OFF");
118 else {
119 sprintf(buffer, "%i", i);
120 WMSetLabelText(panel->resL, buffer);
124 static void resizeCallback(WMWidget * w, void *data)
126 _Panel *panel = (_Panel *) data;
127 char buffer[64];
128 int i;
130 i = WMGetSliderValue(panel->resizeS);
132 if (i == 0)
133 WMSetLabelText(panel->resizeL, "OFF");
134 else {
135 sprintf(buffer, "%i", i);
136 WMSetLabelText(panel->resizeL, buffer);
140 static int getPlacement(char *str)
142 if (!str)
143 return 0;
145 if (strcasecmp(str, "auto") == 0)
146 return 0;
147 else if (strcasecmp(str, "random") == 0)
148 return 1;
149 else if (strcasecmp(str, "manual") == 0)
150 return 2;
151 else if (strcasecmp(str, "cascade") == 0)
152 return 3;
153 else if (strcasecmp(str, "smart") == 0)
154 return 4;
155 else if (strcasecmp(str, "center") == 0)
156 return 5;
157 else
158 wwarning(_("bad option value %s in WindowPlacement. Using default value"), str);
159 return 0;
162 static void showData(_Panel * panel)
164 char *str;
165 WMPropList *arr;
166 int x, y;
168 str = GetStringForKey("WindowPlacement");
170 WMSetPopUpButtonSelectedItem(panel->placP, getPlacement(str));
172 arr = GetObjectForKey("WindowPlaceOrigin");
174 x = 0;
175 y = 0;
176 if (arr && (!WMIsPLArray(arr) || WMGetPropListItemCount(arr) != 2)) {
177 wwarning(_("invalid data in option WindowPlaceOrigin. Using default (0,0)"));
178 } else {
179 if (arr) {
180 x = atoi(WMGetFromPLString(WMGetFromPLArray(arr, 0)));
181 y = atoi(WMGetFromPLString(WMGetFromPLArray(arr, 1)));
185 WMSetSliderValue(panel->hsli, x);
186 WMSetSliderValue(panel->vsli, y);
188 sliderCallback(NULL, panel);
190 x = GetIntegerForKey("EdgeResistance");
191 WMSetSliderValue(panel->resS, x);
192 resistanceCallback(NULL, panel);
194 x = GetIntegerForKey("ResizeIncrement");
195 WMSetSliderValue(panel->resizeS, x);
196 resizeCallback(NULL, panel);
198 WMSetButtonSelected(panel->tranB, GetBoolForKey("OpenTransientOnOwnerWorkspace"));
200 WMSetButtonSelected(panel->opaqB, GetBoolForKey("OpaqueMove"));
201 WMSetButtonSelected(panel->opaqresizeB, GetBoolForKey("OpaqueResize"));
202 WMSetButtonSelected(panel->opaqkeybB, GetBoolForKey("OpaqueMoveResizeKeyboard"));
204 WMSetButtonSelected(panel->miconB, GetBoolForKey("NoWindowOverIcons"));
205 WMSetButtonSelected(panel->mdockB, GetBoolForKey("NoWindowOverDock"));
207 if (GetBoolForKey("Attraction"))
208 WMPerformButtonClick(panel->resrB);
209 else
210 WMPerformButtonClick(panel->resaB);
213 static void storeData(_Panel * panel)
215 WMPropList *arr;
216 char x[16], y[16];
218 SetBoolForKey(WMGetButtonSelected(panel->miconB), "NoWindowOverIcons");
219 SetBoolForKey(WMGetButtonSelected(panel->mdockB), "NoWindowOverDock");
221 SetBoolForKey(WMGetButtonSelected(panel->opaqB), "OpaqueMove");
222 SetBoolForKey(WMGetButtonSelected(panel->opaqresizeB), "OpaqueResize");
223 SetBoolForKey(WMGetButtonSelected(panel->opaqkeybB), "OpaqueMoveResizeKeyboard");
225 SetBoolForKey(WMGetButtonSelected(panel->tranB), "OpenTransientOnOwnerWorkspace");
227 SetStringForKey(placements[WMGetPopUpButtonSelectedItem(panel->placP)], "WindowPlacement");
228 sprintf(x, "%i", WMGetSliderValue(panel->hsli));
229 sprintf(y, "%i", WMGetSliderValue(panel->vsli));
230 arr = WMCreatePLArray(WMCreatePLString(x), WMCreatePLString(y), NULL);
231 SetObjectForKey(arr, "WindowPlaceOrigin");
233 SetIntegerForKey(WMGetSliderValue(panel->resS), "EdgeResistance");
235 SetIntegerForKey(WMGetSliderValue(panel->resizeS), "ResizeIncrement");
236 SetBoolForKey(WMGetButtonSelected(panel->resrB), "Attraction");
238 WMReleasePropList(arr);
241 static void createPanel(Panel * p)
243 _Panel *panel = (Panel *) p;
244 WMScreen *scr = WMWidgetScreen(panel->parent);
245 WMColor *color;
246 WMPixmap *pixmap;
247 int width, height;
248 int swidth, sheight;
249 char *path;
250 WMBox *hbox;
252 panel->box = WMCreateBox(panel->parent);
253 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
254 WMSetBoxHorizontal(panel->box, False);
255 WMSetBoxBorderWidth(panel->box, 8);
257 hbox = WMCreateBox(panel->box);
258 WMSetBoxHorizontal(hbox, True);
259 WMAddBoxSubview(panel->box, WMWidgetView(hbox), False, True, 110, 0, 10);
261 /************** Window Placement ***************/
262 panel->placF = WMCreateFrame(hbox);
263 WMMapWidget(panel->placF);
264 WMAddBoxSubview(hbox, WMWidgetView(panel->placF), True, True, 100, 0, 10);
266 WMSetFrameTitle(panel->placF, _("Window Placement"));
267 WMSetBalloonTextForView(_("How to place windows when they are first put\n"
268 "on screen."), WMWidgetView(panel->placF));
270 panel->placP = WMCreatePopUpButton(panel->placF);
271 WMResizeWidget(panel->placP, 105, 20);
272 WMMoveWidget(panel->placP, 10, 20);
273 WMAddPopUpButtonItem(panel->placP, _("Automatic"));
274 WMAddPopUpButtonItem(panel->placP, _("Random"));
275 WMAddPopUpButtonItem(panel->placP, _("Manual"));
276 WMAddPopUpButtonItem(panel->placP, _("Cascade"));
277 WMAddPopUpButtonItem(panel->placP, _("Smart"));
278 WMAddPopUpButtonItem(panel->placP, _("Center"));
280 panel->porigL = WMCreateLabel(panel->placF);
281 WMResizeWidget(panel->porigL, 110, 32);
282 WMMoveWidget(panel->porigL, 3, 45);
283 WMSetLabelTextAlignment(panel->porigL, WACenter);
284 WMSetLabelText(panel->porigL, _("Placement Origin"));
286 panel->porigvL = WMCreateLabel(panel->placF);
287 WMResizeWidget(panel->porigvL, 80, 20);
288 WMMoveWidget(panel->porigvL, 18, 75);
289 WMSetLabelTextAlignment(panel->porigvL, WACenter);
291 color = WMCreateRGBColor(scr, 0x5100, 0x5100, 0x7100, True);
292 panel->porigF = WMCreateFrame(panel->placF);
293 WMSetWidgetBackgroundColor(panel->porigF, color);
294 WMReleaseColor(color);
295 WMSetFrameRelief(panel->porigF, WRSunken);
297 swidth = WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr)));
298 sheight = HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr)));
300 if (sheight > swidth) {
301 width = 70 * swidth / sheight;
302 if (width > 195)
303 width = 195;
304 height = 195 * sheight / swidth;
305 } else {
306 height = 195 * sheight / swidth;
307 if (height > 70)
308 height = 70;
309 width = 70 * swidth / sheight;
311 WMResizeWidget(panel->porigF, width, height);
312 WMMoveWidget(panel->porigF, 125 + (195 - width) / 2, 20 + (70 - height) / 2);
314 panel->porigW = WMCreateLabel(panel->porigF);
315 WMResizeWidget(panel->porigW, THUMB_SIZE, THUMB_SIZE);
316 WMMoveWidget(panel->porigW, 2, 2);
317 WMSetLabelRelief(panel->porigW, WRRaised);
319 panel->hsli = WMCreateSlider(panel->placF);
320 WMResizeWidget(panel->hsli, width, 12);
321 WMMoveWidget(panel->hsli, 125 + (195 - width) / 2, 20 + (70 - height) / 2 + height + 2);
322 WMSetSliderAction(panel->hsli, sliderCallback, panel);
323 WMSetSliderMinValue(panel->hsli, 0);
324 WMSetSliderMaxValue(panel->hsli, swidth);
326 panel->vsli = WMCreateSlider(panel->placF);
327 WMResizeWidget(panel->vsli, 12, height);
328 WMMoveWidget(panel->vsli, 125 + (195 - width) / 2 + width + 2, 20 + (70 - height) / 2);
329 WMSetSliderAction(panel->vsli, sliderCallback, panel);
330 WMSetSliderMinValue(panel->vsli, 0);
331 WMSetSliderMaxValue(panel->vsli, sheight);
333 WMMapSubwidgets(panel->porigF);
335 WMMapSubwidgets(panel->placF);
337 /************** Opaque Move, Resize ***************/
338 panel->opaqF = WMCreateFrame(hbox);
339 WMMapWidget(panel->opaqF);
340 WMAddBoxSubview(hbox, WMWidgetView(panel->opaqF), False, True, 150, 0, 0);
342 WMSetFrameTitle(panel->opaqF, _("Opaque Move/Resize"));
343 WMSetBalloonTextForView(_("Whether the window contents or only a frame should\n"
344 "be displayed during a move or resize.\n"),
345 WMWidgetView(panel->opaqF));
347 panel->opaqB = WMCreateButton(panel->opaqF, WBTToggle);
348 WMResizeWidget(panel->opaqB, 48,48);
349 WMMoveWidget(panel->opaqB, 18, 20);
350 WMSetButtonImagePosition(panel->opaqB, WIPImageOnly);
352 path = LocateImage(NON_OPAQUE_MOVE_PIXMAP);
353 if (path) {
354 pixmap = WMCreatePixmapFromFile(scr, path);
355 if (pixmap) {
356 WMSetButtonImage(panel->opaqB, pixmap);
357 WMReleasePixmap(pixmap);
358 } else {
359 wwarning(_("could not load icon %s"), path);
361 wfree(path);
364 path = LocateImage(OPAQUE_MOVE_PIXMAP);
365 if (path) {
366 pixmap = WMCreatePixmapFromFile(scr, path);
367 if (pixmap) {
368 WMSetButtonAltImage(panel->opaqB, pixmap);
369 WMReleasePixmap(pixmap);
370 } else {
371 wwarning(_("could not load icon %s"), path);
373 wfree(path);
378 panel->opaqresizeB = WMCreateButton(panel->opaqF, WBTToggle);
379 WMResizeWidget(panel->opaqresizeB, 48,48);
380 WMMoveWidget(panel->opaqresizeB, 86, 20);
381 WMSetButtonImagePosition(panel->opaqresizeB, WIPImageOnly);
383 path = LocateImage(NON_OPAQUE_RESIZE_PIXMAP);
384 if (path) {
385 pixmap = WMCreatePixmapFromFile(scr, path);
386 if (pixmap) {
387 WMSetButtonImage(panel->opaqresizeB, pixmap);
388 WMReleasePixmap(pixmap);
389 } else {
390 wwarning(_("could not load icon %s"), path);
392 wfree(path);
395 path = LocateImage(OPAQUE_RESIZE_PIXMAP);
396 if (path) {
397 pixmap = WMCreatePixmapFromFile(scr, path);
398 if (pixmap) {
399 WMSetButtonAltImage(panel->opaqresizeB, pixmap);
400 WMReleasePixmap(pixmap);
401 } else {
402 wwarning(_("could not load icon %s"), path);
404 wfree(path);
407 panel->opaqkeybB = WMCreateSwitchButton(panel->opaqF);
408 WMResizeWidget(panel->opaqkeybB, 100, 25);
409 WMMoveWidget(panel->opaqkeybB, 18, 76);
410 WMSetButtonText(panel->opaqkeybB, _("by keyboard"));
412 WMMapSubwidgets(panel->opaqF);
415 /**************** Account for Icon/Dock ***************/
416 panel->maxiF = WMCreateFrame(panel->box);
417 WMResizeWidget(panel->maxiF, 205, 100);
418 WMMoveWidget(panel->maxiF, 307, 125);
419 WMSetFrameTitle(panel->maxiF, _("When maximizing..."));
421 panel->miconB = WMCreateSwitchButton(panel->maxiF);
422 WMResizeWidget(panel->miconB, 190, 30);
423 WMMoveWidget(panel->miconB, 10, 14);
424 WMSetButtonText(panel->miconB, _("...do not cover icons"));
426 panel->mdockB = WMCreateSwitchButton(panel->maxiF);
427 WMResizeWidget(panel->mdockB, 190, 30);
428 WMMoveWidget(panel->mdockB, 10, 39);
430 WMSetButtonText(panel->mdockB, _("...do not cover dock"));
432 panel->resizeS = WMCreateSlider(panel->maxiF);
433 WMResizeWidget(panel->resizeS, 50, 15);
434 WMMoveWidget(panel->resizeS, 10, 74);
435 WMSetSliderMinValue(panel->resizeS, 0);
436 WMSetSliderMaxValue(panel->resizeS, 100);
437 WMSetSliderAction(panel->resizeS, resizeCallback, panel);
439 panel->resizeL = WMCreateLabel(panel->maxiF);
440 WMResizeWidget(panel->resizeL, 30, 15);
441 WMMoveWidget(panel->resizeL, 60, 74);
443 panel->resizeTextL = WMCreateLabel(panel->maxiF);
444 WMSetLabelText(panel->resizeTextL, "Mod+Wheel\nresize increment");
445 WMResizeWidget(panel->resizeTextL, 110, 30);
446 WMMoveWidget(panel->resizeTextL, 90, 66);
448 WMMapSubwidgets(panel->maxiF);
450 /**************** Edge Resistance ****************/
451 panel->resF = WMCreateFrame(panel->box);
452 WMResizeWidget(panel->resF, 289, 50);
453 WMMoveWidget(panel->resF, 8, 125);
454 WMSetFrameTitle(panel->resF, _("Edge Resistance"));
456 WMSetBalloonTextForView(_("Edge resistance will make windows `resist'\n"
457 "being moved further for the defined threshold\n"
458 "when moved against other windows or the edges\n"
459 "of the screen."), WMWidgetView(panel->resF));
461 panel->resS = WMCreateSlider(panel->resF);
462 WMResizeWidget(panel->resS, 80, 15);
463 WMMoveWidget(panel->resS, 10, 22);
464 WMSetSliderMinValue(panel->resS, 0);
465 WMSetSliderMaxValue(panel->resS, 80);
466 WMSetSliderAction(panel->resS, resistanceCallback, panel);
468 panel->resL = WMCreateLabel(panel->resF);
469 WMResizeWidget(panel->resL, 30, 15);
470 WMMoveWidget(panel->resL, 95, 22);
472 panel->resaB = WMCreateRadioButton(panel->resF);
473 WMMoveWidget(panel->resaB, 130, 15);
474 WMResizeWidget(panel->resaB, 70, 27);
475 WMSetButtonText(panel->resaB, _("Resist"));
477 panel->resrB = WMCreateRadioButton(panel->resF);
478 WMMoveWidget(panel->resrB, 200, 15);
479 WMResizeWidget(panel->resrB, 70, 27);
480 WMSetButtonText(panel->resrB, _("Attract"));
481 WMGroupButtons(panel->resrB, panel->resaB);
483 WMMapSubwidgets(panel->resF);
485 /**************** Transients on Parent Workspace ****************/
486 panel->tranF = WMCreateFrame(panel->box);
487 WMResizeWidget(panel->tranF, 289, 40);
488 WMMoveWidget(panel->tranF, 8, 185);
490 panel->tranB = WMCreateSwitchButton(panel->tranF);
491 WMMoveWidget(panel->tranB, 10, 5);
492 WMResizeWidget(panel->tranB, 250, 30);
493 WMSetButtonText(panel->tranB, _("Open dialogs in the same workspace\nas their owners"));
495 WMMapSubwidgets(panel->tranF);
497 WMRealizeWidget(panel->box);
498 WMMapSubwidgets(panel->box);
500 /* show the config data */
501 showData(panel);
504 static void undo(_Panel * panel)
506 showData(panel);
509 Panel *InitWindowHandling(WMScreen * scr, WMWidget * parent)
511 _Panel *panel;
513 panel = wmalloc(sizeof(_Panel));
515 panel->sectionName = _("Window Handling Preferences");
517 panel->description = _("Window handling options. Initial placement style\n"
518 "edge resistance, opaque move etc.");
520 panel->parent = parent;
522 panel->callbacks.createWidgets = createPanel;
523 panel->callbacks.updateDomain = storeData;
524 panel->callbacks.undoChanges = undo;
526 AddSection(panel, ICON_FILE);
528 return panel;