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(aicon
->icon
->core
->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(aicon
->icon
->core
->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
, _("Select Icon"), selectCallback
, NULL
);
1167 entry
->text
= _("Select Icon");
1169 entry
= wMenuAddCallback(menu
, _("Select All Icons"),
1170 selectIconsCallback
, NULL
);
1172 entry
->text
= _("Select All Icons");
1174 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1176 entry
->text
= _("Keep Icon");
1178 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1180 entry
->text
= _("Move Icon To");
1181 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1182 if (scr
->clip_submenu
)
1183 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1185 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
,
1188 entry
->text
= _("Remove Icon");
1190 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1193 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1195 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1197 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1199 entry
->text
= _("Hide");
1201 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1203 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1205 if (type
== WM_CLIP
)
1206 scr
->clip_menu
= menu
;
1213 wDockCreate(WScreen
*scr
, int type
)
1221 dock
= wmalloc(sizeof(WDock
));
1222 memset(dock
, 0, sizeof(WDock
));
1224 if (type
== WM_CLIP
)
1225 icon_count
= CLIP_MAX_ICONS
;
1227 icon_count
= scr
->scr_height
/wPreferences
.icon_size
;
1229 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*)*icon_count
);
1230 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*)*icon_count
);
1232 dock
->max_icons
= icon_count
;
1234 btn
= mainIconCreate(scr
, type
);
1238 dock
->x_pos
= btn
->x_pos
;
1239 dock
->y_pos
= btn
->y_pos
;
1240 dock
->screen_ptr
= scr
;
1242 dock
->icon_count
= 1;
1243 dock
->on_right_side
= 1;
1244 dock
->collapsed
= 0;
1245 dock
->auto_collapse
= 0;
1246 dock
->auto_collapse_magic
= NULL
;
1247 dock
->auto_raise_lower
= 0;
1248 dock
->auto_lower_magic
= NULL
;
1249 dock
->auto_raise_magic
= NULL
;
1250 dock
->attract_icons
= 0;
1251 dock
->keep_attracted
= 0;
1253 dock
->icon_array
[0] = btn
;
1254 wRaiseFrame(btn
->icon
->core
);
1255 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1257 /* create dock menu */
1258 dock
->menu
= dockMenuCreate(scr
, type
);
1265 wDockDestroy(WDock
*dock
)
1270 for (i
=(dock
->type
== WM_CLIP
) ? 1 : 0; i
<dock
->max_icons
; i
++) {
1271 aicon
= dock
->icon_array
[i
];
1273 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1274 wDockDetach(dock
, aicon
);
1276 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
1277 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
1278 aicon
->x_pos
, aicon
->y_pos
);
1279 if (!dock
->mapped
|| dock
->collapsed
)
1280 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1284 if (wPreferences
.auto_arrange_icons
)
1285 wArrangeIcons(dock
->screen_ptr
, True
);
1286 free(dock
->icon_array
);
1287 if (dock
->menu
&& dock
->type
!=WM_CLIP
)
1288 wMenuDestroy(dock
->menu
, True
);
1294 wClipIconPaint(WAppIcon
*aicon
)
1296 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1297 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1299 Window win
= aicon
->icon
->core
->window
;
1300 int length
, nlength
;
1301 char *ws_name
, ws_number
[10];
1304 wIconPaint(aicon
->icon
);
1306 length
= strlen(workspace
->name
);
1307 ws_name
= malloc(length
+ 1);
1308 sprintf(ws_name
, "%s", workspace
->name
);
1309 sprintf(ws_number
, "%i", scr
->current_workspace
+ 1);
1310 nlength
= strlen(ws_number
);
1312 gc
= scr
->clip_title_gc
;
1314 if (!workspace
->clip
->collapsed
)
1315 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_NORMAL
]);
1317 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_COLLAPSED
]);
1319 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1321 tx
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
1323 WMDrawString(scr
->wmscreen
, win
, gc
, scr
->clip_title_font
, tx
,
1324 ty
, ws_name
, length
);
1326 tx
= (ICON_SIZE
/2 - WMWidthOfString(scr
->clip_title_font
, ws_number
,
1329 WMDrawString(scr
->wmscreen
, win
, gc
, scr
->clip_title_font
, tx
,
1330 2, ws_number
, nlength
);
1334 if (aicon
->launching
) {
1335 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1336 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1338 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
,
1339 aicon
->dock
->rclip_button_pushed
);
1344 clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1346 wClipIconPaint(desc
->parent
);
1351 dockIconPaint(WAppIcon
*btn
)
1353 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1354 wClipIconPaint(btn
);
1361 make_icon_state(WAppIcon
*btn
)
1363 proplist_t node
= NULL
;
1364 proplist_t command
, autolaunch
, name
, forced
, host
, position
, buggy
;
1365 proplist_t omnipresent
;
1371 command
= PLMakeString("-");
1373 command
= PLMakeString(btn
->command
);
1375 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1377 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1379 name
= PLMakeString(tmp
);
1383 forced
= btn
->forced_dock
? dYes
: dNo
;
1385 buggy
= btn
->buggy_app
? dYes
: dNo
;
1387 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1388 sprintf(buffer
, "%i,%i", btn
->x_pos
, btn
->y_pos
);
1390 sprintf(buffer
, "%hi,%hi", btn
->xindex
, btn
->yindex
);
1391 position
= PLMakeString(buffer
);
1393 node
= PLMakeDictionaryFromEntries(dCommand
, command
,
1395 dAutoLaunch
, autolaunch
,
1397 dBuggyApplication
, buggy
,
1398 dPosition
, position
,
1402 PLRelease(position
);
1404 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1405 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&&
1406 (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1407 PLInsertDictionaryEntry(node
, dOmnipresent
, omnipresent
);
1410 if (btn
->dnd_command
) {
1411 command
= PLMakeString(btn
->dnd_command
);
1412 PLInsertDictionaryEntry(node
, dDropCommand
, command
);
1415 #endif /* OFFIX_DND */
1417 if (btn
->client_machine
&& btn
->remote_start
) {
1418 host
= PLMakeString(btn
->client_machine
);
1419 PLInsertDictionaryEntry(node
, dHost
, host
);
1429 dockSaveState(WDock
*dock
)
1432 proplist_t icon_info
;
1433 proplist_t list
=NULL
, dock_state
=NULL
;
1437 list
= PLMakeArrayFromElements(NULL
);
1439 for (i
=(dock
->type
==WM_DOCK
? 0 : 1); i
<dock
->max_icons
; i
++) {
1440 WAppIcon
*btn
= dock
->icon_array
[i
];
1442 if (!btn
|| (btn
->attracted
&& !dock
->keep_attracted
))
1445 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1446 list
= PLAppendArrayElement(list
, icon_info
);
1447 PLRelease(icon_info
);
1451 dock_state
= PLMakeDictionaryFromEntries(dApplications
, list
, NULL
);
1455 if (dock
->type
== WM_DOCK
) {
1456 sprintf(buffer
, "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0),
1458 value
= PLMakeString(buffer
);
1459 PLInsertDictionaryEntry(dock_state
, dPosition
, value
);
1463 value
= (dock
->lowered
? dYes
: dNo
);
1464 PLInsertDictionaryEntry(dock_state
, dLowered
, value
);
1466 if (dock
->type
== WM_CLIP
) {
1467 value
= (dock
->collapsed
? dYes
: dNo
);
1468 PLInsertDictionaryEntry(dock_state
, dCollapsed
, value
);
1470 value
= (dock
->auto_collapse
? dYes
: dNo
);
1471 PLInsertDictionaryEntry(dock_state
, dAutoCollapse
, value
);
1473 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1474 PLInsertDictionaryEntry(dock_state
, dAutoRaiseLower
, value
);
1476 value
= (dock
->attract_icons
? dYes
: dNo
);
1477 PLInsertDictionaryEntry(dock_state
, dAutoAttractIcons
, value
);
1479 value
= (dock
->keep_attracted
? dYes
: dNo
);
1480 PLInsertDictionaryEntry(dock_state
, dKeepAttracted
, value
);
1488 wDockSaveState(WScreen
*scr
)
1490 proplist_t dock_state
;
1492 dock_state
= dockSaveState(scr
->dock
);
1494 PLInsertDictionaryEntry(scr
->session_state
, dDock
, dock_state
);
1496 PLRelease(dock_state
);
1501 wClipSaveState(WScreen
*scr
)
1503 proplist_t clip_state
;
1505 clip_state
= make_icon_state(scr
->clip_icon
);
1507 PLInsertDictionaryEntry(scr
->session_state
, dClip
, clip_state
);
1509 PLRelease(clip_state
);
1514 wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1516 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1521 restore_icon_state(WScreen
*scr
, proplist_t info
, int type
, int index
)
1524 char *wclass
, *winstance
;
1525 proplist_t cmd
, value
;
1529 cmd
= PLGetDictionaryEntry(info
, dCommand
);
1530 if (!cmd
|| !PLIsString(cmd
)) {
1534 /* parse window name */
1535 value
= PLGetDictionaryEntry(info
, dName
);
1539 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1541 if (!winstance
&& !wclass
) {
1548 command
= wstrdup(PLGetString(cmd
));
1552 if (!command
|| strcmp(command
, "-")==0) {
1563 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
,
1570 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1571 if (type
== WM_CLIP
) {
1572 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1573 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1575 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1576 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1580 cmd
= PLGetDictionaryEntry(info
, dDropCommand
);
1582 aicon
->dnd_command
= wstrdup(PLGetString(cmd
));
1585 /* check auto launch */
1586 value
= PLGetDictionaryEntry(info
, dAutoLaunch
);
1588 aicon
->auto_launch
= 0;
1590 if (PLIsString(value
)) {
1591 if (strcasecmp(PLGetString(value
), "YES")==0)
1592 aicon
->auto_launch
= 1;
1594 wwarning(_("bad value in docked icon state info %s"),
1595 PLGetString(dAutoLaunch
));
1599 /* check if it wasn't normally docked */
1600 value
= PLGetDictionaryEntry(info
, dForced
);
1602 aicon
->forced_dock
= 0;
1604 if (PLIsString(value
)) {
1605 if (strcasecmp(PLGetString(value
), "YES")==0)
1606 aicon
->forced_dock
= 1;
1608 wwarning(_("bad value in docked icon state info %s"),
1609 PLGetString(dForced
));
1613 /* check if we can rely on the stuff in the app */
1614 value
= PLGetDictionaryEntry(info
, dBuggyApplication
);
1616 aicon
->buggy_app
= 0;
1618 if (PLIsString(value
)) {
1619 if (strcasecmp(PLGetString(value
), "YES")==0)
1620 aicon
->buggy_app
= 1;
1622 wwarning(_("bad value in docked icon state info %s"),
1623 PLGetString(dBuggyApplication
));
1627 /* get position in the dock */
1628 value
= PLGetDictionaryEntry(info
, dPosition
);
1629 if (value
&& PLIsString(value
)) {
1630 if (sscanf(PLGetString(value
), "%hi,%hi", &aicon
->xindex
,
1632 wwarning(_("bad value in docked icon state info %s"),
1633 PLGetString(dPosition
));
1635 /* check position sanity */
1636 /* incomplete section! */
1637 if (type
== WM_DOCK
) {
1639 if (aicon
->yindex
< 0)
1640 wwarning(_("bad value in docked icon position %i,%i"),
1641 aicon
->xindex
, aicon
->yindex
);
1644 aicon
->yindex
= index
;
1648 /* check if icon is omnipresent */
1649 value
= PLGetDictionaryEntry(info
, dOmnipresent
);
1651 aicon
->omnipresent
= 0;
1653 if (PLIsString(value
)) {
1654 if (strcasecmp(PLGetString(value
), "YES")==0)
1655 aicon
->omnipresent
= 1;
1657 wwarning(_("bad value in docked icon state info %s"),
1658 PLGetString(dOmnipresent
));
1669 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1673 wClipRestoreState(WScreen
*scr
, proplist_t clip_state
)
1679 icon
= mainIconCreate(scr
, WM_CLIP
);
1684 PLRetain(clip_state
);
1686 /* restore position */
1688 value
= PLGetDictionaryEntry(clip_state
, dPosition
);
1691 if (!PLIsString(value
))
1692 COMPLAIN("Position");
1694 if (sscanf(PLGetString(value
), "%i,%i", &icon
->x_pos
,
1696 COMPLAIN("Position");
1698 /* check position sanity */
1699 if (icon
->y_pos
< 0)
1701 else if (icon
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1702 icon
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1704 if (icon
->x_pos
< 0)
1706 else if (icon
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1707 icon
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1712 value
= PLGetDictionaryEntry(clip_state
, dDropCommand
);
1713 if (value
&& PLIsString(value
))
1714 icon
->dnd_command
= wstrdup(PLGetString(value
));
1717 PLRelease(clip_state
);
1724 wDockRestoreState(WScreen
*scr
, proplist_t dock_state
, int type
)
1729 WAppIcon
*aicon
, *old_top
;
1733 dock
= wDockCreate(scr
, type
);
1739 PLRetain(dock_state
);
1742 /* restore position */
1744 value
= PLGetDictionaryEntry(dock_state
, dPosition
);
1747 if (!PLIsString(value
))
1748 COMPLAIN("Position");
1750 if (sscanf(PLGetString(value
), "%i,%i", &dock
->x_pos
,
1752 COMPLAIN("Position");
1754 /* check position sanity */
1755 if (dock
->y_pos
< 0)
1757 else if (dock
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1758 dock
->y_pos
= scr
->scr_height
- ICON_SIZE
;
1760 /* This is no more needed. ??? */
1761 if (type
== WM_CLIP
) {
1762 if (dock
->x_pos
< 0)
1764 else if (dock
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1765 dock
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1767 if (dock
->x_pos
>= 0) {
1768 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1769 dock
->on_right_side
= 0;
1771 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1772 dock
->on_right_side
= 1;
1778 /* restore lowered/raised state */
1782 value
= PLGetDictionaryEntry(dock_state
, dLowered
);
1785 if (!PLIsString(value
))
1786 COMPLAIN("Lowered");
1788 if (strcasecmp(PLGetString(value
), "YES")==0)
1794 /* restore collapsed state */
1796 dock
->collapsed
= 0;
1798 value
= PLGetDictionaryEntry(dock_state
, dCollapsed
);
1801 if (!PLIsString(value
))
1802 COMPLAIN("Collapsed");
1804 if (strcasecmp(PLGetString(value
), "YES")==0)
1805 dock
->collapsed
= 1;
1810 /* restore auto-collapsed state */
1812 value
= PLGetDictionaryEntry(dock_state
, dAutoCollapse
);
1815 if (!PLIsString(value
))
1816 COMPLAIN("AutoCollapse");
1818 if (strcasecmp(PLGetString(value
), "YES")==0) {
1819 dock
->auto_collapse
= 1;
1820 dock
->collapsed
= 1;
1826 /* restore auto-raise/lower state */
1828 value
= PLGetDictionaryEntry(dock_state
, dAutoRaiseLower
);
1831 if (!PLIsString(value
))
1832 COMPLAIN("AutoRaiseLower");
1834 if (strcasecmp(PLGetString(value
), "YES")==0) {
1835 dock
->auto_raise_lower
= 1;
1840 /* restore attract icons state */
1842 dock
->attract_icons
= 0;
1844 value
= PLGetDictionaryEntry(dock_state
, dAutoAttractIcons
);
1847 if (!PLIsString(value
))
1848 COMPLAIN("AutoAttractIcons");
1850 if (strcasecmp(PLGetString(value
), "YES")==0)
1851 dock
->attract_icons
= 1;
1856 /* restore keep attracted icons state */
1858 dock
->keep_attracted
= 0;
1860 value
= PLGetDictionaryEntry(dock_state
, dKeepAttracted
);
1863 if (!PLIsString(value
))
1864 COMPLAIN("KeepAttracted");
1866 if (strcasecmp(PLGetString(value
), "YES")==0)
1867 dock
->keep_attracted
= 1;
1872 /* application list */
1874 apps
= PLGetDictionaryEntry(dock_state
, dApplications
);
1880 count
= PLGetNumberOfElements(apps
);
1885 old_top
= dock
->icon_array
[0];
1887 /* dock->icon_count is set to 1 when dock is created.
1888 * Since Clip is already restored, we want to keep it so for clip,
1889 * but for dock we may change the default top tile, so we set it to 0.
1891 if (type
== WM_DOCK
)
1892 dock
->icon_count
= 0;
1894 for (i
=0; i
<count
; i
++) {
1895 if (dock
->icon_count
>= dock
->max_icons
) {
1896 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1900 value
= PLGetArrayElement(apps
, i
);
1901 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1903 dock
->icon_array
[dock
->icon_count
] = aicon
;
1907 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
*ICON_SIZE
);
1908 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
*ICON_SIZE
);
1911 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1913 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1915 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
,
1918 if (!dock
->collapsed
)
1919 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1920 wRaiseFrame(aicon
->icon
->core
);
1923 } else if (dock
->icon_count
==0 && type
==WM_DOCK
)
1927 /* if the first icon is not defined, use the default */
1928 if (dock
->icon_array
[0]==NULL
) {
1929 /* update default icon */
1930 old_top
->x_pos
= dock
->x_pos
;
1931 old_top
->y_pos
= dock
->y_pos
;
1933 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1935 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1936 dock
->icon_array
[0] = old_top
;
1937 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1938 /* we don't need to increment dock->icon_count here because it was
1939 * incremented in the loop above.
1941 } else if (old_top
!=dock
->icon_array
[0]) {
1942 if (old_top
== scr
->clip_icon
)
1943 scr
->clip_icon
= dock
->icon_array
[0];
1944 wAppIconDestroy(old_top
);
1949 PLRelease(dock_state
);
1957 wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1959 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1961 btn
->drop_launch
= 0;
1963 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1966 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1978 wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1984 for (i
= 0; i
< dock
->max_icons
; i
++) {
1985 btn
= dock
->icon_array
[i
];
1986 if (!btn
|| !btn
->auto_launch
)
1989 state
= wmalloc(sizeof(WSavedState
));
1990 memset(state
, 0, sizeof(WSavedState
));
1991 state
->workspace
= workspace
;
1992 /* TODO: this is klugy and is very difficult to understand
1993 * what's going on. Try to clean up */
1994 wDockLaunchWithState(dock
, btn
, state
);
1998 #ifdef REDUCE_APPICONS
2000 wDockSimulateLaunch(WDock
*dock
, WAppIcon
*btn
)
2002 if ((btn
== NULL
) || (dock
== NULL
))
2005 if (!btn
->running
) {
2006 if ((btn
->icon
->owner
== NULL
) && (btn
->applist
))
2007 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
2008 if (!btn
->forced_dock
)
2018 findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
2024 if ((dock
= scr
->dock
)!=NULL
) {
2025 for (i
=0; i
<dock
->max_icons
; i
++) {
2026 if (dock
->icon_array
[i
]
2027 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
2033 if (*icon_pos
<0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
)!=NULL
) {
2034 for (i
=0; i
<dock
->max_icons
; i
++) {
2035 if (dock
->icon_array
[i
]
2036 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
2049 wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
2055 dock
= findDock(scr
, event
, &icon_pos
);
2060 * Return True if the drop was on an application icon window.
2061 * In this case, let the ClientMessage handler redirect the
2062 * message to the app.
2064 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!=None
)
2067 if (dock
->icon_array
[icon_pos
]->dnd_command
!=NULL
) {
2068 scr
->flags
.dnd_data_convertion_status
= 0;
2070 btn
= dock
->icon_array
[icon_pos
];
2072 if (!btn
->forced_dock
) {
2073 btn
->relaunching
= btn
->running
;
2076 if (btn
->wm_instance
|| btn
->wm_class
) {
2077 WWindowAttributes attr
;
2078 memset(&attr
, 0, sizeof(WWindowAttributes
));
2079 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
2081 btn
->wm_class
, &attr
, NULL
, True
);
2083 if (!attr
.no_appicon
)
2089 btn
->drop_launch
= 1;
2090 scr
->last_dock
= dock
;
2091 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
2096 if (!btn
->relaunching
) {
2103 #endif /* OFFIX_DND */
2108 wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2115 wwin
= icon
->icon
->owner
;
2116 if (icon
->command
==NULL
) {
2118 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2120 icon
->command
= FlattenStringList(argv
, argc
);
2121 XFreeStringList(argv
);
2125 /* icon->forced_dock = 1;*/
2126 if (!icon
->attracted
|| dock
->type
!=WM_CLIP
|| dock
->keep_attracted
) {
2128 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2129 _("Type the command used to launch the application"),
2131 if (command
&& (command
[0]==0 ||
2132 (command
[0]=='-' && command
[1]==0))) {
2136 icon
->command
= command
;
2142 /* If the target is the dock, reject the icon. If
2143 * the target is the clip, make it an attracted icon
2145 if (dock
->type
==WM_CLIP
) {
2146 icon
->attracted
= 1;
2147 if (!icon
->icon
->shadowed
) {
2148 icon
->icon
->shadowed
= 1;
2149 icon
->icon
->force_paint
= 1;
2161 for (index
=1; index
<dock
->max_icons
; index
++)
2162 if (dock
->icon_array
[index
] == NULL
)
2164 /* if (index == dock->max_icons)
2167 assert(index
< dock
->max_icons
);
2169 dock
->icon_array
[index
] = icon
;
2173 icon
->omnipresent
= 0;
2175 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2176 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2181 icon
->launching
= 0;
2184 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2185 if (dock
->type
== WM_CLIP
) {
2186 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2187 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2189 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2190 icon
->icon
->core
->descriptor
.parent
= icon
;
2192 MoveInStackListUnder(dock
->icon_array
[index
-1]->icon
->core
,
2194 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2195 wAppIconPaint(icon
);
2197 if (wPreferences
.auto_arrange_icons
)
2198 wArrangeIcons(dock
->screen_ptr
, True
);
2201 if (icon
->command
&& !icon
->dnd_command
) {
2202 icon
->dnd_command
= wmalloc(strlen(icon
->command
)+8);
2203 sprintf(icon
->dnd_command
, "%s %%d", icon
->command
);
2212 reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2216 for(index
=1; index
<dock
->max_icons
; index
++) {
2217 if(dock
->icon_array
[index
] == icon
)
2220 assert(index
< dock
->max_icons
);
2225 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2226 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2231 moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2239 return True
; /* No move needed, we're already there */
2244 wwin
= icon
->icon
->owner
;
2247 * For the moment we can't do this if we move icons in Clip from one
2248 * workspace to other, because if we move two or more icons without
2249 * command, the dialog box will not be able to tell us to which of the
2250 * moved icons it applies. -Dan
2252 if ((dest
->type
==WM_DOCK
/*|| dest->keep_attracted*/) && icon
->command
==NULL
) {
2253 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2255 icon
->command
= FlattenStringList(argv
, argc
);
2256 XFreeStringList(argv
);
2261 /* icon->forced_dock = 1;*/
2262 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2263 _("Type the command used to launch the application"),
2265 if (command
&& (command
[0]==0 ||
2266 (command
[0]=='-' && command
[1]==0))) {
2270 icon
->command
= command
;
2281 if (dest
->type
== WM_DOCK
)
2282 wClipMakeIconOmnipresent(icon
, False
);
2284 for(index
=1; index
<src
->max_icons
; index
++) {
2285 if(src
->icon_array
[index
] == icon
)
2288 assert(index
< src
->max_icons
);
2290 src
->icon_array
[index
] = NULL
;
2293 for(index
=1; index
<dest
->max_icons
; index
++) {
2294 if(dest
->icon_array
[index
] == NULL
)
2297 /* if (index == dest->max_icons)
2300 assert(index
< dest
->max_icons
);
2302 dest
->icon_array
[index
] = icon
;
2305 /* deselect the icon */
2306 if (icon
->icon
->selected
)
2307 wIconSelect(icon
->icon
);
2309 if (dest
->type
== WM_DOCK
) {
2310 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2311 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2313 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2314 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2317 /* set it to be kept when moving to dock, or to a clip that keep the
2319 * Unless the icon does not have a command set
2321 if (icon
->command
&& (dest
->type
==WM_DOCK
|| dest
->keep_attracted
)) {
2322 icon
->attracted
= 0;
2323 if (icon
->icon
->shadowed
) {
2324 icon
->icon
->shadowed
= 0;
2325 icon
->icon
->force_paint
= 1;
2329 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2335 icon
->x_pos
= dest
->x_pos
+ x
*ICON_SIZE
;
2336 icon
->y_pos
= dest
->y_pos
+ y
*ICON_SIZE
;
2340 MoveInStackListUnder(dest
->icon_array
[index
-1]->icon
->core
,
2342 wAppIconPaint(icon
);
2349 wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2353 /* make the settings panel be closed */
2355 DestroyDockAppSettingsPanel(icon
->panel
);
2360 icon
->attracted
= 0;
2361 if (icon
->icon
->shadowed
) {
2362 icon
->icon
->shadowed
= 0;
2363 icon
->icon
->force_paint
= 1;
2366 /* This must be called before dock->icon_array[index] is set to NULL.
2367 * Don't move it. -Dan
2369 wClipMakeIconOmnipresent(icon
, False
);
2371 /* deselect the icon */
2372 if (icon
->icon
->selected
)
2373 wIconSelect(icon
->icon
);
2375 if (icon
->command
) {
2376 free(icon
->command
);
2377 icon
->command
= NULL
;
2380 if (icon
->dnd_command
) {
2381 free(icon
->dnd_command
);
2382 icon
->dnd_command
= NULL
;
2386 for (index
=1; index
<dock
->max_icons
; index
++)
2387 if (dock
->icon_array
[index
] == icon
)
2389 assert(index
< dock
->max_icons
);
2390 dock
->icon_array
[index
] = NULL
;
2396 /* if the dock is not attached to an application or
2397 * the the application did not set the approriate hints yet,
2398 * destroy the icon */
2399 #ifdef REDUCE_APPICONS
2400 if ((icon
->num_apps
== 0) && (!icon
->running
|| !wApplicationOf(icon
->main_window
)) )
2402 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2404 wAppIconDestroy(icon
);
2406 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2407 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2408 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2409 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2410 icon
->icon
->core
->descriptor
.parent
= icon
;
2412 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2414 wAppIconPaint(icon
);
2415 if (wPreferences
.auto_arrange_icons
) {
2416 wArrangeIcons(dock
->screen_ptr
, True
);
2419 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2425 * returns the closest Dock slot index for the passed
2428 * Returns False if icon can't be docked.
2430 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2434 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2435 int *ret_x
, int *ret_y
, int redocking
)
2437 WScreen
*scr
= dock
->screen_ptr
;
2440 int i
, offset
= ICON_SIZE
/2;
2441 WAppIcon
*aicon
= NULL
;
2442 WAppIcon
*nicon
= NULL
;
2443 int max_y_icons
, max_x_icons
;
2445 max_x_icons
= scr
->scr_width
/ICON_SIZE
;
2446 max_y_icons
= scr
->scr_height
/ICON_SIZE
-1;
2448 if (wPreferences
.flags
.noupdates
)
2454 /* if the dock is full */
2456 (dock
->icon_count
>= dock
->max_icons
)) {
2460 /* exact position */
2462 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2464 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2467 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2469 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2471 /* check if the icon is outside the screen boundaries */
2472 if (dx
+ ex_x
*ICON_SIZE
< -ICON_SIZE
+2 ||
2473 dx
+ ex_x
*ICON_SIZE
>= scr
->scr_width
-1 ||
2474 dy
+ ex_y
*ICON_SIZE
< -ICON_SIZE
+2 ||
2475 dy
+ ex_y
*ICON_SIZE
>= scr
->scr_height
-1)
2478 if (dock
->type
== WM_DOCK
) {
2479 if (icon
->dock
!= dock
&& ex_x
!= 0)
2483 for (i
=0; i
<dock
->max_icons
; i
++) {
2484 nicon
= dock
->icon_array
[i
];
2485 if (nicon
&& nicon
->yindex
== ex_y
) {
2492 int sig
, done
, closest
;
2494 /* Possible cases when redocking:
2496 * icon dragged out of range of any slot -> false
2497 * icon dragged to range of free slot
2498 * icon dragged to range of same slot
2499 * icon dragged to range of different icon
2501 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2504 if (ex_y
>=0 && ex_y
<=max_y_icons
&& (aicon
==icon
|| !aicon
)) {
2510 /* start looking at the upper slot or lower? */
2511 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2518 /* look for closest free slot */
2519 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2523 closest
= sig
*(i
/2) + ex_y
;
2524 /* check if this slot is used */
2526 for (j
= 0; j
<dock
->max_icons
; j
++) {
2527 if (dock
->icon_array
[j
]
2528 && dock
->icon_array
[j
]->yindex
==closest
) {
2529 /* slot is used by someone else */
2530 if (dock
->icon_array
[j
]!=icon
)
2538 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2539 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2541 (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+1))) {
2546 } else { /* !redocking */
2548 /* if slot is free and the icon is close enough, return it */
2549 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2559 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2560 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+1;
2563 for (k
=start
; k
<stop
; k
++) {
2564 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2567 for (i
=0; i
<tmp
->max_icons
; i
++) {
2568 nicon
= tmp
->icon_array
[i
];
2569 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2577 for (k
=start
; k
<stop
; k
++) {
2578 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2581 for (i
=0; i
<tmp
->max_icons
; i
++) {
2582 nicon
= tmp
->icon_array
[i
];
2583 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2584 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2585 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2594 if (neighbours
&& (aicon
==NULL
|| (redocking
&& aicon
== icon
))) {
2603 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2604 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2606 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2607 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2608 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2612 * returns true if it can find a free slot in the dock,
2613 * in which case it changes x_pos and y_pos accordingly.
2614 * Else returns false.
2617 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2619 WScreen
*scr
= dock
->screen_ptr
;
2621 WAppIconChain
*chain
;
2622 unsigned char *slot_map
;
2626 int i
, done
= False
;
2628 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2631 if (dock
->type
== WM_CLIP
&&
2632 dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2633 extra_count
= scr
->global_icon_count
;
2635 /* if the dock is full */
2636 if (dock
->icon_count
+extra_count
>= dock
->max_icons
) {
2640 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2641 if (scr
->dock
->on_right_side
)
2642 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2644 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2647 if (ex
< dock
->x_pos
)
2649 if (sx
> dock
->x_pos
+ICON_SIZE
)
2650 sx
= dock
->x_pos
+ICON_SIZE
;
2657 /* check if clip is in a corner */
2658 if (dock
->type
==WM_CLIP
) {
2659 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2661 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2663 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2665 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2672 /* If the clip is in the corner, use only slots that are in the border
2674 if (corner
!=C_NONE
) {
2678 hcount
= MIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2679 vcount
= MIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2680 hmap
= wmalloc(hcount
+1);
2681 memset(hmap
, 0, hcount
+1);
2682 vmap
= wmalloc(vcount
+1);
2683 memset(vmap
, 0, vcount
+1);
2685 /* mark used positions */
2688 for (i
=0; i
<dock
->max_icons
; i
++) {
2689 btn
= dock
->icon_array
[i
];
2693 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2694 vmap
[btn
->yindex
] = 1;
2695 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2696 hmap
[btn
->xindex
] = 1;
2698 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2700 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2701 vmap
[btn
->yindex
] = 1;
2702 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2703 hmap
[btn
->xindex
] = 1;
2707 for (i
=0; i
<dock
->max_icons
; i
++) {
2708 btn
= dock
->icon_array
[i
];
2712 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2713 vmap
[btn
->yindex
] = 1;
2714 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2715 hmap
[-btn
->xindex
] = 1;
2717 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2719 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2720 vmap
[btn
->yindex
] = 1;
2721 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2722 hmap
[-btn
->xindex
] = 1;
2726 for (i
=0; i
<dock
->max_icons
; i
++) {
2727 btn
= dock
->icon_array
[i
];
2731 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2732 vmap
[-btn
->yindex
] = 1;
2733 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2734 hmap
[btn
->xindex
] = 1;
2736 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2738 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2739 vmap
[-btn
->yindex
] = 1;
2740 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2741 hmap
[btn
->xindex
] = 1;
2746 for (i
=0; i
<dock
->max_icons
; i
++) {
2747 btn
= dock
->icon_array
[i
];
2751 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2752 vmap
[-btn
->yindex
] = 1;
2753 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2754 hmap
[-btn
->xindex
] = 1;
2756 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2758 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2759 vmap
[-btn
->yindex
] = 1;
2760 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2761 hmap
[-btn
->xindex
] = 1;
2766 /* search a vacant slot */
2767 for (i
=1; i
<MAX(vcount
, hcount
); i
++) {
2768 if (i
< vcount
&& vmap
[i
]==0) {
2774 } else if (i
< hcount
&& hmap
[i
]==0) {
2784 /* If found a slot, translate and return */
2786 if (corner
==C_NW
|| corner
==C_NE
) {
2791 if (corner
==C_NE
|| corner
==C_SE
) {
2798 /* else, try to find a slot somewhere else */
2801 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2802 * placed outside of screen */
2803 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2805 /* In the worst case (the clip is in the corner of the screen),
2806 * the amount of icons that fit in the clip is smaller.
2807 * Double the map to get a safe value.
2813 slot_map
= wmalloc(mwidth
*mwidth
);
2814 memset(slot_map
, 0, mwidth
*mwidth
);
2816 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2818 /* mark used slots in the map. If the slot falls outside the map
2819 * (for example, when all icons are placed in line), ignore them. */
2820 for (i
=0; i
<dock
->max_icons
; i
++) {
2821 btn
= dock
->icon_array
[i
];
2823 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2825 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2826 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2828 /* Find closest slot from the center that is free by scanning the
2829 * map from the center to outward in circular passes.
2830 * This will not result in a neat layout, but will be optimal
2831 * in the sense that there will not be holes left.
2834 for (i
= 1; i
<= r
&& !done
; i
++) {
2837 /* top and bottom parts of the ring */
2838 for (x
= -i
; x
<= i
&& !done
; x
++) {
2839 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2841 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2842 if (slot_map
[XY2OFS(x
,y
)]==0
2843 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2850 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2851 if (slot_map
[XY2OFS(x
,y
)]==0
2852 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2859 /* left and right parts of the ring */
2860 for (y
= -i
+1; y
<= i
-1; y
++) {
2861 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2863 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2864 if (slot_map
[XY2OFS(x
,y
)]==0
2865 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2872 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2873 if (slot_map
[XY2OFS(x
,y
)]==0
2874 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2889 moveDock(WDock
*dock
, int new_x
, int new_y
)
2894 dock
->x_pos
= new_x
;
2895 dock
->y_pos
= new_y
;
2896 for (i
=0; i
<dock
->max_icons
; i
++) {
2897 btn
= dock
->icon_array
[i
];
2899 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2900 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2901 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2908 swapDock(WDock
*dock
)
2910 WScreen
*scr
= dock
->screen_ptr
;
2915 if (dock
->on_right_side
) {
2916 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2918 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2921 for (i
=0; i
<dock
->max_icons
; i
++) {
2922 btn
= dock
->icon_array
[i
];
2925 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2929 wScreenUpdateUsableArea(scr
);
2934 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2936 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2942 cmdline
= ExpandOptions(scr
, command
);
2944 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2952 ParseCommand(cmdline
, &argv
, &argc
);
2962 if ((pid
=fork())==0) {
2966 SetupEnvironment(scr
);
2972 args
= malloc(sizeof(char*)*(argc
+1));
2975 for (i
=0; i
<argc
; i
++) {
2979 execvp(argv
[0], args
);
2988 state
= wmalloc(sizeof(WSavedState
));
2989 memset(state
, 0, sizeof(WSavedState
));
2991 state
->miniaturized
= -1;
2993 if (btn
->dock
==scr
->dock
|| btn
->omnipresent
)
2994 state
->workspace
= -1;
2996 state
->workspace
= scr
->current_workspace
;
2998 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
3000 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
3011 wDockHideIcons(WDock
*dock
)
3018 for (i
=1; i
<dock
->max_icons
; i
++) {
3019 if (dock
->icon_array
[i
])
3020 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3024 dockIconPaint(dock
->icon_array
[0]);
3029 wDockShowIcons(WDock
*dock
)
3037 btn
= dock
->icon_array
[0];
3038 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
3040 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
3041 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
3043 for (i
=1; i
<dock
->max_icons
; i
++) {
3044 if (dock
->icon_array
[i
]) {
3045 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
3051 if (!dock
->collapsed
) {
3052 for (i
=1; i
<dock
->max_icons
; i
++) {
3053 if (dock
->icon_array
[i
]) {
3054 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3065 wDockLower(WDock
*dock
)
3069 for (i
=0; i
<dock
->max_icons
; i
++) {
3070 if (dock
->icon_array
[i
])
3071 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
3077 wDockRaise(WDock
*dock
)
3081 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
3082 if (dock
->icon_array
[i
])
3083 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
3089 wDockRaiseLower(WDock
*dock
)
3091 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
3092 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
3093 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
3101 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
3103 icon
->launching
= 0;
3104 icon
->relaunching
= 0;
3105 dockIconPaint(icon
);
3110 wDockFindIconFor(WDock
*dock
, Window window
)
3115 for (i
=0; i
<dock
->max_icons
; i
++) {
3116 icon
= dock
->icon_array
[i
];
3117 if (icon
&& icon
->main_window
== window
)
3125 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
3128 #ifdef REDUCE_APPICONS
3129 WAppIconAppList
*tapplist
;
3131 char *wm_class
, *wm_instance
;
3133 Bool firstPass
= True
;
3135 char *command
= NULL
;
3141 if (XGetCommand(dpy
, window
, &argv
, &argc
)) {
3142 if (argc
> 0 && argv
!= NULL
)
3143 command
= FlattenStringList(argv
,argc
);
3145 XFreeStringList(argv
);
3150 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
3151 (!wm_class
&& !wm_instance
))
3155 for (i
=0; i
<dock
->max_icons
; i
++) {
3156 icon
= dock
->icon_array
[i
];
3160 /* app is already attached to icon */
3161 if (icon
->main_window
== window
) {
3166 if ((icon
->wm_instance
|| icon
->wm_class
)
3168 || (dock
->screen_ptr
->flags
.startup
&& !icon
->running
))) {
3170 if (icon
->wm_instance
&& wm_instance
&&
3171 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
3174 if (icon
->wm_class
&& wm_class
&&
3175 strcmp(icon
->wm_class
, wm_class
)!=0) {
3178 if (firstPass
&& command
&& strcmp(icon
->command
, command
)!=0) {
3182 if (!icon
->relaunching
) {
3185 /* Possibly an application that was docked with dockit,
3186 * but the user did not update WMState to indicate that
3187 * it was docked by force */
3188 wapp
= wApplicationOf(window
);
3190 icon
->forced_dock
= 1;
3193 if (!icon
->forced_dock
)
3194 icon
->main_window
= window
;
3196 #ifdef REDUCE_APPICONS
3197 tapplist
= wmalloc(sizeof(WAppIconAppList
));
3198 memset(tapplist
, 0, sizeof(WAppIconAppList
));
3199 tapplist
->next
= icon
->applist
;
3201 icon
->applist
->prev
= tapplist
;
3202 icon
->applist
= tapplist
;
3203 tapplist
->wapp
= wApplicationOf(window
);
3208 wDockFinishLaunch(dock
, icon
);
3213 if (firstPass
&& !found
) {
3230 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3232 if (!wPreferences
.flags
.noclip
) {
3233 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3234 if (scr
->current_workspace
!= workspace
) {
3235 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3236 WAppIconChain
*chain
= scr
->global_icons
;
3239 moveIconBetweenDocks(chain
->aicon
->dock
,
3240 scr
->workspaces
[workspace
]->clip
,
3241 chain
->aicon
, chain
->aicon
->xindex
,
3242 chain
->aicon
->yindex
);
3243 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
3244 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3245 chain
= chain
->next
;
3248 wDockHideIcons(old_clip
);
3249 if (old_clip
->auto_raise_lower
) {
3250 if (old_clip
->auto_raise_magic
) {
3251 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3252 old_clip
->auto_raise_magic
= NULL
;
3254 wDockLower(old_clip
);
3256 if (old_clip
->auto_collapse
) {
3257 if (old_clip
->auto_expand_magic
) {
3258 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3259 old_clip
->auto_expand_magic
= NULL
;
3261 old_clip
->collapsed
= 1;
3263 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3265 if (scr
->flags
.clip_balloon_mapped
)
3266 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3273 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3278 for (i
=0; i
<dock
->max_icons
; i
++) {
3279 icon
= dock
->icon_array
[i
];
3283 if (icon
->launching
&& icon
->pid
== pid
) {
3284 if (!icon
->relaunching
) {
3286 icon
->main_window
= None
;
3288 wDockFinishLaunch(dock
, icon
);
3293 sprintf(msg
, _("Could not execute command \"%s\""),
3294 icon
->drop_launch
&& icon
->dnd_command
3295 ? icon
->dnd_command
: icon
->command
);
3297 sprintf(msg
, _("Could not execute command \"%s\""),
3300 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
3301 _("OK"), NULL
, NULL
);
3310 toggleLowered(WDock
*dock
)
3315 /* lower/raise Dock */
3316 if (!dock
->lowered
) {
3317 newlevel
= WMNormalLevel
;
3320 newlevel
= WMDockLevel
;
3324 for (i
=0; i
<dock
->max_icons
; i
++) {
3325 tmp
= dock
->icon_array
[i
];
3329 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3331 wLowerFrame(tmp
->icon
->core
);
3334 if (dock
->type
== WM_DOCK
)
3335 wScreenUpdateUsableArea(dock
->screen_ptr
);
3340 toggleCollapsed(WDock
*dock
)
3342 if (dock
->collapsed
) {
3343 dock
->collapsed
= 0;
3344 wDockShowIcons(dock
);
3347 dock
->collapsed
= 1;
3348 wDockHideIcons(dock
);
3354 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3356 WScreen
*scr
= dock
->screen_ptr
;
3357 WObjDescriptor
*desc
;
3359 WApplication
*wapp
= NULL
;
3363 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3365 if (dock
->type
== WM_DOCK
) {
3367 entry
= dock
->menu
->entries
[index
];
3368 entry
->flags
.indicator_on
= !dock
->lowered
;
3369 entry
->clientdata
= dock
;
3372 if (scr
->clip_options
)
3373 updateClipOptionsMenu(scr
->clip_options
, dock
);
3375 n_selected
= numberOfSelectedIcons(dock
);
3377 /* Rename Workspace */
3378 entry
= dock
->menu
->entries
[++index
];
3379 if (aicon
== scr
->clip_icon
) {
3380 entry
->callback
= renameCallback
;
3381 entry
->clientdata
= dock
;
3382 //entry->flags.indicator = 0;
3383 entry
->text
= _("Rename Workspace");
3385 entry
->callback
= omnipresentCallback
;
3386 entry
->clientdata
= aicon
;
3387 //entry->flags.indicator = 1;
3388 //entry->flags.indicator_on = aicon->omnipresent;
3389 //entry->flags.indicator_type = MI_CHECK;
3390 //entry->text = _("Omnipresent");
3391 if (n_selected
> 0) {
3392 entry
->text
= _("Toggle Omnipresent");
3394 if (aicon
->omnipresent
)
3395 entry
->text
= _("Unset Omnipresent");
3397 entry
->text
= _("Set Omnipresent");
3401 /* select/unselect icon */
3402 entry
= dock
->menu
->entries
[++index
];
3403 entry
->clientdata
= aicon
;
3404 if (aicon
->icon
->selected
)
3405 entry
->text
= _("Unselect Icon");
3407 entry
->text
= _("Select Icon");
3408 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3410 /* select/unselect all icons */
3411 entry
= dock
->menu
->entries
[++index
];
3412 entry
->clientdata
= aicon
;
3414 entry
->text
= _("Unselect All Icons");
3416 entry
->text
= _("Select All Icons");
3417 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3420 entry
= dock
->menu
->entries
[++index
];
3421 entry
->clientdata
= aicon
;
3423 entry
->text
= _("Keep Icons");
3425 entry
->text
= _("Keep Icon");
3426 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3428 /* this is the workspace submenu part */
3429 entry
= dock
->menu
->entries
[++index
];
3431 entry
->text
= _("Move Icons To");
3433 entry
->text
= _("Move Icon To");
3434 if (scr
->clip_submenu
)
3435 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3436 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3438 /* remove icon(s) */
3439 entry
= dock
->menu
->entries
[++index
];
3440 entry
->clientdata
= aicon
;
3442 entry
->text
= _("Remove Icons");
3444 entry
->text
= _("Remove Icon");
3445 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3447 /* attract icon(s) */
3448 entry
= dock
->menu
->entries
[++index
];
3449 entry
->clientdata
= aicon
;
3451 dock
->menu
->flags
.realized
= 0;
3452 wMenuRealize(dock
->menu
);
3456 entry
= dock
->menu
->entries
[++index
];
3457 entry
->clientdata
= aicon
;
3458 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3461 entry
= dock
->menu
->entries
[++index
];
3462 entry
->clientdata
= aicon
;
3463 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3466 entry
= dock
->menu
->entries
[++index
];
3467 entry
->clientdata
= aicon
;
3468 if (aicon
->icon
->owner
) {
3469 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3470 if (wapp
&& wapp
->flags
.hidden
)
3471 entry
->text
= _("Unhide");
3473 entry
->text
= _("Hide");
3475 entry
->text
= _("Hide");
3477 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3480 entry
= dock
->menu
->entries
[++index
];
3481 entry
->clientdata
= aicon
;
3482 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
3483 && !wPreferences
.flags
.noupdates
);
3486 entry
= dock
->menu
->entries
[++index
];
3487 entry
->clientdata
= aicon
;
3488 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3490 if (!dock
->menu
->flags
.realized
)
3491 wMenuRealize(dock
->menu
);
3493 if (dock
->type
== WM_CLIP
) {
3494 x_pos
= event
->xbutton
.x_root
+2;
3496 x_pos
= dock
->on_right_side
?
3497 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 2 : 0;
3500 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3502 /* allow drag select */
3503 event
->xany
.send_event
= True
;
3504 desc
= &dock
->menu
->menu
->descriptor
;
3505 (*desc
->handle_mousedown
)(desc
, event
);
3510 openClipWorkspaceMenu(WScreen
*scr
, int x
, int y
)
3512 if (!scr
->clip_ws_menu
) {
3513 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3515 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
3516 wMenuMapAt(scr
->clip_ws_menu
, x
, y
, False
);
3520 /******************************************************************/
3522 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3524 WAppIcon
*btn
= desc
->parent
;
3525 WDock
*dock
= btn
->dock
;
3526 WApplication
*wapp
= NULL
;
3529 #ifdef REDUCE_APPICONS
3530 if ((btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) ||
3531 ((btn
->icon
->owner
== NULL
) && (btn
->applist
!= NULL
))) {
3532 if (btn
->icon
->owner
== NULL
)
3533 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
3536 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3538 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3542 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3544 /* go to the last workspace that the user worked on the app */
3545 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
3547 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3550 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3553 if (event
->xbutton
.state
& MOD_MASK
) {
3554 wHideOtherApplications(btn
->icon
->owner
);
3557 if (event
->xbutton
.button
==Button1
) {
3559 if (event
->xbutton
.state
& MOD_MASK
) {
3560 /* raise/lower dock */
3561 toggleLowered(dock
);
3562 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3563 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3564 toggleCollapsed(dock
);
3566 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3567 } else if (btn
->command
) {
3568 if (!btn
->launching
&&
3569 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3570 launchDockedApplication(btn
);
3572 } else if (btn
->xindex
== 0 && btn
->yindex
== 0
3573 && btn
->dock
->type
== WM_DOCK
) {
3575 wShowGNUstepPanel(dock
->screen_ptr
);
3583 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3585 WScreen
*scr
= dock
->screen_ptr
;
3586 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3589 int grabbed
= 0, swapped
= 0, done
;
3590 Pixmap ghost
= None
;
3591 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3594 puts("moving dock");
3596 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3597 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3598 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3599 wwarning("pointer grab failed for dock move");
3602 for (x
=0; x
<dock
->max_icons
; x
++) {
3603 if (dock
->icon_array
[x
]!=NULL
&&
3604 dock
->icon_array
[x
]->yindex
> y
)
3605 y
= dock
->icon_array
[x
]->yindex
;
3608 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3612 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3613 |ButtonMotionMask
|ExposureMask
, &ev
);
3621 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3622 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3623 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3624 |ButtonReleaseMask
|ButtonPressMask
,
3625 wCursor
[WCUR_MOVE
], CurrentTime
);
3630 if (dock
->type
== WM_CLIP
) {
3631 if (ev
.xmotion
.x_root
- ofs_x
< 0) {
3633 } else if (ev
.xmotion
.x_root
- ofs_x
+ ICON_SIZE
>
3635 x
= scr
->scr_width
- ICON_SIZE
;
3637 x
= ev
.xmotion
.x_root
- ofs_x
;
3639 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3641 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3643 y
= scr
->scr_height
- ICON_SIZE
;
3645 y
= ev
.xmotion
.y_root
- ofs_y
;
3647 moveDock(dock
, x
, y
);
3649 /* move vertically if pointer is inside the dock*/
3650 if ((dock
->on_right_side
&&
3651 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3652 || (!dock
->on_right_side
&&
3653 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3655 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3657 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3659 y
= scr
->scr_height
- ICON_SIZE
;
3661 y
= ev
.xmotion
.y_root
- ofs_y
;
3663 moveDock(dock
, dock
->x_pos
, y
);
3665 /* move horizontally to change sides */
3666 x
= ev
.xmotion
.x_root
- ofs_x
;
3667 if (!dock
->on_right_side
) {
3671 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3672 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3673 -DOCK_EXTRA_SPACE
-1, dock
->y_pos
);
3674 if (superfluous
&& ghost
==None
) {
3675 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3676 scr
->scr_width
-ICON_SIZE
3677 -DOCK_EXTRA_SPACE
-1,
3679 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3681 XClearWindow(dpy
, scr
->dock_shadow
);
3683 XMapRaised(dpy
, scr
->dock_shadow
);
3686 if (superfluous
&& ghost
!=None
) {
3687 XFreePixmap(dpy
, ghost
);
3690 XUnmapWindow(dpy
, scr
->dock_shadow
);
3695 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3696 XMoveWindow(dpy
, scr
->dock_shadow
,
3697 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3698 if (superfluous
&& ghost
==None
) {
3699 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3700 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3701 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3703 XClearWindow(dpy
, scr
->dock_shadow
);
3705 XMapRaised(dpy
, scr
->dock_shadow
);
3708 XUnmapWindow(dpy
, scr
->dock_shadow
);
3710 if (superfluous
&& ghost
!=None
) {
3711 XFreePixmap(dpy
, ghost
);
3723 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3725 XUngrabPointer(dpy
, CurrentTime
);
3726 XUnmapWindow(dpy
, scr
->dock_shadow
);
3727 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3728 if (dock
->type
== WM_DOCK
) {
3731 dock
->on_right_side
= 1;
3733 dock
->on_right_side
= 0;
3735 wArrangeIcons(scr
, False
);
3744 XFreePixmap(dpy
, ghost
);
3745 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3748 puts("End dock move");
3755 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3757 WScreen
*scr
= dock
->screen_ptr
;
3759 WIcon
*icon
= aicon
->icon
;
3760 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3761 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3763 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3764 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3765 int shad_x
= x
, shad_y
= y
;
3766 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3768 Pixmap ghost
= None
;
3770 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3771 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3774 if (wPreferences
.flags
.noupdates
)
3777 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3778 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3779 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3781 wwarning("pointer grab failed for icon move");
3785 if (!(event
->xbutton
.state
& MOD_MASK
))
3786 wRaiseFrame(icon
->core
);
3788 if (!wPreferences
.flags
.noclip
)
3789 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3791 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3793 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3796 wins
[0] = icon
->core
->window
;
3797 wins
[1] = scr
->dock_shadow
;
3798 XRestackWindows(dpy
, wins
, 2);
3799 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3800 ICON_SIZE
, ICON_SIZE
);
3802 if (icon
->pixmap
!=None
)
3803 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3805 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3807 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3808 XClearWindow(dpy
, scr
->dock_shadow
);
3810 XMapWindow(dpy
, scr
->dock_shadow
);
3816 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3817 |ButtonMotionMask
|ExposureMask
, &ev
);
3825 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3826 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3827 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3828 |ButtonReleaseMask
|ButtonPressMask
,
3829 wCursor
[WCUR_MOVE
], CurrentTime
);
3838 for (i
=0; i
<scr
->workspace_count
; i
++) {
3839 if (i
== scr
->current_workspace
)
3841 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3845 x
= ev
.xmotion
.x_root
- ofs_x
;
3846 y
= ev
.xmotion
.y_root
- ofs_y
;
3847 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3850 if (last_dock
!= dock
&& collapsed
) {
3851 last_dock
->collapsed
= 1;
3852 wDockHideIcons(last_dock
);
3855 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3856 dock
->collapsed
= 0;
3857 wDockShowIcons(dock
);
3859 if (dock
->auto_raise_lower
)
3863 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3866 if (last_dock
!= dock2
&& collapsed
) {
3867 last_dock
->collapsed
= 1;
3868 wDockHideIcons(last_dock
);
3871 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3872 dock2
->collapsed
= 0;
3873 wDockShowIcons(dock2
);
3875 if (dock2
->auto_raise_lower
)
3880 if (aicon
->launching
3881 || (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3882 || (!aicon
->running
&& tmp
)) {
3883 shad_x
= last_dock
->x_pos
+ ix
*wPreferences
.icon_size
;
3884 shad_y
= last_dock
->y_pos
+ iy
*wPreferences
.icon_size
;
3886 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3889 XMapWindow(dpy
, scr
->dock_shadow
);
3894 XUnmapWindow(dpy
, scr
->dock_shadow
);
3898 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3905 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3907 XUngrabPointer(dpy
, CurrentTime
);
3909 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3910 XUnmapWindow(dpy
, scr
->dock_shadow
);
3912 reattachIcon(dock
, aicon
, ix
, iy
);
3913 if (clip
&& dock
!=clip
&& clip
->auto_raise_lower
)
3916 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3918 /* Slide it back if dock rejected it */
3919 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3921 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3923 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3931 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3932 /* We need to deselect it, even if is deselected in
3933 * wDockDetach(), because else DoKaboom() will fail.
3935 if (aicon
->icon
->selected
)
3936 wIconSelect(aicon
->icon
);
3937 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3940 if (clip
&& clip
->auto_raise_lower
)
3942 wDockDetach(dock
, aicon
);
3945 last_dock
->collapsed
= 1;
3946 wDockHideIcons(last_dock
);
3951 XFreePixmap(dpy
, ghost
);
3952 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3956 for (i
=0; i
<scr
->workspace_count
; i
++) {
3957 if (i
== scr
->current_workspace
)
3959 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3964 puts("End icon move");
3973 getClipButton(int px
, int py
)
3975 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
3977 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3980 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
3981 return CLIP_FORWARD
;
3982 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
3990 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3993 int done
, direction
, new_ws
;
3995 WDock
*clip
= scr
->clip_icon
->dock
;
3997 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3999 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
4000 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
4002 wClipIconPaint(scr
->clip_icon
);
4005 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
4006 |ButtonPressMask
, &ev
);
4013 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
4014 if (new_dir
!= direction
) {
4015 direction
= new_dir
;
4016 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
4017 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
4018 wClipIconPaint(scr
->clip_icon
);
4026 if (ev
.xbutton
.button
== event
->xbutton
.button
)
4031 clip
->lclip_button_pushed
= 0;
4032 clip
->rclip_button_pushed
= 0;
4034 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
4036 if (direction
== CLIP_FORWARD
) {
4037 if (scr
->current_workspace
< scr
->workspace_count
-1)
4038 wWorkspaceChange(scr
, scr
->current_workspace
+1);
4039 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
4040 wWorkspaceChange(scr
, scr
->current_workspace
+1);
4041 else if (wPreferences
.ws_cycle
)
4042 wWorkspaceChange(scr
, 0);
4044 else if (direction
== CLIP_REWIND
) {
4045 if (scr
->current_workspace
> 0)
4046 wWorkspaceChange(scr
, scr
->current_workspace
-1);
4047 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
4048 wWorkspaceChange(scr
, scr
->workspace_count
-1);
4051 wClipIconPaint(scr
->clip_icon
);
4056 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
4058 WAppIcon
*aicon
= desc
->parent
;
4059 WDock
*dock
= aicon
->dock
;
4060 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4062 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
4065 scr
->last_dock
= dock
;
4067 if (dock
->menu
->flags
.mapped
)
4068 wMenuUnmap(dock
->menu
);
4070 if (IsDoubleClick(scr
, event
)) {
4071 /* double-click was not in the main clip icon */
4072 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
4073 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
4074 iconDblClick(desc
, event
);
4079 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
4080 XUnmapWindow(dpy
, scr
->clip_balloon
);
4081 scr
->flags
.clip_balloon_mapped
= 0;
4085 puts("handling dock");
4087 if (event
->xbutton
.button
== Button1
) {
4088 if (event
->xbutton
.state
& MOD_MASK
)
4093 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
4094 dock
->type
!=WM_DOCK
) {
4095 wIconSelect(aicon
->icon
);
4099 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
4100 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
4101 && dock
->type
==WM_CLIP
)
4102 handleClipChangeWorkspace(scr
, event
);
4104 handleDockMove(dock
, aicon
, event
);
4106 handleIconMove(dock
, aicon
, event
);
4108 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4109 aicon
==scr
->clip_icon
) {
4110 openClipWorkspaceMenu(scr
, event
->xbutton
.x_root
+2,
4111 event
->xbutton
.y_root
+2);
4112 if (scr
->clip_ws_menu
) {
4114 menu
= scr
->clip_ws_menu
;
4115 desc
= &menu
->menu
->descriptor
;
4117 event
->xany
.send_event
= True
;
4118 (*desc
->handle_mousedown
)(desc
, event
);
4120 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4121 (event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
) {
4122 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
4123 } else if (event
->xbutton
.button
== Button3
) {
4124 openDockMenu(dock
, aicon
, event
);
4130 showClipBalloon(WDock
*dock
, int workspace
)
4134 WScreen
*scr
= dock
->screen_ptr
;
4138 scr
->flags
.clip_balloon_mapped
= 1;
4139 XMapWindow(dpy
, scr
->clip_balloon
);
4141 text
= scr
->workspaces
[workspace
]->name
;
4143 w
= WMWidthOfString(scr
->clip_title_font
, text
, strlen(text
));
4145 h
= WMFontHeight(scr
->clip_title_font
);
4146 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
4148 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
4149 y
= dock
->y_pos
+ ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
4151 if (x
+w
> scr
->scr_width
) {
4152 x
= scr
->scr_width
- w
;
4153 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
4154 y
= dock
->y_pos
- h
- 1;
4156 y
= dock
->y_pos
+ ICON_SIZE
;
4157 XRaiseWindow(dpy
, scr
->clip_balloon
);
4159 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
4160 stack
[1] = scr
->clip_balloon
;
4161 XRestackWindows(dpy
, stack
, 2);
4163 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
4164 XSetForeground(dpy
, scr
->clip_title_gc
,
4165 scr
->clip_title_pixel
[CLIP_NORMAL
]);
4166 XClearWindow(dpy
, scr
->clip_balloon
);
4167 WMDrawString(scr
->wmscreen
, scr
->clip_balloon
, scr
->clip_title_gc
,
4168 scr
->clip_title_font
, 0, 0, text
, strlen(text
));
4173 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
4175 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4179 assert(event
->type
==EnterNotify
);
4181 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4184 scr
= btn
->icon
->core
->screen_ptr
;
4185 if (!btn
->omnipresent
)
4188 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
4190 if (!dock
|| dock
->type
!=WM_CLIP
)
4193 /* The auto raise/lower code */
4194 if (dock
->auto_lower_magic
) {
4195 WMDeleteTimerHandler(dock
->auto_lower_magic
);
4196 dock
->auto_lower_magic
= NULL
;
4198 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
4199 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
,
4204 /* The auto expand/collapse code */
4205 if (dock
->auto_collapse_magic
) {
4206 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
4207 dock
->auto_collapse_magic
= NULL
;
4209 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
4210 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
,
4215 if (btn
->xindex
== 0 && btn
->yindex
== 0)
4216 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4218 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4219 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
4220 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
4227 clipLeave(WDock
*dock
)
4230 WObjDescriptor
*desc
= NULL
;
4232 if (!dock
|| dock
->type
!=WM_CLIP
)
4235 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
)!=False
) {
4236 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
4237 (XPointer
*)&desc
)!=XCNOENT
4238 && desc
&& desc
->parent_type
==WCLASS_DOCK_ICON
4239 && ((WAppIcon
*)desc
->parent
)->dock
4240 && ((WAppIcon
*)desc
->parent
)->dock
->type
==WM_CLIP
) {
4241 /* We didn't left the Clip yet */
4242 XPutBackEvent(dpy
, &event
);
4246 XPutBackEvent(dpy
, &event
);
4248 /* We entered a withdrawn window, so we're still in Clip */
4252 if (dock
->auto_raise_magic
) {
4253 WMDeleteTimerHandler(dock
->auto_raise_magic
);
4254 dock
->auto_raise_magic
= NULL
;
4256 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
4257 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
,
4262 if (dock
->auto_expand_magic
) {
4263 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4264 dock
->auto_expand_magic
= NULL
;
4266 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
4267 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
4275 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4277 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4279 assert(event
->type
==LeaveNotify
);
4281 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4284 clipLeave(btn
->dock
);
4289 clipAutoCollapse(void *cdata
)
4291 WDock
*dock
= (WDock
*)cdata
;
4293 if (dock
->type
!=WM_CLIP
)
4296 if (dock
->auto_collapse
) {
4297 dock
->collapsed
= 1;
4298 wDockHideIcons(dock
);
4300 dock
->auto_collapse_magic
= NULL
;
4305 clipAutoExpand(void *cdata
)
4307 WDock
*dock
= (WDock
*)cdata
;
4309 if (dock
->type
!=WM_CLIP
)
4312 if (dock
->auto_collapse
) {
4313 dock
->collapsed
= 0;
4314 wDockShowIcons(dock
);
4316 dock
->auto_expand_magic
= NULL
;
4321 clipAutoLower(void *cdata
)
4323 WDock
*dock
= (WDock
*)cdata
;
4325 if (dock
->type
!=WM_CLIP
)
4328 if (dock
->auto_raise_lower
)
4331 dock
->auto_lower_magic
= NULL
;
4336 clipAutoRaise(void *cdata
)
4338 WDock
*dock
= (WDock
*)cdata
;
4340 if (dock
->type
!=WM_CLIP
)
4343 if (dock
->auto_raise_lower
)
4346 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4347 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4350 dock
->auto_raise_magic
= NULL
;
4355 iconCanBeOmnipresent(WAppIcon
*aicon
)
4357 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4362 for (i
=0; i
<scr
->workspace_count
; i
++) {
4363 clip
= scr
->workspaces
[i
]->clip
;
4365 if (clip
== aicon
->dock
)
4368 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4369 return False
; /* Clip is full in some workspace */
4371 for (j
=0; j
<clip
->max_icons
; j
++) {
4372 btn
= clip
->icon_array
[j
];
4373 if(btn
&& btn
->xindex
==aicon
->xindex
&& btn
->yindex
==aicon
->yindex
)
4383 wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
4385 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4386 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4387 int status
= WO_SUCCESS
;
4389 if (aicon
->dock
== scr
->dock
|| aicon
== scr
->clip_icon
)
4390 return WO_NOT_APPLICABLE
;
4392 if (aicon
->omnipresent
== omnipresent
)
4396 if (iconCanBeOmnipresent(aicon
)) {
4397 aicon
->omnipresent
= 1;
4398 new_entry
= wmalloc(sizeof(WAppIconChain
));
4399 new_entry
->aicon
= aicon
;
4400 new_entry
->next
= NULL
;
4401 if (!scr
->global_icons
) {
4402 scr
->global_icons
= new_entry
;
4404 tmp
= scr
->global_icons
;
4408 tmp
->next
= new_entry
;
4410 scr
->global_icon_count
++;
4412 aicon
->omnipresent
= 0;
4416 aicon
->omnipresent
= 0;
4417 if (aicon
== scr
->global_icons
->aicon
) {
4418 tmp
= scr
->global_icons
->next
;
4419 free(scr
->global_icons
);
4420 scr
->global_icons
= tmp
;
4421 scr
->global_icon_count
--;
4423 tmp
= scr
->global_icons
;
4425 if (tmp
->next
->aicon
== aicon
) {
4426 tmp1
= tmp
->next
->next
;
4429 scr
->global_icon_count
--;
4437 wAppIconPaint(aicon
);