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
;
74 unsigned int destroyed
:1;
75 unsigned int choosingIcon
:1;
79 void DestroyDockAppSettingsPanel(AppSettingsPanel
*panel
);
83 updateCommand(WAppIcon
*icon
, char *command
)
87 if (command
&& (command
[0]==0 || (command
[0]=='-' && command
[1]==0))) {
91 icon
->command
= command
;
93 if (!icon
->wm_class
&& !icon
->wm_instance
&&
94 icon
->command
&& strlen(icon
->command
)>0) {
95 icon
->forced_dock
= 1;
102 updateDNDCommand(WAppIcon
*icon
, char *command
)
104 if (icon
->dnd_command
)
105 free(icon
->dnd_command
);
106 if (command
&& (command
[0]==0 || (command
[0]=='-' && command
[1]==0))) {
110 icon
->dnd_command
= command
;
112 #endif /* OFFIX_DND */
116 updateSettingsPanelIcon(AppSettingsPanel
*panel
)
120 file
= WMGetTextFieldText(panel
->iconField
);
122 WMSetLabelImage(panel
->iconLabel
, NULL
);
126 path
= FindImage(wPreferences
.icon_path
, file
);
128 wwarning(_("could not find icon %s, used in a docked application"),
131 WMSetLabelImage(panel
->iconLabel
, NULL
);
141 pixmap
= WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel
->win
),
144 WMSetLabelImage(panel
->iconLabel
, NULL
);
146 WMSetLabelImage(panel
->iconLabel
, pixmap
);
147 WMReleasePixmap(pixmap
);
157 chooseIconCallback(WMWidget
*self
, void *clientData
)
160 AppSettingsPanel
*panel
= (AppSettingsPanel
*)clientData
;
163 panel
->choosingIcon
= 1;
165 WMSetButtonEnabled(panel
->browseBtn
, False
);
167 result
= wIconChooserDialog(panel
->wwin
->screen_ptr
, &file
);
169 panel
->choosingIcon
= 0;
170 if (!panel
->destroyed
) {
172 WMSetTextFieldText(panel
->iconField
, file
);
174 updateSettingsPanelIcon(panel
);
177 WMSetButtonEnabled(panel
->browseBtn
, True
);
179 /* kluge for the case, the user asked to close the panel before
180 * the icon chooser */
181 DestroyDockAppSettingsPanel(panel
);
187 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
)) {
204 buf
= wmalloc(strlen(text
) + 64);
205 sprintf(buf
, _("Could not open specified icon file:%s"), text
);
206 wMessageDialog(panel
->wwin
->screen_ptr
, _("Error"), buf
, _("OK"),
212 WAppIcon
*aicon
= panel
->editedIcon
;
214 if (aicon
== aicon
->icon
->core
->screen_ptr
->clip_icon
)
215 wClipIconPaint(aicon
);
217 wAppIconPaint(aicon
);
219 wDefaultChangeIcon(panel
->wwin
->screen_ptr
, aicon
->wm_instance
,
220 aicon
->wm_class
, text
);
225 /* cannot free text from this, because it will be not be duplicated
226 * in updateCommand */
227 text
= WMGetTextFieldText(panel
->commandField
);
232 updateCommand(panel
->editedIcon
, text
);
234 /* cannot free text from this, because it will be not be duplicated
235 * in updateDNDCommand */
236 text
= WMGetTextFieldText(panel
->dndCommandField
);
237 updateDNDCommand(panel
->editedIcon
, text
);
240 panel
->editedIcon
->auto_launch
=
241 WMGetButtonSelected(panel
->autoLaunchBtn
);
245 DestroyDockAppSettingsPanel(panel
);
254 ShowDockAppSettingsPanel(WAppIcon
*aicon
)
256 AppSettingsPanel
*panel
;
257 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
262 panel
= wmalloc(sizeof(AppSettingsPanel
));
263 memset(panel
, 0, sizeof(AppSettingsPanel
));
265 panel
->editedIcon
= aicon
;
267 aicon
->panel
= panel
;
270 panel
->win
= WMCreateWindow(scr
->wmscreen
, "applicationSettings");
271 WMResizeWidget(panel
->win
, PWIDTH
, PHEIGHT
);
273 panel
->iconLabel
= WMCreateLabel(panel
->win
);
274 WMResizeWidget(panel
->iconLabel
, 64, 64);
275 WMMoveWidget(panel
->iconLabel
, 10, 10);
276 WMSetLabelImagePosition(panel
->iconLabel
, WIPImageOnly
);
278 panel
->nameLabel
= WMCreateLabel(panel
->win
);
279 WMResizeWidget(panel
->nameLabel
, 190, 18);
280 WMMoveWidget(panel
->nameLabel
, 80, 35);
281 WMSetLabelTextAlignment(panel
->nameLabel
, WALeft
);
282 font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 14);
283 WMSetLabelFont(panel
->nameLabel
, font
);
285 WMSetLabelText(panel
->nameLabel
, aicon
->wm_class
);
287 panel
->autoLaunchBtn
= WMCreateSwitchButton(panel
->win
);
288 WMResizeWidget(panel
->autoLaunchBtn
, PWIDTH
-30, 20);
289 WMMoveWidget(panel
->autoLaunchBtn
, 15, 80);
290 WMSetButtonText(panel
->autoLaunchBtn
,
291 _("Start when WindowMaker is started"));
292 WMSetButtonSelected(panel
->autoLaunchBtn
, aicon
->auto_launch
);
295 panel
->commandFrame
= WMCreateFrame(panel
->win
);
296 WMResizeWidget(panel
->commandFrame
, 275, 50);
297 WMMoveWidget(panel
->commandFrame
, 10, 105);
298 WMSetFrameTitle(panel
->commandFrame
, _("Application path and arguments"));
300 panel
->commandField
= WMCreateTextField(panel
->commandFrame
);
301 WMResizeWidget(panel
->commandField
, 256, 20);
302 WMMoveWidget(panel
->commandField
, 10, 20);
303 WMSetTextFieldText(panel
->commandField
, aicon
->command
);
305 panel
->dndCommandFrame
= WMCreateFrame(panel
->win
);
306 WMResizeWidget(panel
->dndCommandFrame
, 275, 70);
307 WMMoveWidget(panel
->dndCommandFrame
, 10, 165);
308 WMSetFrameTitle(panel
->dndCommandFrame
,
309 _("Command for files dropped with DND"));
311 panel
->dndCommandField
= WMCreateTextField(panel
->dndCommandFrame
);
312 WMResizeWidget(panel
->dndCommandField
, 256, 20);
313 WMMoveWidget(panel
->dndCommandField
, 10, 20);
315 panel
->dndCommandLabel
= WMCreateLabel(panel
->dndCommandFrame
);
316 WMResizeWidget(panel
->dndCommandLabel
, 256, 18);
317 WMMoveWidget(panel
->dndCommandLabel
, 10, 45);
319 WMSetTextFieldText(panel
->dndCommandField
, aicon
->dnd_command
);
320 WMSetLabelText(panel
->dndCommandLabel
,
321 _("%d will be replaced with the file name"));
323 WMSetTextFieldEnabled(panel
->dndCommandField
, False
);
324 WMSetLabelText(panel
->dndCommandLabel
,
325 _("DND support was not compiled in"));
328 panel
->iconFrame
= WMCreateFrame(panel
->win
);
329 WMResizeWidget(panel
->iconFrame
, 275, 50);
330 WMMoveWidget(panel
->iconFrame
, 10, 245);
331 WMSetFrameTitle(panel
->iconFrame
, _("Icon Image"));
333 panel
->iconField
= WMCreateTextField(panel
->iconFrame
);
334 WMResizeWidget(panel
->iconField
, 176, 20);
335 WMMoveWidget(panel
->iconField
, 10, 20);
336 WMSetTextFieldText(panel
->iconField
,
337 wDefaultGetIconFile(scr
, aicon
->wm_instance
,
338 aicon
->wm_class
, True
));
340 panel
->browseBtn
= WMCreateCommandButton(panel
->iconFrame
);
341 WMResizeWidget(panel
->browseBtn
, 70, 24);
342 WMMoveWidget(panel
->browseBtn
, 195, 18);
343 WMSetButtonText(panel
->browseBtn
, _("Browse..."));
344 WMSetButtonAction(panel
->browseBtn
, chooseIconCallback
, panel
);
347 panel
->okBtn
= WMCreateCommandButton(panel
->win
);
348 WMResizeWidget(panel
->okBtn
, 80, 26);
349 WMMoveWidget(panel
->okBtn
, 200, 308);
350 WMSetButtonText(panel
->okBtn
, _("OK"));
351 WMSetButtonAction(panel
->okBtn
, panelBtnCallback
, panel
);
353 panel
->cancelBtn
= WMCreateCommandButton(panel
->win
);
354 WMResizeWidget(panel
->cancelBtn
, 80, 26);
355 WMMoveWidget(panel
->cancelBtn
, 110, 308);
356 WMSetButtonText(panel
->cancelBtn
, _("Cancel"));
357 WMSetButtonAction(panel
->cancelBtn
, panelBtnCallback
, panel
);
359 WMRealizeWidget(panel
->win
);
360 WMMapSubwidgets(panel
->win
);
361 WMMapSubwidgets(panel
->commandFrame
);
362 WMMapSubwidgets(panel
->dndCommandFrame
);
363 WMMapSubwidgets(panel
->iconFrame
);
365 updateSettingsPanelIcon(panel
);
367 parent
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, PWIDTH
, PHEIGHT
,
369 XSelectInput(dpy
, parent
, KeyPressMask
|KeyReleaseMask
);
371 XReparentWindow(dpy
, WMWidgetXID(panel
->win
), parent
, 0, 0);
376 else if (y
+ PWIDTH
> scr
->scr_height
)
377 y
= scr
->scr_height
- PHEIGHT
- 30;
379 if (aicon
->dock
&& aicon
->dock
->type
== WM_DOCK
) {
380 if (aicon
->dock
->on_right_side
)
381 x
= scr
->scr_width
/2;
383 x
= scr
->scr_width
/2 - PWIDTH
;
385 x
= (scr
->scr_width
- PWIDTH
)/2;
387 panel
->wwin
= wManageInternalWindow(scr
, parent
, None
,
388 _("Docked Application Settings"),
389 x
, y
, PWIDTH
, PHEIGHT
);
391 panel
->wwin
->client_leader
= WMWidgetXID(panel
->win
);
393 WMMapWidget(panel
->win
);
395 wWindowMap(panel
->wwin
);
400 DestroyDockAppSettingsPanel(AppSettingsPanel
*panel
)
402 if (!panel
->destroyed
) {
403 XUnmapWindow(dpy
, panel
->wwin
->client_win
);
404 XReparentWindow(dpy
, panel
->wwin
->client_win
,
405 panel
->wwin
->screen_ptr
->root_win
, 0, 0);
406 wUnmanageWindow(panel
->wwin
, 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
->wwin
->client_win
);
424 panel
->editedIcon
->panel
= NULL
;
426 panel
->editedIcon
->editing
= 0;