1 /* dock.c- built-in Dock module for WindowMaker
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 * Copyright (c) 1998, 1999 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
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
28 #include <X11/Xutil.h>
36 #define PATH_MAX DEFAULT_PATH_MAX
39 #include "WindowMaker.h"
49 #include "properties.h"
53 #include "workspace.h"
55 #include "superfluous.h"
64 /**** Local variables ****/
67 #define CLIP_FORWARD 2
70 /**** Global variables ****/
73 extern void DestroyDockAppSettingsPanel();
75 extern void ShowDockAppSettingsPanel(WAppIcon
*aicon
);
78 extern XContext wWinContext
;
80 extern Cursor wCursor
[WCUR_LAST
];
82 extern WPreferences wPreferences
;
84 extern XContext wWinContext
;
87 extern Atom _XA_DND_PROTOCOL
;
91 #define MOD_MASK wPreferences.modifier_mask
93 extern void appIconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
95 #define ICON_SIZE wPreferences.icon_size
98 /***** Local variables ****/
100 static proplist_t dCommand
=NULL
;
102 static proplist_t dDropCommand
=NULL
;
104 static proplist_t dAutoLaunch
, dLock
;
105 static proplist_t dName
, dForced
, dBuggyApplication
, dYes
, dNo
;
106 static proplist_t dHost
, dDock
, dClip
;
107 static proplist_t dAutoAttractIcons
;
109 static proplist_t dPosition
, dApplications
, dLowered
, dCollapsed
, dAutoCollapse
;
111 static proplist_t dAutoRaiseLower
, dOmnipresent
;
113 static void dockIconPaint(WAppIcon
*btn
);
115 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
117 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
);
119 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
121 static int getClipButton(int px
, int py
);
123 static void toggleLowered(WDock
*dock
);
125 static void toggleCollapsed(WDock
*dock
);
127 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
129 static void clipLeave(WDock
*dock
);
131 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
133 Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
);
135 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
136 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
137 static void clipAutoCollapse(void *cdata
);
138 static void clipAutoExpand(void *cdata
);
139 static void launchDockedApplication(WAppIcon
*btn
);
141 static void clipAutoLower(void *cdata
);
142 static void clipAutoRaise(void *cdata
);
144 static void showClipBalloon(WDock
*dock
, int workspace
);
160 #endif /* OFFIX_DND */
170 dCommand
= PLRetain(PLMakeString("Command"));
172 dDropCommand
= PLRetain(PLMakeString("DropCommand"));
174 dLock
= PLRetain(PLMakeString("Lock"));
175 dAutoLaunch
= PLRetain(PLMakeString("AutoLaunch"));
176 dName
= PLRetain(PLMakeString("Name"));
177 dForced
= PLRetain(PLMakeString("Forced"));
178 dBuggyApplication
= PLRetain(PLMakeString("BuggyApplication"));
179 dYes
= PLRetain(PLMakeString("Yes"));
180 dNo
= PLRetain(PLMakeString("No"));
181 dHost
= PLRetain(PLMakeString("Host"));
183 dPosition
= PLMakeString("Position");
184 dApplications
= PLMakeString("Applications");
185 dLowered
= PLMakeString("Lowered");
186 dCollapsed
= PLMakeString("Collapsed");
187 dAutoCollapse
= PLMakeString("AutoCollapse");
188 dAutoRaiseLower
= PLMakeString("AutoRaiseLower");
189 dAutoAttractIcons
= PLMakeString("AutoAttractIcons");
191 dOmnipresent
= PLMakeString("Omnipresent");
193 dDock
= PLMakeString("Dock");
194 dClip
= PLMakeString("Clip");
200 renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
202 WDock
*dock
= entry
->clientdata
;
207 assert(entry
->clientdata
!=NULL
);
209 wspace
= dock
->screen_ptr
->current_workspace
;
211 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
213 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+1);
214 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
,
216 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
225 toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
227 assert(entry
->clientdata
!=NULL
);
229 toggleLowered(entry
->clientdata
);
231 entry
->flags
.indicator_on
= !(((WDock
*)entry
->clientdata
)->lowered
);
239 killCallback(WMenu
*menu
, WMenuEntry
*entry
)
244 if (!WCHECK_STATE(WSTATE_NORMAL
))
247 assert(entry
->clientdata
!=NULL
);
249 icon
= (WAppIcon
*)entry
->clientdata
;
253 WCHANGE_STATE(WSTATE_MODAL
);
255 buffer
= wstrconcat(icon
->wm_class
,
256 _(" will be forcibly closed.\n"
257 "Any unsaved changes will be lost.\n"
260 if (wPreferences
.dont_confirm_kill
261 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
262 buffer
, _("Yes"), _("No"), NULL
)==WAPRDefault
) {
263 if (icon
->icon
&& icon
->icon
->owner
) {
264 wClientKill(icon
->icon
->owner
);
272 WCHANGE_STATE(WSTATE_NORMAL
);
276 /* TODO: replace this function with a member of the dock struct */
278 numberOfSelectedIcons(WDock
*dock
)
284 for (i
=1; i
<dock
->max_icons
; i
++) {
285 aicon
= dock
->icon_array
[i
];
286 if (aicon
&& aicon
->icon
->selected
) {
296 getSelected(WDock
*dock
)
298 WMArray
*ret
= WMCreateArray(8);
302 for (i
=1; i
<dock
->max_icons
; i
++) {
303 btn
= dock
->icon_array
[i
];
304 if (btn
&& btn
->icon
->selected
) {
305 WMAddToArray(ret
, btn
);
314 paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
316 Window win
= clipIcon
->icon
->core
->window
;
317 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
319 int pt
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
320 int tp
= ICON_SIZE
- pt
;
321 int as
= pt
- 15; /* 15 = 5+5+5 */
322 GC gc
= scr
->clip_title_gc
;
323 #ifdef GRADIENT_CLIP_ARROW
324 Bool collapsed
= clipIcon
->dock
->collapsed
;
330 p
[1].x
= ICON_SIZE
-2;
332 p
[2].x
= ICON_SIZE
-2;
334 } else if (lpushed
) {
338 p
[1].y
= ICON_SIZE
-2;
340 p
[2].y
= ICON_SIZE
-2;
342 if (lpushed
|| rpushed
) {
343 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
344 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
345 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
347 #ifdef GRADIENT_CLIP_ARROW
349 XSetFillStyle(dpy
, scr
->copy_gc
, FillTiled
);
350 XSetTile(dpy
, scr
->copy_gc
, scr
->clip_arrow_gradient
);
351 XSetClipMask(dpy
, scr
->copy_gc
, None
);
354 #endif /* GRADIENT_CLIP_ARROW */
356 /* top right arrow */
357 p
[0].x
= p
[3].x
= ICON_SIZE
-5-as
;
359 p
[1].x
= ICON_SIZE
-6;
361 p
[2].x
= ICON_SIZE
-6;
364 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
365 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
367 #ifdef GRADIENT_CLIP_ARROW
369 XSetTSOrigin(dpy
, gc
, ICON_SIZE
-6-as
, 5);
371 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
372 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
375 /* bottom left arrow */
377 p
[0].y
= p
[3].y
= ICON_SIZE
-5-as
;
379 p
[1].y
= ICON_SIZE
-6;
381 p
[2].y
= ICON_SIZE
-6;
383 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
384 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
386 #ifdef GRADIENT_CLIP_ARROW
388 XSetTSOrigin(dpy
, gc
, 5, ICON_SIZE
-6-as
);
390 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
391 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
393 #ifdef GRADIENT_CLIP_ARROW
395 XSetFillStyle(dpy
, scr
->copy_gc
, FillSolid
);
401 wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
403 RImage
*tile
= RCloneImage(normalTile
);
410 pt
= CLIP_BUTTON_SIZE
*wPreferences
.icon_size
/64;
411 tp
= wPreferences
.icon_size
-1 - pt
;
415 black
.red
= black
.green
= black
.blue
= 0;
418 dark
.red
= dark
.green
= dark
.blue
= 60;
421 light
.red
= light
.green
= light
.blue
= 80;
425 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
-2,
427 RDrawLine(tile
, tp
-1, 0, wPreferences
.icon_size
-1, pt
+1, &black
);
428 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
-3,
432 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4,
433 ICON_SIZE
- 5, 4, &dark
);
434 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5,
435 ICON_SIZE
- 5, 6 + as
, &dark
);
436 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
,
440 ROperateLine(tile
, RAddOperation
, 2, tp
+2, pt
-2,
441 wPreferences
.icon_size
-3, &dark
);
442 RDrawLine(tile
, 0, tp
-1, pt
+1, wPreferences
.icon_size
-1, &black
);
443 ROperateLine(tile
, RSubtractOperation
, 0, tp
-2, pt
+1,
444 wPreferences
.icon_size
-2, &light
);
447 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4,
448 ICON_SIZE
- 5, &dark
);
449 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
,
450 6 + as
, ICON_SIZE
- 5, &dark
);
451 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5,
459 omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
461 WAppIcon
*clickedIcon
= entry
->clientdata
;
464 WMArray
*selectedIcons
;
465 WMArrayIterator iter
;
468 assert(entry
->clientdata
!=NULL
);
470 dock
= clickedIcon
->dock
;
472 selectedIcons
= getSelected(dock
);
474 if (!WMGetArrayItemCount(selectedIcons
))
475 WMAddToArray(selectedIcons
, clickedIcon
);
478 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
479 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
481 else if (aicon
->icon
->selected
)
482 wIconSelect(aicon
->icon
);
484 WMFreeArray(selectedIcons
);
487 wMessageDialog(dock
->screen_ptr
, _("Warning"),
488 _("Some icons cannot be made omnipresent. "
489 "Please make sure that no other icon is "
490 "docked in the same positions on the other "
491 "workspaces and the Clip is not full in "
493 _("OK"), NULL
, NULL
);
494 } else if (failed
== 1) {
495 wMessageDialog(dock
->screen_ptr
, _("Warning"),
496 _("Icon cannot be made omnipresent. "
497 "Please make sure that no other icon is "
498 "docked in the same position on the other "
499 "workspaces and the Clip is not full in "
501 _("OK"), NULL
, NULL
);
507 removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
509 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
512 WMArray
*selectedIcons
;
516 assert(clickedIcon
!=NULL
);
518 dock
= clickedIcon
->dock
;
520 selectedIcons
= getSelected(dock
);
522 if (WMGetArrayItemCount(selectedIcons
)) {
523 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
524 _("All selected icons will be removed!"),
525 _("OK"), _("Cancel"), NULL
)!=WAPRDefault
) {
526 WMFreeArray(selectedIcons
);
530 if (clickedIcon
->xindex
==0 && clickedIcon
->yindex
==0) {
531 WMFreeArray(selectedIcons
);
534 WMAddToArray(selectedIcons
, clickedIcon
);
537 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
538 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
539 wDockDetach(dock
, aicon
);
541 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
542 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
543 aicon
->x_pos
, aicon
->y_pos
);
544 if (!dock
->mapped
|| dock
->collapsed
)
545 XMapWindow(dpy
, aicon
->icon
->core
->window
);
548 WMFreeArray(selectedIcons
);
550 if (wPreferences
.auto_arrange_icons
)
551 wArrangeIcons(dock
->screen_ptr
, True
);
556 keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
558 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
561 WMArray
*selectedIcons
;
564 assert(clickedIcon
!=NULL
);
565 dock
= clickedIcon
->dock
;
567 selectedIcons
= getSelected(dock
);
569 if (!WMGetArrayItemCount(selectedIcons
)
570 && clickedIcon
!=dock
->screen_ptr
->clip_icon
) {
571 char *command
= NULL
;
573 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
574 clickedIcon
->editing
= 1;
575 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
576 _("Type the command used to launch the application"),
578 if (command
&& (command
[0]==0 ||
579 (command
[0]=='-' && command
[1]==0))) {
583 clickedIcon
->command
= command
;
584 clickedIcon
->editing
= 0;
586 clickedIcon
->editing
= 0;
589 WMFreeArray(selectedIcons
);
594 WMAddToArray(selectedIcons
, clickedIcon
);
597 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
598 if (aicon
->icon
->selected
)
599 wIconSelect(aicon
->icon
);
600 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
601 aicon
->attracted
= 0;
602 if (aicon
->icon
->shadowed
) {
603 aicon
->icon
->shadowed
= 0;
604 aicon
->icon
->force_paint
= 1;
605 wAppIconPaint(aicon
);
609 WMFreeArray(selectedIcons
);
616 toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
618 WDock
*dock
= (WDock
*)entry
->clientdata
;
620 assert(entry
->clientdata
!=NULL
);
622 dock
->attract_icons
= !dock
->attract_icons
;
623 /*if (!dock->attract_icons)
624 dock->keep_attracted = 0;*/
626 entry
->flags
.indicator_on
= dock
->attract_icons
;
633 selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
635 WAppIcon
*icon
= (WAppIcon
*)entry
->clientdata
;
639 wIconSelect(icon
->icon
);
646 colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
648 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
651 int x
, y
, x_pos
, y_pos
;
653 assert(entry
->clientdata
!=NULL
);
654 clip
= clickedIcon
->dock
;
656 aicon
= clip
->screen_ptr
->app_icon_list
;
659 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
660 x_pos
= clip
->x_pos
+ x
*ICON_SIZE
;
661 y_pos
= clip
->y_pos
+ y
*ICON_SIZE
;
662 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
664 if (wPreferences
.no_animations
) {
665 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
667 SlideWindow(aicon
->icon
->core
->window
,
668 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
671 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
672 #endif /* ANIMATIONS */
674 aicon
->attracted
= 1;
675 if (!aicon
->icon
->shadowed
) {
676 aicon
->icon
->shadowed
= 1;
677 aicon
->icon
->force_paint
= 1;
678 /* We don't do an wAppIconPaint() here because it's in
679 * wDockAttachIcon(). -Dan
682 wDockAttachIcon(clip
, aicon
, x
, y
);
683 if (clip
->collapsed
|| !clip
->mapped
)
684 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
692 selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
694 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
696 WMArray
*selectedIcons
;
697 WMArrayIterator iter
;
701 assert(clickedIcon
!=NULL
);
702 dock
= clickedIcon
->dock
;
704 selectedIcons
= getSelected(dock
);
706 if (!WMGetArrayItemCount(selectedIcons
)) {
707 for (i
=1; i
<dock
->max_icons
; i
++) {
708 btn
= dock
->icon_array
[i
];
709 if (btn
&& !btn
->icon
->selected
) {
710 wIconSelect(btn
->icon
);
714 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
715 wIconSelect(btn
->icon
);
718 WMFreeArray(selectedIcons
);
725 toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
727 assert(entry
->clientdata
!=NULL
);
729 toggleCollapsed(entry
->clientdata
);
731 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->collapsed
;
738 toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
741 assert(entry
->clientdata
!=NULL
);
743 dock
= (WDock
*) entry
->clientdata
;
745 dock
->auto_collapse
= !dock
->auto_collapse
;
747 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_collapse
;
754 toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
757 assert(entry
->clientdata
!=NULL
);
759 dock
= (WDock
*) entry
->clientdata
;
761 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
763 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_raise_lower
;
770 launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
772 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
774 launchDockedApplication(btn
);
779 settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
781 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
785 ShowDockAppSettingsPanel(btn
);
790 hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
793 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
795 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
797 if (wapp
->flags
.hidden
) {
798 wWorkspaceChange(btn
->icon
->core
->screen_ptr
,wapp
->last_workspace
);
799 wUnhideApplication(wapp
, False
, False
);
801 wHideApplication(wapp
);
807 unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
810 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
812 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
814 wUnhideApplication(wapp
, False
, True
);
819 mainIconCreate(WScreen
*scr
, int type
)
824 if (type
== WM_CLIP
) {
826 return scr
->clip_icon
;
827 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
828 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
829 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
830 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
831 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE;*/
834 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
835 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
841 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
842 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
843 btn
->icon
->core
->descriptor
.parent
= btn
;
844 /*ChangeStackingLevel(btn->icon->core, WMDockLevel);*/
845 XMapWindow(dpy
, btn
->icon
->core
->window
);
850 scr
->clip_icon
= btn
;
857 switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
859 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
860 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
862 WMArray
*selectedIcons
;
865 if (entry
->order
== scr
->current_workspace
)
868 dest
= scr
->workspaces
[entry
->order
]->clip
;
870 selectedIcons
= getSelected(src
);
872 if (WMGetArrayItemCount(selectedIcons
)) {
873 WMArrayIterator iter
;
875 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
876 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
877 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
878 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
881 } else if (icon
!= scr
->clip_icon
) {
882 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
883 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
884 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
887 WMFreeArray(selectedIcons
);
893 launchDockedApplication(WAppIcon
*btn
)
895 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
897 if (!btn
->launching
&& btn
->command
!=NULL
) {
898 if (!btn
->forced_dock
) {
899 btn
->relaunching
= btn
->running
;
902 if (btn
->wm_instance
|| btn
->wm_class
) {
903 WWindowAttributes attr
;
904 memset(&attr
, 0, sizeof(WWindowAttributes
));
905 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
,
908 if (!attr
.no_appicon
&& !btn
->buggy_app
)
913 btn
->drop_launch
= 0;
914 scr
->last_dock
= btn
->dock
;
915 btn
->pid
= execCommand(btn
, btn
->command
, NULL
);
917 if (btn
->buggy_app
) {
918 /* give feedback that the app was launched */
922 WMAddTimerHandler(200, (WMCallback
*)dockIconPaint
, btn
);
927 wwarning(_("could not launch application %s\n"), btn
->command
);
929 if (!btn
->relaunching
)
938 updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
940 WScreen
*scr
= menu
->frame
->screen_ptr
;
941 char title
[MAX_WORKSPACENAME_WIDTH
+1];
947 for (i
=0; i
<scr
->workspace_count
; i
++) {
948 if (i
< menu
->entry_no
) {
949 if (strcmp(menu
->entries
[i
]->text
,scr
->workspaces
[i
]->name
)!=0) {
950 wfree(menu
->entries
[i
]->text
);
951 strcpy(title
, scr
->workspaces
[i
]->name
);
952 menu
->entries
[i
]->text
= wstrdup(title
);
953 menu
->flags
.realized
= 0;
955 menu
->entries
[i
]->clientdata
= (void*)icon
;
957 strcpy(title
, scr
->workspaces
[i
]->name
);
959 wMenuAddCallback(menu
, title
, switchWSCommand
, (void*)icon
);
961 menu
->flags
.realized
= 0;
963 if (i
== scr
->current_workspace
) {
964 wMenuSetEnabled(menu
, i
, False
);
966 wMenuSetEnabled(menu
, i
, True
);
970 if (!menu
->flags
.realized
)
976 makeWorkspaceMenu(WScreen
*scr
)
980 menu
= wMenuCreate(scr
, NULL
, False
);
982 wwarning(_("could not create workspace submenu for Clip menu"));
984 wMenuAddCallback(menu
, "", switchWSCommand
, (void*)scr
->clip_icon
);
986 menu
->flags
.realized
= 0;
994 updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
1003 entry
= menu
->entries
[index
];
1004 entry
->flags
.indicator_on
= !dock
->lowered
;
1005 entry
->clientdata
= dock
;
1008 entry
= menu
->entries
[++index
];
1009 entry
->flags
.indicator_on
= dock
->collapsed
;
1010 entry
->clientdata
= dock
;
1013 entry
= menu
->entries
[++index
];
1014 entry
->flags
.indicator_on
= dock
->auto_collapse
;
1015 entry
->clientdata
= dock
;
1017 /* auto-raise/lower */
1018 entry
= menu
->entries
[++index
];
1019 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1020 entry
->clientdata
= dock
;
1023 entry
= menu
->entries
[++index
];
1024 entry
->flags
.indicator_on
= dock
->attract_icons
;
1025 entry
->clientdata
= dock
;
1027 menu
->flags
.realized
= 0;
1033 makeClipOptionsMenu(WScreen
*scr
)
1038 menu
= wMenuCreate(scr
, NULL
, False
);
1040 wwarning(_("could not create options submenu for Clip menu"));
1044 entry
= wMenuAddCallback(menu
, _("Keep on Top"),
1045 toggleLoweredCallback
, NULL
);
1046 entry
->flags
.indicator
= 1;
1047 entry
->flags
.indicator_on
= 1;
1048 entry
->flags
.indicator_type
= MI_CHECK
;
1050 entry
= wMenuAddCallback(menu
, _("Collapsed"),
1051 toggleCollapsedCallback
, NULL
);
1052 entry
->flags
.indicator
= 1;
1053 entry
->flags
.indicator_on
= 1;
1054 entry
->flags
.indicator_type
= MI_CHECK
;
1056 entry
= wMenuAddCallback(menu
, _("Autocollapse"),
1057 toggleAutoCollapseCallback
, NULL
);
1058 entry
->flags
.indicator
= 1;
1059 entry
->flags
.indicator_on
= 1;
1060 entry
->flags
.indicator_type
= MI_CHECK
;
1062 entry
= wMenuAddCallback(menu
, _("Autoraise"),
1063 toggleAutoRaiseLowerCallback
, NULL
);
1064 entry
->flags
.indicator
= 1;
1065 entry
->flags
.indicator_on
= 1;
1066 entry
->flags
.indicator_type
= MI_CHECK
;
1068 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"),
1069 toggleAutoAttractCallback
, NULL
);
1070 entry
->flags
.indicator
= 1;
1071 entry
->flags
.indicator_on
= 1;
1072 entry
->flags
.indicator_type
= MI_CHECK
;
1074 menu
->flags
.realized
= 0;
1082 dockMenuCreate(WScreen
*scr
, int type
)
1087 if (type
== WM_CLIP
&& scr
->clip_menu
)
1088 return scr
->clip_menu
;
1090 menu
= wMenuCreate(scr
, NULL
, False
);
1091 if (type
!= WM_CLIP
) {
1092 entry
= wMenuAddCallback(menu
, _("Keep on Top"),
1093 toggleLoweredCallback
, NULL
);
1094 entry
->flags
.indicator
= 1;
1095 entry
->flags
.indicator_on
= 1;
1096 entry
->flags
.indicator_type
= MI_CHECK
;
1098 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1099 scr
->clip_options
= makeClipOptionsMenu(scr
);
1100 if (scr
->clip_options
)
1101 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1103 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
,
1106 entry
->text
= _("Rename Workspace");
1108 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1109 entry
->flags
.indicator
= 1;
1110 entry
->flags
.indicator_on
= 1;
1111 entry
->flags
.indicator_type
= MI_CHECK
;
1113 entry
= wMenuAddCallback(menu
, _("Select All Icons"),
1114 selectIconsCallback
, NULL
);
1116 entry
->text
= _("Select All Icons");
1118 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1120 entry
->text
= _("Keep Icon");
1122 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1124 entry
->text
= _("Move Icon To");
1125 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1126 if (scr
->clip_submenu
)
1127 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1129 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
,
1132 entry
->text
= _("Remove Icon");
1134 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1137 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1139 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1141 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1143 entry
->text
= _("Hide");
1145 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1147 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1149 if (type
== WM_CLIP
)
1150 scr
->clip_menu
= menu
;
1157 wDockCreate(WScreen
*scr
, int type
)
1165 dock
= wmalloc(sizeof(WDock
));
1166 memset(dock
, 0, sizeof(WDock
));
1168 if (type
== WM_CLIP
)
1169 icon_count
= CLIP_MAX_ICONS
;
1171 icon_count
= scr
->scr_height
/wPreferences
.icon_size
;
1173 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*)*icon_count
);
1174 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*)*icon_count
);
1176 dock
->max_icons
= icon_count
;
1178 btn
= mainIconCreate(scr
, type
);
1182 dock
->x_pos
= btn
->x_pos
;
1183 dock
->y_pos
= btn
->y_pos
;
1184 dock
->screen_ptr
= scr
;
1186 dock
->icon_count
= 1;
1187 dock
->on_right_side
= 1;
1188 dock
->collapsed
= 0;
1189 dock
->auto_collapse
= 0;
1190 dock
->auto_collapse_magic
= NULL
;
1191 dock
->auto_raise_lower
= 0;
1192 dock
->auto_lower_magic
= NULL
;
1193 dock
->auto_raise_magic
= NULL
;
1194 dock
->attract_icons
= 0;
1196 dock
->icon_array
[0] = btn
;
1197 wRaiseFrame(btn
->icon
->core
);
1198 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1200 /* create dock menu */
1201 dock
->menu
= dockMenuCreate(scr
, type
);
1208 wDockDestroy(WDock
*dock
)
1213 for (i
=(dock
->type
== WM_CLIP
) ? 1 : 0; i
<dock
->max_icons
; i
++) {
1214 aicon
= dock
->icon_array
[i
];
1216 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1217 wDockDetach(dock
, aicon
);
1219 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
1220 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
1221 aicon
->x_pos
, aicon
->y_pos
);
1222 if (!dock
->mapped
|| dock
->collapsed
)
1223 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1227 if (wPreferences
.auto_arrange_icons
)
1228 wArrangeIcons(dock
->screen_ptr
, True
);
1229 wfree(dock
->icon_array
);
1230 if (dock
->menu
&& dock
->type
!=WM_CLIP
)
1231 wMenuDestroy(dock
->menu
, True
);
1232 if (dock
->screen_ptr
->last_dock
== dock
)
1233 dock
->screen_ptr
->last_dock
= NULL
;
1239 wClipIconPaint(WAppIcon
*aicon
)
1241 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1242 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1244 Window win
= aicon
->icon
->core
->window
;
1245 int length
, nlength
;
1246 char *ws_name
, ws_number
[10];
1249 wIconPaint(aicon
->icon
);
1251 length
= strlen(workspace
->name
);
1252 ws_name
= wmalloc(length
+ 1);
1253 snprintf(ws_name
, length
+1, "%s", workspace
->name
);
1254 snprintf(ws_number
, sizeof(ws_number
), "%i", scr
->current_workspace
+ 1);
1255 nlength
= strlen(ws_number
);
1257 gc
= scr
->clip_title_gc
;
1259 if (!workspace
->clip
->collapsed
)
1260 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_NORMAL
]);
1262 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_COLLAPSED
]);
1264 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1266 tx
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
1268 WMDrawString(scr
->wmscreen
, win
, gc
, scr
->clip_title_font
, tx
,
1269 ty
, ws_name
, length
);
1271 tx
= (ICON_SIZE
/2 - WMWidthOfString(scr
->clip_title_font
, ws_number
,
1274 WMDrawString(scr
->wmscreen
, win
, gc
, scr
->clip_title_font
, tx
,
1275 2, ws_number
, nlength
);
1279 if (aicon
->launching
) {
1280 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1281 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1283 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
,
1284 aicon
->dock
->rclip_button_pushed
);
1289 clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1291 wClipIconPaint(desc
->parent
);
1296 dockIconPaint(WAppIcon
*btn
)
1298 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1299 wClipIconPaint(btn
);
1306 make_icon_state(WAppIcon
*btn
)
1308 proplist_t node
= NULL
;
1309 proplist_t command
, autolaunch
, lock
, name
, forced
, host
, position
, buggy
;
1310 proplist_t omnipresent
;
1316 command
= PLMakeString("-");
1318 command
= PLMakeString(btn
->command
);
1320 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1322 lock
= btn
->lock
? dYes
: dNo
;
1324 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1326 name
= PLMakeString(tmp
);
1330 forced
= btn
->forced_dock
? dYes
: dNo
;
1332 buggy
= btn
->buggy_app
? dYes
: dNo
;
1334 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1335 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1337 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1338 position
= PLMakeString(buffer
);
1340 node
= PLMakeDictionaryFromEntries(dCommand
, command
,
1342 dAutoLaunch
, autolaunch
,
1345 dBuggyApplication
, buggy
,
1346 dPosition
, position
,
1350 PLRelease(position
);
1352 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1353 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&&
1354 (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1355 PLInsertDictionaryEntry(node
, dOmnipresent
, omnipresent
);
1358 if (btn
->dnd_command
) {
1359 command
= PLMakeString(btn
->dnd_command
);
1360 PLInsertDictionaryEntry(node
, dDropCommand
, command
);
1363 #endif /* OFFIX_DND */
1365 if (btn
->client_machine
&& btn
->remote_start
) {
1366 host
= PLMakeString(btn
->client_machine
);
1367 PLInsertDictionaryEntry(node
, dHost
, host
);
1377 dockSaveState(WDock
*dock
)
1380 proplist_t icon_info
;
1381 proplist_t list
=NULL
, dock_state
=NULL
;
1382 proplist_t value
, key
;
1385 list
= PLMakeArrayFromElements(NULL
);
1387 for (i
=(dock
->type
==WM_DOCK
? 0 : 1); i
<dock
->max_icons
; i
++) {
1388 WAppIcon
*btn
= dock
->icon_array
[i
];
1390 if (!btn
|| btn
->attracted
)
1393 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1394 list
= PLAppendArrayElement(list
, icon_info
);
1395 PLRelease(icon_info
);
1399 dock_state
= PLMakeDictionaryFromEntries(dApplications
, list
,
1402 if (dock
->type
== WM_DOCK
) {
1403 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1404 key
= PLMakeString(buffer
);
1405 PLInsertDictionaryEntry(dock_state
, key
, list
);
1409 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0),
1411 value
= PLMakeString(buffer
);
1412 PLInsertDictionaryEntry(dock_state
, dPosition
, value
);
1418 value
= (dock
->lowered
? dYes
: dNo
);
1419 PLInsertDictionaryEntry(dock_state
, dLowered
, value
);
1421 if (dock
->type
== WM_CLIP
) {
1422 value
= (dock
->collapsed
? dYes
: dNo
);
1423 PLInsertDictionaryEntry(dock_state
, dCollapsed
, value
);
1425 value
= (dock
->auto_collapse
? dYes
: dNo
);
1426 PLInsertDictionaryEntry(dock_state
, dAutoCollapse
, value
);
1428 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1429 PLInsertDictionaryEntry(dock_state
, dAutoRaiseLower
, value
);
1431 value
= (dock
->attract_icons
? dYes
: dNo
);
1432 PLInsertDictionaryEntry(dock_state
, dAutoAttractIcons
, value
);
1440 wDockSaveState(WScreen
*scr
, proplist_t old_state
)
1442 proplist_t dock_state
;
1445 dock_state
= dockSaveState(scr
->dock
);
1448 * Copy saved states of docks with different sizes.
1454 keys
= PLGetAllDictionaryKeys(old_state
);
1455 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
1456 tmp
= PLGetArrayElement(keys
, i
);
1458 if (strncasecmp(PLGetString(tmp
), "applications", 12) == 0
1459 && !PLGetDictionaryEntry(dock_state
, tmp
)) {
1461 PLInsertDictionaryEntry(dock_state
,
1463 PLGetDictionaryEntry(old_state
, tmp
));
1470 PLInsertDictionaryEntry(scr
->session_state
, dDock
, dock_state
);
1472 PLRelease(dock_state
);
1477 wClipSaveState(WScreen
*scr
)
1479 proplist_t clip_state
;
1481 clip_state
= make_icon_state(scr
->clip_icon
);
1483 PLInsertDictionaryEntry(scr
->session_state
, dClip
, clip_state
);
1485 PLRelease(clip_state
);
1490 wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1492 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1497 getBooleanDockValue(proplist_t value
, proplist_t key
)
1500 if (PLIsString(value
)) {
1501 if (strcasecmp(PLGetString(value
), "YES")==0)
1504 wwarning(_("bad value in docked icon state info %s"),
1513 restore_icon_state(WScreen
*scr
, proplist_t info
, int type
, int index
)
1516 proplist_t cmd
, value
;
1519 cmd
= PLGetDictionaryEntry(info
, dCommand
);
1520 if (!cmd
|| !PLIsString(cmd
)) {
1524 /* parse window name */
1525 value
= PLGetDictionaryEntry(info
, dName
);
1530 char *wclass
, *winstance
;
1533 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1535 if (!winstance
&& !wclass
) {
1542 command
= wstrdup(PLGetString(cmd
));
1546 if (!command
|| strcmp(command
, "-")==0) {
1557 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
,
1567 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1568 if (type
== WM_CLIP
) {
1569 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1570 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1572 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1573 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1577 cmd
= PLGetDictionaryEntry(info
, dDropCommand
);
1579 aicon
->dnd_command
= wstrdup(PLGetString(cmd
));
1582 /* check auto launch */
1583 value
= PLGetDictionaryEntry(info
, dAutoLaunch
);
1585 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1588 value
= PLGetDictionaryEntry(info
, dLock
);
1590 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1592 /* check if it wasn't normally docked */
1593 value
= PLGetDictionaryEntry(info
, dForced
);
1595 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1597 /* check if we can rely on the stuff in the app */
1598 value
= PLGetDictionaryEntry(info
, dBuggyApplication
);
1600 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1602 /* get position in the dock */
1603 value
= PLGetDictionaryEntry(info
, dPosition
);
1604 if (value
&& PLIsString(value
)) {
1605 if (sscanf(PLGetString(value
), "%hi,%hi", &aicon
->xindex
,
1607 wwarning(_("bad value in docked icon state info %s"),
1608 PLGetString(dPosition
));
1610 /* check position sanity */
1611 /* incomplete section! */
1612 if (type
== WM_DOCK
) {
1614 if (aicon
->yindex
< 0)
1615 wwarning(_("bad value in docked icon position %i,%i"),
1616 aicon
->xindex
, aicon
->yindex
);
1619 aicon
->yindex
= index
;
1623 /* check if icon is omnipresent */
1624 value
= PLGetDictionaryEntry(info
, dOmnipresent
);
1626 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1635 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1639 wClipRestoreState(WScreen
*scr
, proplist_t clip_state
)
1645 icon
= mainIconCreate(scr
, WM_CLIP
);
1650 PLRetain(clip_state
);
1652 /* restore position */
1654 value
= PLGetDictionaryEntry(clip_state
, dPosition
);
1657 if (!PLIsString(value
))
1658 COMPLAIN("Position");
1660 if (sscanf(PLGetString(value
), "%i,%i", &icon
->x_pos
,
1662 COMPLAIN("Position");
1664 /* check position sanity */
1665 if (icon
->y_pos
< 0)
1667 else if (icon
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1668 icon
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1670 if (icon
->x_pos
< 0)
1672 else if (icon
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1673 icon
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1678 value
= PLGetDictionaryEntry(clip_state
, dDropCommand
);
1679 if (value
&& PLIsString(value
))
1680 icon
->dnd_command
= wstrdup(PLGetString(value
));
1683 PLRelease(clip_state
);
1690 wDockRestoreState(WScreen
*scr
, proplist_t dock_state
, int type
)
1695 WAppIcon
*aicon
, *old_top
;
1699 dock
= wDockCreate(scr
, type
);
1705 PLRetain(dock_state
);
1708 /* restore position */
1710 value
= PLGetDictionaryEntry(dock_state
, dPosition
);
1713 if (!PLIsString(value
))
1714 COMPLAIN("Position");
1716 if (sscanf(PLGetString(value
), "%i,%i", &dock
->x_pos
,
1718 COMPLAIN("Position");
1720 /* check position sanity */
1721 if (dock
->y_pos
< 0)
1723 else if (dock
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1724 dock
->y_pos
= scr
->scr_height
- ICON_SIZE
;
1726 /* This is no more needed. ??? */
1727 if (type
== WM_CLIP
) {
1728 if (dock
->x_pos
< 0)
1730 else if (dock
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1731 dock
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1733 if (dock
->x_pos
>= 0) {
1734 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1735 dock
->on_right_side
= 0;
1737 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1738 dock
->on_right_side
= 1;
1744 /* restore lowered/raised state */
1748 value
= PLGetDictionaryEntry(dock_state
, dLowered
);
1751 if (!PLIsString(value
))
1752 COMPLAIN("Lowered");
1754 if (strcasecmp(PLGetString(value
), "YES")==0)
1760 /* restore collapsed state */
1762 dock
->collapsed
= 0;
1764 value
= PLGetDictionaryEntry(dock_state
, dCollapsed
);
1767 if (!PLIsString(value
))
1768 COMPLAIN("Collapsed");
1770 if (strcasecmp(PLGetString(value
), "YES")==0)
1771 dock
->collapsed
= 1;
1776 /* restore auto-collapsed state */
1778 value
= PLGetDictionaryEntry(dock_state
, dAutoCollapse
);
1781 if (!PLIsString(value
))
1782 COMPLAIN("AutoCollapse");
1784 if (strcasecmp(PLGetString(value
), "YES")==0) {
1785 dock
->auto_collapse
= 1;
1786 dock
->collapsed
= 1;
1792 /* restore auto-raise/lower state */
1794 value
= PLGetDictionaryEntry(dock_state
, dAutoRaiseLower
);
1797 if (!PLIsString(value
))
1798 COMPLAIN("AutoRaiseLower");
1800 if (strcasecmp(PLGetString(value
), "YES")==0) {
1801 dock
->auto_raise_lower
= 1;
1806 /* restore attract icons state */
1808 dock
->attract_icons
= 0;
1810 value
= PLGetDictionaryEntry(dock_state
, dAutoAttractIcons
);
1813 if (!PLIsString(value
))
1814 COMPLAIN("AutoAttractIcons");
1816 if (strcasecmp(PLGetString(value
), "YES")==0)
1817 dock
->attract_icons
= 1;
1822 /* application list */
1829 * When saving, it saves the dock state in
1830 * Applications and Applicationsnnn
1832 * When loading, it will first try Applicationsnnn.
1833 * If it does not exist, use Applications as default.
1836 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1838 tmp
= PLMakeString(buffer
);
1839 apps
= PLGetDictionaryEntry(dock_state
, tmp
);
1843 apps
= PLGetDictionaryEntry(dock_state
, dApplications
);
1851 count
= PLGetNumberOfElements(apps
);
1856 old_top
= dock
->icon_array
[0];
1858 /* dock->icon_count is set to 1 when dock is created.
1859 * Since Clip is already restored, we want to keep it so for clip,
1860 * but for dock we may change the default top tile, so we set it to 0.
1862 if (type
== WM_DOCK
)
1863 dock
->icon_count
= 0;
1865 for (i
=0; i
<count
; i
++) {
1866 if (dock
->icon_count
>= dock
->max_icons
) {
1867 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1871 value
= PLGetArrayElement(apps
, i
);
1872 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1874 dock
->icon_array
[dock
->icon_count
] = aicon
;
1878 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
*ICON_SIZE
);
1879 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
*ICON_SIZE
);
1882 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1884 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1886 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
,
1889 if (!dock
->collapsed
)
1890 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1891 wRaiseFrame(aicon
->icon
->core
);
1894 } else if (dock
->icon_count
==0 && type
==WM_DOCK
)
1898 /* if the first icon is not defined, use the default */
1899 if (dock
->icon_array
[0]==NULL
) {
1900 /* update default icon */
1901 old_top
->x_pos
= dock
->x_pos
;
1902 old_top
->y_pos
= dock
->y_pos
;
1904 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1906 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1907 dock
->icon_array
[0] = old_top
;
1908 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1909 /* we don't need to increment dock->icon_count here because it was
1910 * incremented in the loop above.
1912 } else if (old_top
!=dock
->icon_array
[0]) {
1913 if (old_top
== scr
->clip_icon
)
1914 scr
->clip_icon
= dock
->icon_array
[0];
1915 wAppIconDestroy(old_top
);
1920 PLRelease(dock_state
);
1928 wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1930 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1932 btn
->drop_launch
= 0;
1934 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1937 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1949 wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1955 for (i
= 0; i
< dock
->max_icons
; i
++) {
1956 btn
= dock
->icon_array
[i
];
1957 if (!btn
|| !btn
->auto_launch
)
1960 state
= wmalloc(sizeof(WSavedState
));
1961 memset(state
, 0, sizeof(WSavedState
));
1962 state
->workspace
= workspace
;
1963 /* TODO: this is klugy and is very difficult to understand
1964 * what's going on. Try to clean up */
1965 wDockLaunchWithState(dock
, btn
, state
);
1972 findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1978 if ((dock
= scr
->dock
)!=NULL
) {
1979 for (i
=0; i
<dock
->max_icons
; i
++) {
1980 if (dock
->icon_array
[i
]
1981 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1987 if (*icon_pos
<0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
)!=NULL
) {
1988 for (i
=0; i
<dock
->max_icons
; i
++) {
1989 if (dock
->icon_array
[i
]
1990 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
2003 wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
2009 dock
= findDock(scr
, event
, &icon_pos
);
2014 * Return True if the drop was on an application icon window.
2015 * In this case, let the ClientMessage handler redirect the
2016 * message to the app.
2018 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!=None
)
2021 if (dock
->icon_array
[icon_pos
]->dnd_command
!=NULL
) {
2022 scr
->flags
.dnd_data_convertion_status
= 0;
2024 btn
= dock
->icon_array
[icon_pos
];
2026 if (!btn
->forced_dock
) {
2027 btn
->relaunching
= btn
->running
;
2030 if (btn
->wm_instance
|| btn
->wm_class
) {
2031 WWindowAttributes attr
;
2032 memset(&attr
, 0, sizeof(WWindowAttributes
));
2033 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
2035 btn
->wm_class
, &attr
, NULL
, True
);
2037 if (!attr
.no_appicon
)
2043 btn
->drop_launch
= 1;
2044 scr
->last_dock
= dock
;
2045 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
2050 if (!btn
->relaunching
) {
2057 #endif /* OFFIX_DND */
2062 wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2069 wwin
= icon
->icon
->owner
;
2070 if (icon
->command
==NULL
) {
2072 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2074 icon
->command
= wtokenjoin(argv
, argc
);
2075 XFreeStringList(argv
);
2079 /* icon->forced_dock = 1;*/
2080 if (dock
->type
!=WM_CLIP
|| !icon
->attracted
) {
2082 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2083 _("Type the command used to launch the application"),
2085 if (command
&& (command
[0]==0 ||
2086 (command
[0]=='-' && command
[1]==0))) {
2090 icon
->command
= command
;
2096 /* If the target is the dock, reject the icon. If
2097 * the target is the clip, make it an attracted icon
2099 if (dock
->type
==WM_CLIP
) {
2100 icon
->attracted
= 1;
2101 if (!icon
->icon
->shadowed
) {
2102 icon
->icon
->shadowed
= 1;
2103 icon
->icon
->force_paint
= 1;
2115 for (index
=1; index
<dock
->max_icons
; index
++)
2116 if (dock
->icon_array
[index
] == NULL
)
2118 /* if (index == dock->max_icons)
2121 assert(index
< dock
->max_icons
);
2123 dock
->icon_array
[index
] = icon
;
2127 icon
->omnipresent
= 0;
2129 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2130 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2135 icon
->launching
= 0;
2138 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2139 if (dock
->type
== WM_CLIP
) {
2140 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2141 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2143 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2144 icon
->icon
->core
->descriptor
.parent
= icon
;
2146 MoveInStackListUnder(dock
->icon_array
[index
-1]->icon
->core
,
2148 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2149 wAppIconPaint(icon
);
2151 if (wPreferences
.auto_arrange_icons
)
2152 wArrangeIcons(dock
->screen_ptr
, True
);
2155 if (icon
->command
&& !icon
->dnd_command
) {
2156 int len
= strlen(icon
->command
)+8;
2157 icon
->dnd_command
= wmalloc(len
);
2158 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
2167 reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2171 for(index
=1; index
<dock
->max_icons
; index
++) {
2172 if(dock
->icon_array
[index
] == icon
)
2175 assert(index
< dock
->max_icons
);
2180 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2181 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2186 moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2194 return True
; /* No move needed, we're already there */
2199 wwin
= icon
->icon
->owner
;
2202 * For the moment we can't do this if we move icons in Clip from one
2203 * workspace to other, because if we move two or more icons without
2204 * command, the dialog box will not be able to tell us to which of the
2205 * moved icons it applies. -Dan
2207 if ((dest
->type
==WM_DOCK
/*|| dest->keep_attracted*/) && icon
->command
==NULL
) {
2208 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2210 icon
->command
= wtokenjoin(argv
, argc
);
2211 XFreeStringList(argv
);
2216 /* icon->forced_dock = 1;*/
2217 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2218 _("Type the command used to launch the application"),
2220 if (command
&& (command
[0]==0 ||
2221 (command
[0]=='-' && command
[1]==0))) {
2225 icon
->command
= command
;
2236 if (dest
->type
== WM_DOCK
)
2237 wClipMakeIconOmnipresent(icon
, False
);
2239 for(index
=1; index
<src
->max_icons
; index
++) {
2240 if(src
->icon_array
[index
] == icon
)
2243 assert(index
< src
->max_icons
);
2245 src
->icon_array
[index
] = NULL
;
2248 for(index
=1; index
<dest
->max_icons
; index
++) {
2249 if(dest
->icon_array
[index
] == NULL
)
2252 /* if (index == dest->max_icons)
2255 assert(index
< dest
->max_icons
);
2257 dest
->icon_array
[index
] = icon
;
2260 /* deselect the icon */
2261 if (icon
->icon
->selected
)
2262 wIconSelect(icon
->icon
);
2264 if (dest
->type
== WM_DOCK
) {
2265 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2266 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2268 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2269 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2272 /* set it to be kept when moving to dock.
2273 * Unless the icon does not have a command set
2275 if (icon
->command
&& dest
->type
==WM_DOCK
) {
2276 icon
->attracted
= 0;
2277 if (icon
->icon
->shadowed
) {
2278 icon
->icon
->shadowed
= 0;
2279 icon
->icon
->force_paint
= 1;
2283 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2289 icon
->x_pos
= dest
->x_pos
+ x
*ICON_SIZE
;
2290 icon
->y_pos
= dest
->y_pos
+ y
*ICON_SIZE
;
2294 MoveInStackListUnder(dest
->icon_array
[index
-1]->icon
->core
,
2296 wAppIconPaint(icon
);
2303 wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2307 /* make the settings panel be closed */
2309 DestroyDockAppSettingsPanel(icon
->panel
);
2312 /* This must be called before icon->dock is set to NULL.
2313 * Don't move it. -Dan
2315 wClipMakeIconOmnipresent(icon
, False
);
2319 icon
->attracted
= 0;
2320 icon
->auto_launch
= 0;
2321 if (icon
->icon
->shadowed
) {
2322 icon
->icon
->shadowed
= 0;
2323 icon
->icon
->force_paint
= 1;
2326 /* deselect the icon */
2327 if (icon
->icon
->selected
)
2328 wIconSelect(icon
->icon
);
2330 if (icon
->command
) {
2331 wfree(icon
->command
);
2332 icon
->command
= NULL
;
2335 if (icon
->dnd_command
) {
2336 wfree(icon
->dnd_command
);
2337 icon
->dnd_command
= NULL
;
2341 for (index
=1; index
<dock
->max_icons
; index
++)
2342 if (dock
->icon_array
[index
] == icon
)
2344 assert(index
< dock
->max_icons
);
2345 dock
->icon_array
[index
] = NULL
;
2351 /* if the dock is not attached to an application or
2352 * the the application did not set the approriate hints yet,
2353 * destroy the icon */
2354 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2355 wAppIconDestroy(icon
);
2357 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2358 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2359 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2360 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2361 icon
->icon
->core
->descriptor
.parent
= icon
;
2363 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2365 wAppIconPaint(icon
);
2366 if (wPreferences
.auto_arrange_icons
) {
2367 wArrangeIcons(dock
->screen_ptr
, True
);
2369 WAppIcon
*bla
= wAppIconNextSibling(icon
);
2372 SlideWindow(icon
->icon
->core
->window
, icon
->x_pos
, icon
->y_pos
,
2373 bla
->x_pos
, bla
->y_pos
);
2374 wAppIconMove(icon
, bla
->x_pos
, bla
->y_pos
);
2378 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2384 * returns the closest Dock slot index for the passed
2387 * Returns False if icon can't be docked.
2389 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2393 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2394 int *ret_x
, int *ret_y
, int redocking
)
2396 WScreen
*scr
= dock
->screen_ptr
;
2399 int i
, offset
= ICON_SIZE
/2;
2400 WAppIcon
*aicon
= NULL
;
2401 WAppIcon
*nicon
= NULL
;
2402 int max_y_icons
, max_x_icons
;
2404 max_x_icons
= scr
->scr_width
/ICON_SIZE
;
2405 max_y_icons
= scr
->scr_height
/ICON_SIZE
-1;
2407 if (wPreferences
.flags
.noupdates
)
2413 /* if the dock is full */
2415 (dock
->icon_count
>= dock
->max_icons
)) {
2419 /* exact position */
2421 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2423 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2426 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2428 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2430 /* check if the icon is outside the screen boundaries */
2431 if (dx
+ ex_x
*ICON_SIZE
< -ICON_SIZE
+2 ||
2432 dx
+ ex_x
*ICON_SIZE
>= scr
->scr_width
-1 ||
2433 dy
+ ex_y
*ICON_SIZE
< -ICON_SIZE
+2 ||
2434 dy
+ ex_y
*ICON_SIZE
>= scr
->scr_height
-1)
2437 if (dock
->type
== WM_DOCK
) {
2438 if (icon
->dock
!= dock
&& ex_x
!= 0)
2442 for (i
=0; i
<dock
->max_icons
; i
++) {
2443 nicon
= dock
->icon_array
[i
];
2444 if (nicon
&& nicon
->yindex
== ex_y
) {
2451 int sig
, done
, closest
;
2453 /* Possible cases when redocking:
2455 * icon dragged out of range of any slot -> false
2456 * icon dragged to range of free slot
2457 * icon dragged to range of same slot
2458 * icon dragged to range of different icon
2460 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2463 if (ex_y
>=0 && ex_y
<=max_y_icons
&& (aicon
==icon
|| !aicon
)) {
2469 /* start looking at the upper slot or lower? */
2470 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2477 /* look for closest free slot */
2478 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2482 closest
= sig
*(i
/2) + ex_y
;
2483 /* check if this slot is used */
2485 for (j
= 0; j
<dock
->max_icons
; j
++) {
2486 if (dock
->icon_array
[j
]
2487 && dock
->icon_array
[j
]->yindex
==closest
) {
2488 /* slot is used by someone else */
2489 if (dock
->icon_array
[j
]!=icon
)
2497 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2498 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2500 (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+1))) {
2505 } else { /* !redocking */
2507 /* if slot is free and the icon is close enough, return it */
2508 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2518 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2519 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+1;
2522 for (k
=start
; k
<stop
; k
++) {
2523 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2526 for (i
=0; i
<tmp
->max_icons
; i
++) {
2527 nicon
= tmp
->icon_array
[i
];
2528 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2536 for (k
=start
; k
<stop
; k
++) {
2537 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2540 for (i
=0; i
<tmp
->max_icons
; i
++) {
2541 nicon
= tmp
->icon_array
[i
];
2542 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2543 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2544 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2553 if (neighbours
&& (aicon
==NULL
|| (redocking
&& aicon
== icon
))) {
2563 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2564 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2565 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2569 * returns true if it can find a free slot in the dock,
2570 * in which case it changes x_pos and y_pos accordingly.
2571 * Else returns false.
2574 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2576 WScreen
*scr
= dock
->screen_ptr
;
2578 WAppIconChain
*chain
;
2579 unsigned char *slot_map
;
2583 int i
, done
= False
;
2585 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2588 if (dock
->type
== WM_CLIP
&&
2589 dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2590 extra_count
= scr
->global_icon_count
;
2592 /* if the dock is full */
2593 if (dock
->icon_count
+extra_count
>= dock
->max_icons
) {
2597 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2598 if (scr
->dock
->on_right_side
)
2599 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2601 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2604 if (ex
< dock
->x_pos
)
2606 if (sx
> dock
->x_pos
+ICON_SIZE
)
2607 sx
= dock
->x_pos
+ICON_SIZE
;
2614 /* check if clip is in a corner */
2615 if (dock
->type
==WM_CLIP
) {
2616 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2618 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2620 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2622 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2629 /* If the clip is in the corner, use only slots that are in the border
2631 if (corner
!=C_NONE
) {
2635 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2636 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2637 hmap
= wmalloc(hcount
+1);
2638 memset(hmap
, 0, hcount
+1);
2639 vmap
= wmalloc(vcount
+1);
2640 memset(vmap
, 0, vcount
+1);
2642 /* mark used positions */
2645 for (i
=0; i
<dock
->max_icons
; i
++) {
2646 btn
= dock
->icon_array
[i
];
2650 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2651 vmap
[btn
->yindex
] = 1;
2652 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2653 hmap
[btn
->xindex
] = 1;
2655 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2657 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2658 vmap
[btn
->yindex
] = 1;
2659 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2660 hmap
[btn
->xindex
] = 1;
2664 for (i
=0; i
<dock
->max_icons
; i
++) {
2665 btn
= dock
->icon_array
[i
];
2669 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2670 vmap
[btn
->yindex
] = 1;
2671 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2672 hmap
[-btn
->xindex
] = 1;
2674 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2676 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2677 vmap
[btn
->yindex
] = 1;
2678 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2679 hmap
[-btn
->xindex
] = 1;
2683 for (i
=0; i
<dock
->max_icons
; i
++) {
2684 btn
= dock
->icon_array
[i
];
2688 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2689 vmap
[-btn
->yindex
] = 1;
2690 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2691 hmap
[btn
->xindex
] = 1;
2693 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2695 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2696 vmap
[-btn
->yindex
] = 1;
2697 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2698 hmap
[btn
->xindex
] = 1;
2703 for (i
=0; i
<dock
->max_icons
; i
++) {
2704 btn
= dock
->icon_array
[i
];
2708 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2709 vmap
[-btn
->yindex
] = 1;
2710 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2711 hmap
[-btn
->xindex
] = 1;
2713 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2715 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2716 vmap
[-btn
->yindex
] = 1;
2717 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2718 hmap
[-btn
->xindex
] = 1;
2723 /* search a vacant slot */
2724 for (i
=1; i
<WMAX(vcount
, hcount
); i
++) {
2725 if (i
< vcount
&& vmap
[i
]==0) {
2731 } else if (i
< hcount
&& hmap
[i
]==0) {
2741 /* If found a slot, translate and return */
2743 if (corner
==C_NW
|| corner
==C_NE
) {
2748 if (corner
==C_NE
|| corner
==C_SE
) {
2755 /* else, try to find a slot somewhere else */
2758 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2759 * placed outside of screen */
2760 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2762 /* In the worst case (the clip is in the corner of the screen),
2763 * the amount of icons that fit in the clip is smaller.
2764 * Double the map to get a safe value.
2770 slot_map
= wmalloc(mwidth
*mwidth
);
2771 memset(slot_map
, 0, mwidth
*mwidth
);
2773 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2775 /* mark used slots in the map. If the slot falls outside the map
2776 * (for example, when all icons are placed in line), ignore them. */
2777 for (i
=0; i
<dock
->max_icons
; i
++) {
2778 btn
= dock
->icon_array
[i
];
2780 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2782 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2783 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2785 /* Find closest slot from the center that is free by scanning the
2786 * map from the center to outward in circular passes.
2787 * This will not result in a neat layout, but will be optimal
2788 * in the sense that there will not be holes left.
2791 for (i
= 1; i
<= r
&& !done
; i
++) {
2794 /* top and bottom parts of the ring */
2795 for (x
= -i
; x
<= i
&& !done
; x
++) {
2796 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2798 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2799 if (slot_map
[XY2OFS(x
,y
)]==0
2800 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2807 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2808 if (slot_map
[XY2OFS(x
,y
)]==0
2809 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2816 /* left and right parts of the ring */
2817 for (y
= -i
+1; y
<= i
-1; y
++) {
2818 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2820 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2821 if (slot_map
[XY2OFS(x
,y
)]==0
2822 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2829 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2830 if (slot_map
[XY2OFS(x
,y
)]==0
2831 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2846 moveDock(WDock
*dock
, int new_x
, int new_y
)
2851 dock
->x_pos
= new_x
;
2852 dock
->y_pos
= new_y
;
2853 for (i
=0; i
<dock
->max_icons
; i
++) {
2854 btn
= dock
->icon_array
[i
];
2856 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2857 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2858 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2865 swapDock(WDock
*dock
)
2867 WScreen
*scr
= dock
->screen_ptr
;
2872 if (dock
->on_right_side
) {
2873 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2875 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2878 for (i
=0; i
<dock
->max_icons
; i
++) {
2879 btn
= dock
->icon_array
[i
];
2882 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2886 wScreenUpdateUsableArea(scr
);
2891 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2893 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2899 cmdline
= ExpandOptions(scr
, command
);
2901 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2909 wtokensplit(cmdline
, &argv
, &argc
);
2919 if ((pid
=fork())==0) {
2923 SetupEnvironment(scr
);
2929 args
= malloc(sizeof(char*)*(argc
+1));
2932 for (i
=0; i
<argc
; i
++) {
2936 execvp(argv
[0], args
);
2940 wfree(argv
[--argc
]);
2945 state
= wmalloc(sizeof(WSavedState
));
2946 memset(state
, 0, sizeof(WSavedState
));
2948 state
->miniaturized
= -1;
2950 if (btn
->dock
==scr
->dock
|| btn
->omnipresent
)
2951 state
->workspace
= -1;
2953 state
->workspace
= scr
->current_workspace
;
2955 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
2957 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
2968 wDockHideIcons(WDock
*dock
)
2975 for (i
=1; i
<dock
->max_icons
; i
++) {
2976 if (dock
->icon_array
[i
])
2977 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2981 dockIconPaint(dock
->icon_array
[0]);
2986 wDockShowIcons(WDock
*dock
)
2994 btn
= dock
->icon_array
[0];
2995 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2997 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2998 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
3000 for (i
=1; i
<dock
->max_icons
; i
++) {
3001 if (dock
->icon_array
[i
]) {
3002 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
3008 if (!dock
->collapsed
) {
3009 for (i
=1; i
<dock
->max_icons
; i
++) {
3010 if (dock
->icon_array
[i
]) {
3011 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3022 wDockLower(WDock
*dock
)
3026 for (i
=0; i
<dock
->max_icons
; i
++) {
3027 if (dock
->icon_array
[i
])
3028 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
3034 wDockRaise(WDock
*dock
)
3038 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
3039 if (dock
->icon_array
[i
])
3040 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
3046 wDockRaiseLower(WDock
*dock
)
3048 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
3049 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
3050 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
3058 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
3060 icon
->launching
= 0;
3061 icon
->relaunching
= 0;
3062 dockIconPaint(icon
);
3067 wDockFindIconForWindow(WDock
*dock
, Window window
)
3072 for (i
=0; i
<dock
->max_icons
; i
++) {
3073 icon
= dock
->icon_array
[i
];
3074 if (icon
&& icon
->main_window
== window
)
3082 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
3085 char *wm_class
, *wm_instance
;
3087 Bool firstPass
= True
;
3089 char *command
= NULL
;
3095 if (XGetCommand(dpy
, window
, &argv
, &argc
)) {
3096 if (argc
> 0 && argv
!= NULL
)
3097 command
= wtokenjoin(argv
,argc
);
3099 XFreeStringList(argv
);
3104 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
3105 (!wm_class
&& !wm_instance
))
3109 for (i
=0; i
<dock
->max_icons
; i
++) {
3110 icon
= dock
->icon_array
[i
];
3114 /* app is already attached to icon */
3115 if (icon
->main_window
== window
) {
3120 if ((icon
->wm_instance
|| icon
->wm_class
)
3122 || (dock
->screen_ptr
->flags
.startup
&& !icon
->running
))) {
3124 if (icon
->wm_instance
&& wm_instance
&&
3125 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
3128 if (icon
->wm_class
&& wm_class
&&
3129 strcmp(icon
->wm_class
, wm_class
)!=0) {
3132 if (firstPass
&& command
&& strcmp(icon
->command
, command
)!=0) {
3136 if (!icon
->relaunching
) {
3139 /* Possibly an application that was docked with dockit,
3140 * but the user did not update WMState to indicate that
3141 * it was docked by force */
3142 wapp
= wApplicationOf(window
);
3144 icon
->forced_dock
= 1;
3147 if (!icon
->forced_dock
)
3148 icon
->main_window
= window
;
3152 wDockFinishLaunch(dock
, icon
);
3157 if (firstPass
&& !found
) {
3174 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3176 if (!wPreferences
.flags
.noclip
) {
3177 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3178 if (scr
->current_workspace
!= workspace
) {
3179 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3180 WAppIconChain
*chain
= scr
->global_icons
;
3183 moveIconBetweenDocks(chain
->aicon
->dock
,
3184 scr
->workspaces
[workspace
]->clip
,
3185 chain
->aicon
, chain
->aicon
->xindex
,
3186 chain
->aicon
->yindex
);
3187 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
3188 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3189 chain
= chain
->next
;
3192 wDockHideIcons(old_clip
);
3193 if (old_clip
->auto_raise_lower
) {
3194 if (old_clip
->auto_raise_magic
) {
3195 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3196 old_clip
->auto_raise_magic
= NULL
;
3198 wDockLower(old_clip
);
3200 if (old_clip
->auto_collapse
) {
3201 if (old_clip
->auto_expand_magic
) {
3202 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3203 old_clip
->auto_expand_magic
= NULL
;
3205 old_clip
->collapsed
= 1;
3207 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3209 if (scr
->flags
.clip_balloon_mapped
)
3210 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3217 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3222 for (i
=0; i
<dock
->max_icons
; i
++) {
3223 icon
= dock
->icon_array
[i
];
3227 if (icon
->launching
&& icon
->pid
== pid
) {
3228 if (!icon
->relaunching
) {
3230 icon
->main_window
= None
;
3232 wDockFinishLaunch(dock
, icon
);
3237 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""),
3238 icon
->drop_launch
&& icon
->dnd_command
3239 ? icon
->dnd_command
: icon
->command
);
3241 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""),
3244 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
3245 _("OK"), NULL
, NULL
);
3254 toggleLowered(WDock
*dock
)
3259 /* lower/raise Dock */
3260 if (!dock
->lowered
) {
3261 newlevel
= WMNormalLevel
;
3264 newlevel
= WMDockLevel
;
3268 for (i
=0; i
<dock
->max_icons
; i
++) {
3269 tmp
= dock
->icon_array
[i
];
3273 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3275 wLowerFrame(tmp
->icon
->core
);
3278 if (dock
->type
== WM_DOCK
)
3279 wScreenUpdateUsableArea(dock
->screen_ptr
);
3284 toggleCollapsed(WDock
*dock
)
3286 if (dock
->collapsed
) {
3287 dock
->collapsed
= 0;
3288 wDockShowIcons(dock
);
3291 dock
->collapsed
= 1;
3292 wDockHideIcons(dock
);
3298 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3300 WScreen
*scr
= dock
->screen_ptr
;
3301 WObjDescriptor
*desc
;
3303 WApplication
*wapp
= NULL
;
3307 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3309 if (dock
->type
== WM_DOCK
) {
3311 entry
= dock
->menu
->entries
[index
];
3312 entry
->flags
.indicator_on
= !dock
->lowered
;
3313 entry
->clientdata
= dock
;
3314 dock
->menu
->flags
.realized
= 0;
3317 if (scr
->clip_options
)
3318 updateClipOptionsMenu(scr
->clip_options
, dock
);
3320 n_selected
= numberOfSelectedIcons(dock
);
3322 /* Rename Workspace */
3323 entry
= dock
->menu
->entries
[++index
];
3324 if (aicon
== scr
->clip_icon
) {
3325 entry
->callback
= renameCallback
;
3326 entry
->clientdata
= dock
;
3327 entry
->flags
.indicator
= 0;
3328 entry
->text
= _("Rename Workspace");
3330 entry
->callback
= omnipresentCallback
;
3331 entry
->clientdata
= aicon
;
3332 if (n_selected
> 0) {
3333 entry
->flags
.indicator
= 0;
3334 entry
->text
= _("Toggle Omnipresent");
3336 entry
->flags
.indicator
= 1;
3337 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3338 entry
->flags
.indicator_type
= MI_CHECK
;
3339 entry
->text
= _("Omnipresent");
3343 /* select/unselect icon */
3344 entry
= dock
->menu
->entries
[++index
];
3345 entry
->clientdata
= aicon
;
3346 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3347 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3349 /* select/unselect all icons */
3350 entry
= dock
->menu
->entries
[++index
];
3351 entry
->clientdata
= aicon
;
3353 entry
->text
= _("Unselect All Icons");
3355 entry
->text
= _("Select All Icons");
3356 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3359 entry
= dock
->menu
->entries
[++index
];
3360 entry
->clientdata
= aicon
;
3362 entry
->text
= _("Keep Icons");
3364 entry
->text
= _("Keep Icon");
3365 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3367 /* this is the workspace submenu part */
3368 entry
= dock
->menu
->entries
[++index
];
3370 entry
->text
= _("Move Icons To");
3372 entry
->text
= _("Move Icon To");
3373 if (scr
->clip_submenu
)
3374 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3375 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3377 /* remove icon(s) */
3378 entry
= dock
->menu
->entries
[++index
];
3379 entry
->clientdata
= aicon
;
3381 entry
->text
= _("Remove Icons");
3383 entry
->text
= _("Remove Icon");
3384 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3386 /* attract icon(s) */
3387 entry
= dock
->menu
->entries
[++index
];
3388 entry
->clientdata
= aicon
;
3390 dock
->menu
->flags
.realized
= 0;
3391 wMenuRealize(dock
->menu
);
3395 if (aicon
->icon
->owner
) {
3396 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3402 entry
= dock
->menu
->entries
[++index
];
3403 entry
->clientdata
= aicon
;
3404 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3407 entry
= dock
->menu
->entries
[++index
];
3408 entry
->clientdata
= aicon
;
3409 if (wapp
&& wapp
->flags
.hidden
) {
3410 entry
->text
= _("Unhide Here");
3412 entry
->text
= _("Bring Here");
3414 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3417 entry
= dock
->menu
->entries
[++index
];
3418 entry
->clientdata
= aicon
;
3419 if (wapp
&& wapp
->flags
.hidden
) {
3420 entry
->text
= _("Unhide");
3422 entry
->text
= _("Hide");
3424 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3427 entry
= dock
->menu
->entries
[++index
];
3428 entry
->clientdata
= aicon
;
3429 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
3430 && !wPreferences
.flags
.noupdates
);
3433 entry
= dock
->menu
->entries
[++index
];
3434 entry
->clientdata
= aicon
;
3435 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3437 if (!dock
->menu
->flags
.realized
)
3438 wMenuRealize(dock
->menu
);
3440 if (dock
->type
== WM_CLIP
) {
3441 x_pos
= event
->xbutton
.x_root
+2;
3443 x_pos
= dock
->on_right_side
?
3444 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 2 : 0;
3447 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3449 /* allow drag select */
3450 event
->xany
.send_event
= True
;
3451 desc
= &dock
->menu
->menu
->descriptor
;
3452 (*desc
->handle_mousedown
)(desc
, event
);
3457 openClipWorkspaceMenu(WScreen
*scr
, int x
, int y
)
3459 if (!scr
->clip_ws_menu
) {
3460 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3462 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
3463 wMenuMapAt(scr
->clip_ws_menu
, x
, y
, False
);
3467 /******************************************************************/
3469 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3471 WAppIcon
*btn
= desc
->parent
;
3472 WDock
*dock
= btn
->dock
;
3473 WApplication
*wapp
= NULL
;
3476 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3477 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3481 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3483 /* go to the last workspace that the user worked on the app */
3484 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
3486 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3489 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3492 if (event
->xbutton
.state
& MOD_MASK
) {
3493 wHideOtherApplications(btn
->icon
->owner
);
3496 if (event
->xbutton
.button
==Button1
) {
3498 if (event
->xbutton
.state
& MOD_MASK
) {
3499 /* raise/lower dock */
3500 toggleLowered(dock
);
3501 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3502 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3503 toggleCollapsed(dock
);
3505 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3506 } else if (btn
->command
) {
3507 if (!btn
->launching
&&
3508 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3509 launchDockedApplication(btn
);
3511 } else if (btn
->xindex
== 0 && btn
->yindex
== 0
3512 && btn
->dock
->type
== WM_DOCK
) {
3514 wShowGNUstepPanel(dock
->screen_ptr
);
3522 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3524 WScreen
*scr
= dock
->screen_ptr
;
3525 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3528 int grabbed
= 0, swapped
= 0, done
;
3529 Pixmap ghost
= None
;
3530 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3533 puts("moving dock");
3535 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3536 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3537 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3538 wwarning("pointer grab failed for dock move");
3541 for (x
=0; x
<dock
->max_icons
; x
++) {
3542 if (dock
->icon_array
[x
]!=NULL
&&
3543 dock
->icon_array
[x
]->yindex
> y
)
3544 y
= dock
->icon_array
[x
]->yindex
;
3547 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3551 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3552 |ButtonMotionMask
|ExposureMask
, &ev
);
3560 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3561 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3562 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3563 |ButtonReleaseMask
|ButtonPressMask
,
3564 wCursor
[WCUR_MOVE
], CurrentTime
);
3569 if (dock
->type
== WM_CLIP
) {
3570 if (ev
.xmotion
.x_root
- ofs_x
< 0) {
3572 } else if (ev
.xmotion
.x_root
- ofs_x
+ ICON_SIZE
>
3574 x
= scr
->scr_width
- ICON_SIZE
;
3576 x
= ev
.xmotion
.x_root
- ofs_x
;
3578 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3580 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3582 y
= scr
->scr_height
- ICON_SIZE
;
3584 y
= ev
.xmotion
.y_root
- ofs_y
;
3586 moveDock(dock
, x
, y
);
3588 /* move vertically if pointer is inside the dock*/
3589 if ((dock
->on_right_side
&&
3590 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3591 || (!dock
->on_right_side
&&
3592 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3594 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3596 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3598 y
= scr
->scr_height
- ICON_SIZE
;
3600 y
= ev
.xmotion
.y_root
- ofs_y
;
3602 moveDock(dock
, dock
->x_pos
, y
);
3604 /* move horizontally to change sides */
3605 x
= ev
.xmotion
.x_root
- ofs_x
;
3606 if (!dock
->on_right_side
) {
3610 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3611 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3612 -DOCK_EXTRA_SPACE
-1, dock
->y_pos
);
3613 if (superfluous
&& ghost
==None
) {
3614 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3615 scr
->scr_width
-ICON_SIZE
3616 -DOCK_EXTRA_SPACE
-1,
3618 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3620 XClearWindow(dpy
, scr
->dock_shadow
);
3622 XMapRaised(dpy
, scr
->dock_shadow
);
3625 if (superfluous
&& ghost
!=None
) {
3626 XFreePixmap(dpy
, ghost
);
3629 XUnmapWindow(dpy
, scr
->dock_shadow
);
3634 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3635 XMoveWindow(dpy
, scr
->dock_shadow
,
3636 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3637 if (superfluous
&& ghost
==None
) {
3638 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3639 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3640 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3642 XClearWindow(dpy
, scr
->dock_shadow
);
3644 XMapRaised(dpy
, scr
->dock_shadow
);
3647 XUnmapWindow(dpy
, scr
->dock_shadow
);
3649 if (superfluous
&& ghost
!=None
) {
3650 XFreePixmap(dpy
, ghost
);
3662 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3664 XUngrabPointer(dpy
, CurrentTime
);
3665 XUnmapWindow(dpy
, scr
->dock_shadow
);
3666 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3667 if (dock
->type
== WM_DOCK
) {
3670 dock
->on_right_side
= 1;
3672 dock
->on_right_side
= 0;
3674 wArrangeIcons(scr
, False
);
3683 XFreePixmap(dpy
, ghost
);
3684 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3687 puts("End dock move");
3694 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3696 WScreen
*scr
= dock
->screen_ptr
;
3698 WIcon
*icon
= aicon
->icon
;
3699 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3700 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3702 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3703 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3704 int shad_x
= x
, shad_y
= y
;
3705 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3707 Pixmap ghost
= None
;
3709 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3710 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3713 if (wPreferences
.flags
.noupdates
)
3716 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3717 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3718 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3720 wwarning("pointer grab failed for icon move");
3724 if (!(event
->xbutton
.state
& MOD_MASK
))
3725 wRaiseFrame(icon
->core
);
3727 if (!wPreferences
.flags
.noclip
)
3728 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3730 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3732 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3735 wins
[0] = icon
->core
->window
;
3736 wins
[1] = scr
->dock_shadow
;
3737 XRestackWindows(dpy
, wins
, 2);
3738 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3739 ICON_SIZE
, ICON_SIZE
);
3741 if (icon
->pixmap
!=None
)
3742 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3744 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3746 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3747 XClearWindow(dpy
, scr
->dock_shadow
);
3749 XMapWindow(dpy
, scr
->dock_shadow
);
3755 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3756 |ButtonMotionMask
|ExposureMask
, &ev
);
3764 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3765 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3766 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3767 |ButtonReleaseMask
|ButtonPressMask
,
3768 wCursor
[WCUR_MOVE
], CurrentTime
);
3777 for (i
=0; i
<scr
->workspace_count
; i
++) {
3778 if (i
== scr
->current_workspace
)
3780 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3784 x
= ev
.xmotion
.x_root
- ofs_x
;
3785 y
= ev
.xmotion
.y_root
- ofs_y
;
3786 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3789 if (last_dock
!= dock
&& collapsed
) {
3790 last_dock
->collapsed
= 1;
3791 wDockHideIcons(last_dock
);
3794 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3795 dock
->collapsed
= 0;
3796 wDockShowIcons(dock
);
3798 if (dock
->auto_raise_lower
)
3802 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3805 if (last_dock
!= dock2
&& collapsed
) {
3806 last_dock
->collapsed
= 1;
3807 wDockHideIcons(last_dock
);
3810 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3811 dock2
->collapsed
= 0;
3812 wDockShowIcons(dock2
);
3814 if (dock2
->auto_raise_lower
)
3819 if (aicon
->launching
3821 || (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3822 || (!aicon
->running
&& tmp
)) {
3823 shad_x
= last_dock
->x_pos
+ ix
*wPreferences
.icon_size
;
3824 shad_y
= last_dock
->y_pos
+ iy
*wPreferences
.icon_size
;
3826 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3829 XMapWindow(dpy
, scr
->dock_shadow
);
3834 XUnmapWindow(dpy
, scr
->dock_shadow
);
3838 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3845 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3847 XUngrabPointer(dpy
, CurrentTime
);
3849 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3850 XUnmapWindow(dpy
, scr
->dock_shadow
);
3852 reattachIcon(dock
, aicon
, ix
, iy
);
3853 if (clip
&& dock
!=clip
&& clip
->auto_raise_lower
)
3856 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3858 /* Slide it back if dock rejected it */
3859 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3861 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3863 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3871 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3872 /* We need to deselect it, even if is deselected in
3873 * wDockDetach(), because else DoKaboom() will fail.
3875 if (aicon
->icon
->selected
)
3876 wIconSelect(aicon
->icon
);
3878 wSoundPlay(WSOUND_KABOOM
);
3879 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3881 wSoundPlay(WSOUND_UNDOCK
);
3884 wSoundPlay(WSOUND_UNDOCK
);
3886 if (clip
&& clip
->auto_raise_lower
)
3888 wDockDetach(dock
, aicon
);
3891 last_dock
->collapsed
= 1;
3892 wDockHideIcons(last_dock
);
3897 XFreePixmap(dpy
, ghost
);
3898 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3902 for (i
=0; i
<scr
->workspace_count
; i
++) {
3903 if (i
== scr
->current_workspace
)
3905 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3910 puts("End icon move");
3919 getClipButton(int px
, int py
)
3921 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
3923 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3926 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
3927 return CLIP_FORWARD
;
3928 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
3936 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3939 int done
, direction
, new_ws
;
3941 WDock
*clip
= scr
->clip_icon
->dock
;
3943 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3945 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3946 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3948 wClipIconPaint(scr
->clip_icon
);
3951 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
3952 |ButtonPressMask
, &ev
);
3959 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3960 if (new_dir
!= direction
) {
3961 direction
= new_dir
;
3962 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3963 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3964 wClipIconPaint(scr
->clip_icon
);
3972 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3977 clip
->lclip_button_pushed
= 0;
3978 clip
->rclip_button_pushed
= 0;
3980 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3982 if (direction
== CLIP_FORWARD
) {
3983 if (scr
->current_workspace
< scr
->workspace_count
-1)
3984 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3985 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
3986 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3987 else if (wPreferences
.ws_cycle
)
3988 wWorkspaceChange(scr
, 0);
3990 else if (direction
== CLIP_REWIND
) {
3991 if (scr
->current_workspace
> 0)
3992 wWorkspaceChange(scr
, scr
->current_workspace
-1);
3993 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
3994 wWorkspaceChange(scr
, scr
->workspace_count
-1);
3997 wClipIconPaint(scr
->clip_icon
);
4002 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
4004 WAppIcon
*aicon
= desc
->parent
;
4005 WDock
*dock
= aicon
->dock
;
4006 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4008 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
4011 scr
->last_dock
= dock
;
4013 if (dock
->menu
->flags
.mapped
)
4014 wMenuUnmap(dock
->menu
);
4016 if (IsDoubleClick(scr
, event
)) {
4017 /* double-click was not in the main clip icon */
4018 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
4019 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
4020 iconDblClick(desc
, event
);
4025 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
4026 XUnmapWindow(dpy
, scr
->clip_balloon
);
4027 scr
->flags
.clip_balloon_mapped
= 0;
4031 puts("handling dock");
4033 if (event
->xbutton
.button
== Button1
) {
4034 if (event
->xbutton
.state
& MOD_MASK
)
4039 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
4040 dock
->type
!=WM_DOCK
) {
4041 wIconSelect(aicon
->icon
);
4045 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
4046 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
4047 && dock
->type
==WM_CLIP
)
4048 handleClipChangeWorkspace(scr
, event
);
4050 handleDockMove(dock
, aicon
, event
);
4052 handleIconMove(dock
, aicon
, event
);
4054 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4055 aicon
==scr
->clip_icon
) {
4056 openClipWorkspaceMenu(scr
, event
->xbutton
.x_root
+2,
4057 event
->xbutton
.y_root
+2);
4058 if (scr
->clip_ws_menu
) {
4060 menu
= scr
->clip_ws_menu
;
4061 desc
= &menu
->menu
->descriptor
;
4063 event
->xany
.send_event
= True
;
4064 (*desc
->handle_mousedown
)(desc
, event
);
4066 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4067 (event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
) {
4068 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
4069 } else if (event
->xbutton
.button
== Button3
) {
4070 if (event
->xbutton
.send_event
&&
4071 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
4072 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
4073 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
4074 wwarning("pointer grab failed for dockicon menu");
4078 openDockMenu(dock
, aicon
, event
);
4084 showClipBalloon(WDock
*dock
, int workspace
)
4088 WScreen
*scr
= dock
->screen_ptr
;
4092 scr
->flags
.clip_balloon_mapped
= 1;
4093 XMapWindow(dpy
, scr
->clip_balloon
);
4095 text
= scr
->workspaces
[workspace
]->name
;
4097 w
= WMWidthOfString(scr
->clip_title_font
, text
, strlen(text
));
4099 h
= WMFontHeight(scr
->clip_title_font
);
4100 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
4102 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
4103 y
= dock
->y_pos
+ ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
4105 if (x
+w
> scr
->scr_width
) {
4106 x
= scr
->scr_width
- w
;
4107 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
4108 y
= dock
->y_pos
- h
- 1;
4110 y
= dock
->y_pos
+ ICON_SIZE
;
4111 XRaiseWindow(dpy
, scr
->clip_balloon
);
4113 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
4114 stack
[1] = scr
->clip_balloon
;
4115 XRestackWindows(dpy
, stack
, 2);
4117 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
4118 XSetForeground(dpy
, scr
->clip_title_gc
,
4119 scr
->clip_title_pixel
[CLIP_NORMAL
]);
4120 XClearWindow(dpy
, scr
->clip_balloon
);
4121 WMDrawString(scr
->wmscreen
, scr
->clip_balloon
, scr
->clip_title_gc
,
4122 scr
->clip_title_font
, 0, 0, text
, strlen(text
));
4127 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
4129 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4133 assert(event
->type
==EnterNotify
);
4135 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4138 scr
= btn
->icon
->core
->screen_ptr
;
4139 if (!btn
->omnipresent
)
4142 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
4144 if (!dock
|| dock
->type
!=WM_CLIP
)
4147 /* The auto raise/lower code */
4148 if (dock
->auto_lower_magic
) {
4149 WMDeleteTimerHandler(dock
->auto_lower_magic
);
4150 dock
->auto_lower_magic
= NULL
;
4152 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
4153 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
,
4158 /* The auto expand/collapse code */
4159 if (dock
->auto_collapse_magic
) {
4160 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
4161 dock
->auto_collapse_magic
= NULL
;
4163 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
4164 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
,
4169 if (btn
->xindex
== 0 && btn
->yindex
== 0)
4170 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4172 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4173 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
4174 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
4181 clipLeave(WDock
*dock
)
4184 WObjDescriptor
*desc
= NULL
;
4186 if (!dock
|| dock
->type
!=WM_CLIP
)
4189 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
)!=False
) {
4190 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
4191 (XPointer
*)&desc
)!=XCNOENT
4192 && desc
&& desc
->parent_type
==WCLASS_DOCK_ICON
4193 && ((WAppIcon
*)desc
->parent
)->dock
4194 && ((WAppIcon
*)desc
->parent
)->dock
->type
==WM_CLIP
) {
4195 /* We didn't left the Clip yet */
4196 XPutBackEvent(dpy
, &event
);
4200 XPutBackEvent(dpy
, &event
);
4202 /* We entered a withdrawn window, so we're still in Clip */
4206 if (dock
->auto_raise_magic
) {
4207 WMDeleteTimerHandler(dock
->auto_raise_magic
);
4208 dock
->auto_raise_magic
= NULL
;
4210 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
4211 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
,
4216 if (dock
->auto_expand_magic
) {
4217 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4218 dock
->auto_expand_magic
= NULL
;
4220 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
4221 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
4229 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4231 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4233 assert(event
->type
==LeaveNotify
);
4235 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4238 clipLeave(btn
->dock
);
4243 clipAutoCollapse(void *cdata
)
4245 WDock
*dock
= (WDock
*)cdata
;
4247 if (dock
->type
!=WM_CLIP
)
4250 if (dock
->auto_collapse
) {
4251 dock
->collapsed
= 1;
4252 wDockHideIcons(dock
);
4254 dock
->auto_collapse_magic
= NULL
;
4259 clipAutoExpand(void *cdata
)
4261 WDock
*dock
= (WDock
*)cdata
;
4263 if (dock
->type
!=WM_CLIP
)
4266 if (dock
->auto_collapse
) {
4267 dock
->collapsed
= 0;
4268 wDockShowIcons(dock
);
4270 dock
->auto_expand_magic
= NULL
;
4275 clipAutoLower(void *cdata
)
4277 WDock
*dock
= (WDock
*)cdata
;
4279 if (dock
->type
!=WM_CLIP
)
4282 if (dock
->auto_raise_lower
)
4285 dock
->auto_lower_magic
= NULL
;
4290 clipAutoRaise(void *cdata
)
4292 WDock
*dock
= (WDock
*)cdata
;
4294 if (dock
->type
!=WM_CLIP
)
4297 if (dock
->auto_raise_lower
)
4300 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4301 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4304 dock
->auto_raise_magic
= NULL
;
4309 iconCanBeOmnipresent(WAppIcon
*aicon
)
4311 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4316 for (i
=0; i
<scr
->workspace_count
; i
++) {
4317 clip
= scr
->workspaces
[i
]->clip
;
4319 if (clip
== aicon
->dock
)
4322 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4323 return False
; /* Clip is full in some workspace */
4325 for (j
=0; j
<clip
->max_icons
; j
++) {
4326 btn
= clip
->icon_array
[j
];
4327 if(btn
&& btn
->xindex
==aicon
->xindex
&& btn
->yindex
==aicon
->yindex
)
4337 wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
4339 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4340 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4341 int status
= WO_SUCCESS
;
4343 if ((scr
->dock
&& aicon
->dock
==scr
->dock
) || aicon
==scr
->clip_icon
) {
4344 return WO_NOT_APPLICABLE
;
4347 if (aicon
->omnipresent
== omnipresent
)
4351 if (iconCanBeOmnipresent(aicon
)) {
4352 aicon
->omnipresent
= 1;
4353 new_entry
= wmalloc(sizeof(WAppIconChain
));
4354 new_entry
->aicon
= aicon
;
4355 new_entry
->next
= scr
->global_icons
;
4356 scr
->global_icons
= new_entry
;
4357 scr
->global_icon_count
++;
4359 aicon
->omnipresent
= 0;
4363 aicon
->omnipresent
= 0;
4364 if (aicon
== scr
->global_icons
->aicon
) {
4365 tmp
= scr
->global_icons
->next
;
4366 wfree(scr
->global_icons
);
4367 scr
->global_icons
= tmp
;
4368 scr
->global_icon_count
--;
4370 tmp
= scr
->global_icons
;
4372 if (tmp
->next
->aicon
== aicon
) {
4373 tmp1
= tmp
->next
->next
;
4376 scr
->global_icon_count
--;
4384 wAppIconPaint(aicon
);