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>
29 #include "WindowMaker.h"
34 #include "dockedapp.h"
41 /**** Global variables ****/
42 extern WPreferences wPreferences
;
44 static void updateCommand(WAppIcon
* icon
, char *command
)
48 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
52 icon
->command
= command
;
54 if (!icon
->wm_class
&& !icon
->wm_instance
&& icon
->command
&& strlen(icon
->command
) > 0) {
55 icon
->forced_dock
= 1;
59 static void updatePasteCommand(WAppIcon
* icon
, char *command
)
61 if (icon
->paste_command
)
62 wfree(icon
->paste_command
);
63 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
67 icon
->paste_command
= command
;
71 static void updateDNDCommand(WAppIcon
* icon
, char *command
)
73 if (icon
->dnd_command
)
74 wfree(icon
->dnd_command
);
75 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
79 icon
->dnd_command
= command
;
83 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 pixmap
= WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel
->win
), path
, &color
);
109 WMSetLabelImage(panel
->iconLabel
, NULL
);
111 WMSetLabelImage(panel
->iconLabel
, pixmap
);
112 WMReleasePixmap(pixmap
);
120 static void chooseIconCallback(WMWidget
* self
, void *clientData
)
123 AppSettingsPanel
*panel
= (AppSettingsPanel
*) clientData
;
126 panel
->choosingIcon
= 1;
128 WMSetButtonEnabled(panel
->browseBtn
, False
);
130 result
= wIconChooserDialog(panel
->wwin
->screen_ptr
, &file
,
131 panel
->editedIcon
->wm_instance
, panel
->editedIcon
->wm_class
);
133 panel
->choosingIcon
= 0;
134 if (!panel
->destroyed
) {
136 WMSetTextFieldText(panel
->iconField
, file
);
138 updateSettingsPanelIcon(panel
);
141 WMSetButtonEnabled(panel
->browseBtn
, True
);
143 /* kluge for the case, the user asked to close the panel before
144 * the icon chooser */
145 DestroyDockAppSettingsPanel(panel
);
149 static void panelBtnCallback(WMWidget
* self
, void *data
)
151 WMButton
*btn
= self
;
152 AppSettingsPanel
*panel
= (AppSettingsPanel
*) data
;
157 if (panel
->okBtn
== btn
) {
158 text
= WMGetTextFieldText(panel
->iconField
);
163 if (!wIconChangeImageFile(panel
->editedIcon
->icon
, text
)) {
165 int len
= strlen(text
) + 64;
168 snprintf(buf
, len
, _("Could not open specified icon file: %s"), text
);
169 if (wMessageDialog(panel
->wwin
->screen_ptr
, _("Error"), buf
,
170 _("OK"), _("Ignore"), NULL
) == WAPRDefault
) {
178 WAppIcon
*aicon
= panel
->editedIcon
;
180 if (aicon
== aicon
->icon
->core
->screen_ptr
->clip_icon
)
181 wClipIconPaint(aicon
);
183 wAppIconPaint(aicon
);
185 wDefaultChangeIcon(panel
->wwin
->screen_ptr
, aicon
->wm_instance
, aicon
->wm_class
, text
);
190 /* cannot free text from this, because it will be not be duplicated
191 * in updateCommand */
192 text
= WMGetTextFieldText(panel
->commandField
);
197 updateCommand(panel
->editedIcon
, text
);
199 /* cannot free text from this, because it will be not be duplicated
200 * in updateDNDCommand */
201 text
= WMGetTextFieldText(panel
->dndCommandField
);
202 updateDNDCommand(panel
->editedIcon
, text
);
204 text
= WMGetTextFieldText(panel
->pasteCommandField
);
205 updatePasteCommand(panel
->editedIcon
, text
);
207 panel
->editedIcon
->auto_launch
= WMGetButtonSelected(panel
->autoLaunchBtn
);
209 panel
->editedIcon
->lock
= WMGetButtonSelected(panel
->lockBtn
);
213 DestroyDockAppSettingsPanel(panel
);
219 void ShowDockAppSettingsPanel(WAppIcon
* aicon
)
221 AppSettingsPanel
*panel
;
222 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
228 panel
= wmalloc(sizeof(AppSettingsPanel
));
230 panel
->editedIcon
= aicon
;
232 aicon
->panel
= panel
;
235 panel
->win
= WMCreateWindow(scr
->wmscreen
, "applicationSettings");
236 WMResizeWidget(panel
->win
, PWIDTH
, PHEIGHT
);
238 panel
->iconLabel
= WMCreateLabel(panel
->win
);
239 WMResizeWidget(panel
->iconLabel
, 64, 64);
240 WMMoveWidget(panel
->iconLabel
, 10, 10);
241 WMSetLabelImagePosition(panel
->iconLabel
, WIPImageOnly
);
243 panel
->nameLabel
= WMCreateLabel(panel
->win
);
244 WMResizeWidget(panel
->nameLabel
, 190, 18);
245 WMMoveWidget(panel
->nameLabel
, 80, 35);
246 WMSetLabelTextAlignment(panel
->nameLabel
, WALeft
);
247 font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 14);
248 WMSetLabelFont(panel
->nameLabel
, font
);
250 if (aicon
->wm_class
&& strcmp(aicon
->wm_class
, "DockApp") == 0)
251 WMSetLabelText(panel
->nameLabel
, aicon
->wm_instance
);
253 WMSetLabelText(panel
->nameLabel
, aicon
->wm_class
);
255 vbox
= WMCreateBox(panel
->win
);
256 WMResizeWidget(vbox
, PWIDTH
- 20, PHEIGHT
- 84 - 10);
257 WMMoveWidget(vbox
, 10, 84);
259 panel
->autoLaunchBtn
= WMCreateSwitchButton(vbox
);
260 WMAddBoxSubview(vbox
, WMWidgetView(panel
->autoLaunchBtn
), False
, True
, 20, 20, 2);
261 WMSetButtonText(panel
->autoLaunchBtn
, _("Start when Window Maker is started"));
262 WMSetButtonSelected(panel
->autoLaunchBtn
, aicon
->auto_launch
);
264 panel
->lockBtn
= WMCreateSwitchButton(vbox
);
265 WMAddBoxSubview(vbox
, WMWidgetView(panel
->lockBtn
), False
, True
, 20, 20, 5);
266 WMSetButtonText(panel
->lockBtn
, _("Lock (prevent accidental removal)"));
267 WMSetButtonSelected(panel
->lockBtn
, aicon
->lock
);
269 panel
->commandFrame
= WMCreateFrame(vbox
);
270 WMSetFrameTitle(panel
->commandFrame
, _("Application path and arguments"));
271 WMAddBoxSubview(vbox
, WMWidgetView(panel
->commandFrame
), False
, True
, 50, 50, 5);
273 panel
->commandField
= WMCreateTextField(panel
->commandFrame
);
274 WMResizeWidget(panel
->commandField
, 256, 20);
275 WMMoveWidget(panel
->commandField
, 10, 20);
276 WMSetTextFieldText(panel
->commandField
, aicon
->command
);
278 WMMapSubwidgets(panel
->commandFrame
);
280 panel
->pasteCommandFrame
= WMCreateFrame(vbox
);
281 WMSetFrameTitle(panel
->pasteCommandFrame
, _("Command for middle-click launch"));
282 WMAddBoxSubview(vbox
, WMWidgetView(panel
->pasteCommandFrame
), False
, True
, 70, 70, 5);
284 panel
->pasteCommandField
= WMCreateTextField(panel
->pasteCommandFrame
);
285 WMResizeWidget(panel
->pasteCommandField
, 256, 20);
286 WMMoveWidget(panel
->pasteCommandField
, 10, 20);
288 panel
->pasteCommandLabel
= WMCreateLabel(panel
->pasteCommandFrame
);
289 WMResizeWidget(panel
->pasteCommandLabel
, 256, 18);
290 WMMoveWidget(panel
->pasteCommandLabel
, 10, 45);
292 WMSetTextFieldText(panel
->pasteCommandField
, aicon
->paste_command
);
293 WMSetLabelText(panel
->pasteCommandLabel
, _("%s will be replaced with current selection"));
294 WMMapSubwidgets(panel
->pasteCommandFrame
);
296 panel
->dndCommandFrame
= WMCreateFrame(vbox
);
297 WMSetFrameTitle(panel
->dndCommandFrame
, _("Command for files dropped with DND"));
298 WMAddBoxSubview(vbox
, WMWidgetView(panel
->dndCommandFrame
), False
, True
, 70, 70, 5);
300 panel
->dndCommandField
= WMCreateTextField(panel
->dndCommandFrame
);
301 WMResizeWidget(panel
->dndCommandField
, 256, 20);
302 WMMoveWidget(panel
->dndCommandField
, 10, 20);
304 panel
->dndCommandLabel
= WMCreateLabel(panel
->dndCommandFrame
);
305 WMResizeWidget(panel
->dndCommandLabel
, 256, 18);
306 WMMoveWidget(panel
->dndCommandLabel
, 10, 45);
308 WMSetTextFieldText(panel
->dndCommandField
, aicon
->dnd_command
);
309 WMSetLabelText(panel
->dndCommandLabel
, _("%d will be replaced with the file name"));
311 WMSetTextFieldEditable(panel
->dndCommandField
, False
);
312 WMSetLabelText(panel
->dndCommandLabel
, _("DND support was not compiled in"));
314 WMMapSubwidgets(panel
->dndCommandFrame
);
316 panel
->iconFrame
= WMCreateFrame(vbox
);
317 WMSetFrameTitle(panel
->iconFrame
, _("Icon Image"));
318 WMAddBoxSubview(vbox
, WMWidgetView(panel
->iconFrame
), False
, True
, 50, 50, 10);
320 panel
->iconField
= WMCreateTextField(panel
->iconFrame
);
321 WMResizeWidget(panel
->iconField
, 176, 20);
322 WMMoveWidget(panel
->iconField
, 10, 20);
323 WMSetTextFieldText(panel
->iconField
, wDefaultGetIconFile(aicon
->wm_instance
, aicon
->wm_class
, False
));
325 panel
->browseBtn
= WMCreateCommandButton(panel
->iconFrame
);
326 WMResizeWidget(panel
->browseBtn
, 70, 24);
327 WMMoveWidget(panel
->browseBtn
, 195, 18);
328 WMSetButtonText(panel
->browseBtn
, _("Browse..."));
329 WMSetButtonAction(panel
->browseBtn
, chooseIconCallback
, panel
);
334 hbox
= WMCreateBox(vbox
);
335 WMSetBoxHorizontal(hbox
, True
);
336 WMAddBoxSubview(vbox
, WMWidgetView(hbox
), False
, True
, 24, 24, 0);
338 panel
->okBtn
= WMCreateCommandButton(hbox
);
339 WMSetButtonText(panel
->okBtn
, _("OK"));
340 WMSetButtonAction(panel
->okBtn
, panelBtnCallback
, panel
);
341 WMAddBoxSubviewAtEnd(hbox
, WMWidgetView(panel
->okBtn
), False
, True
, 80, 80, 0);
343 panel
->cancelBtn
= WMCreateCommandButton(hbox
);
344 WMSetButtonText(panel
->cancelBtn
, _("Cancel"));
345 WMSetButtonAction(panel
->cancelBtn
, panelBtnCallback
, panel
);
346 WMAddBoxSubviewAtEnd(hbox
, WMWidgetView(panel
->cancelBtn
), False
, True
, 80, 80, 5);
348 WMMapSubwidgets(hbox
);
351 WMRealizeWidget(panel
->win
);
352 WMMapSubwidgets(panel
->win
);
353 WMMapSubwidgets(vbox
);
354 WMMapSubwidgets(panel
->iconFrame
);
356 updateSettingsPanelIcon(panel
);
358 parent
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, PWIDTH
, PHEIGHT
, 0, 0, 0);
359 XSelectInput(dpy
, parent
, KeyPressMask
| KeyReleaseMask
);
361 XReparentWindow(dpy
, WMWidgetXID(panel
->win
), parent
, 0, 0);
364 * make things relative to head
367 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
372 else if (y
+ PHEIGHT
> rect
.pos
.y
+ rect
.size
.height
)
373 y
= rect
.pos
.y
+ rect
.size
.height
- PHEIGHT
- 30;
375 if (aicon
->dock
&& aicon
->dock
->type
== WM_DOCK
) {
376 if (aicon
->dock
->on_right_side
)
377 x
= rect
.pos
.x
+ rect
.size
.width
/ 2;
379 x
= rect
.pos
.x
+ rect
.size
.width
/ 2 - PWIDTH
- 2;
381 x
= rect
.pos
.x
+ (rect
.size
.width
- PWIDTH
) / 2;
385 panel
->wwin
= wManageInternalWindow(scr
, parent
, None
,
386 _("Docked Application Settings"), x
, y
, PWIDTH
, PHEIGHT
);
388 panel
->wwin
->client_leader
= WMWidgetXID(panel
->win
);
390 panel
->parent
= parent
;
392 WMMapWidget(panel
->win
);
394 wWindowMap(panel
->wwin
);
397 void DestroyDockAppSettingsPanel(AppSettingsPanel
* panel
)
399 if (!panel
->destroyed
) {
400 XUnmapWindow(dpy
, panel
->wwin
->client_win
);
401 XReparentWindow(dpy
, panel
->wwin
->client_win
, panel
->wwin
->screen_ptr
->root_win
, 0, 0);
402 wUnmanageWindow(panel
->wwin
, False
, False
);
405 panel
->destroyed
= 1;
408 * kluge. If we destroy the panel before the icon chooser is closed,
409 * we will crash when it does close, trying to access something in the
410 * destroyed panel. Could use wretain()/wrelease() in the panel,
411 * but it is not working for some reason.
413 if (panel
->choosingIcon
)
416 WMDestroyWidget(panel
->win
);
418 XDestroyWindow(dpy
, panel
->parent
);
420 panel
->editedIcon
->panel
= NULL
;
422 panel
->editedIcon
->editing
= 0;