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>
35 #define PATH_MAX DEFAULT_PATH_MAX
38 #include "WindowMaker.h"
48 #include "properties.h"
52 #include "workspace.h"
54 #include "superfluous.h"
57 /**** Local variables ****/
60 #define CLIP_FORWARD 2
62 /**** Global variables ****/
65 extern void DestroyDockAppSettingsPanel();
66 extern void ShowDockAppSettingsPanel(WAppIcon
* aicon
);
67 extern Cursor wCursor
[WCUR_LAST
];
68 extern WPreferences wPreferences
;
69 extern XContext wWinContext
;
70 extern void appIconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
72 #define MOD_MASK wPreferences.modifier_mask
73 #define ICON_SIZE wPreferences.icon_size
75 /***** Local variables ****/
77 static WMPropList
*dCommand
= NULL
;
78 static WMPropList
*dPasteCommand
= NULL
;
79 #ifdef XDND /* XXX was OFFIX */
80 static WMPropList
*dDropCommand
= NULL
;
82 static WMPropList
*dAutoLaunch
, *dLock
;
83 static WMPropList
*dName
, *dForced
, *dBuggyApplication
, *dYes
, *dNo
;
84 static WMPropList
*dHost
, *dDock
, *dClip
;
85 static WMPropList
*dAutoAttractIcons
;
87 static WMPropList
*dPosition
, *dApplications
, *dLowered
, *dCollapsed
;
89 static WMPropList
*dAutoCollapse
, *dAutoRaiseLower
, *dOmnipresent
;
91 static void dockIconPaint(WAppIcon
*btn
);
93 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
95 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
);
97 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
99 static int getClipButton(int px
, int py
);
101 static void toggleLowered(WDock
*dock
);
103 static void toggleCollapsed(WDock
*dock
);
105 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
107 static void clipLeave(WDock
*dock
);
109 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
111 static Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
);
113 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
114 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
115 static void clipAutoCollapse(void *cdata
);
116 static void clipAutoExpand(void *cdata
);
117 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
);
119 static void clipAutoLower(void *cdata
);
120 static void clipAutoRaise(void *cdata
);
121 static void reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
);
122 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
);
124 static void make_keys(void)
126 if (dCommand
!= NULL
)
129 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
130 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
132 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
134 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
135 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
136 dName
= WMRetainPropList(WMCreatePLString("Name"));
137 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
138 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
139 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
140 dNo
= WMRetainPropList(WMCreatePLString("No"));
141 dHost
= WMRetainPropList(WMCreatePLString("Host"));
143 dPosition
= WMCreatePLString("Position");
144 dApplications
= WMCreatePLString("Applications");
145 dLowered
= WMCreatePLString("Lowered");
146 dCollapsed
= WMCreatePLString("Collapsed");
147 dAutoCollapse
= WMCreatePLString("AutoCollapse");
148 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
149 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
151 dOmnipresent
= WMCreatePLString("Omnipresent");
153 dDock
= WMCreatePLString("Dock");
154 dClip
= WMCreatePLString("Clip");
157 static void renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
159 WDock
*dock
= entry
->clientdata
;
164 assert(entry
->clientdata
!= NULL
);
166 wspace
= dock
->screen_ptr
->current_workspace
;
168 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
170 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+ 1);
171 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
, &name
)) {
172 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
178 static void toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
180 assert(entry
->clientdata
!= NULL
);
182 toggleLowered(entry
->clientdata
);
184 entry
->flags
.indicator_on
= !(((WDock
*) entry
->clientdata
)->lowered
);
189 static int matchWindow(const void *item
, const void *cdata
)
191 return (((WFakeGroupLeader
*) item
)->leader
== (Window
) cdata
);
194 static void killCallback(WMenu
*menu
, WMenuEntry
*entry
)
196 WScreen
*scr
= menu
->menu
->screen_ptr
;
198 WFakeGroupLeader
*fPtr
;
199 char *buffer
, *shortname
, **argv
;
200 char *basename(const char *shortname
);
203 if (!WCHECK_STATE(WSTATE_NORMAL
))
206 assert(entry
->clientdata
!= NULL
);
208 icon
= (WAppIcon
*) entry
->clientdata
;
212 WCHANGE_STATE(WSTATE_MODAL
);
214 /* strip away dir names */
215 shortname
= basename(icon
->command
);
216 /* separate out command options */
217 wtokensplit(shortname
, &argv
, &argc
);
219 buffer
= wstrconcat(argv
[0],
220 _(" will be forcibly closed.\n"
221 "Any unsaved changes will be lost.\n" "Please confirm."));
223 if (icon
->icon
&& icon
->icon
->owner
) {
224 fPtr
= icon
->icon
->owner
->fake_group
;
226 /* is this really necessary? can we kill a non-running dock icon? */
227 Window win
= icon
->main_window
;
230 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)win
);
231 if (index
!= WANotFound
)
232 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
237 if (wPreferences
.dont_confirm_kill
238 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
239 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
241 WWindow
*wwin
, *twin
;
243 wwin
= scr
->focused_window
;
246 if (wwin
->fake_group
== fPtr
) {
251 } else if (icon
->icon
&& icon
->icon
->owner
) {
252 wClientKill(icon
->icon
->owner
);
257 wtokenfree(argv
, argc
);
261 WCHANGE_STATE(WSTATE_NORMAL
);
264 /* TODO: replace this function with a member of the dock struct */
265 static int numberOfSelectedIcons(WDock
*dock
)
271 for (i
= 1; i
< dock
->max_icons
; i
++) {
272 aicon
= dock
->icon_array
[i
];
273 if (aicon
&& aicon
->icon
->selected
) {
281 static WMArray
*getSelected(WDock
*dock
)
283 WMArray
*ret
= WMCreateArray(8);
287 for (i
= 1; i
< dock
->max_icons
; i
++) {
288 btn
= dock
->icon_array
[i
];
289 if (btn
&& btn
->icon
->selected
) {
290 WMAddToArray(ret
, btn
);
297 static void paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
299 Window win
= clipIcon
->icon
->core
->window
;
300 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
302 int pt
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
303 int tp
= ICON_SIZE
- pt
;
304 int as
= pt
- 15; /* 15 = 5+5+5 */
305 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
308 color
= scr
->clip_title_color
[CLIP_NORMAL
];
310 XSetForeground(dpy
, gc
, WMColorPixel(color
));
315 p
[1].x
= ICON_SIZE
- 2;
317 p
[2].x
= ICON_SIZE
- 2;
319 } else if (lpushed
) {
323 p
[1].y
= ICON_SIZE
- 2;
325 p
[2].y
= ICON_SIZE
- 2;
327 if (lpushed
|| rpushed
) {
328 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
329 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
330 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
333 /* top right arrow */
334 p
[0].x
= p
[3].x
= ICON_SIZE
- 5 - as
;
336 p
[1].x
= ICON_SIZE
- 6;
338 p
[2].x
= ICON_SIZE
- 6;
341 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
342 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
344 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
345 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
348 /* bottom left arrow */
350 p
[0].y
= p
[3].y
= ICON_SIZE
- 5 - as
;
352 p
[1].y
= ICON_SIZE
- 6;
354 p
[2].y
= ICON_SIZE
- 6;
356 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
357 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
359 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
360 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
364 RImage
*wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
366 RImage
*tile
= RCloneImage(normalTile
);
373 pt
= CLIP_BUTTON_SIZE
* wPreferences
.icon_size
/ 64;
374 tp
= wPreferences
.icon_size
- 1 - pt
;
378 black
.red
= black
.green
= black
.blue
= 0;
381 dark
.red
= dark
.green
= dark
.blue
= 60;
384 light
.red
= light
.green
= light
.blue
= 80;
387 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
- 2, pt
- 1, &dark
);
388 RDrawLine(tile
, tp
- 1, 0, wPreferences
.icon_size
- 1, pt
+ 1, &black
);
389 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
- 3, pt
, &light
);
392 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, 4, &dark
);
393 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 5, 6 + as
, &dark
);
394 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
, &light
);
397 ROperateLine(tile
, RAddOperation
, 2, tp
+ 2, pt
- 2, wPreferences
.icon_size
- 3, &dark
);
398 RDrawLine(tile
, 0, tp
- 1, pt
+ 1, wPreferences
.icon_size
- 1, &black
);
399 ROperateLine(tile
, RSubtractOperation
, 0, tp
- 2, pt
+ 1, wPreferences
.icon_size
- 2, &light
);
402 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, &dark
);
403 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
, 6 + as
, ICON_SIZE
- 5, &dark
);
404 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5, &light
);
409 static void omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
411 WAppIcon
*clickedIcon
= entry
->clientdata
;
414 WMArray
*selectedIcons
;
415 WMArrayIterator iter
;
418 assert(entry
->clientdata
!= NULL
);
420 dock
= clickedIcon
->dock
;
422 selectedIcons
= getSelected(dock
);
424 if (!WMGetArrayItemCount(selectedIcons
))
425 WMAddToArray(selectedIcons
, clickedIcon
);
428 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
429 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
431 else if (aicon
->icon
->selected
)
432 wIconSelect(aicon
->icon
);
434 WMFreeArray(selectedIcons
);
437 wMessageDialog(dock
->screen_ptr
, _("Warning"),
438 _("Some icons cannot be made omnipresent. "
439 "Please make sure that no other icon is "
440 "docked in the same positions on the other "
441 "workspaces and the Clip is not full in "
442 "some workspace."), _("OK"), NULL
, NULL
);
443 } else if (failed
== 1) {
444 wMessageDialog(dock
->screen_ptr
, _("Warning"),
445 _("Icon cannot be made omnipresent. "
446 "Please make sure that no other icon is "
447 "docked in the same position on the other "
448 "workspaces and the Clip is not full in "
449 "some workspace."), _("OK"), NULL
, NULL
);
453 static void removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
455 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
458 WMArray
*selectedIcons
;
462 assert(clickedIcon
!= NULL
);
464 dock
= clickedIcon
->dock
;
466 selectedIcons
= getSelected(dock
);
468 if (WMGetArrayItemCount(selectedIcons
)) {
469 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
470 _("All selected icons will be removed!"),
471 _("OK"), _("Cancel"), NULL
) != WAPRDefault
) {
472 WMFreeArray(selectedIcons
);
476 if (clickedIcon
->xindex
== 0 && clickedIcon
->yindex
== 0) {
477 WMFreeArray(selectedIcons
);
480 WMAddToArray(selectedIcons
, clickedIcon
);
483 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
484 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
485 wDockDetach(dock
, aicon
);
487 /* XXX: can: aicon->icon == NULL ? */
488 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
489 wGetHeadForWindow(aicon
->icon
->owner
));
490 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
491 if (!dock
->mapped
|| dock
->collapsed
)
492 XMapWindow(dpy
, aicon
->icon
->core
->window
);
495 WMFreeArray(selectedIcons
);
497 if (wPreferences
.auto_arrange_icons
)
498 wArrangeIcons(dock
->screen_ptr
, True
);
501 static void keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
503 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
506 WMArray
*selectedIcons
;
509 assert(clickedIcon
!= NULL
);
510 dock
= clickedIcon
->dock
;
512 selectedIcons
= getSelected(dock
);
514 if (!WMGetArrayItemCount(selectedIcons
)
515 && clickedIcon
!= dock
->screen_ptr
->clip_icon
) {
516 char *command
= NULL
;
518 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
519 clickedIcon
->editing
= 1;
520 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
521 _("Type the command used to launch the application"), &command
)) {
522 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
526 clickedIcon
->command
= command
;
527 clickedIcon
->editing
= 0;
529 clickedIcon
->editing
= 0;
532 WMFreeArray(selectedIcons
);
537 WMAddToArray(selectedIcons
, clickedIcon
);
540 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
541 if (aicon
->icon
->selected
)
542 wIconSelect(aicon
->icon
);
543 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
544 aicon
->attracted
= 0;
545 if (aicon
->icon
->shadowed
) {
546 aicon
->icon
->shadowed
= 0;
547 aicon
->icon
->force_paint
= 1;
548 wAppIconPaint(aicon
);
553 WMFreeArray(selectedIcons
);
556 static void toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
558 WDock
*dock
= (WDock
*) entry
->clientdata
;
560 assert(entry
->clientdata
!= NULL
);
562 dock
->attract_icons
= !dock
->attract_icons
;
563 /*if (!dock->attract_icons)
564 dock->keep_attracted = 0; */
566 entry
->flags
.indicator_on
= dock
->attract_icons
;
571 static void selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
573 WAppIcon
*icon
= (WAppIcon
*) entry
->clientdata
;
575 assert(icon
!= NULL
);
577 wIconSelect(icon
->icon
);
582 static void colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
584 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
587 int x
, y
, x_pos
, y_pos
;
589 assert(entry
->clientdata
!= NULL
);
590 clip
= clickedIcon
->dock
;
592 aicon
= clip
->screen_ptr
->app_icon_list
;
595 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
596 x_pos
= clip
->x_pos
+ x
* ICON_SIZE
;
597 y_pos
= clip
->y_pos
+ y
* ICON_SIZE
;
598 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
600 if (wPreferences
.no_animations
) {
601 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
603 SlideWindow(aicon
->icon
->core
->window
,
604 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
607 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
608 #endif /* ANIMATIONS */
610 aicon
->attracted
= 1;
611 if (!aicon
->icon
->shadowed
) {
612 aicon
->icon
->shadowed
= 1;
613 aicon
->icon
->force_paint
= 1;
614 /* We don't do an wAppIconPaint() here because it's in
615 * wDockAttachIcon(). -Dan
618 wDockAttachIcon(clip
, aicon
, x
, y
);
619 if (clip
->collapsed
|| !clip
->mapped
)
620 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
626 static void selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
628 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
630 WMArray
*selectedIcons
;
631 WMArrayIterator iter
;
635 assert(clickedIcon
!= NULL
);
636 dock
= clickedIcon
->dock
;
638 selectedIcons
= getSelected(dock
);
640 if (!WMGetArrayItemCount(selectedIcons
)) {
641 for (i
= 1; i
< dock
->max_icons
; i
++) {
642 btn
= dock
->icon_array
[i
];
643 if (btn
&& !btn
->icon
->selected
) {
644 wIconSelect(btn
->icon
);
648 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
649 wIconSelect(btn
->icon
);
652 WMFreeArray(selectedIcons
);
657 static void toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
659 assert(entry
->clientdata
!= NULL
);
661 toggleCollapsed(entry
->clientdata
);
663 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->collapsed
;
668 static void toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
671 assert(entry
->clientdata
!= NULL
);
673 dock
= (WDock
*) entry
->clientdata
;
675 dock
->auto_collapse
= !dock
->auto_collapse
;
677 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_collapse
;
682 static void toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
685 assert(entry
->clientdata
!= NULL
);
687 dock
= (WDock
*) entry
->clientdata
;
689 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
691 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_raise_lower
;
696 static void launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
698 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
700 launchDockedApplication(btn
, False
);
703 static void settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
705 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
709 ShowDockAppSettingsPanel(btn
);
712 static void hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
715 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
717 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
719 if (wapp
->flags
.hidden
) {
720 wWorkspaceChange(btn
->icon
->core
->screen_ptr
, wapp
->last_workspace
);
721 wUnhideApplication(wapp
, False
, False
);
723 wHideApplication(wapp
);
727 static void unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
730 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
732 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
734 wUnhideApplication(wapp
, False
, True
);
737 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
)
742 if (type
== WM_CLIP
) {
744 return scr
->clip_icon
;
745 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
746 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
747 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
748 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
749 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE; */
752 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
753 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
759 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
760 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
761 btn
->icon
->core
->descriptor
.parent
= btn
;
762 /*ChangeStackingLevel(btn->icon->core, WMDockLevel); */
763 XMapWindow(dpy
, btn
->icon
->core
->window
);
768 scr
->clip_icon
= btn
;
773 static void switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
775 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
776 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
778 WMArray
*selectedIcons
;
781 if (entry
->order
== scr
->current_workspace
)
784 dest
= scr
->workspaces
[entry
->order
]->clip
;
786 selectedIcons
= getSelected(src
);
788 if (WMGetArrayItemCount(selectedIcons
)) {
789 WMArrayIterator iter
;
791 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
792 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
793 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
794 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
797 } else if (icon
!= scr
->clip_icon
) {
798 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
799 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
800 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
803 WMFreeArray(selectedIcons
);
806 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
)
808 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
810 if (!btn
->launching
&&
811 ((!withSelection
&& btn
->command
!= NULL
) || (withSelection
&& btn
->paste_command
!= NULL
))) {
812 if (!btn
->forced_dock
) {
813 btn
->relaunching
= btn
->running
;
816 if (btn
->wm_instance
|| btn
->wm_class
) {
817 WWindowAttributes attr
;
818 memset(&attr
, 0, sizeof(WWindowAttributes
));
819 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
821 if (!attr
.no_appicon
&& !btn
->buggy_app
)
826 btn
->drop_launch
= 0;
827 btn
->paste_launch
= withSelection
;
828 scr
->last_dock
= btn
->dock
;
829 btn
->pid
= execCommand(btn
, (withSelection
? btn
->paste_command
: btn
->command
), NULL
);
831 if (btn
->buggy_app
) {
832 /* give feedback that the app was launched */
836 WMAddTimerHandler(200, (WMCallback
*) dockIconPaint
, btn
);
841 wwarning(_("could not launch application %s"), btn
->command
);
843 if (!btn
->relaunching
) {
850 static void updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
852 WScreen
*scr
= menu
->frame
->screen_ptr
;
853 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
859 for (i
= 0; i
< scr
->workspace_count
; i
++) {
860 if (i
< menu
->entry_no
) {
861 if (strcmp(menu
->entries
[i
]->text
, scr
->workspaces
[i
]->name
) != 0) {
862 wfree(menu
->entries
[i
]->text
);
863 strcpy(title
, scr
->workspaces
[i
]->name
);
864 menu
->entries
[i
]->text
= wstrdup(title
);
865 menu
->flags
.realized
= 0;
867 menu
->entries
[i
]->clientdata
= (void *)icon
;
869 strcpy(title
, scr
->workspaces
[i
]->name
);
871 wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)icon
);
873 menu
->flags
.realized
= 0;
875 if (i
== scr
->current_workspace
) {
876 wMenuSetEnabled(menu
, i
, False
);
878 wMenuSetEnabled(menu
, i
, True
);
882 if (!menu
->flags
.realized
)
886 static WMenu
*makeWorkspaceMenu(WScreen
*scr
)
890 menu
= wMenuCreate(scr
, NULL
, False
);
892 wwarning(_("could not create workspace submenu for Clip menu"));
894 wMenuAddCallback(menu
, "", switchWSCommand
, (void *)scr
->clip_icon
);
896 menu
->flags
.realized
= 0;
902 static void updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
911 entry
= menu
->entries
[index
];
912 entry
->flags
.indicator_on
= !dock
->lowered
;
913 entry
->clientdata
= dock
;
916 entry
= menu
->entries
[++index
];
917 entry
->flags
.indicator_on
= dock
->collapsed
;
918 entry
->clientdata
= dock
;
921 entry
= menu
->entries
[++index
];
922 entry
->flags
.indicator_on
= dock
->auto_collapse
;
923 entry
->clientdata
= dock
;
925 /* auto-raise/lower */
926 entry
= menu
->entries
[++index
];
927 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
928 entry
->clientdata
= dock
;
929 wMenuSetEnabled(menu
, index
, dock
->lowered
);
932 entry
= menu
->entries
[++index
];
933 entry
->flags
.indicator_on
= dock
->attract_icons
;
934 entry
->clientdata
= dock
;
936 menu
->flags
.realized
= 0;
940 static WMenu
*makeClipOptionsMenu(WScreen
*scr
)
945 menu
= wMenuCreate(scr
, NULL
, False
);
947 wwarning(_("could not create options submenu for Clip menu"));
951 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
952 entry
->flags
.indicator
= 1;
953 entry
->flags
.indicator_on
= 1;
954 entry
->flags
.indicator_type
= MI_CHECK
;
956 entry
= wMenuAddCallback(menu
, _("Collapsed"), toggleCollapsedCallback
, NULL
);
957 entry
->flags
.indicator
= 1;
958 entry
->flags
.indicator_on
= 1;
959 entry
->flags
.indicator_type
= MI_CHECK
;
961 entry
= wMenuAddCallback(menu
, _("Autocollapse"), toggleAutoCollapseCallback
, NULL
);
962 entry
->flags
.indicator
= 1;
963 entry
->flags
.indicator_on
= 1;
964 entry
->flags
.indicator_type
= MI_CHECK
;
966 entry
= wMenuAddCallback(menu
, _("Autoraise"), toggleAutoRaiseLowerCallback
, NULL
);
967 entry
->flags
.indicator
= 1;
968 entry
->flags
.indicator_on
= 1;
969 entry
->flags
.indicator_type
= MI_CHECK
;
971 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"), toggleAutoAttractCallback
, NULL
);
972 entry
->flags
.indicator
= 1;
973 entry
->flags
.indicator_on
= 1;
974 entry
->flags
.indicator_type
= MI_CHECK
;
976 menu
->flags
.realized
= 0;
982 static WMenu
*dockMenuCreate(WScreen
*scr
, int type
)
987 if (type
== WM_CLIP
&& scr
->clip_menu
)
988 return scr
->clip_menu
;
990 menu
= wMenuCreate(scr
, NULL
, False
);
991 if (type
!= WM_CLIP
) {
992 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
993 entry
->flags
.indicator
= 1;
994 entry
->flags
.indicator_on
= 1;
995 entry
->flags
.indicator_type
= MI_CHECK
;
997 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
998 scr
->clip_options
= makeClipOptionsMenu(scr
);
999 if (scr
->clip_options
)
1000 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1002 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1004 entry
->text
= _("Rename Workspace");
1006 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1007 entry
->flags
.indicator
= 1;
1008 entry
->flags
.indicator_on
= 1;
1009 entry
->flags
.indicator_type
= MI_CHECK
;
1011 entry
= wMenuAddCallback(menu
, _("Select All Icons"), selectIconsCallback
, NULL
);
1013 entry
->text
= _("Select All Icons");
1015 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1017 entry
->text
= _("Keep Icon");
1019 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1021 entry
->text
= _("Move Icon To");
1022 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1023 if (scr
->clip_submenu
)
1024 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1026 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
, NULL
);
1028 entry
->text
= _("Remove Icon");
1030 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1033 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1035 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1037 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1039 entry
->text
= _("Hide");
1041 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1043 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1045 if (type
== WM_CLIP
)
1046 scr
->clip_menu
= menu
;
1051 WDock
*wDockCreate(WScreen
*scr
, int type
)
1058 dock
= wmalloc(sizeof(WDock
));
1060 dock
->max_icons
= DOCK_MAX_ICONS
;
1062 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * dock
->max_icons
);
1064 btn
= mainIconCreate(scr
, type
);
1068 dock
->x_pos
= btn
->x_pos
;
1069 dock
->y_pos
= btn
->y_pos
;
1070 dock
->screen_ptr
= scr
;
1072 dock
->icon_count
= 1;
1073 dock
->on_right_side
= 1;
1074 dock
->collapsed
= 0;
1075 dock
->auto_collapse
= 0;
1076 dock
->auto_collapse_magic
= NULL
;
1077 dock
->auto_raise_lower
= 0;
1078 dock
->auto_lower_magic
= NULL
;
1079 dock
->auto_raise_magic
= NULL
;
1080 dock
->attract_icons
= 0;
1082 dock
->icon_array
[0] = btn
;
1083 wRaiseFrame(btn
->icon
->core
);
1084 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1086 /* create dock menu */
1087 dock
->menu
= dockMenuCreate(scr
, type
);
1092 void wDockDestroy(WDock
*dock
)
1097 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1098 aicon
= dock
->icon_array
[i
];
1100 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1101 wDockDetach(dock
, aicon
);
1103 /* XXX: can: aicon->icon == NULL ? */
1104 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1105 wGetHeadForWindow(aicon
->icon
->owner
));
1106 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1107 if (!dock
->mapped
|| dock
->collapsed
)
1108 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1112 if (wPreferences
.auto_arrange_icons
)
1113 wArrangeIcons(dock
->screen_ptr
, True
);
1114 wfree(dock
->icon_array
);
1115 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1116 wMenuDestroy(dock
->menu
, True
);
1117 if (dock
->screen_ptr
->last_dock
== dock
)
1118 dock
->screen_ptr
->last_dock
= NULL
;
1122 void wClipIconPaint(WAppIcon
*aicon
)
1124 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1125 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1127 Window win
= aicon
->icon
->core
->window
;
1128 int length
, nlength
;
1129 char *ws_name
, ws_number
[10];
1132 wIconPaint(aicon
->icon
);
1134 length
= strlen(workspace
->name
);
1135 ws_name
= wmalloc(length
+ 1);
1136 snprintf(ws_name
, length
+ 1, "%s", workspace
->name
);
1137 snprintf(ws_number
, sizeof(ws_number
), "%i", scr
->current_workspace
+ 1);
1138 nlength
= strlen(ws_number
);
1140 if (!workspace
->clip
->collapsed
)
1141 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1143 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1145 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1147 tx
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
1149 if(wPreferences
.show_clip_title
)
1150 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, ty
, ws_name
, length
);
1152 tx
= (ICON_SIZE
/ 2 - WMWidthOfString(scr
->clip_title_font
, ws_number
, nlength
)) / 2;
1154 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, 2, ws_number
, nlength
);
1158 if (aicon
->launching
) {
1159 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1160 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1162 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
, aicon
->dock
->rclip_button_pushed
);
1165 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1167 wClipIconPaint(desc
->parent
);
1170 static void dockIconPaint(WAppIcon
*btn
)
1172 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1173 wClipIconPaint(btn
);
1180 static WMPropList
*make_icon_state(WAppIcon
*btn
)
1182 WMPropList
*node
= NULL
;
1183 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
;
1184 WMPropList
*position
, *buggy
, *omnipresent
;
1190 command
= WMCreatePLString("-");
1192 command
= WMCreatePLString(btn
->command
);
1194 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1196 lock
= btn
->lock
? dYes
: dNo
;
1198 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1200 name
= WMCreatePLString(tmp
);
1204 forced
= btn
->forced_dock
? dYes
: dNo
;
1206 buggy
= btn
->buggy_app
? dYes
: dNo
;
1208 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1209 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1211 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1212 position
= WMCreatePLString(buffer
);
1214 node
= WMCreatePLDictionary(dCommand
, command
,
1216 dAutoLaunch
, autolaunch
,
1218 dForced
, forced
, dBuggyApplication
, buggy
, dPosition
, position
, NULL
);
1219 WMReleasePropList(command
);
1220 WMReleasePropList(name
);
1221 WMReleasePropList(position
);
1223 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1224 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&& (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1225 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1227 #ifdef XDND /* was OFFIX */
1228 if (btn
->dnd_command
) {
1229 command
= WMCreatePLString(btn
->dnd_command
);
1230 WMPutInPLDictionary(node
, dDropCommand
, command
);
1231 WMReleasePropList(command
);
1235 if (btn
->paste_command
) {
1236 command
= WMCreatePLString(btn
->paste_command
);
1237 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1238 WMReleasePropList(command
);
1245 static WMPropList
*dockSaveState(WDock
*dock
)
1248 WMPropList
*icon_info
;
1249 WMPropList
*list
= NULL
, *dock_state
= NULL
;
1250 WMPropList
*value
, *key
;
1253 list
= WMCreatePLArray(NULL
);
1255 for (i
= (dock
->type
== WM_DOCK
? 0 : 1); i
< dock
->max_icons
; i
++) {
1256 WAppIcon
*btn
= dock
->icon_array
[i
];
1258 if (!btn
|| btn
->attracted
)
1261 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1262 WMAddToPLArray(list
, icon_info
);
1263 WMReleasePropList(icon_info
);
1267 dock_state
= WMCreatePLDictionary(dApplications
, list
, NULL
);
1269 if (dock
->type
== WM_DOCK
) {
1270 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1271 key
= WMCreatePLString(buffer
);
1272 WMPutInPLDictionary(dock_state
, key
, list
);
1273 WMReleasePropList(key
);
1275 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0), dock
->y_pos
);
1276 value
= WMCreatePLString(buffer
);
1277 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1278 WMReleasePropList(value
);
1280 WMReleasePropList(list
);
1282 value
= (dock
->lowered
? dYes
: dNo
);
1283 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1285 if (dock
->type
== WM_CLIP
) {
1286 value
= (dock
->collapsed
? dYes
: dNo
);
1287 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1289 value
= (dock
->auto_collapse
? dYes
: dNo
);
1290 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1292 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1293 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1295 value
= (dock
->attract_icons
? dYes
: dNo
);
1296 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1302 void wDockSaveState(WScreen
*scr
, WMPropList
*old_state
)
1304 WMPropList
*dock_state
;
1307 dock_state
= dockSaveState(scr
->dock
);
1310 * Copy saved states of docks with different sizes.
1316 keys
= WMGetPLDictionaryKeys(old_state
);
1317 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1318 tmp
= WMGetFromPLArray(keys
, i
);
1320 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1321 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1323 WMPutInPLDictionary(dock_state
, tmp
, WMGetFromPLDictionary(old_state
, tmp
));
1326 WMReleasePropList(keys
);
1329 WMPutInPLDictionary(scr
->session_state
, dDock
, dock_state
);
1331 WMReleasePropList(dock_state
);
1334 void wClipSaveState(WScreen
*scr
)
1336 WMPropList
*clip_state
;
1338 clip_state
= make_icon_state(scr
->clip_icon
);
1340 WMPutInPLDictionary(scr
->session_state
, dClip
, clip_state
);
1342 WMReleasePropList(clip_state
);
1345 WMPropList
*wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1347 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1350 static Bool
getBooleanDockValue(WMPropList
*value
, WMPropList
*key
)
1353 if (WMIsPLString(value
)) {
1354 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1357 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1363 static WAppIcon
*restore_icon_state(WScreen
*scr
, WMPropList
*info
, int type
, int index
)
1366 WMPropList
*cmd
, *value
;
1368 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1369 if (!cmd
|| !WMIsPLString(cmd
)) {
1373 /* parse window name */
1374 value
= WMGetFromPLDictionary(info
, dName
);
1379 char *wclass
, *winstance
;
1382 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1384 if (!winstance
&& !wclass
) {
1391 command
= wstrdup(WMGetFromPLString(cmd
));
1395 if (!command
|| strcmp(command
, "-") == 0) {
1406 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1415 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1416 if (type
== WM_CLIP
) {
1417 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1418 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1420 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1421 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1423 #ifdef XDND /* was OFFIX */
1424 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1426 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1429 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1431 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1433 /* check auto launch */
1434 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1436 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1439 value
= WMGetFromPLDictionary(info
, dLock
);
1441 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1443 /* check if it wasn't normally docked */
1444 value
= WMGetFromPLDictionary(info
, dForced
);
1446 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1448 /* check if we can rely on the stuff in the app */
1449 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1451 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1453 /* get position in the dock */
1454 value
= WMGetFromPLDictionary(info
, dPosition
);
1455 if (value
&& WMIsPLString(value
)) {
1456 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1457 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1459 /* check position sanity */
1460 /* incomplete section! */
1461 if (type
== WM_DOCK
) {
1463 if (aicon
->yindex
< 0)
1464 wwarning(_("bad value in docked icon position %i,%i"),
1465 aicon
->xindex
, aicon
->yindex
);
1468 aicon
->yindex
= index
;
1472 /* check if icon is omnipresent */
1473 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1475 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1483 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1485 WAppIcon
*wClipRestoreState(WScreen
*scr
, WMPropList
*clip_state
)
1490 icon
= mainIconCreate(scr
, WM_CLIP
);
1495 WMRetainPropList(clip_state
);
1497 /* restore position */
1499 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1502 if (!WMIsPLString(value
))
1503 COMPLAIN("Position");
1508 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1509 COMPLAIN("Position");
1511 /* check position sanity */
1512 rect
.pos
.x
= icon
->x_pos
;
1513 rect
.pos
.y
= icon
->y_pos
;
1514 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1516 wGetRectPlacementInfo(scr
, rect
, &flags
);
1517 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
1518 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1521 #ifdef XDND /* was OFFIX */
1522 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1523 if (value
&& WMIsPLString(value
))
1524 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1527 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1528 if (value
&& WMIsPLString(value
))
1529 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1531 WMReleasePropList(clip_state
);
1536 WDock
*wDockRestoreState(WScreen
*scr
, WMPropList
*dock_state
, int type
)
1541 WAppIcon
*aicon
, *old_top
;
1544 dock
= wDockCreate(scr
, type
);
1549 WMRetainPropList(dock_state
);
1551 /* restore position */
1552 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1554 if (!WMIsPLString(value
)) {
1555 COMPLAIN("Position");
1560 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1561 COMPLAIN("Position");
1563 /* check position sanity */
1564 rect
.pos
.x
= dock
->x_pos
;
1565 rect
.pos
.y
= dock
->y_pos
;
1566 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1568 wGetRectPlacementInfo(scr
, rect
, &flags
);
1569 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
)) {
1570 int x
= dock
->x_pos
;
1571 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1574 /* Is this needed any more? */
1575 if (type
== WM_CLIP
) {
1576 if (dock
->x_pos
< 0) {
1578 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1579 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1582 if (dock
->x_pos
>= 0) {
1583 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1584 dock
->on_right_side
= 0;
1586 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1587 dock
->on_right_side
= 1;
1593 /* restore lowered/raised state */
1596 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1598 if (!WMIsPLString(value
)) {
1599 COMPLAIN("Lowered");
1601 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1607 /* restore collapsed state */
1608 dock
->collapsed
= 0;
1610 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1612 if (!WMIsPLString(value
)) {
1613 COMPLAIN("Collapsed");
1615 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1616 dock
->collapsed
= 1;
1621 /* restore auto-collapsed state */
1622 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1624 if (!WMIsPLString(value
)) {
1625 COMPLAIN("AutoCollapse");
1627 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1628 dock
->auto_collapse
= 1;
1629 dock
->collapsed
= 1;
1634 /* restore auto-raise/lower state */
1635 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1637 if (!WMIsPLString(value
)) {
1638 COMPLAIN("AutoRaiseLower");
1640 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1641 dock
->auto_raise_lower
= 1;
1645 /* restore attract icons state */
1646 dock
->attract_icons
= 0;
1648 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1650 if (!WMIsPLString(value
)) {
1651 COMPLAIN("AutoAttractIcons");
1653 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1654 dock
->attract_icons
= 1;
1658 /* application list */
1665 * When saving, it saves the dock state in
1666 * Applications and Applicationsnnn
1668 * When loading, it will first try Applicationsnnn.
1669 * If it does not exist, use Applications as default.
1672 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1674 tmp
= WMCreatePLString(buffer
);
1675 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1676 WMReleasePropList(tmp
);
1679 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1685 count
= WMGetPropListItemCount(apps
);
1689 old_top
= dock
->icon_array
[0];
1691 /* dock->icon_count is set to 1 when dock is created.
1692 * Since Clip is already restored, we want to keep it so for clip,
1693 * but for dock we may change the default top tile, so we set it to 0.
1695 if (type
== WM_DOCK
)
1696 dock
->icon_count
= 0;
1698 for (i
= 0; i
< count
; i
++) {
1699 if (dock
->icon_count
>= dock
->max_icons
) {
1700 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1704 value
= WMGetFromPLArray(apps
, i
);
1705 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1707 dock
->icon_array
[dock
->icon_count
] = aicon
;
1711 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1712 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1715 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1717 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1719 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1721 if (!dock
->collapsed
)
1722 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1723 wRaiseFrame(aicon
->icon
->core
);
1726 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
)
1730 /* if the first icon is not defined, use the default */
1731 if (dock
->icon_array
[0] == NULL
) {
1732 /* update default icon */
1733 old_top
->x_pos
= dock
->x_pos
;
1734 old_top
->y_pos
= dock
->y_pos
;
1736 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1738 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1739 dock
->icon_array
[0] = old_top
;
1740 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1741 /* we don't need to increment dock->icon_count here because it was
1742 * incremented in the loop above.
1744 } else if (old_top
!= dock
->icon_array
[0]) {
1745 if (old_top
== scr
->clip_icon
)
1746 scr
->clip_icon
= dock
->icon_array
[0];
1747 wAppIconDestroy(old_top
);
1751 WMReleasePropList(dock_state
);
1756 void wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1758 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1760 btn
->drop_launch
= 0;
1761 btn
->paste_launch
= 0;
1763 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1766 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1776 void wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1782 for (i
= 0; i
< dock
->max_icons
; i
++) {
1783 btn
= dock
->icon_array
[i
];
1784 if (!btn
|| !btn
->auto_launch
)
1787 state
= wmalloc(sizeof(WSavedState
));
1788 state
->workspace
= workspace
;
1789 /* TODO: this is klugy and is very difficult to understand
1790 * what's going on. Try to clean up */
1791 wDockLaunchWithState(dock
, btn
, state
);
1795 #ifdef XDND /* was OFFIX */
1796 static WDock
*findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1802 if ((dock
= scr
->dock
) != NULL
) {
1803 for (i
= 0; i
< dock
->max_icons
; i
++) {
1804 if (dock
->icon_array
[i
]
1805 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1811 if (*icon_pos
< 0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
) != NULL
) {
1812 for (i
= 0; i
< dock
->max_icons
; i
++) {
1813 if (dock
->icon_array
[i
]
1814 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1825 int wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
1831 dock
= findDock(scr
, event
, &icon_pos
);
1836 * Return True if the drop was on an application icon window.
1837 * In this case, let the ClientMessage handler redirect the
1838 * message to the app.
1840 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
1843 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
1844 scr
->flags
.dnd_data_convertion_status
= 0;
1846 btn
= dock
->icon_array
[icon_pos
];
1848 if (!btn
->forced_dock
) {
1849 btn
->relaunching
= btn
->running
;
1852 if (btn
->wm_instance
|| btn
->wm_class
) {
1853 WWindowAttributes attr
;
1854 memset(&attr
, 0, sizeof(WWindowAttributes
));
1855 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
1856 btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
1858 if (!attr
.no_appicon
)
1864 btn
->paste_launch
= 0;
1865 btn
->drop_launch
= 1;
1866 scr
->last_dock
= dock
;
1867 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1872 if (!btn
->relaunching
) {
1881 Bool
wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1886 wwin
= icon
->icon
->owner
;
1887 if (icon
->command
== NULL
) {
1892 command
= GetCommandForWindow(wwin
->client_win
);
1894 icon
->command
= command
;
1896 /* icon->forced_dock = 1; */
1897 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
1899 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
1900 _("Type the command used to launch the application"), &command
)) {
1901 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
1905 icon
->command
= command
;
1911 /* If the target is the dock, reject the icon. If
1912 * the target is the clip, make it an attracted icon
1914 if (dock
->type
== WM_CLIP
) {
1915 icon
->attracted
= 1;
1916 if (!icon
->icon
->shadowed
) {
1917 icon
->icon
->shadowed
= 1;
1918 icon
->icon
->force_paint
= 1;
1930 for (index
= 1; index
< dock
->max_icons
; index
++)
1931 if (dock
->icon_array
[index
] == NULL
)
1933 /* if (index == dock->max_icons)
1936 assert(index
< dock
->max_icons
);
1938 dock
->icon_array
[index
] = icon
;
1942 icon
->omnipresent
= 0;
1944 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
1945 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
1950 icon
->launching
= 0;
1953 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1954 if (dock
->type
== WM_CLIP
) {
1955 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1956 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1958 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1959 icon
->icon
->core
->descriptor
.parent
= icon
;
1961 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
1962 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
1963 wAppIconPaint(icon
);
1966 if (wPreferences
.auto_arrange_icons
)
1967 wArrangeIcons(dock
->screen_ptr
, True
);
1969 #ifdef XDND /* was OFFIX */
1970 if (icon
->command
&& !icon
->dnd_command
) {
1971 int len
= strlen(icon
->command
) + 8;
1972 icon
->dnd_command
= wmalloc(len
);
1973 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
1977 if (icon
->command
&& !icon
->paste_command
) {
1978 int len
= strlen(icon
->command
) + 8;
1979 icon
->paste_command
= wmalloc(len
);
1980 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
1986 static void reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1990 for (index
= 1; index
< dock
->max_icons
; index
++) {
1991 if (dock
->icon_array
[index
] == icon
)
1994 assert(index
< dock
->max_icons
);
1999 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2000 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2003 static Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2010 return True
; /* No move needed, we're already there */
2015 wwin
= icon
->icon
->owner
;
2018 * For the moment we can't do this if we move icons in Clip from one
2019 * workspace to other, because if we move two or more icons without
2020 * command, the dialog box will not be able to tell us to which of the
2021 * moved icons it applies. -Dan
2023 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
2024 command
= GetCommandForWindow(wwin
->client_win
);
2026 icon
->command
= command
;
2029 /* icon->forced_dock = 1; */
2030 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2031 _("Type the command used to launch the application"), &command
)) {
2032 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2036 icon
->command
= command
;
2047 if (dest
->type
== WM_DOCK
)
2048 wClipMakeIconOmnipresent(icon
, False
);
2050 for (index
= 1; index
< src
->max_icons
; index
++) {
2051 if (src
->icon_array
[index
] == icon
)
2054 assert(index
< src
->max_icons
);
2056 src
->icon_array
[index
] = NULL
;
2059 for (index
= 1; index
< dest
->max_icons
; index
++) {
2060 if (dest
->icon_array
[index
] == NULL
)
2063 /* if (index == dest->max_icons)
2066 assert(index
< dest
->max_icons
);
2068 dest
->icon_array
[index
] = icon
;
2071 /* deselect the icon */
2072 if (icon
->icon
->selected
)
2073 wIconSelect(icon
->icon
);
2075 if (dest
->type
== WM_DOCK
) {
2076 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2077 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2079 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2080 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2083 /* set it to be kept when moving to dock.
2084 * Unless the icon does not have a command set
2086 if (icon
->command
&& dest
->type
== WM_DOCK
) {
2087 icon
->attracted
= 0;
2088 if (icon
->icon
->shadowed
) {
2089 icon
->icon
->shadowed
= 0;
2090 icon
->icon
->force_paint
= 1;
2095 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2101 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2102 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2106 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2107 wAppIconPaint(icon
);
2112 void wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2116 /* make the settings panel be closed */
2118 DestroyDockAppSettingsPanel(icon
->panel
);
2121 /* This must be called before icon->dock is set to NULL.
2122 * Don't move it. -Dan
2124 wClipMakeIconOmnipresent(icon
, False
);
2128 icon
->attracted
= 0;
2129 icon
->auto_launch
= 0;
2130 if (icon
->icon
->shadowed
) {
2131 icon
->icon
->shadowed
= 0;
2132 icon
->icon
->force_paint
= 1;
2135 /* deselect the icon */
2136 if (icon
->icon
->selected
)
2137 wIconSelect(icon
->icon
);
2139 if (icon
->command
) {
2140 wfree(icon
->command
);
2141 icon
->command
= NULL
;
2143 #ifdef XDND /* was OFFIX */
2144 if (icon
->dnd_command
) {
2145 wfree(icon
->dnd_command
);
2146 icon
->dnd_command
= NULL
;
2149 if (icon
->paste_command
) {
2150 wfree(icon
->paste_command
);
2151 icon
->paste_command
= NULL
;
2154 for (index
= 1; index
< dock
->max_icons
; index
++)
2155 if (dock
->icon_array
[index
] == icon
)
2157 assert(index
< dock
->max_icons
);
2158 dock
->icon_array
[index
] = NULL
;
2164 /* if the dock is not attached to an application or
2165 * the application did not set the appropriate hints yet,
2166 * destroy the icon */
2167 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2168 wAppIconDestroy(icon
);
2170 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2171 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2172 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2173 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2174 icon
->icon
->core
->descriptor
.parent
= icon
;
2176 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2178 wAppIconPaint(icon
);
2179 if (wPreferences
.auto_arrange_icons
) {
2180 wArrangeIcons(dock
->screen_ptr
, True
);
2183 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2188 * returns the closest Dock slot index for the passed
2191 * Returns False if icon can't be docked.
2193 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2196 Bool
wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2198 WScreen
*scr
= dock
->screen_ptr
;
2201 int i
, offset
= ICON_SIZE
/ 2;
2202 WAppIcon
*aicon
= NULL
;
2203 WAppIcon
*nicon
= NULL
;
2206 /* TODO: XINERAMA, for these */
2207 max_y_icons
= scr
->scr_height
/ ICON_SIZE
- 1;
2209 if (wPreferences
.flags
.noupdates
)
2215 /* if the dock is full */
2216 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
)) {
2220 /* exact position */
2222 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2224 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2227 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2229 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2231 /* check if the icon is outside the screen boundaries */
2236 rect
.pos
.x
= dx
+ ex_x
* ICON_SIZE
;
2237 rect
.pos
.y
= dy
+ ex_y
* ICON_SIZE
;
2238 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2240 wGetRectPlacementInfo(scr
, rect
, &flags
);
2241 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
2245 if (dock
->type
== WM_DOCK
) {
2246 if (icon
->dock
!= dock
&& ex_x
!= 0)
2250 for (i
= 0; i
< dock
->max_icons
; i
++) {
2251 nicon
= dock
->icon_array
[i
];
2252 if (nicon
&& nicon
->yindex
== ex_y
) {
2259 int sig
, done
, closest
;
2261 /* Possible cases when redocking:
2263 * icon dragged out of range of any slot -> false
2264 * icon dragged to range of free slot
2265 * icon dragged to range of same slot
2266 * icon dragged to range of different icon
2268 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2271 if (ex_y
>= 0 && ex_y
<= max_y_icons
&& (aicon
== icon
|| !aicon
)) {
2277 /* start looking at the upper slot or lower? */
2278 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2285 /* look for closest free slot */
2286 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2290 closest
= sig
* (i
/ 2) + ex_y
;
2291 /* check if this slot is used */
2293 for (j
= 0; j
< dock
->max_icons
; j
++) {
2294 if (dock
->icon_array
[j
]
2295 && dock
->icon_array
[j
]->yindex
== closest
) {
2296 /* slot is used by someone else */
2297 if (dock
->icon_array
[j
] != icon
)
2305 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2306 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2307 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2312 } else { /* !redocking */
2314 /* if slot is free and the icon is close enough, return it */
2315 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2325 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2326 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+ 1;
2329 for (k
= start
; k
< stop
; k
++) {
2330 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2333 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2334 nicon
= tmp
->icon_array
[i
];
2335 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2343 for (k
= start
; k
< stop
; k
++) {
2344 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2347 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2348 nicon
= tmp
->icon_array
[i
];
2349 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2350 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2351 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2360 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2369 static int onScreen(WScreen
*scr
, int x
, int y
, int sx
, int ex
, int sy
, int ey
)
2371 WMRect rect
= wmkrect(x
, y
, ICON_SIZE
, ICON_SIZE
);
2374 wGetRectPlacementInfo(scr
, rect
, &flags
);
2376 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2380 * returns true if it can find a free slot in the dock,
2381 * in which case it changes x_pos and y_pos accordingly.
2382 * Else returns false.
2384 Bool
wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2386 WScreen
*scr
= dock
->screen_ptr
;
2388 WAppIconChain
*chain
;
2389 unsigned char *slot_map
;
2393 int i
, done
= False
;
2395 int sx
= 0, sy
= 0, ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2396 int extra_count
= 0;
2398 if (dock
->type
== WM_CLIP
&& dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2399 extra_count
= scr
->global_icon_count
;
2401 /* if the dock is full */
2402 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
) {
2406 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2407 if (scr
->dock
->on_right_side
)
2408 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2410 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2413 if (ex
< dock
->x_pos
)
2415 if (sx
> dock
->x_pos
+ ICON_SIZE
)
2416 sx
= dock
->x_pos
+ ICON_SIZE
;
2423 /* check if clip is in a corner */
2424 if (dock
->type
== WM_CLIP
) {
2425 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2427 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2429 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2431 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2438 /* If the clip is in the corner, use only slots that are in the border
2440 if (corner
!= C_NONE
) {
2444 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2445 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2446 hmap
= wmalloc(hcount
+ 1);
2447 vmap
= wmalloc(vcount
+ 1);
2449 /* mark used positions */
2452 for (i
= 0; i
< dock
->max_icons
; i
++) {
2453 btn
= dock
->icon_array
[i
];
2457 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2458 vmap
[btn
->yindex
] = 1;
2459 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2460 hmap
[btn
->xindex
] = 1;
2462 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2464 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2465 vmap
[btn
->yindex
] = 1;
2466 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2467 hmap
[btn
->xindex
] = 1;
2471 for (i
= 0; i
< dock
->max_icons
; i
++) {
2472 btn
= dock
->icon_array
[i
];
2476 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2477 vmap
[btn
->yindex
] = 1;
2478 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2479 hmap
[-btn
->xindex
] = 1;
2481 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2483 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2484 vmap
[btn
->yindex
] = 1;
2485 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2486 hmap
[-btn
->xindex
] = 1;
2490 for (i
= 0; i
< dock
->max_icons
; i
++) {
2491 btn
= dock
->icon_array
[i
];
2495 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2496 vmap
[-btn
->yindex
] = 1;
2497 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2498 hmap
[btn
->xindex
] = 1;
2500 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2502 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2503 vmap
[-btn
->yindex
] = 1;
2504 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2505 hmap
[btn
->xindex
] = 1;
2510 for (i
= 0; i
< dock
->max_icons
; i
++) {
2511 btn
= dock
->icon_array
[i
];
2515 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2516 vmap
[-btn
->yindex
] = 1;
2517 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2518 hmap
[-btn
->xindex
] = 1;
2520 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2522 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2523 vmap
[-btn
->yindex
] = 1;
2524 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2525 hmap
[-btn
->xindex
] = 1;
2531 /* search a vacant slot */
2532 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2533 if (i
< vcount
&& vmap
[i
] == 0) {
2539 } else if (i
< hcount
&& hmap
[i
] == 0) {
2549 /* If found a slot, translate and return */
2551 if (corner
== C_NW
|| corner
== C_NE
) {
2556 if (corner
== C_NE
|| corner
== C_SE
) {
2563 /* else, try to find a slot somewhere else */
2566 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2567 * placed outside of screen */
2568 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2570 /* In the worst case (the clip is in the corner of the screen),
2571 * the amount of icons that fit in the clip is smaller.
2572 * Double the map to get a safe value.
2576 r
= (mwidth
- 1) / 2;
2578 slot_map
= wmalloc(mwidth
* mwidth
);
2580 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2582 /* mark used slots in the map. If the slot falls outside the map
2583 * (for example, when all icons are placed in line), ignore them. */
2584 for (i
= 0; i
< dock
->max_icons
; i
++) {
2585 btn
= dock
->icon_array
[i
];
2587 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2589 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2590 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2592 /* Find closest slot from the center that is free by scanning the
2593 * map from the center to outward in circular passes.
2594 * This will not result in a neat layout, but will be optimal
2595 * in the sense that there will not be holes left.
2598 for (i
= 1; i
<= r
&& !done
; i
++) {
2601 /* top and bottom parts of the ring */
2602 for (x
= -i
; x
<= i
&& !done
; x
++) {
2603 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2605 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2606 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2613 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2614 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2621 /* left and right parts of the ring */
2622 for (y
= -i
+ 1; y
<= i
- 1; y
++) {
2623 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2625 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2626 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2633 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2634 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2647 static void moveDock(WDock
*dock
, int new_x
, int new_y
)
2652 dock
->x_pos
= new_x
;
2653 dock
->y_pos
= new_y
;
2654 for (i
= 0; i
< dock
->max_icons
; i
++) {
2655 btn
= dock
->icon_array
[i
];
2657 btn
->x_pos
= new_x
+ btn
->xindex
* ICON_SIZE
;
2658 btn
->y_pos
= new_y
+ btn
->yindex
* ICON_SIZE
;
2659 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2664 static void swapDock(WDock
*dock
)
2666 WScreen
*scr
= dock
->screen_ptr
;
2670 if (dock
->on_right_side
) {
2671 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2673 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2676 for (i
= 0; i
< dock
->max_icons
; i
++) {
2677 btn
= dock
->icon_array
[i
];
2680 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2684 wScreenUpdateUsableArea(scr
);
2687 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2689 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2695 cmdline
= ExpandOptions(scr
, command
);
2697 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2705 wtokensplit(cmdline
, &argv
, &argc
);
2715 if ((pid
= fork()) == 0) {
2719 SetupEnvironment(scr
);
2725 args
= malloc(sizeof(char *) * (argc
+ 1));
2728 for (i
= 0; i
< argc
; i
++) {
2732 execvp(argv
[0], args
);
2735 wtokenfree(argv
, argc
);
2739 state
= wmalloc(sizeof(WSavedState
));
2741 state
->miniaturized
= -1;
2743 if (btn
->dock
== scr
->dock
|| btn
->omnipresent
)
2744 state
->workspace
= -1;
2746 state
->workspace
= scr
->current_workspace
;
2748 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
2749 wAddDeathHandler(pid
, (WDeathHandler
*) trackDeadProcess
, btn
->dock
);
2757 void wDockHideIcons(WDock
*dock
)
2764 for (i
= 1; i
< dock
->max_icons
; i
++) {
2765 if (dock
->icon_array
[i
])
2766 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2770 dockIconPaint(dock
->icon_array
[0]);
2773 void wDockShowIcons(WDock
*dock
)
2781 btn
= dock
->icon_array
[0];
2782 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2784 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2785 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2787 for (i
= 1; i
< dock
->max_icons
; i
++) {
2788 if (dock
->icon_array
[i
]) {
2789 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
, btn
->icon
->core
);
2794 if (!dock
->collapsed
) {
2795 for (i
= 1; i
< dock
->max_icons
; i
++) {
2796 if (dock
->icon_array
[i
]) {
2797 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2806 void wDockLower(WDock
*dock
)
2810 for (i
= 0; i
< dock
->max_icons
; i
++) {
2811 if (dock
->icon_array
[i
])
2812 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2816 void wDockRaise(WDock
*dock
)
2820 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
2821 if (dock
->icon_array
[i
])
2822 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2826 void wDockRaiseLower(WDock
*dock
)
2828 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2829 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2830 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2836 void wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
2838 icon
->launching
= 0;
2839 icon
->relaunching
= 0;
2840 dockIconPaint(icon
);
2843 WAppIcon
*wDockFindIconForWindow(WDock
*dock
, Window window
)
2848 for (i
= 0; i
< dock
->max_icons
; i
++) {
2849 icon
= dock
->icon_array
[i
];
2850 if (icon
&& icon
->main_window
== window
)
2856 void wDockTrackWindowLaunch(WDock
*dock
, Window window
)
2859 char *wm_class
, *wm_instance
;
2861 Bool firstPass
= True
;
2863 char *command
= NULL
;
2865 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) || (!wm_class
&& !wm_instance
)) {
2869 command
= GetCommandForWindow(window
);
2871 for (i
= 0; i
< dock
->max_icons
; i
++) {
2872 icon
= dock
->icon_array
[i
];
2876 /* app is already attached to icon */
2877 if (icon
->main_window
== window
) {
2882 if ((icon
->wm_instance
|| icon
->wm_class
)
2883 && (icon
->launching
|| !icon
->running
)) {
2885 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0) {
2888 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0) {
2891 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0) {
2895 if (!icon
->relaunching
) {
2898 /* Possibly an application that was docked with dockit,
2899 * but the user did not update WMState to indicate that
2900 * it was docked by force */
2901 wapp
= wApplicationOf(window
);
2903 icon
->forced_dock
= 1;
2906 if (!icon
->forced_dock
) {
2907 icon
->main_window
= window
;
2911 if (!wPreferences
.no_animations
&& !icon
->launching
&&
2912 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
2916 icon
->launching
= 1;
2917 dockIconPaint(icon
);
2919 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
2920 wm_instance
, wm_class
, TILE_NORMAL
);
2921 /* XXX: can: aicon->icon == NULL ? */
2922 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
2923 wAppIconMove(aicon
, x0
, y0
);
2924 /* Should this always be lowered? -Dan */
2926 wLowerFrame(aicon
->icon
->core
);
2927 XMapWindow(dpy
, aicon
->icon
->core
->window
);
2928 aicon
->launching
= 1;
2929 wAppIconPaint(aicon
);
2930 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
2931 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
2932 wAppIconDestroy(aicon
);
2934 wDockFinishLaunch(dock
, icon
);
2939 if (firstPass
&& !found
) {
2953 void wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
2955 if (!wPreferences
.flags
.noclip
) {
2956 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
2957 if (scr
->current_workspace
!= workspace
) {
2958 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
2959 WAppIconChain
*chain
= scr
->global_icons
;
2962 moveIconBetweenDocks(chain
->aicon
->dock
,
2963 scr
->workspaces
[workspace
]->clip
,
2964 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
2965 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
2966 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
2967 chain
= chain
->next
;
2970 wDockHideIcons(old_clip
);
2971 if (old_clip
->auto_raise_lower
) {
2972 if (old_clip
->auto_raise_magic
) {
2973 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
2974 old_clip
->auto_raise_magic
= NULL
;
2976 wDockLower(old_clip
);
2978 if (old_clip
->auto_collapse
) {
2979 if (old_clip
->auto_expand_magic
) {
2980 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
2981 old_clip
->auto_expand_magic
= NULL
;
2983 old_clip
->collapsed
= 1;
2985 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
2990 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
2995 for (i
= 0; i
< dock
->max_icons
; i
++) {
2996 icon
= dock
->icon_array
[i
];
3000 if (icon
->launching
&& icon
->pid
== pid
) {
3001 if (!icon
->relaunching
) {
3003 icon
->main_window
= None
;
3005 wDockFinishLaunch(dock
, icon
);
3007 if (status
== 111) {
3012 if (icon
->drop_launch
)
3013 cmd
= icon
->dnd_command
;
3016 if (icon
->paste_launch
)
3017 cmd
= icon
->paste_command
;
3019 cmd
= icon
->command
;
3021 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3023 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3030 static void toggleLowered(WDock
*dock
)
3035 /* lower/raise Dock */
3036 if (!dock
->lowered
) {
3037 newlevel
= WMNormalLevel
;
3040 newlevel
= WMDockLevel
;
3044 for (i
= 0; i
< dock
->max_icons
; i
++) {
3045 tmp
= dock
->icon_array
[i
];
3049 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3051 wLowerFrame(tmp
->icon
->core
);
3054 if (dock
->type
== WM_DOCK
)
3055 wScreenUpdateUsableArea(dock
->screen_ptr
);
3058 static void toggleCollapsed(WDock
*dock
)
3060 if (dock
->collapsed
) {
3061 dock
->collapsed
= 0;
3062 wDockShowIcons(dock
);
3064 dock
->collapsed
= 1;
3065 wDockHideIcons(dock
);
3069 static void openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3071 WScreen
*scr
= dock
->screen_ptr
;
3072 WObjDescriptor
*desc
;
3074 WApplication
*wapp
= NULL
;
3078 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3080 if (dock
->type
== WM_DOCK
) {
3082 entry
= dock
->menu
->entries
[index
];
3083 entry
->flags
.indicator_on
= !dock
->lowered
;
3084 entry
->clientdata
= dock
;
3085 dock
->menu
->flags
.realized
= 0;
3088 if (scr
->clip_options
)
3089 updateClipOptionsMenu(scr
->clip_options
, dock
);
3091 n_selected
= numberOfSelectedIcons(dock
);
3093 /* Rename Workspace */
3094 entry
= dock
->menu
->entries
[++index
];
3095 if (aicon
== scr
->clip_icon
) {
3096 entry
->callback
= renameCallback
;
3097 entry
->clientdata
= dock
;
3098 entry
->flags
.indicator
= 0;
3099 entry
->text
= _("Rename Workspace");
3101 entry
->callback
= omnipresentCallback
;
3102 entry
->clientdata
= aicon
;
3103 if (n_selected
> 0) {
3104 entry
->flags
.indicator
= 0;
3105 entry
->text
= _("Toggle Omnipresent");
3107 entry
->flags
.indicator
= 1;
3108 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3109 entry
->flags
.indicator_type
= MI_CHECK
;
3110 entry
->text
= _("Omnipresent");
3114 /* select/unselect icon */
3115 entry
= dock
->menu
->entries
[++index
];
3116 entry
->clientdata
= aicon
;
3117 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3118 wMenuSetEnabled(dock
->menu
, index
, aicon
!= scr
->clip_icon
);
3120 /* select/unselect all icons */
3121 entry
= dock
->menu
->entries
[++index
];
3122 entry
->clientdata
= aicon
;
3124 entry
->text
= _("Unselect All Icons");
3126 entry
->text
= _("Select All Icons");
3127 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3130 entry
= dock
->menu
->entries
[++index
];
3131 entry
->clientdata
= aicon
;
3133 entry
->text
= _("Keep Icons");
3135 entry
->text
= _("Keep Icon");
3136 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3138 /* this is the workspace submenu part */
3139 entry
= dock
->menu
->entries
[++index
];
3141 entry
->text
= _("Move Icons To");
3143 entry
->text
= _("Move Icon To");
3144 if (scr
->clip_submenu
)
3145 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3146 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3148 /* remove icon(s) */
3149 entry
= dock
->menu
->entries
[++index
];
3150 entry
->clientdata
= aicon
;
3152 entry
->text
= _("Remove Icons");
3154 entry
->text
= _("Remove Icon");
3155 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3157 /* attract icon(s) */
3158 entry
= dock
->menu
->entries
[++index
];
3159 entry
->clientdata
= aicon
;
3161 dock
->menu
->flags
.realized
= 0;
3162 wMenuRealize(dock
->menu
);
3165 if (aicon
->icon
->owner
) {
3166 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3172 entry
= dock
->menu
->entries
[++index
];
3173 entry
->clientdata
= aicon
;
3174 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3177 entry
= dock
->menu
->entries
[++index
];
3178 entry
->clientdata
= aicon
;
3179 if (wapp
&& wapp
->flags
.hidden
) {
3180 entry
->text
= _("Unhide Here");
3182 entry
->text
= _("Bring Here");
3184 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3187 entry
= dock
->menu
->entries
[++index
];
3188 entry
->clientdata
= aicon
;
3189 if (wapp
&& wapp
->flags
.hidden
) {
3190 entry
->text
= _("Unhide");
3192 entry
->text
= _("Hide");
3194 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3197 entry
= dock
->menu
->entries
[++index
];
3198 entry
->clientdata
= aicon
;
3199 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3202 entry
= dock
->menu
->entries
[++index
];
3203 entry
->clientdata
= aicon
;
3204 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3206 if (!dock
->menu
->flags
.realized
)
3207 wMenuRealize(dock
->menu
);
3209 if (dock
->type
== WM_CLIP
) {
3210 /*x_pos = event->xbutton.x_root+2; */
3211 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3214 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3215 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3218 x_pos
= dock
->on_right_side
? scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3221 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3223 /* allow drag select */
3224 event
->xany
.send_event
= True
;
3225 desc
= &dock
->menu
->menu
->descriptor
;
3226 (*desc
->handle_mousedown
) (desc
, event
);
3229 /******************************************************************/
3230 static void iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3232 WAppIcon
*btn
= desc
->parent
;
3233 WDock
*dock
= btn
->dock
;
3234 WApplication
*wapp
= NULL
;
3237 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3238 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3240 assert(wapp
!= NULL
);
3242 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3244 /* go to the last workspace that the user worked on the app */
3245 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
&& !unhideHere
) {
3246 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3249 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3251 if (event
->xbutton
.state
& MOD_MASK
) {
3252 wHideOtherApplications(btn
->icon
->owner
);
3255 if (event
->xbutton
.button
== Button1
) {
3257 if (event
->xbutton
.state
& MOD_MASK
) {
3258 /* raise/lower dock */
3259 toggleLowered(dock
);
3260 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3261 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
)
3262 toggleCollapsed(dock
);
3264 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3265 } else if (btn
->command
) {
3266 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3267 launchDockedApplication(btn
, False
);
3273 static void handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3275 WScreen
*scr
= dock
->screen_ptr
;
3276 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3279 int grabbed
= 0, swapped
= 0, done
;
3280 Pixmap ghost
= None
;
3281 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3283 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3284 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3285 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3286 wwarning("pointer grab failed for dock move");
3289 for (x
= 0; x
< dock
->max_icons
; x
++) {
3290 if (dock
->icon_array
[x
] != NULL
&& dock
->icon_array
[x
]->yindex
> y
)
3291 y
= dock
->icon_array
[x
]->yindex
;
3294 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
* y
);
3298 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3299 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3306 /* It means the cursor moved so fast that it entered
3307 * something else (if moving slowly, it would have
3308 * stayed in the dock that is being moved. Ignore such
3309 * "spurious" EnterNotifiy's */
3314 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3315 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3316 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3317 | ButtonReleaseMask
| ButtonPressMask
,
3318 wCursor
[WCUR_MOVE
], CurrentTime
);
3323 if (dock
->type
== WM_CLIP
) {
3324 x
= ev
.xmotion
.x_root
- ofs_x
;
3325 y
= ev
.xmotion
.y_root
- ofs_y
;
3326 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3328 moveDock(dock
, x
, y
);
3330 /* move vertically if pointer is inside the dock */
3331 if ((dock
->on_right_side
&& ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3332 || (!dock
->on_right_side
&& ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
* 2)) {
3334 x
= ev
.xmotion
.x_root
- ofs_x
;
3335 y
= ev
.xmotion
.y_root
- ofs_y
;
3336 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3337 moveDock(dock
, dock
->x_pos
, y
);
3339 /* move horizontally to change sides */
3340 x
= ev
.xmotion
.x_root
- ofs_x
;
3341 if (!dock
->on_right_side
) {
3345 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
* 2) {
3346 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
- ICON_SIZE
3347 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3348 if (superfluous
&& ghost
== None
) {
3349 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3350 scr
->scr_width
- ICON_SIZE
3351 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3352 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3353 XClearWindow(dpy
, scr
->dock_shadow
);
3355 XMapRaised(dpy
, scr
->dock_shadow
);
3358 if (superfluous
&& ghost
!= None
) {
3359 XFreePixmap(dpy
, ghost
);
3362 XUnmapWindow(dpy
, scr
->dock_shadow
);
3367 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3368 XMoveWindow(dpy
, scr
->dock_shadow
, DOCK_EXTRA_SPACE
, dock
->y_pos
);
3369 if (superfluous
&& ghost
== None
) {
3370 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3371 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3372 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3373 XClearWindow(dpy
, scr
->dock_shadow
);
3375 XMapRaised(dpy
, scr
->dock_shadow
);
3378 XUnmapWindow(dpy
, scr
->dock_shadow
);
3380 if (superfluous
&& ghost
!= None
) {
3381 XFreePixmap(dpy
, ghost
);
3393 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3395 XUngrabPointer(dpy
, CurrentTime
);
3396 XUnmapWindow(dpy
, scr
->dock_shadow
);
3397 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3398 if (dock
->type
== WM_DOCK
) {
3401 dock
->on_right_side
= 1;
3403 dock
->on_right_side
= 0;
3405 wArrangeIcons(scr
, False
);
3414 XFreePixmap(dpy
, ghost
);
3415 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3419 static Bool
handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3421 WScreen
*scr
= dock
->screen_ptr
;
3423 WIcon
*icon
= aicon
->icon
;
3424 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3425 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3427 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3428 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3429 int shad_x
= x
, shad_y
= y
;
3430 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3432 Pixmap ghost
= None
;
3434 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3435 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3436 Bool hasMoved
= False
;
3438 if (wPreferences
.flags
.noupdates
)
3441 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3442 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3443 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3446 if (!(event
->xbutton
.state
& MOD_MASK
))
3447 wRaiseFrame(icon
->core
);
3449 if (!wPreferences
.flags
.noclip
)
3450 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3452 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3454 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3457 wins
[0] = icon
->core
->window
;
3458 wins
[1] = scr
->dock_shadow
;
3459 XRestackWindows(dpy
, wins
, 2);
3460 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
3462 if (icon
->pixmap
!= None
)
3463 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3465 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3467 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3468 XClearWindow(dpy
, scr
->dock_shadow
);
3470 XMapWindow(dpy
, scr
->dock_shadow
);
3475 XMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3476 | ButtonMotionMask
| ExposureMask
, &ev
);
3485 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3486 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3487 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3488 | ButtonReleaseMask
| ButtonPressMask
,
3489 wCursor
[WCUR_MOVE
], CurrentTime
);
3498 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3499 if (i
== scr
->current_workspace
)
3501 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3505 x
= ev
.xmotion
.x_root
- ofs_x
;
3506 y
= ev
.xmotion
.y_root
- ofs_y
;
3507 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3510 if (last_dock
!= dock
&& collapsed
) {
3511 last_dock
->collapsed
= 1;
3512 wDockHideIcons(last_dock
);
3515 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3516 dock
->collapsed
= 0;
3517 wDockShowIcons(dock
);
3519 if (dock
->auto_raise_lower
)
3523 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3526 if (last_dock
!= dock2
&& collapsed
) {
3527 last_dock
->collapsed
= 1;
3528 wDockHideIcons(last_dock
);
3531 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3532 dock2
->collapsed
= 0;
3533 wDockShowIcons(dock2
);
3535 if (dock2
->auto_raise_lower
)
3540 if (aicon
->launching
|| aicon
->lock
|| (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3541 || (!aicon
->running
&& tmp
)) {
3542 shad_x
= last_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3543 shad_y
= last_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3545 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3548 XMapWindow(dpy
, scr
->dock_shadow
);
3553 XUnmapWindow(dpy
, scr
->dock_shadow
);
3557 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3564 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3566 XUngrabPointer(dpy
, CurrentTime
);
3568 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3569 XUnmapWindow(dpy
, scr
->dock_shadow
);
3571 reattachIcon(dock
, aicon
, ix
, iy
);
3572 if (clip
&& dock
!= clip
&& clip
->auto_raise_lower
)
3575 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3577 /* Slide it back if dock rejected it */
3578 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
, aicon
->y_pos
);
3579 reattachIcon(dock
, aicon
, aicon
->xindex
, aicon
->yindex
);
3581 if (last_dock
->type
== WM_CLIP
&& last_dock
->auto_collapse
) {
3589 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3590 /* We need to deselect it, even if is deselected in
3591 * wDockDetach(), because else DoKaboom() will fail.
3593 if (aicon
->icon
->selected
)
3594 wIconSelect(aicon
->icon
);
3596 DoKaboom(scr
, aicon
->icon
->core
->window
, x
, y
);
3599 if (clip
&& clip
->auto_raise_lower
)
3601 wDockDetach(dock
, aicon
);
3604 last_dock
->collapsed
= 1;
3605 wDockHideIcons(last_dock
);
3610 XFreePixmap(dpy
, ghost
);
3611 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3615 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3616 if (i
== scr
->current_workspace
)
3618 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3624 return False
; /* never reached */
3627 static int getClipButton(int px
, int py
)
3629 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3631 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3634 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3635 return CLIP_FORWARD
;
3636 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3642 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3645 int done
, direction
, new_ws
;
3647 WDock
*clip
= scr
->clip_icon
->dock
;
3649 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3651 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3652 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3654 wClipIconPaint(scr
->clip_icon
);
3657 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3664 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3665 if (new_dir
!= direction
) {
3666 direction
= new_dir
;
3667 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3668 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3669 wClipIconPaint(scr
->clip_icon
);
3677 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3682 clip
->lclip_button_pushed
= 0;
3683 clip
->rclip_button_pushed
= 0;
3685 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3687 if (direction
== CLIP_FORWARD
) {
3688 if (scr
->current_workspace
< scr
->workspace_count
- 1)
3689 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3690 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
- 1)
3691 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3692 else if (wPreferences
.ws_cycle
)
3693 wWorkspaceChange(scr
, 0);
3694 } else if (direction
== CLIP_REWIND
) {
3695 if (scr
->current_workspace
> 0)
3696 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
3697 else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
)
3698 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
3701 wClipIconPaint(scr
->clip_icon
);
3704 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3706 WAppIcon
*aicon
= desc
->parent
;
3707 WDock
*dock
= aicon
->dock
;
3708 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3710 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3713 scr
->last_dock
= dock
;
3715 if (dock
->menu
->flags
.mapped
)
3716 wMenuUnmap(dock
->menu
);
3718 if (IsDoubleClick(scr
, event
)) {
3719 /* double-click was not in the main clip icon */
3720 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3721 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3722 iconDblClick(desc
, event
);
3727 if (event
->xbutton
.button
== Button1
) {
3728 if (event
->xbutton
.state
& MOD_MASK
)
3733 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
&& dock
->type
!= WM_DOCK
) {
3734 wIconSelect(aicon
->icon
);
3738 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3739 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
3740 && dock
->type
== WM_CLIP
)
3741 handleClipChangeWorkspace(scr
, event
);
3743 handleDockMove(dock
, aicon
, event
);
3745 Bool hasMoved
= handleIconMove(dock
, aicon
, event
);
3746 if (wPreferences
.single_click
&& !hasMoved
)
3747 iconDblClick(desc
, event
);
3749 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&& aicon
== scr
->clip_icon
) {
3750 if (!scr
->clip_ws_menu
) {
3751 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3753 if (scr
->clip_ws_menu
) {
3754 WMenu
*wsMenu
= scr
->clip_ws_menu
;
3757 wWorkspaceMenuUpdate(scr
, wsMenu
);
3759 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
3762 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
3763 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
3765 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
3767 desc
= &wsMenu
->menu
->descriptor
;
3768 event
->xany
.send_event
= True
;
3769 (*desc
->handle_mousedown
) (desc
, event
);
3771 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
3772 (event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
) {
3773 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3774 } else if (event
->xbutton
.button
== Button3
) {
3775 if (event
->xbutton
.send_event
&&
3776 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3777 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3778 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3779 wwarning("pointer grab failed for dockicon menu");
3783 openDockMenu(dock
, aicon
, event
);
3784 } else if (event
->xbutton
.button
== Button2
) {
3785 WAppIcon
*btn
= desc
->parent
;
3787 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3788 launchDockedApplication(btn
, True
);
3793 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3795 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3799 assert(event
->type
== EnterNotify
);
3801 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3804 scr
= btn
->icon
->core
->screen_ptr
;
3805 if (!btn
->omnipresent
)
3808 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3810 if (!dock
|| dock
->type
!= WM_CLIP
)
3813 /* The auto raise/lower code */
3814 if (dock
->auto_lower_magic
) {
3815 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3816 dock
->auto_lower_magic
= NULL
;
3818 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
3819 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
, clipAutoRaise
, (void *)dock
);
3822 /* The auto expand/collapse code */
3823 if (dock
->auto_collapse_magic
) {
3824 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3825 dock
->auto_collapse_magic
= NULL
;
3827 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
3828 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
, clipAutoExpand
, (void *)dock
);
3832 static void clipLeave(WDock
*dock
)
3835 WObjDescriptor
*desc
= NULL
;
3837 if (!dock
|| dock
->type
!= WM_CLIP
)
3840 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
3841 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3842 (XPointer
*) & desc
) != XCNOENT
3843 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
3844 && ((WAppIcon
*) desc
->parent
)->dock
&& ((WAppIcon
*) desc
->parent
)->dock
->type
== WM_CLIP
) {
3845 /* We didn't left the Clip yet */
3846 XPutBackEvent(dpy
, &event
);
3850 XPutBackEvent(dpy
, &event
);
3852 /* We entered a withdrawn window, so we're still in Clip */
3856 if (dock
->auto_raise_magic
) {
3857 WMDeleteTimerHandler(dock
->auto_raise_magic
);
3858 dock
->auto_raise_magic
= NULL
;
3860 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
3861 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
, clipAutoLower
, (void *)dock
);
3864 if (dock
->auto_expand_magic
) {
3865 WMDeleteTimerHandler(dock
->auto_expand_magic
);
3866 dock
->auto_expand_magic
= NULL
;
3868 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
3869 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
, clipAutoCollapse
, (void *)dock
);
3873 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
3875 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3877 assert(event
->type
== LeaveNotify
);
3879 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3882 clipLeave(btn
->dock
);
3885 static void clipAutoCollapse(void *cdata
)
3887 WDock
*dock
= (WDock
*) cdata
;
3889 if (dock
->type
!= WM_CLIP
)
3892 if (dock
->auto_collapse
) {
3893 dock
->collapsed
= 1;
3894 wDockHideIcons(dock
);
3896 dock
->auto_collapse_magic
= NULL
;
3899 static void clipAutoExpand(void *cdata
)
3901 WDock
*dock
= (WDock
*) cdata
;
3903 if (dock
->type
!= WM_CLIP
)
3906 if (dock
->auto_collapse
) {
3907 dock
->collapsed
= 0;
3908 wDockShowIcons(dock
);
3910 dock
->auto_expand_magic
= NULL
;
3913 static void clipAutoLower(void *cdata
)
3915 WDock
*dock
= (WDock
*) cdata
;
3917 if (dock
->type
!= WM_CLIP
)
3920 if (dock
->auto_raise_lower
)
3923 dock
->auto_lower_magic
= NULL
;
3926 static void clipAutoRaise(void *cdata
)
3928 WDock
*dock
= (WDock
*) cdata
;
3930 if (dock
->type
!= WM_CLIP
)
3933 if (dock
->auto_raise_lower
)
3936 dock
->auto_raise_magic
= NULL
;
3939 static Bool
iconCanBeOmnipresent(WAppIcon
*aicon
)
3941 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3946 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3947 clip
= scr
->workspaces
[i
]->clip
;
3949 if (clip
== aicon
->dock
)
3952 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
3953 return False
; /* Clip is full in some workspace */
3955 for (j
= 0; j
< clip
->max_icons
; j
++) {
3956 btn
= clip
->icon_array
[j
];
3957 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
3965 int wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
3967 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3968 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
3969 int status
= WO_SUCCESS
;
3971 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== scr
->clip_icon
) {
3972 return WO_NOT_APPLICABLE
;
3975 if (aicon
->omnipresent
== omnipresent
)
3979 if (iconCanBeOmnipresent(aicon
)) {
3980 aicon
->omnipresent
= 1;
3981 new_entry
= wmalloc(sizeof(WAppIconChain
));
3982 new_entry
->aicon
= aicon
;
3983 new_entry
->next
= scr
->global_icons
;
3984 scr
->global_icons
= new_entry
;
3985 scr
->global_icon_count
++;
3987 aicon
->omnipresent
= 0;
3991 aicon
->omnipresent
= 0;
3992 if (aicon
== scr
->global_icons
->aicon
) {
3993 tmp
= scr
->global_icons
->next
;
3994 wfree(scr
->global_icons
);
3995 scr
->global_icons
= tmp
;
3996 scr
->global_icon_count
--;
3998 tmp
= scr
->global_icons
;
4000 if (tmp
->next
->aicon
== aicon
) {
4001 tmp1
= tmp
->next
->next
;
4004 scr
->global_icon_count
--;
4012 wAppIconPaint(aicon
);