1 /* dockedapp.c- docked application settings panel
3 * Window Maker window manager
5 * Copyright (c) 1998 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"
43 /**** Global variables ****/
44 extern WPreferences wPreferences
;
48 typedef struct _AppSettingsPanel
{
57 WMFrame
*commandFrame
;
58 WMTextField
*commandField
;
60 WMFrame
*dndCommandFrame
;
61 WMTextField
*dndCommandField
;
62 WMLabel
*dndCommandLabel
;
64 WMFrame
*pasteCommandFrame
;
65 WMTextField
*pasteCommandField
;
66 WMLabel
*pasteCommandLabel
;
69 WMTextField
*iconField
;
72 WMButton
*autoLaunchBtn
;
81 unsigned int destroyed
:1;
82 unsigned int choosingIcon
:1;
86 void DestroyDockAppSettingsPanel(AppSettingsPanel
*panel
);
90 updateCommand(WAppIcon
*icon
, char *command
)
94 if (command
&& (command
[0]==0 || (command
[0]=='-' && command
[1]==0))) {
98 icon
->command
= command
;
100 if (!icon
->wm_class
&& !icon
->wm_instance
&& icon
->command
101 && strlen(icon
->command
)>0) {
102 icon
->forced_dock
= 1;
108 updatePasteCommand(WAppIcon
*icon
, char *command
)
110 if (icon
->paste_command
)
111 wfree(icon
->paste_command
);
112 if (command
&& (command
[0]==0 || (command
[0]=='-' && command
[1]==0))) {
116 icon
->paste_command
= command
;
123 updateDNDCommand(WAppIcon
*icon
, char *command
)
125 if (icon
->dnd_command
)
126 wfree(icon
->dnd_command
);
127 if (command
&& (command
[0]==0 || (command
[0]=='-' && command
[1]==0))) {
131 icon
->dnd_command
= command
;
133 #endif /* OFFIX_DND */
137 updateSettingsPanelIcon(AppSettingsPanel
*panel
)
141 file
= WMGetTextFieldText(panel
->iconField
);
143 WMSetLabelImage(panel
->iconLabel
, NULL
);
147 path
= FindImage(wPreferences
.icon_path
, file
);
149 wwarning(_("could not find icon %s, used in a docked application"),
152 WMSetLabelImage(panel
->iconLabel
, NULL
);
162 pixmap
= WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel
->win
),
165 WMSetLabelImage(panel
->iconLabel
, NULL
);
167 WMSetLabelImage(panel
->iconLabel
, pixmap
);
168 WMReleasePixmap(pixmap
);
178 chooseIconCallback(WMWidget
*self
, void *clientData
)
181 AppSettingsPanel
*panel
= (AppSettingsPanel
*)clientData
;
184 panel
->choosingIcon
= 1;
186 WMSetButtonEnabled(panel
->browseBtn
, False
);
188 result
= wIconChooserDialog(panel
->wwin
->screen_ptr
, &file
,
189 panel
->editedIcon
->wm_instance
,
190 panel
->editedIcon
->wm_class
);
192 panel
->choosingIcon
= 0;
193 if (!panel
->destroyed
) {
195 WMSetTextFieldText(panel
->iconField
, file
);
197 updateSettingsPanelIcon(panel
);
200 WMSetButtonEnabled(panel
->browseBtn
, True
);
202 /* kluge for the case, the user asked to close the panel before
203 * the icon chooser */
204 DestroyDockAppSettingsPanel(panel
);
210 panelBtnCallback(WMWidget
*self
, void *data
)
212 WMButton
*btn
= self
;
213 AppSettingsPanel
*panel
= (AppSettingsPanel
*)data
;
218 if (panel
->okBtn
== btn
) {
219 text
= WMGetTextFieldText(panel
->iconField
);
224 if (!wIconChangeImageFile(panel
->editedIcon
->icon
, text
)) {
226 int len
= strlen(text
) + 64;
229 snprintf(buf
, len
, _("Could not open specified icon file: %s"), text
);
230 if (wMessageDialog(panel
->wwin
->screen_ptr
, _("Error"), buf
,
231 _("OK"), _("Ignore"), NULL
) == WAPRDefault
) {
239 WAppIcon
*aicon
= panel
->editedIcon
;
241 if (aicon
== aicon
->icon
->core
->screen_ptr
->clip_icon
)
242 wClipIconPaint(aicon
);
244 wAppIconPaint(aicon
);
246 wDefaultChangeIcon(panel
->wwin
->screen_ptr
, aicon
->wm_instance
,
247 aicon
->wm_class
, text
);
252 /* cannot free text from this, because it will be not be duplicated
253 * in updateCommand */
254 text
= WMGetTextFieldText(panel
->commandField
);
259 updateCommand(panel
->editedIcon
, text
);
261 /* cannot free text from this, because it will be not be duplicated
262 * in updateDNDCommand */
263 text
= WMGetTextFieldText(panel
->dndCommandField
);
264 updateDNDCommand(panel
->editedIcon
, text
);
266 text
= WMGetTextFieldText(panel
->pasteCommandField
);
267 updatePasteCommand(panel
->editedIcon
, text
);
270 panel
->editedIcon
->auto_launch
=
271 WMGetButtonSelected(panel
->autoLaunchBtn
);
273 panel
->editedIcon
->lock
=
274 WMGetButtonSelected(panel
->lockBtn
);
278 DestroyDockAppSettingsPanel(panel
);
287 ShowDockAppSettingsPanel(WAppIcon
*aicon
)
289 AppSettingsPanel
*panel
;
290 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
296 panel
= wmalloc(sizeof(AppSettingsPanel
));
297 memset(panel
, 0, sizeof(AppSettingsPanel
));
299 panel
->editedIcon
= aicon
;
301 aicon
->panel
= panel
;
304 panel
->win
= WMCreateWindow(scr
->wmscreen
, "applicationSettings");
305 WMResizeWidget(panel
->win
, PWIDTH
, PHEIGHT
);
307 panel
->iconLabel
= WMCreateLabel(panel
->win
);
308 WMResizeWidget(panel
->iconLabel
, 64, 64);
309 WMMoveWidget(panel
->iconLabel
, 10, 10);
310 WMSetLabelImagePosition(panel
->iconLabel
, WIPImageOnly
);
312 panel
->nameLabel
= WMCreateLabel(panel
->win
);
313 WMResizeWidget(panel
->nameLabel
, 190, 18);
314 WMMoveWidget(panel
->nameLabel
, 80, 35);
315 WMSetLabelTextAlignment(panel
->nameLabel
, WALeft
);
316 font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 14);
317 WMSetLabelFont(panel
->nameLabel
, font
);
319 if (aicon
->wm_class
&& strcmp(aicon
->wm_class
, "DockApp")==0)
320 WMSetLabelText(panel
->nameLabel
, aicon
->wm_instance
);
322 WMSetLabelText(panel
->nameLabel
, aicon
->wm_class
);
325 vbox
= WMCreateBox(panel
->win
);
326 WMResizeWidget(vbox
, PWIDTH
-20, PHEIGHT
-84-10);
327 WMMoveWidget(vbox
, 10, 84);
329 panel
->autoLaunchBtn
= WMCreateSwitchButton(vbox
);
330 WMAddBoxSubview(vbox
, WMWidgetView(panel
->autoLaunchBtn
), False
, True
,
332 WMSetButtonText(panel
->autoLaunchBtn
,
333 _("Start when Window Maker is started"));
334 WMSetButtonSelected(panel
->autoLaunchBtn
, aicon
->auto_launch
);
336 panel
->lockBtn
= WMCreateSwitchButton(vbox
);
337 WMAddBoxSubview(vbox
, WMWidgetView(panel
->lockBtn
), False
, True
,
339 WMSetButtonText(panel
->lockBtn
,
340 _("Lock (prevent accidental removal)"));
341 WMSetButtonSelected(panel
->lockBtn
, aicon
->lock
);
343 panel
->commandFrame
= WMCreateFrame(vbox
);
344 WMSetFrameTitle(panel
->commandFrame
, _("Application path and arguments"));
345 WMAddBoxSubview(vbox
, WMWidgetView(panel
->commandFrame
), False
, True
,
348 panel
->commandField
= WMCreateTextField(panel
->commandFrame
);
349 WMResizeWidget(panel
->commandField
, 256, 20);
350 WMMoveWidget(panel
->commandField
, 10, 20);
351 WMSetTextFieldText(panel
->commandField
, aicon
->command
);
353 WMMapSubwidgets(panel
->commandFrame
);
355 panel
->pasteCommandFrame
= WMCreateFrame(vbox
);
356 WMSetFrameTitle(panel
->pasteCommandFrame
,
357 _("Command for middle-click launch"));
358 WMAddBoxSubview(vbox
, WMWidgetView(panel
->pasteCommandFrame
), False
, True
,
361 panel
->pasteCommandField
= WMCreateTextField(panel
->pasteCommandFrame
);
362 WMResizeWidget(panel
->pasteCommandField
, 256, 20);
363 WMMoveWidget(panel
->pasteCommandField
, 10, 20);
365 panel
->pasteCommandLabel
= WMCreateLabel(panel
->pasteCommandFrame
);
366 WMResizeWidget(panel
->pasteCommandLabel
, 256, 18);
367 WMMoveWidget(panel
->pasteCommandLabel
, 10, 45);
369 WMSetTextFieldText(panel
->pasteCommandField
, aicon
->paste_command
);
370 WMSetLabelText(panel
->pasteCommandLabel
,
371 _("%s will be replaced with current selection"));
372 WMMapSubwidgets(panel
->pasteCommandFrame
);
374 panel
->dndCommandFrame
= WMCreateFrame(vbox
);
375 WMSetFrameTitle(panel
->dndCommandFrame
,
376 _("Command for files dropped with DND"));
377 WMAddBoxSubview(vbox
, WMWidgetView(panel
->dndCommandFrame
), False
, True
,
380 panel
->dndCommandField
= WMCreateTextField(panel
->dndCommandFrame
);
381 WMResizeWidget(panel
->dndCommandField
, 256, 20);
382 WMMoveWidget(panel
->dndCommandField
, 10, 20);
384 panel
->dndCommandLabel
= WMCreateLabel(panel
->dndCommandFrame
);
385 WMResizeWidget(panel
->dndCommandLabel
, 256, 18);
386 WMMoveWidget(panel
->dndCommandLabel
, 10, 45);
388 WMSetTextFieldText(panel
->dndCommandField
, aicon
->dnd_command
);
389 WMSetLabelText(panel
->dndCommandLabel
,
390 _("%d will be replaced with the file name"));
392 WMSetTextFieldEditable(panel
->dndCommandField
, False
);
393 WMSetLabelText(panel
->dndCommandLabel
,
394 _("DND support was not compiled in"));
396 WMMapSubwidgets(panel
->dndCommandFrame
);
398 panel
->iconFrame
= WMCreateFrame(vbox
);
399 WMSetFrameTitle(panel
->iconFrame
, _("Icon Image"));
400 WMAddBoxSubview(vbox
, WMWidgetView(panel
->iconFrame
), False
, True
,
403 panel
->iconField
= WMCreateTextField(panel
->iconFrame
);
404 WMResizeWidget(panel
->iconField
, 176, 20);
405 WMMoveWidget(panel
->iconField
, 10, 20);
406 WMSetTextFieldText(panel
->iconField
,
407 wDefaultGetIconFile(scr
, aicon
->wm_instance
,
408 aicon
->wm_class
, True
));
410 panel
->browseBtn
= WMCreateCommandButton(panel
->iconFrame
);
411 WMResizeWidget(panel
->browseBtn
, 70, 24);
412 WMMoveWidget(panel
->browseBtn
, 195, 18);
413 WMSetButtonText(panel
->browseBtn
, _("Browse..."));
414 WMSetButtonAction(panel
->browseBtn
, chooseIconCallback
, panel
);
420 hbox
= WMCreateBox(vbox
);
421 WMSetBoxHorizontal(hbox
, True
);
422 WMAddBoxSubview(vbox
, WMWidgetView(hbox
), False
, True
, 24, 24, 0);
425 panel
->okBtn
= WMCreateCommandButton(hbox
);
426 WMSetButtonText(panel
->okBtn
, _("OK"));
427 WMSetButtonAction(panel
->okBtn
, panelBtnCallback
, panel
);
428 WMAddBoxSubviewAtEnd(hbox
, WMWidgetView(panel
->okBtn
), False
, True
, 80, 80, 0);
430 panel
->cancelBtn
= WMCreateCommandButton(hbox
);
431 WMSetButtonText(panel
->cancelBtn
, _("Cancel"));
432 WMSetButtonAction(panel
->cancelBtn
, panelBtnCallback
, panel
);
433 WMAddBoxSubviewAtEnd(hbox
, WMWidgetView(panel
->cancelBtn
), False
, True
, 80, 80, 5);
435 WMMapSubwidgets(hbox
);
438 WMRealizeWidget(panel
->win
);
439 WMMapSubwidgets(panel
->win
);
440 WMMapSubwidgets(vbox
);
441 WMMapSubwidgets(panel
->iconFrame
);
443 updateSettingsPanelIcon(panel
);
445 parent
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, PWIDTH
, PHEIGHT
,
447 XSelectInput(dpy
, parent
, KeyPressMask
|KeyReleaseMask
);
449 XReparentWindow(dpy
, WMWidgetXID(panel
->win
), parent
, 0, 0);
454 else if (y
+ PHEIGHT
> scr
->scr_height
)
455 y
= scr
->scr_height
- PHEIGHT
- 30;
457 if (aicon
->dock
&& aicon
->dock
->type
== WM_DOCK
) {
458 if (aicon
->dock
->on_right_side
)
459 x
= scr
->scr_width
/2;
461 x
= scr
->scr_width
/2 - PWIDTH
- 2;
463 x
= (scr
->scr_width
- PWIDTH
)/2;
465 panel
->wwin
= wManageInternalWindow(scr
, parent
, None
,
466 _("Docked Application Settings"),
467 x
, y
, PWIDTH
, PHEIGHT
);
469 panel
->wwin
->client_leader
= WMWidgetXID(panel
->win
);
471 panel
->parent
= parent
;
473 WMMapWidget(panel
->win
);
475 wWindowMap(panel
->wwin
);
480 DestroyDockAppSettingsPanel(AppSettingsPanel
*panel
)
482 if (!panel
->destroyed
) {
483 XUnmapWindow(dpy
, panel
->wwin
->client_win
);
484 XReparentWindow(dpy
, panel
->wwin
->client_win
,
485 panel
->wwin
->screen_ptr
->root_win
, 0, 0);
486 wUnmanageWindow(panel
->wwin
, False
, False
);
489 panel
->destroyed
= 1;
492 * kluge. If we destroy the panel before the icon chooser is closed,
493 * we will crash when it does close, trying to access something in the
494 * destroyed panel. Could use wretain()/wrelease() in the panel,
495 * but it is not working for some reason.
497 if (panel
->choosingIcon
)
500 WMDestroyWidget(panel
->win
);
502 XDestroyWindow(dpy
, panel
->parent
);
504 panel
->editedIcon
->panel
= NULL
;
506 panel
->editedIcon
->editing
= 0;