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"
41 /**** Global variables ****/
42 extern WPreferences wPreferences
;
44 typedef struct _AppSettingsPanel
{
53 WMFrame
*commandFrame
;
54 WMTextField
*commandField
;
56 WMFrame
*dndCommandFrame
;
57 WMTextField
*dndCommandField
;
58 WMLabel
*dndCommandLabel
;
60 WMFrame
*pasteCommandFrame
;
61 WMTextField
*pasteCommandField
;
62 WMLabel
*pasteCommandLabel
;
65 WMTextField
*iconField
;
68 WMButton
*autoLaunchBtn
;
77 unsigned int destroyed
:1;
78 unsigned int choosingIcon
:1;
81 void DestroyDockAppSettingsPanel(AppSettingsPanel
* panel
);
83 static void updateCommand(WAppIcon
* icon
, char *command
)
87 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
91 icon
->command
= command
;
93 if (!icon
->wm_class
&& !icon
->wm_instance
&& icon
->command
&& strlen(icon
->command
) > 0) {
94 icon
->forced_dock
= 1;
98 static void updatePasteCommand(WAppIcon
* icon
, char *command
)
100 if (icon
->paste_command
)
101 wfree(icon
->paste_command
);
102 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
106 icon
->paste_command
= command
;
110 static void updateDNDCommand(WAppIcon
* icon
, char *command
)
112 if (icon
->dnd_command
)
113 wfree(icon
->dnd_command
);
114 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
118 icon
->dnd_command
= command
;
122 static void updateSettingsPanelIcon(AppSettingsPanel
* panel
)
126 file
= WMGetTextFieldText(panel
->iconField
);
128 WMSetLabelImage(panel
->iconLabel
, NULL
);
132 path
= FindImage(wPreferences
.icon_path
, file
);
134 wwarning(_("could not find icon %s, used in a docked application"), file
);
136 WMSetLabelImage(panel
->iconLabel
, NULL
);
146 pixmap
= WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel
->win
), path
, &color
);
148 WMSetLabelImage(panel
->iconLabel
, NULL
);
150 WMSetLabelImage(panel
->iconLabel
, pixmap
);
151 WMReleasePixmap(pixmap
);
159 static void chooseIconCallback(WMWidget
* self
, void *clientData
)
162 AppSettingsPanel
*panel
= (AppSettingsPanel
*) clientData
;
165 panel
->choosingIcon
= 1;
167 WMSetButtonEnabled(panel
->browseBtn
, False
);
169 result
= wIconChooserDialog(panel
->wwin
->screen_ptr
, &file
,
170 panel
->editedIcon
->wm_instance
, panel
->editedIcon
->wm_class
);
172 panel
->choosingIcon
= 0;
173 if (!panel
->destroyed
) {
175 WMSetTextFieldText(panel
->iconField
, file
);
177 updateSettingsPanelIcon(panel
);
180 WMSetButtonEnabled(panel
->browseBtn
, True
);
182 /* kluge for the case, the user asked to close the panel before
183 * the icon chooser */
184 DestroyDockAppSettingsPanel(panel
);
188 static void panelBtnCallback(WMWidget
* self
, void *data
)
190 WMButton
*btn
= self
;
191 AppSettingsPanel
*panel
= (AppSettingsPanel
*) data
;
196 if (panel
->okBtn
== btn
) {
197 text
= WMGetTextFieldText(panel
->iconField
);
202 if (!wIconChangeImageFile(panel
->editedIcon
->icon
, text
)) {
204 int len
= strlen(text
) + 64;
207 snprintf(buf
, len
, _("Could not open specified icon file: %s"), text
);
208 if (wMessageDialog(panel
->wwin
->screen_ptr
, _("Error"), buf
,
209 _("OK"), _("Ignore"), NULL
) == WAPRDefault
) {
217 WAppIcon
*aicon
= panel
->editedIcon
;
219 if (aicon
== aicon
->icon
->core
->screen_ptr
->clip_icon
)
220 wClipIconPaint(aicon
);
222 wAppIconPaint(aicon
);
224 wDefaultChangeIcon(panel
->wwin
->screen_ptr
, aicon
->wm_instance
, aicon
->wm_class
, text
);
229 /* cannot free text from this, because it will be not be duplicated
230 * in updateCommand */
231 text
= WMGetTextFieldText(panel
->commandField
);
236 updateCommand(panel
->editedIcon
, text
);
238 /* cannot free text from this, because it will be not be duplicated
239 * in updateDNDCommand */
240 text
= WMGetTextFieldText(panel
->dndCommandField
);
241 updateDNDCommand(panel
->editedIcon
, text
);
243 text
= WMGetTextFieldText(panel
->pasteCommandField
);
244 updatePasteCommand(panel
->editedIcon
, text
);
246 panel
->editedIcon
->auto_launch
= WMGetButtonSelected(panel
->autoLaunchBtn
);
248 panel
->editedIcon
->lock
= WMGetButtonSelected(panel
->lockBtn
);
252 DestroyDockAppSettingsPanel(panel
);
258 void ShowDockAppSettingsPanel(WAppIcon
* aicon
)
260 AppSettingsPanel
*panel
;
261 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
267 panel
= wmalloc(sizeof(AppSettingsPanel
));
268 memset(panel
, 0, sizeof(AppSettingsPanel
));
270 panel
->editedIcon
= aicon
;
272 aicon
->panel
= panel
;
275 panel
->win
= WMCreateWindow(scr
->wmscreen
, "applicationSettings");
276 WMResizeWidget(panel
->win
, PWIDTH
, PHEIGHT
);
278 panel
->iconLabel
= WMCreateLabel(panel
->win
);
279 WMResizeWidget(panel
->iconLabel
, 64, 64);
280 WMMoveWidget(panel
->iconLabel
, 10, 10);
281 WMSetLabelImagePosition(panel
->iconLabel
, WIPImageOnly
);
283 panel
->nameLabel
= WMCreateLabel(panel
->win
);
284 WMResizeWidget(panel
->nameLabel
, 190, 18);
285 WMMoveWidget(panel
->nameLabel
, 80, 35);
286 WMSetLabelTextAlignment(panel
->nameLabel
, WALeft
);
287 font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 14);
288 WMSetLabelFont(panel
->nameLabel
, font
);
290 if (aicon
->wm_class
&& strcmp(aicon
->wm_class
, "DockApp") == 0)
291 WMSetLabelText(panel
->nameLabel
, aicon
->wm_instance
);
293 WMSetLabelText(panel
->nameLabel
, aicon
->wm_class
);
295 vbox
= WMCreateBox(panel
->win
);
296 WMResizeWidget(vbox
, PWIDTH
- 20, PHEIGHT
- 84 - 10);
297 WMMoveWidget(vbox
, 10, 84);
299 panel
->autoLaunchBtn
= WMCreateSwitchButton(vbox
);
300 WMAddBoxSubview(vbox
, WMWidgetView(panel
->autoLaunchBtn
), False
, True
, 20, 20, 2);
301 WMSetButtonText(panel
->autoLaunchBtn
, _("Start when Window Maker is started"));
302 WMSetButtonSelected(panel
->autoLaunchBtn
, aicon
->auto_launch
);
304 panel
->lockBtn
= WMCreateSwitchButton(vbox
);
305 WMAddBoxSubview(vbox
, WMWidgetView(panel
->lockBtn
), False
, True
, 20, 20, 5);
306 WMSetButtonText(panel
->lockBtn
, _("Lock (prevent accidental removal)"));
307 WMSetButtonSelected(panel
->lockBtn
, aicon
->lock
);
309 panel
->commandFrame
= WMCreateFrame(vbox
);
310 WMSetFrameTitle(panel
->commandFrame
, _("Application path and arguments"));
311 WMAddBoxSubview(vbox
, WMWidgetView(panel
->commandFrame
), False
, True
, 50, 50, 5);
313 panel
->commandField
= WMCreateTextField(panel
->commandFrame
);
314 WMResizeWidget(panel
->commandField
, 256, 20);
315 WMMoveWidget(panel
->commandField
, 10, 20);
316 WMSetTextFieldText(panel
->commandField
, aicon
->command
);
318 WMMapSubwidgets(panel
->commandFrame
);
320 panel
->pasteCommandFrame
= WMCreateFrame(vbox
);
321 WMSetFrameTitle(panel
->pasteCommandFrame
, _("Command for middle-click launch"));
322 WMAddBoxSubview(vbox
, WMWidgetView(panel
->pasteCommandFrame
), False
, True
, 70, 70, 5);
324 panel
->pasteCommandField
= WMCreateTextField(panel
->pasteCommandFrame
);
325 WMResizeWidget(panel
->pasteCommandField
, 256, 20);
326 WMMoveWidget(panel
->pasteCommandField
, 10, 20);
328 panel
->pasteCommandLabel
= WMCreateLabel(panel
->pasteCommandFrame
);
329 WMResizeWidget(panel
->pasteCommandLabel
, 256, 18);
330 WMMoveWidget(panel
->pasteCommandLabel
, 10, 45);
332 WMSetTextFieldText(panel
->pasteCommandField
, aicon
->paste_command
);
333 WMSetLabelText(panel
->pasteCommandLabel
, _("%s will be replaced with current selection"));
334 WMMapSubwidgets(panel
->pasteCommandFrame
);
336 panel
->dndCommandFrame
= WMCreateFrame(vbox
);
337 WMSetFrameTitle(panel
->dndCommandFrame
, _("Command for files dropped with DND"));
338 WMAddBoxSubview(vbox
, WMWidgetView(panel
->dndCommandFrame
), False
, True
, 70, 70, 5);
340 panel
->dndCommandField
= WMCreateTextField(panel
->dndCommandFrame
);
341 WMResizeWidget(panel
->dndCommandField
, 256, 20);
342 WMMoveWidget(panel
->dndCommandField
, 10, 20);
344 panel
->dndCommandLabel
= WMCreateLabel(panel
->dndCommandFrame
);
345 WMResizeWidget(panel
->dndCommandLabel
, 256, 18);
346 WMMoveWidget(panel
->dndCommandLabel
, 10, 45);
348 WMSetTextFieldText(panel
->dndCommandField
, aicon
->dnd_command
);
349 WMSetLabelText(panel
->dndCommandLabel
, _("%d will be replaced with the file name"));
351 WMSetTextFieldEditable(panel
->dndCommandField
, False
);
352 WMSetLabelText(panel
->dndCommandLabel
, _("DND support was not compiled in"));
354 WMMapSubwidgets(panel
->dndCommandFrame
);
356 panel
->iconFrame
= WMCreateFrame(vbox
);
357 WMSetFrameTitle(panel
->iconFrame
, _("Icon Image"));
358 WMAddBoxSubview(vbox
, WMWidgetView(panel
->iconFrame
), False
, True
, 50, 50, 10);
360 panel
->iconField
= WMCreateTextField(panel
->iconFrame
);
361 WMResizeWidget(panel
->iconField
, 176, 20);
362 WMMoveWidget(panel
->iconField
, 10, 20);
363 WMSetTextFieldText(panel
->iconField
, wDefaultGetIconFile(scr
, aicon
->wm_instance
, aicon
->wm_class
, True
));
365 panel
->browseBtn
= WMCreateCommandButton(panel
->iconFrame
);
366 WMResizeWidget(panel
->browseBtn
, 70, 24);
367 WMMoveWidget(panel
->browseBtn
, 195, 18);
368 WMSetButtonText(panel
->browseBtn
, _("Browse..."));
369 WMSetButtonAction(panel
->browseBtn
, chooseIconCallback
, panel
);
374 hbox
= WMCreateBox(vbox
);
375 WMSetBoxHorizontal(hbox
, True
);
376 WMAddBoxSubview(vbox
, WMWidgetView(hbox
), False
, True
, 24, 24, 0);
378 panel
->okBtn
= WMCreateCommandButton(hbox
);
379 WMSetButtonText(panel
->okBtn
, _("OK"));
380 WMSetButtonAction(panel
->okBtn
, panelBtnCallback
, panel
);
381 WMAddBoxSubviewAtEnd(hbox
, WMWidgetView(panel
->okBtn
), False
, True
, 80, 80, 0);
383 panel
->cancelBtn
= WMCreateCommandButton(hbox
);
384 WMSetButtonText(panel
->cancelBtn
, _("Cancel"));
385 WMSetButtonAction(panel
->cancelBtn
, panelBtnCallback
, panel
);
386 WMAddBoxSubviewAtEnd(hbox
, WMWidgetView(panel
->cancelBtn
), False
, True
, 80, 80, 5);
388 WMMapSubwidgets(hbox
);
391 WMRealizeWidget(panel
->win
);
392 WMMapSubwidgets(panel
->win
);
393 WMMapSubwidgets(vbox
);
394 WMMapSubwidgets(panel
->iconFrame
);
396 updateSettingsPanelIcon(panel
);
398 parent
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, PWIDTH
, PHEIGHT
, 0, 0, 0);
399 XSelectInput(dpy
, parent
, KeyPressMask
| KeyReleaseMask
);
401 XReparentWindow(dpy
, WMWidgetXID(panel
->win
), parent
, 0, 0);
404 * make things relative to head
407 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
412 else if (y
+ PHEIGHT
> rect
.pos
.y
+ rect
.size
.height
)
413 y
= rect
.pos
.y
+ rect
.size
.height
- PHEIGHT
- 30;
415 if (aicon
->dock
&& aicon
->dock
->type
== WM_DOCK
) {
416 if (aicon
->dock
->on_right_side
)
417 x
= rect
.pos
.x
+ rect
.size
.width
/ 2;
419 x
= rect
.pos
.x
+ rect
.size
.width
/ 2 - PWIDTH
- 2;
421 x
= rect
.pos
.x
+ (rect
.size
.width
- PWIDTH
) / 2;
425 panel
->wwin
= wManageInternalWindow(scr
, parent
, None
,
426 _("Docked Application Settings"), x
, y
, PWIDTH
, PHEIGHT
);
428 panel
->wwin
->client_leader
= WMWidgetXID(panel
->win
);
430 panel
->parent
= parent
;
432 WMMapWidget(panel
->win
);
434 wWindowMap(panel
->wwin
);
437 void DestroyDockAppSettingsPanel(AppSettingsPanel
* panel
)
439 if (!panel
->destroyed
) {
440 XUnmapWindow(dpy
, panel
->wwin
->client_win
);
441 XReparentWindow(dpy
, panel
->wwin
->client_win
, panel
->wwin
->screen_ptr
->root_win
, 0, 0);
442 wUnmanageWindow(panel
->wwin
, False
, False
);
445 panel
->destroyed
= 1;
448 * kluge. If we destroy the panel before the icon chooser is closed,
449 * we will crash when it does close, trying to access something in the
450 * destroyed panel. Could use wretain()/wrelease() in the panel,
451 * but it is not working for some reason.
453 if (panel
->choosingIcon
)
456 WMDestroyWidget(panel
->win
);
458 XDestroyWindow(dpy
, panel
->parent
);
460 panel
->editedIcon
->panel
= NULL
;
462 panel
->editedIcon
->editing
= 0;