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
;
63 WMButton
*opaqresizeB
;
67 WMPopUpButton
*dragmaxP
;
70 #define ICON_FILE "whandling"
72 #define OPAQUE_MOVE_PIXMAP "opaque"
74 #define NON_OPAQUE_MOVE_PIXMAP "nonopaque"
76 #define OPAQUE_RESIZE_PIXMAP "opaqueresize"
78 #define NON_OPAQUE_RESIZE_PIXMAP "noopaqueresize"
80 #define PLACEMENT_WINDOW_PIXMAP "smallwindow"
87 } window_placements
[] = {
88 { "auto", N_("Automatic") },
89 { "random", N_("Random") },
90 { "manual", N_("Manual") },
91 { "cascade", N_("Cascade") },
92 { "smart", N_("Smart") },
93 { "center", N_("Center") }
99 } drag_maximized_window_options
[] = {
100 { "Move", N_("...changes its position (normal behavior)") },
101 { "RestoreGeometry", N_("...restores its unmaximized geometry") },
102 { "Unmaximize", N_("...considers the window now unmaximized") },
103 { "NoMove", N_("...does not move the window") }
106 static void sliderCallback(WMWidget
* w
, void *data
)
108 _Panel
*panel
= (_Panel
*) data
;
111 int swidth
= WMGetSliderMaxValue(panel
->hsli
);
112 int sheight
= WMGetSliderMaxValue(panel
->vsli
);
114 /* Parameter not used, but tell the compiler that it is ok */
117 x
= WMGetSliderValue(panel
->hsli
);
118 y
= WMGetSliderValue(panel
->vsli
);
120 rx
= x
* (WMWidgetWidth(panel
->porigF
) - 3) / swidth
+ 2;
121 ry
= y
* (WMWidgetHeight(panel
->porigF
) - 3) / sheight
+ 2;
122 WMMoveWidget(panel
->porigW
, rx
, ry
);
124 sprintf(buffer
, "(%i,%i)", x
, y
);
125 WMSetLabelText(panel
->porigvL
, buffer
);
128 static void resistanceCallback(WMWidget
* w
, void *data
)
130 _Panel
*panel
= (_Panel
*) data
;
134 /* Parameter not used, but tell the compiler that it is ok */
137 i
= WMGetSliderValue(panel
->resS
);
140 WMSetLabelText(panel
->resL
, _("OFF"));
142 sprintf(buffer
, "%i", i
);
143 WMSetLabelText(panel
->resL
, buffer
);
147 static void resizeCallback(WMWidget
* w
, void *data
)
149 _Panel
*panel
= (_Panel
*) data
;
153 /* Parameter not used, but tell the compiler that it is ok */
156 i
= WMGetSliderValue(panel
->resizeS
);
159 WMSetLabelText(panel
->resizeL
, _("OFF"));
161 sprintf(buffer
, "%i", i
);
162 WMSetLabelText(panel
->resizeL
, buffer
);
166 static int getPlacement(const char *str
)
173 for (i
= 0; i
< wlengthof(window_placements
); i
++) {
174 if (strcasecmp(str
, window_placements
[i
].db_value
) == 0)
178 wwarning(_("bad option value %s in WindowPlacement. Using default value"), str
);
182 static int getDragMaximizedWindow(const char *str
)
189 for (i
= 0; i
< wlengthof(drag_maximized_window_options
); i
++) {
190 if (strcasecmp(str
, drag_maximized_window_options
[i
].db_value
) == 0)
194 wwarning(_("bad option value %s in WindowPlacement. Using default value"), str
);
199 static void showData(_Panel
* panel
)
205 str
= GetStringForKey("WindowPlacement");
207 WMSetPopUpButtonSelectedItem(panel
->placP
, getPlacement(str
));
209 arr
= GetObjectForKey("WindowPlaceOrigin");
213 if (arr
&& (!WMIsPLArray(arr
) || WMGetPropListItemCount(arr
) != 2)) {
214 wwarning(_("invalid data in option WindowPlaceOrigin. Using default (0,0)"));
217 x
= atoi(WMGetFromPLString(WMGetFromPLArray(arr
, 0)));
218 y
= atoi(WMGetFromPLString(WMGetFromPLArray(arr
, 1)));
222 WMSetSliderValue(panel
->hsli
, x
);
223 WMSetSliderValue(panel
->vsli
, y
);
225 sliderCallback(NULL
, panel
);
227 x
= GetIntegerForKey("EdgeResistance");
228 WMSetSliderValue(panel
->resS
, x
);
229 resistanceCallback(NULL
, panel
);
231 str
= GetStringForKey("DragMaximizedWindow");
232 WMSetPopUpButtonSelectedItem(panel
->dragmaxP
, getDragMaximizedWindow(str
));
234 x
= GetIntegerForKey("ResizeIncrement");
235 WMSetSliderValue(panel
->resizeS
, x
);
236 resizeCallback(NULL
, panel
);
238 WMSetButtonSelected(panel
->opaqB
, GetBoolForKey("OpaqueMove"));
239 WMSetButtonSelected(panel
->opaqresizeB
, GetBoolForKey("OpaqueResize"));
240 WMSetButtonSelected(panel
->opaqkeybB
, GetBoolForKey("OpaqueMoveResizeKeyboard"));
242 WMSetButtonSelected(panel
->miconB
, GetBoolForKey("NoWindowOverIcons"));
243 WMSetButtonSelected(panel
->mdockB
, GetBoolForKey("NoWindowOverDock"));
245 if (GetBoolForKey("Attraction"))
246 WMPerformButtonClick(panel
->resrB
);
248 WMPerformButtonClick(panel
->resaB
);
251 static void storeData(_Panel
* panel
)
257 SetBoolForKey(WMGetButtonSelected(panel
->miconB
), "NoWindowOverIcons");
258 SetBoolForKey(WMGetButtonSelected(panel
->mdockB
), "NoWindowOverDock");
260 SetBoolForKey(WMGetButtonSelected(panel
->opaqB
), "OpaqueMove");
261 SetBoolForKey(WMGetButtonSelected(panel
->opaqresizeB
), "OpaqueResize");
262 SetBoolForKey(WMGetButtonSelected(panel
->opaqkeybB
), "OpaqueMoveResizeKeyboard");
264 SetStringForKey(window_placements
[WMGetPopUpButtonSelectedItem(panel
->placP
)].db_value
, "WindowPlacement");
265 sprintf(buf
, "%i", WMGetSliderValue(panel
->hsli
));
266 x
= WMCreatePLString(buf
);
267 sprintf(buf
, "%i", WMGetSliderValue(panel
->vsli
));
268 y
= WMCreatePLString(buf
);
269 arr
= WMCreatePLArray(x
, y
, NULL
);
270 WMReleasePropList(x
);
271 WMReleasePropList(y
);
272 SetObjectForKey(arr
, "WindowPlaceOrigin");
274 SetIntegerForKey(WMGetSliderValue(panel
->resS
), "EdgeResistance");
276 SetStringForKey(drag_maximized_window_options
[WMGetPopUpButtonSelectedItem(panel
->dragmaxP
)].db_value
,
277 "DragMaximizedWindow");
279 SetIntegerForKey(WMGetSliderValue(panel
->resizeS
), "ResizeIncrement");
280 SetBoolForKey(WMGetButtonSelected(panel
->resrB
), "Attraction");
282 WMReleasePropList(arr
);
285 static void createPanel(Panel
* p
)
287 _Panel
*panel
= (Panel
*) p
;
288 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
297 panel
->box
= WMCreateBox(panel
->parent
);
298 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
299 WMSetBoxHorizontal(panel
->box
, False
);
300 WMSetBoxBorderWidth(panel
->box
, 8);
302 hbox
= WMCreateBox(panel
->box
);
303 WMSetBoxHorizontal(hbox
, True
);
304 WMAddBoxSubview(panel
->box
, WMWidgetView(hbox
), False
, True
, 110, 0, 10);
306 /************** Window Placement ***************/
307 panel
->placF
= WMCreateFrame(panel
->box
);
308 WMResizeWidget(panel
->placF
, 222, 163);
309 WMMoveWidget(panel
->placF
, 8, 6);
310 WMSetFrameTitle(panel
->placF
, _("Window Placement"));
311 WMSetBalloonTextForView(_("How to place windows when they are first put\n"
312 "on screen."), WMWidgetView(panel
->placF
));
314 panel
->placP
= WMCreatePopUpButton(panel
->placF
);
315 WMResizeWidget(panel
->placP
, 90, 20);
316 WMMoveWidget(panel
->placP
, 9, 19);
318 for (i
= 0; i
< wlengthof(window_placements
); i
++)
319 WMAddPopUpButtonItem(panel
->placP
, _(window_placements
[i
].label
));
321 panel
->porigL
= WMCreateLabel(panel
->placF
);
322 WMResizeWidget(panel
->porigL
, 50, 20);
323 WMMoveWidget(panel
->porigL
, 100, 19);
324 WMSetLabelTextAlignment(panel
->porigL
, WARight
);
325 WMSetLabelText(panel
->porigL
, _("Origin:"));
327 panel
->porigvL
= WMCreateLabel(panel
->placF
);
328 WMResizeWidget(panel
->porigvL
, 69, 20);
329 WMMoveWidget(panel
->porigvL
, 150, 19);
330 WMSetLabelTextAlignment(panel
->porigvL
, WACenter
);
332 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
333 panel
->porigF
= WMCreateFrame(panel
->placF
);
334 WMSetWidgetBackgroundColor(panel
->porigF
, color
);
335 WMReleaseColor(color
);
336 WMSetFrameRelief(panel
->porigF
, WRSunken
);
339 * There is an available area of 204 x 109, starting at x=9 y=45
340 * We have to keep 12 pixels in each direction for the sliders,
341 * and an extra pixel for spacing.
342 * In this area, we want to have a rectangle with the same aspect
343 * ratio as the screen.
345 swidth
= WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
346 sheight
= HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
348 width
= swidth
* (109 - 13) / sheight
;
349 if (width
<= (204 - 13)) {
353 height
= sheight
* (204 - 13) / swidth
;
355 WMResizeWidget(panel
->porigF
, width
, height
);
356 WMMoveWidget(panel
->porigF
, 9 + (204 - 13 - width
) / 2, 45 + (109 - 13 - height
) / 2);
358 panel
->porigW
= WMCreateLabel(panel
->porigF
);
359 WMMoveWidget(panel
->porigW
, 2, 2);
360 path
= LocateImage(PLACEMENT_WINDOW_PIXMAP
);
362 pixmap
= WMCreatePixmapFromFile(scr
, path
);
366 WMSetLabelImagePosition(panel
->porigW
, WIPImageOnly
);
367 size
= WMGetPixmapSize(pixmap
);
368 WMSetLabelImage(panel
->porigW
, pixmap
);
369 WMResizeWidget(panel
->porigW
, size
.width
, size
.height
);
370 WMReleasePixmap(pixmap
);
372 wwarning(_("could not load icon %s"), path
);
376 goto use_old_window_representation
;
378 use_old_window_representation
:
379 WMResizeWidget(panel
->porigW
, THUMB_SIZE
, THUMB_SIZE
);
380 WMSetLabelRelief(panel
->porigW
, WRRaised
);
383 panel
->hsli
= WMCreateSlider(panel
->placF
);
384 WMResizeWidget(panel
->hsli
, width
, 12);
385 WMMoveWidget(panel
->hsli
, 9 + (204 - 13 - width
) / 2, 45 + (109 - 13 - height
) / 2 + height
+ 1);
386 WMSetSliderAction(panel
->hsli
, sliderCallback
, panel
);
387 WMSetSliderMinValue(panel
->hsli
, 0);
388 WMSetSliderMaxValue(panel
->hsli
, swidth
);
390 panel
->vsli
= WMCreateSlider(panel
->placF
);
391 WMResizeWidget(panel
->vsli
, 12, height
);
392 WMMoveWidget(panel
->vsli
, 9 + (204 - 13 - width
) / 2 + width
+ 1, 45 + (109 - 13 - height
) / 2);
393 WMSetSliderAction(panel
->vsli
, sliderCallback
, panel
);
394 WMSetSliderMinValue(panel
->vsli
, 0);
395 WMSetSliderMaxValue(panel
->vsli
, sheight
);
397 WMMapSubwidgets(panel
->porigF
);
399 WMMapSubwidgets(panel
->placF
);
401 /************** Opaque Move, Resize ***************/
402 panel
->opaqF
= WMCreateFrame(panel
->box
);
403 WMResizeWidget(panel
->opaqF
, 140, 118);
404 WMMoveWidget(panel
->opaqF
, 372, 103);
406 WMSetFrameTitle(panel
->opaqF
, _("Opaque Move/Resize"));
407 WMSetBalloonTextForView(_("Whether the window contents or only a frame should\n"
408 "be displayed during a move or resize.\n"),
409 WMWidgetView(panel
->opaqF
));
411 panel
->opaqB
= WMCreateButton(panel
->opaqF
, WBTToggle
);
412 WMResizeWidget(panel
->opaqB
, 54, 54);
413 WMMoveWidget(panel
->opaqB
, 11, 22);
414 WMSetButtonImagePosition(panel
->opaqB
, WIPImageOnly
);
416 path
= LocateImage(NON_OPAQUE_MOVE_PIXMAP
);
418 pixmap
= WMCreatePixmapFromFile(scr
, path
);
420 WMSetButtonImage(panel
->opaqB
, pixmap
);
421 WMReleasePixmap(pixmap
);
423 wwarning(_("could not load icon %s"), path
);
428 path
= LocateImage(OPAQUE_MOVE_PIXMAP
);
430 pixmap
= WMCreatePixmapFromFile(scr
, path
);
432 WMSetButtonAltImage(panel
->opaqB
, pixmap
);
433 WMReleasePixmap(pixmap
);
435 wwarning(_("could not load icon %s"), path
);
442 panel
->opaqresizeB
= WMCreateButton(panel
->opaqF
, WBTToggle
);
443 WMResizeWidget(panel
->opaqresizeB
, 54, 54);
444 WMMoveWidget(panel
->opaqresizeB
, 75, 22);
445 WMSetButtonImagePosition(panel
->opaqresizeB
, WIPImageOnly
);
447 path
= LocateImage(NON_OPAQUE_RESIZE_PIXMAP
);
449 pixmap
= WMCreatePixmapFromFile(scr
, path
);
451 WMSetButtonImage(panel
->opaqresizeB
, pixmap
);
452 WMReleasePixmap(pixmap
);
454 wwarning(_("could not load icon %s"), path
);
459 path
= LocateImage(OPAQUE_RESIZE_PIXMAP
);
461 pixmap
= WMCreatePixmapFromFile(scr
, path
);
463 WMSetButtonAltImage(panel
->opaqresizeB
, pixmap
);
464 WMReleasePixmap(pixmap
);
466 wwarning(_("could not load icon %s"), path
);
471 panel
->opaqkeybB
= WMCreateSwitchButton(panel
->opaqF
);
472 WMResizeWidget(panel
->opaqkeybB
, 122, 25);
473 WMMoveWidget(panel
->opaqkeybB
, 11, 85);
474 WMSetButtonText(panel
->opaqkeybB
, _("by keyboard"));
476 WMSetBalloonTextForView(_("When selected, moving or resizing windows\n"
477 "using keyboard shortcuts will also display its\n"
478 "content instead of just a frame."), WMWidgetView(panel
->opaqkeybB
));
480 WMMapSubwidgets(panel
->opaqF
);
483 /**************** Account for Icon/Dock ***************/
484 panel
->maxiF
= WMCreateFrame(panel
->box
);
485 WMResizeWidget(panel
->maxiF
, 140, 92);
486 WMMoveWidget(panel
->maxiF
, 372, 6);
487 WMSetFrameTitle(panel
->maxiF
, _("When maximizing..."));
489 panel
->maxiL
= WMCreateLabel(panel
->maxiF
);
490 WMSetLabelText(panel
->maxiL
, _("...do not cover:"));
491 WMResizeWidget(panel
->maxiL
, 120, 20);
492 WMMoveWidget(panel
->maxiL
, 10, 16);
494 panel
->miconB
= WMCreateSwitchButton(panel
->maxiF
);
495 WMResizeWidget(panel
->miconB
, 120, 25);
496 WMMoveWidget(panel
->miconB
, 10, 36);
497 WMSetButtonText(panel
->miconB
, _("Icons"));
499 panel
->mdockB
= WMCreateSwitchButton(panel
->maxiF
);
500 WMResizeWidget(panel
->mdockB
, 120, 25);
501 WMMoveWidget(panel
->mdockB
, 10, 61);
502 WMSetButtonText(panel
->mdockB
, _("The dock"));
504 WMMapSubwidgets(panel
->maxiF
);
506 /**************** Resize with Mod+Wheel ***************/
507 panel
->resizeF
= WMCreateFrame(panel
->box
);
508 WMResizeWidget(panel
->resizeF
, 127, 66);
509 WMMoveWidget(panel
->resizeF
, 238, 103);
510 WMSetFrameTitle(panel
->resizeF
, _("Mod+Wheel"));
512 panel
->resizeTextL
= WMCreateLabel(panel
->resizeF
);
513 WMSetLabelText(panel
->resizeTextL
, _("Resize increment:"));
514 WMResizeWidget(panel
->resizeTextL
, 118, 20);
515 WMMoveWidget(panel
->resizeTextL
, 5, 16);
517 panel
->resizeS
= WMCreateSlider(panel
->resizeF
);
518 WMResizeWidget(panel
->resizeS
, 80, 15);
519 WMMoveWidget(panel
->resizeS
, 9, 40);
520 WMSetSliderMinValue(panel
->resizeS
, 0);
521 WMSetSliderMaxValue(panel
->resizeS
, 100);
522 WMSetSliderAction(panel
->resizeS
, resizeCallback
, panel
);
524 panel
->resizeL
= WMCreateLabel(panel
->resizeF
);
525 WMResizeWidget(panel
->resizeL
, 30, 15);
526 WMMoveWidget(panel
->resizeL
, 90, 40);
528 WMMapSubwidgets(panel
->resizeF
);
530 /**************** Edge Resistance ****************/
531 panel
->resF
= WMCreateFrame(panel
->box
);
532 WMResizeWidget(panel
->resF
, 127, 92);
533 WMMoveWidget(panel
->resF
, 238, 6);
534 WMSetFrameTitle(panel
->resF
, _("Edge Resistance"));
536 WMSetBalloonTextForView(_("Edge resistance will make windows `resist'\n"
537 "being moved further for the defined threshold\n"
538 "when moved against other windows or the edges\n"
539 "of the screen."), WMWidgetView(panel
->resF
));
541 panel
->resS
= WMCreateSlider(panel
->resF
);
542 WMResizeWidget(panel
->resS
, 80, 15);
543 WMMoveWidget(panel
->resS
, 9, 20);
544 WMSetSliderMinValue(panel
->resS
, 0);
545 WMSetSliderMaxValue(panel
->resS
, 80);
546 WMSetSliderAction(panel
->resS
, resistanceCallback
, panel
);
548 panel
->resL
= WMCreateLabel(panel
->resF
);
549 WMResizeWidget(panel
->resL
, 30, 15);
550 WMMoveWidget(panel
->resL
, 90, 22);
552 panel
->resaB
= WMCreateRadioButton(panel
->resF
);
553 WMMoveWidget(panel
->resaB
, 9, 39);
554 WMResizeWidget(panel
->resaB
, 107, 23);
555 WMSetButtonText(panel
->resaB
, _("Resist"));
557 panel
->resrB
= WMCreateRadioButton(panel
->resF
);
558 WMMoveWidget(panel
->resrB
, 9, 62);
559 WMResizeWidget(panel
->resrB
, 107, 23);
560 WMSetButtonText(panel
->resrB
, _("Attract"));
561 WMGroupButtons(panel
->resrB
, panel
->resaB
);
563 WMMapSubwidgets(panel
->resF
);
565 /**************** Dragging a Maximized Window ****************/
566 panel
->dragmaxF
= WMCreateFrame(panel
->box
);
567 WMResizeWidget(panel
->dragmaxF
, 357, 49);
568 WMMoveWidget(panel
->dragmaxF
, 8, 172);
569 WMSetFrameTitle(panel
->dragmaxF
, _("Dragging a maximized window..."));
571 panel
->dragmaxP
= WMCreatePopUpButton(panel
->dragmaxF
);
572 WMResizeWidget(panel
->dragmaxP
, 328, 20);
573 WMMoveWidget(panel
->dragmaxP
, 15, 18);
575 for (i
= 0; i
< wlengthof(drag_maximized_window_options
); i
++)
576 WMAddPopUpButtonItem(panel
->dragmaxP
, _(drag_maximized_window_options
[i
].label
));
578 WMMapSubwidgets(panel
->dragmaxF
);
580 WMRealizeWidget(panel
->box
);
581 WMMapSubwidgets(panel
->box
);
583 /* show the config data */
587 static void undo(_Panel
* panel
)
592 Panel
*InitWindowHandling(WMWidget
*parent
)
596 panel
= wmalloc(sizeof(_Panel
));
598 panel
->sectionName
= _("Window Handling Preferences");
600 panel
->description
= _("Window handling options. Initial placement style\n"
601 "edge resistance, opaque move etc.");
603 panel
->parent
= parent
;
605 panel
->callbacks
.createWidgets
= createPanel
;
606 panel
->callbacks
.updateDomain
= storeData
;
607 panel
->callbacks
.undoChanges
= undo
;
609 AddSection(panel
, ICON_FILE
);