1 /* dock.c- built-in Dock module for WindowMaker
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 * Copyright (c) 1998, 1999 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
28 #include <X11/Xutil.h>
36 #define PATH_MAX DEFAULT_PATH_MAX
39 #include "WindowMaker.h"
49 #include "properties.h"
53 #include "workspace.h"
55 #include "superfluous.h"
64 /**** Local variables ****/
67 #define CLIP_FORWARD 2
70 /**** Global variables ****/
73 extern void DestroyDockAppSettingsPanel();
75 extern void ShowDockAppSettingsPanel(WAppIcon
*aicon
);
78 extern XContext wWinContext
;
80 extern Cursor wCursor
[WCUR_LAST
];
82 extern WPreferences wPreferences
;
84 extern XContext wWinContext
;
87 extern Atom _XA_DND_PROTOCOL
;
91 #define MOD_MASK wPreferences.modifier_mask
93 extern void appIconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
95 #define ICON_SIZE wPreferences.icon_size
98 /***** Local variables ****/
100 static proplist_t dCommand
=NULL
;
102 static proplist_t dDropCommand
=NULL
;
104 static proplist_t dAutoLaunch
, dLock
;
105 static proplist_t dName
, dForced
, dBuggyApplication
, dYes
, dNo
;
106 static proplist_t dHost
, dDock
, dClip
;
107 static proplist_t dAutoAttractIcons
;
109 static proplist_t dPosition
, dApplications
, dLowered
, dCollapsed
, dAutoCollapse
;
111 static proplist_t dAutoRaiseLower
, dOmnipresent
;
113 static void dockIconPaint(WAppIcon
*btn
);
115 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
117 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
);
119 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
121 static int getClipButton(int px
, int py
);
123 static void toggleLowered(WDock
*dock
);
125 static void toggleCollapsed(WDock
*dock
);
127 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
129 static void clipLeave(WDock
*dock
);
131 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
133 Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
);
135 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
136 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
137 static void clipAutoCollapse(void *cdata
);
138 static void clipAutoExpand(void *cdata
);
139 static void launchDockedApplication(WAppIcon
*btn
);
141 static void clipAutoLower(void *cdata
);
142 static void clipAutoRaise(void *cdata
);
144 static void showClipBalloon(WDock
*dock
, int workspace
);
160 #endif /* OFFIX_DND */
170 dCommand
= PLRetain(PLMakeString("Command"));
172 dDropCommand
= PLRetain(PLMakeString("DropCommand"));
174 dLock
= PLRetain(PLMakeString("Lock"));
175 dAutoLaunch
= PLRetain(PLMakeString("AutoLaunch"));
176 dName
= PLRetain(PLMakeString("Name"));
177 dForced
= PLRetain(PLMakeString("Forced"));
178 dBuggyApplication
= PLRetain(PLMakeString("BuggyApplication"));
179 dYes
= PLRetain(PLMakeString("Yes"));
180 dNo
= PLRetain(PLMakeString("No"));
181 dHost
= PLRetain(PLMakeString("Host"));
183 dPosition
= PLMakeString("Position");
184 dApplications
= PLMakeString("Applications");
185 dLowered
= PLMakeString("Lowered");
186 dCollapsed
= PLMakeString("Collapsed");
187 dAutoCollapse
= PLMakeString("AutoCollapse");
188 dAutoRaiseLower
= PLMakeString("AutoRaiseLower");
189 dAutoAttractIcons
= PLMakeString("AutoAttractIcons");
191 dOmnipresent
= PLMakeString("Omnipresent");
193 dDock
= PLMakeString("Dock");
194 dClip
= PLMakeString("Clip");
200 renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
202 WDock
*dock
= entry
->clientdata
;
207 assert(entry
->clientdata
!=NULL
);
209 wspace
= dock
->screen_ptr
->current_workspace
;
211 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
213 sprintf(buffer
, _("Type the name for workspace %i:"), wspace
+1);
214 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
,
216 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
225 toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
227 assert(entry
->clientdata
!=NULL
);
229 toggleLowered(entry
->clientdata
);
237 killCallback(WMenu
*menu
, WMenuEntry
*entry
)
240 #ifdef REDUCE_APPICONS
241 WAppIconAppList
*tapplist
;
243 extern Atom _XA_WM_DELETE_WINDOW
;
248 if (!WCHECK_STATE(WSTATE_NORMAL
))
251 assert(entry
->clientdata
!=NULL
);
253 icon
= (WAppIcon
*)entry
->clientdata
;
257 WCHANGE_STATE(WSTATE_MODAL
);
259 #ifdef REDUCE_APPICONS
260 /* Send a delete message to the main window of each application
261 * bound to this docked appicon. - cls
263 tapplist
= icon
->applist
;
264 while (tapplist
!= NULL
) {
265 if (tapplist
->wapp
->main_window_desc
!= NULL
) {
266 if (tapplist
->wapp
->main_window_desc
->protocols
.DELETE_WINDOW
) {
267 wClientSendProtocol(tapplist
->wapp
->main_window_desc
,
268 _XA_WM_DELETE_WINDOW
, CurrentTime
);
270 wClientKill(tapplist
->wapp
->main_window_desc
);
273 tapplist
= tapplist
->next
;
276 buffer
= wstrconcat(icon
->wm_class
,
277 _(" will be forcibly closed.\n"
278 "Any unsaved changes will be lost.\n"
281 if (wPreferences
.dont_confirm_kill
282 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
283 buffer
, _("Yes"), _("No"), NULL
)==WAPRDefault
) {
284 if (icon
->icon
&& icon
->icon
->owner
) {
285 wClientKill(icon
->icon
->owner
);
290 #endif /* !REDUCE_APPICONS */
294 WCHANGE_STATE(WSTATE_NORMAL
);
298 /* TODO: replace this function with a member of the dock struct */
300 numberOfSelectedIcons(WDock
*dock
)
306 for (i
=1; i
<dock
->max_icons
; i
++) {
307 aicon
= dock
->icon_array
[i
];
308 if (aicon
&& aicon
->icon
->selected
) {
318 getSelected(WDock
*dock
)
320 WMBag
*ret
= WMCreateBag(8);
324 for (i
=1; i
<dock
->max_icons
; i
++) {
325 btn
= dock
->icon_array
[i
];
326 if (btn
&& btn
->icon
->selected
) {
327 WMPutInBag(ret
, btn
);
336 paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
338 Window win
= clipIcon
->icon
->core
->window
;
339 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
341 int pt
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
342 int tp
= ICON_SIZE
- pt
;
343 int as
= pt
- 15; /* 15 = 5+5+5 */
344 GC gc
= scr
->clip_title_gc
;
345 #ifdef GRADIENT_CLIP_ARROW
346 Bool collapsed
= clipIcon
->dock
->collapsed
;
352 p
[1].x
= ICON_SIZE
-2;
354 p
[2].x
= ICON_SIZE
-2;
356 } else if (lpushed
) {
360 p
[1].y
= ICON_SIZE
-2;
362 p
[2].y
= ICON_SIZE
-2;
364 if (lpushed
|| rpushed
) {
365 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
366 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
367 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
369 #ifdef GRADIENT_CLIP_ARROW
371 XSetFillStyle(dpy
, scr
->copy_gc
, FillTiled
);
372 XSetTile(dpy
, scr
->copy_gc
, scr
->clip_arrow_gradient
);
373 XSetClipMask(dpy
, scr
->copy_gc
, None
);
376 #endif /* GRADIENT_CLIP_ARROW */
378 /* top right arrow */
379 p
[0].x
= p
[3].x
= ICON_SIZE
-5-as
;
381 p
[1].x
= ICON_SIZE
-6;
383 p
[2].x
= ICON_SIZE
-6;
386 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
387 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
389 #ifdef GRADIENT_CLIP_ARROW
391 XSetTSOrigin(dpy
, gc
, ICON_SIZE
-6-as
, 5);
393 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
394 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
397 /* bottom left arrow */
399 p
[0].y
= p
[3].y
= ICON_SIZE
-5-as
;
401 p
[1].y
= ICON_SIZE
-6;
403 p
[2].y
= ICON_SIZE
-6;
405 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
406 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
408 #ifdef GRADIENT_CLIP_ARROW
410 XSetTSOrigin(dpy
, gc
, 5, ICON_SIZE
-6-as
);
412 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
413 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
415 #ifdef GRADIENT_CLIP_ARROW
417 XSetFillStyle(dpy
, scr
->copy_gc
, FillSolid
);
423 wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
425 RImage
*tile
= RCloneImage(normalTile
);
432 pt
= CLIP_BUTTON_SIZE
*wPreferences
.icon_size
/64;
433 tp
= wPreferences
.icon_size
-1 - pt
;
437 black
.red
= black
.green
= black
.blue
= 0;
440 dark
.red
= dark
.green
= dark
.blue
= 60;
443 light
.red
= light
.green
= light
.blue
= 80;
447 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
-2,
449 RDrawLine(tile
, tp
-1, 0, wPreferences
.icon_size
-1, pt
+1, &black
);
450 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
-3,
454 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4,
455 ICON_SIZE
- 5, 4, &dark
);
456 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5,
457 ICON_SIZE
- 5, 6 + as
, &dark
);
458 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
,
462 ROperateLine(tile
, RAddOperation
, 2, tp
+2, pt
-2,
463 wPreferences
.icon_size
-3, &dark
);
464 RDrawLine(tile
, 0, tp
-1, pt
+1, wPreferences
.icon_size
-1, &black
);
465 ROperateLine(tile
, RSubtractOperation
, 0, tp
-2, pt
+1,
466 wPreferences
.icon_size
-2, &light
);
469 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4,
470 ICON_SIZE
- 5, &dark
);
471 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
,
472 6 + as
, ICON_SIZE
- 5, &dark
);
473 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5,
481 omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
483 WAppIcon
*clickedIcon
= entry
->clientdata
;
486 WMBag
*selectedIcons
;
490 assert(entry
->clientdata
!=NULL
);
492 dock
= clickedIcon
->dock
;
494 selectedIcons
= getSelected(dock
);
496 if (!WMGetBagItemCount(selectedIcons
))
497 WMPutInBag(selectedIcons
, clickedIcon
);
500 for (i
= 0; i
< WMGetBagItemCount(selectedIcons
); i
++) {
501 aicon
= WMGetFromBag(selectedIcons
, i
);
503 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
505 else if (aicon
->icon
->selected
)
506 wIconSelect(aicon
->icon
);
508 WMFreeBag(selectedIcons
);
511 wMessageDialog(dock
->screen_ptr
, _("Warning"),
512 _("Some icons cannot be made omnipresent. "
513 "Please make sure that no other icon is "
514 "docked in the same positions on the other "
515 "workspaces and the Clip is not full in "
517 _("OK"), NULL
, NULL
);
518 } else if (failed
== 1) {
519 wMessageDialog(dock
->screen_ptr
, _("Warning"),
520 _("Icon cannot be made omnipresent. "
521 "Please make sure that no other icon is "
522 "docked in the same position on the other "
523 "workspaces and the Clip is not full in "
525 _("OK"), NULL
, NULL
);
531 removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
533 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
536 WMBag
*selectedIcons
;
540 assert(clickedIcon
!=NULL
);
542 dock
= clickedIcon
->dock
;
544 selectedIcons
= getSelected(dock
);
546 if (WMGetBagItemCount(selectedIcons
)) {
547 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
548 _("All selected icons will be removed!"),
549 _("OK"), _("Cancel"), NULL
)!=WAPRDefault
) {
550 WMFreeBag(selectedIcons
);
554 if (clickedIcon
->xindex
==0 && clickedIcon
->yindex
==0) {
555 WMFreeBag(selectedIcons
);
558 WMPutInBag(selectedIcons
, clickedIcon
);
561 WM_ITERATE_BAG(selectedIcons
, aicon
, it
) {
562 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
563 wDockDetach(dock
, aicon
);
565 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
566 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
567 aicon
->x_pos
, aicon
->y_pos
);
568 if (!dock
->mapped
|| dock
->collapsed
)
569 XMapWindow(dpy
, aicon
->icon
->core
->window
);
572 WMFreeBag(selectedIcons
);
574 if (wPreferences
.auto_arrange_icons
)
575 wArrangeIcons(dock
->screen_ptr
, True
);
580 keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
582 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
585 WMBag
*selectedIcons
;
588 assert(clickedIcon
!=NULL
);
589 dock
= clickedIcon
->dock
;
591 selectedIcons
= getSelected(dock
);
593 if (!WMGetBagItemCount(selectedIcons
)
594 && clickedIcon
!=dock
->screen_ptr
->clip_icon
) {
595 char *command
= NULL
;
597 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
598 clickedIcon
->editing
= 1;
599 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
600 _("Type the command used to launch the application"),
602 if (command
&& (command
[0]==0 ||
603 (command
[0]=='-' && command
[1]==0))) {
607 clickedIcon
->command
= command
;
608 clickedIcon
->editing
= 0;
610 clickedIcon
->editing
= 0;
613 WMFreeBag(selectedIcons
);
618 WMPutInBag(selectedIcons
, clickedIcon
);
621 WM_ITERATE_BAG(selectedIcons
, aicon
, it
) {
622 if (aicon
->icon
->selected
)
623 wIconSelect(aicon
->icon
);
624 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
625 aicon
->attracted
= 0;
626 if (aicon
->icon
->shadowed
) {
627 aicon
->icon
->shadowed
= 0;
628 aicon
->icon
->force_paint
= 1;
629 wAppIconPaint(aicon
);
633 WMFreeBag(selectedIcons
);
640 toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
642 WDock
*dock
= (WDock
*)entry
->clientdata
;
644 assert(entry
->clientdata
!=NULL
);
646 dock
->attract_icons
= !dock
->attract_icons
;
647 /*if (!dock->attract_icons)
648 dock->keep_attracted = 0;*/
650 entry
->flags
.indicator_on
= dock
->attract_icons
;
657 selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
659 WAppIcon
*icon
= (WAppIcon
*)entry
->clientdata
;
663 wIconSelect(icon
->icon
);
670 colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
672 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
675 int x
, y
, x_pos
, y_pos
;
677 assert(entry
->clientdata
!=NULL
);
678 clip
= clickedIcon
->dock
;
680 aicon
= clip
->screen_ptr
->app_icon_list
;
683 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
684 x_pos
= clip
->x_pos
+ x
*ICON_SIZE
;
685 y_pos
= clip
->y_pos
+ y
*ICON_SIZE
;
686 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
688 if (wPreferences
.no_animations
) {
689 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
691 SlideWindow(aicon
->icon
->core
->window
,
692 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
695 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
696 #endif /* ANIMATIONS */
698 aicon
->attracted
= 1;
699 if (!aicon
->icon
->shadowed
) {
700 aicon
->icon
->shadowed
= 1;
701 aicon
->icon
->force_paint
= 1;
702 /* We don't do an wAppIconPaint() here because it's in
703 * wDockAttachIcon(). -Dan
706 wDockAttachIcon(clip
, aicon
, x
, y
);
707 if (clip
->collapsed
|| !clip
->mapped
)
708 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
716 selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
718 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
720 WMBag
*selectedIcons
;
724 assert(clickedIcon
!=NULL
);
725 dock
= clickedIcon
->dock
;
727 selectedIcons
= getSelected(dock
);
729 if (!WMGetBagItemCount(selectedIcons
)) {
730 for (i
=1; i
<dock
->max_icons
; i
++) {
731 btn
= dock
->icon_array
[i
];
732 if (btn
&& !btn
->icon
->selected
) {
733 wIconSelect(btn
->icon
);
737 for (i
= 0; i
< WMGetBagItemCount(selectedIcons
); i
++) {
738 btn
= WMGetFromBag(selectedIcons
, i
);
739 wIconSelect(btn
->icon
);
742 WMFreeBag(selectedIcons
);
749 toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
751 assert(entry
->clientdata
!=NULL
);
753 toggleCollapsed(entry
->clientdata
);
755 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->collapsed
;
762 toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
765 assert(entry
->clientdata
!=NULL
);
767 dock
= (WDock
*) entry
->clientdata
;
769 dock
->auto_collapse
= !dock
->auto_collapse
;
771 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_collapse
;
778 toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
781 assert(entry
->clientdata
!=NULL
);
783 dock
= (WDock
*) entry
->clientdata
;
785 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
787 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_raise_lower
;
794 launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
796 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
798 launchDockedApplication(btn
);
803 settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
805 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
809 ShowDockAppSettingsPanel(btn
);
814 hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
817 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
819 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
821 if (wapp
->flags
.hidden
) {
822 wWorkspaceChange(btn
->icon
->core
->screen_ptr
,wapp
->last_workspace
);
823 wUnhideApplication(wapp
, False
, False
);
825 wHideApplication(wapp
);
831 unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
834 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
836 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
838 wUnhideApplication(wapp
, False
, True
);
843 mainIconCreate(WScreen
*scr
, int type
)
848 if (type
== WM_CLIP
) {
850 return scr
->clip_icon
;
851 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
852 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
853 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
854 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
855 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE;*/
858 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
859 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
865 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
866 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
867 btn
->icon
->core
->descriptor
.parent
= btn
;
868 /*ChangeStackingLevel(btn->icon->core, WMDockLevel);*/
869 XMapWindow(dpy
, btn
->icon
->core
->window
);
874 scr
->clip_icon
= btn
;
881 switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
883 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
884 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
886 WMBag
*selectedIcons
;
889 if (entry
->order
== scr
->current_workspace
)
892 dest
= scr
->workspaces
[entry
->order
]->clip
;
894 selectedIcons
= getSelected(src
);
896 if (WMGetBagItemCount(selectedIcons
)) {
898 for (i
= 0; i
< WMGetBagItemCount(selectedIcons
); i
++) {
899 btn
= WMGetFromBag(selectedIcons
, i
);
900 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
901 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
902 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
905 } else if (icon
!= scr
->clip_icon
) {
906 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
907 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
908 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
911 WMFreeBag(selectedIcons
);
917 launchDockedApplication(WAppIcon
*btn
)
919 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
921 if (!btn
->launching
&& btn
->command
!=NULL
) {
922 if (!btn
->forced_dock
) {
923 btn
->relaunching
= btn
->running
;
926 if (btn
->wm_instance
|| btn
->wm_class
) {
927 WWindowAttributes attr
;
928 memset(&attr
, 0, sizeof(WWindowAttributes
));
929 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
,
932 if (!attr
.no_appicon
&& !btn
->buggy_app
)
937 btn
->drop_launch
= 0;
938 scr
->last_dock
= btn
->dock
;
939 btn
->pid
= execCommand(btn
, btn
->command
, NULL
);
941 if (btn
->buggy_app
) {
942 /* give feedback that the app was launched */
946 WMAddTimerHandler(200, (WMCallback
*)dockIconPaint
, btn
);
951 wwarning(_("could not launch application %s\n"), btn
->command
);
953 if (!btn
->relaunching
)
962 updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
964 WScreen
*scr
= menu
->frame
->screen_ptr
;
965 char title
[MAX_WORKSPACENAME_WIDTH
+1];
971 for (i
=0; i
<scr
->workspace_count
; i
++) {
972 if (i
< menu
->entry_no
) {
973 if (strcmp(menu
->entries
[i
]->text
,scr
->workspaces
[i
]->name
)!=0) {
974 wfree(menu
->entries
[i
]->text
);
975 strcpy(title
, scr
->workspaces
[i
]->name
);
976 menu
->entries
[i
]->text
= wstrdup(title
);
977 menu
->flags
.realized
= 0;
979 menu
->entries
[i
]->clientdata
= (void*)icon
;
981 strcpy(title
, scr
->workspaces
[i
]->name
);
983 wMenuAddCallback(menu
, title
, switchWSCommand
, (void*)icon
);
985 menu
->flags
.realized
= 0;
987 if (i
== scr
->current_workspace
) {
988 wMenuSetEnabled(menu
, i
, False
);
990 wMenuSetEnabled(menu
, i
, True
);
994 if (!menu
->flags
.realized
)
1000 makeWorkspaceMenu(WScreen
*scr
)
1004 menu
= wMenuCreate(scr
, NULL
, False
);
1006 wwarning(_("could not create workspace submenu for Clip menu"));
1008 wMenuAddCallback(menu
, "", switchWSCommand
, (void*)scr
->clip_icon
);
1010 menu
->flags
.realized
= 0;
1018 updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
1027 entry
= menu
->entries
[index
];
1028 if (dock
->lowered
) {
1029 entry
->text
= _("Keep on Top");
1031 entry
->text
= _("Allow Lowering");
1033 entry
->clientdata
= dock
;
1036 entry
= menu
->entries
[++index
];
1037 entry
->flags
.indicator_on
= dock
->collapsed
;
1038 entry
->clientdata
= dock
;
1041 entry
= menu
->entries
[++index
];
1042 entry
->flags
.indicator_on
= dock
->auto_collapse
;
1043 entry
->clientdata
= dock
;
1045 /* auto-raise/lower */
1046 entry
= menu
->entries
[++index
];
1047 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1048 entry
->clientdata
= dock
;
1051 entry
= menu
->entries
[++index
];
1052 entry
->flags
.indicator_on
= dock
->attract_icons
;
1053 entry
->clientdata
= dock
;
1055 menu
->flags
.realized
= 0;
1061 makeClipOptionsMenu(WScreen
*scr
)
1066 menu
= wMenuCreate(scr
, NULL
, False
);
1068 wwarning(_("could not create options submenu for Clip menu"));
1072 entry
= wMenuAddCallback(menu
, _("Keep on Top"),
1073 toggleLoweredCallback
, NULL
);
1075 entry
= wMenuAddCallback(menu
, _("Collapsed"),
1076 toggleCollapsedCallback
, NULL
);
1077 entry
->flags
.indicator
= 1;
1078 entry
->flags
.indicator_on
= 1;
1079 entry
->flags
.indicator_type
= MI_CHECK
;
1081 entry
= wMenuAddCallback(menu
, _("AutoCollapse"),
1082 toggleAutoCollapseCallback
, NULL
);
1083 entry
->flags
.indicator
= 1;
1084 entry
->flags
.indicator_on
= 1;
1085 entry
->flags
.indicator_type
= MI_CHECK
;
1087 entry
= wMenuAddCallback(menu
, _("AutoRaiseLower"),
1088 toggleAutoRaiseLowerCallback
, NULL
);
1089 entry
->flags
.indicator
= 1;
1090 entry
->flags
.indicator_on
= 1;
1091 entry
->flags
.indicator_type
= MI_CHECK
;
1093 entry
= wMenuAddCallback(menu
, _("AutoAttract Icons"),
1094 toggleAutoAttractCallback
, NULL
);
1095 entry
->flags
.indicator
= 1;
1096 entry
->flags
.indicator_on
= 1;
1097 entry
->flags
.indicator_type
= MI_CHECK
;
1099 menu
->flags
.realized
= 0;
1107 dockMenuCreate(WScreen
*scr
, int type
)
1112 if (type
== WM_CLIP
&& scr
->clip_menu
)
1113 return scr
->clip_menu
;
1115 menu
= wMenuCreate(scr
, NULL
, False
);
1116 if (type
!= WM_CLIP
) {
1117 entry
= wMenuAddCallback(menu
, _("Keep on Top"),
1118 toggleLoweredCallback
, NULL
);
1120 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1121 scr
->clip_options
= makeClipOptionsMenu(scr
);
1122 if (scr
->clip_options
)
1123 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1125 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
,
1128 entry
->text
= _("Rename Workspace");
1130 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1131 entry
->flags
.indicator
= 1;
1132 entry
->flags
.indicator_on
= 1;
1133 entry
->flags
.indicator_type
= MI_CHECK
;
1135 entry
= wMenuAddCallback(menu
, _("Select All Icons"),
1136 selectIconsCallback
, NULL
);
1138 entry
->text
= _("Select All Icons");
1140 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1142 entry
->text
= _("Keep Icon");
1144 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1146 entry
->text
= _("Move Icon To");
1147 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1148 if (scr
->clip_submenu
)
1149 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1151 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
,
1154 entry
->text
= _("Remove Icon");
1156 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1159 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1161 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1163 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1165 entry
->text
= _("Hide");
1167 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1169 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1171 if (type
== WM_CLIP
)
1172 scr
->clip_menu
= menu
;
1179 wDockCreate(WScreen
*scr
, int type
)
1187 dock
= wmalloc(sizeof(WDock
));
1188 memset(dock
, 0, sizeof(WDock
));
1190 if (type
== WM_CLIP
)
1191 icon_count
= CLIP_MAX_ICONS
;
1193 icon_count
= scr
->scr_height
/wPreferences
.icon_size
;
1195 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*)*icon_count
);
1196 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*)*icon_count
);
1198 dock
->max_icons
= icon_count
;
1200 btn
= mainIconCreate(scr
, type
);
1204 dock
->x_pos
= btn
->x_pos
;
1205 dock
->y_pos
= btn
->y_pos
;
1206 dock
->screen_ptr
= scr
;
1208 dock
->icon_count
= 1;
1209 dock
->on_right_side
= 1;
1210 dock
->collapsed
= 0;
1211 dock
->auto_collapse
= 0;
1212 dock
->auto_collapse_magic
= NULL
;
1213 dock
->auto_raise_lower
= 0;
1214 dock
->auto_lower_magic
= NULL
;
1215 dock
->auto_raise_magic
= NULL
;
1216 dock
->attract_icons
= 0;
1218 dock
->icon_array
[0] = btn
;
1219 wRaiseFrame(btn
->icon
->core
);
1220 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1222 /* create dock menu */
1223 dock
->menu
= dockMenuCreate(scr
, type
);
1230 wDockDestroy(WDock
*dock
)
1235 for (i
=(dock
->type
== WM_CLIP
) ? 1 : 0; i
<dock
->max_icons
; i
++) {
1236 aicon
= dock
->icon_array
[i
];
1238 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1239 wDockDetach(dock
, aicon
);
1241 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
1242 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
1243 aicon
->x_pos
, aicon
->y_pos
);
1244 if (!dock
->mapped
|| dock
->collapsed
)
1245 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1249 if (wPreferences
.auto_arrange_icons
)
1250 wArrangeIcons(dock
->screen_ptr
, True
);
1251 wfree(dock
->icon_array
);
1252 if (dock
->menu
&& dock
->type
!=WM_CLIP
)
1253 wMenuDestroy(dock
->menu
, True
);
1254 if (dock
->screen_ptr
->last_dock
== dock
)
1255 dock
->screen_ptr
->last_dock
= NULL
;
1261 wClipIconPaint(WAppIcon
*aicon
)
1263 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1264 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1266 Window win
= aicon
->icon
->core
->window
;
1267 int length
, nlength
;
1268 char *ws_name
, ws_number
[10];
1271 wIconPaint(aicon
->icon
);
1273 length
= strlen(workspace
->name
);
1274 ws_name
= malloc(length
+ 1);
1275 sprintf(ws_name
, "%s", workspace
->name
);
1276 sprintf(ws_number
, "%i", scr
->current_workspace
+ 1);
1277 nlength
= strlen(ws_number
);
1279 gc
= scr
->clip_title_gc
;
1281 if (!workspace
->clip
->collapsed
)
1282 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_NORMAL
]);
1284 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_COLLAPSED
]);
1286 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1288 tx
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
1290 WMDrawString(scr
->wmscreen
, win
, gc
, scr
->clip_title_font
, tx
,
1291 ty
, ws_name
, length
);
1293 tx
= (ICON_SIZE
/2 - WMWidthOfString(scr
->clip_title_font
, ws_number
,
1296 WMDrawString(scr
->wmscreen
, win
, gc
, scr
->clip_title_font
, tx
,
1297 2, ws_number
, nlength
);
1301 if (aicon
->launching
) {
1302 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1303 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1305 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
,
1306 aicon
->dock
->rclip_button_pushed
);
1311 clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1313 wClipIconPaint(desc
->parent
);
1318 dockIconPaint(WAppIcon
*btn
)
1320 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1321 wClipIconPaint(btn
);
1328 make_icon_state(WAppIcon
*btn
)
1330 proplist_t node
= NULL
;
1331 proplist_t command
, autolaunch
, lock
, name
, forced
, host
, position
, buggy
;
1332 proplist_t omnipresent
;
1338 command
= PLMakeString("-");
1340 command
= PLMakeString(btn
->command
);
1342 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1344 lock
= btn
->lock
? dYes
: dNo
;
1346 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1348 name
= PLMakeString(tmp
);
1352 forced
= btn
->forced_dock
? dYes
: dNo
;
1354 buggy
= btn
->buggy_app
? dYes
: dNo
;
1356 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1357 sprintf(buffer
, "%i,%i", btn
->x_pos
, btn
->y_pos
);
1359 sprintf(buffer
, "%hi,%hi", btn
->xindex
, btn
->yindex
);
1360 position
= PLMakeString(buffer
);
1362 node
= PLMakeDictionaryFromEntries(dCommand
, command
,
1364 dAutoLaunch
, autolaunch
,
1367 dBuggyApplication
, buggy
,
1368 dPosition
, position
,
1372 PLRelease(position
);
1374 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1375 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&&
1376 (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1377 PLInsertDictionaryEntry(node
, dOmnipresent
, omnipresent
);
1380 if (btn
->dnd_command
) {
1381 command
= PLMakeString(btn
->dnd_command
);
1382 PLInsertDictionaryEntry(node
, dDropCommand
, command
);
1385 #endif /* OFFIX_DND */
1387 if (btn
->client_machine
&& btn
->remote_start
) {
1388 host
= PLMakeString(btn
->client_machine
);
1389 PLInsertDictionaryEntry(node
, dHost
, host
);
1399 dockSaveState(WDock
*dock
)
1402 proplist_t icon_info
;
1403 proplist_t list
=NULL
, dock_state
=NULL
;
1404 proplist_t value
, key
;
1407 list
= PLMakeArrayFromElements(NULL
);
1409 for (i
=(dock
->type
==WM_DOCK
? 0 : 1); i
<dock
->max_icons
; i
++) {
1410 WAppIcon
*btn
= dock
->icon_array
[i
];
1412 if (!btn
|| btn
->attracted
)
1415 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1416 list
= PLAppendArrayElement(list
, icon_info
);
1417 PLRelease(icon_info
);
1421 dock_state
= PLMakeDictionaryFromEntries(dApplications
, list
,
1424 if (dock
->type
== WM_DOCK
) {
1425 sprintf(buffer
, "Applications%i", dock
->screen_ptr
->scr_height
);
1426 key
= PLMakeString(buffer
);
1427 PLInsertDictionaryEntry(dock_state
, key
, list
);
1431 sprintf(buffer
, "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0),
1433 value
= PLMakeString(buffer
);
1434 PLInsertDictionaryEntry(dock_state
, dPosition
, value
);
1440 value
= (dock
->lowered
? dYes
: dNo
);
1441 PLInsertDictionaryEntry(dock_state
, dLowered
, value
);
1443 if (dock
->type
== WM_CLIP
) {
1444 value
= (dock
->collapsed
? dYes
: dNo
);
1445 PLInsertDictionaryEntry(dock_state
, dCollapsed
, value
);
1447 value
= (dock
->auto_collapse
? dYes
: dNo
);
1448 PLInsertDictionaryEntry(dock_state
, dAutoCollapse
, value
);
1450 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1451 PLInsertDictionaryEntry(dock_state
, dAutoRaiseLower
, value
);
1453 value
= (dock
->attract_icons
? dYes
: dNo
);
1454 PLInsertDictionaryEntry(dock_state
, dAutoAttractIcons
, value
);
1462 wDockSaveState(WScreen
*scr
, proplist_t old_state
)
1464 proplist_t dock_state
;
1467 dock_state
= dockSaveState(scr
->dock
);
1470 * Copy saved states of docks with different sizes.
1476 keys
= PLGetAllDictionaryKeys(old_state
);
1477 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
1478 tmp
= PLGetArrayElement(keys
, i
);
1480 if (strncasecmp(PLGetString(tmp
), "applications", 12) == 0
1481 && !PLGetDictionaryEntry(dock_state
, tmp
)) {
1483 PLInsertDictionaryEntry(dock_state
,
1485 PLGetDictionaryEntry(old_state
, tmp
));
1492 PLInsertDictionaryEntry(scr
->session_state
, dDock
, dock_state
);
1494 PLRelease(dock_state
);
1499 wClipSaveState(WScreen
*scr
)
1501 proplist_t clip_state
;
1503 clip_state
= make_icon_state(scr
->clip_icon
);
1505 PLInsertDictionaryEntry(scr
->session_state
, dClip
, clip_state
);
1507 PLRelease(clip_state
);
1512 wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1514 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1519 getBooleanDockValue(proplist_t value
, proplist_t key
)
1522 if (PLIsString(value
)) {
1523 if (strcasecmp(PLGetString(value
), "YES")==0)
1526 wwarning(_("bad value in docked icon state info %s"),
1535 restore_icon_state(WScreen
*scr
, proplist_t info
, int type
, int index
)
1538 proplist_t cmd
, value
;
1541 cmd
= PLGetDictionaryEntry(info
, dCommand
);
1542 if (!cmd
|| !PLIsString(cmd
)) {
1546 /* parse window name */
1547 value
= PLGetDictionaryEntry(info
, dName
);
1552 char *wclass
, *winstance
;
1555 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1557 if (!winstance
&& !wclass
) {
1564 command
= wstrdup(PLGetString(cmd
));
1568 if (!command
|| strcmp(command
, "-")==0) {
1579 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
,
1589 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1590 if (type
== WM_CLIP
) {
1591 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1592 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1594 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1595 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1599 cmd
= PLGetDictionaryEntry(info
, dDropCommand
);
1601 aicon
->dnd_command
= wstrdup(PLGetString(cmd
));
1604 /* check auto launch */
1605 value
= PLGetDictionaryEntry(info
, dAutoLaunch
);
1607 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1610 value
= PLGetDictionaryEntry(info
, dLock
);
1612 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1614 /* check if it wasn't normally docked */
1615 value
= PLGetDictionaryEntry(info
, dForced
);
1617 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1619 /* check if we can rely on the stuff in the app */
1620 value
= PLGetDictionaryEntry(info
, dBuggyApplication
);
1622 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1624 /* get position in the dock */
1625 value
= PLGetDictionaryEntry(info
, dPosition
);
1626 if (value
&& PLIsString(value
)) {
1627 if (sscanf(PLGetString(value
), "%hi,%hi", &aicon
->xindex
,
1629 wwarning(_("bad value in docked icon state info %s"),
1630 PLGetString(dPosition
));
1632 /* check position sanity */
1633 /* incomplete section! */
1634 if (type
== WM_DOCK
) {
1636 if (aicon
->yindex
< 0)
1637 wwarning(_("bad value in docked icon position %i,%i"),
1638 aicon
->xindex
, aicon
->yindex
);
1641 aicon
->yindex
= index
;
1645 /* check if icon is omnipresent */
1646 value
= PLGetDictionaryEntry(info
, dOmnipresent
);
1648 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1657 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1661 wClipRestoreState(WScreen
*scr
, proplist_t clip_state
)
1667 icon
= mainIconCreate(scr
, WM_CLIP
);
1672 PLRetain(clip_state
);
1674 /* restore position */
1676 value
= PLGetDictionaryEntry(clip_state
, dPosition
);
1679 if (!PLIsString(value
))
1680 COMPLAIN("Position");
1682 if (sscanf(PLGetString(value
), "%i,%i", &icon
->x_pos
,
1684 COMPLAIN("Position");
1686 /* check position sanity */
1687 if (icon
->y_pos
< 0)
1689 else if (icon
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1690 icon
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1692 if (icon
->x_pos
< 0)
1694 else if (icon
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1695 icon
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1700 value
= PLGetDictionaryEntry(clip_state
, dDropCommand
);
1701 if (value
&& PLIsString(value
))
1702 icon
->dnd_command
= wstrdup(PLGetString(value
));
1705 PLRelease(clip_state
);
1712 wDockRestoreState(WScreen
*scr
, proplist_t dock_state
, int type
)
1717 WAppIcon
*aicon
, *old_top
;
1721 dock
= wDockCreate(scr
, type
);
1727 PLRetain(dock_state
);
1730 /* restore position */
1732 value
= PLGetDictionaryEntry(dock_state
, dPosition
);
1735 if (!PLIsString(value
))
1736 COMPLAIN("Position");
1738 if (sscanf(PLGetString(value
), "%i,%i", &dock
->x_pos
,
1740 COMPLAIN("Position");
1742 /* check position sanity */
1743 if (dock
->y_pos
< 0)
1745 else if (dock
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1746 dock
->y_pos
= scr
->scr_height
- ICON_SIZE
;
1748 /* This is no more needed. ??? */
1749 if (type
== WM_CLIP
) {
1750 if (dock
->x_pos
< 0)
1752 else if (dock
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1753 dock
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1755 if (dock
->x_pos
>= 0) {
1756 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1757 dock
->on_right_side
= 0;
1759 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1760 dock
->on_right_side
= 1;
1766 /* restore lowered/raised state */
1770 value
= PLGetDictionaryEntry(dock_state
, dLowered
);
1773 if (!PLIsString(value
))
1774 COMPLAIN("Lowered");
1776 if (strcasecmp(PLGetString(value
), "YES")==0)
1782 /* restore collapsed state */
1784 dock
->collapsed
= 0;
1786 value
= PLGetDictionaryEntry(dock_state
, dCollapsed
);
1789 if (!PLIsString(value
))
1790 COMPLAIN("Collapsed");
1792 if (strcasecmp(PLGetString(value
), "YES")==0)
1793 dock
->collapsed
= 1;
1798 /* restore auto-collapsed state */
1800 value
= PLGetDictionaryEntry(dock_state
, dAutoCollapse
);
1803 if (!PLIsString(value
))
1804 COMPLAIN("AutoCollapse");
1806 if (strcasecmp(PLGetString(value
), "YES")==0) {
1807 dock
->auto_collapse
= 1;
1808 dock
->collapsed
= 1;
1814 /* restore auto-raise/lower state */
1816 value
= PLGetDictionaryEntry(dock_state
, dAutoRaiseLower
);
1819 if (!PLIsString(value
))
1820 COMPLAIN("AutoRaiseLower");
1822 if (strcasecmp(PLGetString(value
), "YES")==0) {
1823 dock
->auto_raise_lower
= 1;
1828 /* restore attract icons state */
1830 dock
->attract_icons
= 0;
1832 value
= PLGetDictionaryEntry(dock_state
, dAutoAttractIcons
);
1835 if (!PLIsString(value
))
1836 COMPLAIN("AutoAttractIcons");
1838 if (strcasecmp(PLGetString(value
), "YES")==0)
1839 dock
->attract_icons
= 1;
1844 /* application list */
1851 * When saving, it saves the dock state in
1852 * Applications and Applicationsnnn
1854 * When loading, it will first try Applicationsnnn.
1855 * If it does not exist, use Applications as default.
1858 sprintf(buffer
, "Applications%i", scr
->scr_height
);
1860 tmp
= PLMakeString(buffer
);
1861 apps
= PLGetDictionaryEntry(dock_state
, tmp
);
1865 apps
= PLGetDictionaryEntry(dock_state
, dApplications
);
1873 count
= PLGetNumberOfElements(apps
);
1878 old_top
= dock
->icon_array
[0];
1880 /* dock->icon_count is set to 1 when dock is created.
1881 * Since Clip is already restored, we want to keep it so for clip,
1882 * but for dock we may change the default top tile, so we set it to 0.
1884 if (type
== WM_DOCK
)
1885 dock
->icon_count
= 0;
1887 for (i
=0; i
<count
; i
++) {
1888 if (dock
->icon_count
>= dock
->max_icons
) {
1889 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1893 value
= PLGetArrayElement(apps
, i
);
1894 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1896 dock
->icon_array
[dock
->icon_count
] = aicon
;
1900 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
*ICON_SIZE
);
1901 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
*ICON_SIZE
);
1904 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1906 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1908 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
,
1911 if (!dock
->collapsed
)
1912 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1913 wRaiseFrame(aicon
->icon
->core
);
1916 } else if (dock
->icon_count
==0 && type
==WM_DOCK
)
1920 /* if the first icon is not defined, use the default */
1921 if (dock
->icon_array
[0]==NULL
) {
1922 /* update default icon */
1923 old_top
->x_pos
= dock
->x_pos
;
1924 old_top
->y_pos
= dock
->y_pos
;
1926 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1928 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1929 dock
->icon_array
[0] = old_top
;
1930 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1931 /* we don't need to increment dock->icon_count here because it was
1932 * incremented in the loop above.
1934 } else if (old_top
!=dock
->icon_array
[0]) {
1935 if (old_top
== scr
->clip_icon
)
1936 scr
->clip_icon
= dock
->icon_array
[0];
1937 wAppIconDestroy(old_top
);
1942 PLRelease(dock_state
);
1950 wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1952 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1954 btn
->drop_launch
= 0;
1956 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1959 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1971 wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1977 for (i
= 0; i
< dock
->max_icons
; i
++) {
1978 btn
= dock
->icon_array
[i
];
1979 if (!btn
|| !btn
->auto_launch
)
1982 state
= wmalloc(sizeof(WSavedState
));
1983 memset(state
, 0, sizeof(WSavedState
));
1984 state
->workspace
= workspace
;
1985 /* TODO: this is klugy and is very difficult to understand
1986 * what's going on. Try to clean up */
1987 wDockLaunchWithState(dock
, btn
, state
);
1991 #ifdef REDUCE_APPICONS
1993 wDockSimulateLaunch(WDock
*dock
, WAppIcon
*btn
)
1995 if ((btn
== NULL
) || (dock
== NULL
))
1998 if (!btn
->running
) {
1999 if ((btn
->icon
->owner
== NULL
) && (btn
->applist
))
2000 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
2001 if (!btn
->forced_dock
)
2011 findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
2017 if ((dock
= scr
->dock
)!=NULL
) {
2018 for (i
=0; i
<dock
->max_icons
; i
++) {
2019 if (dock
->icon_array
[i
]
2020 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
2026 if (*icon_pos
<0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
)!=NULL
) {
2027 for (i
=0; i
<dock
->max_icons
; i
++) {
2028 if (dock
->icon_array
[i
]
2029 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
2042 wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
2048 dock
= findDock(scr
, event
, &icon_pos
);
2053 * Return True if the drop was on an application icon window.
2054 * In this case, let the ClientMessage handler redirect the
2055 * message to the app.
2057 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!=None
)
2060 if (dock
->icon_array
[icon_pos
]->dnd_command
!=NULL
) {
2061 scr
->flags
.dnd_data_convertion_status
= 0;
2063 btn
= dock
->icon_array
[icon_pos
];
2065 if (!btn
->forced_dock
) {
2066 btn
->relaunching
= btn
->running
;
2069 if (btn
->wm_instance
|| btn
->wm_class
) {
2070 WWindowAttributes attr
;
2071 memset(&attr
, 0, sizeof(WWindowAttributes
));
2072 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
2074 btn
->wm_class
, &attr
, NULL
, True
);
2076 if (!attr
.no_appicon
)
2082 btn
->drop_launch
= 1;
2083 scr
->last_dock
= dock
;
2084 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
2089 if (!btn
->relaunching
) {
2096 #endif /* OFFIX_DND */
2101 wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2108 wwin
= icon
->icon
->owner
;
2109 if (icon
->command
==NULL
) {
2111 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2113 icon
->command
= wtokenjoin(argv
, argc
);
2114 XFreeStringList(argv
);
2118 /* icon->forced_dock = 1;*/
2119 if (dock
->type
!=WM_CLIP
|| !icon
->attracted
) {
2121 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2122 _("Type the command used to launch the application"),
2124 if (command
&& (command
[0]==0 ||
2125 (command
[0]=='-' && command
[1]==0))) {
2129 icon
->command
= command
;
2135 /* If the target is the dock, reject the icon. If
2136 * the target is the clip, make it an attracted icon
2138 if (dock
->type
==WM_CLIP
) {
2139 icon
->attracted
= 1;
2140 if (!icon
->icon
->shadowed
) {
2141 icon
->icon
->shadowed
= 1;
2142 icon
->icon
->force_paint
= 1;
2154 for (index
=1; index
<dock
->max_icons
; index
++)
2155 if (dock
->icon_array
[index
] == NULL
)
2157 /* if (index == dock->max_icons)
2160 assert(index
< dock
->max_icons
);
2162 dock
->icon_array
[index
] = icon
;
2166 icon
->omnipresent
= 0;
2168 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2169 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2174 icon
->launching
= 0;
2177 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2178 if (dock
->type
== WM_CLIP
) {
2179 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2180 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2182 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2183 icon
->icon
->core
->descriptor
.parent
= icon
;
2185 MoveInStackListUnder(dock
->icon_array
[index
-1]->icon
->core
,
2187 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2188 wAppIconPaint(icon
);
2190 if (wPreferences
.auto_arrange_icons
)
2191 wArrangeIcons(dock
->screen_ptr
, True
);
2194 if (icon
->command
&& !icon
->dnd_command
) {
2195 icon
->dnd_command
= wmalloc(strlen(icon
->command
)+8);
2196 sprintf(icon
->dnd_command
, "%s %%d", icon
->command
);
2205 reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2209 for(index
=1; index
<dock
->max_icons
; index
++) {
2210 if(dock
->icon_array
[index
] == icon
)
2213 assert(index
< dock
->max_icons
);
2218 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2219 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2224 moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2232 return True
; /* No move needed, we're already there */
2237 wwin
= icon
->icon
->owner
;
2240 * For the moment we can't do this if we move icons in Clip from one
2241 * workspace to other, because if we move two or more icons without
2242 * command, the dialog box will not be able to tell us to which of the
2243 * moved icons it applies. -Dan
2245 if ((dest
->type
==WM_DOCK
/*|| dest->keep_attracted*/) && icon
->command
==NULL
) {
2246 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2248 icon
->command
= wtokenjoin(argv
, argc
);
2249 XFreeStringList(argv
);
2254 /* icon->forced_dock = 1;*/
2255 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2256 _("Type the command used to launch the application"),
2258 if (command
&& (command
[0]==0 ||
2259 (command
[0]=='-' && command
[1]==0))) {
2263 icon
->command
= command
;
2274 if (dest
->type
== WM_DOCK
)
2275 wClipMakeIconOmnipresent(icon
, False
);
2277 for(index
=1; index
<src
->max_icons
; index
++) {
2278 if(src
->icon_array
[index
] == icon
)
2281 assert(index
< src
->max_icons
);
2283 src
->icon_array
[index
] = NULL
;
2286 for(index
=1; index
<dest
->max_icons
; index
++) {
2287 if(dest
->icon_array
[index
] == NULL
)
2290 /* if (index == dest->max_icons)
2293 assert(index
< dest
->max_icons
);
2295 dest
->icon_array
[index
] = icon
;
2298 /* deselect the icon */
2299 if (icon
->icon
->selected
)
2300 wIconSelect(icon
->icon
);
2302 if (dest
->type
== WM_DOCK
) {
2303 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2304 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2306 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2307 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2310 /* set it to be kept when moving to dock.
2311 * Unless the icon does not have a command set
2313 if (icon
->command
&& dest
->type
==WM_DOCK
) {
2314 icon
->attracted
= 0;
2315 if (icon
->icon
->shadowed
) {
2316 icon
->icon
->shadowed
= 0;
2317 icon
->icon
->force_paint
= 1;
2321 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2327 icon
->x_pos
= dest
->x_pos
+ x
*ICON_SIZE
;
2328 icon
->y_pos
= dest
->y_pos
+ y
*ICON_SIZE
;
2332 MoveInStackListUnder(dest
->icon_array
[index
-1]->icon
->core
,
2334 wAppIconPaint(icon
);
2341 wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2345 /* make the settings panel be closed */
2347 DestroyDockAppSettingsPanel(icon
->panel
);
2350 /* This must be called before icon->dock is set to NULL.
2351 * Don't move it. -Dan
2353 wClipMakeIconOmnipresent(icon
, False
);
2357 icon
->attracted
= 0;
2358 icon
->auto_launch
= 0;
2359 if (icon
->icon
->shadowed
) {
2360 icon
->icon
->shadowed
= 0;
2361 icon
->icon
->force_paint
= 1;
2364 /* deselect the icon */
2365 if (icon
->icon
->selected
)
2366 wIconSelect(icon
->icon
);
2368 if (icon
->command
) {
2369 wfree(icon
->command
);
2370 icon
->command
= NULL
;
2373 if (icon
->dnd_command
) {
2374 wfree(icon
->dnd_command
);
2375 icon
->dnd_command
= NULL
;
2379 for (index
=1; index
<dock
->max_icons
; index
++)
2380 if (dock
->icon_array
[index
] == icon
)
2382 assert(index
< dock
->max_icons
);
2383 dock
->icon_array
[index
] = NULL
;
2389 /* if the dock is not attached to an application or
2390 * the the application did not set the approriate hints yet,
2391 * destroy the icon */
2392 #ifdef REDUCE_APPICONS
2393 if ((icon
->num_apps
== 0) && (!icon
->running
|| !wApplicationOf(icon
->main_window
)) )
2395 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2397 wAppIconDestroy(icon
);
2399 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2400 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2401 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2402 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2403 icon
->icon
->core
->descriptor
.parent
= icon
;
2405 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2407 wAppIconPaint(icon
);
2408 if (wPreferences
.auto_arrange_icons
) {
2409 wArrangeIcons(dock
->screen_ptr
, True
);
2412 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2418 * returns the closest Dock slot index for the passed
2421 * Returns False if icon can't be docked.
2423 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2427 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2428 int *ret_x
, int *ret_y
, int redocking
)
2430 WScreen
*scr
= dock
->screen_ptr
;
2433 int i
, offset
= ICON_SIZE
/2;
2434 WAppIcon
*aicon
= NULL
;
2435 WAppIcon
*nicon
= NULL
;
2436 int max_y_icons
, max_x_icons
;
2438 max_x_icons
= scr
->scr_width
/ICON_SIZE
;
2439 max_y_icons
= scr
->scr_height
/ICON_SIZE
-1;
2441 if (wPreferences
.flags
.noupdates
)
2447 /* if the dock is full */
2449 (dock
->icon_count
>= dock
->max_icons
)) {
2453 /* exact position */
2455 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2457 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2460 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2462 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2464 /* check if the icon is outside the screen boundaries */
2465 if (dx
+ ex_x
*ICON_SIZE
< -ICON_SIZE
+2 ||
2466 dx
+ ex_x
*ICON_SIZE
>= scr
->scr_width
-1 ||
2467 dy
+ ex_y
*ICON_SIZE
< -ICON_SIZE
+2 ||
2468 dy
+ ex_y
*ICON_SIZE
>= scr
->scr_height
-1)
2471 if (dock
->type
== WM_DOCK
) {
2472 if (icon
->dock
!= dock
&& ex_x
!= 0)
2476 for (i
=0; i
<dock
->max_icons
; i
++) {
2477 nicon
= dock
->icon_array
[i
];
2478 if (nicon
&& nicon
->yindex
== ex_y
) {
2485 int sig
, done
, closest
;
2487 /* Possible cases when redocking:
2489 * icon dragged out of range of any slot -> false
2490 * icon dragged to range of free slot
2491 * icon dragged to range of same slot
2492 * icon dragged to range of different icon
2494 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2497 if (ex_y
>=0 && ex_y
<=max_y_icons
&& (aicon
==icon
|| !aicon
)) {
2503 /* start looking at the upper slot or lower? */
2504 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2511 /* look for closest free slot */
2512 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2516 closest
= sig
*(i
/2) + ex_y
;
2517 /* check if this slot is used */
2519 for (j
= 0; j
<dock
->max_icons
; j
++) {
2520 if (dock
->icon_array
[j
]
2521 && dock
->icon_array
[j
]->yindex
==closest
) {
2522 /* slot is used by someone else */
2523 if (dock
->icon_array
[j
]!=icon
)
2531 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2532 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2534 (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+1))) {
2539 } else { /* !redocking */
2541 /* if slot is free and the icon is close enough, return it */
2542 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2552 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2553 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+1;
2556 for (k
=start
; k
<stop
; k
++) {
2557 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2560 for (i
=0; i
<tmp
->max_icons
; i
++) {
2561 nicon
= tmp
->icon_array
[i
];
2562 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2570 for (k
=start
; k
<stop
; k
++) {
2571 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2574 for (i
=0; i
<tmp
->max_icons
; i
++) {
2575 nicon
= tmp
->icon_array
[i
];
2576 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2577 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2578 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2587 if (neighbours
&& (aicon
==NULL
|| (redocking
&& aicon
== icon
))) {
2596 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2597 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2599 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2600 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2601 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2605 * returns true if it can find a free slot in the dock,
2606 * in which case it changes x_pos and y_pos accordingly.
2607 * Else returns false.
2610 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2612 WScreen
*scr
= dock
->screen_ptr
;
2614 WAppIconChain
*chain
;
2615 unsigned char *slot_map
;
2619 int i
, done
= False
;
2621 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2624 if (dock
->type
== WM_CLIP
&&
2625 dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2626 extra_count
= scr
->global_icon_count
;
2628 /* if the dock is full */
2629 if (dock
->icon_count
+extra_count
>= dock
->max_icons
) {
2633 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2634 if (scr
->dock
->on_right_side
)
2635 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2637 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2640 if (ex
< dock
->x_pos
)
2642 if (sx
> dock
->x_pos
+ICON_SIZE
)
2643 sx
= dock
->x_pos
+ICON_SIZE
;
2650 /* check if clip is in a corner */
2651 if (dock
->type
==WM_CLIP
) {
2652 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2654 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2656 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2658 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2665 /* If the clip is in the corner, use only slots that are in the border
2667 if (corner
!=C_NONE
) {
2671 hcount
= MIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2672 vcount
= MIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2673 hmap
= wmalloc(hcount
+1);
2674 memset(hmap
, 0, hcount
+1);
2675 vmap
= wmalloc(vcount
+1);
2676 memset(vmap
, 0, vcount
+1);
2678 /* mark used positions */
2681 for (i
=0; i
<dock
->max_icons
; i
++) {
2682 btn
= dock
->icon_array
[i
];
2686 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2687 vmap
[btn
->yindex
] = 1;
2688 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2689 hmap
[btn
->xindex
] = 1;
2691 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2693 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2694 vmap
[btn
->yindex
] = 1;
2695 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2696 hmap
[btn
->xindex
] = 1;
2700 for (i
=0; i
<dock
->max_icons
; i
++) {
2701 btn
= dock
->icon_array
[i
];
2705 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2706 vmap
[btn
->yindex
] = 1;
2707 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2708 hmap
[-btn
->xindex
] = 1;
2710 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2712 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2713 vmap
[btn
->yindex
] = 1;
2714 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2715 hmap
[-btn
->xindex
] = 1;
2719 for (i
=0; i
<dock
->max_icons
; i
++) {
2720 btn
= dock
->icon_array
[i
];
2724 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2725 vmap
[-btn
->yindex
] = 1;
2726 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2727 hmap
[btn
->xindex
] = 1;
2729 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2731 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2732 vmap
[-btn
->yindex
] = 1;
2733 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2734 hmap
[btn
->xindex
] = 1;
2739 for (i
=0; i
<dock
->max_icons
; i
++) {
2740 btn
= dock
->icon_array
[i
];
2744 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2745 vmap
[-btn
->yindex
] = 1;
2746 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2747 hmap
[-btn
->xindex
] = 1;
2749 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2751 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2752 vmap
[-btn
->yindex
] = 1;
2753 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2754 hmap
[-btn
->xindex
] = 1;
2759 /* search a vacant slot */
2760 for (i
=1; i
<MAX(vcount
, hcount
); i
++) {
2761 if (i
< vcount
&& vmap
[i
]==0) {
2767 } else if (i
< hcount
&& hmap
[i
]==0) {
2777 /* If found a slot, translate and return */
2779 if (corner
==C_NW
|| corner
==C_NE
) {
2784 if (corner
==C_NE
|| corner
==C_SE
) {
2791 /* else, try to find a slot somewhere else */
2794 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2795 * placed outside of screen */
2796 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2798 /* In the worst case (the clip is in the corner of the screen),
2799 * the amount of icons that fit in the clip is smaller.
2800 * Double the map to get a safe value.
2806 slot_map
= wmalloc(mwidth
*mwidth
);
2807 memset(slot_map
, 0, mwidth
*mwidth
);
2809 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2811 /* mark used slots in the map. If the slot falls outside the map
2812 * (for example, when all icons are placed in line), ignore them. */
2813 for (i
=0; i
<dock
->max_icons
; i
++) {
2814 btn
= dock
->icon_array
[i
];
2816 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2818 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2819 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2821 /* Find closest slot from the center that is free by scanning the
2822 * map from the center to outward in circular passes.
2823 * This will not result in a neat layout, but will be optimal
2824 * in the sense that there will not be holes left.
2827 for (i
= 1; i
<= r
&& !done
; i
++) {
2830 /* top and bottom parts of the ring */
2831 for (x
= -i
; x
<= i
&& !done
; x
++) {
2832 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2834 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2835 if (slot_map
[XY2OFS(x
,y
)]==0
2836 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2843 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2844 if (slot_map
[XY2OFS(x
,y
)]==0
2845 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2852 /* left and right parts of the ring */
2853 for (y
= -i
+1; y
<= i
-1; y
++) {
2854 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2856 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2857 if (slot_map
[XY2OFS(x
,y
)]==0
2858 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2865 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2866 if (slot_map
[XY2OFS(x
,y
)]==0
2867 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2882 moveDock(WDock
*dock
, int new_x
, int new_y
)
2887 dock
->x_pos
= new_x
;
2888 dock
->y_pos
= new_y
;
2889 for (i
=0; i
<dock
->max_icons
; i
++) {
2890 btn
= dock
->icon_array
[i
];
2892 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2893 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2894 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2901 swapDock(WDock
*dock
)
2903 WScreen
*scr
= dock
->screen_ptr
;
2908 if (dock
->on_right_side
) {
2909 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2911 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2914 for (i
=0; i
<dock
->max_icons
; i
++) {
2915 btn
= dock
->icon_array
[i
];
2918 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2922 wScreenUpdateUsableArea(scr
);
2927 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2929 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2935 cmdline
= ExpandOptions(scr
, command
);
2937 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2945 wtokensplit(cmdline
, &argv
, &argc
);
2955 if ((pid
=fork())==0) {
2959 SetupEnvironment(scr
);
2965 args
= malloc(sizeof(char*)*(argc
+1));
2968 for (i
=0; i
<argc
; i
++) {
2972 execvp(argv
[0], args
);
2976 wfree(argv
[--argc
]);
2981 state
= wmalloc(sizeof(WSavedState
));
2982 memset(state
, 0, sizeof(WSavedState
));
2984 state
->miniaturized
= -1;
2986 if (btn
->dock
==scr
->dock
|| btn
->omnipresent
)
2987 state
->workspace
= -1;
2989 state
->workspace
= scr
->current_workspace
;
2991 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
2993 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
3004 wDockHideIcons(WDock
*dock
)
3011 for (i
=1; i
<dock
->max_icons
; i
++) {
3012 if (dock
->icon_array
[i
])
3013 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3017 dockIconPaint(dock
->icon_array
[0]);
3022 wDockShowIcons(WDock
*dock
)
3030 btn
= dock
->icon_array
[0];
3031 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
3033 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
3034 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
3036 for (i
=1; i
<dock
->max_icons
; i
++) {
3037 if (dock
->icon_array
[i
]) {
3038 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
3044 if (!dock
->collapsed
) {
3045 for (i
=1; i
<dock
->max_icons
; i
++) {
3046 if (dock
->icon_array
[i
]) {
3047 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3058 wDockLower(WDock
*dock
)
3062 for (i
=0; i
<dock
->max_icons
; i
++) {
3063 if (dock
->icon_array
[i
])
3064 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
3070 wDockRaise(WDock
*dock
)
3074 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
3075 if (dock
->icon_array
[i
])
3076 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
3082 wDockRaiseLower(WDock
*dock
)
3084 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
3085 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
3086 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
3094 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
3096 icon
->launching
= 0;
3097 icon
->relaunching
= 0;
3098 dockIconPaint(icon
);
3103 wDockFindIconForWindow(WDock
*dock
, Window window
)
3108 for (i
=0; i
<dock
->max_icons
; i
++) {
3109 icon
= dock
->icon_array
[i
];
3110 if (icon
&& icon
->main_window
== window
)
3118 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
3121 #ifdef REDUCE_APPICONS
3122 WAppIconAppList
*tapplist
;
3124 char *wm_class
, *wm_instance
;
3126 Bool firstPass
= True
;
3128 char *command
= NULL
;
3134 if (XGetCommand(dpy
, window
, &argv
, &argc
)) {
3135 if (argc
> 0 && argv
!= NULL
)
3136 command
= wtokenjoin(argv
,argc
);
3138 XFreeStringList(argv
);
3143 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
3144 (!wm_class
&& !wm_instance
))
3148 for (i
=0; i
<dock
->max_icons
; i
++) {
3149 icon
= dock
->icon_array
[i
];
3153 /* app is already attached to icon */
3154 if (icon
->main_window
== window
) {
3159 if ((icon
->wm_instance
|| icon
->wm_class
)
3161 || (dock
->screen_ptr
->flags
.startup
&& !icon
->running
))) {
3163 if (icon
->wm_instance
&& wm_instance
&&
3164 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
3167 if (icon
->wm_class
&& wm_class
&&
3168 strcmp(icon
->wm_class
, wm_class
)!=0) {
3171 if (firstPass
&& command
&& strcmp(icon
->command
, command
)!=0) {
3175 if (!icon
->relaunching
) {
3178 /* Possibly an application that was docked with dockit,
3179 * but the user did not update WMState to indicate that
3180 * it was docked by force */
3181 wapp
= wApplicationOf(window
);
3183 icon
->forced_dock
= 1;
3186 if (!icon
->forced_dock
)
3187 icon
->main_window
= window
;
3189 #ifdef REDUCE_APPICONS
3190 tapplist
= wmalloc(sizeof(WAppIconAppList
));
3191 memset(tapplist
, 0, sizeof(WAppIconAppList
));
3192 tapplist
->next
= icon
->applist
;
3194 icon
->applist
->prev
= tapplist
;
3195 icon
->applist
= tapplist
;
3196 tapplist
->wapp
= wApplicationOf(window
);
3201 wDockFinishLaunch(dock
, icon
);
3206 if (firstPass
&& !found
) {
3223 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3225 if (!wPreferences
.flags
.noclip
) {
3226 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3227 if (scr
->current_workspace
!= workspace
) {
3228 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3229 WAppIconChain
*chain
= scr
->global_icons
;
3232 moveIconBetweenDocks(chain
->aicon
->dock
,
3233 scr
->workspaces
[workspace
]->clip
,
3234 chain
->aicon
, chain
->aicon
->xindex
,
3235 chain
->aicon
->yindex
);
3236 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
3237 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3238 chain
= chain
->next
;
3241 wDockHideIcons(old_clip
);
3242 if (old_clip
->auto_raise_lower
) {
3243 if (old_clip
->auto_raise_magic
) {
3244 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3245 old_clip
->auto_raise_magic
= NULL
;
3247 wDockLower(old_clip
);
3249 if (old_clip
->auto_collapse
) {
3250 if (old_clip
->auto_expand_magic
) {
3251 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3252 old_clip
->auto_expand_magic
= NULL
;
3254 old_clip
->collapsed
= 1;
3256 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3258 if (scr
->flags
.clip_balloon_mapped
)
3259 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3266 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3271 for (i
=0; i
<dock
->max_icons
; i
++) {
3272 icon
= dock
->icon_array
[i
];
3276 if (icon
->launching
&& icon
->pid
== pid
) {
3277 if (!icon
->relaunching
) {
3279 icon
->main_window
= None
;
3281 wDockFinishLaunch(dock
, icon
);
3286 sprintf(msg
, _("Could not execute command \"%s\""),
3287 icon
->drop_launch
&& icon
->dnd_command
3288 ? icon
->dnd_command
: icon
->command
);
3290 sprintf(msg
, _("Could not execute command \"%s\""),
3293 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
3294 _("OK"), NULL
, NULL
);
3303 toggleLowered(WDock
*dock
)
3308 /* lower/raise Dock */
3309 if (!dock
->lowered
) {
3310 newlevel
= WMNormalLevel
;
3313 newlevel
= WMDockLevel
;
3317 for (i
=0; i
<dock
->max_icons
; i
++) {
3318 tmp
= dock
->icon_array
[i
];
3322 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3324 wLowerFrame(tmp
->icon
->core
);
3327 if (dock
->type
== WM_DOCK
)
3328 wScreenUpdateUsableArea(dock
->screen_ptr
);
3333 toggleCollapsed(WDock
*dock
)
3335 if (dock
->collapsed
) {
3336 dock
->collapsed
= 0;
3337 wDockShowIcons(dock
);
3340 dock
->collapsed
= 1;
3341 wDockHideIcons(dock
);
3347 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3349 WScreen
*scr
= dock
->screen_ptr
;
3350 WObjDescriptor
*desc
;
3352 WApplication
*wapp
= NULL
;
3356 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3358 if (dock
->type
== WM_DOCK
) {
3360 entry
= dock
->menu
->entries
[index
];
3362 if (dock
->lowered
) {
3363 entry
->text
= _("Keep on Top");
3365 entry
->text
= _("Allow Lowering");
3367 entry
->clientdata
= dock
;
3369 dock
->menu
->flags
.realized
= 0;
3372 if (scr
->clip_options
)
3373 updateClipOptionsMenu(scr
->clip_options
, dock
);
3375 n_selected
= numberOfSelectedIcons(dock
);
3377 /* Rename Workspace */
3378 entry
= dock
->menu
->entries
[++index
];
3379 if (aicon
== scr
->clip_icon
) {
3380 entry
->callback
= renameCallback
;
3381 entry
->clientdata
= dock
;
3382 entry
->flags
.indicator
= 0;
3383 entry
->text
= _("Rename Workspace");
3385 entry
->callback
= omnipresentCallback
;
3386 entry
->clientdata
= aicon
;
3387 if (n_selected
> 0) {
3388 entry
->flags
.indicator
= 0;
3389 entry
->text
= _("Toggle Omnipresent");
3391 entry
->flags
.indicator
= 1;
3392 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3393 entry
->flags
.indicator_type
= MI_CHECK
;
3394 entry
->text
= _("Omnipresent");
3398 /* select/unselect icon */
3399 entry
= dock
->menu
->entries
[++index
];
3400 entry
->clientdata
= aicon
;
3401 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3402 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3404 /* select/unselect all icons */
3405 entry
= dock
->menu
->entries
[++index
];
3406 entry
->clientdata
= aicon
;
3408 entry
->text
= _("Unselect All Icons");
3410 entry
->text
= _("Select All Icons");
3411 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3414 entry
= dock
->menu
->entries
[++index
];
3415 entry
->clientdata
= aicon
;
3417 entry
->text
= _("Keep Icons");
3419 entry
->text
= _("Keep Icon");
3420 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3422 /* this is the workspace submenu part */
3423 entry
= dock
->menu
->entries
[++index
];
3425 entry
->text
= _("Move Icons To");
3427 entry
->text
= _("Move Icon To");
3428 if (scr
->clip_submenu
)
3429 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3430 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3432 /* remove icon(s) */
3433 entry
= dock
->menu
->entries
[++index
];
3434 entry
->clientdata
= aicon
;
3436 entry
->text
= _("Remove Icons");
3438 entry
->text
= _("Remove Icon");
3439 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3441 /* attract icon(s) */
3442 entry
= dock
->menu
->entries
[++index
];
3443 entry
->clientdata
= aicon
;
3445 dock
->menu
->flags
.realized
= 0;
3446 wMenuRealize(dock
->menu
);
3450 if (aicon
->icon
->owner
) {
3451 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3457 entry
= dock
->menu
->entries
[++index
];
3458 entry
->clientdata
= aicon
;
3459 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3462 entry
= dock
->menu
->entries
[++index
];
3463 entry
->clientdata
= aicon
;
3464 if (wapp
&& wapp
->flags
.hidden
) {
3465 entry
->text
= _("Unhide Here");
3467 entry
->text
= _("Bring Here");
3469 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3472 entry
= dock
->menu
->entries
[++index
];
3473 entry
->clientdata
= aicon
;
3474 if (wapp
&& wapp
->flags
.hidden
) {
3475 entry
->text
= _("Unhide");
3477 entry
->text
= _("Hide");
3479 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3482 entry
= dock
->menu
->entries
[++index
];
3483 entry
->clientdata
= aicon
;
3484 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
3485 && !wPreferences
.flags
.noupdates
);
3488 entry
= dock
->menu
->entries
[++index
];
3489 entry
->clientdata
= aicon
;
3490 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3492 if (!dock
->menu
->flags
.realized
)
3493 wMenuRealize(dock
->menu
);
3495 if (dock
->type
== WM_CLIP
) {
3496 x_pos
= event
->xbutton
.x_root
+2;
3498 x_pos
= dock
->on_right_side
?
3499 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 2 : 0;
3502 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3504 /* allow drag select */
3505 event
->xany
.send_event
= True
;
3506 desc
= &dock
->menu
->menu
->descriptor
;
3507 (*desc
->handle_mousedown
)(desc
, event
);
3512 openClipWorkspaceMenu(WScreen
*scr
, int x
, int y
)
3514 if (!scr
->clip_ws_menu
) {
3515 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3517 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
3518 wMenuMapAt(scr
->clip_ws_menu
, x
, y
, False
);
3522 /******************************************************************/
3524 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3526 WAppIcon
*btn
= desc
->parent
;
3527 WDock
*dock
= btn
->dock
;
3528 WApplication
*wapp
= NULL
;
3531 #ifdef REDUCE_APPICONS
3532 if ((btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) ||
3533 ((btn
->icon
->owner
== NULL
) && (btn
->applist
!= NULL
))) {
3534 if (btn
->icon
->owner
== NULL
)
3535 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
3537 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3539 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3543 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3545 /* go to the last workspace that the user worked on the app */
3546 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
3548 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3551 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3554 if (event
->xbutton
.state
& MOD_MASK
) {
3555 wHideOtherApplications(btn
->icon
->owner
);
3558 if (event
->xbutton
.button
==Button1
) {
3560 if (event
->xbutton
.state
& MOD_MASK
) {
3561 /* raise/lower dock */
3562 toggleLowered(dock
);
3563 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3564 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3565 toggleCollapsed(dock
);
3567 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3568 } else if (btn
->command
) {
3569 if (!btn
->launching
&&
3570 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3571 launchDockedApplication(btn
);
3573 } else if (btn
->xindex
== 0 && btn
->yindex
== 0
3574 && btn
->dock
->type
== WM_DOCK
) {
3576 wShowGNUstepPanel(dock
->screen_ptr
);
3584 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3586 WScreen
*scr
= dock
->screen_ptr
;
3587 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3590 int grabbed
= 0, swapped
= 0, done
;
3591 Pixmap ghost
= None
;
3592 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3595 puts("moving dock");
3597 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3598 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3599 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3600 wwarning("pointer grab failed for dock move");
3603 for (x
=0; x
<dock
->max_icons
; x
++) {
3604 if (dock
->icon_array
[x
]!=NULL
&&
3605 dock
->icon_array
[x
]->yindex
> y
)
3606 y
= dock
->icon_array
[x
]->yindex
;
3609 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3613 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3614 |ButtonMotionMask
|ExposureMask
, &ev
);
3622 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3623 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3624 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3625 |ButtonReleaseMask
|ButtonPressMask
,
3626 wCursor
[WCUR_MOVE
], CurrentTime
);
3631 if (dock
->type
== WM_CLIP
) {
3632 if (ev
.xmotion
.x_root
- ofs_x
< 0) {
3634 } else if (ev
.xmotion
.x_root
- ofs_x
+ ICON_SIZE
>
3636 x
= scr
->scr_width
- ICON_SIZE
;
3638 x
= ev
.xmotion
.x_root
- ofs_x
;
3640 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3642 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3644 y
= scr
->scr_height
- ICON_SIZE
;
3646 y
= ev
.xmotion
.y_root
- ofs_y
;
3648 moveDock(dock
, x
, y
);
3650 /* move vertically if pointer is inside the dock*/
3651 if ((dock
->on_right_side
&&
3652 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3653 || (!dock
->on_right_side
&&
3654 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3656 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3658 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3660 y
= scr
->scr_height
- ICON_SIZE
;
3662 y
= ev
.xmotion
.y_root
- ofs_y
;
3664 moveDock(dock
, dock
->x_pos
, y
);
3666 /* move horizontally to change sides */
3667 x
= ev
.xmotion
.x_root
- ofs_x
;
3668 if (!dock
->on_right_side
) {
3672 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3673 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3674 -DOCK_EXTRA_SPACE
-1, dock
->y_pos
);
3675 if (superfluous
&& ghost
==None
) {
3676 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3677 scr
->scr_width
-ICON_SIZE
3678 -DOCK_EXTRA_SPACE
-1,
3680 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3682 XClearWindow(dpy
, scr
->dock_shadow
);
3684 XMapRaised(dpy
, scr
->dock_shadow
);
3687 if (superfluous
&& ghost
!=None
) {
3688 XFreePixmap(dpy
, ghost
);
3691 XUnmapWindow(dpy
, scr
->dock_shadow
);
3696 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3697 XMoveWindow(dpy
, scr
->dock_shadow
,
3698 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3699 if (superfluous
&& ghost
==None
) {
3700 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3701 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3702 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3704 XClearWindow(dpy
, scr
->dock_shadow
);
3706 XMapRaised(dpy
, scr
->dock_shadow
);
3709 XUnmapWindow(dpy
, scr
->dock_shadow
);
3711 if (superfluous
&& ghost
!=None
) {
3712 XFreePixmap(dpy
, ghost
);
3724 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3726 XUngrabPointer(dpy
, CurrentTime
);
3727 XUnmapWindow(dpy
, scr
->dock_shadow
);
3728 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3729 if (dock
->type
== WM_DOCK
) {
3732 dock
->on_right_side
= 1;
3734 dock
->on_right_side
= 0;
3736 wArrangeIcons(scr
, False
);
3745 XFreePixmap(dpy
, ghost
);
3746 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3749 puts("End dock move");
3756 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3758 WScreen
*scr
= dock
->screen_ptr
;
3760 WIcon
*icon
= aicon
->icon
;
3761 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3762 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3764 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3765 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3766 int shad_x
= x
, shad_y
= y
;
3767 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3769 Pixmap ghost
= None
;
3771 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3772 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3775 if (wPreferences
.flags
.noupdates
)
3778 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3779 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3780 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3782 wwarning("pointer grab failed for icon move");
3786 if (!(event
->xbutton
.state
& MOD_MASK
))
3787 wRaiseFrame(icon
->core
);
3789 if (!wPreferences
.flags
.noclip
)
3790 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3792 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3794 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3797 wins
[0] = icon
->core
->window
;
3798 wins
[1] = scr
->dock_shadow
;
3799 XRestackWindows(dpy
, wins
, 2);
3800 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3801 ICON_SIZE
, ICON_SIZE
);
3803 if (icon
->pixmap
!=None
)
3804 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3806 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3808 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3809 XClearWindow(dpy
, scr
->dock_shadow
);
3811 XMapWindow(dpy
, scr
->dock_shadow
);
3817 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3818 |ButtonMotionMask
|ExposureMask
, &ev
);
3826 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3827 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3828 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3829 |ButtonReleaseMask
|ButtonPressMask
,
3830 wCursor
[WCUR_MOVE
], CurrentTime
);
3839 for (i
=0; i
<scr
->workspace_count
; i
++) {
3840 if (i
== scr
->current_workspace
)
3842 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3846 x
= ev
.xmotion
.x_root
- ofs_x
;
3847 y
= ev
.xmotion
.y_root
- ofs_y
;
3848 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3851 if (last_dock
!= dock
&& collapsed
) {
3852 last_dock
->collapsed
= 1;
3853 wDockHideIcons(last_dock
);
3856 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3857 dock
->collapsed
= 0;
3858 wDockShowIcons(dock
);
3860 if (dock
->auto_raise_lower
)
3864 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3867 if (last_dock
!= dock2
&& collapsed
) {
3868 last_dock
->collapsed
= 1;
3869 wDockHideIcons(last_dock
);
3872 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3873 dock2
->collapsed
= 0;
3874 wDockShowIcons(dock2
);
3876 if (dock2
->auto_raise_lower
)
3881 if (aicon
->launching
3883 || (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3884 || (!aicon
->running
&& tmp
)) {
3885 shad_x
= last_dock
->x_pos
+ ix
*wPreferences
.icon_size
;
3886 shad_y
= last_dock
->y_pos
+ iy
*wPreferences
.icon_size
;
3888 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3891 XMapWindow(dpy
, scr
->dock_shadow
);
3896 XUnmapWindow(dpy
, scr
->dock_shadow
);
3900 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3907 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3909 XUngrabPointer(dpy
, CurrentTime
);
3911 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3912 XUnmapWindow(dpy
, scr
->dock_shadow
);
3914 reattachIcon(dock
, aicon
, ix
, iy
);
3915 if (clip
&& dock
!=clip
&& clip
->auto_raise_lower
)
3918 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3920 /* Slide it back if dock rejected it */
3921 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3923 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3925 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3933 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3934 /* We need to deselect it, even if is deselected in
3935 * wDockDetach(), because else DoKaboom() will fail.
3937 if (aicon
->icon
->selected
)
3938 wIconSelect(aicon
->icon
);
3941 wSoundPlay(WSOUND_KABOOM
);
3943 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3946 wSoundPlay(WSOUND_UNDOCK
);
3951 wSoundPlay(WSOUND_UNDOCK
);
3954 if (clip
&& clip
->auto_raise_lower
)
3956 wDockDetach(dock
, aicon
);
3959 last_dock
->collapsed
= 1;
3960 wDockHideIcons(last_dock
);
3965 XFreePixmap(dpy
, ghost
);
3966 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3970 for (i
=0; i
<scr
->workspace_count
; i
++) {
3971 if (i
== scr
->current_workspace
)
3973 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3978 puts("End icon move");
3987 getClipButton(int px
, int py
)
3989 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
3991 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3994 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
3995 return CLIP_FORWARD
;
3996 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
4004 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
4007 int done
, direction
, new_ws
;
4009 WDock
*clip
= scr
->clip_icon
->dock
;
4011 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
4013 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
4014 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
4016 wClipIconPaint(scr
->clip_icon
);
4019 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
4020 |ButtonPressMask
, &ev
);
4027 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
4028 if (new_dir
!= direction
) {
4029 direction
= new_dir
;
4030 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
4031 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
4032 wClipIconPaint(scr
->clip_icon
);
4040 if (ev
.xbutton
.button
== event
->xbutton
.button
)
4045 clip
->lclip_button_pushed
= 0;
4046 clip
->rclip_button_pushed
= 0;
4048 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
4050 if (direction
== CLIP_FORWARD
) {
4051 if (scr
->current_workspace
< scr
->workspace_count
-1)
4052 wWorkspaceChange(scr
, scr
->current_workspace
+1);
4053 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
4054 wWorkspaceChange(scr
, scr
->current_workspace
+1);
4055 else if (wPreferences
.ws_cycle
)
4056 wWorkspaceChange(scr
, 0);
4058 else if (direction
== CLIP_REWIND
) {
4059 if (scr
->current_workspace
> 0)
4060 wWorkspaceChange(scr
, scr
->current_workspace
-1);
4061 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
4062 wWorkspaceChange(scr
, scr
->workspace_count
-1);
4065 wClipIconPaint(scr
->clip_icon
);
4070 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
4072 WAppIcon
*aicon
= desc
->parent
;
4073 WDock
*dock
= aicon
->dock
;
4074 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4076 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
4079 scr
->last_dock
= dock
;
4081 if (dock
->menu
->flags
.mapped
)
4082 wMenuUnmap(dock
->menu
);
4084 if (IsDoubleClick(scr
, event
)) {
4085 /* double-click was not in the main clip icon */
4086 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
4087 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
4088 iconDblClick(desc
, event
);
4093 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
4094 XUnmapWindow(dpy
, scr
->clip_balloon
);
4095 scr
->flags
.clip_balloon_mapped
= 0;
4099 puts("handling dock");
4101 if (event
->xbutton
.button
== Button1
) {
4102 if (event
->xbutton
.state
& MOD_MASK
)
4107 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
4108 dock
->type
!=WM_DOCK
) {
4109 wIconSelect(aicon
->icon
);
4113 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
4114 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
4115 && dock
->type
==WM_CLIP
)
4116 handleClipChangeWorkspace(scr
, event
);
4118 handleDockMove(dock
, aicon
, event
);
4120 handleIconMove(dock
, aicon
, event
);
4122 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4123 aicon
==scr
->clip_icon
) {
4124 openClipWorkspaceMenu(scr
, event
->xbutton
.x_root
+2,
4125 event
->xbutton
.y_root
+2);
4126 if (scr
->clip_ws_menu
) {
4128 menu
= scr
->clip_ws_menu
;
4129 desc
= &menu
->menu
->descriptor
;
4131 event
->xany
.send_event
= True
;
4132 (*desc
->handle_mousedown
)(desc
, event
);
4134 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4135 (event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
) {
4136 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
4137 } else if (event
->xbutton
.button
== Button3
) {
4138 if (event
->xbutton
.send_event
&&
4139 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
4140 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
4141 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
4142 wwarning("pointer grab failed for dockicon menu");
4146 openDockMenu(dock
, aicon
, event
);
4152 showClipBalloon(WDock
*dock
, int workspace
)
4156 WScreen
*scr
= dock
->screen_ptr
;
4160 scr
->flags
.clip_balloon_mapped
= 1;
4161 XMapWindow(dpy
, scr
->clip_balloon
);
4163 text
= scr
->workspaces
[workspace
]->name
;
4165 w
= WMWidthOfString(scr
->clip_title_font
, text
, strlen(text
));
4167 h
= WMFontHeight(scr
->clip_title_font
);
4168 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
4170 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
4171 y
= dock
->y_pos
+ ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
4173 if (x
+w
> scr
->scr_width
) {
4174 x
= scr
->scr_width
- w
;
4175 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
4176 y
= dock
->y_pos
- h
- 1;
4178 y
= dock
->y_pos
+ ICON_SIZE
;
4179 XRaiseWindow(dpy
, scr
->clip_balloon
);
4181 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
4182 stack
[1] = scr
->clip_balloon
;
4183 XRestackWindows(dpy
, stack
, 2);
4185 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
4186 XSetForeground(dpy
, scr
->clip_title_gc
,
4187 scr
->clip_title_pixel
[CLIP_NORMAL
]);
4188 XClearWindow(dpy
, scr
->clip_balloon
);
4189 WMDrawString(scr
->wmscreen
, scr
->clip_balloon
, scr
->clip_title_gc
,
4190 scr
->clip_title_font
, 0, 0, text
, strlen(text
));
4195 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
4197 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4201 assert(event
->type
==EnterNotify
);
4203 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4206 scr
= btn
->icon
->core
->screen_ptr
;
4207 if (!btn
->omnipresent
)
4210 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
4212 if (!dock
|| dock
->type
!=WM_CLIP
)
4215 /* The auto raise/lower code */
4216 if (dock
->auto_lower_magic
) {
4217 WMDeleteTimerHandler(dock
->auto_lower_magic
);
4218 dock
->auto_lower_magic
= NULL
;
4220 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
4221 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
,
4226 /* The auto expand/collapse code */
4227 if (dock
->auto_collapse_magic
) {
4228 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
4229 dock
->auto_collapse_magic
= NULL
;
4231 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
4232 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
,
4237 if (btn
->xindex
== 0 && btn
->yindex
== 0)
4238 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4240 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4241 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
4242 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
4249 clipLeave(WDock
*dock
)
4252 WObjDescriptor
*desc
= NULL
;
4254 if (!dock
|| dock
->type
!=WM_CLIP
)
4257 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
)!=False
) {
4258 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
4259 (XPointer
*)&desc
)!=XCNOENT
4260 && desc
&& desc
->parent_type
==WCLASS_DOCK_ICON
4261 && ((WAppIcon
*)desc
->parent
)->dock
4262 && ((WAppIcon
*)desc
->parent
)->dock
->type
==WM_CLIP
) {
4263 /* We didn't left the Clip yet */
4264 XPutBackEvent(dpy
, &event
);
4268 XPutBackEvent(dpy
, &event
);
4270 /* We entered a withdrawn window, so we're still in Clip */
4274 if (dock
->auto_raise_magic
) {
4275 WMDeleteTimerHandler(dock
->auto_raise_magic
);
4276 dock
->auto_raise_magic
= NULL
;
4278 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
4279 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
,
4284 if (dock
->auto_expand_magic
) {
4285 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4286 dock
->auto_expand_magic
= NULL
;
4288 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
4289 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
4297 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4299 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4301 assert(event
->type
==LeaveNotify
);
4303 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4306 clipLeave(btn
->dock
);
4311 clipAutoCollapse(void *cdata
)
4313 WDock
*dock
= (WDock
*)cdata
;
4315 if (dock
->type
!=WM_CLIP
)
4318 if (dock
->auto_collapse
) {
4319 dock
->collapsed
= 1;
4320 wDockHideIcons(dock
);
4322 dock
->auto_collapse_magic
= NULL
;
4327 clipAutoExpand(void *cdata
)
4329 WDock
*dock
= (WDock
*)cdata
;
4331 if (dock
->type
!=WM_CLIP
)
4334 if (dock
->auto_collapse
) {
4335 dock
->collapsed
= 0;
4336 wDockShowIcons(dock
);
4338 dock
->auto_expand_magic
= NULL
;
4343 clipAutoLower(void *cdata
)
4345 WDock
*dock
= (WDock
*)cdata
;
4347 if (dock
->type
!=WM_CLIP
)
4350 if (dock
->auto_raise_lower
)
4353 dock
->auto_lower_magic
= NULL
;
4358 clipAutoRaise(void *cdata
)
4360 WDock
*dock
= (WDock
*)cdata
;
4362 if (dock
->type
!=WM_CLIP
)
4365 if (dock
->auto_raise_lower
)
4368 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4369 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4372 dock
->auto_raise_magic
= NULL
;
4377 iconCanBeOmnipresent(WAppIcon
*aicon
)
4379 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4384 for (i
=0; i
<scr
->workspace_count
; i
++) {
4385 clip
= scr
->workspaces
[i
]->clip
;
4387 if (clip
== aicon
->dock
)
4390 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4391 return False
; /* Clip is full in some workspace */
4393 for (j
=0; j
<clip
->max_icons
; j
++) {
4394 btn
= clip
->icon_array
[j
];
4395 if(btn
&& btn
->xindex
==aicon
->xindex
&& btn
->yindex
==aicon
->yindex
)
4405 wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
4407 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4408 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4409 int status
= WO_SUCCESS
;
4411 if ((scr
->dock
&& aicon
->dock
==scr
->dock
) || aicon
==scr
->clip_icon
) {
4412 return WO_NOT_APPLICABLE
;
4415 if (aicon
->omnipresent
== omnipresent
)
4419 if (iconCanBeOmnipresent(aicon
)) {
4420 aicon
->omnipresent
= 1;
4421 new_entry
= wmalloc(sizeof(WAppIconChain
));
4422 new_entry
->aicon
= aicon
;
4423 new_entry
->next
= scr
->global_icons
;
4424 scr
->global_icons
= new_entry
;
4425 scr
->global_icon_count
++;
4427 aicon
->omnipresent
= 0;
4431 aicon
->omnipresent
= 0;
4432 if (aicon
== scr
->global_icons
->aicon
) {
4433 tmp
= scr
->global_icons
->next
;
4434 wfree(scr
->global_icons
);
4435 scr
->global_icons
= tmp
;
4436 scr
->global_icon_count
--;
4438 tmp
= scr
->global_icons
;
4440 if (tmp
->next
->aicon
== aicon
) {
4441 tmp1
= tmp
->next
->next
;
4444 scr
->global_icon_count
--;
4452 wAppIconPaint(aicon
);