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"
40 /**** Global variables ****/
41 extern WPreferences wPreferences
;
43 typedef struct _AppSettingsPanel
{
52 WMFrame
*commandFrame
;
53 WMTextField
*commandField
;
55 WMFrame
*dndCommandFrame
;
56 WMTextField
*dndCommandField
;
57 WMLabel
*dndCommandLabel
;
59 WMFrame
*pasteCommandFrame
;
60 WMTextField
*pasteCommandField
;
61 WMLabel
*pasteCommandLabel
;
64 WMTextField
*iconField
;
67 WMButton
*autoLaunchBtn
;
76 unsigned int destroyed
:1;
77 unsigned int choosingIcon
:1;
80 void DestroyDockAppSettingsPanel(AppSettingsPanel
* panel
);
82 static void updateCommand(WAppIcon
* icon
, char *command
)
86 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
90 icon
->command
= command
;
92 if (!icon
->wm_class
&& !icon
->wm_instance
&& icon
->command
&& strlen(icon
->command
) > 0) {
93 icon
->forced_dock
= 1;
97 static void updatePasteCommand(WAppIcon
* icon
, char *command
)
99 if (icon
->paste_command
)
100 wfree(icon
->paste_command
);
101 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
105 icon
->paste_command
= command
;
109 static void updateDNDCommand(WAppIcon
* icon
, char *command
)
111 if (icon
->dnd_command
)
112 wfree(icon
->dnd_command
);
113 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
117 icon
->dnd_command
= command
;
121 static void updateSettingsPanelIcon(AppSettingsPanel
* panel
)
125 file
= WMGetTextFieldText(panel
->iconField
);
127 WMSetLabelImage(panel
->iconLabel
, NULL
);
131 path
= FindImage(wPreferences
.icon_path
, file
);
133 wwarning(_("could not find icon %s, used in a docked application"), file
);
135 WMSetLabelImage(panel
->iconLabel
, NULL
);
145 pixmap
= WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel
->win
), path
, &color
);
147 WMSetLabelImage(panel
->iconLabel
, NULL
);
149 WMSetLabelImage(panel
->iconLabel
, pixmap
);
150 WMReleasePixmap(pixmap
);
158 static void chooseIconCallback(WMWidget
* self
, void *clientData
)
161 AppSettingsPanel
*panel
= (AppSettingsPanel
*) clientData
;
164 panel
->choosingIcon
= 1;
166 WMSetButtonEnabled(panel
->browseBtn
, False
);
168 result
= wIconChooserDialog(panel
->wwin
->screen_ptr
, &file
,
169 panel
->editedIcon
->wm_instance
, panel
->editedIcon
->wm_class
);
171 panel
->choosingIcon
= 0;
172 if (!panel
->destroyed
) {
174 WMSetTextFieldText(panel
->iconField
, file
);
176 updateSettingsPanelIcon(panel
);
179 WMSetButtonEnabled(panel
->browseBtn
, True
);
181 /* kluge for the case, the user asked to close the panel before
182 * the icon chooser */
183 DestroyDockAppSettingsPanel(panel
);
187 static void panelBtnCallback(WMWidget
* self
, void *data
)
189 WMButton
*btn
= self
;
190 AppSettingsPanel
*panel
= (AppSettingsPanel
*) data
;
195 if (panel
->okBtn
== btn
) {
196 text
= WMGetTextFieldText(panel
->iconField
);
201 if (!wIconChangeImageFile(panel
->editedIcon
->icon
, text
)) {
203 int len
= strlen(text
) + 64;
206 snprintf(buf
, len
, _("Could not open specified icon file: %s"), text
);
207 if (wMessageDialog(panel
->wwin
->screen_ptr
, _("Error"), buf
,
208 _("OK"), _("Ignore"), NULL
) == WAPRDefault
) {
216 WAppIcon
*aicon
= panel
->editedIcon
;
218 if (aicon
== aicon
->icon
->core
->screen_ptr
->clip_icon
)
219 wClipIconPaint(aicon
);
221 wAppIconPaint(aicon
);
223 wDefaultChangeIcon(panel
->wwin
->screen_ptr
, aicon
->wm_instance
, aicon
->wm_class
, text
);
228 /* cannot free text from this, because it will be not be duplicated
229 * in updateCommand */
230 text
= WMGetTextFieldText(panel
->commandField
);
235 updateCommand(panel
->editedIcon
, text
);
237 /* cannot free text from this, because it will be not be duplicated
238 * in updateDNDCommand */
239 text
= WMGetTextFieldText(panel
->dndCommandField
);
240 updateDNDCommand(panel
->editedIcon
, text
);
242 text
= WMGetTextFieldText(panel
->pasteCommandField
);
243 updatePasteCommand(panel
->editedIcon
, text
);
245 panel
->editedIcon
->auto_launch
= WMGetButtonSelected(panel
->autoLaunchBtn
);
247 panel
->editedIcon
->lock
= WMGetButtonSelected(panel
->lockBtn
);
251 DestroyDockAppSettingsPanel(panel
);
257 void ShowDockAppSettingsPanel(WAppIcon
* aicon
)
259 AppSettingsPanel
*panel
;
260 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
266 panel
= wmalloc(sizeof(AppSettingsPanel
));
267 memset(panel
, 0, sizeof(AppSettingsPanel
));
269 panel
->editedIcon
= aicon
;
271 aicon
->panel
= panel
;
274 panel
->win
= WMCreateWindow(scr
->wmscreen
, "applicationSettings");
275 WMResizeWidget(panel
->win
, PWIDTH
, PHEIGHT
);
277 panel
->iconLabel
= WMCreateLabel(panel
->win
);
278 WMResizeWidget(panel
->iconLabel
, 64, 64);
279 WMMoveWidget(panel
->iconLabel
, 10, 10);
280 WMSetLabelImagePosition(panel
->iconLabel
, WIPImageOnly
);
282 panel
->nameLabel
= WMCreateLabel(panel
->win
);
283 WMResizeWidget(panel
->nameLabel
, 190, 18);
284 WMMoveWidget(panel
->nameLabel
, 80, 35);
285 WMSetLabelTextAlignment(panel
->nameLabel
, WALeft
);
286 font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 14);
287 WMSetLabelFont(panel
->nameLabel
, font
);
289 if (aicon
->wm_class
&& strcmp(aicon
->wm_class
, "DockApp") == 0)
290 WMSetLabelText(panel
->nameLabel
, aicon
->wm_instance
);
292 WMSetLabelText(panel
->nameLabel
, aicon
->wm_class
);
294 vbox
= WMCreateBox(panel
->win
);
295 WMResizeWidget(vbox
, PWIDTH
- 20, PHEIGHT
- 84 - 10);
296 WMMoveWidget(vbox
, 10, 84);
298 panel
->autoLaunchBtn
= WMCreateSwitchButton(vbox
);
299 WMAddBoxSubview(vbox
, WMWidgetView(panel
->autoLaunchBtn
), False
, True
, 20, 20, 2);
300 WMSetButtonText(panel
->autoLaunchBtn
, _("Start when Window Maker is started"));
301 WMSetButtonSelected(panel
->autoLaunchBtn
, aicon
->auto_launch
);
303 panel
->lockBtn
= WMCreateSwitchButton(vbox
);
304 WMAddBoxSubview(vbox
, WMWidgetView(panel
->lockBtn
), False
, True
, 20, 20, 5);
305 WMSetButtonText(panel
->lockBtn
, _("Lock (prevent accidental removal)"));
306 WMSetButtonSelected(panel
->lockBtn
, aicon
->lock
);
308 panel
->commandFrame
= WMCreateFrame(vbox
);
309 WMSetFrameTitle(panel
->commandFrame
, _("Application path and arguments"));
310 WMAddBoxSubview(vbox
, WMWidgetView(panel
->commandFrame
), False
, True
, 50, 50, 5);
312 panel
->commandField
= WMCreateTextField(panel
->commandFrame
);
313 WMResizeWidget(panel
->commandField
, 256, 20);
314 WMMoveWidget(panel
->commandField
, 10, 20);
315 WMSetTextFieldText(panel
->commandField
, aicon
->command
);
317 WMMapSubwidgets(panel
->commandFrame
);
319 panel
->pasteCommandFrame
= WMCreateFrame(vbox
);
320 WMSetFrameTitle(panel
->pasteCommandFrame
, _("Command for middle-click launch"));
321 WMAddBoxSubview(vbox
, WMWidgetView(panel
->pasteCommandFrame
), False
, True
, 70, 70, 5);
323 panel
->pasteCommandField
= WMCreateTextField(panel
->pasteCommandFrame
);
324 WMResizeWidget(panel
->pasteCommandField
, 256, 20);
325 WMMoveWidget(panel
->pasteCommandField
, 10, 20);
327 panel
->pasteCommandLabel
= WMCreateLabel(panel
->pasteCommandFrame
);
328 WMResizeWidget(panel
->pasteCommandLabel
, 256, 18);
329 WMMoveWidget(panel
->pasteCommandLabel
, 10, 45);
331 WMSetTextFieldText(panel
->pasteCommandField
, aicon
->paste_command
);
332 WMSetLabelText(panel
->pasteCommandLabel
, _("%s will be replaced with current selection"));
333 WMMapSubwidgets(panel
->pasteCommandFrame
);
335 panel
->dndCommandFrame
= WMCreateFrame(vbox
);
336 WMSetFrameTitle(panel
->dndCommandFrame
, _("Command for files dropped with DND"));
337 WMAddBoxSubview(vbox
, WMWidgetView(panel
->dndCommandFrame
), False
, True
, 70, 70, 5);
339 panel
->dndCommandField
= WMCreateTextField(panel
->dndCommandFrame
);
340 WMResizeWidget(panel
->dndCommandField
, 256, 20);
341 WMMoveWidget(panel
->dndCommandField
, 10, 20);
343 panel
->dndCommandLabel
= WMCreateLabel(panel
->dndCommandFrame
);
344 WMResizeWidget(panel
->dndCommandLabel
, 256, 18);
345 WMMoveWidget(panel
->dndCommandLabel
, 10, 45);
347 WMSetTextFieldText(panel
->dndCommandField
, aicon
->dnd_command
);
348 WMSetLabelText(panel
->dndCommandLabel
, _("%d will be replaced with the file name"));
350 WMSetTextFieldEditable(panel
->dndCommandField
, False
);
351 WMSetLabelText(panel
->dndCommandLabel
, _("DND support was not compiled in"));
353 WMMapSubwidgets(panel
->dndCommandFrame
);
355 panel
->iconFrame
= WMCreateFrame(vbox
);
356 WMSetFrameTitle(panel
->iconFrame
, _("Icon Image"));
357 WMAddBoxSubview(vbox
, WMWidgetView(panel
->iconFrame
), False
, True
, 50, 50, 10);
359 panel
->iconField
= WMCreateTextField(panel
->iconFrame
);
360 WMResizeWidget(panel
->iconField
, 176, 20);
361 WMMoveWidget(panel
->iconField
, 10, 20);
362 WMSetTextFieldText(panel
->iconField
, wDefaultGetIconFile(scr
, aicon
->wm_instance
, aicon
->wm_class
, True
));
364 panel
->browseBtn
= WMCreateCommandButton(panel
->iconFrame
);
365 WMResizeWidget(panel
->browseBtn
, 70, 24);
366 WMMoveWidget(panel
->browseBtn
, 195, 18);
367 WMSetButtonText(panel
->browseBtn
, _("Browse..."));
368 WMSetButtonAction(panel
->browseBtn
, chooseIconCallback
, panel
);
373 hbox
= WMCreateBox(vbox
);
374 WMSetBoxHorizontal(hbox
, True
);
375 WMAddBoxSubview(vbox
, WMWidgetView(hbox
), False
, True
, 24, 24, 0);
377 panel
->okBtn
= WMCreateCommandButton(hbox
);
378 WMSetButtonText(panel
->okBtn
, _("OK"));
379 WMSetButtonAction(panel
->okBtn
, panelBtnCallback
, panel
);
380 WMAddBoxSubviewAtEnd(hbox
, WMWidgetView(panel
->okBtn
), False
, True
, 80, 80, 0);
382 panel
->cancelBtn
= WMCreateCommandButton(hbox
);
383 WMSetButtonText(panel
->cancelBtn
, _("Cancel"));
384 WMSetButtonAction(panel
->cancelBtn
, panelBtnCallback
, panel
);
385 WMAddBoxSubviewAtEnd(hbox
, WMWidgetView(panel
->cancelBtn
), False
, True
, 80, 80, 5);
387 WMMapSubwidgets(hbox
);
390 WMRealizeWidget(panel
->win
);
391 WMMapSubwidgets(panel
->win
);
392 WMMapSubwidgets(vbox
);
393 WMMapSubwidgets(panel
->iconFrame
);
395 updateSettingsPanelIcon(panel
);
397 parent
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, PWIDTH
, PHEIGHT
, 0, 0, 0);
398 XSelectInput(dpy
, parent
, KeyPressMask
| KeyReleaseMask
);
400 XReparentWindow(dpy
, WMWidgetXID(panel
->win
), parent
, 0, 0);
403 * make things relative to head
406 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
411 else if (y
+ PHEIGHT
> rect
.pos
.y
+ rect
.size
.height
)
412 y
= rect
.pos
.y
+ rect
.size
.height
- PHEIGHT
- 30;
414 if (aicon
->dock
&& aicon
->dock
->type
== WM_DOCK
) {
415 if (aicon
->dock
->on_right_side
)
416 x
= rect
.pos
.x
+ rect
.size
.width
/ 2;
418 x
= rect
.pos
.x
+ rect
.size
.width
/ 2 - PWIDTH
- 2;
420 x
= rect
.pos
.x
+ (rect
.size
.width
- PWIDTH
) / 2;
424 panel
->wwin
= wManageInternalWindow(scr
, parent
, None
,
425 _("Docked Application Settings"), x
, y
, PWIDTH
, PHEIGHT
);
427 panel
->wwin
->client_leader
= WMWidgetXID(panel
->win
);
429 panel
->parent
= parent
;
431 WMMapWidget(panel
->win
);
433 wWindowMap(panel
->wwin
);
436 void DestroyDockAppSettingsPanel(AppSettingsPanel
* panel
)
438 if (!panel
->destroyed
) {
439 XUnmapWindow(dpy
, panel
->wwin
->client_win
);
440 XReparentWindow(dpy
, panel
->wwin
->client_win
, panel
->wwin
->screen_ptr
->root_win
, 0, 0);
441 wUnmanageWindow(panel
->wwin
, False
, False
);
444 panel
->destroyed
= 1;
447 * kluge. If we destroy the panel before the icon chooser is closed,
448 * we will crash when it does close, trying to access something in the
449 * destroyed panel. Could use wretain()/wrelease() in the panel,
450 * but it is not working for some reason.
452 if (panel
->choosingIcon
)
455 WMDestroyWidget(panel
->win
);
457 XDestroyWindow(dpy
, panel
->parent
);
459 panel
->editedIcon
->panel
= NULL
;
461 panel
->editedIcon
->editing
= 0;