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 getSelected(WDock
*dock
)
299 LinkedList
*ret
=NULL
;
303 for (i
=1; i
<dock
->max_icons
; i
++) {
304 btn
= dock
->icon_array
[i
];
305 if (btn
&& btn
->icon
->selected
) {
306 ret
= list_cons(btn
, ret
);
315 paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
317 Window win
= clipIcon
->icon
->core
->window
;
318 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
320 int pt
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
321 int tp
= ICON_SIZE
- pt
;
322 int as
= pt
- 15; /* 15 = 5+5+5 */
323 GC gc
= scr
->clip_title_gc
;
324 #ifdef GRADIENT_CLIP_ARROW
325 Bool collapsed
= clipIcon
->dock
->collapsed
;
331 p
[1].x
= ICON_SIZE
-2;
333 p
[2].x
= ICON_SIZE
-2;
335 } else if (lpushed
) {
339 p
[1].y
= ICON_SIZE
-2;
341 p
[2].y
= ICON_SIZE
-2;
343 if (lpushed
|| rpushed
) {
344 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
345 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
346 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
348 #ifdef GRADIENT_CLIP_ARROW
350 XSetFillStyle(dpy
, scr
->copy_gc
, FillTiled
);
351 XSetTile(dpy
, scr
->copy_gc
, scr
->clip_arrow_gradient
);
352 XSetClipMask(dpy
, scr
->copy_gc
, None
);
355 #endif /* GRADIENT_CLIP_ARROW */
357 /* top right arrow */
358 p
[0].x
= p
[3].x
= ICON_SIZE
-5-as
;
360 p
[1].x
= ICON_SIZE
-6;
362 p
[2].x
= ICON_SIZE
-6;
365 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
366 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
368 #ifdef GRADIENT_CLIP_ARROW
370 XSetTSOrigin(dpy
, gc
, ICON_SIZE
-6-as
, 5);
372 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
373 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
376 /* bottom left arrow */
378 p
[0].y
= p
[3].y
= ICON_SIZE
-5-as
;
380 p
[1].y
= ICON_SIZE
-6;
382 p
[2].y
= ICON_SIZE
-6;
384 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
385 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
387 #ifdef GRADIENT_CLIP_ARROW
389 XSetTSOrigin(dpy
, gc
, 5, ICON_SIZE
-6-as
);
391 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
392 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
394 #ifdef GRADIENT_CLIP_ARROW
396 XSetFillStyle(dpy
, scr
->copy_gc
, FillSolid
);
402 wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
404 RImage
*tile
= RCloneImage(normalTile
);
411 pt
= CLIP_BUTTON_SIZE
*wPreferences
.icon_size
/64;
412 tp
= wPreferences
.icon_size
-1 - pt
;
416 black
.red
= black
.green
= black
.blue
= 0;
419 dark
.red
= dark
.green
= dark
.blue
= 60;
422 light
.red
= light
.green
= light
.blue
= 80;
426 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
-2,
428 RDrawLine(tile
, tp
-1, 0, wPreferences
.icon_size
-1, pt
+1, &black
);
429 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
-3,
433 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4,
434 ICON_SIZE
- 5, 4, &dark
);
435 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5,
436 ICON_SIZE
- 5, 6 + as
, &dark
);
437 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
,
441 ROperateLine(tile
, RAddOperation
, 2, tp
+2, pt
-2,
442 wPreferences
.icon_size
-3, &dark
);
443 RDrawLine(tile
, 0, tp
-1, pt
+1, wPreferences
.icon_size
-1, &black
);
444 ROperateLine(tile
, RSubtractOperation
, 0, tp
-2, pt
+1,
445 wPreferences
.icon_size
-2, &light
);
448 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4,
449 ICON_SIZE
- 5, &dark
);
450 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
,
451 6 + as
, ICON_SIZE
- 5, &dark
);
452 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5,
460 removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
462 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
465 LinkedList
*selectedIcons
;
468 assert(clickedIcon
!=NULL
);
470 dock
= clickedIcon
->dock
;
472 selectedIcons
= getSelected(dock
);
475 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
476 _("All selected icons will be removed!"),
477 _("OK"), _("Cancel"), NULL
)!=WAPRDefault
) {
481 if (clickedIcon
->xindex
==0 && clickedIcon
->yindex
==0)
483 selectedIcons
= list_cons(clickedIcon
, NULL
);
486 while (selectedIcons
) {
487 aicon
= selectedIcons
->head
;
488 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
489 wDockDetach(dock
, aicon
);
491 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
492 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
493 aicon
->x_pos
, aicon
->y_pos
);
494 if (!dock
->mapped
|| dock
->collapsed
)
495 XMapWindow(dpy
, aicon
->icon
->core
->window
);
497 list_remove_head(&selectedIcons
);
500 if (wPreferences
.auto_arrange_icons
)
501 wArrangeIcons(dock
->screen_ptr
, True
);
506 keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
508 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
511 LinkedList
*selectedIcons
;
513 assert(clickedIcon
!=NULL
);
514 dock
= clickedIcon
->dock
;
516 selectedIcons
= getSelected(dock
);
518 if (!selectedIcons
&& clickedIcon
!=dock
->screen_ptr
->clip_icon
) {
519 char *command
= NULL
;
521 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
522 clickedIcon
->editing
= 1;
523 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
524 _("Type the command used to launch the application"),
526 if (command
&& (command
[0]==0 ||
527 (command
[0]=='-' && command
[1]==0))) {
531 clickedIcon
->command
= command
;
532 clickedIcon
->editing
= 0;
534 clickedIcon
->editing
= 0;
541 selectedIcons
= list_cons(clickedIcon
, NULL
);
544 while (selectedIcons
) {
545 aicon
= selectedIcons
->head
;
546 if (aicon
->icon
->selected
)
547 wIconSelect(aicon
->icon
);
548 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
549 aicon
->attracted
= 0;
550 if (aicon
->icon
->shadowed
) {
551 aicon
->icon
->shadowed
= 0;
552 aicon
->icon
->force_paint
= 1;
553 wAppIconPaint(aicon
);
556 list_remove_head(&selectedIcons
);
564 toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
566 WDock
*dock
= (WDock
*)entry
->clientdata
;
568 assert(entry
->clientdata
!=NULL
);
570 dock
->attract_icons
= !dock
->attract_icons
;
571 /*if (!dock->attract_icons)
572 dock->keep_attracted = 0;*/
574 entry
->flags
.indicator_on
= dock
->attract_icons
;
581 toggleKeepCallback(WMenu
*menu
, WMenuEntry
*entry
)
583 WDock
*dock
= (WDock
*)entry
->clientdata
;
587 assert(entry
->clientdata
!=NULL
);
589 dock
->keep_attracted
= !dock
->keep_attracted
;
591 if (dock
->keep_attracted
) {
592 for (i
=0; i
< dock
->max_icons
; i
++) {
593 btn
= dock
->icon_array
[i
];
594 if (btn
&& btn
->attracted
&& btn
->command
) {
596 if (btn
->icon
->shadowed
) {
597 btn
->icon
->shadowed
= 0;
598 btn
->icon
->force_paint
= 1;
605 entry
->flags
.indicator_on
= dock
->keep_attracted
;
612 selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
614 WAppIcon
*icon
= (WAppIcon
*)entry
->clientdata
;
618 wIconSelect(icon
->icon
);
625 colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
627 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
630 int x
, y
, x_pos
, y_pos
;
632 assert(entry
->clientdata
!=NULL
);
633 clip
= clickedIcon
->dock
;
635 aicon
= clip
->screen_ptr
->app_icon_list
;
638 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
639 x_pos
= clip
->x_pos
+ x
*ICON_SIZE
;
640 y_pos
= clip
->y_pos
+ y
*ICON_SIZE
;
641 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
643 if (wPreferences
.no_animations
) {
644 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
646 SlideWindow(aicon
->icon
->core
->window
,
647 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
650 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
651 #endif /* ANIMATIONS */
653 aicon
->attracted
= 1;
654 if (!clip
->keep_attracted
&& !aicon
->icon
->shadowed
) {
655 aicon
->icon
->shadowed
= 1;
656 aicon
->icon
->force_paint
= 1;
657 /* We don't do an wAppIconPaint() here because it's in
658 * wDockAttachIcon(). -Dan
661 wDockAttachIcon(clip
, aicon
, x
, y
);
662 if (clip
->collapsed
|| !clip
->mapped
)
663 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
671 selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
673 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
675 LinkedList
*selectedIcons
;
679 assert(clickedIcon
!=NULL
);
680 dock
= clickedIcon
->dock
;
682 selectedIcons
= getSelected(dock
);
684 if (!selectedIcons
) {
685 for (i
=1; i
<dock
->max_icons
; i
++) {
686 btn
= dock
->icon_array
[i
];
687 if (btn
&& !btn
->icon
->selected
) {
688 wIconSelect(btn
->icon
);
692 while(selectedIcons
) {
693 btn
= selectedIcons
->head
;
694 wIconSelect(btn
->icon
);
695 list_remove_head(&selectedIcons
);
704 toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
706 assert(entry
->clientdata
!=NULL
);
708 toggleCollapsed(entry
->clientdata
);
710 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->collapsed
;
717 toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
720 assert(entry
->clientdata
!=NULL
);
722 dock
= (WDock
*) entry
->clientdata
;
724 dock
->auto_collapse
= !dock
->auto_collapse
;
726 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_collapse
;
733 toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
736 assert(entry
->clientdata
!=NULL
);
738 dock
= (WDock
*) entry
->clientdata
;
740 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
742 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_raise_lower
;
749 launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
751 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
753 launchDockedApplication(btn
);
758 settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
760 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
764 ShowDockAppSettingsPanel(btn
);
769 hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
772 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
774 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
776 if (wapp
->flags
.hidden
) {
777 wWorkspaceChange(btn
->icon
->core
->screen_ptr
,wapp
->last_workspace
);
778 wUnhideApplication(wapp
, False
, False
);
780 wHideApplication(wapp
);
786 unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
789 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
791 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
793 wUnhideApplication(wapp
, False
, True
);
798 mainIconCreate(WScreen
*scr
, int type
)
803 if (type
== WM_CLIP
) {
805 return scr
->clip_icon
;
806 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
807 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
808 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
809 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
810 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE;*/
813 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
814 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
820 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
821 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
822 btn
->icon
->core
->descriptor
.parent
= btn
;
823 /*ChangeStackingLevel(btn->icon->core, WMDockLevel);*/
824 XMapWindow(dpy
, btn
->icon
->core
->window
);
829 scr
->clip_icon
= btn
;
836 switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
838 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
839 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
841 LinkedList
*selectedIcons
;
844 if (entry
->order
== scr
->current_workspace
)
847 dest
= scr
->workspaces
[entry
->order
]->clip
;
849 selectedIcons
= getSelected(src
);
852 while(selectedIcons
) {
853 btn
= selectedIcons
->head
;
854 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
855 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
856 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
858 list_remove_head(&selectedIcons
);
860 } else if (icon
!= scr
->clip_icon
) {
861 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
862 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
863 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
871 launchDockedApplication(WAppIcon
*btn
)
873 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
875 if (!btn
->launching
&& btn
->command
!=NULL
) {
876 if (!btn
->forced_dock
) {
877 btn
->relaunching
= btn
->running
;
880 if (btn
->wm_instance
|| btn
->wm_class
) {
881 WWindowAttributes attr
;
882 memset(&attr
, 0, sizeof(WWindowAttributes
));
883 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
,
886 if (!attr
.no_appicon
&& !btn
->buggy_app
)
891 btn
->drop_launch
= 0;
892 scr
->last_dock
= btn
->dock
;
893 btn
->pid
= execCommand(btn
, btn
->command
, NULL
);
895 if (btn
->buggy_app
) {
896 /* give feedback that the app was launched */
900 WMAddTimerHandler(200, (WMCallback
*)dockIconPaint
, btn
);
905 wwarning(_("could not launch application %s\n"), btn
->command
);
907 if (!btn
->relaunching
)
916 updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
918 WScreen
*scr
= menu
->frame
->screen_ptr
;
919 char title
[MAX_WORKSPACENAME_WIDTH
+1];
925 for (i
=0; i
<scr
->workspace_count
; i
++) {
926 if (i
< menu
->entry_no
) {
927 if (strcmp(menu
->entries
[i
]->text
,scr
->workspaces
[i
]->name
)!=0) {
928 free(menu
->entries
[i
]->text
);
929 strcpy(title
, scr
->workspaces
[i
]->name
);
930 menu
->entries
[i
]->text
= wstrdup(title
);
931 menu
->flags
.realized
= 0;
933 menu
->entries
[i
]->clientdata
= (void*)icon
;
935 strcpy(title
, scr
->workspaces
[i
]->name
);
937 wMenuAddCallback(menu
, title
, switchWSCommand
, (void*)icon
);
939 menu
->flags
.realized
= 0;
941 if (i
== scr
->current_workspace
) {
942 wMenuSetEnabled(menu
, i
, False
);
944 wMenuSetEnabled(menu
, i
, True
);
948 if (!menu
->flags
.realized
)
954 makeWorkspaceMenu(WScreen
*scr
)
958 menu
= wMenuCreate(scr
, NULL
, False
);
960 wwarning(_("could not create workspace submenu for Clip menu"));
962 wMenuAddCallback(menu
, "", switchWSCommand
, (void*)scr
->clip_icon
);
964 menu
->flags
.realized
= 0;
972 updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
981 entry
= menu
->entries
[index
];
982 entry
->flags
.indicator_on
= !dock
->lowered
;
983 entry
->clientdata
= dock
;
986 entry
= menu
->entries
[++index
];
987 entry
->flags
.indicator_on
= dock
->collapsed
;
988 entry
->clientdata
= dock
;
991 entry
= menu
->entries
[++index
];
992 entry
->flags
.indicator_on
= dock
->auto_collapse
;
993 entry
->clientdata
= dock
;
995 /* auto-raise/lower */
996 entry
= menu
->entries
[++index
];
997 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
998 entry
->clientdata
= dock
;
1001 entry
= menu
->entries
[++index
];
1002 entry
->flags
.indicator_on
= dock
->attract_icons
;
1003 entry
->clientdata
= dock
;
1005 /* keep attracted icons */
1006 entry
= menu
->entries
[++index
];
1007 entry
->flags
.indicator_on
= dock
->keep_attracted
;
1008 entry
->clientdata
= dock
;
1010 menu
->flags
.realized
= 0;
1016 makeClipOptionsMenu(WScreen
*scr
)
1021 menu
= wMenuCreate(scr
, NULL
, False
);
1023 wwarning(_("could not create options submenu for Clip menu"));
1027 entry
= wMenuAddCallback(menu
, _("Keep on Top"),
1028 toggleLoweredCallback
, NULL
);
1029 entry
->flags
.indicator
= 1;
1030 entry
->flags
.indicator_on
= 1;
1031 entry
->flags
.indicator_type
= MI_CHECK
;
1033 entry
= wMenuAddCallback(menu
, _("Collapsed"),
1034 toggleCollapsedCallback
, NULL
);
1035 entry
->flags
.indicator
= 1;
1036 entry
->flags
.indicator_on
= 1;
1037 entry
->flags
.indicator_type
= MI_CHECK
;
1039 entry
= wMenuAddCallback(menu
, _("AutoCollapse"),
1040 toggleAutoCollapseCallback
, NULL
);
1041 entry
->flags
.indicator
= 1;
1042 entry
->flags
.indicator_on
= 1;
1043 entry
->flags
.indicator_type
= MI_CHECK
;
1045 entry
= wMenuAddCallback(menu
, _("AutoRaiseLower"),
1046 toggleAutoRaiseLowerCallback
, NULL
);
1047 entry
->flags
.indicator
= 1;
1048 entry
->flags
.indicator_on
= 1;
1049 entry
->flags
.indicator_type
= MI_CHECK
;
1051 entry
= wMenuAddCallback(menu
, _("AutoAttract Icons"),
1052 toggleAutoAttractCallback
, NULL
);
1053 entry
->flags
.indicator
= 1;
1054 entry
->flags
.indicator_on
= 1;
1055 entry
->flags
.indicator_type
= MI_CHECK
;
1057 entry
= wMenuAddCallback(menu
, _("Keep Attracted Icons"),
1058 toggleKeepCallback
, NULL
);
1059 entry
->flags
.indicator
= 1;
1060 entry
->flags
.indicator_on
= 1;
1061 entry
->flags
.indicator_type
= MI_CHECK
;
1063 menu
->flags
.realized
= 0;
1071 dockMenuCreate(WScreen
*scr
, int type
)
1076 if (type
== WM_CLIP
&& scr
->clip_menu
)
1077 return scr
->clip_menu
;
1079 menu
= wMenuCreate(scr
, NULL
, False
);
1080 if (type
!= WM_CLIP
) {
1081 entry
= wMenuAddCallback(menu
, _("Keep on top"),
1082 toggleLoweredCallback
, NULL
);
1083 entry
->flags
.indicator
= 1;
1084 entry
->flags
.indicator_on
= 1;
1085 entry
->flags
.indicator_type
= MI_CHECK
;
1087 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1088 scr
->clip_options
= makeClipOptionsMenu(scr
);
1089 if (scr
->clip_options
)
1090 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1092 wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1094 wMenuAddCallback(menu
, _("(Un)Select Icon"), selectCallback
, NULL
);
1096 wMenuAddCallback(menu
, _("(Un)Select All Icons"), selectIconsCallback
,
1099 wMenuAddCallback(menu
, _("Keep Icon(s)"), keepIconsCallback
, NULL
);
1101 entry
= wMenuAddCallback(menu
, _("Move Icon(s) To"), NULL
, NULL
);
1102 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1103 if (scr
->clip_submenu
)
1104 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1106 wMenuAddCallback(menu
, _("Remove Icon(s)"), removeIconsCallback
, NULL
);
1108 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1111 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1113 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1115 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1117 entry
->text
= _("Hide");
1119 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1121 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1123 if (type
== WM_CLIP
)
1124 scr
->clip_menu
= menu
;
1131 wDockCreate(WScreen
*scr
, int type
)
1139 dock
= wmalloc(sizeof(WDock
));
1140 memset(dock
, 0, sizeof(WDock
));
1142 if (type
== WM_CLIP
)
1143 icon_count
= CLIP_MAX_ICONS
;
1145 icon_count
= scr
->scr_height
/wPreferences
.icon_size
;
1147 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*)*icon_count
);
1148 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*)*icon_count
);
1150 dock
->max_icons
= icon_count
;
1152 btn
= mainIconCreate(scr
, type
);
1156 dock
->x_pos
= btn
->x_pos
;
1157 dock
->y_pos
= btn
->y_pos
;
1158 dock
->screen_ptr
= scr
;
1160 dock
->icon_count
= 1;
1161 dock
->on_right_side
= 1;
1162 dock
->collapsed
= 0;
1163 dock
->auto_collapse
= 0;
1164 dock
->auto_collapse_magic
= NULL
;
1165 dock
->auto_raise_lower
= 0;
1166 dock
->auto_lower_magic
= NULL
;
1167 dock
->auto_raise_magic
= NULL
;
1168 dock
->attract_icons
= 0;
1169 dock
->keep_attracted
= 0;
1171 dock
->icon_array
[0] = btn
;
1172 wRaiseFrame(btn
->icon
->core
);
1173 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1175 /* create dock menu */
1176 dock
->menu
= dockMenuCreate(scr
, type
);
1183 wDockDestroy(WDock
*dock
)
1188 for (i
=(dock
->type
== WM_CLIP
) ? 1 : 0; i
<dock
->max_icons
; i
++) {
1189 aicon
= dock
->icon_array
[i
];
1191 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1192 wDockDetach(dock
, aicon
);
1194 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
1195 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
1196 aicon
->x_pos
, aicon
->y_pos
);
1197 if (!dock
->mapped
|| dock
->collapsed
)
1198 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1202 if (wPreferences
.auto_arrange_icons
)
1203 wArrangeIcons(dock
->screen_ptr
, True
);
1204 free(dock
->icon_array
);
1205 if (dock
->menu
&& dock
->type
!=WM_CLIP
)
1206 wMenuDestroy(dock
->menu
, True
);
1212 wClipIconPaint(WAppIcon
*aicon
)
1214 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1215 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1217 Window win
= aicon
->icon
->core
->window
;
1218 int length
, nlength
;
1219 char *ws_name
, ws_number
[10];
1222 wIconPaint(aicon
->icon
);
1224 length
= strlen(workspace
->name
);
1225 ws_name
= malloc(length
+ 1);
1226 sprintf(ws_name
, "%s", workspace
->name
);
1227 sprintf(ws_number
, "%i", scr
->current_workspace
+ 1);
1228 nlength
= strlen(ws_number
);
1230 gc
= scr
->clip_title_gc
;
1232 if (!workspace
->clip
->collapsed
)
1233 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_NORMAL
]);
1235 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_COLLAPSED
]);
1237 ty
= ICON_SIZE
- scr
->clip_title_font
->height
- 3;
1239 tx
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
1241 wDrawString(win
, scr
->clip_title_font
, gc
, tx
,
1242 ty
+ scr
->clip_title_font
->y
, ws_name
, length
);
1244 tx
= (ICON_SIZE
/2 - wTextWidth(scr
->clip_title_font
->font
, ws_number
, nlength
))/2;
1246 wDrawString(win
, scr
->clip_title_font
, gc
, tx
,
1247 scr
->clip_title_font
->y
+ 2, ws_number
, nlength
);
1251 if (aicon
->launching
) {
1252 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1253 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1255 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
,
1256 aicon
->dock
->rclip_button_pushed
);
1261 clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1263 wClipIconPaint(desc
->parent
);
1268 dockIconPaint(WAppIcon
*btn
)
1270 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1271 wClipIconPaint(btn
);
1278 make_icon_state(WAppIcon
*btn
)
1280 proplist_t node
= NULL
;
1281 proplist_t command
, autolaunch
, name
, forced
, host
, position
, buggy
;
1282 proplist_t omnipresent
;
1288 command
= PLMakeString("-");
1290 command
= PLMakeString(btn
->command
);
1292 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1294 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1296 name
= PLMakeString(tmp
);
1300 forced
= btn
->forced_dock
? dYes
: dNo
;
1302 buggy
= btn
->buggy_app
? dYes
: dNo
;
1304 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1305 sprintf(buffer
, "%i,%i", btn
->x_pos
, btn
->y_pos
);
1307 sprintf(buffer
, "%hi,%hi", btn
->xindex
, btn
->yindex
);
1308 position
= PLMakeString(buffer
);
1310 node
= PLMakeDictionaryFromEntries(dCommand
, command
,
1312 dAutoLaunch
, autolaunch
,
1314 dBuggyApplication
, buggy
,
1315 dPosition
, position
,
1319 PLRelease(position
);
1321 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1322 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&&
1323 (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1324 PLInsertDictionaryEntry(node
, dOmnipresent
, omnipresent
);
1327 if (btn
->dnd_command
) {
1328 command
= PLMakeString(btn
->dnd_command
);
1329 PLInsertDictionaryEntry(node
, dDropCommand
, command
);
1332 #endif /* OFFIX_DND */
1334 if (btn
->client_machine
&& btn
->remote_start
) {
1335 host
= PLMakeString(btn
->client_machine
);
1336 PLInsertDictionaryEntry(node
, dHost
, host
);
1346 dockSaveState(WDock
*dock
)
1349 proplist_t icon_info
;
1350 proplist_t list
=NULL
, dock_state
=NULL
;
1354 list
= PLMakeArrayFromElements(NULL
);
1356 for (i
=(dock
->type
==WM_DOCK
? 0 : 1); i
<dock
->max_icons
; i
++) {
1357 WAppIcon
*btn
= dock
->icon_array
[i
];
1359 if (!btn
|| (btn
->attracted
&& !dock
->keep_attracted
))
1362 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1363 list
= PLAppendArrayElement(list
, icon_info
);
1364 PLRelease(icon_info
);
1368 dock_state
= PLMakeDictionaryFromEntries(dApplications
, list
, NULL
);
1372 if (dock
->type
== WM_DOCK
) {
1373 sprintf(buffer
, "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0),
1375 value
= PLMakeString(buffer
);
1376 PLInsertDictionaryEntry(dock_state
, dPosition
, value
);
1380 value
= (dock
->lowered
? dYes
: dNo
);
1381 PLInsertDictionaryEntry(dock_state
, dLowered
, value
);
1383 if (dock
->type
== WM_CLIP
) {
1384 value
= (dock
->collapsed
? dYes
: dNo
);
1385 PLInsertDictionaryEntry(dock_state
, dCollapsed
, value
);
1387 value
= (dock
->auto_collapse
? dYes
: dNo
);
1388 PLInsertDictionaryEntry(dock_state
, dAutoCollapse
, value
);
1390 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1391 PLInsertDictionaryEntry(dock_state
, dAutoRaiseLower
, value
);
1393 value
= (dock
->attract_icons
? dYes
: dNo
);
1394 PLInsertDictionaryEntry(dock_state
, dAutoAttractIcons
, value
);
1396 value
= (dock
->keep_attracted
? dYes
: dNo
);
1397 PLInsertDictionaryEntry(dock_state
, dKeepAttracted
, value
);
1405 wDockSaveState(WScreen
*scr
)
1407 proplist_t dock_state
;
1409 dock_state
= dockSaveState(scr
->dock
);
1411 PLInsertDictionaryEntry(scr
->session_state
, dDock
, dock_state
);
1413 PLRelease(dock_state
);
1418 wClipSaveState(WScreen
*scr
)
1420 proplist_t clip_state
;
1422 clip_state
= make_icon_state(scr
->clip_icon
);
1424 PLInsertDictionaryEntry(scr
->session_state
, dClip
, clip_state
);
1426 PLRelease(clip_state
);
1431 wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1433 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1438 restore_icon_state(WScreen
*scr
, proplist_t info
, int type
, int index
)
1441 char *wclass
, *winstance
;
1442 proplist_t cmd
, value
;
1446 cmd
= PLGetDictionaryEntry(info
, dCommand
);
1447 if (!cmd
|| !PLIsString(cmd
)) {
1451 /* parse window name */
1452 value
= PLGetDictionaryEntry(info
, dName
);
1456 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1458 if (!winstance
&& !wclass
) {
1465 command
= wstrdup(PLGetString(cmd
));
1469 if (!command
|| strcmp(command
, "-")==0) {
1480 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
,
1487 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1488 if (type
== WM_CLIP
) {
1489 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1490 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1492 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1493 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1497 cmd
= PLGetDictionaryEntry(info
, dDropCommand
);
1499 aicon
->dnd_command
= wstrdup(PLGetString(cmd
));
1502 /* check auto launch */
1503 value
= PLGetDictionaryEntry(info
, dAutoLaunch
);
1505 aicon
->auto_launch
= 0;
1507 if (PLIsString(value
)) {
1508 if (strcasecmp(PLGetString(value
), "YES")==0)
1509 aicon
->auto_launch
= 1;
1511 wwarning(_("bad value in docked icon state info %s"),
1512 PLGetString(dAutoLaunch
));
1516 /* check if it wasn't normally docked */
1517 value
= PLGetDictionaryEntry(info
, dForced
);
1519 aicon
->forced_dock
= 0;
1521 if (PLIsString(value
)) {
1522 if (strcasecmp(PLGetString(value
), "YES")==0)
1523 aicon
->forced_dock
= 1;
1525 wwarning(_("bad value in docked icon state info %s"),
1526 PLGetString(dForced
));
1530 /* check if we can rely on the stuff in the app */
1531 value
= PLGetDictionaryEntry(info
, dBuggyApplication
);
1533 aicon
->buggy_app
= 0;
1535 if (PLIsString(value
)) {
1536 if (strcasecmp(PLGetString(value
), "YES")==0)
1537 aicon
->buggy_app
= 1;
1539 wwarning(_("bad value in docked icon state info %s"),
1540 PLGetString(dBuggyApplication
));
1544 /* get position in the dock */
1545 value
= PLGetDictionaryEntry(info
, dPosition
);
1546 if (value
&& PLIsString(value
)) {
1547 if (sscanf(PLGetString(value
), "%hi,%hi", &aicon
->xindex
,
1549 wwarning(_("bad value in docked icon state info %s"),
1550 PLGetString(dPosition
));
1552 /* check position sanity */
1553 /* incomplete section! */
1554 if (type
== WM_DOCK
) {
1556 if (aicon
->yindex
< 0)
1557 wwarning(_("bad value in docked icon position %i,%i"),
1558 aicon
->xindex
, aicon
->yindex
);
1561 aicon
->yindex
= index
;
1565 /* check if icon is omnipresent */
1566 value
= PLGetDictionaryEntry(info
, dOmnipresent
);
1568 aicon
->omnipresent
= 0;
1570 if (PLIsString(value
)) {
1571 if (strcasecmp(PLGetString(value
), "YES")==0)
1572 aicon
->omnipresent
= 1;
1574 wwarning(_("bad value in docked icon state info %s"),
1575 PLGetString(dOmnipresent
));
1586 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1590 wClipRestoreState(WScreen
*scr
, proplist_t clip_state
)
1596 icon
= mainIconCreate(scr
, WM_CLIP
);
1601 PLRetain(clip_state
);
1603 /* restore position */
1605 value
= PLGetDictionaryEntry(clip_state
, dPosition
);
1608 if (!PLIsString(value
))
1609 COMPLAIN("Position");
1611 if (sscanf(PLGetString(value
), "%i,%i", &icon
->x_pos
,
1613 COMPLAIN("Position");
1615 /* check position sanity */
1616 if (icon
->y_pos
< 0)
1618 else if (icon
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1619 icon
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1621 if (icon
->x_pos
< 0)
1623 else if (icon
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1624 icon
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1629 value
= PLGetDictionaryEntry(clip_state
, dDropCommand
);
1630 if (value
&& PLIsString(value
))
1631 icon
->dnd_command
= wstrdup(PLGetString(value
));
1634 PLRelease(clip_state
);
1641 wDockRestoreState(WScreen
*scr
, proplist_t dock_state
, int type
)
1646 WAppIcon
*aicon
, *old_top
;
1650 dock
= wDockCreate(scr
, type
);
1656 PLRetain(dock_state
);
1659 /* restore position */
1661 value
= PLGetDictionaryEntry(dock_state
, dPosition
);
1664 if (!PLIsString(value
))
1665 COMPLAIN("Position");
1667 if (sscanf(PLGetString(value
), "%i,%i", &dock
->x_pos
,
1669 COMPLAIN("Position");
1671 /* check position sanity */
1672 if (dock
->y_pos
< 0)
1674 else if (dock
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1675 dock
->y_pos
= scr
->scr_height
- ICON_SIZE
;
1677 /* This is no more needed. ??? */
1678 if (type
== WM_CLIP
) {
1679 if (dock
->x_pos
< 0)
1681 else if (dock
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1682 dock
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1684 if (dock
->x_pos
>= 0) {
1685 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1686 dock
->on_right_side
= 0;
1688 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1689 dock
->on_right_side
= 1;
1695 /* restore lowered/raised state */
1699 value
= PLGetDictionaryEntry(dock_state
, dLowered
);
1702 if (!PLIsString(value
))
1703 COMPLAIN("Lowered");
1705 if (strcasecmp(PLGetString(value
), "YES")==0)
1711 /* restore collapsed state */
1713 dock
->collapsed
= 0;
1715 value
= PLGetDictionaryEntry(dock_state
, dCollapsed
);
1718 if (!PLIsString(value
))
1719 COMPLAIN("Collapsed");
1721 if (strcasecmp(PLGetString(value
), "YES")==0)
1722 dock
->collapsed
= 1;
1727 /* restore auto-collapsed state */
1729 value
= PLGetDictionaryEntry(dock_state
, dAutoCollapse
);
1732 if (!PLIsString(value
))
1733 COMPLAIN("AutoCollapse");
1735 if (strcasecmp(PLGetString(value
), "YES")==0) {
1736 dock
->auto_collapse
= 1;
1737 dock
->collapsed
= 1;
1743 /* restore auto-raise/lower state */
1745 value
= PLGetDictionaryEntry(dock_state
, dAutoRaiseLower
);
1748 if (!PLIsString(value
))
1749 COMPLAIN("AutoRaiseLower");
1751 if (strcasecmp(PLGetString(value
), "YES")==0) {
1752 dock
->auto_raise_lower
= 1;
1757 /* restore attract icons state */
1759 dock
->attract_icons
= 0;
1761 value
= PLGetDictionaryEntry(dock_state
, dAutoAttractIcons
);
1764 if (!PLIsString(value
))
1765 COMPLAIN("AutoAttractIcons");
1767 if (strcasecmp(PLGetString(value
), "YES")==0)
1768 dock
->attract_icons
= 1;
1773 /* restore keep attracted icons state */
1775 dock
->keep_attracted
= 0;
1777 value
= PLGetDictionaryEntry(dock_state
, dKeepAttracted
);
1780 if (!PLIsString(value
))
1781 COMPLAIN("KeepAttracted");
1783 if (strcasecmp(PLGetString(value
), "YES")==0)
1784 dock
->keep_attracted
= 1;
1789 /* application list */
1791 apps
= PLGetDictionaryEntry(dock_state
, dApplications
);
1797 count
= PLGetNumberOfElements(apps
);
1802 old_top
= dock
->icon_array
[0];
1804 /* dock->icon_count is set to 1 when dock is created.
1805 * Since Clip is already restored, we want to keep it so for clip,
1806 * but for dock we may change the default top tile, so we set it to 0.
1808 if (type
== WM_DOCK
)
1809 dock
->icon_count
= 0;
1811 for (i
=0; i
<count
; i
++) {
1812 if (dock
->icon_count
>= dock
->max_icons
) {
1813 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1817 value
= PLGetArrayElement(apps
, i
);
1818 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1820 dock
->icon_array
[dock
->icon_count
] = aicon
;
1824 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
*ICON_SIZE
);
1825 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
*ICON_SIZE
);
1828 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1830 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1832 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
,
1835 if (!dock
->collapsed
)
1836 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1837 wRaiseFrame(aicon
->icon
->core
);
1840 } else if (dock
->icon_count
==0 && type
==WM_DOCK
)
1844 /* if the first icon is not defined, use the default */
1845 if (dock
->icon_array
[0]==NULL
) {
1846 /* update default icon */
1847 old_top
->x_pos
= dock
->x_pos
;
1848 old_top
->y_pos
= dock
->y_pos
;
1850 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1852 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1853 dock
->icon_array
[0] = old_top
;
1854 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1855 /* we don't need to increment dock->icon_count here because it was
1856 * incremented in the loop above.
1858 } else if (old_top
!=dock
->icon_array
[0]) {
1859 if (old_top
== scr
->clip_icon
)
1860 scr
->clip_icon
= dock
->icon_array
[0];
1861 wAppIconDestroy(old_top
);
1866 PLRelease(dock_state
);
1874 wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1876 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1878 btn
->drop_launch
= 0;
1880 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1883 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1895 wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1901 for (i
= 0; i
< dock
->max_icons
; i
++) {
1902 btn
= dock
->icon_array
[i
];
1903 if (!btn
|| !btn
->auto_launch
)
1906 state
= wmalloc(sizeof(WSavedState
));
1907 memset(state
, 0, sizeof(WSavedState
));
1908 state
->workspace
= workspace
;
1909 /* TODO: this is klugy and is very difficult to understand
1910 * what's going on. Try to clean up */
1911 wDockLaunchWithState(dock
, btn
, state
);
1915 #ifdef REDUCE_APPICONS
1917 wDockSimulateLaunch(WDock
*dock
, WAppIcon
*btn
)
1919 if ((btn
== NULL
) || (dock
== NULL
))
1922 if (!btn
->running
) {
1923 if ((btn
->icon
->owner
== NULL
) && (btn
->applist
))
1924 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
1925 if (!btn
->forced_dock
)
1935 findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1941 if ((dock
= scr
->dock
)!=NULL
) {
1942 for (i
=0; i
<dock
->max_icons
; i
++) {
1943 if (dock
->icon_array
[i
]
1944 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1950 if (*icon_pos
<0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
)!=NULL
) {
1951 for (i
=0; i
<dock
->max_icons
; i
++) {
1952 if (dock
->icon_array
[i
]
1953 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1966 wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
1972 dock
= findDock(scr
, event
, &icon_pos
);
1977 * Return True if the drop was on an application icon window.
1978 * In this case, let the ClientMessage handler redirect the
1979 * message to the app.
1981 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!=None
)
1984 if (dock
->icon_array
[icon_pos
]->dnd_command
!=NULL
) {
1985 scr
->flags
.dnd_data_convertion_status
= 0;
1987 btn
= dock
->icon_array
[icon_pos
];
1989 if (!btn
->forced_dock
) {
1990 btn
->relaunching
= btn
->running
;
1993 if (btn
->wm_instance
|| btn
->wm_class
) {
1994 WWindowAttributes attr
;
1995 memset(&attr
, 0, sizeof(WWindowAttributes
));
1996 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
1998 btn
->wm_class
, &attr
, NULL
, True
);
2000 if (!attr
.no_appicon
)
2006 btn
->drop_launch
= 1;
2007 scr
->last_dock
= dock
;
2008 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
2013 if (!btn
->relaunching
) {
2020 #endif /* OFFIX_DND */
2025 wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2032 wwin
= icon
->icon
->owner
;
2033 if (icon
->command
==NULL
) {
2035 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2037 icon
->command
= FlattenStringList(argv
, argc
);
2038 XFreeStringList(argv
);
2042 /* icon->forced_dock = 1;*/
2043 if (!icon
->attracted
|| dock
->type
!=WM_CLIP
|| dock
->keep_attracted
) {
2045 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2046 _("Type the command used to launch the application"),
2048 if (command
&& (command
[0]==0 ||
2049 (command
[0]=='-' && command
[1]==0))) {
2053 icon
->command
= command
;
2059 /* If the target is the dock, reject the icon. If
2060 * the target is the clip, make it an attracted icon
2062 if (dock
->type
==WM_CLIP
) {
2063 icon
->attracted
= 1;
2064 if (!icon
->icon
->shadowed
) {
2065 icon
->icon
->shadowed
= 1;
2066 icon
->icon
->force_paint
= 1;
2078 for (index
=1; index
<dock
->max_icons
; index
++)
2079 if (dock
->icon_array
[index
] == NULL
)
2081 /* if (index == dock->max_icons)
2084 assert(index
< dock
->max_icons
);
2086 dock
->icon_array
[index
] = icon
;
2090 icon
->omnipresent
= 0;
2092 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2093 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2098 icon
->launching
= 0;
2101 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2102 if (dock
->type
== WM_CLIP
) {
2103 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2104 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2106 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2107 icon
->icon
->core
->descriptor
.parent
= icon
;
2109 MoveInStackListUnder(dock
->icon_array
[index
-1]->icon
->core
,
2111 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2112 wAppIconPaint(icon
);
2114 if (wPreferences
.auto_arrange_icons
)
2115 wArrangeIcons(dock
->screen_ptr
, True
);
2118 if (icon
->command
&& !icon
->dnd_command
) {
2119 icon
->dnd_command
= wmalloc(strlen(icon
->command
)+8);
2120 sprintf(icon
->dnd_command
, "%s %%d", icon
->command
);
2129 reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2133 for(index
=1; index
<dock
->max_icons
; index
++) {
2134 if(dock
->icon_array
[index
] == icon
)
2137 assert(index
< dock
->max_icons
);
2142 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2143 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2148 moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2156 return True
; /* No move needed, we're already there */
2161 wwin
= icon
->icon
->owner
;
2164 * For the moment we can't do this if we move icons in Clip from one
2165 * workspace to other, because if we move two or more icons without
2166 * command, the dialog box will not be able to tell us to which of the
2167 * moved icons it applies. -Dan
2169 if ((dest
->type
==WM_DOCK
/*|| dest->keep_attracted*/) && icon
->command
==NULL
) {
2170 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2172 icon
->command
= FlattenStringList(argv
, argc
);
2173 XFreeStringList(argv
);
2178 /* icon->forced_dock = 1;*/
2179 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2180 _("Type the command used to launch the application"),
2182 if (command
&& (command
[0]==0 ||
2183 (command
[0]=='-' && command
[1]==0))) {
2187 icon
->command
= command
;
2198 if (dest
->type
== WM_DOCK
)
2199 wClipMakeIconOmnipresent(icon
, False
);
2201 for(index
=1; index
<src
->max_icons
; index
++) {
2202 if(src
->icon_array
[index
] == icon
)
2205 assert(index
< src
->max_icons
);
2207 src
->icon_array
[index
] = NULL
;
2210 for(index
=1; index
<dest
->max_icons
; index
++) {
2211 if(dest
->icon_array
[index
] == NULL
)
2214 /* if (index == dest->max_icons)
2217 assert(index
< dest
->max_icons
);
2219 dest
->icon_array
[index
] = icon
;
2222 /* deselect the icon */
2223 if (icon
->icon
->selected
)
2224 wIconSelect(icon
->icon
);
2226 if (dest
->type
== WM_DOCK
) {
2227 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2228 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2230 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2231 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2234 /* set it to be kept when moving to dock, or to a clip that keep the
2236 * Unless the icon does not have a command set
2238 if (icon
->command
&& (dest
->type
==WM_DOCK
|| dest
->keep_attracted
)) {
2239 icon
->attracted
= 0;
2240 if (icon
->icon
->shadowed
) {
2241 icon
->icon
->shadowed
= 0;
2242 icon
->icon
->force_paint
= 1;
2246 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2252 icon
->x_pos
= dest
->x_pos
+ x
*ICON_SIZE
;
2253 icon
->y_pos
= dest
->y_pos
+ y
*ICON_SIZE
;
2257 MoveInStackListUnder(dest
->icon_array
[index
-1]->icon
->core
,
2259 wAppIconPaint(icon
);
2266 wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2270 /* make the settings panel be closed */
2272 DestroyDockAppSettingsPanel(icon
->panel
);
2277 icon
->attracted
= 0;
2278 if (icon
->icon
->shadowed
) {
2279 icon
->icon
->shadowed
= 0;
2280 icon
->icon
->force_paint
= 1;
2283 /* This must be called before dock->icon_array[index] is set to NULL.
2284 * Don't move it. -Dan
2286 wClipMakeIconOmnipresent(icon
, False
);
2288 /* deselect the icon */
2289 if (icon
->icon
->selected
)
2290 wIconSelect(icon
->icon
);
2292 if (icon
->command
) {
2293 free(icon
->command
);
2294 icon
->command
= NULL
;
2297 if (icon
->dnd_command
) {
2298 free(icon
->dnd_command
);
2299 icon
->dnd_command
= NULL
;
2303 for (index
=1; index
<dock
->max_icons
; index
++)
2304 if (dock
->icon_array
[index
] == icon
)
2306 assert(index
< dock
->max_icons
);
2307 dock
->icon_array
[index
] = NULL
;
2313 /* if the dock is not attached to an application or
2314 * the the application did not set the approriate hints yet,
2315 * destroy the icon */
2316 #ifdef REDUCE_APPICONS
2317 if ((icon
->num_apps
== 0) && (!icon
->running
|| !wApplicationOf(icon
->main_window
)) )
2319 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2321 wAppIconDestroy(icon
);
2323 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2324 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2325 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2326 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2327 icon
->icon
->core
->descriptor
.parent
= icon
;
2329 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2331 wAppIconPaint(icon
);
2332 if (wPreferences
.auto_arrange_icons
) {
2333 wArrangeIcons(dock
->screen_ptr
, True
);
2336 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2342 * returns the closest Dock slot index for the passed
2345 * Returns False if icon can't be docked.
2347 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2351 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2352 int *ret_x
, int *ret_y
, int redocking
)
2354 WScreen
*scr
= dock
->screen_ptr
;
2357 int i
, offset
= ICON_SIZE
/2;
2358 WAppIcon
*aicon
= NULL
;
2359 WAppIcon
*nicon
= NULL
;
2360 int max_y_icons
, max_x_icons
;
2362 max_x_icons
= scr
->scr_width
/ICON_SIZE
;
2363 max_y_icons
= scr
->scr_height
/ICON_SIZE
-1;
2365 if (wPreferences
.flags
.noupdates
)
2371 /* if the dock is full */
2373 (dock
->icon_count
>= dock
->max_icons
)) {
2377 /* exact position */
2379 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2381 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2384 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2386 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2388 /* check if the icon is outside the screen boundaries */
2389 if (dx
+ ex_x
*ICON_SIZE
< -ICON_SIZE
+2 ||
2390 dx
+ ex_x
*ICON_SIZE
>= scr
->scr_width
-1 ||
2391 dy
+ ex_y
*ICON_SIZE
< -ICON_SIZE
+2 ||
2392 dy
+ ex_y
*ICON_SIZE
>= scr
->scr_height
-1)
2395 if (dock
->type
== WM_DOCK
) {
2396 if (icon
->dock
!= dock
&& ex_x
!= 0)
2400 for (i
=0; i
<dock
->max_icons
; i
++) {
2401 nicon
= dock
->icon_array
[i
];
2402 if (nicon
&& nicon
->yindex
== ex_y
) {
2409 int sig
, done
, closest
;
2411 /* Possible cases when redocking:
2413 * icon dragged out of range of any slot -> false
2414 * icon dragged to range of free slot
2415 * icon dragged to range of same slot
2416 * icon dragged to range of different icon
2418 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2421 if (ex_y
>=0 && ex_y
<=max_y_icons
&& (aicon
==icon
|| !aicon
)) {
2427 /* start looking at the upper slot or lower? */
2428 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2435 /* look for closest free slot */
2436 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2440 closest
= sig
*(i
/2) + ex_y
;
2441 /* check if this slot is used */
2443 for (j
= 0; j
<dock
->max_icons
; j
++) {
2444 if (dock
->icon_array
[j
]
2445 && dock
->icon_array
[j
]->yindex
==closest
) {
2446 /* slot is used by someone else */
2447 if (dock
->icon_array
[j
]!=icon
)
2455 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2456 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2458 (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+1))) {
2463 } else { /* !redocking */
2465 /* if slot is free and the icon is close enough, return it */
2466 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2476 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2477 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+1;
2480 for (k
=start
; k
<stop
; k
++) {
2481 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2484 for (i
=0; i
<tmp
->max_icons
; i
++) {
2485 nicon
= tmp
->icon_array
[i
];
2486 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2494 for (k
=start
; k
<stop
; k
++) {
2495 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2498 for (i
=0; i
<tmp
->max_icons
; i
++) {
2499 nicon
= tmp
->icon_array
[i
];
2500 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2501 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2502 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2511 if (neighbours
&& (aicon
==NULL
|| (redocking
&& aicon
== icon
))) {
2520 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2521 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2523 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2524 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2525 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2529 * returns true if it can find a free slot in the dock,
2530 * in which case it changes x_pos and y_pos accordingly.
2531 * Else returns false.
2534 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2536 WScreen
*scr
= dock
->screen_ptr
;
2538 WAppIconChain
*chain
;
2539 unsigned char *slot_map
;
2543 int i
, done
= False
;
2545 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2548 if (dock
->type
== WM_CLIP
&&
2549 dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2550 extra_count
= scr
->global_icon_count
;
2552 /* if the dock is full */
2553 if (dock
->icon_count
+extra_count
>= dock
->max_icons
) {
2557 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2558 if (scr
->dock
->on_right_side
)
2559 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2561 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2564 if (ex
< dock
->x_pos
)
2566 if (sx
> dock
->x_pos
+ICON_SIZE
)
2567 sx
= dock
->x_pos
+ICON_SIZE
;
2574 /* check if clip is in a corner */
2575 if (dock
->type
==WM_CLIP
) {
2576 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2578 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2580 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2582 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2589 /* If the clip is in the corner, use only slots that are in the border
2591 if (corner
!=C_NONE
) {
2595 hcount
= MIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2596 vcount
= MIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2597 hmap
= wmalloc(hcount
+1);
2598 memset(hmap
, 0, hcount
+1);
2599 vmap
= wmalloc(vcount
+1);
2600 memset(vmap
, 0, vcount
+1);
2602 /* mark used positions */
2605 for (i
=0; i
<dock
->max_icons
; i
++) {
2606 btn
= dock
->icon_array
[i
];
2610 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2611 vmap
[btn
->yindex
] = 1;
2612 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2613 hmap
[btn
->xindex
] = 1;
2615 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2617 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2618 vmap
[btn
->yindex
] = 1;
2619 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2620 hmap
[btn
->xindex
] = 1;
2624 for (i
=0; i
<dock
->max_icons
; i
++) {
2625 btn
= dock
->icon_array
[i
];
2629 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2630 vmap
[btn
->yindex
] = 1;
2631 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2632 hmap
[-btn
->xindex
] = 1;
2634 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2636 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2637 vmap
[btn
->yindex
] = 1;
2638 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2639 hmap
[-btn
->xindex
] = 1;
2643 for (i
=0; i
<dock
->max_icons
; i
++) {
2644 btn
= dock
->icon_array
[i
];
2648 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2649 vmap
[-btn
->yindex
] = 1;
2650 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2651 hmap
[btn
->xindex
] = 1;
2653 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2655 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2656 vmap
[-btn
->yindex
] = 1;
2657 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2658 hmap
[btn
->xindex
] = 1;
2663 for (i
=0; i
<dock
->max_icons
; i
++) {
2664 btn
= dock
->icon_array
[i
];
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;
2673 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2675 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2676 vmap
[-btn
->yindex
] = 1;
2677 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2678 hmap
[-btn
->xindex
] = 1;
2683 /* search a vacant slot */
2684 for (i
=1; i
<MAX(vcount
, hcount
); i
++) {
2685 if (i
< vcount
&& vmap
[i
]==0) {
2691 } else if (i
< hcount
&& hmap
[i
]==0) {
2701 /* If found a slot, translate and return */
2703 if (corner
==C_NW
|| corner
==C_NE
) {
2708 if (corner
==C_NE
|| corner
==C_SE
) {
2715 /* else, try to find a slot somewhere else */
2718 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2719 * placed outside of screen */
2720 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2722 /* In the worst case (the clip is in the corner of the screen),
2723 * the amount of icons that fit in the clip is smaller.
2724 * Double the map to get a safe value.
2730 slot_map
= wmalloc(mwidth
*mwidth
);
2731 memset(slot_map
, 0, mwidth
*mwidth
);
2733 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2735 /* mark used slots in the map. If the slot falls outside the map
2736 * (for example, when all icons are placed in line), ignore them. */
2737 for (i
=0; i
<dock
->max_icons
; i
++) {
2738 btn
= dock
->icon_array
[i
];
2740 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2742 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2743 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2745 /* Find closest slot from the center that is free by scanning the
2746 * map from the center to outward in circular passes.
2747 * This will not result in a neat layout, but will be optimal
2748 * in the sense that there will not be holes left.
2751 for (i
= 1; i
<= r
&& !done
; i
++) {
2754 /* top and bottom parts of the ring */
2755 for (x
= -i
; x
<= i
&& !done
; x
++) {
2756 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2758 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2759 if (slot_map
[XY2OFS(x
,y
)]==0
2760 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2767 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2768 if (slot_map
[XY2OFS(x
,y
)]==0
2769 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2776 /* left and right parts of the ring */
2777 for (y
= -i
+1; y
<= i
-1; y
++) {
2778 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2780 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2781 if (slot_map
[XY2OFS(x
,y
)]==0
2782 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2789 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2790 if (slot_map
[XY2OFS(x
,y
)]==0
2791 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2806 moveDock(WDock
*dock
, int new_x
, int new_y
)
2811 dock
->x_pos
= new_x
;
2812 dock
->y_pos
= new_y
;
2813 for (i
=0; i
<dock
->max_icons
; i
++) {
2814 btn
= dock
->icon_array
[i
];
2816 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2817 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2818 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2825 swapDock(WDock
*dock
)
2827 WScreen
*scr
= dock
->screen_ptr
;
2832 if (dock
->on_right_side
) {
2833 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2835 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2838 for (i
=0; i
<dock
->max_icons
; i
++) {
2839 btn
= dock
->icon_array
[i
];
2842 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2846 wScreenUpdateUsableArea(scr
);
2851 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2853 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2859 cmdline
= ExpandOptions(scr
, command
);
2861 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2869 ParseCommand(cmdline
, &argv
, &argc
);
2879 if ((pid
=fork())==0) {
2883 SetupEnvironment(scr
);
2889 args
= malloc(sizeof(char*)*(argc
+1));
2892 for (i
=0; i
<argc
; i
++) {
2896 execvp(argv
[0], args
);
2905 state
= wmalloc(sizeof(WSavedState
));
2906 memset(state
, 0, sizeof(WSavedState
));
2908 state
->miniaturized
= -1;
2910 if (btn
->dock
== scr
->dock
)
2911 state
->workspace
= -1;
2913 state
->workspace
= scr
->current_workspace
;
2915 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
2917 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
2928 wDockHideIcons(WDock
*dock
)
2935 for (i
=1; i
<dock
->max_icons
; i
++) {
2936 if (dock
->icon_array
[i
])
2937 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2941 dockIconPaint(dock
->icon_array
[0]);
2946 wDockShowIcons(WDock
*dock
)
2954 btn
= dock
->icon_array
[0];
2955 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2957 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2958 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2960 for (i
=1; i
<dock
->max_icons
; i
++) {
2961 if (dock
->icon_array
[i
]) {
2962 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
2968 if (!dock
->collapsed
) {
2969 for (i
=1; i
<dock
->max_icons
; i
++) {
2970 if (dock
->icon_array
[i
]) {
2971 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2982 wDockLower(WDock
*dock
)
2986 for (i
=0; i
<dock
->max_icons
; i
++) {
2987 if (dock
->icon_array
[i
])
2988 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2994 wDockRaise(WDock
*dock
)
2998 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
2999 if (dock
->icon_array
[i
])
3000 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
3006 wDockRaiseLower(WDock
*dock
)
3008 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
3009 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
3010 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
3018 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
3020 icon
->launching
= 0;
3021 icon
->relaunching
= 0;
3022 dockIconPaint(icon
);
3027 wDockFindIconFor(WDock
*dock
, Window window
)
3032 for (i
=0; i
<dock
->max_icons
; i
++) {
3033 icon
= dock
->icon_array
[i
];
3034 if (icon
&& icon
->main_window
== window
)
3042 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
3045 #ifdef REDUCE_APPICONS
3046 WAppIconAppList
*tapplist
;
3048 char *wm_class
, *wm_instance
;
3050 Bool firstPass
= True
;
3052 char *command
= NULL
;
3058 if (XGetCommand(dpy
, window
, &argv
, &argc
)) {
3059 if (argc
> 0 && argv
!= NULL
)
3060 command
= FlattenStringList(argv
,argc
);
3062 XFreeStringList(argv
);
3067 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
3068 (!wm_class
&& !wm_instance
))
3072 for (i
=0; i
<dock
->max_icons
; i
++) {
3073 icon
= dock
->icon_array
[i
];
3077 /* app is already attached to icon */
3078 if (icon
->main_window
== window
) {
3083 if ((icon
->wm_instance
|| icon
->wm_class
)
3085 || (dock
->screen_ptr
->flags
.startup
&& !icon
->running
))) {
3087 if (icon
->wm_instance
&& wm_instance
&&
3088 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
3091 if (icon
->wm_class
&& wm_class
&&
3092 strcmp(icon
->wm_class
, wm_class
)!=0) {
3095 if (firstPass
&& command
&& strcmp(icon
->command
, command
)!=0) {
3099 if (!icon
->relaunching
) {
3102 /* Possibly an application that was docked with dockit,
3103 * but the user did not update WMState to indicate that
3104 * it was docked by force */
3105 wapp
= wApplicationOf(window
);
3107 icon
->forced_dock
= 1;
3110 if (!icon
->forced_dock
)
3111 icon
->main_window
= window
;
3113 #ifdef REDUCE_APPICONS
3114 tapplist
= wmalloc(sizeof(WAppIconAppList
));
3115 memset(tapplist
, 0, sizeof(WAppIconAppList
));
3116 tapplist
->next
= icon
->applist
;
3118 icon
->applist
->prev
= tapplist
;
3119 icon
->applist
= tapplist
;
3120 tapplist
->wapp
= wApplicationOf(window
);
3125 wDockFinishLaunch(dock
, icon
);
3130 if (firstPass
&& !found
) {
3147 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3149 if (!wPreferences
.flags
.noclip
) {
3150 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3151 if (scr
->current_workspace
!= workspace
) {
3152 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3153 WAppIconChain
*chain
= scr
->global_icons
;
3156 moveIconBetweenDocks(chain
->aicon
->dock
,
3157 scr
->workspaces
[workspace
]->clip
,
3158 chain
->aicon
, chain
->aicon
->xindex
,
3159 chain
->aicon
->yindex
);
3160 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
3161 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3162 chain
= chain
->next
;
3165 wDockHideIcons(old_clip
);
3166 if (old_clip
->auto_raise_lower
) {
3167 if (old_clip
->auto_raise_magic
) {
3168 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3169 old_clip
->auto_raise_magic
= NULL
;
3171 wDockLower(old_clip
);
3173 if (old_clip
->auto_collapse
) {
3174 if (old_clip
->auto_expand_magic
) {
3175 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3176 old_clip
->auto_expand_magic
= NULL
;
3178 old_clip
->collapsed
= 1;
3180 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3182 if (scr
->flags
.clip_balloon_mapped
)
3183 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3190 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3195 for (i
=0; i
<dock
->max_icons
; i
++) {
3196 icon
= dock
->icon_array
[i
];
3200 if (icon
->launching
&& icon
->pid
== pid
) {
3201 if (!icon
->relaunching
) {
3203 icon
->main_window
= None
;
3205 wDockFinishLaunch(dock
, icon
);
3210 sprintf(msg
, _("Could not execute command \"%s\""),
3211 icon
->drop_launch
&& icon
->dnd_command
3212 ? icon
->dnd_command
: icon
->command
);
3214 sprintf(msg
, _("Could not execute command \"%s\""),
3217 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
3218 _("OK"), NULL
, NULL
);
3227 toggleLowered(WDock
*dock
)
3232 /* lower/raise Dock */
3233 if (!dock
->lowered
) {
3234 newlevel
= WMNormalLevel
;
3237 newlevel
= WMDockLevel
;
3241 for (i
=0; i
<dock
->max_icons
; i
++) {
3242 tmp
= dock
->icon_array
[i
];
3246 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3248 wLowerFrame(tmp
->icon
->core
);
3251 if (dock
->type
== WM_DOCK
)
3252 wScreenUpdateUsableArea(dock
->screen_ptr
);
3257 toggleCollapsed(WDock
*dock
)
3259 if (dock
->collapsed
) {
3260 dock
->collapsed
= 0;
3261 wDockShowIcons(dock
);
3264 dock
->collapsed
= 1;
3265 wDockHideIcons(dock
);
3271 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3273 WScreen
*scr
= dock
->screen_ptr
;
3274 WObjDescriptor
*desc
;
3276 WApplication
*wapp
= NULL
;
3279 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3281 if (dock
->type
== WM_DOCK
) {
3283 entry
= dock
->menu
->entries
[index
];
3284 entry
->flags
.indicator_on
= !dock
->lowered
;
3285 entry
->clientdata
= dock
;
3288 if (scr
->clip_options
)
3289 updateClipOptionsMenu(scr
->clip_options
, dock
);
3291 /* Rename Workspace */
3292 entry
= dock
->menu
->entries
[++index
];
3293 entry
->clientdata
= dock
;
3296 entry
= dock
->menu
->entries
[++index
];
3297 entry
->clientdata
= aicon
;
3298 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3300 /* (un)select all icons */
3301 entry
= dock
->menu
->entries
[++index
];
3302 entry
->clientdata
= aicon
;
3303 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3306 entry
= dock
->menu
->entries
[++index
];
3307 entry
->clientdata
= aicon
;
3308 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3310 /* this is the workspace submenu part */
3311 if (scr
->clip_submenu
)
3312 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3313 wMenuSetEnabled(dock
->menu
, ++index
, !aicon
->omnipresent
);
3315 /* remove icon(s) */
3316 entry
= dock
->menu
->entries
[++index
];
3317 entry
->clientdata
= aicon
;
3318 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3320 /* attract icon(s) */
3321 entry
= dock
->menu
->entries
[++index
];
3322 entry
->clientdata
= aicon
;
3326 entry
= dock
->menu
->entries
[++index
];
3327 entry
->clientdata
= aicon
;
3328 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3331 entry
= dock
->menu
->entries
[++index
];
3332 entry
->clientdata
= aicon
;
3333 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3336 entry
= dock
->menu
->entries
[++index
];
3337 entry
->clientdata
= aicon
;
3338 if (aicon
->icon
->owner
) {
3339 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3340 if (wapp
&& wapp
->flags
.hidden
)
3341 entry
->text
= _("Unhide");
3343 entry
->text
= _("Hide");
3345 entry
->text
= _("Hide");
3347 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3350 entry
= dock
->menu
->entries
[++index
];
3351 entry
->clientdata
= aicon
;
3352 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
3353 && !wPreferences
.flags
.noupdates
);
3356 entry
= dock
->menu
->entries
[++index
];
3357 entry
->clientdata
= aicon
;
3358 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3360 if (!dock
->menu
->flags
.realized
)
3361 wMenuRealize(dock
->menu
);
3363 if (dock
->type
== WM_CLIP
) {
3364 x_pos
= event
->xbutton
.x_root
+2;
3366 x_pos
= dock
->on_right_side
?
3367 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 2 : 0;
3370 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3372 /* allow drag select */
3373 event
->xany
.send_event
= True
;
3374 desc
= &dock
->menu
->menu
->descriptor
;
3375 (*desc
->handle_mousedown
)(desc
, event
);
3380 openClipWorkspaceMenu(WScreen
*scr
, int x
, int y
)
3382 if (!scr
->clip_ws_menu
) {
3383 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3385 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
3386 wMenuMapAt(scr
->clip_ws_menu
, x
, y
, False
);
3390 /******************************************************************/
3392 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3394 WAppIcon
*btn
= desc
->parent
;
3395 WDock
*dock
= btn
->dock
;
3396 WApplication
*wapp
= NULL
;
3399 #ifdef REDUCE_APPICONS
3400 if ((btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) ||
3401 ((btn
->icon
->owner
== NULL
) && (btn
->applist
!= NULL
))) {
3402 if (btn
->icon
->owner
== NULL
)
3403 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
3406 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3408 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3412 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3414 /* go to the last workspace that the user worked on the app */
3415 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
3417 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3420 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3423 if (event
->xbutton
.state
& MOD_MASK
) {
3424 wHideOtherApplications(btn
->icon
->owner
);
3427 if (event
->xbutton
.button
==Button1
) {
3429 if (event
->xbutton
.state
& MOD_MASK
) {
3430 /* raise/lower dock */
3431 toggleLowered(dock
);
3432 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3433 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3434 toggleCollapsed(dock
);
3436 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3437 } else if (btn
->command
) {
3438 if (!btn
->launching
&&
3439 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3440 launchDockedApplication(btn
);
3442 } else if (btn
->xindex
== 0 && btn
->yindex
== 0
3443 && btn
->dock
->type
== WM_DOCK
) {
3445 wShowGNUstepPanel(dock
->screen_ptr
);
3453 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3455 WScreen
*scr
= dock
->screen_ptr
;
3456 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3459 int grabbed
= 0, swapped
= 0, done
;
3460 Pixmap ghost
= None
;
3461 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3464 puts("moving dock");
3466 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3467 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3468 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3469 wwarning("pointer grab failed for dock move");
3472 for (x
=0; x
<dock
->max_icons
; x
++) {
3473 if (dock
->icon_array
[x
]!=NULL
&&
3474 dock
->icon_array
[x
]->yindex
> y
)
3475 y
= dock
->icon_array
[x
]->yindex
;
3478 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3482 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3483 |ButtonMotionMask
|ExposureMask
, &ev
);
3491 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3492 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3493 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3494 |ButtonReleaseMask
|ButtonPressMask
,
3495 wCursor
[WCUR_MOVE
], CurrentTime
);
3500 if (dock
->type
== WM_CLIP
) {
3501 if (ev
.xmotion
.x_root
- ofs_x
< 0) {
3503 } else if (ev
.xmotion
.x_root
- ofs_x
+ ICON_SIZE
>
3505 x
= scr
->scr_width
- ICON_SIZE
;
3507 x
= ev
.xmotion
.x_root
- ofs_x
;
3509 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3511 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3513 y
= scr
->scr_height
- ICON_SIZE
;
3515 y
= ev
.xmotion
.y_root
- ofs_y
;
3517 moveDock(dock
, x
, y
);
3519 /* move vertically if pointer is inside the dock*/
3520 if ((dock
->on_right_side
&&
3521 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3522 || (!dock
->on_right_side
&&
3523 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3525 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3527 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3529 y
= scr
->scr_height
- ICON_SIZE
;
3531 y
= ev
.xmotion
.y_root
- ofs_y
;
3533 moveDock(dock
, dock
->x_pos
, y
);
3535 /* move horizontally to change sides */
3536 x
= ev
.xmotion
.x_root
- ofs_x
;
3537 if (!dock
->on_right_side
) {
3541 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3542 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3543 -DOCK_EXTRA_SPACE
-1, dock
->y_pos
);
3544 if (superfluous
&& ghost
==None
) {
3545 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3546 scr
->scr_width
-ICON_SIZE
3547 -DOCK_EXTRA_SPACE
-1,
3549 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3551 XClearWindow(dpy
, scr
->dock_shadow
);
3553 XMapRaised(dpy
, scr
->dock_shadow
);
3556 if (superfluous
&& ghost
!=None
) {
3557 XFreePixmap(dpy
, ghost
);
3560 XUnmapWindow(dpy
, scr
->dock_shadow
);
3565 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3566 XMoveWindow(dpy
, scr
->dock_shadow
,
3567 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3568 if (superfluous
&& ghost
==None
) {
3569 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3570 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3571 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3573 XClearWindow(dpy
, scr
->dock_shadow
);
3575 XMapRaised(dpy
, scr
->dock_shadow
);
3578 XUnmapWindow(dpy
, scr
->dock_shadow
);
3580 if (superfluous
&& ghost
!=None
) {
3581 XFreePixmap(dpy
, ghost
);
3593 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3595 XUngrabPointer(dpy
, CurrentTime
);
3596 XUnmapWindow(dpy
, scr
->dock_shadow
);
3597 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3598 if (dock
->type
== WM_DOCK
) {
3601 dock
->on_right_side
= 1;
3603 dock
->on_right_side
= 0;
3605 wArrangeIcons(scr
, False
);
3614 XFreePixmap(dpy
, ghost
);
3615 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3618 puts("End dock move");
3625 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3627 WScreen
*scr
= dock
->screen_ptr
;
3629 WIcon
*icon
= aicon
->icon
;
3630 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3631 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3633 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3634 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3635 int shad_x
= x
, shad_y
= y
;
3636 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3638 Pixmap ghost
= None
;
3640 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3641 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3644 if (wPreferences
.flags
.noupdates
)
3647 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3648 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3649 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3651 wwarning("pointer grab failed for icon move");
3655 if (!(event
->xbutton
.state
& MOD_MASK
))
3656 wRaiseFrame(icon
->core
);
3658 if (!wPreferences
.flags
.noclip
)
3659 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3661 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3663 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3666 wins
[0] = icon
->core
->window
;
3667 wins
[1] = scr
->dock_shadow
;
3668 XRestackWindows(dpy
, wins
, 2);
3669 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3670 ICON_SIZE
, ICON_SIZE
);
3672 if (icon
->pixmap
!=None
)
3673 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3675 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3677 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3678 XClearWindow(dpy
, scr
->dock_shadow
);
3680 XMapWindow(dpy
, scr
->dock_shadow
);
3686 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3687 |ButtonMotionMask
|ExposureMask
, &ev
);
3695 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3696 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3697 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3698 |ButtonReleaseMask
|ButtonPressMask
,
3699 wCursor
[WCUR_MOVE
], CurrentTime
);
3708 for (i
=0; i
<scr
->workspace_count
; i
++) {
3709 if (i
== scr
->current_workspace
)
3711 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3715 x
= ev
.xmotion
.x_root
- ofs_x
;
3716 y
= ev
.xmotion
.y_root
- ofs_y
;
3717 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3720 if (last_dock
!= dock
&& collapsed
) {
3721 last_dock
->collapsed
= 1;
3722 wDockHideIcons(last_dock
);
3725 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3726 dock
->collapsed
= 0;
3727 wDockShowIcons(dock
);
3729 if (dock
->auto_raise_lower
)
3733 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3736 if (last_dock
!= dock2
&& collapsed
) {
3737 last_dock
->collapsed
= 1;
3738 wDockHideIcons(last_dock
);
3741 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3742 dock2
->collapsed
= 0;
3743 wDockShowIcons(dock2
);
3745 if (dock2
->auto_raise_lower
)
3750 if (aicon
->launching
3751 || (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3752 || (!aicon
->running
&& tmp
)) {
3753 shad_x
= last_dock
->x_pos
+ ix
*wPreferences
.icon_size
;
3754 shad_y
= last_dock
->y_pos
+ iy
*wPreferences
.icon_size
;
3756 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3759 XMapWindow(dpy
, scr
->dock_shadow
);
3764 XUnmapWindow(dpy
, scr
->dock_shadow
);
3768 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3775 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3777 XUngrabPointer(dpy
, CurrentTime
);
3779 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3780 XUnmapWindow(dpy
, scr
->dock_shadow
);
3782 reattachIcon(dock
, aicon
, ix
, iy
);
3783 if (clip
&& dock
!=clip
&& clip
->auto_raise_lower
)
3786 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3788 /* Slide it back if dock rejected it */
3789 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3791 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3793 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3801 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3802 /* We need to deselect it, even if is deselected in
3803 * wDockDetach(), because else DoKaboom() will fail.
3805 if (aicon
->icon
->selected
)
3806 wIconSelect(aicon
->icon
);
3807 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3810 if (clip
&& clip
->auto_raise_lower
)
3812 wDockDetach(dock
, aicon
);
3815 last_dock
->collapsed
= 1;
3816 wDockHideIcons(last_dock
);
3821 XFreePixmap(dpy
, ghost
);
3822 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3826 for (i
=0; i
<scr
->workspace_count
; i
++) {
3827 if (i
== scr
->current_workspace
)
3829 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3834 puts("End icon move");
3843 getClipButton(int px
, int py
)
3845 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
3847 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3850 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
3851 return CLIP_FORWARD
;
3852 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
3860 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3863 int done
, direction
, new_ws
;
3865 WDock
*clip
= scr
->clip_icon
->dock
;
3867 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3869 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3870 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3872 wClipIconPaint(scr
->clip_icon
);
3875 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
3876 |ButtonPressMask
, &ev
);
3883 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3884 if (new_dir
!= direction
) {
3885 direction
= new_dir
;
3886 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3887 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3888 wClipIconPaint(scr
->clip_icon
);
3896 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3901 clip
->lclip_button_pushed
= 0;
3902 clip
->rclip_button_pushed
= 0;
3904 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3906 if (direction
== CLIP_FORWARD
) {
3907 if (scr
->current_workspace
< scr
->workspace_count
-1)
3908 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3909 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
3910 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3911 else if (wPreferences
.ws_cycle
)
3912 wWorkspaceChange(scr
, 0);
3914 else if (direction
== CLIP_REWIND
) {
3915 if (scr
->current_workspace
> 0)
3916 wWorkspaceChange(scr
, scr
->current_workspace
-1);
3917 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
3918 wWorkspaceChange(scr
, scr
->workspace_count
-1);
3921 wClipIconPaint(scr
->clip_icon
);
3926 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3928 WAppIcon
*aicon
= desc
->parent
;
3929 WDock
*dock
= aicon
->dock
;
3930 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3932 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3935 scr
->last_dock
= dock
;
3937 if (dock
->menu
->flags
.mapped
)
3938 wMenuUnmap(dock
->menu
);
3940 if (IsDoubleClick(scr
, event
)) {
3941 /* double-click was not in the main clip icon */
3942 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
3943 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
3944 iconDblClick(desc
, event
);
3949 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
3950 XUnmapWindow(dpy
, scr
->clip_balloon
);
3951 scr
->flags
.clip_balloon_mapped
= 0;
3955 puts("handling dock");
3957 if (event
->xbutton
.button
== Button1
) {
3958 if (event
->xbutton
.state
& MOD_MASK
)
3963 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
3964 dock
->type
!=WM_DOCK
) {
3965 wIconSelect(aicon
->icon
);
3969 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
3970 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
3971 && dock
->type
==WM_CLIP
)
3972 handleClipChangeWorkspace(scr
, event
);
3974 handleDockMove(dock
, aicon
, event
);
3976 handleIconMove(dock
, aicon
, event
);
3978 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
3979 aicon
==scr
->clip_icon
) {
3980 openClipWorkspaceMenu(scr
, event
->xbutton
.x_root
+2,
3981 event
->xbutton
.y_root
+2);
3982 if (scr
->clip_ws_menu
) {
3984 menu
= scr
->clip_ws_menu
;
3985 desc
= &menu
->menu
->descriptor
;
3987 event
->xany
.send_event
= True
;
3988 (*desc
->handle_mousedown
)(desc
, event
);
3991 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
3992 (event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
) {
3993 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3995 } else if (event
->xbutton
.button
== Button3
) {
3996 openDockMenu(dock
, aicon
, event
);
4002 showClipBalloon(WDock
*dock
, int workspace
)
4006 WScreen
*scr
= dock
->screen_ptr
;
4010 scr
->flags
.clip_balloon_mapped
= 1;
4011 XMapWindow(dpy
, scr
->clip_balloon
);
4013 text
= scr
->workspaces
[workspace
]->name
;
4015 w
= wTextWidth(scr
->clip_title_font
->font
, text
, strlen(text
));
4017 h
= scr
->clip_title_font
->height
;
4018 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
4020 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
4021 y
= dock
->y_pos
+ ICON_SIZE
-scr
->clip_title_font
->height
- 3;
4023 if (x
+w
> scr
->scr_width
) {
4024 x
= scr
->scr_width
- w
;
4025 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
4026 y
= dock
->y_pos
- h
- 1;
4028 y
= dock
->y_pos
+ ICON_SIZE
;
4029 XRaiseWindow(dpy
, scr
->clip_balloon
);
4031 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
4032 stack
[1] = scr
->clip_balloon
;
4033 XRestackWindows(dpy
, stack
, 2);
4035 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
4036 XSetForeground(dpy
, scr
->clip_title_gc
,
4037 scr
->clip_title_pixel
[CLIP_NORMAL
]);
4038 XClearWindow(dpy
, scr
->clip_balloon
);
4039 wDrawString(scr
->clip_balloon
, scr
->clip_title_font
, scr
->clip_title_gc
,
4040 0, scr
->clip_title_font
->y
, text
, strlen(text
));
4045 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
4047 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4051 assert(event
->type
==EnterNotify
);
4053 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4056 scr
= btn
->icon
->core
->screen_ptr
;
4057 if (!btn
->omnipresent
)
4060 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
4062 if (!dock
|| dock
->type
!=WM_CLIP
)
4065 /* The auto raise/lower code */
4066 if (dock
->auto_lower_magic
) {
4067 WMDeleteTimerHandler(dock
->auto_lower_magic
);
4068 dock
->auto_lower_magic
= NULL
;
4070 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
4071 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
,
4076 /* The auto expand/collapse code */
4077 if (dock
->auto_collapse_magic
) {
4078 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
4079 dock
->auto_collapse_magic
= NULL
;
4081 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
4082 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
,
4087 if (btn
->xindex
== 0 && btn
->yindex
== 0)
4088 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4090 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4091 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
4092 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
4099 clipLeave(WDock
*dock
)
4102 WObjDescriptor
*desc
= NULL
;
4104 if (!dock
|| dock
->type
!=WM_CLIP
)
4107 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
)!=False
) {
4108 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
4109 (XPointer
*)&desc
)!=XCNOENT
4110 && desc
&& desc
->parent_type
==WCLASS_DOCK_ICON
4111 && ((WAppIcon
*)desc
->parent
)->dock
4112 && ((WAppIcon
*)desc
->parent
)->dock
->type
==WM_CLIP
) {
4113 /* We didn't left the Clip yet */
4114 XPutBackEvent(dpy
, &event
);
4118 XPutBackEvent(dpy
, &event
);
4120 /* We entered a withdrawn window, so we're still in Clip */
4124 if (dock
->auto_raise_magic
) {
4125 WMDeleteTimerHandler(dock
->auto_raise_magic
);
4126 dock
->auto_raise_magic
= NULL
;
4128 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
4129 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
,
4134 if (dock
->auto_expand_magic
) {
4135 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4136 dock
->auto_expand_magic
= NULL
;
4138 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
4139 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
4147 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4149 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4151 assert(event
->type
==LeaveNotify
);
4153 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4156 clipLeave(btn
->dock
);
4161 clipAutoCollapse(void *cdata
)
4163 WDock
*dock
= (WDock
*)cdata
;
4165 if (dock
->type
!=WM_CLIP
)
4168 if (dock
->auto_collapse
) {
4169 dock
->collapsed
= 1;
4170 wDockHideIcons(dock
);
4172 dock
->auto_collapse_magic
= NULL
;
4177 clipAutoExpand(void *cdata
)
4179 WDock
*dock
= (WDock
*)cdata
;
4181 if (dock
->type
!=WM_CLIP
)
4184 if (dock
->auto_collapse
) {
4185 dock
->collapsed
= 0;
4186 wDockShowIcons(dock
);
4188 dock
->auto_expand_magic
= NULL
;
4193 clipAutoLower(void *cdata
)
4195 WDock
*dock
= (WDock
*)cdata
;
4197 if (dock
->type
!=WM_CLIP
)
4200 if (dock
->auto_raise_lower
)
4203 dock
->auto_lower_magic
= NULL
;
4208 clipAutoRaise(void *cdata
)
4210 WDock
*dock
= (WDock
*)cdata
;
4212 if (dock
->type
!=WM_CLIP
)
4215 if (dock
->auto_raise_lower
)
4218 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4219 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4222 dock
->auto_raise_magic
= NULL
;
4227 iconCanBeOmnipresent(WAppIcon
*aicon
)
4229 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4234 for (i
=0; i
<scr
->workspace_count
; i
++) {
4235 clip
= scr
->workspaces
[i
]->clip
;
4237 if (clip
== aicon
->dock
)
4240 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4241 return False
; /* Clip is full in some workspace */
4243 for (j
=0; j
<clip
->max_icons
; j
++) {
4244 btn
= clip
->icon_array
[j
];
4245 if(btn
&& btn
->xindex
==aicon
->xindex
&& btn
->yindex
==aicon
->yindex
)
4255 wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
4257 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4258 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4259 int status
= WO_SUCCESS
;
4261 if (aicon
->dock
== scr
->dock
|| aicon
== scr
->clip_icon
)
4262 return WO_NOT_APPLICABLE
;
4264 if (aicon
->omnipresent
== omnipresent
)
4268 if (iconCanBeOmnipresent(aicon
)) {
4269 aicon
->omnipresent
= 1;
4270 new_entry
= wmalloc(sizeof(WAppIconChain
));
4271 new_entry
->aicon
= aicon
;
4272 new_entry
->next
= NULL
;
4273 if (!scr
->global_icons
) {
4274 scr
->global_icons
= new_entry
;
4276 tmp
= scr
->global_icons
;
4280 tmp
->next
= new_entry
;
4282 scr
->global_icon_count
++;
4284 aicon
->omnipresent
= 0;
4288 aicon
->omnipresent
= 0;
4289 if (aicon
== scr
->global_icons
->aicon
) {
4290 tmp
= scr
->global_icons
->next
;
4291 free(scr
->global_icons
);
4292 scr
->global_icons
= tmp
;
4293 scr
->global_icon_count
--;
4295 tmp
= scr
->global_icons
;
4297 if (tmp
->next
->aicon
== aicon
) {
4298 tmp1
= tmp
->next
->next
;
4301 scr
->global_icon_count
--;