1 /* dock.c- built-in Dock module for WindowMaker
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <X11/Xutil.h>
37 #define PATH_MAX DEFAULT_PATH_MAX
40 #include "WindowMaker.h"
48 #include "dockedapp.h"
51 #include "properties.h"
55 #include "workspace.h"
57 #include "superfluous.h"
59 #include "placement.h"
63 /**** Local variables ****/
66 #define CLIP_FORWARD 2
68 #define MOD_MASK wPreferences.modifier_mask
69 #define ICON_SIZE wPreferences.icon_size
71 /***** Local variables ****/
73 static WMPropList
*dCommand
= NULL
;
74 static WMPropList
*dPasteCommand
= NULL
;
75 #ifdef XDND /* XXX was OFFIX */
76 static WMPropList
*dDropCommand
= NULL
;
78 static WMPropList
*dAutoLaunch
, *dLock
;
79 static WMPropList
*dName
, *dForced
, *dBuggyApplication
, *dYes
, *dNo
;
80 static WMPropList
*dHost
, *dDock
, *dClip
;
81 static WMPropList
*dAutoAttractIcons
;
83 static WMPropList
*dPosition
, *dApplications
, *dLowered
, *dCollapsed
;
85 static WMPropList
*dAutoCollapse
, *dAutoRaiseLower
, *dOmnipresent
;
87 static WMPropList
*dDrawers
= NULL
;
89 static void dockIconPaint(WAppIcon
*btn
);
91 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
93 static pid_t
execCommand(WAppIcon
*btn
, const char *command
, WSavedState
*state
);
95 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
97 static int getClipButton(int px
, int py
);
99 static void toggleLowered(WDock
*dock
);
101 static void toggleCollapsed(WDock
*dock
);
103 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
105 static void clipLeave(WDock
*dock
);
107 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
109 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
110 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
111 static void clipAutoCollapse(void *cdata
);
112 static void clipAutoExpand(void *cdata
);
113 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
);
115 static void clipAutoLower(void *cdata
);
116 static void clipAutoRaise(void *cdata
);
117 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
, const char *name
);
119 static void drawerIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
120 static void removeDrawerCallback(WMenu
*menu
, WMenuEntry
*entry
);
121 static void drawerAppendToChain(WScreen
*scr
, WDock
*drawer
);
122 static char *findUniqueName(WScreen
*scr
, const char *instance_basename
);
123 static void addADrawerCallback(WMenu
*menu
, WMenuEntry
*entry
);
124 static void swapDrawers(WScreen
*scr
, int on_right_side
, int new_x
);
125 static WDock
* getDrawer(WScreen
*scr
, int y_index
);
126 static int indexOfHole(WDock
*drawer
, WAppIcon
*moving_aicon
, int redocking
);
127 static void drawerConsolidateIcons(WDock
*drawer
);
129 static int onScreen(WScreen
*scr
, int x
, int y
);
131 static void make_keys(void)
133 if (dCommand
!= NULL
)
136 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
137 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
139 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
141 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
142 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
143 dName
= WMRetainPropList(WMCreatePLString("Name"));
144 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
145 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
146 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
147 dNo
= WMRetainPropList(WMCreatePLString("No"));
148 dHost
= WMRetainPropList(WMCreatePLString("Host"));
150 dPosition
= WMCreatePLString("Position");
151 dApplications
= WMCreatePLString("Applications");
152 dLowered
= WMCreatePLString("Lowered");
153 dCollapsed
= WMCreatePLString("Collapsed");
154 dAutoCollapse
= WMCreatePLString("AutoCollapse");
155 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
156 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
158 dOmnipresent
= WMCreatePLString("Omnipresent");
160 dDock
= WMCreatePLString("Dock");
161 dClip
= WMCreatePLString("Clip");
162 dDrawers
= WMCreatePLString("Drawers");
165 static void renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
167 WDock
*dock
= entry
->clientdata
;
172 assert(entry
->clientdata
!= NULL
);
174 wspace
= w_global
.workspace
.current
;
176 name
= wstrdup(w_global
.workspace
.array
[wspace
]->name
);
178 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+ 1);
179 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
, &name
))
180 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
185 static void toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
187 assert(entry
->clientdata
!= NULL
);
189 toggleLowered(entry
->clientdata
);
191 entry
->flags
.indicator_on
= !(((WDock
*) entry
->clientdata
)->lowered
);
196 static int matchWindow(const void *item
, const void *cdata
)
198 return (((WFakeGroupLeader
*) item
)->leader
== (Window
) cdata
);
201 static void killCallback(WMenu
*menu
, WMenuEntry
*entry
)
203 WScreen
*scr
= menu
->menu
->screen_ptr
;
205 WFakeGroupLeader
*fPtr
;
206 char *buffer
, *shortname
, **argv
;
209 if (!WCHECK_STATE(WSTATE_NORMAL
))
212 assert(entry
->clientdata
!= NULL
);
214 icon
= (WAppIcon
*) entry
->clientdata
;
218 WCHANGE_STATE(WSTATE_MODAL
);
220 /* strip away dir names */
221 shortname
= basename(icon
->command
);
222 /* separate out command options */
223 wtokensplit(shortname
, &argv
, &argc
);
225 buffer
= wstrconcat(argv
[0],
226 _(" will be forcibly closed.\n"
227 "Any unsaved changes will be lost.\n" "Please confirm."));
229 if (icon
->icon
&& icon
->icon
->owner
) {
230 fPtr
= icon
->icon
->owner
->fake_group
;
232 /* is this really necessary? can we kill a non-running dock icon? */
233 Window win
= icon
->main_window
;
236 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)win
);
237 if (index
!= WANotFound
)
238 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
243 if (wPreferences
.dont_confirm_kill
244 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
245 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
247 WWindow
*wwin
, *twin
;
249 wwin
= scr
->focused_window
;
252 if (wwin
->fake_group
== fPtr
)
257 } else if (icon
->icon
&& icon
->icon
->owner
) {
258 wClientKill(icon
->icon
->owner
);
263 wtokenfree(argv
, argc
);
267 WCHANGE_STATE(WSTATE_NORMAL
);
270 /* TODO: replace this function with a member of the dock struct */
271 static int numberOfSelectedIcons(WDock
*dock
)
277 for (i
= 1; i
< dock
->max_icons
; i
++) {
278 aicon
= dock
->icon_array
[i
];
279 if (aicon
&& aicon
->icon
->selected
)
286 static WMArray
*getSelected(WDock
*dock
)
288 WMArray
*ret
= WMCreateArray(8);
292 for (i
= 1; i
< dock
->max_icons
; i
++) {
293 btn
= dock
->icon_array
[i
];
294 if (btn
&& btn
->icon
->selected
)
295 WMAddToArray(ret
, btn
);
301 static void paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
303 Window win
= clipIcon
->icon
->core
->window
;
304 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
306 int pt
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
307 int tp
= ICON_SIZE
- pt
;
308 int as
= pt
- 15; /* 15 = 5+5+5 */
309 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
312 color
= scr
->clip_title_color
[CLIP_NORMAL
];
314 XSetForeground(dpy
, gc
, WMColorPixel(color
));
319 p
[1].x
= ICON_SIZE
- 2;
321 p
[2].x
= ICON_SIZE
- 2;
323 } else if (lpushed
) {
327 p
[1].y
= ICON_SIZE
- 2;
329 p
[2].y
= ICON_SIZE
- 2;
331 if (lpushed
|| rpushed
) {
332 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
333 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
334 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
337 /* top right arrow */
338 p
[0].x
= p
[3].x
= ICON_SIZE
- 5 - as
;
340 p
[1].x
= ICON_SIZE
- 6;
342 p
[2].x
= ICON_SIZE
- 6;
345 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
346 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
348 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
349 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
352 /* bottom left arrow */
354 p
[0].y
= p
[3].y
= ICON_SIZE
- 5 - as
;
356 p
[1].y
= ICON_SIZE
- 6;
358 p
[2].y
= ICON_SIZE
- 6;
360 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
361 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
363 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
364 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
368 RImage
*wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
370 RImage
*tile
= RCloneImage(normalTile
);
377 pt
= CLIP_BUTTON_SIZE
* wPreferences
.icon_size
/ 64;
378 tp
= wPreferences
.icon_size
- 1 - pt
;
382 black
.red
= black
.green
= black
.blue
= 0;
385 dark
.red
= dark
.green
= dark
.blue
= 60;
388 light
.red
= light
.green
= light
.blue
= 80;
391 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
- 2, pt
- 1, &dark
);
392 RDrawLine(tile
, tp
- 1, 0, wPreferences
.icon_size
- 1, pt
+ 1, &black
);
393 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
- 3, pt
, &light
);
396 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, 4, &dark
);
397 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 5, 6 + as
, &dark
);
398 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
, &light
);
401 ROperateLine(tile
, RAddOperation
, 2, tp
+ 2, pt
- 2, wPreferences
.icon_size
- 3, &dark
);
402 RDrawLine(tile
, 0, tp
- 1, pt
+ 1, wPreferences
.icon_size
- 1, &black
);
403 ROperateLine(tile
, RSubtractOperation
, 0, tp
- 2, pt
+ 1, wPreferences
.icon_size
- 2, &light
);
406 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, &dark
);
407 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
, 6 + as
, ICON_SIZE
- 5, &dark
);
408 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5, &light
);
413 static void omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
415 WAppIcon
*clickedIcon
= entry
->clientdata
;
418 WMArray
*selectedIcons
;
419 WMArrayIterator iter
;
422 assert(entry
->clientdata
!= NULL
);
424 dock
= clickedIcon
->dock
;
426 selectedIcons
= getSelected(dock
);
428 if (!WMGetArrayItemCount(selectedIcons
))
429 WMAddToArray(selectedIcons
, clickedIcon
);
432 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
433 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
435 else if (aicon
->icon
->selected
)
436 wIconSelect(aicon
->icon
);
438 WMFreeArray(selectedIcons
);
441 wMessageDialog(dock
->screen_ptr
, _("Warning"),
442 _("Some icons cannot be made omnipresent. "
443 "Please make sure that no other icon is "
444 "docked in the same positions on the other "
445 "workspaces and the Clip is not full in "
446 "some workspace."), _("OK"), NULL
, NULL
);
447 } else if (failed
== 1) {
448 wMessageDialog(dock
->screen_ptr
, _("Warning"),
449 _("Icon cannot be made omnipresent. "
450 "Please make sure that no other icon is "
451 "docked in the same position on the other "
452 "workspaces and the Clip is not full in "
453 "some workspace."), _("OK"), NULL
, NULL
);
457 static void removeIcons(WMArray
*icons
, WDock
*dock
)
463 WM_ITERATE_ARRAY(icons
, aicon
, it
) {
464 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
465 wDockDetach(dock
, aicon
);
467 /* XXX: can: aicon->icon == NULL ? */
468 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
469 wGetHeadForWindow(aicon
->icon
->owner
));
470 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
471 if (!dock
->mapped
|| dock
->collapsed
)
472 XMapWindow(dpy
, aicon
->icon
->core
->window
);
477 if (wPreferences
.auto_arrange_icons
)
478 wArrangeIcons(dock
->screen_ptr
, True
);
481 static void removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
483 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
485 WMArray
*selectedIcons
;
487 assert(clickedIcon
!= NULL
);
489 dock
= clickedIcon
->dock
;
491 selectedIcons
= getSelected(dock
);
493 if (WMGetArrayItemCount(selectedIcons
)) {
494 if (wMessageDialog(dock
->screen_ptr
,
495 dock
->type
== WM_CLIP
? _("Workspace Clip") : _("Drawer"),
496 _("All selected icons will be removed!"),
497 _("OK"), _("Cancel"), NULL
) != WAPRDefault
) {
498 WMFreeArray(selectedIcons
);
502 if (clickedIcon
->xindex
== 0 && clickedIcon
->yindex
== 0) {
503 WMFreeArray(selectedIcons
);
506 WMAddToArray(selectedIcons
, clickedIcon
);
509 removeIcons(selectedIcons
, dock
);
511 if (dock
->type
== WM_DRAWER
) {
512 drawerConsolidateIcons(dock
);
516 static void keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
518 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
521 WMArray
*selectedIcons
;
524 assert(clickedIcon
!= NULL
);
525 dock
= clickedIcon
->dock
;
527 selectedIcons
= getSelected(dock
);
529 if (!WMGetArrayItemCount(selectedIcons
)
530 && clickedIcon
!= w_global
.clip
.icon
) {
531 char *command
= NULL
;
533 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
534 clickedIcon
->editing
= 1;
535 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
536 _("Type the command used to launch the application"), &command
)) {
537 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
541 clickedIcon
->command
= command
;
542 clickedIcon
->editing
= 0;
544 clickedIcon
->editing
= 0;
547 WMFreeArray(selectedIcons
);
552 WMAddToArray(selectedIcons
, clickedIcon
);
555 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
556 if (aicon
->icon
->selected
)
557 wIconSelect(aicon
->icon
);
559 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
560 aicon
->attracted
= 0;
561 if (aicon
->icon
->shadowed
) {
562 aicon
->icon
->shadowed
= 0;
565 * Update icon pixmap, RImage doesn't change,
566 * so call wIconUpdate is not needed
568 update_icon_pixmap(aicon
->icon
);
571 wAppIconPaint(aicon
);
574 save_appicon(aicon
, True
);
576 WMFreeArray(selectedIcons
);
579 static void toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
581 WDock
*dock
= (WDock
*) entry
->clientdata
;
582 WScreen
*scr
= dock
->screen_ptr
;
584 assert(entry
->clientdata
!= NULL
);
586 dock
->attract_icons
= !dock
->attract_icons
;
588 entry
->flags
.indicator_on
= dock
->attract_icons
;
592 if (dock
->attract_icons
) {
593 if (dock
->type
== WM_DRAWER
) {
594 /* The newly auto-attracting dock is a drawer: disable any clip and
595 * previously attracting drawer */
597 if (!wPreferences
.flags
.noclip
) {
599 for (i
= 0; i
< w_global
.workspace
.count
; i
++)
600 w_global
.workspace
.array
[i
]->clip
->attract_icons
= False
;
601 /* dock menu will be updated later, when opened */
604 if (scr
->attracting_drawer
!= NULL
)
605 scr
->attracting_drawer
->attract_icons
= False
;
606 scr
->attracting_drawer
= dock
;
608 /* The newly auto-attracting dock is a clip: disable
609 * previously attracting drawer, if applicable */
610 if (scr
->attracting_drawer
!= NULL
) {
611 scr
->attracting_drawer
->attract_icons
= False
;
612 /* again, its menu will be updated, later. */
613 scr
->attracting_drawer
= NULL
;
619 static void selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
621 WAppIcon
*icon
= (WAppIcon
*) entry
->clientdata
;
623 assert(icon
!= NULL
);
625 wIconSelect(icon
->icon
);
630 static void colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
632 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
633 WDock
*clip
; /* clip... is a WM_CLIP or a WM_DRAWER */
635 int x
, y
, x_pos
, y_pos
;
636 Bool update_icon
= False
;
638 assert(entry
->clientdata
!= NULL
);
639 clip
= clickedIcon
->dock
;
641 aicon
= w_global
.app_icon_list
;
644 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
645 x_pos
= clip
->x_pos
+ x
* ICON_SIZE
;
646 y_pos
= clip
->y_pos
+ y
* ICON_SIZE
;
647 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
)
648 move_window(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
650 aicon
->attracted
= 1;
651 if (!aicon
->icon
->shadowed
) {
652 aicon
->icon
->shadowed
= 1;
655 wDockAttachIcon(clip
, aicon
, x
, y
, update_icon
);
656 if (clip
->collapsed
|| !clip
->mapped
)
657 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
663 static void selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
665 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
667 WMArray
*selectedIcons
;
668 WMArrayIterator iter
;
672 assert(clickedIcon
!= NULL
);
673 dock
= clickedIcon
->dock
;
675 selectedIcons
= getSelected(dock
);
677 if (!WMGetArrayItemCount(selectedIcons
)) {
678 for (i
= 1; i
< dock
->max_icons
; i
++) {
679 btn
= dock
->icon_array
[i
];
680 if (btn
&& !btn
->icon
->selected
)
681 wIconSelect(btn
->icon
);
684 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
685 wIconSelect(btn
->icon
);
688 WMFreeArray(selectedIcons
);
693 static void toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
695 assert(entry
->clientdata
!= NULL
);
697 toggleCollapsed(entry
->clientdata
);
699 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->collapsed
;
704 static void toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
707 assert(entry
->clientdata
!= NULL
);
709 dock
= (WDock
*) entry
->clientdata
;
711 dock
->auto_collapse
= !dock
->auto_collapse
;
713 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_collapse
;
718 static void toggleAutoRaiseLower(WDock
*dock
)
722 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
723 if (dock
->type
== WM_DOCK
)
725 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
726 toggleAutoRaiseLower(dc
->adrawer
);
731 static void toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
734 assert(entry
->clientdata
!= NULL
);
736 dock
= (WDock
*) entry
->clientdata
;
738 toggleAutoRaiseLower(dock
);
740 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_raise_lower
;
745 static void launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
747 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
749 launchDockedApplication(btn
, False
);
752 static void settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
754 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
758 ShowDockAppSettingsPanel(btn
);
761 static void hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
764 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
766 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
768 if (wapp
->flags
.hidden
) {
769 wWorkspaceChange(btn
->icon
->core
->screen_ptr
, wapp
->last_workspace
);
770 wUnhideApplication(wapp
, False
, False
);
772 wHideApplication(wapp
);
776 static void unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
779 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
781 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
783 wUnhideApplication(wapp
, False
, True
);
786 /* Name is only used when type == WM_DRAWER and when restoring a specific
787 * drawer, with a specific name. When creating a drawer, leave name to NULL
788 * and mainIconCreate will find the first unused unique name */
789 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
, const char *name
)
796 if (w_global
.clip
.icon
)
797 return w_global
.clip
.icon
;
799 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
800 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
804 default: /* to avoid a warning about btn and x_pos, basically */
805 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
806 if (wPreferences
.flags
.clip_merged_in_dock
)
807 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
808 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
812 name
= findUniqueName(scr
, "Drawer");
813 btn
= wAppIconCreateForDock(scr
, NULL
, name
, "WMDrawer", TILE_DRAWER
);
814 btn
->icon
->core
->descriptor
.handle_expose
= drawerIconExpose
;
821 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
822 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
823 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
824 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
825 btn
->icon
->core
->descriptor
.parent
= btn
;
826 XMapWindow(dpy
, btn
->icon
->core
->window
);
830 if (type
== WM_CLIP
||
831 (type
== WM_DOCK
&& wPreferences
.flags
.clip_merged_in_dock
))
832 w_global
.clip
.icon
= btn
;
837 static void switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
839 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
841 WMArray
*selectedIcons
;
844 if (entry
->order
== w_global
.workspace
.current
)
847 dest
= w_global
.workspace
.array
[entry
->order
]->clip
;
849 selectedIcons
= getSelected(src
);
851 if (WMGetArrayItemCount(selectedIcons
)) {
852 WMArrayIterator iter
;
854 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
855 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
856 wDockMoveIconBetweenDocks(src
, dest
, btn
, x
, y
);
857 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
860 } else if (icon
!= w_global
.clip
.icon
) {
861 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
862 wDockMoveIconBetweenDocks(src
, dest
, icon
, x
, y
);
863 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
866 WMFreeArray(selectedIcons
);
869 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
)
871 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
873 if (!btn
->launching
&&
874 ((!withSelection
&& btn
->command
!= NULL
) || (withSelection
&& btn
->paste_command
!= NULL
))) {
875 if (!btn
->forced_dock
) {
876 btn
->relaunching
= btn
->running
;
879 if (btn
->wm_instance
|| btn
->wm_class
) {
880 WWindowAttributes attr
;
881 memset(&attr
, 0, sizeof(WWindowAttributes
));
882 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
884 if (!attr
.no_appicon
&& !btn
->buggy_app
)
889 btn
->drop_launch
= 0;
890 btn
->paste_launch
= withSelection
;
891 scr
->last_dock
= btn
->dock
;
892 btn
->pid
= execCommand(btn
, (withSelection
? btn
->paste_command
: btn
->command
), NULL
);
894 if (btn
->buggy_app
) {
895 /* give feedback that the app was launched */
899 WMAddTimerHandler(200, (WMCallback
*) dockIconPaint
, btn
);
904 wwarning(_("could not launch application %s"), btn
->command
);
906 if (!btn
->relaunching
)
912 static void updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
914 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
920 for (i
= 0; i
< w_global
.workspace
.count
; i
++) {
921 if (i
< menu
->entry_no
) {
922 if (strcmp(menu
->entries
[i
]->text
, w_global
.workspace
.array
[i
]->name
) != 0) {
923 wfree(menu
->entries
[i
]->text
);
924 strcpy(title
, w_global
.workspace
.array
[i
]->name
);
925 menu
->entries
[i
]->text
= wstrdup(title
);
926 menu
->flags
.realized
= 0;
928 menu
->entries
[i
]->clientdata
= (void *)icon
;
930 strcpy(title
, w_global
.workspace
.array
[i
]->name
);
932 wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)icon
);
934 menu
->flags
.realized
= 0;
937 if (i
== w_global
.workspace
.current
)
938 wMenuSetEnabled(menu
, i
, False
);
940 wMenuSetEnabled(menu
, i
, True
);
943 if (!menu
->flags
.realized
)
947 static WMenu
*makeWorkspaceMenu(WScreen
*scr
)
951 menu
= wMenuCreate(scr
, NULL
, False
);
953 wwarning(_("could not create workspace submenu for Clip menu"));
955 wMenuAddCallback(menu
, "", switchWSCommand
, (void *)w_global
.clip
.icon
);
957 menu
->flags
.realized
= 0;
963 static void updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
972 entry
= menu
->entries
[index
];
973 entry
->flags
.indicator_on
= !dock
->lowered
;
974 entry
->clientdata
= dock
;
975 wMenuSetEnabled(menu
, index
, dock
->type
== WM_CLIP
);
978 entry
= menu
->entries
[++index
];
979 entry
->flags
.indicator_on
= dock
->collapsed
;
980 entry
->clientdata
= dock
;
983 entry
= menu
->entries
[++index
];
984 entry
->flags
.indicator_on
= dock
->auto_collapse
;
985 entry
->clientdata
= dock
;
987 /* auto-raise/lower */
988 entry
= menu
->entries
[++index
];
989 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
990 entry
->clientdata
= dock
;
991 wMenuSetEnabled(menu
, index
, dock
->lowered
&& (dock
->type
== WM_CLIP
));
994 entry
= menu
->entries
[++index
];
995 entry
->flags
.indicator_on
= dock
->attract_icons
;
996 entry
->clientdata
= dock
;
998 menu
->flags
.realized
= 0;
1003 static WMenu
*makeClipOptionsMenu(WScreen
*scr
)
1008 menu
= wMenuCreate(scr
, NULL
, False
);
1010 wwarning(_("could not create options submenu for Clip menu"));
1014 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
1015 entry
->flags
.indicator
= 1;
1016 entry
->flags
.indicator_on
= 1;
1017 entry
->flags
.indicator_type
= MI_CHECK
;
1019 entry
= wMenuAddCallback(menu
, _("Collapsed"), toggleCollapsedCallback
, NULL
);
1020 entry
->flags
.indicator
= 1;
1021 entry
->flags
.indicator_on
= 1;
1022 entry
->flags
.indicator_type
= MI_CHECK
;
1024 entry
= wMenuAddCallback(menu
, _("Autocollapse"), toggleAutoCollapseCallback
, NULL
);
1025 entry
->flags
.indicator
= 1;
1026 entry
->flags
.indicator_on
= 1;
1027 entry
->flags
.indicator_type
= MI_CHECK
;
1029 entry
= wMenuAddCallback(menu
, _("Autoraise"), toggleAutoRaiseLowerCallback
, NULL
);
1030 entry
->flags
.indicator
= 1;
1031 entry
->flags
.indicator_on
= 1;
1032 entry
->flags
.indicator_type
= MI_CHECK
;
1034 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"), toggleAutoAttractCallback
, NULL
);
1035 entry
->flags
.indicator
= 1;
1036 entry
->flags
.indicator_on
= 1;
1037 entry
->flags
.indicator_type
= MI_CHECK
;
1039 menu
->flags
.realized
= 0;
1046 static void setDockPositionNormalCallback(WMenu
*menu
, WMenuEntry
*entry
)
1048 WDock
*dock
= (WDock
*) entry
->clientdata
;
1050 if (entry
->flags
.indicator_on
) // already set, nothing to do
1052 // Do we come from auto raise lower or keep on top?
1053 if (dock
->auto_raise_lower
)
1055 dock
->auto_raise_lower
= 0;
1056 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1057 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1058 dc
->adrawer
->auto_raise_lower
= 0;
1063 // Will take care of setting lowered = 0 in drawers
1064 toggleLowered(dock
);
1066 entry
->flags
.indicator_on
= 1;
1069 static void setDockPositionAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
1071 WDock
*dock
= (WDock
*) entry
->clientdata
;
1073 if (entry
->flags
.indicator_on
) // already set, nothing to do
1075 // Do we come from normal or keep on top?
1078 toggleLowered(dock
);
1080 dock
->auto_raise_lower
= 1;
1081 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1082 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1083 dc
->adrawer
->auto_raise_lower
= 1;
1085 entry
->flags
.indicator_on
= 1;
1088 static void setDockPositionKeepOnTopCallback(WMenu
*menu
, WMenuEntry
*entry
)
1090 WDock
*dock
= (WDock
*) entry
->clientdata
;
1092 if (entry
->flags
.indicator_on
) // already set, nothing to do
1094 dock
->auto_raise_lower
= 0;
1095 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1096 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1097 dc
->adrawer
->auto_raise_lower
= 0;
1099 toggleLowered(dock
);
1100 entry
->flags
.indicator_on
= 1;
1103 static void updateDockPositionMenu(WMenu
*menu
, WDock
*dock
)
1112 entry
= menu
->entries
[index
++];
1113 entry
->flags
.indicator_on
= (dock
->lowered
&& !dock
->auto_raise_lower
);
1114 entry
->clientdata
= dock
;
1116 /* Auto-raise/lower */
1117 entry
= menu
->entries
[index
++];
1118 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1119 entry
->clientdata
= dock
;
1122 entry
= menu
->entries
[index
++];
1123 entry
->flags
.indicator_on
= !dock
->lowered
;
1124 entry
->clientdata
= dock
;
1127 static WMenu
*makeDockPositionMenu(WScreen
*scr
)
1129 /* When calling this, the dock is being created, so scr->dock is still not set
1130 * Therefore the callbacks' clientdata and the indicators can't be set,
1131 * they will be updated when the dock menu is opened. */
1135 menu
= wMenuCreate(scr
, NULL
, False
);
1137 wwarning(_("could not create options submenu for dock position menu"));
1141 entry
= wMenuAddCallback(menu
, _("Normal"), setDockPositionNormalCallback
, NULL
);
1142 entry
->flags
.indicator
= 1;
1143 entry
->flags
.indicator_type
= MI_DIAMOND
;
1145 entry
= wMenuAddCallback(menu
, _("Auto raise & lower"), setDockPositionAutoRaiseLowerCallback
, NULL
);
1146 entry
->flags
.indicator
= 1;
1147 entry
->flags
.indicator_type
= MI_DIAMOND
;
1149 entry
= wMenuAddCallback(menu
, _("Keep on Top"), setDockPositionKeepOnTopCallback
, NULL
);
1150 entry
->flags
.indicator
= 1;
1151 entry
->flags
.indicator_type
= MI_DIAMOND
;
1153 menu
->flags
.realized
= 0;
1160 static WMenu
*dockMenuCreate(WScreen
*scr
, int type
)
1165 if (type
== WM_CLIP
&& w_global
.clip
.menu
)
1166 return w_global
.clip
.menu
;
1168 if (type
== WM_DRAWER
&& w_global
.dock
.drawer_menu
)
1169 return w_global
.dock
.drawer_menu
;
1171 menu
= wMenuCreate(scr
, NULL
, False
);
1172 if (type
== WM_DOCK
) {
1173 entry
= wMenuAddCallback(menu
, _("Dock position"), NULL
, NULL
);
1174 if (w_global
.dock
.pos_menu
== NULL
)
1175 w_global
.dock
.pos_menu
= makeDockPositionMenu(scr
);
1176 wMenuEntrySetCascade(menu
, entry
, w_global
.dock
.pos_menu
);
1178 if (!wPreferences
.flags
.nodrawer
) {
1179 entry
= wMenuAddCallback(menu
, _("Add a drawer"), addADrawerCallback
, NULL
);
1182 if (type
== WM_CLIP
)
1183 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1184 else /* if (type == WM_DRAWER) */
1185 entry
= wMenuAddCallback(menu
, _("Drawer options"), NULL
, NULL
);
1187 if (w_global
.clip
.opt_menu
== NULL
)
1188 w_global
.clip
.opt_menu
= makeClipOptionsMenu(scr
);
1190 wMenuEntrySetCascade(menu
, entry
, w_global
.clip
.opt_menu
);
1192 /* The same menu is used for the dock and its appicons. If the menu
1193 * entry text is different between the two contexts, or if it can
1194 * change depending on some state, free the duplicated string (from
1195 * wMenuInsertCallback) and use gettext's string */
1196 if (type
== WM_CLIP
) {
1197 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1199 entry
->text
= _("Rename Workspace"); /* can be: (Toggle) Omnipresent */
1202 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1203 entry
->flags
.indicator
= 1;
1204 entry
->flags
.indicator_on
= 1;
1205 entry
->flags
.indicator_type
= MI_CHECK
;
1207 entry
= wMenuAddCallback(menu
, _("Select All Icons"), selectIconsCallback
, NULL
);
1209 entry
->text
= _("Select All Icons"); /* can be: Unselect all icons */
1211 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1213 entry
->text
= _("Keep Icon"); /* can be: Keep Icons */
1215 if (type
== WM_CLIP
) {
1216 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1218 entry
->text
= _("Move Icon To"); /* can be: Move Icons to */
1219 w_global
.clip
.submenu
= makeWorkspaceMenu(scr
);
1220 if (w_global
.clip
.submenu
)
1221 wMenuEntrySetCascade(menu
, entry
, w_global
.clip
.submenu
);
1224 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
, NULL
);
1226 entry
->text
= _("Remove Icon"); /* can be: Remove Icons */
1228 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1231 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1233 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1235 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1237 entry
->text
= _("Hide"); /* can be: Unhide */
1239 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1241 entry
= wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1243 entry
->text
= _("Kill"); /* can be: Remove drawer */
1245 if (type
== WM_CLIP
)
1246 w_global
.clip
.menu
= menu
;
1248 if (type
== WM_DRAWER
)
1249 w_global
.dock
.drawer_menu
= menu
;
1254 WDock
*wDockCreate(WScreen
*scr
, int type
, const char *name
)
1261 dock
= wmalloc(sizeof(WDock
));
1265 dock
->max_icons
= DOCK_MAX_ICONS
;
1268 dock
->max_icons
= scr
->scr_width
/ wPreferences
.icon_size
;
1272 dock
->max_icons
= scr
->scr_height
/ wPreferences
.icon_size
;
1275 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * dock
->max_icons
);
1277 btn
= mainIconCreate(scr
, type
, name
);
1281 dock
->x_pos
= btn
->x_pos
;
1282 dock
->y_pos
= btn
->y_pos
;
1283 dock
->screen_ptr
= scr
;
1285 dock
->icon_count
= 1;
1286 if (type
== WM_DRAWER
)
1287 dock
->on_right_side
= scr
->dock
->on_right_side
;
1289 dock
->on_right_side
= 1;
1290 dock
->collapsed
= 0;
1291 dock
->auto_collapse
= 0;
1292 dock
->auto_collapse_magic
= NULL
;
1293 dock
->auto_raise_lower
= 0;
1294 dock
->auto_lower_magic
= NULL
;
1295 dock
->auto_raise_magic
= NULL
;
1296 dock
->attract_icons
= 0;
1298 dock
->icon_array
[0] = btn
;
1299 wRaiseFrame(btn
->icon
->core
);
1300 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1302 /* create dock menu */
1303 dock
->menu
= dockMenuCreate(scr
, type
);
1305 if (type
== WM_DRAWER
) {
1306 drawerAppendToChain(scr
, dock
);
1307 dock
->auto_collapse
= 1;
1313 void wDockDestroy(WDock
*dock
)
1318 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1319 aicon
= dock
->icon_array
[i
];
1321 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1322 wDockDetach(dock
, aicon
);
1324 /* XXX: can: aicon->icon == NULL ? */
1325 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1326 wGetHeadForWindow(aicon
->icon
->owner
));
1327 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1328 if (!dock
->mapped
|| dock
->collapsed
)
1329 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1333 if (wPreferences
.auto_arrange_icons
)
1334 wArrangeIcons(dock
->screen_ptr
, True
);
1335 wfree(dock
->icon_array
);
1336 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1337 wMenuDestroy(dock
->menu
, True
);
1338 if (dock
->screen_ptr
->last_dock
== dock
)
1339 dock
->screen_ptr
->last_dock
= NULL
;
1343 void wClipIconPaint(void)
1345 WAppIcon
*aicon
= w_global
.clip
.icon
;
1346 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1347 WWorkspace
*workspace
= w_global
.workspace
.array
[w_global
.workspace
.current
];
1349 Window win
= aicon
->icon
->core
->window
;
1350 int length
, nlength
;
1351 char *ws_name
, ws_number
[10];
1354 wIconPaint(aicon
->icon
);
1356 length
= strlen(workspace
->name
);
1357 ws_name
= wmalloc(length
+ 1);
1358 snprintf(ws_name
, length
+ 1, "%s", workspace
->name
);
1359 snprintf(ws_number
, sizeof(ws_number
), "%i", w_global
.workspace
.current
+ 1);
1360 nlength
= strlen(ws_number
);
1362 if (wPreferences
.flags
.noclip
|| !workspace
->clip
->collapsed
)
1363 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1365 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1367 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1369 tx
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
1371 if(wPreferences
.show_clip_title
)
1372 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, ty
, ws_name
, length
);
1374 tx
= (ICON_SIZE
/ 2 - WMWidthOfString(scr
->clip_title_font
, ws_number
, nlength
)) / 2;
1376 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, 2, ws_number
, nlength
);
1380 if (aicon
->launching
)
1381 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1382 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1384 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
, aicon
->dock
->rclip_button_pushed
);
1387 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1392 static void dockIconPaint(WAppIcon
*btn
)
1394 if (btn
== w_global
.clip
.icon
) {
1396 } else if (wIsADrawer(btn
)) {
1397 wDrawerIconPaint(btn
);
1400 save_appicon(btn
, True
);
1404 static WMPropList
*make_icon_state(WAppIcon
*btn
)
1406 WMPropList
*node
= NULL
;
1407 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
;
1408 WMPropList
*position
, *buggy
, *omnipresent
;
1414 command
= WMCreatePLString("-");
1416 command
= WMCreatePLString(btn
->command
);
1418 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1420 lock
= btn
->lock
? dYes
: dNo
;
1422 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1424 name
= WMCreatePLString(tmp
);
1428 forced
= btn
->forced_dock
? dYes
: dNo
;
1430 buggy
= btn
->buggy_app
? dYes
: dNo
;
1432 if (!wPreferences
.flags
.clip_merged_in_dock
&& btn
== w_global
.clip
.icon
)
1433 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1435 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1436 position
= WMCreatePLString(buffer
);
1438 node
= WMCreatePLDictionary(dCommand
, command
,
1440 dAutoLaunch
, autolaunch
,
1442 dForced
, forced
, dBuggyApplication
, buggy
, dPosition
, position
, NULL
);
1443 WMReleasePropList(command
);
1444 WMReleasePropList(name
);
1445 WMReleasePropList(position
);
1447 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1448 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&& (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1449 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1451 #ifdef XDND /* was OFFIX */
1452 if (btn
->dnd_command
) {
1453 command
= WMCreatePLString(btn
->dnd_command
);
1454 WMPutInPLDictionary(node
, dDropCommand
, command
);
1455 WMReleasePropList(command
);
1459 if (btn
->paste_command
) {
1460 command
= WMCreatePLString(btn
->paste_command
);
1461 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1462 WMReleasePropList(command
);
1469 static WMPropList
*dockSaveState(WDock
*dock
)
1472 WMPropList
*icon_info
;
1473 WMPropList
*list
= NULL
, *dock_state
= NULL
;
1474 WMPropList
*value
, *key
;
1477 list
= WMCreatePLArray(NULL
);
1479 for (i
= (dock
->type
== WM_DOCK
? 0 : 1); i
< dock
->max_icons
; i
++) {
1480 WAppIcon
*btn
= dock
->icon_array
[i
];
1482 if (!btn
|| btn
->attracted
)
1485 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1486 WMAddToPLArray(list
, icon_info
);
1487 WMReleasePropList(icon_info
);
1491 dock_state
= WMCreatePLDictionary(dApplications
, list
, NULL
);
1493 if (dock
->type
== WM_DOCK
) {
1494 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1495 key
= WMCreatePLString(buffer
);
1496 WMPutInPLDictionary(dock_state
, key
, list
);
1497 WMReleasePropList(key
);
1499 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0), dock
->y_pos
);
1500 value
= WMCreatePLString(buffer
);
1501 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1502 WMReleasePropList(value
);
1504 WMReleasePropList(list
);
1506 if (dock
->type
== WM_CLIP
|| dock
->type
== WM_DRAWER
) {
1507 value
= (dock
->collapsed
? dYes
: dNo
);
1508 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1510 value
= (dock
->auto_collapse
? dYes
: dNo
);
1511 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1513 value
= (dock
->attract_icons
? dYes
: dNo
);
1514 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1517 if (dock
->type
== WM_DOCK
|| dock
->type
== WM_CLIP
) {
1518 value
= (dock
->lowered
? dYes
: dNo
);
1519 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1521 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1522 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1528 void wDockSaveState(WScreen
*scr
, WMPropList
*old_state
)
1530 WMPropList
*dock_state
;
1533 dock_state
= dockSaveState(scr
->dock
);
1536 * Copy saved states of docks with different sizes.
1542 keys
= WMGetPLDictionaryKeys(old_state
);
1543 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1544 tmp
= WMGetFromPLArray(keys
, i
);
1546 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1547 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1549 WMPutInPLDictionary(dock_state
, tmp
, WMGetFromPLDictionary(old_state
, tmp
));
1552 WMReleasePropList(keys
);
1555 WMPutInPLDictionary(w_global
.session_state
, dDock
, dock_state
);
1556 WMReleasePropList(dock_state
);
1559 void wClipSaveState(WScreen
*scr
)
1561 WMPropList
*clip_state
;
1563 clip_state
= make_icon_state(w_global
.clip
.icon
);
1565 WMPutInPLDictionary(w_global
.session_state
, dClip
, clip_state
);
1566 WMReleasePropList(clip_state
);
1569 WMPropList
*wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1571 return dockSaveState(w_global
.workspace
.array
[workspace
]->clip
);
1574 static Bool
getBooleanDockValue(WMPropList
*value
, WMPropList
*key
)
1577 if (WMIsPLString(value
)) {
1578 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1581 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1587 static WAppIcon
*restore_icon_state(WScreen
*scr
, WMPropList
*info
, int type
, int index
)
1590 WMPropList
*cmd
, *value
;
1591 char *wclass
, *winstance
, *command
;
1593 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1594 if (!cmd
|| !WMIsPLString(cmd
))
1597 /* parse window name */
1598 value
= WMGetFromPLDictionary(info
, dName
);
1602 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1604 if (!winstance
&& !wclass
)
1609 command
= wstrdup(WMGetFromPLString(cmd
));
1613 if (!command
|| strcmp(command
, "-") == 0) {
1624 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1632 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1633 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1634 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1635 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1636 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1638 #ifdef XDND /* was OFFIX */
1639 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1641 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1644 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1646 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1648 /* check auto launch */
1649 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1651 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1654 value
= WMGetFromPLDictionary(info
, dLock
);
1656 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1658 /* check if it wasn't normally docked */
1659 value
= WMGetFromPLDictionary(info
, dForced
);
1661 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1663 /* check if we can rely on the stuff in the app */
1664 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1666 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1668 /* get position in the dock */
1669 value
= WMGetFromPLDictionary(info
, dPosition
);
1670 if (value
&& WMIsPLString(value
)) {
1671 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1672 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1674 /* check position sanity */
1675 /* *Very* incomplete section! */
1676 if (type
== WM_DOCK
) {
1680 aicon
->yindex
= index
;
1684 /* check if icon is omnipresent */
1685 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1687 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1695 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1697 WAppIcon
*wClipRestoreState(WScreen
*scr
, WMPropList
*clip_state
)
1702 icon
= mainIconCreate(scr
, WM_CLIP
, NULL
);
1707 WMRetainPropList(clip_state
);
1709 /* restore position */
1711 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1714 if (!WMIsPLString(value
)) {
1715 COMPLAIN("Position");
1717 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1718 COMPLAIN("Position");
1720 /* check position sanity */
1721 if (!onScreen(scr
, icon
->x_pos
, icon
->y_pos
))
1722 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1725 #ifdef XDND /* was OFFIX */
1726 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1727 if (value
&& WMIsPLString(value
))
1728 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1731 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1732 if (value
&& WMIsPLString(value
))
1733 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1735 WMReleasePropList(clip_state
);
1740 WDock
*wDockRestoreState(WScreen
*scr
, WMPropList
*dock_state
, int type
)
1745 WAppIcon
*aicon
, *old_top
;
1748 dock
= wDockCreate(scr
, type
, NULL
);
1753 WMRetainPropList(dock_state
);
1755 /* restore position */
1756 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1758 if (!WMIsPLString(value
)) {
1759 COMPLAIN("Position");
1761 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1762 COMPLAIN("Position");
1764 /* check position sanity */
1765 if (!onScreen(scr
, dock
->x_pos
, dock
->y_pos
)) {
1766 int x
= dock
->x_pos
;
1767 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1770 /* Is this needed any more? */
1771 if (type
== WM_CLIP
) {
1772 if (dock
->x_pos
< 0) {
1774 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1775 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1778 if (dock
->x_pos
>= 0) {
1779 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1780 dock
->on_right_side
= 0;
1782 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1783 dock
->on_right_side
= 1;
1789 /* restore lowered/raised state */
1792 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1794 if (!WMIsPLString(value
)) {
1795 COMPLAIN("Lowered");
1797 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1802 /* restore collapsed state */
1803 dock
->collapsed
= 0;
1805 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1807 if (!WMIsPLString(value
)) {
1808 COMPLAIN("Collapsed");
1810 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1811 dock
->collapsed
= 1;
1815 /* restore auto-collapsed state */
1816 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1818 if (!WMIsPLString(value
)) {
1819 COMPLAIN("AutoCollapse");
1821 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1822 dock
->auto_collapse
= 1;
1823 dock
->collapsed
= 1;
1828 /* restore auto-raise/lower state */
1829 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1831 if (!WMIsPLString(value
)) {
1832 COMPLAIN("AutoRaiseLower");
1834 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1835 dock
->auto_raise_lower
= 1;
1839 /* restore attract icons state */
1840 dock
->attract_icons
= 0;
1842 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1844 if (!WMIsPLString(value
)) {
1845 COMPLAIN("AutoAttractIcons");
1847 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1848 dock
->attract_icons
= 1;
1852 /* application list */
1859 * When saving, it saves the dock state in
1860 * Applications and Applicationsnnn
1862 * When loading, it will first try Applicationsnnn.
1863 * If it does not exist, use Applications as default.
1866 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1868 tmp
= WMCreatePLString(buffer
);
1869 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1870 WMReleasePropList(tmp
);
1873 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1879 count
= WMGetPropListItemCount(apps
);
1883 old_top
= dock
->icon_array
[0];
1885 /* dock->icon_count is set to 1 when dock is created.
1886 * Since Clip is already restored, we want to keep it so for clip,
1887 * but for dock we may change the default top tile, so we set it to 0.
1889 if (type
== WM_DOCK
)
1890 dock
->icon_count
= 0;
1892 for (i
= 0; i
< count
; i
++) {
1893 if (dock
->icon_count
>= dock
->max_icons
) {
1894 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1898 value
= WMGetFromPLArray(apps
, i
);
1899 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1901 dock
->icon_array
[dock
->icon_count
] = aicon
;
1905 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1906 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1909 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1911 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1913 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1914 if (!dock
->collapsed
)
1915 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1917 wRaiseFrame(aicon
->icon
->core
);
1920 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
) {
1925 /* if the first icon is not defined, use the default */
1926 if (dock
->icon_array
[0] == NULL
) {
1927 /* update default icon */
1928 old_top
->x_pos
= dock
->x_pos
;
1929 old_top
->y_pos
= dock
->y_pos
;
1931 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1933 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1935 dock
->icon_array
[0] = old_top
;
1936 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1937 /* we don't need to increment dock->icon_count here because it was
1938 * incremented in the loop above.
1940 } else if (old_top
!= dock
->icon_array
[0]) {
1941 if (old_top
== w_global
.clip
.icon
) /* TODO dande: understand the logic */
1942 w_global
.clip
.icon
= dock
->icon_array
[0];
1944 wAppIconDestroy(old_top
);
1948 WMReleasePropList(dock_state
);
1953 void wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1955 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1956 btn
->drop_launch
= 0;
1957 btn
->paste_launch
= 0;
1959 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1962 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1972 void wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1978 for (i
= 0; i
< dock
->max_icons
; i
++) {
1979 btn
= dock
->icon_array
[i
];
1980 if (!btn
|| !btn
->auto_launch
)
1983 state
= wmalloc(sizeof(WSavedState
));
1984 state
->workspace
= workspace
;
1985 /* TODO: this is klugy and is very difficult to understand
1986 * what's going on. Try to clean up */
1987 wDockLaunchWithState(dock
, btn
, state
);
1991 #ifdef XDND /* was OFFIX */
1992 static WDock
*findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1998 if ((dock
= scr
->dock
) != NULL
) {
1999 for (i
= 0; i
< dock
->max_icons
; i
++) {
2000 if (dock
->icon_array
[i
]
2001 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
2007 if (*icon_pos
< 0 && (dock
= w_global
.workspace
.array
[w_global
.workspace
.current
]->clip
) != NULL
) {
2008 for (i
= 0; i
< dock
->max_icons
; i
++) {
2009 if (dock
->icon_array
[i
]
2010 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
2021 int wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
2027 dock
= findDock(scr
, event
, &icon_pos
);
2032 * Return True if the drop was on an application icon window.
2033 * In this case, let the ClientMessage handler redirect the
2034 * message to the app.
2036 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
2039 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
2040 scr
->flags
.dnd_data_convertion_status
= 0;
2042 btn
= dock
->icon_array
[icon_pos
];
2044 if (!btn
->forced_dock
) {
2045 btn
->relaunching
= btn
->running
;
2048 if (btn
->wm_instance
|| btn
->wm_class
) {
2049 WWindowAttributes attr
;
2050 memset(&attr
, 0, sizeof(WWindowAttributes
));
2051 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
2053 if (!attr
.no_appicon
)
2059 btn
->paste_launch
= 0;
2060 btn
->drop_launch
= 1;
2061 scr
->last_dock
= dock
;
2062 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
2067 if (!btn
->relaunching
)
2075 Bool
wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
, Bool update_icon
)
2078 Bool lupdate_icon
= False
;
2079 char *command
= NULL
;
2085 lupdate_icon
= True
;
2087 if (icon
->command
== NULL
) {
2088 /* If icon->owner exists, it means the application is running */
2089 if (icon
->icon
->owner
) {
2090 wwin
= icon
->icon
->owner
;
2091 command
= GetCommandForWindow(wwin
->client_win
);
2095 icon
->command
= command
;
2097 /* icon->forced_dock = 1; */
2098 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
2100 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2101 _("Type the command used to launch the application"), &command
)) {
2102 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2106 icon
->command
= command
;
2112 /* If the target is the dock, reject the icon. If
2113 * the target is the clip, make it an attracted icon
2115 if (dock
->type
== WM_CLIP
) {
2116 icon
->attracted
= 1;
2117 if (!icon
->icon
->shadowed
) {
2118 icon
->icon
->shadowed
= 1;
2119 lupdate_icon
= True
;
2129 for (index
= 1; index
< dock
->max_icons
; index
++)
2130 if (dock
->icon_array
[index
] == NULL
)
2132 /* if (index == dock->max_icons)
2135 assert(index
< dock
->max_icons
);
2137 dock
->icon_array
[index
] = icon
;
2141 icon
->omnipresent
= 0;
2143 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2144 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2149 icon
->launching
= 0;
2152 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2153 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2154 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2155 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2156 icon
->icon
->core
->descriptor
.parent
= icon
;
2158 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2159 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2162 * Update icon pixmap, RImage doesn't change,
2163 * so call wIconUpdate is not needed
2166 update_icon_pixmap(icon
->icon
);
2169 wAppIconPaint(icon
);
2172 save_appicon(icon
, True
);
2174 if (wPreferences
.auto_arrange_icons
)
2175 wArrangeIcons(dock
->screen_ptr
, True
);
2177 #ifdef XDND /* was OFFIX */
2178 if (icon
->command
&& !icon
->dnd_command
) {
2179 int len
= strlen(icon
->command
) + 8;
2180 icon
->dnd_command
= wmalloc(len
);
2181 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
2185 if (icon
->command
&& !icon
->paste_command
) {
2186 int len
= strlen(icon
->command
) + 8;
2187 icon
->paste_command
= wmalloc(len
);
2188 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
2194 void wDockReattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2198 for (index
= 1; index
< dock
->max_icons
; index
++) {
2199 if (dock
->icon_array
[index
] == icon
)
2202 assert(index
< dock
->max_icons
);
2207 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2208 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2211 Bool
wDockMoveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2214 char *command
= NULL
;
2216 Bool update_icon
= False
;
2219 return True
; /* No move needed, we're already there */
2225 * For the moment we can't do this if we move icons in Clip from one
2226 * workspace to other, because if we move two or more icons without
2227 * command, the dialog box will not be able to tell us to which of the
2228 * moved icons it applies. -Dan
2230 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
2231 /* If icon->owner exists, it means the application is running */
2232 if (icon
->icon
->owner
) {
2233 wwin
= icon
->icon
->owner
;
2234 command
= GetCommandForWindow(wwin
->client_win
);
2238 icon
->command
= command
;
2241 /* icon->forced_dock = 1; */
2242 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2243 _("Type the command used to launch the application"), &command
)) {
2244 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2248 icon
->command
= command
;
2259 if (dest
->type
== WM_DOCK
|| dest
->type
== WM_DRAWER
)
2260 wClipMakeIconOmnipresent(icon
, False
);
2262 for (index
= 1; index
< src
->max_icons
; index
++) {
2263 if (src
->icon_array
[index
] == icon
)
2266 assert(index
< src
->max_icons
);
2268 src
->icon_array
[index
] = NULL
;
2271 for (index
= 1; index
< dest
->max_icons
; index
++) {
2272 if (dest
->icon_array
[index
] == NULL
)
2276 assert(index
< dest
->max_icons
);
2278 dest
->icon_array
[index
] = icon
;
2281 /* deselect the icon */
2282 if (icon
->icon
->selected
)
2283 wIconSelect(icon
->icon
);
2285 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2286 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2288 /* set it to be kept when moving to dock.
2289 * Unless the icon does not have a command set
2291 if (icon
->command
&& (dest
->type
== WM_DOCK
|| dest
->type
== WM_DRAWER
)) {
2292 icon
->attracted
= 0;
2293 if (icon
->icon
->shadowed
) {
2294 icon
->icon
->shadowed
= 0;
2297 save_appicon(icon
, True
);
2300 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2306 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2307 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2311 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2314 * Update icon pixmap, RImage doesn't change,
2315 * so call wIconUpdate is not needed
2318 update_icon_pixmap(icon
->icon
);
2321 wAppIconPaint(icon
);
2326 void wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2329 Bool update_icon
= False
;
2331 /* make the settings panel be closed */
2333 DestroyDockAppSettingsPanel(icon
->panel
);
2335 /* This must be called before icon->dock is set to NULL.
2336 * Don't move it. -Dan
2338 wClipMakeIconOmnipresent(icon
, False
);
2342 icon
->attracted
= 0;
2343 icon
->auto_launch
= 0;
2344 if (icon
->icon
->shadowed
) {
2345 icon
->icon
->shadowed
= 0;
2349 /* deselect the icon */
2350 if (icon
->icon
->selected
)
2351 wIconSelect(icon
->icon
);
2353 if (icon
->command
) {
2354 wfree(icon
->command
);
2355 icon
->command
= NULL
;
2357 #ifdef XDND /* was OFFIX */
2358 if (icon
->dnd_command
) {
2359 wfree(icon
->dnd_command
);
2360 icon
->dnd_command
= NULL
;
2363 if (icon
->paste_command
) {
2364 wfree(icon
->paste_command
);
2365 icon
->paste_command
= NULL
;
2368 for (index
= 1; index
< dock
->max_icons
; index
++)
2369 if (dock
->icon_array
[index
] == icon
)
2372 assert(index
< dock
->max_icons
);
2373 dock
->icon_array
[index
] = NULL
;
2379 /* if the dock is not attached to an application or
2380 * the application did not set the appropriate hints yet,
2381 * destroy the icon */
2382 if (!icon
->running
|| !wApplicationOf(icon
->main_window
)) {
2383 wAppIconDestroy(icon
);
2385 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2386 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2387 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2388 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2389 icon
->icon
->core
->descriptor
.parent
= icon
;
2391 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2394 * Update icon pixmap, RImage doesn't change,
2395 * so call wIconUpdate is not needed
2398 update_icon_pixmap(icon
->icon
);
2401 wAppIconPaint(icon
);
2403 if (wPreferences
.auto_arrange_icons
)
2404 wArrangeIcons(dock
->screen_ptr
, True
);
2406 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2411 * returns the closest Dock slot index for the passed
2414 * Returns False if icon can't be docked.
2416 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2419 /* Redocking == true means either icon->dock == dock (normal case)
2420 * or we are called from handleDockMove for a drawer */
2421 Bool
wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2423 WScreen
*scr
= dock
->screen_ptr
;
2426 int i
, offset
= ICON_SIZE
/ 2;
2427 WAppIcon
*aicon
= NULL
;
2428 WAppIcon
*nicon
= NULL
;
2430 if (wPreferences
.flags
.noupdates
)
2436 /* if the dock is full */
2437 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
))
2440 /* exact position */
2442 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2444 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2447 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2449 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2451 /* check if the icon is outside the screen boundaries */
2452 if (!onScreen(scr
, dx
+ ex_x
* ICON_SIZE
, dy
+ ex_y
* ICON_SIZE
))
2455 switch (dock
->type
) {
2457 /* We can return False right away if
2458 * - we do not come from this dock (which is a WM_DOCK),
2459 * - we are not right over it, and
2460 * - we are not the main tile of a drawer.
2461 * In the latter case, we are called from handleDockMove. */
2462 if (icon
->dock
!= dock
&& ex_x
!= 0 &&
2463 !(icon
->dock
&& icon
->dock
->type
== WM_DRAWER
&& icon
== icon
->dock
->icon_array
[0]))
2466 if (!redocking
&& ex_x
!= 0)
2469 if (getDrawer(scr
, ex_y
)) /* Return false so that the drawer gets it. */
2473 for (i
= 0; i
< dock
->max_icons
; i
++) {
2474 nicon
= dock
->icon_array
[i
];
2475 if (nicon
&& nicon
->yindex
== ex_y
) {
2482 int sig
, done
, closest
;
2484 /* Possible cases when redocking:
2486 * icon dragged out of range of any slot -> false
2487 * icon dragged on a drawer -> false (to open the drawer)
2488 * icon dragged to range of free slot
2489 * icon dragged to range of same slot
2490 * icon dragged to range of different icon
2492 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2495 if (aicon
== icon
|| !aicon
) {
2501 /* start looking at the upper slot or lower? */
2502 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2508 /* look for closest free slot */
2509 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2513 closest
= sig
* (i
/ 2) + ex_y
;
2514 /* check if this slot is fully on the screen and not used */
2515 if (onScreen(scr
, dx
, dy
+ closest
* ICON_SIZE
)) {
2516 for (j
= 0; j
< dock
->max_icons
; j
++) {
2517 if (dock
->icon_array
[j
]
2518 && dock
->icon_array
[j
]->yindex
== closest
) {
2519 /* slot is used by someone else */
2520 if (dock
->icon_array
[j
] != icon
)
2525 /* slot is used by a drawer */
2526 done
= done
&& !getDrawer(scr
, closest
);
2533 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2534 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2539 } else { /* !redocking */
2541 /* if slot is free and the icon is close enough, return it */
2542 if (!aicon
&& ex_x
== 0) {
2554 start
= icon
->omnipresent
? 0 : w_global
.workspace
.current
;
2555 stop
= icon
->omnipresent
? w_global
.workspace
.count
: start
+ 1;
2558 for (k
= start
; k
< stop
; k
++) {
2559 WDock
*tmp
= w_global
.workspace
.array
[k
]->clip
;
2562 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2563 nicon
= tmp
->icon_array
[i
];
2564 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2572 for (k
= start
; k
< stop
; k
++) {
2573 WDock
*tmp
= w_global
.workspace
.array
[k
]->clip
;
2576 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2577 nicon
= tmp
->icon_array
[i
];
2578 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2579 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2580 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2589 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2598 WAppIcon
*aicons_to_shift
[ dock
->icon_count
];
2599 int index_of_hole
, j
;
2602 abs(ex_x
) - dock
->icon_count
> DOCK_DETTACH_THRESHOLD
||
2603 (ex_x
< 0 && !dock
->on_right_side
) ||
2604 (ex_x
> 0 && dock
->on_right_side
)) {
2609 ex_x
= (dock
->on_right_side
? -1 : 1);
2611 /* "Reduce" ex_x but keep its sign */
2613 if (abs(ex_x
) > dock
->icon_count
- 1) /* minus 1: do not take icon_array[0] into account */
2614 ex_x
= ex_x
* (dock
->icon_count
- 1) / abs(ex_x
); /* don't use *= ! */
2616 if (abs(ex_x
) > dock
->icon_count
)
2617 ex_x
= ex_x
* dock
->icon_count
/ abs(ex_x
);
2619 index_of_hole
= indexOfHole(dock
, icon
, redocking
);
2621 /* Find the appicons between where icon was (index_of_hole) and where
2622 * it wants to be (ex_x) and slide them. */
2624 for (i
= 1; i
< dock
->max_icons
; i
++) {
2625 if ((aicon
= dock
->icon_array
[ i
]) && aicon
!= icon
&&
2626 ((ex_x
<= aicon
->xindex
&& aicon
->xindex
< index_of_hole
) ||
2627 (index_of_hole
< aicon
->xindex
&& aicon
->xindex
<= ex_x
)))
2628 aicons_to_shift
[ j
++ ] = aicon
;
2630 assert(j
== abs(ex_x
- index_of_hole
));
2632 wSlideAppicons(aicons_to_shift
, j
, (index_of_hole
< ex_x
));
2642 static int onScreen(WScreen
*scr
, int x
, int y
)
2649 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2651 wGetRectPlacementInfo(scr
, rect
, &flags
);
2653 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2657 * returns true if it can find a free slot in the dock,
2658 * in which case it changes x_pos and y_pos accordingly.
2659 * Else returns false.
2661 Bool
wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2663 WScreen
*scr
= dock
->screen_ptr
;
2665 WAppIconChain
*chain
;
2666 unsigned char *slot_map
;
2670 int i
, done
= False
;
2672 int sx
= 0, ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2673 int extra_count
= 0;
2675 if (dock
->type
== WM_DRAWER
) {
2676 if (dock
->icon_count
>= dock
->max_icons
) { /* drawer is full */
2679 *x_pos
= dock
->icon_count
* (dock
->on_right_side
? -1 : 1);
2684 if (dock
->type
== WM_CLIP
&& dock
!= w_global
.workspace
.array
[w_global
.workspace
.current
]->clip
)
2685 extra_count
= scr
->global_icon_count
;
2687 /* if the dock is full */
2688 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
)
2691 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2692 if (scr
->dock
->on_right_side
)
2693 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2695 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2698 if (ex
< dock
->x_pos
)
2700 if (sx
> dock
->x_pos
+ ICON_SIZE
)
2701 sx
= dock
->x_pos
+ ICON_SIZE
;
2708 /* check if clip is in a corner */
2709 if (dock
->type
== WM_CLIP
) {
2710 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2712 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2714 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2716 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2724 /* If the clip is in the corner, use only slots that are in the border
2726 if (corner
!= C_NONE
) {
2730 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2731 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2732 hmap
= wmalloc(hcount
+ 1);
2733 vmap
= wmalloc(vcount
+ 1);
2735 /* mark used positions */
2738 for (i
= 0; i
< dock
->max_icons
; i
++) {
2739 btn
= dock
->icon_array
[i
];
2743 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2744 vmap
[btn
->yindex
] = 1;
2745 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2746 hmap
[btn
->xindex
] = 1;
2748 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2750 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2751 vmap
[btn
->yindex
] = 1;
2752 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2753 hmap
[btn
->xindex
] = 1;
2757 for (i
= 0; i
< dock
->max_icons
; i
++) {
2758 btn
= dock
->icon_array
[i
];
2762 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2763 vmap
[btn
->yindex
] = 1;
2764 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2765 hmap
[-btn
->xindex
] = 1;
2767 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2769 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2770 vmap
[btn
->yindex
] = 1;
2771 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2772 hmap
[-btn
->xindex
] = 1;
2776 for (i
= 0; i
< dock
->max_icons
; i
++) {
2777 btn
= dock
->icon_array
[i
];
2781 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2782 vmap
[-btn
->yindex
] = 1;
2783 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2784 hmap
[btn
->xindex
] = 1;
2786 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2788 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2789 vmap
[-btn
->yindex
] = 1;
2790 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2791 hmap
[btn
->xindex
] = 1;
2796 for (i
= 0; i
< dock
->max_icons
; i
++) {
2797 btn
= dock
->icon_array
[i
];
2801 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2802 vmap
[-btn
->yindex
] = 1;
2803 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2804 hmap
[-btn
->xindex
] = 1;
2806 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2808 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2809 vmap
[-btn
->yindex
] = 1;
2810 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2811 hmap
[-btn
->xindex
] = 1;
2817 /* search a vacant slot */
2818 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2819 if (i
< vcount
&& vmap
[i
] == 0) {
2825 } else if (i
< hcount
&& hmap
[i
] == 0) {
2835 /* If found a slot, translate and return */
2837 if (corner
== C_NW
|| corner
== C_NE
)
2842 if (corner
== C_NE
|| corner
== C_SE
)
2849 /* else, try to find a slot somewhere else */
2852 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2853 * placed outside of screen */
2854 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2856 /* In the worst case (the clip is in the corner of the screen),
2857 * the amount of icons that fit in the clip is smaller.
2858 * Double the map to get a safe value.
2862 r
= (mwidth
- 1) / 2;
2864 slot_map
= wmalloc(mwidth
* mwidth
);
2866 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2868 /* mark used slots in the map. If the slot falls outside the map
2869 * (for example, when all icons are placed in line), ignore them. */
2870 for (i
= 0; i
< dock
->max_icons
; i
++) {
2871 btn
= dock
->icon_array
[i
];
2873 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2876 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
)
2877 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2879 /* Find closest slot from the center that is free by scanning the
2880 * map from the center to outward in circular passes.
2881 * This will not result in a neat layout, but will be optimal
2882 * in the sense that there will not be holes left.
2885 for (i
= 1; i
<= r
&& !done
; i
++) {
2888 /* top and bottom parts of the ring */
2889 for (x
= -i
; x
<= i
&& !done
; x
++) {
2890 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2892 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2893 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2900 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2901 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2908 /* left and right parts of the ring */
2909 for (y
= -i
+ 1; y
<= i
- 1; y
++) {
2910 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2912 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2913 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2920 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2921 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2934 static void moveDock(WDock
*dock
, int new_x
, int new_y
)
2940 if (dock
->type
== WM_DOCK
) {
2941 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
2942 moveDock(dc
->adrawer
, new_x
, dc
->adrawer
->y_pos
- dock
->y_pos
+ new_y
);
2945 dock
->x_pos
= new_x
;
2946 dock
->y_pos
= new_y
;
2947 for (i
= 0; i
< dock
->max_icons
; i
++) {
2948 btn
= dock
->icon_array
[i
];
2950 btn
->x_pos
= new_x
+ btn
->xindex
* ICON_SIZE
;
2951 btn
->y_pos
= new_y
+ btn
->yindex
* ICON_SIZE
;
2952 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2957 static void swapDock(WDock
*dock
)
2959 WScreen
*scr
= dock
->screen_ptr
;
2963 if (dock
->on_right_side
)
2964 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2966 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2968 swapDrawers(scr
, dock
->on_right_side
, x
);
2970 for (i
= 0; i
< dock
->max_icons
; i
++) {
2971 btn
= dock
->icon_array
[i
];
2974 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2978 wScreenUpdateUsableArea(scr
);
2981 static pid_t
execCommand(WAppIcon
*btn
, const char *command
, WSavedState
*state
)
2983 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2989 cmdline
= ExpandOptions(scr
, command
);
2991 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2999 wtokensplit(cmdline
, &argv
, &argc
);
3009 if ((pid
= fork()) == 0) {
3013 SetupEnvironment(scr
);
3019 args
= malloc(sizeof(char *) * (argc
+ 1));
3023 for (i
= 0; i
< argc
; i
++)
3027 execvp(argv
[0], args
);
3030 wtokenfree(argv
, argc
);
3034 state
= wmalloc(sizeof(WSavedState
));
3036 state
->miniaturized
= -1;
3038 if (btn
->dock
== scr
->dock
|| btn
->dock
->type
== WM_DRAWER
|| btn
->omnipresent
)
3039 state
->workspace
= -1;
3041 state
->workspace
= w_global
.workspace
.current
;
3043 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
3044 wAddDeathHandler(pid
, (WDeathHandler
*) trackDeadProcess
, btn
->dock
);
3052 void wDockHideIcons(WDock
*dock
)
3059 for (i
= 1; i
< dock
->max_icons
; i
++) {
3060 if (dock
->icon_array
[i
])
3061 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3065 dockIconPaint(dock
->icon_array
[0]);
3068 void wDockShowIcons(WDock
*dock
)
3076 btn
= dock
->icon_array
[0];
3077 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
3079 /* Deleting any change in stacking level, this function is now only about
3082 if (!dock
->collapsed
) {
3083 for (i
= 1; i
< dock
->max_icons
; i
++) {
3084 if (dock
->icon_array
[i
])
3085 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3093 void wDockLower(WDock
*dock
)
3098 if (dock
->type
== WM_DOCK
) {
3099 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3100 wDockLower(dc
->adrawer
);
3102 for (i
= 0; i
< dock
->max_icons
; i
++) {
3103 if (dock
->icon_array
[i
])
3104 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
3108 void wDockRaise(WDock
*dock
)
3113 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
3114 if (dock
->icon_array
[i
])
3115 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
3117 if (dock
->type
== WM_DOCK
) {
3118 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3119 wDockRaise(dc
->adrawer
);
3123 void wDockRaiseLower(WDock
*dock
)
3125 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
3126 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
3127 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
3133 void wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
3135 icon
->launching
= 0;
3136 icon
->relaunching
= 0;
3137 dockIconPaint(icon
);
3140 WAppIcon
*wDockFindIconForWindow(WDock
*dock
, Window window
)
3145 for (i
= 0; i
< dock
->max_icons
; i
++) {
3146 icon
= dock
->icon_array
[i
];
3147 if (icon
&& icon
->main_window
== window
)
3153 void wDockTrackWindowLaunch(WDock
*dock
, Window window
)
3156 char *wm_class
, *wm_instance
;
3158 Bool firstPass
= True
;
3160 char *command
= NULL
;
3162 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) || (!wm_class
&& !wm_instance
))
3165 command
= GetCommandForWindow(window
);
3167 for (i
= 0; i
< dock
->max_icons
; i
++) {
3168 icon
= dock
->icon_array
[i
];
3172 /* app is already attached to icon */
3173 if (icon
->main_window
== window
) {
3178 if ((icon
->wm_instance
|| icon
->wm_class
)
3179 && (icon
->launching
|| !icon
->running
)) {
3181 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0)
3184 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0)
3187 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0)
3190 if (!icon
->relaunching
) {
3193 /* Possibly an application that was docked with dockit,
3194 * but the user did not update WMState to indicate that
3195 * it was docked by force */
3196 wapp
= wApplicationOf(window
);
3198 icon
->forced_dock
= 1;
3201 if (!icon
->forced_dock
)
3202 icon
->main_window
= window
;
3205 if (!wPreferences
.no_animations
&& !icon
->launching
&&
3206 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
3210 icon
->launching
= 1;
3211 dockIconPaint(icon
);
3213 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
3214 wm_instance
, wm_class
, TILE_NORMAL
);
3215 /* XXX: can: aicon->icon == NULL ? */
3216 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
3217 wAppIconMove(aicon
, x0
, y0
);
3218 /* Should this always be lowered? -Dan */
3220 wLowerFrame(aicon
->icon
->core
);
3221 XMapWindow(dpy
, aicon
->icon
->core
->window
);
3222 aicon
->launching
= 1;
3223 wAppIconPaint(aicon
);
3224 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
3225 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
3226 wAppIconDestroy(aicon
);
3228 wDockFinishLaunch(dock
, icon
);
3233 if (firstPass
&& !found
) {
3247 void wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3249 if (!wPreferences
.flags
.noclip
) {
3250 w_global
.clip
.icon
->dock
= w_global
.workspace
.array
[workspace
]->clip
;
3251 if (w_global
.workspace
.current
!= workspace
) {
3252 WDock
*old_clip
= w_global
.workspace
.array
[w_global
.workspace
.current
]->clip
;
3253 WAppIconChain
*chain
= scr
->global_icons
;
3256 wDockMoveIconBetweenDocks(chain
->aicon
->dock
,
3257 w_global
.workspace
.array
[workspace
]->clip
,
3258 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
3259 if (w_global
.workspace
.array
[workspace
]->clip
->collapsed
)
3260 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3261 chain
= chain
->next
;
3264 wDockHideIcons(old_clip
);
3265 if (old_clip
->auto_raise_lower
) {
3266 if (old_clip
->auto_raise_magic
) {
3267 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3268 old_clip
->auto_raise_magic
= NULL
;
3270 wDockLower(old_clip
);
3272 if (old_clip
->auto_collapse
) {
3273 if (old_clip
->auto_expand_magic
) {
3274 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3275 old_clip
->auto_expand_magic
= NULL
;
3277 old_clip
->collapsed
= 1;
3279 wDockShowIcons(w_global
.workspace
.array
[workspace
]->clip
);
3284 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3289 for (i
= 0; i
< dock
->max_icons
; i
++) {
3290 icon
= dock
->icon_array
[i
];
3294 if (icon
->launching
&& icon
->pid
== pid
) {
3295 if (!icon
->relaunching
) {
3297 icon
->main_window
= None
;
3299 wDockFinishLaunch(dock
, icon
);
3301 if (status
== 111) {
3306 if (icon
->drop_launch
)
3307 cmd
= icon
->dnd_command
;
3310 if (icon
->paste_launch
)
3311 cmd
= icon
->paste_command
;
3313 cmd
= icon
->command
;
3315 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3317 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3324 /* This function is called when the dock switches state between
3325 * "normal" (including auto-raise/lower) and "keep on top". It is
3326 * therefore clearly distinct from wDockLower/Raise, which are called
3327 * each time a not-kept-on-top dock is lowered/raised. */
3328 static void toggleLowered(WDock
*dock
)
3334 if (!dock
->lowered
) {
3335 newlevel
= WMNormalLevel
;
3338 newlevel
= WMDockLevel
;
3342 for (i
= 0; i
< dock
->max_icons
; i
++) {
3343 tmp
= dock
->icon_array
[i
];
3347 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3349 /* When the dock is no longer "on top", explicitly lower it as well.
3350 * It saves some CPU cycles (probably) to do it ourselves here
3351 * rather than calling wDockLower at the end of toggleLowered */
3353 wLowerFrame(tmp
->icon
->core
);
3356 if (dock
->type
== WM_DOCK
) {
3357 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
3358 toggleLowered(dc
->adrawer
);
3360 wScreenUpdateUsableArea(dock
->screen_ptr
);
3364 static void toggleCollapsed(WDock
*dock
)
3366 if (dock
->collapsed
) {
3367 dock
->collapsed
= 0;
3368 wDockShowIcons(dock
);
3370 dock
->collapsed
= 1;
3371 wDockHideIcons(dock
);
3375 static void openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3377 WScreen
*scr
= dock
->screen_ptr
;
3378 WObjDescriptor
*desc
;
3380 WApplication
*wapp
= NULL
;
3384 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3386 if (dock
->type
== WM_DOCK
) {
3387 /* Dock position menu */
3388 updateDockPositionMenu(w_global
.dock
.pos_menu
, dock
);
3389 dock
->menu
->flags
.realized
= 0;
3390 if (!wPreferences
.flags
.nodrawer
) {
3392 entry
= dock
->menu
->entries
[++index
];
3393 entry
->clientdata
= aicon
;
3394 wMenuSetEnabled(dock
->menu
, index
, True
);
3397 /* clip/drawer options */
3398 if (w_global
.clip
.opt_menu
)
3399 updateClipOptionsMenu(w_global
.clip
.opt_menu
, dock
);
3401 n_selected
= numberOfSelectedIcons(dock
);
3403 if (dock
->type
== WM_CLIP
) {
3404 /* Rename Workspace */
3405 entry
= dock
->menu
->entries
[++index
];
3406 if (aicon
== w_global
.clip
.icon
) {
3407 entry
->callback
= renameCallback
;
3408 entry
->clientdata
= dock
;
3409 entry
->flags
.indicator
= 0;
3410 entry
->text
= _("Rename Workspace");
3412 entry
->callback
= omnipresentCallback
;
3413 entry
->clientdata
= aicon
;
3414 if (n_selected
> 0) {
3415 entry
->flags
.indicator
= 0;
3416 entry
->text
= _("Toggle Omnipresent");
3418 entry
->flags
.indicator
= 1;
3419 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3420 entry
->flags
.indicator_type
= MI_CHECK
;
3421 entry
->text
= _("Omnipresent");
3426 /* select/unselect icon */
3427 entry
= dock
->menu
->entries
[++index
];
3428 entry
->clientdata
= aicon
;
3429 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3430 wMenuSetEnabled(dock
->menu
, index
, aicon
!= w_global
.clip
.icon
&& !wIsADrawer(aicon
));
3432 /* select/unselect all icons */
3433 entry
= dock
->menu
->entries
[++index
];
3434 entry
->clientdata
= aicon
;
3436 entry
->text
= _("Unselect All Icons");
3438 entry
->text
= _("Select All Icons");
3440 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3443 entry
= dock
->menu
->entries
[++index
];
3444 entry
->clientdata
= aicon
;
3446 entry
->text
= _("Keep Icons");
3448 entry
->text
= _("Keep Icon");
3450 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3452 if (dock
->type
== WM_CLIP
) {
3453 /* this is the workspace submenu part */
3454 entry
= dock
->menu
->entries
[++index
];
3456 entry
->text
= _("Move Icons To");
3458 entry
->text
= _("Move Icon To");
3460 if (w_global
.clip
.submenu
)
3461 updateWorkspaceMenu(w_global
.clip
.submenu
, aicon
);
3463 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3466 /* remove icon(s) */
3467 entry
= dock
->menu
->entries
[++index
];
3468 entry
->clientdata
= aicon
;
3470 entry
->text
= _("Remove Icons");
3472 entry
->text
= _("Remove Icon");
3474 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3476 /* attract icon(s) */
3477 entry
= dock
->menu
->entries
[++index
];
3478 entry
->clientdata
= aicon
;
3480 dock
->menu
->flags
.realized
= 0;
3481 wMenuRealize(dock
->menu
);
3484 if (aicon
->icon
->owner
)
3485 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3490 entry
= dock
->menu
->entries
[++index
];
3491 entry
->clientdata
= aicon
;
3492 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3495 entry
= dock
->menu
->entries
[++index
];
3496 entry
->clientdata
= aicon
;
3497 if (wapp
&& wapp
->flags
.hidden
)
3498 entry
->text
= _("Unhide Here");
3500 entry
->text
= _("Bring Here");
3502 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3505 entry
= dock
->menu
->entries
[++index
];
3506 entry
->clientdata
= aicon
;
3507 if (wapp
&& wapp
->flags
.hidden
)
3508 entry
->text
= _("Unhide");
3510 entry
->text
= _("Hide");
3512 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3515 entry
= dock
->menu
->entries
[++index
];
3516 entry
->clientdata
= aicon
;
3517 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3519 /* kill or remove drawer */
3520 entry
= dock
->menu
->entries
[++index
];
3521 entry
->clientdata
= aicon
;
3522 if (wIsADrawer(aicon
)) {
3523 entry
->callback
= removeDrawerCallback
;
3524 entry
->text
= _("Remove drawer");
3525 wMenuSetEnabled(dock
->menu
, index
, True
);
3527 entry
->callback
= killCallback
;
3528 entry
->text
= _("Kill");
3529 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3532 if (!dock
->menu
->flags
.realized
)
3533 wMenuRealize(dock
->menu
);
3535 if (dock
->type
== WM_CLIP
|| dock
->type
== WM_DRAWER
) {
3536 /*x_pos = event->xbutton.x_root+2; */
3537 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3540 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3541 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3544 x_pos
= dock
->on_right_side
? scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3547 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3549 /* allow drag select */
3550 event
->xany
.send_event
= True
;
3551 desc
= &dock
->menu
->menu
->descriptor
;
3552 (*desc
->handle_mousedown
) (desc
, event
);
3555 /******************************************************************/
3556 static void iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3558 WAppIcon
*btn
= desc
->parent
;
3559 WDock
*dock
= btn
->dock
;
3560 WApplication
*wapp
= NULL
;
3563 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3564 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3566 assert(wapp
!= NULL
);
3568 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3570 /* go to the last workspace that the user worked on the app */
3571 if (wapp
->last_workspace
!= w_global
.workspace
.current
&& !unhideHere
)
3572 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3574 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3576 if (event
->xbutton
.state
& MOD_MASK
)
3577 wHideOtherApplications(btn
->icon
->owner
);
3579 if (event
->xbutton
.button
== Button1
) {
3580 if (event
->xbutton
.state
& MOD_MASK
) {
3581 /* raise/lower dock */
3582 toggleLowered(dock
);
3583 } else if (btn
== w_global
.clip
.icon
) {
3584 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
)
3585 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3586 else if (wPreferences
.flags
.clip_merged_in_dock
) {
3587 // Is actually the dock
3590 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3591 launchDockedApplication(btn
, False
);
3595 wShowInfoPanel(dock
->screen_ptr
);
3599 toggleCollapsed(dock
);
3600 } else if (wIsADrawer(btn
)) {
3601 toggleCollapsed(dock
);
3602 } else if (btn
->command
) {
3603 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3604 launchDockedApplication(btn
, False
);
3605 } else if (btn
->xindex
== 0 && btn
->yindex
== 0 && btn
->dock
->type
== WM_DOCK
) {
3606 wShowInfoPanel(dock
->screen_ptr
);
3612 static void handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3614 WScreen
*scr
= dock
->screen_ptr
;
3615 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3616 WIcon
*icon
= aicon
->icon
;
3619 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;;
3620 int shad_x
= x
, shad_y
= y
;
3622 int grabbed
= 0, done
, previously_on_right
, now_on_right
, previous_x_pos
, i
;
3623 Pixmap ghost
= None
;
3624 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3626 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3627 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3628 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
)
3629 wwarning("pointer grab failed for dock move");
3631 if (dock
->type
== WM_DRAWER
) {
3633 wins
[0] = icon
->core
->window
;
3634 wins
[1] = scr
->dock_shadow
;
3635 XRestackWindows(dpy
, wins
, 2);
3636 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3637 ICON_SIZE
, ICON_SIZE
);
3639 if (icon
->pixmap
!=None
)
3640 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3642 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3644 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3645 XClearWindow(dpy
, scr
->dock_shadow
);
3647 XMapWindow(dpy
, scr
->dock_shadow
);
3650 previously_on_right
= now_on_right
= dock
->on_right_side
;
3651 previous_x_pos
= dock
->x_pos
;
3654 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3655 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3662 /* It means the cursor moved so fast that it entered
3663 * something else (if moving slowly, it would have
3664 * stayed in the dock that is being moved. Ignore such
3665 * "spurious" EnterNotifiy's */
3670 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3671 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3672 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3673 | ButtonReleaseMask
| ButtonPressMask
,
3674 wPreferences
.cursor
[WCUR_MOVE
], CurrentTime
);
3679 switch (dock
->type
) {
3681 x
= ev
.xmotion
.x_root
- ofs_x
;
3682 y
= ev
.xmotion
.y_root
- ofs_y
;
3683 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3684 moveDock(dock
, x
, y
);
3687 x
= ev
.xmotion
.x_root
- ofs_x
;
3688 y
= ev
.xmotion
.y_root
- ofs_y
;
3689 if (previously_on_right
)
3691 now_on_right
= (ev
.xmotion
.x_root
>= previous_x_pos
- ICON_SIZE
);
3695 now_on_right
= (ev
.xmotion
.x_root
> previous_x_pos
+ ICON_SIZE
* 2);
3697 if (now_on_right
!= dock
->on_right_side
)
3699 dock
->on_right_side
= now_on_right
;
3701 wArrangeIcons(scr
, False
);
3703 // Also perform the vertical move
3704 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3705 moveDock(dock
, dock
->x_pos
, y
);
3706 if (wPreferences
.flags
.wrap_appicons_in_dock
)
3708 for (i
= 0; i
< dock
->max_icons
; i
++) {
3709 int new_y
, new_index
, j
, ok
;
3710 if ((tmpaicon
= dock
->icon_array
[i
]) == NULL
)
3712 if (onScreen(scr
, tmpaicon
->x_pos
, tmpaicon
->y_pos
))
3714 new_y
= (tmpaicon
->y_pos
+ ICON_SIZE
* dock
->max_icons
) % (ICON_SIZE
* dock
->max_icons
);
3715 new_index
= (new_y
- dock
->y_pos
) / ICON_SIZE
;
3716 if (!onScreen(scr
, tmpaicon
->x_pos
, new_y
))
3719 for (j
= 0; j
< dock
->max_icons
; j
++)
3721 if (dock
->icon_array
[j
] != NULL
&&
3722 dock
->icon_array
[j
]->yindex
== new_index
)
3728 if (!ok
|| getDrawer(scr
, new_index
) != NULL
)
3730 wDockReattachIcon(dock
, tmpaicon
, tmpaicon
->xindex
, new_index
);
3732 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3734 int new_y
, new_index
, j
, ok
;
3735 tmpaicon
= dc
->adrawer
->icon_array
[0];
3736 if (onScreen(scr
, tmpaicon
->x_pos
, tmpaicon
->y_pos
))
3738 new_y
= (tmpaicon
->y_pos
+ ICON_SIZE
* dock
->max_icons
) % (ICON_SIZE
* dock
->max_icons
);
3739 new_index
= (new_y
- dock
->y_pos
) / ICON_SIZE
;
3740 if (!onScreen(scr
, tmpaicon
->x_pos
, new_y
))
3743 for (j
= 0; j
< dock
->max_icons
; j
++)
3745 if (dock
->icon_array
[j
] != NULL
&&
3746 dock
->icon_array
[j
]->yindex
== new_index
)
3752 if (!ok
|| getDrawer(scr
, new_index
) != NULL
)
3754 moveDock(dc
->adrawer
, tmpaicon
->x_pos
, new_y
);
3760 WDock
*real_dock
= dock
->screen_ptr
->dock
;
3763 x
= ev
.xmotion
.x_root
- ofs_x
;
3764 y
= ev
.xmotion
.y_root
- ofs_y
;
3765 snapped
= wDockSnapIcon(real_dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3767 shad_x
= real_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3768 shad_y
= real_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3769 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3771 moveDock(dock
, x
, y
);
3781 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3783 XUngrabPointer(dpy
, CurrentTime
);
3784 if (dock
->type
== WM_DRAWER
) {
3785 Window
*wins
[dock
->icon_count
];
3787 for (i
= 0; i
< dock
->max_icons
; i
++) {
3788 if ((tmpaicon
= dock
->icon_array
[i
]) == NULL
)
3790 wins
[ tmpaicon
->xindex
+ (dock
->on_right_side
? dock
->icon_count
- 1 : 0) ] = &tmpaicon
->icon
->core
->window
;
3792 SlideWindows(wins
, dock
->icon_count
,
3793 (dock
->on_right_side
? x
- (dock
->icon_count
- 1) * ICON_SIZE
: x
),
3795 (dock
->on_right_side
? shad_x
- (dock
->icon_count
- 1) * ICON_SIZE
: shad_x
),
3797 XUnmapWindow(dpy
, scr
->dock_shadow
);
3798 moveDock(dock
, shad_x
, shad_y
);
3799 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3807 XFreePixmap(dpy
, ghost
);
3808 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3813 static int getClipButton(int px
, int py
)
3815 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3817 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3820 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3821 return CLIP_FORWARD
;
3822 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3828 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3831 int done
, direction
, new_ws
;
3833 WDock
*clip
= w_global
.clip
.icon
->dock
;
3835 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3837 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3838 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3843 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3850 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3851 if (new_dir
!= direction
) {
3852 direction
= new_dir
;
3853 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3854 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3863 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3868 clip
->lclip_button_pushed
= 0;
3869 clip
->rclip_button_pushed
= 0;
3871 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3873 if (direction
== CLIP_FORWARD
) {
3874 if (w_global
.workspace
.current
< w_global
.workspace
.count
- 1)
3875 wWorkspaceChange(scr
, w_global
.workspace
.current
+ 1);
3876 else if (new_ws
&& w_global
.workspace
.current
< MAX_WORKSPACES
- 1)
3877 wWorkspaceChange(scr
, w_global
.workspace
.current
+ 1);
3878 else if (wPreferences
.ws_cycle
)
3879 wWorkspaceChange(scr
, 0);
3880 } else if (direction
== CLIP_REWIND
) {
3881 if (w_global
.workspace
.current
> 0)
3882 wWorkspaceChange(scr
, w_global
.workspace
.current
- 1);
3883 else if (w_global
.workspace
.current
== 0 && wPreferences
.ws_cycle
)
3884 wWorkspaceChange(scr
, w_global
.workspace
.count
- 1);
3890 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3892 WAppIcon
*aicon
= desc
->parent
;
3893 WDock
*dock
= aicon
->dock
;
3894 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3896 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3899 scr
->last_dock
= dock
;
3901 if (dock
->menu
->flags
.mapped
)
3902 wMenuUnmap(dock
->menu
);
3904 if (IsDoubleClick(scr
, event
)) {
3905 /* double-click was not in the main clip icon */
3906 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3907 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3908 iconDblClick(desc
, event
);
3913 if (event
->xbutton
.button
== Button1
) {
3914 if (event
->xbutton
.state
& MOD_MASK
)
3919 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= w_global
.clip
.icon
&& dock
->type
!= WM_DOCK
) {
3920 wIconSelect(aicon
->icon
);
3924 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3925 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
&&
3926 (dock
->type
== WM_CLIP
|| (dock
->type
== WM_DOCK
&& wPreferences
.flags
.clip_merged_in_dock
)))
3927 handleClipChangeWorkspace(scr
, event
);
3929 handleDockMove(dock
, aicon
, event
);
3931 Bool hasMoved
= wHandleAppIconMove(aicon
, event
);
3932 if (wPreferences
.single_click
&& !hasMoved
)
3933 iconDblClick(desc
, event
);
3935 } else if (event
->xbutton
.button
== Button2
&& aicon
== w_global
.clip
.icon
) {
3936 if (!w_global
.clip
.ws_menu
)
3937 w_global
.clip
.ws_menu
= wWorkspaceMenuMake(scr
, False
);
3939 if (w_global
.clip
.ws_menu
) {
3940 WMenu
*wsMenu
= w_global
.clip
.ws_menu
;
3943 wWorkspaceMenuUpdate(wsMenu
);
3945 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
3948 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
3949 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
3951 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
3953 desc
= &wsMenu
->menu
->descriptor
;
3954 event
->xany
.send_event
= True
;
3955 (*desc
->handle_mousedown
) (desc
, event
);
3957 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
3958 (event
->xbutton
.state
& ShiftMask
) && aicon
!= w_global
.clip
.icon
) {
3959 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3960 } else if (event
->xbutton
.button
== Button3
) {
3961 if (event
->xbutton
.send_event
&&
3962 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3963 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3964 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3965 wwarning("pointer grab failed for dockicon menu");
3969 openDockMenu(dock
, aicon
, event
);
3970 } else if (event
->xbutton
.button
== Button2
) {
3971 WAppIcon
*btn
= desc
->parent
;
3973 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3974 launchDockedApplication(btn
, True
);
3978 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3980 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3984 assert(event
->type
== EnterNotify
);
3986 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3989 scr
= btn
->icon
->core
->screen_ptr
;
3995 /* The auto raise/lower code */
3996 tmp
= (dock
->type
== WM_DRAWER
? scr
->dock
: dock
);
3997 if (tmp
->auto_lower_magic
) {
3998 WMDeleteTimerHandler(tmp
->auto_lower_magic
);
3999 tmp
->auto_lower_magic
= NULL
;
4001 if (tmp
->auto_raise_lower
&& !tmp
->auto_raise_magic
)
4002 tmp
->auto_raise_magic
= WMAddTimerHandler(wPreferences
.clip_auto_raise_delay
, clipAutoRaise
, (void *) tmp
);
4004 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4007 /* The auto expand/collapse code */
4008 if (dock
->auto_collapse_magic
) {
4009 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
4010 dock
->auto_collapse_magic
= NULL
;
4012 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
)
4013 dock
->auto_expand_magic
= WMAddTimerHandler(wPreferences
.clip_auto_expand_delay
, clipAutoExpand
, (void *)dock
);
4016 static void clipLeave(WDock
*dock
)
4019 WObjDescriptor
*desc
= NULL
;
4025 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
4026 if (XFindContext(dpy
, event
.xcrossing
.window
, w_global
.context
.client_win
,
4027 (XPointer
*) & desc
) != XCNOENT
4028 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
4029 && ((WAppIcon
*) desc
->parent
)->dock
== dock
) {
4030 /* We haven't left the dock/clip/drawer yet */
4031 XPutBackEvent(dpy
, &event
);
4035 XPutBackEvent(dpy
, &event
);
4037 /* We entered a withdrawn window, so we're still in Clip */
4041 tmp
= (dock
->type
== WM_DRAWER
? dock
->screen_ptr
->dock
: dock
);
4042 if (tmp
->auto_raise_magic
) {
4043 WMDeleteTimerHandler(tmp
->auto_raise_magic
);
4044 tmp
->auto_raise_magic
= NULL
;
4046 if (tmp
->auto_raise_lower
&& !tmp
->auto_lower_magic
)
4047 tmp
->auto_lower_magic
= WMAddTimerHandler(wPreferences
.clip_auto_lower_delay
, clipAutoLower
, (void *)tmp
);
4049 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4052 if (dock
->auto_expand_magic
) {
4053 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4054 dock
->auto_expand_magic
= NULL
;
4056 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
)
4057 dock
->auto_collapse_magic
= WMAddTimerHandler(wPreferences
.clip_auto_collapse_delay
, clipAutoCollapse
, (void *)dock
);
4060 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4062 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
4064 assert(event
->type
== LeaveNotify
);
4066 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
4069 clipLeave(btn
->dock
);
4072 static void clipAutoCollapse(void *cdata
)
4074 WDock
*dock
= (WDock
*) cdata
;
4076 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4079 if (dock
->auto_collapse
) {
4080 dock
->collapsed
= 1;
4081 wDockHideIcons(dock
);
4083 dock
->auto_collapse_magic
= NULL
;
4086 static void clipAutoExpand(void *cdata
)
4088 WDock
*dock
= (WDock
*) cdata
;
4090 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4093 if (dock
->auto_collapse
) {
4094 dock
->collapsed
= 0;
4095 wDockShowIcons(dock
);
4097 dock
->auto_expand_magic
= NULL
;
4100 static void clipAutoLower(void *cdata
)
4102 WDock
*dock
= (WDock
*) cdata
;
4104 if (dock
->auto_raise_lower
)
4107 dock
->auto_lower_magic
= NULL
;
4110 static void clipAutoRaise(void *cdata
)
4112 WDock
*dock
= (WDock
*) cdata
;
4114 if (dock
->auto_raise_lower
)
4117 dock
->auto_raise_magic
= NULL
;
4120 static Bool
iconCanBeOmnipresent(WAppIcon
*aicon
)
4122 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4127 for (i
= 0; i
< w_global
.workspace
.count
; i
++) {
4128 clip
= w_global
.workspace
.array
[i
]->clip
;
4130 if (clip
== aicon
->dock
)
4133 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4134 return False
; /* Clip is full in some workspace */
4136 for (j
= 0; j
< clip
->max_icons
; j
++) {
4137 btn
= clip
->icon_array
[j
];
4138 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
4146 int wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
4148 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4149 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4150 int status
= WO_SUCCESS
;
4152 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== w_global
.clip
.icon
)
4153 return WO_NOT_APPLICABLE
;
4155 if (aicon
->omnipresent
== omnipresent
)
4159 if (iconCanBeOmnipresent(aicon
)) {
4160 aicon
->omnipresent
= 1;
4161 new_entry
= wmalloc(sizeof(WAppIconChain
));
4162 new_entry
->aicon
= aicon
;
4163 new_entry
->next
= scr
->global_icons
;
4164 scr
->global_icons
= new_entry
;
4165 scr
->global_icon_count
++;
4167 aicon
->omnipresent
= 0;
4171 aicon
->omnipresent
= 0;
4172 if (aicon
== scr
->global_icons
->aicon
) {
4173 tmp
= scr
->global_icons
->next
;
4174 wfree(scr
->global_icons
);
4175 scr
->global_icons
= tmp
;
4176 scr
->global_icon_count
--;
4178 tmp
= scr
->global_icons
;
4180 if (tmp
->next
->aicon
== aicon
) {
4181 tmp1
= tmp
->next
->next
;
4184 scr
->global_icon_count
--;
4192 wAppIconPaint(aicon
);
4197 static void drawerAppendToChain(WScreen
*scr
, WDock
*drawer
)
4199 WDrawerChain
**where_to_add
;
4201 where_to_add
= &scr
->drawers
;
4202 while ((*where_to_add
) != NULL
) {
4203 where_to_add
= &(*where_to_add
)->next
;
4206 *where_to_add
= wmalloc(sizeof(WDrawerChain
));
4207 (*where_to_add
)->adrawer
= drawer
;
4208 (*where_to_add
)->next
= NULL
;
4209 scr
->drawer_count
++;
4213 static void drawerRemoveFromChain(WScreen
*scr
, WDock
*drawer
)
4215 WDrawerChain
*next
, **to_remove
;
4217 to_remove
= &scr
->drawers
;
4219 if (*to_remove
== NULL
) {
4220 wwarning("The drawer to be removed can not be found.");
4223 if ((*to_remove
)->adrawer
== drawer
)
4226 to_remove
= &(*to_remove
)->next
;
4228 next
= (*to_remove
)->next
;
4231 scr
->drawer_count
--;
4235 /* Don't free the returned string. Duplicate it. */
4236 static char * findUniqueName(WScreen
*scr
, const char *instance_basename
)
4238 static char buffer
[128];
4241 Bool already_in_use
= True
;
4243 #define UNIQUE_NAME_WATCHDOG 128
4244 for (i
= 0; already_in_use
&& i
< UNIQUE_NAME_WATCHDOG
; i
++) {
4245 snprintf(buffer
, sizeof buffer
, "%s%d", instance_basename
, i
);
4247 already_in_use
= False
;
4249 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4250 if (!strncmp(dc
->adrawer
->icon_array
[0]->wm_instance
, buffer
,
4252 already_in_use
= True
;
4258 if (i
== UNIQUE_NAME_WATCHDOG
)
4259 wwarning("Couldn't find a unique name for drawer in %d attempts.", i
);
4260 #undef UNIQUE_NAME_WATCHDOG
4266 static void drawerIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
4268 wDrawerIconPaint((WAppIcon
*) desc
->parent
);
4272 static int addADrawer(WScreen
*scr
)
4274 int i
, y
, sig
, found_y
;
4275 WDock
*drawer
, *dock
= scr
->dock
;
4277 char can_be_here
[2 * dock
->max_icons
- 1];
4279 if (dock
->icon_count
+ scr
->drawer_count
>= dock
->max_icons
)
4282 for (y
= -dock
->max_icons
+ 1; y
< dock
->max_icons
; y
++) {
4283 can_be_here
[y
+ dock
->max_icons
- 1] = True
;
4285 for (i
= 0; i
< dock
->max_icons
; i
++) {
4286 if (dock
->icon_array
[i
] != NULL
)
4287 can_be_here
[dock
->icon_array
[i
]->yindex
+ dock
->max_icons
- 1] = False
;
4289 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4290 y
= (int) ((dc
->adrawer
->y_pos
- dock
->y_pos
) / ICON_SIZE
);
4291 can_be_here
[y
+ dock
->max_icons
- 1] = False
;
4295 for (sig
= 1; !found_y
&& sig
> -2; sig
-= 2) // 1, then -1
4297 for (y
= sig
; sig
* y
< dock
->max_icons
; y
+= sig
)
4299 if (can_be_here
[y
+ dock
->max_icons
- 1] &&
4300 onScreen(scr
, dock
->x_pos
, dock
->y_pos
+ y
* ICON_SIZE
))
4309 /* This can happen even when dock->icon_count + scr->drawer_count
4310 * < dock->max_icons when the dock is not aligned on an
4311 * ICON_SIZE multiple, as some space is lost above and under it */
4314 drawer
= wDockCreate(scr
, WM_DRAWER
, NULL
);
4315 drawer
->lowered
= scr
->dock
->lowered
;
4316 if (!drawer
->lowered
)
4317 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMDockLevel
);
4319 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMNormalLevel
);
4320 drawer
->auto_raise_lower
= scr
->dock
->auto_raise_lower
;
4321 drawer
->x_pos
= dock
->x_pos
;
4322 drawer
->y_pos
= dock
->y_pos
+ ICON_SIZE
* y
;
4323 drawer
->icon_array
[0]->xindex
= 0;
4324 drawer
->icon_array
[0]->yindex
= 0;
4325 drawer
->icon_array
[0]->x_pos
= drawer
->x_pos
;
4326 drawer
->icon_array
[0]->y_pos
= drawer
->y_pos
;
4327 XMoveWindow(dpy
, drawer
->icon_array
[0]->icon
->core
->window
,
4328 drawer
->icon_array
[0]->x_pos
, drawer
->icon_array
[0]->y_pos
);
4334 static void addADrawerCallback(WMenu
*menu
, WMenuEntry
*entry
)
4336 assert(entry
->clientdata
!=NULL
);
4337 addADrawer(((WAppIcon
*) entry
->clientdata
)->dock
->screen_ptr
);
4341 static void drawerDestroy(WDock
*drawer
)
4345 WAppIcon
*aicon
= NULL
;
4351 scr
= drawer
->screen_ptr
;
4353 /* Note regarding menus: we can't delete any dock/clip/drawer menu, because
4354 * that would (attempt to) wfree some memory in gettext library (see menu
4355 * entries that have several "versions", such like "Hide" and "Unhide"). */
4356 wDefaultPurgeInfo(scr
, drawer
->icon_array
[0]->wm_instance
,
4357 drawer
->icon_array
[0]->wm_class
);
4359 if (drawer
->icon_count
== 2) {
4360 /* Drawer contains a single appicon: dock it where the drawer was */
4361 for (i
= 1; i
< drawer
->max_icons
; i
++) {
4362 if ((aicon
= drawer
->icon_array
[i
]))
4366 wDockMoveIconBetweenDocks(drawer
, scr
->dock
, aicon
,
4367 0, (drawer
->y_pos
- scr
->dock
->y_pos
) / ICON_SIZE
);
4368 XMoveWindow(dpy
, aicon
->icon
->core
->window
, drawer
->x_pos
, drawer
->y_pos
);
4369 XMapWindow(dpy
, aicon
->icon
->core
->window
);
4370 } else if (drawer
->icon_count
> 2) {
4371 icons
= WMCreateArray(drawer
->icon_count
- 1);
4372 for (i
= 1; i
< drawer
->max_icons
; i
++) {
4373 if (!(aicon
= drawer
->icon_array
[i
]))
4375 WMAddToArray(icons
, aicon
);
4377 removeIcons(icons
, drawer
);
4380 if (drawer
->auto_collapse_magic
) {
4381 WMDeleteTimerHandler(drawer
->auto_collapse_magic
);
4382 drawer
->auto_collapse_magic
= NULL
;
4384 if (drawer
->auto_lower_magic
) {
4385 WMDeleteTimerHandler(drawer
->auto_lower_magic
);
4386 drawer
->auto_lower_magic
= NULL
;
4389 wAppIconDestroy(drawer
->icon_array
[0]);
4390 wfree(drawer
->icon_array
);
4393 drawerRemoveFromChain(scr
, drawer
);
4394 if (scr
->last_dock
== drawer
)
4395 scr
->last_dock
= NULL
;
4396 if (scr
->attracting_drawer
== drawer
)
4397 scr
->attracting_drawer
= NULL
;
4401 static void removeDrawerCallback(WMenu
*menu
, WMenuEntry
*entry
)
4403 WDock
*dock
= ((WAppIcon
*)entry
->clientdata
)->dock
;
4404 assert(dock
!= NULL
);
4406 if (dock
->icon_count
> 2) {
4407 if (wMessageDialog(dock
->screen_ptr
, _("Drawer"),
4408 _("All icons in this drawer will be detached!"),
4409 _("OK"), _("Cancel"), NULL
) != WAPRDefault
)
4412 drawerDestroy(dock
);
4416 void wDrawerIconPaint(WAppIcon
*dicon
)
4418 Window win
= dicon
->icon
->core
->window
;
4419 WScreen
*scr
= dicon
->icon
->core
->screen_ptr
;
4421 GC gc
= scr
->draw_gc
;
4424 wIconPaint(dicon
->icon
);
4426 if (!dicon
->dock
->collapsed
)
4427 color
= scr
->clip_title_color
[CLIP_NORMAL
];
4429 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
4430 XSetForeground(dpy
, gc
, WMColorPixel(color
));
4432 if (dicon
->dock
->on_right_side
) {
4433 p
[0].x
= p
[3].x
= 10;
4434 p
[0].y
= p
[3].y
= ICON_SIZE
/ 2 - 5;
4436 p
[1].y
= ICON_SIZE
/ 2 + 5;
4438 p
[2].y
= ICON_SIZE
/ 2;
4441 p
[0].x
= p
[3].x
= ICON_SIZE
-1 - 10;
4442 p
[0].y
= p
[3].y
= ICON_SIZE
/ 2 - 5;
4443 p
[1].x
= ICON_SIZE
-1 - 10;
4444 p
[1].y
= ICON_SIZE
/ 2 + 5;
4445 p
[2].x
= ICON_SIZE
-1 - 5;
4446 p
[2].y
= ICON_SIZE
/ 2;
4448 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
4449 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
4453 RImage
* wDrawerMakeTile(WScreen
*scr
, RImage
*normalTile
)
4455 RImage
*tile
= RCloneImage(normalTile
);
4460 dark
.red
= dark
.green
= dark
.blue
= 60;
4463 light
.red
= light
.green
= light
.blue
= 80;
4466 if (!scr
->dock
|| scr
->dock
->on_right_side
) {
4467 ROperateLine(tile
, RSubtractOperation
, 11, ICON_SIZE
/ 2 - 7,
4468 4, ICON_SIZE
/ 2, &dark
); /* / */
4469 ROperateLine(tile
, RSubtractOperation
, 11, ICON_SIZE
/ 2 + 7,
4470 4, ICON_SIZE
/ 2, &dark
); /* \ */
4471 ROperateLine(tile
, RAddOperation
, 11, ICON_SIZE
/ 2 - 7,
4472 11, ICON_SIZE
/ 2 + 7, &light
); /* | */
4475 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 - 7,
4476 ICON_SIZE
-1 - 4, ICON_SIZE
/ 2, &dark
); /* \ */
4477 ROperateLine(tile
, RAddOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 + 7,
4478 ICON_SIZE
-1 - 4, ICON_SIZE
/ 2, &light
); /* / */
4479 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 - 7,
4480 ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 + 7, &dark
); /* | */
4486 static void swapDrawer(WDock
*drawer
, int new_x
)
4490 drawer
->on_right_side
= !drawer
->on_right_side
;
4491 drawer
->x_pos
= new_x
;
4493 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4495 if ((ai
= drawer
->icon_array
[i
]) == NULL
)
4497 ai
->xindex
*= -1; /* so A B C becomes C B A */
4498 ai
->x_pos
= new_x
+ ai
->xindex
* ICON_SIZE
;
4500 /* Update drawer's tile */
4502 wIconUpdate(ai
->icon
);
4503 wDrawerIconPaint(ai
);
4505 XMoveWindow(dpy
, ai
->icon
->core
->window
, ai
->x_pos
, ai
->y_pos
);
4510 static void swapDrawers(WScreen
*scr
, int on_right_side
, int new_x
)
4514 if (scr
->drawer_tile
) {
4515 RReleaseImage(scr
->drawer_tile
);
4517 scr
->drawer_tile
= wDrawerMakeTile(scr
, scr
->icon_tile
);
4519 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4520 swapDrawer(dc
->adrawer
, new_x
);
4521 assert(dc
->adrawer
->on_right_side
== on_right_side
);
4526 int wIsADrawer(WAppIcon
*aicon
)
4528 return aicon
&& aicon
->dock
&&
4529 aicon
->dock
->type
== WM_DRAWER
&& aicon
->dock
->icon_array
[0] == aicon
;
4533 static WDock
* getDrawer(WScreen
*scr
, int y_index
)
4537 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4538 if (dc
->adrawer
->y_pos
- scr
->dock
->y_pos
== y_index
* ICON_SIZE
)
4546 /* Find the "hole" a moving appicon created when snapped into the
4547 * drawer. redocking is a boolean. If the moving appicon comes from the
4548 * drawer, drawer->icon_count is correct. If not, redocking is then false and
4549 * there are now drawer->icon_count plus one appicons in the drawer. */
4550 static int indexOfHole(WDock
*drawer
, WAppIcon
*moving_aicon
, int redocking
)
4552 int index_of_hole
, i
;
4554 /* Classic interview question...
4556 * We have n-1 (n = drawer->icon_count-1 or drawer->icon_count, see
4557 * redocking) appicons, whose xindex are unique in [1..n]. One is missing:
4558 * that's where the ghost of the moving appicon is, that's what the
4559 * function should return.
4561 * We compute 1+2+...+n (this sum is equal to n*(n+1)/2), we substract to
4562 * this sum the xindex of each of the n-1 appicons, and we get the correct
4566 index_of_hole
= (drawer
->icon_count
- 1) * drawer
->icon_count
/ 2;
4568 index_of_hole
= drawer
->icon_count
* (drawer
->icon_count
+ 1) / 2;
4570 index_of_hole
*= (drawer
->on_right_side
? -1 : 1);
4572 for (i
= 1; i
< drawer
->max_icons
; i
++) {
4573 if (drawer
->icon_array
[i
] && drawer
->icon_array
[i
] != moving_aicon
)
4574 index_of_hole
-= drawer
->icon_array
[i
]->xindex
;
4576 /* wmessage(" Index of the moving appicon is %d (%sredocking)", index_of_hole, (redocking ? "" : "not ")); */
4577 if (abs(index_of_hole
) > abs(drawer
->icon_count
) - (redocking
? 1 : 0))
4578 wwarning(" index_of_hole is too large ! (%d greater than %d)",
4579 index_of_hole
, abs(drawer
->icon_count
) - (redocking
? 1 : 0));
4580 if (index_of_hole
== 0)
4581 wwarning(" index_of_hole == 0 (%sredocking, icon_count == %d)", (redocking
? "" : "not "), drawer
->icon_count
);
4583 return index_of_hole
;
4587 void wSlideAppicons(WAppIcon
**appicons
, int n
, int to_the_left
)
4590 int leftmost
= -1, min_index
= 9999, from_x
= -1; // leftmost and from_x initialized to avoid warning
4597 for (i
= 0; i
< n
; i
++) {
4598 aicon
= appicons
[i
];
4599 aicon
->xindex
+= (to_the_left
? -1 : +1);
4600 if (aicon
->xindex
< min_index
) {
4601 min_index
= aicon
->xindex
;
4603 from_x
= aicon
->x_pos
;
4605 aicon
->x_pos
+= (to_the_left
? -ICON_SIZE
: +ICON_SIZE
);
4608 for (i
= 0; i
< n
; i
++) {
4609 aicon
= appicons
[i
];
4610 wins
[aicon
->xindex
- min_index
] = &aicon
->icon
->core
->window
;
4612 aicon
= appicons
[leftmost
];
4613 SlideWindows(wins
, n
, from_x
, aicon
->y_pos
, aicon
->x_pos
, aicon
->y_pos
);
4617 void wDrawerFillTheGap(WDock
*drawer
, WAppIcon
*aicon
, Bool redocking
)
4620 int index_of_hole
= indexOfHole(drawer
, aicon
, redocking
);
4621 WAppIcon
*aicons_to_shift
[drawer
->icon_count
];
4624 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4625 WAppIcon
*ai
= drawer
->icon_array
[i
];
4626 if (ai
&& ai
!= aicon
&&
4627 abs(ai
->xindex
) > abs(index_of_hole
))
4628 aicons_to_shift
[j
++] = ai
;
4630 if (j
!= drawer
->icon_count
- abs(index_of_hole
) - (redocking
? 1 : 0))
4631 wwarning("Removing aicon at index %d from %s: j=%d but should be %d",
4632 index_of_hole
, drawer
->icon_array
[0]->wm_instance
,
4633 j
, drawer
->icon_count
- abs(index_of_hole
) - (redocking
? 1 : 0));
4634 wSlideAppicons(aicons_to_shift
, j
, !drawer
->on_right_side
);
4638 static void drawerConsolidateIcons(WDock
*drawer
)
4640 WAppIcon
*aicons_to_shift
[drawer
->icon_count
];
4641 int maxRemaining
= 0;
4644 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4645 WAppIcon
*ai
= drawer
->icon_array
[i
];
4648 sum
+= abs(ai
->xindex
);
4649 if (abs(ai
->xindex
) > maxRemaining
)
4650 maxRemaining
= abs(ai
->xindex
);
4652 while (sum
!= maxRemaining
* (maxRemaining
+ 1) / 2) { // while there is a hole
4655 // Look up for the hole at max position
4657 for (maxDeleted
= maxRemaining
- 1; maxDeleted
> 0; maxDeleted
--) {
4658 Bool foundAppIconThere
= False
;
4659 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4660 WAppIcon
*ai
= drawer
->icon_array
[i
];
4663 if (abs(ai
->xindex
) == maxDeleted
) {
4664 foundAppIconThere
= True
;
4668 if (!foundAppIconThere
)
4671 assert(maxDeleted
> 0); // would mean while test is wrong
4673 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4674 ai
= drawer
->icon_array
[i
];
4675 if (ai
!= NULL
&& abs(ai
->xindex
) > maxDeleted
)
4676 aicons_to_shift
[n
++] = ai
;
4678 assert(n
== maxRemaining
- maxDeleted
); // for the code review ;-)
4679 wSlideAppicons(aicons_to_shift
, n
, !drawer
->on_right_side
);
4680 // Efficient beancounting
4688 /* similar to wDockRestoreState, but a lot a specific stuff too... */
4689 static WDock
* drawerRestoreState(WScreen
*scr
, WMPropList
*drawer_state
)
4692 WMPropList
*apps
, *value
, *dock_state
;
4701 WMRetainPropList(drawer_state
);
4703 /* Get the instance name, and create a drawer */
4704 value
= WMGetFromPLDictionary(drawer_state
, dName
);
4705 drawer
= wDockCreate(scr
, WM_DRAWER
, WMGetFromPLString(value
));
4707 /* restore DnD command and paste command */
4709 value
= WMGetFromPLDictionary(drawer_state
, dDropCommand
);
4710 if (value
&& WMIsPLString(value
))
4711 drawer
->icon_array
[0]->dnd_command
= wstrdup(WMGetFromPLString(value
));
4714 value
= WMGetFromPLDictionary(drawer_state
, dPasteCommand
);
4715 if (value
&& WMIsPLString(value
))
4716 drawer
->icon_array
[0]->paste_command
= wstrdup(WMGetFromPLString(value
));
4718 /* restore position */
4719 value
= WMGetFromPLDictionary(drawer_state
, dPosition
);
4720 if (!value
|| !WMIsPLString(value
))
4721 COMPLAIN("Position");
4724 if (sscanf(WMGetFromPLString(value
), "%i,%i", &x
, &y
) != 2)
4725 COMPLAIN("Position");
4727 /* check position sanity */
4728 if (x
!= scr
->dock
->x_pos
) {
4729 x
= scr
->dock
->x_pos
;
4731 y_index
= (y
- scr
->dock
->y_pos
) / ICON_SIZE
;
4732 if (y_index
>= scr
->dock
->max_icons
) {
4733 /* Here we should do something more intelligent, since it
4734 * can happen even if the user hasn't hand-edited his
4735 * G/D/State file (but uses a lower resolution). */
4736 y_index
= scr
->dock
->max_icons
- 1;
4738 y
= scr
->dock
->y_pos
+ y_index
* ICON_SIZE
;
4739 moveDock(drawer
, x
, y
);
4742 /* restore dock properties (applist and others) */
4743 dock_state
= WMGetFromPLDictionary(drawer_state
, dDock
);
4745 /* restore lowered/raised state: same as scr->dock, no matter what */
4746 drawer
->lowered
= scr
->dock
->lowered
;
4747 if (!drawer
->lowered
)
4748 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMDockLevel
);
4750 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMNormalLevel
);
4751 wRaiseFrame(drawer
->icon_array
[0]->icon
->core
);
4753 /* restore collapsed state */
4754 drawer
->collapsed
= 0;
4755 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
4756 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4757 drawer
->collapsed
= 1;
4759 /* restore auto-collapsed state */
4760 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
4761 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4762 drawer
->auto_collapse
= 1;
4763 drawer
->collapsed
= 1;
4765 drawer
->auto_collapse
= 0; // because wDockCreate sets it (drawers only)
4768 /* restore auto-raise/lower state: same as scr->dock, no matter what */
4769 drawer
->auto_raise_lower
= scr
->dock
->auto_raise_lower
;
4771 /* restore attract icons state */
4772 drawer
->attract_icons
= 0;
4773 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
4774 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4775 drawer
->attract_icons
= 1;
4776 scr
->attracting_drawer
= drawer
;
4779 /* application list */
4780 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
4786 count
= WMGetPropListItemCount(apps
);
4791 for (i
=0; i
<count
; i
++) {
4792 if (drawer
->icon_count
>= drawer
->max_icons
) {
4793 wwarning(_("there are too many icons stored in drawer. Ignoring what doesn't fit"));
4797 value
= WMGetFromPLArray(apps
, i
);
4798 aicon
= restore_icon_state(scr
, value
, WM_DRAWER
, drawer
->icon_count
);
4800 drawer
->icon_array
[drawer
->icon_count
] = aicon
;
4803 aicon
->dock
= drawer
;
4804 aicon
->x_pos
= drawer
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
4805 aicon
->y_pos
= drawer
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
4807 if (!drawer
->lowered
)
4808 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
4810 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
4812 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
4814 if (!drawer
->collapsed
)
4815 XMapWindow(dpy
, aicon
->icon
->core
->window
);
4816 wRaiseFrame(aicon
->icon
->core
);
4818 drawer
->icon_count
++;
4823 WMReleasePropList(drawer_state
);
4829 /* Same kind of comment than for previous function: this function is
4830 * very similar to make_icon_state, but has substential differences as
4832 static WMPropList
*drawerSaveState(WScreen
*scr
, WDock
*drawer
)
4834 WMPropList
*pstr
, *drawer_state
;
4838 ai
= drawer
->icon_array
[0];
4839 /* Store its name */
4840 pstr
= WMCreatePLString(ai
->wm_instance
);
4841 drawer_state
= WMCreatePLDictionary(dName
, pstr
, NULL
); /* we need this final NULL */
4842 WMReleasePropList(pstr
);
4844 /* Store its position */
4845 snprintf(buffer
, sizeof(buffer
), "%i,%i", ai
->x_pos
, ai
->y_pos
);
4846 pstr
= WMCreatePLString(buffer
);
4847 WMPutInPLDictionary(drawer_state
, dPosition
, pstr
);
4848 WMReleasePropList(pstr
);
4851 /* Store its DnD command */
4852 if (ai
->dnd_command
) {
4853 pstr
= WMCreatePLString(ai
->dnd_command
);
4854 WMPutInPLDictionary(drawer_state
, dDropCommand
, pstr
);
4855 WMReleasePropList(pstr
);
4859 /* Store its paste command */
4860 if (ai
->paste_command
) {
4861 pstr
= WMCreatePLString(ai
->paste_command
);
4862 WMPutInPLDictionary(drawer_state
, dPasteCommand
, pstr
);
4863 WMReleasePropList(pstr
);
4866 /* Store applications list and other properties */
4867 pstr
= dockSaveState(drawer
);
4868 WMPutInPLDictionary(drawer_state
, dDock
, pstr
);
4869 WMReleasePropList(pstr
);
4871 return drawer_state
;
4875 void wDrawersSaveState(WScreen
*scr
)
4877 WMPropList
*all_drawers
, *drawer_state
;
4883 all_drawers
= WMCreatePLArray(NULL
);
4884 for (i
=0, dc
= scr
->drawers
;
4885 i
< scr
->drawer_count
;
4886 i
++, dc
= dc
->next
) {
4887 drawer_state
= drawerSaveState(scr
, dc
->adrawer
);
4888 WMAddToPLArray(all_drawers
, drawer_state
);
4889 WMReleasePropList(drawer_state
);
4891 WMPutInPLDictionary(w_global
.session_state
, dDrawers
, all_drawers
);
4892 WMReleasePropList(all_drawers
);
4896 void wDrawersRestoreState(WScreen
*scr
)
4898 WMPropList
*all_drawers
, *drawer_state
;
4903 if (w_global
.session_state
== NULL
)
4906 all_drawers
= WMGetFromPLDictionary(w_global
.session_state
, dDrawers
);
4910 for (i
= 0; i
< WMGetPropListItemCount(all_drawers
); i
++) {
4911 drawer_state
= WMGetFromPLArray(all_drawers
, i
);
4912 drawerRestoreState(scr
, drawer_state
);
4913 // Note: scr->drawers was updated when the the drawer was created