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
;
65 WMTextField
*iconField
;
68 WMButton
*autoLaunchBtn
;
77 unsigned int destroyed
:1;
78 unsigned int choosingIcon
:1;
82 void DestroyDockAppSettingsPanel(AppSettingsPanel
*panel
);
86 updateCommand(WAppIcon
*icon
, char *command
)
90 if (command
&& (command
[0]==0 || (command
[0]=='-' && command
[1]==0))) {
94 icon
->command
= command
;
96 if (!icon
->wm_class
&& !icon
->wm_instance
&& icon
->command
97 && strlen(icon
->command
)>0) {
98 icon
->forced_dock
= 1;
105 updateDNDCommand(WAppIcon
*icon
, char *command
)
107 if (icon
->dnd_command
)
108 wfree(icon
->dnd_command
);
109 if (command
&& (command
[0]==0 || (command
[0]=='-' && command
[1]==0))) {
113 icon
->dnd_command
= command
;
115 #endif /* OFFIX_DND */
119 updateSettingsPanelIcon(AppSettingsPanel
*panel
)
123 file
= WMGetTextFieldText(panel
->iconField
);
125 WMSetLabelImage(panel
->iconLabel
, NULL
);
129 path
= FindImage(wPreferences
.icon_path
, file
);
131 wwarning(_("could not find icon %s, used in a docked application"),
134 WMSetLabelImage(panel
->iconLabel
, NULL
);
144 pixmap
= WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel
->win
),
147 WMSetLabelImage(panel
->iconLabel
, NULL
);
149 WMSetLabelImage(panel
->iconLabel
, pixmap
);
150 WMReleasePixmap(pixmap
);
160 chooseIconCallback(WMWidget
*self
, void *clientData
)
163 AppSettingsPanel
*panel
= (AppSettingsPanel
*)clientData
;
166 panel
->choosingIcon
= 1;
168 WMSetButtonEnabled(panel
->browseBtn
, False
);
170 result
= wIconChooserDialog(panel
->wwin
->screen_ptr
, &file
,
171 panel
->editedIcon
->wm_instance
,
172 panel
->editedIcon
->wm_class
);
174 panel
->choosingIcon
= 0;
175 if (!panel
->destroyed
) {
177 WMSetTextFieldText(panel
->iconField
, file
);
179 updateSettingsPanelIcon(panel
);
182 WMSetButtonEnabled(panel
->browseBtn
, True
);
184 /* kluge for the case, the user asked to close the panel before
185 * the icon chooser */
186 DestroyDockAppSettingsPanel(panel
);
192 panelBtnCallback(WMWidget
*self
, void *data
)
194 WMButton
*btn
= self
;
195 AppSettingsPanel
*panel
= (AppSettingsPanel
*)data
;
200 if (panel
->okBtn
== btn
) {
201 text
= WMGetTextFieldText(panel
->iconField
);
206 if (!wIconChangeImageFile(panel
->editedIcon
->icon
, text
)) {
208 int len
= strlen(text
) + 64;
211 snprintf(buf
, len
, _("Could not open specified icon file: %s"), text
);
212 if (wMessageDialog(panel
->wwin
->screen_ptr
, _("Error"), buf
,
213 _("OK"), _("Ignore"), NULL
) == WAPRDefault
) {
221 WAppIcon
*aicon
= panel
->editedIcon
;
223 if (aicon
== aicon
->icon
->core
->screen_ptr
->clip_icon
)
224 wClipIconPaint(aicon
);
226 wAppIconPaint(aicon
);
228 wDefaultChangeIcon(panel
->wwin
->screen_ptr
, aicon
->wm_instance
,
229 aicon
->wm_class
, text
);
234 /* cannot free text from this, because it will be not be duplicated
235 * in updateCommand */
236 text
= WMGetTextFieldText(panel
->commandField
);
241 updateCommand(panel
->editedIcon
, text
);
243 /* cannot free text from this, because it will be not be duplicated
244 * in updateDNDCommand */
245 text
= WMGetTextFieldText(panel
->dndCommandField
);
246 updateDNDCommand(panel
->editedIcon
, text
);
249 panel
->editedIcon
->auto_launch
=
250 WMGetButtonSelected(panel
->autoLaunchBtn
);
252 panel
->editedIcon
->lock
=
253 WMGetButtonSelected(panel
->lockBtn
);
257 DestroyDockAppSettingsPanel(panel
);
266 ShowDockAppSettingsPanel(WAppIcon
*aicon
)
268 AppSettingsPanel
*panel
;
269 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
274 panel
= wmalloc(sizeof(AppSettingsPanel
));
275 memset(panel
, 0, sizeof(AppSettingsPanel
));
277 panel
->editedIcon
= aicon
;
279 aicon
->panel
= panel
;
282 panel
->win
= WMCreateWindow(scr
->wmscreen
, "applicationSettings");
283 WMResizeWidget(panel
->win
, PWIDTH
, PHEIGHT
);
285 panel
->iconLabel
= WMCreateLabel(panel
->win
);
286 WMResizeWidget(panel
->iconLabel
, 64, 64);
287 WMMoveWidget(panel
->iconLabel
, 10, 10);
288 WMSetLabelImagePosition(panel
->iconLabel
, WIPImageOnly
);
290 panel
->nameLabel
= WMCreateLabel(panel
->win
);
291 WMResizeWidget(panel
->nameLabel
, 190, 18);
292 WMMoveWidget(panel
->nameLabel
, 80, 35);
293 WMSetLabelTextAlignment(panel
->nameLabel
, WALeft
);
294 font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 14);
295 WMSetLabelFont(panel
->nameLabel
, font
);
297 if (aicon
->wm_class
&& strcmp(aicon
->wm_class
, "DockApp")==0)
298 WMSetLabelText(panel
->nameLabel
, aicon
->wm_instance
);
300 WMSetLabelText(panel
->nameLabel
, aicon
->wm_class
);
302 panel
->autoLaunchBtn
= WMCreateSwitchButton(panel
->win
);
303 WMResizeWidget(panel
->autoLaunchBtn
, PWIDTH
-30, 20);
304 WMMoveWidget(panel
->autoLaunchBtn
, 15, 80);
305 WMSetButtonText(panel
->autoLaunchBtn
,
306 _("Start when Window Maker is started"));
307 WMSetButtonSelected(panel
->autoLaunchBtn
, aicon
->auto_launch
);
309 panel
->lockBtn
= WMCreateSwitchButton(panel
->win
);
310 WMResizeWidget(panel
->lockBtn
, PWIDTH
-30, 20);
311 WMMoveWidget(panel
->lockBtn
, 15, 100);
312 WMSetButtonText(panel
->lockBtn
,
313 _("Lock (prevent accidental removal)"));
314 WMSetButtonSelected(panel
->lockBtn
, aicon
->lock
);
316 panel
->commandFrame
= WMCreateFrame(panel
->win
);
317 WMResizeWidget(panel
->commandFrame
, 275, 50);
318 WMMoveWidget(panel
->commandFrame
, 10, 125);
319 WMSetFrameTitle(panel
->commandFrame
, _("Application path and arguments"));
321 panel
->commandField
= WMCreateTextField(panel
->commandFrame
);
322 WMResizeWidget(panel
->commandField
, 256, 20);
323 WMMoveWidget(panel
->commandField
, 10, 20);
324 WMSetTextFieldText(panel
->commandField
, aicon
->command
);
326 panel
->dndCommandFrame
= WMCreateFrame(panel
->win
);
327 WMResizeWidget(panel
->dndCommandFrame
, 275, 70);
328 WMMoveWidget(panel
->dndCommandFrame
, 10, 185);
329 WMSetFrameTitle(panel
->dndCommandFrame
,
330 _("Command for files dropped with DND"));
332 panel
->dndCommandField
= WMCreateTextField(panel
->dndCommandFrame
);
333 WMResizeWidget(panel
->dndCommandField
, 256, 20);
334 WMMoveWidget(panel
->dndCommandField
, 10, 20);
336 panel
->dndCommandLabel
= WMCreateLabel(panel
->dndCommandFrame
);
337 WMResizeWidget(panel
->dndCommandLabel
, 256, 18);
338 WMMoveWidget(panel
->dndCommandLabel
, 10, 45);
340 WMSetTextFieldText(panel
->dndCommandField
, aicon
->dnd_command
);
341 WMSetLabelText(panel
->dndCommandLabel
,
342 _("%d will be replaced with the file name"));
344 WMSetTextFieldEditable(panel
->dndCommandField
, False
);
345 WMSetLabelText(panel
->dndCommandLabel
,
346 _("DND support was not compiled in"));
349 panel
->iconFrame
= WMCreateFrame(panel
->win
);
350 WMResizeWidget(panel
->iconFrame
, 275, 50);
351 WMMoveWidget(panel
->iconFrame
, 10, 265);
352 WMSetFrameTitle(panel
->iconFrame
, _("Icon Image"));
354 panel
->iconField
= WMCreateTextField(panel
->iconFrame
);
355 WMResizeWidget(panel
->iconField
, 176, 20);
356 WMMoveWidget(panel
->iconField
, 10, 20);
357 WMSetTextFieldText(panel
->iconField
,
358 wDefaultGetIconFile(scr
, aicon
->wm_instance
,
359 aicon
->wm_class
, True
));
361 panel
->browseBtn
= WMCreateCommandButton(panel
->iconFrame
);
362 WMResizeWidget(panel
->browseBtn
, 70, 24);
363 WMMoveWidget(panel
->browseBtn
, 195, 18);
364 WMSetButtonText(panel
->browseBtn
, _("Browse..."));
365 WMSetButtonAction(panel
->browseBtn
, chooseIconCallback
, panel
);
368 panel
->okBtn
= WMCreateCommandButton(panel
->win
);
369 WMResizeWidget(panel
->okBtn
, 80, 26);
370 WMMoveWidget(panel
->okBtn
, 200, 328);
371 WMSetButtonText(panel
->okBtn
, _("OK"));
372 WMSetButtonAction(panel
->okBtn
, panelBtnCallback
, panel
);
374 panel
->cancelBtn
= WMCreateCommandButton(panel
->win
);
375 WMResizeWidget(panel
->cancelBtn
, 80, 26);
376 WMMoveWidget(panel
->cancelBtn
, 110, 328);
377 WMSetButtonText(panel
->cancelBtn
, _("Cancel"));
378 WMSetButtonAction(panel
->cancelBtn
, panelBtnCallback
, panel
);
380 WMRealizeWidget(panel
->win
);
381 WMMapSubwidgets(panel
->win
);
382 WMMapSubwidgets(panel
->commandFrame
);
383 WMMapSubwidgets(panel
->dndCommandFrame
);
384 WMMapSubwidgets(panel
->iconFrame
);
386 updateSettingsPanelIcon(panel
);
388 parent
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, PWIDTH
, PHEIGHT
,
390 XSelectInput(dpy
, parent
, KeyPressMask
|KeyReleaseMask
);
392 XReparentWindow(dpy
, WMWidgetXID(panel
->win
), parent
, 0, 0);
397 else if (y
+ PHEIGHT
> scr
->scr_height
)
398 y
= scr
->scr_height
- PHEIGHT
- 30;
400 if (aicon
->dock
&& aicon
->dock
->type
== WM_DOCK
) {
401 if (aicon
->dock
->on_right_side
)
402 x
= scr
->scr_width
/2;
404 x
= scr
->scr_width
/2 - PWIDTH
- 2;
406 x
= (scr
->scr_width
- PWIDTH
)/2;
408 panel
->wwin
= wManageInternalWindow(scr
, parent
, None
,
409 _("Docked Application Settings"),
410 x
, y
, PWIDTH
, PHEIGHT
);
412 panel
->wwin
->client_leader
= WMWidgetXID(panel
->win
);
414 panel
->parent
= parent
;
416 WMMapWidget(panel
->win
);
418 wWindowMap(panel
->wwin
);
423 DestroyDockAppSettingsPanel(AppSettingsPanel
*panel
)
425 if (!panel
->destroyed
) {
426 XUnmapWindow(dpy
, panel
->wwin
->client_win
);
427 XReparentWindow(dpy
, panel
->wwin
->client_win
,
428 panel
->wwin
->screen_ptr
->root_win
, 0, 0);
429 wUnmanageWindow(panel
->wwin
, False
, False
);
432 panel
->destroyed
= 1;
435 * kluge. If we destroy the panel before the icon chooser is closed,
436 * we will crash when it does close, trying to access something in the
437 * destroyed panel. Could use wretain()/wrelease() in the panel,
438 * but it is not working for some reason.
440 if (panel
->choosingIcon
)
443 WMDestroyWidget(panel
->win
);
445 XDestroyWindow(dpy
, panel
->parent
);
447 panel
->editedIcon
->panel
= NULL
;
449 panel
->editedIcon
->editing
= 0;