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
;
101 static proplist_t dPasteCommand
=NULL
;
103 static proplist_t dDropCommand
=NULL
;
105 static proplist_t dAutoLaunch
, dLock
;
106 static proplist_t dName
, dForced
, dBuggyApplication
, dYes
, dNo
;
107 static proplist_t dHost
, dDock
, dClip
;
108 static proplist_t dAutoAttractIcons
;
110 static proplist_t dPosition
, dApplications
, dLowered
, dCollapsed
, dAutoCollapse
;
112 static proplist_t dAutoRaiseLower
, dOmnipresent
;
114 static void dockIconPaint(WAppIcon
*btn
);
116 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
118 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
);
120 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
122 static int getClipButton(int px
, int py
);
124 static void toggleLowered(WDock
*dock
);
126 static void toggleCollapsed(WDock
*dock
);
128 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
130 static void clipLeave(WDock
*dock
);
132 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
134 Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
);
136 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
137 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
138 static void clipAutoCollapse(void *cdata
);
139 static void clipAutoExpand(void *cdata
);
140 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
);
142 static void clipAutoLower(void *cdata
);
143 static void clipAutoRaise(void *cdata
);
145 static void showClipBalloon(WDock
*dock
, int workspace
);
161 #endif /* OFFIX_DND */
171 dCommand
= PLRetain(PLMakeString("Command"));
172 dPasteCommand
= PLRetain(PLMakeString("PasteCommand"));
173 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 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+1);
214 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
,
216 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
225 toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
227 assert(entry
->clientdata
!=NULL
);
229 toggleLowered(entry
->clientdata
);
231 entry
->flags
.indicator_on
= !(((WDock
*)entry
->clientdata
)->lowered
);
239 killCallback(WMenu
*menu
, WMenuEntry
*entry
)
244 if (!WCHECK_STATE(WSTATE_NORMAL
))
247 assert(entry
->clientdata
!=NULL
);
249 icon
= (WAppIcon
*)entry
->clientdata
;
253 WCHANGE_STATE(WSTATE_MODAL
);
255 buffer
= wstrconcat(icon
->wm_class
,
256 _(" will be forcibly closed.\n"
257 "Any unsaved changes will be lost.\n"
260 if (wPreferences
.dont_confirm_kill
261 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
262 buffer
, _("Yes"), _("No"), NULL
)==WAPRDefault
) {
263 if (icon
->icon
&& icon
->icon
->owner
) {
264 wClientKill(icon
->icon
->owner
);
272 WCHANGE_STATE(WSTATE_NORMAL
);
276 /* TODO: replace this function with a member of the dock struct */
278 numberOfSelectedIcons(WDock
*dock
)
284 for (i
=1; i
<dock
->max_icons
; i
++) {
285 aicon
= dock
->icon_array
[i
];
286 if (aicon
&& aicon
->icon
->selected
) {
296 getSelected(WDock
*dock
)
298 WMArray
*ret
= WMCreateArray(8);
302 for (i
=1; i
<dock
->max_icons
; i
++) {
303 btn
= dock
->icon_array
[i
];
304 if (btn
&& btn
->icon
->selected
) {
305 WMAddToArray(ret
, btn
);
314 paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
316 Window win
= clipIcon
->icon
->core
->window
;
317 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
319 int pt
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
320 int tp
= ICON_SIZE
- pt
;
321 int as
= pt
- 15; /* 15 = 5+5+5 */
322 GC gc
= scr
->clip_title_gc
;
323 #ifdef GRADIENT_CLIP_ARROW
324 Bool collapsed
= clipIcon
->dock
->collapsed
;
330 p
[1].x
= ICON_SIZE
-2;
332 p
[2].x
= ICON_SIZE
-2;
334 } else if (lpushed
) {
338 p
[1].y
= ICON_SIZE
-2;
340 p
[2].y
= ICON_SIZE
-2;
342 if (lpushed
|| rpushed
) {
343 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
344 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
345 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
347 #ifdef GRADIENT_CLIP_ARROW
349 XSetFillStyle(dpy
, scr
->copy_gc
, FillTiled
);
350 XSetTile(dpy
, scr
->copy_gc
, scr
->clip_arrow_gradient
);
351 XSetClipMask(dpy
, scr
->copy_gc
, None
);
354 #endif /* GRADIENT_CLIP_ARROW */
356 /* top right arrow */
357 p
[0].x
= p
[3].x
= ICON_SIZE
-5-as
;
359 p
[1].x
= ICON_SIZE
-6;
361 p
[2].x
= ICON_SIZE
-6;
364 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
365 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
367 #ifdef GRADIENT_CLIP_ARROW
369 XSetTSOrigin(dpy
, gc
, ICON_SIZE
-6-as
, 5);
371 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
372 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
375 /* bottom left arrow */
377 p
[0].y
= p
[3].y
= ICON_SIZE
-5-as
;
379 p
[1].y
= ICON_SIZE
-6;
381 p
[2].y
= ICON_SIZE
-6;
383 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
384 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
386 #ifdef GRADIENT_CLIP_ARROW
388 XSetTSOrigin(dpy
, gc
, 5, ICON_SIZE
-6-as
);
390 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
391 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
393 #ifdef GRADIENT_CLIP_ARROW
395 XSetFillStyle(dpy
, scr
->copy_gc
, FillSolid
);
401 wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
403 RImage
*tile
= RCloneImage(normalTile
);
410 pt
= CLIP_BUTTON_SIZE
*wPreferences
.icon_size
/64;
411 tp
= wPreferences
.icon_size
-1 - pt
;
415 black
.red
= black
.green
= black
.blue
= 0;
418 dark
.red
= dark
.green
= dark
.blue
= 60;
421 light
.red
= light
.green
= light
.blue
= 80;
425 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
-2,
427 RDrawLine(tile
, tp
-1, 0, wPreferences
.icon_size
-1, pt
+1, &black
);
428 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
-3,
432 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4,
433 ICON_SIZE
- 5, 4, &dark
);
434 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5,
435 ICON_SIZE
- 5, 6 + as
, &dark
);
436 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
,
440 ROperateLine(tile
, RAddOperation
, 2, tp
+2, pt
-2,
441 wPreferences
.icon_size
-3, &dark
);
442 RDrawLine(tile
, 0, tp
-1, pt
+1, wPreferences
.icon_size
-1, &black
);
443 ROperateLine(tile
, RSubtractOperation
, 0, tp
-2, pt
+1,
444 wPreferences
.icon_size
-2, &light
);
447 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4,
448 ICON_SIZE
- 5, &dark
);
449 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
,
450 6 + as
, ICON_SIZE
- 5, &dark
);
451 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5,
459 omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
461 WAppIcon
*clickedIcon
= entry
->clientdata
;
464 WMArray
*selectedIcons
;
465 WMArrayIterator iter
;
468 assert(entry
->clientdata
!=NULL
);
470 dock
= clickedIcon
->dock
;
472 selectedIcons
= getSelected(dock
);
474 if (!WMGetArrayItemCount(selectedIcons
))
475 WMAddToArray(selectedIcons
, clickedIcon
);
478 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
479 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
481 else if (aicon
->icon
->selected
)
482 wIconSelect(aicon
->icon
);
484 WMFreeArray(selectedIcons
);
487 wMessageDialog(dock
->screen_ptr
, _("Warning"),
488 _("Some icons cannot be made omnipresent. "
489 "Please make sure that no other icon is "
490 "docked in the same positions on the other "
491 "workspaces and the Clip is not full in "
493 _("OK"), NULL
, NULL
);
494 } else if (failed
== 1) {
495 wMessageDialog(dock
->screen_ptr
, _("Warning"),
496 _("Icon cannot be made omnipresent. "
497 "Please make sure that no other icon is "
498 "docked in the same position on the other "
499 "workspaces and the Clip is not full in "
501 _("OK"), NULL
, NULL
);
507 removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
509 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
512 WMArray
*selectedIcons
;
516 assert(clickedIcon
!=NULL
);
518 dock
= clickedIcon
->dock
;
520 selectedIcons
= getSelected(dock
);
522 if (WMGetArrayItemCount(selectedIcons
)) {
523 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
524 _("All selected icons will be removed!"),
525 _("OK"), _("Cancel"), NULL
)!=WAPRDefault
) {
526 WMFreeArray(selectedIcons
);
530 if (clickedIcon
->xindex
==0 && clickedIcon
->yindex
==0) {
531 WMFreeArray(selectedIcons
);
534 WMAddToArray(selectedIcons
, clickedIcon
);
537 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
538 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
539 wDockDetach(dock
, aicon
);
541 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
542 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
543 aicon
->x_pos
, aicon
->y_pos
);
544 if (!dock
->mapped
|| dock
->collapsed
)
545 XMapWindow(dpy
, aicon
->icon
->core
->window
);
548 WMFreeArray(selectedIcons
);
550 if (wPreferences
.auto_arrange_icons
)
551 wArrangeIcons(dock
->screen_ptr
, True
);
556 keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
558 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
561 WMArray
*selectedIcons
;
564 assert(clickedIcon
!=NULL
);
565 dock
= clickedIcon
->dock
;
567 selectedIcons
= getSelected(dock
);
569 if (!WMGetArrayItemCount(selectedIcons
)
570 && clickedIcon
!=dock
->screen_ptr
->clip_icon
) {
571 char *command
= NULL
;
573 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
574 clickedIcon
->editing
= 1;
575 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
576 _("Type the command used to launch the application"),
578 if (command
&& (command
[0]==0 ||
579 (command
[0]=='-' && command
[1]==0))) {
583 clickedIcon
->command
= command
;
584 clickedIcon
->editing
= 0;
586 clickedIcon
->editing
= 0;
589 WMFreeArray(selectedIcons
);
594 WMAddToArray(selectedIcons
, clickedIcon
);
597 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
598 if (aicon
->icon
->selected
)
599 wIconSelect(aicon
->icon
);
600 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
601 aicon
->attracted
= 0;
602 if (aicon
->icon
->shadowed
) {
603 aicon
->icon
->shadowed
= 0;
604 aicon
->icon
->force_paint
= 1;
605 wAppIconPaint(aicon
);
609 WMFreeArray(selectedIcons
);
616 toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
618 WDock
*dock
= (WDock
*)entry
->clientdata
;
620 assert(entry
->clientdata
!=NULL
);
622 dock
->attract_icons
= !dock
->attract_icons
;
623 /*if (!dock->attract_icons)
624 dock->keep_attracted = 0;*/
626 entry
->flags
.indicator_on
= dock
->attract_icons
;
633 selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
635 WAppIcon
*icon
= (WAppIcon
*)entry
->clientdata
;
639 wIconSelect(icon
->icon
);
646 colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
648 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
651 int x
, y
, x_pos
, y_pos
;
653 assert(entry
->clientdata
!=NULL
);
654 clip
= clickedIcon
->dock
;
656 aicon
= clip
->screen_ptr
->app_icon_list
;
659 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
660 x_pos
= clip
->x_pos
+ x
*ICON_SIZE
;
661 y_pos
= clip
->y_pos
+ y
*ICON_SIZE
;
662 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
664 if (wPreferences
.no_animations
) {
665 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
667 SlideWindow(aicon
->icon
->core
->window
,
668 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
671 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
672 #endif /* ANIMATIONS */
674 aicon
->attracted
= 1;
675 if (!aicon
->icon
->shadowed
) {
676 aicon
->icon
->shadowed
= 1;
677 aicon
->icon
->force_paint
= 1;
678 /* We don't do an wAppIconPaint() here because it's in
679 * wDockAttachIcon(). -Dan
682 wDockAttachIcon(clip
, aicon
, x
, y
);
683 if (clip
->collapsed
|| !clip
->mapped
)
684 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
692 selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
694 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
696 WMArray
*selectedIcons
;
697 WMArrayIterator iter
;
701 assert(clickedIcon
!=NULL
);
702 dock
= clickedIcon
->dock
;
704 selectedIcons
= getSelected(dock
);
706 if (!WMGetArrayItemCount(selectedIcons
)) {
707 for (i
=1; i
<dock
->max_icons
; i
++) {
708 btn
= dock
->icon_array
[i
];
709 if (btn
&& !btn
->icon
->selected
) {
710 wIconSelect(btn
->icon
);
714 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
715 wIconSelect(btn
->icon
);
718 WMFreeArray(selectedIcons
);
725 toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
727 assert(entry
->clientdata
!=NULL
);
729 toggleCollapsed(entry
->clientdata
);
731 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->collapsed
;
738 toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
741 assert(entry
->clientdata
!=NULL
);
743 dock
= (WDock
*) entry
->clientdata
;
745 dock
->auto_collapse
= !dock
->auto_collapse
;
747 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_collapse
;
754 toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
757 assert(entry
->clientdata
!=NULL
);
759 dock
= (WDock
*) entry
->clientdata
;
761 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
763 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_raise_lower
;
770 launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
772 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
774 launchDockedApplication(btn
, False
);
779 settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
781 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
785 ShowDockAppSettingsPanel(btn
);
790 hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
793 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
795 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
797 if (wapp
->flags
.hidden
) {
798 wWorkspaceChange(btn
->icon
->core
->screen_ptr
,wapp
->last_workspace
);
799 wUnhideApplication(wapp
, False
, False
);
801 wHideApplication(wapp
);
807 unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
810 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
812 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
814 wUnhideApplication(wapp
, False
, True
);
819 mainIconCreate(WScreen
*scr
, int type
)
824 if (type
== WM_CLIP
) {
826 return scr
->clip_icon
;
827 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
828 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
829 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
830 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
831 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE;*/
834 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
835 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
841 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
842 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
843 btn
->icon
->core
->descriptor
.parent
= btn
;
844 /*ChangeStackingLevel(btn->icon->core, WMDockLevel);*/
845 XMapWindow(dpy
, btn
->icon
->core
->window
);
850 scr
->clip_icon
= btn
;
857 switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
859 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
860 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
862 WMArray
*selectedIcons
;
865 if (entry
->order
== scr
->current_workspace
)
868 dest
= scr
->workspaces
[entry
->order
]->clip
;
870 selectedIcons
= getSelected(src
);
872 if (WMGetArrayItemCount(selectedIcons
)) {
873 WMArrayIterator iter
;
875 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
876 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
877 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
878 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
881 } else if (icon
!= scr
->clip_icon
) {
882 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
883 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
884 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
887 WMFreeArray(selectedIcons
);
893 launchDockedApplication(WAppIcon
*btn
, Bool withSelection
)
895 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
897 if (!btn
->launching
&&
898 ((!withSelection
&& btn
->command
!=NULL
) ||
899 (withSelection
&& btn
->paste_command
!=NULL
))) {
900 if (!btn
->forced_dock
) {
901 btn
->relaunching
= btn
->running
;
904 if (btn
->wm_instance
|| btn
->wm_class
) {
905 WWindowAttributes attr
;
906 memset(&attr
, 0, sizeof(WWindowAttributes
));
907 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
,
910 if (!attr
.no_appicon
&& !btn
->buggy_app
)
915 btn
->drop_launch
= 0;
916 btn
->paste_launch
= withSelection
;
917 scr
->last_dock
= btn
->dock
;
918 btn
->pid
= execCommand(btn
,
919 withSelection
? btn
->paste_command
: btn
->command
,
922 if (btn
->buggy_app
) {
923 /* give feedback that the app was launched */
927 WMAddTimerHandler(200, (WMCallback
*)dockIconPaint
, btn
);
932 wwarning(_("could not launch application %s\n"), btn
->command
);
934 if (!btn
->relaunching
)
943 updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
945 WScreen
*scr
= menu
->frame
->screen_ptr
;
946 char title
[MAX_WORKSPACENAME_WIDTH
+1];
952 for (i
=0; i
<scr
->workspace_count
; i
++) {
953 if (i
< menu
->entry_no
) {
954 if (strcmp(menu
->entries
[i
]->text
,scr
->workspaces
[i
]->name
)!=0) {
955 wfree(menu
->entries
[i
]->text
);
956 strcpy(title
, scr
->workspaces
[i
]->name
);
957 menu
->entries
[i
]->text
= wstrdup(title
);
958 menu
->flags
.realized
= 0;
960 menu
->entries
[i
]->clientdata
= (void*)icon
;
962 strcpy(title
, scr
->workspaces
[i
]->name
);
964 wMenuAddCallback(menu
, title
, switchWSCommand
, (void*)icon
);
966 menu
->flags
.realized
= 0;
968 if (i
== scr
->current_workspace
) {
969 wMenuSetEnabled(menu
, i
, False
);
971 wMenuSetEnabled(menu
, i
, True
);
975 if (!menu
->flags
.realized
)
981 makeWorkspaceMenu(WScreen
*scr
)
985 menu
= wMenuCreate(scr
, NULL
, False
);
987 wwarning(_("could not create workspace submenu for Clip menu"));
989 wMenuAddCallback(menu
, "", switchWSCommand
, (void*)scr
->clip_icon
);
991 menu
->flags
.realized
= 0;
999 updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
1008 entry
= menu
->entries
[index
];
1009 entry
->flags
.indicator_on
= !dock
->lowered
;
1010 entry
->clientdata
= dock
;
1013 entry
= menu
->entries
[++index
];
1014 entry
->flags
.indicator_on
= dock
->collapsed
;
1015 entry
->clientdata
= dock
;
1018 entry
= menu
->entries
[++index
];
1019 entry
->flags
.indicator_on
= dock
->auto_collapse
;
1020 entry
->clientdata
= dock
;
1022 /* auto-raise/lower */
1023 entry
= menu
->entries
[++index
];
1024 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1025 entry
->clientdata
= dock
;
1028 entry
= menu
->entries
[++index
];
1029 entry
->flags
.indicator_on
= dock
->attract_icons
;
1030 entry
->clientdata
= dock
;
1032 menu
->flags
.realized
= 0;
1038 makeClipOptionsMenu(WScreen
*scr
)
1043 menu
= wMenuCreate(scr
, NULL
, False
);
1045 wwarning(_("could not create options submenu for Clip menu"));
1049 entry
= wMenuAddCallback(menu
, _("Keep on Top"),
1050 toggleLoweredCallback
, NULL
);
1051 entry
->flags
.indicator
= 1;
1052 entry
->flags
.indicator_on
= 1;
1053 entry
->flags
.indicator_type
= MI_CHECK
;
1055 entry
= wMenuAddCallback(menu
, _("Collapsed"),
1056 toggleCollapsedCallback
, NULL
);
1057 entry
->flags
.indicator
= 1;
1058 entry
->flags
.indicator_on
= 1;
1059 entry
->flags
.indicator_type
= MI_CHECK
;
1061 entry
= wMenuAddCallback(menu
, _("Autocollapse"),
1062 toggleAutoCollapseCallback
, NULL
);
1063 entry
->flags
.indicator
= 1;
1064 entry
->flags
.indicator_on
= 1;
1065 entry
->flags
.indicator_type
= MI_CHECK
;
1067 entry
= wMenuAddCallback(menu
, _("Autoraise"),
1068 toggleAutoRaiseLowerCallback
, NULL
);
1069 entry
->flags
.indicator
= 1;
1070 entry
->flags
.indicator_on
= 1;
1071 entry
->flags
.indicator_type
= MI_CHECK
;
1073 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"),
1074 toggleAutoAttractCallback
, NULL
);
1075 entry
->flags
.indicator
= 1;
1076 entry
->flags
.indicator_on
= 1;
1077 entry
->flags
.indicator_type
= MI_CHECK
;
1079 menu
->flags
.realized
= 0;
1087 dockMenuCreate(WScreen
*scr
, int type
)
1092 if (type
== WM_CLIP
&& scr
->clip_menu
)
1093 return scr
->clip_menu
;
1095 menu
= wMenuCreate(scr
, NULL
, False
);
1096 if (type
!= WM_CLIP
) {
1097 entry
= wMenuAddCallback(menu
, _("Keep on Top"),
1098 toggleLoweredCallback
, NULL
);
1099 entry
->flags
.indicator
= 1;
1100 entry
->flags
.indicator_on
= 1;
1101 entry
->flags
.indicator_type
= MI_CHECK
;
1103 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1104 scr
->clip_options
= makeClipOptionsMenu(scr
);
1105 if (scr
->clip_options
)
1106 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1108 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
,
1111 entry
->text
= _("Rename Workspace");
1113 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1114 entry
->flags
.indicator
= 1;
1115 entry
->flags
.indicator_on
= 1;
1116 entry
->flags
.indicator_type
= MI_CHECK
;
1118 entry
= wMenuAddCallback(menu
, _("Select All Icons"),
1119 selectIconsCallback
, NULL
);
1121 entry
->text
= _("Select All Icons");
1123 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1125 entry
->text
= _("Keep Icon");
1127 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1129 entry
->text
= _("Move Icon To");
1130 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1131 if (scr
->clip_submenu
)
1132 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1134 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
,
1137 entry
->text
= _("Remove Icon");
1139 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1142 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1144 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1146 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1148 entry
->text
= _("Hide");
1150 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1152 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1154 if (type
== WM_CLIP
)
1155 scr
->clip_menu
= menu
;
1162 wDockCreate(WScreen
*scr
, int type
)
1170 dock
= wmalloc(sizeof(WDock
));
1171 memset(dock
, 0, sizeof(WDock
));
1173 if (type
== WM_CLIP
)
1174 icon_count
= CLIP_MAX_ICONS
;
1176 icon_count
= scr
->scr_height
/wPreferences
.icon_size
;
1178 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*)*icon_count
);
1179 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*)*icon_count
);
1181 dock
->max_icons
= icon_count
;
1183 btn
= mainIconCreate(scr
, type
);
1187 dock
->x_pos
= btn
->x_pos
;
1188 dock
->y_pos
= btn
->y_pos
;
1189 dock
->screen_ptr
= scr
;
1191 dock
->icon_count
= 1;
1192 dock
->on_right_side
= 1;
1193 dock
->collapsed
= 0;
1194 dock
->auto_collapse
= 0;
1195 dock
->auto_collapse_magic
= NULL
;
1196 dock
->auto_raise_lower
= 0;
1197 dock
->auto_lower_magic
= NULL
;
1198 dock
->auto_raise_magic
= NULL
;
1199 dock
->attract_icons
= 0;
1201 dock
->icon_array
[0] = btn
;
1202 wRaiseFrame(btn
->icon
->core
);
1203 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1205 /* create dock menu */
1206 dock
->menu
= dockMenuCreate(scr
, type
);
1213 wDockDestroy(WDock
*dock
)
1218 for (i
=(dock
->type
== WM_CLIP
) ? 1 : 0; i
<dock
->max_icons
; i
++) {
1219 aicon
= dock
->icon_array
[i
];
1221 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1222 wDockDetach(dock
, aicon
);
1224 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
1225 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
1226 aicon
->x_pos
, aicon
->y_pos
);
1227 if (!dock
->mapped
|| dock
->collapsed
)
1228 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1232 if (wPreferences
.auto_arrange_icons
)
1233 wArrangeIcons(dock
->screen_ptr
, True
);
1234 wfree(dock
->icon_array
);
1235 if (dock
->menu
&& dock
->type
!=WM_CLIP
)
1236 wMenuDestroy(dock
->menu
, True
);
1237 if (dock
->screen_ptr
->last_dock
== dock
)
1238 dock
->screen_ptr
->last_dock
= NULL
;
1244 wClipIconPaint(WAppIcon
*aicon
)
1246 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1247 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1249 Window win
= aicon
->icon
->core
->window
;
1250 int length
, nlength
;
1251 char *ws_name
, ws_number
[10];
1254 wIconPaint(aicon
->icon
);
1256 length
= strlen(workspace
->name
);
1257 ws_name
= wmalloc(length
+ 1);
1258 snprintf(ws_name
, length
+1, "%s", workspace
->name
);
1259 snprintf(ws_number
, sizeof(ws_number
), "%i", scr
->current_workspace
+ 1);
1260 nlength
= strlen(ws_number
);
1262 gc
= scr
->clip_title_gc
;
1264 if (!workspace
->clip
->collapsed
)
1265 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_NORMAL
]);
1267 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_COLLAPSED
]);
1269 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1271 tx
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
1273 WMDrawString(scr
->wmscreen
, win
, gc
, scr
->clip_title_font
, tx
,
1274 ty
, ws_name
, length
);
1276 tx
= (ICON_SIZE
/2 - WMWidthOfString(scr
->clip_title_font
, ws_number
,
1279 WMDrawString(scr
->wmscreen
, win
, gc
, scr
->clip_title_font
, tx
,
1280 2, ws_number
, nlength
);
1284 if (aicon
->launching
) {
1285 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1286 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1288 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
,
1289 aicon
->dock
->rclip_button_pushed
);
1294 clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1296 wClipIconPaint(desc
->parent
);
1301 dockIconPaint(WAppIcon
*btn
)
1303 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1304 wClipIconPaint(btn
);
1311 make_icon_state(WAppIcon
*btn
)
1313 proplist_t node
= NULL
;
1314 proplist_t command
, autolaunch
, lock
, name
, forced
, host
, position
, buggy
;
1315 proplist_t omnipresent
;
1321 command
= PLMakeString("-");
1323 command
= PLMakeString(btn
->command
);
1325 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1327 lock
= btn
->lock
? dYes
: dNo
;
1329 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1331 name
= PLMakeString(tmp
);
1335 forced
= btn
->forced_dock
? dYes
: dNo
;
1337 buggy
= btn
->buggy_app
? dYes
: dNo
;
1339 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1340 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1342 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1343 position
= PLMakeString(buffer
);
1345 node
= PLMakeDictionaryFromEntries(dCommand
, command
,
1347 dAutoLaunch
, autolaunch
,
1350 dBuggyApplication
, buggy
,
1351 dPosition
, position
,
1355 PLRelease(position
);
1357 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1358 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&&
1359 (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1360 PLInsertDictionaryEntry(node
, dOmnipresent
, omnipresent
);
1363 if (btn
->dnd_command
) {
1364 command
= PLMakeString(btn
->dnd_command
);
1365 PLInsertDictionaryEntry(node
, dDropCommand
, command
);
1368 #endif /* OFFIX_DND */
1370 if (btn
->paste_command
) {
1371 command
= PLMakeString(btn
->paste_command
);
1372 PLInsertDictionaryEntry(node
, dPasteCommand
, command
);
1376 if (btn
->client_machine
&& btn
->remote_start
) {
1377 host
= PLMakeString(btn
->client_machine
);
1378 PLInsertDictionaryEntry(node
, dHost
, host
);
1388 dockSaveState(WDock
*dock
)
1391 proplist_t icon_info
;
1392 proplist_t list
=NULL
, dock_state
=NULL
;
1393 proplist_t value
, key
;
1396 list
= PLMakeArrayFromElements(NULL
);
1398 for (i
=(dock
->type
==WM_DOCK
? 0 : 1); i
<dock
->max_icons
; i
++) {
1399 WAppIcon
*btn
= dock
->icon_array
[i
];
1401 if (!btn
|| btn
->attracted
)
1404 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1405 list
= PLAppendArrayElement(list
, icon_info
);
1406 PLRelease(icon_info
);
1410 dock_state
= PLMakeDictionaryFromEntries(dApplications
, list
,
1413 if (dock
->type
== WM_DOCK
) {
1414 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1415 key
= PLMakeString(buffer
);
1416 PLInsertDictionaryEntry(dock_state
, key
, list
);
1420 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0),
1422 value
= PLMakeString(buffer
);
1423 PLInsertDictionaryEntry(dock_state
, dPosition
, value
);
1429 value
= (dock
->lowered
? dYes
: dNo
);
1430 PLInsertDictionaryEntry(dock_state
, dLowered
, value
);
1432 if (dock
->type
== WM_CLIP
) {
1433 value
= (dock
->collapsed
? dYes
: dNo
);
1434 PLInsertDictionaryEntry(dock_state
, dCollapsed
, value
);
1436 value
= (dock
->auto_collapse
? dYes
: dNo
);
1437 PLInsertDictionaryEntry(dock_state
, dAutoCollapse
, value
);
1439 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1440 PLInsertDictionaryEntry(dock_state
, dAutoRaiseLower
, value
);
1442 value
= (dock
->attract_icons
? dYes
: dNo
);
1443 PLInsertDictionaryEntry(dock_state
, dAutoAttractIcons
, value
);
1451 wDockSaveState(WScreen
*scr
, proplist_t old_state
)
1453 proplist_t dock_state
;
1456 dock_state
= dockSaveState(scr
->dock
);
1459 * Copy saved states of docks with different sizes.
1465 keys
= PLGetAllDictionaryKeys(old_state
);
1466 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
1467 tmp
= PLGetArrayElement(keys
, i
);
1469 if (strncasecmp(PLGetString(tmp
), "applications", 12) == 0
1470 && !PLGetDictionaryEntry(dock_state
, tmp
)) {
1472 PLInsertDictionaryEntry(dock_state
,
1474 PLGetDictionaryEntry(old_state
, tmp
));
1481 PLInsertDictionaryEntry(scr
->session_state
, dDock
, dock_state
);
1483 PLRelease(dock_state
);
1488 wClipSaveState(WScreen
*scr
)
1490 proplist_t clip_state
;
1492 clip_state
= make_icon_state(scr
->clip_icon
);
1494 PLInsertDictionaryEntry(scr
->session_state
, dClip
, clip_state
);
1496 PLRelease(clip_state
);
1501 wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1503 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1508 getBooleanDockValue(proplist_t value
, proplist_t key
)
1511 if (PLIsString(value
)) {
1512 if (strcasecmp(PLGetString(value
), "YES")==0)
1515 wwarning(_("bad value in docked icon state info %s"),
1524 restore_icon_state(WScreen
*scr
, proplist_t info
, int type
, int index
)
1527 proplist_t cmd
, value
;
1530 cmd
= PLGetDictionaryEntry(info
, dCommand
);
1531 if (!cmd
|| !PLIsString(cmd
)) {
1535 /* parse window name */
1536 value
= PLGetDictionaryEntry(info
, dName
);
1541 char *wclass
, *winstance
;
1544 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1546 if (!winstance
&& !wclass
) {
1553 command
= wstrdup(PLGetString(cmd
));
1557 if (!command
|| strcmp(command
, "-")==0) {
1568 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
,
1578 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1579 if (type
== WM_CLIP
) {
1580 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1581 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1583 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1584 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1588 cmd
= PLGetDictionaryEntry(info
, dDropCommand
);
1590 aicon
->dnd_command
= wstrdup(PLGetString(cmd
));
1593 cmd
= PLGetDictionaryEntry(info
, dPasteCommand
);
1595 aicon
->paste_command
= wstrdup(PLGetString(cmd
));
1597 /* check auto launch */
1598 value
= PLGetDictionaryEntry(info
, dAutoLaunch
);
1600 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1603 value
= PLGetDictionaryEntry(info
, dLock
);
1605 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1607 /* check if it wasn't normally docked */
1608 value
= PLGetDictionaryEntry(info
, dForced
);
1610 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1612 /* check if we can rely on the stuff in the app */
1613 value
= PLGetDictionaryEntry(info
, dBuggyApplication
);
1615 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1617 /* get position in the dock */
1618 value
= PLGetDictionaryEntry(info
, dPosition
);
1619 if (value
&& PLIsString(value
)) {
1620 if (sscanf(PLGetString(value
), "%hi,%hi", &aicon
->xindex
,
1622 wwarning(_("bad value in docked icon state info %s"),
1623 PLGetString(dPosition
));
1625 /* check position sanity */
1626 /* incomplete section! */
1627 if (type
== WM_DOCK
) {
1629 if (aicon
->yindex
< 0)
1630 wwarning(_("bad value in docked icon position %i,%i"),
1631 aicon
->xindex
, aicon
->yindex
);
1634 aicon
->yindex
= index
;
1638 /* check if icon is omnipresent */
1639 value
= PLGetDictionaryEntry(info
, dOmnipresent
);
1641 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1650 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1654 wClipRestoreState(WScreen
*scr
, proplist_t clip_state
)
1660 icon
= mainIconCreate(scr
, WM_CLIP
);
1665 PLRetain(clip_state
);
1667 /* restore position */
1669 value
= PLGetDictionaryEntry(clip_state
, dPosition
);
1672 if (!PLIsString(value
))
1673 COMPLAIN("Position");
1675 if (sscanf(PLGetString(value
), "%i,%i", &icon
->x_pos
,
1677 COMPLAIN("Position");
1679 /* check position sanity */
1680 if (icon
->y_pos
< 0)
1682 else if (icon
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1683 icon
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1685 if (icon
->x_pos
< 0)
1687 else if (icon
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1688 icon
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1693 value
= PLGetDictionaryEntry(clip_state
, dDropCommand
);
1694 if (value
&& PLIsString(value
))
1695 icon
->dnd_command
= wstrdup(PLGetString(value
));
1698 value
= PLGetDictionaryEntry(clip_state
, dPasteCommand
);
1699 if (value
&& PLIsString(value
))
1700 icon
->paste_command
= wstrdup(PLGetString(value
));
1702 PLRelease(clip_state
);
1709 wDockRestoreState(WScreen
*scr
, proplist_t dock_state
, int type
)
1714 WAppIcon
*aicon
, *old_top
;
1718 dock
= wDockCreate(scr
, type
);
1724 PLRetain(dock_state
);
1727 /* restore position */
1729 value
= PLGetDictionaryEntry(dock_state
, dPosition
);
1732 if (!PLIsString(value
))
1733 COMPLAIN("Position");
1735 if (sscanf(PLGetString(value
), "%i,%i", &dock
->x_pos
,
1737 COMPLAIN("Position");
1739 /* check position sanity */
1740 if (dock
->y_pos
< 0)
1742 else if (dock
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1743 dock
->y_pos
= scr
->scr_height
- ICON_SIZE
;
1745 /* This is no more needed. ??? */
1746 if (type
== WM_CLIP
) {
1747 if (dock
->x_pos
< 0)
1749 else if (dock
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1750 dock
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1752 if (dock
->x_pos
>= 0) {
1753 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1754 dock
->on_right_side
= 0;
1756 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1757 dock
->on_right_side
= 1;
1763 /* restore lowered/raised state */
1767 value
= PLGetDictionaryEntry(dock_state
, dLowered
);
1770 if (!PLIsString(value
))
1771 COMPLAIN("Lowered");
1773 if (strcasecmp(PLGetString(value
), "YES")==0)
1779 /* restore collapsed state */
1781 dock
->collapsed
= 0;
1783 value
= PLGetDictionaryEntry(dock_state
, dCollapsed
);
1786 if (!PLIsString(value
))
1787 COMPLAIN("Collapsed");
1789 if (strcasecmp(PLGetString(value
), "YES")==0)
1790 dock
->collapsed
= 1;
1795 /* restore auto-collapsed state */
1797 value
= PLGetDictionaryEntry(dock_state
, dAutoCollapse
);
1800 if (!PLIsString(value
))
1801 COMPLAIN("AutoCollapse");
1803 if (strcasecmp(PLGetString(value
), "YES")==0) {
1804 dock
->auto_collapse
= 1;
1805 dock
->collapsed
= 1;
1811 /* restore auto-raise/lower state */
1813 value
= PLGetDictionaryEntry(dock_state
, dAutoRaiseLower
);
1816 if (!PLIsString(value
))
1817 COMPLAIN("AutoRaiseLower");
1819 if (strcasecmp(PLGetString(value
), "YES")==0) {
1820 dock
->auto_raise_lower
= 1;
1825 /* restore attract icons state */
1827 dock
->attract_icons
= 0;
1829 value
= PLGetDictionaryEntry(dock_state
, dAutoAttractIcons
);
1832 if (!PLIsString(value
))
1833 COMPLAIN("AutoAttractIcons");
1835 if (strcasecmp(PLGetString(value
), "YES")==0)
1836 dock
->attract_icons
= 1;
1841 /* application list */
1848 * When saving, it saves the dock state in
1849 * Applications and Applicationsnnn
1851 * When loading, it will first try Applicationsnnn.
1852 * If it does not exist, use Applications as default.
1855 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1857 tmp
= PLMakeString(buffer
);
1858 apps
= PLGetDictionaryEntry(dock_state
, tmp
);
1862 apps
= PLGetDictionaryEntry(dock_state
, dApplications
);
1870 count
= PLGetNumberOfElements(apps
);
1875 old_top
= dock
->icon_array
[0];
1877 /* dock->icon_count is set to 1 when dock is created.
1878 * Since Clip is already restored, we want to keep it so for clip,
1879 * but for dock we may change the default top tile, so we set it to 0.
1881 if (type
== WM_DOCK
)
1882 dock
->icon_count
= 0;
1884 for (i
=0; i
<count
; i
++) {
1885 if (dock
->icon_count
>= dock
->max_icons
) {
1886 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1890 value
= PLGetArrayElement(apps
, i
);
1891 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1893 dock
->icon_array
[dock
->icon_count
] = aicon
;
1897 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
*ICON_SIZE
);
1898 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
*ICON_SIZE
);
1901 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1903 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1905 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
,
1908 if (!dock
->collapsed
)
1909 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1910 wRaiseFrame(aicon
->icon
->core
);
1913 } else if (dock
->icon_count
==0 && type
==WM_DOCK
)
1917 /* if the first icon is not defined, use the default */
1918 if (dock
->icon_array
[0]==NULL
) {
1919 /* update default icon */
1920 old_top
->x_pos
= dock
->x_pos
;
1921 old_top
->y_pos
= dock
->y_pos
;
1923 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1925 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1926 dock
->icon_array
[0] = old_top
;
1927 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1928 /* we don't need to increment dock->icon_count here because it was
1929 * incremented in the loop above.
1931 } else if (old_top
!=dock
->icon_array
[0]) {
1932 if (old_top
== scr
->clip_icon
)
1933 scr
->clip_icon
= dock
->icon_array
[0];
1934 wAppIconDestroy(old_top
);
1939 PLRelease(dock_state
);
1947 wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1949 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1951 btn
->drop_launch
= 0;
1952 btn
->paste_launch
= 0;
1954 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1957 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1969 wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1975 for (i
= 0; i
< dock
->max_icons
; i
++) {
1976 btn
= dock
->icon_array
[i
];
1977 if (!btn
|| !btn
->auto_launch
)
1980 state
= wmalloc(sizeof(WSavedState
));
1981 memset(state
, 0, sizeof(WSavedState
));
1982 state
->workspace
= workspace
;
1983 /* TODO: this is klugy and is very difficult to understand
1984 * what's going on. Try to clean up */
1985 wDockLaunchWithState(dock
, btn
, state
);
1992 findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1998 if ((dock
= scr
->dock
)!=NULL
) {
1999 for (i
=0; i
<dock
->max_icons
; i
++) {
2000 if (dock
->icon_array
[i
]
2001 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
2007 if (*icon_pos
<0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
)!=NULL
) {
2008 for (i
=0; i
<dock
->max_icons
; i
++) {
2009 if (dock
->icon_array
[i
]
2010 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
2023 wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
2029 dock
= findDock(scr
, event
, &icon_pos
);
2034 * Return True if the drop was on an application icon window.
2035 * In this case, let the ClientMessage handler redirect the
2036 * message to the app.
2038 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!=None
)
2041 if (dock
->icon_array
[icon_pos
]->dnd_command
!=NULL
) {
2042 scr
->flags
.dnd_data_convertion_status
= 0;
2044 btn
= dock
->icon_array
[icon_pos
];
2046 if (!btn
->forced_dock
) {
2047 btn
->relaunching
= btn
->running
;
2050 if (btn
->wm_instance
|| btn
->wm_class
) {
2051 WWindowAttributes attr
;
2052 memset(&attr
, 0, sizeof(WWindowAttributes
));
2053 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
2055 btn
->wm_class
, &attr
, NULL
, True
);
2057 if (!attr
.no_appicon
)
2063 btn
->paste_launch
= 0;
2064 btn
->drop_launch
= 1;
2065 scr
->last_dock
= dock
;
2066 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
2071 if (!btn
->relaunching
) {
2078 #endif /* OFFIX_DND */
2083 wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2090 wwin
= icon
->icon
->owner
;
2091 if (icon
->command
==NULL
) {
2093 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2095 icon
->command
= wtokenjoin(argv
, argc
);
2096 XFreeStringList(argv
);
2100 /* icon->forced_dock = 1;*/
2101 if (dock
->type
!=WM_CLIP
|| !icon
->attracted
) {
2103 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2104 _("Type the command used to launch the application"),
2106 if (command
&& (command
[0]==0 ||
2107 (command
[0]=='-' && command
[1]==0))) {
2111 icon
->command
= command
;
2117 /* If the target is the dock, reject the icon. If
2118 * the target is the clip, make it an attracted icon
2120 if (dock
->type
==WM_CLIP
) {
2121 icon
->attracted
= 1;
2122 if (!icon
->icon
->shadowed
) {
2123 icon
->icon
->shadowed
= 1;
2124 icon
->icon
->force_paint
= 1;
2136 for (index
=1; index
<dock
->max_icons
; index
++)
2137 if (dock
->icon_array
[index
] == NULL
)
2139 /* if (index == dock->max_icons)
2142 assert(index
< dock
->max_icons
);
2144 dock
->icon_array
[index
] = icon
;
2148 icon
->omnipresent
= 0;
2150 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2151 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2156 icon
->launching
= 0;
2159 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2160 if (dock
->type
== WM_CLIP
) {
2161 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2162 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2164 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2165 icon
->icon
->core
->descriptor
.parent
= icon
;
2167 MoveInStackListUnder(dock
->icon_array
[index
-1]->icon
->core
,
2169 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2170 wAppIconPaint(icon
);
2172 if (wPreferences
.auto_arrange_icons
)
2173 wArrangeIcons(dock
->screen_ptr
, True
);
2176 if (icon
->command
&& !icon
->dnd_command
) {
2177 int len
= strlen(icon
->command
)+8;
2178 icon
->dnd_command
= wmalloc(len
);
2179 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
2183 if (icon
->command
&& !icon
->paste_command
) {
2184 int len
= strlen(icon
->command
)+8;
2185 icon
->paste_command
= wmalloc(len
);
2186 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
2194 reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2198 for(index
=1; index
<dock
->max_icons
; index
++) {
2199 if(dock
->icon_array
[index
] == icon
)
2202 assert(index
< dock
->max_icons
);
2207 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2208 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2213 moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2221 return True
; /* No move needed, we're already there */
2226 wwin
= icon
->icon
->owner
;
2229 * For the moment we can't do this if we move icons in Clip from one
2230 * workspace to other, because if we move two or more icons without
2231 * command, the dialog box will not be able to tell us to which of the
2232 * moved icons it applies. -Dan
2234 if ((dest
->type
==WM_DOCK
/*|| dest->keep_attracted*/) && icon
->command
==NULL
) {
2235 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2237 icon
->command
= wtokenjoin(argv
, argc
);
2238 XFreeStringList(argv
);
2243 /* icon->forced_dock = 1;*/
2244 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2245 _("Type the command used to launch the application"),
2247 if (command
&& (command
[0]==0 ||
2248 (command
[0]=='-' && command
[1]==0))) {
2252 icon
->command
= command
;
2263 if (dest
->type
== WM_DOCK
)
2264 wClipMakeIconOmnipresent(icon
, False
);
2266 for(index
=1; index
<src
->max_icons
; index
++) {
2267 if(src
->icon_array
[index
] == icon
)
2270 assert(index
< src
->max_icons
);
2272 src
->icon_array
[index
] = NULL
;
2275 for(index
=1; index
<dest
->max_icons
; index
++) {
2276 if(dest
->icon_array
[index
] == NULL
)
2279 /* if (index == dest->max_icons)
2282 assert(index
< dest
->max_icons
);
2284 dest
->icon_array
[index
] = icon
;
2287 /* deselect the icon */
2288 if (icon
->icon
->selected
)
2289 wIconSelect(icon
->icon
);
2291 if (dest
->type
== WM_DOCK
) {
2292 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2293 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2295 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2296 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2299 /* set it to be kept when moving to dock.
2300 * Unless the icon does not have a command set
2302 if (icon
->command
&& dest
->type
==WM_DOCK
) {
2303 icon
->attracted
= 0;
2304 if (icon
->icon
->shadowed
) {
2305 icon
->icon
->shadowed
= 0;
2306 icon
->icon
->force_paint
= 1;
2310 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2316 icon
->x_pos
= dest
->x_pos
+ x
*ICON_SIZE
;
2317 icon
->y_pos
= dest
->y_pos
+ y
*ICON_SIZE
;
2321 MoveInStackListUnder(dest
->icon_array
[index
-1]->icon
->core
,
2323 wAppIconPaint(icon
);
2330 wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2334 /* make the settings panel be closed */
2336 DestroyDockAppSettingsPanel(icon
->panel
);
2339 /* This must be called before icon->dock is set to NULL.
2340 * Don't move it. -Dan
2342 wClipMakeIconOmnipresent(icon
, False
);
2346 icon
->attracted
= 0;
2347 icon
->auto_launch
= 0;
2348 if (icon
->icon
->shadowed
) {
2349 icon
->icon
->shadowed
= 0;
2350 icon
->icon
->force_paint
= 1;
2353 /* deselect the icon */
2354 if (icon
->icon
->selected
)
2355 wIconSelect(icon
->icon
);
2357 if (icon
->command
) {
2358 wfree(icon
->command
);
2359 icon
->command
= NULL
;
2362 if (icon
->dnd_command
) {
2363 wfree(icon
->dnd_command
);
2364 icon
->dnd_command
= NULL
;
2367 if (icon
->paste_command
) {
2368 wfree(icon
->paste_command
);
2369 icon
->paste_command
= NULL
;
2372 for (index
=1; index
<dock
->max_icons
; index
++)
2373 if (dock
->icon_array
[index
] == icon
)
2375 assert(index
< dock
->max_icons
);
2376 dock
->icon_array
[index
] = NULL
;
2382 /* if the dock is not attached to an application or
2383 * the the application did not set the approriate hints yet,
2384 * destroy the icon */
2385 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2386 wAppIconDestroy(icon
);
2388 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2389 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2390 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2391 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2392 icon
->icon
->core
->descriptor
.parent
= icon
;
2394 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2396 wAppIconPaint(icon
);
2397 if (wPreferences
.auto_arrange_icons
) {
2398 wArrangeIcons(dock
->screen_ptr
, True
);
2400 WAppIcon
*bla
= wAppIconNextSibling(icon
);
2403 SlideWindow(icon
->icon
->core
->window
, icon
->x_pos
, icon
->y_pos
,
2404 bla
->x_pos
, bla
->y_pos
);
2405 wAppIconMove(icon
, bla
->x_pos
, bla
->y_pos
);
2409 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2415 * returns the closest Dock slot index for the passed
2418 * Returns False if icon can't be docked.
2420 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2424 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2425 int *ret_x
, int *ret_y
, int redocking
)
2427 WScreen
*scr
= dock
->screen_ptr
;
2430 int i
, offset
= ICON_SIZE
/2;
2431 WAppIcon
*aicon
= NULL
;
2432 WAppIcon
*nicon
= NULL
;
2433 int max_y_icons
, max_x_icons
;
2435 max_x_icons
= scr
->scr_width
/ICON_SIZE
;
2436 max_y_icons
= scr
->scr_height
/ICON_SIZE
-1;
2438 if (wPreferences
.flags
.noupdates
)
2444 /* if the dock is full */
2446 (dock
->icon_count
>= dock
->max_icons
)) {
2450 /* exact position */
2452 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2454 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2457 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2459 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2461 /* check if the icon is outside the screen boundaries */
2462 if (dx
+ ex_x
*ICON_SIZE
< -ICON_SIZE
+2 ||
2463 dx
+ ex_x
*ICON_SIZE
>= scr
->scr_width
-1 ||
2464 dy
+ ex_y
*ICON_SIZE
< -ICON_SIZE
+2 ||
2465 dy
+ ex_y
*ICON_SIZE
>= scr
->scr_height
-1)
2468 if (dock
->type
== WM_DOCK
) {
2469 if (icon
->dock
!= dock
&& ex_x
!= 0)
2473 for (i
=0; i
<dock
->max_icons
; i
++) {
2474 nicon
= dock
->icon_array
[i
];
2475 if (nicon
&& nicon
->yindex
== ex_y
) {
2482 int sig
, done
, closest
;
2484 /* Possible cases when redocking:
2486 * icon dragged out of range of any slot -> false
2487 * icon dragged to range of free slot
2488 * icon dragged to range of same slot
2489 * icon dragged to range of different icon
2491 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2494 if (ex_y
>=0 && ex_y
<=max_y_icons
&& (aicon
==icon
|| !aicon
)) {
2500 /* start looking at the upper slot or lower? */
2501 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2508 /* look for closest free slot */
2509 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2513 closest
= sig
*(i
/2) + ex_y
;
2514 /* check if this slot is used */
2516 for (j
= 0; j
<dock
->max_icons
; j
++) {
2517 if (dock
->icon_array
[j
]
2518 && dock
->icon_array
[j
]->yindex
==closest
) {
2519 /* slot is used by someone else */
2520 if (dock
->icon_array
[j
]!=icon
)
2528 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2529 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2531 (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+1))) {
2536 } else { /* !redocking */
2538 /* if slot is free and the icon is close enough, return it */
2539 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2549 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2550 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+1;
2553 for (k
=start
; k
<stop
; k
++) {
2554 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2557 for (i
=0; i
<tmp
->max_icons
; i
++) {
2558 nicon
= tmp
->icon_array
[i
];
2559 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2567 for (k
=start
; k
<stop
; k
++) {
2568 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2571 for (i
=0; i
<tmp
->max_icons
; i
++) {
2572 nicon
= tmp
->icon_array
[i
];
2573 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2574 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2575 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2584 if (neighbours
&& (aicon
==NULL
|| (redocking
&& aicon
== icon
))) {
2594 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2595 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2596 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2600 * returns true if it can find a free slot in the dock,
2601 * in which case it changes x_pos and y_pos accordingly.
2602 * Else returns false.
2605 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2607 WScreen
*scr
= dock
->screen_ptr
;
2609 WAppIconChain
*chain
;
2610 unsigned char *slot_map
;
2614 int i
, done
= False
;
2616 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2619 if (dock
->type
== WM_CLIP
&&
2620 dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2621 extra_count
= scr
->global_icon_count
;
2623 /* if the dock is full */
2624 if (dock
->icon_count
+extra_count
>= dock
->max_icons
) {
2628 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2629 if (scr
->dock
->on_right_side
)
2630 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2632 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2635 if (ex
< dock
->x_pos
)
2637 if (sx
> dock
->x_pos
+ICON_SIZE
)
2638 sx
= dock
->x_pos
+ICON_SIZE
;
2645 /* check if clip is in a corner */
2646 if (dock
->type
==WM_CLIP
) {
2647 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2649 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2651 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2653 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2660 /* If the clip is in the corner, use only slots that are in the border
2662 if (corner
!=C_NONE
) {
2666 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2667 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2668 hmap
= wmalloc(hcount
+1);
2669 memset(hmap
, 0, hcount
+1);
2670 vmap
= wmalloc(vcount
+1);
2671 memset(vmap
, 0, vcount
+1);
2673 /* mark used positions */
2676 for (i
=0; i
<dock
->max_icons
; i
++) {
2677 btn
= dock
->icon_array
[i
];
2681 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2682 vmap
[btn
->yindex
] = 1;
2683 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2684 hmap
[btn
->xindex
] = 1;
2686 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2688 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2689 vmap
[btn
->yindex
] = 1;
2690 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2691 hmap
[btn
->xindex
] = 1;
2695 for (i
=0; i
<dock
->max_icons
; i
++) {
2696 btn
= dock
->icon_array
[i
];
2700 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2701 vmap
[btn
->yindex
] = 1;
2702 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2703 hmap
[-btn
->xindex
] = 1;
2705 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2707 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2708 vmap
[btn
->yindex
] = 1;
2709 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2710 hmap
[-btn
->xindex
] = 1;
2714 for (i
=0; i
<dock
->max_icons
; i
++) {
2715 btn
= dock
->icon_array
[i
];
2719 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2720 vmap
[-btn
->yindex
] = 1;
2721 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2722 hmap
[btn
->xindex
] = 1;
2724 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2726 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2727 vmap
[-btn
->yindex
] = 1;
2728 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2729 hmap
[btn
->xindex
] = 1;
2734 for (i
=0; i
<dock
->max_icons
; i
++) {
2735 btn
= dock
->icon_array
[i
];
2739 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2740 vmap
[-btn
->yindex
] = 1;
2741 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2742 hmap
[-btn
->xindex
] = 1;
2744 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2746 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2747 vmap
[-btn
->yindex
] = 1;
2748 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2749 hmap
[-btn
->xindex
] = 1;
2754 /* search a vacant slot */
2755 for (i
=1; i
<WMAX(vcount
, hcount
); i
++) {
2756 if (i
< vcount
&& vmap
[i
]==0) {
2762 } else if (i
< hcount
&& hmap
[i
]==0) {
2772 /* If found a slot, translate and return */
2774 if (corner
==C_NW
|| corner
==C_NE
) {
2779 if (corner
==C_NE
|| corner
==C_SE
) {
2786 /* else, try to find a slot somewhere else */
2789 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2790 * placed outside of screen */
2791 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2793 /* In the worst case (the clip is in the corner of the screen),
2794 * the amount of icons that fit in the clip is smaller.
2795 * Double the map to get a safe value.
2801 slot_map
= wmalloc(mwidth
*mwidth
);
2802 memset(slot_map
, 0, mwidth
*mwidth
);
2804 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2806 /* mark used slots in the map. If the slot falls outside the map
2807 * (for example, when all icons are placed in line), ignore them. */
2808 for (i
=0; i
<dock
->max_icons
; i
++) {
2809 btn
= dock
->icon_array
[i
];
2811 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2813 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2814 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2816 /* Find closest slot from the center that is free by scanning the
2817 * map from the center to outward in circular passes.
2818 * This will not result in a neat layout, but will be optimal
2819 * in the sense that there will not be holes left.
2822 for (i
= 1; i
<= r
&& !done
; i
++) {
2825 /* top and bottom parts of the ring */
2826 for (x
= -i
; x
<= i
&& !done
; x
++) {
2827 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2829 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2830 if (slot_map
[XY2OFS(x
,y
)]==0
2831 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2838 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2839 if (slot_map
[XY2OFS(x
,y
)]==0
2840 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2847 /* left and right parts of the ring */
2848 for (y
= -i
+1; y
<= i
-1; y
++) {
2849 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2851 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2852 if (slot_map
[XY2OFS(x
,y
)]==0
2853 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2860 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2861 if (slot_map
[XY2OFS(x
,y
)]==0
2862 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2877 moveDock(WDock
*dock
, int new_x
, int new_y
)
2882 dock
->x_pos
= new_x
;
2883 dock
->y_pos
= new_y
;
2884 for (i
=0; i
<dock
->max_icons
; i
++) {
2885 btn
= dock
->icon_array
[i
];
2887 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2888 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2889 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2896 swapDock(WDock
*dock
)
2898 WScreen
*scr
= dock
->screen_ptr
;
2903 if (dock
->on_right_side
) {
2904 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2906 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2909 for (i
=0; i
<dock
->max_icons
; i
++) {
2910 btn
= dock
->icon_array
[i
];
2913 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2917 wScreenUpdateUsableArea(scr
);
2922 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2924 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2930 cmdline
= ExpandOptions(scr
, command
);
2932 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2940 wtokensplit(cmdline
, &argv
, &argc
);
2950 if ((pid
=fork())==0) {
2954 SetupEnvironment(scr
);
2960 args
= malloc(sizeof(char*)*(argc
+1));
2963 for (i
=0; i
<argc
; i
++) {
2967 execvp(argv
[0], args
);
2970 wtokenfree(argv
, argc
);
2974 state
= wmalloc(sizeof(WSavedState
));
2975 memset(state
, 0, sizeof(WSavedState
));
2977 state
->miniaturized
= -1;
2979 if (btn
->dock
==scr
->dock
|| btn
->omnipresent
)
2980 state
->workspace
= -1;
2982 state
->workspace
= scr
->current_workspace
;
2984 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
2986 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
2997 wDockHideIcons(WDock
*dock
)
3004 for (i
=1; i
<dock
->max_icons
; i
++) {
3005 if (dock
->icon_array
[i
])
3006 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3010 dockIconPaint(dock
->icon_array
[0]);
3015 wDockShowIcons(WDock
*dock
)
3023 btn
= dock
->icon_array
[0];
3024 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
3026 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
3027 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
3029 for (i
=1; i
<dock
->max_icons
; i
++) {
3030 if (dock
->icon_array
[i
]) {
3031 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
3037 if (!dock
->collapsed
) {
3038 for (i
=1; i
<dock
->max_icons
; i
++) {
3039 if (dock
->icon_array
[i
]) {
3040 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3051 wDockLower(WDock
*dock
)
3055 for (i
=0; i
<dock
->max_icons
; i
++) {
3056 if (dock
->icon_array
[i
])
3057 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
3063 wDockRaise(WDock
*dock
)
3067 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
3068 if (dock
->icon_array
[i
])
3069 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
3075 wDockRaiseLower(WDock
*dock
)
3077 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
3078 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
3079 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
3087 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
3089 icon
->launching
= 0;
3090 icon
->relaunching
= 0;
3091 dockIconPaint(icon
);
3096 wDockFindIconForWindow(WDock
*dock
, Window window
)
3101 for (i
=0; i
<dock
->max_icons
; i
++) {
3102 icon
= dock
->icon_array
[i
];
3103 if (icon
&& icon
->main_window
== window
)
3111 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
3114 char *wm_class
, *wm_instance
;
3116 Bool firstPass
= True
;
3118 char *command
= NULL
;
3124 if (XGetCommand(dpy
, window
, &argv
, &argc
)) {
3125 if (argc
> 0 && argv
!= NULL
)
3126 command
= wtokenjoin(argv
,argc
);
3128 XFreeStringList(argv
);
3133 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
3134 (!wm_class
&& !wm_instance
))
3138 for (i
=0; i
<dock
->max_icons
; i
++) {
3139 icon
= dock
->icon_array
[i
];
3143 /* app is already attached to icon */
3144 if (icon
->main_window
== window
) {
3149 if ((icon
->wm_instance
|| icon
->wm_class
)
3151 || (dock
->screen_ptr
->flags
.startup
&& !icon
->running
))) {
3153 if (icon
->wm_instance
&& wm_instance
&&
3154 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
3157 if (icon
->wm_class
&& wm_class
&&
3158 strcmp(icon
->wm_class
, wm_class
)!=0) {
3161 if (firstPass
&& command
&& strcmp(icon
->command
, command
)!=0) {
3165 if (!icon
->relaunching
) {
3168 /* Possibly an application that was docked with dockit,
3169 * but the user did not update WMState to indicate that
3170 * it was docked by force */
3171 wapp
= wApplicationOf(window
);
3173 icon
->forced_dock
= 1;
3176 if (!icon
->forced_dock
)
3177 icon
->main_window
= window
;
3181 wDockFinishLaunch(dock
, icon
);
3186 if (firstPass
&& !found
) {
3203 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3205 if (!wPreferences
.flags
.noclip
) {
3206 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3207 if (scr
->current_workspace
!= workspace
) {
3208 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3209 WAppIconChain
*chain
= scr
->global_icons
;
3212 moveIconBetweenDocks(chain
->aicon
->dock
,
3213 scr
->workspaces
[workspace
]->clip
,
3214 chain
->aicon
, chain
->aicon
->xindex
,
3215 chain
->aicon
->yindex
);
3216 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
3217 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3218 chain
= chain
->next
;
3221 wDockHideIcons(old_clip
);
3222 if (old_clip
->auto_raise_lower
) {
3223 if (old_clip
->auto_raise_magic
) {
3224 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3225 old_clip
->auto_raise_magic
= NULL
;
3227 wDockLower(old_clip
);
3229 if (old_clip
->auto_collapse
) {
3230 if (old_clip
->auto_expand_magic
) {
3231 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3232 old_clip
->auto_expand_magic
= NULL
;
3234 old_clip
->collapsed
= 1;
3236 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3238 if (scr
->flags
.clip_balloon_mapped
)
3239 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3246 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3251 for (i
=0; i
<dock
->max_icons
; i
++) {
3252 icon
= dock
->icon_array
[i
];
3256 if (icon
->launching
&& icon
->pid
== pid
) {
3257 if (!icon
->relaunching
) {
3259 icon
->main_window
= None
;
3261 wDockFinishLaunch(dock
, icon
);
3266 if (icon
->drop_launch
)
3267 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""),
3269 else if (icon
->paste_launch
)
3270 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""),
3271 icon
->paste_command
);
3273 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""),
3276 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
3277 _("OK"), NULL
, NULL
);
3286 toggleLowered(WDock
*dock
)
3291 /* lower/raise Dock */
3292 if (!dock
->lowered
) {
3293 newlevel
= WMNormalLevel
;
3296 newlevel
= WMDockLevel
;
3300 for (i
=0; i
<dock
->max_icons
; i
++) {
3301 tmp
= dock
->icon_array
[i
];
3305 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3307 wLowerFrame(tmp
->icon
->core
);
3310 if (dock
->type
== WM_DOCK
)
3311 wScreenUpdateUsableArea(dock
->screen_ptr
);
3316 toggleCollapsed(WDock
*dock
)
3318 if (dock
->collapsed
) {
3319 dock
->collapsed
= 0;
3320 wDockShowIcons(dock
);
3323 dock
->collapsed
= 1;
3324 wDockHideIcons(dock
);
3330 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3332 WScreen
*scr
= dock
->screen_ptr
;
3333 WObjDescriptor
*desc
;
3335 WApplication
*wapp
= NULL
;
3339 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3341 if (dock
->type
== WM_DOCK
) {
3343 entry
= dock
->menu
->entries
[index
];
3344 entry
->flags
.indicator_on
= !dock
->lowered
;
3345 entry
->clientdata
= dock
;
3346 dock
->menu
->flags
.realized
= 0;
3349 if (scr
->clip_options
)
3350 updateClipOptionsMenu(scr
->clip_options
, dock
);
3352 n_selected
= numberOfSelectedIcons(dock
);
3354 /* Rename Workspace */
3355 entry
= dock
->menu
->entries
[++index
];
3356 if (aicon
== scr
->clip_icon
) {
3357 entry
->callback
= renameCallback
;
3358 entry
->clientdata
= dock
;
3359 entry
->flags
.indicator
= 0;
3360 entry
->text
= _("Rename Workspace");
3362 entry
->callback
= omnipresentCallback
;
3363 entry
->clientdata
= aicon
;
3364 if (n_selected
> 0) {
3365 entry
->flags
.indicator
= 0;
3366 entry
->text
= _("Toggle Omnipresent");
3368 entry
->flags
.indicator
= 1;
3369 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3370 entry
->flags
.indicator_type
= MI_CHECK
;
3371 entry
->text
= _("Omnipresent");
3375 /* select/unselect icon */
3376 entry
= dock
->menu
->entries
[++index
];
3377 entry
->clientdata
= aicon
;
3378 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3379 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3381 /* select/unselect all icons */
3382 entry
= dock
->menu
->entries
[++index
];
3383 entry
->clientdata
= aicon
;
3385 entry
->text
= _("Unselect All Icons");
3387 entry
->text
= _("Select All Icons");
3388 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3391 entry
= dock
->menu
->entries
[++index
];
3392 entry
->clientdata
= aicon
;
3394 entry
->text
= _("Keep Icons");
3396 entry
->text
= _("Keep Icon");
3397 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3399 /* this is the workspace submenu part */
3400 entry
= dock
->menu
->entries
[++index
];
3402 entry
->text
= _("Move Icons To");
3404 entry
->text
= _("Move Icon To");
3405 if (scr
->clip_submenu
)
3406 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3407 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3409 /* remove icon(s) */
3410 entry
= dock
->menu
->entries
[++index
];
3411 entry
->clientdata
= aicon
;
3413 entry
->text
= _("Remove Icons");
3415 entry
->text
= _("Remove Icon");
3416 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3418 /* attract icon(s) */
3419 entry
= dock
->menu
->entries
[++index
];
3420 entry
->clientdata
= aicon
;
3422 dock
->menu
->flags
.realized
= 0;
3423 wMenuRealize(dock
->menu
);
3427 if (aicon
->icon
->owner
) {
3428 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3434 entry
= dock
->menu
->entries
[++index
];
3435 entry
->clientdata
= aicon
;
3436 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3439 entry
= dock
->menu
->entries
[++index
];
3440 entry
->clientdata
= aicon
;
3441 if (wapp
&& wapp
->flags
.hidden
) {
3442 entry
->text
= _("Unhide Here");
3444 entry
->text
= _("Bring Here");
3446 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3449 entry
= dock
->menu
->entries
[++index
];
3450 entry
->clientdata
= aicon
;
3451 if (wapp
&& wapp
->flags
.hidden
) {
3452 entry
->text
= _("Unhide");
3454 entry
->text
= _("Hide");
3456 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3459 entry
= dock
->menu
->entries
[++index
];
3460 entry
->clientdata
= aicon
;
3461 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
3462 && !wPreferences
.flags
.noupdates
);
3465 entry
= dock
->menu
->entries
[++index
];
3466 entry
->clientdata
= aicon
;
3467 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3469 if (!dock
->menu
->flags
.realized
)
3470 wMenuRealize(dock
->menu
);
3472 if (dock
->type
== WM_CLIP
) {
3473 x_pos
= event
->xbutton
.x_root
+2;
3475 x_pos
= dock
->on_right_side
?
3476 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 2 : 0;
3479 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3481 /* allow drag select */
3482 event
->xany
.send_event
= True
;
3483 desc
= &dock
->menu
->menu
->descriptor
;
3484 (*desc
->handle_mousedown
)(desc
, event
);
3489 openClipWorkspaceMenu(WScreen
*scr
, int x
, int y
)
3491 if (!scr
->clip_ws_menu
) {
3492 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3494 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
3495 wMenuMapAt(scr
->clip_ws_menu
, x
, y
, False
);
3499 /******************************************************************/
3501 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3503 WAppIcon
*btn
= desc
->parent
;
3504 WDock
*dock
= btn
->dock
;
3505 WApplication
*wapp
= NULL
;
3508 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3509 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3513 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3515 /* go to the last workspace that the user worked on the app */
3516 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
3518 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3521 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3524 if (event
->xbutton
.state
& MOD_MASK
) {
3525 wHideOtherApplications(btn
->icon
->owner
);
3528 if (event
->xbutton
.button
==Button1
) {
3530 if (event
->xbutton
.state
& MOD_MASK
) {
3531 /* raise/lower dock */
3532 toggleLowered(dock
);
3533 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3534 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3535 toggleCollapsed(dock
);
3537 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3538 } else if (btn
->command
) {
3539 if (!btn
->launching
&&
3540 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3541 launchDockedApplication(btn
, False
);
3543 } else if (btn
->xindex
== 0 && btn
->yindex
== 0
3544 && btn
->dock
->type
== WM_DOCK
) {
3546 wShowGNUstepPanel(dock
->screen_ptr
);
3555 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3557 WScreen
*scr
= dock
->screen_ptr
;
3558 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3561 int grabbed
= 0, swapped
= 0, done
;
3562 Pixmap ghost
= None
;
3563 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3566 puts("moving dock");
3568 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3569 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3570 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3571 wwarning("pointer grab failed for dock move");
3574 for (x
=0; x
<dock
->max_icons
; x
++) {
3575 if (dock
->icon_array
[x
]!=NULL
&&
3576 dock
->icon_array
[x
]->yindex
> y
)
3577 y
= dock
->icon_array
[x
]->yindex
;
3580 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3584 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3585 |ButtonMotionMask
|ExposureMask
, &ev
);
3593 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3594 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3595 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3596 |ButtonReleaseMask
|ButtonPressMask
,
3597 wCursor
[WCUR_MOVE
], CurrentTime
);
3602 if (dock
->type
== WM_CLIP
) {
3603 if (ev
.xmotion
.x_root
- ofs_x
< 0) {
3605 } else if (ev
.xmotion
.x_root
- ofs_x
+ ICON_SIZE
>
3607 x
= scr
->scr_width
- ICON_SIZE
;
3609 x
= ev
.xmotion
.x_root
- ofs_x
;
3611 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3613 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3615 y
= scr
->scr_height
- ICON_SIZE
;
3617 y
= ev
.xmotion
.y_root
- ofs_y
;
3619 moveDock(dock
, x
, y
);
3621 /* move vertically if pointer is inside the dock*/
3622 if ((dock
->on_right_side
&&
3623 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3624 || (!dock
->on_right_side
&&
3625 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3627 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3629 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3631 y
= scr
->scr_height
- ICON_SIZE
;
3633 y
= ev
.xmotion
.y_root
- ofs_y
;
3635 moveDock(dock
, dock
->x_pos
, y
);
3637 /* move horizontally to change sides */
3638 x
= ev
.xmotion
.x_root
- ofs_x
;
3639 if (!dock
->on_right_side
) {
3643 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3644 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3645 -DOCK_EXTRA_SPACE
-1, dock
->y_pos
);
3646 if (superfluous
&& ghost
==None
) {
3647 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3648 scr
->scr_width
-ICON_SIZE
3649 -DOCK_EXTRA_SPACE
-1,
3651 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3653 XClearWindow(dpy
, scr
->dock_shadow
);
3655 XMapRaised(dpy
, scr
->dock_shadow
);
3658 if (superfluous
&& ghost
!=None
) {
3659 XFreePixmap(dpy
, ghost
);
3662 XUnmapWindow(dpy
, scr
->dock_shadow
);
3667 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3668 XMoveWindow(dpy
, scr
->dock_shadow
,
3669 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3670 if (superfluous
&& ghost
==None
) {
3671 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3672 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3673 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3675 XClearWindow(dpy
, scr
->dock_shadow
);
3677 XMapRaised(dpy
, scr
->dock_shadow
);
3680 XUnmapWindow(dpy
, scr
->dock_shadow
);
3682 if (superfluous
&& ghost
!=None
) {
3683 XFreePixmap(dpy
, ghost
);
3695 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3697 XUngrabPointer(dpy
, CurrentTime
);
3698 XUnmapWindow(dpy
, scr
->dock_shadow
);
3699 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3700 if (dock
->type
== WM_DOCK
) {
3703 dock
->on_right_side
= 1;
3705 dock
->on_right_side
= 0;
3707 wArrangeIcons(scr
, False
);
3716 XFreePixmap(dpy
, ghost
);
3717 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3720 puts("End dock move");
3727 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3729 WScreen
*scr
= dock
->screen_ptr
;
3731 WIcon
*icon
= aicon
->icon
;
3732 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3733 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3735 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3736 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3737 int shad_x
= x
, shad_y
= y
;
3738 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3740 Pixmap ghost
= None
;
3742 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3743 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3746 if (wPreferences
.flags
.noupdates
)
3749 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3750 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3751 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3753 wwarning("pointer grab failed for icon move");
3757 if (!(event
->xbutton
.state
& MOD_MASK
))
3758 wRaiseFrame(icon
->core
);
3760 if (!wPreferences
.flags
.noclip
)
3761 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3763 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3765 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3768 wins
[0] = icon
->core
->window
;
3769 wins
[1] = scr
->dock_shadow
;
3770 XRestackWindows(dpy
, wins
, 2);
3771 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3772 ICON_SIZE
, ICON_SIZE
);
3774 if (icon
->pixmap
!=None
)
3775 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3777 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3779 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3780 XClearWindow(dpy
, scr
->dock_shadow
);
3782 XMapWindow(dpy
, scr
->dock_shadow
);
3788 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3789 |ButtonMotionMask
|ExposureMask
, &ev
);
3797 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3798 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3799 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3800 |ButtonReleaseMask
|ButtonPressMask
,
3801 wCursor
[WCUR_MOVE
], CurrentTime
);
3810 for (i
=0; i
<scr
->workspace_count
; i
++) {
3811 if (i
== scr
->current_workspace
)
3813 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3817 x
= ev
.xmotion
.x_root
- ofs_x
;
3818 y
= ev
.xmotion
.y_root
- ofs_y
;
3819 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3822 if (last_dock
!= dock
&& collapsed
) {
3823 last_dock
->collapsed
= 1;
3824 wDockHideIcons(last_dock
);
3827 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3828 dock
->collapsed
= 0;
3829 wDockShowIcons(dock
);
3831 if (dock
->auto_raise_lower
)
3835 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3838 if (last_dock
!= dock2
&& collapsed
) {
3839 last_dock
->collapsed
= 1;
3840 wDockHideIcons(last_dock
);
3843 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3844 dock2
->collapsed
= 0;
3845 wDockShowIcons(dock2
);
3847 if (dock2
->auto_raise_lower
)
3852 if (aicon
->launching
3854 || (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3855 || (!aicon
->running
&& tmp
)) {
3856 shad_x
= last_dock
->x_pos
+ ix
*wPreferences
.icon_size
;
3857 shad_y
= last_dock
->y_pos
+ iy
*wPreferences
.icon_size
;
3859 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3862 XMapWindow(dpy
, scr
->dock_shadow
);
3867 XUnmapWindow(dpy
, scr
->dock_shadow
);
3871 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3878 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3880 XUngrabPointer(dpy
, CurrentTime
);
3882 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3883 XUnmapWindow(dpy
, scr
->dock_shadow
);
3885 reattachIcon(dock
, aicon
, ix
, iy
);
3886 if (clip
&& dock
!=clip
&& clip
->auto_raise_lower
)
3889 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3891 /* Slide it back if dock rejected it */
3892 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3894 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3896 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3904 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3905 /* We need to deselect it, even if is deselected in
3906 * wDockDetach(), because else DoKaboom() will fail.
3908 if (aicon
->icon
->selected
)
3909 wIconSelect(aicon
->icon
);
3911 wSoundPlay(WSOUND_KABOOM
);
3912 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3914 wSoundPlay(WSOUND_UNDOCK
);
3917 wSoundPlay(WSOUND_UNDOCK
);
3919 if (clip
&& clip
->auto_raise_lower
)
3921 wDockDetach(dock
, aicon
);
3924 last_dock
->collapsed
= 1;
3925 wDockHideIcons(last_dock
);
3930 XFreePixmap(dpy
, ghost
);
3931 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3935 for (i
=0; i
<scr
->workspace_count
; i
++) {
3936 if (i
== scr
->current_workspace
)
3938 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3943 puts("End icon move");
3952 getClipButton(int px
, int py
)
3954 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
3956 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3959 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
3960 return CLIP_FORWARD
;
3961 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
3969 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3972 int done
, direction
, new_ws
;
3974 WDock
*clip
= scr
->clip_icon
->dock
;
3976 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3978 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3979 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3981 wClipIconPaint(scr
->clip_icon
);
3984 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
3985 |ButtonPressMask
, &ev
);
3992 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3993 if (new_dir
!= direction
) {
3994 direction
= new_dir
;
3995 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3996 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3997 wClipIconPaint(scr
->clip_icon
);
4005 if (ev
.xbutton
.button
== event
->xbutton
.button
)
4010 clip
->lclip_button_pushed
= 0;
4011 clip
->rclip_button_pushed
= 0;
4013 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
4015 if (direction
== CLIP_FORWARD
) {
4016 if (scr
->current_workspace
< scr
->workspace_count
-1)
4017 wWorkspaceChange(scr
, scr
->current_workspace
+1);
4018 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
4019 wWorkspaceChange(scr
, scr
->current_workspace
+1);
4020 else if (wPreferences
.ws_cycle
)
4021 wWorkspaceChange(scr
, 0);
4023 else if (direction
== CLIP_REWIND
) {
4024 if (scr
->current_workspace
> 0)
4025 wWorkspaceChange(scr
, scr
->current_workspace
-1);
4026 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
4027 wWorkspaceChange(scr
, scr
->workspace_count
-1);
4030 wClipIconPaint(scr
->clip_icon
);
4035 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
4037 WAppIcon
*aicon
= desc
->parent
;
4038 WDock
*dock
= aicon
->dock
;
4039 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4041 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
4044 scr
->last_dock
= dock
;
4046 if (dock
->menu
->flags
.mapped
)
4047 wMenuUnmap(dock
->menu
);
4049 if (IsDoubleClick(scr
, event
)) {
4050 /* double-click was not in the main clip icon */
4051 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
4052 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
4053 iconDblClick(desc
, event
);
4058 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
4059 XUnmapWindow(dpy
, scr
->clip_balloon
);
4060 scr
->flags
.clip_balloon_mapped
= 0;
4064 puts("handling dock");
4066 if (event
->xbutton
.button
== Button1
) {
4067 if (event
->xbutton
.state
& MOD_MASK
)
4072 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
4073 dock
->type
!=WM_DOCK
) {
4074 wIconSelect(aicon
->icon
);
4078 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
4079 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
4080 && dock
->type
==WM_CLIP
)
4081 handleClipChangeWorkspace(scr
, event
);
4083 handleDockMove(dock
, aicon
, event
);
4085 handleIconMove(dock
, aicon
, event
);
4087 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4088 aicon
==scr
->clip_icon
) {
4089 openClipWorkspaceMenu(scr
, event
->xbutton
.x_root
+2,
4090 event
->xbutton
.y_root
+2);
4091 if (scr
->clip_ws_menu
) {
4093 menu
= scr
->clip_ws_menu
;
4094 desc
= &menu
->menu
->descriptor
;
4096 event
->xany
.send_event
= True
;
4097 (*desc
->handle_mousedown
)(desc
, event
);
4099 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4100 (event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
) {
4101 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
4102 } else if (event
->xbutton
.button
== Button3
) {
4103 if (event
->xbutton
.send_event
&&
4104 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
4105 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
4106 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
4107 wwarning("pointer grab failed for dockicon menu");
4111 openDockMenu(dock
, aicon
, event
);
4112 } else if (event
->xbutton
.button
== Button2
) {
4113 WAppIcon
*btn
= desc
->parent
;
4115 if (!btn
->launching
&&
4116 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
4117 launchDockedApplication(btn
, True
);
4124 showClipBalloon(WDock
*dock
, int workspace
)
4128 WScreen
*scr
= dock
->screen_ptr
;
4132 scr
->flags
.clip_balloon_mapped
= 1;
4133 XMapWindow(dpy
, scr
->clip_balloon
);
4135 text
= scr
->workspaces
[workspace
]->name
;
4137 w
= WMWidthOfString(scr
->clip_title_font
, text
, strlen(text
));
4139 h
= WMFontHeight(scr
->clip_title_font
);
4140 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
4142 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
4143 y
= dock
->y_pos
+ ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
4145 if (x
+w
> scr
->scr_width
) {
4146 x
= scr
->scr_width
- w
;
4147 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
4148 y
= dock
->y_pos
- h
- 1;
4150 y
= dock
->y_pos
+ ICON_SIZE
;
4151 XRaiseWindow(dpy
, scr
->clip_balloon
);
4153 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
4154 stack
[1] = scr
->clip_balloon
;
4155 XRestackWindows(dpy
, stack
, 2);
4157 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
4158 XSetForeground(dpy
, scr
->clip_title_gc
,
4159 scr
->clip_title_pixel
[CLIP_NORMAL
]);
4160 XClearWindow(dpy
, scr
->clip_balloon
);
4161 WMDrawString(scr
->wmscreen
, scr
->clip_balloon
, scr
->clip_title_gc
,
4162 scr
->clip_title_font
, 0, 0, text
, strlen(text
));
4167 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
4169 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4173 assert(event
->type
==EnterNotify
);
4175 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4178 scr
= btn
->icon
->core
->screen_ptr
;
4179 if (!btn
->omnipresent
)
4182 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
4184 if (!dock
|| dock
->type
!=WM_CLIP
)
4187 /* The auto raise/lower code */
4188 if (dock
->auto_lower_magic
) {
4189 WMDeleteTimerHandler(dock
->auto_lower_magic
);
4190 dock
->auto_lower_magic
= NULL
;
4192 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
4193 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
,
4198 /* The auto expand/collapse code */
4199 if (dock
->auto_collapse_magic
) {
4200 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
4201 dock
->auto_collapse_magic
= NULL
;
4203 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
4204 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
,
4209 if (btn
->xindex
== 0 && btn
->yindex
== 0)
4210 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4212 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4213 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
4214 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
4221 clipLeave(WDock
*dock
)
4224 WObjDescriptor
*desc
= NULL
;
4226 if (!dock
|| dock
->type
!=WM_CLIP
)
4229 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
)!=False
) {
4230 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
4231 (XPointer
*)&desc
)!=XCNOENT
4232 && desc
&& desc
->parent_type
==WCLASS_DOCK_ICON
4233 && ((WAppIcon
*)desc
->parent
)->dock
4234 && ((WAppIcon
*)desc
->parent
)->dock
->type
==WM_CLIP
) {
4235 /* We didn't left the Clip yet */
4236 XPutBackEvent(dpy
, &event
);
4240 XPutBackEvent(dpy
, &event
);
4242 /* We entered a withdrawn window, so we're still in Clip */
4246 if (dock
->auto_raise_magic
) {
4247 WMDeleteTimerHandler(dock
->auto_raise_magic
);
4248 dock
->auto_raise_magic
= NULL
;
4250 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
4251 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
,
4256 if (dock
->auto_expand_magic
) {
4257 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4258 dock
->auto_expand_magic
= NULL
;
4260 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
4261 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
4269 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4271 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4273 assert(event
->type
==LeaveNotify
);
4275 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4278 clipLeave(btn
->dock
);
4283 clipAutoCollapse(void *cdata
)
4285 WDock
*dock
= (WDock
*)cdata
;
4287 if (dock
->type
!=WM_CLIP
)
4290 if (dock
->auto_collapse
) {
4291 dock
->collapsed
= 1;
4292 wDockHideIcons(dock
);
4294 dock
->auto_collapse_magic
= NULL
;
4299 clipAutoExpand(void *cdata
)
4301 WDock
*dock
= (WDock
*)cdata
;
4303 if (dock
->type
!=WM_CLIP
)
4306 if (dock
->auto_collapse
) {
4307 dock
->collapsed
= 0;
4308 wDockShowIcons(dock
);
4310 dock
->auto_expand_magic
= NULL
;
4315 clipAutoLower(void *cdata
)
4317 WDock
*dock
= (WDock
*)cdata
;
4319 if (dock
->type
!=WM_CLIP
)
4322 if (dock
->auto_raise_lower
)
4325 dock
->auto_lower_magic
= NULL
;
4330 clipAutoRaise(void *cdata
)
4332 WDock
*dock
= (WDock
*)cdata
;
4334 if (dock
->type
!=WM_CLIP
)
4337 if (dock
->auto_raise_lower
)
4340 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4341 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4344 dock
->auto_raise_magic
= NULL
;
4349 iconCanBeOmnipresent(WAppIcon
*aicon
)
4351 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4356 for (i
=0; i
<scr
->workspace_count
; i
++) {
4357 clip
= scr
->workspaces
[i
]->clip
;
4359 if (clip
== aicon
->dock
)
4362 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4363 return False
; /* Clip is full in some workspace */
4365 for (j
=0; j
<clip
->max_icons
; j
++) {
4366 btn
= clip
->icon_array
[j
];
4367 if(btn
&& btn
->xindex
==aicon
->xindex
&& btn
->yindex
==aicon
->yindex
)
4377 wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
4379 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4380 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4381 int status
= WO_SUCCESS
;
4383 if ((scr
->dock
&& aicon
->dock
==scr
->dock
) || aicon
==scr
->clip_icon
) {
4384 return WO_NOT_APPLICABLE
;
4387 if (aicon
->omnipresent
== omnipresent
)
4391 if (iconCanBeOmnipresent(aicon
)) {
4392 aicon
->omnipresent
= 1;
4393 new_entry
= wmalloc(sizeof(WAppIconChain
));
4394 new_entry
->aicon
= aicon
;
4395 new_entry
->next
= scr
->global_icons
;
4396 scr
->global_icons
= new_entry
;
4397 scr
->global_icon_count
++;
4399 aicon
->omnipresent
= 0;
4403 aicon
->omnipresent
= 0;
4404 if (aicon
== scr
->global_icons
->aicon
) {
4405 tmp
= scr
->global_icons
->next
;
4406 wfree(scr
->global_icons
);
4407 scr
->global_icons
= tmp
;
4408 scr
->global_icon_count
--;
4410 tmp
= scr
->global_icons
;
4412 if (tmp
->next
->aicon
== aicon
) {
4413 tmp1
= tmp
->next
->next
;
4416 scr
->global_icon_count
--;
4424 wAppIconPaint(aicon
);