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.
24 typedef struct _Panel
{
31 CallbackRec callbacks
;
62 WMButton
*opaqresizeB
;
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"
80 static char *placements
[] = {
88 static void sliderCallback(WMWidget
* w
, void *data
)
90 _Panel
*panel
= (_Panel
*) data
;
93 int swidth
= WMGetSliderMaxValue(panel
->hsli
);
94 int sheight
= WMGetSliderMaxValue(panel
->vsli
);
96 x
= WMGetSliderValue(panel
->hsli
);
97 y
= WMGetSliderValue(panel
->vsli
);
99 rx
= x
* (WMWidgetWidth(panel
->porigF
) - 3) / swidth
+ 2;
100 ry
= y
* (WMWidgetHeight(panel
->porigF
) - 3) / sheight
+ 2;
101 WMMoveWidget(panel
->porigW
, rx
, ry
);
103 sprintf(buffer
, "(%i,%i)", x
, y
);
104 WMSetLabelText(panel
->porigvL
, buffer
);
107 static void resistanceCallback(WMWidget
* w
, void *data
)
109 _Panel
*panel
= (_Panel
*) data
;
113 i
= WMGetSliderValue(panel
->resS
);
116 WMSetLabelText(panel
->resL
, "OFF");
118 sprintf(buffer
, "%i", i
);
119 WMSetLabelText(panel
->resL
, buffer
);
123 static void resizeCallback(WMWidget
* w
, void *data
)
125 _Panel
*panel
= (_Panel
*) data
;
129 i
= WMGetSliderValue(panel
->resizeS
);
132 WMSetLabelText(panel
->resizeL
, "OFF");
134 sprintf(buffer
, "%i", i
);
135 WMSetLabelText(panel
->resizeL
, buffer
);
139 static int getPlacement(char *str
)
144 if (strcasecmp(str
, "auto") == 0)
146 else if (strcasecmp(str
, "random") == 0)
148 else if (strcasecmp(str
, "manual") == 0)
150 else if (strcasecmp(str
, "cascade") == 0)
152 else if (strcasecmp(str
, "smart") == 0)
155 wwarning(_("bad option value %s in WindowPlacement. Using default value"), str
);
159 static void showData(_Panel
* panel
)
165 str
= GetStringForKey("WindowPlacement");
167 WMSetPopUpButtonSelectedItem(panel
->placP
, getPlacement(str
));
169 arr
= GetObjectForKey("WindowPlaceOrigin");
173 if (arr
&& (!WMIsPLArray(arr
) || WMGetPropListItemCount(arr
) != 2)) {
174 wwarning(_("invalid data in option WindowPlaceOrigin. Using default (0,0)"));
177 x
= atoi(WMGetFromPLString(WMGetFromPLArray(arr
, 0)));
178 y
= atoi(WMGetFromPLString(WMGetFromPLArray(arr
, 1)));
182 WMSetSliderValue(panel
->hsli
, x
);
183 WMSetSliderValue(panel
->vsli
, y
);
185 sliderCallback(NULL
, panel
);
187 x
= GetIntegerForKey("EdgeResistance");
188 WMSetSliderValue(panel
->resS
, x
);
189 resistanceCallback(NULL
, panel
);
191 x
= GetIntegerForKey("ResizeIncrement");
192 WMSetSliderValue(panel
->resizeS
, x
);
193 resizeCallback(NULL
, panel
);
195 WMSetButtonSelected(panel
->tranB
, GetBoolForKey("OpenTransientOnOwnerWorkspace"));
197 WMSetButtonSelected(panel
->opaqB
, GetBoolForKey("OpaqueMove"));
199 WMSetButtonSelected(panel
->opaqresizeB
, GetBoolForKey("OpaqueResize"));
201 WMSetButtonSelected(panel
->miconB
, GetBoolForKey("NoWindowOverIcons"));
203 WMSetButtonSelected(panel
->mdockB
, GetBoolForKey("NoWindowOverDock"));
205 if (GetBoolForKey("Attraction"))
206 WMPerformButtonClick(panel
->resrB
);
208 WMPerformButtonClick(panel
->resaB
);
211 static void storeData(_Panel
* panel
)
216 SetBoolForKey(WMGetButtonSelected(panel
->miconB
), "NoWindowOverIcons");
217 SetBoolForKey(WMGetButtonSelected(panel
->mdockB
), "NoWindowOverDock");
218 SetBoolForKey(WMGetButtonSelected(panel
->opaqB
), "OpaqueMove");
219 SetBoolForKey(WMGetButtonSelected(panel
->opaqresizeB
), "OpaqueResize");
220 SetBoolForKey(WMGetButtonSelected(panel
->tranB
), "OpenTransientOnOwnerWorkspace");
221 SetStringForKey(placements
[WMGetPopUpButtonSelectedItem(panel
->placP
)], "WindowPlacement");
222 sprintf(x
, "%i", WMGetSliderValue(panel
->hsli
));
223 sprintf(y
, "%i", WMGetSliderValue(panel
->vsli
));
224 arr
= WMCreatePLArray(WMCreatePLString(x
), WMCreatePLString(y
), NULL
);
225 SetObjectForKey(arr
, "WindowPlaceOrigin");
226 SetIntegerForKey(WMGetSliderValue(panel
->resS
), "EdgeResistance");
227 SetIntegerForKey(WMGetSliderValue(panel
->resizeS
), "ResizeIncrement");
228 SetBoolForKey(WMGetButtonSelected(panel
->resrB
), "Attraction");
229 WMReleasePropList(arr
);
232 static void createPanel(Panel
* p
)
234 _Panel
*panel
= (Panel
*) p
;
235 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
243 panel
->box
= WMCreateBox(panel
->parent
);
244 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
245 WMSetBoxHorizontal(panel
->box
, False
);
246 WMSetBoxBorderWidth(panel
->box
, 8);
248 hbox
= WMCreateBox(panel
->box
);
249 WMSetBoxHorizontal(hbox
, True
);
250 WMAddBoxSubview(panel
->box
, WMWidgetView(hbox
), False
, True
, 110, 0, 10);
252 /************** Window Placement ***************/
253 panel
->placF
= WMCreateFrame(hbox
);
254 WMMapWidget(panel
->placF
);
255 WMAddBoxSubview(hbox
, WMWidgetView(panel
->placF
), True
, True
, 100, 0, 10);
257 WMSetFrameTitle(panel
->placF
, _("Window Placement"));
258 WMSetBalloonTextForView(_("How to place windows when they are first put\n"
259 "on screen."), WMWidgetView(panel
->placF
));
261 panel
->placP
= WMCreatePopUpButton(panel
->placF
);
262 WMResizeWidget(panel
->placP
, 105, 20);
263 WMMoveWidget(panel
->placP
, 15, 20);
264 WMAddPopUpButtonItem(panel
->placP
, _("Automatic"));
265 WMAddPopUpButtonItem(panel
->placP
, _("Random"));
266 WMAddPopUpButtonItem(panel
->placP
, _("Manual"));
267 WMAddPopUpButtonItem(panel
->placP
, _("Cascade"));
268 WMAddPopUpButtonItem(panel
->placP
, _("Smart"));
270 panel
->porigL
= WMCreateLabel(panel
->placF
);
271 WMResizeWidget(panel
->porigL
, 120, 32);
272 WMMoveWidget(panel
->porigL
, 5, 45);
273 WMSetLabelTextAlignment(panel
->porigL
, WACenter
);
274 WMSetLabelText(panel
->porigL
, _("Placement Origin"));
276 panel
->porigvL
= WMCreateLabel(panel
->placF
);
277 WMResizeWidget(panel
->porigvL
, 80, 20);
278 WMMoveWidget(panel
->porigvL
, 30, 75);
279 WMSetLabelTextAlignment(panel
->porigvL
, WACenter
);
281 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
282 panel
->porigF
= WMCreateFrame(panel
->placF
);
283 WMSetWidgetBackgroundColor(panel
->porigF
, color
);
284 WMReleaseColor(color
);
285 WMSetFrameRelief(panel
->porigF
, WRSunken
);
287 swidth
= WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
288 sheight
= HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
290 if (sheight
> swidth
) {
292 width
= 70 * swidth
/ sheight
;
295 height
= 240 * sheight
/ swidth
;
298 height
= 240 * sheight
/ swidth
;
301 width
= 70 * swidth
/ sheight
;
303 WMResizeWidget(panel
->porigF
, width
, height
);
304 WMMoveWidget(panel
->porigF
, 130 + (240 - width
) / 2, 20 + (70 - height
) / 2);
306 panel
->porigW
= WMCreateLabel(panel
->porigF
);
307 WMResizeWidget(panel
->porigW
, THUMB_SIZE
, THUMB_SIZE
);
308 WMMoveWidget(panel
->porigW
, 2, 2);
309 WMSetLabelRelief(panel
->porigW
, WRRaised
);
311 panel
->hsli
= WMCreateSlider(panel
->placF
);
312 WMResizeWidget(panel
->hsli
, width
, 12);
313 WMMoveWidget(panel
->hsli
, 130 + (240 - width
) / 2, 20 + (70 - height
) / 2 + height
+ 2);
314 WMSetSliderAction(panel
->hsli
, sliderCallback
, panel
);
315 WMSetSliderMinValue(panel
->hsli
, 0);
316 WMSetSliderMaxValue(panel
->hsli
, swidth
);
318 panel
->vsli
= WMCreateSlider(panel
->placF
);
319 WMResizeWidget(panel
->vsli
, 12, height
);
320 WMMoveWidget(panel
->vsli
, 130 + (240 - width
) / 2 + width
+ 2, 20 + (70 - height
) / 2);
321 WMSetSliderAction(panel
->vsli
, sliderCallback
, panel
);
322 WMSetSliderMinValue(panel
->vsli
, 0);
323 WMSetSliderMaxValue(panel
->vsli
, sheight
);
325 WMMapSubwidgets(panel
->porigF
);
327 WMMapSubwidgets(panel
->placF
);
329 /************** Opaque Move, Resize ***************/
330 panel
->opaqF
= WMCreateFrame(hbox
);
331 WMMapWidget(panel
->opaqF
);
332 WMAddBoxSubview(hbox
, WMWidgetView(panel
->opaqF
), False
, True
, 122, 0, 0);
334 WMSetFrameTitle(panel
->opaqF
, _("Opaque Move/Resize"));
335 WMSetBalloonTextForView(_("Whether the window contents or only a frame should\n"
336 "be displayed during a move or resize.\n"),
337 WMWidgetView(panel
->opaqF
));
339 panel
->opaqB
= WMCreateButton(panel
->opaqF
, WBTToggle
);
340 WMResizeWidget(panel
->opaqB
, 48,48);
341 WMMoveWidget(panel
->opaqB
, 7, 35);
342 WMSetButtonImagePosition(panel
->opaqB
, WIPImageOnly
);
344 path
= LocateImage(NON_OPAQUE_MOVE_PIXMAP
);
346 pixmap
= WMCreatePixmapFromFile(scr
, path
);
348 WMSetButtonImage(panel
->opaqB
, pixmap
);
349 WMReleasePixmap(pixmap
);
351 wwarning(_("could not load icon %s"), path
);
356 path
= LocateImage(OPAQUE_MOVE_PIXMAP
);
358 pixmap
= WMCreatePixmapFromFile(scr
, path
);
360 WMSetButtonAltImage(panel
->opaqB
, pixmap
);
361 WMReleasePixmap(pixmap
);
363 wwarning(_("could not load icon %s"), path
);
370 panel
->opaqresizeB
= WMCreateButton(panel
->opaqF
, WBTToggle
);
371 WMResizeWidget(panel
->opaqresizeB
, 48,48);
372 WMMoveWidget(panel
->opaqresizeB
, 65, 35);
373 WMSetButtonImagePosition(panel
->opaqresizeB
, WIPImageOnly
);
375 path
= LocateImage(NON_OPAQUE_RESIZE_PIXMAP
);
377 pixmap
= WMCreatePixmapFromFile(scr
, path
);
379 WMSetButtonImage(panel
->opaqresizeB
, pixmap
);
380 WMReleasePixmap(pixmap
);
382 wwarning(_("could not load icon %s"), path
);
387 path
= LocateImage(OPAQUE_RESIZE_PIXMAP
);
389 pixmap
= WMCreatePixmapFromFile(scr
, path
);
391 WMSetButtonAltImage(panel
->opaqresizeB
, pixmap
);
392 WMReleasePixmap(pixmap
);
394 wwarning(_("could not load icon %s"), path
);
399 WMMapSubwidgets(panel
->opaqF
);
402 /**************** Account for Icon/Dock ***************/
403 panel
->maxiF
= WMCreateFrame(panel
->box
);
404 WMResizeWidget(panel
->maxiF
, 205, 95);
405 WMMoveWidget(panel
->maxiF
, 305, 125);
406 WMSetFrameTitle(panel
->maxiF
, _("When maximizing..."));
408 panel
->miconB
= WMCreateSwitchButton(panel
->maxiF
);
409 WMResizeWidget(panel
->miconB
, 190, 30);
410 WMMoveWidget(panel
->miconB
, 10, 12);
411 WMSetButtonText(panel
->miconB
, _("...do not cover icons"));
413 panel
->mdockB
= WMCreateSwitchButton(panel
->maxiF
);
414 WMResizeWidget(panel
->mdockB
, 190, 30);
415 WMMoveWidget(panel
->mdockB
, 10, 35);
417 WMSetButtonText(panel
->mdockB
, _("...do not cover dock"));
419 panel
->resizeS
= WMCreateSlider(panel
->maxiF
);
420 WMResizeWidget(panel
->resizeS
, 50, 15);
421 WMMoveWidget(panel
->resizeS
, 10, 70);
422 WMSetSliderMinValue(panel
->resizeS
, 0);
423 WMSetSliderMaxValue(panel
->resizeS
, 100);
424 WMSetSliderAction(panel
->resizeS
, resizeCallback
, panel
);
426 panel
->resizeL
= WMCreateLabel(panel
->maxiF
);
427 WMResizeWidget(panel
->resizeL
, 30, 15);
428 WMMoveWidget(panel
->resizeL
, 60, 70);
430 panel
->resizeTextL
= WMCreateLabel(panel
->maxiF
);
431 WMSetLabelText(panel
->resizeTextL
, "Mod+Wheel\nresize increment");
432 WMResizeWidget(panel
->resizeTextL
, 110, 30);
433 WMMoveWidget(panel
->resizeTextL
, 90, 62);
435 WMMapSubwidgets(panel
->maxiF
);
437 /**************** Edge Resistance ****************/
439 panel
->resF
= WMCreateFrame(panel
->box
);
440 WMResizeWidget(panel
->resF
, 285, 45);
441 WMMoveWidget(panel
->resF
, 8, 125);
442 WMSetFrameTitle(panel
->resF
, _("Edge Resistance"));
444 WMSetBalloonTextForView(_("Edge resistance will make windows `resist'\n"
445 "being moved further for the defined threshold\n"
446 "when moved against other windows or the edges\n"
447 "of the screen."), WMWidgetView(panel
->resF
));
449 panel
->resS
= WMCreateSlider(panel
->resF
);
450 WMResizeWidget(panel
->resS
, 80, 15);
451 WMMoveWidget(panel
->resS
, 10, 20);
452 WMSetSliderMinValue(panel
->resS
, 0);
453 WMSetSliderMaxValue(panel
->resS
, 80);
454 WMSetSliderAction(panel
->resS
, resistanceCallback
, panel
);
456 panel
->resL
= WMCreateLabel(panel
->resF
);
457 WMResizeWidget(panel
->resL
, 30, 15);
458 WMMoveWidget(panel
->resL
, 95, 20);
460 panel
->resaB
= WMCreateRadioButton(panel
->resF
);
461 WMMoveWidget(panel
->resaB
, 130, 15);
462 WMResizeWidget(panel
->resaB
, 70, 25);
463 WMSetButtonText(panel
->resaB
, _("Resist"));
465 panel
->resrB
= WMCreateRadioButton(panel
->resF
);
466 WMMoveWidget(panel
->resrB
, 200, 15);
467 WMResizeWidget(panel
->resrB
, 70, 25);
468 WMSetButtonText(panel
->resrB
, _("Attract"));
469 WMGroupButtons(panel
->resrB
, panel
->resaB
);
471 WMMapSubwidgets(panel
->resF
);
473 /**************** Transients on Parent Workspace ****************/
475 panel
->tranF
= WMCreateFrame(panel
->box
);
476 WMResizeWidget(panel
->tranF
, 285, 40);
477 WMMoveWidget(panel
->tranF
, 8, 180);
479 panel
->tranB
= WMCreateSwitchButton(panel
->tranF
);
480 WMMoveWidget(panel
->tranB
, 10, 5);
481 WMResizeWidget(panel
->tranB
, 250, 30);
482 WMSetButtonText(panel
->tranB
, _("Open dialogs in the same workspace\nas their owners"));
484 WMMapSubwidgets(panel
->tranF
);
486 WMRealizeWidget(panel
->box
);
487 WMMapSubwidgets(panel
->box
);
489 /* show the config data */
493 static void undo(_Panel
* panel
)
498 Panel
*InitWindowHandling(WMScreen
* scr
, WMWidget
* parent
)
502 panel
= wmalloc(sizeof(_Panel
));
503 memset(panel
, 0, sizeof(_Panel
));
505 panel
->sectionName
= _("Window Handling Preferences");
507 panel
->description
= _("Window handling options. Initial placement style\n"
508 "edge resistance, opaque move etc.");
510 panel
->parent
= parent
;
512 panel
->callbacks
.createWidgets
= createPanel
;
513 panel
->callbacks
.updateDomain
= storeData
;
514 panel
->callbacks
.undoChanges
= undo
;
516 AddSection(panel
, ICON_FILE
);