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
, dName
, dForced
, dBuggyApplication
, dYes
, dNo
;
105 static proplist_t dHost
, dDock
, dClip
;
106 static proplist_t dAutoAttractIcons
, dKeepAttracted
;
108 static proplist_t dPosition
, dApplications
, dLowered
, dCollapsed
, dAutoCollapse
;
110 static proplist_t dAutoRaiseLower
, dOmnipresent
;
112 static void dockIconPaint(WAppIcon
*btn
);
114 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
116 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
);
118 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
120 static int getClipButton(int px
, int py
);
122 static void toggleLowered(WDock
*dock
);
124 static void toggleCollapsed(WDock
*dock
);
126 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
128 static void clipLeave(WDock
*dock
);
130 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
132 Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
);
134 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
135 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
136 static void clipAutoCollapse(void *cdata
);
137 static void clipAutoExpand(void *cdata
);
138 static void launchDockedApplication(WAppIcon
*btn
);
140 static void clipAutoLower(void *cdata
);
141 static void clipAutoRaise(void *cdata
);
143 static void showClipBalloon(WDock
*dock
, int workspace
);
159 #endif /* OFFIX_DND */
169 dCommand
= PLRetain(PLMakeString("Command"));
171 dDropCommand
= PLRetain(PLMakeString("DropCommand"));
173 dAutoLaunch
= PLRetain(PLMakeString("AutoLaunch"));
174 dName
= PLRetain(PLMakeString("Name"));
175 dForced
= PLRetain(PLMakeString("Forced"));
176 dBuggyApplication
= PLRetain(PLMakeString("BuggyApplication"));
177 dYes
= PLRetain(PLMakeString("Yes"));
178 dNo
= PLRetain(PLMakeString("No"));
179 dHost
= PLRetain(PLMakeString("Host"));
181 dPosition
= PLMakeString("Position");
182 dApplications
= PLMakeString("Applications");
183 dLowered
= PLMakeString("Lowered");
184 dCollapsed
= PLMakeString("Collapsed");
185 dAutoCollapse
= PLMakeString("AutoCollapse");
186 dAutoRaiseLower
= PLMakeString("AutoRaiseLower");
187 dAutoAttractIcons
= PLMakeString("AutoAttractIcons");
188 dKeepAttracted
= PLMakeString("KeepAttracted");
190 dOmnipresent
= PLMakeString("Omnipresent");
192 dDock
= PLMakeString("Dock");
193 dClip
= PLMakeString("Clip");
199 renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
201 WDock
*dock
= entry
->clientdata
;
206 assert(entry
->clientdata
!=NULL
);
208 wspace
= dock
->screen_ptr
->current_workspace
;
210 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
212 sprintf(buffer
, _("Type the name for workspace %i:"), wspace
+1);
213 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
,
215 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
224 toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
226 assert(entry
->clientdata
!=NULL
);
228 toggleLowered(entry
->clientdata
);
230 entry
->flags
.indicator_on
= !((WDock
*)entry
->clientdata
)->lowered
;
238 killCallback(WMenu
*menu
, WMenuEntry
*entry
)
241 #ifdef REDUCE_APPICONS
242 WAppIconAppList
*tapplist
;
244 extern Atom _XA_WM_DELETE_WINDOW
;
249 if (!WCHECK_STATE(WSTATE_NORMAL
))
252 assert(entry
->clientdata
!=NULL
);
254 icon
= (WAppIcon
*)entry
->clientdata
;
258 WCHANGE_STATE(WSTATE_MODAL
);
260 #ifdef REDUCE_APPICONS
261 /* Send a delete message to the main window of each application
262 * bound to this docked appicon. - cls
264 tapplist
= icon
->applist
;
265 while (tapplist
!= NULL
) {
266 if (tapplist
->wapp
->main_window_desc
!= NULL
) {
267 if (tapplist
->wapp
->main_window_desc
->protocols
.DELETE_WINDOW
) {
268 wClientSendProtocol(tapplist
->wapp
->main_window_desc
,
269 _XA_WM_DELETE_WINDOW
, CurrentTime
);
271 wClientKill(tapplist
->wapp
->main_window_desc
);
274 tapplist
= tapplist
->next
;
277 buffer
= wstrappend(icon
->wm_class
,
278 _(" will be forcibly closed.\n"
279 "Any unsaved changes will be lost.\n"
282 if (wPreferences
.dont_confirm_kill
283 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
284 buffer
, _("Yes"), _("No"), NULL
)==WAPRDefault
) {
285 if (icon
->icon
&& icon
->icon
->owner
) {
286 wClientKill(icon
->icon
->owner
);
289 #endif /* !REDUCE_APPICONS */
293 WCHANGE_STATE(WSTATE_NORMAL
);
297 /* TODO: replace this function with a member of the dock struct */
299 numberOfSelectedIcons(WDock
*dock
)
305 for (i
=1; i
<dock
->max_icons
; i
++) {
306 aicon
= dock
->icon_array
[i
];
307 if (aicon
&& aicon
->icon
->selected
) {
317 getSelected(WDock
*dock
)
319 LinkedList
*ret
=NULL
;
323 for (i
=1; i
<dock
->max_icons
; i
++) {
324 btn
= dock
->icon_array
[i
];
325 if (btn
&& btn
->icon
->selected
) {
326 ret
= list_cons(btn
, ret
);
335 paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
337 Window win
= clipIcon
->icon
->core
->window
;
338 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
340 int pt
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
341 int tp
= ICON_SIZE
- pt
;
342 int as
= pt
- 15; /* 15 = 5+5+5 */
343 GC gc
= scr
->clip_title_gc
;
344 #ifdef GRADIENT_CLIP_ARROW
345 Bool collapsed
= clipIcon
->dock
->collapsed
;
351 p
[1].x
= ICON_SIZE
-2;
353 p
[2].x
= ICON_SIZE
-2;
355 } else if (lpushed
) {
359 p
[1].y
= ICON_SIZE
-2;
361 p
[2].y
= ICON_SIZE
-2;
363 if (lpushed
|| rpushed
) {
364 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
365 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
366 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
368 #ifdef GRADIENT_CLIP_ARROW
370 XSetFillStyle(dpy
, scr
->copy_gc
, FillTiled
);
371 XSetTile(dpy
, scr
->copy_gc
, scr
->clip_arrow_gradient
);
372 XSetClipMask(dpy
, scr
->copy_gc
, None
);
375 #endif /* GRADIENT_CLIP_ARROW */
377 /* top right arrow */
378 p
[0].x
= p
[3].x
= ICON_SIZE
-5-as
;
380 p
[1].x
= ICON_SIZE
-6;
382 p
[2].x
= ICON_SIZE
-6;
385 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
386 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
388 #ifdef GRADIENT_CLIP_ARROW
390 XSetTSOrigin(dpy
, gc
, ICON_SIZE
-6-as
, 5);
392 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
393 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
396 /* bottom left arrow */
398 p
[0].y
= p
[3].y
= ICON_SIZE
-5-as
;
400 p
[1].y
= ICON_SIZE
-6;
402 p
[2].y
= ICON_SIZE
-6;
404 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
405 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
407 #ifdef GRADIENT_CLIP_ARROW
409 XSetTSOrigin(dpy
, gc
, 5, ICON_SIZE
-6-as
);
411 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
412 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
414 #ifdef GRADIENT_CLIP_ARROW
416 XSetFillStyle(dpy
, scr
->copy_gc
, FillSolid
);
422 wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
424 RImage
*tile
= RCloneImage(normalTile
);
431 pt
= CLIP_BUTTON_SIZE
*wPreferences
.icon_size
/64;
432 tp
= wPreferences
.icon_size
-1 - pt
;
436 black
.red
= black
.green
= black
.blue
= 0;
439 dark
.red
= dark
.green
= dark
.blue
= 60;
442 light
.red
= light
.green
= light
.blue
= 80;
446 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
-2,
448 RDrawLine(tile
, tp
-1, 0, wPreferences
.icon_size
-1, pt
+1, &black
);
449 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
-3,
453 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4,
454 ICON_SIZE
- 5, 4, &dark
);
455 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5,
456 ICON_SIZE
- 5, 6 + as
, &dark
);
457 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
,
461 ROperateLine(tile
, RAddOperation
, 2, tp
+2, pt
-2,
462 wPreferences
.icon_size
-3, &dark
);
463 RDrawLine(tile
, 0, tp
-1, pt
+1, wPreferences
.icon_size
-1, &black
);
464 ROperateLine(tile
, RSubtractOperation
, 0, tp
-2, pt
+1,
465 wPreferences
.icon_size
-2, &light
);
468 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4,
469 ICON_SIZE
- 5, &dark
);
470 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
,
471 6 + as
, ICON_SIZE
- 5, &dark
);
472 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5,
480 removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
482 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
485 LinkedList
*selectedIcons
;
488 assert(clickedIcon
!=NULL
);
490 dock
= clickedIcon
->dock
;
492 selectedIcons
= getSelected(dock
);
495 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
496 _("All selected icons will be removed!"),
497 _("OK"), _("Cancel"), NULL
)!=WAPRDefault
) {
501 if (clickedIcon
->xindex
==0 && clickedIcon
->yindex
==0)
503 selectedIcons
= list_cons(clickedIcon
, NULL
);
506 while (selectedIcons
) {
507 aicon
= selectedIcons
->head
;
508 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
509 wDockDetach(dock
, aicon
);
511 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
512 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
513 aicon
->x_pos
, aicon
->y_pos
);
514 if (!dock
->mapped
|| dock
->collapsed
)
515 XMapWindow(dpy
, aicon
->icon
->core
->window
);
517 list_remove_head(&selectedIcons
);
520 if (wPreferences
.auto_arrange_icons
)
521 wArrangeIcons(dock
->screen_ptr
, True
);
526 keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
528 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
531 LinkedList
*selectedIcons
;
533 assert(clickedIcon
!=NULL
);
534 dock
= clickedIcon
->dock
;
536 selectedIcons
= getSelected(dock
);
538 if (!selectedIcons
&& clickedIcon
!=dock
->screen_ptr
->clip_icon
) {
539 char *command
= NULL
;
541 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
542 clickedIcon
->editing
= 1;
543 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
544 _("Type the command used to launch the application"),
546 if (command
&& (command
[0]==0 ||
547 (command
[0]=='-' && command
[1]==0))) {
551 clickedIcon
->command
= command
;
552 clickedIcon
->editing
= 0;
554 clickedIcon
->editing
= 0;
561 selectedIcons
= list_cons(clickedIcon
, NULL
);
564 while (selectedIcons
) {
565 aicon
= selectedIcons
->head
;
566 if (aicon
->icon
->selected
)
567 wIconSelect(aicon
->icon
);
568 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
569 aicon
->attracted
= 0;
570 if (aicon
->icon
->shadowed
) {
571 aicon
->icon
->shadowed
= 0;
572 aicon
->icon
->force_paint
= 1;
573 wAppIconPaint(aicon
);
576 list_remove_head(&selectedIcons
);
584 toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
586 WDock
*dock
= (WDock
*)entry
->clientdata
;
588 assert(entry
->clientdata
!=NULL
);
590 dock
->attract_icons
= !dock
->attract_icons
;
591 /*if (!dock->attract_icons)
592 dock->keep_attracted = 0;*/
594 entry
->flags
.indicator_on
= dock
->attract_icons
;
601 toggleKeepCallback(WMenu
*menu
, WMenuEntry
*entry
)
603 WDock
*dock
= (WDock
*)entry
->clientdata
;
607 assert(entry
->clientdata
!=NULL
);
609 dock
->keep_attracted
= !dock
->keep_attracted
;
611 if (dock
->keep_attracted
) {
612 for (i
=0; i
< dock
->max_icons
; i
++) {
613 btn
= dock
->icon_array
[i
];
614 if (btn
&& btn
->attracted
&& btn
->command
) {
616 if (btn
->icon
->shadowed
) {
617 btn
->icon
->shadowed
= 0;
618 btn
->icon
->force_paint
= 1;
625 entry
->flags
.indicator_on
= dock
->keep_attracted
;
632 selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
634 WAppIcon
*icon
= (WAppIcon
*)entry
->clientdata
;
638 wIconSelect(icon
->icon
);
645 colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
647 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
650 int x
, y
, x_pos
, y_pos
;
652 assert(entry
->clientdata
!=NULL
);
653 clip
= clickedIcon
->dock
;
655 aicon
= clip
->screen_ptr
->app_icon_list
;
658 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
659 x_pos
= clip
->x_pos
+ x
*ICON_SIZE
;
660 y_pos
= clip
->y_pos
+ y
*ICON_SIZE
;
661 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
663 if (wPreferences
.no_animations
) {
664 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
666 SlideWindow(aicon
->icon
->core
->window
,
667 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
670 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
671 #endif /* ANIMATIONS */
673 aicon
->attracted
= 1;
674 if (!clip
->keep_attracted
&& !aicon
->icon
->shadowed
) {
675 aicon
->icon
->shadowed
= 1;
676 aicon
->icon
->force_paint
= 1;
677 /* We don't do an wAppIconPaint() here because it's in
678 * wDockAttachIcon(). -Dan
681 wDockAttachIcon(clip
, aicon
, x
, y
);
682 if (clip
->collapsed
|| !clip
->mapped
)
683 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
691 selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
693 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
695 LinkedList
*selectedIcons
;
699 assert(clickedIcon
!=NULL
);
700 dock
= clickedIcon
->dock
;
702 selectedIcons
= getSelected(dock
);
704 if (!selectedIcons
) {
705 for (i
=1; i
<dock
->max_icons
; i
++) {
706 btn
= dock
->icon_array
[i
];
707 if (btn
&& !btn
->icon
->selected
) {
708 wIconSelect(btn
->icon
);
712 while(selectedIcons
) {
713 btn
= selectedIcons
->head
;
714 wIconSelect(btn
->icon
);
715 list_remove_head(&selectedIcons
);
724 toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
726 assert(entry
->clientdata
!=NULL
);
728 toggleCollapsed(entry
->clientdata
);
730 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->collapsed
;
737 toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
740 assert(entry
->clientdata
!=NULL
);
742 dock
= (WDock
*) entry
->clientdata
;
744 dock
->auto_collapse
= !dock
->auto_collapse
;
746 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_collapse
;
753 toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
756 assert(entry
->clientdata
!=NULL
);
758 dock
= (WDock
*) entry
->clientdata
;
760 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
762 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_raise_lower
;
769 launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
771 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
773 launchDockedApplication(btn
);
778 settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
780 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
784 ShowDockAppSettingsPanel(btn
);
789 hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
792 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
794 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
796 if (wapp
->flags
.hidden
) {
797 wWorkspaceChange(btn
->icon
->core
->screen_ptr
,wapp
->last_workspace
);
798 wUnhideApplication(wapp
, False
, False
);
800 wHideApplication(wapp
);
806 unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
809 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
811 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
813 wUnhideApplication(wapp
, False
, True
);
818 mainIconCreate(WScreen
*scr
, int type
)
823 if (type
== WM_CLIP
) {
825 return scr
->clip_icon
;
826 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
827 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
828 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
829 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
830 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE;*/
833 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
834 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
840 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
841 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
842 btn
->icon
->core
->descriptor
.parent
= btn
;
843 /*ChangeStackingLevel(btn->icon->core, WMDockLevel);*/
844 XMapWindow(dpy
, btn
->icon
->core
->window
);
849 scr
->clip_icon
= btn
;
856 switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
858 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
859 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
861 LinkedList
*selectedIcons
;
864 if (entry
->order
== scr
->current_workspace
)
867 dest
= scr
->workspaces
[entry
->order
]->clip
;
869 selectedIcons
= getSelected(src
);
872 while(selectedIcons
) {
873 btn
= selectedIcons
->head
;
874 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
875 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
876 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
878 list_remove_head(&selectedIcons
);
880 } else if (icon
!= scr
->clip_icon
) {
881 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
882 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
883 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
891 launchDockedApplication(WAppIcon
*btn
)
893 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
895 if (!btn
->launching
&& btn
->command
!=NULL
) {
896 if (!btn
->forced_dock
) {
897 btn
->relaunching
= btn
->running
;
900 if (btn
->wm_instance
|| btn
->wm_class
) {
901 WWindowAttributes attr
;
902 memset(&attr
, 0, sizeof(WWindowAttributes
));
903 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
,
906 if (!attr
.no_appicon
&& !btn
->buggy_app
)
911 btn
->drop_launch
= 0;
912 scr
->last_dock
= btn
->dock
;
913 btn
->pid
= execCommand(btn
, btn
->command
, NULL
);
915 if (btn
->buggy_app
) {
916 /* give feedback that the app was launched */
920 WMAddTimerHandler(200, (WMCallback
*)dockIconPaint
, btn
);
925 wwarning(_("could not launch application %s\n"), btn
->command
);
927 if (!btn
->relaunching
)
936 updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
938 WScreen
*scr
= menu
->frame
->screen_ptr
;
939 char title
[MAX_WORKSPACENAME_WIDTH
+1];
945 for (i
=0; i
<scr
->workspace_count
; i
++) {
946 if (i
< menu
->entry_no
) {
947 if (strcmp(menu
->entries
[i
]->text
,scr
->workspaces
[i
]->name
)!=0) {
948 free(menu
->entries
[i
]->text
);
949 strcpy(title
, scr
->workspaces
[i
]->name
);
950 menu
->entries
[i
]->text
= wstrdup(title
);
951 menu
->flags
.realized
= 0;
953 menu
->entries
[i
]->clientdata
= (void*)icon
;
955 strcpy(title
, scr
->workspaces
[i
]->name
);
957 wMenuAddCallback(menu
, title
, switchWSCommand
, (void*)icon
);
959 menu
->flags
.realized
= 0;
961 if (i
== scr
->current_workspace
) {
962 wMenuSetEnabled(menu
, i
, False
);
964 wMenuSetEnabled(menu
, i
, True
);
968 if (!menu
->flags
.realized
)
974 makeWorkspaceMenu(WScreen
*scr
)
978 menu
= wMenuCreate(scr
, NULL
, False
);
980 wwarning(_("could not create workspace submenu for Clip menu"));
982 wMenuAddCallback(menu
, "", switchWSCommand
, (void*)scr
->clip_icon
);
984 menu
->flags
.realized
= 0;
992 updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
1001 entry
= menu
->entries
[index
];
1002 entry
->flags
.indicator_on
= !dock
->lowered
;
1003 entry
->clientdata
= dock
;
1006 entry
= menu
->entries
[++index
];
1007 entry
->flags
.indicator_on
= dock
->collapsed
;
1008 entry
->clientdata
= dock
;
1011 entry
= menu
->entries
[++index
];
1012 entry
->flags
.indicator_on
= dock
->auto_collapse
;
1013 entry
->clientdata
= dock
;
1015 /* auto-raise/lower */
1016 entry
= menu
->entries
[++index
];
1017 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1018 entry
->clientdata
= dock
;
1021 entry
= menu
->entries
[++index
];
1022 entry
->flags
.indicator_on
= dock
->attract_icons
;
1023 entry
->clientdata
= dock
;
1025 /* keep attracted icons */
1026 entry
= menu
->entries
[++index
];
1027 entry
->flags
.indicator_on
= dock
->keep_attracted
;
1028 entry
->clientdata
= dock
;
1030 menu
->flags
.realized
= 0;
1036 makeClipOptionsMenu(WScreen
*scr
)
1041 menu
= wMenuCreate(scr
, NULL
, False
);
1043 wwarning(_("could not create options submenu for Clip menu"));
1047 entry
= wMenuAddCallback(menu
, _("Keep on Top"),
1048 toggleLoweredCallback
, NULL
);
1049 entry
->flags
.indicator
= 1;
1050 entry
->flags
.indicator_on
= 1;
1051 entry
->flags
.indicator_type
= MI_CHECK
;
1053 entry
= wMenuAddCallback(menu
, _("Collapsed"),
1054 toggleCollapsedCallback
, NULL
);
1055 entry
->flags
.indicator
= 1;
1056 entry
->flags
.indicator_on
= 1;
1057 entry
->flags
.indicator_type
= MI_CHECK
;
1059 entry
= wMenuAddCallback(menu
, _("AutoCollapse"),
1060 toggleAutoCollapseCallback
, NULL
);
1061 entry
->flags
.indicator
= 1;
1062 entry
->flags
.indicator_on
= 1;
1063 entry
->flags
.indicator_type
= MI_CHECK
;
1065 entry
= wMenuAddCallback(menu
, _("AutoRaiseLower"),
1066 toggleAutoRaiseLowerCallback
, NULL
);
1067 entry
->flags
.indicator
= 1;
1068 entry
->flags
.indicator_on
= 1;
1069 entry
->flags
.indicator_type
= MI_CHECK
;
1071 entry
= wMenuAddCallback(menu
, _("AutoAttract Icons"),
1072 toggleAutoAttractCallback
, NULL
);
1073 entry
->flags
.indicator
= 1;
1074 entry
->flags
.indicator_on
= 1;
1075 entry
->flags
.indicator_type
= MI_CHECK
;
1077 entry
= wMenuAddCallback(menu
, _("Keep Attracted Icons"),
1078 toggleKeepCallback
, NULL
);
1079 entry
->flags
.indicator
= 1;
1080 entry
->flags
.indicator_on
= 1;
1081 entry
->flags
.indicator_type
= MI_CHECK
;
1083 menu
->flags
.realized
= 0;
1091 dockMenuCreate(WScreen
*scr
, int type
)
1096 if (type
== WM_CLIP
&& scr
->clip_menu
)
1097 return scr
->clip_menu
;
1099 menu
= wMenuCreate(scr
, NULL
, False
);
1100 if (type
!= WM_CLIP
) {
1101 entry
= wMenuAddCallback(menu
, _("Keep on top"),
1102 toggleLoweredCallback
, NULL
);
1103 entry
->flags
.indicator
= 1;
1104 entry
->flags
.indicator_on
= 1;
1105 entry
->flags
.indicator_type
= MI_CHECK
;
1107 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1108 scr
->clip_options
= makeClipOptionsMenu(scr
);
1109 if (scr
->clip_options
)
1110 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1112 wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1114 entry
= wMenuAddCallback(menu
, _("Select Icon"), selectCallback
, NULL
);
1116 entry
->text
= _("Select Icon");
1118 entry
= wMenuAddCallback(menu
, _("Select All Icons"),
1119 selectIconsCallback
, NULL
);
1121 entry
->text
= _("Select All Icons");
1123 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1125 entry
->text
= _("Keep Icon");
1127 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1129 entry
->text
= _("Move Icon To");
1130 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1131 if (scr
->clip_submenu
)
1132 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1134 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
,
1137 entry
->text
= _("Remove Icon");
1139 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1142 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1144 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1146 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1148 entry
->text
= _("Hide");
1150 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1152 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1154 if (type
== WM_CLIP
)
1155 scr
->clip_menu
= menu
;
1162 wDockCreate(WScreen
*scr
, int type
)
1170 dock
= wmalloc(sizeof(WDock
));
1171 memset(dock
, 0, sizeof(WDock
));
1173 if (type
== WM_CLIP
)
1174 icon_count
= CLIP_MAX_ICONS
;
1176 icon_count
= scr
->scr_height
/wPreferences
.icon_size
;
1178 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*)*icon_count
);
1179 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*)*icon_count
);
1181 dock
->max_icons
= icon_count
;
1183 btn
= mainIconCreate(scr
, type
);
1187 dock
->x_pos
= btn
->x_pos
;
1188 dock
->y_pos
= btn
->y_pos
;
1189 dock
->screen_ptr
= scr
;
1191 dock
->icon_count
= 1;
1192 dock
->on_right_side
= 1;
1193 dock
->collapsed
= 0;
1194 dock
->auto_collapse
= 0;
1195 dock
->auto_collapse_magic
= NULL
;
1196 dock
->auto_raise_lower
= 0;
1197 dock
->auto_lower_magic
= NULL
;
1198 dock
->auto_raise_magic
= NULL
;
1199 dock
->attract_icons
= 0;
1200 dock
->keep_attracted
= 0;
1202 dock
->icon_array
[0] = btn
;
1203 wRaiseFrame(btn
->icon
->core
);
1204 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1206 /* create dock menu */
1207 dock
->menu
= dockMenuCreate(scr
, type
);
1214 wDockDestroy(WDock
*dock
)
1219 for (i
=(dock
->type
== WM_CLIP
) ? 1 : 0; i
<dock
->max_icons
; i
++) {
1220 aicon
= dock
->icon_array
[i
];
1222 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1223 wDockDetach(dock
, aicon
);
1225 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
1226 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
1227 aicon
->x_pos
, aicon
->y_pos
);
1228 if (!dock
->mapped
|| dock
->collapsed
)
1229 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1233 if (wPreferences
.auto_arrange_icons
)
1234 wArrangeIcons(dock
->screen_ptr
, True
);
1235 free(dock
->icon_array
);
1236 if (dock
->menu
&& dock
->type
!=WM_CLIP
)
1237 wMenuDestroy(dock
->menu
, True
);
1243 wClipIconPaint(WAppIcon
*aicon
)
1245 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1246 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1248 Window win
= aicon
->icon
->core
->window
;
1249 int length
, nlength
;
1250 char *ws_name
, ws_number
[10];
1253 wIconPaint(aicon
->icon
);
1255 length
= strlen(workspace
->name
);
1256 ws_name
= malloc(length
+ 1);
1257 sprintf(ws_name
, "%s", workspace
->name
);
1258 sprintf(ws_number
, "%i", scr
->current_workspace
+ 1);
1259 nlength
= strlen(ws_number
);
1261 gc
= scr
->clip_title_gc
;
1263 if (!workspace
->clip
->collapsed
)
1264 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_NORMAL
]);
1266 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_COLLAPSED
]);
1268 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1270 tx
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
1272 WMDrawString(scr
->wmscreen
, win
, gc
, scr
->clip_title_font
, tx
,
1273 ty
, ws_name
, length
);
1275 tx
= (ICON_SIZE
/2 - WMWidthOfString(scr
->clip_title_font
, ws_number
,
1278 WMDrawString(scr
->wmscreen
, win
, gc
, scr
->clip_title_font
, tx
,
1279 2, ws_number
, nlength
);
1283 if (aicon
->launching
) {
1284 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1285 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1287 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
,
1288 aicon
->dock
->rclip_button_pushed
);
1293 clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1295 wClipIconPaint(desc
->parent
);
1300 dockIconPaint(WAppIcon
*btn
)
1302 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1303 wClipIconPaint(btn
);
1310 make_icon_state(WAppIcon
*btn
)
1312 proplist_t node
= NULL
;
1313 proplist_t command
, autolaunch
, name
, forced
, host
, position
, buggy
;
1314 proplist_t omnipresent
;
1320 command
= PLMakeString("-");
1322 command
= PLMakeString(btn
->command
);
1324 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1326 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1328 name
= PLMakeString(tmp
);
1332 forced
= btn
->forced_dock
? dYes
: dNo
;
1334 buggy
= btn
->buggy_app
? dYes
: dNo
;
1336 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1337 sprintf(buffer
, "%i,%i", btn
->x_pos
, btn
->y_pos
);
1339 sprintf(buffer
, "%hi,%hi", btn
->xindex
, btn
->yindex
);
1340 position
= PLMakeString(buffer
);
1342 node
= PLMakeDictionaryFromEntries(dCommand
, command
,
1344 dAutoLaunch
, autolaunch
,
1346 dBuggyApplication
, buggy
,
1347 dPosition
, position
,
1351 PLRelease(position
);
1353 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1354 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&&
1355 (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1356 PLInsertDictionaryEntry(node
, dOmnipresent
, omnipresent
);
1359 if (btn
->dnd_command
) {
1360 command
= PLMakeString(btn
->dnd_command
);
1361 PLInsertDictionaryEntry(node
, dDropCommand
, command
);
1364 #endif /* OFFIX_DND */
1366 if (btn
->client_machine
&& btn
->remote_start
) {
1367 host
= PLMakeString(btn
->client_machine
);
1368 PLInsertDictionaryEntry(node
, dHost
, host
);
1378 dockSaveState(WDock
*dock
)
1381 proplist_t icon_info
;
1382 proplist_t list
=NULL
, dock_state
=NULL
;
1386 list
= PLMakeArrayFromElements(NULL
);
1388 for (i
=(dock
->type
==WM_DOCK
? 0 : 1); i
<dock
->max_icons
; i
++) {
1389 WAppIcon
*btn
= dock
->icon_array
[i
];
1391 if (!btn
|| (btn
->attracted
&& !dock
->keep_attracted
))
1394 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1395 list
= PLAppendArrayElement(list
, icon_info
);
1396 PLRelease(icon_info
);
1400 dock_state
= PLMakeDictionaryFromEntries(dApplications
, list
, NULL
);
1404 if (dock
->type
== WM_DOCK
) {
1405 sprintf(buffer
, "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0),
1407 value
= PLMakeString(buffer
);
1408 PLInsertDictionaryEntry(dock_state
, dPosition
, value
);
1412 value
= (dock
->lowered
? dYes
: dNo
);
1413 PLInsertDictionaryEntry(dock_state
, dLowered
, value
);
1415 if (dock
->type
== WM_CLIP
) {
1416 value
= (dock
->collapsed
? dYes
: dNo
);
1417 PLInsertDictionaryEntry(dock_state
, dCollapsed
, value
);
1419 value
= (dock
->auto_collapse
? dYes
: dNo
);
1420 PLInsertDictionaryEntry(dock_state
, dAutoCollapse
, value
);
1422 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1423 PLInsertDictionaryEntry(dock_state
, dAutoRaiseLower
, value
);
1425 value
= (dock
->attract_icons
? dYes
: dNo
);
1426 PLInsertDictionaryEntry(dock_state
, dAutoAttractIcons
, value
);
1428 value
= (dock
->keep_attracted
? dYes
: dNo
);
1429 PLInsertDictionaryEntry(dock_state
, dKeepAttracted
, value
);
1437 wDockSaveState(WScreen
*scr
)
1439 proplist_t dock_state
;
1441 dock_state
= dockSaveState(scr
->dock
);
1443 PLInsertDictionaryEntry(scr
->session_state
, dDock
, dock_state
);
1445 PLRelease(dock_state
);
1450 wClipSaveState(WScreen
*scr
)
1452 proplist_t clip_state
;
1454 clip_state
= make_icon_state(scr
->clip_icon
);
1456 PLInsertDictionaryEntry(scr
->session_state
, dClip
, clip_state
);
1458 PLRelease(clip_state
);
1463 wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1465 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1470 restore_icon_state(WScreen
*scr
, proplist_t info
, int type
, int index
)
1473 char *wclass
, *winstance
;
1474 proplist_t cmd
, value
;
1478 cmd
= PLGetDictionaryEntry(info
, dCommand
);
1479 if (!cmd
|| !PLIsString(cmd
)) {
1483 /* parse window name */
1484 value
= PLGetDictionaryEntry(info
, dName
);
1488 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1490 if (!winstance
&& !wclass
) {
1497 command
= wstrdup(PLGetString(cmd
));
1501 if (!command
|| strcmp(command
, "-")==0) {
1512 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
,
1519 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1520 if (type
== WM_CLIP
) {
1521 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1522 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1524 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1525 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1529 cmd
= PLGetDictionaryEntry(info
, dDropCommand
);
1531 aicon
->dnd_command
= wstrdup(PLGetString(cmd
));
1534 /* check auto launch */
1535 value
= PLGetDictionaryEntry(info
, dAutoLaunch
);
1537 aicon
->auto_launch
= 0;
1539 if (PLIsString(value
)) {
1540 if (strcasecmp(PLGetString(value
), "YES")==0)
1541 aicon
->auto_launch
= 1;
1543 wwarning(_("bad value in docked icon state info %s"),
1544 PLGetString(dAutoLaunch
));
1548 /* check if it wasn't normally docked */
1549 value
= PLGetDictionaryEntry(info
, dForced
);
1551 aicon
->forced_dock
= 0;
1553 if (PLIsString(value
)) {
1554 if (strcasecmp(PLGetString(value
), "YES")==0)
1555 aicon
->forced_dock
= 1;
1557 wwarning(_("bad value in docked icon state info %s"),
1558 PLGetString(dForced
));
1562 /* check if we can rely on the stuff in the app */
1563 value
= PLGetDictionaryEntry(info
, dBuggyApplication
);
1565 aicon
->buggy_app
= 0;
1567 if (PLIsString(value
)) {
1568 if (strcasecmp(PLGetString(value
), "YES")==0)
1569 aicon
->buggy_app
= 1;
1571 wwarning(_("bad value in docked icon state info %s"),
1572 PLGetString(dBuggyApplication
));
1576 /* get position in the dock */
1577 value
= PLGetDictionaryEntry(info
, dPosition
);
1578 if (value
&& PLIsString(value
)) {
1579 if (sscanf(PLGetString(value
), "%hi,%hi", &aicon
->xindex
,
1581 wwarning(_("bad value in docked icon state info %s"),
1582 PLGetString(dPosition
));
1584 /* check position sanity */
1585 /* incomplete section! */
1586 if (type
== WM_DOCK
) {
1588 if (aicon
->yindex
< 0)
1589 wwarning(_("bad value in docked icon position %i,%i"),
1590 aicon
->xindex
, aicon
->yindex
);
1593 aicon
->yindex
= index
;
1597 /* check if icon is omnipresent */
1598 value
= PLGetDictionaryEntry(info
, dOmnipresent
);
1600 aicon
->omnipresent
= 0;
1602 if (PLIsString(value
)) {
1603 if (strcasecmp(PLGetString(value
), "YES")==0)
1604 aicon
->omnipresent
= 1;
1606 wwarning(_("bad value in docked icon state info %s"),
1607 PLGetString(dOmnipresent
));
1618 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1622 wClipRestoreState(WScreen
*scr
, proplist_t clip_state
)
1628 icon
= mainIconCreate(scr
, WM_CLIP
);
1633 PLRetain(clip_state
);
1635 /* restore position */
1637 value
= PLGetDictionaryEntry(clip_state
, dPosition
);
1640 if (!PLIsString(value
))
1641 COMPLAIN("Position");
1643 if (sscanf(PLGetString(value
), "%i,%i", &icon
->x_pos
,
1645 COMPLAIN("Position");
1647 /* check position sanity */
1648 if (icon
->y_pos
< 0)
1650 else if (icon
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1651 icon
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1653 if (icon
->x_pos
< 0)
1655 else if (icon
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1656 icon
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1661 value
= PLGetDictionaryEntry(clip_state
, dDropCommand
);
1662 if (value
&& PLIsString(value
))
1663 icon
->dnd_command
= wstrdup(PLGetString(value
));
1666 PLRelease(clip_state
);
1673 wDockRestoreState(WScreen
*scr
, proplist_t dock_state
, int type
)
1678 WAppIcon
*aicon
, *old_top
;
1682 dock
= wDockCreate(scr
, type
);
1688 PLRetain(dock_state
);
1691 /* restore position */
1693 value
= PLGetDictionaryEntry(dock_state
, dPosition
);
1696 if (!PLIsString(value
))
1697 COMPLAIN("Position");
1699 if (sscanf(PLGetString(value
), "%i,%i", &dock
->x_pos
,
1701 COMPLAIN("Position");
1703 /* check position sanity */
1704 if (dock
->y_pos
< 0)
1706 else if (dock
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1707 dock
->y_pos
= scr
->scr_height
- ICON_SIZE
;
1709 /* This is no more needed. ??? */
1710 if (type
== WM_CLIP
) {
1711 if (dock
->x_pos
< 0)
1713 else if (dock
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1714 dock
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1716 if (dock
->x_pos
>= 0) {
1717 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1718 dock
->on_right_side
= 0;
1720 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1721 dock
->on_right_side
= 1;
1727 /* restore lowered/raised state */
1731 value
= PLGetDictionaryEntry(dock_state
, dLowered
);
1734 if (!PLIsString(value
))
1735 COMPLAIN("Lowered");
1737 if (strcasecmp(PLGetString(value
), "YES")==0)
1743 /* restore collapsed state */
1745 dock
->collapsed
= 0;
1747 value
= PLGetDictionaryEntry(dock_state
, dCollapsed
);
1750 if (!PLIsString(value
))
1751 COMPLAIN("Collapsed");
1753 if (strcasecmp(PLGetString(value
), "YES")==0)
1754 dock
->collapsed
= 1;
1759 /* restore auto-collapsed state */
1761 value
= PLGetDictionaryEntry(dock_state
, dAutoCollapse
);
1764 if (!PLIsString(value
))
1765 COMPLAIN("AutoCollapse");
1767 if (strcasecmp(PLGetString(value
), "YES")==0) {
1768 dock
->auto_collapse
= 1;
1769 dock
->collapsed
= 1;
1775 /* restore auto-raise/lower state */
1777 value
= PLGetDictionaryEntry(dock_state
, dAutoRaiseLower
);
1780 if (!PLIsString(value
))
1781 COMPLAIN("AutoRaiseLower");
1783 if (strcasecmp(PLGetString(value
), "YES")==0) {
1784 dock
->auto_raise_lower
= 1;
1789 /* restore attract icons state */
1791 dock
->attract_icons
= 0;
1793 value
= PLGetDictionaryEntry(dock_state
, dAutoAttractIcons
);
1796 if (!PLIsString(value
))
1797 COMPLAIN("AutoAttractIcons");
1799 if (strcasecmp(PLGetString(value
), "YES")==0)
1800 dock
->attract_icons
= 1;
1805 /* restore keep attracted icons state */
1807 dock
->keep_attracted
= 0;
1809 value
= PLGetDictionaryEntry(dock_state
, dKeepAttracted
);
1812 if (!PLIsString(value
))
1813 COMPLAIN("KeepAttracted");
1815 if (strcasecmp(PLGetString(value
), "YES")==0)
1816 dock
->keep_attracted
= 1;
1821 /* application list */
1823 apps
= PLGetDictionaryEntry(dock_state
, dApplications
);
1829 count
= PLGetNumberOfElements(apps
);
1834 old_top
= dock
->icon_array
[0];
1836 /* dock->icon_count is set to 1 when dock is created.
1837 * Since Clip is already restored, we want to keep it so for clip,
1838 * but for dock we may change the default top tile, so we set it to 0.
1840 if (type
== WM_DOCK
)
1841 dock
->icon_count
= 0;
1843 for (i
=0; i
<count
; i
++) {
1844 if (dock
->icon_count
>= dock
->max_icons
) {
1845 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1849 value
= PLGetArrayElement(apps
, i
);
1850 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1852 dock
->icon_array
[dock
->icon_count
] = aicon
;
1856 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
*ICON_SIZE
);
1857 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
*ICON_SIZE
);
1860 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1862 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1864 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
,
1867 if (!dock
->collapsed
)
1868 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1869 wRaiseFrame(aicon
->icon
->core
);
1872 } else if (dock
->icon_count
==0 && type
==WM_DOCK
)
1876 /* if the first icon is not defined, use the default */
1877 if (dock
->icon_array
[0]==NULL
) {
1878 /* update default icon */
1879 old_top
->x_pos
= dock
->x_pos
;
1880 old_top
->y_pos
= dock
->y_pos
;
1882 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1884 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1885 dock
->icon_array
[0] = old_top
;
1886 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1887 /* we don't need to increment dock->icon_count here because it was
1888 * incremented in the loop above.
1890 } else if (old_top
!=dock
->icon_array
[0]) {
1891 if (old_top
== scr
->clip_icon
)
1892 scr
->clip_icon
= dock
->icon_array
[0];
1893 wAppIconDestroy(old_top
);
1898 PLRelease(dock_state
);
1906 wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1908 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1910 btn
->drop_launch
= 0;
1912 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1915 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1927 wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1933 for (i
= 0; i
< dock
->max_icons
; i
++) {
1934 btn
= dock
->icon_array
[i
];
1935 if (!btn
|| !btn
->auto_launch
)
1938 state
= wmalloc(sizeof(WSavedState
));
1939 memset(state
, 0, sizeof(WSavedState
));
1940 state
->workspace
= workspace
;
1941 /* TODO: this is klugy and is very difficult to understand
1942 * what's going on. Try to clean up */
1943 wDockLaunchWithState(dock
, btn
, state
);
1947 #ifdef REDUCE_APPICONS
1949 wDockSimulateLaunch(WDock
*dock
, WAppIcon
*btn
)
1951 if ((btn
== NULL
) || (dock
== NULL
))
1954 if (!btn
->running
) {
1955 if ((btn
->icon
->owner
== NULL
) && (btn
->applist
))
1956 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
1957 if (!btn
->forced_dock
)
1967 findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1973 if ((dock
= scr
->dock
)!=NULL
) {
1974 for (i
=0; i
<dock
->max_icons
; i
++) {
1975 if (dock
->icon_array
[i
]
1976 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1982 if (*icon_pos
<0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
)!=NULL
) {
1983 for (i
=0; i
<dock
->max_icons
; i
++) {
1984 if (dock
->icon_array
[i
]
1985 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1998 wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
2004 dock
= findDock(scr
, event
, &icon_pos
);
2009 * Return True if the drop was on an application icon window.
2010 * In this case, let the ClientMessage handler redirect the
2011 * message to the app.
2013 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!=None
)
2016 if (dock
->icon_array
[icon_pos
]->dnd_command
!=NULL
) {
2017 scr
->flags
.dnd_data_convertion_status
= 0;
2019 btn
= dock
->icon_array
[icon_pos
];
2021 if (!btn
->forced_dock
) {
2022 btn
->relaunching
= btn
->running
;
2025 if (btn
->wm_instance
|| btn
->wm_class
) {
2026 WWindowAttributes attr
;
2027 memset(&attr
, 0, sizeof(WWindowAttributes
));
2028 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
2030 btn
->wm_class
, &attr
, NULL
, True
);
2032 if (!attr
.no_appicon
)
2038 btn
->drop_launch
= 1;
2039 scr
->last_dock
= dock
;
2040 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
2045 if (!btn
->relaunching
) {
2052 #endif /* OFFIX_DND */
2057 wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2064 wwin
= icon
->icon
->owner
;
2065 if (icon
->command
==NULL
) {
2067 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2069 icon
->command
= FlattenStringList(argv
, argc
);
2070 XFreeStringList(argv
);
2074 /* icon->forced_dock = 1;*/
2075 if (!icon
->attracted
|| dock
->type
!=WM_CLIP
|| dock
->keep_attracted
) {
2077 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2078 _("Type the command used to launch the application"),
2080 if (command
&& (command
[0]==0 ||
2081 (command
[0]=='-' && command
[1]==0))) {
2085 icon
->command
= command
;
2091 /* If the target is the dock, reject the icon. If
2092 * the target is the clip, make it an attracted icon
2094 if (dock
->type
==WM_CLIP
) {
2095 icon
->attracted
= 1;
2096 if (!icon
->icon
->shadowed
) {
2097 icon
->icon
->shadowed
= 1;
2098 icon
->icon
->force_paint
= 1;
2110 for (index
=1; index
<dock
->max_icons
; index
++)
2111 if (dock
->icon_array
[index
] == NULL
)
2113 /* if (index == dock->max_icons)
2116 assert(index
< dock
->max_icons
);
2118 dock
->icon_array
[index
] = icon
;
2122 icon
->omnipresent
= 0;
2124 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2125 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2130 icon
->launching
= 0;
2133 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2134 if (dock
->type
== WM_CLIP
) {
2135 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2136 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2138 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2139 icon
->icon
->core
->descriptor
.parent
= icon
;
2141 MoveInStackListUnder(dock
->icon_array
[index
-1]->icon
->core
,
2143 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2144 wAppIconPaint(icon
);
2146 if (wPreferences
.auto_arrange_icons
)
2147 wArrangeIcons(dock
->screen_ptr
, True
);
2150 if (icon
->command
&& !icon
->dnd_command
) {
2151 icon
->dnd_command
= wmalloc(strlen(icon
->command
)+8);
2152 sprintf(icon
->dnd_command
, "%s %%d", icon
->command
);
2161 reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2165 for(index
=1; index
<dock
->max_icons
; index
++) {
2166 if(dock
->icon_array
[index
] == icon
)
2169 assert(index
< dock
->max_icons
);
2174 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2175 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2180 moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2188 return True
; /* No move needed, we're already there */
2193 wwin
= icon
->icon
->owner
;
2196 * For the moment we can't do this if we move icons in Clip from one
2197 * workspace to other, because if we move two or more icons without
2198 * command, the dialog box will not be able to tell us to which of the
2199 * moved icons it applies. -Dan
2201 if ((dest
->type
==WM_DOCK
/*|| dest->keep_attracted*/) && icon
->command
==NULL
) {
2202 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2204 icon
->command
= FlattenStringList(argv
, argc
);
2205 XFreeStringList(argv
);
2210 /* icon->forced_dock = 1;*/
2211 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2212 _("Type the command used to launch the application"),
2214 if (command
&& (command
[0]==0 ||
2215 (command
[0]=='-' && command
[1]==0))) {
2219 icon
->command
= command
;
2230 if (dest
->type
== WM_DOCK
)
2231 wClipMakeIconOmnipresent(icon
, False
);
2233 for(index
=1; index
<src
->max_icons
; index
++) {
2234 if(src
->icon_array
[index
] == icon
)
2237 assert(index
< src
->max_icons
);
2239 src
->icon_array
[index
] = NULL
;
2242 for(index
=1; index
<dest
->max_icons
; index
++) {
2243 if(dest
->icon_array
[index
] == NULL
)
2246 /* if (index == dest->max_icons)
2249 assert(index
< dest
->max_icons
);
2251 dest
->icon_array
[index
] = icon
;
2254 /* deselect the icon */
2255 if (icon
->icon
->selected
)
2256 wIconSelect(icon
->icon
);
2258 if (dest
->type
== WM_DOCK
) {
2259 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2260 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2262 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2263 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2266 /* set it to be kept when moving to dock, or to a clip that keep the
2268 * Unless the icon does not have a command set
2270 if (icon
->command
&& (dest
->type
==WM_DOCK
|| dest
->keep_attracted
)) {
2271 icon
->attracted
= 0;
2272 if (icon
->icon
->shadowed
) {
2273 icon
->icon
->shadowed
= 0;
2274 icon
->icon
->force_paint
= 1;
2278 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2284 icon
->x_pos
= dest
->x_pos
+ x
*ICON_SIZE
;
2285 icon
->y_pos
= dest
->y_pos
+ y
*ICON_SIZE
;
2289 MoveInStackListUnder(dest
->icon_array
[index
-1]->icon
->core
,
2291 wAppIconPaint(icon
);
2298 wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2302 /* make the settings panel be closed */
2304 DestroyDockAppSettingsPanel(icon
->panel
);
2309 icon
->attracted
= 0;
2310 if (icon
->icon
->shadowed
) {
2311 icon
->icon
->shadowed
= 0;
2312 icon
->icon
->force_paint
= 1;
2315 /* This must be called before dock->icon_array[index] is set to NULL.
2316 * Don't move it. -Dan
2318 wClipMakeIconOmnipresent(icon
, False
);
2320 /* deselect the icon */
2321 if (icon
->icon
->selected
)
2322 wIconSelect(icon
->icon
);
2324 if (icon
->command
) {
2325 free(icon
->command
);
2326 icon
->command
= NULL
;
2329 if (icon
->dnd_command
) {
2330 free(icon
->dnd_command
);
2331 icon
->dnd_command
= NULL
;
2335 for (index
=1; index
<dock
->max_icons
; index
++)
2336 if (dock
->icon_array
[index
] == icon
)
2338 assert(index
< dock
->max_icons
);
2339 dock
->icon_array
[index
] = NULL
;
2345 /* if the dock is not attached to an application or
2346 * the the application did not set the approriate hints yet,
2347 * destroy the icon */
2348 #ifdef REDUCE_APPICONS
2349 if ((icon
->num_apps
== 0) && (!icon
->running
|| !wApplicationOf(icon
->main_window
)) )
2351 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2353 wAppIconDestroy(icon
);
2355 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2356 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2357 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2358 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2359 icon
->icon
->core
->descriptor
.parent
= icon
;
2361 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2363 wAppIconPaint(icon
);
2364 if (wPreferences
.auto_arrange_icons
) {
2365 wArrangeIcons(dock
->screen_ptr
, True
);
2368 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2374 * returns the closest Dock slot index for the passed
2377 * Returns False if icon can't be docked.
2379 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2383 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2384 int *ret_x
, int *ret_y
, int redocking
)
2386 WScreen
*scr
= dock
->screen_ptr
;
2389 int i
, offset
= ICON_SIZE
/2;
2390 WAppIcon
*aicon
= NULL
;
2391 WAppIcon
*nicon
= NULL
;
2392 int max_y_icons
, max_x_icons
;
2394 max_x_icons
= scr
->scr_width
/ICON_SIZE
;
2395 max_y_icons
= scr
->scr_height
/ICON_SIZE
-1;
2397 if (wPreferences
.flags
.noupdates
)
2403 /* if the dock is full */
2405 (dock
->icon_count
>= dock
->max_icons
)) {
2409 /* exact position */
2411 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2413 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2416 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2418 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2420 /* check if the icon is outside the screen boundaries */
2421 if (dx
+ ex_x
*ICON_SIZE
< -ICON_SIZE
+2 ||
2422 dx
+ ex_x
*ICON_SIZE
>= scr
->scr_width
-1 ||
2423 dy
+ ex_y
*ICON_SIZE
< -ICON_SIZE
+2 ||
2424 dy
+ ex_y
*ICON_SIZE
>= scr
->scr_height
-1)
2427 if (dock
->type
== WM_DOCK
) {
2428 if (icon
->dock
!= dock
&& ex_x
!= 0)
2432 for (i
=0; i
<dock
->max_icons
; i
++) {
2433 nicon
= dock
->icon_array
[i
];
2434 if (nicon
&& nicon
->yindex
== ex_y
) {
2441 int sig
, done
, closest
;
2443 /* Possible cases when redocking:
2445 * icon dragged out of range of any slot -> false
2446 * icon dragged to range of free slot
2447 * icon dragged to range of same slot
2448 * icon dragged to range of different icon
2450 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2453 if (ex_y
>=0 && ex_y
<=max_y_icons
&& (aicon
==icon
|| !aicon
)) {
2459 /* start looking at the upper slot or lower? */
2460 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2467 /* look for closest free slot */
2468 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2472 closest
= sig
*(i
/2) + ex_y
;
2473 /* check if this slot is used */
2475 for (j
= 0; j
<dock
->max_icons
; j
++) {
2476 if (dock
->icon_array
[j
]
2477 && dock
->icon_array
[j
]->yindex
==closest
) {
2478 /* slot is used by someone else */
2479 if (dock
->icon_array
[j
]!=icon
)
2487 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2488 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2490 (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+1))) {
2495 } else { /* !redocking */
2497 /* if slot is free and the icon is close enough, return it */
2498 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2508 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2509 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+1;
2512 for (k
=start
; k
<stop
; k
++) {
2513 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2516 for (i
=0; i
<tmp
->max_icons
; i
++) {
2517 nicon
= tmp
->icon_array
[i
];
2518 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2526 for (k
=start
; k
<stop
; k
++) {
2527 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2530 for (i
=0; i
<tmp
->max_icons
; i
++) {
2531 nicon
= tmp
->icon_array
[i
];
2532 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2533 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2534 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2543 if (neighbours
&& (aicon
==NULL
|| (redocking
&& aicon
== icon
))) {
2552 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2553 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2555 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2556 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2557 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2561 * returns true if it can find a free slot in the dock,
2562 * in which case it changes x_pos and y_pos accordingly.
2563 * Else returns false.
2566 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2568 WScreen
*scr
= dock
->screen_ptr
;
2570 WAppIconChain
*chain
;
2571 unsigned char *slot_map
;
2575 int i
, done
= False
;
2577 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2580 if (dock
->type
== WM_CLIP
&&
2581 dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2582 extra_count
= scr
->global_icon_count
;
2584 /* if the dock is full */
2585 if (dock
->icon_count
+extra_count
>= dock
->max_icons
) {
2589 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2590 if (scr
->dock
->on_right_side
)
2591 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2593 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2596 if (ex
< dock
->x_pos
)
2598 if (sx
> dock
->x_pos
+ICON_SIZE
)
2599 sx
= dock
->x_pos
+ICON_SIZE
;
2606 /* check if clip is in a corner */
2607 if (dock
->type
==WM_CLIP
) {
2608 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2610 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2612 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2614 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2621 /* If the clip is in the corner, use only slots that are in the border
2623 if (corner
!=C_NONE
) {
2627 hcount
= MIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2628 vcount
= MIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2629 hmap
= wmalloc(hcount
+1);
2630 memset(hmap
, 0, hcount
+1);
2631 vmap
= wmalloc(vcount
+1);
2632 memset(vmap
, 0, vcount
+1);
2634 /* mark used positions */
2637 for (i
=0; i
<dock
->max_icons
; i
++) {
2638 btn
= dock
->icon_array
[i
];
2642 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2643 vmap
[btn
->yindex
] = 1;
2644 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2645 hmap
[btn
->xindex
] = 1;
2647 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2649 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2650 vmap
[btn
->yindex
] = 1;
2651 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2652 hmap
[btn
->xindex
] = 1;
2656 for (i
=0; i
<dock
->max_icons
; i
++) {
2657 btn
= dock
->icon_array
[i
];
2661 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2662 vmap
[btn
->yindex
] = 1;
2663 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2664 hmap
[-btn
->xindex
] = 1;
2666 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2668 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2669 vmap
[btn
->yindex
] = 1;
2670 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2671 hmap
[-btn
->xindex
] = 1;
2675 for (i
=0; i
<dock
->max_icons
; i
++) {
2676 btn
= dock
->icon_array
[i
];
2680 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2681 vmap
[-btn
->yindex
] = 1;
2682 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2683 hmap
[btn
->xindex
] = 1;
2685 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2687 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2688 vmap
[-btn
->yindex
] = 1;
2689 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2690 hmap
[btn
->xindex
] = 1;
2695 for (i
=0; i
<dock
->max_icons
; i
++) {
2696 btn
= dock
->icon_array
[i
];
2700 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2701 vmap
[-btn
->yindex
] = 1;
2702 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2703 hmap
[-btn
->xindex
] = 1;
2705 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2707 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2708 vmap
[-btn
->yindex
] = 1;
2709 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2710 hmap
[-btn
->xindex
] = 1;
2715 /* search a vacant slot */
2716 for (i
=1; i
<MAX(vcount
, hcount
); i
++) {
2717 if (i
< vcount
&& vmap
[i
]==0) {
2723 } else if (i
< hcount
&& hmap
[i
]==0) {
2733 /* If found a slot, translate and return */
2735 if (corner
==C_NW
|| corner
==C_NE
) {
2740 if (corner
==C_NE
|| corner
==C_SE
) {
2747 /* else, try to find a slot somewhere else */
2750 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2751 * placed outside of screen */
2752 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2754 /* In the worst case (the clip is in the corner of the screen),
2755 * the amount of icons that fit in the clip is smaller.
2756 * Double the map to get a safe value.
2762 slot_map
= wmalloc(mwidth
*mwidth
);
2763 memset(slot_map
, 0, mwidth
*mwidth
);
2765 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2767 /* mark used slots in the map. If the slot falls outside the map
2768 * (for example, when all icons are placed in line), ignore them. */
2769 for (i
=0; i
<dock
->max_icons
; i
++) {
2770 btn
= dock
->icon_array
[i
];
2772 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2774 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2775 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2777 /* Find closest slot from the center that is free by scanning the
2778 * map from the center to outward in circular passes.
2779 * This will not result in a neat layout, but will be optimal
2780 * in the sense that there will not be holes left.
2783 for (i
= 1; i
<= r
&& !done
; i
++) {
2786 /* top and bottom parts of the ring */
2787 for (x
= -i
; x
<= i
&& !done
; x
++) {
2788 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2790 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2791 if (slot_map
[XY2OFS(x
,y
)]==0
2792 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2799 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2800 if (slot_map
[XY2OFS(x
,y
)]==0
2801 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2808 /* left and right parts of the ring */
2809 for (y
= -i
+1; y
<= i
-1; y
++) {
2810 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2812 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2813 if (slot_map
[XY2OFS(x
,y
)]==0
2814 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2821 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2822 if (slot_map
[XY2OFS(x
,y
)]==0
2823 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2838 moveDock(WDock
*dock
, int new_x
, int new_y
)
2843 dock
->x_pos
= new_x
;
2844 dock
->y_pos
= new_y
;
2845 for (i
=0; i
<dock
->max_icons
; i
++) {
2846 btn
= dock
->icon_array
[i
];
2848 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2849 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2850 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2857 swapDock(WDock
*dock
)
2859 WScreen
*scr
= dock
->screen_ptr
;
2864 if (dock
->on_right_side
) {
2865 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2867 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2870 for (i
=0; i
<dock
->max_icons
; i
++) {
2871 btn
= dock
->icon_array
[i
];
2874 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2878 wScreenUpdateUsableArea(scr
);
2883 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2885 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2891 cmdline
= ExpandOptions(scr
, command
);
2893 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2901 ParseCommand(cmdline
, &argv
, &argc
);
2911 if ((pid
=fork())==0) {
2915 SetupEnvironment(scr
);
2921 args
= malloc(sizeof(char*)*(argc
+1));
2924 for (i
=0; i
<argc
; i
++) {
2928 execvp(argv
[0], args
);
2937 state
= wmalloc(sizeof(WSavedState
));
2938 memset(state
, 0, sizeof(WSavedState
));
2940 state
->miniaturized
= -1;
2942 if (btn
->dock
==scr
->dock
|| btn
->omnipresent
)
2943 state
->workspace
= -1;
2945 state
->workspace
= scr
->current_workspace
;
2947 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
2949 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
2960 wDockHideIcons(WDock
*dock
)
2967 for (i
=1; i
<dock
->max_icons
; i
++) {
2968 if (dock
->icon_array
[i
])
2969 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2973 dockIconPaint(dock
->icon_array
[0]);
2978 wDockShowIcons(WDock
*dock
)
2986 btn
= dock
->icon_array
[0];
2987 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2989 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2990 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2992 for (i
=1; i
<dock
->max_icons
; i
++) {
2993 if (dock
->icon_array
[i
]) {
2994 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
3000 if (!dock
->collapsed
) {
3001 for (i
=1; i
<dock
->max_icons
; i
++) {
3002 if (dock
->icon_array
[i
]) {
3003 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3014 wDockLower(WDock
*dock
)
3018 for (i
=0; i
<dock
->max_icons
; i
++) {
3019 if (dock
->icon_array
[i
])
3020 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
3026 wDockRaise(WDock
*dock
)
3030 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
3031 if (dock
->icon_array
[i
])
3032 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
3038 wDockRaiseLower(WDock
*dock
)
3040 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
3041 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
3042 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
3050 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
3052 icon
->launching
= 0;
3053 icon
->relaunching
= 0;
3054 dockIconPaint(icon
);
3059 wDockFindIconFor(WDock
*dock
, Window window
)
3064 for (i
=0; i
<dock
->max_icons
; i
++) {
3065 icon
= dock
->icon_array
[i
];
3066 if (icon
&& icon
->main_window
== window
)
3074 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
3077 #ifdef REDUCE_APPICONS
3078 WAppIconAppList
*tapplist
;
3080 char *wm_class
, *wm_instance
;
3082 Bool firstPass
= True
;
3084 char *command
= NULL
;
3090 if (XGetCommand(dpy
, window
, &argv
, &argc
)) {
3091 if (argc
> 0 && argv
!= NULL
)
3092 command
= FlattenStringList(argv
,argc
);
3094 XFreeStringList(argv
);
3099 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
3100 (!wm_class
&& !wm_instance
))
3104 for (i
=0; i
<dock
->max_icons
; i
++) {
3105 icon
= dock
->icon_array
[i
];
3109 /* app is already attached to icon */
3110 if (icon
->main_window
== window
) {
3115 if ((icon
->wm_instance
|| icon
->wm_class
)
3117 || (dock
->screen_ptr
->flags
.startup
&& !icon
->running
))) {
3119 if (icon
->wm_instance
&& wm_instance
&&
3120 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
3123 if (icon
->wm_class
&& wm_class
&&
3124 strcmp(icon
->wm_class
, wm_class
)!=0) {
3127 if (firstPass
&& command
&& strcmp(icon
->command
, command
)!=0) {
3131 if (!icon
->relaunching
) {
3134 /* Possibly an application that was docked with dockit,
3135 * but the user did not update WMState to indicate that
3136 * it was docked by force */
3137 wapp
= wApplicationOf(window
);
3139 icon
->forced_dock
= 1;
3142 if (!icon
->forced_dock
)
3143 icon
->main_window
= window
;
3145 #ifdef REDUCE_APPICONS
3146 tapplist
= wmalloc(sizeof(WAppIconAppList
));
3147 memset(tapplist
, 0, sizeof(WAppIconAppList
));
3148 tapplist
->next
= icon
->applist
;
3150 icon
->applist
->prev
= tapplist
;
3151 icon
->applist
= tapplist
;
3152 tapplist
->wapp
= wApplicationOf(window
);
3157 wDockFinishLaunch(dock
, icon
);
3162 if (firstPass
&& !found
) {
3179 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3181 if (!wPreferences
.flags
.noclip
) {
3182 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3183 if (scr
->current_workspace
!= workspace
) {
3184 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3185 WAppIconChain
*chain
= scr
->global_icons
;
3188 moveIconBetweenDocks(chain
->aicon
->dock
,
3189 scr
->workspaces
[workspace
]->clip
,
3190 chain
->aicon
, chain
->aicon
->xindex
,
3191 chain
->aicon
->yindex
);
3192 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
3193 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3194 chain
= chain
->next
;
3197 wDockHideIcons(old_clip
);
3198 if (old_clip
->auto_raise_lower
) {
3199 if (old_clip
->auto_raise_magic
) {
3200 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3201 old_clip
->auto_raise_magic
= NULL
;
3203 wDockLower(old_clip
);
3205 if (old_clip
->auto_collapse
) {
3206 if (old_clip
->auto_expand_magic
) {
3207 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3208 old_clip
->auto_expand_magic
= NULL
;
3210 old_clip
->collapsed
= 1;
3212 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3214 if (scr
->flags
.clip_balloon_mapped
)
3215 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3222 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3227 for (i
=0; i
<dock
->max_icons
; i
++) {
3228 icon
= dock
->icon_array
[i
];
3232 if (icon
->launching
&& icon
->pid
== pid
) {
3233 if (!icon
->relaunching
) {
3235 icon
->main_window
= None
;
3237 wDockFinishLaunch(dock
, icon
);
3242 sprintf(msg
, _("Could not execute command \"%s\""),
3243 icon
->drop_launch
&& icon
->dnd_command
3244 ? icon
->dnd_command
: icon
->command
);
3246 sprintf(msg
, _("Could not execute command \"%s\""),
3249 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
3250 _("OK"), NULL
, NULL
);
3259 toggleLowered(WDock
*dock
)
3264 /* lower/raise Dock */
3265 if (!dock
->lowered
) {
3266 newlevel
= WMNormalLevel
;
3269 newlevel
= WMDockLevel
;
3273 for (i
=0; i
<dock
->max_icons
; i
++) {
3274 tmp
= dock
->icon_array
[i
];
3278 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3280 wLowerFrame(tmp
->icon
->core
);
3283 if (dock
->type
== WM_DOCK
)
3284 wScreenUpdateUsableArea(dock
->screen_ptr
);
3289 toggleCollapsed(WDock
*dock
)
3291 if (dock
->collapsed
) {
3292 dock
->collapsed
= 0;
3293 wDockShowIcons(dock
);
3296 dock
->collapsed
= 1;
3297 wDockHideIcons(dock
);
3303 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3305 WScreen
*scr
= dock
->screen_ptr
;
3306 WObjDescriptor
*desc
;
3308 WApplication
*wapp
= NULL
;
3312 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3314 if (dock
->type
== WM_DOCK
) {
3316 entry
= dock
->menu
->entries
[index
];
3317 entry
->flags
.indicator_on
= !dock
->lowered
;
3318 entry
->clientdata
= dock
;
3321 if (scr
->clip_options
)
3322 updateClipOptionsMenu(scr
->clip_options
, dock
);
3324 /* Rename Workspace */
3325 entry
= dock
->menu
->entries
[++index
];
3326 entry
->clientdata
= dock
;
3328 /* select/unselect icon */
3329 entry
= dock
->menu
->entries
[++index
];
3330 entry
->clientdata
= aicon
;
3331 if (aicon
->icon
->selected
)
3332 entry
->text
= _("Unselect Icon");
3334 entry
->text
= _("Select Icon");
3335 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3337 n_selected
= numberOfSelectedIcons(dock
);
3338 /* select/unselect all icons */
3339 entry
= dock
->menu
->entries
[++index
];
3340 entry
->clientdata
= aicon
;
3342 entry
->text
= _("Unselect All Icons");
3344 entry
->text
= _("Select All Icons");
3345 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3348 entry
= dock
->menu
->entries
[++index
];
3349 entry
->clientdata
= aicon
;
3351 entry
->text
= _("Keep Icons");
3353 entry
->text
= _("Keep Icon");
3354 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3356 /* this is the workspace submenu part */
3357 entry
= dock
->menu
->entries
[++index
];
3359 entry
->text
= _("Move Icons To");
3361 entry
->text
= _("Move Icon To");
3362 if (scr
->clip_submenu
)
3363 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3364 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3366 /* remove icon(s) */
3367 entry
= dock
->menu
->entries
[++index
];
3368 entry
->clientdata
= aicon
;
3370 entry
->text
= _("Remove Icons");
3372 entry
->text
= _("Remove Icon");
3373 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3375 /* attract icon(s) */
3376 entry
= dock
->menu
->entries
[++index
];
3377 entry
->clientdata
= aicon
;
3381 entry
= dock
->menu
->entries
[++index
];
3382 entry
->clientdata
= aicon
;
3383 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3386 entry
= dock
->menu
->entries
[++index
];
3387 entry
->clientdata
= aicon
;
3388 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3391 entry
= dock
->menu
->entries
[++index
];
3392 entry
->clientdata
= aicon
;
3393 if (aicon
->icon
->owner
) {
3394 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3395 if (wapp
&& wapp
->flags
.hidden
)
3396 entry
->text
= _("Unhide");
3398 entry
->text
= _("Hide");
3400 entry
->text
= _("Hide");
3402 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3405 entry
= dock
->menu
->entries
[++index
];
3406 entry
->clientdata
= aicon
;
3407 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
3408 && !wPreferences
.flags
.noupdates
);
3411 entry
= dock
->menu
->entries
[++index
];
3412 entry
->clientdata
= aicon
;
3413 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3415 if (!dock
->menu
->flags
.realized
)
3416 wMenuRealize(dock
->menu
);
3418 if (dock
->type
== WM_CLIP
) {
3419 x_pos
= event
->xbutton
.x_root
+2;
3421 x_pos
= dock
->on_right_side
?
3422 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 2 : 0;
3425 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3427 /* allow drag select */
3428 event
->xany
.send_event
= True
;
3429 desc
= &dock
->menu
->menu
->descriptor
;
3430 (*desc
->handle_mousedown
)(desc
, event
);
3435 openClipWorkspaceMenu(WScreen
*scr
, int x
, int y
)
3437 if (!scr
->clip_ws_menu
) {
3438 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3440 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
3441 wMenuMapAt(scr
->clip_ws_menu
, x
, y
, False
);
3445 /******************************************************************/
3447 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3449 WAppIcon
*btn
= desc
->parent
;
3450 WDock
*dock
= btn
->dock
;
3451 WApplication
*wapp
= NULL
;
3454 #ifdef REDUCE_APPICONS
3455 if ((btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) ||
3456 ((btn
->icon
->owner
== NULL
) && (btn
->applist
!= NULL
))) {
3457 if (btn
->icon
->owner
== NULL
)
3458 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
3461 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3463 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3467 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3469 /* go to the last workspace that the user worked on the app */
3470 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
3472 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3475 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3478 if (event
->xbutton
.state
& MOD_MASK
) {
3479 wHideOtherApplications(btn
->icon
->owner
);
3482 if (event
->xbutton
.button
==Button1
) {
3484 if (event
->xbutton
.state
& MOD_MASK
) {
3485 /* raise/lower dock */
3486 toggleLowered(dock
);
3487 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3488 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3489 toggleCollapsed(dock
);
3491 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3492 } else if (btn
->command
) {
3493 if (!btn
->launching
&&
3494 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3495 launchDockedApplication(btn
);
3497 } else if (btn
->xindex
== 0 && btn
->yindex
== 0
3498 && btn
->dock
->type
== WM_DOCK
) {
3500 wShowGNUstepPanel(dock
->screen_ptr
);
3508 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3510 WScreen
*scr
= dock
->screen_ptr
;
3511 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3514 int grabbed
= 0, swapped
= 0, done
;
3515 Pixmap ghost
= None
;
3516 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3519 puts("moving dock");
3521 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3522 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3523 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3524 wwarning("pointer grab failed for dock move");
3527 for (x
=0; x
<dock
->max_icons
; x
++) {
3528 if (dock
->icon_array
[x
]!=NULL
&&
3529 dock
->icon_array
[x
]->yindex
> y
)
3530 y
= dock
->icon_array
[x
]->yindex
;
3533 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3537 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3538 |ButtonMotionMask
|ExposureMask
, &ev
);
3546 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3547 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3548 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3549 |ButtonReleaseMask
|ButtonPressMask
,
3550 wCursor
[WCUR_MOVE
], CurrentTime
);
3555 if (dock
->type
== WM_CLIP
) {
3556 if (ev
.xmotion
.x_root
- ofs_x
< 0) {
3558 } else if (ev
.xmotion
.x_root
- ofs_x
+ ICON_SIZE
>
3560 x
= scr
->scr_width
- ICON_SIZE
;
3562 x
= ev
.xmotion
.x_root
- ofs_x
;
3564 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3566 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3568 y
= scr
->scr_height
- ICON_SIZE
;
3570 y
= ev
.xmotion
.y_root
- ofs_y
;
3572 moveDock(dock
, x
, y
);
3574 /* move vertically if pointer is inside the dock*/
3575 if ((dock
->on_right_side
&&
3576 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3577 || (!dock
->on_right_side
&&
3578 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3580 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3582 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3584 y
= scr
->scr_height
- ICON_SIZE
;
3586 y
= ev
.xmotion
.y_root
- ofs_y
;
3588 moveDock(dock
, dock
->x_pos
, y
);
3590 /* move horizontally to change sides */
3591 x
= ev
.xmotion
.x_root
- ofs_x
;
3592 if (!dock
->on_right_side
) {
3596 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3597 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3598 -DOCK_EXTRA_SPACE
-1, dock
->y_pos
);
3599 if (superfluous
&& ghost
==None
) {
3600 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3601 scr
->scr_width
-ICON_SIZE
3602 -DOCK_EXTRA_SPACE
-1,
3604 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3606 XClearWindow(dpy
, scr
->dock_shadow
);
3608 XMapRaised(dpy
, scr
->dock_shadow
);
3611 if (superfluous
&& ghost
!=None
) {
3612 XFreePixmap(dpy
, ghost
);
3615 XUnmapWindow(dpy
, scr
->dock_shadow
);
3620 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3621 XMoveWindow(dpy
, scr
->dock_shadow
,
3622 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3623 if (superfluous
&& ghost
==None
) {
3624 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3625 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3626 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3628 XClearWindow(dpy
, scr
->dock_shadow
);
3630 XMapRaised(dpy
, scr
->dock_shadow
);
3633 XUnmapWindow(dpy
, scr
->dock_shadow
);
3635 if (superfluous
&& ghost
!=None
) {
3636 XFreePixmap(dpy
, ghost
);
3648 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3650 XUngrabPointer(dpy
, CurrentTime
);
3651 XUnmapWindow(dpy
, scr
->dock_shadow
);
3652 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3653 if (dock
->type
== WM_DOCK
) {
3656 dock
->on_right_side
= 1;
3658 dock
->on_right_side
= 0;
3660 wArrangeIcons(scr
, False
);
3669 XFreePixmap(dpy
, ghost
);
3670 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3673 puts("End dock move");
3680 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3682 WScreen
*scr
= dock
->screen_ptr
;
3684 WIcon
*icon
= aicon
->icon
;
3685 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3686 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3688 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3689 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3690 int shad_x
= x
, shad_y
= y
;
3691 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3693 Pixmap ghost
= None
;
3695 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3696 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3699 if (wPreferences
.flags
.noupdates
)
3702 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3703 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3704 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3706 wwarning("pointer grab failed for icon move");
3710 if (!(event
->xbutton
.state
& MOD_MASK
))
3711 wRaiseFrame(icon
->core
);
3713 if (!wPreferences
.flags
.noclip
)
3714 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3716 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3718 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3721 wins
[0] = icon
->core
->window
;
3722 wins
[1] = scr
->dock_shadow
;
3723 XRestackWindows(dpy
, wins
, 2);
3724 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3725 ICON_SIZE
, ICON_SIZE
);
3727 if (icon
->pixmap
!=None
)
3728 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3730 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3732 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3733 XClearWindow(dpy
, scr
->dock_shadow
);
3735 XMapWindow(dpy
, scr
->dock_shadow
);
3741 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3742 |ButtonMotionMask
|ExposureMask
, &ev
);
3750 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3751 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3752 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3753 |ButtonReleaseMask
|ButtonPressMask
,
3754 wCursor
[WCUR_MOVE
], CurrentTime
);
3763 for (i
=0; i
<scr
->workspace_count
; i
++) {
3764 if (i
== scr
->current_workspace
)
3766 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3770 x
= ev
.xmotion
.x_root
- ofs_x
;
3771 y
= ev
.xmotion
.y_root
- ofs_y
;
3772 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3775 if (last_dock
!= dock
&& collapsed
) {
3776 last_dock
->collapsed
= 1;
3777 wDockHideIcons(last_dock
);
3780 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3781 dock
->collapsed
= 0;
3782 wDockShowIcons(dock
);
3784 if (dock
->auto_raise_lower
)
3788 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3791 if (last_dock
!= dock2
&& collapsed
) {
3792 last_dock
->collapsed
= 1;
3793 wDockHideIcons(last_dock
);
3796 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3797 dock2
->collapsed
= 0;
3798 wDockShowIcons(dock2
);
3800 if (dock2
->auto_raise_lower
)
3805 if (aicon
->launching
3806 || (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3807 || (!aicon
->running
&& tmp
)) {
3808 shad_x
= last_dock
->x_pos
+ ix
*wPreferences
.icon_size
;
3809 shad_y
= last_dock
->y_pos
+ iy
*wPreferences
.icon_size
;
3811 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3814 XMapWindow(dpy
, scr
->dock_shadow
);
3819 XUnmapWindow(dpy
, scr
->dock_shadow
);
3823 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3830 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3832 XUngrabPointer(dpy
, CurrentTime
);
3834 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3835 XUnmapWindow(dpy
, scr
->dock_shadow
);
3837 reattachIcon(dock
, aicon
, ix
, iy
);
3838 if (clip
&& dock
!=clip
&& clip
->auto_raise_lower
)
3841 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3843 /* Slide it back if dock rejected it */
3844 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3846 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3848 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3856 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3857 /* We need to deselect it, even if is deselected in
3858 * wDockDetach(), because else DoKaboom() will fail.
3860 if (aicon
->icon
->selected
)
3861 wIconSelect(aicon
->icon
);
3862 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3865 if (clip
&& clip
->auto_raise_lower
)
3867 wDockDetach(dock
, aicon
);
3870 last_dock
->collapsed
= 1;
3871 wDockHideIcons(last_dock
);
3876 XFreePixmap(dpy
, ghost
);
3877 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3881 for (i
=0; i
<scr
->workspace_count
; i
++) {
3882 if (i
== scr
->current_workspace
)
3884 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3889 puts("End icon move");
3898 getClipButton(int px
, int py
)
3900 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
3902 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3905 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
3906 return CLIP_FORWARD
;
3907 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
3915 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3918 int done
, direction
, new_ws
;
3920 WDock
*clip
= scr
->clip_icon
->dock
;
3922 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3924 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3925 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3927 wClipIconPaint(scr
->clip_icon
);
3930 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
3931 |ButtonPressMask
, &ev
);
3938 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3939 if (new_dir
!= direction
) {
3940 direction
= new_dir
;
3941 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3942 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3943 wClipIconPaint(scr
->clip_icon
);
3951 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3956 clip
->lclip_button_pushed
= 0;
3957 clip
->rclip_button_pushed
= 0;
3959 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3961 if (direction
== CLIP_FORWARD
) {
3962 if (scr
->current_workspace
< scr
->workspace_count
-1)
3963 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3964 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
3965 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3966 else if (wPreferences
.ws_cycle
)
3967 wWorkspaceChange(scr
, 0);
3969 else if (direction
== CLIP_REWIND
) {
3970 if (scr
->current_workspace
> 0)
3971 wWorkspaceChange(scr
, scr
->current_workspace
-1);
3972 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
3973 wWorkspaceChange(scr
, scr
->workspace_count
-1);
3976 wClipIconPaint(scr
->clip_icon
);
3981 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3983 WAppIcon
*aicon
= desc
->parent
;
3984 WDock
*dock
= aicon
->dock
;
3985 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3987 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3990 scr
->last_dock
= dock
;
3992 if (dock
->menu
->flags
.mapped
)
3993 wMenuUnmap(dock
->menu
);
3995 if (IsDoubleClick(scr
, event
)) {
3996 /* double-click was not in the main clip icon */
3997 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
3998 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
3999 iconDblClick(desc
, event
);
4004 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
4005 XUnmapWindow(dpy
, scr
->clip_balloon
);
4006 scr
->flags
.clip_balloon_mapped
= 0;
4010 puts("handling dock");
4012 if (event
->xbutton
.button
== Button1
) {
4013 if (event
->xbutton
.state
& MOD_MASK
)
4018 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
4019 dock
->type
!=WM_DOCK
) {
4020 wIconSelect(aicon
->icon
);
4024 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
4025 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
4026 && dock
->type
==WM_CLIP
)
4027 handleClipChangeWorkspace(scr
, event
);
4029 handleDockMove(dock
, aicon
, event
);
4031 handleIconMove(dock
, aicon
, event
);
4033 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4034 aicon
==scr
->clip_icon
) {
4035 openClipWorkspaceMenu(scr
, event
->xbutton
.x_root
+2,
4036 event
->xbutton
.y_root
+2);
4037 if (scr
->clip_ws_menu
) {
4039 menu
= scr
->clip_ws_menu
;
4040 desc
= &menu
->menu
->descriptor
;
4042 event
->xany
.send_event
= True
;
4043 (*desc
->handle_mousedown
)(desc
, event
);
4046 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4047 (event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
) {
4048 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
4050 } else if (event
->xbutton
.button
== Button3
) {
4051 openDockMenu(dock
, aicon
, event
);
4057 showClipBalloon(WDock
*dock
, int workspace
)
4061 WScreen
*scr
= dock
->screen_ptr
;
4065 scr
->flags
.clip_balloon_mapped
= 1;
4066 XMapWindow(dpy
, scr
->clip_balloon
);
4068 text
= scr
->workspaces
[workspace
]->name
;
4070 w
= WMWidthOfString(scr
->clip_title_font
, text
, strlen(text
));
4072 h
= WMFontHeight(scr
->clip_title_font
);
4073 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
4075 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
4076 y
= dock
->y_pos
+ ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
4078 if (x
+w
> scr
->scr_width
) {
4079 x
= scr
->scr_width
- w
;
4080 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
4081 y
= dock
->y_pos
- h
- 1;
4083 y
= dock
->y_pos
+ ICON_SIZE
;
4084 XRaiseWindow(dpy
, scr
->clip_balloon
);
4086 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
4087 stack
[1] = scr
->clip_balloon
;
4088 XRestackWindows(dpy
, stack
, 2);
4090 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
4091 XSetForeground(dpy
, scr
->clip_title_gc
,
4092 scr
->clip_title_pixel
[CLIP_NORMAL
]);
4093 XClearWindow(dpy
, scr
->clip_balloon
);
4094 WMDrawString(scr
->wmscreen
, scr
->clip_balloon
, scr
->clip_title_gc
,
4095 scr
->clip_title_font
, 0, 0, text
, strlen(text
));
4100 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
4102 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4106 assert(event
->type
==EnterNotify
);
4108 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4111 scr
= btn
->icon
->core
->screen_ptr
;
4112 if (!btn
->omnipresent
)
4115 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
4117 if (!dock
|| dock
->type
!=WM_CLIP
)
4120 /* The auto raise/lower code */
4121 if (dock
->auto_lower_magic
) {
4122 WMDeleteTimerHandler(dock
->auto_lower_magic
);
4123 dock
->auto_lower_magic
= NULL
;
4125 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
4126 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
,
4131 /* The auto expand/collapse code */
4132 if (dock
->auto_collapse_magic
) {
4133 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
4134 dock
->auto_collapse_magic
= NULL
;
4136 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
4137 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
,
4142 if (btn
->xindex
== 0 && btn
->yindex
== 0)
4143 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4145 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4146 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
4147 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
4154 clipLeave(WDock
*dock
)
4157 WObjDescriptor
*desc
= NULL
;
4159 if (!dock
|| dock
->type
!=WM_CLIP
)
4162 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
)!=False
) {
4163 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
4164 (XPointer
*)&desc
)!=XCNOENT
4165 && desc
&& desc
->parent_type
==WCLASS_DOCK_ICON
4166 && ((WAppIcon
*)desc
->parent
)->dock
4167 && ((WAppIcon
*)desc
->parent
)->dock
->type
==WM_CLIP
) {
4168 /* We didn't left the Clip yet */
4169 XPutBackEvent(dpy
, &event
);
4173 XPutBackEvent(dpy
, &event
);
4175 /* We entered a withdrawn window, so we're still in Clip */
4179 if (dock
->auto_raise_magic
) {
4180 WMDeleteTimerHandler(dock
->auto_raise_magic
);
4181 dock
->auto_raise_magic
= NULL
;
4183 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
4184 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
,
4189 if (dock
->auto_expand_magic
) {
4190 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4191 dock
->auto_expand_magic
= NULL
;
4193 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
4194 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
4202 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4204 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4206 assert(event
->type
==LeaveNotify
);
4208 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4211 clipLeave(btn
->dock
);
4216 clipAutoCollapse(void *cdata
)
4218 WDock
*dock
= (WDock
*)cdata
;
4220 if (dock
->type
!=WM_CLIP
)
4223 if (dock
->auto_collapse
) {
4224 dock
->collapsed
= 1;
4225 wDockHideIcons(dock
);
4227 dock
->auto_collapse_magic
= NULL
;
4232 clipAutoExpand(void *cdata
)
4234 WDock
*dock
= (WDock
*)cdata
;
4236 if (dock
->type
!=WM_CLIP
)
4239 if (dock
->auto_collapse
) {
4240 dock
->collapsed
= 0;
4241 wDockShowIcons(dock
);
4243 dock
->auto_expand_magic
= NULL
;
4248 clipAutoLower(void *cdata
)
4250 WDock
*dock
= (WDock
*)cdata
;
4252 if (dock
->type
!=WM_CLIP
)
4255 if (dock
->auto_raise_lower
)
4258 dock
->auto_lower_magic
= NULL
;
4263 clipAutoRaise(void *cdata
)
4265 WDock
*dock
= (WDock
*)cdata
;
4267 if (dock
->type
!=WM_CLIP
)
4270 if (dock
->auto_raise_lower
)
4273 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4274 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4277 dock
->auto_raise_magic
= NULL
;
4282 iconCanBeOmnipresent(WAppIcon
*aicon
)
4284 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4289 for (i
=0; i
<scr
->workspace_count
; i
++) {
4290 clip
= scr
->workspaces
[i
]->clip
;
4292 if (clip
== aicon
->dock
)
4295 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4296 return False
; /* Clip is full in some workspace */
4298 for (j
=0; j
<clip
->max_icons
; j
++) {
4299 btn
= clip
->icon_array
[j
];
4300 if(btn
&& btn
->xindex
==aicon
->xindex
&& btn
->yindex
==aicon
->yindex
)
4310 wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
4312 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4313 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4314 int status
= WO_SUCCESS
;
4316 if (aicon
->dock
== scr
->dock
|| aicon
== scr
->clip_icon
)
4317 return WO_NOT_APPLICABLE
;
4319 if (aicon
->omnipresent
== omnipresent
)
4323 if (iconCanBeOmnipresent(aicon
)) {
4324 aicon
->omnipresent
= 1;
4325 new_entry
= wmalloc(sizeof(WAppIconChain
));
4326 new_entry
->aicon
= aicon
;
4327 new_entry
->next
= NULL
;
4328 if (!scr
->global_icons
) {
4329 scr
->global_icons
= new_entry
;
4331 tmp
= scr
->global_icons
;
4335 tmp
->next
= new_entry
;
4337 scr
->global_icon_count
++;
4339 aicon
->omnipresent
= 0;
4343 aicon
->omnipresent
= 0;
4344 if (aicon
== scr
->global_icons
->aicon
) {
4345 tmp
= scr
->global_icons
->next
;
4346 free(scr
->global_icons
);
4347 scr
->global_icons
= tmp
;
4348 scr
->global_icon_count
--;
4350 tmp
= scr
->global_icons
;
4352 if (tmp
->next
->aicon
== aicon
) {
4353 tmp1
= tmp
->next
->next
;
4356 scr
->global_icon_count
--;