Update local copy of GPLv2 and FSF address in copyrights
[wmaker-crm.git] / WPrefs.app / WindowHandling.c
blob39d2b7debc9bcd33ea26da3dcbb3c48775713c54
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;
62 WMFrame *tranF;
63 WMButton *tranB;
64 } _Panel;
66 #define ICON_FILE "whandling"
68 #define OPAQUE_MOVE_PIXMAP "opaque"
70 #define NON_OPAQUE_MOVE_PIXMAP "nonopaque"
72 #define THUMB_SIZE 16
74 static char *placements[] = {
75 "auto",
76 "random",
77 "manual",
78 "cascade",
79 "smart"
82 static void sliderCallback(WMWidget * w, void *data)
84 _Panel *panel = (_Panel *) data;
85 int x, y, rx, ry;
86 char buffer[64];
87 int swidth = WMGetSliderMaxValue(panel->hsli);
88 int sheight = WMGetSliderMaxValue(panel->vsli);
90 x = WMGetSliderValue(panel->hsli);
91 y = WMGetSliderValue(panel->vsli);
93 rx = x * (WMWidgetWidth(panel->porigF) - 3) / swidth + 2;
94 ry = y * (WMWidgetHeight(panel->porigF) - 3) / sheight + 2;
95 WMMoveWidget(panel->porigW, rx, ry);
97 sprintf(buffer, "(%i,%i)", x, y);
98 WMSetLabelText(panel->porigvL, buffer);
101 static void resistanceCallback(WMWidget * w, void *data)
103 _Panel *panel = (_Panel *) data;
104 char buffer[64];
105 int i;
107 i = WMGetSliderValue(panel->resS);
109 if (i == 0)
110 WMSetLabelText(panel->resL, "OFF");
111 else {
112 sprintf(buffer, "%i", i);
113 WMSetLabelText(panel->resL, buffer);
117 static void resizeCallback(WMWidget * w, void *data)
119 _Panel *panel = (_Panel *) data;
120 char buffer[64];
121 int i;
123 i = WMGetSliderValue(panel->resizeS);
125 if (i == 0)
126 WMSetLabelText(panel->resizeL, "OFF");
127 else {
128 sprintf(buffer, "%i", i);
129 WMSetLabelText(panel->resizeL, buffer);
133 static int getPlacement(char *str)
135 if (!str)
136 return 0;
138 if (strcasecmp(str, "auto") == 0)
139 return 0;
140 else if (strcasecmp(str, "random") == 0)
141 return 1;
142 else if (strcasecmp(str, "manual") == 0)
143 return 2;
144 else if (strcasecmp(str, "cascade") == 0)
145 return 3;
146 else if (strcasecmp(str, "smart") == 0)
147 return 4;
148 else
149 wwarning(_("bad option value %s in WindowPlacement. Using default value"), str);
150 return 0;
153 static void showData(_Panel * panel)
155 char *str;
156 WMPropList *arr;
157 int x, y;
159 str = GetStringForKey("WindowPlacement");
161 WMSetPopUpButtonSelectedItem(panel->placP, getPlacement(str));
163 arr = GetObjectForKey("WindowPlaceOrigin");
165 x = 0;
166 y = 0;
167 if (arr && (!WMIsPLArray(arr) || WMGetPropListItemCount(arr) != 2)) {
168 wwarning(_("invalid data in option WindowPlaceOrigin. Using default (0,0)"));
169 } else {
170 if (arr) {
171 x = atoi(WMGetFromPLString(WMGetFromPLArray(arr, 0)));
172 y = atoi(WMGetFromPLString(WMGetFromPLArray(arr, 1)));
176 WMSetSliderValue(panel->hsli, x);
177 WMSetSliderValue(panel->vsli, y);
179 sliderCallback(NULL, panel);
181 x = GetIntegerForKey("EdgeResistance");
182 WMSetSliderValue(panel->resS, x);
183 resistanceCallback(NULL, panel);
185 x = GetIntegerForKey("ResizeIncrement");
186 WMSetSliderValue(panel->resizeS, x);
187 resizeCallback(NULL, panel);
189 WMSetButtonSelected(panel->tranB, GetBoolForKey("OpenTransientOnOwnerWorkspace"));
191 WMSetButtonSelected(panel->opaqB, GetBoolForKey("OpaqueMove"));
193 WMSetButtonSelected(panel->miconB, GetBoolForKey("NoWindowOverIcons"));
195 WMSetButtonSelected(panel->mdockB, GetBoolForKey("NoWindowOverDock"));
197 if (GetBoolForKey("Attraction"))
198 WMPerformButtonClick(panel->resrB);
199 else
200 WMPerformButtonClick(panel->resaB);
203 static void storeData(_Panel * panel)
205 WMPropList *arr;
206 char x[16], y[16];
208 SetBoolForKey(WMGetButtonSelected(panel->miconB), "NoWindowOverIcons");
209 SetBoolForKey(WMGetButtonSelected(panel->mdockB), "NoWindowOverDock");
210 SetBoolForKey(WMGetButtonSelected(panel->opaqB), "OpaqueMove");
211 SetBoolForKey(WMGetButtonSelected(panel->tranB), "OpenTransientOnOwnerWorkspace");
212 SetStringForKey(placements[WMGetPopUpButtonSelectedItem(panel->placP)], "WindowPlacement");
213 sprintf(x, "%i", WMGetSliderValue(panel->hsli));
214 sprintf(y, "%i", WMGetSliderValue(panel->vsli));
215 arr = WMCreatePLArray(WMCreatePLString(x), WMCreatePLString(y), NULL);
216 SetObjectForKey(arr, "WindowPlaceOrigin");
217 SetIntegerForKey(WMGetSliderValue(panel->resS), "EdgeResistance");
218 SetIntegerForKey(WMGetSliderValue(panel->resizeS), "ResizeIncrement");
219 SetBoolForKey(WMGetButtonSelected(panel->resrB), "Attraction");
220 WMReleasePropList(arr);
223 static void createPanel(Panel * p)
225 _Panel *panel = (Panel *) p;
226 WMScreen *scr = WMWidgetScreen(panel->parent);
227 WMColor *color;
228 WMPixmap *pixmap;
229 int width, height;
230 int swidth, sheight;
231 char *path;
232 WMBox *hbox;
234 panel->box = WMCreateBox(panel->parent);
235 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
236 WMSetBoxHorizontal(panel->box, False);
237 WMSetBoxBorderWidth(panel->box, 8);
239 hbox = WMCreateBox(panel->box);
240 WMSetBoxHorizontal(hbox, True);
241 WMAddBoxSubview(panel->box, WMWidgetView(hbox), False, True, 110, 0, 10);
243 /************** Window Placement ***************/
244 panel->placF = WMCreateFrame(hbox);
245 WMMapWidget(panel->placF);
246 WMAddBoxSubview(hbox, WMWidgetView(panel->placF), True, True, 100, 0, 10);
248 WMSetFrameTitle(panel->placF, _("Window Placement"));
249 WMSetBalloonTextForView(_("How to place windows when they are first put\n"
250 "on screen."), WMWidgetView(panel->placF));
252 panel->placP = WMCreatePopUpButton(panel->placF);
253 WMResizeWidget(panel->placP, 105, 20);
254 WMMoveWidget(panel->placP, 15, 20);
255 WMAddPopUpButtonItem(panel->placP, _("Automatic"));
256 WMAddPopUpButtonItem(panel->placP, _("Random"));
257 WMAddPopUpButtonItem(panel->placP, _("Manual"));
258 WMAddPopUpButtonItem(panel->placP, _("Cascade"));
259 WMAddPopUpButtonItem(panel->placP, _("Smart"));
261 panel->porigL = WMCreateLabel(panel->placF);
262 WMResizeWidget(panel->porigL, 120, 32);
263 WMMoveWidget(panel->porigL, 5, 45);
264 WMSetLabelTextAlignment(panel->porigL, WACenter);
265 WMSetLabelText(panel->porigL, _("Placement Origin"));
267 panel->porigvL = WMCreateLabel(panel->placF);
268 WMResizeWidget(panel->porigvL, 80, 20);
269 WMMoveWidget(panel->porigvL, 30, 75);
270 WMSetLabelTextAlignment(panel->porigvL, WACenter);
272 color = WMCreateRGBColor(scr, 0x5100, 0x5100, 0x7100, True);
273 panel->porigF = WMCreateFrame(panel->placF);
274 WMSetWidgetBackgroundColor(panel->porigF, color);
275 WMReleaseColor(color);
276 WMSetFrameRelief(panel->porigF, WRSunken);
278 swidth = WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr)));
279 sheight = HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr)));
281 if (sheight > swidth) {
282 height = 70;
283 width = 70 * swidth / sheight;
284 if (width > 240)
285 width = 240;
286 height = 240 * sheight / swidth;
287 } else {
288 width = 240;
289 height = 240 * sheight / swidth;
290 if (height > 70)
291 height = 70;
292 width = 70 * swidth / sheight;
294 WMResizeWidget(panel->porigF, width, height);
295 WMMoveWidget(panel->porigF, 130 + (240 - width) / 2, 20 + (70 - height) / 2);
297 panel->porigW = WMCreateLabel(panel->porigF);
298 WMResizeWidget(panel->porigW, THUMB_SIZE, THUMB_SIZE);
299 WMMoveWidget(panel->porigW, 2, 2);
300 WMSetLabelRelief(panel->porigW, WRRaised);
302 panel->hsli = WMCreateSlider(panel->placF);
303 WMResizeWidget(panel->hsli, width, 12);
304 WMMoveWidget(panel->hsli, 130 + (240 - width) / 2, 20 + (70 - height) / 2 + height + 2);
305 WMSetSliderAction(panel->hsli, sliderCallback, panel);
306 WMSetSliderMinValue(panel->hsli, 0);
307 WMSetSliderMaxValue(panel->hsli, swidth);
309 panel->vsli = WMCreateSlider(panel->placF);
310 WMResizeWidget(panel->vsli, 12, height);
311 WMMoveWidget(panel->vsli, 130 + (240 - width) / 2 + width + 2, 20 + (70 - height) / 2);
312 WMSetSliderAction(panel->vsli, sliderCallback, panel);
313 WMSetSliderMinValue(panel->vsli, 0);
314 WMSetSliderMaxValue(panel->vsli, sheight);
316 WMMapSubwidgets(panel->porigF);
318 WMMapSubwidgets(panel->placF);
320 /************** Opaque Move ***************/
321 panel->opaqF = WMCreateFrame(hbox);
322 WMMapWidget(panel->opaqF);
323 WMAddBoxSubview(hbox, WMWidgetView(panel->opaqF), False, True, 110, 0, 0);
325 WMSetFrameTitle(panel->opaqF, _("Opaque Move"));
326 WMSetBalloonTextForView(_("Whether the window contents should be moved\n"
327 "when dragging windows aroung or if only a\n"
328 "frame should be displayed.\n"), WMWidgetView(panel->opaqF));
330 panel->opaqB = WMCreateButton(panel->opaqF, WBTToggle);
331 WMResizeWidget(panel->opaqB, 64, 64);
332 WMMoveWidget(panel->opaqB, 24, 25);
333 WMSetButtonImagePosition(panel->opaqB, WIPImageOnly);
335 path = LocateImage(NON_OPAQUE_MOVE_PIXMAP);
336 if (path) {
337 pixmap = WMCreatePixmapFromFile(scr, path);
338 if (pixmap) {
339 WMSetButtonImage(panel->opaqB, pixmap);
340 WMReleasePixmap(pixmap);
341 } else {
342 wwarning(_("could not load icon %s"), path);
344 wfree(path);
347 path = LocateImage(OPAQUE_MOVE_PIXMAP);
348 if (path) {
349 pixmap = WMCreatePixmapFromFile(scr, path);
350 if (pixmap) {
351 WMSetButtonAltImage(panel->opaqB, pixmap);
352 WMReleasePixmap(pixmap);
353 } else {
354 wwarning(_("could not load icon %s"), path);
356 wfree(path);
358 WMMapSubwidgets(panel->opaqF);
360 /**************** Account for Icon/Dock ***************/
361 panel->maxiF = WMCreateFrame(panel->box);
362 WMResizeWidget(panel->maxiF, 205, 95);
363 WMMoveWidget(panel->maxiF, 305, 125);
364 WMSetFrameTitle(panel->maxiF, _("When maximizing..."));
366 panel->miconB = WMCreateSwitchButton(panel->maxiF);
367 WMResizeWidget(panel->miconB, 190, 30);
368 WMMoveWidget(panel->miconB, 10, 12);
369 WMSetButtonText(panel->miconB, _("...do not cover icons"));
371 panel->mdockB = WMCreateSwitchButton(panel->maxiF);
372 WMResizeWidget(panel->mdockB, 190, 30);
373 WMMoveWidget(panel->mdockB, 10, 35);
375 WMSetButtonText(panel->mdockB, _("...do not cover dock"));
377 panel->resizeS = WMCreateSlider(panel->maxiF);
378 WMResizeWidget(panel->resizeS, 50, 15);
379 WMMoveWidget(panel->resizeS, 10, 70);
380 WMSetSliderMinValue(panel->resizeS, 0);
381 WMSetSliderMaxValue(panel->resizeS, 100);
382 WMSetSliderAction(panel->resizeS, resizeCallback, panel);
384 panel->resizeL = WMCreateLabel(panel->maxiF);
385 WMResizeWidget(panel->resizeL, 30, 15);
386 WMMoveWidget(panel->resizeL, 60, 70);
388 panel->resizeTextL = WMCreateLabel(panel->maxiF);
389 WMSetLabelText(panel->resizeTextL, "Mod+Wheel\nresize increment");
390 WMResizeWidget(panel->resizeTextL, 110, 30);
391 WMMoveWidget(panel->resizeTextL, 90, 62);
393 WMMapSubwidgets(panel->maxiF);
395 /**************** Edge Resistance ****************/
397 panel->resF = WMCreateFrame(panel->box);
398 WMResizeWidget(panel->resF, 285, 45);
399 WMMoveWidget(panel->resF, 8, 125);
400 WMSetFrameTitle(panel->resF, _("Edge Resistance"));
402 WMSetBalloonTextForView(_("Edge resistance will make windows `resist'\n"
403 "being moved further for the defined threshold\n"
404 "when moved against other windows or the edges\n"
405 "of the screen."), WMWidgetView(panel->resF));
407 panel->resS = WMCreateSlider(panel->resF);
408 WMResizeWidget(panel->resS, 80, 15);
409 WMMoveWidget(panel->resS, 10, 20);
410 WMSetSliderMinValue(panel->resS, 0);
411 WMSetSliderMaxValue(panel->resS, 80);
412 WMSetSliderAction(panel->resS, resistanceCallback, panel);
414 panel->resL = WMCreateLabel(panel->resF);
415 WMResizeWidget(panel->resL, 30, 15);
416 WMMoveWidget(panel->resL, 95, 20);
418 panel->resaB = WMCreateRadioButton(panel->resF);
419 WMMoveWidget(panel->resaB, 130, 15);
420 WMResizeWidget(panel->resaB, 70, 25);
421 WMSetButtonText(panel->resaB, _("Resist"));
423 panel->resrB = WMCreateRadioButton(panel->resF);
424 WMMoveWidget(panel->resrB, 200, 15);
425 WMResizeWidget(panel->resrB, 70, 25);
426 WMSetButtonText(panel->resrB, _("Attract"));
427 WMGroupButtons(panel->resrB, panel->resaB);
429 WMMapSubwidgets(panel->resF);
431 /**************** Transients on Parent Workspace ****************/
433 panel->tranF = WMCreateFrame(panel->box);
434 WMResizeWidget(panel->tranF, 285, 40);
435 WMMoveWidget(panel->tranF, 8, 180);
437 panel->tranB = WMCreateSwitchButton(panel->tranF);
438 WMMoveWidget(panel->tranB, 10, 5);
439 WMResizeWidget(panel->tranB, 250, 30);
440 WMSetButtonText(panel->tranB, _("Open dialogs in the same workspace\nas their owners"));
442 WMMapSubwidgets(panel->tranF);
444 WMRealizeWidget(panel->box);
445 WMMapSubwidgets(panel->box);
447 /* show the config data */
448 showData(panel);
451 static void undo(_Panel * panel)
453 showData(panel);
456 Panel *InitWindowHandling(WMScreen * scr, WMWidget * parent)
458 _Panel *panel;
460 panel = wmalloc(sizeof(_Panel));
461 memset(panel, 0, sizeof(_Panel));
463 panel->sectionName = _("Window Handling Preferences");
465 panel->description = _("Window handling options. Initial placement style\n"
466 "edge resistance, opaque move etc.");
468 panel->parent = parent;
470 panel->callbacks.createWidgets = createPanel;
471 panel->callbacks.updateDomain = storeData;
472 panel->callbacks.undoChanges = undo;
474 AddSection(panel, ICON_FILE);
476 return panel;