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
;
69 WMButton
*omnipresentBtn
;
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 free(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
;
197 int done
, omnipresent
;
200 if (panel
->okBtn
== btn
) {
201 text
= WMGetTextFieldText(panel
->iconField
);
206 if (!wIconChangeImageFile(panel
->editedIcon
->icon
, text
)) {
209 buf
= wmalloc(strlen(text
) + 64);
210 sprintf(buf
, _("Could not open specified icon file: %s"), text
);
211 if (wMessageDialog(panel
->wwin
->screen_ptr
, _("Error"), buf
,
212 _("OK"), _("Ignore"), NULL
) == WAPRDefault
) {
220 WAppIcon
*aicon
= panel
->editedIcon
;
222 if (aicon
== aicon
->icon
->core
->screen_ptr
->clip_icon
)
223 wClipIconPaint(aicon
);
225 wAppIconPaint(aicon
);
227 wDefaultChangeIcon(panel
->wwin
->screen_ptr
, aicon
->wm_instance
,
228 aicon
->wm_class
, text
);
233 /* cannot free text from this, because it will be not be duplicated
234 * in updateCommand */
235 text
= WMGetTextFieldText(panel
->commandField
);
240 updateCommand(panel
->editedIcon
, text
);
242 /* cannot free text from this, because it will be not be duplicated
243 * in updateDNDCommand */
244 text
= WMGetTextFieldText(panel
->dndCommandField
);
245 updateDNDCommand(panel
->editedIcon
, text
);
248 omnipresent
= WMGetButtonSelected(panel
->omnipresentBtn
);
249 if (wClipMakeIconOmnipresent(panel
->editedIcon
, omnipresent
) ==
251 wMessageDialog(panel
->wwin
->screen_ptr
, _("Error"),
252 _("Sorry, icon cannot be made omnipresent. "
253 "Please make sure that no other icon is "
254 "docked in the same position on the other "
255 "workspaces, and the Clip is not full in "
256 "some workspace, then try again."),
257 _("OK"), NULL
, NULL
);
261 panel
->editedIcon
->auto_launch
=
262 WMGetButtonSelected(panel
->autoLaunchBtn
);
266 DestroyDockAppSettingsPanel(panel
);
275 ShowDockAppSettingsPanel(WAppIcon
*aicon
)
277 AppSettingsPanel
*panel
;
278 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
283 panel
= wmalloc(sizeof(AppSettingsPanel
));
284 memset(panel
, 0, sizeof(AppSettingsPanel
));
286 panel
->editedIcon
= aicon
;
288 aicon
->panel
= panel
;
291 panel
->win
= WMCreateWindow(scr
->wmscreen
, "applicationSettings");
292 WMResizeWidget(panel
->win
, PWIDTH
, PHEIGHT
);
294 panel
->iconLabel
= WMCreateLabel(panel
->win
);
295 WMResizeWidget(panel
->iconLabel
, 64, 64);
296 WMMoveWidget(panel
->iconLabel
, 10, 10);
297 WMSetLabelImagePosition(panel
->iconLabel
, WIPImageOnly
);
299 panel
->nameLabel
= WMCreateLabel(panel
->win
);
300 WMResizeWidget(panel
->nameLabel
, 190, 18);
301 WMMoveWidget(panel
->nameLabel
, 80, 35);
302 WMSetLabelTextAlignment(panel
->nameLabel
, WALeft
);
303 font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 14);
304 WMSetLabelFont(panel
->nameLabel
, font
);
306 WMSetLabelText(panel
->nameLabel
, aicon
->wm_class
);
308 panel
->autoLaunchBtn
= WMCreateSwitchButton(panel
->win
);
309 WMResizeWidget(panel
->autoLaunchBtn
, PWIDTH
-30, 20);
310 WMMoveWidget(panel
->autoLaunchBtn
, 15, 80);
311 WMSetButtonText(panel
->autoLaunchBtn
,
312 _("Start when WindowMaker is started"));
313 WMSetButtonSelected(panel
->autoLaunchBtn
, aicon
->auto_launch
);
315 panel
->omnipresentBtn
= WMCreateSwitchButton(panel
->win
);
316 WMResizeWidget(panel
->omnipresentBtn
, PWIDTH
-30, 20);
317 WMMoveWidget(panel
->omnipresentBtn
, 15, 102);
318 WMSetButtonText(panel
->omnipresentBtn
,
319 _("Omnipresent application icon"));
320 WMSetButtonEnabled(panel
->omnipresentBtn
,
321 aicon
->dock
!=scr
->dock
&& aicon
!=scr
->clip_icon
);
322 WMSetButtonSelected(panel
->omnipresentBtn
, (aicon
->omnipresent
||
323 aicon
->dock
==scr
->dock
|| aicon
==scr
->clip_icon
));
325 panel
->commandFrame
= WMCreateFrame(panel
->win
);
326 WMResizeWidget(panel
->commandFrame
, 275, 50);
327 WMMoveWidget(panel
->commandFrame
, 10, 130);
328 WMSetFrameTitle(panel
->commandFrame
, _("Application path and arguments"));
330 panel
->commandField
= WMCreateTextField(panel
->commandFrame
);
331 WMResizeWidget(panel
->commandField
, 256, 20);
332 WMMoveWidget(panel
->commandField
, 10, 20);
333 WMSetTextFieldText(panel
->commandField
, aicon
->command
);
335 panel
->dndCommandFrame
= WMCreateFrame(panel
->win
);
336 WMResizeWidget(panel
->dndCommandFrame
, 275, 70);
337 WMMoveWidget(panel
->dndCommandFrame
, 10, 190);
338 WMSetFrameTitle(panel
->dndCommandFrame
,
339 _("Command for files dropped with DND"));
341 panel
->dndCommandField
= WMCreateTextField(panel
->dndCommandFrame
);
342 WMResizeWidget(panel
->dndCommandField
, 256, 20);
343 WMMoveWidget(panel
->dndCommandField
, 10, 20);
345 panel
->dndCommandLabel
= WMCreateLabel(panel
->dndCommandFrame
);
346 WMResizeWidget(panel
->dndCommandLabel
, 256, 18);
347 WMMoveWidget(panel
->dndCommandLabel
, 10, 45);
349 WMSetTextFieldText(panel
->dndCommandField
, aicon
->dnd_command
);
350 WMSetLabelText(panel
->dndCommandLabel
,
351 _("%d will be replaced with the file name"));
353 WMSetTextFieldEditable(panel
->dndCommandField
, False
);
354 WMSetLabelText(panel
->dndCommandLabel
,
355 _("DND support was not compiled in"));
358 panel
->iconFrame
= WMCreateFrame(panel
->win
);
359 WMResizeWidget(panel
->iconFrame
, 275, 50);
360 WMMoveWidget(panel
->iconFrame
, 10, 270);
361 WMSetFrameTitle(panel
->iconFrame
, _("Icon Image"));
363 panel
->iconField
= WMCreateTextField(panel
->iconFrame
);
364 WMResizeWidget(panel
->iconField
, 176, 20);
365 WMMoveWidget(panel
->iconField
, 10, 20);
366 WMSetTextFieldText(panel
->iconField
,
367 wDefaultGetIconFile(scr
, aicon
->wm_instance
,
368 aicon
->wm_class
, True
));
370 panel
->browseBtn
= WMCreateCommandButton(panel
->iconFrame
);
371 WMResizeWidget(panel
->browseBtn
, 70, 24);
372 WMMoveWidget(panel
->browseBtn
, 195, 18);
373 WMSetButtonText(panel
->browseBtn
, _("Browse..."));
374 WMSetButtonAction(panel
->browseBtn
, chooseIconCallback
, panel
);
377 panel
->okBtn
= WMCreateCommandButton(panel
->win
);
378 WMResizeWidget(panel
->okBtn
, 80, 26);
379 WMMoveWidget(panel
->okBtn
, 200, 333);
380 WMSetButtonText(panel
->okBtn
, _("OK"));
381 WMSetButtonAction(panel
->okBtn
, panelBtnCallback
, panel
);
383 panel
->cancelBtn
= WMCreateCommandButton(panel
->win
);
384 WMResizeWidget(panel
->cancelBtn
, 80, 26);
385 WMMoveWidget(panel
->cancelBtn
, 110, 333);
386 WMSetButtonText(panel
->cancelBtn
, _("Cancel"));
387 WMSetButtonAction(panel
->cancelBtn
, panelBtnCallback
, panel
);
389 WMRealizeWidget(panel
->win
);
390 WMMapSubwidgets(panel
->win
);
391 WMMapSubwidgets(panel
->commandFrame
);
392 WMMapSubwidgets(panel
->dndCommandFrame
);
393 WMMapSubwidgets(panel
->iconFrame
);
395 updateSettingsPanelIcon(panel
);
397 parent
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, PWIDTH
, PHEIGHT
,
399 XSelectInput(dpy
, parent
, KeyPressMask
|KeyReleaseMask
);
401 XReparentWindow(dpy
, WMWidgetXID(panel
->win
), parent
, 0, 0);
406 else if (y
+ PWIDTH
> scr
->scr_height
)
407 y
= scr
->scr_height
- PHEIGHT
- 30;
409 if (aicon
->dock
&& aicon
->dock
->type
== WM_DOCK
) {
410 if (aicon
->dock
->on_right_side
)
411 x
= scr
->scr_width
/2;
413 x
= scr
->scr_width
/2 - PWIDTH
;
415 x
= (scr
->scr_width
- PWIDTH
)/2;
417 panel
->wwin
= wManageInternalWindow(scr
, parent
, None
,
418 _("Docked Application Settings"),
419 x
, y
, PWIDTH
, PHEIGHT
);
421 panel
->wwin
->client_leader
= WMWidgetXID(panel
->win
);
423 panel
->parent
= parent
;
425 WMMapWidget(panel
->win
);
427 wWindowMap(panel
->wwin
);
432 DestroyDockAppSettingsPanel(AppSettingsPanel
*panel
)
434 if (!panel
->destroyed
) {
435 XUnmapWindow(dpy
, panel
->wwin
->client_win
);
436 XReparentWindow(dpy
, panel
->wwin
->client_win
,
437 panel
->wwin
->screen_ptr
->root_win
, 0, 0);
438 wUnmanageWindow(panel
->wwin
, False
, False
);
441 panel
->destroyed
= 1;
444 * kluge. If we destroy the panel before the icon chooser is closed,
445 * we will crash when it does close, trying to access something in the
446 * destroyed panel. Could use wretain()/wrelease() in the panel,
447 * but it is not working for some reason.
449 if (panel
->choosingIcon
)
452 WMDestroyWidget(panel
->win
);
454 XDestroyWindow(dpy
, panel
->parent
);
456 panel
->editedIcon
->panel
= NULL
;
458 panel
->editedIcon
->editing
= 0;