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 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 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 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1210 name
= PLMakeString(tmp
);
1214 forced
= btn
->forced_dock
? dYes
: dNo
;
1216 buggy
= btn
->buggy_app
? dYes
: dNo
;
1218 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1219 sprintf(buffer
, "%i,%i", btn
->x_pos
, btn
->y_pos
);
1221 sprintf(buffer
, "%hi,%hi", btn
->xindex
, btn
->yindex
);
1222 position
= PLMakeString(buffer
);
1224 node
= PLMakeDictionaryFromEntries(dCommand
, command
,
1226 dAutoLaunch
, autolaunch
,
1228 dBuggyApplication
, buggy
,
1229 dPosition
, position
,
1233 PLRelease(position
);
1235 if (btn
->dnd_command
) {
1236 command
= PLMakeString(btn
->dnd_command
);
1237 PLInsertDictionaryEntry(node
, dDropCommand
, command
);
1240 #endif /* OFFIX_DND */
1242 if (btn
->client_machine
&& btn
->remote_start
) {
1243 host
= PLMakeString(btn
->client_machine
);
1244 PLInsertDictionaryEntry(node
, dHost
, host
);
1254 dockSaveState(WDock
*dock
)
1257 proplist_t icon_info
;
1258 proplist_t list
=NULL
, dock_state
=NULL
;
1262 list
= PLMakeArrayFromElements(NULL
);
1264 for (i
=(dock
->type
==WM_DOCK
? 0 : 1); i
<dock
->max_icons
; i
++) {
1265 WAppIcon
*btn
= dock
->icon_array
[i
];
1267 if (!btn
|| (btn
->attracted
&& !dock
->keep_attracted
))
1270 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1271 list
= PLAppendArrayElement(list
, icon_info
);
1272 PLRelease(icon_info
);
1276 dock_state
= PLMakeDictionaryFromEntries(dApplications
, list
, NULL
);
1280 if (dock
->type
== WM_DOCK
) {
1281 sprintf(buffer
, "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0),
1283 value
= PLMakeString(buffer
);
1284 PLInsertDictionaryEntry(dock_state
, dPosition
, value
);
1288 value
= (dock
->lowered
? dYes
: dNo
);
1289 PLInsertDictionaryEntry(dock_state
, dLowered
, value
);
1291 if (dock
->type
== WM_CLIP
) {
1292 value
= (dock
->collapsed
? dYes
: dNo
);
1293 PLInsertDictionaryEntry(dock_state
, dCollapsed
, value
);
1295 value
= (dock
->auto_collapse
? dYes
: dNo
);
1296 PLInsertDictionaryEntry(dock_state
, dAutoCollapse
, value
);
1298 value
= (dock
->attract_icons
? dYes
: dNo
);
1299 PLInsertDictionaryEntry(dock_state
, dAutoAttractIcons
, value
);
1301 value
= (dock
->keep_attracted
? dYes
: dNo
);
1302 PLInsertDictionaryEntry(dock_state
, dKeepAttracted
, value
);
1310 wDockSaveState(WScreen
*scr
)
1312 proplist_t dock_state
;
1314 dock_state
= dockSaveState(scr
->dock
);
1316 PLInsertDictionaryEntry(scr
->session_state
, dDock
, dock_state
);
1318 PLRelease(dock_state
);
1323 wClipSaveState(WScreen
*scr
)
1325 proplist_t clip_state
;
1327 clip_state
= make_icon_state(scr
->clip_icon
);
1329 PLInsertDictionaryEntry(scr
->session_state
, dClip
, clip_state
);
1331 PLRelease(clip_state
);
1336 wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1338 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1343 restore_icon_state(WScreen
*scr
, proplist_t info
, int type
, int index
)
1346 char *wclass
, *winstance
;
1347 proplist_t cmd
, value
;
1351 cmd
= PLGetDictionaryEntry(info
, dCommand
);
1352 if (!cmd
|| !PLIsString(cmd
)) {
1356 /* parse window name */
1357 value
= PLGetDictionaryEntry(info
, dName
);
1361 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1363 if (!winstance
&& !wclass
) {
1370 command
= wstrdup(PLGetString(cmd
));
1374 if (!command
|| strcmp(command
, "-")==0) {
1385 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
,
1392 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1393 if (type
== WM_CLIP
) {
1394 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1395 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1397 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1398 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1402 cmd
= PLGetDictionaryEntry(info
, dDropCommand
);
1404 aicon
->dnd_command
= wstrdup(PLGetString(cmd
));
1407 /* check auto launch */
1408 value
= PLGetDictionaryEntry(info
, dAutoLaunch
);
1410 aicon
->auto_launch
= 0;
1412 if (PLIsString(value
)) {
1413 if (strcasecmp(PLGetString(value
), "YES")==0)
1414 aicon
->auto_launch
= 1;
1416 wwarning(_("bad value in docked icon state info %s"),
1417 PLGetString(dAutoLaunch
));
1421 /* check if it wasn't normally docked */
1422 value
= PLGetDictionaryEntry(info
, dForced
);
1424 aicon
->forced_dock
= 0;
1426 if (PLIsString(value
)) {
1427 if (strcasecmp(PLGetString(value
), "YES")==0)
1428 aicon
->forced_dock
= 1;
1430 wwarning(_("bad value in docked icon state info %s"),
1431 PLGetString(dForced
));
1435 /* check if we can rely on the stuff in the app */
1436 value
= PLGetDictionaryEntry(info
, dBuggyApplication
);
1438 aicon
->buggy_app
= 0;
1440 if (PLIsString(value
)) {
1441 if (strcasecmp(PLGetString(value
), "YES")==0)
1442 aicon
->buggy_app
= 1;
1444 wwarning(_("bad value in docked icon state info %s"),
1445 PLGetString(dBuggyApplication
));
1449 /* get position in the dock */
1450 value
= PLGetDictionaryEntry(info
, dPosition
);
1451 if (value
&& PLIsString(value
)) {
1452 if (sscanf(PLGetString(value
), "%hi,%hi", &aicon
->xindex
,
1454 wwarning(_("bad value in docked icon state info %s"),
1455 PLGetString(dPosition
));
1457 /* check position sanity */
1458 /* incomplete section! */
1459 if (type
== WM_DOCK
) {
1461 if (aicon
->yindex
< 0)
1462 wwarning(_("bad value in docked icon position %i,%i"),
1463 aicon
->xindex
, aicon
->yindex
);
1466 aicon
->yindex
= index
;
1477 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1481 wClipRestoreState(WScreen
*scr
, proplist_t clip_state
)
1487 icon
= mainIconCreate(scr
, WM_CLIP
);
1492 PLRetain(clip_state
);
1494 /* restore position */
1496 value
= PLGetDictionaryEntry(clip_state
, dPosition
);
1499 if (!PLIsString(value
))
1500 COMPLAIN("Position");
1502 if (sscanf(PLGetString(value
), "%i,%i", &icon
->x_pos
,
1504 COMPLAIN("Position");
1506 /* check position sanity */
1507 if (icon
->y_pos
< 0)
1509 else if (icon
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1510 icon
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1512 if (icon
->x_pos
< 0)
1514 else if (icon
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1515 icon
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1520 value
= PLGetDictionaryEntry(clip_state
, dDropCommand
);
1521 if (value
&& PLIsString(value
))
1522 icon
->dnd_command
= wstrdup(PLGetString(value
));
1525 PLRelease(clip_state
);
1532 wDockRestoreState(WScreen
*scr
, proplist_t dock_state
, int type
)
1537 WAppIcon
*aicon
, *old_top
;
1541 dock
= wDockCreate(scr
, type
);
1547 PLRetain(dock_state
);
1550 /* restore position */
1552 value
= PLGetDictionaryEntry(dock_state
, dPosition
);
1555 if (!PLIsString(value
))
1556 COMPLAIN("Position");
1558 if (sscanf(PLGetString(value
), "%i,%i", &dock
->x_pos
,
1560 COMPLAIN("Position");
1562 /* check position sanity */
1563 if (dock
->y_pos
< 0)
1565 else if (dock
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1566 dock
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1568 /* This is no more needed. ??? */
1569 if (type
== WM_CLIP
) {
1570 if (dock
->x_pos
< 0)
1572 else if (dock
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1573 dock
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1576 if (dock
->x_pos
>= 0) {
1577 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1578 dock
->on_right_side
= 0;
1580 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1581 dock
->on_right_side
= 1;
1587 /* restore lowered/raised state */
1591 value
= PLGetDictionaryEntry(dock_state
, dLowered
);
1594 if (!PLIsString(value
))
1595 COMPLAIN("Lowered");
1597 if (strcasecmp(PLGetString(value
), "YES")==0)
1603 /* restore collapsed state */
1605 dock
->collapsed
= 0;
1607 value
= PLGetDictionaryEntry(dock_state
, dCollapsed
);
1610 if (!PLIsString(value
))
1611 COMPLAIN("Collapsed");
1613 if (strcasecmp(PLGetString(value
), "YES")==0)
1614 dock
->collapsed
= 1;
1619 /* restore auto-collapsed state */
1621 value
= PLGetDictionaryEntry(dock_state
, dAutoCollapse
);
1624 if (!PLIsString(value
))
1625 COMPLAIN("AutoCollapse");
1627 if (strcasecmp(PLGetString(value
), "YES")==0) {
1628 dock
->auto_collapse
= 1;
1629 dock
->collapsed
= 1;
1635 /* restore attract icons state */
1637 dock
->attract_icons
= 0;
1639 value
= PLGetDictionaryEntry(dock_state
, dAutoAttractIcons
);
1642 if (!PLIsString(value
))
1643 COMPLAIN("AutoAttractIcons");
1645 if (strcasecmp(PLGetString(value
), "YES")==0)
1646 dock
->attract_icons
= 1;
1651 /* restore keep attracted icons state */
1653 dock
->keep_attracted
= 0;
1655 value
= PLGetDictionaryEntry(dock_state
, dKeepAttracted
);
1658 if (!PLIsString(value
))
1659 COMPLAIN("KeepAttracted");
1661 if (strcasecmp(PLGetString(value
), "YES")==0)
1662 dock
->keep_attracted
= 1;
1667 /* application list */
1669 apps
= PLGetDictionaryEntry(dock_state
, dApplications
);
1675 count
= PLGetNumberOfElements(apps
);
1680 old_top
= dock
->icon_array
[0];
1682 /* dock->icon_count is set to 1 when dock is created.
1683 * Since Clip is already restored, we want to keep it so for clip,
1684 * but for dock we may change the default top tile, so we set it to 0.
1686 if (type
== WM_DOCK
)
1687 dock
->icon_count
= 0;
1689 for (i
=0; i
<count
; i
++) {
1690 if (dock
->icon_count
>= dock
->max_icons
) {
1691 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1695 value
= PLGetArrayElement(apps
, i
);
1696 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1698 dock
->icon_array
[dock
->icon_count
] = aicon
;
1702 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
*ICON_SIZE
);
1703 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
*ICON_SIZE
);
1706 ChangeStackingLevel(aicon
->icon
->core
, WMNormalWindowLevel
);
1708 ChangeStackingLevel(aicon
->icon
->core
, WMDockWindowLevel
);
1710 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
,
1713 if (!dock
->collapsed
)
1714 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1715 wRaiseFrame(aicon
->icon
->core
);
1718 } else if (dock
->icon_count
==0 && type
==WM_DOCK
)
1722 /* if the first icon is not defined, use the default */
1723 if (dock
->icon_array
[0]==NULL
) {
1724 /* update default icon */
1725 old_top
->x_pos
= dock
->x_pos
;
1726 old_top
->y_pos
= dock
->y_pos
;
1728 ChangeStackingLevel(old_top
->icon
->core
, WMNormalWindowLevel
);
1730 ChangeStackingLevel(old_top
->icon
->core
, WMDockWindowLevel
);
1731 dock
->icon_array
[0] = old_top
;
1732 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1733 /* we don't need to increment dock->icon_count here because it was
1734 * incremented in the loop above.
1736 } else if (old_top
!=dock
->icon_array
[0]) {
1737 if (old_top
== scr
->clip_icon
)
1738 scr
->clip_icon
= dock
->icon_array
[0];
1739 wAppIconDestroy(old_top
);
1744 PLRelease(dock_state
);
1752 wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1754 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1756 btn
->drop_launch
= 0;
1758 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1761 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1773 wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1779 for (i
=0; i
< dock
->max_icons
; i
++) {
1780 btn
= dock
->icon_array
[i
];
1781 if (!btn
|| !btn
->auto_launch
)
1784 state
= wmalloc(sizeof(WSavedState
));
1785 memset(state
, 0, sizeof(WSavedState
));
1786 state
->workspace
= workspace
;
1787 /* TODO: this is klugy and is very difficult to understand
1788 * what's going on. Try to clean up */
1789 wDockLaunchWithState(dock
, btn
, state
);
1793 #ifdef REDUCE_APPICONS
1795 wDockSimulateLaunch(WDock
*dock
, WAppIcon
*btn
)
1797 if ((btn
== NULL
) || (dock
== NULL
))
1800 if (!btn
->running
) {
1801 if ((btn
->icon
->owner
== NULL
) && (btn
->applist
))
1802 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
1803 if (!btn
->forced_dock
)
1813 findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1819 if ((dock
= scr
->dock
)!=NULL
) {
1820 for (i
=0; i
<dock
->max_icons
; i
++) {
1821 if (dock
->icon_array
[i
]
1822 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1828 if (*icon_pos
<0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
)!=NULL
) {
1829 for (i
=0; i
<dock
->max_icons
; i
++) {
1830 if (dock
->icon_array
[i
]
1831 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1844 wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
1850 dock
= findDock(scr
, event
, &icon_pos
);
1855 * Return True if the drop was on an application icon window.
1856 * In this case, let the ClientMessage handler redirect the
1857 * message to the app.
1859 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!=None
)
1862 if (dock
->icon_array
[icon_pos
]->dnd_command
!=NULL
) {
1863 scr
->flags
.dnd_data_convertion_status
= 0;
1865 btn
= dock
->icon_array
[icon_pos
];
1867 if (!btn
->forced_dock
) {
1868 btn
->relaunching
= btn
->running
;
1871 if (btn
->wm_instance
|| btn
->wm_class
) {
1872 WWindowAttributes attr
;
1873 memset(&attr
, 0, sizeof(WWindowAttributes
));
1874 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
1876 btn
->wm_class
, &attr
, True
);
1878 if (!attr
.no_appicon
)
1884 btn
->drop_launch
= 1;
1885 scr
->last_dock
= dock
;
1886 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1891 if (!btn
->relaunching
) {
1898 #endif /* OFFIX_DND */
1903 wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1910 wwin
= icon
->icon
->owner
;
1911 if (icon
->command
==NULL
) {
1913 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
1915 icon
->command
= FlattenStringList(argv
, argc
);
1916 XFreeStringList(argv
);
1920 /* icon->forced_dock = 1;*/
1921 if (!icon
->attracted
|| dock
->type
!=WM_CLIP
|| dock
->keep_attracted
) {
1923 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
1924 _("Type the command used to launch the application"),
1925 &command
)==WDB_OK
) {
1926 if (command
&& (command
[0]==0 ||
1927 (command
[0]=='-' && command
[1]==0))) {
1931 icon
->command
= command
;
1937 /* If the target is the dock, reject the icon. If
1938 * the target is the clip, make it an attracted icon
1940 if (dock
->type
==WM_CLIP
) {
1941 icon
->attracted
= 1;
1942 if (!icon
->icon
->shadowed
) {
1943 icon
->icon
->shadowed
= 1;
1944 icon
->icon
->force_paint
= 1;
1956 for (index
=1; index
<dock
->max_icons
; index
++)
1957 if (dock
->icon_array
[index
] == NULL
)
1959 /* if (index == dock->max_icons)
1962 assert(index
< dock
->max_icons
);
1964 dock
->icon_array
[index
] = icon
;
1968 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
1969 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
1974 icon
->launching
= 0;
1977 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1978 if (dock
->type
== WM_CLIP
) {
1979 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1980 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1982 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1983 icon
->icon
->core
->descriptor
.parent
= icon
;
1985 MoveInStackListUnder(dock
->icon_array
[index
-1]->icon
->core
,
1987 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
1988 wAppIconPaint(icon
);
1990 if (wPreferences
.auto_arrange_icons
)
1991 wArrangeIcons(dock
->screen_ptr
, True
);
1998 reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2002 for(index
=1; index
<dock
->max_icons
; index
++) {
2003 if(dock
->icon_array
[index
] == icon
)
2006 assert(index
< dock
->max_icons
);
2011 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2012 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2017 moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2027 wwin
= icon
->icon
->owner
;
2030 * For the moment we can't do this if we move icons in Clip from one
2031 * workspace to other, because if we move two or more icons without
2032 * command, the dialog box will not be able to tell us to which of the
2033 * moved icons it applies. -Dan
2035 if ((dest
->type
==WM_DOCK
/*|| dest->keep_attracted*/) && icon
->command
==NULL
) {
2036 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2038 icon
->command
= FlattenStringList(argv
, argc
);
2039 XFreeStringList(argv
);
2044 /* icon->forced_dock = 1;*/
2045 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2046 _("Type the command used to launch the application"),
2047 &command
)==WDB_OK
) {
2048 if (command
&& (command
[0]==0 ||
2049 (command
[0]=='-' && command
[1]==0))) {
2053 icon
->command
= command
;
2064 for(index
=1; index
<src
->max_icons
; index
++) {
2065 if(src
->icon_array
[index
] == icon
)
2068 assert(index
< src
->max_icons
);
2070 src
->icon_array
[index
] = NULL
;
2073 for(index
=1; index
<dest
->max_icons
; index
++) {
2074 if(dest
->icon_array
[index
] == NULL
)
2077 /* if (index == dest->max_icons)
2080 assert(index
< dest
->max_icons
);
2082 dest
->icon_array
[index
] = icon
;
2085 /* deselect the icon */
2086 if (icon
->icon
->selected
)
2087 wIconSelect(icon
->icon
);
2089 if (dest
->type
== WM_DOCK
) {
2090 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2091 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2093 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2094 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2097 /* set it to be kept when moving to dock, or to a clip that keep the
2099 * Unless the icon does not have a command set
2101 if (icon
->command
&& (dest
->type
==WM_DOCK
|| dest
->keep_attracted
)) {
2102 icon
->attracted
= 0;
2103 if (icon
->icon
->shadowed
) {
2104 icon
->icon
->shadowed
= 0;
2105 icon
->icon
->force_paint
= 1;
2109 if (src
->auto_collapse
)
2115 icon
->x_pos
= dest
->x_pos
+ x
*ICON_SIZE
;
2116 icon
->y_pos
= dest
->y_pos
+ y
*ICON_SIZE
;
2120 MoveInStackListUnder(dest
->icon_array
[index
-1]->icon
->core
,
2122 wAppIconPaint(icon
);
2128 wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2132 /* make the settings panel be closed */
2134 DestroyDockAppSettingsPanel(icon
->panel
);
2139 icon
->attracted
= 0;
2140 if (icon
->icon
->shadowed
) {
2141 icon
->icon
->shadowed
= 0;
2142 icon
->icon
->force_paint
= 1;
2145 /* deselect the icon */
2146 if (icon
->icon
->selected
)
2147 wIconSelect(icon
->icon
);
2149 if (icon
->command
) {
2150 free(icon
->command
);
2151 icon
->command
= NULL
;
2154 if (icon
->dnd_command
) {
2155 free(icon
->dnd_command
);
2156 icon
->dnd_command
= NULL
;
2160 for (index
=1; index
<dock
->max_icons
; index
++)
2161 if (dock
->icon_array
[index
] == icon
)
2163 assert(index
< dock
->max_icons
);
2164 dock
->icon_array
[index
] = NULL
;
2169 /* if the dock is not attached to an application or
2170 * the the application did not set the approriate hints yet,
2171 * destroy the icon */
2172 #ifdef REDUCE_APPICONS
2173 if ((icon
->num_apps
== 0) && (!icon
->running
|| !wApplicationOf(icon
->main_window
)) )
2175 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2177 wAppIconDestroy(icon
);
2179 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2180 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2181 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2182 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2183 icon
->icon
->core
->descriptor
.parent
= icon
;
2184 ChangeStackingLevel(icon
->icon
->core
, WMNormalWindowLevel
);
2185 wAppIconPaint(icon
);
2186 if (wPreferences
.auto_arrange_icons
) {
2187 wArrangeIcons(dock
->screen_ptr
, True
);
2190 if (dock
->auto_collapse
)
2196 * returns the closest Dock slot index for the passed
2199 * Returns False if icon can't be docked.
2202 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2203 int *ret_x
, int *ret_y
, int redocking
)
2205 WScreen
*scr
= dock
->screen_ptr
;
2208 int i
, offset
= ICON_SIZE
/2;
2209 WAppIcon
*aicon
= NULL
;
2210 WAppIcon
*nicon
= NULL
;
2216 /* if the dock is full */
2218 (dock
->icon_count
>= dock
->max_icons
)) {
2222 /* exact position */
2224 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2226 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2229 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2231 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2233 /* check if the icon is outside the screen boundaries */
2234 if (dx
+ ex_x
*ICON_SIZE
< -ICON_SIZE
+2 ||
2235 dx
+ ex_x
*ICON_SIZE
> scr
->scr_width
-1 ||
2236 dy
+ ex_y
*ICON_SIZE
< -ICON_SIZE
+2 ||
2237 dy
+ ex_y
*ICON_SIZE
> scr
->scr_height
-1)
2240 if (dock
->type
== WM_DOCK
) {
2241 for (i
=0; i
<dock
->max_icons
; i
++) {
2242 nicon
= dock
->icon_array
[i
];
2243 if (nicon
&& nicon
->yindex
== ex_y
) {
2252 int sig
, done
, closest
;
2254 /* Possible cases when redocking:
2256 * icon dragged out of range of any slot -> false
2257 * icon dragged to range of free slot
2258 * icon dragged to range of same slot
2259 * icon dragged to range of different icon
2261 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2264 if (ex_y
>=0 && (aicon
== icon
|| !aicon
)) {
2271 /* start looking at the upper slot or lower? */
2272 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2279 /* look for closest free slot */
2280 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2284 closest
= sig
*(i
/2) + ex_y
;
2285 /* check if this slot is used */
2287 for (j
= 0; j
<dock
->max_icons
; j
++) {
2288 if (dock
->icon_array
[j
]
2289 && dock
->icon_array
[j
]->yindex
==closest
) {
2290 /* slot is used by someone else */
2291 if (dock
->icon_array
[j
]!=icon
)
2299 if (done
&& closest
>= 0 &&
2300 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2302 (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+1))) {
2308 } else { /* !redocking */
2310 /* if slot is free and the icon is close enough, return it */
2311 if (!aicon
&& ex_x
==0 && ex_y
>=0) {
2319 for (i
=0; i
<dock
->max_icons
; i
++) {
2320 nicon
= dock
->icon_array
[i
];
2321 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2327 for (i
=0; i
<dock
->max_icons
; i
++) {
2328 nicon
= dock
->icon_array
[i
];
2329 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2330 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2331 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2336 if ((!redocking
&& neighbours
&& !aicon
) ||
2337 (redocking
&& neighbours
&& (aicon
== icon
|| !aicon
))) {
2346 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2347 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2349 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2350 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2351 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2355 * returns true if it can find a free slot in the dock,
2356 * in which case it changes x_pos and y_pos accordingly.
2357 * Else returns false.
2360 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2362 WScreen
*scr
= dock
->screen_ptr
;
2364 unsigned char *slot_map
;
2368 int i
, done
= False
;
2370 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2372 /* if the dock is full */
2373 if (dock
->icon_count
>= dock
->max_icons
) {
2377 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2378 if (scr
->dock
->on_right_side
)
2379 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2381 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2384 if (ex
< dock
->x_pos
)
2386 if (sx
> dock
->x_pos
+ICON_SIZE
)
2387 sx
= dock
->x_pos
+ICON_SIZE
;
2394 /* check if clip is in a corner */
2395 if (dock
->type
==WM_CLIP
) {
2396 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2398 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2400 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2402 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2409 /* If the clip is in the corner, use only slots that are in the border
2411 if (corner
!=C_NONE
) {
2415 hcount
= MIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2416 vcount
= MIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2417 hmap
= wmalloc(hcount
+1);
2418 memset(hmap
, 0, hcount
+1);
2419 vmap
= wmalloc(vcount
+1);
2420 memset(vmap
, 0, vcount
+1);
2422 /* mark used positions */
2425 for (i
=0; i
<dock
->max_icons
; i
++) {
2426 btn
= dock
->icon_array
[i
];
2430 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2431 vmap
[btn
->yindex
] = 1;
2432 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2433 hmap
[btn
->xindex
] = 1;
2436 for (i
=0; i
<dock
->max_icons
; i
++) {
2437 btn
= dock
->icon_array
[i
];
2441 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2442 vmap
[btn
->yindex
] = 1;
2443 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2444 hmap
[-btn
->xindex
] = 1;
2447 for (i
=0; i
<dock
->max_icons
; i
++) {
2448 btn
= dock
->icon_array
[i
];
2452 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2453 vmap
[-btn
->yindex
] = 1;
2454 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2455 hmap
[btn
->xindex
] = 1;
2459 for (i
=0; i
<dock
->max_icons
; i
++) {
2460 btn
= dock
->icon_array
[i
];
2464 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2465 vmap
[-btn
->yindex
] = 1;
2466 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2467 hmap
[-btn
->xindex
] = 1;
2472 /* search a vacant slot */
2473 for (i
=1; i
<MAX(vcount
, hcount
); i
++) {
2474 if (i
< vcount
&& vmap
[i
]==0) {
2480 } else if (i
< hcount
&& hmap
[i
]==0) {
2490 /* If found a slot, translate and return */
2492 if (corner
==C_NW
|| corner
==C_NE
) {
2497 if (corner
==C_NE
|| corner
==C_SE
) {
2504 /* else, try to find a slot somewhere else */
2507 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2508 * placed outside of screen */
2509 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2511 /* In the worst case (the clip is in the corner of the screen),
2512 * the amount of icons that fit in the clip is smaller.
2513 * Double the map to get a safe value.
2519 slot_map
= wmalloc(mwidth
*mwidth
);
2520 memset(slot_map
, 0, mwidth
*mwidth
);
2522 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2524 /* mark used slots in the map. If the slot falls outside the map
2525 * (for example, when all icons are placed in line), ignore them. */
2526 for (i
=0; i
<dock
->max_icons
; i
++) {
2527 btn
= dock
->icon_array
[i
];
2529 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2531 /* Find closest slot from the center that is free by scanning the
2532 * map from the center to outward in circular passes.
2533 * This will not result in a neat layout, but will be optimal
2534 * in the sense that there will not be holes left.
2537 for (i
= 1; i
<= r
&& !done
; i
++) {
2540 /* top and bottom parts of the ring */
2541 for (x
= -i
; x
<= i
&& !done
; x
++) {
2542 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2544 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2545 if (slot_map
[XY2OFS(x
,y
)]==0
2546 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2553 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2554 if (slot_map
[XY2OFS(x
,y
)]==0
2555 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2562 /* left and right parts of the ring */
2563 for (y
= -i
+1; y
<= i
-1; y
++) {
2564 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2566 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2567 if (slot_map
[XY2OFS(x
,y
)]==0
2568 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2575 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2576 if (slot_map
[XY2OFS(x
,y
)]==0
2577 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2592 moveDock(WDock
*dock
, int new_x
, int new_y
)
2597 dock
->x_pos
= new_x
;
2598 dock
->y_pos
= new_y
;
2599 for (i
=0; i
<dock
->max_icons
; i
++) {
2600 btn
= dock
->icon_array
[i
];
2602 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2603 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2604 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2611 swapDock(WDock
*dock
)
2613 WScreen
*scr
= dock
->screen_ptr
;
2618 if (dock
->on_right_side
) {
2619 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2621 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2624 for (i
=0; i
<dock
->max_icons
; i
++) {
2625 btn
= dock
->icon_array
[i
];
2628 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2635 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2637 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2643 cmdline
= ExpandOptions(scr
, command
);
2645 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2653 ParseCommand(cmdline
, &argv
, &argc
);
2663 if ((pid
=fork())==0) {
2667 SetupEnvironment(scr
);
2669 close(ConnectionNumber(dpy
));
2675 args
= malloc(sizeof(char*)*(argc
+1));
2678 for (i
=0; i
<argc
; i
++) {
2682 execvp(argv
[0], args
);
2691 state
= wmalloc(sizeof(WSavedState
));
2692 memset(state
, 0, sizeof(WSavedState
));
2694 state
->miniaturized
= -1;
2696 if (btn
->dock
== scr
->dock
)
2697 state
->workspace
= -1;
2699 state
->workspace
= scr
->current_workspace
;
2701 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
2703 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
2714 wDockHideIcons(WDock
*dock
)
2722 btn
= dock
->icon_array
[0];
2724 for (i
=1; i
<dock
->max_icons
; i
++) {
2725 if (dock
->icon_array
[i
])
2726 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2735 wDockShowIcons(WDock
*dock
)
2743 btn
= dock
->icon_array
[0];
2744 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2746 newlevel
= dock
->lowered
? WMNormalWindowLevel
: WMDockWindowLevel
;
2747 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2749 for (i
=1; i
<dock
->max_icons
; i
++) {
2750 if (dock
->icon_array
[i
]) {
2751 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
2757 if (!dock
->collapsed
) {
2758 for (i
=1; i
<dock
->max_icons
; i
++) {
2759 if (dock
->icon_array
[i
]) {
2760 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2771 wDockLower(WDock
*dock
)
2775 for (i
=0; i
<dock
->max_icons
; i
++) {
2776 if (dock
->icon_array
[i
])
2777 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2783 wDockRaise(WDock
*dock
)
2787 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
2788 if (dock
->icon_array
[i
])
2789 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2795 wDockRaiseLower(WDock
*dock
)
2797 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2798 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2799 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2807 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
2809 icon
->launching
= 0;
2810 icon
->relaunching
= 0;
2811 dockIconPaint(icon
);
2816 wDockFindIconFor(WDock
*dock
, Window window
)
2821 for (i
=0; i
<dock
->max_icons
; i
++) {
2822 icon
= dock
->icon_array
[i
];
2823 if (icon
&& icon
->main_window
== window
)
2831 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
2834 #ifdef REDUCE_APPICONS
2835 WAppIconAppList
*tapplist
;
2837 char *wm_class
, *wm_instance
;
2841 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
2842 (!wm_class
&& !wm_instance
))
2845 for (i
=0; i
<dock
->max_icons
; i
++) {
2846 icon
= dock
->icon_array
[i
];
2850 /* kluge. If this does not exist, some windows attach themselves
2851 * to more than one icon. Find out why */
2852 if (icon
->main_window
== window
) {
2855 if ((icon
->wm_instance
|| icon
->wm_class
)
2857 || (dock
->screen_ptr
->flags
.startup
&& !icon
->running
))) {
2859 if (icon
->wm_instance
&& wm_instance
&&
2860 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
2863 if (icon
->wm_class
&& wm_class
&&
2864 strcmp(icon
->wm_class
, wm_class
)!=0) {
2868 if (!icon
->relaunching
) {
2871 /* Possibly an application that was docked with dockit,
2872 * but the user did not update WMState to indicate that
2873 * it was docked by force */
2874 wapp
= wApplicationOf(window
);
2876 icon
->forced_dock
= 1;
2879 if (!icon
->forced_dock
)
2880 icon
->main_window
= window
;
2881 #ifdef REDUCE_APPICONS
2882 tapplist
= wmalloc(sizeof(WAppIconAppList
));
2883 memset(tapplist
, 0, sizeof(WAppIconAppList
));
2884 tapplist
->next
= icon
->applist
;
2886 icon
->applist
->prev
= tapplist
;
2887 icon
->applist
= tapplist
;
2888 tapplist
->wapp
= wApplicationOf(window
);
2892 wDockFinishLaunch(dock
, icon
);
2906 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
2908 if (!wPreferences
.flags
.noclip
) {
2909 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
2910 if (scr
->current_workspace
!= workspace
) {
2911 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
2913 wDockHideIcons(old_clip
);
2914 if (old_clip
->auto_collapse
&& !old_clip
->collapsed
)
2915 old_clip
->collapsed
= 1;
2916 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
2918 if (scr
->flags
.clip_balloon_mapped
)
2919 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
2926 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
2931 for (i
=0; i
<dock
->max_icons
; i
++) {
2932 icon
= dock
->icon_array
[i
];
2936 if (icon
->launching
&& icon
->pid
== pid
) {
2937 if (!icon
->relaunching
) {
2939 icon
->main_window
= None
;
2941 wDockFinishLaunch(dock
, icon
);
2946 sprintf(msg
, _("Could not execute command \"%s\""),
2947 icon
->drop_launch
&& icon
->dnd_command
2948 ? icon
->dnd_command
: icon
->command
);
2950 sprintf(msg
, _("Could not execute command \"%s\""),
2953 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
2954 _("OK"), NULL
, NULL
);
2963 toggleLowered(WDock
*dock
)
2968 /* lower/raise Dock */
2969 if (!dock
->lowered
) {
2970 newlevel
= WMNormalWindowLevel
;
2973 newlevel
= WMDockWindowLevel
;
2977 for (i
=0; i
<dock
->max_icons
; i
++) {
2978 tmp
= dock
->icon_array
[i
];
2982 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
2984 wLowerFrame(tmp
->icon
->core
);
2990 toggleCollapsed(WDock
*dock
)
2992 if (dock
->collapsed
) {
2993 dock
->collapsed
= 0;
2994 wDockShowIcons(dock
);
2997 dock
->collapsed
= 1;
2998 wDockHideIcons(dock
);
3004 toggleAutoCollapse(WDock
*dock
)
3006 dock
->auto_collapse
= !dock
->auto_collapse
;
3007 if (dock
->auto_collapse_magic
) {
3008 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3009 dock
->auto_collapse_magic
= NULL
;
3015 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3017 WScreen
*scr
= dock
->screen_ptr
;
3018 WObjDescriptor
*desc
;
3022 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3024 if (dock
->type
== WM_DOCK
) {
3026 entry
= dock
->menu
->entries
[index
];
3027 entry
->flags
.indicator_on
= !dock
->lowered
;
3028 entry
->clientdata
= dock
;
3031 if (scr
->clip_options
)
3032 updateClipOptionsMenu(scr
->clip_options
, dock
);
3034 /* Rename Workspace */
3035 entry
= dock
->menu
->entries
[++index
];
3036 entry
->clientdata
= dock
;
3039 entry
= dock
->menu
->entries
[++index
];
3040 entry
->clientdata
= aicon
;
3041 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3043 /* (un)select all icons */
3044 entry
= dock
->menu
->entries
[++index
];
3045 entry
->clientdata
= aicon
;
3046 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3049 entry
= dock
->menu
->entries
[++index
];
3050 entry
->clientdata
= aicon
;
3051 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3053 /* this is the workspace submenu part */
3054 if (scr
->clip_submenu
)
3055 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3058 /* remove icon(s) */
3059 entry
= dock
->menu
->entries
[++index
];
3060 entry
->clientdata
= aicon
;
3061 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3063 /* attract icon(s) */
3064 entry
= dock
->menu
->entries
[++index
];
3065 entry
->clientdata
= aicon
;
3069 entry
= dock
->menu
->entries
[++index
];
3070 entry
->clientdata
= aicon
;
3071 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3074 entry
= dock
->menu
->entries
[++index
];
3075 entry
->clientdata
= aicon
;
3076 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3079 entry
= dock
->menu
->entries
[++index
];
3080 entry
->clientdata
= aicon
;
3081 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3084 entry
= dock
->menu
->entries
[++index
];
3085 entry
->clientdata
= aicon
;
3086 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
);
3089 entry
= dock
->menu
->entries
[++index
];
3090 entry
->clientdata
= aicon
;
3091 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3093 if (!dock
->menu
->flags
.realized
)
3094 wMenuRealize(dock
->menu
);
3096 if (dock
->type
== WM_CLIP
) {
3097 x_pos
= event
->xbutton
.x_root
+2;
3099 x_pos
= dock
->on_right_side
?
3100 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 2 : 0;
3103 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3105 /* allow drag select */
3106 event
->xany
.send_event
= True
;
3107 desc
= &dock
->menu
->menu
->descriptor
;
3108 (*desc
->handle_mousedown
)(desc
, event
);
3113 openClipWorkspaceMenu(WScreen
*scr
, int x
, int y
)
3115 if (!scr
->clip_ws_menu
) {
3116 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3118 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
3119 wMenuMapAt(scr
->clip_ws_menu
, x
, y
, False
);
3123 /******************************************************************/
3125 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3127 WAppIcon
*btn
= desc
->parent
;
3128 WDock
*dock
= btn
->dock
;
3129 WApplication
*wapp
= NULL
;
3132 #ifdef REDUCE_APPICONS
3133 if ((btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) ||
3134 ((btn
->icon
->owner
== NULL
) && (btn
->applist
!= NULL
))) {
3135 if (btn
->icon
->owner
== NULL
)
3136 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
3141 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3143 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3147 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3149 /* go to the last workspace that the user worked on the app */
3151 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3154 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3157 if (event
->xbutton
.state
& MOD_MASK
) {
3158 wHideOtherApplications(btn
->icon
->owner
);
3161 if (event
->xbutton
.button
==Button1
) {
3163 if (event
->xbutton
.state
& MOD_MASK
) {
3164 /* raise/lower dock */
3165 toggleLowered(dock
);
3166 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3167 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3168 toggleCollapsed(dock
);
3170 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3171 } else if (btn
->command
) {
3172 if (!btn
->launching
&&
3173 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3174 launchDockedApplication(btn
);
3183 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3185 WScreen
*scr
= dock
->screen_ptr
;
3186 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3189 int grabbed
= 0, swapped
= 0, done
;
3190 Pixmap ghost
= None
;
3191 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3194 puts("moving dock");
3196 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3197 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3198 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3199 wwarning("pointer grab failed for dock move");
3202 for (x
=0; x
<dock
->max_icons
; x
++) {
3203 if (dock
->icon_array
[x
]!=NULL
&&
3204 dock
->icon_array
[x
]->yindex
> y
)
3205 y
= dock
->icon_array
[x
]->yindex
;
3208 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3212 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3213 |ButtonMotionMask
|ExposureMask
, &ev
);
3221 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3222 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3223 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3224 |ButtonReleaseMask
|ButtonPressMask
,
3225 wCursor
[WCUR_MOVE
], CurrentTime
);
3230 if (dock
->type
== WM_CLIP
) {
3231 if (ev
.xmotion
.x_root
- ofs_x
< 0) {
3233 } else if (ev
.xmotion
.x_root
- ofs_x
+ ICON_SIZE
>
3235 x
= scr
->scr_width
- ICON_SIZE
;
3237 x
= ev
.xmotion
.x_root
- ofs_x
;
3239 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3241 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3243 y
= scr
->scr_height
- ICON_SIZE
;
3245 y
= ev
.xmotion
.y_root
- ofs_y
;
3247 moveDock(dock
, x
, y
);
3250 /* move vertically if pointer is inside the dock*/
3251 if ((dock
->on_right_side
&&
3252 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3253 || (!dock
->on_right_side
&&
3254 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3256 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3258 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3260 y
= scr
->scr_height
- ICON_SIZE
;
3262 y
= ev
.xmotion
.y_root
- ofs_y
;
3264 moveDock(dock
, dock
->x_pos
, y
);
3266 /* move horizontally to change sides */
3267 x
= ev
.xmotion
.x_root
- ofs_x
;
3268 if (!dock
->on_right_side
) {
3272 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3273 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3274 -DOCK_EXTRA_SPACE
, dock
->y_pos
);
3277 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3278 scr
->scr_width
-ICON_SIZE
3281 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3283 XClearWindow(dpy
, scr
->dock_shadow
);
3286 XMapRaised(dpy
, scr
->dock_shadow
);
3289 if (superfluous
&& ghost
!=None
) {
3290 XFreePixmap(dpy
, ghost
);
3293 XUnmapWindow(dpy
, scr
->dock_shadow
);
3298 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3299 XMoveWindow(dpy
, scr
->dock_shadow
,
3300 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3303 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3304 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3305 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3307 XClearWindow(dpy
, scr
->dock_shadow
);
3310 XMapRaised(dpy
, scr
->dock_shadow
);
3313 XUnmapWindow(dpy
, scr
->dock_shadow
);
3315 if (superfluous
&& ghost
!=None
) {
3316 XFreePixmap(dpy
, ghost
);
3328 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3330 XUngrabPointer(dpy
, CurrentTime
);
3331 XUnmapWindow(dpy
, scr
->dock_shadow
);
3332 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3333 if (dock
->type
== WM_DOCK
) {
3336 dock
->on_right_side
= 1;
3338 dock
->on_right_side
= 0;
3340 wArrangeIcons(scr
, False
);
3349 XFreePixmap(dpy
, ghost
);
3350 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3353 puts("End dock move");
3360 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3362 WScreen
*scr
= dock
->screen_ptr
;
3364 WIcon
*icon
= aicon
->icon
;
3365 WDock
*dock2
= NULL
, *last_dock
= dock
;
3366 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3368 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3369 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3370 int shad_x
= x
, shad_y
= y
;
3371 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3373 Pixmap ghost
= None
;
3375 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3377 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3378 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3379 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3381 wwarning("pointer grab failed for icon move");
3385 wRaiseFrame(icon
->core
);
3387 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3388 dock2
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3389 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3392 wins
[0] = icon
->core
->window
;
3393 wins
[1] = scr
->dock_shadow
;
3394 XRestackWindows(dpy
, wins
, 2);
3395 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3396 ICON_SIZE
, ICON_SIZE
);
3398 if (icon
->pixmap
!=None
)
3399 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3401 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3403 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3404 XClearWindow(dpy
, scr
->dock_shadow
);
3406 XMapWindow(dpy
, scr
->dock_shadow
);
3412 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3413 |ButtonMotionMask
|ExposureMask
, &ev
);
3421 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3422 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3423 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3424 |ButtonReleaseMask
|ButtonPressMask
,
3425 wCursor
[WCUR_MOVE
], CurrentTime
);
3432 x
= ev
.xmotion
.x_root
- ofs_x
;
3433 y
= ev
.xmotion
.y_root
- ofs_y
;
3434 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3437 if (last_dock
!= dock
&& collapsed
) {
3438 last_dock
->collapsed
= 1;
3439 wDockHideIcons(last_dock
);
3442 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3443 dock
->collapsed
= 0;
3444 wDockShowIcons(dock
);
3449 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3452 if (last_dock
!= dock2
&& collapsed
) {
3453 last_dock
->collapsed
= 1;
3454 wDockHideIcons(last_dock
);
3457 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3458 dock2
->collapsed
= 0;
3459 wDockShowIcons(dock2
);
3464 if (aicon
->launching
3465 || (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3466 || (!aicon
->running
&& tmp
)) {
3467 shad_x
= last_dock
->x_pos
+ ix
*wPreferences
.icon_size
;
3468 shad_y
= last_dock
->y_pos
+ iy
*wPreferences
.icon_size
;
3470 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3473 XMapWindow(dpy
, scr
->dock_shadow
);
3475 if (!collapsed
&& (collapsed
= last_dock
->collapsed
)) {
3476 last_dock
->collapsed
= 0;
3477 wDockShowIcons(last_dock
);
3484 XUnmapWindow(dpy
, scr
->dock_shadow
);
3486 if (last_dock
&& collapsed
&&
3487 aicon
->running
&& (ev
.xmotion
.state
& MOD_MASK
)) {
3488 last_dock
->collapsed
= 1;
3489 wDockHideIcons(last_dock
);
3496 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3503 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3505 XUngrabPointer(dpy
, CurrentTime
);
3507 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3508 XUnmapWindow(dpy
, scr
->dock_shadow
);
3510 reattachIcon(dock
, aicon
, ix
, iy
);
3512 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3514 /* Slide it back if dock rejected it */
3515 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3517 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3519 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3527 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3528 /* We need to deselect it, even if is deselected in
3529 * wDockDetach(), because else DoKaboom() will fail.
3531 if (aicon
->icon
->selected
)
3532 wIconSelect(aicon
->icon
);
3533 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3536 wDockDetach(dock
, aicon
);
3539 last_dock
->collapsed
= 1;
3540 wDockHideIcons(last_dock
);
3545 XFreePixmap(dpy
, ghost
);
3546 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3549 puts("End icon move");
3558 getClipButton(int px
, int py
)
3560 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
3562 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3565 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
3566 return CLIP_FORWARD
;
3567 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
3575 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3578 int done
, direction
, new_ws
;
3580 WDock
*clip
= scr
->clip_icon
->dock
;
3582 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3584 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3585 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3587 wClipIconPaint(scr
->clip_icon
);
3590 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
3591 |ButtonPressMask
, &ev
);
3598 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3599 if (new_dir
!= direction
) {
3600 direction
= new_dir
;
3601 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3602 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3603 wClipIconPaint(scr
->clip_icon
);
3611 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3616 clip
->lclip_button_pushed
= 0;
3617 clip
->rclip_button_pushed
= 0;
3619 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3621 if (direction
== CLIP_FORWARD
) {
3622 if (scr
->current_workspace
< scr
->workspace_count
-1)
3623 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3624 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
3625 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3626 else if (wPreferences
.ws_cycle
)
3627 wWorkspaceChange(scr
, 0);
3629 else if (direction
== CLIP_REWIND
) {
3630 if (scr
->current_workspace
> 0)
3631 wWorkspaceChange(scr
, scr
->current_workspace
-1);
3632 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
3633 wWorkspaceChange(scr
, scr
->workspace_count
-1);
3636 wClipIconPaint(scr
->clip_icon
);
3641 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3643 WAppIcon
*aicon
= desc
->parent
;
3644 WDock
*dock
= aicon
->dock
;
3645 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3650 scr
->last_dock
= dock
;
3652 if (dock
->menu
->flags
.mapped
)
3653 wMenuUnmap(dock
->menu
);
3655 if (IsDoubleClick(scr
, event
)) {
3656 /* double-click was not in the main clip icon */
3657 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
3658 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
3659 iconDblClick(desc
, event
);
3664 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
3665 XUnmapWindow(dpy
, scr
->clip_balloon
);
3666 scr
->flags
.clip_balloon_mapped
= 0;
3670 puts("handling dock");
3672 if (event
->xbutton
.button
== Button1
) {
3673 if (event
->xbutton
.state
& MOD_MASK
)
3678 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
3679 dock
->type
!=WM_DOCK
) {
3680 wIconSelect(aicon
->icon
);
3684 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
3685 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
3686 && dock
->type
==WM_CLIP
)
3687 handleClipChangeWorkspace(scr
, event
);
3689 handleDockMove(dock
, aicon
, event
);
3691 handleIconMove(dock
, aicon
, event
);
3693 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
3694 aicon
->xindex
==0 && aicon
->yindex
==0) {
3695 openClipWorkspaceMenu(scr
, event
->xbutton
.x_root
+2,
3696 event
->xbutton
.y_root
+2);
3697 if (scr
->clip_ws_menu
) {
3699 menu
= scr
->clip_ws_menu
;
3700 desc
= &menu
->menu
->descriptor
;
3702 event
->xany
.send_event
= True
;
3703 (*desc
->handle_mousedown
)(desc
, event
);
3705 } else if (event
->xbutton
.button
== Button3
) {
3706 openDockMenu(dock
, aicon
, event
);
3712 showClipBalloon(WDock
*dock
, int workspace
)
3716 WScreen
*scr
= dock
->screen_ptr
;
3720 scr
->flags
.clip_balloon_mapped
= 1;
3721 XMapWindow(dpy
, scr
->clip_balloon
);
3723 text
= scr
->workspaces
[workspace
]->name
;
3725 w
= wTextWidth(scr
->clip_title_font
->font
, text
, strlen(text
));
3727 h
= scr
->clip_title_font
->height
;
3728 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
3730 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
3731 y
= dock
->y_pos
+ ICON_SIZE
-scr
->clip_title_font
->height
- 3;
3733 if (x
+w
> scr
->scr_width
) {
3734 x
= scr
->scr_width
- w
;
3735 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
3736 y
= dock
->y_pos
- h
- 1;
3738 y
= dock
->y_pos
+ ICON_SIZE
;
3739 XRaiseWindow(dpy
, scr
->clip_balloon
);
3741 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
3742 stack
[1] = scr
->clip_balloon
;
3743 XRestackWindows(dpy
, stack
, 2);
3745 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
3746 XSetForeground(dpy
, scr
->clip_title_gc
,
3747 scr
->clip_title_pixel
[CLIP_NORMAL
]);
3748 XClearWindow(dpy
, scr
->clip_balloon
);
3749 wDrawString(scr
->clip_balloon
, scr
->clip_title_font
, scr
->clip_title_gc
,
3750 0, scr
->clip_title_font
->y
, text
, strlen(text
));
3755 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3757 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
3760 assert(event
->type
==EnterNotify
);
3762 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
3766 if (!dock
|| dock
->type
!=WM_CLIP
)
3769 if (btn
->xindex
== 0 && btn
->yindex
== 0)
3770 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
3772 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
3773 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
3774 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
3777 if (!dock
->auto_collapse
)
3780 if (dock
->auto_collapse_magic
) {
3781 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3782 dock
->auto_collapse_magic
= NULL
;
3785 if (dock
->collapsed
)
3786 toggleCollapsed(dock
);
3791 clipLeave(WDock
*dock
)
3793 if (!dock
|| dock
->type
!=WM_CLIP
|| !dock
->auto_collapse
)
3796 if (dock
->auto_collapse_magic
) {
3797 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3798 dock
->auto_collapse_magic
= NULL
;
3800 if (!dock
->collapsed
) {
3801 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
3809 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
3811 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
3813 assert(event
->type
==LeaveNotify
);
3815 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
3818 clipLeave(btn
->dock
);
3823 clipAutoCollapse(void *cdata
)
3825 WDock
*dock
= (WDock
*)cdata
;
3827 if (dock
->type
!=WM_CLIP
|| !dock
->auto_collapse
)
3830 if (!dock
->collapsed
&& dock
->auto_collapse_magic
!=NULL
) {
3831 toggleCollapsed(dock
);
3833 dock
->auto_collapse_magic
= NULL
;