Change to the linux kernel coding style
[wmaker-crm.git] / src / dockedapp.c
Commit [+]AuthorDateLineData
9d2e6ef9 scottc1998-09-29 22:36:29 +00001/* dockedapp.c- docked application settings panel
70a363de dan1999-05-14 23:49:07 +00002 *
9af1c6c4 dan1998-10-21 14:43:47 +00003 * Window Maker window manager
70a363de dan1999-05-14 23:49:07 +00004 *
4153e2fd dan2003-01-16 23:30:45 +00005 * Copyright (c) 1998-2003 Alfredo K. Kojima
70a363de dan1999-05-14 23:49:07 +00006 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00007 * 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.
11 *
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.
16 *
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
70a363de dan1999-05-14 23:49:07 +000019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
9d2e6ef9 scottc1998-09-29 22:36:29 +000020 * USA.
21 */
22
9d2e6ef9 scottc1998-09-29 22:36:29 +000023#include "wconfig.h"
24
25#include <X11/Xlib.h>
26#include <X11/Xutil.h>
27#include <stdlib.h>
28#include <string.h>
29
30#include "WindowMaker.h"
31#include "wcore.h"
32#include "window.h"
33#include "icon.h"
34#include "appicon.h"
35#include "dock.h"
36#include "dialog.h"
37#include "funcs.h"
38#include "defaults.h"
39#include "framewin.h"
a10214a5 kojima2002-11-28 22:04:07 +000040#include "xinerama.h"
9d2e6ef9 scottc1998-09-29 22:36:29 +000041
9d2e6ef9 scottc1998-09-29 22:36:29 +000042/**** Global variables ****/
43extern WPreferences wPreferences;
44
9d2e6ef9 scottc1998-09-29 22:36:29 +000045typedef struct _AppSettingsPanel {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020046 WMWindow *win;
47 WAppIcon *editedIcon;
70a363de dan1999-05-14 23:49:07 +000048
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020049 WWindow *wwin;
9d2e6ef9 scottc1998-09-29 22:36:29 +000050
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020051 WMLabel *iconLabel;
52 WMLabel *nameLabel;
70a363de dan1999-05-14 23:49:07 +000053
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020054 WMFrame *commandFrame;
55 WMTextField *commandField;
9d2e6ef9 scottc1998-09-29 22:36:29 +000056
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020057 WMFrame *dndCommandFrame;
58 WMTextField *dndCommandField;
59 WMLabel *dndCommandLabel;
9d2e6ef9 scottc1998-09-29 22:36:29 +000060
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020061 WMFrame *pasteCommandFrame;
62 WMTextField *pasteCommandField;
63 WMLabel *pasteCommandLabel;
6830b057 dan2004-10-12 21:28:27 +000064
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020065 WMFrame *iconFrame;
66 WMTextField *iconField;
67 WMButton *browseBtn;
9d2e6ef9 scottc1998-09-29 22:36:29 +000068
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020069 WMButton *autoLaunchBtn;
70 WMButton *lockBtn;
c56756dc dan1999-03-14 22:35:50 +000071
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020072 WMButton *okBtn;
73 WMButton *cancelBtn;
9d2e6ef9 scottc1998-09-29 22:36:29 +000074
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020075 Window parent;
c56756dc dan1999-03-14 22:35:50 +000076
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020077 /* kluge */
78 unsigned int destroyed:1;
79 unsigned int choosingIcon:1;
9d2e6ef9 scottc1998-09-29 22:36:29 +000080} AppSettingsPanel;
81
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020082void DestroyDockAppSettingsPanel(AppSettingsPanel * panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +000083
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020084static void updateCommand(WAppIcon * icon, char *command)
9d2e6ef9 scottc1998-09-29 22:36:29 +000085{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020086 if (icon->command)
87 wfree(icon->command);
88 if (command && (command[0] == 0 || (command[0] == '-' && command[1] == 0))) {
89 wfree(command);
90 command = NULL;
91 }
92 icon->command = command;
93
94 if (!icon->wm_class && !icon->wm_instance && icon->command && strlen(icon->command) > 0) {
95 icon->forced_dock = 1;
96 }
9d2e6ef9 scottc1998-09-29 22:36:29 +000097}
98
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020099static void updatePasteCommand(WAppIcon * icon, char *command)
80fefd29 kojima2001-09-03 22:31:30 +0000100{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200101 if (icon->paste_command)
102 wfree(icon->paste_command);
103 if (command && (command[0] == 0 || (command[0] == '-' && command[1] == 0))) {
104 wfree(command);
105 command = NULL;
106 }
107 icon->paste_command = command;
80fefd29 kojima2001-09-03 22:31:30 +0000108}
109
879b00a5 kojima2004-10-13 05:09:08 +0000110#ifdef XDND
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200111static void updateDNDCommand(WAppIcon * icon, char *command)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000112{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200113 if (icon->dnd_command)
114 wfree(icon->dnd_command);
115 if (command && (command[0] == 0 || (command[0] == '-' && command[1] == 0))) {
116 wfree(command);
117 command = NULL;
118 }
119 icon->dnd_command = command;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000120}
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200121#endif /* XDND */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000122
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200123static void updateSettingsPanelIcon(AppSettingsPanel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000124{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200125 char *file;
126
127 file = WMGetTextFieldText(panel->iconField);
128 if (!file)
129 WMSetLabelImage(panel->iconLabel, NULL);
130 else {
131 char *path;
132
133 path = FindImage(wPreferences.icon_path, file);
134 if (!path) {
135 wwarning(_("could not find icon %s, used in a docked application"), file);
136 wfree(file);
137 WMSetLabelImage(panel->iconLabel, NULL);
138 return;
139 } else {
140 WMPixmap *pixmap;
141 RColor color;
142
143 color.red = 0xae;
144 color.green = 0xaa;
145 color.blue = 0xae;
146 color.alpha = 0;
147 pixmap = WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel->win), path, &color);
148 if (!pixmap) {
149 WMSetLabelImage(panel->iconLabel, NULL);
150 } else {
151 WMSetLabelImage(panel->iconLabel, pixmap);
152 WMReleasePixmap(pixmap);
153 }
154 }
155 wfree(file);
156 wfree(path);
157 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000158}
159
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200160static void chooseIconCallback(WMWidget * self, void *clientData)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000161{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200162 char *file;
163 AppSettingsPanel *panel = (AppSettingsPanel *) clientData;
164 int result;
165
166 panel->choosingIcon = 1;
167
168 WMSetButtonEnabled(panel->browseBtn, False);
169
170 result = wIconChooserDialog(panel->wwin->screen_ptr, &file,
171 panel->editedIcon->wm_instance, panel->editedIcon->wm_class);
172
173 panel->choosingIcon = 0;
174 if (!panel->destroyed) {
175 if (result) {
176 WMSetTextFieldText(panel->iconField, file);
177 wfree(file);
178 updateSettingsPanelIcon(panel);
179 }
180
181 WMSetButtonEnabled(panel->browseBtn, True);
182 } else {
183 /* kluge for the case, the user asked to close the panel before
184 * the icon chooser */
185 DestroyDockAppSettingsPanel(panel);
186 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000187}
188
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200189static void panelBtnCallback(WMWidget * self, void *data)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000190{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200191 WMButton *btn = self;
192 AppSettingsPanel *panel = (AppSettingsPanel *) data;
193 char *text;
194 int done;
195
196 done = 1;
197 if (panel->okBtn == btn) {
198 text = WMGetTextFieldText(panel->iconField);
199 if (text[0] == 0) {
200 wfree(text);
201 text = NULL;
202 }
203 if (!wIconChangeImageFile(panel->editedIcon->icon, text)) {
204 char *buf;
205 int len = strlen(text) + 64;
206
207 buf = wmalloc(len);
208 snprintf(buf, len, _("Could not open specified icon file: %s"), text);
209 if (wMessageDialog(panel->wwin->screen_ptr, _("Error"), buf,
210 _("OK"), _("Ignore"), NULL) == WAPRDefault) {
211 if (text)
212 wfree(text);
213 wfree(buf);
214 return;
215 }
216 wfree(buf);
217 } else {
218 WAppIcon *aicon = panel->editedIcon;
219
220 if (aicon == aicon->icon->core->screen_ptr->clip_icon)
221 wClipIconPaint(aicon);
222 else
223 wAppIconPaint(aicon);
224
225 wDefaultChangeIcon(panel->wwin->screen_ptr, aicon->wm_instance, aicon->wm_class, text);
226 }
227 if (text)
228 wfree(text);
229
230 /* cannot free text from this, because it will be not be duplicated
231 * in updateCommand */
232 text = WMGetTextFieldText(panel->commandField);
233 if (text[0] == 0) {
234 wfree(text);
235 text = NULL;
236 }
237 updateCommand(panel->editedIcon, text);
879b00a5 kojima2004-10-13 05:09:08 +0000238#ifdef XDND
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200239 /* cannot free text from this, because it will be not be duplicated
240 * in updateDNDCommand */
241 text = WMGetTextFieldText(panel->dndCommandField);
242 updateDNDCommand(panel->editedIcon, text);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000243#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200244 text = WMGetTextFieldText(panel->pasteCommandField);
245 updatePasteCommand(panel->editedIcon, text);
9007a657 dan1998-11-23 11:32:19 +0000246
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200247 panel->editedIcon->auto_launch = WMGetButtonSelected(panel->autoLaunchBtn);
eb87c409 kojima1999-10-20 03:25:06 +0000248
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200249 panel->editedIcon->lock = WMGetButtonSelected(panel->lockBtn);
250 }
9007a657 dan1998-11-23 11:32:19 +0000251
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200252 if (done)
253 DestroyDockAppSettingsPanel(panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000254}
255
9d2e6ef9 scottc1998-09-29 22:36:29 +0000256#define PWIDTH 295
80fefd29 kojima2001-09-03 22:31:30 +0000257#define PHEIGHT 430
9d2e6ef9 scottc1998-09-29 22:36:29 +0000258
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200259void ShowDockAppSettingsPanel(WAppIcon * aicon)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000260{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200261 AppSettingsPanel *panel;
262 WScreen *scr = aicon->icon->core->screen_ptr;
263 Window parent;
264 WMFont *font;
265 int x, y;
266 WMBox *vbox;
267
268 panel = wmalloc(sizeof(AppSettingsPanel));
269 memset(panel, 0, sizeof(AppSettingsPanel));
270
271 panel->editedIcon = aicon;
272
273 aicon->panel = panel;
274 aicon->editing = 1;
275
276 panel->win = WMCreateWindow(scr->wmscreen, "applicationSettings");
277 WMResizeWidget(panel->win, PWIDTH, PHEIGHT);
278
279 panel->iconLabel = WMCreateLabel(panel->win);
280 WMResizeWidget(panel->iconLabel, 64, 64);
281 WMMoveWidget(panel->iconLabel, 10, 10);
282 WMSetLabelImagePosition(panel->iconLabel, WIPImageOnly);
283
284 panel->nameLabel = WMCreateLabel(panel->win);
285 WMResizeWidget(panel->nameLabel, 190, 18);
286 WMMoveWidget(panel->nameLabel, 80, 35);
287 WMSetLabelTextAlignment(panel->nameLabel, WALeft);
288 font = WMBoldSystemFontOfSize(scr->wmscreen, 14);
289 WMSetLabelFont(panel->nameLabel, font);
290 WMReleaseFont(font);
291 if (aicon->wm_class && strcmp(aicon->wm_class, "DockApp") == 0)
292 WMSetLabelText(panel->nameLabel, aicon->wm_instance);
293 else
294 WMSetLabelText(panel->nameLabel, aicon->wm_class);
295
296 vbox = WMCreateBox(panel->win);
297 WMResizeWidget(vbox, PWIDTH - 20, PHEIGHT - 84 - 10);
298 WMMoveWidget(vbox, 10, 84);
299
300 panel->autoLaunchBtn = WMCreateSwitchButton(vbox);
301 WMAddBoxSubview(vbox, WMWidgetView(panel->autoLaunchBtn), False, True, 20, 20, 2);
302 WMSetButtonText(panel->autoLaunchBtn, _("Start when Window Maker is started"));
303 WMSetButtonSelected(panel->autoLaunchBtn, aicon->auto_launch);
304
305 panel->lockBtn = WMCreateSwitchButton(vbox);
306 WMAddBoxSubview(vbox, WMWidgetView(panel->lockBtn), False, True, 20, 20, 5);
307 WMSetButtonText(panel->lockBtn, _("Lock (prevent accidental removal)"));
308 WMSetButtonSelected(panel->lockBtn, aicon->lock);
309
310 panel->commandFrame = WMCreateFrame(vbox);
311 WMSetFrameTitle(panel->commandFrame, _("Application path and arguments"));
312 WMAddBoxSubview(vbox, WMWidgetView(panel->commandFrame), False, True, 50, 50, 5);
313
314 panel->commandField = WMCreateTextField(panel->commandFrame);
315 WMResizeWidget(panel->commandField, 256, 20);
316 WMMoveWidget(panel->commandField, 10, 20);
317 WMSetTextFieldText(panel->commandField, aicon->command);
318
319 WMMapSubwidgets(panel->commandFrame);
320
321 panel->pasteCommandFrame = WMCreateFrame(vbox);
322 WMSetFrameTitle(panel->pasteCommandFrame, _("Command for middle-click launch"));
323 WMAddBoxSubview(vbox, WMWidgetView(panel->pasteCommandFrame), False, True, 70, 70, 5);
324
325 panel->pasteCommandField = WMCreateTextField(panel->pasteCommandFrame);
326 WMResizeWidget(panel->pasteCommandField, 256, 20);
327 WMMoveWidget(panel->pasteCommandField, 10, 20);
328
329 panel->pasteCommandLabel = WMCreateLabel(panel->pasteCommandFrame);
330 WMResizeWidget(panel->pasteCommandLabel, 256, 18);
331 WMMoveWidget(panel->pasteCommandLabel, 10, 45);
332
333 WMSetTextFieldText(panel->pasteCommandField, aicon->paste_command);
334 WMSetLabelText(panel->pasteCommandLabel, _("%s will be replaced with current selection"));
335 WMMapSubwidgets(panel->pasteCommandFrame);
336
337 panel->dndCommandFrame = WMCreateFrame(vbox);
338 WMSetFrameTitle(panel->dndCommandFrame, _("Command for files dropped with DND"));
339 WMAddBoxSubview(vbox, WMWidgetView(panel->dndCommandFrame), False, True, 70, 70, 5);
340
341 panel->dndCommandField = WMCreateTextField(panel->dndCommandFrame);
342 WMResizeWidget(panel->dndCommandField, 256, 20);
343 WMMoveWidget(panel->dndCommandField, 10, 20);
344
345 panel->dndCommandLabel = WMCreateLabel(panel->dndCommandFrame);
346 WMResizeWidget(panel->dndCommandLabel, 256, 18);
347 WMMoveWidget(panel->dndCommandLabel, 10, 45);
879b00a5 kojima2004-10-13 05:09:08 +0000348#ifdef XDND
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200349 WMSetTextFieldText(panel->dndCommandField, aicon->dnd_command);
350 WMSetLabelText(panel->dndCommandLabel, _("%d will be replaced with the file name"));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000351#else
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200352 WMSetTextFieldEditable(panel->dndCommandField, False);
353 WMSetLabelText(panel->dndCommandLabel, _("DND support was not compiled in"));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000354#endif
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200355 WMMapSubwidgets(panel->dndCommandFrame);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000356
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200357 panel->iconFrame = WMCreateFrame(vbox);
358 WMSetFrameTitle(panel->iconFrame, _("Icon Image"));
359 WMAddBoxSubview(vbox, WMWidgetView(panel->iconFrame), False, True, 50, 50, 10);
70a363de dan1999-05-14 23:49:07 +0000360
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200361 panel->iconField = WMCreateTextField(panel->iconFrame);
362 WMResizeWidget(panel->iconField, 176, 20);
363 WMMoveWidget(panel->iconField, 10, 20);
364 WMSetTextFieldText(panel->iconField, wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class, True));
70a363de dan1999-05-14 23:49:07 +0000365
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200366 panel->browseBtn = WMCreateCommandButton(panel->iconFrame);
367 WMResizeWidget(panel->browseBtn, 70, 24);
368 WMMoveWidget(panel->browseBtn, 195, 18);
369 WMSetButtonText(panel->browseBtn, _("Browse..."));
370 WMSetButtonAction(panel->browseBtn, chooseIconCallback, panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000371
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200372 {
373 WMBox *hbox;
70a363de dan1999-05-14 23:49:07 +0000374
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200375 hbox = WMCreateBox(vbox);
376 WMSetBoxHorizontal(hbox, True);
377 WMAddBoxSubview(vbox, WMWidgetView(hbox), False, True, 24, 24, 0);
6830b057 dan2004-10-12 21:28:27 +0000378
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200379 panel->okBtn = WMCreateCommandButton(hbox);
380 WMSetButtonText(panel->okBtn, _("OK"));
381 WMSetButtonAction(panel->okBtn, panelBtnCallback, panel);
382 WMAddBoxSubviewAtEnd(hbox, WMWidgetView(panel->okBtn), False, True, 80, 80, 0);
6830b057 dan2004-10-12 21:28:27 +0000383
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200384 panel->cancelBtn = WMCreateCommandButton(hbox);
385 WMSetButtonText(panel->cancelBtn, _("Cancel"));
386 WMSetButtonAction(panel->cancelBtn, panelBtnCallback, panel);
387 WMAddBoxSubviewAtEnd(hbox, WMWidgetView(panel->cancelBtn), False, True, 80, 80, 5);
6830b057 dan2004-10-12 21:28:27 +0000388
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200389 WMMapSubwidgets(hbox);
390 }
6830b057 dan2004-10-12 21:28:27 +0000391
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200392 WMRealizeWidget(panel->win);
393 WMMapSubwidgets(panel->win);
394 WMMapSubwidgets(vbox);
395 WMMapSubwidgets(panel->iconFrame);
6830b057 dan2004-10-12 21:28:27 +0000396
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200397 updateSettingsPanelIcon(panel);
6830b057 dan2004-10-12 21:28:27 +0000398
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200399 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, PWIDTH, PHEIGHT, 0, 0, 0);
400 XSelectInput(dpy, parent, KeyPressMask | KeyReleaseMask);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000401
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200402 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000403
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200404 /*
405 * make things relative to head
406 */
407 {
408 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000409
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200410 y = aicon->y_pos;
411 if (y < 0)
412 y = 0;
413 else if (y + PHEIGHT > rect.pos.y + rect.size.height)
414 y = rect.pos.y + rect.size.height - PHEIGHT - 30;
70a363de dan1999-05-14 23:49:07 +0000415
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200416 if (aicon->dock && aicon->dock->type == WM_DOCK) {
417 if (aicon->dock->on_right_side)
418 x = rect.pos.x + rect.size.width / 2;
419 else
420 x = rect.pos.x + rect.size.width / 2 - PWIDTH - 2;
421 } else {
422 x = rect.pos.x + (rect.size.width - PWIDTH) / 2;
423 }
424 }
6830b057 dan2004-10-12 21:28:27 +0000425
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200426 panel->wwin = wManageInternalWindow(scr, parent, None,
427 _("Docked Application Settings"), x, y, PWIDTH, PHEIGHT);
6830b057 dan2004-10-12 21:28:27 +0000428
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200429 panel->wwin->client_leader = WMWidgetXID(panel->win);
a10214a5 kojima2002-11-28 22:04:07 +0000430
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200431 panel->parent = parent;
70a363de dan1999-05-14 23:49:07 +0000432
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200433 WMMapWidget(panel->win);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000434
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200435 wWindowMap(panel->wwin);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000436}
437
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200438void DestroyDockAppSettingsPanel(AppSettingsPanel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000439{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200440 if (!panel->destroyed) {
441 XUnmapWindow(dpy, panel->wwin->client_win);
442 XReparentWindow(dpy, panel->wwin->client_win, panel->wwin->screen_ptr->root_win, 0, 0);
443 wUnmanageWindow(panel->wwin, False, False);
444 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000445
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200446 panel->destroyed = 1;
70a363de dan1999-05-14 23:49:07 +0000447
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200448 /*
449 * kluge. If we destroy the panel before the icon chooser is closed,
450 * we will crash when it does close, trying to access something in the
451 * destroyed panel. Could use wretain()/wrelease() in the panel,
452 * but it is not working for some reason.
453 */
454 if (panel->choosingIcon)
455 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000456
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200457 WMDestroyWidget(panel->win);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000458
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200459 XDestroyWindow(dpy, panel->parent);
c56756dc dan1999-03-14 22:35:50 +0000460
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200461 panel->editedIcon->panel = NULL;
c56756dc dan1999-03-14 22:35:50 +0000462
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200463 panel->editedIcon->editing = 0;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000464
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200465 wfree(panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000466}