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"
42 /**** Global variables ****/
43 extern WPreferences wPreferences
;
45 static void updateCommand(WAppIcon
* icon
, char *command
)
49 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
53 icon
->command
= command
;
55 if (!icon
->wm_class
&& !icon
->wm_instance
&& icon
->command
&& strlen(icon
->command
) > 0) {
56 icon
->forced_dock
= 1;
60 static void updatePasteCommand(WAppIcon
* icon
, char *command
)
62 if (icon
->paste_command
)
63 wfree(icon
->paste_command
);
64 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
68 icon
->paste_command
= command
;
72 static void updateDNDCommand(WAppIcon
* icon
, char *command
)
74 if (icon
->dnd_command
)
75 wfree(icon
->dnd_command
);
76 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
80 icon
->dnd_command
= command
;
84 static void updateSettingsPanelIcon(AppSettingsPanel
* panel
)
88 file
= WMGetTextFieldText(panel
->iconField
);
90 WMSetLabelImage(panel
->iconLabel
, NULL
);
94 path
= FindImage(wPreferences
.icon_path
, file
);
96 wwarning(_("could not find icon %s, used in a docked application"), file
);
98 WMSetLabelImage(panel
->iconLabel
, NULL
);
108 pixmap
= WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel
->win
), path
, &color
);
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 panel
->choosingIcon
= 1;
129 WMSetButtonEnabled(panel
->browseBtn
, False
);
131 result
= wIconChooserDialog(panel
->wwin
->screen_ptr
, &file
,
132 panel
->editedIcon
->wm_instance
, panel
->editedIcon
->wm_class
);
134 panel
->choosingIcon
= 0;
135 if (!panel
->destroyed
) {
137 WMSetTextFieldText(panel
->iconField
, file
);
139 updateSettingsPanelIcon(panel
);
142 WMSetButtonEnabled(panel
->browseBtn
, True
);
144 /* kluge for the case, the user asked to close the panel before
145 * the icon chooser */
146 DestroyDockAppSettingsPanel(panel
);
150 static void panelBtnCallback(WMWidget
* self
, void *data
)
152 WMButton
*btn
= self
;
153 AppSettingsPanel
*panel
= (AppSettingsPanel
*) data
;
157 if (panel
->okBtn
== btn
) {
158 text
= WMGetTextFieldText(panel
->iconField
);
164 if (!wIconChangeImageFile(panel
->editedIcon
->icon
, text
)) {
166 int len
= strlen(text
) + 64;
169 snprintf(buf
, len
, _("Could not open specified icon file: %s"), text
);
170 if (wMessageDialog(panel
->wwin
->screen_ptr
, _("Error"), buf
,
171 _("OK"), _("Ignore"), NULL
) == WAPRDefault
) {
179 WAppIcon
*aicon
= panel
->editedIcon
;
181 // Cf dock.c:dockIconPaint(WAppIcon *aicon)?
182 if (aicon
== aicon
->icon
->core
->screen_ptr
->clip_icon
)
183 wClipIconPaint(aicon
);
184 else if (wIsADrawer(aicon
->icon
->core
->screen_ptr
, aicon
))
185 wDrawerIconPaint(aicon
);
187 wAppIconPaint(aicon
);
189 wDefaultChangeIcon(panel
->wwin
->screen_ptr
, aicon
->wm_instance
, aicon
->wm_class
, text
);
194 /* cannot free text from this, because it will be not be duplicated
195 * in updateCommand */
196 text
= WMGetTextFieldText(panel
->commandField
);
201 updateCommand(panel
->editedIcon
, text
);
203 /* cannot free text from this, because it will be not be duplicated
204 * in updateDNDCommand */
205 text
= WMGetTextFieldText(panel
->dndCommandField
);
206 updateDNDCommand(panel
->editedIcon
, text
);
208 text
= WMGetTextFieldText(panel
->pasteCommandField
);
209 updatePasteCommand(panel
->editedIcon
, text
);
211 panel
->editedIcon
->auto_launch
= WMGetButtonSelected(panel
->autoLaunchBtn
);
213 panel
->editedIcon
->lock
= WMGetButtonSelected(panel
->lockBtn
);
217 DestroyDockAppSettingsPanel(panel
);
223 void ShowDockAppSettingsPanel(WAppIcon
* aicon
)
225 AppSettingsPanel
*panel
;
226 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
232 panel
= wmalloc(sizeof(AppSettingsPanel
));
234 panel
->editedIcon
= aicon
;
236 aicon
->panel
= panel
;
239 panel
->win
= WMCreateWindow(scr
->wmscreen
, "applicationSettings");
240 WMResizeWidget(panel
->win
, PWIDTH
, PHEIGHT
);
242 panel
->iconLabel
= WMCreateLabel(panel
->win
);
243 WMResizeWidget(panel
->iconLabel
, 64, 64);
244 WMMoveWidget(panel
->iconLabel
, 10, 10);
245 WMSetLabelImagePosition(panel
->iconLabel
, WIPImageOnly
);
247 panel
->nameLabel
= WMCreateLabel(panel
->win
);
248 WMResizeWidget(panel
->nameLabel
, 190, 18);
249 WMMoveWidget(panel
->nameLabel
, 80, 35);
250 WMSetLabelTextAlignment(panel
->nameLabel
, WALeft
);
251 font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 14);
252 WMSetLabelFont(panel
->nameLabel
, font
);
254 if (aicon
->wm_class
&& strcmp(aicon
->wm_class
, "DockApp") == 0)
255 WMSetLabelText(panel
->nameLabel
, aicon
->wm_instance
);
257 WMSetLabelText(panel
->nameLabel
, aicon
->wm_class
);
259 vbox
= WMCreateBox(panel
->win
);
260 WMResizeWidget(vbox
, PWIDTH
- 20, PHEIGHT
- 84 - 10);
261 WMMoveWidget(vbox
, 10, 84);
263 panel
->autoLaunchBtn
= WMCreateSwitchButton(vbox
);
264 WMAddBoxSubview(vbox
, WMWidgetView(panel
->autoLaunchBtn
), False
, True
, 20, 20, 2);
265 WMSetButtonText(panel
->autoLaunchBtn
, _("Start when Window Maker is started"));
266 WMSetButtonSelected(panel
->autoLaunchBtn
, aicon
->auto_launch
);
268 panel
->lockBtn
= WMCreateSwitchButton(vbox
);
269 WMAddBoxSubview(vbox
, WMWidgetView(panel
->lockBtn
), False
, True
, 20, 20, 5);
270 WMSetButtonText(panel
->lockBtn
, _("Lock (prevent accidental removal)"));
271 WMSetButtonSelected(panel
->lockBtn
, aicon
->lock
);
273 panel
->commandFrame
= WMCreateFrame(vbox
);
274 WMSetFrameTitle(panel
->commandFrame
, _("Application path and arguments"));
275 WMAddBoxSubview(vbox
, WMWidgetView(panel
->commandFrame
), False
, True
, 50, 50, 5);
277 panel
->commandField
= WMCreateTextField(panel
->commandFrame
);
278 WMResizeWidget(panel
->commandField
, 256, 20);
279 WMMoveWidget(panel
->commandField
, 10, 20);
280 WMSetTextFieldText(panel
->commandField
, aicon
->command
);
282 WMMapSubwidgets(panel
->commandFrame
);
284 panel
->pasteCommandFrame
= WMCreateFrame(vbox
);
285 WMSetFrameTitle(panel
->pasteCommandFrame
, _("Command for middle-click launch"));
286 WMAddBoxSubview(vbox
, WMWidgetView(panel
->pasteCommandFrame
), False
, True
, 70, 70, 5);
288 panel
->pasteCommandField
= WMCreateTextField(panel
->pasteCommandFrame
);
289 WMResizeWidget(panel
->pasteCommandField
, 256, 20);
290 WMMoveWidget(panel
->pasteCommandField
, 10, 20);
292 panel
->pasteCommandLabel
= WMCreateLabel(panel
->pasteCommandFrame
);
293 WMResizeWidget(panel
->pasteCommandLabel
, 256, 18);
294 WMMoveWidget(panel
->pasteCommandLabel
, 10, 45);
296 WMSetTextFieldText(panel
->pasteCommandField
, aicon
->paste_command
);
297 WMSetLabelText(panel
->pasteCommandLabel
, _("%s will be replaced with current selection"));
298 WMMapSubwidgets(panel
->pasteCommandFrame
);
300 panel
->dndCommandFrame
= WMCreateFrame(vbox
);
301 WMSetFrameTitle(panel
->dndCommandFrame
, _("Command for files dropped with DND"));
302 WMAddBoxSubview(vbox
, WMWidgetView(panel
->dndCommandFrame
), False
, True
, 70, 70, 5);
304 panel
->dndCommandField
= WMCreateTextField(panel
->dndCommandFrame
);
305 WMResizeWidget(panel
->dndCommandField
, 256, 20);
306 WMMoveWidget(panel
->dndCommandField
, 10, 20);
308 panel
->dndCommandLabel
= WMCreateLabel(panel
->dndCommandFrame
);
309 WMResizeWidget(panel
->dndCommandLabel
, 256, 18);
310 WMMoveWidget(panel
->dndCommandLabel
, 10, 45);
312 WMSetTextFieldText(panel
->dndCommandField
, aicon
->dnd_command
);
313 WMSetLabelText(panel
->dndCommandLabel
, _("%d will be replaced with the file name"));
315 WMSetTextFieldEditable(panel
->dndCommandField
, False
);
316 WMSetLabelText(panel
->dndCommandLabel
, _("DND support was not compiled in"));
318 WMMapSubwidgets(panel
->dndCommandFrame
);
320 panel
->iconFrame
= WMCreateFrame(vbox
);
321 WMSetFrameTitle(panel
->iconFrame
, _("Icon Image"));
322 WMAddBoxSubview(vbox
, WMWidgetView(panel
->iconFrame
), False
, True
, 50, 50, 10);
324 panel
->iconField
= WMCreateTextField(panel
->iconFrame
);
325 WMResizeWidget(panel
->iconField
, 176, 20);
326 WMMoveWidget(panel
->iconField
, 10, 20);
327 WMSetTextFieldText(panel
->iconField
, wDefaultGetIconFile(aicon
->wm_instance
, aicon
->wm_class
, False
));
329 panel
->browseBtn
= WMCreateCommandButton(panel
->iconFrame
);
330 WMResizeWidget(panel
->browseBtn
, 70, 24);
331 WMMoveWidget(panel
->browseBtn
, 195, 18);
332 WMSetButtonText(panel
->browseBtn
, _("Browse..."));
333 WMSetButtonAction(panel
->browseBtn
, chooseIconCallback
, panel
);
338 hbox
= WMCreateBox(vbox
);
339 WMSetBoxHorizontal(hbox
, True
);
340 WMAddBoxSubview(vbox
, WMWidgetView(hbox
), False
, True
, 24, 24, 0);
342 panel
->okBtn
= WMCreateCommandButton(hbox
);
343 WMSetButtonText(panel
->okBtn
, _("OK"));
344 WMSetButtonAction(panel
->okBtn
, panelBtnCallback
, panel
);
345 WMAddBoxSubviewAtEnd(hbox
, WMWidgetView(panel
->okBtn
), False
, True
, 80, 80, 0);
347 panel
->cancelBtn
= WMCreateCommandButton(hbox
);
348 WMSetButtonText(panel
->cancelBtn
, _("Cancel"));
349 WMSetButtonAction(panel
->cancelBtn
, panelBtnCallback
, panel
);
350 WMAddBoxSubviewAtEnd(hbox
, WMWidgetView(panel
->cancelBtn
), False
, True
, 80, 80, 5);
352 WMMapSubwidgets(hbox
);
355 WMRealizeWidget(panel
->win
);
356 WMMapSubwidgets(panel
->win
);
357 WMMapSubwidgets(vbox
);
358 WMMapSubwidgets(panel
->iconFrame
);
360 updateSettingsPanelIcon(panel
);
362 parent
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, PWIDTH
, PHEIGHT
, 0, 0, 0);
363 XSelectInput(dpy
, parent
, KeyPressMask
| KeyReleaseMask
);
365 XReparentWindow(dpy
, WMWidgetXID(panel
->win
), parent
, 0, 0);
368 * make things relative to head
371 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
376 else if (y
+ PHEIGHT
> rect
.pos
.y
+ rect
.size
.height
)
377 y
= rect
.pos
.y
+ rect
.size
.height
- PHEIGHT
- 30;
379 if (aicon
->dock
&& aicon
->dock
->type
== WM_DOCK
) {
380 if (aicon
->dock
->on_right_side
)
381 x
= rect
.pos
.x
+ rect
.size
.width
/ 2;
383 x
= rect
.pos
.x
+ rect
.size
.width
/ 2 - PWIDTH
- 2;
385 x
= rect
.pos
.x
+ (rect
.size
.width
- PWIDTH
) / 2;
389 panel
->wwin
= wManageInternalWindow(scr
, parent
, None
,
390 _("Docked Application Settings"), x
, y
, PWIDTH
, PHEIGHT
);
392 panel
->wwin
->client_leader
= WMWidgetXID(panel
->win
);
394 panel
->parent
= parent
;
396 WMMapWidget(panel
->win
);
398 wWindowMap(panel
->wwin
);
401 void DestroyDockAppSettingsPanel(AppSettingsPanel
* panel
)
403 if (!panel
->destroyed
) {
404 XUnmapWindow(dpy
, panel
->wwin
->client_win
);
405 XReparentWindow(dpy
, panel
->wwin
->client_win
, panel
->wwin
->screen_ptr
->root_win
, 0, 0);
406 wUnmanageWindow(panel
->wwin
, False
, False
);
409 panel
->destroyed
= 1;
412 * kluge. If we destroy the panel before the icon chooser is closed,
413 * we will crash when it does close, trying to access something in the
414 * destroyed panel. Could use wretain()/wrelease() in the panel,
415 * but it is not working for some reason.
417 if (panel
->choosingIcon
)
420 WMDestroyWidget(panel
->win
);
422 XDestroyWindow(dpy
, panel
->parent
);
424 panel
->editedIcon
->panel
= NULL
;
426 panel
->editedIcon
->editing
= 0;