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
{
31 CallbackRec callbacks
;
61 #define ICON_FILE "whandling"
63 #define OPAQUE_MOVE_PIXMAP "opaque"
65 #define NON_OPAQUE_MOVE_PIXMAP "nonopaque"
71 static char *placements
[] = {
80 sliderCallback(WMWidget
*w
, void *data
)
82 _Panel
*panel
= (_Panel
*)data
;
85 int swidth
= WMGetSliderMaxValue(panel
->hsli
);
86 int sheight
= WMGetSliderMaxValue(panel
->vsli
);
88 x
= WMGetSliderValue(panel
->hsli
);
89 y
= WMGetSliderValue(panel
->vsli
);
91 rx
= x
*(WMWidgetWidth(panel
->porigF
)-3)/swidth
+2;
92 ry
= y
*(WMWidgetHeight(panel
->porigF
)-3)/sheight
+2;
93 WMMoveWidget(panel
->porigW
, rx
, ry
);
95 sprintf(buffer
, "(%i,%i)", x
, y
);
96 WMSetLabelText(panel
->porigvL
, buffer
);
102 resistanceCallback(WMWidget
*w
, void *data
)
104 _Panel
*panel
= (_Panel
*)data
;
108 i
= WMGetSliderValue(panel
->resS
);
111 WMSetLabelText(panel
->resL
, "OFF");
113 sprintf(buffer
, "%i", i
);
114 WMSetLabelText(panel
->resL
, buffer
);
120 getPlacement(char *str
)
125 if (strcasecmp(str
, "auto")==0 || strcasecmp(str
, "smart")==0)
127 else if (strcasecmp(str
, "random")==0)
129 else if (strcasecmp(str
, "manual")==0)
131 else if (strcasecmp(str
, "cascade")==0)
134 wwarning(_("bad option value %s in WindowPlacement. Using default value"),
141 showData(_Panel
*panel
)
147 str
= GetStringForKey("WindowPlacement");
149 WMSetPopUpButtonSelectedItem(panel
->placP
, getPlacement(str
));
151 arr
= GetObjectForKey("WindowPlaceOrigin");
155 if (arr
&& (!PLIsArray(arr
) || PLGetNumberOfElements(arr
)!=2)) {
156 wwarning(_("invalid data in option WindowPlaceOrigin. Using default (0,0)"));
159 x
= atoi(PLGetString(PLGetArrayElement(arr
, 0)));
160 y
= atoi(PLGetString(PLGetArrayElement(arr
, 1)));
164 WMSetSliderValue(panel
->hsli
, x
);
165 WMSetSliderValue(panel
->vsli
, y
);
167 sliderCallback(NULL
, panel
);
169 x
= GetIntegerForKey("EdgeResistance");
170 WMSetSliderValue(panel
->resS
, x
);
171 resistanceCallback(NULL
, panel
);
173 WMSetButtonSelected(panel
->tranB
, GetBoolForKey("OpenTransientOnOwnerWorkspace"));
175 WMSetButtonSelected(panel
->opaqB
, GetBoolForKey("OpaqueMove"));
177 WMSetButtonSelected(panel
->miconB
, GetBoolForKey("NoWindowOverIcons"));
179 WMSetButtonSelected(panel
->mdockB
, GetBoolForKey("NoWindowOverDock"));
184 storeData(_Panel
*panel
)
189 SetBoolForKey(WMGetButtonSelected(panel
->miconB
), "NoWindowOverIcons");
190 SetBoolForKey(WMGetButtonSelected(panel
->mdockB
), "NoWindowOverDock");
191 SetBoolForKey(WMGetButtonSelected(panel
->opaqB
), "OpaqueMove");
192 SetBoolForKey(WMGetButtonSelected(panel
->tranB
), "OpenTransientOnOwnerWorkspace");
193 SetStringForKey(placements
[WMGetPopUpButtonSelectedItem(panel
->placP
)],
195 sprintf(x
, "%i", WMGetSliderValue(panel
->hsli
));
196 sprintf(y
, "%i", WMGetSliderValue(panel
->vsli
));
197 arr
= PLMakeArrayFromElements(PLMakeString(x
), PLMakeString(y
), NULL
);
198 SetObjectForKey(arr
, "WindowPlaceOrigin");
199 SetIntegerForKey(WMGetSliderValue(panel
->resS
), "EdgeResistance");
205 createPanel(Panel
*p
)
207 _Panel
*panel
= (Panel
*)p
;
208 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
215 panel
->frame
= WMCreateFrame(panel
->win
);
216 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
217 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
219 /************** Window Placement ***************/
220 panel
->placF
= WMCreateFrame(panel
->frame
);
221 WMResizeWidget(panel
->placF
, 270, 110);
222 WMMoveWidget(panel
->placF
, 20, 10);
223 WMSetFrameTitle(panel
->placF
, _("Window Placement"));
225 panel
->placP
= WMCreatePopUpButton(panel
->placF
);
226 WMResizeWidget(panel
->placP
, 105, 20);
227 WMMoveWidget(panel
->placP
, 15, 20);
228 WMAddPopUpButtonItem(panel
->placP
, _("Automatic"));
229 WMAddPopUpButtonItem(panel
->placP
, _("Random"));
230 WMAddPopUpButtonItem(panel
->placP
, _("Manual"));
231 WMAddPopUpButtonItem(panel
->placP
, _("Cascade"));
233 panel
->porigL
= WMCreateLabel(panel
->placF
);
234 WMResizeWidget(panel
->porigL
, 120, 32);
235 WMMoveWidget(panel
->porigL
, 5, 45);
236 WMSetLabelTextAlignment(panel
->porigL
, WACenter
);
237 WMSetLabelText(panel
->porigL
, _("Placement Origin"));
239 panel
->porigvL
= WMCreateLabel(panel
->placF
);
240 WMResizeWidget(panel
->porigvL
, 80, 20);
241 WMMoveWidget(panel
->porigvL
, 30, 75);
242 WMSetLabelTextAlignment(panel
->porigvL
, WACenter
);
244 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
245 panel
->porigF
= WMCreateFrame(panel
->placF
);
246 WMSetWidgetBackgroundColor(panel
->porigF
, color
);
247 WMReleaseColor(color
);
248 WMSetFrameRelief(panel
->porigF
, WRSunken
);
250 swidth
= WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
251 sheight
= HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
253 if (sheight
> swidth
) {
255 width
= 70*swidth
/sheight
;
258 height
= 115*sheight
/swidth
;
261 height
= 115*sheight
/swidth
;
264 width
= 70*swidth
/sheight
;
266 WMResizeWidget(panel
->porigF
, width
, height
);
267 WMMoveWidget(panel
->porigF
, 130+(115-width
)/2, 20+(70-height
)/2);
269 panel
->porigW
= WMCreateLabel(panel
->porigF
);
270 WMResizeWidget(panel
->porigW
, THUMB_SIZE
, THUMB_SIZE
);
271 WMMoveWidget(panel
->porigW
, 2, 2);
272 WMSetLabelRelief(panel
->porigW
, WRRaised
);
275 panel
->hsli
= WMCreateSlider(panel
->placF
);
276 WMResizeWidget(panel
->hsli
, width
, 12);
277 WMMoveWidget(panel
->hsli
, 130+(115-width
)/2, 20+(70-height
)/2+height
+2);
278 WMSetSliderAction(panel
->hsli
, sliderCallback
, panel
);
279 WMSetSliderMinValue(panel
->hsli
, 0);
280 WMSetSliderMaxValue(panel
->hsli
, swidth
);
282 panel
->vsli
= WMCreateSlider(panel
->placF
);
283 WMResizeWidget(panel
->vsli
, 12, height
);
284 WMMoveWidget(panel
->vsli
, 130+(115-width
)/2+width
+2, 20+(70-height
)/2);
285 WMSetSliderAction(panel
->vsli
, sliderCallback
, panel
);
286 WMSetSliderMinValue(panel
->vsli
, 0);
287 WMSetSliderMaxValue(panel
->vsli
, sheight
);
289 WMMapSubwidgets(panel
->porigF
);
291 WMMapSubwidgets(panel
->placF
);
293 /************** Opaque Move ***************/
294 panel
->opaqF
= WMCreateFrame(panel
->frame
);
295 WMResizeWidget(panel
->opaqF
, 205, 110);
296 WMMoveWidget(panel
->opaqF
, 300, 10);
297 WMSetFrameTitle(panel
->opaqF
, _("Opaque Move"));
299 panel
->opaqB
= WMCreateButton(panel
->opaqF
, WBTToggle
);
300 WMResizeWidget(panel
->opaqB
, 64, 64);
301 WMMoveWidget(panel
->opaqB
, 70, 25);
302 WMSetButtonImagePosition(panel
->opaqB
, WIPImageOnly
);
304 path
= LocateImage(NON_OPAQUE_MOVE_PIXMAP
);
306 pixmap
= WMCreatePixmapFromFile(scr
, path
);
308 WMSetButtonImage(panel
->opaqB
, pixmap
);
309 WMReleasePixmap(pixmap
);
311 wwarning(_("could not load icon %s"), path
);
316 path
= LocateImage(OPAQUE_MOVE_PIXMAP
);
318 pixmap
= WMCreatePixmapFromFile(scr
, path
);
320 WMSetButtonAltImage(panel
->opaqB
, pixmap
);
321 WMReleasePixmap(pixmap
);
323 wwarning(_("could not load icon %s"), path
);
327 WMMapSubwidgets(panel
->opaqF
);
329 /**************** Account for Icon/Dock ***************/
330 panel
->maxiF
= WMCreateFrame(panel
->frame
);
331 WMResizeWidget(panel
->maxiF
, 205, 95);
332 WMMoveWidget(panel
->maxiF
, 300, 125);
333 WMSetFrameTitle(panel
->maxiF
, _("When maximizing..."));
335 panel
->miconB
= WMCreateSwitchButton(panel
->maxiF
);
336 WMResizeWidget(panel
->miconB
, 185, 30);
337 WMMoveWidget(panel
->miconB
, 10, 18);
338 WMSetButtonText(panel
->miconB
, _("...do not cover icons"));
340 panel
->mdockB
= WMCreateSwitchButton(panel
->maxiF
);
341 WMResizeWidget(panel
->mdockB
, 185, 30);
342 WMMoveWidget(panel
->mdockB
, 10, 53);
344 WMSetButtonText(panel
->mdockB
, _("...do not cover dock"));
346 WMMapSubwidgets(panel
->maxiF
);
348 /**************** Edge Resistance ****************/
350 panel
->resF
= WMCreateFrame(panel
->frame
);
351 WMResizeWidget(panel
->resF
, 270, 45);
352 WMMoveWidget(panel
->resF
, 20, 125);
353 WMSetFrameTitle(panel
->resF
, _("Edge Resistance"));
355 panel
->resS
= WMCreateSlider(panel
->resF
);
356 WMResizeWidget(panel
->resS
, 200, 15);
357 WMMoveWidget(panel
->resS
, 10, 20);
358 WMSetSliderMinValue(panel
->resS
, 0);
359 WMSetSliderMaxValue(panel
->resS
, 200);
360 WMSetSliderAction(panel
->resS
, resistanceCallback
, panel
);
362 panel
->resL
= WMCreateLabel(panel
->resF
);
363 WMResizeWidget(panel
->resL
, 40, 15);
364 WMMoveWidget(panel
->resL
, 220, 20);
366 WMMapSubwidgets(panel
->resF
);
368 /**************** Transients on Parent Workspace ****************/
370 panel
->tranF
= WMCreateFrame(panel
->frame
);
371 WMResizeWidget(panel
->tranF
, 270, 40);
372 WMMoveWidget(panel
->tranF
, 20, 180);
374 panel
->tranB
= WMCreateSwitchButton(panel
->tranF
);
375 WMMoveWidget(panel
->tranB
, 10, 5);
376 WMResizeWidget(panel
->tranB
, 250, 30);
377 WMSetButtonText(panel
->tranB
, _("Open dialogs in same workspace as their owners"));
379 WMMapSubwidgets(panel
->tranF
);
381 WMRealizeWidget(panel
->frame
);
382 WMMapSubwidgets(panel
->frame
);
384 /* show the config data */
397 InitWindowHandling(WMScreen
*scr
, WMWindow
*win
)
401 panel
= wmalloc(sizeof(_Panel
));
402 memset(panel
, 0, sizeof(_Panel
));
404 panel
->sectionName
= _("Window Handling Preferences");
408 panel
->callbacks
.createWidgets
= createPanel
;
409 panel
->callbacks
.updateDomain
= storeData
;
410 panel
->callbacks
.undoChanges
= undo
;
412 AddSection(panel
, ICON_FILE
);