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
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 #include <X11/Xutil.h>
30 #include "WindowMaker.h"
42 /**** Global variables ****/
43 extern WPreferences wPreferences
;
45 typedef struct _AppSettingsPanel
{
54 WMFrame
*commandFrame
;
55 WMTextField
*commandField
;
57 WMFrame
*dndCommandFrame
;
58 WMTextField
*dndCommandField
;
59 WMLabel
*dndCommandLabel
;
61 WMFrame
*pasteCommandFrame
;
62 WMTextField
*pasteCommandField
;
63 WMLabel
*pasteCommandLabel
;
66 WMTextField
*iconField
;
69 WMButton
*autoLaunchBtn
;
78 unsigned int destroyed
:1;
79 unsigned int choosingIcon
:1;
82 void DestroyDockAppSettingsPanel(AppSettingsPanel
* panel
);
84 static void updateCommand(WAppIcon
* icon
, char *command
)
88 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
92 icon
->command
= command
;
94 if (!icon
->wm_class
&& !icon
->wm_instance
&& icon
->command
&& strlen(icon
->command
) > 0) {
95 icon
->forced_dock
= 1;
99 static void updatePasteCommand(WAppIcon
* icon
, char *command
)
101 if (icon
->paste_command
)
102 wfree(icon
->paste_command
);
103 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
107 icon
->paste_command
= command
;
111 static void updateDNDCommand(WAppIcon
* icon
, char *command
)
113 if (icon
->dnd_command
)
114 wfree(icon
->dnd_command
);
115 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
119 icon
->dnd_command
= command
;
123 static void updateSettingsPanelIcon(AppSettingsPanel
* panel
)
127 file
= WMGetTextFieldText(panel
->iconField
);
129 WMSetLabelImage(panel
->iconLabel
, NULL
);
133 path
= FindImage(wPreferences
.icon_path
, file
);
135 wwarning(_("could not find icon %s, used in a docked application"), file
);
137 WMSetLabelImage(panel
->iconLabel
, NULL
);
147 pixmap
= WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel
->win
), path
, &color
);
149 WMSetLabelImage(panel
->iconLabel
, NULL
);
151 WMSetLabelImage(panel
->iconLabel
, pixmap
);
152 WMReleasePixmap(pixmap
);
160 static void chooseIconCallback(WMWidget
* self
, void *clientData
)
163 AppSettingsPanel
*panel
= (AppSettingsPanel
*) clientData
;
166 panel
->choosingIcon
= 1;
168 WMSetButtonEnabled(panel
->browseBtn
, False
);
170 result
= wIconChooserDialog(panel
->wwin
->screen_ptr
, &file
,
171 panel
->editedIcon
->wm_instance
, panel
->editedIcon
->wm_class
);
173 panel
->choosingIcon
= 0;
174 if (!panel
->destroyed
) {
176 WMSetTextFieldText(panel
->iconField
, file
);
178 updateSettingsPanelIcon(panel
);
181 WMSetButtonEnabled(panel
->browseBtn
, True
);
183 /* kluge for the case, the user asked to close the panel before
184 * the icon chooser */
185 DestroyDockAppSettingsPanel(panel
);
189 static void panelBtnCallback(WMWidget
* self
, void *data
)
191 WMButton
*btn
= self
;
192 AppSettingsPanel
*panel
= (AppSettingsPanel
*) data
;
197 if (panel
->okBtn
== btn
) {
198 text
= WMGetTextFieldText(panel
->iconField
);
203 if (!wIconChangeImageFile(panel
->editedIcon
->icon
, text
)) {
205 int len
= strlen(text
) + 64;
208 snprintf(buf
, len
, _("Could not open specified icon file: %s"), text
);
209 if (wMessageDialog(panel
->wwin
->screen_ptr
, _("Error"), buf
,
210 _("OK"), _("Ignore"), NULL
) == WAPRDefault
) {
218 WAppIcon
*aicon
= panel
->editedIcon
;
220 if (aicon
== aicon
->icon
->core
->screen_ptr
->clip_icon
)
221 wClipIconPaint(aicon
);
223 wAppIconPaint(aicon
);
225 wDefaultChangeIcon(panel
->wwin
->screen_ptr
, aicon
->wm_instance
, aicon
->wm_class
, text
);
230 /* cannot free text from this, because it will be not be duplicated
231 * in updateCommand */
232 text
= WMGetTextFieldText(panel
->commandField
);
237 updateCommand(panel
->editedIcon
, text
);
239 /* cannot free text from this, because it will be not be duplicated
240 * in updateDNDCommand */
241 text
= WMGetTextFieldText(panel
->dndCommandField
);
242 updateDNDCommand(panel
->editedIcon
, text
);
244 text
= WMGetTextFieldText(panel
->pasteCommandField
);
245 updatePasteCommand(panel
->editedIcon
, text
);
247 panel
->editedIcon
->auto_launch
= WMGetButtonSelected(panel
->autoLaunchBtn
);
249 panel
->editedIcon
->lock
= WMGetButtonSelected(panel
->lockBtn
);
253 DestroyDockAppSettingsPanel(panel
);
259 void ShowDockAppSettingsPanel(WAppIcon
* aicon
)
261 AppSettingsPanel
*panel
;
262 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
268 panel
= wmalloc(sizeof(AppSettingsPanel
));
269 memset(panel
, 0, sizeof(AppSettingsPanel
));
271 panel
->editedIcon
= aicon
;
273 aicon
->panel
= panel
;
276 panel
->win
= WMCreateWindow(scr
->wmscreen
, "applicationSettings");
277 WMResizeWidget(panel
->win
, PWIDTH
, PHEIGHT
);
279 panel
->iconLabel
= WMCreateLabel(panel
->win
);
280 WMResizeWidget(panel
->iconLabel
, 64, 64);
281 WMMoveWidget(panel
->iconLabel
, 10, 10);
282 WMSetLabelImagePosition(panel
->iconLabel
, WIPImageOnly
);
284 panel
->nameLabel
= WMCreateLabel(panel
->win
);
285 WMResizeWidget(panel
->nameLabel
, 190, 18);
286 WMMoveWidget(panel
->nameLabel
, 80, 35);
287 WMSetLabelTextAlignment(panel
->nameLabel
, WALeft
);
288 font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 14);
289 WMSetLabelFont(panel
->nameLabel
, font
);
291 if (aicon
->wm_class
&& strcmp(aicon
->wm_class
, "DockApp") == 0)
292 WMSetLabelText(panel
->nameLabel
, aicon
->wm_instance
);
294 WMSetLabelText(panel
->nameLabel
, aicon
->wm_class
);
296 vbox
= WMCreateBox(panel
->win
);
297 WMResizeWidget(vbox
, PWIDTH
- 20, PHEIGHT
- 84 - 10);
298 WMMoveWidget(vbox
, 10, 84);
300 panel
->autoLaunchBtn
= WMCreateSwitchButton(vbox
);
301 WMAddBoxSubview(vbox
, WMWidgetView(panel
->autoLaunchBtn
), False
, True
, 20, 20, 2);
302 WMSetButtonText(panel
->autoLaunchBtn
, _("Start when Window Maker is started"));
303 WMSetButtonSelected(panel
->autoLaunchBtn
, aicon
->auto_launch
);
305 panel
->lockBtn
= WMCreateSwitchButton(vbox
);
306 WMAddBoxSubview(vbox
, WMWidgetView(panel
->lockBtn
), False
, True
, 20, 20, 5);
307 WMSetButtonText(panel
->lockBtn
, _("Lock (prevent accidental removal)"));
308 WMSetButtonSelected(panel
->lockBtn
, aicon
->lock
);
310 panel
->commandFrame
= WMCreateFrame(vbox
);
311 WMSetFrameTitle(panel
->commandFrame
, _("Application path and arguments"));
312 WMAddBoxSubview(vbox
, WMWidgetView(panel
->commandFrame
), False
, True
, 50, 50, 5);
314 panel
->commandField
= WMCreateTextField(panel
->commandFrame
);
315 WMResizeWidget(panel
->commandField
, 256, 20);
316 WMMoveWidget(panel
->commandField
, 10, 20);
317 WMSetTextFieldText(panel
->commandField
, aicon
->command
);
319 WMMapSubwidgets(panel
->commandFrame
);
321 panel
->pasteCommandFrame
= WMCreateFrame(vbox
);
322 WMSetFrameTitle(panel
->pasteCommandFrame
, _("Command for middle-click launch"));
323 WMAddBoxSubview(vbox
, WMWidgetView(panel
->pasteCommandFrame
), False
, True
, 70, 70, 5);
325 panel
->pasteCommandField
= WMCreateTextField(panel
->pasteCommandFrame
);
326 WMResizeWidget(panel
->pasteCommandField
, 256, 20);
327 WMMoveWidget(panel
->pasteCommandField
, 10, 20);
329 panel
->pasteCommandLabel
= WMCreateLabel(panel
->pasteCommandFrame
);
330 WMResizeWidget(panel
->pasteCommandLabel
, 256, 18);
331 WMMoveWidget(panel
->pasteCommandLabel
, 10, 45);
333 WMSetTextFieldText(panel
->pasteCommandField
, aicon
->paste_command
);
334 WMSetLabelText(panel
->pasteCommandLabel
, _("%s will be replaced with current selection"));
335 WMMapSubwidgets(panel
->pasteCommandFrame
);
337 panel
->dndCommandFrame
= WMCreateFrame(vbox
);
338 WMSetFrameTitle(panel
->dndCommandFrame
, _("Command for files dropped with DND"));
339 WMAddBoxSubview(vbox
, WMWidgetView(panel
->dndCommandFrame
), False
, True
, 70, 70, 5);
341 panel
->dndCommandField
= WMCreateTextField(panel
->dndCommandFrame
);
342 WMResizeWidget(panel
->dndCommandField
, 256, 20);
343 WMMoveWidget(panel
->dndCommandField
, 10, 20);
345 panel
->dndCommandLabel
= WMCreateLabel(panel
->dndCommandFrame
);
346 WMResizeWidget(panel
->dndCommandLabel
, 256, 18);
347 WMMoveWidget(panel
->dndCommandLabel
, 10, 45);
349 WMSetTextFieldText(panel
->dndCommandField
, aicon
->dnd_command
);
350 WMSetLabelText(panel
->dndCommandLabel
, _("%d will be replaced with the file name"));
352 WMSetTextFieldEditable(panel
->dndCommandField
, False
);
353 WMSetLabelText(panel
->dndCommandLabel
, _("DND support was not compiled in"));
355 WMMapSubwidgets(panel
->dndCommandFrame
);
357 panel
->iconFrame
= WMCreateFrame(vbox
);
358 WMSetFrameTitle(panel
->iconFrame
, _("Icon Image"));
359 WMAddBoxSubview(vbox
, WMWidgetView(panel
->iconFrame
), False
, True
, 50, 50, 10);
361 panel
->iconField
= WMCreateTextField(panel
->iconFrame
);
362 WMResizeWidget(panel
->iconField
, 176, 20);
363 WMMoveWidget(panel
->iconField
, 10, 20);
364 WMSetTextFieldText(panel
->iconField
, wDefaultGetIconFile(scr
, aicon
->wm_instance
, aicon
->wm_class
, True
));
366 panel
->browseBtn
= WMCreateCommandButton(panel
->iconFrame
);
367 WMResizeWidget(panel
->browseBtn
, 70, 24);
368 WMMoveWidget(panel
->browseBtn
, 195, 18);
369 WMSetButtonText(panel
->browseBtn
, _("Browse..."));
370 WMSetButtonAction(panel
->browseBtn
, chooseIconCallback
, panel
);
375 hbox
= WMCreateBox(vbox
);
376 WMSetBoxHorizontal(hbox
, True
);
377 WMAddBoxSubview(vbox
, WMWidgetView(hbox
), False
, True
, 24, 24, 0);
379 panel
->okBtn
= WMCreateCommandButton(hbox
);
380 WMSetButtonText(panel
->okBtn
, _("OK"));
381 WMSetButtonAction(panel
->okBtn
, panelBtnCallback
, panel
);
382 WMAddBoxSubviewAtEnd(hbox
, WMWidgetView(panel
->okBtn
), False
, True
, 80, 80, 0);
384 panel
->cancelBtn
= WMCreateCommandButton(hbox
);
385 WMSetButtonText(panel
->cancelBtn
, _("Cancel"));
386 WMSetButtonAction(panel
->cancelBtn
, panelBtnCallback
, panel
);
387 WMAddBoxSubviewAtEnd(hbox
, WMWidgetView(panel
->cancelBtn
), False
, True
, 80, 80, 5);
389 WMMapSubwidgets(hbox
);
392 WMRealizeWidget(panel
->win
);
393 WMMapSubwidgets(panel
->win
);
394 WMMapSubwidgets(vbox
);
395 WMMapSubwidgets(panel
->iconFrame
);
397 updateSettingsPanelIcon(panel
);
399 parent
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, PWIDTH
, PHEIGHT
, 0, 0, 0);
400 XSelectInput(dpy
, parent
, KeyPressMask
| KeyReleaseMask
);
402 XReparentWindow(dpy
, WMWidgetXID(panel
->win
), parent
, 0, 0);
405 * make things relative to head
408 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
413 else if (y
+ PHEIGHT
> rect
.pos
.y
+ rect
.size
.height
)
414 y
= rect
.pos
.y
+ rect
.size
.height
- PHEIGHT
- 30;
416 if (aicon
->dock
&& aicon
->dock
->type
== WM_DOCK
) {
417 if (aicon
->dock
->on_right_side
)
418 x
= rect
.pos
.x
+ rect
.size
.width
/ 2;
420 x
= rect
.pos
.x
+ rect
.size
.width
/ 2 - PWIDTH
- 2;
422 x
= rect
.pos
.x
+ (rect
.size
.width
- PWIDTH
) / 2;
426 panel
->wwin
= wManageInternalWindow(scr
, parent
, None
,
427 _("Docked Application Settings"), x
, y
, PWIDTH
, PHEIGHT
);
429 panel
->wwin
->client_leader
= WMWidgetXID(panel
->win
);
431 panel
->parent
= parent
;
433 WMMapWidget(panel
->win
);
435 wWindowMap(panel
->wwin
);
438 void DestroyDockAppSettingsPanel(AppSettingsPanel
* panel
)
440 if (!panel
->destroyed
) {
441 XUnmapWindow(dpy
, panel
->wwin
->client_win
);
442 XReparentWindow(dpy
, panel
->wwin
->client_win
, panel
->wwin
->screen_ptr
->root_win
, 0, 0);
443 wUnmanageWindow(panel
->wwin
, False
, False
);
446 panel
->destroyed
= 1;
449 * kluge. If we destroy the panel before the icon chooser is closed,
450 * we will crash when it does close, trying to access something in the
451 * destroyed panel. Could use wretain()/wrelease() in the panel,
452 * but it is not working for some reason.
454 if (panel
->choosingIcon
)
457 WMDestroyWidget(panel
->win
);
459 XDestroyWindow(dpy
, panel
->parent
);
461 panel
->editedIcon
->panel
= NULL
;
463 panel
->editedIcon
->editing
= 0;