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"
46 #include "dockedapp.h"
49 #include "properties.h"
53 #include "workspace.h"
55 #include "superfluous.h"
58 /**** Local variables ****/
61 #define CLIP_FORWARD 2
63 /**** Global variables ****/
64 extern Cursor wCursor
[WCUR_LAST
];
65 extern WPreferences wPreferences
;
66 extern XContext wWinContext
;
67 extern void appIconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
69 #define MOD_MASK wPreferences.modifier_mask
70 #define ICON_SIZE wPreferences.icon_size
72 /***** Local variables ****/
74 static WMPropList
*dCommand
= NULL
;
75 static WMPropList
*dPasteCommand
= NULL
;
76 #ifdef XDND /* XXX was OFFIX */
77 static WMPropList
*dDropCommand
= NULL
;
79 static WMPropList
*dAutoLaunch
, *dLock
;
80 static WMPropList
*dName
, *dForced
, *dBuggyApplication
, *dYes
, *dNo
;
81 static WMPropList
*dHost
, *dDock
, *dClip
;
82 static WMPropList
*dAutoAttractIcons
;
84 static WMPropList
*dPosition
, *dApplications
, *dLowered
, *dCollapsed
;
86 static WMPropList
*dAutoCollapse
, *dAutoRaiseLower
, *dOmnipresent
;
88 static void dockIconPaint(WAppIcon
*btn
);
90 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
92 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
);
94 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
96 static int getClipButton(int px
, int py
);
98 static void toggleLowered(WDock
*dock
);
100 static void toggleCollapsed(WDock
*dock
);
102 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
104 static void clipLeave(WDock
*dock
);
106 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
108 static Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
);
110 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
111 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
112 static void clipAutoCollapse(void *cdata
);
113 static void clipAutoExpand(void *cdata
);
114 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
);
116 static void clipAutoLower(void *cdata
);
117 static void clipAutoRaise(void *cdata
);
118 static void reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
);
119 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
);
121 static void make_keys(void)
123 if (dCommand
!= NULL
)
126 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
127 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
129 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
131 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
132 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
133 dName
= WMRetainPropList(WMCreatePLString("Name"));
134 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
135 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
136 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
137 dNo
= WMRetainPropList(WMCreatePLString("No"));
138 dHost
= WMRetainPropList(WMCreatePLString("Host"));
140 dPosition
= WMCreatePLString("Position");
141 dApplications
= WMCreatePLString("Applications");
142 dLowered
= WMCreatePLString("Lowered");
143 dCollapsed
= WMCreatePLString("Collapsed");
144 dAutoCollapse
= WMCreatePLString("AutoCollapse");
145 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
146 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
148 dOmnipresent
= WMCreatePLString("Omnipresent");
150 dDock
= WMCreatePLString("Dock");
151 dClip
= WMCreatePLString("Clip");
154 static void renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
156 WDock
*dock
= entry
->clientdata
;
161 assert(entry
->clientdata
!= NULL
);
163 wspace
= dock
->screen_ptr
->current_workspace
;
165 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
167 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+ 1);
168 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
, &name
))
169 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
174 static void toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
176 assert(entry
->clientdata
!= NULL
);
178 toggleLowered(entry
->clientdata
);
180 entry
->flags
.indicator_on
= !(((WDock
*) entry
->clientdata
)->lowered
);
185 static int matchWindow(const void *item
, const void *cdata
)
187 return (((WFakeGroupLeader
*) item
)->leader
== (Window
) cdata
);
190 static void killCallback(WMenu
*menu
, WMenuEntry
*entry
)
192 WScreen
*scr
= menu
->menu
->screen_ptr
;
194 WFakeGroupLeader
*fPtr
;
195 char *buffer
, *shortname
, **argv
;
196 char *basename(const char *shortname
);
199 if (!WCHECK_STATE(WSTATE_NORMAL
))
202 assert(entry
->clientdata
!= NULL
);
204 icon
= (WAppIcon
*) entry
->clientdata
;
208 WCHANGE_STATE(WSTATE_MODAL
);
210 /* strip away dir names */
211 shortname
= basename(icon
->command
);
212 /* separate out command options */
213 wtokensplit(shortname
, &argv
, &argc
);
215 buffer
= wstrconcat(argv
[0],
216 _(" will be forcibly closed.\n"
217 "Any unsaved changes will be lost.\n" "Please confirm."));
219 if (icon
->icon
&& icon
->icon
->owner
) {
220 fPtr
= icon
->icon
->owner
->fake_group
;
222 /* is this really necessary? can we kill a non-running dock icon? */
223 Window win
= icon
->main_window
;
226 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)win
);
227 if (index
!= WANotFound
)
228 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
233 if (wPreferences
.dont_confirm_kill
234 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
235 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
237 WWindow
*wwin
, *twin
;
239 wwin
= scr
->focused_window
;
242 if (wwin
->fake_group
== fPtr
)
247 } else if (icon
->icon
&& icon
->icon
->owner
) {
248 wClientKill(icon
->icon
->owner
);
253 wtokenfree(argv
, argc
);
257 WCHANGE_STATE(WSTATE_NORMAL
);
260 /* TODO: replace this function with a member of the dock struct */
261 static int numberOfSelectedIcons(WDock
*dock
)
267 for (i
= 1; i
< dock
->max_icons
; i
++) {
268 aicon
= dock
->icon_array
[i
];
269 if (aicon
&& aicon
->icon
->selected
)
276 static WMArray
*getSelected(WDock
*dock
)
278 WMArray
*ret
= WMCreateArray(8);
282 for (i
= 1; i
< dock
->max_icons
; i
++) {
283 btn
= dock
->icon_array
[i
];
284 if (btn
&& btn
->icon
->selected
)
285 WMAddToArray(ret
, btn
);
291 static void paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
293 Window win
= clipIcon
->icon
->core
->window
;
294 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
296 int pt
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
297 int tp
= ICON_SIZE
- pt
;
298 int as
= pt
- 15; /* 15 = 5+5+5 */
299 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
302 color
= scr
->clip_title_color
[CLIP_NORMAL
];
304 XSetForeground(dpy
, gc
, WMColorPixel(color
));
309 p
[1].x
= ICON_SIZE
- 2;
311 p
[2].x
= ICON_SIZE
- 2;
313 } else if (lpushed
) {
317 p
[1].y
= ICON_SIZE
- 2;
319 p
[2].y
= ICON_SIZE
- 2;
321 if (lpushed
|| rpushed
) {
322 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
323 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
324 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
327 /* top right arrow */
328 p
[0].x
= p
[3].x
= ICON_SIZE
- 5 - as
;
330 p
[1].x
= ICON_SIZE
- 6;
332 p
[2].x
= ICON_SIZE
- 6;
335 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
336 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
338 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
339 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
342 /* bottom left arrow */
344 p
[0].y
= p
[3].y
= ICON_SIZE
- 5 - as
;
346 p
[1].y
= ICON_SIZE
- 6;
348 p
[2].y
= ICON_SIZE
- 6;
350 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
351 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
353 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
354 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
358 RImage
*wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
360 RImage
*tile
= RCloneImage(normalTile
);
367 pt
= CLIP_BUTTON_SIZE
* wPreferences
.icon_size
/ 64;
368 tp
= wPreferences
.icon_size
- 1 - pt
;
372 black
.red
= black
.green
= black
.blue
= 0;
375 dark
.red
= dark
.green
= dark
.blue
= 60;
378 light
.red
= light
.green
= light
.blue
= 80;
381 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
- 2, pt
- 1, &dark
);
382 RDrawLine(tile
, tp
- 1, 0, wPreferences
.icon_size
- 1, pt
+ 1, &black
);
383 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
- 3, pt
, &light
);
386 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, 4, &dark
);
387 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 5, 6 + as
, &dark
);
388 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
, &light
);
391 ROperateLine(tile
, RAddOperation
, 2, tp
+ 2, pt
- 2, wPreferences
.icon_size
- 3, &dark
);
392 RDrawLine(tile
, 0, tp
- 1, pt
+ 1, wPreferences
.icon_size
- 1, &black
);
393 ROperateLine(tile
, RSubtractOperation
, 0, tp
- 2, pt
+ 1, wPreferences
.icon_size
- 2, &light
);
396 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, &dark
);
397 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
, 6 + as
, ICON_SIZE
- 5, &dark
);
398 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5, &light
);
403 static void omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
405 WAppIcon
*clickedIcon
= entry
->clientdata
;
408 WMArray
*selectedIcons
;
409 WMArrayIterator iter
;
412 assert(entry
->clientdata
!= NULL
);
414 dock
= clickedIcon
->dock
;
416 selectedIcons
= getSelected(dock
);
418 if (!WMGetArrayItemCount(selectedIcons
))
419 WMAddToArray(selectedIcons
, clickedIcon
);
422 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
423 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
425 else if (aicon
->icon
->selected
)
426 wIconSelect(aicon
->icon
);
428 WMFreeArray(selectedIcons
);
431 wMessageDialog(dock
->screen_ptr
, _("Warning"),
432 _("Some icons cannot be made omnipresent. "
433 "Please make sure that no other icon is "
434 "docked in the same positions on the other "
435 "workspaces and the Clip is not full in "
436 "some workspace."), _("OK"), NULL
, NULL
);
437 } else if (failed
== 1) {
438 wMessageDialog(dock
->screen_ptr
, _("Warning"),
439 _("Icon cannot be made omnipresent. "
440 "Please make sure that no other icon is "
441 "docked in the same position on the other "
442 "workspaces and the Clip is not full in "
443 "some workspace."), _("OK"), NULL
, NULL
);
447 static void removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
449 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
452 WMArray
*selectedIcons
;
456 assert(clickedIcon
!= NULL
);
458 dock
= clickedIcon
->dock
;
460 selectedIcons
= getSelected(dock
);
462 if (WMGetArrayItemCount(selectedIcons
)) {
463 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
464 _("All selected icons will be removed!"),
465 _("OK"), _("Cancel"), NULL
) != WAPRDefault
) {
466 WMFreeArray(selectedIcons
);
470 if (clickedIcon
->xindex
== 0 && clickedIcon
->yindex
== 0) {
471 WMFreeArray(selectedIcons
);
474 WMAddToArray(selectedIcons
, clickedIcon
);
477 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
478 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
479 wDockDetach(dock
, aicon
);
481 /* XXX: can: aicon->icon == NULL ? */
482 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
483 wGetHeadForWindow(aicon
->icon
->owner
));
484 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
485 if (!dock
->mapped
|| dock
->collapsed
)
486 XMapWindow(dpy
, aicon
->icon
->core
->window
);
489 WMFreeArray(selectedIcons
);
491 if (wPreferences
.auto_arrange_icons
)
492 wArrangeIcons(dock
->screen_ptr
, True
);
495 static void keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
497 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
500 WMArray
*selectedIcons
;
503 assert(clickedIcon
!= NULL
);
504 dock
= clickedIcon
->dock
;
506 selectedIcons
= getSelected(dock
);
508 if (!WMGetArrayItemCount(selectedIcons
)
509 && clickedIcon
!= dock
->screen_ptr
->clip_icon
) {
510 char *command
= NULL
;
512 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
513 clickedIcon
->editing
= 1;
514 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
515 _("Type the command used to launch the application"), &command
)) {
516 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
520 clickedIcon
->command
= command
;
521 clickedIcon
->editing
= 0;
523 clickedIcon
->editing
= 0;
526 WMFreeArray(selectedIcons
);
531 WMAddToArray(selectedIcons
, clickedIcon
);
534 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
535 if (aicon
->icon
->selected
)
536 wIconSelect(aicon
->icon
);
538 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
539 aicon
->attracted
= 0;
540 if (aicon
->icon
->shadowed
) {
541 aicon
->icon
->shadowed
= 0;
543 /* Update the icon images */
544 wIconUpdate(aicon
->icon
, NULL
);
547 wAppIconPaint(aicon
);
550 save_appicon(aicon
, True
);
552 WMFreeArray(selectedIcons
);
555 static void toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
557 WDock
*dock
= (WDock
*) entry
->clientdata
;
559 assert(entry
->clientdata
!= NULL
);
561 dock
->attract_icons
= !dock
->attract_icons
;
563 entry
->flags
.indicator_on
= dock
->attract_icons
;
568 static void selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
570 WAppIcon
*icon
= (WAppIcon
*) entry
->clientdata
;
572 assert(icon
!= NULL
);
574 wIconSelect(icon
->icon
);
579 static void colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
581 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
584 int x
, y
, x_pos
, y_pos
;
585 Bool update_icon
= False
;
587 assert(entry
->clientdata
!= NULL
);
588 clip
= clickedIcon
->dock
;
590 aicon
= clip
->screen_ptr
->app_icon_list
;
593 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
594 x_pos
= clip
->x_pos
+ x
* ICON_SIZE
;
595 y_pos
= clip
->y_pos
+ y
* ICON_SIZE
;
596 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
)
597 move_window(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
599 aicon
->attracted
= 1;
600 if (!aicon
->icon
->shadowed
) {
601 aicon
->icon
->shadowed
= 1;
604 wDockAttachIcon(clip
, aicon
, x
, y
, update_icon
);
605 if (clip
->collapsed
|| !clip
->mapped
)
606 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
612 static void selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
614 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
616 WMArray
*selectedIcons
;
617 WMArrayIterator iter
;
621 assert(clickedIcon
!= NULL
);
622 dock
= clickedIcon
->dock
;
624 selectedIcons
= getSelected(dock
);
626 if (!WMGetArrayItemCount(selectedIcons
)) {
627 for (i
= 1; i
< dock
->max_icons
; i
++) {
628 btn
= dock
->icon_array
[i
];
629 if (btn
&& !btn
->icon
->selected
)
630 wIconSelect(btn
->icon
);
633 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
634 wIconSelect(btn
->icon
);
637 WMFreeArray(selectedIcons
);
642 static void toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
644 assert(entry
->clientdata
!= NULL
);
646 toggleCollapsed(entry
->clientdata
);
648 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->collapsed
;
653 static void toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
656 assert(entry
->clientdata
!= NULL
);
658 dock
= (WDock
*) entry
->clientdata
;
660 dock
->auto_collapse
= !dock
->auto_collapse
;
662 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_collapse
;
667 static void toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
670 assert(entry
->clientdata
!= NULL
);
672 dock
= (WDock
*) entry
->clientdata
;
674 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
676 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_raise_lower
;
681 static void launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
683 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
685 launchDockedApplication(btn
, False
);
688 static void settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
690 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
694 ShowDockAppSettingsPanel(btn
);
697 static void hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
700 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
702 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
704 if (wapp
->flags
.hidden
) {
705 wWorkspaceChange(btn
->icon
->core
->screen_ptr
, wapp
->last_workspace
);
706 wUnhideApplication(wapp
, False
, False
);
708 wHideApplication(wapp
);
712 static void unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
715 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
717 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
719 wUnhideApplication(wapp
, False
, True
);
722 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
)
727 if (type
== WM_CLIP
) {
729 return scr
->clip_icon
;
730 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
731 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
732 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
733 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
736 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
737 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
743 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
744 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
745 btn
->icon
->core
->descriptor
.parent
= btn
;
746 XMapWindow(dpy
, btn
->icon
->core
->window
);
751 scr
->clip_icon
= btn
;
756 static void switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
758 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
759 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
761 WMArray
*selectedIcons
;
764 if (entry
->order
== scr
->current_workspace
)
767 dest
= scr
->workspaces
[entry
->order
]->clip
;
769 selectedIcons
= getSelected(src
);
771 if (WMGetArrayItemCount(selectedIcons
)) {
772 WMArrayIterator iter
;
774 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
775 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
776 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
777 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
780 } else if (icon
!= scr
->clip_icon
) {
781 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
782 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
783 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
786 WMFreeArray(selectedIcons
);
789 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
)
791 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
793 if (!btn
->launching
&&
794 ((!withSelection
&& btn
->command
!= NULL
) || (withSelection
&& btn
->paste_command
!= NULL
))) {
795 if (!btn
->forced_dock
) {
796 btn
->relaunching
= btn
->running
;
799 if (btn
->wm_instance
|| btn
->wm_class
) {
800 WWindowAttributes attr
;
801 memset(&attr
, 0, sizeof(WWindowAttributes
));
802 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
804 if (!attr
.no_appicon
&& !btn
->buggy_app
)
809 btn
->drop_launch
= 0;
810 btn
->paste_launch
= withSelection
;
811 scr
->last_dock
= btn
->dock
;
812 btn
->pid
= execCommand(btn
, (withSelection
? btn
->paste_command
: btn
->command
), NULL
);
814 if (btn
->buggy_app
) {
815 /* give feedback that the app was launched */
819 WMAddTimerHandler(200, (WMCallback
*) dockIconPaint
, btn
);
824 wwarning(_("could not launch application %s"), btn
->command
);
826 if (!btn
->relaunching
)
832 static void updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
834 WScreen
*scr
= menu
->frame
->screen_ptr
;
835 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
841 for (i
= 0; i
< scr
->workspace_count
; i
++) {
842 if (i
< menu
->entry_no
) {
843 if (strcmp(menu
->entries
[i
]->text
, scr
->workspaces
[i
]->name
) != 0) {
844 wfree(menu
->entries
[i
]->text
);
845 strcpy(title
, scr
->workspaces
[i
]->name
);
846 menu
->entries
[i
]->text
= wstrdup(title
);
847 menu
->flags
.realized
= 0;
849 menu
->entries
[i
]->clientdata
= (void *)icon
;
851 strcpy(title
, scr
->workspaces
[i
]->name
);
853 wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)icon
);
855 menu
->flags
.realized
= 0;
858 if (i
== scr
->current_workspace
)
859 wMenuSetEnabled(menu
, i
, False
);
861 wMenuSetEnabled(menu
, i
, True
);
864 if (!menu
->flags
.realized
)
868 static WMenu
*makeWorkspaceMenu(WScreen
*scr
)
872 menu
= wMenuCreate(scr
, NULL
, False
);
874 wwarning(_("could not create workspace submenu for Clip menu"));
876 wMenuAddCallback(menu
, "", switchWSCommand
, (void *)scr
->clip_icon
);
878 menu
->flags
.realized
= 0;
884 static void updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
893 entry
= menu
->entries
[index
];
894 entry
->flags
.indicator_on
= !dock
->lowered
;
895 entry
->clientdata
= dock
;
898 entry
= menu
->entries
[++index
];
899 entry
->flags
.indicator_on
= dock
->collapsed
;
900 entry
->clientdata
= dock
;
903 entry
= menu
->entries
[++index
];
904 entry
->flags
.indicator_on
= dock
->auto_collapse
;
905 entry
->clientdata
= dock
;
907 /* auto-raise/lower */
908 entry
= menu
->entries
[++index
];
909 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
910 entry
->clientdata
= dock
;
911 wMenuSetEnabled(menu
, index
, dock
->lowered
);
914 entry
= menu
->entries
[++index
];
915 entry
->flags
.indicator_on
= dock
->attract_icons
;
916 entry
->clientdata
= dock
;
918 menu
->flags
.realized
= 0;
922 static WMenu
*makeClipOptionsMenu(WScreen
*scr
)
927 menu
= wMenuCreate(scr
, NULL
, False
);
929 wwarning(_("could not create options submenu for Clip menu"));
933 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
934 entry
->flags
.indicator
= 1;
935 entry
->flags
.indicator_on
= 1;
936 entry
->flags
.indicator_type
= MI_CHECK
;
938 entry
= wMenuAddCallback(menu
, _("Collapsed"), toggleCollapsedCallback
, NULL
);
939 entry
->flags
.indicator
= 1;
940 entry
->flags
.indicator_on
= 1;
941 entry
->flags
.indicator_type
= MI_CHECK
;
943 entry
= wMenuAddCallback(menu
, _("Autocollapse"), toggleAutoCollapseCallback
, NULL
);
944 entry
->flags
.indicator
= 1;
945 entry
->flags
.indicator_on
= 1;
946 entry
->flags
.indicator_type
= MI_CHECK
;
948 entry
= wMenuAddCallback(menu
, _("Autoraise"), toggleAutoRaiseLowerCallback
, NULL
);
949 entry
->flags
.indicator
= 1;
950 entry
->flags
.indicator_on
= 1;
951 entry
->flags
.indicator_type
= MI_CHECK
;
953 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"), toggleAutoAttractCallback
, NULL
);
954 entry
->flags
.indicator
= 1;
955 entry
->flags
.indicator_on
= 1;
956 entry
->flags
.indicator_type
= MI_CHECK
;
958 menu
->flags
.realized
= 0;
964 static WMenu
*dockMenuCreate(WScreen
*scr
, int type
)
969 if (type
== WM_CLIP
&& scr
->clip_menu
)
970 return scr
->clip_menu
;
972 menu
= wMenuCreate(scr
, NULL
, False
);
973 if (type
!= WM_CLIP
) {
974 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
975 entry
->flags
.indicator
= 1;
976 entry
->flags
.indicator_on
= 1;
977 entry
->flags
.indicator_type
= MI_CHECK
;
979 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
980 scr
->clip_options
= makeClipOptionsMenu(scr
);
981 if (scr
->clip_options
)
982 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
984 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
986 entry
->text
= _("Rename Workspace");
988 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
989 entry
->flags
.indicator
= 1;
990 entry
->flags
.indicator_on
= 1;
991 entry
->flags
.indicator_type
= MI_CHECK
;
993 entry
= wMenuAddCallback(menu
, _("Select All Icons"), selectIconsCallback
, NULL
);
995 entry
->text
= _("Select All Icons");
997 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
999 entry
->text
= _("Keep Icon");
1001 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1003 entry
->text
= _("Move Icon To");
1004 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1005 if (scr
->clip_submenu
)
1006 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1008 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
, NULL
);
1010 entry
->text
= _("Remove Icon");
1012 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1015 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1017 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1019 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1021 entry
->text
= _("Hide");
1023 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1025 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1027 if (type
== WM_CLIP
)
1028 scr
->clip_menu
= menu
;
1033 WDock
*wDockCreate(WScreen
*scr
, int type
)
1040 dock
= wmalloc(sizeof(WDock
));
1042 dock
->max_icons
= DOCK_MAX_ICONS
;
1044 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * dock
->max_icons
);
1046 btn
= mainIconCreate(scr
, type
);
1050 dock
->x_pos
= btn
->x_pos
;
1051 dock
->y_pos
= btn
->y_pos
;
1052 dock
->screen_ptr
= scr
;
1054 dock
->icon_count
= 1;
1055 dock
->on_right_side
= 1;
1056 dock
->collapsed
= 0;
1057 dock
->auto_collapse
= 0;
1058 dock
->auto_collapse_magic
= NULL
;
1059 dock
->auto_raise_lower
= 0;
1060 dock
->auto_lower_magic
= NULL
;
1061 dock
->auto_raise_magic
= NULL
;
1062 dock
->attract_icons
= 0;
1064 dock
->icon_array
[0] = btn
;
1065 wRaiseFrame(btn
->icon
->core
);
1066 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1068 /* create dock menu */
1069 dock
->menu
= dockMenuCreate(scr
, type
);
1074 void wDockDestroy(WDock
*dock
)
1079 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1080 aicon
= dock
->icon_array
[i
];
1082 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1083 wDockDetach(dock
, aicon
);
1085 /* XXX: can: aicon->icon == NULL ? */
1086 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1087 wGetHeadForWindow(aicon
->icon
->owner
));
1088 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1089 if (!dock
->mapped
|| dock
->collapsed
)
1090 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1094 if (wPreferences
.auto_arrange_icons
)
1095 wArrangeIcons(dock
->screen_ptr
, True
);
1096 wfree(dock
->icon_array
);
1097 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1098 wMenuDestroy(dock
->menu
, True
);
1099 if (dock
->screen_ptr
->last_dock
== dock
)
1100 dock
->screen_ptr
->last_dock
= NULL
;
1104 void wClipIconPaint(WAppIcon
*aicon
)
1106 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1107 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1109 Window win
= aicon
->icon
->core
->window
;
1110 int length
, nlength
;
1111 char *ws_name
, ws_number
[10];
1114 wIconPaint(aicon
->icon
);
1116 length
= strlen(workspace
->name
);
1117 ws_name
= wmalloc(length
+ 1);
1118 snprintf(ws_name
, length
+ 1, "%s", workspace
->name
);
1119 snprintf(ws_number
, sizeof(ws_number
), "%i", scr
->current_workspace
+ 1);
1120 nlength
= strlen(ws_number
);
1122 if (!workspace
->clip
->collapsed
)
1123 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1125 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1127 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1129 tx
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
1131 if(wPreferences
.show_clip_title
)
1132 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, ty
, ws_name
, length
);
1134 tx
= (ICON_SIZE
/ 2 - WMWidthOfString(scr
->clip_title_font
, ws_number
, nlength
)) / 2;
1136 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, 2, ws_number
, nlength
);
1140 if (aicon
->launching
)
1141 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1142 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1144 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
, aicon
->dock
->rclip_button_pushed
);
1147 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1149 wClipIconPaint(desc
->parent
);
1152 static void dockIconPaint(WAppIcon
*btn
)
1154 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
) {
1155 wClipIconPaint(btn
);
1158 save_appicon(btn
, True
);
1162 static WMPropList
*make_icon_state(WAppIcon
*btn
)
1164 WMPropList
*node
= NULL
;
1165 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
;
1166 WMPropList
*position
, *buggy
, *omnipresent
;
1172 command
= WMCreatePLString("-");
1174 command
= WMCreatePLString(btn
->command
);
1176 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1178 lock
= btn
->lock
? dYes
: dNo
;
1180 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1182 name
= WMCreatePLString(tmp
);
1186 forced
= btn
->forced_dock
? dYes
: dNo
;
1188 buggy
= btn
->buggy_app
? dYes
: dNo
;
1190 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1191 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1193 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1194 position
= WMCreatePLString(buffer
);
1196 node
= WMCreatePLDictionary(dCommand
, command
,
1198 dAutoLaunch
, autolaunch
,
1200 dForced
, forced
, dBuggyApplication
, buggy
, dPosition
, position
, NULL
);
1201 WMReleasePropList(command
);
1202 WMReleasePropList(name
);
1203 WMReleasePropList(position
);
1205 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1206 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&& (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1207 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1209 #ifdef XDND /* was OFFIX */
1210 if (btn
->dnd_command
) {
1211 command
= WMCreatePLString(btn
->dnd_command
);
1212 WMPutInPLDictionary(node
, dDropCommand
, command
);
1213 WMReleasePropList(command
);
1217 if (btn
->paste_command
) {
1218 command
= WMCreatePLString(btn
->paste_command
);
1219 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1220 WMReleasePropList(command
);
1227 static WMPropList
*dockSaveState(WDock
*dock
)
1230 WMPropList
*icon_info
;
1231 WMPropList
*list
= NULL
, *dock_state
= NULL
;
1232 WMPropList
*value
, *key
;
1235 list
= WMCreatePLArray(NULL
);
1237 for (i
= (dock
->type
== WM_DOCK
? 0 : 1); i
< dock
->max_icons
; i
++) {
1238 WAppIcon
*btn
= dock
->icon_array
[i
];
1240 if (!btn
|| btn
->attracted
)
1243 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1244 WMAddToPLArray(list
, icon_info
);
1245 WMReleasePropList(icon_info
);
1249 dock_state
= WMCreatePLDictionary(dApplications
, list
, NULL
);
1251 if (dock
->type
== WM_DOCK
) {
1252 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1253 key
= WMCreatePLString(buffer
);
1254 WMPutInPLDictionary(dock_state
, key
, list
);
1255 WMReleasePropList(key
);
1257 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0), dock
->y_pos
);
1258 value
= WMCreatePLString(buffer
);
1259 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1260 WMReleasePropList(value
);
1262 WMReleasePropList(list
);
1264 value
= (dock
->lowered
? dYes
: dNo
);
1265 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1267 if (dock
->type
== WM_CLIP
) {
1268 value
= (dock
->collapsed
? dYes
: dNo
);
1269 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1271 value
= (dock
->auto_collapse
? dYes
: dNo
);
1272 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1274 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1275 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1277 value
= (dock
->attract_icons
? dYes
: dNo
);
1278 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1284 void wDockSaveState(WScreen
*scr
, WMPropList
*old_state
)
1286 WMPropList
*dock_state
;
1289 dock_state
= dockSaveState(scr
->dock
);
1292 * Copy saved states of docks with different sizes.
1298 keys
= WMGetPLDictionaryKeys(old_state
);
1299 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1300 tmp
= WMGetFromPLArray(keys
, i
);
1302 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1303 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1305 WMPutInPLDictionary(dock_state
, tmp
, WMGetFromPLDictionary(old_state
, tmp
));
1308 WMReleasePropList(keys
);
1311 WMPutInPLDictionary(scr
->session_state
, dDock
, dock_state
);
1313 WMReleasePropList(dock_state
);
1316 void wClipSaveState(WScreen
*scr
)
1318 WMPropList
*clip_state
;
1320 clip_state
= make_icon_state(scr
->clip_icon
);
1322 WMPutInPLDictionary(scr
->session_state
, dClip
, clip_state
);
1324 WMReleasePropList(clip_state
);
1327 WMPropList
*wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1329 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1332 static Bool
getBooleanDockValue(WMPropList
*value
, WMPropList
*key
)
1335 if (WMIsPLString(value
)) {
1336 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1339 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1345 static WAppIcon
*restore_icon_state(WScreen
*scr
, WMPropList
*info
, int type
, int index
)
1348 WMPropList
*cmd
, *value
;
1349 char *wclass
, *winstance
, *command
;
1351 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1352 if (!cmd
|| !WMIsPLString(cmd
))
1355 /* parse window name */
1356 value
= WMGetFromPLDictionary(info
, dName
);
1360 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1362 if (!winstance
&& !wclass
)
1367 command
= wstrdup(WMGetFromPLString(cmd
));
1371 if (!command
|| strcmp(command
, "-") == 0) {
1382 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1390 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1391 if (type
== WM_CLIP
) {
1392 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1393 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1395 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1396 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1398 #ifdef XDND /* was OFFIX */
1399 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1401 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1404 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1406 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1408 /* check auto launch */
1409 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1411 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1414 value
= WMGetFromPLDictionary(info
, dLock
);
1416 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1418 /* check if it wasn't normally docked */
1419 value
= WMGetFromPLDictionary(info
, dForced
);
1421 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1423 /* check if we can rely on the stuff in the app */
1424 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1426 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1428 /* get position in the dock */
1429 value
= WMGetFromPLDictionary(info
, dPosition
);
1430 if (value
&& WMIsPLString(value
)) {
1431 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1432 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1434 /* check position sanity */
1435 /* incomplete section! */
1436 if (type
== WM_DOCK
) {
1438 if (aicon
->yindex
< 0)
1439 wwarning(_("bad value in docked icon position %i,%i"),
1440 aicon
->xindex
, aicon
->yindex
);
1443 aicon
->yindex
= index
;
1447 /* check if icon is omnipresent */
1448 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1450 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1458 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1460 WAppIcon
*wClipRestoreState(WScreen
*scr
, WMPropList
*clip_state
)
1465 icon
= mainIconCreate(scr
, WM_CLIP
);
1470 WMRetainPropList(clip_state
);
1472 /* restore position */
1474 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1477 if (!WMIsPLString(value
)) {
1478 COMPLAIN("Position");
1483 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1484 COMPLAIN("Position");
1486 /* check position sanity */
1487 rect
.pos
.x
= icon
->x_pos
;
1488 rect
.pos
.y
= icon
->y_pos
;
1489 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1491 wGetRectPlacementInfo(scr
, rect
, &flags
);
1492 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
1493 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1496 #ifdef XDND /* was OFFIX */
1497 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1498 if (value
&& WMIsPLString(value
))
1499 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1502 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1503 if (value
&& WMIsPLString(value
))
1504 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1506 WMReleasePropList(clip_state
);
1511 WDock
*wDockRestoreState(WScreen
*scr
, WMPropList
*dock_state
, int type
)
1516 WAppIcon
*aicon
, *old_top
;
1519 dock
= wDockCreate(scr
, type
);
1524 WMRetainPropList(dock_state
);
1526 /* restore position */
1527 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1529 if (!WMIsPLString(value
)) {
1530 COMPLAIN("Position");
1535 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1536 COMPLAIN("Position");
1538 /* check position sanity */
1539 rect
.pos
.x
= dock
->x_pos
;
1540 rect
.pos
.y
= dock
->y_pos
;
1541 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1543 wGetRectPlacementInfo(scr
, rect
, &flags
);
1544 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
)) {
1545 int x
= dock
->x_pos
;
1546 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1549 /* Is this needed any more? */
1550 if (type
== WM_CLIP
) {
1551 if (dock
->x_pos
< 0) {
1553 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1554 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1557 if (dock
->x_pos
>= 0) {
1558 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1559 dock
->on_right_side
= 0;
1561 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1562 dock
->on_right_side
= 1;
1568 /* restore lowered/raised state */
1571 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1573 if (!WMIsPLString(value
)) {
1574 COMPLAIN("Lowered");
1576 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1581 /* restore collapsed state */
1582 dock
->collapsed
= 0;
1584 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1586 if (!WMIsPLString(value
)) {
1587 COMPLAIN("Collapsed");
1589 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1590 dock
->collapsed
= 1;
1594 /* restore auto-collapsed state */
1595 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1597 if (!WMIsPLString(value
)) {
1598 COMPLAIN("AutoCollapse");
1600 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1601 dock
->auto_collapse
= 1;
1602 dock
->collapsed
= 1;
1607 /* restore auto-raise/lower state */
1608 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1610 if (!WMIsPLString(value
)) {
1611 COMPLAIN("AutoRaiseLower");
1613 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1614 dock
->auto_raise_lower
= 1;
1618 /* restore attract icons state */
1619 dock
->attract_icons
= 0;
1621 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1623 if (!WMIsPLString(value
)) {
1624 COMPLAIN("AutoAttractIcons");
1626 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1627 dock
->attract_icons
= 1;
1631 /* application list */
1638 * When saving, it saves the dock state in
1639 * Applications and Applicationsnnn
1641 * When loading, it will first try Applicationsnnn.
1642 * If it does not exist, use Applications as default.
1645 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1647 tmp
= WMCreatePLString(buffer
);
1648 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1649 WMReleasePropList(tmp
);
1652 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1658 count
= WMGetPropListItemCount(apps
);
1662 old_top
= dock
->icon_array
[0];
1664 /* dock->icon_count is set to 1 when dock is created.
1665 * Since Clip is already restored, we want to keep it so for clip,
1666 * but for dock we may change the default top tile, so we set it to 0.
1668 if (type
== WM_DOCK
)
1669 dock
->icon_count
= 0;
1671 for (i
= 0; i
< count
; i
++) {
1672 if (dock
->icon_count
>= dock
->max_icons
) {
1673 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1677 value
= WMGetFromPLArray(apps
, i
);
1678 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1680 dock
->icon_array
[dock
->icon_count
] = aicon
;
1684 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1685 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1688 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1690 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1692 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1693 if (!dock
->collapsed
)
1694 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1696 wRaiseFrame(aicon
->icon
->core
);
1699 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
) {
1704 /* if the first icon is not defined, use the default */
1705 if (dock
->icon_array
[0] == NULL
) {
1706 /* update default icon */
1707 old_top
->x_pos
= dock
->x_pos
;
1708 old_top
->y_pos
= dock
->y_pos
;
1710 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1712 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1714 dock
->icon_array
[0] = old_top
;
1715 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1716 /* we don't need to increment dock->icon_count here because it was
1717 * incremented in the loop above.
1719 } else if (old_top
!= dock
->icon_array
[0]) {
1720 if (old_top
== scr
->clip_icon
)
1721 scr
->clip_icon
= dock
->icon_array
[0];
1723 wAppIconDestroy(old_top
);
1727 WMReleasePropList(dock_state
);
1732 void wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1734 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1735 btn
->drop_launch
= 0;
1736 btn
->paste_launch
= 0;
1738 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1741 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1751 void wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1757 for (i
= 0; i
< dock
->max_icons
; i
++) {
1758 btn
= dock
->icon_array
[i
];
1759 if (!btn
|| !btn
->auto_launch
)
1762 state
= wmalloc(sizeof(WSavedState
));
1763 state
->workspace
= workspace
;
1764 /* TODO: this is klugy and is very difficult to understand
1765 * what's going on. Try to clean up */
1766 wDockLaunchWithState(dock
, btn
, state
);
1770 #ifdef XDND /* was OFFIX */
1771 static WDock
*findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1777 if ((dock
= scr
->dock
) != NULL
) {
1778 for (i
= 0; i
< dock
->max_icons
; i
++) {
1779 if (dock
->icon_array
[i
]
1780 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1786 if (*icon_pos
< 0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
) != NULL
) {
1787 for (i
= 0; i
< dock
->max_icons
; i
++) {
1788 if (dock
->icon_array
[i
]
1789 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1800 int wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
1806 dock
= findDock(scr
, event
, &icon_pos
);
1811 * Return True if the drop was on an application icon window.
1812 * In this case, let the ClientMessage handler redirect the
1813 * message to the app.
1815 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
1818 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
1819 scr
->flags
.dnd_data_convertion_status
= 0;
1821 btn
= dock
->icon_array
[icon_pos
];
1823 if (!btn
->forced_dock
) {
1824 btn
->relaunching
= btn
->running
;
1827 if (btn
->wm_instance
|| btn
->wm_class
) {
1828 WWindowAttributes attr
;
1829 memset(&attr
, 0, sizeof(WWindowAttributes
));
1830 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
1832 if (!attr
.no_appicon
)
1838 btn
->paste_launch
= 0;
1839 btn
->drop_launch
= 1;
1840 scr
->last_dock
= dock
;
1841 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1846 if (!btn
->relaunching
)
1854 Bool
wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
, Bool update_icon
)
1857 Bool lupdate_icon
= False
;
1858 char *command
= NULL
;
1864 lupdate_icon
= True
;
1866 if (icon
->command
== NULL
) {
1867 /* If icon->owner exists, it means the application is running */
1868 if (icon
->icon
->owner
) {
1869 wwin
= icon
->icon
->owner
;
1870 command
= GetCommandForWindow(wwin
->client_win
);
1874 icon
->command
= command
;
1876 /* icon->forced_dock = 1; */
1877 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
1879 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
1880 _("Type the command used to launch the application"), &command
)) {
1881 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
1885 icon
->command
= command
;
1891 /* If the target is the dock, reject the icon. If
1892 * the target is the clip, make it an attracted icon
1894 if (dock
->type
== WM_CLIP
) {
1895 icon
->attracted
= 1;
1896 if (!icon
->icon
->shadowed
) {
1897 icon
->icon
->shadowed
= 1;
1898 lupdate_icon
= True
;
1908 for (index
= 1; index
< dock
->max_icons
; index
++)
1909 if (dock
->icon_array
[index
] == NULL
)
1911 /* if (index == dock->max_icons)
1914 assert(index
< dock
->max_icons
);
1916 dock
->icon_array
[index
] = icon
;
1920 icon
->omnipresent
= 0;
1922 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
1923 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
1928 icon
->launching
= 0;
1931 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1932 if (dock
->type
== WM_CLIP
) {
1933 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1934 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1936 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1937 icon
->icon
->core
->descriptor
.parent
= icon
;
1939 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
1940 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
1942 /* Update the icon images */
1944 wIconUpdate(icon
->icon
, NULL
);
1947 wAppIconPaint(icon
);
1950 save_appicon(icon
, True
);
1952 if (wPreferences
.auto_arrange_icons
)
1953 wArrangeIcons(dock
->screen_ptr
, True
);
1955 #ifdef XDND /* was OFFIX */
1956 if (icon
->command
&& !icon
->dnd_command
) {
1957 int len
= strlen(icon
->command
) + 8;
1958 icon
->dnd_command
= wmalloc(len
);
1959 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
1963 if (icon
->command
&& !icon
->paste_command
) {
1964 int len
= strlen(icon
->command
) + 8;
1965 icon
->paste_command
= wmalloc(len
);
1966 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
1972 static void reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1976 for (index
= 1; index
< dock
->max_icons
; index
++) {
1977 if (dock
->icon_array
[index
] == icon
)
1980 assert(index
< dock
->max_icons
);
1985 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
1986 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
1989 static Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
1992 char *command
= NULL
;
1994 Bool update_icon
= False
;
1997 return True
; /* No move needed, we're already there */
2003 * For the moment we can't do this if we move icons in Clip from one
2004 * workspace to other, because if we move two or more icons without
2005 * command, the dialog box will not be able to tell us to which of the
2006 * moved icons it applies. -Dan
2008 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
2009 /* If icon->owner exists, it means the application is running */
2010 if (icon
->icon
->owner
) {
2011 wwin
= icon
->icon
->owner
;
2012 command
= GetCommandForWindow(wwin
->client_win
);
2016 icon
->command
= command
;
2019 /* icon->forced_dock = 1; */
2020 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2021 _("Type the command used to launch the application"), &command
)) {
2022 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2026 icon
->command
= command
;
2037 if (dest
->type
== WM_DOCK
)
2038 wClipMakeIconOmnipresent(icon
, False
);
2040 for (index
= 1; index
< src
->max_icons
; index
++) {
2041 if (src
->icon_array
[index
] == icon
)
2044 assert(index
< src
->max_icons
);
2046 src
->icon_array
[index
] = NULL
;
2049 for (index
= 1; index
< dest
->max_icons
; index
++) {
2050 if (dest
->icon_array
[index
] == NULL
)
2054 assert(index
< dest
->max_icons
);
2056 dest
->icon_array
[index
] = icon
;
2059 /* deselect the icon */
2060 if (icon
->icon
->selected
)
2061 wIconSelect(icon
->icon
);
2063 if (dest
->type
== WM_DOCK
) {
2064 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2065 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2067 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2068 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2071 /* set it to be kept when moving to dock.
2072 * Unless the icon does not have a command set
2074 if (icon
->command
&& dest
->type
== WM_DOCK
) {
2075 icon
->attracted
= 0;
2076 if (icon
->icon
->shadowed
) {
2077 icon
->icon
->shadowed
= 0;
2080 save_appicon(icon
, True
);
2083 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2089 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2090 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2094 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2096 /* Update the icon images */
2098 wIconUpdate(icon
->icon
, NULL
);
2101 wAppIconPaint(icon
);
2106 void wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2109 Bool update_icon
= False
;
2111 /* make the settings panel be closed */
2113 DestroyDockAppSettingsPanel(icon
->panel
);
2115 /* This must be called before icon->dock is set to NULL.
2116 * Don't move it. -Dan
2118 wClipMakeIconOmnipresent(icon
, False
);
2122 icon
->attracted
= 0;
2123 icon
->auto_launch
= 0;
2124 if (icon
->icon
->shadowed
) {
2125 icon
->icon
->shadowed
= 0;
2129 /* deselect the icon */
2130 if (icon
->icon
->selected
)
2131 wIconSelect(icon
->icon
);
2133 if (icon
->command
) {
2134 wfree(icon
->command
);
2135 icon
->command
= NULL
;
2137 #ifdef XDND /* was OFFIX */
2138 if (icon
->dnd_command
) {
2139 wfree(icon
->dnd_command
);
2140 icon
->dnd_command
= NULL
;
2143 if (icon
->paste_command
) {
2144 wfree(icon
->paste_command
);
2145 icon
->paste_command
= NULL
;
2148 for (index
= 1; index
< dock
->max_icons
; index
++)
2149 if (dock
->icon_array
[index
] == icon
)
2152 assert(index
< dock
->max_icons
);
2153 dock
->icon_array
[index
] = NULL
;
2159 /* if the dock is not attached to an application or
2160 * the application did not set the appropriate hints yet,
2161 * destroy the icon */
2162 if (!icon
->running
|| !wApplicationOf(icon
->main_window
)) {
2163 wAppIconDestroy(icon
);
2165 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2166 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2167 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2168 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2169 icon
->icon
->core
->descriptor
.parent
= icon
;
2171 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2173 /* Update the icon images */
2175 wIconUpdate(icon
->icon
, NULL
);
2178 wAppIconPaint(icon
);
2180 if (wPreferences
.auto_arrange_icons
)
2181 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
))
2219 /* exact position */
2221 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2223 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2226 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2228 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2230 /* check if the icon is outside the screen boundaries */
2235 rect
.pos
.x
= dx
+ ex_x
* ICON_SIZE
;
2236 rect
.pos
.y
= dy
+ ex_y
* ICON_SIZE
;
2237 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2239 wGetRectPlacementInfo(scr
, rect
, &flags
);
2240 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
2244 if (dock
->type
== WM_DOCK
) {
2245 if (icon
->dock
!= dock
&& ex_x
!= 0)
2249 for (i
= 0; i
< dock
->max_icons
; i
++) {
2250 nicon
= dock
->icon_array
[i
];
2251 if (nicon
&& nicon
->yindex
== ex_y
) {
2258 int sig
, done
, closest
;
2260 /* Possible cases when redocking:
2262 * icon dragged out of range of any slot -> false
2263 * icon dragged to range of free slot
2264 * icon dragged to range of same slot
2265 * icon dragged to range of different icon
2267 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2270 if (ex_y
>= 0 && ex_y
<= max_y_icons
&& (aicon
== icon
|| !aicon
)) {
2276 /* start looking at the upper slot or lower? */
2277 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2284 /* look for closest free slot */
2285 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2289 closest
= sig
* (i
/ 2) + ex_y
;
2290 /* check if this slot is used */
2292 for (j
= 0; j
< dock
->max_icons
; j
++) {
2293 if (dock
->icon_array
[j
]
2294 && dock
->icon_array
[j
]->yindex
== closest
) {
2295 /* slot is used by someone else */
2296 if (dock
->icon_array
[j
] != icon
)
2304 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2305 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2306 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2311 } else { /* !redocking */
2313 /* if slot is free and the icon is close enough, return it */
2314 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2324 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2325 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+ 1;
2328 for (k
= start
; k
< stop
; k
++) {
2329 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2332 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2333 nicon
= tmp
->icon_array
[i
];
2334 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2342 for (k
= start
; k
< stop
; k
++) {
2343 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2346 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2347 nicon
= tmp
->icon_array
[i
];
2348 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2349 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2350 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2359 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2368 static int onScreen(WScreen
*scr
, int x
, int y
, int sx
, int ex
, int sy
, int ey
)
2370 WMRect rect
= wmkrect(x
, y
, ICON_SIZE
, ICON_SIZE
);
2373 wGetRectPlacementInfo(scr
, rect
, &flags
);
2375 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2379 * returns true if it can find a free slot in the dock,
2380 * in which case it changes x_pos and y_pos accordingly.
2381 * Else returns false.
2383 Bool
wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2385 WScreen
*scr
= dock
->screen_ptr
;
2387 WAppIconChain
*chain
;
2388 unsigned char *slot_map
;
2392 int i
, done
= False
;
2394 int sx
= 0, sy
= 0, ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2395 int extra_count
= 0;
2397 if (dock
->type
== WM_CLIP
&& dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2398 extra_count
= scr
->global_icon_count
;
2400 /* if the dock is full */
2401 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
)
2404 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2405 if (scr
->dock
->on_right_side
)
2406 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2408 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2411 if (ex
< dock
->x_pos
)
2413 if (sx
> dock
->x_pos
+ ICON_SIZE
)
2414 sx
= dock
->x_pos
+ ICON_SIZE
;
2421 /* check if clip is in a corner */
2422 if (dock
->type
== WM_CLIP
) {
2423 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2425 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2427 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2429 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2437 /* If the clip is in the corner, use only slots that are in the border
2439 if (corner
!= C_NONE
) {
2443 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2444 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2445 hmap
= wmalloc(hcount
+ 1);
2446 vmap
= wmalloc(vcount
+ 1);
2448 /* mark used positions */
2451 for (i
= 0; i
< dock
->max_icons
; i
++) {
2452 btn
= dock
->icon_array
[i
];
2456 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2457 vmap
[btn
->yindex
] = 1;
2458 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2459 hmap
[btn
->xindex
] = 1;
2461 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2463 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2464 vmap
[btn
->yindex
] = 1;
2465 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2466 hmap
[btn
->xindex
] = 1;
2470 for (i
= 0; i
< dock
->max_icons
; i
++) {
2471 btn
= dock
->icon_array
[i
];
2475 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2476 vmap
[btn
->yindex
] = 1;
2477 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2478 hmap
[-btn
->xindex
] = 1;
2480 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2482 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2483 vmap
[btn
->yindex
] = 1;
2484 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2485 hmap
[-btn
->xindex
] = 1;
2489 for (i
= 0; i
< dock
->max_icons
; i
++) {
2490 btn
= dock
->icon_array
[i
];
2494 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2495 vmap
[-btn
->yindex
] = 1;
2496 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2497 hmap
[btn
->xindex
] = 1;
2499 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2501 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2502 vmap
[-btn
->yindex
] = 1;
2503 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2504 hmap
[btn
->xindex
] = 1;
2509 for (i
= 0; i
< dock
->max_icons
; i
++) {
2510 btn
= dock
->icon_array
[i
];
2514 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2515 vmap
[-btn
->yindex
] = 1;
2516 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2517 hmap
[-btn
->xindex
] = 1;
2519 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2521 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2522 vmap
[-btn
->yindex
] = 1;
2523 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2524 hmap
[-btn
->xindex
] = 1;
2530 /* search a vacant slot */
2531 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2532 if (i
< vcount
&& vmap
[i
] == 0) {
2538 } else if (i
< hcount
&& hmap
[i
] == 0) {
2548 /* If found a slot, translate and return */
2550 if (corner
== C_NW
|| corner
== C_NE
)
2555 if (corner
== C_NE
|| corner
== C_SE
)
2562 /* else, try to find a slot somewhere else */
2565 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2566 * placed outside of screen */
2567 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2569 /* In the worst case (the clip is in the corner of the screen),
2570 * the amount of icons that fit in the clip is smaller.
2571 * Double the map to get a safe value.
2575 r
= (mwidth
- 1) / 2;
2577 slot_map
= wmalloc(mwidth
* mwidth
);
2579 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2581 /* mark used slots in the map. If the slot falls outside the map
2582 * (for example, when all icons are placed in line), ignore them. */
2583 for (i
= 0; i
< dock
->max_icons
; i
++) {
2584 btn
= dock
->icon_array
[i
];
2586 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
;
2675 for (i
= 0; i
< dock
->max_icons
; i
++) {
2676 btn
= dock
->icon_array
[i
];
2679 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2683 wScreenUpdateUsableArea(scr
);
2686 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2688 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2694 cmdline
= ExpandOptions(scr
, command
);
2696 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2704 wtokensplit(cmdline
, &argv
, &argc
);
2714 if ((pid
= fork()) == 0) {
2718 SetupEnvironment(scr
);
2724 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
);
2805 void wDockLower(WDock
*dock
)
2809 for (i
= 0; i
< dock
->max_icons
; i
++) {
2810 if (dock
->icon_array
[i
])
2811 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2815 void wDockRaise(WDock
*dock
)
2819 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
2820 if (dock
->icon_array
[i
])
2821 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2825 void wDockRaiseLower(WDock
*dock
)
2827 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2828 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2829 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2835 void wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
2837 icon
->launching
= 0;
2838 icon
->relaunching
= 0;
2839 dockIconPaint(icon
);
2842 WAppIcon
*wDockFindIconForWindow(WDock
*dock
, Window window
)
2847 for (i
= 0; i
< dock
->max_icons
; i
++) {
2848 icon
= dock
->icon_array
[i
];
2849 if (icon
&& icon
->main_window
== window
)
2855 void wDockTrackWindowLaunch(WDock
*dock
, Window window
)
2858 char *wm_class
, *wm_instance
;
2860 Bool firstPass
= True
;
2862 char *command
= NULL
;
2864 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) || (!wm_class
&& !wm_instance
))
2867 command
= GetCommandForWindow(window
);
2869 for (i
= 0; i
< dock
->max_icons
; i
++) {
2870 icon
= dock
->icon_array
[i
];
2874 /* app is already attached to icon */
2875 if (icon
->main_window
== window
) {
2880 if ((icon
->wm_instance
|| icon
->wm_class
)
2881 && (icon
->launching
|| !icon
->running
)) {
2883 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0)
2886 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0)
2889 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0)
2892 if (!icon
->relaunching
) {
2895 /* Possibly an application that was docked with dockit,
2896 * but the user did not update WMState to indicate that
2897 * it was docked by force */
2898 wapp
= wApplicationOf(window
);
2900 icon
->forced_dock
= 1;
2903 if (!icon
->forced_dock
)
2904 icon
->main_window
= window
;
2907 if (!wPreferences
.no_animations
&& !icon
->launching
&&
2908 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
2912 icon
->launching
= 1;
2913 dockIconPaint(icon
);
2915 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
2916 wm_instance
, wm_class
, TILE_NORMAL
);
2917 /* XXX: can: aicon->icon == NULL ? */
2918 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
2919 wAppIconMove(aicon
, x0
, y0
);
2920 /* Should this always be lowered? -Dan */
2922 wLowerFrame(aicon
->icon
->core
);
2923 XMapWindow(dpy
, aicon
->icon
->core
->window
);
2924 aicon
->launching
= 1;
2925 wAppIconPaint(aicon
);
2926 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
2927 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
2928 wAppIconDestroy(aicon
);
2930 wDockFinishLaunch(dock
, icon
);
2935 if (firstPass
&& !found
) {
2949 void wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
2951 if (!wPreferences
.flags
.noclip
) {
2952 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
2953 if (scr
->current_workspace
!= workspace
) {
2954 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
2955 WAppIconChain
*chain
= scr
->global_icons
;
2958 moveIconBetweenDocks(chain
->aicon
->dock
,
2959 scr
->workspaces
[workspace
]->clip
,
2960 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
2961 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
2962 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
2963 chain
= chain
->next
;
2966 wDockHideIcons(old_clip
);
2967 if (old_clip
->auto_raise_lower
) {
2968 if (old_clip
->auto_raise_magic
) {
2969 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
2970 old_clip
->auto_raise_magic
= NULL
;
2972 wDockLower(old_clip
);
2974 if (old_clip
->auto_collapse
) {
2975 if (old_clip
->auto_expand_magic
) {
2976 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
2977 old_clip
->auto_expand_magic
= NULL
;
2979 old_clip
->collapsed
= 1;
2981 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
2986 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
2991 for (i
= 0; i
< dock
->max_icons
; i
++) {
2992 icon
= dock
->icon_array
[i
];
2996 if (icon
->launching
&& icon
->pid
== pid
) {
2997 if (!icon
->relaunching
) {
2999 icon
->main_window
= None
;
3001 wDockFinishLaunch(dock
, icon
);
3003 if (status
== 111) {
3008 if (icon
->drop_launch
)
3009 cmd
= icon
->dnd_command
;
3012 if (icon
->paste_launch
)
3013 cmd
= icon
->paste_command
;
3015 cmd
= icon
->command
;
3017 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3019 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3026 static void toggleLowered(WDock
*dock
)
3031 /* lower/raise Dock */
3032 if (!dock
->lowered
) {
3033 newlevel
= WMNormalLevel
;
3036 newlevel
= WMDockLevel
;
3040 for (i
= 0; i
< dock
->max_icons
; i
++) {
3041 tmp
= dock
->icon_array
[i
];
3045 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3047 wLowerFrame(tmp
->icon
->core
);
3050 if (dock
->type
== WM_DOCK
)
3051 wScreenUpdateUsableArea(dock
->screen_ptr
);
3054 static void toggleCollapsed(WDock
*dock
)
3056 if (dock
->collapsed
) {
3057 dock
->collapsed
= 0;
3058 wDockShowIcons(dock
);
3060 dock
->collapsed
= 1;
3061 wDockHideIcons(dock
);
3065 static void openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3067 WScreen
*scr
= dock
->screen_ptr
;
3068 WObjDescriptor
*desc
;
3070 WApplication
*wapp
= NULL
;
3074 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3076 if (dock
->type
== WM_DOCK
) {
3078 entry
= dock
->menu
->entries
[index
];
3079 entry
->flags
.indicator_on
= !dock
->lowered
;
3080 entry
->clientdata
= dock
;
3081 dock
->menu
->flags
.realized
= 0;
3084 if (scr
->clip_options
)
3085 updateClipOptionsMenu(scr
->clip_options
, dock
);
3087 n_selected
= numberOfSelectedIcons(dock
);
3089 /* Rename Workspace */
3090 entry
= dock
->menu
->entries
[++index
];
3091 if (aicon
== scr
->clip_icon
) {
3092 entry
->callback
= renameCallback
;
3093 entry
->clientdata
= dock
;
3094 entry
->flags
.indicator
= 0;
3095 entry
->text
= _("Rename Workspace");
3097 entry
->callback
= omnipresentCallback
;
3098 entry
->clientdata
= aicon
;
3099 if (n_selected
> 0) {
3100 entry
->flags
.indicator
= 0;
3101 entry
->text
= _("Toggle Omnipresent");
3103 entry
->flags
.indicator
= 1;
3104 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3105 entry
->flags
.indicator_type
= MI_CHECK
;
3106 entry
->text
= _("Omnipresent");
3110 /* select/unselect icon */
3111 entry
= dock
->menu
->entries
[++index
];
3112 entry
->clientdata
= aicon
;
3113 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3114 wMenuSetEnabled(dock
->menu
, index
, aicon
!= scr
->clip_icon
);
3116 /* select/unselect all icons */
3117 entry
= dock
->menu
->entries
[++index
];
3118 entry
->clientdata
= aicon
;
3120 entry
->text
= _("Unselect All Icons");
3122 entry
->text
= _("Select All Icons");
3124 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3127 entry
= dock
->menu
->entries
[++index
];
3128 entry
->clientdata
= aicon
;
3130 entry
->text
= _("Keep Icons");
3132 entry
->text
= _("Keep Icon");
3134 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3136 /* this is the workspace submenu part */
3137 entry
= dock
->menu
->entries
[++index
];
3139 entry
->text
= _("Move Icons To");
3141 entry
->text
= _("Move Icon To");
3143 if (scr
->clip_submenu
)
3144 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");
3156 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3158 /* attract icon(s) */
3159 entry
= dock
->menu
->entries
[++index
];
3160 entry
->clientdata
= aicon
;
3162 dock
->menu
->flags
.realized
= 0;
3163 wMenuRealize(dock
->menu
);
3166 if (aicon
->icon
->owner
)
3167 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
);
3248 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3250 if (event
->xbutton
.state
& MOD_MASK
)
3251 wHideOtherApplications(btn
->icon
->owner
);
3253 if (event
->xbutton
.button
== Button1
) {
3254 if (event
->xbutton
.state
& MOD_MASK
) {
3255 /* raise/lower dock */
3256 toggleLowered(dock
);
3257 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3258 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
)
3259 toggleCollapsed(dock
);
3261 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3262 } else if (btn
->command
) {
3263 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3264 launchDockedApplication(btn
, False
);
3270 static void handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3272 WScreen
*scr
= dock
->screen_ptr
;
3273 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3276 int grabbed
= 0, swapped
= 0, done
;
3277 Pixmap ghost
= None
;
3278 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3280 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3281 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3282 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
)
3283 wwarning("pointer grab failed for dock move");
3286 for (x
= 0; x
< dock
->max_icons
; x
++) {
3287 if (dock
->icon_array
[x
] != NULL
&& dock
->icon_array
[x
]->yindex
> y
)
3288 y
= dock
->icon_array
[x
]->yindex
;
3291 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
* y
);
3295 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3296 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3303 /* It means the cursor moved so fast that it entered
3304 * something else (if moving slowly, it would have
3305 * stayed in the dock that is being moved. Ignore such
3306 * "spurious" EnterNotifiy's */
3311 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3312 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3313 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3314 | ButtonReleaseMask
| ButtonPressMask
,
3315 wCursor
[WCUR_MOVE
], CurrentTime
);
3320 if (dock
->type
== WM_CLIP
) {
3321 x
= ev
.xmotion
.x_root
- ofs_x
;
3322 y
= ev
.xmotion
.y_root
- ofs_y
;
3323 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3325 moveDock(dock
, x
, y
);
3327 /* move vertically if pointer is inside the dock */
3328 if ((dock
->on_right_side
&& ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3329 || (!dock
->on_right_side
&& ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
* 2)) {
3331 x
= ev
.xmotion
.x_root
- ofs_x
;
3332 y
= ev
.xmotion
.y_root
- ofs_y
;
3333 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3334 moveDock(dock
, dock
->x_pos
, y
);
3336 /* move horizontally to change sides */
3337 x
= ev
.xmotion
.x_root
- ofs_x
;
3338 if (!dock
->on_right_side
) {
3341 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
* 2) {
3342 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
- ICON_SIZE
3343 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3344 if (superfluous
&& ghost
== None
) {
3345 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3346 scr
->scr_width
- ICON_SIZE
3347 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3348 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3349 XClearWindow(dpy
, scr
->dock_shadow
);
3351 XMapRaised(dpy
, scr
->dock_shadow
);
3354 if (superfluous
&& ghost
!= None
) {
3355 XFreePixmap(dpy
, ghost
);
3358 XUnmapWindow(dpy
, scr
->dock_shadow
);
3363 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3364 XMoveWindow(dpy
, scr
->dock_shadow
, DOCK_EXTRA_SPACE
, dock
->y_pos
);
3365 if (superfluous
&& ghost
== None
) {
3366 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3367 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3368 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3369 XClearWindow(dpy
, scr
->dock_shadow
);
3371 XMapRaised(dpy
, scr
->dock_shadow
);
3374 XUnmapWindow(dpy
, scr
->dock_shadow
);
3376 if (superfluous
&& ghost
!= None
) {
3377 XFreePixmap(dpy
, ghost
);
3389 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3391 XUngrabPointer(dpy
, CurrentTime
);
3392 XUnmapWindow(dpy
, scr
->dock_shadow
);
3393 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3394 if (dock
->type
== WM_DOCK
) {
3397 dock
->on_right_side
= 1;
3399 dock
->on_right_side
= 0;
3401 wArrangeIcons(scr
, False
);
3410 XFreePixmap(dpy
, ghost
);
3411 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3415 static Bool
handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3417 WScreen
*scr
= dock
->screen_ptr
;
3419 WIcon
*icon
= aicon
->icon
;
3420 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3421 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3423 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3424 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3425 int shad_x
= x
, shad_y
= y
;
3426 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3428 Pixmap ghost
= None
;
3430 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3431 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3432 Bool hasMoved
= False
;
3434 if (wPreferences
.flags
.noupdates
)
3437 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3438 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3439 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3442 if (!(event
->xbutton
.state
& MOD_MASK
))
3443 wRaiseFrame(icon
->core
);
3445 if (!wPreferences
.flags
.noclip
)
3446 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3448 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3450 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3453 wins
[0] = icon
->core
->window
;
3454 wins
[1] = scr
->dock_shadow
;
3455 XRestackWindows(dpy
, wins
, 2);
3456 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
3458 if (icon
->pixmap
!= None
)
3459 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3461 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3463 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3464 XClearWindow(dpy
, scr
->dock_shadow
);
3466 XMapWindow(dpy
, scr
->dock_shadow
);
3471 XMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3472 | ButtonMotionMask
| ExposureMask
, &ev
);
3481 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3482 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3483 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3484 | ButtonReleaseMask
| ButtonPressMask
,
3485 wCursor
[WCUR_MOVE
], CurrentTime
);
3494 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3495 if (i
== scr
->current_workspace
)
3497 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3501 x
= ev
.xmotion
.x_root
- ofs_x
;
3502 y
= ev
.xmotion
.y_root
- ofs_y
;
3503 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3506 if (last_dock
!= dock
&& collapsed
) {
3507 last_dock
->collapsed
= 1;
3508 wDockHideIcons(last_dock
);
3511 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3512 dock
->collapsed
= 0;
3513 wDockShowIcons(dock
);
3515 if (dock
->auto_raise_lower
)
3519 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3522 if (last_dock
!= dock2
&& collapsed
) {
3523 last_dock
->collapsed
= 1;
3524 wDockHideIcons(last_dock
);
3527 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3528 dock2
->collapsed
= 0;
3529 wDockShowIcons(dock2
);
3531 if (dock2
->auto_raise_lower
)
3536 if (aicon
->launching
|| aicon
->lock
|| (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3537 || (!aicon
->running
&& tmp
)) {
3538 shad_x
= last_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3539 shad_y
= last_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3541 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3544 XMapWindow(dpy
, scr
->dock_shadow
);
3549 XUnmapWindow(dpy
, scr
->dock_shadow
);
3553 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3560 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3562 XUngrabPointer(dpy
, CurrentTime
);
3564 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3565 XUnmapWindow(dpy
, scr
->dock_shadow
);
3567 reattachIcon(dock
, aicon
, ix
, iy
);
3568 if (clip
&& dock
!= clip
&& clip
->auto_raise_lower
)
3571 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3573 /* Slide it back if dock rejected it */
3574 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
, aicon
->y_pos
);
3575 reattachIcon(dock
, aicon
, aicon
->xindex
, aicon
->yindex
);
3577 if (last_dock
->type
== WM_CLIP
&& last_dock
->auto_collapse
)
3584 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3585 /* We need to deselect it, even if is deselected in
3586 * wDockDetach(), because else DoKaboom() will fail.
3588 if (aicon
->icon
->selected
)
3589 wIconSelect(aicon
->icon
);
3591 DoKaboom(scr
, aicon
->icon
->core
->window
, x
, y
);
3594 if (clip
&& clip
->auto_raise_lower
)
3596 wDockDetach(dock
, aicon
);
3599 last_dock
->collapsed
= 1;
3600 wDockHideIcons(last_dock
);
3605 XFreePixmap(dpy
, ghost
);
3606 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3610 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3611 if (i
== scr
->current_workspace
)
3613 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3619 return False
; /* never reached */
3622 static int getClipButton(int px
, int py
)
3624 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3626 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3629 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3630 return CLIP_FORWARD
;
3631 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3637 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3640 int done
, direction
, new_ws
;
3642 WDock
*clip
= scr
->clip_icon
->dock
;
3644 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3646 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3647 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3649 wClipIconPaint(scr
->clip_icon
);
3652 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3659 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3660 if (new_dir
!= direction
) {
3661 direction
= new_dir
;
3662 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3663 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3664 wClipIconPaint(scr
->clip_icon
);
3672 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3677 clip
->lclip_button_pushed
= 0;
3678 clip
->rclip_button_pushed
= 0;
3680 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3682 if (direction
== CLIP_FORWARD
) {
3683 if (scr
->current_workspace
< scr
->workspace_count
- 1)
3684 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3685 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
- 1)
3686 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3687 else if (wPreferences
.ws_cycle
)
3688 wWorkspaceChange(scr
, 0);
3689 } else if (direction
== CLIP_REWIND
) {
3690 if (scr
->current_workspace
> 0)
3691 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
3692 else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
)
3693 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
3696 wClipIconPaint(scr
->clip_icon
);
3699 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3701 WAppIcon
*aicon
= desc
->parent
;
3702 WDock
*dock
= aicon
->dock
;
3703 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3705 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3708 scr
->last_dock
= dock
;
3710 if (dock
->menu
->flags
.mapped
)
3711 wMenuUnmap(dock
->menu
);
3713 if (IsDoubleClick(scr
, event
)) {
3714 /* double-click was not in the main clip icon */
3715 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3716 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3717 iconDblClick(desc
, event
);
3722 if (event
->xbutton
.button
== Button1
) {
3723 if (event
->xbutton
.state
& MOD_MASK
)
3728 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
&& dock
->type
!= WM_DOCK
) {
3729 wIconSelect(aicon
->icon
);
3733 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3734 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
3735 && dock
->type
== WM_CLIP
)
3736 handleClipChangeWorkspace(scr
, event
);
3738 handleDockMove(dock
, aicon
, event
);
3740 Bool hasMoved
= handleIconMove(dock
, aicon
, event
);
3741 if (wPreferences
.single_click
&& !hasMoved
)
3742 iconDblClick(desc
, event
);
3744 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&& aicon
== scr
->clip_icon
) {
3745 if (!scr
->clip_ws_menu
) {
3746 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3748 if (scr
->clip_ws_menu
) {
3749 WMenu
*wsMenu
= scr
->clip_ws_menu
;
3752 wWorkspaceMenuUpdate(scr
, wsMenu
);
3754 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
3757 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
3758 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
3760 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
3762 desc
= &wsMenu
->menu
->descriptor
;
3763 event
->xany
.send_event
= True
;
3764 (*desc
->handle_mousedown
) (desc
, event
);
3766 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
3767 (event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
) {
3768 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3769 } else if (event
->xbutton
.button
== Button3
) {
3770 if (event
->xbutton
.send_event
&&
3771 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3772 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3773 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3774 wwarning("pointer grab failed for dockicon menu");
3778 openDockMenu(dock
, aicon
, event
);
3779 } else if (event
->xbutton
.button
== Button2
) {
3780 WAppIcon
*btn
= desc
->parent
;
3782 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3783 launchDockedApplication(btn
, True
);
3787 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3789 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3793 assert(event
->type
== EnterNotify
);
3795 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3798 scr
= btn
->icon
->core
->screen_ptr
;
3799 if (!btn
->omnipresent
)
3802 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3804 if (!dock
|| dock
->type
!= WM_CLIP
)
3807 /* The auto raise/lower code */
3808 if (dock
->auto_lower_magic
) {
3809 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3810 dock
->auto_lower_magic
= NULL
;
3812 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
)
3813 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
, clipAutoRaise
, (void *)dock
);
3815 /* The auto expand/collapse code */
3816 if (dock
->auto_collapse_magic
) {
3817 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3818 dock
->auto_collapse_magic
= NULL
;
3820 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
)
3821 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
, clipAutoExpand
, (void *)dock
);
3824 static void clipLeave(WDock
*dock
)
3827 WObjDescriptor
*desc
= NULL
;
3829 if (!dock
|| dock
->type
!= WM_CLIP
)
3832 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
3833 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3834 (XPointer
*) & desc
) != XCNOENT
3835 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
3836 && ((WAppIcon
*) desc
->parent
)->dock
&& ((WAppIcon
*) desc
->parent
)->dock
->type
== WM_CLIP
) {
3837 /* We didn't left the Clip yet */
3838 XPutBackEvent(dpy
, &event
);
3842 XPutBackEvent(dpy
, &event
);
3844 /* We entered a withdrawn window, so we're still in Clip */
3848 if (dock
->auto_raise_magic
) {
3849 WMDeleteTimerHandler(dock
->auto_raise_magic
);
3850 dock
->auto_raise_magic
= NULL
;
3852 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
)
3853 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
, clipAutoLower
, (void *)dock
);
3855 if (dock
->auto_expand_magic
) {
3856 WMDeleteTimerHandler(dock
->auto_expand_magic
);
3857 dock
->auto_expand_magic
= NULL
;
3859 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
)
3860 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
, clipAutoCollapse
, (void *)dock
);
3863 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
3865 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3867 assert(event
->type
== LeaveNotify
);
3869 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3872 clipLeave(btn
->dock
);
3875 static void clipAutoCollapse(void *cdata
)
3877 WDock
*dock
= (WDock
*) cdata
;
3879 if (dock
->type
!= WM_CLIP
)
3882 if (dock
->auto_collapse
) {
3883 dock
->collapsed
= 1;
3884 wDockHideIcons(dock
);
3886 dock
->auto_collapse_magic
= NULL
;
3889 static void clipAutoExpand(void *cdata
)
3891 WDock
*dock
= (WDock
*) cdata
;
3893 if (dock
->type
!= WM_CLIP
)
3896 if (dock
->auto_collapse
) {
3897 dock
->collapsed
= 0;
3898 wDockShowIcons(dock
);
3900 dock
->auto_expand_magic
= NULL
;
3903 static void clipAutoLower(void *cdata
)
3905 WDock
*dock
= (WDock
*) cdata
;
3907 if (dock
->type
!= WM_CLIP
)
3910 if (dock
->auto_raise_lower
)
3913 dock
->auto_lower_magic
= NULL
;
3916 static void clipAutoRaise(void *cdata
)
3918 WDock
*dock
= (WDock
*) cdata
;
3920 if (dock
->type
!= WM_CLIP
)
3923 if (dock
->auto_raise_lower
)
3926 dock
->auto_raise_magic
= NULL
;
3929 static Bool
iconCanBeOmnipresent(WAppIcon
*aicon
)
3931 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3936 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3937 clip
= scr
->workspaces
[i
]->clip
;
3939 if (clip
== aicon
->dock
)
3942 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
3943 return False
; /* Clip is full in some workspace */
3945 for (j
= 0; j
< clip
->max_icons
; j
++) {
3946 btn
= clip
->icon_array
[j
];
3947 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
3955 int wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
3957 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3958 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
3959 int status
= WO_SUCCESS
;
3961 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== scr
->clip_icon
)
3962 return WO_NOT_APPLICABLE
;
3964 if (aicon
->omnipresent
== omnipresent
)
3968 if (iconCanBeOmnipresent(aicon
)) {
3969 aicon
->omnipresent
= 1;
3970 new_entry
= wmalloc(sizeof(WAppIconChain
));
3971 new_entry
->aicon
= aicon
;
3972 new_entry
->next
= scr
->global_icons
;
3973 scr
->global_icons
= new_entry
;
3974 scr
->global_icon_count
++;
3976 aicon
->omnipresent
= 0;
3980 aicon
->omnipresent
= 0;
3981 if (aicon
== scr
->global_icons
->aicon
) {
3982 tmp
= scr
->global_icons
->next
;
3983 wfree(scr
->global_icons
);
3984 scr
->global_icons
= tmp
;
3985 scr
->global_icon_count
--;
3987 tmp
= scr
->global_icons
;
3989 if (tmp
->next
->aicon
== aicon
) {
3990 tmp1
= tmp
->next
->next
;
3993 scr
->global_icon_count
--;
4001 wAppIconPaint(aicon
);