1 /* dockedapp.c- docked application settings panel
3 * Window Maker window manager
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.
25 #include <X11/Xutil.h>
30 #include "WindowMaker.h"
35 #include "dockedapp.h"
43 static void updateCommand(WAppIcon
* icon
, char *command
)
47 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
51 icon
->command
= command
;
53 if (!icon
->wm_class
&& !icon
->wm_instance
&& icon
->command
&& strlen(icon
->command
) > 0) {
54 icon
->forced_dock
= 1;
58 static void updatePasteCommand(WAppIcon
* icon
, char *command
)
60 if (icon
->paste_command
)
61 wfree(icon
->paste_command
);
62 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
66 icon
->paste_command
= command
;
70 static void updateDNDCommand(WAppIcon
* icon
, char *command
)
72 if (icon
->dnd_command
)
73 wfree(icon
->dnd_command
);
74 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
78 icon
->dnd_command
= command
;
80 #endif /* USE_DOCK_XDND */
82 static void updateSettingsPanelIcon(AppSettingsPanel
* panel
)
87 file
= WMGetTextFieldText(panel
->iconField
);
89 WMSetLabelImage(panel
->iconLabel
, NULL
);
93 path
= FindImage(wPreferences
.icon_path
, file
);
95 wwarning(_("could not find icon %s, used in a docked application"), file
);
97 WMSetLabelImage(panel
->iconLabel
, NULL
);
107 size
= wPreferences
.icon_size
;
108 pixmap
= WMCreateScaledBlendedPixmapFromFile(WMWidgetScreen(panel
->win
), path
, &color
, size
, size
);
110 WMSetLabelImage(panel
->iconLabel
, NULL
);
112 WMSetLabelImage(panel
->iconLabel
, pixmap
);
113 WMReleasePixmap(pixmap
);
121 static void chooseIconCallback(WMWidget
* self
, void *clientData
)
124 AppSettingsPanel
*panel
= (AppSettingsPanel
*) clientData
;
127 /* Parameter not used, but tell the compiler that it is ok */
130 panel
->choosingIcon
= 1;
132 WMSetButtonEnabled(panel
->browseBtn
, False
);
134 result
= wIconChooserDialog(panel
->wwin
->screen_ptr
, &file
,
135 panel
->editedIcon
->wm_instance
, panel
->editedIcon
->wm_class
);
137 panel
->choosingIcon
= 0;
138 if (!panel
->destroyed
) {
140 WMSetTextFieldText(panel
->iconField
, file
);
141 updateSettingsPanelIcon(panel
);
144 WMSetButtonEnabled(panel
->browseBtn
, True
);
146 /* kluge for the case, the user asked to close the panel before
147 * the icon chooser */
148 DestroyDockAppSettingsPanel(panel
);
154 static void panelBtnCallback(WMWidget
* self
, void *data
)
156 WMButton
*btn
= self
;
157 AppSettingsPanel
*panel
= (AppSettingsPanel
*) data
;
160 if (panel
->okBtn
== btn
) {
161 text
= WMGetTextFieldText(panel
->iconField
);
167 if (!wIconChangeImageFile(panel
->editedIcon
->icon
, text
)) {
169 int len
= strlen(text
) + 64;
172 snprintf(buf
, len
, _("Could not open specified icon file: %s"), text
);
173 if (wMessageDialog(panel
->wwin
->screen_ptr
, _("Error"), buf
,
174 _("OK"), _("Ignore"), NULL
) == WAPRDefault
) {
181 WAppIcon
*aicon
= panel
->editedIcon
;
183 // Cf dock.c:dockIconPaint(WAppIcon *aicon)?
184 if (aicon
== aicon
->icon
->core
->screen_ptr
->clip_icon
)
185 wClipIconPaint(aicon
);
186 else if (wIsADrawer(aicon
))
187 wDrawerIconPaint(aicon
);
189 wAppIconPaint(aicon
);
191 wDefaultChangeIcon(aicon
->wm_instance
, aicon
->wm_class
, text
);
196 /* cannot free text from this, because it will be not be duplicated
197 * in updateCommand */
198 text
= WMGetTextFieldText(panel
->commandField
);
203 updateCommand(panel
->editedIcon
, text
);
205 /* cannot free text from this, because it will be not be duplicated
206 * in updateDNDCommand */
207 text
= WMGetTextFieldText(panel
->dndCommandField
);
208 updateDNDCommand(panel
->editedIcon
, text
);
210 text
= WMGetTextFieldText(panel
->pasteCommandField
);
211 updatePasteCommand(panel
->editedIcon
, text
);
213 panel
->editedIcon
->auto_launch
= WMGetButtonSelected(panel
->autoLaunchBtn
);
215 panel
->editedIcon
->lock
= WMGetButtonSelected(panel
->lockBtn
);
218 DestroyDockAppSettingsPanel(panel
);
221 void ShowDockAppSettingsPanel(WAppIcon
* aicon
)
223 AppSettingsPanel
*panel
;
224 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
229 int wmScaleWidth
, wmScaleHeight
;
233 /* get the width and height values of the system font for use with the WMScaleX/WMScaleY macros */
234 WMGetScaleBaseFromSystemFont(scr
->wmscreen
, &wmScaleWidth
, &wmScaleHeight
);
236 /* calculate the required width and height for the panel */
237 iconSize
= wPreferences
.icon_size
;
238 pwidth
= WMScaleX(300);
239 pheight
= WMScaleY(10) /* upper margin */
240 + iconSize
/* icon and its label */
241 + WMScaleY(10) /* padding */
242 + WMScaleY(20) + WMScaleY(2) /* start option */
243 + WMScaleY(20) + WMScaleY(5) /* lock option */
244 + WMScaleY(50) + WMScaleY(5) /* app path and arguments */
245 + WMScaleY(70) + WMScaleY(5) /* middle-click command */
246 + WMScaleY(70) + WMScaleY(5) /* drag&drop command */
247 + WMScaleY(50) + WMScaleY(10) /* icon file */
248 + WMScaleY(24) /* buttons */
249 + WMScaleY(10); /* lower margin */
251 panel
= wmalloc(sizeof(AppSettingsPanel
));
253 panel
->editedIcon
= aicon
;
255 aicon
->panel
= panel
;
258 panel
->win
= WMCreateWindow(scr
->wmscreen
, "applicationSettings");
259 WMResizeWidget(panel
->win
, pwidth
, pheight
);
261 panel
->iconLabel
= WMCreateLabel(panel
->win
);
262 WMResizeWidget(panel
->iconLabel
, iconSize
, iconSize
);
263 WMMoveWidget(panel
->iconLabel
, WMScaleX(10), WMScaleY(10));
264 WMSetLabelImagePosition(panel
->iconLabel
, WIPImageOnly
);
266 panel
->nameLabel
= WMCreateLabel(panel
->win
);
267 font
= WMBoldSystemFontOfSize(scr
->wmscreen
, WMScaleY(14));
268 WMResizeWidget(panel
->nameLabel
, WMScaleX(190), WMScaleY(18));
269 WMMoveWidget(panel
->nameLabel
, 2 * WMScaleX(10) + iconSize
, WMScaleY(10) + ((iconSize
- WMFontHeight(font
)) / 2));
270 WMSetLabelTextAlignment(panel
->nameLabel
, WALeft
);
271 WMSetLabelFont(panel
->nameLabel
, font
);
273 if (aicon
->wm_class
&& strcmp(aicon
->wm_class
, "DockApp") == 0)
274 WMSetLabelText(panel
->nameLabel
, aicon
->wm_instance
);
276 WMSetLabelText(panel
->nameLabel
, aicon
->wm_class
);
278 vbox
= WMCreateBox(panel
->win
);
279 WMResizeWidget(vbox
, pwidth
- 2 * WMScaleX(10), pheight
- iconSize
- 3 * WMScaleY(10));
280 WMMoveWidget(vbox
, WMScaleX(10), iconSize
+ 2 * WMScaleY(10));
282 panel
->autoLaunchBtn
= WMCreateSwitchButton(vbox
);
283 WMAddBoxSubview(vbox
, WMWidgetView(panel
->autoLaunchBtn
), False
, True
, WMScaleY(20), WMScaleY(20), WMScaleY(2));
284 WMSetButtonText(panel
->autoLaunchBtn
, _("Start when Window Maker is started"));
285 WMSetButtonSelected(panel
->autoLaunchBtn
, aicon
->auto_launch
);
287 panel
->lockBtn
= WMCreateSwitchButton(vbox
);
288 WMAddBoxSubview(vbox
, WMWidgetView(panel
->lockBtn
), False
, True
, WMScaleY(20), WMScaleY(20), WMScaleY(5));
289 WMSetButtonText(panel
->lockBtn
, _("Lock (prevent accidental removal)"));
290 WMSetButtonSelected(panel
->lockBtn
, aicon
->lock
);
292 panel
->commandFrame
= WMCreateFrame(vbox
);
293 WMSetFrameTitle(panel
->commandFrame
, _("Application path and arguments"));
294 WMAddBoxSubview(vbox
, WMWidgetView(panel
->commandFrame
), False
, True
, WMScaleY(50), WMScaleY(50), WMScaleY(5));
296 panel
->commandField
= WMCreateTextField(panel
->commandFrame
);
297 WMResizeWidget(panel
->commandField
, WMScaleX(260), WMScaleY(20));
298 WMMoveWidget(panel
->commandField
, WMScaleX(10), WMScaleY(20));
299 WMSetTextFieldText(panel
->commandField
, aicon
->command
);
301 WMMapSubwidgets(panel
->commandFrame
);
303 panel
->pasteCommandFrame
= WMCreateFrame(vbox
);
304 WMSetFrameTitle(panel
->pasteCommandFrame
, _("Command for middle-click launch"));
305 WMAddBoxSubview(vbox
, WMWidgetView(panel
->pasteCommandFrame
), False
, True
, WMScaleY(70), WMScaleY(70), WMScaleY(5));
307 panel
->pasteCommandField
= WMCreateTextField(panel
->pasteCommandFrame
);
308 WMResizeWidget(panel
->pasteCommandField
, WMScaleX(260), WMScaleY(20));
309 WMMoveWidget(panel
->pasteCommandField
, WMScaleX(10), WMScaleY(20));
311 panel
->pasteCommandLabel
= WMCreateLabel(panel
->pasteCommandFrame
);
312 WMResizeWidget(panel
->pasteCommandLabel
, WMScaleX(260), WMScaleY(18));
313 WMMoveWidget(panel
->pasteCommandLabel
, WMScaleX(10), WMScaleY(45));
315 WMSetTextFieldText(panel
->pasteCommandField
, aicon
->paste_command
);
316 WMSetLabelText(panel
->pasteCommandLabel
, _("%s will be replaced with current selection"));
317 WMMapSubwidgets(panel
->pasteCommandFrame
);
319 panel
->dndCommandFrame
= WMCreateFrame(vbox
);
320 WMSetFrameTitle(panel
->dndCommandFrame
, _("Command for dragged and dropped files"));
321 WMAddBoxSubview(vbox
, WMWidgetView(panel
->dndCommandFrame
), False
, True
, WMScaleY(70), WMScaleY(70), WMScaleY(5));
323 panel
->dndCommandField
= WMCreateTextField(panel
->dndCommandFrame
);
324 WMResizeWidget(panel
->dndCommandField
, WMScaleX(260), WMScaleY(20));
325 WMMoveWidget(panel
->dndCommandField
, WMScaleX(10), WMScaleY(20));
327 panel
->dndCommandLabel
= WMCreateLabel(panel
->dndCommandFrame
);
328 WMResizeWidget(panel
->dndCommandLabel
, WMScaleX(260), WMScaleY(18));
329 WMMoveWidget(panel
->dndCommandLabel
, WMScaleX(10), WMScaleY(45));
331 WMSetTextFieldText(panel
->dndCommandField
, aicon
->dnd_command
);
332 WMSetLabelText(panel
->dndCommandLabel
, _("%d will be replaced with the file name"));
334 WMSetTextFieldEditable(panel
->dndCommandField
, False
);
335 WMSetLabelText(panel
->dndCommandLabel
, _("XDnD support was not compiled in"));
337 WMSetFrameTitleColor(panel
->dndCommandFrame
, WMDarkGrayColor(scr
->wmscreen
));
338 WMSetLabelTextColor(panel
->dndCommandLabel
, WMDarkGrayColor(scr
->wmscreen
));
340 WMMapSubwidgets(panel
->dndCommandFrame
);
342 panel
->iconFrame
= WMCreateFrame(vbox
);
343 WMSetFrameTitle(panel
->iconFrame
, _("Icon Image"));
344 WMAddBoxSubview(vbox
, WMWidgetView(panel
->iconFrame
), False
, True
, WMScaleY(50), WMScaleY(50), WMScaleY(10));
346 panel
->iconField
= WMCreateTextField(panel
->iconFrame
);
347 WMResizeWidget(panel
->iconField
, WMScaleX(180), WMScaleY(20));
348 WMMoveWidget(panel
->iconField
, WMScaleX(10), WMScaleY(20));
349 WMSetTextFieldText(panel
->iconField
, wDefaultGetIconFile(aicon
->wm_instance
, aicon
->wm_class
, False
));
351 panel
->browseBtn
= WMCreateCommandButton(panel
->iconFrame
);
352 WMResizeWidget(panel
->browseBtn
, WMScaleX(70), WMScaleY(24));
353 WMMoveWidget(panel
->browseBtn
, WMScaleX(200), WMScaleY(18));
354 WMSetButtonText(panel
->browseBtn
, _("Browse..."));
355 WMSetButtonAction(panel
->browseBtn
, chooseIconCallback
, panel
);
360 hbox
= WMCreateBox(vbox
);
361 WMSetBoxHorizontal(hbox
, True
);
362 WMAddBoxSubview(vbox
, WMWidgetView(hbox
), False
, True
, WMScaleY(24), WMScaleY(24), 0);
364 panel
->okBtn
= WMCreateCommandButton(hbox
);
365 WMSetButtonText(panel
->okBtn
, _("OK"));
366 WMSetButtonAction(panel
->okBtn
, panelBtnCallback
, panel
);
367 WMAddBoxSubviewAtEnd(hbox
, WMWidgetView(panel
->okBtn
), False
, True
, WMScaleX(80), WMScaleX(80), 0);
369 panel
->cancelBtn
= WMCreateCommandButton(hbox
);
370 WMSetButtonText(panel
->cancelBtn
, _("Cancel"));
371 WMSetButtonAction(panel
->cancelBtn
, panelBtnCallback
, panel
);
372 WMAddBoxSubviewAtEnd(hbox
, WMWidgetView(panel
->cancelBtn
), False
, True
, WMScaleX(80), WMScaleX(80), 5);
374 WMMapSubwidgets(hbox
);
377 WMRealizeWidget(panel
->win
);
378 WMMapSubwidgets(panel
->win
);
379 WMMapSubwidgets(vbox
);
380 WMMapSubwidgets(panel
->iconFrame
);
382 updateSettingsPanelIcon(panel
);
384 parent
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, pwidth
, pheight
, 0, 0, 0);
385 XSelectInput(dpy
, parent
, KeyPressMask
| KeyReleaseMask
);
387 XReparentWindow(dpy
, WMWidgetXID(panel
->win
), parent
, 0, 0);
390 * make things relative to head
393 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
398 else if (y
+ pheight
> rect
.pos
.y
+ rect
.size
.height
)
399 y
= rect
.pos
.y
+ rect
.size
.height
- pheight
- 3 * WMScaleY(10);
401 if (aicon
->dock
&& aicon
->dock
->type
== WM_DOCK
) {
402 if (aicon
->dock
->on_right_side
)
403 x
= rect
.pos
.x
+ rect
.size
.width
/ 2;
405 x
= rect
.pos
.x
+ rect
.size
.width
/ 2 - pwidth
- WMScaleX(2);
407 x
= rect
.pos
.x
+ (rect
.size
.width
- pwidth
) / 2;
411 panel
->wwin
= wManageInternalWindow(scr
, parent
, None
,
412 _("Docked Application Settings"), x
, y
, pwidth
, pheight
);
414 panel
->wwin
->client_leader
= WMWidgetXID(panel
->win
);
416 panel
->parent
= parent
;
418 WMMapWidget(panel
->win
);
420 wWindowMap(panel
->wwin
);
423 void DestroyDockAppSettingsPanel(AppSettingsPanel
* panel
)
425 if (!panel
->destroyed
) {
426 XUnmapWindow(dpy
, panel
->wwin
->client_win
);
427 XReparentWindow(dpy
, panel
->wwin
->client_win
, panel
->wwin
->screen_ptr
->root_win
, 0, 0);
428 wUnmanageWindow(panel
->wwin
, False
, False
);
431 panel
->destroyed
= 1;
434 * kluge. If we destroy the panel before the icon chooser is closed,
435 * we will crash when it does close, trying to access something in the
436 * destroyed panel. Could use wretain()/wrelease() in the panel,
437 * but it is not working for some reason.
439 if (panel
->choosingIcon
)
442 WMDestroyWidget(panel
->win
);
444 XDestroyWindow(dpy
, panel
->parent
);
446 panel
->editedIcon
->panel
= NULL
;
448 panel
->editedIcon
->editing
= 0;