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
;
61 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
[] = {
89 static void sliderCallback(WMWidget
* w
, void *data
)
91 _Panel
*panel
= (_Panel
*) data
;
94 int swidth
= WMGetSliderMaxValue(panel
->hsli
);
95 int sheight
= WMGetSliderMaxValue(panel
->vsli
);
97 x
= WMGetSliderValue(panel
->hsli
);
98 y
= WMGetSliderValue(panel
->vsli
);
100 rx
= x
* (WMWidgetWidth(panel
->porigF
) - 3) / swidth
+ 2;
101 ry
= y
* (WMWidgetHeight(panel
->porigF
) - 3) / sheight
+ 2;
102 WMMoveWidget(panel
->porigW
, rx
, ry
);
104 sprintf(buffer
, "(%i,%i)", x
, y
);
105 WMSetLabelText(panel
->porigvL
, buffer
);
108 static void resistanceCallback(WMWidget
* w
, void *data
)
110 _Panel
*panel
= (_Panel
*) data
;
114 i
= WMGetSliderValue(panel
->resS
);
117 WMSetLabelText(panel
->resL
, "OFF");
119 sprintf(buffer
, "%i", i
);
120 WMSetLabelText(panel
->resL
, buffer
);
124 static void resizeCallback(WMWidget
* w
, void *data
)
126 _Panel
*panel
= (_Panel
*) data
;
130 i
= WMGetSliderValue(panel
->resizeS
);
133 WMSetLabelText(panel
->resizeL
, "OFF");
135 sprintf(buffer
, "%i", i
);
136 WMSetLabelText(panel
->resizeL
, buffer
);
140 static int getPlacement(const char *str
)
145 if (strcasecmp(str
, "auto") == 0)
147 else if (strcasecmp(str
, "random") == 0)
149 else if (strcasecmp(str
, "manual") == 0)
151 else if (strcasecmp(str
, "cascade") == 0)
153 else if (strcasecmp(str
, "smart") == 0)
155 else if (strcasecmp(str
, "center") == 0)
158 wwarning(_("bad option value %s in WindowPlacement. Using default value"), str
);
162 static void showData(_Panel
* panel
)
168 str
= GetStringForKey("WindowPlacement");
170 WMSetPopUpButtonSelectedItem(panel
->placP
, getPlacement(str
));
172 arr
= GetObjectForKey("WindowPlaceOrigin");
176 if (arr
&& (!WMIsPLArray(arr
) || WMGetPropListItemCount(arr
) != 2)) {
177 wwarning(_("invalid data in option WindowPlaceOrigin. Using default (0,0)"));
180 x
= atoi(WMGetFromPLString(WMGetFromPLArray(arr
, 0)));
181 y
= atoi(WMGetFromPLString(WMGetFromPLArray(arr
, 1)));
185 WMSetSliderValue(panel
->hsli
, x
);
186 WMSetSliderValue(panel
->vsli
, y
);
188 sliderCallback(NULL
, panel
);
190 x
= GetIntegerForKey("EdgeResistance");
191 WMSetSliderValue(panel
->resS
, x
);
192 resistanceCallback(NULL
, panel
);
194 x
= GetIntegerForKey("ResizeIncrement");
195 WMSetSliderValue(panel
->resizeS
, x
);
196 resizeCallback(NULL
, panel
);
198 WMSetButtonSelected(panel
->tranB
, GetBoolForKey("OpenTransientOnOwnerWorkspace"));
200 WMSetButtonSelected(panel
->opaqB
, GetBoolForKey("OpaqueMove"));
201 WMSetButtonSelected(panel
->opaqresizeB
, GetBoolForKey("OpaqueResize"));
202 WMSetButtonSelected(panel
->opaqkeybB
, GetBoolForKey("OpaqueMoveResizeKeyboard"));
204 WMSetButtonSelected(panel
->miconB
, GetBoolForKey("NoWindowOverIcons"));
205 WMSetButtonSelected(panel
->mdockB
, GetBoolForKey("NoWindowOverDock"));
207 if (GetBoolForKey("Attraction"))
208 WMPerformButtonClick(panel
->resrB
);
210 WMPerformButtonClick(panel
->resaB
);
213 static void storeData(_Panel
* panel
)
218 SetBoolForKey(WMGetButtonSelected(panel
->miconB
), "NoWindowOverIcons");
219 SetBoolForKey(WMGetButtonSelected(panel
->mdockB
), "NoWindowOverDock");
221 SetBoolForKey(WMGetButtonSelected(panel
->opaqB
), "OpaqueMove");
222 SetBoolForKey(WMGetButtonSelected(panel
->opaqresizeB
), "OpaqueResize");
223 SetBoolForKey(WMGetButtonSelected(panel
->opaqkeybB
), "OpaqueMoveResizeKeyboard");
225 SetBoolForKey(WMGetButtonSelected(panel
->tranB
), "OpenTransientOnOwnerWorkspace");
227 SetStringForKey(placements
[WMGetPopUpButtonSelectedItem(panel
->placP
)], "WindowPlacement");
228 sprintf(x
, "%i", WMGetSliderValue(panel
->hsli
));
229 sprintf(y
, "%i", WMGetSliderValue(panel
->vsli
));
230 arr
= WMCreatePLArray(WMCreatePLString(x
), WMCreatePLString(y
), NULL
);
231 SetObjectForKey(arr
, "WindowPlaceOrigin");
233 SetIntegerForKey(WMGetSliderValue(panel
->resS
), "EdgeResistance");
235 SetIntegerForKey(WMGetSliderValue(panel
->resizeS
), "ResizeIncrement");
236 SetBoolForKey(WMGetButtonSelected(panel
->resrB
), "Attraction");
238 WMReleasePropList(arr
);
241 static void createPanel(Panel
* p
)
243 _Panel
*panel
= (Panel
*) p
;
244 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
252 panel
->box
= WMCreateBox(panel
->parent
);
253 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
254 WMSetBoxHorizontal(panel
->box
, False
);
255 WMSetBoxBorderWidth(panel
->box
, 8);
257 hbox
= WMCreateBox(panel
->box
);
258 WMSetBoxHorizontal(hbox
, True
);
259 WMAddBoxSubview(panel
->box
, WMWidgetView(hbox
), False
, True
, 110, 0, 10);
261 /************** Window Placement ***************/
262 panel
->placF
= WMCreateFrame(hbox
);
263 WMMapWidget(panel
->placF
);
264 WMAddBoxSubview(hbox
, WMWidgetView(panel
->placF
), True
, True
, 100, 0, 10);
266 WMSetFrameTitle(panel
->placF
, _("Window Placement"));
267 WMSetBalloonTextForView(_("How to place windows when they are first put\n"
268 "on screen."), WMWidgetView(panel
->placF
));
270 panel
->placP
= WMCreatePopUpButton(panel
->placF
);
271 WMResizeWidget(panel
->placP
, 105, 20);
272 WMMoveWidget(panel
->placP
, 10, 20);
273 WMAddPopUpButtonItem(panel
->placP
, _("Automatic"));
274 WMAddPopUpButtonItem(panel
->placP
, _("Random"));
275 WMAddPopUpButtonItem(panel
->placP
, _("Manual"));
276 WMAddPopUpButtonItem(panel
->placP
, _("Cascade"));
277 WMAddPopUpButtonItem(panel
->placP
, _("Smart"));
278 WMAddPopUpButtonItem(panel
->placP
, _("Center"));
280 panel
->porigL
= WMCreateLabel(panel
->placF
);
281 WMResizeWidget(panel
->porigL
, 110, 32);
282 WMMoveWidget(panel
->porigL
, 3, 45);
283 WMSetLabelTextAlignment(panel
->porigL
, WACenter
);
284 WMSetLabelText(panel
->porigL
, _("Placement Origin"));
286 panel
->porigvL
= WMCreateLabel(panel
->placF
);
287 WMResizeWidget(panel
->porigvL
, 80, 20);
288 WMMoveWidget(panel
->porigvL
, 18, 75);
289 WMSetLabelTextAlignment(panel
->porigvL
, WACenter
);
291 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
292 panel
->porigF
= WMCreateFrame(panel
->placF
);
293 WMSetWidgetBackgroundColor(panel
->porigF
, color
);
294 WMReleaseColor(color
);
295 WMSetFrameRelief(panel
->porigF
, WRSunken
);
297 swidth
= WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
298 sheight
= HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
300 if (sheight
> swidth
) {
301 width
= 70 * swidth
/ sheight
;
304 height
= 195 * sheight
/ swidth
;
306 height
= 195 * sheight
/ swidth
;
309 width
= 70 * swidth
/ sheight
;
311 WMResizeWidget(panel
->porigF
, width
, height
);
312 WMMoveWidget(panel
->porigF
, 125 + (195 - width
) / 2, 20 + (70 - height
) / 2);
314 panel
->porigW
= WMCreateLabel(panel
->porigF
);
315 WMResizeWidget(panel
->porigW
, THUMB_SIZE
, THUMB_SIZE
);
316 WMMoveWidget(panel
->porigW
, 2, 2);
317 WMSetLabelRelief(panel
->porigW
, WRRaised
);
319 panel
->hsli
= WMCreateSlider(panel
->placF
);
320 WMResizeWidget(panel
->hsli
, width
, 12);
321 WMMoveWidget(panel
->hsli
, 125 + (195 - width
) / 2, 20 + (70 - height
) / 2 + height
+ 2);
322 WMSetSliderAction(panel
->hsli
, sliderCallback
, panel
);
323 WMSetSliderMinValue(panel
->hsli
, 0);
324 WMSetSliderMaxValue(panel
->hsli
, swidth
);
326 panel
->vsli
= WMCreateSlider(panel
->placF
);
327 WMResizeWidget(panel
->vsli
, 12, height
);
328 WMMoveWidget(panel
->vsli
, 125 + (195 - width
) / 2 + width
+ 2, 20 + (70 - height
) / 2);
329 WMSetSliderAction(panel
->vsli
, sliderCallback
, panel
);
330 WMSetSliderMinValue(panel
->vsli
, 0);
331 WMSetSliderMaxValue(panel
->vsli
, sheight
);
333 WMMapSubwidgets(panel
->porigF
);
335 WMMapSubwidgets(panel
->placF
);
337 /************** Opaque Move, Resize ***************/
338 panel
->opaqF
= WMCreateFrame(hbox
);
339 WMMapWidget(panel
->opaqF
);
340 WMAddBoxSubview(hbox
, WMWidgetView(panel
->opaqF
), False
, True
, 150, 0, 0);
342 WMSetFrameTitle(panel
->opaqF
, _("Opaque Move/Resize"));
343 WMSetBalloonTextForView(_("Whether the window contents or only a frame should\n"
344 "be displayed during a move or resize.\n"),
345 WMWidgetView(panel
->opaqF
));
347 panel
->opaqB
= WMCreateButton(panel
->opaqF
, WBTToggle
);
348 WMResizeWidget(panel
->opaqB
, 48,48);
349 WMMoveWidget(panel
->opaqB
, 18, 20);
350 WMSetButtonImagePosition(panel
->opaqB
, WIPImageOnly
);
352 path
= LocateImage(NON_OPAQUE_MOVE_PIXMAP
);
354 pixmap
= WMCreatePixmapFromFile(scr
, path
);
356 WMSetButtonImage(panel
->opaqB
, pixmap
);
357 WMReleasePixmap(pixmap
);
359 wwarning(_("could not load icon %s"), path
);
364 path
= LocateImage(OPAQUE_MOVE_PIXMAP
);
366 pixmap
= WMCreatePixmapFromFile(scr
, path
);
368 WMSetButtonAltImage(panel
->opaqB
, pixmap
);
369 WMReleasePixmap(pixmap
);
371 wwarning(_("could not load icon %s"), path
);
378 panel
->opaqresizeB
= WMCreateButton(panel
->opaqF
, WBTToggle
);
379 WMResizeWidget(panel
->opaqresizeB
, 48,48);
380 WMMoveWidget(panel
->opaqresizeB
, 86, 20);
381 WMSetButtonImagePosition(panel
->opaqresizeB
, WIPImageOnly
);
383 path
= LocateImage(NON_OPAQUE_RESIZE_PIXMAP
);
385 pixmap
= WMCreatePixmapFromFile(scr
, path
);
387 WMSetButtonImage(panel
->opaqresizeB
, pixmap
);
388 WMReleasePixmap(pixmap
);
390 wwarning(_("could not load icon %s"), path
);
395 path
= LocateImage(OPAQUE_RESIZE_PIXMAP
);
397 pixmap
= WMCreatePixmapFromFile(scr
, path
);
399 WMSetButtonAltImage(panel
->opaqresizeB
, pixmap
);
400 WMReleasePixmap(pixmap
);
402 wwarning(_("could not load icon %s"), path
);
407 panel
->opaqkeybB
= WMCreateSwitchButton(panel
->opaqF
);
408 WMResizeWidget(panel
->opaqkeybB
, 100, 25);
409 WMMoveWidget(panel
->opaqkeybB
, 18, 76);
410 WMSetButtonText(panel
->opaqkeybB
, _("by keyboard"));
412 WMMapSubwidgets(panel
->opaqF
);
415 /**************** Account for Icon/Dock ***************/
416 panel
->maxiF
= WMCreateFrame(panel
->box
);
417 WMResizeWidget(panel
->maxiF
, 205, 100);
418 WMMoveWidget(panel
->maxiF
, 307, 125);
419 WMSetFrameTitle(panel
->maxiF
, _("When maximizing..."));
421 panel
->miconB
= WMCreateSwitchButton(panel
->maxiF
);
422 WMResizeWidget(panel
->miconB
, 190, 30);
423 WMMoveWidget(panel
->miconB
, 10, 14);
424 WMSetButtonText(panel
->miconB
, _("...do not cover icons"));
426 panel
->mdockB
= WMCreateSwitchButton(panel
->maxiF
);
427 WMResizeWidget(panel
->mdockB
, 190, 30);
428 WMMoveWidget(panel
->mdockB
, 10, 39);
430 WMSetButtonText(panel
->mdockB
, _("...do not cover dock"));
432 panel
->resizeS
= WMCreateSlider(panel
->maxiF
);
433 WMResizeWidget(panel
->resizeS
, 50, 15);
434 WMMoveWidget(panel
->resizeS
, 10, 74);
435 WMSetSliderMinValue(panel
->resizeS
, 0);
436 WMSetSliderMaxValue(panel
->resizeS
, 100);
437 WMSetSliderAction(panel
->resizeS
, resizeCallback
, panel
);
439 panel
->resizeL
= WMCreateLabel(panel
->maxiF
);
440 WMResizeWidget(panel
->resizeL
, 30, 15);
441 WMMoveWidget(panel
->resizeL
, 60, 74);
443 panel
->resizeTextL
= WMCreateLabel(panel
->maxiF
);
444 WMSetLabelText(panel
->resizeTextL
, "Mod+Wheel\nresize increment");
445 WMResizeWidget(panel
->resizeTextL
, 110, 30);
446 WMMoveWidget(panel
->resizeTextL
, 90, 66);
448 WMMapSubwidgets(panel
->maxiF
);
450 /**************** Edge Resistance ****************/
451 panel
->resF
= WMCreateFrame(panel
->box
);
452 WMResizeWidget(panel
->resF
, 289, 50);
453 WMMoveWidget(panel
->resF
, 8, 125);
454 WMSetFrameTitle(panel
->resF
, _("Edge Resistance"));
456 WMSetBalloonTextForView(_("Edge resistance will make windows `resist'\n"
457 "being moved further for the defined threshold\n"
458 "when moved against other windows or the edges\n"
459 "of the screen."), WMWidgetView(panel
->resF
));
461 panel
->resS
= WMCreateSlider(panel
->resF
);
462 WMResizeWidget(panel
->resS
, 80, 15);
463 WMMoveWidget(panel
->resS
, 10, 22);
464 WMSetSliderMinValue(panel
->resS
, 0);
465 WMSetSliderMaxValue(panel
->resS
, 80);
466 WMSetSliderAction(panel
->resS
, resistanceCallback
, panel
);
468 panel
->resL
= WMCreateLabel(panel
->resF
);
469 WMResizeWidget(panel
->resL
, 30, 15);
470 WMMoveWidget(panel
->resL
, 95, 22);
472 panel
->resaB
= WMCreateRadioButton(panel
->resF
);
473 WMMoveWidget(panel
->resaB
, 130, 15);
474 WMResizeWidget(panel
->resaB
, 70, 27);
475 WMSetButtonText(panel
->resaB
, _("Resist"));
477 panel
->resrB
= WMCreateRadioButton(panel
->resF
);
478 WMMoveWidget(panel
->resrB
, 200, 15);
479 WMResizeWidget(panel
->resrB
, 70, 27);
480 WMSetButtonText(panel
->resrB
, _("Attract"));
481 WMGroupButtons(panel
->resrB
, panel
->resaB
);
483 WMMapSubwidgets(panel
->resF
);
485 /**************** Transients on Parent Workspace ****************/
486 panel
->tranF
= WMCreateFrame(panel
->box
);
487 WMResizeWidget(panel
->tranF
, 289, 40);
488 WMMoveWidget(panel
->tranF
, 8, 185);
490 panel
->tranB
= WMCreateSwitchButton(panel
->tranF
);
491 WMMoveWidget(panel
->tranB
, 10, 5);
492 WMResizeWidget(panel
->tranB
, 250, 30);
493 WMSetButtonText(panel
->tranB
, _("Open dialogs in the same workspace\nas their owners"));
495 WMMapSubwidgets(panel
->tranF
);
497 WMRealizeWidget(panel
->box
);
498 WMMapSubwidgets(panel
->box
);
500 /* show the config data */
504 static void undo(_Panel
* panel
)
509 Panel
*InitWindowHandling(WMScreen
* scr
, WMWidget
* parent
)
513 panel
= wmalloc(sizeof(_Panel
));
515 panel
->sectionName
= _("Window Handling Preferences");
517 panel
->description
= _("Window handling options. Initial placement style\n"
518 "edge resistance, opaque move etc.");
520 panel
->parent
= parent
;
522 panel
->callbacks
.createWidgets
= createPanel
;
523 panel
->callbacks
.updateDomain
= storeData
;
524 panel
->callbacks
.undoChanges
= undo
;
526 AddSection(panel
, ICON_FILE
);