1 /* dock.c- built-in Dock module for WindowMaker
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 * Copyright (c) 1998, 1999 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
28 #include <X11/Xutil.h>
36 #define PATH_MAX DEFAULT_PATH_MAX
39 #include "WindowMaker.h"
49 #include "properties.h"
53 #include "workspace.h"
55 #include "superfluous.h"
64 /**** Local variables ****/
67 #define CLIP_FORWARD 2
70 /**** Global variables ****/
73 extern void DestroyDockAppSettingsPanel();
75 extern void ShowDockAppSettingsPanel(WAppIcon
*aicon
);
78 extern XContext wWinContext
;
80 extern Cursor wCursor
[WCUR_LAST
];
82 extern WPreferences wPreferences
;
84 extern XContext wWinContext
;
87 extern Atom _XA_DND_PROTOCOL
;
91 #define MOD_MASK wPreferences.modifier_mask
93 extern void appIconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
95 #define ICON_SIZE wPreferences.icon_size
98 /***** Local variables ****/
100 static proplist_t dCommand
=NULL
;
102 static proplist_t dDropCommand
=NULL
;
104 static proplist_t dAutoLaunch
, dName
, dForced
, dBuggyApplication
, dYes
, dNo
;
105 static proplist_t dHost
, dDock
, dClip
;
106 static proplist_t dAutoAttractIcons
, dKeepAttracted
;
108 static proplist_t dPosition
, dApplications
, dLowered
, dCollapsed
, dAutoCollapse
;
110 static proplist_t dAutoRaiseLower
, dOmnipresent
;
112 static void dockIconPaint(WAppIcon
*btn
);
114 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
116 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
);
118 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
120 static int getClipButton(int px
, int py
);
122 static void toggleLowered(WDock
*dock
);
124 static void toggleCollapsed(WDock
*dock
);
126 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
128 static void clipLeave(WDock
*dock
);
130 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
132 Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
);
134 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
135 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
136 static void clipAutoCollapse(void *cdata
);
137 static void clipAutoExpand(void *cdata
);
138 static void launchDockedApplication(WAppIcon
*btn
);
140 static void clipAutoLower(void *cdata
);
141 static void clipAutoRaise(void *cdata
);
143 static void showClipBalloon(WDock
*dock
, int workspace
);
159 #endif /* OFFIX_DND */
169 dCommand
= PLRetain(PLMakeString("Command"));
171 dDropCommand
= PLRetain(PLMakeString("DropCommand"));
173 dAutoLaunch
= PLRetain(PLMakeString("AutoLaunch"));
174 dName
= PLRetain(PLMakeString("Name"));
175 dForced
= PLRetain(PLMakeString("Forced"));
176 dBuggyApplication
= PLRetain(PLMakeString("BuggyApplication"));
177 dYes
= PLRetain(PLMakeString("Yes"));
178 dNo
= PLRetain(PLMakeString("No"));
179 dHost
= PLRetain(PLMakeString("Host"));
181 dPosition
= PLMakeString("Position");
182 dApplications
= PLMakeString("Applications");
183 dLowered
= PLMakeString("Lowered");
184 dCollapsed
= PLMakeString("Collapsed");
185 dAutoCollapse
= PLMakeString("AutoCollapse");
186 dAutoRaiseLower
= PLMakeString("AutoRaiseLower");
187 dAutoAttractIcons
= PLMakeString("AutoAttractIcons");
188 dKeepAttracted
= PLMakeString("KeepAttracted");
190 dOmnipresent
= PLMakeString("Omnipresent");
192 dDock
= PLMakeString("Dock");
193 dClip
= PLMakeString("Clip");
199 renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
201 WDock
*dock
= entry
->clientdata
;
206 assert(entry
->clientdata
!=NULL
);
208 wspace
= dock
->screen_ptr
->current_workspace
;
210 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
212 sprintf(buffer
, _("Type the name for workspace %i:"), wspace
+1);
213 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
,
215 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
224 toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
226 assert(entry
->clientdata
!=NULL
);
228 toggleLowered(entry
->clientdata
);
230 entry
->flags
.indicator_on
= !((WDock
*)entry
->clientdata
)->lowered
;
238 killCallback(WMenu
*menu
, WMenuEntry
*entry
)
241 #ifdef REDUCE_APPICONS
242 WAppIconAppList
*tapplist
;
244 extern Atom _XA_WM_DELETE_WINDOW
;
249 if (!WCHECK_STATE(WSTATE_NORMAL
))
252 assert(entry
->clientdata
!=NULL
);
254 icon
= (WAppIcon
*)entry
->clientdata
;
258 WCHANGE_STATE(WSTATE_MODAL
);
260 #ifdef REDUCE_APPICONS
261 /* Send a delete message to the main window of each application
262 * bound to this docked appicon. - cls
264 tapplist
= icon
->applist
;
265 while (tapplist
!= NULL
) {
266 if (tapplist
->wapp
->main_window_desc
!= NULL
) {
267 if (tapplist
->wapp
->main_window_desc
->protocols
.DELETE_WINDOW
) {
268 wClientSendProtocol(tapplist
->wapp
->main_window_desc
,
269 _XA_WM_DELETE_WINDOW
, CurrentTime
);
271 wClientKill(tapplist
->wapp
->main_window_desc
);
274 tapplist
= tapplist
->next
;
277 buffer
= wstrappend(icon
->wm_class
,
278 _(" will be forcibly closed.\n"
279 "Any unsaved changes will be lost.\n"
282 if (wPreferences
.dont_confirm_kill
283 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
284 buffer
, _("Yes"), _("No"), NULL
)==WAPRDefault
) {
285 if (icon
->icon
&& icon
->icon
->owner
) {
286 wClientKill(icon
->icon
->owner
);
289 #endif /* !REDUCE_APPICONS */
293 WCHANGE_STATE(WSTATE_NORMAL
);
297 /* TODO: replace this function with a member of the dock struct */
299 numberOfSelectedIcons(WDock
*dock
)
305 for (i
=1; i
<dock
->max_icons
; i
++) {
306 aicon
= dock
->icon_array
[i
];
307 if (aicon
&& aicon
->icon
->selected
) {
317 getSelected(WDock
*dock
)
319 LinkedList
*ret
=NULL
;
323 for (i
=1; i
<dock
->max_icons
; i
++) {
324 btn
= dock
->icon_array
[i
];
325 if (btn
&& btn
->icon
->selected
) {
326 ret
= list_cons(btn
, ret
);
335 paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
337 Window win
= clipIcon
->icon
->core
->window
;
338 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
340 int pt
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
341 int tp
= ICON_SIZE
- pt
;
342 int as
= pt
- 15; /* 15 = 5+5+5 */
343 GC gc
= scr
->clip_title_gc
;
344 #ifdef GRADIENT_CLIP_ARROW
345 Bool collapsed
= clipIcon
->dock
->collapsed
;
351 p
[1].x
= ICON_SIZE
-2;
353 p
[2].x
= ICON_SIZE
-2;
355 } else if (lpushed
) {
359 p
[1].y
= ICON_SIZE
-2;
361 p
[2].y
= ICON_SIZE
-2;
363 if (lpushed
|| rpushed
) {
364 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
365 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
366 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
368 #ifdef GRADIENT_CLIP_ARROW
370 XSetFillStyle(dpy
, scr
->copy_gc
, FillTiled
);
371 XSetTile(dpy
, scr
->copy_gc
, scr
->clip_arrow_gradient
);
372 XSetClipMask(dpy
, scr
->copy_gc
, None
);
375 #endif /* GRADIENT_CLIP_ARROW */
377 /* top right arrow */
378 p
[0].x
= p
[3].x
= ICON_SIZE
-5-as
;
380 p
[1].x
= ICON_SIZE
-6;
382 p
[2].x
= ICON_SIZE
-6;
385 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
386 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
388 #ifdef GRADIENT_CLIP_ARROW
390 XSetTSOrigin(dpy
, gc
, ICON_SIZE
-6-as
, 5);
392 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
393 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
396 /* bottom left arrow */
398 p
[0].y
= p
[3].y
= ICON_SIZE
-5-as
;
400 p
[1].y
= ICON_SIZE
-6;
402 p
[2].y
= ICON_SIZE
-6;
404 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
405 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
407 #ifdef GRADIENT_CLIP_ARROW
409 XSetTSOrigin(dpy
, gc
, 5, ICON_SIZE
-6-as
);
411 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
412 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
414 #ifdef GRADIENT_CLIP_ARROW
416 XSetFillStyle(dpy
, scr
->copy_gc
, FillSolid
);
422 wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
424 RImage
*tile
= RCloneImage(normalTile
);
431 pt
= CLIP_BUTTON_SIZE
*wPreferences
.icon_size
/64;
432 tp
= wPreferences
.icon_size
-1 - pt
;
436 black
.red
= black
.green
= black
.blue
= 0;
439 dark
.red
= dark
.green
= dark
.blue
= 60;
442 light
.red
= light
.green
= light
.blue
= 80;
446 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
-2,
448 RDrawLine(tile
, tp
-1, 0, wPreferences
.icon_size
-1, pt
+1, &black
);
449 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
-3,
453 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4,
454 ICON_SIZE
- 5, 4, &dark
);
455 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5,
456 ICON_SIZE
- 5, 6 + as
, &dark
);
457 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
,
461 ROperateLine(tile
, RAddOperation
, 2, tp
+2, pt
-2,
462 wPreferences
.icon_size
-3, &dark
);
463 RDrawLine(tile
, 0, tp
-1, pt
+1, wPreferences
.icon_size
-1, &black
);
464 ROperateLine(tile
, RSubtractOperation
, 0, tp
-2, pt
+1,
465 wPreferences
.icon_size
-2, &light
);
468 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4,
469 ICON_SIZE
- 5, &dark
);
470 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
,
471 6 + as
, ICON_SIZE
- 5, &dark
);
472 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5,
480 omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
482 WAppIcon
*clickedIcon
= entry
->clientdata
;
485 LinkedList
*selectedIcons
;
488 assert(entry
->clientdata
!=NULL
);
490 dock
= clickedIcon
->dock
;
492 selectedIcons
= getSelected(dock
);
495 selectedIcons
= list_cons(clickedIcon
, NULL
);
498 while (selectedIcons
) {
499 aicon
= selectedIcons
->head
;
500 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
502 else if (aicon
->icon
->selected
)
503 wIconSelect(aicon
->icon
);
504 list_remove_head(&selectedIcons
);
508 wMessageDialog(dock
->screen_ptr
, _("Warning"),
509 _("Some icons cannot be made omnipresent. "
510 "Please make sure that no other icon is "
511 "docked in the same positions on the other "
512 "workspaces and the Clip is not full in "
514 _("OK"), NULL
, NULL
);
515 } else if (failed
== 1) {
516 wMessageDialog(dock
->screen_ptr
, _("Warning"),
517 _("Icon cannot be made omnipresent. "
518 "Please make sure that no other icon is "
519 "docked in the same position on the other "
520 "workspaces and the Clip is not full in "
522 _("OK"), NULL
, NULL
);
528 removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
530 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
533 LinkedList
*selectedIcons
;
536 assert(clickedIcon
!=NULL
);
538 dock
= clickedIcon
->dock
;
540 selectedIcons
= getSelected(dock
);
543 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
544 _("All selected icons will be removed!"),
545 _("OK"), _("Cancel"), NULL
)!=WAPRDefault
) {
549 if (clickedIcon
->xindex
==0 && clickedIcon
->yindex
==0)
551 selectedIcons
= list_cons(clickedIcon
, NULL
);
554 while (selectedIcons
) {
555 aicon
= selectedIcons
->head
;
556 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
557 wDockDetach(dock
, aicon
);
559 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
560 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
561 aicon
->x_pos
, aicon
->y_pos
);
562 if (!dock
->mapped
|| dock
->collapsed
)
563 XMapWindow(dpy
, aicon
->icon
->core
->window
);
565 list_remove_head(&selectedIcons
);
568 if (wPreferences
.auto_arrange_icons
)
569 wArrangeIcons(dock
->screen_ptr
, True
);
574 keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
576 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
579 LinkedList
*selectedIcons
;
581 assert(clickedIcon
!=NULL
);
582 dock
= clickedIcon
->dock
;
584 selectedIcons
= getSelected(dock
);
586 if (!selectedIcons
&& clickedIcon
!=dock
->screen_ptr
->clip_icon
) {
587 char *command
= NULL
;
589 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
590 clickedIcon
->editing
= 1;
591 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
592 _("Type the command used to launch the application"),
594 if (command
&& (command
[0]==0 ||
595 (command
[0]=='-' && command
[1]==0))) {
599 clickedIcon
->command
= command
;
600 clickedIcon
->editing
= 0;
602 clickedIcon
->editing
= 0;
609 selectedIcons
= list_cons(clickedIcon
, NULL
);
612 while (selectedIcons
) {
613 aicon
= selectedIcons
->head
;
614 if (aicon
->icon
->selected
)
615 wIconSelect(aicon
->icon
);
616 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
617 aicon
->attracted
= 0;
618 if (aicon
->icon
->shadowed
) {
619 aicon
->icon
->shadowed
= 0;
620 aicon
->icon
->force_paint
= 1;
621 wAppIconPaint(aicon
);
624 list_remove_head(&selectedIcons
);
632 toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
634 WDock
*dock
= (WDock
*)entry
->clientdata
;
636 assert(entry
->clientdata
!=NULL
);
638 dock
->attract_icons
= !dock
->attract_icons
;
639 /*if (!dock->attract_icons)
640 dock->keep_attracted = 0;*/
642 entry
->flags
.indicator_on
= dock
->attract_icons
;
649 toggleKeepCallback(WMenu
*menu
, WMenuEntry
*entry
)
651 WDock
*dock
= (WDock
*)entry
->clientdata
;
655 assert(entry
->clientdata
!=NULL
);
657 dock
->keep_attracted
= !dock
->keep_attracted
;
659 if (dock
->keep_attracted
) {
660 for (i
=0; i
< dock
->max_icons
; i
++) {
661 btn
= dock
->icon_array
[i
];
662 if (btn
&& btn
->attracted
&& btn
->command
) {
664 if (btn
->icon
->shadowed
) {
665 btn
->icon
->shadowed
= 0;
666 btn
->icon
->force_paint
= 1;
673 entry
->flags
.indicator_on
= dock
->keep_attracted
;
680 selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
682 WAppIcon
*icon
= (WAppIcon
*)entry
->clientdata
;
686 wIconSelect(icon
->icon
);
693 colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
695 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
698 int x
, y
, x_pos
, y_pos
;
700 assert(entry
->clientdata
!=NULL
);
701 clip
= clickedIcon
->dock
;
703 aicon
= clip
->screen_ptr
->app_icon_list
;
706 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
707 x_pos
= clip
->x_pos
+ x
*ICON_SIZE
;
708 y_pos
= clip
->y_pos
+ y
*ICON_SIZE
;
709 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
711 if (wPreferences
.no_animations
) {
712 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
714 SlideWindow(aicon
->icon
->core
->window
,
715 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
718 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
719 #endif /* ANIMATIONS */
721 aicon
->attracted
= 1;
722 if (!clip
->keep_attracted
&& !aicon
->icon
->shadowed
) {
723 aicon
->icon
->shadowed
= 1;
724 aicon
->icon
->force_paint
= 1;
725 /* We don't do an wAppIconPaint() here because it's in
726 * wDockAttachIcon(). -Dan
729 wDockAttachIcon(clip
, aicon
, x
, y
);
730 if (clip
->collapsed
|| !clip
->mapped
)
731 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
739 selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
741 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
743 LinkedList
*selectedIcons
;
747 assert(clickedIcon
!=NULL
);
748 dock
= clickedIcon
->dock
;
750 selectedIcons
= getSelected(dock
);
752 if (!selectedIcons
) {
753 for (i
=1; i
<dock
->max_icons
; i
++) {
754 btn
= dock
->icon_array
[i
];
755 if (btn
&& !btn
->icon
->selected
) {
756 wIconSelect(btn
->icon
);
760 while(selectedIcons
) {
761 btn
= selectedIcons
->head
;
762 wIconSelect(btn
->icon
);
763 list_remove_head(&selectedIcons
);
772 toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
774 assert(entry
->clientdata
!=NULL
);
776 toggleCollapsed(entry
->clientdata
);
778 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->collapsed
;
785 toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
788 assert(entry
->clientdata
!=NULL
);
790 dock
= (WDock
*) entry
->clientdata
;
792 dock
->auto_collapse
= !dock
->auto_collapse
;
794 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_collapse
;
801 toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
804 assert(entry
->clientdata
!=NULL
);
806 dock
= (WDock
*) entry
->clientdata
;
808 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
810 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_raise_lower
;
817 launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
819 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
821 launchDockedApplication(btn
);
826 settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
828 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
832 ShowDockAppSettingsPanel(btn
);
837 hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
840 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
842 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
844 if (wapp
->flags
.hidden
) {
845 wWorkspaceChange(btn
->icon
->core
->screen_ptr
,wapp
->last_workspace
);
846 wUnhideApplication(wapp
, False
, False
);
848 wHideApplication(wapp
);
854 unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
857 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
859 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
861 wUnhideApplication(wapp
, False
, True
);
866 mainIconCreate(WScreen
*scr
, int type
)
871 if (type
== WM_CLIP
) {
873 return scr
->clip_icon
;
874 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
875 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
876 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
877 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
878 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE;*/
881 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
882 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
888 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
889 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
890 btn
->icon
->core
->descriptor
.parent
= btn
;
891 /*ChangeStackingLevel(btn->icon->core, WMDockLevel);*/
892 XMapWindow(dpy
, btn
->icon
->core
->window
);
897 scr
->clip_icon
= btn
;
904 switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
906 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
907 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
909 LinkedList
*selectedIcons
;
912 if (entry
->order
== scr
->current_workspace
)
915 dest
= scr
->workspaces
[entry
->order
]->clip
;
917 selectedIcons
= getSelected(src
);
920 while(selectedIcons
) {
921 btn
= selectedIcons
->head
;
922 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
923 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
924 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
926 list_remove_head(&selectedIcons
);
928 } else if (icon
!= scr
->clip_icon
) {
929 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
930 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
931 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
939 launchDockedApplication(WAppIcon
*btn
)
941 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
943 if (!btn
->launching
&& btn
->command
!=NULL
) {
944 if (!btn
->forced_dock
) {
945 btn
->relaunching
= btn
->running
;
948 if (btn
->wm_instance
|| btn
->wm_class
) {
949 WWindowAttributes attr
;
950 memset(&attr
, 0, sizeof(WWindowAttributes
));
951 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
,
954 if (!attr
.no_appicon
&& !btn
->buggy_app
)
959 btn
->drop_launch
= 0;
960 scr
->last_dock
= btn
->dock
;
961 btn
->pid
= execCommand(btn
, btn
->command
, NULL
);
963 if (btn
->buggy_app
) {
964 /* give feedback that the app was launched */
968 WMAddTimerHandler(200, (WMCallback
*)dockIconPaint
, btn
);
973 wwarning(_("could not launch application %s\n"), btn
->command
);
975 if (!btn
->relaunching
)
984 updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
986 WScreen
*scr
= menu
->frame
->screen_ptr
;
987 char title
[MAX_WORKSPACENAME_WIDTH
+1];
993 for (i
=0; i
<scr
->workspace_count
; i
++) {
994 if (i
< menu
->entry_no
) {
995 if (strcmp(menu
->entries
[i
]->text
,scr
->workspaces
[i
]->name
)!=0) {
996 free(menu
->entries
[i
]->text
);
997 strcpy(title
, scr
->workspaces
[i
]->name
);
998 menu
->entries
[i
]->text
= wstrdup(title
);
999 menu
->flags
.realized
= 0;
1001 menu
->entries
[i
]->clientdata
= (void*)icon
;
1003 strcpy(title
, scr
->workspaces
[i
]->name
);
1005 wMenuAddCallback(menu
, title
, switchWSCommand
, (void*)icon
);
1007 menu
->flags
.realized
= 0;
1009 if (i
== scr
->current_workspace
) {
1010 wMenuSetEnabled(menu
, i
, False
);
1012 wMenuSetEnabled(menu
, i
, True
);
1016 if (!menu
->flags
.realized
)
1022 makeWorkspaceMenu(WScreen
*scr
)
1026 menu
= wMenuCreate(scr
, NULL
, False
);
1028 wwarning(_("could not create workspace submenu for Clip menu"));
1030 wMenuAddCallback(menu
, "", switchWSCommand
, (void*)scr
->clip_icon
);
1032 menu
->flags
.realized
= 0;
1040 updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
1049 entry
= menu
->entries
[index
];
1050 entry
->flags
.indicator_on
= !dock
->lowered
;
1051 entry
->clientdata
= dock
;
1054 entry
= menu
->entries
[++index
];
1055 entry
->flags
.indicator_on
= dock
->collapsed
;
1056 entry
->clientdata
= dock
;
1059 entry
= menu
->entries
[++index
];
1060 entry
->flags
.indicator_on
= dock
->auto_collapse
;
1061 entry
->clientdata
= dock
;
1063 /* auto-raise/lower */
1064 entry
= menu
->entries
[++index
];
1065 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1066 entry
->clientdata
= dock
;
1069 entry
= menu
->entries
[++index
];
1070 entry
->flags
.indicator_on
= dock
->attract_icons
;
1071 entry
->clientdata
= dock
;
1073 /* keep attracted icons */
1074 entry
= menu
->entries
[++index
];
1075 entry
->flags
.indicator_on
= dock
->keep_attracted
;
1076 entry
->clientdata
= dock
;
1078 menu
->flags
.realized
= 0;
1084 makeClipOptionsMenu(WScreen
*scr
)
1089 menu
= wMenuCreate(scr
, NULL
, False
);
1091 wwarning(_("could not create options submenu for Clip menu"));
1095 entry
= wMenuAddCallback(menu
, _("Keep on Top"),
1096 toggleLoweredCallback
, NULL
);
1097 entry
->flags
.indicator
= 1;
1098 entry
->flags
.indicator_on
= 1;
1099 entry
->flags
.indicator_type
= MI_CHECK
;
1101 entry
= wMenuAddCallback(menu
, _("Collapsed"),
1102 toggleCollapsedCallback
, NULL
);
1103 entry
->flags
.indicator
= 1;
1104 entry
->flags
.indicator_on
= 1;
1105 entry
->flags
.indicator_type
= MI_CHECK
;
1107 entry
= wMenuAddCallback(menu
, _("AutoCollapse"),
1108 toggleAutoCollapseCallback
, NULL
);
1109 entry
->flags
.indicator
= 1;
1110 entry
->flags
.indicator_on
= 1;
1111 entry
->flags
.indicator_type
= MI_CHECK
;
1113 entry
= wMenuAddCallback(menu
, _("AutoRaiseLower"),
1114 toggleAutoRaiseLowerCallback
, NULL
);
1115 entry
->flags
.indicator
= 1;
1116 entry
->flags
.indicator_on
= 1;
1117 entry
->flags
.indicator_type
= MI_CHECK
;
1119 entry
= wMenuAddCallback(menu
, _("AutoAttract Icons"),
1120 toggleAutoAttractCallback
, NULL
);
1121 entry
->flags
.indicator
= 1;
1122 entry
->flags
.indicator_on
= 1;
1123 entry
->flags
.indicator_type
= MI_CHECK
;
1125 entry
= wMenuAddCallback(menu
, _("Keep Attracted Icons"),
1126 toggleKeepCallback
, NULL
);
1127 entry
->flags
.indicator
= 1;
1128 entry
->flags
.indicator_on
= 1;
1129 entry
->flags
.indicator_type
= MI_CHECK
;
1131 menu
->flags
.realized
= 0;
1139 dockMenuCreate(WScreen
*scr
, int type
)
1144 if (type
== WM_CLIP
&& scr
->clip_menu
)
1145 return scr
->clip_menu
;
1147 menu
= wMenuCreate(scr
, NULL
, False
);
1148 if (type
!= WM_CLIP
) {
1149 entry
= wMenuAddCallback(menu
, _("Keep on top"),
1150 toggleLoweredCallback
, NULL
);
1151 entry
->flags
.indicator
= 1;
1152 entry
->flags
.indicator_on
= 1;
1153 entry
->flags
.indicator_type
= MI_CHECK
;
1155 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1156 scr
->clip_options
= makeClipOptionsMenu(scr
);
1157 if (scr
->clip_options
)
1158 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1160 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
,
1163 entry
->text
= _("Rename Workspace");
1165 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1166 entry
->flags
.indicator
= 1;
1167 entry
->flags
.indicator_on
= 1;
1168 entry
->flags
.indicator_type
= MI_CHECK
;
1170 entry
= wMenuAddCallback(menu
, _("Select All Icons"),
1171 selectIconsCallback
, NULL
);
1173 entry
->text
= _("Select All Icons");
1175 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1177 entry
->text
= _("Keep Icon");
1179 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1181 entry
->text
= _("Move Icon To");
1182 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1183 if (scr
->clip_submenu
)
1184 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1186 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
,
1189 entry
->text
= _("Remove Icon");
1191 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1194 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1196 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1198 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1200 entry
->text
= _("Hide");
1202 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1204 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1206 if (type
== WM_CLIP
)
1207 scr
->clip_menu
= menu
;
1214 wDockCreate(WScreen
*scr
, int type
)
1222 dock
= wmalloc(sizeof(WDock
));
1223 memset(dock
, 0, sizeof(WDock
));
1225 if (type
== WM_CLIP
)
1226 icon_count
= CLIP_MAX_ICONS
;
1228 icon_count
= scr
->scr_height
/wPreferences
.icon_size
;
1230 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*)*icon_count
);
1231 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*)*icon_count
);
1233 dock
->max_icons
= icon_count
;
1235 btn
= mainIconCreate(scr
, type
);
1239 dock
->x_pos
= btn
->x_pos
;
1240 dock
->y_pos
= btn
->y_pos
;
1241 dock
->screen_ptr
= scr
;
1243 dock
->icon_count
= 1;
1244 dock
->on_right_side
= 1;
1245 dock
->collapsed
= 0;
1246 dock
->auto_collapse
= 0;
1247 dock
->auto_collapse_magic
= NULL
;
1248 dock
->auto_raise_lower
= 0;
1249 dock
->auto_lower_magic
= NULL
;
1250 dock
->auto_raise_magic
= NULL
;
1251 dock
->attract_icons
= 0;
1252 dock
->keep_attracted
= 0;
1254 dock
->icon_array
[0] = btn
;
1255 wRaiseFrame(btn
->icon
->core
);
1256 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1258 /* create dock menu */
1259 dock
->menu
= dockMenuCreate(scr
, type
);
1266 wDockDestroy(WDock
*dock
)
1271 for (i
=(dock
->type
== WM_CLIP
) ? 1 : 0; i
<dock
->max_icons
; i
++) {
1272 aicon
= dock
->icon_array
[i
];
1274 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1275 wDockDetach(dock
, aicon
);
1277 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
1278 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
1279 aicon
->x_pos
, aicon
->y_pos
);
1280 if (!dock
->mapped
|| dock
->collapsed
)
1281 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1285 if (wPreferences
.auto_arrange_icons
)
1286 wArrangeIcons(dock
->screen_ptr
, True
);
1287 free(dock
->icon_array
);
1288 if (dock
->menu
&& dock
->type
!=WM_CLIP
)
1289 wMenuDestroy(dock
->menu
, True
);
1295 wClipIconPaint(WAppIcon
*aicon
)
1297 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1298 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1300 Window win
= aicon
->icon
->core
->window
;
1301 int length
, nlength
;
1302 char *ws_name
, ws_number
[10];
1305 wIconPaint(aicon
->icon
);
1307 length
= strlen(workspace
->name
);
1308 ws_name
= malloc(length
+ 1);
1309 sprintf(ws_name
, "%s", workspace
->name
);
1310 sprintf(ws_number
, "%i", scr
->current_workspace
+ 1);
1311 nlength
= strlen(ws_number
);
1313 gc
= scr
->clip_title_gc
;
1315 if (!workspace
->clip
->collapsed
)
1316 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_NORMAL
]);
1318 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_COLLAPSED
]);
1320 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1322 tx
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
1324 WMDrawString(scr
->wmscreen
, win
, gc
, scr
->clip_title_font
, tx
,
1325 ty
, ws_name
, length
);
1327 tx
= (ICON_SIZE
/2 - WMWidthOfString(scr
->clip_title_font
, ws_number
,
1330 WMDrawString(scr
->wmscreen
, win
, gc
, scr
->clip_title_font
, tx
,
1331 2, ws_number
, nlength
);
1335 if (aicon
->launching
) {
1336 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1337 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1339 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
,
1340 aicon
->dock
->rclip_button_pushed
);
1345 clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1347 wClipIconPaint(desc
->parent
);
1352 dockIconPaint(WAppIcon
*btn
)
1354 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1355 wClipIconPaint(btn
);
1362 make_icon_state(WAppIcon
*btn
)
1364 proplist_t node
= NULL
;
1365 proplist_t command
, autolaunch
, name
, forced
, host
, position
, buggy
;
1366 proplist_t omnipresent
;
1372 command
= PLMakeString("-");
1374 command
= PLMakeString(btn
->command
);
1376 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1378 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1380 name
= PLMakeString(tmp
);
1384 forced
= btn
->forced_dock
? dYes
: dNo
;
1386 buggy
= btn
->buggy_app
? dYes
: dNo
;
1388 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1389 sprintf(buffer
, "%i,%i", btn
->x_pos
, btn
->y_pos
);
1391 sprintf(buffer
, "%hi,%hi", btn
->xindex
, btn
->yindex
);
1392 position
= PLMakeString(buffer
);
1394 node
= PLMakeDictionaryFromEntries(dCommand
, command
,
1396 dAutoLaunch
, autolaunch
,
1398 dBuggyApplication
, buggy
,
1399 dPosition
, position
,
1403 PLRelease(position
);
1405 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1406 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&&
1407 (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1408 PLInsertDictionaryEntry(node
, dOmnipresent
, omnipresent
);
1411 if (btn
->dnd_command
) {
1412 command
= PLMakeString(btn
->dnd_command
);
1413 PLInsertDictionaryEntry(node
, dDropCommand
, command
);
1416 #endif /* OFFIX_DND */
1418 if (btn
->client_machine
&& btn
->remote_start
) {
1419 host
= PLMakeString(btn
->client_machine
);
1420 PLInsertDictionaryEntry(node
, dHost
, host
);
1430 dockSaveState(WDock
*dock
)
1433 proplist_t icon_info
;
1434 proplist_t list
=NULL
, dock_state
=NULL
;
1438 list
= PLMakeArrayFromElements(NULL
);
1440 for (i
=(dock
->type
==WM_DOCK
? 0 : 1); i
<dock
->max_icons
; i
++) {
1441 WAppIcon
*btn
= dock
->icon_array
[i
];
1443 if (!btn
|| (btn
->attracted
&& !dock
->keep_attracted
))
1446 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1447 list
= PLAppendArrayElement(list
, icon_info
);
1448 PLRelease(icon_info
);
1452 dock_state
= PLMakeDictionaryFromEntries(dApplications
, list
, NULL
);
1456 if (dock
->type
== WM_DOCK
) {
1457 sprintf(buffer
, "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0),
1459 value
= PLMakeString(buffer
);
1460 PLInsertDictionaryEntry(dock_state
, dPosition
, value
);
1464 value
= (dock
->lowered
? dYes
: dNo
);
1465 PLInsertDictionaryEntry(dock_state
, dLowered
, value
);
1467 if (dock
->type
== WM_CLIP
) {
1468 value
= (dock
->collapsed
? dYes
: dNo
);
1469 PLInsertDictionaryEntry(dock_state
, dCollapsed
, value
);
1471 value
= (dock
->auto_collapse
? dYes
: dNo
);
1472 PLInsertDictionaryEntry(dock_state
, dAutoCollapse
, value
);
1474 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1475 PLInsertDictionaryEntry(dock_state
, dAutoRaiseLower
, value
);
1477 value
= (dock
->attract_icons
? dYes
: dNo
);
1478 PLInsertDictionaryEntry(dock_state
, dAutoAttractIcons
, value
);
1480 value
= (dock
->keep_attracted
? dYes
: dNo
);
1481 PLInsertDictionaryEntry(dock_state
, dKeepAttracted
, value
);
1489 wDockSaveState(WScreen
*scr
)
1491 proplist_t dock_state
;
1493 dock_state
= dockSaveState(scr
->dock
);
1495 PLInsertDictionaryEntry(scr
->session_state
, dDock
, dock_state
);
1497 PLRelease(dock_state
);
1502 wClipSaveState(WScreen
*scr
)
1504 proplist_t clip_state
;
1506 clip_state
= make_icon_state(scr
->clip_icon
);
1508 PLInsertDictionaryEntry(scr
->session_state
, dClip
, clip_state
);
1510 PLRelease(clip_state
);
1515 wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1517 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1522 restore_icon_state(WScreen
*scr
, proplist_t info
, int type
, int index
)
1525 char *wclass
, *winstance
;
1526 proplist_t cmd
, value
;
1530 cmd
= PLGetDictionaryEntry(info
, dCommand
);
1531 if (!cmd
|| !PLIsString(cmd
)) {
1535 /* parse window name */
1536 value
= PLGetDictionaryEntry(info
, dName
);
1540 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1542 if (!winstance
&& !wclass
) {
1549 command
= wstrdup(PLGetString(cmd
));
1553 if (!command
|| strcmp(command
, "-")==0) {
1564 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
,
1571 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1572 if (type
== WM_CLIP
) {
1573 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1574 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1576 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1577 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1581 cmd
= PLGetDictionaryEntry(info
, dDropCommand
);
1583 aicon
->dnd_command
= wstrdup(PLGetString(cmd
));
1586 /* check auto launch */
1587 value
= PLGetDictionaryEntry(info
, dAutoLaunch
);
1589 aicon
->auto_launch
= 0;
1591 if (PLIsString(value
)) {
1592 if (strcasecmp(PLGetString(value
), "YES")==0)
1593 aicon
->auto_launch
= 1;
1595 wwarning(_("bad value in docked icon state info %s"),
1596 PLGetString(dAutoLaunch
));
1600 /* check if it wasn't normally docked */
1601 value
= PLGetDictionaryEntry(info
, dForced
);
1603 aicon
->forced_dock
= 0;
1605 if (PLIsString(value
)) {
1606 if (strcasecmp(PLGetString(value
), "YES")==0)
1607 aicon
->forced_dock
= 1;
1609 wwarning(_("bad value in docked icon state info %s"),
1610 PLGetString(dForced
));
1614 /* check if we can rely on the stuff in the app */
1615 value
= PLGetDictionaryEntry(info
, dBuggyApplication
);
1617 aicon
->buggy_app
= 0;
1619 if (PLIsString(value
)) {
1620 if (strcasecmp(PLGetString(value
), "YES")==0)
1621 aicon
->buggy_app
= 1;
1623 wwarning(_("bad value in docked icon state info %s"),
1624 PLGetString(dBuggyApplication
));
1628 /* get position in the dock */
1629 value
= PLGetDictionaryEntry(info
, dPosition
);
1630 if (value
&& PLIsString(value
)) {
1631 if (sscanf(PLGetString(value
), "%hi,%hi", &aicon
->xindex
,
1633 wwarning(_("bad value in docked icon state info %s"),
1634 PLGetString(dPosition
));
1636 /* check position sanity */
1637 /* incomplete section! */
1638 if (type
== WM_DOCK
) {
1640 if (aicon
->yindex
< 0)
1641 wwarning(_("bad value in docked icon position %i,%i"),
1642 aicon
->xindex
, aicon
->yindex
);
1645 aicon
->yindex
= index
;
1649 /* check if icon is omnipresent */
1650 value
= PLGetDictionaryEntry(info
, dOmnipresent
);
1652 aicon
->omnipresent
= 0;
1654 if (PLIsString(value
)) {
1655 if (strcasecmp(PLGetString(value
), "YES")==0)
1656 aicon
->omnipresent
= 1;
1658 wwarning(_("bad value in docked icon state info %s"),
1659 PLGetString(dOmnipresent
));
1670 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1674 wClipRestoreState(WScreen
*scr
, proplist_t clip_state
)
1680 icon
= mainIconCreate(scr
, WM_CLIP
);
1685 PLRetain(clip_state
);
1687 /* restore position */
1689 value
= PLGetDictionaryEntry(clip_state
, dPosition
);
1692 if (!PLIsString(value
))
1693 COMPLAIN("Position");
1695 if (sscanf(PLGetString(value
), "%i,%i", &icon
->x_pos
,
1697 COMPLAIN("Position");
1699 /* check position sanity */
1700 if (icon
->y_pos
< 0)
1702 else if (icon
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1703 icon
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1705 if (icon
->x_pos
< 0)
1707 else if (icon
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1708 icon
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1713 value
= PLGetDictionaryEntry(clip_state
, dDropCommand
);
1714 if (value
&& PLIsString(value
))
1715 icon
->dnd_command
= wstrdup(PLGetString(value
));
1718 PLRelease(clip_state
);
1725 wDockRestoreState(WScreen
*scr
, proplist_t dock_state
, int type
)
1730 WAppIcon
*aicon
, *old_top
;
1734 dock
= wDockCreate(scr
, type
);
1740 PLRetain(dock_state
);
1743 /* restore position */
1745 value
= PLGetDictionaryEntry(dock_state
, dPosition
);
1748 if (!PLIsString(value
))
1749 COMPLAIN("Position");
1751 if (sscanf(PLGetString(value
), "%i,%i", &dock
->x_pos
,
1753 COMPLAIN("Position");
1755 /* check position sanity */
1756 if (dock
->y_pos
< 0)
1758 else if (dock
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1759 dock
->y_pos
= scr
->scr_height
- ICON_SIZE
;
1761 /* This is no more needed. ??? */
1762 if (type
== WM_CLIP
) {
1763 if (dock
->x_pos
< 0)
1765 else if (dock
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1766 dock
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1768 if (dock
->x_pos
>= 0) {
1769 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1770 dock
->on_right_side
= 0;
1772 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1773 dock
->on_right_side
= 1;
1779 /* restore lowered/raised state */
1783 value
= PLGetDictionaryEntry(dock_state
, dLowered
);
1786 if (!PLIsString(value
))
1787 COMPLAIN("Lowered");
1789 if (strcasecmp(PLGetString(value
), "YES")==0)
1795 /* restore collapsed state */
1797 dock
->collapsed
= 0;
1799 value
= PLGetDictionaryEntry(dock_state
, dCollapsed
);
1802 if (!PLIsString(value
))
1803 COMPLAIN("Collapsed");
1805 if (strcasecmp(PLGetString(value
), "YES")==0)
1806 dock
->collapsed
= 1;
1811 /* restore auto-collapsed state */
1813 value
= PLGetDictionaryEntry(dock_state
, dAutoCollapse
);
1816 if (!PLIsString(value
))
1817 COMPLAIN("AutoCollapse");
1819 if (strcasecmp(PLGetString(value
), "YES")==0) {
1820 dock
->auto_collapse
= 1;
1821 dock
->collapsed
= 1;
1827 /* restore auto-raise/lower state */
1829 value
= PLGetDictionaryEntry(dock_state
, dAutoRaiseLower
);
1832 if (!PLIsString(value
))
1833 COMPLAIN("AutoRaiseLower");
1835 if (strcasecmp(PLGetString(value
), "YES")==0) {
1836 dock
->auto_raise_lower
= 1;
1841 /* restore attract icons state */
1843 dock
->attract_icons
= 0;
1845 value
= PLGetDictionaryEntry(dock_state
, dAutoAttractIcons
);
1848 if (!PLIsString(value
))
1849 COMPLAIN("AutoAttractIcons");
1851 if (strcasecmp(PLGetString(value
), "YES")==0)
1852 dock
->attract_icons
= 1;
1857 /* restore keep attracted icons state */
1859 dock
->keep_attracted
= 0;
1861 value
= PLGetDictionaryEntry(dock_state
, dKeepAttracted
);
1864 if (!PLIsString(value
))
1865 COMPLAIN("KeepAttracted");
1867 if (strcasecmp(PLGetString(value
), "YES")==0)
1868 dock
->keep_attracted
= 1;
1873 /* application list */
1875 apps
= PLGetDictionaryEntry(dock_state
, dApplications
);
1881 count
= PLGetNumberOfElements(apps
);
1886 old_top
= dock
->icon_array
[0];
1888 /* dock->icon_count is set to 1 when dock is created.
1889 * Since Clip is already restored, we want to keep it so for clip,
1890 * but for dock we may change the default top tile, so we set it to 0.
1892 if (type
== WM_DOCK
)
1893 dock
->icon_count
= 0;
1895 for (i
=0; i
<count
; i
++) {
1896 if (dock
->icon_count
>= dock
->max_icons
) {
1897 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1901 value
= PLGetArrayElement(apps
, i
);
1902 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1904 dock
->icon_array
[dock
->icon_count
] = aicon
;
1908 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
*ICON_SIZE
);
1909 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
*ICON_SIZE
);
1912 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1914 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1916 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
,
1919 if (!dock
->collapsed
)
1920 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1921 wRaiseFrame(aicon
->icon
->core
);
1924 } else if (dock
->icon_count
==0 && type
==WM_DOCK
)
1928 /* if the first icon is not defined, use the default */
1929 if (dock
->icon_array
[0]==NULL
) {
1930 /* update default icon */
1931 old_top
->x_pos
= dock
->x_pos
;
1932 old_top
->y_pos
= dock
->y_pos
;
1934 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1936 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1937 dock
->icon_array
[0] = old_top
;
1938 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1939 /* we don't need to increment dock->icon_count here because it was
1940 * incremented in the loop above.
1942 } else if (old_top
!=dock
->icon_array
[0]) {
1943 if (old_top
== scr
->clip_icon
)
1944 scr
->clip_icon
= dock
->icon_array
[0];
1945 wAppIconDestroy(old_top
);
1950 PLRelease(dock_state
);
1958 wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1960 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1962 btn
->drop_launch
= 0;
1964 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1967 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1979 wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1985 for (i
= 0; i
< dock
->max_icons
; i
++) {
1986 btn
= dock
->icon_array
[i
];
1987 if (!btn
|| !btn
->auto_launch
)
1990 state
= wmalloc(sizeof(WSavedState
));
1991 memset(state
, 0, sizeof(WSavedState
));
1992 state
->workspace
= workspace
;
1993 /* TODO: this is klugy and is very difficult to understand
1994 * what's going on. Try to clean up */
1995 wDockLaunchWithState(dock
, btn
, state
);
1999 #ifdef REDUCE_APPICONS
2001 wDockSimulateLaunch(WDock
*dock
, WAppIcon
*btn
)
2003 if ((btn
== NULL
) || (dock
== NULL
))
2006 if (!btn
->running
) {
2007 if ((btn
->icon
->owner
== NULL
) && (btn
->applist
))
2008 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
2009 if (!btn
->forced_dock
)
2019 findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
2025 if ((dock
= scr
->dock
)!=NULL
) {
2026 for (i
=0; i
<dock
->max_icons
; i
++) {
2027 if (dock
->icon_array
[i
]
2028 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
2034 if (*icon_pos
<0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
)!=NULL
) {
2035 for (i
=0; i
<dock
->max_icons
; i
++) {
2036 if (dock
->icon_array
[i
]
2037 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
2050 wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
2056 dock
= findDock(scr
, event
, &icon_pos
);
2061 * Return True if the drop was on an application icon window.
2062 * In this case, let the ClientMessage handler redirect the
2063 * message to the app.
2065 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!=None
)
2068 if (dock
->icon_array
[icon_pos
]->dnd_command
!=NULL
) {
2069 scr
->flags
.dnd_data_convertion_status
= 0;
2071 btn
= dock
->icon_array
[icon_pos
];
2073 if (!btn
->forced_dock
) {
2074 btn
->relaunching
= btn
->running
;
2077 if (btn
->wm_instance
|| btn
->wm_class
) {
2078 WWindowAttributes attr
;
2079 memset(&attr
, 0, sizeof(WWindowAttributes
));
2080 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
2082 btn
->wm_class
, &attr
, NULL
, True
);
2084 if (!attr
.no_appicon
)
2090 btn
->drop_launch
= 1;
2091 scr
->last_dock
= dock
;
2092 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
2097 if (!btn
->relaunching
) {
2104 #endif /* OFFIX_DND */
2109 wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2116 wwin
= icon
->icon
->owner
;
2117 if (icon
->command
==NULL
) {
2119 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2121 icon
->command
= FlattenStringList(argv
, argc
);
2122 XFreeStringList(argv
);
2126 /* icon->forced_dock = 1;*/
2127 if (!icon
->attracted
|| dock
->type
!=WM_CLIP
|| dock
->keep_attracted
) {
2129 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2130 _("Type the command used to launch the application"),
2132 if (command
&& (command
[0]==0 ||
2133 (command
[0]=='-' && command
[1]==0))) {
2137 icon
->command
= command
;
2143 /* If the target is the dock, reject the icon. If
2144 * the target is the clip, make it an attracted icon
2146 if (dock
->type
==WM_CLIP
) {
2147 icon
->attracted
= 1;
2148 if (!icon
->icon
->shadowed
) {
2149 icon
->icon
->shadowed
= 1;
2150 icon
->icon
->force_paint
= 1;
2162 for (index
=1; index
<dock
->max_icons
; index
++)
2163 if (dock
->icon_array
[index
] == NULL
)
2165 /* if (index == dock->max_icons)
2168 assert(index
< dock
->max_icons
);
2170 dock
->icon_array
[index
] = icon
;
2174 icon
->omnipresent
= 0;
2176 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2177 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2182 icon
->launching
= 0;
2185 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2186 if (dock
->type
== WM_CLIP
) {
2187 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2188 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2190 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2191 icon
->icon
->core
->descriptor
.parent
= icon
;
2193 MoveInStackListUnder(dock
->icon_array
[index
-1]->icon
->core
,
2195 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2196 wAppIconPaint(icon
);
2198 if (wPreferences
.auto_arrange_icons
)
2199 wArrangeIcons(dock
->screen_ptr
, True
);
2202 if (icon
->command
&& !icon
->dnd_command
) {
2203 icon
->dnd_command
= wmalloc(strlen(icon
->command
)+8);
2204 sprintf(icon
->dnd_command
, "%s %%d", icon
->command
);
2213 reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2217 for(index
=1; index
<dock
->max_icons
; index
++) {
2218 if(dock
->icon_array
[index
] == icon
)
2221 assert(index
< dock
->max_icons
);
2226 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2227 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2232 moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2240 return True
; /* No move needed, we're already there */
2245 wwin
= icon
->icon
->owner
;
2248 * For the moment we can't do this if we move icons in Clip from one
2249 * workspace to other, because if we move two or more icons without
2250 * command, the dialog box will not be able to tell us to which of the
2251 * moved icons it applies. -Dan
2253 if ((dest
->type
==WM_DOCK
/*|| dest->keep_attracted*/) && icon
->command
==NULL
) {
2254 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2256 icon
->command
= FlattenStringList(argv
, argc
);
2257 XFreeStringList(argv
);
2262 /* icon->forced_dock = 1;*/
2263 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2264 _("Type the command used to launch the application"),
2266 if (command
&& (command
[0]==0 ||
2267 (command
[0]=='-' && command
[1]==0))) {
2271 icon
->command
= command
;
2282 if (dest
->type
== WM_DOCK
)
2283 wClipMakeIconOmnipresent(icon
, False
);
2285 for(index
=1; index
<src
->max_icons
; index
++) {
2286 if(src
->icon_array
[index
] == icon
)
2289 assert(index
< src
->max_icons
);
2291 src
->icon_array
[index
] = NULL
;
2294 for(index
=1; index
<dest
->max_icons
; index
++) {
2295 if(dest
->icon_array
[index
] == NULL
)
2298 /* if (index == dest->max_icons)
2301 assert(index
< dest
->max_icons
);
2303 dest
->icon_array
[index
] = icon
;
2306 /* deselect the icon */
2307 if (icon
->icon
->selected
)
2308 wIconSelect(icon
->icon
);
2310 if (dest
->type
== WM_DOCK
) {
2311 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2312 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2314 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2315 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2318 /* set it to be kept when moving to dock, or to a clip that keep the
2320 * Unless the icon does not have a command set
2322 if (icon
->command
&& (dest
->type
==WM_DOCK
|| dest
->keep_attracted
)) {
2323 icon
->attracted
= 0;
2324 if (icon
->icon
->shadowed
) {
2325 icon
->icon
->shadowed
= 0;
2326 icon
->icon
->force_paint
= 1;
2330 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2336 icon
->x_pos
= dest
->x_pos
+ x
*ICON_SIZE
;
2337 icon
->y_pos
= dest
->y_pos
+ y
*ICON_SIZE
;
2341 MoveInStackListUnder(dest
->icon_array
[index
-1]->icon
->core
,
2343 wAppIconPaint(icon
);
2350 wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2354 /* make the settings panel be closed */
2356 DestroyDockAppSettingsPanel(icon
->panel
);
2361 icon
->attracted
= 0;
2362 if (icon
->icon
->shadowed
) {
2363 icon
->icon
->shadowed
= 0;
2364 icon
->icon
->force_paint
= 1;
2367 /* This must be called before dock->icon_array[index] is set to NULL.
2368 * Don't move it. -Dan
2370 wClipMakeIconOmnipresent(icon
, False
);
2372 /* deselect the icon */
2373 if (icon
->icon
->selected
)
2374 wIconSelect(icon
->icon
);
2376 if (icon
->command
) {
2377 free(icon
->command
);
2378 icon
->command
= NULL
;
2381 if (icon
->dnd_command
) {
2382 free(icon
->dnd_command
);
2383 icon
->dnd_command
= NULL
;
2387 for (index
=1; index
<dock
->max_icons
; index
++)
2388 if (dock
->icon_array
[index
] == icon
)
2390 assert(index
< dock
->max_icons
);
2391 dock
->icon_array
[index
] = NULL
;
2397 /* if the dock is not attached to an application or
2398 * the the application did not set the approriate hints yet,
2399 * destroy the icon */
2400 #ifdef REDUCE_APPICONS
2401 if ((icon
->num_apps
== 0) && (!icon
->running
|| !wApplicationOf(icon
->main_window
)) )
2403 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2405 wAppIconDestroy(icon
);
2407 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2408 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2409 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2410 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2411 icon
->icon
->core
->descriptor
.parent
= icon
;
2413 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2415 wAppIconPaint(icon
);
2416 if (wPreferences
.auto_arrange_icons
) {
2417 wArrangeIcons(dock
->screen_ptr
, True
);
2420 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2426 * returns the closest Dock slot index for the passed
2429 * Returns False if icon can't be docked.
2431 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2435 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2436 int *ret_x
, int *ret_y
, int redocking
)
2438 WScreen
*scr
= dock
->screen_ptr
;
2441 int i
, offset
= ICON_SIZE
/2;
2442 WAppIcon
*aicon
= NULL
;
2443 WAppIcon
*nicon
= NULL
;
2444 int max_y_icons
, max_x_icons
;
2446 max_x_icons
= scr
->scr_width
/ICON_SIZE
;
2447 max_y_icons
= scr
->scr_height
/ICON_SIZE
-1;
2449 if (wPreferences
.flags
.noupdates
)
2455 /* if the dock is full */
2457 (dock
->icon_count
>= dock
->max_icons
)) {
2461 /* exact position */
2463 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2465 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2468 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2470 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2472 /* check if the icon is outside the screen boundaries */
2473 if (dx
+ ex_x
*ICON_SIZE
< -ICON_SIZE
+2 ||
2474 dx
+ ex_x
*ICON_SIZE
>= scr
->scr_width
-1 ||
2475 dy
+ ex_y
*ICON_SIZE
< -ICON_SIZE
+2 ||
2476 dy
+ ex_y
*ICON_SIZE
>= scr
->scr_height
-1)
2479 if (dock
->type
== WM_DOCK
) {
2480 if (icon
->dock
!= dock
&& ex_x
!= 0)
2484 for (i
=0; i
<dock
->max_icons
; i
++) {
2485 nicon
= dock
->icon_array
[i
];
2486 if (nicon
&& nicon
->yindex
== ex_y
) {
2493 int sig
, done
, closest
;
2495 /* Possible cases when redocking:
2497 * icon dragged out of range of any slot -> false
2498 * icon dragged to range of free slot
2499 * icon dragged to range of same slot
2500 * icon dragged to range of different icon
2502 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2505 if (ex_y
>=0 && ex_y
<=max_y_icons
&& (aicon
==icon
|| !aicon
)) {
2511 /* start looking at the upper slot or lower? */
2512 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2519 /* look for closest free slot */
2520 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2524 closest
= sig
*(i
/2) + ex_y
;
2525 /* check if this slot is used */
2527 for (j
= 0; j
<dock
->max_icons
; j
++) {
2528 if (dock
->icon_array
[j
]
2529 && dock
->icon_array
[j
]->yindex
==closest
) {
2530 /* slot is used by someone else */
2531 if (dock
->icon_array
[j
]!=icon
)
2539 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2540 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2542 (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+1))) {
2547 } else { /* !redocking */
2549 /* if slot is free and the icon is close enough, return it */
2550 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2560 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2561 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+1;
2564 for (k
=start
; k
<stop
; k
++) {
2565 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2568 for (i
=0; i
<tmp
->max_icons
; i
++) {
2569 nicon
= tmp
->icon_array
[i
];
2570 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2578 for (k
=start
; k
<stop
; k
++) {
2579 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2582 for (i
=0; i
<tmp
->max_icons
; i
++) {
2583 nicon
= tmp
->icon_array
[i
];
2584 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2585 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2586 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2595 if (neighbours
&& (aicon
==NULL
|| (redocking
&& aicon
== icon
))) {
2604 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2605 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2607 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2608 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2609 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2613 * returns true if it can find a free slot in the dock,
2614 * in which case it changes x_pos and y_pos accordingly.
2615 * Else returns false.
2618 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2620 WScreen
*scr
= dock
->screen_ptr
;
2622 WAppIconChain
*chain
;
2623 unsigned char *slot_map
;
2627 int i
, done
= False
;
2629 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2632 if (dock
->type
== WM_CLIP
&&
2633 dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2634 extra_count
= scr
->global_icon_count
;
2636 /* if the dock is full */
2637 if (dock
->icon_count
+extra_count
>= dock
->max_icons
) {
2641 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2642 if (scr
->dock
->on_right_side
)
2643 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2645 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2648 if (ex
< dock
->x_pos
)
2650 if (sx
> dock
->x_pos
+ICON_SIZE
)
2651 sx
= dock
->x_pos
+ICON_SIZE
;
2658 /* check if clip is in a corner */
2659 if (dock
->type
==WM_CLIP
) {
2660 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2662 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2664 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2666 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2673 /* If the clip is in the corner, use only slots that are in the border
2675 if (corner
!=C_NONE
) {
2679 hcount
= MIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2680 vcount
= MIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2681 hmap
= wmalloc(hcount
+1);
2682 memset(hmap
, 0, hcount
+1);
2683 vmap
= wmalloc(vcount
+1);
2684 memset(vmap
, 0, vcount
+1);
2686 /* mark used positions */
2689 for (i
=0; i
<dock
->max_icons
; i
++) {
2690 btn
= dock
->icon_array
[i
];
2694 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2695 vmap
[btn
->yindex
] = 1;
2696 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2697 hmap
[btn
->xindex
] = 1;
2699 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2701 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2702 vmap
[btn
->yindex
] = 1;
2703 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2704 hmap
[btn
->xindex
] = 1;
2708 for (i
=0; i
<dock
->max_icons
; i
++) {
2709 btn
= dock
->icon_array
[i
];
2713 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2714 vmap
[btn
->yindex
] = 1;
2715 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2716 hmap
[-btn
->xindex
] = 1;
2718 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2720 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2721 vmap
[btn
->yindex
] = 1;
2722 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2723 hmap
[-btn
->xindex
] = 1;
2727 for (i
=0; i
<dock
->max_icons
; i
++) {
2728 btn
= dock
->icon_array
[i
];
2732 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2733 vmap
[-btn
->yindex
] = 1;
2734 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2735 hmap
[btn
->xindex
] = 1;
2737 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
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;
2747 for (i
=0; i
<dock
->max_icons
; i
++) {
2748 btn
= dock
->icon_array
[i
];
2752 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2753 vmap
[-btn
->yindex
] = 1;
2754 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2755 hmap
[-btn
->xindex
] = 1;
2757 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2759 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2760 vmap
[-btn
->yindex
] = 1;
2761 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2762 hmap
[-btn
->xindex
] = 1;
2767 /* search a vacant slot */
2768 for (i
=1; i
<MAX(vcount
, hcount
); i
++) {
2769 if (i
< vcount
&& vmap
[i
]==0) {
2775 } else if (i
< hcount
&& hmap
[i
]==0) {
2785 /* If found a slot, translate and return */
2787 if (corner
==C_NW
|| corner
==C_NE
) {
2792 if (corner
==C_NE
|| corner
==C_SE
) {
2799 /* else, try to find a slot somewhere else */
2802 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2803 * placed outside of screen */
2804 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2806 /* In the worst case (the clip is in the corner of the screen),
2807 * the amount of icons that fit in the clip is smaller.
2808 * Double the map to get a safe value.
2814 slot_map
= wmalloc(mwidth
*mwidth
);
2815 memset(slot_map
, 0, mwidth
*mwidth
);
2817 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2819 /* mark used slots in the map. If the slot falls outside the map
2820 * (for example, when all icons are placed in line), ignore them. */
2821 for (i
=0; i
<dock
->max_icons
; i
++) {
2822 btn
= dock
->icon_array
[i
];
2824 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2826 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2827 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2829 /* Find closest slot from the center that is free by scanning the
2830 * map from the center to outward in circular passes.
2831 * This will not result in a neat layout, but will be optimal
2832 * in the sense that there will not be holes left.
2835 for (i
= 1; i
<= r
&& !done
; i
++) {
2838 /* top and bottom parts of the ring */
2839 for (x
= -i
; x
<= i
&& !done
; x
++) {
2840 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2842 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2843 if (slot_map
[XY2OFS(x
,y
)]==0
2844 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2851 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2852 if (slot_map
[XY2OFS(x
,y
)]==0
2853 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2860 /* left and right parts of the ring */
2861 for (y
= -i
+1; y
<= i
-1; y
++) {
2862 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2864 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2865 if (slot_map
[XY2OFS(x
,y
)]==0
2866 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2873 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2874 if (slot_map
[XY2OFS(x
,y
)]==0
2875 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2890 moveDock(WDock
*dock
, int new_x
, int new_y
)
2895 dock
->x_pos
= new_x
;
2896 dock
->y_pos
= new_y
;
2897 for (i
=0; i
<dock
->max_icons
; i
++) {
2898 btn
= dock
->icon_array
[i
];
2900 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2901 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2902 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2909 swapDock(WDock
*dock
)
2911 WScreen
*scr
= dock
->screen_ptr
;
2916 if (dock
->on_right_side
) {
2917 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2919 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2922 for (i
=0; i
<dock
->max_icons
; i
++) {
2923 btn
= dock
->icon_array
[i
];
2926 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2930 wScreenUpdateUsableArea(scr
);
2935 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2937 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2943 cmdline
= ExpandOptions(scr
, command
);
2945 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2953 ParseCommand(cmdline
, &argv
, &argc
);
2963 if ((pid
=fork())==0) {
2967 SetupEnvironment(scr
);
2973 args
= malloc(sizeof(char*)*(argc
+1));
2976 for (i
=0; i
<argc
; i
++) {
2980 execvp(argv
[0], args
);
2989 state
= wmalloc(sizeof(WSavedState
));
2990 memset(state
, 0, sizeof(WSavedState
));
2992 state
->miniaturized
= -1;
2994 if (btn
->dock
==scr
->dock
|| btn
->omnipresent
)
2995 state
->workspace
= -1;
2997 state
->workspace
= scr
->current_workspace
;
2999 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
3001 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
3012 wDockHideIcons(WDock
*dock
)
3019 for (i
=1; i
<dock
->max_icons
; i
++) {
3020 if (dock
->icon_array
[i
])
3021 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3025 dockIconPaint(dock
->icon_array
[0]);
3030 wDockShowIcons(WDock
*dock
)
3038 btn
= dock
->icon_array
[0];
3039 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
3041 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
3042 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
3044 for (i
=1; i
<dock
->max_icons
; i
++) {
3045 if (dock
->icon_array
[i
]) {
3046 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
3052 if (!dock
->collapsed
) {
3053 for (i
=1; i
<dock
->max_icons
; i
++) {
3054 if (dock
->icon_array
[i
]) {
3055 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3066 wDockLower(WDock
*dock
)
3070 for (i
=0; i
<dock
->max_icons
; i
++) {
3071 if (dock
->icon_array
[i
])
3072 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
3078 wDockRaise(WDock
*dock
)
3082 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
3083 if (dock
->icon_array
[i
])
3084 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
3090 wDockRaiseLower(WDock
*dock
)
3092 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
3093 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
3094 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
3102 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
3104 icon
->launching
= 0;
3105 icon
->relaunching
= 0;
3106 dockIconPaint(icon
);
3111 wDockFindIconFor(WDock
*dock
, Window window
)
3116 for (i
=0; i
<dock
->max_icons
; i
++) {
3117 icon
= dock
->icon_array
[i
];
3118 if (icon
&& icon
->main_window
== window
)
3126 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
3129 #ifdef REDUCE_APPICONS
3130 WAppIconAppList
*tapplist
;
3132 char *wm_class
, *wm_instance
;
3134 Bool firstPass
= True
;
3136 char *command
= NULL
;
3142 if (XGetCommand(dpy
, window
, &argv
, &argc
)) {
3143 if (argc
> 0 && argv
!= NULL
)
3144 command
= FlattenStringList(argv
,argc
);
3146 XFreeStringList(argv
);
3151 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
3152 (!wm_class
&& !wm_instance
))
3156 for (i
=0; i
<dock
->max_icons
; i
++) {
3157 icon
= dock
->icon_array
[i
];
3161 /* app is already attached to icon */
3162 if (icon
->main_window
== window
) {
3167 if ((icon
->wm_instance
|| icon
->wm_class
)
3169 || (dock
->screen_ptr
->flags
.startup
&& !icon
->running
))) {
3171 if (icon
->wm_instance
&& wm_instance
&&
3172 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
3175 if (icon
->wm_class
&& wm_class
&&
3176 strcmp(icon
->wm_class
, wm_class
)!=0) {
3179 if (firstPass
&& command
&& strcmp(icon
->command
, command
)!=0) {
3183 if (!icon
->relaunching
) {
3186 /* Possibly an application that was docked with dockit,
3187 * but the user did not update WMState to indicate that
3188 * it was docked by force */
3189 wapp
= wApplicationOf(window
);
3191 icon
->forced_dock
= 1;
3194 if (!icon
->forced_dock
)
3195 icon
->main_window
= window
;
3197 #ifdef REDUCE_APPICONS
3198 tapplist
= wmalloc(sizeof(WAppIconAppList
));
3199 memset(tapplist
, 0, sizeof(WAppIconAppList
));
3200 tapplist
->next
= icon
->applist
;
3202 icon
->applist
->prev
= tapplist
;
3203 icon
->applist
= tapplist
;
3204 tapplist
->wapp
= wApplicationOf(window
);
3209 wDockFinishLaunch(dock
, icon
);
3214 if (firstPass
&& !found
) {
3231 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3233 if (!wPreferences
.flags
.noclip
) {
3234 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3235 if (scr
->current_workspace
!= workspace
) {
3236 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3237 WAppIconChain
*chain
= scr
->global_icons
;
3240 moveIconBetweenDocks(chain
->aicon
->dock
,
3241 scr
->workspaces
[workspace
]->clip
,
3242 chain
->aicon
, chain
->aicon
->xindex
,
3243 chain
->aicon
->yindex
);
3244 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
3245 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3246 chain
= chain
->next
;
3249 wDockHideIcons(old_clip
);
3250 if (old_clip
->auto_raise_lower
) {
3251 if (old_clip
->auto_raise_magic
) {
3252 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3253 old_clip
->auto_raise_magic
= NULL
;
3255 wDockLower(old_clip
);
3257 if (old_clip
->auto_collapse
) {
3258 if (old_clip
->auto_expand_magic
) {
3259 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3260 old_clip
->auto_expand_magic
= NULL
;
3262 old_clip
->collapsed
= 1;
3264 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3266 if (scr
->flags
.clip_balloon_mapped
)
3267 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3274 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3279 for (i
=0; i
<dock
->max_icons
; i
++) {
3280 icon
= dock
->icon_array
[i
];
3284 if (icon
->launching
&& icon
->pid
== pid
) {
3285 if (!icon
->relaunching
) {
3287 icon
->main_window
= None
;
3289 wDockFinishLaunch(dock
, icon
);
3294 sprintf(msg
, _("Could not execute command \"%s\""),
3295 icon
->drop_launch
&& icon
->dnd_command
3296 ? icon
->dnd_command
: icon
->command
);
3298 sprintf(msg
, _("Could not execute command \"%s\""),
3301 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
3302 _("OK"), NULL
, NULL
);
3311 toggleLowered(WDock
*dock
)
3316 /* lower/raise Dock */
3317 if (!dock
->lowered
) {
3318 newlevel
= WMNormalLevel
;
3321 newlevel
= WMDockLevel
;
3325 for (i
=0; i
<dock
->max_icons
; i
++) {
3326 tmp
= dock
->icon_array
[i
];
3330 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3332 wLowerFrame(tmp
->icon
->core
);
3335 if (dock
->type
== WM_DOCK
)
3336 wScreenUpdateUsableArea(dock
->screen_ptr
);
3341 toggleCollapsed(WDock
*dock
)
3343 if (dock
->collapsed
) {
3344 dock
->collapsed
= 0;
3345 wDockShowIcons(dock
);
3348 dock
->collapsed
= 1;
3349 wDockHideIcons(dock
);
3355 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3357 WScreen
*scr
= dock
->screen_ptr
;
3358 WObjDescriptor
*desc
;
3360 WApplication
*wapp
= NULL
;
3364 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3366 if (dock
->type
== WM_DOCK
) {
3368 entry
= dock
->menu
->entries
[index
];
3369 entry
->flags
.indicator_on
= !dock
->lowered
;
3370 entry
->clientdata
= dock
;
3373 if (scr
->clip_options
)
3374 updateClipOptionsMenu(scr
->clip_options
, dock
);
3376 n_selected
= numberOfSelectedIcons(dock
);
3378 /* Rename Workspace */
3379 entry
= dock
->menu
->entries
[++index
];
3380 if (aicon
== scr
->clip_icon
) {
3381 entry
->callback
= renameCallback
;
3382 entry
->clientdata
= dock
;
3383 entry
->flags
.indicator
= 0;
3384 entry
->text
= _("Rename Workspace");
3386 entry
->callback
= omnipresentCallback
;
3387 entry
->clientdata
= aicon
;
3388 if (n_selected
> 0) {
3389 entry
->flags
.indicator
= 0;
3390 entry
->text
= _("Toggle Omnipresent");
3392 entry
->flags
.indicator
= 1;
3393 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3394 entry
->flags
.indicator_type
= MI_CHECK
;
3395 entry
->text
= _("Omnipresent");
3399 /* select/unselect icon */
3400 entry
= dock
->menu
->entries
[++index
];
3401 entry
->clientdata
= aicon
;
3402 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3403 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3405 /* select/unselect all icons */
3406 entry
= dock
->menu
->entries
[++index
];
3407 entry
->clientdata
= aicon
;
3409 entry
->text
= _("Unselect All Icons");
3411 entry
->text
= _("Select All Icons");
3412 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3415 entry
= dock
->menu
->entries
[++index
];
3416 entry
->clientdata
= aicon
;
3418 entry
->text
= _("Keep Icons");
3420 entry
->text
= _("Keep Icon");
3421 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3423 /* this is the workspace submenu part */
3424 entry
= dock
->menu
->entries
[++index
];
3426 entry
->text
= _("Move Icons To");
3428 entry
->text
= _("Move Icon To");
3429 if (scr
->clip_submenu
)
3430 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3431 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3433 /* remove icon(s) */
3434 entry
= dock
->menu
->entries
[++index
];
3435 entry
->clientdata
= aicon
;
3437 entry
->text
= _("Remove Icons");
3439 entry
->text
= _("Remove Icon");
3440 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3442 /* attract icon(s) */
3443 entry
= dock
->menu
->entries
[++index
];
3444 entry
->clientdata
= aicon
;
3446 dock
->menu
->flags
.realized
= 0;
3447 wMenuRealize(dock
->menu
);
3451 entry
= dock
->menu
->entries
[++index
];
3452 entry
->clientdata
= aicon
;
3453 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3456 entry
= dock
->menu
->entries
[++index
];
3457 entry
->clientdata
= aicon
;
3458 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3461 entry
= dock
->menu
->entries
[++index
];
3462 entry
->clientdata
= aicon
;
3463 if (aicon
->icon
->owner
) {
3464 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3465 if (wapp
&& wapp
->flags
.hidden
)
3466 entry
->text
= _("Unhide");
3468 entry
->text
= _("Hide");
3470 entry
->text
= _("Hide");
3472 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3475 entry
= dock
->menu
->entries
[++index
];
3476 entry
->clientdata
= aicon
;
3477 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
3478 && !wPreferences
.flags
.noupdates
);
3481 entry
= dock
->menu
->entries
[++index
];
3482 entry
->clientdata
= aicon
;
3483 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3485 if (!dock
->menu
->flags
.realized
)
3486 wMenuRealize(dock
->menu
);
3488 if (dock
->type
== WM_CLIP
) {
3489 x_pos
= event
->xbutton
.x_root
+2;
3491 x_pos
= dock
->on_right_side
?
3492 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 2 : 0;
3495 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3497 /* allow drag select */
3498 event
->xany
.send_event
= True
;
3499 desc
= &dock
->menu
->menu
->descriptor
;
3500 (*desc
->handle_mousedown
)(desc
, event
);
3505 openClipWorkspaceMenu(WScreen
*scr
, int x
, int y
)
3507 if (!scr
->clip_ws_menu
) {
3508 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3510 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
3511 wMenuMapAt(scr
->clip_ws_menu
, x
, y
, False
);
3515 /******************************************************************/
3517 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3519 WAppIcon
*btn
= desc
->parent
;
3520 WDock
*dock
= btn
->dock
;
3521 WApplication
*wapp
= NULL
;
3524 #ifdef REDUCE_APPICONS
3525 if ((btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) ||
3526 ((btn
->icon
->owner
== NULL
) && (btn
->applist
!= NULL
))) {
3527 if (btn
->icon
->owner
== NULL
)
3528 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
3531 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3533 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3537 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3539 /* go to the last workspace that the user worked on the app */
3540 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
3542 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3545 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3548 if (event
->xbutton
.state
& MOD_MASK
) {
3549 wHideOtherApplications(btn
->icon
->owner
);
3552 if (event
->xbutton
.button
==Button1
) {
3554 if (event
->xbutton
.state
& MOD_MASK
) {
3555 /* raise/lower dock */
3556 toggleLowered(dock
);
3557 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3558 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3559 toggleCollapsed(dock
);
3561 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3562 } else if (btn
->command
) {
3563 if (!btn
->launching
&&
3564 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3565 launchDockedApplication(btn
);
3567 } else if (btn
->xindex
== 0 && btn
->yindex
== 0
3568 && btn
->dock
->type
== WM_DOCK
) {
3570 wShowGNUstepPanel(dock
->screen_ptr
);
3578 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3580 WScreen
*scr
= dock
->screen_ptr
;
3581 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3584 int grabbed
= 0, swapped
= 0, done
;
3585 Pixmap ghost
= None
;
3586 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3589 puts("moving dock");
3591 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3592 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3593 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3594 wwarning("pointer grab failed for dock move");
3597 for (x
=0; x
<dock
->max_icons
; x
++) {
3598 if (dock
->icon_array
[x
]!=NULL
&&
3599 dock
->icon_array
[x
]->yindex
> y
)
3600 y
= dock
->icon_array
[x
]->yindex
;
3603 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3607 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3608 |ButtonMotionMask
|ExposureMask
, &ev
);
3616 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3617 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3618 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3619 |ButtonReleaseMask
|ButtonPressMask
,
3620 wCursor
[WCUR_MOVE
], CurrentTime
);
3625 if (dock
->type
== WM_CLIP
) {
3626 if (ev
.xmotion
.x_root
- ofs_x
< 0) {
3628 } else if (ev
.xmotion
.x_root
- ofs_x
+ ICON_SIZE
>
3630 x
= scr
->scr_width
- ICON_SIZE
;
3632 x
= ev
.xmotion
.x_root
- ofs_x
;
3634 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3636 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3638 y
= scr
->scr_height
- ICON_SIZE
;
3640 y
= ev
.xmotion
.y_root
- ofs_y
;
3642 moveDock(dock
, x
, y
);
3644 /* move vertically if pointer is inside the dock*/
3645 if ((dock
->on_right_side
&&
3646 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3647 || (!dock
->on_right_side
&&
3648 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3650 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3652 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3654 y
= scr
->scr_height
- ICON_SIZE
;
3656 y
= ev
.xmotion
.y_root
- ofs_y
;
3658 moveDock(dock
, dock
->x_pos
, y
);
3660 /* move horizontally to change sides */
3661 x
= ev
.xmotion
.x_root
- ofs_x
;
3662 if (!dock
->on_right_side
) {
3666 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3667 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3668 -DOCK_EXTRA_SPACE
-1, dock
->y_pos
);
3669 if (superfluous
&& ghost
==None
) {
3670 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3671 scr
->scr_width
-ICON_SIZE
3672 -DOCK_EXTRA_SPACE
-1,
3674 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3676 XClearWindow(dpy
, scr
->dock_shadow
);
3678 XMapRaised(dpy
, scr
->dock_shadow
);
3681 if (superfluous
&& ghost
!=None
) {
3682 XFreePixmap(dpy
, ghost
);
3685 XUnmapWindow(dpy
, scr
->dock_shadow
);
3690 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3691 XMoveWindow(dpy
, scr
->dock_shadow
,
3692 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3693 if (superfluous
&& ghost
==None
) {
3694 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3695 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3696 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3698 XClearWindow(dpy
, scr
->dock_shadow
);
3700 XMapRaised(dpy
, scr
->dock_shadow
);
3703 XUnmapWindow(dpy
, scr
->dock_shadow
);
3705 if (superfluous
&& ghost
!=None
) {
3706 XFreePixmap(dpy
, ghost
);
3718 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3720 XUngrabPointer(dpy
, CurrentTime
);
3721 XUnmapWindow(dpy
, scr
->dock_shadow
);
3722 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3723 if (dock
->type
== WM_DOCK
) {
3726 dock
->on_right_side
= 1;
3728 dock
->on_right_side
= 0;
3730 wArrangeIcons(scr
, False
);
3739 XFreePixmap(dpy
, ghost
);
3740 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3743 puts("End dock move");
3750 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3752 WScreen
*scr
= dock
->screen_ptr
;
3754 WIcon
*icon
= aicon
->icon
;
3755 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3756 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3758 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3759 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3760 int shad_x
= x
, shad_y
= y
;
3761 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3763 Pixmap ghost
= None
;
3765 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3766 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3769 if (wPreferences
.flags
.noupdates
)
3772 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3773 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3774 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3776 wwarning("pointer grab failed for icon move");
3780 if (!(event
->xbutton
.state
& MOD_MASK
))
3781 wRaiseFrame(icon
->core
);
3783 if (!wPreferences
.flags
.noclip
)
3784 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3786 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3788 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3791 wins
[0] = icon
->core
->window
;
3792 wins
[1] = scr
->dock_shadow
;
3793 XRestackWindows(dpy
, wins
, 2);
3794 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3795 ICON_SIZE
, ICON_SIZE
);
3797 if (icon
->pixmap
!=None
)
3798 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3800 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3802 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3803 XClearWindow(dpy
, scr
->dock_shadow
);
3805 XMapWindow(dpy
, scr
->dock_shadow
);
3811 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3812 |ButtonMotionMask
|ExposureMask
, &ev
);
3820 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3821 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3822 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3823 |ButtonReleaseMask
|ButtonPressMask
,
3824 wCursor
[WCUR_MOVE
], CurrentTime
);
3833 for (i
=0; i
<scr
->workspace_count
; i
++) {
3834 if (i
== scr
->current_workspace
)
3836 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3840 x
= ev
.xmotion
.x_root
- ofs_x
;
3841 y
= ev
.xmotion
.y_root
- ofs_y
;
3842 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3845 if (last_dock
!= dock
&& collapsed
) {
3846 last_dock
->collapsed
= 1;
3847 wDockHideIcons(last_dock
);
3850 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3851 dock
->collapsed
= 0;
3852 wDockShowIcons(dock
);
3854 if (dock
->auto_raise_lower
)
3858 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3861 if (last_dock
!= dock2
&& collapsed
) {
3862 last_dock
->collapsed
= 1;
3863 wDockHideIcons(last_dock
);
3866 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3867 dock2
->collapsed
= 0;
3868 wDockShowIcons(dock2
);
3870 if (dock2
->auto_raise_lower
)
3875 if (aicon
->launching
3876 || (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3877 || (!aicon
->running
&& tmp
)) {
3878 shad_x
= last_dock
->x_pos
+ ix
*wPreferences
.icon_size
;
3879 shad_y
= last_dock
->y_pos
+ iy
*wPreferences
.icon_size
;
3881 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3884 XMapWindow(dpy
, scr
->dock_shadow
);
3889 XUnmapWindow(dpy
, scr
->dock_shadow
);
3893 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3900 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3902 XUngrabPointer(dpy
, CurrentTime
);
3904 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3905 XUnmapWindow(dpy
, scr
->dock_shadow
);
3907 reattachIcon(dock
, aicon
, ix
, iy
);
3908 if (clip
&& dock
!=clip
&& clip
->auto_raise_lower
)
3911 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3913 /* Slide it back if dock rejected it */
3914 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3916 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3918 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3926 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3927 /* We need to deselect it, even if is deselected in
3928 * wDockDetach(), because else DoKaboom() will fail.
3930 if (aicon
->icon
->selected
)
3931 wIconSelect(aicon
->icon
);
3932 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3935 if (clip
&& clip
->auto_raise_lower
)
3937 wDockDetach(dock
, aicon
);
3940 last_dock
->collapsed
= 1;
3941 wDockHideIcons(last_dock
);
3946 XFreePixmap(dpy
, ghost
);
3947 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3951 for (i
=0; i
<scr
->workspace_count
; i
++) {
3952 if (i
== scr
->current_workspace
)
3954 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3959 puts("End icon move");
3968 getClipButton(int px
, int py
)
3970 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
3972 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3975 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
3976 return CLIP_FORWARD
;
3977 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
3985 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3988 int done
, direction
, new_ws
;
3990 WDock
*clip
= scr
->clip_icon
->dock
;
3992 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3994 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3995 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3997 wClipIconPaint(scr
->clip_icon
);
4000 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
4001 |ButtonPressMask
, &ev
);
4008 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
4009 if (new_dir
!= direction
) {
4010 direction
= new_dir
;
4011 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
4012 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
4013 wClipIconPaint(scr
->clip_icon
);
4021 if (ev
.xbutton
.button
== event
->xbutton
.button
)
4026 clip
->lclip_button_pushed
= 0;
4027 clip
->rclip_button_pushed
= 0;
4029 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
4031 if (direction
== CLIP_FORWARD
) {
4032 if (scr
->current_workspace
< scr
->workspace_count
-1)
4033 wWorkspaceChange(scr
, scr
->current_workspace
+1);
4034 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
4035 wWorkspaceChange(scr
, scr
->current_workspace
+1);
4036 else if (wPreferences
.ws_cycle
)
4037 wWorkspaceChange(scr
, 0);
4039 else if (direction
== CLIP_REWIND
) {
4040 if (scr
->current_workspace
> 0)
4041 wWorkspaceChange(scr
, scr
->current_workspace
-1);
4042 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
4043 wWorkspaceChange(scr
, scr
->workspace_count
-1);
4046 wClipIconPaint(scr
->clip_icon
);
4051 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
4053 WAppIcon
*aicon
= desc
->parent
;
4054 WDock
*dock
= aicon
->dock
;
4055 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4057 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
4060 scr
->last_dock
= dock
;
4062 if (dock
->menu
->flags
.mapped
)
4063 wMenuUnmap(dock
->menu
);
4065 if (IsDoubleClick(scr
, event
)) {
4066 /* double-click was not in the main clip icon */
4067 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
4068 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
4069 iconDblClick(desc
, event
);
4074 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
4075 XUnmapWindow(dpy
, scr
->clip_balloon
);
4076 scr
->flags
.clip_balloon_mapped
= 0;
4080 puts("handling dock");
4082 if (event
->xbutton
.button
== Button1
) {
4083 if (event
->xbutton
.state
& MOD_MASK
)
4088 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
4089 dock
->type
!=WM_DOCK
) {
4090 wIconSelect(aicon
->icon
);
4094 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
4095 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
4096 && dock
->type
==WM_CLIP
)
4097 handleClipChangeWorkspace(scr
, event
);
4099 handleDockMove(dock
, aicon
, event
);
4101 handleIconMove(dock
, aicon
, event
);
4103 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4104 aicon
==scr
->clip_icon
) {
4105 openClipWorkspaceMenu(scr
, event
->xbutton
.x_root
+2,
4106 event
->xbutton
.y_root
+2);
4107 if (scr
->clip_ws_menu
) {
4109 menu
= scr
->clip_ws_menu
;
4110 desc
= &menu
->menu
->descriptor
;
4112 event
->xany
.send_event
= True
;
4113 (*desc
->handle_mousedown
)(desc
, event
);
4115 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4116 (event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
) {
4117 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
4118 } else if (event
->xbutton
.button
== Button3
) {
4119 openDockMenu(dock
, aicon
, event
);
4125 showClipBalloon(WDock
*dock
, int workspace
)
4129 WScreen
*scr
= dock
->screen_ptr
;
4133 scr
->flags
.clip_balloon_mapped
= 1;
4134 XMapWindow(dpy
, scr
->clip_balloon
);
4136 text
= scr
->workspaces
[workspace
]->name
;
4138 w
= WMWidthOfString(scr
->clip_title_font
, text
, strlen(text
));
4140 h
= WMFontHeight(scr
->clip_title_font
);
4141 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
4143 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
4144 y
= dock
->y_pos
+ ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
4146 if (x
+w
> scr
->scr_width
) {
4147 x
= scr
->scr_width
- w
;
4148 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
4149 y
= dock
->y_pos
- h
- 1;
4151 y
= dock
->y_pos
+ ICON_SIZE
;
4152 XRaiseWindow(dpy
, scr
->clip_balloon
);
4154 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
4155 stack
[1] = scr
->clip_balloon
;
4156 XRestackWindows(dpy
, stack
, 2);
4158 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
4159 XSetForeground(dpy
, scr
->clip_title_gc
,
4160 scr
->clip_title_pixel
[CLIP_NORMAL
]);
4161 XClearWindow(dpy
, scr
->clip_balloon
);
4162 WMDrawString(scr
->wmscreen
, scr
->clip_balloon
, scr
->clip_title_gc
,
4163 scr
->clip_title_font
, 0, 0, text
, strlen(text
));
4168 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
4170 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4174 assert(event
->type
==EnterNotify
);
4176 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4179 scr
= btn
->icon
->core
->screen_ptr
;
4180 if (!btn
->omnipresent
)
4183 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
4185 if (!dock
|| dock
->type
!=WM_CLIP
)
4188 /* The auto raise/lower code */
4189 if (dock
->auto_lower_magic
) {
4190 WMDeleteTimerHandler(dock
->auto_lower_magic
);
4191 dock
->auto_lower_magic
= NULL
;
4193 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
4194 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
,
4199 /* The auto expand/collapse code */
4200 if (dock
->auto_collapse_magic
) {
4201 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
4202 dock
->auto_collapse_magic
= NULL
;
4204 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
4205 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
,
4210 if (btn
->xindex
== 0 && btn
->yindex
== 0)
4211 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4213 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4214 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
4215 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
4222 clipLeave(WDock
*dock
)
4225 WObjDescriptor
*desc
= NULL
;
4227 if (!dock
|| dock
->type
!=WM_CLIP
)
4230 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
)!=False
) {
4231 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
4232 (XPointer
*)&desc
)!=XCNOENT
4233 && desc
&& desc
->parent_type
==WCLASS_DOCK_ICON
4234 && ((WAppIcon
*)desc
->parent
)->dock
4235 && ((WAppIcon
*)desc
->parent
)->dock
->type
==WM_CLIP
) {
4236 /* We didn't left the Clip yet */
4237 XPutBackEvent(dpy
, &event
);
4241 XPutBackEvent(dpy
, &event
);
4243 /* We entered a withdrawn window, so we're still in Clip */
4247 if (dock
->auto_raise_magic
) {
4248 WMDeleteTimerHandler(dock
->auto_raise_magic
);
4249 dock
->auto_raise_magic
= NULL
;
4251 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
4252 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
,
4257 if (dock
->auto_expand_magic
) {
4258 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4259 dock
->auto_expand_magic
= NULL
;
4261 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
4262 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
4270 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4272 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4274 assert(event
->type
==LeaveNotify
);
4276 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4279 clipLeave(btn
->dock
);
4284 clipAutoCollapse(void *cdata
)
4286 WDock
*dock
= (WDock
*)cdata
;
4288 if (dock
->type
!=WM_CLIP
)
4291 if (dock
->auto_collapse
) {
4292 dock
->collapsed
= 1;
4293 wDockHideIcons(dock
);
4295 dock
->auto_collapse_magic
= NULL
;
4300 clipAutoExpand(void *cdata
)
4302 WDock
*dock
= (WDock
*)cdata
;
4304 if (dock
->type
!=WM_CLIP
)
4307 if (dock
->auto_collapse
) {
4308 dock
->collapsed
= 0;
4309 wDockShowIcons(dock
);
4311 dock
->auto_expand_magic
= NULL
;
4316 clipAutoLower(void *cdata
)
4318 WDock
*dock
= (WDock
*)cdata
;
4320 if (dock
->type
!=WM_CLIP
)
4323 if (dock
->auto_raise_lower
)
4326 dock
->auto_lower_magic
= NULL
;
4331 clipAutoRaise(void *cdata
)
4333 WDock
*dock
= (WDock
*)cdata
;
4335 if (dock
->type
!=WM_CLIP
)
4338 if (dock
->auto_raise_lower
)
4341 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4342 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4345 dock
->auto_raise_magic
= NULL
;
4350 iconCanBeOmnipresent(WAppIcon
*aicon
)
4352 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4357 for (i
=0; i
<scr
->workspace_count
; i
++) {
4358 clip
= scr
->workspaces
[i
]->clip
;
4360 if (clip
== aicon
->dock
)
4363 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4364 return False
; /* Clip is full in some workspace */
4366 for (j
=0; j
<clip
->max_icons
; j
++) {
4367 btn
= clip
->icon_array
[j
];
4368 if(btn
&& btn
->xindex
==aicon
->xindex
&& btn
->yindex
==aicon
->yindex
)
4378 wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
4380 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4381 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4382 int status
= WO_SUCCESS
;
4384 if (aicon
->dock
== scr
->dock
|| aicon
== scr
->clip_icon
)
4385 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
= NULL
;
4396 if (!scr
->global_icons
) {
4397 scr
->global_icons
= new_entry
;
4399 tmp
= scr
->global_icons
;
4403 tmp
->next
= new_entry
;
4405 scr
->global_icon_count
++;
4407 aicon
->omnipresent
= 0;
4411 aicon
->omnipresent
= 0;
4412 if (aicon
== scr
->global_icons
->aicon
) {
4413 tmp
= scr
->global_icons
->next
;
4414 free(scr
->global_icons
);
4415 scr
->global_icons
= tmp
;
4416 scr
->global_icon_count
--;
4418 tmp
= scr
->global_icons
;
4420 if (tmp
->next
->aicon
== aicon
) {
4421 tmp1
= tmp
->next
->next
;
4424 scr
->global_icon_count
--;
4432 wAppIconPaint(aicon
);