1 /* WindowHandling.c- options for handling windows
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 1998 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,
26 typedef struct _Panel
{
33 CallbackRec callbacks
;
65 #define ICON_FILE "whandling"
67 #define OPAQUE_MOVE_PIXMAP "opaque"
69 #define NON_OPAQUE_MOVE_PIXMAP "nonopaque"
75 static char *placements
[] = {
85 sliderCallback(WMWidget
*w
, void *data
)
87 _Panel
*panel
= (_Panel
*)data
;
90 int swidth
= WMGetSliderMaxValue(panel
->hsli
);
91 int sheight
= WMGetSliderMaxValue(panel
->vsli
);
93 x
= WMGetSliderValue(panel
->hsli
);
94 y
= WMGetSliderValue(panel
->vsli
);
96 rx
= x
*(WMWidgetWidth(panel
->porigF
)-3)/swidth
+2;
97 ry
= y
*(WMWidgetHeight(panel
->porigF
)-3)/sheight
+2;
98 WMMoveWidget(panel
->porigW
, rx
, ry
);
100 sprintf(buffer
, "(%i,%i)", x
, y
);
101 WMSetLabelText(panel
->porigvL
, buffer
);
107 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
);
125 getPlacement(char *str
)
130 if (strcasecmp(str
, "auto")==0)
132 else if (strcasecmp(str
, "random")==0)
134 else if (strcasecmp(str
, "manual")==0)
136 else if (strcasecmp(str
, "cascade")==0)
138 else if (strcasecmp(str
, "smart")==0)
141 wwarning(_("bad option value %s in WindowPlacement. Using default value"),
148 showData(_Panel
*panel
)
154 str
= GetStringForKey("WindowPlacement");
156 WMSetPopUpButtonSelectedItem(panel
->placP
, getPlacement(str
));
158 arr
= GetObjectForKey("WindowPlaceOrigin");
162 if (arr
&& (!PLIsArray(arr
) || PLGetNumberOfElements(arr
)!=2)) {
163 wwarning(_("invalid data in option WindowPlaceOrigin. Using default (0,0)"));
166 x
= atoi(PLGetString(PLGetArrayElement(arr
, 0)));
167 y
= atoi(PLGetString(PLGetArrayElement(arr
, 1)));
171 WMSetSliderValue(panel
->hsli
, x
);
172 WMSetSliderValue(panel
->vsli
, y
);
174 sliderCallback(NULL
, panel
);
176 x
= GetIntegerForKey("EdgeResistance");
177 WMSetSliderValue(panel
->resS
, x
);
178 resistanceCallback(NULL
, panel
);
180 WMSetButtonSelected(panel
->tranB
, GetBoolForKey("OpenTransientOnOwnerWorkspace"));
182 WMSetButtonSelected(panel
->opaqB
, GetBoolForKey("OpaqueMove"));
184 WMSetButtonSelected(panel
->miconB
, GetBoolForKey("NoWindowOverIcons"));
186 WMSetButtonSelected(panel
->mdockB
, GetBoolForKey("NoWindowOverDock"));
188 if (GetBoolForKey("Attraction"))
189 WMPerformButtonClick(panel
->resrB
);
191 WMPerformButtonClick(panel
->resaB
);
196 storeData(_Panel
*panel
)
201 SetBoolForKey(WMGetButtonSelected(panel
->miconB
), "NoWindowOverIcons");
202 SetBoolForKey(WMGetButtonSelected(panel
->mdockB
), "NoWindowOverDock");
203 SetBoolForKey(WMGetButtonSelected(panel
->opaqB
), "OpaqueMove");
204 SetBoolForKey(WMGetButtonSelected(panel
->tranB
), "OpenTransientOnOwnerWorkspace");
205 SetStringForKey(placements
[WMGetPopUpButtonSelectedItem(panel
->placP
)],
207 sprintf(x
, "%i", WMGetSliderValue(panel
->hsli
));
208 sprintf(y
, "%i", WMGetSliderValue(panel
->vsli
));
209 arr
= PLMakeArrayFromElements(PLMakeString(x
), PLMakeString(y
), NULL
);
210 SetObjectForKey(arr
, "WindowPlaceOrigin");
211 SetIntegerForKey(WMGetSliderValue(panel
->resS
), "EdgeResistance");
212 SetBoolForKey(WMGetButtonSelected(panel
->resrB
), "Attraction");
218 createPanel(Panel
*p
)
220 _Panel
*panel
= (Panel
*)p
;
221 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
229 panel
->box
= WMCreateBox(panel
->parent
);
230 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
231 WMSetBoxHorizontal(panel
->box
, False
);
232 WMSetBoxBorderWidth(panel
->box
, 8);
234 hbox
= WMCreateBox(panel
->box
);
235 WMSetBoxHorizontal(hbox
, True
);
236 WMAddBoxSubview(panel
->box
, WMWidgetView(hbox
), False
, True
, 110, 0, 10);
238 /************** Window Placement ***************/
239 panel
->placF
= WMCreateFrame(hbox
);
240 WMMapWidget(panel
->placF
);
241 WMAddBoxSubview(hbox
, WMWidgetView(panel
->placF
), True
, True
, 100, 0, 10);
243 WMSetFrameTitle(panel
->placF
, _("Window Placement"));
244 WMSetBalloonTextForView(_("How to place windows when they are first put\n"
245 "on screen."), WMWidgetView(panel
->placF
));
247 panel
->placP
= WMCreatePopUpButton(panel
->placF
);
248 WMResizeWidget(panel
->placP
, 105, 20);
249 WMMoveWidget(panel
->placP
, 15, 20);
250 WMAddPopUpButtonItem(panel
->placP
, _("Automatic"));
251 WMAddPopUpButtonItem(panel
->placP
, _("Random"));
252 WMAddPopUpButtonItem(panel
->placP
, _("Manual"));
253 WMAddPopUpButtonItem(panel
->placP
, _("Cascade"));
254 WMAddPopUpButtonItem(panel
->placP
, _("Smart"));
256 panel
->porigL
= WMCreateLabel(panel
->placF
);
257 WMResizeWidget(panel
->porigL
, 120, 32);
258 WMMoveWidget(panel
->porigL
, 5, 45);
259 WMSetLabelTextAlignment(panel
->porigL
, WACenter
);
260 WMSetLabelText(panel
->porigL
, _("Placement Origin"));
262 panel
->porigvL
= WMCreateLabel(panel
->placF
);
263 WMResizeWidget(panel
->porigvL
, 80, 20);
264 WMMoveWidget(panel
->porigvL
, 30, 75);
265 WMSetLabelTextAlignment(panel
->porigvL
, WACenter
);
267 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
268 panel
->porigF
= WMCreateFrame(panel
->placF
);
269 WMSetWidgetBackgroundColor(panel
->porigF
, color
);
270 WMReleaseColor(color
);
271 WMSetFrameRelief(panel
->porigF
, WRSunken
);
273 swidth
= WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
274 sheight
= HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
276 if (sheight
> swidth
) {
278 width
= 70*swidth
/sheight
;
281 height
= 240*sheight
/swidth
;
284 height
= 240*sheight
/swidth
;
287 width
= 70*swidth
/sheight
;
289 WMResizeWidget(panel
->porigF
, width
, height
);
290 WMMoveWidget(panel
->porigF
, 130+(240-width
)/2, 20+(70-height
)/2);
292 panel
->porigW
= WMCreateLabel(panel
->porigF
);
293 WMResizeWidget(panel
->porigW
, THUMB_SIZE
, THUMB_SIZE
);
294 WMMoveWidget(panel
->porigW
, 2, 2);
295 WMSetLabelRelief(panel
->porigW
, WRRaised
);
298 panel
->hsli
= WMCreateSlider(panel
->placF
);
299 WMResizeWidget(panel
->hsli
, width
, 12);
300 WMMoveWidget(panel
->hsli
, 130+(240-width
)/2, 20+(70-height
)/2+height
+2);
301 WMSetSliderAction(panel
->hsli
, sliderCallback
, panel
);
302 WMSetSliderMinValue(panel
->hsli
, 0);
303 WMSetSliderMaxValue(panel
->hsli
, swidth
);
305 panel
->vsli
= WMCreateSlider(panel
->placF
);
306 WMResizeWidget(panel
->vsli
, 12, height
);
307 WMMoveWidget(panel
->vsli
, 130+(240-width
)/2+width
+2, 20+(70-height
)/2);
308 WMSetSliderAction(panel
->vsli
, sliderCallback
, panel
);
309 WMSetSliderMinValue(panel
->vsli
, 0);
310 WMSetSliderMaxValue(panel
->vsli
, sheight
);
312 WMMapSubwidgets(panel
->porigF
);
314 WMMapSubwidgets(panel
->placF
);
316 /************** Opaque Move ***************/
317 panel
->opaqF
= WMCreateFrame(hbox
);
318 WMMapWidget(panel
->opaqF
);
319 WMAddBoxSubview(hbox
, WMWidgetView(panel
->opaqF
), False
, True
, 110, 0, 0);
321 WMSetFrameTitle(panel
->opaqF
, _("Opaque Move"));
322 WMSetBalloonTextForView(_("Whether the window contents should be moved\n"
323 "when dragging windows aroung or if only a\n"
324 "frame should be displayed.\n"),
325 WMWidgetView(panel
->opaqF
));
327 panel
->opaqB
= WMCreateButton(panel
->opaqF
, WBTToggle
);
328 WMResizeWidget(panel
->opaqB
, 64, 64);
329 WMMoveWidget(panel
->opaqB
, 24, 25);
330 WMSetButtonImagePosition(panel
->opaqB
, WIPImageOnly
);
332 path
= LocateImage(NON_OPAQUE_MOVE_PIXMAP
);
334 pixmap
= WMCreatePixmapFromFile(scr
, path
);
336 WMSetButtonImage(panel
->opaqB
, pixmap
);
337 WMReleasePixmap(pixmap
);
339 wwarning(_("could not load icon %s"), path
);
344 path
= LocateImage(OPAQUE_MOVE_PIXMAP
);
346 pixmap
= WMCreatePixmapFromFile(scr
, path
);
348 WMSetButtonAltImage(panel
->opaqB
, pixmap
);
349 WMReleasePixmap(pixmap
);
351 wwarning(_("could not load icon %s"), path
);
355 WMMapSubwidgets(panel
->opaqF
);
357 /**************** Account for Icon/Dock ***************/
358 panel
->maxiF
= WMCreateFrame(panel
->box
);
359 WMResizeWidget(panel
->maxiF
, 205, 95);
360 WMMoveWidget(panel
->maxiF
, 305, 125);
361 WMSetFrameTitle(panel
->maxiF
, _("When maximizing..."));
363 panel
->miconB
= WMCreateSwitchButton(panel
->maxiF
);
364 WMResizeWidget(panel
->miconB
, 190, 30);
365 WMMoveWidget(panel
->miconB
, 10, 18);
366 WMSetButtonText(panel
->miconB
, _("...do not cover icons"));
368 panel
->mdockB
= WMCreateSwitchButton(panel
->maxiF
);
369 WMResizeWidget(panel
->mdockB
, 190, 30);
370 WMMoveWidget(panel
->mdockB
, 10, 53);
372 WMSetButtonText(panel
->mdockB
, _("...do not cover dock"));
374 WMMapSubwidgets(panel
->maxiF
);
376 /**************** Edge Resistance ****************/
378 panel
->resF
= WMCreateFrame(panel
->box
);
379 WMResizeWidget(panel
->resF
, 285, 45);
380 WMMoveWidget(panel
->resF
, 8, 125);
381 WMSetFrameTitle(panel
->resF
, _("Edge Resistance"));
383 WMSetBalloonTextForView(_("Edge resistance will make windows `resist'\n"
384 "being moved further for the defined threshold\n"
385 "when moved against other windows or the edges\n"
386 "of the screen."), WMWidgetView(panel
->resF
));
388 panel
->resS
= WMCreateSlider(panel
->resF
);
389 WMResizeWidget(panel
->resS
, 80, 15);
390 WMMoveWidget(panel
->resS
, 10, 20);
391 WMSetSliderMinValue(panel
->resS
, 0);
392 WMSetSliderMaxValue(panel
->resS
, 80);
393 WMSetSliderAction(panel
->resS
, resistanceCallback
, panel
);
395 panel
->resL
= WMCreateLabel(panel
->resF
);
396 WMResizeWidget(panel
->resL
, 30, 15);
397 WMMoveWidget(panel
->resL
, 95, 20);
399 panel
->resaB
= WMCreateRadioButton(panel
->resF
);
400 WMMoveWidget(panel
->resaB
, 130, 14);
401 WMResizeWidget(panel
->resaB
, 70, 26);
402 WMSetButtonText(panel
->resaB
, _("Resist"));
404 panel
->resrB
= WMCreateRadioButton(panel
->resF
);
405 WMMoveWidget(panel
->resrB
, 200, 12);
406 WMResizeWidget(panel
->resrB
, 65, 30);
407 WMSetButtonText(panel
->resrB
, _("Attract"));
408 WMGroupButtons(panel
->resrB
, panel
->resaB
);
412 WMMapSubwidgets(panel
->resF
);
414 /**************** Transients on Parent Workspace ****************/
416 panel
->tranF
= WMCreateFrame(panel
->box
);
417 WMResizeWidget(panel
->tranF
, 285, 40);
418 WMMoveWidget(panel
->tranF
, 8, 180);
420 panel
->tranB
= WMCreateSwitchButton(panel
->tranF
);
421 WMMoveWidget(panel
->tranB
, 10, 5);
422 WMResizeWidget(panel
->tranB
, 250, 30);
423 WMSetButtonText(panel
->tranB
, _("Open dialogs in same workspace\nas their owners"));
425 WMMapSubwidgets(panel
->tranF
);
427 WMRealizeWidget(panel
->box
);
428 WMMapSubwidgets(panel
->box
);
430 /* show the config data */
443 InitWindowHandling(WMScreen
*scr
, WMWidget
*parent
)
447 panel
= wmalloc(sizeof(_Panel
));
448 memset(panel
, 0, sizeof(_Panel
));
450 panel
->sectionName
= _("Window Handling Preferences");
452 panel
->description
= _("Window handling options. Initial placement style\n"
453 "edge resistance, opaque move etc.");
455 panel
->parent
= parent
;
457 panel
->callbacks
.createWidgets
= createPanel
;
458 panel
->callbacks
.updateDomain
= storeData
;
459 panel
->callbacks
.undoChanges
= undo
;
461 AddSection(panel
, ICON_FILE
);