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
);
1263 wClipIconPaint(WAppIcon
*aicon
)
1265 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1266 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1268 Window win
= aicon
->icon
->core
->window
;
1269 int length
, nlength
;
1270 char *ws_name
, ws_number
[10];
1273 wIconPaint(aicon
->icon
);
1275 length
= strlen(workspace
->name
);
1276 ws_name
= malloc(length
+ 1);
1277 sprintf(ws_name
, "%s", workspace
->name
);
1278 sprintf(ws_number
, "%i", scr
->current_workspace
+ 1);
1279 nlength
= strlen(ws_number
);
1281 gc
= scr
->clip_title_gc
;
1283 if (!workspace
->clip
->collapsed
)
1284 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_NORMAL
]);
1286 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_COLLAPSED
]);
1288 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1290 tx
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
1292 WMDrawString(scr
->wmscreen
, win
, gc
, scr
->clip_title_font
, tx
,
1293 ty
, ws_name
, length
);
1295 tx
= (ICON_SIZE
/2 - WMWidthOfString(scr
->clip_title_font
, ws_number
,
1298 WMDrawString(scr
->wmscreen
, win
, gc
, scr
->clip_title_font
, tx
,
1299 2, ws_number
, nlength
);
1303 if (aicon
->launching
) {
1304 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1305 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1307 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
,
1308 aicon
->dock
->rclip_button_pushed
);
1313 clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1315 wClipIconPaint(desc
->parent
);
1320 dockIconPaint(WAppIcon
*btn
)
1322 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1323 wClipIconPaint(btn
);
1330 make_icon_state(WAppIcon
*btn
)
1332 proplist_t node
= NULL
;
1333 proplist_t command
, autolaunch
, lock
, name
, forced
, host
, position
, buggy
;
1334 proplist_t omnipresent
;
1340 command
= PLMakeString("-");
1342 command
= PLMakeString(btn
->command
);
1344 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1346 lock
= btn
->lock
? dYes
: dNo
;
1348 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1350 name
= PLMakeString(tmp
);
1354 forced
= btn
->forced_dock
? dYes
: dNo
;
1356 buggy
= btn
->buggy_app
? dYes
: dNo
;
1358 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1359 sprintf(buffer
, "%i,%i", btn
->x_pos
, btn
->y_pos
);
1361 sprintf(buffer
, "%hi,%hi", btn
->xindex
, btn
->yindex
);
1362 position
= PLMakeString(buffer
);
1364 node
= PLMakeDictionaryFromEntries(dCommand
, command
,
1366 dAutoLaunch
, autolaunch
,
1369 dBuggyApplication
, buggy
,
1370 dPosition
, position
,
1374 PLRelease(position
);
1376 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1377 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&&
1378 (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1379 PLInsertDictionaryEntry(node
, dOmnipresent
, omnipresent
);
1382 if (btn
->dnd_command
) {
1383 command
= PLMakeString(btn
->dnd_command
);
1384 PLInsertDictionaryEntry(node
, dDropCommand
, command
);
1387 #endif /* OFFIX_DND */
1389 if (btn
->client_machine
&& btn
->remote_start
) {
1390 host
= PLMakeString(btn
->client_machine
);
1391 PLInsertDictionaryEntry(node
, dHost
, host
);
1401 dockSaveState(WDock
*dock
)
1404 proplist_t icon_info
;
1405 proplist_t list
=NULL
, dock_state
=NULL
;
1406 proplist_t value
, key
;
1409 list
= PLMakeArrayFromElements(NULL
);
1411 for (i
=(dock
->type
==WM_DOCK
? 0 : 1); i
<dock
->max_icons
; i
++) {
1412 WAppIcon
*btn
= dock
->icon_array
[i
];
1414 if (!btn
|| btn
->attracted
)
1417 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1418 list
= PLAppendArrayElement(list
, icon_info
);
1419 PLRelease(icon_info
);
1423 dock_state
= PLMakeDictionaryFromEntries(dApplications
, list
,
1426 if (dock
->type
== WM_DOCK
) {
1427 sprintf(buffer
, "Applications%i", dock
->screen_ptr
->scr_height
);
1428 key
= PLMakeString(buffer
);
1429 PLInsertDictionaryEntry(dock_state
, key
, list
);
1433 sprintf(buffer
, "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0),
1435 value
= PLMakeString(buffer
);
1436 PLInsertDictionaryEntry(dock_state
, dPosition
, value
);
1442 value
= (dock
->lowered
? dYes
: dNo
);
1443 PLInsertDictionaryEntry(dock_state
, dLowered
, value
);
1445 if (dock
->type
== WM_CLIP
) {
1446 value
= (dock
->collapsed
? dYes
: dNo
);
1447 PLInsertDictionaryEntry(dock_state
, dCollapsed
, value
);
1449 value
= (dock
->auto_collapse
? dYes
: dNo
);
1450 PLInsertDictionaryEntry(dock_state
, dAutoCollapse
, value
);
1452 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1453 PLInsertDictionaryEntry(dock_state
, dAutoRaiseLower
, value
);
1455 value
= (dock
->attract_icons
? dYes
: dNo
);
1456 PLInsertDictionaryEntry(dock_state
, dAutoAttractIcons
, value
);
1464 wDockSaveState(WScreen
*scr
, proplist_t old_state
)
1466 proplist_t dock_state
;
1469 dock_state
= dockSaveState(scr
->dock
);
1472 * Copy saved states of docks with different sizes.
1478 keys
= PLGetAllDictionaryKeys(old_state
);
1479 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
1480 tmp
= PLGetArrayElement(keys
, i
);
1482 if (strncasecmp(PLGetString(tmp
), "applications", 12) == 0
1483 && !PLGetDictionaryEntry(dock_state
, tmp
)) {
1485 PLInsertDictionaryEntry(dock_state
,
1487 PLGetDictionaryEntry(old_state
, tmp
));
1494 PLInsertDictionaryEntry(scr
->session_state
, dDock
, dock_state
);
1496 PLRelease(dock_state
);
1501 wClipSaveState(WScreen
*scr
)
1503 proplist_t clip_state
;
1505 clip_state
= make_icon_state(scr
->clip_icon
);
1507 PLInsertDictionaryEntry(scr
->session_state
, dClip
, clip_state
);
1509 PLRelease(clip_state
);
1514 wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1516 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1521 getBooleanDockValue(proplist_t value
, proplist_t key
)
1524 if (PLIsString(value
)) {
1525 if (strcasecmp(PLGetString(value
), "YES")==0)
1528 wwarning(_("bad value in docked icon state info %s"),
1537 restore_icon_state(WScreen
*scr
, proplist_t info
, int type
, int index
)
1540 char *wclass
, *winstance
;
1541 proplist_t cmd
, value
;
1545 cmd
= PLGetDictionaryEntry(info
, dCommand
);
1546 if (!cmd
|| !PLIsString(cmd
)) {
1550 /* parse window name */
1551 value
= PLGetDictionaryEntry(info
, dName
);
1555 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1557 if (!winstance
&& !wclass
) {
1564 command
= wstrdup(PLGetString(cmd
));
1568 if (!command
|| strcmp(command
, "-")==0) {
1579 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
,
1586 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1587 if (type
== WM_CLIP
) {
1588 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1589 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1591 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1592 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1596 cmd
= PLGetDictionaryEntry(info
, dDropCommand
);
1598 aicon
->dnd_command
= wstrdup(PLGetString(cmd
));
1601 /* check auto launch */
1602 value
= PLGetDictionaryEntry(info
, dAutoLaunch
);
1604 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1607 value
= PLGetDictionaryEntry(info
, dLock
);
1609 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1611 /* check if it wasn't normally docked */
1612 value
= PLGetDictionaryEntry(info
, dForced
);
1614 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1616 /* check if we can rely on the stuff in the app */
1617 value
= PLGetDictionaryEntry(info
, dBuggyApplication
);
1619 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1621 /* get position in the dock */
1622 value
= PLGetDictionaryEntry(info
, dPosition
);
1623 if (value
&& PLIsString(value
)) {
1624 if (sscanf(PLGetString(value
), "%hi,%hi", &aicon
->xindex
,
1626 wwarning(_("bad value in docked icon state info %s"),
1627 PLGetString(dPosition
));
1629 /* check position sanity */
1630 /* incomplete section! */
1631 if (type
== WM_DOCK
) {
1633 if (aicon
->yindex
< 0)
1634 wwarning(_("bad value in docked icon position %i,%i"),
1635 aicon
->xindex
, aicon
->yindex
);
1638 aicon
->yindex
= index
;
1642 /* check if icon is omnipresent */
1643 value
= PLGetDictionaryEntry(info
, dOmnipresent
);
1645 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1654 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1658 wClipRestoreState(WScreen
*scr
, proplist_t clip_state
)
1664 icon
= mainIconCreate(scr
, WM_CLIP
);
1669 PLRetain(clip_state
);
1671 /* restore position */
1673 value
= PLGetDictionaryEntry(clip_state
, dPosition
);
1676 if (!PLIsString(value
))
1677 COMPLAIN("Position");
1679 if (sscanf(PLGetString(value
), "%i,%i", &icon
->x_pos
,
1681 COMPLAIN("Position");
1683 /* check position sanity */
1684 if (icon
->y_pos
< 0)
1686 else if (icon
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1687 icon
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1689 if (icon
->x_pos
< 0)
1691 else if (icon
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1692 icon
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1697 value
= PLGetDictionaryEntry(clip_state
, dDropCommand
);
1698 if (value
&& PLIsString(value
))
1699 icon
->dnd_command
= wstrdup(PLGetString(value
));
1702 PLRelease(clip_state
);
1709 wDockRestoreState(WScreen
*scr
, proplist_t dock_state
, int type
)
1714 WAppIcon
*aicon
, *old_top
;
1718 dock
= wDockCreate(scr
, type
);
1724 PLRetain(dock_state
);
1727 /* restore position */
1729 value
= PLGetDictionaryEntry(dock_state
, dPosition
);
1732 if (!PLIsString(value
))
1733 COMPLAIN("Position");
1735 if (sscanf(PLGetString(value
), "%i,%i", &dock
->x_pos
,
1737 COMPLAIN("Position");
1739 /* check position sanity */
1740 if (dock
->y_pos
< 0)
1742 else if (dock
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1743 dock
->y_pos
= scr
->scr_height
- ICON_SIZE
;
1745 /* This is no more needed. ??? */
1746 if (type
== WM_CLIP
) {
1747 if (dock
->x_pos
< 0)
1749 else if (dock
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1750 dock
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1752 if (dock
->x_pos
>= 0) {
1753 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1754 dock
->on_right_side
= 0;
1756 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1757 dock
->on_right_side
= 1;
1763 /* restore lowered/raised state */
1767 value
= PLGetDictionaryEntry(dock_state
, dLowered
);
1770 if (!PLIsString(value
))
1771 COMPLAIN("Lowered");
1773 if (strcasecmp(PLGetString(value
), "YES")==0)
1779 /* restore collapsed state */
1781 dock
->collapsed
= 0;
1783 value
= PLGetDictionaryEntry(dock_state
, dCollapsed
);
1786 if (!PLIsString(value
))
1787 COMPLAIN("Collapsed");
1789 if (strcasecmp(PLGetString(value
), "YES")==0)
1790 dock
->collapsed
= 1;
1795 /* restore auto-collapsed state */
1797 value
= PLGetDictionaryEntry(dock_state
, dAutoCollapse
);
1800 if (!PLIsString(value
))
1801 COMPLAIN("AutoCollapse");
1803 if (strcasecmp(PLGetString(value
), "YES")==0) {
1804 dock
->auto_collapse
= 1;
1805 dock
->collapsed
= 1;
1811 /* restore auto-raise/lower state */
1813 value
= PLGetDictionaryEntry(dock_state
, dAutoRaiseLower
);
1816 if (!PLIsString(value
))
1817 COMPLAIN("AutoRaiseLower");
1819 if (strcasecmp(PLGetString(value
), "YES")==0) {
1820 dock
->auto_raise_lower
= 1;
1825 /* restore attract icons state */
1827 dock
->attract_icons
= 0;
1829 value
= PLGetDictionaryEntry(dock_state
, dAutoAttractIcons
);
1832 if (!PLIsString(value
))
1833 COMPLAIN("AutoAttractIcons");
1835 if (strcasecmp(PLGetString(value
), "YES")==0)
1836 dock
->attract_icons
= 1;
1841 /* application list */
1848 * When saving, it saves the dock state in
1849 * Applications and Applicationsnnn
1851 * When loading, it will first try Applicationsnnn.
1852 * If it does not exist, use Applications as default.
1855 sprintf(buffer
, "Applications%i", scr
->scr_height
);
1857 tmp
= PLMakeString(buffer
);
1858 apps
= PLGetDictionaryEntry(dock_state
, tmp
);
1862 apps
= PLGetDictionaryEntry(dock_state
, dApplications
);
1870 count
= PLGetNumberOfElements(apps
);
1875 old_top
= dock
->icon_array
[0];
1877 /* dock->icon_count is set to 1 when dock is created.
1878 * Since Clip is already restored, we want to keep it so for clip,
1879 * but for dock we may change the default top tile, so we set it to 0.
1881 if (type
== WM_DOCK
)
1882 dock
->icon_count
= 0;
1884 for (i
=0; i
<count
; i
++) {
1885 if (dock
->icon_count
>= dock
->max_icons
) {
1886 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1890 value
= PLGetArrayElement(apps
, i
);
1891 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1893 dock
->icon_array
[dock
->icon_count
] = aicon
;
1897 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
*ICON_SIZE
);
1898 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
*ICON_SIZE
);
1901 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1903 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1905 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
,
1908 if (!dock
->collapsed
)
1909 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1910 wRaiseFrame(aicon
->icon
->core
);
1913 } else if (dock
->icon_count
==0 && type
==WM_DOCK
)
1917 /* if the first icon is not defined, use the default */
1918 if (dock
->icon_array
[0]==NULL
) {
1919 /* update default icon */
1920 old_top
->x_pos
= dock
->x_pos
;
1921 old_top
->y_pos
= dock
->y_pos
;
1923 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1925 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1926 dock
->icon_array
[0] = old_top
;
1927 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1928 /* we don't need to increment dock->icon_count here because it was
1929 * incremented in the loop above.
1931 } else if (old_top
!=dock
->icon_array
[0]) {
1932 if (old_top
== scr
->clip_icon
)
1933 scr
->clip_icon
= dock
->icon_array
[0];
1934 wAppIconDestroy(old_top
);
1939 PLRelease(dock_state
);
1947 wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1949 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1951 btn
->drop_launch
= 0;
1953 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1956 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1968 wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1974 for (i
= 0; i
< dock
->max_icons
; i
++) {
1975 btn
= dock
->icon_array
[i
];
1976 if (!btn
|| !btn
->auto_launch
)
1979 state
= wmalloc(sizeof(WSavedState
));
1980 memset(state
, 0, sizeof(WSavedState
));
1981 state
->workspace
= workspace
;
1982 /* TODO: this is klugy and is very difficult to understand
1983 * what's going on. Try to clean up */
1984 wDockLaunchWithState(dock
, btn
, state
);
1988 #ifdef REDUCE_APPICONS
1990 wDockSimulateLaunch(WDock
*dock
, WAppIcon
*btn
)
1992 if ((btn
== NULL
) || (dock
== NULL
))
1995 if (!btn
->running
) {
1996 if ((btn
->icon
->owner
== NULL
) && (btn
->applist
))
1997 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
1998 if (!btn
->forced_dock
)
2008 findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
2014 if ((dock
= scr
->dock
)!=NULL
) {
2015 for (i
=0; i
<dock
->max_icons
; i
++) {
2016 if (dock
->icon_array
[i
]
2017 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
2023 if (*icon_pos
<0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
)!=NULL
) {
2024 for (i
=0; i
<dock
->max_icons
; i
++) {
2025 if (dock
->icon_array
[i
]
2026 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
2039 wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
2045 dock
= findDock(scr
, event
, &icon_pos
);
2050 * Return True if the drop was on an application icon window.
2051 * In this case, let the ClientMessage handler redirect the
2052 * message to the app.
2054 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!=None
)
2057 if (dock
->icon_array
[icon_pos
]->dnd_command
!=NULL
) {
2058 scr
->flags
.dnd_data_convertion_status
= 0;
2060 btn
= dock
->icon_array
[icon_pos
];
2062 if (!btn
->forced_dock
) {
2063 btn
->relaunching
= btn
->running
;
2066 if (btn
->wm_instance
|| btn
->wm_class
) {
2067 WWindowAttributes attr
;
2068 memset(&attr
, 0, sizeof(WWindowAttributes
));
2069 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
2071 btn
->wm_class
, &attr
, NULL
, True
);
2073 if (!attr
.no_appicon
)
2079 btn
->drop_launch
= 1;
2080 scr
->last_dock
= dock
;
2081 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
2086 if (!btn
->relaunching
) {
2093 #endif /* OFFIX_DND */
2098 wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2105 wwin
= icon
->icon
->owner
;
2106 if (icon
->command
==NULL
) {
2108 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2110 icon
->command
= FlattenStringList(argv
, argc
);
2111 XFreeStringList(argv
);
2115 /* icon->forced_dock = 1;*/
2116 if (dock
->type
!=WM_CLIP
|| !icon
->attracted
) {
2118 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2119 _("Type the command used to launch the application"),
2121 if (command
&& (command
[0]==0 ||
2122 (command
[0]=='-' && command
[1]==0))) {
2126 icon
->command
= command
;
2132 /* If the target is the dock, reject the icon. If
2133 * the target is the clip, make it an attracted icon
2135 if (dock
->type
==WM_CLIP
) {
2136 icon
->attracted
= 1;
2137 if (!icon
->icon
->shadowed
) {
2138 icon
->icon
->shadowed
= 1;
2139 icon
->icon
->force_paint
= 1;
2151 for (index
=1; index
<dock
->max_icons
; index
++)
2152 if (dock
->icon_array
[index
] == NULL
)
2154 /* if (index == dock->max_icons)
2157 assert(index
< dock
->max_icons
);
2159 dock
->icon_array
[index
] = icon
;
2163 icon
->omnipresent
= 0;
2165 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2166 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2171 icon
->launching
= 0;
2174 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2175 if (dock
->type
== WM_CLIP
) {
2176 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2177 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2179 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2180 icon
->icon
->core
->descriptor
.parent
= icon
;
2182 MoveInStackListUnder(dock
->icon_array
[index
-1]->icon
->core
,
2184 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2185 wAppIconPaint(icon
);
2187 if (wPreferences
.auto_arrange_icons
)
2188 wArrangeIcons(dock
->screen_ptr
, True
);
2191 if (icon
->command
&& !icon
->dnd_command
) {
2192 icon
->dnd_command
= wmalloc(strlen(icon
->command
)+8);
2193 sprintf(icon
->dnd_command
, "%s %%d", icon
->command
);
2202 reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2206 for(index
=1; index
<dock
->max_icons
; index
++) {
2207 if(dock
->icon_array
[index
] == icon
)
2210 assert(index
< dock
->max_icons
);
2215 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2216 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2221 moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2229 return True
; /* No move needed, we're already there */
2234 wwin
= icon
->icon
->owner
;
2237 * For the moment we can't do this if we move icons in Clip from one
2238 * workspace to other, because if we move two or more icons without
2239 * command, the dialog box will not be able to tell us to which of the
2240 * moved icons it applies. -Dan
2242 if ((dest
->type
==WM_DOCK
/*|| dest->keep_attracted*/) && icon
->command
==NULL
) {
2243 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2245 icon
->command
= FlattenStringList(argv
, argc
);
2246 XFreeStringList(argv
);
2251 /* icon->forced_dock = 1;*/
2252 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2253 _("Type the command used to launch the application"),
2255 if (command
&& (command
[0]==0 ||
2256 (command
[0]=='-' && command
[1]==0))) {
2260 icon
->command
= command
;
2271 if (dest
->type
== WM_DOCK
)
2272 wClipMakeIconOmnipresent(icon
, False
);
2274 for(index
=1; index
<src
->max_icons
; index
++) {
2275 if(src
->icon_array
[index
] == icon
)
2278 assert(index
< src
->max_icons
);
2280 src
->icon_array
[index
] = NULL
;
2283 for(index
=1; index
<dest
->max_icons
; index
++) {
2284 if(dest
->icon_array
[index
] == NULL
)
2287 /* if (index == dest->max_icons)
2290 assert(index
< dest
->max_icons
);
2292 dest
->icon_array
[index
] = icon
;
2295 /* deselect the icon */
2296 if (icon
->icon
->selected
)
2297 wIconSelect(icon
->icon
);
2299 if (dest
->type
== WM_DOCK
) {
2300 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2301 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2303 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2304 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2307 /* set it to be kept when moving to dock.
2308 * Unless the icon does not have a command set
2310 if (icon
->command
&& dest
->type
==WM_DOCK
) {
2311 icon
->attracted
= 0;
2312 if (icon
->icon
->shadowed
) {
2313 icon
->icon
->shadowed
= 0;
2314 icon
->icon
->force_paint
= 1;
2318 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2324 icon
->x_pos
= dest
->x_pos
+ x
*ICON_SIZE
;
2325 icon
->y_pos
= dest
->y_pos
+ y
*ICON_SIZE
;
2329 MoveInStackListUnder(dest
->icon_array
[index
-1]->icon
->core
,
2331 wAppIconPaint(icon
);
2338 wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2342 /* make the settings panel be closed */
2344 DestroyDockAppSettingsPanel(icon
->panel
);
2347 /* This must be called before icon->dock is set to NULL.
2348 * Don't move it. -Dan
2350 wClipMakeIconOmnipresent(icon
, False
);
2354 icon
->attracted
= 0;
2355 icon
->auto_launch
= 0;
2356 if (icon
->icon
->shadowed
) {
2357 icon
->icon
->shadowed
= 0;
2358 icon
->icon
->force_paint
= 1;
2361 /* deselect the icon */
2362 if (icon
->icon
->selected
)
2363 wIconSelect(icon
->icon
);
2365 if (icon
->command
) {
2366 free(icon
->command
);
2367 icon
->command
= NULL
;
2370 if (icon
->dnd_command
) {
2371 free(icon
->dnd_command
);
2372 icon
->dnd_command
= NULL
;
2376 for (index
=1; index
<dock
->max_icons
; index
++)
2377 if (dock
->icon_array
[index
] == icon
)
2379 assert(index
< dock
->max_icons
);
2380 dock
->icon_array
[index
] = NULL
;
2386 /* if the dock is not attached to an application or
2387 * the the application did not set the approriate hints yet,
2388 * destroy the icon */
2389 #ifdef REDUCE_APPICONS
2390 if ((icon
->num_apps
== 0) && (!icon
->running
|| !wApplicationOf(icon
->main_window
)) )
2392 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2394 wAppIconDestroy(icon
);
2396 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2397 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2398 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2399 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2400 icon
->icon
->core
->descriptor
.parent
= icon
;
2402 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2404 wAppIconPaint(icon
);
2405 if (wPreferences
.auto_arrange_icons
) {
2406 wArrangeIcons(dock
->screen_ptr
, True
);
2409 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2415 * returns the closest Dock slot index for the passed
2418 * Returns False if icon can't be docked.
2420 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2424 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2425 int *ret_x
, int *ret_y
, int redocking
)
2427 WScreen
*scr
= dock
->screen_ptr
;
2430 int i
, offset
= ICON_SIZE
/2;
2431 WAppIcon
*aicon
= NULL
;
2432 WAppIcon
*nicon
= NULL
;
2433 int max_y_icons
, max_x_icons
;
2435 max_x_icons
= scr
->scr_width
/ICON_SIZE
;
2436 max_y_icons
= scr
->scr_height
/ICON_SIZE
-1;
2438 if (wPreferences
.flags
.noupdates
)
2444 /* if the dock is full */
2446 (dock
->icon_count
>= dock
->max_icons
)) {
2450 /* exact position */
2452 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2454 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2457 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2459 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2461 /* check if the icon is outside the screen boundaries */
2462 if (dx
+ ex_x
*ICON_SIZE
< -ICON_SIZE
+2 ||
2463 dx
+ ex_x
*ICON_SIZE
>= scr
->scr_width
-1 ||
2464 dy
+ ex_y
*ICON_SIZE
< -ICON_SIZE
+2 ||
2465 dy
+ ex_y
*ICON_SIZE
>= scr
->scr_height
-1)
2468 if (dock
->type
== WM_DOCK
) {
2469 if (icon
->dock
!= dock
&& ex_x
!= 0)
2473 for (i
=0; i
<dock
->max_icons
; i
++) {
2474 nicon
= dock
->icon_array
[i
];
2475 if (nicon
&& nicon
->yindex
== ex_y
) {
2482 int sig
, done
, closest
;
2484 /* Possible cases when redocking:
2486 * icon dragged out of range of any slot -> false
2487 * icon dragged to range of free slot
2488 * icon dragged to range of same slot
2489 * icon dragged to range of different icon
2491 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2494 if (ex_y
>=0 && ex_y
<=max_y_icons
&& (aicon
==icon
|| !aicon
)) {
2500 /* start looking at the upper slot or lower? */
2501 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2508 /* look for closest free slot */
2509 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2513 closest
= sig
*(i
/2) + ex_y
;
2514 /* check if this slot is used */
2516 for (j
= 0; j
<dock
->max_icons
; j
++) {
2517 if (dock
->icon_array
[j
]
2518 && dock
->icon_array
[j
]->yindex
==closest
) {
2519 /* slot is used by someone else */
2520 if (dock
->icon_array
[j
]!=icon
)
2528 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2529 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2531 (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+1))) {
2536 } else { /* !redocking */
2538 /* if slot is free and the icon is close enough, return it */
2539 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2549 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2550 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+1;
2553 for (k
=start
; k
<stop
; k
++) {
2554 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2557 for (i
=0; i
<tmp
->max_icons
; i
++) {
2558 nicon
= tmp
->icon_array
[i
];
2559 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2567 for (k
=start
; k
<stop
; k
++) {
2568 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2571 for (i
=0; i
<tmp
->max_icons
; i
++) {
2572 nicon
= tmp
->icon_array
[i
];
2573 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2574 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2575 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2584 if (neighbours
&& (aicon
==NULL
|| (redocking
&& aicon
== icon
))) {
2593 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2594 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2596 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2597 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2598 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2602 * returns true if it can find a free slot in the dock,
2603 * in which case it changes x_pos and y_pos accordingly.
2604 * Else returns false.
2607 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2609 WScreen
*scr
= dock
->screen_ptr
;
2611 WAppIconChain
*chain
;
2612 unsigned char *slot_map
;
2616 int i
, done
= False
;
2618 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2621 if (dock
->type
== WM_CLIP
&&
2622 dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2623 extra_count
= scr
->global_icon_count
;
2625 /* if the dock is full */
2626 if (dock
->icon_count
+extra_count
>= dock
->max_icons
) {
2630 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2631 if (scr
->dock
->on_right_side
)
2632 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2634 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2637 if (ex
< dock
->x_pos
)
2639 if (sx
> dock
->x_pos
+ICON_SIZE
)
2640 sx
= dock
->x_pos
+ICON_SIZE
;
2647 /* check if clip is in a corner */
2648 if (dock
->type
==WM_CLIP
) {
2649 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2651 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2653 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2655 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2662 /* If the clip is in the corner, use only slots that are in the border
2664 if (corner
!=C_NONE
) {
2668 hcount
= MIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2669 vcount
= MIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2670 hmap
= wmalloc(hcount
+1);
2671 memset(hmap
, 0, hcount
+1);
2672 vmap
= wmalloc(vcount
+1);
2673 memset(vmap
, 0, vcount
+1);
2675 /* mark used positions */
2678 for (i
=0; i
<dock
->max_icons
; i
++) {
2679 btn
= dock
->icon_array
[i
];
2683 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2684 vmap
[btn
->yindex
] = 1;
2685 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2686 hmap
[btn
->xindex
] = 1;
2688 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2690 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2691 vmap
[btn
->yindex
] = 1;
2692 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2693 hmap
[btn
->xindex
] = 1;
2697 for (i
=0; i
<dock
->max_icons
; i
++) {
2698 btn
= dock
->icon_array
[i
];
2702 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2703 vmap
[btn
->yindex
] = 1;
2704 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2705 hmap
[-btn
->xindex
] = 1;
2707 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2709 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2710 vmap
[btn
->yindex
] = 1;
2711 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2712 hmap
[-btn
->xindex
] = 1;
2716 for (i
=0; i
<dock
->max_icons
; i
++) {
2717 btn
= dock
->icon_array
[i
];
2721 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2722 vmap
[-btn
->yindex
] = 1;
2723 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2724 hmap
[btn
->xindex
] = 1;
2726 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2728 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2729 vmap
[-btn
->yindex
] = 1;
2730 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2731 hmap
[btn
->xindex
] = 1;
2736 for (i
=0; i
<dock
->max_icons
; i
++) {
2737 btn
= dock
->icon_array
[i
];
2741 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2742 vmap
[-btn
->yindex
] = 1;
2743 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2744 hmap
[-btn
->xindex
] = 1;
2746 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2748 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2749 vmap
[-btn
->yindex
] = 1;
2750 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2751 hmap
[-btn
->xindex
] = 1;
2756 /* search a vacant slot */
2757 for (i
=1; i
<MAX(vcount
, hcount
); i
++) {
2758 if (i
< vcount
&& vmap
[i
]==0) {
2764 } else if (i
< hcount
&& hmap
[i
]==0) {
2774 /* If found a slot, translate and return */
2776 if (corner
==C_NW
|| corner
==C_NE
) {
2781 if (corner
==C_NE
|| corner
==C_SE
) {
2788 /* else, try to find a slot somewhere else */
2791 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2792 * placed outside of screen */
2793 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2795 /* In the worst case (the clip is in the corner of the screen),
2796 * the amount of icons that fit in the clip is smaller.
2797 * Double the map to get a safe value.
2803 slot_map
= wmalloc(mwidth
*mwidth
);
2804 memset(slot_map
, 0, mwidth
*mwidth
);
2806 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2808 /* mark used slots in the map. If the slot falls outside the map
2809 * (for example, when all icons are placed in line), ignore them. */
2810 for (i
=0; i
<dock
->max_icons
; i
++) {
2811 btn
= dock
->icon_array
[i
];
2813 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2815 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2816 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2818 /* Find closest slot from the center that is free by scanning the
2819 * map from the center to outward in circular passes.
2820 * This will not result in a neat layout, but will be optimal
2821 * in the sense that there will not be holes left.
2824 for (i
= 1; i
<= r
&& !done
; i
++) {
2827 /* top and bottom parts of the ring */
2828 for (x
= -i
; x
<= i
&& !done
; x
++) {
2829 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2831 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2832 if (slot_map
[XY2OFS(x
,y
)]==0
2833 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2840 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2841 if (slot_map
[XY2OFS(x
,y
)]==0
2842 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2849 /* left and right parts of the ring */
2850 for (y
= -i
+1; y
<= i
-1; y
++) {
2851 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2853 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2854 if (slot_map
[XY2OFS(x
,y
)]==0
2855 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2862 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2863 if (slot_map
[XY2OFS(x
,y
)]==0
2864 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2879 moveDock(WDock
*dock
, int new_x
, int new_y
)
2884 dock
->x_pos
= new_x
;
2885 dock
->y_pos
= new_y
;
2886 for (i
=0; i
<dock
->max_icons
; i
++) {
2887 btn
= dock
->icon_array
[i
];
2889 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2890 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2891 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2898 swapDock(WDock
*dock
)
2900 WScreen
*scr
= dock
->screen_ptr
;
2905 if (dock
->on_right_side
) {
2906 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2908 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2911 for (i
=0; i
<dock
->max_icons
; i
++) {
2912 btn
= dock
->icon_array
[i
];
2915 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2919 wScreenUpdateUsableArea(scr
);
2924 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2926 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2932 cmdline
= ExpandOptions(scr
, command
);
2934 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2942 ParseCommand(cmdline
, &argv
, &argc
);
2952 if ((pid
=fork())==0) {
2956 SetupEnvironment(scr
);
2962 args
= malloc(sizeof(char*)*(argc
+1));
2965 for (i
=0; i
<argc
; i
++) {
2969 execvp(argv
[0], args
);
2978 state
= wmalloc(sizeof(WSavedState
));
2979 memset(state
, 0, sizeof(WSavedState
));
2981 state
->miniaturized
= -1;
2983 if (btn
->dock
==scr
->dock
|| btn
->omnipresent
)
2984 state
->workspace
= -1;
2986 state
->workspace
= scr
->current_workspace
;
2988 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
2990 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
3001 wDockHideIcons(WDock
*dock
)
3008 for (i
=1; i
<dock
->max_icons
; i
++) {
3009 if (dock
->icon_array
[i
])
3010 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3014 dockIconPaint(dock
->icon_array
[0]);
3019 wDockShowIcons(WDock
*dock
)
3027 btn
= dock
->icon_array
[0];
3028 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
3030 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
3031 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
3033 for (i
=1; i
<dock
->max_icons
; i
++) {
3034 if (dock
->icon_array
[i
]) {
3035 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
3041 if (!dock
->collapsed
) {
3042 for (i
=1; i
<dock
->max_icons
; i
++) {
3043 if (dock
->icon_array
[i
]) {
3044 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3055 wDockLower(WDock
*dock
)
3059 for (i
=0; i
<dock
->max_icons
; i
++) {
3060 if (dock
->icon_array
[i
])
3061 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
3067 wDockRaise(WDock
*dock
)
3071 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
3072 if (dock
->icon_array
[i
])
3073 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
3079 wDockRaiseLower(WDock
*dock
)
3081 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
3082 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
3083 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
3091 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
3093 icon
->launching
= 0;
3094 icon
->relaunching
= 0;
3095 dockIconPaint(icon
);
3100 wDockFindIconFor(WDock
*dock
, Window window
)
3105 for (i
=0; i
<dock
->max_icons
; i
++) {
3106 icon
= dock
->icon_array
[i
];
3107 if (icon
&& icon
->main_window
== window
)
3115 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
3118 #ifdef REDUCE_APPICONS
3119 WAppIconAppList
*tapplist
;
3121 char *wm_class
, *wm_instance
;
3123 Bool firstPass
= True
;
3125 char *command
= NULL
;
3131 if (XGetCommand(dpy
, window
, &argv
, &argc
)) {
3132 if (argc
> 0 && argv
!= NULL
)
3133 command
= FlattenStringList(argv
,argc
);
3135 XFreeStringList(argv
);
3140 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
3141 (!wm_class
&& !wm_instance
))
3145 for (i
=0; i
<dock
->max_icons
; i
++) {
3146 icon
= dock
->icon_array
[i
];
3150 /* app is already attached to icon */
3151 if (icon
->main_window
== window
) {
3156 if ((icon
->wm_instance
|| icon
->wm_class
)
3158 || (dock
->screen_ptr
->flags
.startup
&& !icon
->running
))) {
3160 if (icon
->wm_instance
&& wm_instance
&&
3161 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
3164 if (icon
->wm_class
&& wm_class
&&
3165 strcmp(icon
->wm_class
, wm_class
)!=0) {
3168 if (firstPass
&& command
&& strcmp(icon
->command
, command
)!=0) {
3172 if (!icon
->relaunching
) {
3175 /* Possibly an application that was docked with dockit,
3176 * but the user did not update WMState to indicate that
3177 * it was docked by force */
3178 wapp
= wApplicationOf(window
);
3180 icon
->forced_dock
= 1;
3183 if (!icon
->forced_dock
)
3184 icon
->main_window
= window
;
3186 #ifdef REDUCE_APPICONS
3187 tapplist
= wmalloc(sizeof(WAppIconAppList
));
3188 memset(tapplist
, 0, sizeof(WAppIconAppList
));
3189 tapplist
->next
= icon
->applist
;
3191 icon
->applist
->prev
= tapplist
;
3192 icon
->applist
= tapplist
;
3193 tapplist
->wapp
= wApplicationOf(window
);
3198 wDockFinishLaunch(dock
, icon
);
3203 if (firstPass
&& !found
) {
3220 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3222 if (!wPreferences
.flags
.noclip
) {
3223 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3224 if (scr
->current_workspace
!= workspace
) {
3225 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3226 WAppIconChain
*chain
= scr
->global_icons
;
3229 moveIconBetweenDocks(chain
->aicon
->dock
,
3230 scr
->workspaces
[workspace
]->clip
,
3231 chain
->aicon
, chain
->aicon
->xindex
,
3232 chain
->aicon
->yindex
);
3233 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
3234 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3235 chain
= chain
->next
;
3238 wDockHideIcons(old_clip
);
3239 if (old_clip
->auto_raise_lower
) {
3240 if (old_clip
->auto_raise_magic
) {
3241 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3242 old_clip
->auto_raise_magic
= NULL
;
3244 wDockLower(old_clip
);
3246 if (old_clip
->auto_collapse
) {
3247 if (old_clip
->auto_expand_magic
) {
3248 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3249 old_clip
->auto_expand_magic
= NULL
;
3251 old_clip
->collapsed
= 1;
3253 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3255 if (scr
->flags
.clip_balloon_mapped
)
3256 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3263 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3268 for (i
=0; i
<dock
->max_icons
; i
++) {
3269 icon
= dock
->icon_array
[i
];
3273 if (icon
->launching
&& icon
->pid
== pid
) {
3274 if (!icon
->relaunching
) {
3276 icon
->main_window
= None
;
3278 wDockFinishLaunch(dock
, icon
);
3283 sprintf(msg
, _("Could not execute command \"%s\""),
3284 icon
->drop_launch
&& icon
->dnd_command
3285 ? icon
->dnd_command
: icon
->command
);
3287 sprintf(msg
, _("Could not execute command \"%s\""),
3290 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
3291 _("OK"), NULL
, NULL
);
3300 toggleLowered(WDock
*dock
)
3305 /* lower/raise Dock */
3306 if (!dock
->lowered
) {
3307 newlevel
= WMNormalLevel
;
3310 newlevel
= WMDockLevel
;
3314 for (i
=0; i
<dock
->max_icons
; i
++) {
3315 tmp
= dock
->icon_array
[i
];
3319 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3321 wLowerFrame(tmp
->icon
->core
);
3324 if (dock
->type
== WM_DOCK
)
3325 wScreenUpdateUsableArea(dock
->screen_ptr
);
3330 toggleCollapsed(WDock
*dock
)
3332 if (dock
->collapsed
) {
3333 dock
->collapsed
= 0;
3334 wDockShowIcons(dock
);
3337 dock
->collapsed
= 1;
3338 wDockHideIcons(dock
);
3344 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3346 WScreen
*scr
= dock
->screen_ptr
;
3347 WObjDescriptor
*desc
;
3349 WApplication
*wapp
= NULL
;
3353 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3355 if (dock
->type
== WM_DOCK
) {
3357 entry
= dock
->menu
->entries
[index
];
3358 entry
->flags
.indicator_on
= !dock
->lowered
;
3359 entry
->clientdata
= dock
;
3362 if (scr
->clip_options
)
3363 updateClipOptionsMenu(scr
->clip_options
, dock
);
3365 n_selected
= numberOfSelectedIcons(dock
);
3367 /* Rename Workspace */
3368 entry
= dock
->menu
->entries
[++index
];
3369 if (aicon
== scr
->clip_icon
) {
3370 entry
->callback
= renameCallback
;
3371 entry
->clientdata
= dock
;
3372 entry
->flags
.indicator
= 0;
3373 entry
->text
= _("Rename Workspace");
3375 entry
->callback
= omnipresentCallback
;
3376 entry
->clientdata
= aicon
;
3377 if (n_selected
> 0) {
3378 entry
->flags
.indicator
= 0;
3379 entry
->text
= _("Toggle Omnipresent");
3381 entry
->flags
.indicator
= 1;
3382 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3383 entry
->flags
.indicator_type
= MI_CHECK
;
3384 entry
->text
= _("Omnipresent");
3388 /* select/unselect icon */
3389 entry
= dock
->menu
->entries
[++index
];
3390 entry
->clientdata
= aicon
;
3391 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3392 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3394 /* select/unselect all icons */
3395 entry
= dock
->menu
->entries
[++index
];
3396 entry
->clientdata
= aicon
;
3398 entry
->text
= _("Unselect All Icons");
3400 entry
->text
= _("Select All Icons");
3401 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3404 entry
= dock
->menu
->entries
[++index
];
3405 entry
->clientdata
= aicon
;
3407 entry
->text
= _("Keep Icons");
3409 entry
->text
= _("Keep Icon");
3410 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3412 /* this is the workspace submenu part */
3413 entry
= dock
->menu
->entries
[++index
];
3415 entry
->text
= _("Move Icons To");
3417 entry
->text
= _("Move Icon To");
3418 if (scr
->clip_submenu
)
3419 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3420 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3422 /* remove icon(s) */
3423 entry
= dock
->menu
->entries
[++index
];
3424 entry
->clientdata
= aicon
;
3426 entry
->text
= _("Remove Icons");
3428 entry
->text
= _("Remove Icon");
3429 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3431 /* attract icon(s) */
3432 entry
= dock
->menu
->entries
[++index
];
3433 entry
->clientdata
= aicon
;
3435 dock
->menu
->flags
.realized
= 0;
3436 wMenuRealize(dock
->menu
);
3440 entry
= dock
->menu
->entries
[++index
];
3441 entry
->clientdata
= aicon
;
3442 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3445 entry
= dock
->menu
->entries
[++index
];
3446 entry
->clientdata
= aicon
;
3447 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3450 entry
= dock
->menu
->entries
[++index
];
3451 entry
->clientdata
= aicon
;
3452 if (aicon
->icon
->owner
) {
3453 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3454 if (wapp
&& wapp
->flags
.hidden
)
3455 entry
->text
= _("Unhide");
3457 entry
->text
= _("Hide");
3459 entry
->text
= _("Hide");
3461 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3464 entry
= dock
->menu
->entries
[++index
];
3465 entry
->clientdata
= aicon
;
3466 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
3467 && !wPreferences
.flags
.noupdates
);
3470 entry
= dock
->menu
->entries
[++index
];
3471 entry
->clientdata
= aicon
;
3472 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3474 if (!dock
->menu
->flags
.realized
)
3475 wMenuRealize(dock
->menu
);
3477 if (dock
->type
== WM_CLIP
) {
3478 x_pos
= event
->xbutton
.x_root
+2;
3480 x_pos
= dock
->on_right_side
?
3481 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 2 : 0;
3484 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3486 /* allow drag select */
3487 event
->xany
.send_event
= True
;
3488 desc
= &dock
->menu
->menu
->descriptor
;
3489 (*desc
->handle_mousedown
)(desc
, event
);
3494 openClipWorkspaceMenu(WScreen
*scr
, int x
, int y
)
3496 if (!scr
->clip_ws_menu
) {
3497 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3499 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
3500 wMenuMapAt(scr
->clip_ws_menu
, x
, y
, False
);
3504 /******************************************************************/
3506 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3508 WAppIcon
*btn
= desc
->parent
;
3509 WDock
*dock
= btn
->dock
;
3510 WApplication
*wapp
= NULL
;
3513 #ifdef REDUCE_APPICONS
3514 if ((btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) ||
3515 ((btn
->icon
->owner
== NULL
) && (btn
->applist
!= NULL
))) {
3516 if (btn
->icon
->owner
== NULL
)
3517 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
3519 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3521 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3525 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3527 /* go to the last workspace that the user worked on the app */
3528 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
3530 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3533 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3536 if (event
->xbutton
.state
& MOD_MASK
) {
3537 wHideOtherApplications(btn
->icon
->owner
);
3540 if (event
->xbutton
.button
==Button1
) {
3542 if (event
->xbutton
.state
& MOD_MASK
) {
3543 /* raise/lower dock */
3544 toggleLowered(dock
);
3545 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3546 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3547 toggleCollapsed(dock
);
3549 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3550 } else if (btn
->command
) {
3551 if (!btn
->launching
&&
3552 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3553 launchDockedApplication(btn
);
3555 } else if (btn
->xindex
== 0 && btn
->yindex
== 0
3556 && btn
->dock
->type
== WM_DOCK
) {
3558 wShowGNUstepPanel(dock
->screen_ptr
);
3566 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3568 WScreen
*scr
= dock
->screen_ptr
;
3569 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3572 int grabbed
= 0, swapped
= 0, done
;
3573 Pixmap ghost
= None
;
3574 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3577 puts("moving dock");
3579 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3580 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3581 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3582 wwarning("pointer grab failed for dock move");
3585 for (x
=0; x
<dock
->max_icons
; x
++) {
3586 if (dock
->icon_array
[x
]!=NULL
&&
3587 dock
->icon_array
[x
]->yindex
> y
)
3588 y
= dock
->icon_array
[x
]->yindex
;
3591 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3595 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3596 |ButtonMotionMask
|ExposureMask
, &ev
);
3604 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3605 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3606 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3607 |ButtonReleaseMask
|ButtonPressMask
,
3608 wCursor
[WCUR_MOVE
], CurrentTime
);
3613 if (dock
->type
== WM_CLIP
) {
3614 if (ev
.xmotion
.x_root
- ofs_x
< 0) {
3616 } else if (ev
.xmotion
.x_root
- ofs_x
+ ICON_SIZE
>
3618 x
= scr
->scr_width
- ICON_SIZE
;
3620 x
= ev
.xmotion
.x_root
- ofs_x
;
3622 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3624 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3626 y
= scr
->scr_height
- ICON_SIZE
;
3628 y
= ev
.xmotion
.y_root
- ofs_y
;
3630 moveDock(dock
, x
, y
);
3632 /* move vertically if pointer is inside the dock*/
3633 if ((dock
->on_right_side
&&
3634 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3635 || (!dock
->on_right_side
&&
3636 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3638 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3640 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3642 y
= scr
->scr_height
- ICON_SIZE
;
3644 y
= ev
.xmotion
.y_root
- ofs_y
;
3646 moveDock(dock
, dock
->x_pos
, y
);
3648 /* move horizontally to change sides */
3649 x
= ev
.xmotion
.x_root
- ofs_x
;
3650 if (!dock
->on_right_side
) {
3654 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3655 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3656 -DOCK_EXTRA_SPACE
-1, dock
->y_pos
);
3657 if (superfluous
&& ghost
==None
) {
3658 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3659 scr
->scr_width
-ICON_SIZE
3660 -DOCK_EXTRA_SPACE
-1,
3662 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3664 XClearWindow(dpy
, scr
->dock_shadow
);
3666 XMapRaised(dpy
, scr
->dock_shadow
);
3669 if (superfluous
&& ghost
!=None
) {
3670 XFreePixmap(dpy
, ghost
);
3673 XUnmapWindow(dpy
, scr
->dock_shadow
);
3678 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3679 XMoveWindow(dpy
, scr
->dock_shadow
,
3680 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3681 if (superfluous
&& ghost
==None
) {
3682 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3683 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3684 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3686 XClearWindow(dpy
, scr
->dock_shadow
);
3688 XMapRaised(dpy
, scr
->dock_shadow
);
3691 XUnmapWindow(dpy
, scr
->dock_shadow
);
3693 if (superfluous
&& ghost
!=None
) {
3694 XFreePixmap(dpy
, ghost
);
3706 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3708 XUngrabPointer(dpy
, CurrentTime
);
3709 XUnmapWindow(dpy
, scr
->dock_shadow
);
3710 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3711 if (dock
->type
== WM_DOCK
) {
3714 dock
->on_right_side
= 1;
3716 dock
->on_right_side
= 0;
3718 wArrangeIcons(scr
, False
);
3727 XFreePixmap(dpy
, ghost
);
3728 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3731 puts("End dock move");
3738 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3740 WScreen
*scr
= dock
->screen_ptr
;
3742 WIcon
*icon
= aicon
->icon
;
3743 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3744 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3746 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3747 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3748 int shad_x
= x
, shad_y
= y
;
3749 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3751 Pixmap ghost
= None
;
3753 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3754 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3757 if (wPreferences
.flags
.noupdates
)
3760 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3761 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3762 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3764 wwarning("pointer grab failed for icon move");
3768 if (!(event
->xbutton
.state
& MOD_MASK
))
3769 wRaiseFrame(icon
->core
);
3771 if (!wPreferences
.flags
.noclip
)
3772 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3774 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3776 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3779 wins
[0] = icon
->core
->window
;
3780 wins
[1] = scr
->dock_shadow
;
3781 XRestackWindows(dpy
, wins
, 2);
3782 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3783 ICON_SIZE
, ICON_SIZE
);
3785 if (icon
->pixmap
!=None
)
3786 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3788 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3790 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3791 XClearWindow(dpy
, scr
->dock_shadow
);
3793 XMapWindow(dpy
, scr
->dock_shadow
);
3799 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3800 |ButtonMotionMask
|ExposureMask
, &ev
);
3808 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3809 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3810 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3811 |ButtonReleaseMask
|ButtonPressMask
,
3812 wCursor
[WCUR_MOVE
], CurrentTime
);
3821 for (i
=0; i
<scr
->workspace_count
; i
++) {
3822 if (i
== scr
->current_workspace
)
3824 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3828 x
= ev
.xmotion
.x_root
- ofs_x
;
3829 y
= ev
.xmotion
.y_root
- ofs_y
;
3830 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3833 if (last_dock
!= dock
&& collapsed
) {
3834 last_dock
->collapsed
= 1;
3835 wDockHideIcons(last_dock
);
3838 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3839 dock
->collapsed
= 0;
3840 wDockShowIcons(dock
);
3842 if (dock
->auto_raise_lower
)
3846 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3849 if (last_dock
!= dock2
&& collapsed
) {
3850 last_dock
->collapsed
= 1;
3851 wDockHideIcons(last_dock
);
3854 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3855 dock2
->collapsed
= 0;
3856 wDockShowIcons(dock2
);
3858 if (dock2
->auto_raise_lower
)
3863 if (aicon
->launching
3865 || (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3866 || (!aicon
->running
&& tmp
)) {
3867 shad_x
= last_dock
->x_pos
+ ix
*wPreferences
.icon_size
;
3868 shad_y
= last_dock
->y_pos
+ iy
*wPreferences
.icon_size
;
3870 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3873 XMapWindow(dpy
, scr
->dock_shadow
);
3878 XUnmapWindow(dpy
, scr
->dock_shadow
);
3882 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3889 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3891 XUngrabPointer(dpy
, CurrentTime
);
3893 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3894 XUnmapWindow(dpy
, scr
->dock_shadow
);
3896 reattachIcon(dock
, aicon
, ix
, iy
);
3897 if (clip
&& dock
!=clip
&& clip
->auto_raise_lower
)
3900 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3902 /* Slide it back if dock rejected it */
3903 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3905 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3907 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3915 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3916 /* We need to deselect it, even if is deselected in
3917 * wDockDetach(), because else DoKaboom() will fail.
3919 if (aicon
->icon
->selected
)
3920 wIconSelect(aicon
->icon
);
3923 wSoundPlay(WMSOUND_KABOOM
);
3925 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3928 wSoundPlay(WMSOUND_UNDOCK
);
3933 wSoundPlay(WMSOUND_UNDOCK
);
3936 if (clip
&& clip
->auto_raise_lower
)
3938 wDockDetach(dock
, aicon
);
3941 last_dock
->collapsed
= 1;
3942 wDockHideIcons(last_dock
);
3947 XFreePixmap(dpy
, ghost
);
3948 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3952 for (i
=0; i
<scr
->workspace_count
; i
++) {
3953 if (i
== scr
->current_workspace
)
3955 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3960 puts("End icon move");
3969 getClipButton(int px
, int py
)
3971 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
3973 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3976 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
3977 return CLIP_FORWARD
;
3978 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
3986 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3989 int done
, direction
, new_ws
;
3991 WDock
*clip
= scr
->clip_icon
->dock
;
3993 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3995 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3996 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3998 wClipIconPaint(scr
->clip_icon
);
4001 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
4002 |ButtonPressMask
, &ev
);
4009 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
4010 if (new_dir
!= direction
) {
4011 direction
= new_dir
;
4012 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
4013 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
4014 wClipIconPaint(scr
->clip_icon
);
4022 if (ev
.xbutton
.button
== event
->xbutton
.button
)
4027 clip
->lclip_button_pushed
= 0;
4028 clip
->rclip_button_pushed
= 0;
4030 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
4032 if (direction
== CLIP_FORWARD
) {
4033 if (scr
->current_workspace
< scr
->workspace_count
-1)
4034 wWorkspaceChange(scr
, scr
->current_workspace
+1);
4035 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
4036 wWorkspaceChange(scr
, scr
->current_workspace
+1);
4037 else if (wPreferences
.ws_cycle
)
4038 wWorkspaceChange(scr
, 0);
4040 else if (direction
== CLIP_REWIND
) {
4041 if (scr
->current_workspace
> 0)
4042 wWorkspaceChange(scr
, scr
->current_workspace
-1);
4043 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
4044 wWorkspaceChange(scr
, scr
->workspace_count
-1);
4047 wClipIconPaint(scr
->clip_icon
);
4052 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
4054 WAppIcon
*aicon
= desc
->parent
;
4055 WDock
*dock
= aicon
->dock
;
4056 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4058 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
4061 scr
->last_dock
= dock
;
4063 if (dock
->menu
->flags
.mapped
)
4064 wMenuUnmap(dock
->menu
);
4066 if (IsDoubleClick(scr
, event
)) {
4067 /* double-click was not in the main clip icon */
4068 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
4069 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
4070 iconDblClick(desc
, event
);
4075 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
4076 XUnmapWindow(dpy
, scr
->clip_balloon
);
4077 scr
->flags
.clip_balloon_mapped
= 0;
4081 puts("handling dock");
4083 if (event
->xbutton
.button
== Button1
) {
4084 if (event
->xbutton
.state
& MOD_MASK
)
4089 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
4090 dock
->type
!=WM_DOCK
) {
4091 wIconSelect(aicon
->icon
);
4095 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
4096 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
4097 && dock
->type
==WM_CLIP
)
4098 handleClipChangeWorkspace(scr
, event
);
4100 handleDockMove(dock
, aicon
, event
);
4102 handleIconMove(dock
, aicon
, event
);
4104 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4105 aicon
==scr
->clip_icon
) {
4106 openClipWorkspaceMenu(scr
, event
->xbutton
.x_root
+2,
4107 event
->xbutton
.y_root
+2);
4108 if (scr
->clip_ws_menu
) {
4110 menu
= scr
->clip_ws_menu
;
4111 desc
= &menu
->menu
->descriptor
;
4113 event
->xany
.send_event
= True
;
4114 (*desc
->handle_mousedown
)(desc
, event
);
4116 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4117 (event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
) {
4118 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
4119 } else if (event
->xbutton
.button
== Button3
) {
4120 openDockMenu(dock
, aicon
, event
);
4126 showClipBalloon(WDock
*dock
, int workspace
)
4130 WScreen
*scr
= dock
->screen_ptr
;
4134 scr
->flags
.clip_balloon_mapped
= 1;
4135 XMapWindow(dpy
, scr
->clip_balloon
);
4137 text
= scr
->workspaces
[workspace
]->name
;
4139 w
= WMWidthOfString(scr
->clip_title_font
, text
, strlen(text
));
4141 h
= WMFontHeight(scr
->clip_title_font
);
4142 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
4144 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
4145 y
= dock
->y_pos
+ ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
4147 if (x
+w
> scr
->scr_width
) {
4148 x
= scr
->scr_width
- w
;
4149 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
4150 y
= dock
->y_pos
- h
- 1;
4152 y
= dock
->y_pos
+ ICON_SIZE
;
4153 XRaiseWindow(dpy
, scr
->clip_balloon
);
4155 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
4156 stack
[1] = scr
->clip_balloon
;
4157 XRestackWindows(dpy
, stack
, 2);
4159 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
4160 XSetForeground(dpy
, scr
->clip_title_gc
,
4161 scr
->clip_title_pixel
[CLIP_NORMAL
]);
4162 XClearWindow(dpy
, scr
->clip_balloon
);
4163 WMDrawString(scr
->wmscreen
, scr
->clip_balloon
, scr
->clip_title_gc
,
4164 scr
->clip_title_font
, 0, 0, text
, strlen(text
));
4169 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
4171 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4175 assert(event
->type
==EnterNotify
);
4177 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4180 scr
= btn
->icon
->core
->screen_ptr
;
4181 if (!btn
->omnipresent
)
4184 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
4186 if (!dock
|| dock
->type
!=WM_CLIP
)
4189 /* The auto raise/lower code */
4190 if (dock
->auto_lower_magic
) {
4191 WMDeleteTimerHandler(dock
->auto_lower_magic
);
4192 dock
->auto_lower_magic
= NULL
;
4194 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
4195 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
,
4200 /* The auto expand/collapse code */
4201 if (dock
->auto_collapse_magic
) {
4202 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
4203 dock
->auto_collapse_magic
= NULL
;
4205 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
4206 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
,
4211 if (btn
->xindex
== 0 && btn
->yindex
== 0)
4212 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4214 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4215 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
4216 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
4223 clipLeave(WDock
*dock
)
4226 WObjDescriptor
*desc
= NULL
;
4228 if (!dock
|| dock
->type
!=WM_CLIP
)
4231 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
)!=False
) {
4232 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
4233 (XPointer
*)&desc
)!=XCNOENT
4234 && desc
&& desc
->parent_type
==WCLASS_DOCK_ICON
4235 && ((WAppIcon
*)desc
->parent
)->dock
4236 && ((WAppIcon
*)desc
->parent
)->dock
->type
==WM_CLIP
) {
4237 /* We didn't left the Clip yet */
4238 XPutBackEvent(dpy
, &event
);
4242 XPutBackEvent(dpy
, &event
);
4244 /* We entered a withdrawn window, so we're still in Clip */
4248 if (dock
->auto_raise_magic
) {
4249 WMDeleteTimerHandler(dock
->auto_raise_magic
);
4250 dock
->auto_raise_magic
= NULL
;
4252 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
4253 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
,
4258 if (dock
->auto_expand_magic
) {
4259 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4260 dock
->auto_expand_magic
= NULL
;
4262 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
4263 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
4271 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4273 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4275 assert(event
->type
==LeaveNotify
);
4277 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4280 clipLeave(btn
->dock
);
4285 clipAutoCollapse(void *cdata
)
4287 WDock
*dock
= (WDock
*)cdata
;
4289 if (dock
->type
!=WM_CLIP
)
4292 if (dock
->auto_collapse
) {
4293 dock
->collapsed
= 1;
4294 wDockHideIcons(dock
);
4296 dock
->auto_collapse_magic
= NULL
;
4301 clipAutoExpand(void *cdata
)
4303 WDock
*dock
= (WDock
*)cdata
;
4305 if (dock
->type
!=WM_CLIP
)
4308 if (dock
->auto_collapse
) {
4309 dock
->collapsed
= 0;
4310 wDockShowIcons(dock
);
4312 dock
->auto_expand_magic
= NULL
;
4317 clipAutoLower(void *cdata
)
4319 WDock
*dock
= (WDock
*)cdata
;
4321 if (dock
->type
!=WM_CLIP
)
4324 if (dock
->auto_raise_lower
)
4327 dock
->auto_lower_magic
= NULL
;
4332 clipAutoRaise(void *cdata
)
4334 WDock
*dock
= (WDock
*)cdata
;
4336 if (dock
->type
!=WM_CLIP
)
4339 if (dock
->auto_raise_lower
)
4342 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4343 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4346 dock
->auto_raise_magic
= NULL
;
4351 iconCanBeOmnipresent(WAppIcon
*aicon
)
4353 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4358 for (i
=0; i
<scr
->workspace_count
; i
++) {
4359 clip
= scr
->workspaces
[i
]->clip
;
4361 if (clip
== aicon
->dock
)
4364 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4365 return False
; /* Clip is full in some workspace */
4367 for (j
=0; j
<clip
->max_icons
; j
++) {
4368 btn
= clip
->icon_array
[j
];
4369 if(btn
&& btn
->xindex
==aicon
->xindex
&& btn
->yindex
==aicon
->yindex
)
4379 wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
4381 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4382 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4383 int status
= WO_SUCCESS
;
4385 if ((scr
->dock
&& aicon
->dock
==scr
->dock
) || aicon
==scr
->clip_icon
) {
4386 return WO_NOT_APPLICABLE
;
4389 if (aicon
->omnipresent
== omnipresent
)
4393 if (iconCanBeOmnipresent(aicon
)) {
4394 aicon
->omnipresent
= 1;
4395 new_entry
= wmalloc(sizeof(WAppIconChain
));
4396 new_entry
->aicon
= aicon
;
4397 new_entry
->next
= scr
->global_icons
;
4398 scr
->global_icons
= new_entry
;
4399 scr
->global_icon_count
++;
4401 aicon
->omnipresent
= 0;
4405 aicon
->omnipresent
= 0;
4406 if (aicon
== scr
->global_icons
->aicon
) {
4407 tmp
= scr
->global_icons
->next
;
4408 free(scr
->global_icons
);
4409 scr
->global_icons
= tmp
;
4410 scr
->global_icon_count
--;
4412 tmp
= scr
->global_icons
;
4414 if (tmp
->next
->aicon
== aicon
) {
4415 tmp1
= tmp
->next
->next
;
4418 scr
->global_icon_count
--;
4426 wAppIconPaint(aicon
);