Update for 0.51.2-pre2
[wmaker-crm.git] / WPrefs.app / WindowHandling.c
blobce8ebe52a46a8362c54762461fa29834c2a45385
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 CallbackRec callbacks;
33 WMWindow *win;
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;
49 WMFrame *maxiF;
50 WMButton *miconB;
51 WMButton *mdockB;
53 WMFrame *opaqF;
54 WMButton *opaqB;
56 WMFrame *tranF;
57 WMButton *tranB;
58 } _Panel;
61 #define ICON_FILE "whandling"
63 #define OPAQUE_MOVE_PIXMAP "opaque"
65 #define NON_OPAQUE_MOVE_PIXMAP "nonopaque"
68 #define THUMB_SIZE 16
71 static char *placements[] = {
72 "auto",
73 "random",
74 "manual",
75 "cascade"
79 static void
80 sliderCallback(WMWidget *w, void *data)
82 _Panel *panel = (_Panel*)data;
83 int x, y, rx, ry;
84 char buffer[64];
85 int swidth = WMGetSliderMaxValue(panel->hsli);
86 int sheight = WMGetSliderMaxValue(panel->vsli);
88 x = WMGetSliderValue(panel->hsli);
89 y = WMGetSliderValue(panel->vsli);
91 rx = x*(WMWidgetWidth(panel->porigF)-3)/swidth+2;
92 ry = y*(WMWidgetHeight(panel->porigF)-3)/sheight+2;
93 WMMoveWidget(panel->porigW, rx, ry);
95 sprintf(buffer, "(%i,%i)", x, y);
96 WMSetLabelText(panel->porigvL, buffer);
101 static void
102 resistanceCallback(WMWidget *w, void *data)
104 _Panel *panel = (_Panel*)data;
105 char buffer[64];
106 int i;
108 i = WMGetSliderValue(panel->resS);
110 if (i == 0)
111 WMSetLabelText(panel->resL, "OFF");
112 else {
113 sprintf(buffer, "%i", i);
114 WMSetLabelText(panel->resL, buffer);
119 static int
120 getPlacement(char *str)
122 if (!str)
123 return 0;
125 if (strcasecmp(str, "auto")==0 || strcasecmp(str, "smart")==0)
126 return 0;
127 else if (strcasecmp(str, "random")==0)
128 return 1;
129 else if (strcasecmp(str, "manual")==0)
130 return 2;
131 else if (strcasecmp(str, "cascade")==0)
132 return 3;
133 else
134 wwarning(_("bad option value %s in WindowPlacement. Using default value"),
135 str);
136 return 0;
140 static void
141 showData(_Panel *panel)
143 char *str;
144 proplist_t arr;
145 int x, y;
147 str = GetStringForKey("WindowPlacement");
149 WMSetPopUpButtonSelectedItem(panel->placP, getPlacement(str));
151 arr = GetObjectForKey("WindowPlaceOrigin");
153 x = 0;
154 y = 0;
155 if (arr && (!PLIsArray(arr) || PLGetNumberOfElements(arr)!=2)) {
156 wwarning(_("invalid data in option WindowPlaceOrigin. Using default (0,0)"));
157 } else {
158 if (arr) {
159 x = atoi(PLGetString(PLGetArrayElement(arr, 0)));
160 y = atoi(PLGetString(PLGetArrayElement(arr, 1)));
164 WMSetSliderValue(panel->hsli, x);
165 WMSetSliderValue(panel->vsli, y);
167 sliderCallback(NULL, panel);
169 x = GetIntegerForKey("EdgeResistance");
170 WMSetSliderValue(panel->resS, x);
171 resistanceCallback(NULL, panel);
173 WMSetButtonSelected(panel->tranB, GetBoolForKey("OpenTransientOnOwnerWorkspace"));
175 WMSetButtonSelected(panel->opaqB, GetBoolForKey("OpaqueMove"));
177 WMSetButtonSelected(panel->miconB, GetBoolForKey("NoWindowOverIcons"));
179 WMSetButtonSelected(panel->mdockB, GetBoolForKey("NoWindowOverDock"));
183 static void
184 storeData(_Panel *panel)
186 proplist_t arr;
187 char x[16], y[16];
189 SetBoolForKey(WMGetButtonSelected(panel->miconB), "NoWindowOverIcons");
190 SetBoolForKey(WMGetButtonSelected(panel->mdockB), "NoWindowOverDock");
191 SetBoolForKey(WMGetButtonSelected(panel->opaqB), "OpaqueMove");
192 SetBoolForKey(WMGetButtonSelected(panel->tranB), "OpenTransientOnOwnerWorkspace");
193 SetStringForKey(placements[WMGetPopUpButtonSelectedItem(panel->placP)],
194 "WindowPlacement");
195 sprintf(x, "%i", WMGetSliderValue(panel->hsli));
196 sprintf(y, "%i", WMGetSliderValue(panel->vsli));
197 arr = PLMakeArrayFromElements(PLMakeString(x), PLMakeString(y), NULL);
198 SetObjectForKey(arr, "WindowPlaceOrigin");
199 SetIntegerForKey(WMGetSliderValue(panel->resS), "EdgeResistance");
200 PLRelease(arr);
204 static void
205 createPanel(Panel *p)
207 _Panel *panel = (Panel*)p;
208 WMScreen *scr = WMWidgetScreen(panel->win);
209 WMColor *color;
210 WMPixmap *pixmap;
211 int width, height;
212 int swidth, sheight;
213 char *path;
215 panel->frame = WMCreateFrame(panel->win);
216 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
217 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
219 /************** Window Placement ***************/
220 panel->placF = WMCreateFrame(panel->frame);
221 WMResizeWidget(panel->placF, 270, 110);
222 WMMoveWidget(panel->placF, 20, 10);
223 WMSetFrameTitle(panel->placF, _("Window Placement"));
225 panel->placP = WMCreatePopUpButton(panel->placF);
226 WMResizeWidget(panel->placP, 105, 20);
227 WMMoveWidget(panel->placP, 15, 20);
228 WMAddPopUpButtonItem(panel->placP, _("Automatic"));
229 WMAddPopUpButtonItem(panel->placP, _("Random"));
230 WMAddPopUpButtonItem(panel->placP, _("Manual"));
231 WMAddPopUpButtonItem(panel->placP, _("Cascade"));
233 panel->porigL = WMCreateLabel(panel->placF);
234 WMResizeWidget(panel->porigL, 120, 32);
235 WMMoveWidget(panel->porigL, 5, 45);
236 WMSetLabelTextAlignment(panel->porigL, WACenter);
237 WMSetLabelText(panel->porigL, _("Placement Origin"));
239 panel->porigvL = WMCreateLabel(panel->placF);
240 WMResizeWidget(panel->porigvL, 80, 20);
241 WMMoveWidget(panel->porigvL, 30, 75);
242 WMSetLabelTextAlignment(panel->porigvL, WACenter);
244 color = WMCreateRGBColor(scr, 0x5100, 0x5100, 0x7100, True);
245 panel->porigF = WMCreateFrame(panel->placF);
246 WMSetWidgetBackgroundColor(panel->porigF, color);
247 WMReleaseColor(color);
248 WMSetFrameRelief(panel->porigF, WRSunken);
250 swidth = WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr)));
251 sheight = HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr)));
253 if (sheight > swidth) {
254 height = 70;
255 width = 70*swidth/sheight;
256 if (width > 115)
257 width = 115;
258 height = 115*sheight/swidth;
259 } else {
260 width = 115;
261 height = 115*sheight/swidth;
262 if (height > 70)
263 height = 70;
264 width = 70*swidth/sheight;
266 WMResizeWidget(panel->porigF, width, height);
267 WMMoveWidget(panel->porigF, 130+(115-width)/2, 20+(70-height)/2);
269 panel->porigW = WMCreateLabel(panel->porigF);
270 WMResizeWidget(panel->porigW, THUMB_SIZE, THUMB_SIZE);
271 WMMoveWidget(panel->porigW, 2, 2);
272 WMSetLabelRelief(panel->porigW, WRRaised);
275 panel->hsli = WMCreateSlider(panel->placF);
276 WMResizeWidget(panel->hsli, width, 12);
277 WMMoveWidget(panel->hsli, 130+(115-width)/2, 20+(70-height)/2+height+2);
278 WMSetSliderAction(panel->hsli, sliderCallback, panel);
279 WMSetSliderMinValue(panel->hsli, 0);
280 WMSetSliderMaxValue(panel->hsli, swidth);
282 panel->vsli = WMCreateSlider(panel->placF);
283 WMResizeWidget(panel->vsli, 12, height);
284 WMMoveWidget(panel->vsli, 130+(115-width)/2+width+2, 20+(70-height)/2);
285 WMSetSliderAction(panel->vsli, sliderCallback, panel);
286 WMSetSliderMinValue(panel->vsli, 0);
287 WMSetSliderMaxValue(panel->vsli, sheight);
289 WMMapSubwidgets(panel->porigF);
291 WMMapSubwidgets(panel->placF);
293 /************** Opaque Move ***************/
294 panel->opaqF = WMCreateFrame(panel->frame);
295 WMResizeWidget(panel->opaqF, 205, 110);
296 WMMoveWidget(panel->opaqF, 300, 10);
297 WMSetFrameTitle(panel->opaqF, _("Opaque Move"));
299 panel->opaqB = WMCreateButton(panel->opaqF, WBTToggle);
300 WMResizeWidget(panel->opaqB, 64, 64);
301 WMMoveWidget(panel->opaqB, 70, 25);
302 WMSetButtonImagePosition(panel->opaqB, WIPImageOnly);
304 path = LocateImage(NON_OPAQUE_MOVE_PIXMAP);
305 if (path) {
306 pixmap = WMCreatePixmapFromFile(scr, path);
307 if (pixmap) {
308 WMSetButtonImage(panel->opaqB, pixmap);
309 WMReleasePixmap(pixmap);
310 } else {
311 wwarning(_("could not load icon %s"), path);
313 free(path);
316 path = LocateImage(OPAQUE_MOVE_PIXMAP);
317 if (path) {
318 pixmap = WMCreatePixmapFromFile(scr, path);
319 if (pixmap) {
320 WMSetButtonAltImage(panel->opaqB, pixmap);
321 WMReleasePixmap(pixmap);
322 } else {
323 wwarning(_("could not load icon %s"), path);
325 free(path);
327 WMMapSubwidgets(panel->opaqF);
329 /**************** Account for Icon/Dock ***************/
330 panel->maxiF = WMCreateFrame(panel->frame);
331 WMResizeWidget(panel->maxiF, 205, 95);
332 WMMoveWidget(panel->maxiF, 300, 125);
333 WMSetFrameTitle(panel->maxiF, _("When maximizing..."));
335 panel->miconB = WMCreateSwitchButton(panel->maxiF);
336 WMResizeWidget(panel->miconB, 185, 30);
337 WMMoveWidget(panel->miconB, 10, 18);
338 WMSetButtonText(panel->miconB, _("...do not cover icons"));
340 panel->mdockB = WMCreateSwitchButton(panel->maxiF);
341 WMResizeWidget(panel->mdockB, 185, 30);
342 WMMoveWidget(panel->mdockB, 10, 53);
344 WMSetButtonText(panel->mdockB, _("...do not cover dock"));
346 WMMapSubwidgets(panel->maxiF);
348 /**************** Edge Resistance ****************/
350 panel->resF = WMCreateFrame(panel->frame);
351 WMResizeWidget(panel->resF, 270, 45);
352 WMMoveWidget(panel->resF, 20, 125);
353 WMSetFrameTitle(panel->resF, _("Edge Resistance"));
355 panel->resS = WMCreateSlider(panel->resF);
356 WMResizeWidget(panel->resS, 200, 15);
357 WMMoveWidget(panel->resS, 10, 20);
358 WMSetSliderMinValue(panel->resS, 0);
359 WMSetSliderMaxValue(panel->resS, 200);
360 WMSetSliderAction(panel->resS, resistanceCallback, panel);
362 panel->resL = WMCreateLabel(panel->resF);
363 WMResizeWidget(panel->resL, 40, 15);
364 WMMoveWidget(panel->resL, 220, 20);
366 WMMapSubwidgets(panel->resF);
368 /**************** Transients on Parent Workspace ****************/
370 panel->tranF = WMCreateFrame(panel->frame);
371 WMResizeWidget(panel->tranF, 270, 40);
372 WMMoveWidget(panel->tranF, 20, 180);
374 panel->tranB = WMCreateSwitchButton(panel->tranF);
375 WMMoveWidget(panel->tranB, 10, 5);
376 WMResizeWidget(panel->tranB, 250, 30);
377 WMSetButtonText(panel->tranB, _("Open dialogs in same workspace as their owners"));
379 WMMapSubwidgets(panel->tranF);
381 WMRealizeWidget(panel->frame);
382 WMMapSubwidgets(panel->frame);
384 /* show the config data */
385 showData(panel);
389 static void
390 undo(_Panel *panel)
392 showData(panel);
396 Panel*
397 InitWindowHandling(WMScreen *scr, WMWindow *win)
399 _Panel *panel;
401 panel = wmalloc(sizeof(_Panel));
402 memset(panel, 0, sizeof(_Panel));
404 panel->sectionName = _("Window Handling Preferences");
406 panel->win = win;
408 panel->callbacks.createWidgets = createPanel;
409 panel->callbacks.updateDomain = storeData;
410 panel->callbacks.undoChanges = undo;
412 AddSection(panel, ICON_FILE);
414 return panel;