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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25 typedef struct _Panel
{
32 CallbackRec callbacks
;
63 #define ICON_FILE "whandling"
65 #define OPAQUE_MOVE_PIXMAP "opaque"
67 #define NON_OPAQUE_MOVE_PIXMAP "nonopaque"
71 static char *placements
[] = {
79 static void sliderCallback(WMWidget
* w
, void *data
)
81 _Panel
*panel
= (_Panel
*) data
;
84 int swidth
= WMGetSliderMaxValue(panel
->hsli
);
85 int sheight
= WMGetSliderMaxValue(panel
->vsli
);
87 x
= WMGetSliderValue(panel
->hsli
);
88 y
= WMGetSliderValue(panel
->vsli
);
90 rx
= x
* (WMWidgetWidth(panel
->porigF
) - 3) / swidth
+ 2;
91 ry
= y
* (WMWidgetHeight(panel
->porigF
) - 3) / sheight
+ 2;
92 WMMoveWidget(panel
->porigW
, rx
, ry
);
94 sprintf(buffer
, "(%i,%i)", x
, y
);
95 WMSetLabelText(panel
->porigvL
, buffer
);
98 static void resistanceCallback(WMWidget
* w
, void *data
)
100 _Panel
*panel
= (_Panel
*) data
;
104 i
= WMGetSliderValue(panel
->resS
);
107 WMSetLabelText(panel
->resL
, "OFF");
109 sprintf(buffer
, "%i", i
);
110 WMSetLabelText(panel
->resL
, buffer
);
114 static int getPlacement(char *str
)
119 if (strcasecmp(str
, "auto") == 0)
121 else if (strcasecmp(str
, "random") == 0)
123 else if (strcasecmp(str
, "manual") == 0)
125 else if (strcasecmp(str
, "cascade") == 0)
127 else if (strcasecmp(str
, "smart") == 0)
130 wwarning(_("bad option value %s in WindowPlacement. Using default value"), str
);
134 static void showData(_Panel
* panel
)
140 str
= GetStringForKey("WindowPlacement");
142 WMSetPopUpButtonSelectedItem(panel
->placP
, getPlacement(str
));
144 arr
= GetObjectForKey("WindowPlaceOrigin");
148 if (arr
&& (!WMIsPLArray(arr
) || WMGetPropListItemCount(arr
) != 2)) {
149 wwarning(_("invalid data in option WindowPlaceOrigin. Using default (0,0)"));
152 x
= atoi(WMGetFromPLString(WMGetFromPLArray(arr
, 0)));
153 y
= atoi(WMGetFromPLString(WMGetFromPLArray(arr
, 1)));
157 WMSetSliderValue(panel
->hsli
, x
);
158 WMSetSliderValue(panel
->vsli
, y
);
160 sliderCallback(NULL
, panel
);
162 x
= GetIntegerForKey("EdgeResistance");
163 WMSetSliderValue(panel
->resS
, x
);
164 resistanceCallback(NULL
, panel
);
166 WMSetButtonSelected(panel
->tranB
, GetBoolForKey("OpenTransientOnOwnerWorkspace"));
168 WMSetButtonSelected(panel
->opaqB
, GetBoolForKey("OpaqueMove"));
170 WMSetButtonSelected(panel
->miconB
, GetBoolForKey("NoWindowOverIcons"));
172 WMSetButtonSelected(panel
->mdockB
, GetBoolForKey("NoWindowOverDock"));
174 if (GetBoolForKey("Attraction"))
175 WMPerformButtonClick(panel
->resrB
);
177 WMPerformButtonClick(panel
->resaB
);
180 static void storeData(_Panel
* panel
)
185 SetBoolForKey(WMGetButtonSelected(panel
->miconB
), "NoWindowOverIcons");
186 SetBoolForKey(WMGetButtonSelected(panel
->mdockB
), "NoWindowOverDock");
187 SetBoolForKey(WMGetButtonSelected(panel
->opaqB
), "OpaqueMove");
188 SetBoolForKey(WMGetButtonSelected(panel
->tranB
), "OpenTransientOnOwnerWorkspace");
189 SetStringForKey(placements
[WMGetPopUpButtonSelectedItem(panel
->placP
)], "WindowPlacement");
190 sprintf(x
, "%i", WMGetSliderValue(panel
->hsli
));
191 sprintf(y
, "%i", WMGetSliderValue(panel
->vsli
));
192 arr
= WMCreatePLArray(WMCreatePLString(x
), WMCreatePLString(y
), NULL
);
193 SetObjectForKey(arr
, "WindowPlaceOrigin");
194 SetIntegerForKey(WMGetSliderValue(panel
->resS
), "EdgeResistance");
195 SetBoolForKey(WMGetButtonSelected(panel
->resrB
), "Attraction");
196 WMReleasePropList(arr
);
199 static void createPanel(Panel
* p
)
201 _Panel
*panel
= (Panel
*) p
;
202 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
210 panel
->box
= WMCreateBox(panel
->parent
);
211 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
212 WMSetBoxHorizontal(panel
->box
, False
);
213 WMSetBoxBorderWidth(panel
->box
, 8);
215 hbox
= WMCreateBox(panel
->box
);
216 WMSetBoxHorizontal(hbox
, True
);
217 WMAddBoxSubview(panel
->box
, WMWidgetView(hbox
), False
, True
, 110, 0, 10);
219 /************** Window Placement ***************/
220 panel
->placF
= WMCreateFrame(hbox
);
221 WMMapWidget(panel
->placF
);
222 WMAddBoxSubview(hbox
, WMWidgetView(panel
->placF
), True
, True
, 100, 0, 10);
224 WMSetFrameTitle(panel
->placF
, _("Window Placement"));
225 WMSetBalloonTextForView(_("How to place windows when they are first put\n"
226 "on screen."), WMWidgetView(panel
->placF
));
228 panel
->placP
= WMCreatePopUpButton(panel
->placF
);
229 WMResizeWidget(panel
->placP
, 105, 20);
230 WMMoveWidget(panel
->placP
, 15, 20);
231 WMAddPopUpButtonItem(panel
->placP
, _("Automatic"));
232 WMAddPopUpButtonItem(panel
->placP
, _("Random"));
233 WMAddPopUpButtonItem(panel
->placP
, _("Manual"));
234 WMAddPopUpButtonItem(panel
->placP
, _("Cascade"));
235 WMAddPopUpButtonItem(panel
->placP
, _("Smart"));
237 panel
->porigL
= WMCreateLabel(panel
->placF
);
238 WMResizeWidget(panel
->porigL
, 120, 32);
239 WMMoveWidget(panel
->porigL
, 5, 45);
240 WMSetLabelTextAlignment(panel
->porigL
, WACenter
);
241 WMSetLabelText(panel
->porigL
, _("Placement Origin"));
243 panel
->porigvL
= WMCreateLabel(panel
->placF
);
244 WMResizeWidget(panel
->porigvL
, 80, 20);
245 WMMoveWidget(panel
->porigvL
, 30, 75);
246 WMSetLabelTextAlignment(panel
->porigvL
, WACenter
);
248 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
249 panel
->porigF
= WMCreateFrame(panel
->placF
);
250 WMSetWidgetBackgroundColor(panel
->porigF
, color
);
251 WMReleaseColor(color
);
252 WMSetFrameRelief(panel
->porigF
, WRSunken
);
254 swidth
= WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
255 sheight
= HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
257 if (sheight
> swidth
) {
259 width
= 70 * swidth
/ sheight
;
262 height
= 240 * sheight
/ swidth
;
265 height
= 240 * sheight
/ swidth
;
268 width
= 70 * swidth
/ sheight
;
270 WMResizeWidget(panel
->porigF
, width
, height
);
271 WMMoveWidget(panel
->porigF
, 130 + (240 - width
) / 2, 20 + (70 - height
) / 2);
273 panel
->porigW
= WMCreateLabel(panel
->porigF
);
274 WMResizeWidget(panel
->porigW
, THUMB_SIZE
, THUMB_SIZE
);
275 WMMoveWidget(panel
->porigW
, 2, 2);
276 WMSetLabelRelief(panel
->porigW
, WRRaised
);
278 panel
->hsli
= WMCreateSlider(panel
->placF
);
279 WMResizeWidget(panel
->hsli
, width
, 12);
280 WMMoveWidget(panel
->hsli
, 130 + (240 - width
) / 2, 20 + (70 - height
) / 2 + height
+ 2);
281 WMSetSliderAction(panel
->hsli
, sliderCallback
, panel
);
282 WMSetSliderMinValue(panel
->hsli
, 0);
283 WMSetSliderMaxValue(panel
->hsli
, swidth
);
285 panel
->vsli
= WMCreateSlider(panel
->placF
);
286 WMResizeWidget(panel
->vsli
, 12, height
);
287 WMMoveWidget(panel
->vsli
, 130 + (240 - width
) / 2 + width
+ 2, 20 + (70 - height
) / 2);
288 WMSetSliderAction(panel
->vsli
, sliderCallback
, panel
);
289 WMSetSliderMinValue(panel
->vsli
, 0);
290 WMSetSliderMaxValue(panel
->vsli
, sheight
);
292 WMMapSubwidgets(panel
->porigF
);
294 WMMapSubwidgets(panel
->placF
);
296 /************** Opaque Move ***************/
297 panel
->opaqF
= WMCreateFrame(hbox
);
298 WMMapWidget(panel
->opaqF
);
299 WMAddBoxSubview(hbox
, WMWidgetView(panel
->opaqF
), False
, True
, 110, 0, 0);
301 WMSetFrameTitle(panel
->opaqF
, _("Opaque Move"));
302 WMSetBalloonTextForView(_("Whether the window contents should be moved\n"
303 "when dragging windows aroung or if only a\n"
304 "frame should be displayed.\n"), WMWidgetView(panel
->opaqF
));
306 panel
->opaqB
= WMCreateButton(panel
->opaqF
, WBTToggle
);
307 WMResizeWidget(panel
->opaqB
, 64, 64);
308 WMMoveWidget(panel
->opaqB
, 24, 25);
309 WMSetButtonImagePosition(panel
->opaqB
, WIPImageOnly
);
311 path
= LocateImage(NON_OPAQUE_MOVE_PIXMAP
);
313 pixmap
= WMCreatePixmapFromFile(scr
, path
);
315 WMSetButtonImage(panel
->opaqB
, pixmap
);
316 WMReleasePixmap(pixmap
);
318 wwarning(_("could not load icon %s"), path
);
323 path
= LocateImage(OPAQUE_MOVE_PIXMAP
);
325 pixmap
= WMCreatePixmapFromFile(scr
, path
);
327 WMSetButtonAltImage(panel
->opaqB
, pixmap
);
328 WMReleasePixmap(pixmap
);
330 wwarning(_("could not load icon %s"), path
);
334 WMMapSubwidgets(panel
->opaqF
);
336 /**************** Account for Icon/Dock ***************/
337 panel
->maxiF
= WMCreateFrame(panel
->box
);
338 WMResizeWidget(panel
->maxiF
, 205, 95);
339 WMMoveWidget(panel
->maxiF
, 305, 125);
340 WMSetFrameTitle(panel
->maxiF
, _("When maximizing..."));
342 panel
->miconB
= WMCreateSwitchButton(panel
->maxiF
);
343 WMResizeWidget(panel
->miconB
, 190, 30);
344 WMMoveWidget(panel
->miconB
, 10, 18);
345 WMSetButtonText(panel
->miconB
, _("...do not cover icons"));
347 panel
->mdockB
= WMCreateSwitchButton(panel
->maxiF
);
348 WMResizeWidget(panel
->mdockB
, 190, 30);
349 WMMoveWidget(panel
->mdockB
, 10, 53);
351 WMSetButtonText(panel
->mdockB
, _("...do not cover dock"));
353 WMMapSubwidgets(panel
->maxiF
);
355 /**************** Edge Resistance ****************/
357 panel
->resF
= WMCreateFrame(panel
->box
);
358 WMResizeWidget(panel
->resF
, 285, 45);
359 WMMoveWidget(panel
->resF
, 8, 125);
360 WMSetFrameTitle(panel
->resF
, _("Edge Resistance"));
362 WMSetBalloonTextForView(_("Edge resistance will make windows `resist'\n"
363 "being moved further for the defined threshold\n"
364 "when moved against other windows or the edges\n"
365 "of the screen."), WMWidgetView(panel
->resF
));
367 panel
->resS
= WMCreateSlider(panel
->resF
);
368 WMResizeWidget(panel
->resS
, 80, 15);
369 WMMoveWidget(panel
->resS
, 10, 20);
370 WMSetSliderMinValue(panel
->resS
, 0);
371 WMSetSliderMaxValue(panel
->resS
, 80);
372 WMSetSliderAction(panel
->resS
, resistanceCallback
, panel
);
374 panel
->resL
= WMCreateLabel(panel
->resF
);
375 WMResizeWidget(panel
->resL
, 30, 15);
376 WMMoveWidget(panel
->resL
, 95, 20);
378 panel
->resaB
= WMCreateRadioButton(panel
->resF
);
379 WMMoveWidget(panel
->resaB
, 130, 15);
380 WMResizeWidget(panel
->resaB
, 70, 25);
381 WMSetButtonText(panel
->resaB
, _("Resist"));
383 panel
->resrB
= WMCreateRadioButton(panel
->resF
);
384 WMMoveWidget(panel
->resrB
, 200, 15);
385 WMResizeWidget(panel
->resrB
, 70, 25);
386 WMSetButtonText(panel
->resrB
, _("Attract"));
387 WMGroupButtons(panel
->resrB
, panel
->resaB
);
389 WMMapSubwidgets(panel
->resF
);
391 /**************** Transients on Parent Workspace ****************/
393 panel
->tranF
= WMCreateFrame(panel
->box
);
394 WMResizeWidget(panel
->tranF
, 285, 40);
395 WMMoveWidget(panel
->tranF
, 8, 180);
397 panel
->tranB
= WMCreateSwitchButton(panel
->tranF
);
398 WMMoveWidget(panel
->tranB
, 10, 5);
399 WMResizeWidget(panel
->tranB
, 250, 30);
400 WMSetButtonText(panel
->tranB
, _("Open dialogs in the same workspace\nas their owners"));
402 WMMapSubwidgets(panel
->tranF
);
404 WMRealizeWidget(panel
->box
);
405 WMMapSubwidgets(panel
->box
);
407 /* show the config data */
411 static void undo(_Panel
* panel
)
416 Panel
*InitWindowHandling(WMScreen
* scr
, WMWidget
* parent
)
420 panel
= wmalloc(sizeof(_Panel
));
421 memset(panel
, 0, sizeof(_Panel
));
423 panel
->sectionName
= _("Window Handling Preferences");
425 panel
->description
= _("Window handling options. Initial placement style\n"
426 "edge resistance, opaque move etc.");
428 panel
->parent
= parent
;
430 panel
->callbacks
.createWidgets
= createPanel
;
431 panel
->callbacks
.updateDomain
= storeData
;
432 panel
->callbacks
.undoChanges
= undo
;
434 AddSection(panel
, ICON_FILE
);