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,
27 #include <X11/Xutil.h>
31 #include "WindowMaker.h"
44 /**** Global variables ****/
45 extern WPreferences wPreferences
;
49 typedef struct _AppSettingsPanel
{
58 WMFrame
*commandFrame
;
59 WMTextField
*commandField
;
61 WMFrame
*dndCommandFrame
;
62 WMTextField
*dndCommandField
;
63 WMLabel
*dndCommandLabel
;
65 WMFrame
*pasteCommandFrame
;
66 WMTextField
*pasteCommandField
;
67 WMLabel
*pasteCommandLabel
;
70 WMTextField
*iconField
;
73 WMButton
*autoLaunchBtn
;
82 unsigned int destroyed
:1;
83 unsigned int choosingIcon
:1;
87 void DestroyDockAppSettingsPanel(AppSettingsPanel
*panel
);
91 updateCommand(WAppIcon
*icon
, char *command
)
95 if (command
&& (command
[0]==0 || (command
[0]=='-' && command
[1]==0))) {
99 icon
->command
= command
;
101 if (!icon
->wm_class
&& !icon
->wm_instance
&& icon
->command
102 && strlen(icon
->command
)>0) {
103 icon
->forced_dock
= 1;
109 updatePasteCommand(WAppIcon
*icon
, char *command
)
111 if (icon
->paste_command
)
112 wfree(icon
->paste_command
);
113 if (command
&& (command
[0]==0 || (command
[0]=='-' && command
[1]==0))) {
117 icon
->paste_command
= command
;
124 updateDNDCommand(WAppIcon
*icon
, char *command
)
126 if (icon
->dnd_command
)
127 wfree(icon
->dnd_command
);
128 if (command
&& (command
[0]==0 || (command
[0]=='-' && command
[1]==0))) {
132 icon
->dnd_command
= command
;
134 #endif /* OFFIX_DND */
138 updateSettingsPanelIcon(AppSettingsPanel
*panel
)
142 file
= WMGetTextFieldText(panel
->iconField
);
144 WMSetLabelImage(panel
->iconLabel
, NULL
);
148 path
= FindImage(wPreferences
.icon_path
, file
);
150 wwarning(_("could not find icon %s, used in a docked application"),
153 WMSetLabelImage(panel
->iconLabel
, NULL
);
163 pixmap
= WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel
->win
),
166 WMSetLabelImage(panel
->iconLabel
, NULL
);
168 WMSetLabelImage(panel
->iconLabel
, pixmap
);
169 WMReleasePixmap(pixmap
);
179 chooseIconCallback(WMWidget
*self
, void *clientData
)
182 AppSettingsPanel
*panel
= (AppSettingsPanel
*)clientData
;
185 panel
->choosingIcon
= 1;
187 WMSetButtonEnabled(panel
->browseBtn
, False
);
189 result
= wIconChooserDialog(panel
->wwin
->screen_ptr
, &file
,
190 panel
->editedIcon
->wm_instance
,
191 panel
->editedIcon
->wm_class
);
193 panel
->choosingIcon
= 0;
194 if (!panel
->destroyed
) {
196 WMSetTextFieldText(panel
->iconField
, file
);
198 updateSettingsPanelIcon(panel
);
201 WMSetButtonEnabled(panel
->browseBtn
, True
);
203 /* kluge for the case, the user asked to close the panel before
204 * the icon chooser */
205 DestroyDockAppSettingsPanel(panel
);
211 panelBtnCallback(WMWidget
*self
, void *data
)
213 WMButton
*btn
= self
;
214 AppSettingsPanel
*panel
= (AppSettingsPanel
*)data
;
219 if (panel
->okBtn
== btn
) {
220 text
= WMGetTextFieldText(panel
->iconField
);
225 if (!wIconChangeImageFile(panel
->editedIcon
->icon
, text
)) {
227 int len
= strlen(text
) + 64;
230 snprintf(buf
, len
, _("Could not open specified icon file: %s"), text
);
231 if (wMessageDialog(panel
->wwin
->screen_ptr
, _("Error"), buf
,
232 _("OK"), _("Ignore"), NULL
) == WAPRDefault
) {
240 WAppIcon
*aicon
= panel
->editedIcon
;
242 if (aicon
== aicon
->icon
->core
->screen_ptr
->clip_icon
)
243 wClipIconPaint(aicon
);
245 wAppIconPaint(aicon
);
247 wDefaultChangeIcon(panel
->wwin
->screen_ptr
, aicon
->wm_instance
,
248 aicon
->wm_class
, text
);
253 /* cannot free text from this, because it will be not be duplicated
254 * in updateCommand */
255 text
= WMGetTextFieldText(panel
->commandField
);
260 updateCommand(panel
->editedIcon
, text
);
262 /* cannot free text from this, because it will be not be duplicated
263 * in updateDNDCommand */
264 text
= WMGetTextFieldText(panel
->dndCommandField
);
265 updateDNDCommand(panel
->editedIcon
, text
);
267 text
= WMGetTextFieldText(panel
->pasteCommandField
);
268 updatePasteCommand(panel
->editedIcon
, text
);
271 panel
->editedIcon
->auto_launch
=
272 WMGetButtonSelected(panel
->autoLaunchBtn
);
274 panel
->editedIcon
->lock
=
275 WMGetButtonSelected(panel
->lockBtn
);
279 DestroyDockAppSettingsPanel(panel
);
288 ShowDockAppSettingsPanel(WAppIcon
*aicon
)
290 AppSettingsPanel
*panel
;
291 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
297 panel
= wmalloc(sizeof(AppSettingsPanel
));
298 memset(panel
, 0, sizeof(AppSettingsPanel
));
300 panel
->editedIcon
= aicon
;
302 aicon
->panel
= panel
;
305 panel
->win
= WMCreateWindow(scr
->wmscreen
, "applicationSettings");
306 WMResizeWidget(panel
->win
, PWIDTH
, PHEIGHT
);
308 panel
->iconLabel
= WMCreateLabel(panel
->win
);
309 WMResizeWidget(panel
->iconLabel
, 64, 64);
310 WMMoveWidget(panel
->iconLabel
, 10, 10);
311 WMSetLabelImagePosition(panel
->iconLabel
, WIPImageOnly
);
313 panel
->nameLabel
= WMCreateLabel(panel
->win
);
314 WMResizeWidget(panel
->nameLabel
, 190, 18);
315 WMMoveWidget(panel
->nameLabel
, 80, 35);
316 WMSetLabelTextAlignment(panel
->nameLabel
, WALeft
);
317 font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 14);
318 WMSetLabelFont(panel
->nameLabel
, font
);
320 if (aicon
->wm_class
&& strcmp(aicon
->wm_class
, "DockApp")==0)
321 WMSetLabelText(panel
->nameLabel
, aicon
->wm_instance
);
323 WMSetLabelText(panel
->nameLabel
, aicon
->wm_class
);
326 vbox
= WMCreateBox(panel
->win
);
327 WMResizeWidget(vbox
, PWIDTH
-20, PHEIGHT
-84-10);
328 WMMoveWidget(vbox
, 10, 84);
330 panel
->autoLaunchBtn
= WMCreateSwitchButton(vbox
);
331 WMAddBoxSubview(vbox
, WMWidgetView(panel
->autoLaunchBtn
), False
, True
,
333 WMSetButtonText(panel
->autoLaunchBtn
,
334 _("Start when Window Maker is started"));
335 WMSetButtonSelected(panel
->autoLaunchBtn
, aicon
->auto_launch
);
337 panel
->lockBtn
= WMCreateSwitchButton(vbox
);
338 WMAddBoxSubview(vbox
, WMWidgetView(panel
->lockBtn
), False
, True
,
340 WMSetButtonText(panel
->lockBtn
,
341 _("Lock (prevent accidental removal)"));
342 WMSetButtonSelected(panel
->lockBtn
, aicon
->lock
);
344 panel
->commandFrame
= WMCreateFrame(vbox
);
345 WMSetFrameTitle(panel
->commandFrame
, _("Application path and arguments"));
346 WMAddBoxSubview(vbox
, WMWidgetView(panel
->commandFrame
), False
, True
,
349 panel
->commandField
= WMCreateTextField(panel
->commandFrame
);
350 WMResizeWidget(panel
->commandField
, 256, 20);
351 WMMoveWidget(panel
->commandField
, 10, 20);
352 WMSetTextFieldText(panel
->commandField
, aicon
->command
);
354 WMMapSubwidgets(panel
->commandFrame
);
356 panel
->pasteCommandFrame
= WMCreateFrame(vbox
);
357 WMSetFrameTitle(panel
->pasteCommandFrame
,
358 _("Command for middle-click launch"));
359 WMAddBoxSubview(vbox
, WMWidgetView(panel
->pasteCommandFrame
), False
, True
,
362 panel
->pasteCommandField
= WMCreateTextField(panel
->pasteCommandFrame
);
363 WMResizeWidget(panel
->pasteCommandField
, 256, 20);
364 WMMoveWidget(panel
->pasteCommandField
, 10, 20);
366 panel
->pasteCommandLabel
= WMCreateLabel(panel
->pasteCommandFrame
);
367 WMResizeWidget(panel
->pasteCommandLabel
, 256, 18);
368 WMMoveWidget(panel
->pasteCommandLabel
, 10, 45);
370 WMSetTextFieldText(panel
->pasteCommandField
, aicon
->paste_command
);
371 WMSetLabelText(panel
->pasteCommandLabel
,
372 _("%s will be replaced with current selection"));
373 WMMapSubwidgets(panel
->pasteCommandFrame
);
375 panel
->dndCommandFrame
= WMCreateFrame(vbox
);
376 WMSetFrameTitle(panel
->dndCommandFrame
,
377 _("Command for files dropped with DND"));
378 WMAddBoxSubview(vbox
, WMWidgetView(panel
->dndCommandFrame
), False
, True
,
381 panel
->dndCommandField
= WMCreateTextField(panel
->dndCommandFrame
);
382 WMResizeWidget(panel
->dndCommandField
, 256, 20);
383 WMMoveWidget(panel
->dndCommandField
, 10, 20);
385 panel
->dndCommandLabel
= WMCreateLabel(panel
->dndCommandFrame
);
386 WMResizeWidget(panel
->dndCommandLabel
, 256, 18);
387 WMMoveWidget(panel
->dndCommandLabel
, 10, 45);
389 WMSetTextFieldText(panel
->dndCommandField
, aicon
->dnd_command
);
390 WMSetLabelText(panel
->dndCommandLabel
,
391 _("%d will be replaced with the file name"));
393 WMSetTextFieldEditable(panel
->dndCommandField
, False
);
394 WMSetLabelText(panel
->dndCommandLabel
,
395 _("DND support was not compiled in"));
397 WMMapSubwidgets(panel
->dndCommandFrame
);
399 panel
->iconFrame
= WMCreateFrame(vbox
);
400 WMSetFrameTitle(panel
->iconFrame
, _("Icon Image"));
401 WMAddBoxSubview(vbox
, WMWidgetView(panel
->iconFrame
), False
, True
,
404 panel
->iconField
= WMCreateTextField(panel
->iconFrame
);
405 WMResizeWidget(panel
->iconField
, 176, 20);
406 WMMoveWidget(panel
->iconField
, 10, 20);
407 WMSetTextFieldText(panel
->iconField
,
408 wDefaultGetIconFile(scr
, aicon
->wm_instance
,
409 aicon
->wm_class
, True
));
411 panel
->browseBtn
= WMCreateCommandButton(panel
->iconFrame
);
412 WMResizeWidget(panel
->browseBtn
, 70, 24);
413 WMMoveWidget(panel
->browseBtn
, 195, 18);
414 WMSetButtonText(panel
->browseBtn
, _("Browse..."));
415 WMSetButtonAction(panel
->browseBtn
, chooseIconCallback
, panel
);
421 hbox
= WMCreateBox(vbox
);
422 WMSetBoxHorizontal(hbox
, True
);
423 WMAddBoxSubview(vbox
, WMWidgetView(hbox
), False
, True
, 24, 24, 0);
426 panel
->okBtn
= WMCreateCommandButton(hbox
);
427 WMSetButtonText(panel
->okBtn
, _("OK"));
428 WMSetButtonAction(panel
->okBtn
, panelBtnCallback
, panel
);
429 WMAddBoxSubviewAtEnd(hbox
, WMWidgetView(panel
->okBtn
), False
, True
, 80, 80, 0);
431 panel
->cancelBtn
= WMCreateCommandButton(hbox
);
432 WMSetButtonText(panel
->cancelBtn
, _("Cancel"));
433 WMSetButtonAction(panel
->cancelBtn
, panelBtnCallback
, panel
);
434 WMAddBoxSubviewAtEnd(hbox
, WMWidgetView(panel
->cancelBtn
), False
, True
, 80, 80, 5);
436 WMMapSubwidgets(hbox
);
439 WMRealizeWidget(panel
->win
);
440 WMMapSubwidgets(panel
->win
);
441 WMMapSubwidgets(vbox
);
442 WMMapSubwidgets(panel
->iconFrame
);
444 updateSettingsPanelIcon(panel
);
446 parent
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, PWIDTH
, PHEIGHT
,
448 XSelectInput(dpy
, parent
, KeyPressMask
|KeyReleaseMask
);
450 XReparentWindow(dpy
, WMWidgetXID(panel
->win
), parent
, 0, 0);
453 * make things relative to head
456 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
461 else if (y
+ PHEIGHT
> rect
.pos
.y
+ rect
.size
.height
)
462 y
= rect
.pos
.y
+ rect
.size
.height
- PHEIGHT
- 30;
464 if (aicon
->dock
&& aicon
->dock
->type
== WM_DOCK
) {
465 if (aicon
->dock
->on_right_side
)
466 x
= rect
.pos
.x
+ rect
.size
.width
/2;
468 x
= rect
.pos
.x
+ rect
.size
.width
/2 - PWIDTH
- 2;
470 x
= rect
.pos
.x
+ (rect
.size
.width
- PWIDTH
)/2;
474 panel
->wwin
= wManageInternalWindow(scr
, parent
, None
,
475 _("Docked Application Settings"),
476 x
, y
, PWIDTH
, PHEIGHT
);
478 panel
->wwin
->client_leader
= WMWidgetXID(panel
->win
);
480 panel
->parent
= parent
;
482 WMMapWidget(panel
->win
);
484 wWindowMap(panel
->wwin
);
489 DestroyDockAppSettingsPanel(AppSettingsPanel
*panel
)
491 if (!panel
->destroyed
) {
492 XUnmapWindow(dpy
, panel
->wwin
->client_win
);
493 XReparentWindow(dpy
, panel
->wwin
->client_win
,
494 panel
->wwin
->screen_ptr
->root_win
, 0, 0);
495 wUnmanageWindow(panel
->wwin
, False
, False
);
498 panel
->destroyed
= 1;
501 * kluge. If we destroy the panel before the icon chooser is closed,
502 * we will crash when it does close, trying to access something in the
503 * destroyed panel. Could use wretain()/wrelease() in the panel,
504 * but it is not working for some reason.
506 if (panel
->choosingIcon
)
509 WMDestroyWidget(panel
->win
);
511 XDestroyWindow(dpy
, panel
->parent
);
513 panel
->editedIcon
->panel
= NULL
;
515 panel
->editedIcon
->editing
= 0;