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 sprintf(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
)
242 #ifdef REDUCE_APPICONS
243 WAppIconAppList
*tapplist
;
245 extern Atom _XA_WM_DELETE_WINDOW
;
250 if (!WCHECK_STATE(WSTATE_NORMAL
))
253 assert(entry
->clientdata
!=NULL
);
255 icon
= (WAppIcon
*)entry
->clientdata
;
259 WCHANGE_STATE(WSTATE_MODAL
);
261 #ifdef REDUCE_APPICONS
262 /* Send a delete message to the main window of each application
263 * bound to this docked appicon. - cls
265 tapplist
= icon
->applist
;
266 while (tapplist
!= NULL
) {
267 if (tapplist
->wapp
->main_window_desc
!= NULL
) {
268 if (tapplist
->wapp
->main_window_desc
->protocols
.DELETE_WINDOW
) {
269 wClientSendProtocol(tapplist
->wapp
->main_window_desc
,
270 _XA_WM_DELETE_WINDOW
, CurrentTime
);
272 wClientKill(tapplist
->wapp
->main_window_desc
);
275 tapplist
= tapplist
->next
;
278 buffer
= wstrappend(icon
->wm_class
,
279 _(" will be forcibly closed.\n"
280 "Any unsaved changes will be lost.\n"
283 if (wPreferences
.dont_confirm_kill
284 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
285 buffer
, _("Yes"), _("No"), NULL
)==WAPRDefault
) {
286 if (icon
->icon
&& icon
->icon
->owner
) {
287 wClientKill(icon
->icon
->owner
);
290 #endif /* !REDUCE_APPICONS */
294 WCHANGE_STATE(WSTATE_NORMAL
);
298 /* TODO: replace this function with a member of the dock struct */
300 numberOfSelectedIcons(WDock
*dock
)
306 for (i
=1; i
<dock
->max_icons
; i
++) {
307 aicon
= dock
->icon_array
[i
];
308 if (aicon
&& aicon
->icon
->selected
) {
318 getSelected(WDock
*dock
)
320 WMBag
*ret
= WMCreateBag(8);
324 for (i
=1; i
<dock
->max_icons
; i
++) {
325 btn
= dock
->icon_array
[i
];
326 if (btn
&& btn
->icon
->selected
) {
327 WMPutInBag(ret
, btn
);
336 paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
338 Window win
= clipIcon
->icon
->core
->window
;
339 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
341 int pt
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
342 int tp
= ICON_SIZE
- pt
;
343 int as
= pt
- 15; /* 15 = 5+5+5 */
344 GC gc
= scr
->clip_title_gc
;
345 #ifdef GRADIENT_CLIP_ARROW
346 Bool collapsed
= clipIcon
->dock
->collapsed
;
352 p
[1].x
= ICON_SIZE
-2;
354 p
[2].x
= ICON_SIZE
-2;
356 } else if (lpushed
) {
360 p
[1].y
= ICON_SIZE
-2;
362 p
[2].y
= ICON_SIZE
-2;
364 if (lpushed
|| rpushed
) {
365 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
366 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
367 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
369 #ifdef GRADIENT_CLIP_ARROW
371 XSetFillStyle(dpy
, scr
->copy_gc
, FillTiled
);
372 XSetTile(dpy
, scr
->copy_gc
, scr
->clip_arrow_gradient
);
373 XSetClipMask(dpy
, scr
->copy_gc
, None
);
376 #endif /* GRADIENT_CLIP_ARROW */
378 /* top right arrow */
379 p
[0].x
= p
[3].x
= ICON_SIZE
-5-as
;
381 p
[1].x
= ICON_SIZE
-6;
383 p
[2].x
= ICON_SIZE
-6;
386 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
387 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
389 #ifdef GRADIENT_CLIP_ARROW
391 XSetTSOrigin(dpy
, gc
, ICON_SIZE
-6-as
, 5);
393 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
394 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
397 /* bottom left arrow */
399 p
[0].y
= p
[3].y
= ICON_SIZE
-5-as
;
401 p
[1].y
= ICON_SIZE
-6;
403 p
[2].y
= ICON_SIZE
-6;
405 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
406 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
408 #ifdef GRADIENT_CLIP_ARROW
410 XSetTSOrigin(dpy
, gc
, 5, ICON_SIZE
-6-as
);
412 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
413 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
415 #ifdef GRADIENT_CLIP_ARROW
417 XSetFillStyle(dpy
, scr
->copy_gc
, FillSolid
);
423 wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
425 RImage
*tile
= RCloneImage(normalTile
);
432 pt
= CLIP_BUTTON_SIZE
*wPreferences
.icon_size
/64;
433 tp
= wPreferences
.icon_size
-1 - pt
;
437 black
.red
= black
.green
= black
.blue
= 0;
440 dark
.red
= dark
.green
= dark
.blue
= 60;
443 light
.red
= light
.green
= light
.blue
= 80;
447 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
-2,
449 RDrawLine(tile
, tp
-1, 0, wPreferences
.icon_size
-1, pt
+1, &black
);
450 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
-3,
454 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4,
455 ICON_SIZE
- 5, 4, &dark
);
456 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5,
457 ICON_SIZE
- 5, 6 + as
, &dark
);
458 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
,
462 ROperateLine(tile
, RAddOperation
, 2, tp
+2, pt
-2,
463 wPreferences
.icon_size
-3, &dark
);
464 RDrawLine(tile
, 0, tp
-1, pt
+1, wPreferences
.icon_size
-1, &black
);
465 ROperateLine(tile
, RSubtractOperation
, 0, tp
-2, pt
+1,
466 wPreferences
.icon_size
-2, &light
);
469 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4,
470 ICON_SIZE
- 5, &dark
);
471 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
,
472 6 + as
, ICON_SIZE
- 5, &dark
);
473 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5,
481 omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
483 WAppIcon
*clickedIcon
= entry
->clientdata
;
486 WMBag
*selectedIcons
;
490 assert(entry
->clientdata
!=NULL
);
492 dock
= clickedIcon
->dock
;
494 selectedIcons
= getSelected(dock
);
496 if (!WMGetBagItemCount(selectedIcons
))
497 WMPutInBag(selectedIcons
, clickedIcon
);
500 for (i
= 0; i
< WMGetBagItemCount(selectedIcons
); i
++) {
501 aicon
= WMGetFromBag(selectedIcons
, i
);
503 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
505 else if (aicon
->icon
->selected
)
506 wIconSelect(aicon
->icon
);
508 WMFreeBag(selectedIcons
);
511 wMessageDialog(dock
->screen_ptr
, _("Warning"),
512 _("Some icons cannot be made omnipresent. "
513 "Please make sure that no other icon is "
514 "docked in the same positions on the other "
515 "workspaces and the Clip is not full in "
517 _("OK"), NULL
, NULL
);
518 } else if (failed
== 1) {
519 wMessageDialog(dock
->screen_ptr
, _("Warning"),
520 _("Icon cannot be made omnipresent. "
521 "Please make sure that no other icon is "
522 "docked in the same position on the other "
523 "workspaces and the Clip is not full in "
525 _("OK"), NULL
, NULL
);
531 removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
533 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
536 WMBag
*selectedIcons
;
540 assert(clickedIcon
!=NULL
);
542 dock
= clickedIcon
->dock
;
544 selectedIcons
= getSelected(dock
);
546 if (WMGetBagItemCount(selectedIcons
)) {
547 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
548 _("All selected icons will be removed!"),
549 _("OK"), _("Cancel"), NULL
)!=WAPRDefault
) {
550 WMFreeBag(selectedIcons
);
554 if (clickedIcon
->xindex
==0 && clickedIcon
->yindex
==0) {
555 WMFreeBag(selectedIcons
);
558 WMPutInBag(selectedIcons
, clickedIcon
);
561 for (i
= 0; i
< WMGetBagItemCount(selectedIcons
); i
++) {
562 aicon
= WMGetFromBag(selectedIcons
, i
);
563 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
564 wDockDetach(dock
, aicon
);
566 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
567 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
568 aicon
->x_pos
, aicon
->y_pos
);
569 if (!dock
->mapped
|| dock
->collapsed
)
570 XMapWindow(dpy
, aicon
->icon
->core
->window
);
573 WMFreeBag(selectedIcons
);
575 if (wPreferences
.auto_arrange_icons
)
576 wArrangeIcons(dock
->screen_ptr
, True
);
581 keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
583 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
586 WMBag
*selectedIcons
;
589 assert(clickedIcon
!=NULL
);
590 dock
= clickedIcon
->dock
;
592 selectedIcons
= getSelected(dock
);
594 if (!WMGetBagItemCount(selectedIcons
)
595 && clickedIcon
!=dock
->screen_ptr
->clip_icon
) {
596 char *command
= NULL
;
598 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
599 clickedIcon
->editing
= 1;
600 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
601 _("Type the command used to launch the application"),
603 if (command
&& (command
[0]==0 ||
604 (command
[0]=='-' && command
[1]==0))) {
608 clickedIcon
->command
= command
;
609 clickedIcon
->editing
= 0;
611 clickedIcon
->editing
= 0;
614 WMFreeBag(selectedIcons
);
619 WMPutInBag(selectedIcons
, clickedIcon
);
622 for (i
= 0; i
< WMGetBagItemCount(selectedIcons
); i
++) {
623 aicon
= WMGetFromBag(selectedIcons
, i
);
624 if (aicon
->icon
->selected
)
625 wIconSelect(aicon
->icon
);
626 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
627 aicon
->attracted
= 0;
628 if (aicon
->icon
->shadowed
) {
629 aicon
->icon
->shadowed
= 0;
630 aicon
->icon
->force_paint
= 1;
631 wAppIconPaint(aicon
);
635 WMFreeBag(selectedIcons
);
642 toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
644 WDock
*dock
= (WDock
*)entry
->clientdata
;
646 assert(entry
->clientdata
!=NULL
);
648 dock
->attract_icons
= !dock
->attract_icons
;
649 /*if (!dock->attract_icons)
650 dock->keep_attracted = 0;*/
652 entry
->flags
.indicator_on
= dock
->attract_icons
;
659 selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
661 WAppIcon
*icon
= (WAppIcon
*)entry
->clientdata
;
665 wIconSelect(icon
->icon
);
672 colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
674 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
677 int x
, y
, x_pos
, y_pos
;
679 assert(entry
->clientdata
!=NULL
);
680 clip
= clickedIcon
->dock
;
682 aicon
= clip
->screen_ptr
->app_icon_list
;
685 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
686 x_pos
= clip
->x_pos
+ x
*ICON_SIZE
;
687 y_pos
= clip
->y_pos
+ y
*ICON_SIZE
;
688 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
690 if (wPreferences
.no_animations
) {
691 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
693 SlideWindow(aicon
->icon
->core
->window
,
694 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
697 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
698 #endif /* ANIMATIONS */
700 aicon
->attracted
= 1;
701 if (!aicon
->icon
->shadowed
) {
702 aicon
->icon
->shadowed
= 1;
703 aicon
->icon
->force_paint
= 1;
704 /* We don't do an wAppIconPaint() here because it's in
705 * wDockAttachIcon(). -Dan
708 wDockAttachIcon(clip
, aicon
, x
, y
);
709 if (clip
->collapsed
|| !clip
->mapped
)
710 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
718 selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
720 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
722 WMBag
*selectedIcons
;
726 assert(clickedIcon
!=NULL
);
727 dock
= clickedIcon
->dock
;
729 selectedIcons
= getSelected(dock
);
731 if (!WMGetBagItemCount(selectedIcons
)) {
732 for (i
=1; i
<dock
->max_icons
; i
++) {
733 btn
= dock
->icon_array
[i
];
734 if (btn
&& !btn
->icon
->selected
) {
735 wIconSelect(btn
->icon
);
739 for (i
= 0; i
< WMGetBagItemCount(selectedIcons
); i
++) {
740 btn
= WMGetFromBag(selectedIcons
, i
);
741 wIconSelect(btn
->icon
);
744 WMFreeBag(selectedIcons
);
751 toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
753 assert(entry
->clientdata
!=NULL
);
755 toggleCollapsed(entry
->clientdata
);
757 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->collapsed
;
764 toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
767 assert(entry
->clientdata
!=NULL
);
769 dock
= (WDock
*) entry
->clientdata
;
771 dock
->auto_collapse
= !dock
->auto_collapse
;
773 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_collapse
;
780 toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
783 assert(entry
->clientdata
!=NULL
);
785 dock
= (WDock
*) entry
->clientdata
;
787 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
789 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_raise_lower
;
796 launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
798 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
800 launchDockedApplication(btn
);
805 settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
807 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
811 ShowDockAppSettingsPanel(btn
);
816 hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
819 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
821 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
823 if (wapp
->flags
.hidden
) {
824 wWorkspaceChange(btn
->icon
->core
->screen_ptr
,wapp
->last_workspace
);
825 wUnhideApplication(wapp
, False
, False
);
827 wHideApplication(wapp
);
833 unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
836 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
838 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
840 wUnhideApplication(wapp
, False
, True
);
845 mainIconCreate(WScreen
*scr
, int type
)
850 if (type
== WM_CLIP
) {
852 return scr
->clip_icon
;
853 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
854 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
855 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
856 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
857 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE;*/
860 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
861 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
867 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
868 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
869 btn
->icon
->core
->descriptor
.parent
= btn
;
870 /*ChangeStackingLevel(btn->icon->core, WMDockLevel);*/
871 XMapWindow(dpy
, btn
->icon
->core
->window
);
876 scr
->clip_icon
= btn
;
883 switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
885 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
886 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
888 WMBag
*selectedIcons
;
891 if (entry
->order
== scr
->current_workspace
)
894 dest
= scr
->workspaces
[entry
->order
]->clip
;
896 selectedIcons
= getSelected(src
);
898 if (WMGetBagItemCount(selectedIcons
)) {
900 for (i
= 0; i
< WMGetBagItemCount(selectedIcons
); i
++) {
901 btn
= WMGetFromBag(selectedIcons
, i
);
902 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
903 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
904 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
907 } else if (icon
!= scr
->clip_icon
) {
908 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
909 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
910 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
913 WMFreeBag(selectedIcons
);
919 launchDockedApplication(WAppIcon
*btn
)
921 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
923 if (!btn
->launching
&& btn
->command
!=NULL
) {
924 if (!btn
->forced_dock
) {
925 btn
->relaunching
= btn
->running
;
928 if (btn
->wm_instance
|| btn
->wm_class
) {
929 WWindowAttributes attr
;
930 memset(&attr
, 0, sizeof(WWindowAttributes
));
931 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
,
934 if (!attr
.no_appicon
&& !btn
->buggy_app
)
939 btn
->drop_launch
= 0;
940 scr
->last_dock
= btn
->dock
;
941 btn
->pid
= execCommand(btn
, btn
->command
, NULL
);
943 if (btn
->buggy_app
) {
944 /* give feedback that the app was launched */
948 WMAddTimerHandler(200, (WMCallback
*)dockIconPaint
, btn
);
953 wwarning(_("could not launch application %s\n"), btn
->command
);
955 if (!btn
->relaunching
)
964 updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
966 WScreen
*scr
= menu
->frame
->screen_ptr
;
967 char title
[MAX_WORKSPACENAME_WIDTH
+1];
973 for (i
=0; i
<scr
->workspace_count
; i
++) {
974 if (i
< menu
->entry_no
) {
975 if (strcmp(menu
->entries
[i
]->text
,scr
->workspaces
[i
]->name
)!=0) {
976 free(menu
->entries
[i
]->text
);
977 strcpy(title
, scr
->workspaces
[i
]->name
);
978 menu
->entries
[i
]->text
= wstrdup(title
);
979 menu
->flags
.realized
= 0;
981 menu
->entries
[i
]->clientdata
= (void*)icon
;
983 strcpy(title
, scr
->workspaces
[i
]->name
);
985 wMenuAddCallback(menu
, title
, switchWSCommand
, (void*)icon
);
987 menu
->flags
.realized
= 0;
989 if (i
== scr
->current_workspace
) {
990 wMenuSetEnabled(menu
, i
, False
);
992 wMenuSetEnabled(menu
, i
, True
);
996 if (!menu
->flags
.realized
)
1002 makeWorkspaceMenu(WScreen
*scr
)
1006 menu
= wMenuCreate(scr
, NULL
, False
);
1008 wwarning(_("could not create workspace submenu for Clip menu"));
1010 wMenuAddCallback(menu
, "", switchWSCommand
, (void*)scr
->clip_icon
);
1012 menu
->flags
.realized
= 0;
1020 updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
1029 entry
= menu
->entries
[index
];
1030 entry
->flags
.indicator_on
= !dock
->lowered
;
1031 entry
->clientdata
= dock
;
1034 entry
= menu
->entries
[++index
];
1035 entry
->flags
.indicator_on
= dock
->collapsed
;
1036 entry
->clientdata
= dock
;
1039 entry
= menu
->entries
[++index
];
1040 entry
->flags
.indicator_on
= dock
->auto_collapse
;
1041 entry
->clientdata
= dock
;
1043 /* auto-raise/lower */
1044 entry
= menu
->entries
[++index
];
1045 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1046 entry
->clientdata
= dock
;
1049 entry
= menu
->entries
[++index
];
1050 entry
->flags
.indicator_on
= dock
->attract_icons
;
1051 entry
->clientdata
= dock
;
1053 menu
->flags
.realized
= 0;
1059 makeClipOptionsMenu(WScreen
*scr
)
1064 menu
= wMenuCreate(scr
, NULL
, False
);
1066 wwarning(_("could not create options submenu for Clip menu"));
1070 entry
= wMenuAddCallback(menu
, _("Keep on Top"),
1071 toggleLoweredCallback
, NULL
);
1072 entry
->flags
.indicator
= 1;
1073 entry
->flags
.indicator_on
= 1;
1074 entry
->flags
.indicator_type
= MI_CHECK
;
1076 entry
= wMenuAddCallback(menu
, _("Collapsed"),
1077 toggleCollapsedCallback
, NULL
);
1078 entry
->flags
.indicator
= 1;
1079 entry
->flags
.indicator_on
= 1;
1080 entry
->flags
.indicator_type
= MI_CHECK
;
1082 entry
= wMenuAddCallback(menu
, _("AutoCollapse"),
1083 toggleAutoCollapseCallback
, NULL
);
1084 entry
->flags
.indicator
= 1;
1085 entry
->flags
.indicator_on
= 1;
1086 entry
->flags
.indicator_type
= MI_CHECK
;
1088 entry
= wMenuAddCallback(menu
, _("AutoRaiseLower"),
1089 toggleAutoRaiseLowerCallback
, NULL
);
1090 entry
->flags
.indicator
= 1;
1091 entry
->flags
.indicator_on
= 1;
1092 entry
->flags
.indicator_type
= MI_CHECK
;
1094 entry
= wMenuAddCallback(menu
, _("AutoAttract Icons"),
1095 toggleAutoAttractCallback
, NULL
);
1096 entry
->flags
.indicator
= 1;
1097 entry
->flags
.indicator_on
= 1;
1098 entry
->flags
.indicator_type
= MI_CHECK
;
1100 menu
->flags
.realized
= 0;
1108 dockMenuCreate(WScreen
*scr
, int type
)
1113 if (type
== WM_CLIP
&& scr
->clip_menu
)
1114 return scr
->clip_menu
;
1116 menu
= wMenuCreate(scr
, NULL
, False
);
1117 if (type
!= WM_CLIP
) {
1118 entry
= wMenuAddCallback(menu
, _("Keep on top"),
1119 toggleLoweredCallback
, NULL
);
1120 entry
->flags
.indicator
= 1;
1121 entry
->flags
.indicator_on
= 1;
1122 entry
->flags
.indicator_type
= MI_CHECK
;
1124 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1125 scr
->clip_options
= makeClipOptionsMenu(scr
);
1126 if (scr
->clip_options
)
1127 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1129 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
,
1132 entry
->text
= _("Rename Workspace");
1134 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1135 entry
->flags
.indicator
= 1;
1136 entry
->flags
.indicator_on
= 1;
1137 entry
->flags
.indicator_type
= MI_CHECK
;
1139 entry
= wMenuAddCallback(menu
, _("Select All Icons"),
1140 selectIconsCallback
, NULL
);
1142 entry
->text
= _("Select All Icons");
1144 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1146 entry
->text
= _("Keep Icon");
1148 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1150 entry
->text
= _("Move Icon To");
1151 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1152 if (scr
->clip_submenu
)
1153 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1155 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
,
1158 entry
->text
= _("Remove Icon");
1160 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1163 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1165 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1167 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1169 entry
->text
= _("Hide");
1171 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1173 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1175 if (type
== WM_CLIP
)
1176 scr
->clip_menu
= menu
;
1183 wDockCreate(WScreen
*scr
, int type
)
1191 dock
= wmalloc(sizeof(WDock
));
1192 memset(dock
, 0, sizeof(WDock
));
1194 if (type
== WM_CLIP
)
1195 icon_count
= CLIP_MAX_ICONS
;
1197 icon_count
= scr
->scr_height
/wPreferences
.icon_size
;
1199 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*)*icon_count
);
1200 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*)*icon_count
);
1202 dock
->max_icons
= icon_count
;
1204 btn
= mainIconCreate(scr
, type
);
1208 dock
->x_pos
= btn
->x_pos
;
1209 dock
->y_pos
= btn
->y_pos
;
1210 dock
->screen_ptr
= scr
;
1212 dock
->icon_count
= 1;
1213 dock
->on_right_side
= 1;
1214 dock
->collapsed
= 0;
1215 dock
->auto_collapse
= 0;
1216 dock
->auto_collapse_magic
= NULL
;
1217 dock
->auto_raise_lower
= 0;
1218 dock
->auto_lower_magic
= NULL
;
1219 dock
->auto_raise_magic
= NULL
;
1220 dock
->attract_icons
= 0;
1222 dock
->icon_array
[0] = btn
;
1223 wRaiseFrame(btn
->icon
->core
);
1224 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1226 /* create dock menu */
1227 dock
->menu
= dockMenuCreate(scr
, type
);
1234 wDockDestroy(WDock
*dock
)
1239 for (i
=(dock
->type
== WM_CLIP
) ? 1 : 0; i
<dock
->max_icons
; i
++) {
1240 aicon
= dock
->icon_array
[i
];
1242 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1243 wDockDetach(dock
, aicon
);
1245 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
1246 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
1247 aicon
->x_pos
, aicon
->y_pos
);
1248 if (!dock
->mapped
|| dock
->collapsed
)
1249 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1253 if (wPreferences
.auto_arrange_icons
)
1254 wArrangeIcons(dock
->screen_ptr
, True
);
1255 free(dock
->icon_array
);
1256 if (dock
->menu
&& dock
->type
!=WM_CLIP
)
1257 wMenuDestroy(dock
->menu
, True
);
1258 if (dock
->screen_ptr
->last_dock
== dock
)
1259 dock
->screen_ptr
->last_dock
= NULL
;
1265 wClipIconPaint(WAppIcon
*aicon
)
1267 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1268 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1270 Window win
= aicon
->icon
->core
->window
;
1271 int length
, nlength
;
1272 char *ws_name
, ws_number
[10];
1275 wIconPaint(aicon
->icon
);
1277 length
= strlen(workspace
->name
);
1278 ws_name
= malloc(length
+ 1);
1279 sprintf(ws_name
, "%s", workspace
->name
);
1280 sprintf(ws_number
, "%i", scr
->current_workspace
+ 1);
1281 nlength
= strlen(ws_number
);
1283 gc
= scr
->clip_title_gc
;
1285 if (!workspace
->clip
->collapsed
)
1286 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_NORMAL
]);
1288 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_COLLAPSED
]);
1290 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1292 tx
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
1294 WMDrawString(scr
->wmscreen
, win
, gc
, scr
->clip_title_font
, tx
,
1295 ty
, ws_name
, length
);
1297 tx
= (ICON_SIZE
/2 - WMWidthOfString(scr
->clip_title_font
, ws_number
,
1300 WMDrawString(scr
->wmscreen
, win
, gc
, scr
->clip_title_font
, tx
,
1301 2, ws_number
, nlength
);
1305 if (aicon
->launching
) {
1306 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1307 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1309 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
,
1310 aicon
->dock
->rclip_button_pushed
);
1315 clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1317 wClipIconPaint(desc
->parent
);
1322 dockIconPaint(WAppIcon
*btn
)
1324 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1325 wClipIconPaint(btn
);
1332 make_icon_state(WAppIcon
*btn
)
1334 proplist_t node
= NULL
;
1335 proplist_t command
, autolaunch
, lock
, name
, forced
, host
, position
, buggy
;
1336 proplist_t omnipresent
;
1342 command
= PLMakeString("-");
1344 command
= PLMakeString(btn
->command
);
1346 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1348 lock
= btn
->lock
? dYes
: dNo
;
1350 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1352 name
= PLMakeString(tmp
);
1356 forced
= btn
->forced_dock
? dYes
: dNo
;
1358 buggy
= btn
->buggy_app
? dYes
: dNo
;
1360 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1361 sprintf(buffer
, "%i,%i", btn
->x_pos
, btn
->y_pos
);
1363 sprintf(buffer
, "%hi,%hi", btn
->xindex
, btn
->yindex
);
1364 position
= PLMakeString(buffer
);
1366 node
= PLMakeDictionaryFromEntries(dCommand
, command
,
1368 dAutoLaunch
, autolaunch
,
1371 dBuggyApplication
, buggy
,
1372 dPosition
, position
,
1376 PLRelease(position
);
1378 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1379 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&&
1380 (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1381 PLInsertDictionaryEntry(node
, dOmnipresent
, omnipresent
);
1384 if (btn
->dnd_command
) {
1385 command
= PLMakeString(btn
->dnd_command
);
1386 PLInsertDictionaryEntry(node
, dDropCommand
, command
);
1389 #endif /* OFFIX_DND */
1391 if (btn
->client_machine
&& btn
->remote_start
) {
1392 host
= PLMakeString(btn
->client_machine
);
1393 PLInsertDictionaryEntry(node
, dHost
, host
);
1403 dockSaveState(WDock
*dock
)
1406 proplist_t icon_info
;
1407 proplist_t list
=NULL
, dock_state
=NULL
;
1408 proplist_t value
, key
;
1411 list
= PLMakeArrayFromElements(NULL
);
1413 for (i
=(dock
->type
==WM_DOCK
? 0 : 1); i
<dock
->max_icons
; i
++) {
1414 WAppIcon
*btn
= dock
->icon_array
[i
];
1416 if (!btn
|| btn
->attracted
)
1419 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1420 list
= PLAppendArrayElement(list
, icon_info
);
1421 PLRelease(icon_info
);
1425 dock_state
= PLMakeDictionaryFromEntries(dApplications
, list
,
1428 if (dock
->type
== WM_DOCK
) {
1429 sprintf(buffer
, "Applications%i", dock
->screen_ptr
->scr_height
);
1430 key
= PLMakeString(buffer
);
1431 PLInsertDictionaryEntry(dock_state
, key
, list
);
1435 sprintf(buffer
, "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0),
1437 value
= PLMakeString(buffer
);
1438 PLInsertDictionaryEntry(dock_state
, dPosition
, value
);
1444 value
= (dock
->lowered
? dYes
: dNo
);
1445 PLInsertDictionaryEntry(dock_state
, dLowered
, value
);
1447 if (dock
->type
== WM_CLIP
) {
1448 value
= (dock
->collapsed
? dYes
: dNo
);
1449 PLInsertDictionaryEntry(dock_state
, dCollapsed
, value
);
1451 value
= (dock
->auto_collapse
? dYes
: dNo
);
1452 PLInsertDictionaryEntry(dock_state
, dAutoCollapse
, value
);
1454 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1455 PLInsertDictionaryEntry(dock_state
, dAutoRaiseLower
, value
);
1457 value
= (dock
->attract_icons
? dYes
: dNo
);
1458 PLInsertDictionaryEntry(dock_state
, dAutoAttractIcons
, value
);
1466 wDockSaveState(WScreen
*scr
, proplist_t old_state
)
1468 proplist_t dock_state
;
1471 dock_state
= dockSaveState(scr
->dock
);
1474 * Copy saved states of docks with different sizes.
1480 keys
= PLGetAllDictionaryKeys(old_state
);
1481 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
1482 tmp
= PLGetArrayElement(keys
, i
);
1484 if (strncasecmp(PLGetString(tmp
), "applications", 12) == 0
1485 && !PLGetDictionaryEntry(dock_state
, tmp
)) {
1487 PLInsertDictionaryEntry(dock_state
,
1489 PLGetDictionaryEntry(old_state
, tmp
));
1496 PLInsertDictionaryEntry(scr
->session_state
, dDock
, dock_state
);
1498 PLRelease(dock_state
);
1503 wClipSaveState(WScreen
*scr
)
1505 proplist_t clip_state
;
1507 clip_state
= make_icon_state(scr
->clip_icon
);
1509 PLInsertDictionaryEntry(scr
->session_state
, dClip
, clip_state
);
1511 PLRelease(clip_state
);
1516 wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1518 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1523 getBooleanDockValue(proplist_t value
, proplist_t key
)
1526 if (PLIsString(value
)) {
1527 if (strcasecmp(PLGetString(value
), "YES")==0)
1530 wwarning(_("bad value in docked icon state info %s"),
1539 restore_icon_state(WScreen
*scr
, proplist_t info
, int type
, int index
)
1542 char *wclass
, *winstance
;
1543 proplist_t cmd
, value
;
1547 cmd
= PLGetDictionaryEntry(info
, dCommand
);
1548 if (!cmd
|| !PLIsString(cmd
)) {
1552 /* parse window name */
1553 value
= PLGetDictionaryEntry(info
, dName
);
1557 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1559 if (!winstance
&& !wclass
) {
1566 command
= wstrdup(PLGetString(cmd
));
1570 if (!command
|| strcmp(command
, "-")==0) {
1581 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
,
1588 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1589 if (type
== WM_CLIP
) {
1590 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1591 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1593 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1594 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1598 cmd
= PLGetDictionaryEntry(info
, dDropCommand
);
1600 aicon
->dnd_command
= wstrdup(PLGetString(cmd
));
1603 /* check auto launch */
1604 value
= PLGetDictionaryEntry(info
, dAutoLaunch
);
1606 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1609 value
= PLGetDictionaryEntry(info
, dLock
);
1611 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1613 /* check if it wasn't normally docked */
1614 value
= PLGetDictionaryEntry(info
, dForced
);
1616 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1618 /* check if we can rely on the stuff in the app */
1619 value
= PLGetDictionaryEntry(info
, dBuggyApplication
);
1621 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1623 /* get position in the dock */
1624 value
= PLGetDictionaryEntry(info
, dPosition
);
1625 if (value
&& PLIsString(value
)) {
1626 if (sscanf(PLGetString(value
), "%hi,%hi", &aicon
->xindex
,
1628 wwarning(_("bad value in docked icon state info %s"),
1629 PLGetString(dPosition
));
1631 /* check position sanity */
1632 /* incomplete section! */
1633 if (type
== WM_DOCK
) {
1635 if (aicon
->yindex
< 0)
1636 wwarning(_("bad value in docked icon position %i,%i"),
1637 aicon
->xindex
, aicon
->yindex
);
1640 aicon
->yindex
= index
;
1644 /* check if icon is omnipresent */
1645 value
= PLGetDictionaryEntry(info
, dOmnipresent
);
1647 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1656 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1660 wClipRestoreState(WScreen
*scr
, proplist_t clip_state
)
1666 icon
= mainIconCreate(scr
, WM_CLIP
);
1671 PLRetain(clip_state
);
1673 /* restore position */
1675 value
= PLGetDictionaryEntry(clip_state
, dPosition
);
1678 if (!PLIsString(value
))
1679 COMPLAIN("Position");
1681 if (sscanf(PLGetString(value
), "%i,%i", &icon
->x_pos
,
1683 COMPLAIN("Position");
1685 /* check position sanity */
1686 if (icon
->y_pos
< 0)
1688 else if (icon
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1689 icon
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1691 if (icon
->x_pos
< 0)
1693 else if (icon
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1694 icon
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1699 value
= PLGetDictionaryEntry(clip_state
, dDropCommand
);
1700 if (value
&& PLIsString(value
))
1701 icon
->dnd_command
= wstrdup(PLGetString(value
));
1704 PLRelease(clip_state
);
1711 wDockRestoreState(WScreen
*scr
, proplist_t dock_state
, int type
)
1716 WAppIcon
*aicon
, *old_top
;
1720 dock
= wDockCreate(scr
, type
);
1726 PLRetain(dock_state
);
1729 /* restore position */
1731 value
= PLGetDictionaryEntry(dock_state
, dPosition
);
1734 if (!PLIsString(value
))
1735 COMPLAIN("Position");
1737 if (sscanf(PLGetString(value
), "%i,%i", &dock
->x_pos
,
1739 COMPLAIN("Position");
1741 /* check position sanity */
1742 if (dock
->y_pos
< 0)
1744 else if (dock
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1745 dock
->y_pos
= scr
->scr_height
- ICON_SIZE
;
1747 /* This is no more needed. ??? */
1748 if (type
== WM_CLIP
) {
1749 if (dock
->x_pos
< 0)
1751 else if (dock
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1752 dock
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1754 if (dock
->x_pos
>= 0) {
1755 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1756 dock
->on_right_side
= 0;
1758 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1759 dock
->on_right_side
= 1;
1765 /* restore lowered/raised state */
1769 value
= PLGetDictionaryEntry(dock_state
, dLowered
);
1772 if (!PLIsString(value
))
1773 COMPLAIN("Lowered");
1775 if (strcasecmp(PLGetString(value
), "YES")==0)
1781 /* restore collapsed state */
1783 dock
->collapsed
= 0;
1785 value
= PLGetDictionaryEntry(dock_state
, dCollapsed
);
1788 if (!PLIsString(value
))
1789 COMPLAIN("Collapsed");
1791 if (strcasecmp(PLGetString(value
), "YES")==0)
1792 dock
->collapsed
= 1;
1797 /* restore auto-collapsed state */
1799 value
= PLGetDictionaryEntry(dock_state
, dAutoCollapse
);
1802 if (!PLIsString(value
))
1803 COMPLAIN("AutoCollapse");
1805 if (strcasecmp(PLGetString(value
), "YES")==0) {
1806 dock
->auto_collapse
= 1;
1807 dock
->collapsed
= 1;
1813 /* restore auto-raise/lower state */
1815 value
= PLGetDictionaryEntry(dock_state
, dAutoRaiseLower
);
1818 if (!PLIsString(value
))
1819 COMPLAIN("AutoRaiseLower");
1821 if (strcasecmp(PLGetString(value
), "YES")==0) {
1822 dock
->auto_raise_lower
= 1;
1827 /* restore attract icons state */
1829 dock
->attract_icons
= 0;
1831 value
= PLGetDictionaryEntry(dock_state
, dAutoAttractIcons
);
1834 if (!PLIsString(value
))
1835 COMPLAIN("AutoAttractIcons");
1837 if (strcasecmp(PLGetString(value
), "YES")==0)
1838 dock
->attract_icons
= 1;
1843 /* application list */
1850 * When saving, it saves the dock state in
1851 * Applications and Applicationsnnn
1853 * When loading, it will first try Applicationsnnn.
1854 * If it does not exist, use Applications as default.
1857 sprintf(buffer
, "Applications%i", scr
->scr_height
);
1859 tmp
= PLMakeString(buffer
);
1860 apps
= PLGetDictionaryEntry(dock_state
, tmp
);
1864 apps
= PLGetDictionaryEntry(dock_state
, dApplications
);
1872 count
= PLGetNumberOfElements(apps
);
1877 old_top
= dock
->icon_array
[0];
1879 /* dock->icon_count is set to 1 when dock is created.
1880 * Since Clip is already restored, we want to keep it so for clip,
1881 * but for dock we may change the default top tile, so we set it to 0.
1883 if (type
== WM_DOCK
)
1884 dock
->icon_count
= 0;
1886 for (i
=0; i
<count
; i
++) {
1887 if (dock
->icon_count
>= dock
->max_icons
) {
1888 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1892 value
= PLGetArrayElement(apps
, i
);
1893 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1895 dock
->icon_array
[dock
->icon_count
] = aicon
;
1899 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
*ICON_SIZE
);
1900 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
*ICON_SIZE
);
1903 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1905 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1907 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
,
1910 if (!dock
->collapsed
)
1911 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1912 wRaiseFrame(aicon
->icon
->core
);
1915 } else if (dock
->icon_count
==0 && type
==WM_DOCK
)
1919 /* if the first icon is not defined, use the default */
1920 if (dock
->icon_array
[0]==NULL
) {
1921 /* update default icon */
1922 old_top
->x_pos
= dock
->x_pos
;
1923 old_top
->y_pos
= dock
->y_pos
;
1925 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1927 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1928 dock
->icon_array
[0] = old_top
;
1929 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1930 /* we don't need to increment dock->icon_count here because it was
1931 * incremented in the loop above.
1933 } else if (old_top
!=dock
->icon_array
[0]) {
1934 if (old_top
== scr
->clip_icon
)
1935 scr
->clip_icon
= dock
->icon_array
[0];
1936 wAppIconDestroy(old_top
);
1941 PLRelease(dock_state
);
1949 wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1951 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1953 btn
->drop_launch
= 0;
1955 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1958 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1970 wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1976 for (i
= 0; i
< dock
->max_icons
; i
++) {
1977 btn
= dock
->icon_array
[i
];
1978 if (!btn
|| !btn
->auto_launch
)
1981 state
= wmalloc(sizeof(WSavedState
));
1982 memset(state
, 0, sizeof(WSavedState
));
1983 state
->workspace
= workspace
;
1984 /* TODO: this is klugy and is very difficult to understand
1985 * what's going on. Try to clean up */
1986 wDockLaunchWithState(dock
, btn
, state
);
1990 #ifdef REDUCE_APPICONS
1992 wDockSimulateLaunch(WDock
*dock
, WAppIcon
*btn
)
1994 if ((btn
== NULL
) || (dock
== NULL
))
1997 if (!btn
->running
) {
1998 if ((btn
->icon
->owner
== NULL
) && (btn
->applist
))
1999 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
2000 if (!btn
->forced_dock
)
2010 findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
2016 if ((dock
= scr
->dock
)!=NULL
) {
2017 for (i
=0; i
<dock
->max_icons
; i
++) {
2018 if (dock
->icon_array
[i
]
2019 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
2025 if (*icon_pos
<0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
)!=NULL
) {
2026 for (i
=0; i
<dock
->max_icons
; i
++) {
2027 if (dock
->icon_array
[i
]
2028 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
2041 wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
2047 dock
= findDock(scr
, event
, &icon_pos
);
2052 * Return True if the drop was on an application icon window.
2053 * In this case, let the ClientMessage handler redirect the
2054 * message to the app.
2056 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!=None
)
2059 if (dock
->icon_array
[icon_pos
]->dnd_command
!=NULL
) {
2060 scr
->flags
.dnd_data_convertion_status
= 0;
2062 btn
= dock
->icon_array
[icon_pos
];
2064 if (!btn
->forced_dock
) {
2065 btn
->relaunching
= btn
->running
;
2068 if (btn
->wm_instance
|| btn
->wm_class
) {
2069 WWindowAttributes attr
;
2070 memset(&attr
, 0, sizeof(WWindowAttributes
));
2071 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
2073 btn
->wm_class
, &attr
, NULL
, True
);
2075 if (!attr
.no_appicon
)
2081 btn
->drop_launch
= 1;
2082 scr
->last_dock
= dock
;
2083 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
2088 if (!btn
->relaunching
) {
2095 #endif /* OFFIX_DND */
2100 wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2107 wwin
= icon
->icon
->owner
;
2108 if (icon
->command
==NULL
) {
2110 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2112 icon
->command
= FlattenStringList(argv
, argc
);
2113 XFreeStringList(argv
);
2117 /* icon->forced_dock = 1;*/
2118 if (dock
->type
!=WM_CLIP
|| !icon
->attracted
) {
2120 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2121 _("Type the command used to launch the application"),
2123 if (command
&& (command
[0]==0 ||
2124 (command
[0]=='-' && command
[1]==0))) {
2128 icon
->command
= command
;
2134 /* If the target is the dock, reject the icon. If
2135 * the target is the clip, make it an attracted icon
2137 if (dock
->type
==WM_CLIP
) {
2138 icon
->attracted
= 1;
2139 if (!icon
->icon
->shadowed
) {
2140 icon
->icon
->shadowed
= 1;
2141 icon
->icon
->force_paint
= 1;
2153 for (index
=1; index
<dock
->max_icons
; index
++)
2154 if (dock
->icon_array
[index
] == NULL
)
2156 /* if (index == dock->max_icons)
2159 assert(index
< dock
->max_icons
);
2161 dock
->icon_array
[index
] = icon
;
2165 icon
->omnipresent
= 0;
2167 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2168 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2173 icon
->launching
= 0;
2176 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2177 if (dock
->type
== WM_CLIP
) {
2178 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2179 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2181 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2182 icon
->icon
->core
->descriptor
.parent
= icon
;
2184 MoveInStackListUnder(dock
->icon_array
[index
-1]->icon
->core
,
2186 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2187 wAppIconPaint(icon
);
2189 if (wPreferences
.auto_arrange_icons
)
2190 wArrangeIcons(dock
->screen_ptr
, True
);
2193 if (icon
->command
&& !icon
->dnd_command
) {
2194 icon
->dnd_command
= wmalloc(strlen(icon
->command
)+8);
2195 sprintf(icon
->dnd_command
, "%s %%d", icon
->command
);
2204 reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2208 for(index
=1; index
<dock
->max_icons
; index
++) {
2209 if(dock
->icon_array
[index
] == icon
)
2212 assert(index
< dock
->max_icons
);
2217 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2218 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2223 moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2231 return True
; /* No move needed, we're already there */
2236 wwin
= icon
->icon
->owner
;
2239 * For the moment we can't do this if we move icons in Clip from one
2240 * workspace to other, because if we move two or more icons without
2241 * command, the dialog box will not be able to tell us to which of the
2242 * moved icons it applies. -Dan
2244 if ((dest
->type
==WM_DOCK
/*|| dest->keep_attracted*/) && icon
->command
==NULL
) {
2245 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2247 icon
->command
= FlattenStringList(argv
, argc
);
2248 XFreeStringList(argv
);
2253 /* icon->forced_dock = 1;*/
2254 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2255 _("Type the command used to launch the application"),
2257 if (command
&& (command
[0]==0 ||
2258 (command
[0]=='-' && command
[1]==0))) {
2262 icon
->command
= command
;
2273 if (dest
->type
== WM_DOCK
)
2274 wClipMakeIconOmnipresent(icon
, False
);
2276 for(index
=1; index
<src
->max_icons
; index
++) {
2277 if(src
->icon_array
[index
] == icon
)
2280 assert(index
< src
->max_icons
);
2282 src
->icon_array
[index
] = NULL
;
2285 for(index
=1; index
<dest
->max_icons
; index
++) {
2286 if(dest
->icon_array
[index
] == NULL
)
2289 /* if (index == dest->max_icons)
2292 assert(index
< dest
->max_icons
);
2294 dest
->icon_array
[index
] = icon
;
2297 /* deselect the icon */
2298 if (icon
->icon
->selected
)
2299 wIconSelect(icon
->icon
);
2301 if (dest
->type
== WM_DOCK
) {
2302 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2303 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2305 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2306 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2309 /* set it to be kept when moving to dock.
2310 * Unless the icon does not have a command set
2312 if (icon
->command
&& dest
->type
==WM_DOCK
) {
2313 icon
->attracted
= 0;
2314 if (icon
->icon
->shadowed
) {
2315 icon
->icon
->shadowed
= 0;
2316 icon
->icon
->force_paint
= 1;
2320 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2326 icon
->x_pos
= dest
->x_pos
+ x
*ICON_SIZE
;
2327 icon
->y_pos
= dest
->y_pos
+ y
*ICON_SIZE
;
2331 MoveInStackListUnder(dest
->icon_array
[index
-1]->icon
->core
,
2333 wAppIconPaint(icon
);
2340 wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2344 /* make the settings panel be closed */
2346 DestroyDockAppSettingsPanel(icon
->panel
);
2349 /* This must be called before icon->dock is set to NULL.
2350 * Don't move it. -Dan
2352 wClipMakeIconOmnipresent(icon
, False
);
2356 icon
->attracted
= 0;
2357 icon
->auto_launch
= 0;
2358 if (icon
->icon
->shadowed
) {
2359 icon
->icon
->shadowed
= 0;
2360 icon
->icon
->force_paint
= 1;
2363 /* deselect the icon */
2364 if (icon
->icon
->selected
)
2365 wIconSelect(icon
->icon
);
2367 if (icon
->command
) {
2368 free(icon
->command
);
2369 icon
->command
= NULL
;
2372 if (icon
->dnd_command
) {
2373 free(icon
->dnd_command
);
2374 icon
->dnd_command
= NULL
;
2378 for (index
=1; index
<dock
->max_icons
; index
++)
2379 if (dock
->icon_array
[index
] == icon
)
2381 assert(index
< dock
->max_icons
);
2382 dock
->icon_array
[index
] = NULL
;
2388 /* if the dock is not attached to an application or
2389 * the the application did not set the approriate hints yet,
2390 * destroy the icon */
2391 #ifdef REDUCE_APPICONS
2392 if ((icon
->num_apps
== 0) && (!icon
->running
|| !wApplicationOf(icon
->main_window
)) )
2394 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2396 wAppIconDestroy(icon
);
2398 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2399 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2400 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2401 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2402 icon
->icon
->core
->descriptor
.parent
= icon
;
2404 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2406 wAppIconPaint(icon
);
2407 if (wPreferences
.auto_arrange_icons
) {
2408 wArrangeIcons(dock
->screen_ptr
, True
);
2411 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2417 * returns the closest Dock slot index for the passed
2420 * Returns False if icon can't be docked.
2422 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2426 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2427 int *ret_x
, int *ret_y
, int redocking
)
2429 WScreen
*scr
= dock
->screen_ptr
;
2432 int i
, offset
= ICON_SIZE
/2;
2433 WAppIcon
*aicon
= NULL
;
2434 WAppIcon
*nicon
= NULL
;
2435 int max_y_icons
, max_x_icons
;
2437 max_x_icons
= scr
->scr_width
/ICON_SIZE
;
2438 max_y_icons
= scr
->scr_height
/ICON_SIZE
-1;
2440 if (wPreferences
.flags
.noupdates
)
2446 /* if the dock is full */
2448 (dock
->icon_count
>= dock
->max_icons
)) {
2452 /* exact position */
2454 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2456 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2459 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2461 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2463 /* check if the icon is outside the screen boundaries */
2464 if (dx
+ ex_x
*ICON_SIZE
< -ICON_SIZE
+2 ||
2465 dx
+ ex_x
*ICON_SIZE
>= scr
->scr_width
-1 ||
2466 dy
+ ex_y
*ICON_SIZE
< -ICON_SIZE
+2 ||
2467 dy
+ ex_y
*ICON_SIZE
>= scr
->scr_height
-1)
2470 if (dock
->type
== WM_DOCK
) {
2471 if (icon
->dock
!= dock
&& ex_x
!= 0)
2475 for (i
=0; i
<dock
->max_icons
; i
++) {
2476 nicon
= dock
->icon_array
[i
];
2477 if (nicon
&& nicon
->yindex
== ex_y
) {
2484 int sig
, done
, closest
;
2486 /* Possible cases when redocking:
2488 * icon dragged out of range of any slot -> false
2489 * icon dragged to range of free slot
2490 * icon dragged to range of same slot
2491 * icon dragged to range of different icon
2493 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2496 if (ex_y
>=0 && ex_y
<=max_y_icons
&& (aicon
==icon
|| !aicon
)) {
2502 /* start looking at the upper slot or lower? */
2503 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2510 /* look for closest free slot */
2511 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2515 closest
= sig
*(i
/2) + ex_y
;
2516 /* check if this slot is used */
2518 for (j
= 0; j
<dock
->max_icons
; j
++) {
2519 if (dock
->icon_array
[j
]
2520 && dock
->icon_array
[j
]->yindex
==closest
) {
2521 /* slot is used by someone else */
2522 if (dock
->icon_array
[j
]!=icon
)
2530 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2531 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2533 (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+1))) {
2538 } else { /* !redocking */
2540 /* if slot is free and the icon is close enough, return it */
2541 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2551 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2552 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+1;
2555 for (k
=start
; k
<stop
; k
++) {
2556 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2559 for (i
=0; i
<tmp
->max_icons
; i
++) {
2560 nicon
= tmp
->icon_array
[i
];
2561 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2569 for (k
=start
; k
<stop
; k
++) {
2570 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2573 for (i
=0; i
<tmp
->max_icons
; i
++) {
2574 nicon
= tmp
->icon_array
[i
];
2575 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2576 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2577 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2586 if (neighbours
&& (aicon
==NULL
|| (redocking
&& aicon
== icon
))) {
2595 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2596 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2598 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2599 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2600 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2604 * returns true if it can find a free slot in the dock,
2605 * in which case it changes x_pos and y_pos accordingly.
2606 * Else returns false.
2609 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2611 WScreen
*scr
= dock
->screen_ptr
;
2613 WAppIconChain
*chain
;
2614 unsigned char *slot_map
;
2618 int i
, done
= False
;
2620 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2623 if (dock
->type
== WM_CLIP
&&
2624 dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2625 extra_count
= scr
->global_icon_count
;
2627 /* if the dock is full */
2628 if (dock
->icon_count
+extra_count
>= dock
->max_icons
) {
2632 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2633 if (scr
->dock
->on_right_side
)
2634 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2636 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2639 if (ex
< dock
->x_pos
)
2641 if (sx
> dock
->x_pos
+ICON_SIZE
)
2642 sx
= dock
->x_pos
+ICON_SIZE
;
2649 /* check if clip is in a corner */
2650 if (dock
->type
==WM_CLIP
) {
2651 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2653 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2655 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2657 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2664 /* If the clip is in the corner, use only slots that are in the border
2666 if (corner
!=C_NONE
) {
2670 hcount
= MIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2671 vcount
= MIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2672 hmap
= wmalloc(hcount
+1);
2673 memset(hmap
, 0, hcount
+1);
2674 vmap
= wmalloc(vcount
+1);
2675 memset(vmap
, 0, vcount
+1);
2677 /* mark used positions */
2680 for (i
=0; i
<dock
->max_icons
; i
++) {
2681 btn
= dock
->icon_array
[i
];
2685 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2686 vmap
[btn
->yindex
] = 1;
2687 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2688 hmap
[btn
->xindex
] = 1;
2690 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2692 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2693 vmap
[btn
->yindex
] = 1;
2694 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2695 hmap
[btn
->xindex
] = 1;
2699 for (i
=0; i
<dock
->max_icons
; i
++) {
2700 btn
= dock
->icon_array
[i
];
2704 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2705 vmap
[btn
->yindex
] = 1;
2706 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2707 hmap
[-btn
->xindex
] = 1;
2709 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2711 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2712 vmap
[btn
->yindex
] = 1;
2713 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2714 hmap
[-btn
->xindex
] = 1;
2718 for (i
=0; i
<dock
->max_icons
; i
++) {
2719 btn
= dock
->icon_array
[i
];
2723 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2724 vmap
[-btn
->yindex
] = 1;
2725 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2726 hmap
[btn
->xindex
] = 1;
2728 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2730 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2731 vmap
[-btn
->yindex
] = 1;
2732 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2733 hmap
[btn
->xindex
] = 1;
2738 for (i
=0; i
<dock
->max_icons
; i
++) {
2739 btn
= dock
->icon_array
[i
];
2743 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2744 vmap
[-btn
->yindex
] = 1;
2745 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2746 hmap
[-btn
->xindex
] = 1;
2748 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2750 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2751 vmap
[-btn
->yindex
] = 1;
2752 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2753 hmap
[-btn
->xindex
] = 1;
2758 /* search a vacant slot */
2759 for (i
=1; i
<MAX(vcount
, hcount
); i
++) {
2760 if (i
< vcount
&& vmap
[i
]==0) {
2766 } else if (i
< hcount
&& hmap
[i
]==0) {
2776 /* If found a slot, translate and return */
2778 if (corner
==C_NW
|| corner
==C_NE
) {
2783 if (corner
==C_NE
|| corner
==C_SE
) {
2790 /* else, try to find a slot somewhere else */
2793 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2794 * placed outside of screen */
2795 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2797 /* In the worst case (the clip is in the corner of the screen),
2798 * the amount of icons that fit in the clip is smaller.
2799 * Double the map to get a safe value.
2805 slot_map
= wmalloc(mwidth
*mwidth
);
2806 memset(slot_map
, 0, mwidth
*mwidth
);
2808 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2810 /* mark used slots in the map. If the slot falls outside the map
2811 * (for example, when all icons are placed in line), ignore them. */
2812 for (i
=0; i
<dock
->max_icons
; i
++) {
2813 btn
= dock
->icon_array
[i
];
2815 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2817 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2818 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2820 /* Find closest slot from the center that is free by scanning the
2821 * map from the center to outward in circular passes.
2822 * This will not result in a neat layout, but will be optimal
2823 * in the sense that there will not be holes left.
2826 for (i
= 1; i
<= r
&& !done
; i
++) {
2829 /* top and bottom parts of the ring */
2830 for (x
= -i
; x
<= i
&& !done
; x
++) {
2831 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2833 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2834 if (slot_map
[XY2OFS(x
,y
)]==0
2835 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2842 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2843 if (slot_map
[XY2OFS(x
,y
)]==0
2844 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2851 /* left and right parts of the ring */
2852 for (y
= -i
+1; y
<= i
-1; y
++) {
2853 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2855 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2856 if (slot_map
[XY2OFS(x
,y
)]==0
2857 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2864 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2865 if (slot_map
[XY2OFS(x
,y
)]==0
2866 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2881 moveDock(WDock
*dock
, int new_x
, int new_y
)
2886 dock
->x_pos
= new_x
;
2887 dock
->y_pos
= new_y
;
2888 for (i
=0; i
<dock
->max_icons
; i
++) {
2889 btn
= dock
->icon_array
[i
];
2891 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2892 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2893 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2900 swapDock(WDock
*dock
)
2902 WScreen
*scr
= dock
->screen_ptr
;
2907 if (dock
->on_right_side
) {
2908 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2910 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2913 for (i
=0; i
<dock
->max_icons
; i
++) {
2914 btn
= dock
->icon_array
[i
];
2917 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2921 wScreenUpdateUsableArea(scr
);
2926 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2928 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2934 cmdline
= ExpandOptions(scr
, command
);
2936 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2944 ParseCommand(cmdline
, &argv
, &argc
);
2954 if ((pid
=fork())==0) {
2958 SetupEnvironment(scr
);
2964 args
= malloc(sizeof(char*)*(argc
+1));
2967 for (i
=0; i
<argc
; i
++) {
2971 execvp(argv
[0], args
);
2980 state
= wmalloc(sizeof(WSavedState
));
2981 memset(state
, 0, sizeof(WSavedState
));
2983 state
->miniaturized
= -1;
2985 if (btn
->dock
==scr
->dock
|| btn
->omnipresent
)
2986 state
->workspace
= -1;
2988 state
->workspace
= scr
->current_workspace
;
2990 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
2992 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
3003 wDockHideIcons(WDock
*dock
)
3010 for (i
=1; i
<dock
->max_icons
; i
++) {
3011 if (dock
->icon_array
[i
])
3012 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3016 dockIconPaint(dock
->icon_array
[0]);
3021 wDockShowIcons(WDock
*dock
)
3029 btn
= dock
->icon_array
[0];
3030 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
3032 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
3033 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
3035 for (i
=1; i
<dock
->max_icons
; i
++) {
3036 if (dock
->icon_array
[i
]) {
3037 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
3043 if (!dock
->collapsed
) {
3044 for (i
=1; i
<dock
->max_icons
; i
++) {
3045 if (dock
->icon_array
[i
]) {
3046 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3057 wDockLower(WDock
*dock
)
3061 for (i
=0; i
<dock
->max_icons
; i
++) {
3062 if (dock
->icon_array
[i
])
3063 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
3069 wDockRaise(WDock
*dock
)
3073 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
3074 if (dock
->icon_array
[i
])
3075 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
3081 wDockRaiseLower(WDock
*dock
)
3083 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
3084 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
3085 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
3093 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
3095 icon
->launching
= 0;
3096 icon
->relaunching
= 0;
3097 dockIconPaint(icon
);
3102 wDockFindIconForWindow(WDock
*dock
, Window window
)
3107 for (i
=0; i
<dock
->max_icons
; i
++) {
3108 icon
= dock
->icon_array
[i
];
3109 if (icon
&& icon
->main_window
== window
)
3117 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
3120 #ifdef REDUCE_APPICONS
3121 WAppIconAppList
*tapplist
;
3123 char *wm_class
, *wm_instance
;
3125 Bool firstPass
= True
;
3127 char *command
= NULL
;
3133 if (XGetCommand(dpy
, window
, &argv
, &argc
)) {
3134 if (argc
> 0 && argv
!= NULL
)
3135 command
= FlattenStringList(argv
,argc
);
3137 XFreeStringList(argv
);
3142 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
3143 (!wm_class
&& !wm_instance
))
3147 for (i
=0; i
<dock
->max_icons
; i
++) {
3148 icon
= dock
->icon_array
[i
];
3152 /* app is already attached to icon */
3153 if (icon
->main_window
== window
) {
3158 if ((icon
->wm_instance
|| icon
->wm_class
)
3160 || (dock
->screen_ptr
->flags
.startup
&& !icon
->running
))) {
3162 if (icon
->wm_instance
&& wm_instance
&&
3163 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
3166 if (icon
->wm_class
&& wm_class
&&
3167 strcmp(icon
->wm_class
, wm_class
)!=0) {
3170 if (firstPass
&& command
&& strcmp(icon
->command
, command
)!=0) {
3174 if (!icon
->relaunching
) {
3177 /* Possibly an application that was docked with dockit,
3178 * but the user did not update WMState to indicate that
3179 * it was docked by force */
3180 wapp
= wApplicationOf(window
);
3182 icon
->forced_dock
= 1;
3185 if (!icon
->forced_dock
)
3186 icon
->main_window
= window
;
3188 #ifdef REDUCE_APPICONS
3189 tapplist
= wmalloc(sizeof(WAppIconAppList
));
3190 memset(tapplist
, 0, sizeof(WAppIconAppList
));
3191 tapplist
->next
= icon
->applist
;
3193 icon
->applist
->prev
= tapplist
;
3194 icon
->applist
= tapplist
;
3195 tapplist
->wapp
= wApplicationOf(window
);
3200 wDockFinishLaunch(dock
, icon
);
3205 if (firstPass
&& !found
) {
3222 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3224 if (!wPreferences
.flags
.noclip
) {
3225 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3226 if (scr
->current_workspace
!= workspace
) {
3227 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3228 WAppIconChain
*chain
= scr
->global_icons
;
3231 moveIconBetweenDocks(chain
->aicon
->dock
,
3232 scr
->workspaces
[workspace
]->clip
,
3233 chain
->aicon
, chain
->aicon
->xindex
,
3234 chain
->aicon
->yindex
);
3235 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
3236 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3237 chain
= chain
->next
;
3240 wDockHideIcons(old_clip
);
3241 if (old_clip
->auto_raise_lower
) {
3242 if (old_clip
->auto_raise_magic
) {
3243 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3244 old_clip
->auto_raise_magic
= NULL
;
3246 wDockLower(old_clip
);
3248 if (old_clip
->auto_collapse
) {
3249 if (old_clip
->auto_expand_magic
) {
3250 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3251 old_clip
->auto_expand_magic
= NULL
;
3253 old_clip
->collapsed
= 1;
3255 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3257 if (scr
->flags
.clip_balloon_mapped
)
3258 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3265 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3270 for (i
=0; i
<dock
->max_icons
; i
++) {
3271 icon
= dock
->icon_array
[i
];
3275 if (icon
->launching
&& icon
->pid
== pid
) {
3276 if (!icon
->relaunching
) {
3278 icon
->main_window
= None
;
3280 wDockFinishLaunch(dock
, icon
);
3285 sprintf(msg
, _("Could not execute command \"%s\""),
3286 icon
->drop_launch
&& icon
->dnd_command
3287 ? icon
->dnd_command
: icon
->command
);
3289 sprintf(msg
, _("Could not execute command \"%s\""),
3292 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
3293 _("OK"), NULL
, NULL
);
3302 toggleLowered(WDock
*dock
)
3307 /* lower/raise Dock */
3308 if (!dock
->lowered
) {
3309 newlevel
= WMNormalLevel
;
3312 newlevel
= WMDockLevel
;
3316 for (i
=0; i
<dock
->max_icons
; i
++) {
3317 tmp
= dock
->icon_array
[i
];
3321 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3323 wLowerFrame(tmp
->icon
->core
);
3326 if (dock
->type
== WM_DOCK
)
3327 wScreenUpdateUsableArea(dock
->screen_ptr
);
3332 toggleCollapsed(WDock
*dock
)
3334 if (dock
->collapsed
) {
3335 dock
->collapsed
= 0;
3336 wDockShowIcons(dock
);
3339 dock
->collapsed
= 1;
3340 wDockHideIcons(dock
);
3346 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3348 WScreen
*scr
= dock
->screen_ptr
;
3349 WObjDescriptor
*desc
;
3351 WApplication
*wapp
= NULL
;
3355 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3357 if (dock
->type
== WM_DOCK
) {
3359 entry
= dock
->menu
->entries
[index
];
3360 entry
->flags
.indicator_on
= !dock
->lowered
;
3361 entry
->clientdata
= dock
;
3364 if (scr
->clip_options
)
3365 updateClipOptionsMenu(scr
->clip_options
, dock
);
3367 n_selected
= numberOfSelectedIcons(dock
);
3369 /* Rename Workspace */
3370 entry
= dock
->menu
->entries
[++index
];
3371 if (aicon
== scr
->clip_icon
) {
3372 entry
->callback
= renameCallback
;
3373 entry
->clientdata
= dock
;
3374 entry
->flags
.indicator
= 0;
3375 entry
->text
= _("Rename Workspace");
3377 entry
->callback
= omnipresentCallback
;
3378 entry
->clientdata
= aicon
;
3379 if (n_selected
> 0) {
3380 entry
->flags
.indicator
= 0;
3381 entry
->text
= _("Toggle Omnipresent");
3383 entry
->flags
.indicator
= 1;
3384 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3385 entry
->flags
.indicator_type
= MI_CHECK
;
3386 entry
->text
= _("Omnipresent");
3390 /* select/unselect icon */
3391 entry
= dock
->menu
->entries
[++index
];
3392 entry
->clientdata
= aicon
;
3393 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3394 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3396 /* select/unselect all icons */
3397 entry
= dock
->menu
->entries
[++index
];
3398 entry
->clientdata
= aicon
;
3400 entry
->text
= _("Unselect All Icons");
3402 entry
->text
= _("Select All Icons");
3403 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3406 entry
= dock
->menu
->entries
[++index
];
3407 entry
->clientdata
= aicon
;
3409 entry
->text
= _("Keep Icons");
3411 entry
->text
= _("Keep Icon");
3412 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3414 /* this is the workspace submenu part */
3415 entry
= dock
->menu
->entries
[++index
];
3417 entry
->text
= _("Move Icons To");
3419 entry
->text
= _("Move Icon To");
3420 if (scr
->clip_submenu
)
3421 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3422 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3424 /* remove icon(s) */
3425 entry
= dock
->menu
->entries
[++index
];
3426 entry
->clientdata
= aicon
;
3428 entry
->text
= _("Remove Icons");
3430 entry
->text
= _("Remove Icon");
3431 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3433 /* attract icon(s) */
3434 entry
= dock
->menu
->entries
[++index
];
3435 entry
->clientdata
= aicon
;
3437 dock
->menu
->flags
.realized
= 0;
3438 wMenuRealize(dock
->menu
);
3442 entry
= dock
->menu
->entries
[++index
];
3443 entry
->clientdata
= aicon
;
3444 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3447 entry
= dock
->menu
->entries
[++index
];
3448 entry
->clientdata
= aicon
;
3449 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3452 entry
= dock
->menu
->entries
[++index
];
3453 entry
->clientdata
= aicon
;
3454 if (aicon
->icon
->owner
) {
3455 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3456 if (wapp
&& wapp
->flags
.hidden
)
3457 entry
->text
= _("Unhide");
3459 entry
->text
= _("Hide");
3461 entry
->text
= _("Hide");
3463 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3466 entry
= dock
->menu
->entries
[++index
];
3467 entry
->clientdata
= aicon
;
3468 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
3469 && !wPreferences
.flags
.noupdates
);
3472 entry
= dock
->menu
->entries
[++index
];
3473 entry
->clientdata
= aicon
;
3474 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3476 if (!dock
->menu
->flags
.realized
)
3477 wMenuRealize(dock
->menu
);
3479 if (dock
->type
== WM_CLIP
) {
3480 x_pos
= event
->xbutton
.x_root
+2;
3482 x_pos
= dock
->on_right_side
?
3483 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 2 : 0;
3486 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3488 /* allow drag select */
3489 event
->xany
.send_event
= True
;
3490 desc
= &dock
->menu
->menu
->descriptor
;
3491 (*desc
->handle_mousedown
)(desc
, event
);
3496 openClipWorkspaceMenu(WScreen
*scr
, int x
, int y
)
3498 if (!scr
->clip_ws_menu
) {
3499 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3501 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
3502 wMenuMapAt(scr
->clip_ws_menu
, x
, y
, False
);
3506 /******************************************************************/
3508 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3510 WAppIcon
*btn
= desc
->parent
;
3511 WDock
*dock
= btn
->dock
;
3512 WApplication
*wapp
= NULL
;
3515 #ifdef REDUCE_APPICONS
3516 if ((btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) ||
3517 ((btn
->icon
->owner
== NULL
) && (btn
->applist
!= NULL
))) {
3518 if (btn
->icon
->owner
== NULL
)
3519 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
3521 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3523 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3527 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3529 /* go to the last workspace that the user worked on the app */
3530 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
3532 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3535 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3538 if (event
->xbutton
.state
& MOD_MASK
) {
3539 wHideOtherApplications(btn
->icon
->owner
);
3542 if (event
->xbutton
.button
==Button1
) {
3544 if (event
->xbutton
.state
& MOD_MASK
) {
3545 /* raise/lower dock */
3546 toggleLowered(dock
);
3547 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3548 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3549 toggleCollapsed(dock
);
3551 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3552 } else if (btn
->command
) {
3553 if (!btn
->launching
&&
3554 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3555 launchDockedApplication(btn
);
3557 } else if (btn
->xindex
== 0 && btn
->yindex
== 0
3558 && btn
->dock
->type
== WM_DOCK
) {
3560 wShowGNUstepPanel(dock
->screen_ptr
);
3568 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3570 WScreen
*scr
= dock
->screen_ptr
;
3571 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3574 int grabbed
= 0, swapped
= 0, done
;
3575 Pixmap ghost
= None
;
3576 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3579 puts("moving dock");
3581 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3582 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3583 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3584 wwarning("pointer grab failed for dock move");
3587 for (x
=0; x
<dock
->max_icons
; x
++) {
3588 if (dock
->icon_array
[x
]!=NULL
&&
3589 dock
->icon_array
[x
]->yindex
> y
)
3590 y
= dock
->icon_array
[x
]->yindex
;
3593 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3597 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3598 |ButtonMotionMask
|ExposureMask
, &ev
);
3606 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3607 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3608 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3609 |ButtonReleaseMask
|ButtonPressMask
,
3610 wCursor
[WCUR_MOVE
], CurrentTime
);
3615 if (dock
->type
== WM_CLIP
) {
3616 if (ev
.xmotion
.x_root
- ofs_x
< 0) {
3618 } else if (ev
.xmotion
.x_root
- ofs_x
+ ICON_SIZE
>
3620 x
= scr
->scr_width
- ICON_SIZE
;
3622 x
= ev
.xmotion
.x_root
- ofs_x
;
3624 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3626 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3628 y
= scr
->scr_height
- ICON_SIZE
;
3630 y
= ev
.xmotion
.y_root
- ofs_y
;
3632 moveDock(dock
, x
, y
);
3634 /* move vertically if pointer is inside the dock*/
3635 if ((dock
->on_right_side
&&
3636 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3637 || (!dock
->on_right_side
&&
3638 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3640 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3642 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3644 y
= scr
->scr_height
- ICON_SIZE
;
3646 y
= ev
.xmotion
.y_root
- ofs_y
;
3648 moveDock(dock
, dock
->x_pos
, y
);
3650 /* move horizontally to change sides */
3651 x
= ev
.xmotion
.x_root
- ofs_x
;
3652 if (!dock
->on_right_side
) {
3656 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3657 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3658 -DOCK_EXTRA_SPACE
-1, dock
->y_pos
);
3659 if (superfluous
&& ghost
==None
) {
3660 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3661 scr
->scr_width
-ICON_SIZE
3662 -DOCK_EXTRA_SPACE
-1,
3664 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3666 XClearWindow(dpy
, scr
->dock_shadow
);
3668 XMapRaised(dpy
, scr
->dock_shadow
);
3671 if (superfluous
&& ghost
!=None
) {
3672 XFreePixmap(dpy
, ghost
);
3675 XUnmapWindow(dpy
, scr
->dock_shadow
);
3680 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3681 XMoveWindow(dpy
, scr
->dock_shadow
,
3682 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3683 if (superfluous
&& ghost
==None
) {
3684 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3685 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3686 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3688 XClearWindow(dpy
, scr
->dock_shadow
);
3690 XMapRaised(dpy
, scr
->dock_shadow
);
3693 XUnmapWindow(dpy
, scr
->dock_shadow
);
3695 if (superfluous
&& ghost
!=None
) {
3696 XFreePixmap(dpy
, ghost
);
3708 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3710 XUngrabPointer(dpy
, CurrentTime
);
3711 XUnmapWindow(dpy
, scr
->dock_shadow
);
3712 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3713 if (dock
->type
== WM_DOCK
) {
3716 dock
->on_right_side
= 1;
3718 dock
->on_right_side
= 0;
3720 wArrangeIcons(scr
, False
);
3729 XFreePixmap(dpy
, ghost
);
3730 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3733 puts("End dock move");
3740 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3742 WScreen
*scr
= dock
->screen_ptr
;
3744 WIcon
*icon
= aicon
->icon
;
3745 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3746 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3748 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3749 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3750 int shad_x
= x
, shad_y
= y
;
3751 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3753 Pixmap ghost
= None
;
3755 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3756 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3759 if (wPreferences
.flags
.noupdates
)
3762 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3763 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3764 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3766 wwarning("pointer grab failed for icon move");
3770 if (!(event
->xbutton
.state
& MOD_MASK
))
3771 wRaiseFrame(icon
->core
);
3773 if (!wPreferences
.flags
.noclip
)
3774 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3776 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3778 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3781 wins
[0] = icon
->core
->window
;
3782 wins
[1] = scr
->dock_shadow
;
3783 XRestackWindows(dpy
, wins
, 2);
3784 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3785 ICON_SIZE
, ICON_SIZE
);
3787 if (icon
->pixmap
!=None
)
3788 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3790 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3792 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3793 XClearWindow(dpy
, scr
->dock_shadow
);
3795 XMapWindow(dpy
, scr
->dock_shadow
);
3801 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3802 |ButtonMotionMask
|ExposureMask
, &ev
);
3810 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3811 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3812 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3813 |ButtonReleaseMask
|ButtonPressMask
,
3814 wCursor
[WCUR_MOVE
], CurrentTime
);
3823 for (i
=0; i
<scr
->workspace_count
; i
++) {
3824 if (i
== scr
->current_workspace
)
3826 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3830 x
= ev
.xmotion
.x_root
- ofs_x
;
3831 y
= ev
.xmotion
.y_root
- ofs_y
;
3832 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3835 if (last_dock
!= dock
&& collapsed
) {
3836 last_dock
->collapsed
= 1;
3837 wDockHideIcons(last_dock
);
3840 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3841 dock
->collapsed
= 0;
3842 wDockShowIcons(dock
);
3844 if (dock
->auto_raise_lower
)
3848 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3851 if (last_dock
!= dock2
&& collapsed
) {
3852 last_dock
->collapsed
= 1;
3853 wDockHideIcons(last_dock
);
3856 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3857 dock2
->collapsed
= 0;
3858 wDockShowIcons(dock2
);
3860 if (dock2
->auto_raise_lower
)
3865 if (aicon
->launching
3867 || (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3868 || (!aicon
->running
&& tmp
)) {
3869 shad_x
= last_dock
->x_pos
+ ix
*wPreferences
.icon_size
;
3870 shad_y
= last_dock
->y_pos
+ iy
*wPreferences
.icon_size
;
3872 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3875 XMapWindow(dpy
, scr
->dock_shadow
);
3880 XUnmapWindow(dpy
, scr
->dock_shadow
);
3884 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3891 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3893 XUngrabPointer(dpy
, CurrentTime
);
3895 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3896 XUnmapWindow(dpy
, scr
->dock_shadow
);
3898 reattachIcon(dock
, aicon
, ix
, iy
);
3899 if (clip
&& dock
!=clip
&& clip
->auto_raise_lower
)
3902 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3904 /* Slide it back if dock rejected it */
3905 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3907 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3909 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3917 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3918 /* We need to deselect it, even if is deselected in
3919 * wDockDetach(), because else DoKaboom() will fail.
3921 if (aicon
->icon
->selected
)
3922 wIconSelect(aicon
->icon
);
3925 wSoundPlay(WMSOUND_KABOOM
);
3927 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3930 wSoundPlay(WMSOUND_UNDOCK
);
3935 wSoundPlay(WMSOUND_UNDOCK
);
3938 if (clip
&& clip
->auto_raise_lower
)
3940 wDockDetach(dock
, aicon
);
3943 last_dock
->collapsed
= 1;
3944 wDockHideIcons(last_dock
);
3949 XFreePixmap(dpy
, ghost
);
3950 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3954 for (i
=0; i
<scr
->workspace_count
; i
++) {
3955 if (i
== scr
->current_workspace
)
3957 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3962 puts("End icon move");
3971 getClipButton(int px
, int py
)
3973 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
3975 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3978 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
3979 return CLIP_FORWARD
;
3980 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
3988 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3991 int done
, direction
, new_ws
;
3993 WDock
*clip
= scr
->clip_icon
->dock
;
3995 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3997 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3998 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
4000 wClipIconPaint(scr
->clip_icon
);
4003 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
4004 |ButtonPressMask
, &ev
);
4011 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
4012 if (new_dir
!= direction
) {
4013 direction
= new_dir
;
4014 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
4015 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
4016 wClipIconPaint(scr
->clip_icon
);
4024 if (ev
.xbutton
.button
== event
->xbutton
.button
)
4029 clip
->lclip_button_pushed
= 0;
4030 clip
->rclip_button_pushed
= 0;
4032 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
4034 if (direction
== CLIP_FORWARD
) {
4035 if (scr
->current_workspace
< scr
->workspace_count
-1)
4036 wWorkspaceChange(scr
, scr
->current_workspace
+1);
4037 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
4038 wWorkspaceChange(scr
, scr
->current_workspace
+1);
4039 else if (wPreferences
.ws_cycle
)
4040 wWorkspaceChange(scr
, 0);
4042 else if (direction
== CLIP_REWIND
) {
4043 if (scr
->current_workspace
> 0)
4044 wWorkspaceChange(scr
, scr
->current_workspace
-1);
4045 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
4046 wWorkspaceChange(scr
, scr
->workspace_count
-1);
4049 wClipIconPaint(scr
->clip_icon
);
4054 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
4056 WAppIcon
*aicon
= desc
->parent
;
4057 WDock
*dock
= aicon
->dock
;
4058 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4060 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
4063 scr
->last_dock
= dock
;
4065 if (dock
->menu
->flags
.mapped
)
4066 wMenuUnmap(dock
->menu
);
4068 if (IsDoubleClick(scr
, event
)) {
4069 /* double-click was not in the main clip icon */
4070 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
4071 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
4072 iconDblClick(desc
, event
);
4077 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
4078 XUnmapWindow(dpy
, scr
->clip_balloon
);
4079 scr
->flags
.clip_balloon_mapped
= 0;
4083 puts("handling dock");
4085 if (event
->xbutton
.button
== Button1
) {
4086 if (event
->xbutton
.state
& MOD_MASK
)
4091 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
4092 dock
->type
!=WM_DOCK
) {
4093 wIconSelect(aicon
->icon
);
4097 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
4098 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
4099 && dock
->type
==WM_CLIP
)
4100 handleClipChangeWorkspace(scr
, event
);
4102 handleDockMove(dock
, aicon
, event
);
4104 handleIconMove(dock
, aicon
, event
);
4106 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4107 aicon
==scr
->clip_icon
) {
4108 openClipWorkspaceMenu(scr
, event
->xbutton
.x_root
+2,
4109 event
->xbutton
.y_root
+2);
4110 if (scr
->clip_ws_menu
) {
4112 menu
= scr
->clip_ws_menu
;
4113 desc
= &menu
->menu
->descriptor
;
4115 event
->xany
.send_event
= True
;
4116 (*desc
->handle_mousedown
)(desc
, event
);
4118 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4119 (event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
) {
4120 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
4121 } else if (event
->xbutton
.button
== Button3
) {
4122 openDockMenu(dock
, aicon
, event
);
4128 showClipBalloon(WDock
*dock
, int workspace
)
4132 WScreen
*scr
= dock
->screen_ptr
;
4136 scr
->flags
.clip_balloon_mapped
= 1;
4137 XMapWindow(dpy
, scr
->clip_balloon
);
4139 text
= scr
->workspaces
[workspace
]->name
;
4141 w
= WMWidthOfString(scr
->clip_title_font
, text
, strlen(text
));
4143 h
= WMFontHeight(scr
->clip_title_font
);
4144 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
4146 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
4147 y
= dock
->y_pos
+ ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
4149 if (x
+w
> scr
->scr_width
) {
4150 x
= scr
->scr_width
- w
;
4151 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
4152 y
= dock
->y_pos
- h
- 1;
4154 y
= dock
->y_pos
+ ICON_SIZE
;
4155 XRaiseWindow(dpy
, scr
->clip_balloon
);
4157 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
4158 stack
[1] = scr
->clip_balloon
;
4159 XRestackWindows(dpy
, stack
, 2);
4161 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
4162 XSetForeground(dpy
, scr
->clip_title_gc
,
4163 scr
->clip_title_pixel
[CLIP_NORMAL
]);
4164 XClearWindow(dpy
, scr
->clip_balloon
);
4165 WMDrawString(scr
->wmscreen
, scr
->clip_balloon
, scr
->clip_title_gc
,
4166 scr
->clip_title_font
, 0, 0, text
, strlen(text
));
4171 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
4173 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4177 assert(event
->type
==EnterNotify
);
4179 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4182 scr
= btn
->icon
->core
->screen_ptr
;
4183 if (!btn
->omnipresent
)
4186 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
4188 if (!dock
|| dock
->type
!=WM_CLIP
)
4191 /* The auto raise/lower code */
4192 if (dock
->auto_lower_magic
) {
4193 WMDeleteTimerHandler(dock
->auto_lower_magic
);
4194 dock
->auto_lower_magic
= NULL
;
4196 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
4197 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
,
4202 /* The auto expand/collapse code */
4203 if (dock
->auto_collapse_magic
) {
4204 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
4205 dock
->auto_collapse_magic
= NULL
;
4207 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
4208 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
,
4213 if (btn
->xindex
== 0 && btn
->yindex
== 0)
4214 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4216 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4217 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
4218 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
4225 clipLeave(WDock
*dock
)
4228 WObjDescriptor
*desc
= NULL
;
4230 if (!dock
|| dock
->type
!=WM_CLIP
)
4233 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
)!=False
) {
4234 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
4235 (XPointer
*)&desc
)!=XCNOENT
4236 && desc
&& desc
->parent_type
==WCLASS_DOCK_ICON
4237 && ((WAppIcon
*)desc
->parent
)->dock
4238 && ((WAppIcon
*)desc
->parent
)->dock
->type
==WM_CLIP
) {
4239 /* We didn't left the Clip yet */
4240 XPutBackEvent(dpy
, &event
);
4244 XPutBackEvent(dpy
, &event
);
4246 /* We entered a withdrawn window, so we're still in Clip */
4250 if (dock
->auto_raise_magic
) {
4251 WMDeleteTimerHandler(dock
->auto_raise_magic
);
4252 dock
->auto_raise_magic
= NULL
;
4254 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
4255 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
,
4260 if (dock
->auto_expand_magic
) {
4261 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4262 dock
->auto_expand_magic
= NULL
;
4264 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
4265 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
4273 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4275 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4277 assert(event
->type
==LeaveNotify
);
4279 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4282 clipLeave(btn
->dock
);
4287 clipAutoCollapse(void *cdata
)
4289 WDock
*dock
= (WDock
*)cdata
;
4291 if (dock
->type
!=WM_CLIP
)
4294 if (dock
->auto_collapse
) {
4295 dock
->collapsed
= 1;
4296 wDockHideIcons(dock
);
4298 dock
->auto_collapse_magic
= NULL
;
4303 clipAutoExpand(void *cdata
)
4305 WDock
*dock
= (WDock
*)cdata
;
4307 if (dock
->type
!=WM_CLIP
)
4310 if (dock
->auto_collapse
) {
4311 dock
->collapsed
= 0;
4312 wDockShowIcons(dock
);
4314 dock
->auto_expand_magic
= NULL
;
4319 clipAutoLower(void *cdata
)
4321 WDock
*dock
= (WDock
*)cdata
;
4323 if (dock
->type
!=WM_CLIP
)
4326 if (dock
->auto_raise_lower
)
4329 dock
->auto_lower_magic
= NULL
;
4334 clipAutoRaise(void *cdata
)
4336 WDock
*dock
= (WDock
*)cdata
;
4338 if (dock
->type
!=WM_CLIP
)
4341 if (dock
->auto_raise_lower
)
4344 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4345 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4348 dock
->auto_raise_magic
= NULL
;
4353 iconCanBeOmnipresent(WAppIcon
*aicon
)
4355 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4360 for (i
=0; i
<scr
->workspace_count
; i
++) {
4361 clip
= scr
->workspaces
[i
]->clip
;
4363 if (clip
== aicon
->dock
)
4366 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4367 return False
; /* Clip is full in some workspace */
4369 for (j
=0; j
<clip
->max_icons
; j
++) {
4370 btn
= clip
->icon_array
[j
];
4371 if(btn
&& btn
->xindex
==aicon
->xindex
&& btn
->yindex
==aicon
->yindex
)
4381 wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
4383 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4384 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4385 int status
= WO_SUCCESS
;
4387 if ((scr
->dock
&& aicon
->dock
==scr
->dock
) || aicon
==scr
->clip_icon
) {
4388 return WO_NOT_APPLICABLE
;
4391 if (aicon
->omnipresent
== omnipresent
)
4395 if (iconCanBeOmnipresent(aicon
)) {
4396 aicon
->omnipresent
= 1;
4397 new_entry
= wmalloc(sizeof(WAppIconChain
));
4398 new_entry
->aicon
= aicon
;
4399 new_entry
->next
= scr
->global_icons
;
4400 scr
->global_icons
= new_entry
;
4401 scr
->global_icon_count
++;
4403 aicon
->omnipresent
= 0;
4407 aicon
->omnipresent
= 0;
4408 if (aicon
== scr
->global_icons
->aicon
) {
4409 tmp
= scr
->global_icons
->next
;
4410 free(scr
->global_icons
);
4411 scr
->global_icons
= tmp
;
4412 scr
->global_icon_count
--;
4414 tmp
= scr
->global_icons
;
4416 if (tmp
->next
->aicon
== aicon
) {
4417 tmp1
= tmp
->next
->next
;
4420 scr
->global_icon_count
--;
4428 wAppIconPaint(aicon
);