1 /* dock.c- built-in Dock module for WindowMaker
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 #include <X11/Xutil.h>
35 #define PATH_MAX DEFAULT_PATH_MAX
38 #include "WindowMaker.h"
48 #include "properties.h"
52 #include "workspace.h"
54 #include "superfluous.h"
67 /**** Local variables ****/
70 #define CLIP_FORWARD 2
72 #define CLIP_BUTTON_SIZE 23
75 /**** Global variables ****/
78 extern void DestroyDockAppSettingsPanel();
80 extern void ShowDockAppSettingsPanel(WAppIcon
*aicon
);
84 extern Cursor wCursor
[WCUR_LAST
];
86 extern WPreferences wPreferences
;
88 extern XContext wWinContext
;
91 extern Atom _XA_DND_PROTOCOL
;
95 #define MOD_MASK wPreferences.modifier_mask
97 extern void appIconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
99 #define ICON_SIZE wPreferences.icon_size
102 /***** Local variables ****/
104 static proplist_t dCommand
=NULL
;
106 static proplist_t dDropCommand
=NULL
;
108 static proplist_t dAutoLaunch
, dName
, dForced
, dBuggyApplication
, dYes
, dNo
;
109 static proplist_t dHost
, dDock
, dClip
;
110 static proplist_t dAutoAttractIcons
, dKeepAttracted
;
112 static proplist_t dPosition
, dApplications
, dLowered
, dCollapsed
, dAutoCollapse
;
114 static void dockIconPaint(WAppIcon
*btn
);
116 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
118 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
);
120 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
122 static int getClipButton(int px
, int py
);
124 static void toggleLowered(WDock
*dock
);
126 static void toggleCollapsed(WDock
*dock
);
128 static void toggleAutoCollapse(WDock
*dock
);
130 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
132 static void clipLeave(WDock
*dock
);
134 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
136 Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
);
138 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
139 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
140 static void clipAutoCollapse(void *cdata
);
141 static void launchDockedApplication(WAppIcon
*btn
);
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 dAutoAttractIcons
= PLMakeString("AutoAttractIcons");
187 dKeepAttracted
= PLMakeString("KeepAttracted");
189 dDock
= PLMakeString("Dock");
190 dClip
= PLMakeString("Clip");
196 renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
198 WDock
*dock
= entry
->clientdata
;
203 assert(entry
->clientdata
!=NULL
);
205 wspace
= dock
->screen_ptr
->current_workspace
;
207 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
209 sprintf(buffer
, _("Type the name for workspace %i:"), wspace
+1);
210 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
,
212 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
221 toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
223 assert(entry
->clientdata
!=NULL
);
225 toggleLowered(entry
->clientdata
);
227 entry
->flags
.indicator_on
= !((WDock
*)entry
->clientdata
)->lowered
;
235 killCallback(WMenu
*menu
, WMenuEntry
*entry
)
238 #ifdef REDUCE_APPICONS
239 WAppIconAppList
*tapplist
;
241 extern Atom _XA_WM_DELETE_WINDOW
;
244 assert(entry
->clientdata
!=NULL
);
246 icon
= (WAppIcon
*)entry
->clientdata
;
250 #ifdef REDUCE_APPICONS
251 /* Send a delete message to the main window of each application
252 * bound to this docked appicon. - cls
254 tapplist
= icon
->applist
;
255 while (tapplist
!= NULL
) {
256 if (tapplist
->wapp
->main_window_desc
!= NULL
) {
257 if (tapplist
->wapp
->main_window_desc
->protocols
.DELETE_WINDOW
) {
258 wClientSendProtocol(tapplist
->wapp
->main_window_desc
,
259 _XA_WM_DELETE_WINDOW
, CurrentTime
);
261 wClientKill(tapplist
->wapp
->main_window_desc
);
264 tapplist
= tapplist
->next
;
267 if (wPreferences
.dont_confirm_kill
268 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
269 _("This will kill the application.\nAny unsaved changes will be lost.\nPlease confirm."),
270 _("Yes"), _("No"), NULL
)==WAPRDefault
) {
271 if (icon
->icon
&& icon
->icon
->owner
) {
272 wClientKill(icon
->icon
->owner
);
275 #endif /* !REDUCE_APPICONS */
282 getSelected(WDock
*dock
)
284 LinkedList
*ret
=NULL
;
288 for (i
=1; i
<dock
->max_icons
; i
++) {
289 btn
= dock
->icon_array
[i
];
290 if (btn
&& btn
->icon
->selected
) {
291 ret
= list_cons(btn
, ret
);
300 paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
302 Window win
= clipIcon
->icon
->core
->window
;
303 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
305 int pt
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
306 int tp
= ICON_SIZE
- pt
;
307 int as
= pt
- 15; /* 15 = 5+5+5 */
313 p
[1].x
= ICON_SIZE
-2;
315 p
[2].x
= ICON_SIZE
-2;
317 } else if (lpushed
) {
321 p
[1].y
= ICON_SIZE
-2;
323 p
[2].y
= ICON_SIZE
-2;
325 if (lpushed
|| rpushed
) {
326 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
327 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
328 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
331 p
[0].x
= p
[3].x
= ICON_SIZE
-6-as
;
333 p
[1].x
= ICON_SIZE
-6;
335 p
[2].x
= ICON_SIZE
-6;
338 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
339 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
341 XFillPolygon(dpy
, win
, scr
->clip_title_gc
, p
,3,Convex
,CoordModeOrigin
);
342 XDrawLines(dpy
, win
, scr
->clip_title_gc
, p
,4,CoordModeOrigin
);
346 p
[0].y
= p
[3].y
= ICON_SIZE
-6-as
;
348 p
[1].y
= ICON_SIZE
-6;
350 p
[2].y
= ICON_SIZE
-6;
352 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
353 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
355 XFillPolygon(dpy
, win
, scr
->clip_title_gc
, p
,3,Convex
,CoordModeOrigin
);
356 XDrawLines(dpy
, win
, scr
->clip_title_gc
, p
,4,CoordModeOrigin
);
362 wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
364 RImage
*tile
= RCloneImage(normalTile
);
370 pt
= CLIP_BUTTON_SIZE
*wPreferences
.icon_size
/64;
371 tp
= wPreferences
.icon_size
-1 - pt
;
374 black
.red
= black
.green
= black
.blue
= 0;
377 dark
.red
= dark
.green
= dark
.blue
= 80;
380 light
.red
= light
.green
= light
.blue
= 80;
384 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
-2,
386 RDrawLine(tile
, tp
-1, 0, wPreferences
.icon_size
-1, pt
+1, &black
);
387 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
-3,
392 ROperateLine(tile
, RAddOperation
, 2, tp
+2, pt
-2,
393 wPreferences
.icon_size
-3, &dark
);
394 RDrawLine(tile
, 0, tp
-1, pt
+1, wPreferences
.icon_size
-1, &black
);
395 ROperateLine(tile
, RSubtractOperation
, 0, tp
-2, pt
+1,
396 wPreferences
.icon_size
-2, &light
);
403 removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
405 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
408 LinkedList
*selectedIcons
;
411 assert(clickedIcon
!=NULL
);
413 dock
= clickedIcon
->dock
;
415 selectedIcons
= getSelected(dock
);
418 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
419 _("All selected icons will be removed!"),
420 _("OK"), _("Cancel"), NULL
)!=WAPRDefault
) {
424 if (clickedIcon
->xindex
==0 && clickedIcon
->yindex
==0)
426 selectedIcons
= list_cons(clickedIcon
, NULL
);
429 while (selectedIcons
) {
430 aicon
= selectedIcons
->head
;
431 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
432 wDockDetach(dock
, aicon
);
434 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
436 wLowerFrame(aicon
->icon
->core
);
438 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
439 aicon
->x_pos
, aicon
->y_pos
);
440 if (!dock
->mapped
|| dock
->collapsed
)
441 XMapWindow(dpy
, aicon
->icon
->core
->window
);
443 list_remove_head(&selectedIcons
);
446 if (wPreferences
.auto_arrange_icons
)
447 wArrangeIcons(dock
->screen_ptr
, True
);
452 keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
454 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
457 LinkedList
*selectedIcons
;
459 assert(clickedIcon
!=NULL
);
460 dock
= clickedIcon
->dock
;
462 selectedIcons
= getSelected(dock
);
464 if (!selectedIcons
&& clickedIcon
!=dock
->screen_ptr
->clip_icon
) {
465 char *command
= NULL
;
467 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
468 clickedIcon
->editing
= 1;
469 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
470 _("Type the command used to launch the application"),
472 if (command
&& (command
[0]==0 ||
473 (command
[0]=='-' && command
[1]==0))) {
477 clickedIcon
->command
= command
;
478 clickedIcon
->editing
= 0;
480 clickedIcon
->editing
= 0;
487 selectedIcons
= list_cons(clickedIcon
, NULL
);
490 while (selectedIcons
) {
491 aicon
= selectedIcons
->head
;
492 if (aicon
->icon
->selected
)
493 wIconSelect(aicon
->icon
);
494 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
495 aicon
->attracted
= 0;
496 if (aicon
->icon
->shadowed
) {
497 aicon
->icon
->shadowed
= 0;
498 aicon
->icon
->force_paint
= 1;
499 wAppIconPaint(aicon
);
502 list_remove_head(&selectedIcons
);
510 toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
512 WDock
*dock
= (WDock
*)entry
->clientdata
;
514 assert(entry
->clientdata
!=NULL
);
516 dock
->attract_icons
= !dock
->attract_icons
;
517 /*if (!dock->attract_icons)
518 dock->keep_attracted = 0;*/
520 entry
->flags
.indicator_on
= dock
->attract_icons
;
527 toggleKeepCallback(WMenu
*menu
, WMenuEntry
*entry
)
529 WDock
*dock
= (WDock
*)entry
->clientdata
;
533 assert(entry
->clientdata
!=NULL
);
535 dock
->keep_attracted
= !dock
->keep_attracted
;
537 if (dock
->keep_attracted
) {
538 for (i
=0; i
< dock
->max_icons
; i
++) {
539 btn
= dock
->icon_array
[i
];
540 if (btn
&& btn
->attracted
&& btn
->command
) {
542 if (btn
->icon
->shadowed
) {
543 btn
->icon
->shadowed
= 0;
544 btn
->icon
->force_paint
= 1;
551 entry
->flags
.indicator_on
= dock
->keep_attracted
;
558 selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
560 WAppIcon
*icon
= (WAppIcon
*)entry
->clientdata
;
564 wIconSelect(icon
->icon
);
571 colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
573 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
576 int x
, y
, x_pos
, y_pos
;
578 assert(entry
->clientdata
!=NULL
);
579 clip
= clickedIcon
->dock
;
581 aicon
= clip
->screen_ptr
->app_icon_list
;
584 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
585 x_pos
= clip
->x_pos
+ x
*ICON_SIZE
;
586 y_pos
= clip
->y_pos
+ y
*ICON_SIZE
;
587 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
589 if (wPreferences
.no_animations
) {
590 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
592 SlideWindow(aicon
->icon
->core
->window
,
593 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
596 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
597 #endif /* ANIMATIONS */
599 aicon
->attracted
= 1;
600 if (!clip
->keep_attracted
&& !aicon
->icon
->shadowed
) {
601 aicon
->icon
->shadowed
= 1;
602 aicon
->icon
->force_paint
= 1;
603 /* We don't do an wAppIconPaint() here because it's in
604 * wDockAttachIcon(). -Dan
607 wDockAttachIcon(clip
, aicon
, x
, y
);
608 if (clip
->collapsed
|| !clip
->mapped
)
609 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
617 selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
619 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
621 LinkedList
*selectedIcons
;
625 assert(clickedIcon
!=NULL
);
626 dock
= clickedIcon
->dock
;
628 selectedIcons
= getSelected(dock
);
630 if (!selectedIcons
) {
631 for (i
=1; i
<dock
->max_icons
; i
++) {
632 btn
= dock
->icon_array
[i
];
633 if (btn
&& !btn
->icon
->selected
) {
634 wIconSelect(btn
->icon
);
638 while(selectedIcons
) {
639 btn
= selectedIcons
->head
;
640 wIconSelect(btn
->icon
);
641 list_remove_head(&selectedIcons
);
650 toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
652 assert(entry
->clientdata
!=NULL
);
654 toggleCollapsed(entry
->clientdata
);
656 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->collapsed
;
663 toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
665 assert(entry
->clientdata
!=NULL
);
667 toggleAutoCollapse(entry
->clientdata
);
669 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_collapse
;
676 launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
678 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
680 launchDockedApplication(btn
);
685 settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
687 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
691 ShowDockAppSettingsPanel(btn
);
696 hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
699 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
701 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
703 if (wapp
->flags
.hidden
) {
704 wWorkspaceChange(btn
->icon
->core
->screen_ptr
,wapp
->last_workspace
);
705 wUnhideApplication(wapp
, False
, False
);
707 wHideApplication(wapp
);
713 unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
716 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
718 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
720 wUnhideApplication(wapp
, False
, True
);
725 mainIconCreate(WScreen
*scr
, int type
)
730 if (type
== WM_CLIP
) {
732 return scr
->clip_icon
;
733 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
734 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
735 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
736 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
737 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE;*/
741 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
742 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
748 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
749 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
750 btn
->icon
->core
->descriptor
.parent
= btn
;
751 /*ChangeStackingLevel(btn->icon->core, NSDockWindowLevel);*/
752 XMapWindow(dpy
, btn
->icon
->core
->window
);
757 scr
->clip_icon
= btn
;
764 switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
766 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
767 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
769 LinkedList
*selectedIcons
;
772 if (entry
->order
== scr
->current_workspace
)
775 dest
= scr
->workspaces
[entry
->order
]->clip
;
777 selectedIcons
= getSelected(src
);
780 while(selectedIcons
) {
781 btn
= selectedIcons
->head
;
782 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
783 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
784 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
786 list_remove_head(&selectedIcons
);
788 } else if (icon
!= scr
->clip_icon
) {
789 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
790 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
791 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
799 launchDockedApplication(WAppIcon
*btn
)
801 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
803 if (!btn
->launching
&& btn
->command
!=NULL
) {
804 if (!btn
->forced_dock
) {
805 btn
->relaunching
= btn
->running
;
808 if (btn
->wm_instance
|| btn
->wm_class
) {
809 WWindowAttributes attr
;
810 memset(&attr
, 0, sizeof(WWindowAttributes
));
811 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
, &attr
,
814 if (!attr
.no_appicon
&& !btn
->buggy_app
)
819 btn
->drop_launch
= 0;
820 scr
->last_dock
= btn
->dock
;
821 btn
->pid
= execCommand(btn
, btn
->command
, NULL
);
823 if (btn
->buggy_app
) {
824 /* give feedback that the app was launched */
828 WMAddTimerHandler(200, (WMCallback
*)dockIconPaint
, btn
);
833 wwarning(_("could not launch application %s\n"), btn
->command
);
835 if (!btn
->relaunching
)
844 updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
846 WScreen
*scr
= menu
->frame
->screen_ptr
;
847 char title
[MAX_WORKSPACENAME_WIDTH
+1];
853 for (i
=0; i
<scr
->workspace_count
; i
++) {
854 if (i
< menu
->entry_no
) {
855 if (strcmp(menu
->entries
[i
]->text
,scr
->workspaces
[i
]->name
)!=0) {
856 free(menu
->entries
[i
]->text
);
857 strcpy(title
, scr
->workspaces
[i
]->name
);
858 menu
->entries
[i
]->text
= wstrdup(title
);
859 menu
->flags
.realized
= 0;
861 menu
->entries
[i
]->clientdata
= (void*)icon
;
863 strcpy(title
, scr
->workspaces
[i
]->name
);
865 wMenuAddCallback(menu
, title
, switchWSCommand
, (void*)icon
);
867 menu
->flags
.realized
= 0;
869 if (i
== scr
->current_workspace
) {
870 wMenuSetEnabled(menu
, i
, False
);
872 wMenuSetEnabled(menu
, i
, True
);
876 if (!menu
->flags
.realized
)
882 makeWorkspaceMenu(WScreen
*scr
)
886 menu
= wMenuCreate(scr
, NULL
, False
);
888 wwarning(_("could not create workspace submenu for Clip menu"));
890 wMenuAddCallback(menu
, "", switchWSCommand
, (void*)scr
->clip_icon
);
892 menu
->flags
.realized
= 0;
900 updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
909 entry
= menu
->entries
[index
];
910 entry
->flags
.indicator_on
= !dock
->lowered
;
911 entry
->clientdata
= dock
;
914 entry
= menu
->entries
[++index
];
915 entry
->flags
.indicator_on
= dock
->collapsed
;
916 entry
->clientdata
= dock
;
919 entry
= menu
->entries
[++index
];
920 entry
->flags
.indicator_on
= dock
->auto_collapse
;
921 entry
->clientdata
= dock
;
924 entry
= menu
->entries
[++index
];
925 entry
->flags
.indicator_on
= dock
->attract_icons
;
926 entry
->clientdata
= dock
;
928 /* keep attracted icons */
929 entry
= menu
->entries
[++index
];
930 entry
->flags
.indicator_on
= dock
->keep_attracted
;
931 entry
->clientdata
= dock
;
933 menu
->flags
.realized
= 0;
939 makeClipOptionsMenu(WScreen
*scr
)
944 menu
= wMenuCreate(scr
, NULL
, False
);
946 wwarning(_("could not create options submenu for Clip menu"));
950 entry
= wMenuAddCallback(menu
, _("Keep Clip On Top"),
951 toggleLoweredCallback
, NULL
);
952 entry
->flags
.indicator
= 1;
953 entry
->flags
.indicator_on
= 1;
954 entry
->flags
.indicator_type
= MI_CHECK
;
956 entry
= wMenuAddCallback(menu
, _("Collapsed"),
957 toggleCollapsedCallback
, NULL
);
958 entry
->flags
.indicator
= 1;
959 entry
->flags
.indicator_on
= 1;
960 entry
->flags
.indicator_type
= MI_CHECK
;
962 entry
= wMenuAddCallback(menu
, _("AutoCollapse"),
963 toggleAutoCollapseCallback
, NULL
);
964 entry
->flags
.indicator
= 1;
965 entry
->flags
.indicator_on
= 1;
966 entry
->flags
.indicator_type
= MI_CHECK
;
968 entry
= wMenuAddCallback(menu
, _("AutoAttract Icons"),
969 toggleAutoAttractCallback
, NULL
);
970 entry
->flags
.indicator
= 1;
971 entry
->flags
.indicator_on
= 1;
972 entry
->flags
.indicator_type
= MI_CHECK
;
974 entry
= wMenuAddCallback(menu
, _("Keep Attracted Icons"),
975 toggleKeepCallback
, NULL
);
976 entry
->flags
.indicator
= 1;
977 entry
->flags
.indicator_on
= 1;
978 entry
->flags
.indicator_type
= MI_CHECK
;
980 menu
->flags
.realized
= 0;
988 dockMenuCreate(WScreen
*scr
, int type
)
993 if (type
== WM_CLIP
&& scr
->clip_menu
)
994 return scr
->clip_menu
;
996 menu
= wMenuCreate(scr
, NULL
, False
);
997 if (type
!= WM_CLIP
) {
998 entry
= wMenuAddCallback(menu
, _("Keep Dock On Top"),
999 toggleLoweredCallback
, NULL
);
1000 entry
->flags
.indicator
= 1;
1001 entry
->flags
.indicator_on
= 1;
1002 entry
->flags
.indicator_type
= MI_CHECK
;
1004 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1005 scr
->clip_options
= makeClipOptionsMenu(scr
);
1006 if (scr
->clip_options
)
1007 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1009 wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1011 wMenuAddCallback(menu
, _("(Un)Select Icon"), selectCallback
, NULL
);
1013 wMenuAddCallback(menu
, _("(Un)Select All Icons"), selectIconsCallback
,
1016 wMenuAddCallback(menu
, _("Keep Icon(s)"), keepIconsCallback
, NULL
);
1018 entry
= wMenuAddCallback(menu
, _("Move Icon(s) To"), NULL
, NULL
);
1019 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1020 if (scr
->clip_submenu
)
1021 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1023 wMenuAddCallback(menu
, _("Remove Icon(s)"), removeIconsCallback
, NULL
);
1025 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1028 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1030 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1032 wMenuAddCallback(menu
, _("(Un)Hide"), hideCallback
, NULL
);
1034 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1036 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1038 if (type
== WM_CLIP
)
1039 scr
->clip_menu
= menu
;
1046 wDockCreate(WScreen
*scr
, int type
)
1054 dock
= wmalloc(sizeof(WDock
));
1055 memset(dock
, 0, sizeof(WDock
));
1057 if (type
== WM_CLIP
)
1058 icon_count
= CLIP_MAX_ICONS
;
1060 icon_count
= scr
->scr_height
/wPreferences
.icon_size
;
1062 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*)*icon_count
);
1063 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*)*icon_count
);
1065 dock
->max_icons
= icon_count
;
1067 btn
= mainIconCreate(scr
, type
);
1071 dock
->x_pos
= btn
->x_pos
;
1072 dock
->y_pos
= btn
->y_pos
;
1073 dock
->screen_ptr
= scr
;
1075 dock
->icon_count
= 1;
1076 dock
->on_right_side
= 1;
1077 dock
->collapsed
= 0;
1078 dock
->auto_collapse
= 0;
1079 dock
->auto_collapse_magic
= NULL
;
1080 dock
->attract_icons
= 0;
1081 dock
->keep_attracted
= 0;
1083 dock
->icon_array
[0] = btn
;
1084 wRaiseFrame(btn
->icon
->core
);
1085 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1087 /* create dock menu */
1088 dock
->menu
= dockMenuCreate(scr
, type
);
1095 wDockDestroy(WDock
*dock
)
1100 for (i
=(dock
->type
== WM_CLIP
) ? 1 : 0; i
<dock
->max_icons
; i
++) {
1101 aicon
= dock
->icon_array
[i
];
1103 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1104 wDockDetach(dock
, aicon
);
1106 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
1108 wLowerFrame(aicon
->icon
->core
);
1110 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
1111 aicon
->x_pos
, aicon
->y_pos
);
1112 if (!dock
->mapped
|| dock
->collapsed
)
1113 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1117 if (wPreferences
.auto_arrange_icons
)
1118 wArrangeIcons(dock
->screen_ptr
, True
);
1119 free(dock
->icon_array
);
1120 if (dock
->menu
&& dock
->type
!=WM_CLIP
)
1121 wMenuDestroy(dock
->menu
, True
);
1127 wClipIconPaint(WAppIcon
*aicon
)
1129 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1130 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1132 Window win
= aicon
->icon
->core
->window
;
1133 int length
, nlength
;
1134 char *ws_name
, ws_number
[10];
1137 wIconPaint(aicon
->icon
);
1139 length
= strlen(workspace
->name
);
1140 ws_name
= malloc(length
+ 1);
1141 sprintf(ws_name
, "%s", workspace
->name
);
1142 sprintf(ws_number
, "%i", scr
->current_workspace
+ 1);
1143 nlength
= strlen(ws_number
);
1145 gc
= scr
->clip_title_gc
;
1147 if (!workspace
->clip
->collapsed
)
1148 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_NORMAL
]);
1150 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_COLLAPSED
]);
1152 ty
= ICON_SIZE
- scr
->clip_title_font
->height
- 3;
1154 tx
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
1156 wDrawString(win
, scr
->clip_title_font
, gc
, tx
,
1157 ty
+ scr
->clip_title_font
->y
, ws_name
, length
);
1159 tx
= (ICON_SIZE
/2 - wTextWidth(scr
->clip_title_font
->font
, ws_number
, nlength
))/2;
1161 wDrawString(win
, scr
->clip_title_font
, gc
, tx
,
1162 scr
->clip_title_font
->y
+ 2, ws_number
, nlength
);
1166 if (aicon
->launching
) {
1167 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1168 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1170 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
,
1171 aicon
->dock
->rclip_button_pushed
);
1176 clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1178 wClipIconPaint(desc
->parent
);
1183 dockIconPaint(WAppIcon
*btn
)
1185 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1186 wClipIconPaint(btn
);
1193 make_icon_state(WAppIcon
*btn
)
1195 proplist_t node
= NULL
;
1196 proplist_t command
, autolaunch
, name
, forced
, host
, position
, buggy
;
1202 command
= PLMakeString("-");
1204 command
= PLMakeString(btn
->command
);
1206 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1208 if (btn
->wm_class
&& btn
->wm_instance
)
1209 sprintf(buffer
, "%s.%s", btn
->wm_instance
, btn
->wm_class
);
1210 else if (btn
->wm_instance
)
1211 sprintf(buffer
, "%s", btn
->wm_instance
);
1212 else if (btn
->wm_class
)
1213 sprintf(buffer
, ".%s", btn
->wm_class
);
1215 sprintf(buffer
, ".");
1217 name
= PLMakeString(buffer
);
1219 forced
= btn
->forced_dock
? dYes
: dNo
;
1221 buggy
= btn
->buggy_app
? dYes
: dNo
;
1223 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1224 sprintf(buffer
, "%i,%i", btn
->x_pos
, btn
->y_pos
);
1226 sprintf(buffer
, "%hi,%hi", btn
->xindex
, btn
->yindex
);
1227 position
= PLMakeString(buffer
);
1229 node
= PLMakeDictionaryFromEntries(dCommand
, command
,
1231 dAutoLaunch
, autolaunch
,
1233 dBuggyApplication
, buggy
,
1234 dPosition
, position
,
1238 PLRelease(position
);
1240 if (btn
->dnd_command
) {
1241 command
= PLMakeString(btn
->dnd_command
);
1242 PLInsertDictionaryEntry(node
, dDropCommand
, command
);
1245 #endif /* OFFIX_DND */
1247 if (btn
->client_machine
&& btn
->remote_start
) {
1248 host
= PLMakeString(btn
->client_machine
);
1249 PLInsertDictionaryEntry(node
, dHost
, host
);
1259 dockSaveState(WDock
*dock
)
1262 proplist_t icon_info
;
1263 proplist_t list
=NULL
, dock_state
=NULL
;
1267 list
= PLMakeArrayFromElements(NULL
);
1269 for (i
=(dock
->type
==WM_DOCK
? 0 : 1); i
<dock
->max_icons
; i
++) {
1270 WAppIcon
*btn
= dock
->icon_array
[i
];
1272 if (!btn
|| (btn
->attracted
&& !dock
->keep_attracted
))
1275 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1276 list
= PLAppendArrayElement(list
, icon_info
);
1277 PLRelease(icon_info
);
1281 dock_state
= PLMakeDictionaryFromEntries(dApplications
, list
, NULL
);
1285 if (dock
->type
== WM_DOCK
) {
1286 sprintf(buffer
, "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0),
1288 value
= PLMakeString(buffer
);
1289 PLInsertDictionaryEntry(dock_state
, dPosition
, value
);
1293 value
= (dock
->lowered
? dYes
: dNo
);
1294 PLInsertDictionaryEntry(dock_state
, dLowered
, value
);
1296 if (dock
->type
== WM_CLIP
) {
1297 value
= (dock
->collapsed
? dYes
: dNo
);
1298 PLInsertDictionaryEntry(dock_state
, dCollapsed
, value
);
1300 value
= (dock
->auto_collapse
? dYes
: dNo
);
1301 PLInsertDictionaryEntry(dock_state
, dAutoCollapse
, value
);
1303 value
= (dock
->attract_icons
? dYes
: dNo
);
1304 PLInsertDictionaryEntry(dock_state
, dAutoAttractIcons
, value
);
1306 value
= (dock
->keep_attracted
? dYes
: dNo
);
1307 PLInsertDictionaryEntry(dock_state
, dKeepAttracted
, value
);
1315 wDockSaveState(WScreen
*scr
)
1317 proplist_t dock_state
;
1319 dock_state
= dockSaveState(scr
->dock
);
1321 PLInsertDictionaryEntry(scr
->session_state
, dDock
, dock_state
);
1323 PLRelease(dock_state
);
1328 wClipSaveState(WScreen
*scr
)
1330 proplist_t clip_state
;
1332 clip_state
= make_icon_state(scr
->clip_icon
);
1334 PLInsertDictionaryEntry(scr
->session_state
, dClip
, clip_state
);
1336 PLRelease(clip_state
);
1341 wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1343 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1348 restore_icon_state(WScreen
*scr
, proplist_t info
, int type
, int index
)
1351 char *wclass
, *winstance
;
1352 proplist_t cmd
, value
;
1356 cmd
= PLGetDictionaryEntry(info
, dCommand
);
1357 if (!cmd
|| !PLIsString(cmd
)) {
1361 /* parse window name */
1362 value
= PLGetDictionaryEntry(info
, dName
);
1366 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1368 if (!winstance
&& !wclass
) {
1374 command
= wstrdup(PLGetString(cmd
));
1376 if (!command
|| strcmp(command
, "-")==0) {
1387 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
,
1394 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1395 if (type
== WM_CLIP
) {
1396 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1397 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1399 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1400 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1404 cmd
= PLGetDictionaryEntry(info
, dDropCommand
);
1406 aicon
->dnd_command
= wstrdup(PLGetString(cmd
));
1409 /* check auto launch */
1410 value
= PLGetDictionaryEntry(info
, dAutoLaunch
);
1412 aicon
->auto_launch
= 0;
1414 if (PLIsString(value
)) {
1415 if (strcasecmp(PLGetString(value
), "YES")==0)
1416 aicon
->auto_launch
= 1;
1418 wwarning(_("bad value in docked icon state info %s"),
1419 PLGetString(dAutoLaunch
));
1423 /* check if it wasn't normally docked */
1424 value
= PLGetDictionaryEntry(info
, dForced
);
1426 aicon
->forced_dock
= 0;
1428 if (PLIsString(value
)) {
1429 if (strcasecmp(PLGetString(value
), "YES")==0)
1430 aicon
->forced_dock
= 1;
1432 wwarning(_("bad value in docked icon state info %s"),
1433 PLGetString(dForced
));
1437 /* check if we can rely on the stuff in the app */
1438 value
= PLGetDictionaryEntry(info
, dBuggyApplication
);
1440 aicon
->buggy_app
= 0;
1442 if (PLIsString(value
)) {
1443 if (strcasecmp(PLGetString(value
), "YES")==0)
1444 aicon
->buggy_app
= 1;
1446 wwarning(_("bad value in docked icon state info %s"),
1447 PLGetString(dBuggyApplication
));
1451 /* get position in the dock */
1452 value
= PLGetDictionaryEntry(info
, dPosition
);
1453 if (value
&& PLIsString(value
)) {
1454 if (sscanf(PLGetString(value
), "%hi,%hi", &aicon
->xindex
,
1456 wwarning(_("bad value in docked icon state info %s"),
1457 PLGetString(dPosition
));
1459 /* check position sanity */
1460 /* incomplete section! */
1461 if (type
== WM_DOCK
) {
1463 if (aicon
->yindex
< 0)
1464 wwarning(_("bad value in docked icon position %i,%i"),
1465 aicon
->xindex
, aicon
->yindex
);
1468 aicon
->yindex
= index
;
1479 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1483 wClipRestoreState(WScreen
*scr
, proplist_t clip_state
)
1489 icon
= mainIconCreate(scr
, WM_CLIP
);
1494 PLRetain(clip_state
);
1496 /* restore position */
1498 value
= PLGetDictionaryEntry(clip_state
, dPosition
);
1501 if (!PLIsString(value
))
1502 COMPLAIN("Position");
1504 if (sscanf(PLGetString(value
), "%i,%i", &icon
->x_pos
,
1506 COMPLAIN("Position");
1508 /* check position sanity */
1509 if (icon
->y_pos
< 0)
1511 else if (icon
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1512 icon
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1514 if (icon
->x_pos
< 0)
1516 else if (icon
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1517 icon
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1522 value
= PLGetDictionaryEntry(clip_state
, dDropCommand
);
1523 if (value
&& PLIsString(value
))
1524 icon
->dnd_command
= wstrdup(PLGetString(value
));
1527 PLRelease(clip_state
);
1534 wDockRestoreState(WScreen
*scr
, proplist_t dock_state
, int type
)
1539 WAppIcon
*aicon
, *old_top
;
1543 dock
= wDockCreate(scr
, type
);
1549 PLRetain(dock_state
);
1552 /* restore position */
1554 value
= PLGetDictionaryEntry(dock_state
, dPosition
);
1557 if (!PLIsString(value
))
1558 COMPLAIN("Position");
1560 if (sscanf(PLGetString(value
), "%i,%i", &dock
->x_pos
,
1562 COMPLAIN("Position");
1564 /* check position sanity */
1565 if (dock
->y_pos
< 0)
1567 else if (dock
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1568 dock
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1570 /* This is no more needed. ??? */
1571 if (type
== WM_CLIP
) {
1572 if (dock
->x_pos
< 0)
1574 else if (dock
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1575 dock
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1578 if (dock
->x_pos
>= 0) {
1579 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1580 dock
->on_right_side
= 0;
1582 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1583 dock
->on_right_side
= 1;
1589 /* restore lowered/raised state */
1593 value
= PLGetDictionaryEntry(dock_state
, dLowered
);
1596 if (!PLIsString(value
))
1597 COMPLAIN("Lowered");
1599 if (strcasecmp(PLGetString(value
), "YES")==0)
1605 /* restore collapsed state */
1607 dock
->collapsed
= 0;
1609 value
= PLGetDictionaryEntry(dock_state
, dCollapsed
);
1612 if (!PLIsString(value
))
1613 COMPLAIN("Collapsed");
1615 if (strcasecmp(PLGetString(value
), "YES")==0)
1616 dock
->collapsed
= 1;
1621 /* restore auto-collapsed state */
1623 value
= PLGetDictionaryEntry(dock_state
, dAutoCollapse
);
1626 if (!PLIsString(value
))
1627 COMPLAIN("AutoCollapse");
1629 if (strcasecmp(PLGetString(value
), "YES")==0) {
1630 dock
->auto_collapse
= 1;
1631 dock
->collapsed
= 1;
1637 /* restore attract icons state */
1639 dock
->attract_icons
= 0;
1641 value
= PLGetDictionaryEntry(dock_state
, dAutoAttractIcons
);
1644 if (!PLIsString(value
))
1645 COMPLAIN("AutoAttractIcons");
1647 if (strcasecmp(PLGetString(value
), "YES")==0)
1648 dock
->attract_icons
= 1;
1653 /* restore keep attracted icons state */
1655 dock
->keep_attracted
= 0;
1657 value
= PLGetDictionaryEntry(dock_state
, dKeepAttracted
);
1660 if (!PLIsString(value
))
1661 COMPLAIN("KeepAttracted");
1663 if (strcasecmp(PLGetString(value
), "YES")==0)
1664 dock
->keep_attracted
= 1;
1669 /* application list */
1671 apps
= PLGetDictionaryEntry(dock_state
, dApplications
);
1677 count
= PLGetNumberOfElements(apps
);
1682 old_top
= dock
->icon_array
[0];
1684 /* dock->icon_count is set to 1 when dock is created.
1685 * Since Clip is already restored, we want to keep it so for clip,
1686 * but for dock we may change the default top tile, so we set it to 0.
1688 if (type
== WM_DOCK
)
1689 dock
->icon_count
= 0;
1691 for (i
=0; i
<count
; i
++) {
1692 if (dock
->icon_count
>= dock
->max_icons
) {
1693 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1697 value
= PLGetArrayElement(apps
, i
);
1698 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1700 dock
->icon_array
[dock
->icon_count
] = aicon
;
1704 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
*ICON_SIZE
);
1705 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
*ICON_SIZE
);
1708 ChangeStackingLevel(aicon
->icon
->core
, WMNormalWindowLevel
);
1710 ChangeStackingLevel(aicon
->icon
->core
, WMDockWindowLevel
);
1712 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
,
1715 if (!dock
->collapsed
)
1716 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1717 wRaiseFrame(aicon
->icon
->core
);
1720 } else if (dock
->icon_count
==0 && type
==WM_DOCK
)
1724 /* if the first icon is not defined, use the default */
1725 if (dock
->icon_array
[0]==NULL
) {
1726 /* update default icon */
1727 old_top
->x_pos
= dock
->x_pos
;
1728 old_top
->y_pos
= dock
->y_pos
;
1730 ChangeStackingLevel(old_top
->icon
->core
, WMNormalWindowLevel
);
1732 ChangeStackingLevel(old_top
->icon
->core
, WMDockWindowLevel
);
1733 dock
->icon_array
[0] = old_top
;
1734 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1735 /* we don't need to increment dock->icon_count here because it was
1736 * incremented in the loop above.
1738 } else if (old_top
!=dock
->icon_array
[0]) {
1739 if (old_top
== scr
->clip_icon
)
1740 scr
->clip_icon
= dock
->icon_array
[0];
1741 wAppIconDestroy(old_top
);
1746 PLRelease(dock_state
);
1754 wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1756 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1758 btn
->drop_launch
= 0;
1760 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1763 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1775 wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1781 for (i
=0; i
< dock
->max_icons
; i
++) {
1782 btn
= dock
->icon_array
[i
];
1783 if (!btn
|| !btn
->auto_launch
)
1786 state
= wmalloc(sizeof(WSavedState
));
1787 memset(state
, 0, sizeof(WSavedState
));
1788 state
->workspace
= workspace
;
1789 /* TODO: this is klugy and is very difficult to understand
1790 * what's going on. Try to clean up */
1791 wDockLaunchWithState(dock
, btn
, state
);
1795 #ifdef REDUCE_APPICONS
1797 wDockSimulateLaunch(WDock
*dock
, WAppIcon
*btn
)
1799 if ((btn
== NULL
) || (dock
== NULL
))
1802 if (!btn
->running
) {
1803 if ((btn
->icon
->owner
== NULL
) && (btn
->applist
))
1804 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
1805 if (!btn
->forced_dock
)
1815 findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1821 if ((dock
= scr
->dock
)!=NULL
) {
1822 for (i
=0; i
<dock
->max_icons
; i
++) {
1823 if (dock
->icon_array
[i
]
1824 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1830 if (*icon_pos
<0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
)!=NULL
) {
1831 for (i
=0; i
<dock
->max_icons
; i
++) {
1832 if (dock
->icon_array
[i
]
1833 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1846 wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
1852 dock
= findDock(scr
, event
, &icon_pos
);
1857 * Return True if the drop was on an application icon window.
1858 * In this case, let the ClientMessage handler redirect the
1859 * message to the app.
1861 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!=None
)
1864 if (dock
->icon_array
[icon_pos
]->dnd_command
!=NULL
) {
1865 scr
->flags
.dnd_data_convertion_status
= 0;
1867 btn
= dock
->icon_array
[icon_pos
];
1869 if (!btn
->forced_dock
) {
1870 btn
->relaunching
= btn
->running
;
1873 if (btn
->wm_instance
|| btn
->wm_class
) {
1874 WWindowAttributes attr
;
1875 memset(&attr
, 0, sizeof(WWindowAttributes
));
1876 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
1878 btn
->wm_class
, &attr
, True
);
1880 if (!attr
.no_appicon
)
1886 btn
->drop_launch
= 1;
1887 scr
->last_dock
= dock
;
1888 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1893 if (!btn
->relaunching
) {
1900 #endif /* OFFIX_DND */
1905 wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1912 wwin
= icon
->icon
->owner
;
1913 if (icon
->command
==NULL
) {
1915 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
1917 icon
->command
= FlattenStringList(argv
, argc
);
1918 XFreeStringList(argv
);
1922 /* icon->forced_dock = 1;*/
1923 if (!icon
->attracted
|| dock
->type
!=WM_CLIP
|| dock
->keep_attracted
) {
1925 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
1926 _("Type the command used to launch the application"),
1927 &command
)==WDB_OK
) {
1928 if (command
&& (command
[0]==0 ||
1929 (command
[0]=='-' && command
[1]==0))) {
1933 icon
->command
= command
;
1939 /* If the target is the dock, reject the icon. If
1940 * the target is the clip, make it an attracted icon
1942 if (dock
->type
==WM_CLIP
) {
1943 icon
->attracted
= 1;
1944 if (!icon
->icon
->shadowed
) {
1945 icon
->icon
->shadowed
= 1;
1946 icon
->icon
->force_paint
= 1;
1958 for (index
=1; index
<dock
->max_icons
; index
++)
1959 if (dock
->icon_array
[index
] == NULL
)
1961 /* if (index == dock->max_icons)
1964 assert(index
< dock
->max_icons
);
1966 dock
->icon_array
[index
] = icon
;
1970 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
1971 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
1976 icon
->launching
= 0;
1979 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1980 if (dock
->type
== WM_CLIP
) {
1981 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1982 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1984 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1985 icon
->icon
->core
->descriptor
.parent
= icon
;
1987 MoveInStackListUnder(dock
->icon_array
[index
-1]->icon
->core
,
1989 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
1990 wAppIconPaint(icon
);
1992 if (wPreferences
.auto_arrange_icons
)
1993 wArrangeIcons(dock
->screen_ptr
, True
);
2000 reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2004 for(index
=1; index
<dock
->max_icons
; index
++) {
2005 if(dock
->icon_array
[index
] == icon
)
2008 assert(index
< dock
->max_icons
);
2013 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2014 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2019 moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2029 wwin
= icon
->icon
->owner
;
2032 * For the moment we can't do this if we move icons in Clip from one
2033 * workspace to other, because if we move two or more icons without
2034 * command, the dialog box will not be able to tell us to which of the
2035 * moved icons it applies. -Dan
2037 if ((dest
->type
==WM_DOCK
/*|| dest->keep_attracted*/) && icon
->command
==NULL
) {
2038 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2040 icon
->command
= FlattenStringList(argv
, argc
);
2041 XFreeStringList(argv
);
2046 /* icon->forced_dock = 1;*/
2047 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2048 _("Type the command used to launch the application"),
2049 &command
)==WDB_OK
) {
2050 if (command
&& (command
[0]==0 ||
2051 (command
[0]=='-' && command
[1]==0))) {
2055 icon
->command
= command
;
2066 for(index
=1; index
<src
->max_icons
; index
++) {
2067 if(src
->icon_array
[index
] == icon
)
2070 assert(index
< src
->max_icons
);
2072 src
->icon_array
[index
] = NULL
;
2075 for(index
=1; index
<dest
->max_icons
; index
++) {
2076 if(dest
->icon_array
[index
] == NULL
)
2079 /* if (index == dest->max_icons)
2082 assert(index
< dest
->max_icons
);
2084 dest
->icon_array
[index
] = icon
;
2087 /* deselect the icon */
2088 if (icon
->icon
->selected
)
2089 wIconSelect(icon
->icon
);
2091 if (dest
->type
== WM_DOCK
) {
2092 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2093 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2095 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2096 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2099 /* set it to be kept when moving to dock, or to a clip that keep the
2101 * Unless the icon does not have a command set
2103 if (icon
->command
&& (dest
->type
==WM_DOCK
|| dest
->keep_attracted
)) {
2104 icon
->attracted
= 0;
2105 if (icon
->icon
->shadowed
) {
2106 icon
->icon
->shadowed
= 0;
2107 icon
->icon
->force_paint
= 1;
2111 if (src
->auto_collapse
)
2117 icon
->x_pos
= dest
->x_pos
+ x
*ICON_SIZE
;
2118 icon
->y_pos
= dest
->y_pos
+ y
*ICON_SIZE
;
2122 MoveInStackListUnder(dest
->icon_array
[index
-1]->icon
->core
,
2124 wAppIconPaint(icon
);
2130 wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2134 /* make the settings panel be closed */
2136 DestroyDockAppSettingsPanel(icon
->panel
);
2141 icon
->attracted
= 0;
2142 if (icon
->icon
->shadowed
) {
2143 icon
->icon
->shadowed
= 0;
2144 icon
->icon
->force_paint
= 1;
2147 /* deselect the icon */
2148 if (icon
->icon
->selected
)
2149 wIconSelect(icon
->icon
);
2151 if (icon
->command
) {
2152 free(icon
->command
);
2153 icon
->command
= NULL
;
2156 if (icon
->dnd_command
) {
2157 free(icon
->dnd_command
);
2158 icon
->dnd_command
= NULL
;
2162 for (index
=1; index
<dock
->max_icons
; index
++)
2163 if (dock
->icon_array
[index
] == icon
)
2165 assert(index
< dock
->max_icons
);
2166 dock
->icon_array
[index
] = NULL
;
2171 /* if the dock is not attached to an application or
2172 * the the application did not set the approriate hints yet,
2173 * destroy the icon */
2174 #ifdef REDUCE_APPICONS
2175 if ((icon
->num_apps
== 0) && (!icon
->running
|| !wApplicationOf(icon
->main_window
)) )
2177 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2179 wAppIconDestroy(icon
);
2181 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2182 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2183 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2184 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2185 icon
->icon
->core
->descriptor
.parent
= icon
;
2186 ChangeStackingLevel(icon
->icon
->core
, WMNormalWindowLevel
);
2187 wAppIconPaint(icon
);
2188 if (wPreferences
.auto_arrange_icons
) {
2189 wArrangeIcons(dock
->screen_ptr
, True
);
2192 if (dock
->auto_collapse
)
2198 * returns the closest Dock slot index for the passed
2201 * Returns False if icon can't be docked.
2204 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2205 int *ret_x
, int *ret_y
, int redocking
)
2207 WScreen
*scr
= dock
->screen_ptr
;
2210 int i
, offset
= ICON_SIZE
/2;
2211 WAppIcon
*aicon
= NULL
;
2212 WAppIcon
*nicon
= NULL
;
2218 /* if the dock is full */
2220 (dock
->icon_count
>= dock
->max_icons
)) {
2224 /* exact position */
2226 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2228 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2231 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2233 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2235 /* check if the icon is outside the screen boundaries */
2236 if (dx
+ ex_x
*ICON_SIZE
< -ICON_SIZE
+2 ||
2237 dx
+ ex_x
*ICON_SIZE
> scr
->scr_width
-1 ||
2238 dy
+ ex_y
*ICON_SIZE
< -ICON_SIZE
+2 ||
2239 dy
+ ex_y
*ICON_SIZE
> scr
->scr_height
-1)
2242 if (dock
->type
== WM_DOCK
) {
2243 for (i
=0; i
<dock
->max_icons
; i
++) {
2244 nicon
= dock
->icon_array
[i
];
2245 if (nicon
&& nicon
->yindex
== ex_y
) {
2254 int sig
, done
, closest
;
2256 /* Possible cases when redocking:
2258 * icon dragged out of range of any slot -> false
2259 * icon dragged to range of free slot
2260 * icon dragged to range of same slot
2261 * icon dragged to range of different icon
2263 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2266 if (ex_y
>=0 && (aicon
== icon
|| !aicon
)) {
2273 /* start looking at the upper slot or lower? */
2274 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2281 /* look for closest free slot */
2282 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2286 closest
= sig
*(i
/2) + ex_y
;
2287 /* check if this slot is used */
2289 for (j
= 0; j
<dock
->max_icons
; j
++) {
2290 if (dock
->icon_array
[j
]
2291 && dock
->icon_array
[j
]->yindex
==closest
) {
2292 /* slot is used by someone else */
2293 if (dock
->icon_array
[j
]!=icon
)
2301 if (done
&& closest
>= 0 &&
2302 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2304 (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+1))) {
2310 } else { /* !redocking */
2312 /* if slot is free and the icon is close enough, return it */
2313 if (!aicon
&& ex_x
==0 && ex_y
>=0) {
2321 for (i
=0; i
<dock
->max_icons
; i
++) {
2322 nicon
= dock
->icon_array
[i
];
2323 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2329 for (i
=0; i
<dock
->max_icons
; i
++) {
2330 nicon
= dock
->icon_array
[i
];
2331 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2332 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2333 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2338 if ((!redocking
&& neighbours
&& !aicon
) ||
2339 (redocking
&& neighbours
&& (aicon
== icon
|| !aicon
))) {
2348 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2349 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2351 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2352 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2353 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2357 * returns true if it can find a free slot in the dock,
2358 * in which case it changes x_pos and y_pos accordingly.
2359 * Else returns false.
2362 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2364 WScreen
*scr
= dock
->screen_ptr
;
2366 unsigned char *slot_map
;
2370 int i
, done
= False
;
2372 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2374 /* if the dock is full */
2375 if (dock
->icon_count
>= dock
->max_icons
) {
2379 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2380 if (scr
->dock
->on_right_side
)
2381 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2383 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2386 if (ex
< dock
->x_pos
)
2388 if (sx
> dock
->x_pos
+ICON_SIZE
)
2389 sx
= dock
->x_pos
+ICON_SIZE
;
2396 /* check if clip is in a corner */
2397 if (dock
->type
==WM_CLIP
) {
2398 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2400 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2402 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2404 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2411 /* If the clip is in the corner, use only slots that are in the border
2413 if (corner
!=C_NONE
) {
2417 hcount
= MIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2418 vcount
= MIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2419 hmap
= wmalloc(hcount
+1);
2420 memset(hmap
, 0, hcount
+1);
2421 vmap
= wmalloc(vcount
+1);
2422 memset(vmap
, 0, vcount
+1);
2424 /* mark used positions */
2427 for (i
=0; i
<dock
->max_icons
; i
++) {
2428 btn
= dock
->icon_array
[i
];
2432 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2433 vmap
[btn
->yindex
] = 1;
2434 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2435 hmap
[btn
->xindex
] = 1;
2438 for (i
=0; i
<dock
->max_icons
; i
++) {
2439 btn
= dock
->icon_array
[i
];
2443 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2444 vmap
[btn
->yindex
] = 1;
2445 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2446 hmap
[-btn
->xindex
] = 1;
2449 for (i
=0; i
<dock
->max_icons
; i
++) {
2450 btn
= dock
->icon_array
[i
];
2454 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2455 vmap
[-btn
->yindex
] = 1;
2456 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2457 hmap
[btn
->xindex
] = 1;
2461 for (i
=0; i
<dock
->max_icons
; i
++) {
2462 btn
= dock
->icon_array
[i
];
2466 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2467 vmap
[-btn
->yindex
] = 1;
2468 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2469 hmap
[-btn
->xindex
] = 1;
2474 /* search a vacant slot */
2475 for (i
=1; i
<MAX(vcount
, hcount
); i
++) {
2476 if (i
< vcount
&& vmap
[i
]==0) {
2482 } else if (i
< hcount
&& hmap
[i
]==0) {
2492 /* If found a slot, translate and return */
2494 if (corner
==C_NW
|| corner
==C_NE
) {
2499 if (corner
==C_NE
|| corner
==C_SE
) {
2506 /* else, try to find a slot somewhere else */
2509 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2510 * placed outside of screen */
2511 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2513 /* In the worst case (the clip is in the corner of the screen),
2514 * the amount of icons that fit in the clip is smaller.
2515 * Double the map to get a safe value.
2521 slot_map
= wmalloc(mwidth
*mwidth
);
2522 memset(slot_map
, 0, mwidth
*mwidth
);
2524 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2526 /* mark used slots in the map. If the slot falls outside the map
2527 * (for example, when all icons are placed in line), ignore them. */
2528 for (i
=0; i
<dock
->max_icons
; i
++) {
2529 btn
= dock
->icon_array
[i
];
2531 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2533 /* Find closest slot from the center that is free by scanning the
2534 * map from the center to outward in circular passes.
2535 * This will not result in a neat layout, but will be optimal
2536 * in the sense that there will not be holes left.
2539 for (i
= 1; i
<= r
&& !done
; i
++) {
2542 /* top and bottom parts of the ring */
2543 for (x
= -i
; x
<= i
&& !done
; x
++) {
2544 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2546 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2547 if (slot_map
[XY2OFS(x
,y
)]==0
2548 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2555 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2556 if (slot_map
[XY2OFS(x
,y
)]==0
2557 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2564 /* left and right parts of the ring */
2565 for (y
= -i
+1; y
<= i
-1; y
++) {
2566 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2568 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2569 if (slot_map
[XY2OFS(x
,y
)]==0
2570 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2577 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2578 if (slot_map
[XY2OFS(x
,y
)]==0
2579 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2594 moveDock(WDock
*dock
, int new_x
, int new_y
)
2599 dock
->x_pos
= new_x
;
2600 dock
->y_pos
= new_y
;
2601 for (i
=0; i
<dock
->max_icons
; i
++) {
2602 btn
= dock
->icon_array
[i
];
2604 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2605 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2606 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2613 swapDock(WDock
*dock
)
2615 WScreen
*scr
= dock
->screen_ptr
;
2620 if (dock
->on_right_side
) {
2621 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2623 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2626 for (i
=0; i
<dock
->max_icons
; i
++) {
2627 btn
= dock
->icon_array
[i
];
2630 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2637 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2639 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2645 cmdline
= ExpandOptions(scr
, command
);
2647 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2655 ParseCommand(cmdline
, &argv
, &argc
);
2665 if ((pid
=fork())==0) {
2669 SetupEnvironment(scr
);
2671 close(ConnectionNumber(dpy
));
2677 args
= malloc(sizeof(char*)*(argc
+1));
2680 for (i
=0; i
<argc
; i
++) {
2684 execvp(argv
[0], args
);
2693 state
= wmalloc(sizeof(WSavedState
));
2694 memset(state
, 0, sizeof(WSavedState
));
2696 state
->miniaturized
= -1;
2698 if (btn
->dock
== scr
->dock
)
2699 state
->workspace
= -1;
2701 state
->workspace
= scr
->current_workspace
;
2703 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
2705 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
2716 wDockHideIcons(WDock
*dock
)
2724 btn
= dock
->icon_array
[0];
2726 for (i
=1; i
<dock
->max_icons
; i
++) {
2727 if (dock
->icon_array
[i
])
2728 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2737 wDockShowIcons(WDock
*dock
)
2745 btn
= dock
->icon_array
[0];
2746 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2748 newlevel
= dock
->lowered
? WMNormalWindowLevel
: WMDockWindowLevel
;
2749 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2751 for (i
=1; i
<dock
->max_icons
; i
++) {
2752 if (dock
->icon_array
[i
]) {
2753 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
2759 if (!dock
->collapsed
) {
2760 for (i
=1; i
<dock
->max_icons
; i
++) {
2761 if (dock
->icon_array
[i
]) {
2762 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2773 wDockLower(WDock
*dock
)
2777 for (i
=0; i
<dock
->max_icons
; i
++) {
2778 if (dock
->icon_array
[i
])
2779 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2785 wDockRaise(WDock
*dock
)
2789 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
2790 if (dock
->icon_array
[i
])
2791 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2797 wDockRaiseLower(WDock
*dock
)
2799 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2800 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2801 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2809 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
2811 icon
->launching
= 0;
2812 icon
->relaunching
= 0;
2813 dockIconPaint(icon
);
2818 wDockFindIconFor(WDock
*dock
, Window window
)
2823 for (i
=0; i
<dock
->max_icons
; i
++) {
2824 icon
= dock
->icon_array
[i
];
2825 if (icon
&& icon
->main_window
== window
)
2833 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
2836 #ifdef REDUCE_APPICONS
2837 WAppIconAppList
*tapplist
;
2839 char *wm_class
, *wm_instance
;
2843 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
2844 (!wm_class
&& !wm_instance
))
2847 for (i
=0; i
<dock
->max_icons
; i
++) {
2848 icon
= dock
->icon_array
[i
];
2852 /* kluge. If this does not exist, some windows attach themselves
2853 * to more than one icon. Find out why */
2854 if (icon
->main_window
== window
) {
2857 if ((icon
->wm_instance
|| icon
->wm_class
)
2859 || (dock
->screen_ptr
->flags
.startup
&& !icon
->running
))) {
2861 if (icon
->wm_instance
&& wm_instance
&&
2862 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
2865 if (icon
->wm_class
&& wm_class
&&
2866 strcmp(icon
->wm_class
, wm_class
)!=0) {
2870 if (!icon
->relaunching
) {
2873 /* Possibly an application that was docked with dockit,
2874 * but the user did not update WMState to indicate that
2875 * it was docked by force */
2876 wapp
= wApplicationOf(window
);
2878 icon
->forced_dock
= 1;
2881 if (!icon
->forced_dock
)
2882 icon
->main_window
= window
;
2883 #ifdef REDUCE_APPICONS
2884 tapplist
= wmalloc(sizeof(WAppIconAppList
));
2885 memset(tapplist
, 0, sizeof(WAppIconAppList
));
2886 tapplist
->next
= icon
->applist
;
2888 icon
->applist
->prev
= tapplist
;
2889 icon
->applist
= tapplist
;
2890 tapplist
->wapp
= wApplicationOf(window
);
2894 wDockFinishLaunch(dock
, icon
);
2908 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
2910 if (!wPreferences
.flags
.noclip
) {
2911 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
2912 if (scr
->current_workspace
!= workspace
) {
2913 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
2915 wDockHideIcons(old_clip
);
2916 if (old_clip
->auto_collapse
&& !old_clip
->collapsed
)
2917 old_clip
->collapsed
= 1;
2918 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
2920 if (scr
->flags
.clip_balloon_mapped
)
2921 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
2928 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
2933 for (i
=0; i
<dock
->max_icons
; i
++) {
2934 icon
= dock
->icon_array
[i
];
2938 if (icon
->launching
&& icon
->pid
== pid
) {
2939 if (!icon
->relaunching
) {
2941 icon
->main_window
= None
;
2943 wDockFinishLaunch(dock
, icon
);
2948 sprintf(msg
, _("Could not execute command \"%s\""),
2949 icon
->drop_launch
&& icon
->dnd_command
2950 ? icon
->dnd_command
: icon
->command
);
2952 sprintf(msg
, _("Could not execute command \"%s\""),
2955 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
2956 _("OK"), NULL
, NULL
);
2965 toggleLowered(WDock
*dock
)
2970 /* lower/raise Dock */
2971 if (!dock
->lowered
) {
2972 newlevel
= WMNormalWindowLevel
;
2975 newlevel
= WMDockWindowLevel
;
2979 for (i
=0; i
<dock
->max_icons
; i
++) {
2980 tmp
= dock
->icon_array
[i
];
2984 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
2986 wLowerFrame(tmp
->icon
->core
);
2992 toggleCollapsed(WDock
*dock
)
2994 if (dock
->collapsed
) {
2995 dock
->collapsed
= 0;
2996 wDockShowIcons(dock
);
2999 dock
->collapsed
= 1;
3000 wDockHideIcons(dock
);
3006 toggleAutoCollapse(WDock
*dock
)
3008 dock
->auto_collapse
= !dock
->auto_collapse
;
3009 if (dock
->auto_collapse_magic
) {
3010 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3011 dock
->auto_collapse_magic
= NULL
;
3017 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3019 WScreen
*scr
= dock
->screen_ptr
;
3020 WObjDescriptor
*desc
;
3024 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3026 if (dock
->type
== WM_DOCK
) {
3028 entry
= dock
->menu
->entries
[index
];
3029 entry
->flags
.indicator_on
= !dock
->lowered
;
3030 entry
->clientdata
= dock
;
3033 if (scr
->clip_options
)
3034 updateClipOptionsMenu(scr
->clip_options
, dock
);
3036 /* Rename Workspace */
3037 entry
= dock
->menu
->entries
[++index
];
3038 entry
->clientdata
= dock
;
3041 entry
= dock
->menu
->entries
[++index
];
3042 entry
->clientdata
= aicon
;
3043 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3045 /* (un)select all icons */
3046 entry
= dock
->menu
->entries
[++index
];
3047 entry
->clientdata
= aicon
;
3048 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3051 entry
= dock
->menu
->entries
[++index
];
3052 entry
->clientdata
= aicon
;
3053 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3055 /* this is the workspace submenu part */
3056 if (scr
->clip_submenu
)
3057 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3060 /* remove icon(s) */
3061 entry
= dock
->menu
->entries
[++index
];
3062 entry
->clientdata
= aicon
;
3063 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3065 /* attract icon(s) */
3066 entry
= dock
->menu
->entries
[++index
];
3067 entry
->clientdata
= aicon
;
3071 entry
= dock
->menu
->entries
[++index
];
3072 entry
->clientdata
= aicon
;
3073 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3076 entry
= dock
->menu
->entries
[++index
];
3077 entry
->clientdata
= aicon
;
3078 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3081 entry
= dock
->menu
->entries
[++index
];
3082 entry
->clientdata
= aicon
;
3083 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3086 entry
= dock
->menu
->entries
[++index
];
3087 entry
->clientdata
= aicon
;
3088 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
);
3091 entry
= dock
->menu
->entries
[++index
];
3092 entry
->clientdata
= aicon
;
3093 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3095 if (!dock
->menu
->flags
.realized
)
3096 wMenuRealize(dock
->menu
);
3098 if (dock
->type
== WM_CLIP
) {
3099 x_pos
= event
->xbutton
.x_root
+2;
3101 x_pos
= dock
->on_right_side
?
3102 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 2 : 0;
3105 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3107 /* allow drag select */
3108 event
->xany
.send_event
= True
;
3109 desc
= &dock
->menu
->menu
->descriptor
;
3110 (*desc
->handle_mousedown
)(desc
, event
);
3115 openClipWorkspaceMenu(WScreen
*scr
, int x
, int y
)
3117 if (!scr
->clip_ws_menu
) {
3118 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3120 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
3121 wMenuMapAt(scr
->clip_ws_menu
, x
, y
, False
);
3125 /******************************************************************/
3127 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3129 WAppIcon
*btn
= desc
->parent
;
3130 WDock
*dock
= btn
->dock
;
3131 WApplication
*wapp
= NULL
;
3134 #ifdef REDUCE_APPICONS
3135 if ((btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) ||
3136 ((btn
->icon
->owner
== NULL
) && (btn
->applist
!= NULL
))) {
3137 if (btn
->icon
->owner
== NULL
)
3138 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
3143 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3145 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3149 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3151 /* go to the last workspace that the user worked on the app */
3153 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3156 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3159 if (event
->xbutton
.state
& MOD_MASK
) {
3160 wHideOtherApplications(btn
->icon
->owner
);
3163 if (event
->xbutton
.button
==Button1
) {
3165 if (event
->xbutton
.state
& MOD_MASK
) {
3166 /* raise/lower dock */
3167 toggleLowered(dock
);
3168 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3169 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3170 toggleCollapsed(dock
);
3172 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3173 } else if (btn
->command
) {
3174 if (!btn
->launching
&&
3175 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3176 launchDockedApplication(btn
);
3185 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3187 WScreen
*scr
= dock
->screen_ptr
;
3188 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3191 int grabbed
= 0, swapped
= 0, done
;
3192 Pixmap ghost
= None
;
3193 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3196 puts("moving dock");
3198 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3199 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3200 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3201 wwarning("pointer grab failed for dock move");
3204 for (x
=0; x
<dock
->max_icons
; x
++) {
3205 if (dock
->icon_array
[x
]!=NULL
&&
3206 dock
->icon_array
[x
]->yindex
> y
)
3207 y
= dock
->icon_array
[x
]->yindex
;
3210 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3214 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3215 |ButtonMotionMask
|ExposureMask
, &ev
);
3223 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3224 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3225 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3226 |ButtonReleaseMask
|ButtonPressMask
,
3227 wCursor
[WCUR_MOVE
], CurrentTime
);
3232 if (dock
->type
== WM_CLIP
) {
3233 if (ev
.xmotion
.x_root
- ofs_x
< 0) {
3235 } else if (ev
.xmotion
.x_root
- ofs_x
+ ICON_SIZE
>
3237 x
= scr
->scr_width
- ICON_SIZE
;
3239 x
= ev
.xmotion
.x_root
- ofs_x
;
3241 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3243 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3245 y
= scr
->scr_height
- ICON_SIZE
;
3247 y
= ev
.xmotion
.y_root
- ofs_y
;
3249 moveDock(dock
, x
, y
);
3252 /* move vertically if pointer is inside the dock*/
3253 if ((dock
->on_right_side
&&
3254 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3255 || (!dock
->on_right_side
&&
3256 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3258 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3260 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3262 y
= scr
->scr_height
- ICON_SIZE
;
3264 y
= ev
.xmotion
.y_root
- ofs_y
;
3266 moveDock(dock
, dock
->x_pos
, y
);
3268 /* move horizontally to change sides */
3269 x
= ev
.xmotion
.x_root
- ofs_x
;
3270 if (!dock
->on_right_side
) {
3274 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3275 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3276 -DOCK_EXTRA_SPACE
, dock
->y_pos
);
3279 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3280 scr
->scr_width
-ICON_SIZE
3283 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3285 XClearWindow(dpy
, scr
->dock_shadow
);
3288 XMapRaised(dpy
, scr
->dock_shadow
);
3291 if (superfluous
&& ghost
!=None
) {
3292 XFreePixmap(dpy
, ghost
);
3295 XUnmapWindow(dpy
, scr
->dock_shadow
);
3300 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3301 XMoveWindow(dpy
, scr
->dock_shadow
,
3302 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3305 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3306 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3307 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3309 XClearWindow(dpy
, scr
->dock_shadow
);
3312 XMapRaised(dpy
, scr
->dock_shadow
);
3315 XUnmapWindow(dpy
, scr
->dock_shadow
);
3317 if (superfluous
&& ghost
!=None
) {
3318 XFreePixmap(dpy
, ghost
);
3330 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3332 XUngrabPointer(dpy
, CurrentTime
);
3333 XUnmapWindow(dpy
, scr
->dock_shadow
);
3334 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3335 if (dock
->type
== WM_DOCK
) {
3338 dock
->on_right_side
= 1;
3340 dock
->on_right_side
= 0;
3342 wArrangeIcons(scr
, False
);
3351 XFreePixmap(dpy
, ghost
);
3352 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3355 puts("End dock move");
3362 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3364 WScreen
*scr
= dock
->screen_ptr
;
3366 WIcon
*icon
= aicon
->icon
;
3367 WDock
*dock2
= NULL
, *last_dock
= dock
;
3368 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3370 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3371 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3372 int shad_x
= x
, shad_y
= y
;
3373 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3375 Pixmap ghost
= None
;
3377 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3379 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3380 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3381 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3383 wwarning("pointer grab failed for icon move");
3387 wRaiseFrame(icon
->core
);
3389 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3390 dock2
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3391 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3394 wins
[0] = icon
->core
->window
;
3395 wins
[1] = scr
->dock_shadow
;
3396 XRestackWindows(dpy
, wins
, 2);
3397 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3398 ICON_SIZE
, ICON_SIZE
);
3400 if (icon
->pixmap
!=None
)
3401 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3403 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3405 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3406 XClearWindow(dpy
, scr
->dock_shadow
);
3408 XMapWindow(dpy
, scr
->dock_shadow
);
3414 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3415 |ButtonMotionMask
|ExposureMask
, &ev
);
3423 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3424 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3425 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3426 |ButtonReleaseMask
|ButtonPressMask
,
3427 wCursor
[WCUR_MOVE
], CurrentTime
);
3434 x
= ev
.xmotion
.x_root
- ofs_x
;
3435 y
= ev
.xmotion
.y_root
- ofs_y
;
3436 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3439 if (last_dock
!= dock
&& collapsed
) {
3440 last_dock
->collapsed
= 1;
3441 wDockHideIcons(last_dock
);
3444 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3445 dock
->collapsed
= 0;
3446 wDockShowIcons(dock
);
3451 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3454 if (last_dock
!= dock2
&& collapsed
) {
3455 last_dock
->collapsed
= 1;
3456 wDockHideIcons(last_dock
);
3459 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3460 dock2
->collapsed
= 0;
3461 wDockShowIcons(dock2
);
3466 if (aicon
->launching
3467 || (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3468 || (!aicon
->running
&& tmp
)) {
3469 shad_x
= last_dock
->x_pos
+ ix
*wPreferences
.icon_size
;
3470 shad_y
= last_dock
->y_pos
+ iy
*wPreferences
.icon_size
;
3472 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3475 XMapWindow(dpy
, scr
->dock_shadow
);
3477 if (!collapsed
&& (collapsed
= last_dock
->collapsed
)) {
3478 last_dock
->collapsed
= 0;
3479 wDockShowIcons(last_dock
);
3486 XUnmapWindow(dpy
, scr
->dock_shadow
);
3488 if (last_dock
&& collapsed
&&
3489 aicon
->running
&& (ev
.xmotion
.state
& MOD_MASK
)) {
3490 last_dock
->collapsed
= 1;
3491 wDockHideIcons(last_dock
);
3498 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3505 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3507 XUngrabPointer(dpy
, CurrentTime
);
3509 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3510 XUnmapWindow(dpy
, scr
->dock_shadow
);
3512 reattachIcon(dock
, aicon
, ix
, iy
);
3514 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3516 /* Slide it back if dock rejected it */
3517 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3519 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3521 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3529 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3530 /* We need to deselect it, even if is deselected in
3531 * wDockDetach(), because else DoKaboom() will fail.
3533 if (aicon
->icon
->selected
)
3534 wIconSelect(aicon
->icon
);
3535 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3538 wDockDetach(dock
, aicon
);
3541 last_dock
->collapsed
= 1;
3542 wDockHideIcons(last_dock
);
3547 XFreePixmap(dpy
, ghost
);
3548 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3551 puts("End icon move");
3560 getClipButton(int px
, int py
)
3562 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
3564 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3567 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
3568 return CLIP_FORWARD
;
3569 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
3577 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3580 int done
, direction
, new_ws
;
3582 WDock
*clip
= scr
->clip_icon
->dock
;
3584 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3586 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3587 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3589 wClipIconPaint(scr
->clip_icon
);
3592 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
3593 |ButtonPressMask
, &ev
);
3600 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3601 if (new_dir
!= direction
) {
3602 direction
= new_dir
;
3603 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3604 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3605 wClipIconPaint(scr
->clip_icon
);
3613 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3618 clip
->lclip_button_pushed
= 0;
3619 clip
->rclip_button_pushed
= 0;
3621 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3623 if (direction
== CLIP_FORWARD
) {
3624 if (scr
->current_workspace
< scr
->workspace_count
-1)
3625 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3626 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
3627 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3628 else if (wPreferences
.ws_cycle
)
3629 wWorkspaceChange(scr
, 0);
3631 else if (direction
== CLIP_REWIND
) {
3632 if (scr
->current_workspace
> 0)
3633 wWorkspaceChange(scr
, scr
->current_workspace
-1);
3634 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
3635 wWorkspaceChange(scr
, scr
->workspace_count
-1);
3638 wClipIconPaint(scr
->clip_icon
);
3643 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3645 WAppIcon
*aicon
= desc
->parent
;
3646 WDock
*dock
= aicon
->dock
;
3647 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3652 scr
->last_dock
= dock
;
3654 if (dock
->menu
->flags
.mapped
)
3655 wMenuUnmap(dock
->menu
);
3657 if (IsDoubleClick(scr
, event
)) {
3658 /* double-click was not in the main clip icon */
3659 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
3660 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
3661 iconDblClick(desc
, event
);
3666 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
3667 XUnmapWindow(dpy
, scr
->clip_balloon
);
3668 scr
->flags
.clip_balloon_mapped
= 0;
3672 puts("handling dock");
3674 if (event
->xbutton
.button
== Button1
) {
3675 if (event
->xbutton
.state
& MOD_MASK
)
3680 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
3681 dock
->type
!=WM_DOCK
) {
3682 wIconSelect(aicon
->icon
);
3686 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
3687 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
3688 && dock
->type
==WM_CLIP
)
3689 handleClipChangeWorkspace(scr
, event
);
3691 handleDockMove(dock
, aicon
, event
);
3693 handleIconMove(dock
, aicon
, event
);
3695 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
3696 aicon
->xindex
==0 && aicon
->yindex
==0) {
3697 openClipWorkspaceMenu(scr
, event
->xbutton
.x_root
+2,
3698 event
->xbutton
.y_root
+2);
3699 if (scr
->clip_ws_menu
) {
3701 menu
= scr
->clip_ws_menu
;
3702 desc
= &menu
->menu
->descriptor
;
3704 event
->xany
.send_event
= True
;
3705 (*desc
->handle_mousedown
)(desc
, event
);
3707 } else if (event
->xbutton
.button
== Button3
) {
3708 openDockMenu(dock
, aicon
, event
);
3714 showClipBalloon(WDock
*dock
, int workspace
)
3718 WScreen
*scr
= dock
->screen_ptr
;
3722 scr
->flags
.clip_balloon_mapped
= 1;
3723 XMapWindow(dpy
, scr
->clip_balloon
);
3725 text
= scr
->workspaces
[workspace
]->name
;
3727 w
= wTextWidth(scr
->clip_title_font
->font
, text
, strlen(text
)) + 4;
3729 h
= scr
->clip_title_font
->height
;
3730 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
3732 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
3733 y
= dock
->y_pos
+ ICON_SIZE
-scr
->clip_title_font
->height
- 3;
3735 if (x
+w
> scr
->scr_width
) {
3736 x
= scr
->scr_width
- w
;
3737 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
3738 y
= dock
->y_pos
- h
- 1;
3740 y
= dock
->y_pos
+ ICON_SIZE
;
3741 XRaiseWindow(dpy
, scr
->clip_balloon
);
3743 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
3744 stack
[1] = scr
->clip_balloon
;
3745 XRestackWindows(dpy
, stack
, 2);
3747 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
3748 XSetForeground(dpy
, scr
->clip_title_gc
,
3749 scr
->clip_title_pixel
[CLIP_NORMAL
]);
3750 XClearWindow(dpy
, scr
->clip_balloon
);
3751 wDrawString(scr
->clip_balloon
, scr
->clip_title_font
, scr
->clip_title_gc
,
3752 0, scr
->clip_title_font
->y
, text
, strlen(text
));
3757 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3759 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
3762 assert(event
->type
==EnterNotify
);
3764 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
3768 if (!dock
|| dock
->type
!=WM_CLIP
)
3771 if (btn
->xindex
== 0 && btn
->yindex
== 0)
3772 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
3774 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
3775 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
3776 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
3779 if (!dock
->auto_collapse
)
3782 if (dock
->auto_collapse_magic
) {
3783 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3784 dock
->auto_collapse_magic
= NULL
;
3787 if (dock
->collapsed
)
3788 toggleCollapsed(dock
);
3793 clipLeave(WDock
*dock
)
3795 if (!dock
|| dock
->type
!=WM_CLIP
|| !dock
->auto_collapse
)
3798 if (dock
->auto_collapse_magic
) {
3799 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3800 dock
->auto_collapse_magic
= NULL
;
3802 if (!dock
->collapsed
) {
3803 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
3811 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
3813 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
3815 assert(event
->type
==LeaveNotify
);
3817 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
3820 clipLeave(btn
->dock
);
3825 clipAutoCollapse(void *cdata
)
3827 WDock
*dock
= (WDock
*)cdata
;
3829 if (dock
->type
!=WM_CLIP
|| !dock
->auto_collapse
)
3832 if (!dock
->collapsed
&& dock
->auto_collapse_magic
!=NULL
) {
3833 toggleCollapsed(dock
);
3835 dock
->auto_collapse_magic
= NULL
;