Edge attraction.
[wmaker-crm.git] / WPrefs.app / WindowHandling.c
blob1c047620fe8a6b781157c1faead4421654f52600
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"
83 static void
84 sliderCallback(WMWidget *w, void *data)
86 _Panel *panel = (_Panel*)data;
87 int x, y, rx, ry;
88 char buffer[64];
89 int swidth = WMGetSliderMaxValue(panel->hsli);
90 int sheight = WMGetSliderMaxValue(panel->vsli);
92 x = WMGetSliderValue(panel->hsli);
93 y = WMGetSliderValue(panel->vsli);
95 rx = x*(WMWidgetWidth(panel->porigF)-3)/swidth+2;
96 ry = y*(WMWidgetHeight(panel->porigF)-3)/sheight+2;
97 WMMoveWidget(panel->porigW, rx, ry);
99 sprintf(buffer, "(%i,%i)", x, y);
100 WMSetLabelText(panel->porigvL, buffer);
105 static void
106 resistanceCallback(WMWidget *w, void *data)
108 _Panel *panel = (_Panel*)data;
109 char buffer[64];
110 int i;
112 i = WMGetSliderValue(panel->resS);
114 if (i == 0)
115 WMSetLabelText(panel->resL, "OFF");
116 else {
117 sprintf(buffer, "%i", i);
118 WMSetLabelText(panel->resL, buffer);
123 static int
124 getPlacement(char *str)
126 if (!str)
127 return 0;
129 if (strcasecmp(str, "auto")==0 || strcasecmp(str, "smart")==0)
130 return 0;
131 else if (strcasecmp(str, "random")==0)
132 return 1;
133 else if (strcasecmp(str, "manual")==0)
134 return 2;
135 else if (strcasecmp(str, "cascade")==0)
136 return 3;
137 else
138 wwarning(_("bad option value %s in WindowPlacement. Using default value"),
139 str);
140 return 0;
144 static void
145 showData(_Panel *panel)
147 char *str;
148 proplist_t arr;
149 int x, y;
151 str = GetStringForKey("WindowPlacement");
153 WMSetPopUpButtonSelectedItem(panel->placP, getPlacement(str));
155 arr = GetObjectForKey("WindowPlaceOrigin");
157 x = 0;
158 y = 0;
159 if (arr && (!PLIsArray(arr) || PLGetNumberOfElements(arr)!=2)) {
160 wwarning(_("invalid data in option WindowPlaceOrigin. Using default (0,0)"));
161 } else {
162 if (arr) {
163 x = atoi(PLGetString(PLGetArrayElement(arr, 0)));
164 y = atoi(PLGetString(PLGetArrayElement(arr, 1)));
168 WMSetSliderValue(panel->hsli, x);
169 WMSetSliderValue(panel->vsli, y);
171 sliderCallback(NULL, panel);
173 x = GetIntegerForKey("EdgeResistance");
174 WMSetSliderValue(panel->resS, x);
175 resistanceCallback(NULL, panel);
177 WMSetButtonSelected(panel->tranB, GetBoolForKey("OpenTransientOnOwnerWorkspace"));
179 WMSetButtonSelected(panel->opaqB, GetBoolForKey("OpaqueMove"));
181 WMSetButtonSelected(panel->miconB, GetBoolForKey("NoWindowOverIcons"));
183 WMSetButtonSelected(panel->mdockB, GetBoolForKey("NoWindowOverDock"));
185 if (GetBoolForKey("Attraction"))
186 WMPerformButtonClick(panel->resrB);
187 else
188 WMPerformButtonClick(panel->resaB);
192 static void
193 storeData(_Panel *panel)
195 proplist_t arr;
196 char x[16], y[16];
198 SetBoolForKey(WMGetButtonSelected(panel->miconB), "NoWindowOverIcons");
199 SetBoolForKey(WMGetButtonSelected(panel->mdockB), "NoWindowOverDock");
200 SetBoolForKey(WMGetButtonSelected(panel->opaqB), "OpaqueMove");
201 SetBoolForKey(WMGetButtonSelected(panel->tranB), "OpenTransientOnOwnerWorkspace");
202 SetStringForKey(placements[WMGetPopUpButtonSelectedItem(panel->placP)],
203 "WindowPlacement");
204 sprintf(x, "%i", WMGetSliderValue(panel->hsli));
205 sprintf(y, "%i", WMGetSliderValue(panel->vsli));
206 arr = PLMakeArrayFromElements(PLMakeString(x), PLMakeString(y), NULL);
207 SetObjectForKey(arr, "WindowPlaceOrigin");
208 SetIntegerForKey(WMGetSliderValue(panel->resS), "EdgeResistance");
209 SetBoolForKey(WMGetButtonSelected(panel->resrB), "Attraction");
210 PLRelease(arr);
214 static void
215 createPanel(Panel *p)
217 _Panel *panel = (Panel*)p;
218 WMScreen *scr = WMWidgetScreen(panel->win);
219 WMColor *color;
220 WMPixmap *pixmap;
221 int width, height;
222 int swidth, sheight;
223 char *path;
225 panel->frame = WMCreateFrame(panel->win);
226 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
227 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
229 /************** Window Placement ***************/
230 panel->placF = WMCreateFrame(panel->frame);
231 WMResizeWidget(panel->placF, 270, 110);
232 WMMoveWidget(panel->placF, 20, 10);
233 WMSetFrameTitle(panel->placF, _("Window Placement"));
234 WMSetBalloonTextForView(_("How to place windows when they are first put\n"
235 "on screen."), WMWidgetView(panel->placF));
237 panel->placP = WMCreatePopUpButton(panel->placF);
238 WMResizeWidget(panel->placP, 105, 20);
239 WMMoveWidget(panel->placP, 15, 20);
240 WMAddPopUpButtonItem(panel->placP, _("Automatic"));
241 WMAddPopUpButtonItem(panel->placP, _("Random"));
242 WMAddPopUpButtonItem(panel->placP, _("Manual"));
243 WMAddPopUpButtonItem(panel->placP, _("Cascade"));
245 panel->porigL = WMCreateLabel(panel->placF);
246 WMResizeWidget(panel->porigL, 120, 32);
247 WMMoveWidget(panel->porigL, 5, 45);
248 WMSetLabelTextAlignment(panel->porigL, WACenter);
249 WMSetLabelText(panel->porigL, _("Placement Origin"));
251 panel->porigvL = WMCreateLabel(panel->placF);
252 WMResizeWidget(panel->porigvL, 80, 20);
253 WMMoveWidget(panel->porigvL, 30, 75);
254 WMSetLabelTextAlignment(panel->porigvL, WACenter);
256 color = WMCreateRGBColor(scr, 0x5100, 0x5100, 0x7100, True);
257 panel->porigF = WMCreateFrame(panel->placF);
258 WMSetWidgetBackgroundColor(panel->porigF, color);
259 WMReleaseColor(color);
260 WMSetFrameRelief(panel->porigF, WRSunken);
262 swidth = WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr)));
263 sheight = HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr)));
265 if (sheight > swidth) {
266 height = 70;
267 width = 70*swidth/sheight;
268 if (width > 115)
269 width = 115;
270 height = 115*sheight/swidth;
271 } else {
272 width = 115;
273 height = 115*sheight/swidth;
274 if (height > 70)
275 height = 70;
276 width = 70*swidth/sheight;
278 WMResizeWidget(panel->porigF, width, height);
279 WMMoveWidget(panel->porigF, 130+(115-width)/2, 20+(70-height)/2);
281 panel->porigW = WMCreateLabel(panel->porigF);
282 WMResizeWidget(panel->porigW, THUMB_SIZE, THUMB_SIZE);
283 WMMoveWidget(panel->porigW, 2, 2);
284 WMSetLabelRelief(panel->porigW, WRRaised);
287 panel->hsli = WMCreateSlider(panel->placF);
288 WMResizeWidget(panel->hsli, width, 12);
289 WMMoveWidget(panel->hsli, 130+(115-width)/2, 20+(70-height)/2+height+2);
290 WMSetSliderAction(panel->hsli, sliderCallback, panel);
291 WMSetSliderMinValue(panel->hsli, 0);
292 WMSetSliderMaxValue(panel->hsli, swidth);
294 panel->vsli = WMCreateSlider(panel->placF);
295 WMResizeWidget(panel->vsli, 12, height);
296 WMMoveWidget(panel->vsli, 130+(115-width)/2+width+2, 20+(70-height)/2);
297 WMSetSliderAction(panel->vsli, sliderCallback, panel);
298 WMSetSliderMinValue(panel->vsli, 0);
299 WMSetSliderMaxValue(panel->vsli, sheight);
301 WMMapSubwidgets(panel->porigF);
303 WMMapSubwidgets(panel->placF);
305 /************** Opaque Move ***************/
306 panel->opaqF = WMCreateFrame(panel->frame);
307 WMResizeWidget(panel->opaqF, 205, 110);
308 WMMoveWidget(panel->opaqF, 300, 10);
309 WMSetFrameTitle(panel->opaqF, _("Opaque Move"));
310 WMSetBalloonTextForView(_("Whether the window contents should be moved\n"
311 "when dragging windows aroung or if only a\n"
312 "frame should be displayed.\n"),
313 WMWidgetView(panel->opaqF));
315 panel->opaqB = WMCreateButton(panel->opaqF, WBTToggle);
316 WMResizeWidget(panel->opaqB, 64, 64);
317 WMMoveWidget(panel->opaqB, 70, 25);
318 WMSetButtonImagePosition(panel->opaqB, WIPImageOnly);
320 path = LocateImage(NON_OPAQUE_MOVE_PIXMAP);
321 if (path) {
322 pixmap = WMCreatePixmapFromFile(scr, path);
323 if (pixmap) {
324 WMSetButtonImage(panel->opaqB, pixmap);
325 WMReleasePixmap(pixmap);
326 } else {
327 wwarning(_("could not load icon %s"), path);
329 free(path);
332 path = LocateImage(OPAQUE_MOVE_PIXMAP);
333 if (path) {
334 pixmap = WMCreatePixmapFromFile(scr, path);
335 if (pixmap) {
336 WMSetButtonAltImage(panel->opaqB, pixmap);
337 WMReleasePixmap(pixmap);
338 } else {
339 wwarning(_("could not load icon %s"), path);
341 free(path);
343 WMMapSubwidgets(panel->opaqF);
345 /**************** Account for Icon/Dock ***************/
346 panel->maxiF = WMCreateFrame(panel->frame);
347 WMResizeWidget(panel->maxiF, 205, 95);
348 WMMoveWidget(panel->maxiF, 300, 125);
349 WMSetFrameTitle(panel->maxiF, _("When maximizing..."));
351 panel->miconB = WMCreateSwitchButton(panel->maxiF);
352 WMResizeWidget(panel->miconB, 185, 30);
353 WMMoveWidget(panel->miconB, 10, 18);
354 WMSetButtonText(panel->miconB, _("...do not cover icons"));
356 panel->mdockB = WMCreateSwitchButton(panel->maxiF);
357 WMResizeWidget(panel->mdockB, 185, 30);
358 WMMoveWidget(panel->mdockB, 10, 53);
360 WMSetButtonText(panel->mdockB, _("...do not cover dock"));
362 WMMapSubwidgets(panel->maxiF);
364 /**************** Edge Resistance ****************/
366 panel->resF = WMCreateFrame(panel->frame);
367 WMResizeWidget(panel->resF, 270, 45);
368 WMMoveWidget(panel->resF, 20, 125);
369 WMSetFrameTitle(panel->resF, _("Edge Resistance"));
371 WMSetBalloonTextForView(_("Edge resistance will make windows `resist'\n"
372 "being moved further for the defined threshold\n"
373 "when moved against other windows or the edges\n"
374 "of the screen."), WMWidgetView(panel->resF));
376 panel->resS = WMCreateSlider(panel->resF);
377 WMResizeWidget(panel->resS, 80, 15);
378 WMMoveWidget(panel->resS, 10, 20);
379 WMSetSliderMinValue(panel->resS, 0);
380 WMSetSliderMaxValue(panel->resS, 80);
381 WMSetSliderAction(panel->resS, resistanceCallback, panel);
383 panel->resL = WMCreateLabel(panel->resF);
384 WMResizeWidget(panel->resL, 30, 15);
385 WMMoveWidget(panel->resL, 95, 20);
387 panel->resaB = WMCreateRadioButton(panel->resF);
388 WMMoveWidget(panel->resaB, 130, 12);
389 WMResizeWidget(panel->resaB, 70, 30);
390 WMSetButtonText(panel->resaB, _("Resist"));
392 panel->resrB = WMCreateRadioButton(panel->resF);
393 WMMoveWidget(panel->resrB, 200, 12);
394 WMResizeWidget(panel->resrB, 65, 30);
395 WMSetButtonText(panel->resrB, _("Attract"));
396 WMGroupButtons(panel->resrB, panel->resaB);
400 WMMapSubwidgets(panel->resF);
402 /**************** Transients on Parent Workspace ****************/
404 panel->tranF = WMCreateFrame(panel->frame);
405 WMResizeWidget(panel->tranF, 270, 40);
406 WMMoveWidget(panel->tranF, 20, 180);
408 panel->tranB = WMCreateSwitchButton(panel->tranF);
409 WMMoveWidget(panel->tranB, 10, 5);
410 WMResizeWidget(panel->tranB, 250, 30);
411 WMSetButtonText(panel->tranB, _("Open dialogs in same workspace as their owners"));
413 WMMapSubwidgets(panel->tranF);
415 WMRealizeWidget(panel->frame);
416 WMMapSubwidgets(panel->frame);
418 /* show the config data */
419 showData(panel);
423 static void
424 undo(_Panel *panel)
426 showData(panel);
430 Panel*
431 InitWindowHandling(WMScreen *scr, WMWindow *win)
433 _Panel *panel;
435 panel = wmalloc(sizeof(_Panel));
436 memset(panel, 0, sizeof(_Panel));
438 panel->sectionName = _("Window Handling Preferences");
440 panel->description = _("Window handling options. Initial placement style\n"
441 "edge resistance, opaque move etc.");
443 panel->win = win;
445 panel->callbacks.createWidgets = createPanel;
446 panel->callbacks.updateDomain = storeData;
447 panel->callbacks.undoChanges = undo;
449 AddSection(panel, ICON_FILE);
451 return panel;