- Fixed compilation warnings.
[wmaker-crm.git] / WPrefs.app / WindowHandling.c
blobe27458df0a7e8603665f712559513fd3ad7c6526
1 /* WindowHandling.c- options for handling windows
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 char *description;
33 CallbackRec callbacks;
35 WMWindow *win;
37 WMFrame *placF;
38 WMPopUpButton *placP;
39 WMLabel *porigL;
40 WMLabel *porigvL;
41 WMFrame *porigF;
42 WMLabel *porigW;
44 WMSlider *vsli;
45 WMSlider *hsli;
47 WMFrame *resF;
48 WMSlider *resS;
49 WMLabel *resL;
50 WMButton *resaB;
51 WMButton *resrB;
53 WMFrame *maxiF;
54 WMButton *miconB;
55 WMButton *mdockB;
57 WMFrame *opaqF;
58 WMButton *opaqB;
60 WMFrame *tranF;
61 WMButton *tranB;
62 } _Panel;
65 #define ICON_FILE "whandling"
67 #define OPAQUE_MOVE_PIXMAP "opaque"
69 #define NON_OPAQUE_MOVE_PIXMAP "nonopaque"
72 #define THUMB_SIZE 16
75 static char *placements[] = {
76 "auto",
77 "random",
78 "manual",
79 "cascade",
80 "smart"
84 static void
85 sliderCallback(WMWidget *w, void *data)
87 _Panel *panel = (_Panel*)data;
88 int x, y, rx, ry;
89 char buffer[64];
90 int swidth = WMGetSliderMaxValue(panel->hsli);
91 int sheight = WMGetSliderMaxValue(panel->vsli);
93 x = WMGetSliderValue(panel->hsli);
94 y = WMGetSliderValue(panel->vsli);
96 rx = x*(WMWidgetWidth(panel->porigF)-3)/swidth+2;
97 ry = y*(WMWidgetHeight(panel->porigF)-3)/sheight+2;
98 WMMoveWidget(panel->porigW, rx, ry);
100 sprintf(buffer, "(%i,%i)", x, y);
101 WMSetLabelText(panel->porigvL, buffer);
106 static void
107 resistanceCallback(WMWidget *w, void *data)
109 _Panel *panel = (_Panel*)data;
110 char buffer[64];
111 int i;
113 i = WMGetSliderValue(panel->resS);
115 if (i == 0)
116 WMSetLabelText(panel->resL, "OFF");
117 else {
118 sprintf(buffer, "%i", i);
119 WMSetLabelText(panel->resL, buffer);
124 static int
125 getPlacement(char *str)
127 if (!str)
128 return 0;
130 if (strcasecmp(str, "auto")==0)
131 return 0;
132 else if (strcasecmp(str, "random")==0)
133 return 1;
134 else if (strcasecmp(str, "manual")==0)
135 return 2;
136 else if (strcasecmp(str, "cascade")==0)
137 return 3;
138 else if (strcasecmp(str, "smart")==0)
139 return 4;
140 else
141 wwarning(_("bad option value %s in WindowPlacement. Using default value"),
142 str);
143 return 0;
147 static void
148 showData(_Panel *panel)
150 char *str;
151 proplist_t arr;
152 int x, y;
154 str = GetStringForKey("WindowPlacement");
156 WMSetPopUpButtonSelectedItem(panel->placP, getPlacement(str));
158 arr = GetObjectForKey("WindowPlaceOrigin");
160 x = 0;
161 y = 0;
162 if (arr && (!PLIsArray(arr) || PLGetNumberOfElements(arr)!=2)) {
163 wwarning(_("invalid data in option WindowPlaceOrigin. Using default (0,0)"));
164 } else {
165 if (arr) {
166 x = atoi(PLGetString(PLGetArrayElement(arr, 0)));
167 y = atoi(PLGetString(PLGetArrayElement(arr, 1)));
171 WMSetSliderValue(panel->hsli, x);
172 WMSetSliderValue(panel->vsli, y);
174 sliderCallback(NULL, panel);
176 x = GetIntegerForKey("EdgeResistance");
177 WMSetSliderValue(panel->resS, x);
178 resistanceCallback(NULL, panel);
180 WMSetButtonSelected(panel->tranB, GetBoolForKey("OpenTransientOnOwnerWorkspace"));
182 WMSetButtonSelected(panel->opaqB, GetBoolForKey("OpaqueMove"));
184 WMSetButtonSelected(panel->miconB, GetBoolForKey("NoWindowOverIcons"));
186 WMSetButtonSelected(panel->mdockB, GetBoolForKey("NoWindowOverDock"));
188 if (GetBoolForKey("Attraction"))
189 WMPerformButtonClick(panel->resrB);
190 else
191 WMPerformButtonClick(panel->resaB);
195 static void
196 storeData(_Panel *panel)
198 proplist_t arr;
199 char x[16], y[16];
201 SetBoolForKey(WMGetButtonSelected(panel->miconB), "NoWindowOverIcons");
202 SetBoolForKey(WMGetButtonSelected(panel->mdockB), "NoWindowOverDock");
203 SetBoolForKey(WMGetButtonSelected(panel->opaqB), "OpaqueMove");
204 SetBoolForKey(WMGetButtonSelected(panel->tranB), "OpenTransientOnOwnerWorkspace");
205 SetStringForKey(placements[WMGetPopUpButtonSelectedItem(panel->placP)],
206 "WindowPlacement");
207 sprintf(x, "%i", WMGetSliderValue(panel->hsli));
208 sprintf(y, "%i", WMGetSliderValue(panel->vsli));
209 arr = PLMakeArrayFromElements(PLMakeString(x), PLMakeString(y), NULL);
210 SetObjectForKey(arr, "WindowPlaceOrigin");
211 SetIntegerForKey(WMGetSliderValue(panel->resS), "EdgeResistance");
212 SetBoolForKey(WMGetButtonSelected(panel->resrB), "Attraction");
213 PLRelease(arr);
217 static void
218 createPanel(Panel *p)
220 _Panel *panel = (Panel*)p;
221 WMScreen *scr = WMWidgetScreen(panel->win);
222 WMColor *color;
223 WMPixmap *pixmap;
224 int width, height;
225 int swidth, sheight;
226 char *path;
228 panel->frame = WMCreateFrame(panel->win);
229 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
230 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
232 /************** Window Placement ***************/
233 panel->placF = WMCreateFrame(panel->frame);
234 WMResizeWidget(panel->placF, 270, 110);
235 WMMoveWidget(panel->placF, 20, 10);
236 WMSetFrameTitle(panel->placF, _("Window Placement"));
237 WMSetBalloonTextForView(_("How to place windows when they are first put\n"
238 "on screen."), WMWidgetView(panel->placF));
240 panel->placP = WMCreatePopUpButton(panel->placF);
241 WMResizeWidget(panel->placP, 105, 20);
242 WMMoveWidget(panel->placP, 15, 20);
243 WMAddPopUpButtonItem(panel->placP, _("Automatic"));
244 WMAddPopUpButtonItem(panel->placP, _("Random"));
245 WMAddPopUpButtonItem(panel->placP, _("Manual"));
246 WMAddPopUpButtonItem(panel->placP, _("Cascade"));
247 WMAddPopUpButtonItem(panel->placP, _("Smart"));
249 panel->porigL = WMCreateLabel(panel->placF);
250 WMResizeWidget(panel->porigL, 120, 32);
251 WMMoveWidget(panel->porigL, 5, 45);
252 WMSetLabelTextAlignment(panel->porigL, WACenter);
253 WMSetLabelText(panel->porigL, _("Placement Origin"));
255 panel->porigvL = WMCreateLabel(panel->placF);
256 WMResizeWidget(panel->porigvL, 80, 20);
257 WMMoveWidget(panel->porigvL, 30, 75);
258 WMSetLabelTextAlignment(panel->porigvL, WACenter);
260 color = WMCreateRGBColor(scr, 0x5100, 0x5100, 0x7100, True);
261 panel->porigF = WMCreateFrame(panel->placF);
262 WMSetWidgetBackgroundColor(panel->porigF, color);
263 WMReleaseColor(color);
264 WMSetFrameRelief(panel->porigF, WRSunken);
266 swidth = WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr)));
267 sheight = HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr)));
269 if (sheight > swidth) {
270 height = 70;
271 width = 70*swidth/sheight;
272 if (width > 115)
273 width = 115;
274 height = 115*sheight/swidth;
275 } else {
276 width = 115;
277 height = 115*sheight/swidth;
278 if (height > 70)
279 height = 70;
280 width = 70*swidth/sheight;
282 WMResizeWidget(panel->porigF, width, height);
283 WMMoveWidget(panel->porigF, 130+(115-width)/2, 20+(70-height)/2);
285 panel->porigW = WMCreateLabel(panel->porigF);
286 WMResizeWidget(panel->porigW, THUMB_SIZE, THUMB_SIZE);
287 WMMoveWidget(panel->porigW, 2, 2);
288 WMSetLabelRelief(panel->porigW, WRRaised);
291 panel->hsli = WMCreateSlider(panel->placF);
292 WMResizeWidget(panel->hsli, width, 12);
293 WMMoveWidget(panel->hsli, 130+(115-width)/2, 20+(70-height)/2+height+2);
294 WMSetSliderAction(panel->hsli, sliderCallback, panel);
295 WMSetSliderMinValue(panel->hsli, 0);
296 WMSetSliderMaxValue(panel->hsli, swidth);
298 panel->vsli = WMCreateSlider(panel->placF);
299 WMResizeWidget(panel->vsli, 12, height);
300 WMMoveWidget(panel->vsli, 130+(115-width)/2+width+2, 20+(70-height)/2);
301 WMSetSliderAction(panel->vsli, sliderCallback, panel);
302 WMSetSliderMinValue(panel->vsli, 0);
303 WMSetSliderMaxValue(panel->vsli, sheight);
305 WMMapSubwidgets(panel->porigF);
307 WMMapSubwidgets(panel->placF);
309 /************** Opaque Move ***************/
310 panel->opaqF = WMCreateFrame(panel->frame);
311 WMResizeWidget(panel->opaqF, 205, 110);
312 WMMoveWidget(panel->opaqF, 300, 10);
313 WMSetFrameTitle(panel->opaqF, _("Opaque Move"));
314 WMSetBalloonTextForView(_("Whether the window contents should be moved\n"
315 "when dragging windows aroung or if only a\n"
316 "frame should be displayed.\n"),
317 WMWidgetView(panel->opaqF));
319 panel->opaqB = WMCreateButton(panel->opaqF, WBTToggle);
320 WMResizeWidget(panel->opaqB, 64, 64);
321 WMMoveWidget(panel->opaqB, 70, 25);
322 WMSetButtonImagePosition(panel->opaqB, WIPImageOnly);
324 path = LocateImage(NON_OPAQUE_MOVE_PIXMAP);
325 if (path) {
326 pixmap = WMCreatePixmapFromFile(scr, path);
327 if (pixmap) {
328 WMSetButtonImage(panel->opaqB, pixmap);
329 WMReleasePixmap(pixmap);
330 } else {
331 wwarning(_("could not load icon %s"), path);
333 free(path);
336 path = LocateImage(OPAQUE_MOVE_PIXMAP);
337 if (path) {
338 pixmap = WMCreatePixmapFromFile(scr, path);
339 if (pixmap) {
340 WMSetButtonAltImage(panel->opaqB, pixmap);
341 WMReleasePixmap(pixmap);
342 } else {
343 wwarning(_("could not load icon %s"), path);
345 free(path);
347 WMMapSubwidgets(panel->opaqF);
349 /**************** Account for Icon/Dock ***************/
350 panel->maxiF = WMCreateFrame(panel->frame);
351 WMResizeWidget(panel->maxiF, 205, 95);
352 WMMoveWidget(panel->maxiF, 300, 125);
353 WMSetFrameTitle(panel->maxiF, _("When maximizing..."));
355 panel->miconB = WMCreateSwitchButton(panel->maxiF);
356 WMResizeWidget(panel->miconB, 185, 30);
357 WMMoveWidget(panel->miconB, 10, 18);
358 WMSetButtonText(panel->miconB, _("...do not cover icons"));
360 panel->mdockB = WMCreateSwitchButton(panel->maxiF);
361 WMResizeWidget(panel->mdockB, 185, 30);
362 WMMoveWidget(panel->mdockB, 10, 53);
364 WMSetButtonText(panel->mdockB, _("...do not cover dock"));
366 WMMapSubwidgets(panel->maxiF);
368 /**************** Edge Resistance ****************/
370 panel->resF = WMCreateFrame(panel->frame);
371 WMResizeWidget(panel->resF, 270, 45);
372 WMMoveWidget(panel->resF, 20, 125);
373 WMSetFrameTitle(panel->resF, _("Edge Resistance"));
375 WMSetBalloonTextForView(_("Edge resistance will make windows `resist'\n"
376 "being moved further for the defined threshold\n"
377 "when moved against other windows or the edges\n"
378 "of the screen."), WMWidgetView(panel->resF));
380 panel->resS = WMCreateSlider(panel->resF);
381 WMResizeWidget(panel->resS, 80, 15);
382 WMMoveWidget(panel->resS, 10, 20);
383 WMSetSliderMinValue(panel->resS, 0);
384 WMSetSliderMaxValue(panel->resS, 80);
385 WMSetSliderAction(panel->resS, resistanceCallback, panel);
387 panel->resL = WMCreateLabel(panel->resF);
388 WMResizeWidget(panel->resL, 30, 15);
389 WMMoveWidget(panel->resL, 95, 20);
391 panel->resaB = WMCreateRadioButton(panel->resF);
392 WMMoveWidget(panel->resaB, 130, 12);
393 WMResizeWidget(panel->resaB, 70, 30);
394 WMSetButtonText(panel->resaB, _("Resist"));
396 panel->resrB = WMCreateRadioButton(panel->resF);
397 WMMoveWidget(panel->resrB, 200, 12);
398 WMResizeWidget(panel->resrB, 65, 30);
399 WMSetButtonText(panel->resrB, _("Attract"));
400 WMGroupButtons(panel->resrB, panel->resaB);
404 WMMapSubwidgets(panel->resF);
406 /**************** Transients on Parent Workspace ****************/
408 panel->tranF = WMCreateFrame(panel->frame);
409 WMResizeWidget(panel->tranF, 270, 40);
410 WMMoveWidget(panel->tranF, 20, 180);
412 panel->tranB = WMCreateSwitchButton(panel->tranF);
413 WMMoveWidget(panel->tranB, 10, 5);
414 WMResizeWidget(panel->tranB, 250, 30);
415 WMSetButtonText(panel->tranB, _("Open dialogs in same workspace as their owners"));
417 WMMapSubwidgets(panel->tranF);
419 WMRealizeWidget(panel->frame);
420 WMMapSubwidgets(panel->frame);
422 /* show the config data */
423 showData(panel);
427 static void
428 undo(_Panel *panel)
430 showData(panel);
434 Panel*
435 InitWindowHandling(WMScreen *scr, WMWindow *win)
437 _Panel *panel;
439 panel = wmalloc(sizeof(_Panel));
440 memset(panel, 0, sizeof(_Panel));
442 panel->sectionName = _("Window Handling Preferences");
444 panel->description = _("Window handling options. Initial placement style\n"
445 "edge resistance, opaque move etc.");
447 panel->win = win;
449 panel->callbacks.createWidgets = createPanel;
450 panel->callbacks.updateDomain = storeData;
451 panel->callbacks.undoChanges = undo;
453 AddSection(panel, ICON_FILE);
455 return panel;