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
;
63 #define ICON_FILE "whandling"
65 #define OPAQUE_MOVE_PIXMAP "opaque"
67 #define NON_OPAQUE_MOVE_PIXMAP "nonopaque"
73 static char *placements
[] = {
82 sliderCallback(WMWidget
*w
, void *data
)
84 _Panel
*panel
= (_Panel
*)data
;
87 int swidth
= WMGetSliderMaxValue(panel
->hsli
);
88 int sheight
= WMGetSliderMaxValue(panel
->vsli
);
90 x
= WMGetSliderValue(panel
->hsli
);
91 y
= WMGetSliderValue(panel
->vsli
);
93 rx
= x
*(WMWidgetWidth(panel
->porigF
)-3)/swidth
+2;
94 ry
= y
*(WMWidgetHeight(panel
->porigF
)-3)/sheight
+2;
95 WMMoveWidget(panel
->porigW
, rx
, ry
);
97 sprintf(buffer
, "(%i,%i)", x
, y
);
98 WMSetLabelText(panel
->porigvL
, buffer
);
104 resistanceCallback(WMWidget
*w
, void *data
)
106 _Panel
*panel
= (_Panel
*)data
;
110 i
= WMGetSliderValue(panel
->resS
);
113 WMSetLabelText(panel
->resL
, "OFF");
115 sprintf(buffer
, "%i", i
);
116 WMSetLabelText(panel
->resL
, buffer
);
122 getPlacement(char *str
)
127 if (strcasecmp(str
, "auto")==0 || strcasecmp(str
, "smart")==0)
129 else if (strcasecmp(str
, "random")==0)
131 else if (strcasecmp(str
, "manual")==0)
133 else if (strcasecmp(str
, "cascade")==0)
136 wwarning(_("bad option value %s in WindowPlacement. Using default value"),
143 showData(_Panel
*panel
)
149 str
= GetStringForKey("WindowPlacement");
151 WMSetPopUpButtonSelectedItem(panel
->placP
, getPlacement(str
));
153 arr
= GetObjectForKey("WindowPlaceOrigin");
157 if (arr
&& (!PLIsArray(arr
) || PLGetNumberOfElements(arr
)!=2)) {
158 wwarning(_("invalid data in option WindowPlaceOrigin. Using default (0,0)"));
161 x
= atoi(PLGetString(PLGetArrayElement(arr
, 0)));
162 y
= atoi(PLGetString(PLGetArrayElement(arr
, 1)));
166 WMSetSliderValue(panel
->hsli
, x
);
167 WMSetSliderValue(panel
->vsli
, y
);
169 sliderCallback(NULL
, panel
);
171 x
= GetIntegerForKey("EdgeResistance");
172 WMSetSliderValue(panel
->resS
, x
);
173 resistanceCallback(NULL
, panel
);
175 WMSetButtonSelected(panel
->tranB
, GetBoolForKey("OpenTransientOnOwnerWorkspace"));
177 WMSetButtonSelected(panel
->opaqB
, GetBoolForKey("OpaqueMove"));
179 WMSetButtonSelected(panel
->miconB
, GetBoolForKey("NoWindowOverIcons"));
181 WMSetButtonSelected(panel
->mdockB
, GetBoolForKey("NoWindowOverDock"));
186 storeData(_Panel
*panel
)
191 SetBoolForKey(WMGetButtonSelected(panel
->miconB
), "NoWindowOverIcons");
192 SetBoolForKey(WMGetButtonSelected(panel
->mdockB
), "NoWindowOverDock");
193 SetBoolForKey(WMGetButtonSelected(panel
->opaqB
), "OpaqueMove");
194 SetBoolForKey(WMGetButtonSelected(panel
->tranB
), "OpenTransientOnOwnerWorkspace");
195 SetStringForKey(placements
[WMGetPopUpButtonSelectedItem(panel
->placP
)],
197 sprintf(x
, "%i", WMGetSliderValue(panel
->hsli
));
198 sprintf(y
, "%i", WMGetSliderValue(panel
->vsli
));
199 arr
= PLMakeArrayFromElements(PLMakeString(x
), PLMakeString(y
), NULL
);
200 SetObjectForKey(arr
, "WindowPlaceOrigin");
201 SetIntegerForKey(WMGetSliderValue(panel
->resS
), "EdgeResistance");
207 createPanel(Panel
*p
)
209 _Panel
*panel
= (Panel
*)p
;
210 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
217 panel
->frame
= WMCreateFrame(panel
->win
);
218 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
219 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
221 /************** Window Placement ***************/
222 panel
->placF
= WMCreateFrame(panel
->frame
);
223 WMResizeWidget(panel
->placF
, 270, 110);
224 WMMoveWidget(panel
->placF
, 20, 10);
225 WMSetFrameTitle(panel
->placF
, _("Window Placement"));
226 WMSetBalloonTextForView(_("How to place windows when they are first put\n"
227 "on screen."), WMWidgetView(panel
->placF
));
229 panel
->placP
= WMCreatePopUpButton(panel
->placF
);
230 WMResizeWidget(panel
->placP
, 105, 20);
231 WMMoveWidget(panel
->placP
, 15, 20);
232 WMAddPopUpButtonItem(panel
->placP
, _("Automatic"));
233 WMAddPopUpButtonItem(panel
->placP
, _("Random"));
234 WMAddPopUpButtonItem(panel
->placP
, _("Manual"));
235 WMAddPopUpButtonItem(panel
->placP
, _("Cascade"));
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
= 115*sheight
/swidth
;
265 height
= 115*sheight
/swidth
;
268 width
= 70*swidth
/sheight
;
270 WMResizeWidget(panel
->porigF
, width
, height
);
271 WMMoveWidget(panel
->porigF
, 130+(115-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
);
279 panel
->hsli
= WMCreateSlider(panel
->placF
);
280 WMResizeWidget(panel
->hsli
, width
, 12);
281 WMMoveWidget(panel
->hsli
, 130+(115-width
)/2, 20+(70-height
)/2+height
+2);
282 WMSetSliderAction(panel
->hsli
, sliderCallback
, panel
);
283 WMSetSliderMinValue(panel
->hsli
, 0);
284 WMSetSliderMaxValue(panel
->hsli
, swidth
);
286 panel
->vsli
= WMCreateSlider(panel
->placF
);
287 WMResizeWidget(panel
->vsli
, 12, height
);
288 WMMoveWidget(panel
->vsli
, 130+(115-width
)/2+width
+2, 20+(70-height
)/2);
289 WMSetSliderAction(panel
->vsli
, sliderCallback
, panel
);
290 WMSetSliderMinValue(panel
->vsli
, 0);
291 WMSetSliderMaxValue(panel
->vsli
, sheight
);
293 WMMapSubwidgets(panel
->porigF
);
295 WMMapSubwidgets(panel
->placF
);
297 /************** Opaque Move ***************/
298 panel
->opaqF
= WMCreateFrame(panel
->frame
);
299 WMResizeWidget(panel
->opaqF
, 205, 110);
300 WMMoveWidget(panel
->opaqF
, 300, 10);
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"),
305 WMWidgetView(panel
->opaqF
));
307 panel
->opaqB
= WMCreateButton(panel
->opaqF
, WBTToggle
);
308 WMResizeWidget(panel
->opaqB
, 64, 64);
309 WMMoveWidget(panel
->opaqB
, 70, 25);
310 WMSetButtonImagePosition(panel
->opaqB
, WIPImageOnly
);
312 path
= LocateImage(NON_OPAQUE_MOVE_PIXMAP
);
314 pixmap
= WMCreatePixmapFromFile(scr
, path
);
316 WMSetButtonImage(panel
->opaqB
, pixmap
);
317 WMReleasePixmap(pixmap
);
319 wwarning(_("could not load icon %s"), path
);
324 path
= LocateImage(OPAQUE_MOVE_PIXMAP
);
326 pixmap
= WMCreatePixmapFromFile(scr
, path
);
328 WMSetButtonAltImage(panel
->opaqB
, pixmap
);
329 WMReleasePixmap(pixmap
);
331 wwarning(_("could not load icon %s"), path
);
335 WMMapSubwidgets(panel
->opaqF
);
337 /**************** Account for Icon/Dock ***************/
338 panel
->maxiF
= WMCreateFrame(panel
->frame
);
339 WMResizeWidget(panel
->maxiF
, 205, 95);
340 WMMoveWidget(panel
->maxiF
, 300, 125);
341 WMSetFrameTitle(panel
->maxiF
, _("When maximizing..."));
343 panel
->miconB
= WMCreateSwitchButton(panel
->maxiF
);
344 WMResizeWidget(panel
->miconB
, 185, 30);
345 WMMoveWidget(panel
->miconB
, 10, 18);
346 WMSetButtonText(panel
->miconB
, _("...do not cover icons"));
348 panel
->mdockB
= WMCreateSwitchButton(panel
->maxiF
);
349 WMResizeWidget(panel
->mdockB
, 185, 30);
350 WMMoveWidget(panel
->mdockB
, 10, 53);
352 WMSetButtonText(panel
->mdockB
, _("...do not cover dock"));
354 WMMapSubwidgets(panel
->maxiF
);
356 /**************** Edge Resistance ****************/
358 panel
->resF
= WMCreateFrame(panel
->frame
);
359 WMResizeWidget(panel
->resF
, 270, 45);
360 WMMoveWidget(panel
->resF
, 20, 125);
361 WMSetFrameTitle(panel
->resF
, _("Edge Resistance"));
363 WMSetBalloonTextForView(_("Edge resistance will make windows `resist'\n"
364 "being moved further for the defined threshold\n"
365 "when moved against other windows or the edges\n"
366 "of the screen."), WMWidgetView(panel
->resF
));
368 panel
->resS
= WMCreateSlider(panel
->resF
);
369 WMResizeWidget(panel
->resS
, 200, 15);
370 WMMoveWidget(panel
->resS
, 20, 20);
371 WMSetSliderMinValue(panel
->resS
, 0);
372 WMSetSliderMaxValue(panel
->resS
, 200);
373 WMSetSliderAction(panel
->resS
, resistanceCallback
, panel
);
375 panel
->resL
= WMCreateLabel(panel
->resF
);
376 WMResizeWidget(panel
->resL
, 30, 15);
377 WMMoveWidget(panel
->resL
, 230, 20);
379 WMMapSubwidgets(panel
->resF
);
381 /**************** Transients on Parent Workspace ****************/
383 panel
->tranF
= WMCreateFrame(panel
->frame
);
384 WMResizeWidget(panel
->tranF
, 270, 40);
385 WMMoveWidget(panel
->tranF
, 20, 180);
387 panel
->tranB
= WMCreateSwitchButton(panel
->tranF
);
388 WMMoveWidget(panel
->tranB
, 10, 5);
389 WMResizeWidget(panel
->tranB
, 250, 30);
390 WMSetButtonText(panel
->tranB
, _("Open dialogs in same workspace as their owners"));
392 WMMapSubwidgets(panel
->tranF
);
394 WMRealizeWidget(panel
->frame
);
395 WMMapSubwidgets(panel
->frame
);
397 /* show the config data */
410 InitWindowHandling(WMScreen
*scr
, WMWindow
*win
)
414 panel
= wmalloc(sizeof(_Panel
));
415 memset(panel
, 0, sizeof(_Panel
));
417 panel
->sectionName
= _("Window Handling Preferences");
419 panel
->description
= _("Window handling options. Initial placement style\n"
420 "edge resistance, opaque move etc.");
424 panel
->callbacks
.createWidgets
= createPanel
;
425 panel
->callbacks
.updateDomain
= storeData
;
426 panel
->callbacks
.undoChanges
= undo
;
428 AddSection(panel
, ICON_FILE
);