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
);
435 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
436 aicon
->x_pos
, aicon
->y_pos
);
437 if (!dock
->mapped
|| dock
->collapsed
)
438 XMapWindow(dpy
, aicon
->icon
->core
->window
);
440 list_remove_head(&selectedIcons
);
443 if (wPreferences
.auto_arrange_icons
)
444 wArrangeIcons(dock
->screen_ptr
, True
);
449 keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
451 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
454 LinkedList
*selectedIcons
;
456 assert(clickedIcon
!=NULL
);
457 dock
= clickedIcon
->dock
;
459 selectedIcons
= getSelected(dock
);
461 if (!selectedIcons
&& clickedIcon
!=dock
->screen_ptr
->clip_icon
) {
462 char *command
= NULL
;
464 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
465 clickedIcon
->editing
= 1;
466 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
467 _("Type the command used to launch the application"),
469 if (command
&& (command
[0]==0 ||
470 (command
[0]=='-' && command
[1]==0))) {
474 clickedIcon
->command
= command
;
475 clickedIcon
->editing
= 0;
477 clickedIcon
->editing
= 0;
484 selectedIcons
= list_cons(clickedIcon
, NULL
);
487 while (selectedIcons
) {
488 aicon
= selectedIcons
->head
;
489 if (aicon
->icon
->selected
)
490 wIconSelect(aicon
->icon
);
491 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
492 aicon
->attracted
= 0;
493 if (aicon
->icon
->shadowed
) {
494 aicon
->icon
->shadowed
= 0;
495 aicon
->icon
->force_paint
= 1;
496 wAppIconPaint(aicon
);
499 list_remove_head(&selectedIcons
);
507 toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
509 WDock
*dock
= (WDock
*)entry
->clientdata
;
511 assert(entry
->clientdata
!=NULL
);
513 dock
->attract_icons
= !dock
->attract_icons
;
514 /*if (!dock->attract_icons)
515 dock->keep_attracted = 0;*/
517 entry
->flags
.indicator_on
= dock
->attract_icons
;
524 toggleKeepCallback(WMenu
*menu
, WMenuEntry
*entry
)
526 WDock
*dock
= (WDock
*)entry
->clientdata
;
530 assert(entry
->clientdata
!=NULL
);
532 dock
->keep_attracted
= !dock
->keep_attracted
;
534 if (dock
->keep_attracted
) {
535 for (i
=0; i
< dock
->max_icons
; i
++) {
536 btn
= dock
->icon_array
[i
];
537 if (btn
&& btn
->attracted
&& btn
->command
) {
539 if (btn
->icon
->shadowed
) {
540 btn
->icon
->shadowed
= 0;
541 btn
->icon
->force_paint
= 1;
548 entry
->flags
.indicator_on
= dock
->keep_attracted
;
555 selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
557 WAppIcon
*icon
= (WAppIcon
*)entry
->clientdata
;
561 wIconSelect(icon
->icon
);
568 colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
570 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
573 int x
, y
, x_pos
, y_pos
;
575 assert(entry
->clientdata
!=NULL
);
576 clip
= clickedIcon
->dock
;
578 aicon
= clip
->screen_ptr
->app_icon_list
;
581 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
582 x_pos
= clip
->x_pos
+ x
*ICON_SIZE
;
583 y_pos
= clip
->y_pos
+ y
*ICON_SIZE
;
584 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
586 if (wPreferences
.no_animations
) {
587 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
589 SlideWindow(aicon
->icon
->core
->window
,
590 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
593 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
594 #endif /* ANIMATIONS */
596 aicon
->attracted
= 1;
597 if (!clip
->keep_attracted
&& !aicon
->icon
->shadowed
) {
598 aicon
->icon
->shadowed
= 1;
599 aicon
->icon
->force_paint
= 1;
600 /* We don't do an wAppIconPaint() here because it's in
601 * wDockAttachIcon(). -Dan
604 wDockAttachIcon(clip
, aicon
, x
, y
);
605 if (clip
->collapsed
|| !clip
->mapped
)
606 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
614 selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
616 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
618 LinkedList
*selectedIcons
;
622 assert(clickedIcon
!=NULL
);
623 dock
= clickedIcon
->dock
;
625 selectedIcons
= getSelected(dock
);
627 if (!selectedIcons
) {
628 for (i
=1; i
<dock
->max_icons
; i
++) {
629 btn
= dock
->icon_array
[i
];
630 if (btn
&& !btn
->icon
->selected
) {
631 wIconSelect(btn
->icon
);
635 while(selectedIcons
) {
636 btn
= selectedIcons
->head
;
637 wIconSelect(btn
->icon
);
638 list_remove_head(&selectedIcons
);
647 toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
649 assert(entry
->clientdata
!=NULL
);
651 toggleCollapsed(entry
->clientdata
);
653 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->collapsed
;
660 toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
662 assert(entry
->clientdata
!=NULL
);
664 toggleAutoCollapse(entry
->clientdata
);
666 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_collapse
;
673 launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
675 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
677 launchDockedApplication(btn
);
682 settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
684 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
688 ShowDockAppSettingsPanel(btn
);
693 hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
696 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
698 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
700 if (wapp
->flags
.hidden
) {
701 wWorkspaceChange(btn
->icon
->core
->screen_ptr
,wapp
->last_workspace
);
702 wUnhideApplication(wapp
, False
, False
);
704 wHideApplication(wapp
);
710 unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
713 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
715 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
717 wUnhideApplication(wapp
, False
, True
);
722 mainIconCreate(WScreen
*scr
, int type
)
727 if (type
== WM_CLIP
) {
729 return scr
->clip_icon
;
730 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
731 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
732 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
733 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
734 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE;*/
738 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
739 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
745 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
746 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
747 btn
->icon
->core
->descriptor
.parent
= btn
;
748 /*ChangeStackingLevel(btn->icon->core, WMDockLevel);*/
749 XMapWindow(dpy
, btn
->icon
->core
->window
);
754 scr
->clip_icon
= btn
;
761 switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
763 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
764 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
766 LinkedList
*selectedIcons
;
769 if (entry
->order
== scr
->current_workspace
)
772 dest
= scr
->workspaces
[entry
->order
]->clip
;
774 selectedIcons
= getSelected(src
);
777 while(selectedIcons
) {
778 btn
= selectedIcons
->head
;
779 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
780 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
781 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
783 list_remove_head(&selectedIcons
);
785 } else if (icon
!= scr
->clip_icon
) {
786 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
787 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
788 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
796 launchDockedApplication(WAppIcon
*btn
)
798 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
800 if (!btn
->launching
&& btn
->command
!=NULL
) {
801 if (!btn
->forced_dock
) {
802 btn
->relaunching
= btn
->running
;
805 if (btn
->wm_instance
|| btn
->wm_class
) {
806 WWindowAttributes attr
;
807 memset(&attr
, 0, sizeof(WWindowAttributes
));
808 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
, &attr
,
811 if (!attr
.no_appicon
&& !btn
->buggy_app
)
816 btn
->drop_launch
= 0;
817 scr
->last_dock
= btn
->dock
;
818 btn
->pid
= execCommand(btn
, btn
->command
, NULL
);
820 if (btn
->buggy_app
) {
821 /* give feedback that the app was launched */
825 WMAddTimerHandler(200, (WMCallback
*)dockIconPaint
, btn
);
830 wwarning(_("could not launch application %s\n"), btn
->command
);
832 if (!btn
->relaunching
)
841 updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
843 WScreen
*scr
= menu
->frame
->screen_ptr
;
844 char title
[MAX_WORKSPACENAME_WIDTH
+1];
850 for (i
=0; i
<scr
->workspace_count
; i
++) {
851 if (i
< menu
->entry_no
) {
852 if (strcmp(menu
->entries
[i
]->text
,scr
->workspaces
[i
]->name
)!=0) {
853 free(menu
->entries
[i
]->text
);
854 strcpy(title
, scr
->workspaces
[i
]->name
);
855 menu
->entries
[i
]->text
= wstrdup(title
);
856 menu
->flags
.realized
= 0;
858 menu
->entries
[i
]->clientdata
= (void*)icon
;
860 strcpy(title
, scr
->workspaces
[i
]->name
);
862 wMenuAddCallback(menu
, title
, switchWSCommand
, (void*)icon
);
864 menu
->flags
.realized
= 0;
866 if (i
== scr
->current_workspace
) {
867 wMenuSetEnabled(menu
, i
, False
);
869 wMenuSetEnabled(menu
, i
, True
);
873 if (!menu
->flags
.realized
)
879 makeWorkspaceMenu(WScreen
*scr
)
883 menu
= wMenuCreate(scr
, NULL
, False
);
885 wwarning(_("could not create workspace submenu for Clip menu"));
887 wMenuAddCallback(menu
, "", switchWSCommand
, (void*)scr
->clip_icon
);
889 menu
->flags
.realized
= 0;
897 updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
906 entry
= menu
->entries
[index
];
907 entry
->flags
.indicator_on
= !dock
->lowered
;
908 entry
->clientdata
= dock
;
911 entry
= menu
->entries
[++index
];
912 entry
->flags
.indicator_on
= dock
->collapsed
;
913 entry
->clientdata
= dock
;
916 entry
= menu
->entries
[++index
];
917 entry
->flags
.indicator_on
= dock
->auto_collapse
;
918 entry
->clientdata
= dock
;
921 entry
= menu
->entries
[++index
];
922 entry
->flags
.indicator_on
= dock
->attract_icons
;
923 entry
->clientdata
= dock
;
925 /* keep attracted icons */
926 entry
= menu
->entries
[++index
];
927 entry
->flags
.indicator_on
= dock
->keep_attracted
;
928 entry
->clientdata
= dock
;
930 menu
->flags
.realized
= 0;
936 makeClipOptionsMenu(WScreen
*scr
)
941 menu
= wMenuCreate(scr
, NULL
, False
);
943 wwarning(_("could not create options submenu for Clip menu"));
947 entry
= wMenuAddCallback(menu
, _("Keep on top"),
948 toggleLoweredCallback
, NULL
);
949 entry
->flags
.indicator
= 1;
950 entry
->flags
.indicator_on
= 1;
951 entry
->flags
.indicator_type
= MI_CHECK
;
953 entry
= wMenuAddCallback(menu
, _("Collapsed"),
954 toggleCollapsedCallback
, NULL
);
955 entry
->flags
.indicator
= 1;
956 entry
->flags
.indicator_on
= 1;
957 entry
->flags
.indicator_type
= MI_CHECK
;
959 entry
= wMenuAddCallback(menu
, _("AutoCollapse"),
960 toggleAutoCollapseCallback
, NULL
);
961 entry
->flags
.indicator
= 1;
962 entry
->flags
.indicator_on
= 1;
963 entry
->flags
.indicator_type
= MI_CHECK
;
965 entry
= wMenuAddCallback(menu
, _("AutoAttract Icons"),
966 toggleAutoAttractCallback
, NULL
);
967 entry
->flags
.indicator
= 1;
968 entry
->flags
.indicator_on
= 1;
969 entry
->flags
.indicator_type
= MI_CHECK
;
971 entry
= wMenuAddCallback(menu
, _("Keep Attracted Icons"),
972 toggleKeepCallback
, NULL
);
973 entry
->flags
.indicator
= 1;
974 entry
->flags
.indicator_on
= 1;
975 entry
->flags
.indicator_type
= MI_CHECK
;
977 menu
->flags
.realized
= 0;
985 dockMenuCreate(WScreen
*scr
, int type
)
990 if (type
== WM_CLIP
&& scr
->clip_menu
)
991 return scr
->clip_menu
;
993 menu
= wMenuCreate(scr
, NULL
, False
);
994 if (type
!= WM_CLIP
) {
995 entry
= wMenuAddCallback(menu
, _("Keep on top"),
996 toggleLoweredCallback
, NULL
);
997 entry
->flags
.indicator
= 1;
998 entry
->flags
.indicator_on
= 1;
999 entry
->flags
.indicator_type
= MI_CHECK
;
1001 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1002 scr
->clip_options
= makeClipOptionsMenu(scr
);
1003 if (scr
->clip_options
)
1004 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1006 wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1008 wMenuAddCallback(menu
, _("(Un)Select Icon"), selectCallback
, NULL
);
1010 wMenuAddCallback(menu
, _("(Un)Select All Icons"), selectIconsCallback
,
1013 wMenuAddCallback(menu
, _("Keep Icon(s)"), keepIconsCallback
, NULL
);
1015 entry
= wMenuAddCallback(menu
, _("Move Icon(s) To"), NULL
, NULL
);
1016 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1017 if (scr
->clip_submenu
)
1018 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1020 wMenuAddCallback(menu
, _("Remove Icon(s)"), removeIconsCallback
, NULL
);
1022 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1025 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1027 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1029 wMenuAddCallback(menu
, _("(Un)Hide"), hideCallback
, NULL
);
1031 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1033 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1035 if (type
== WM_CLIP
)
1036 scr
->clip_menu
= menu
;
1043 wDockCreate(WScreen
*scr
, int type
)
1051 dock
= wmalloc(sizeof(WDock
));
1052 memset(dock
, 0, sizeof(WDock
));
1054 if (type
== WM_CLIP
)
1055 icon_count
= CLIP_MAX_ICONS
;
1057 icon_count
= scr
->scr_height
/wPreferences
.icon_size
;
1059 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*)*icon_count
);
1060 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*)*icon_count
);
1062 dock
->max_icons
= icon_count
;
1064 btn
= mainIconCreate(scr
, type
);
1068 dock
->x_pos
= btn
->x_pos
;
1069 dock
->y_pos
= btn
->y_pos
;
1070 dock
->screen_ptr
= scr
;
1072 dock
->icon_count
= 1;
1073 dock
->on_right_side
= 1;
1074 dock
->collapsed
= 0;
1075 dock
->auto_collapse
= 0;
1076 dock
->auto_collapse_magic
= NULL
;
1077 dock
->attract_icons
= 0;
1078 dock
->keep_attracted
= 0;
1080 dock
->icon_array
[0] = btn
;
1081 wRaiseFrame(btn
->icon
->core
);
1082 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1084 /* create dock menu */
1085 dock
->menu
= dockMenuCreate(scr
, type
);
1092 wDockDestroy(WDock
*dock
)
1097 for (i
=(dock
->type
== WM_CLIP
) ? 1 : 0; i
<dock
->max_icons
; i
++) {
1098 aicon
= dock
->icon_array
[i
];
1100 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1101 wDockDetach(dock
, aicon
);
1103 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
1104 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
1105 aicon
->x_pos
, aicon
->y_pos
);
1106 if (!dock
->mapped
|| dock
->collapsed
)
1107 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1111 if (wPreferences
.auto_arrange_icons
)
1112 wArrangeIcons(dock
->screen_ptr
, True
);
1113 free(dock
->icon_array
);
1114 if (dock
->menu
&& dock
->type
!=WM_CLIP
)
1115 wMenuDestroy(dock
->menu
, True
);
1121 wClipIconPaint(WAppIcon
*aicon
)
1123 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1124 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1126 Window win
= aicon
->icon
->core
->window
;
1127 int length
, nlength
;
1128 char *ws_name
, ws_number
[10];
1131 wIconPaint(aicon
->icon
);
1133 length
= strlen(workspace
->name
);
1134 ws_name
= malloc(length
+ 1);
1135 sprintf(ws_name
, "%s", workspace
->name
);
1136 sprintf(ws_number
, "%i", scr
->current_workspace
+ 1);
1137 nlength
= strlen(ws_number
);
1139 gc
= scr
->clip_title_gc
;
1141 if (!workspace
->clip
->collapsed
)
1142 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_NORMAL
]);
1144 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_COLLAPSED
]);
1146 ty
= ICON_SIZE
- scr
->clip_title_font
->height
- 3;
1148 tx
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
1150 wDrawString(win
, scr
->clip_title_font
, gc
, tx
,
1151 ty
+ scr
->clip_title_font
->y
, ws_name
, length
);
1153 tx
= (ICON_SIZE
/2 - wTextWidth(scr
->clip_title_font
->font
, ws_number
, nlength
))/2;
1155 wDrawString(win
, scr
->clip_title_font
, gc
, tx
,
1156 scr
->clip_title_font
->y
+ 2, ws_number
, nlength
);
1160 if (aicon
->launching
) {
1161 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1162 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1164 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
,
1165 aicon
->dock
->rclip_button_pushed
);
1170 clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1172 wClipIconPaint(desc
->parent
);
1177 dockIconPaint(WAppIcon
*btn
)
1179 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1180 wClipIconPaint(btn
);
1187 make_icon_state(WAppIcon
*btn
)
1189 proplist_t node
= NULL
;
1190 proplist_t command
, autolaunch
, name
, forced
, host
, position
, buggy
;
1196 command
= PLMakeString("-");
1198 command
= PLMakeString(btn
->command
);
1200 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1202 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1204 name
= PLMakeString(tmp
);
1208 forced
= btn
->forced_dock
? dYes
: dNo
;
1210 buggy
= btn
->buggy_app
? dYes
: dNo
;
1212 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1213 sprintf(buffer
, "%i,%i", btn
->x_pos
, btn
->y_pos
);
1215 sprintf(buffer
, "%hi,%hi", btn
->xindex
, btn
->yindex
);
1216 position
= PLMakeString(buffer
);
1218 node
= PLMakeDictionaryFromEntries(dCommand
, command
,
1220 dAutoLaunch
, autolaunch
,
1222 dBuggyApplication
, buggy
,
1223 dPosition
, position
,
1227 PLRelease(position
);
1229 if (btn
->dnd_command
) {
1230 command
= PLMakeString(btn
->dnd_command
);
1231 PLInsertDictionaryEntry(node
, dDropCommand
, command
);
1234 #endif /* OFFIX_DND */
1236 if (btn
->client_machine
&& btn
->remote_start
) {
1237 host
= PLMakeString(btn
->client_machine
);
1238 PLInsertDictionaryEntry(node
, dHost
, host
);
1248 dockSaveState(WDock
*dock
)
1251 proplist_t icon_info
;
1252 proplist_t list
=NULL
, dock_state
=NULL
;
1256 list
= PLMakeArrayFromElements(NULL
);
1258 for (i
=(dock
->type
==WM_DOCK
? 0 : 1); i
<dock
->max_icons
; i
++) {
1259 WAppIcon
*btn
= dock
->icon_array
[i
];
1261 if (!btn
|| (btn
->attracted
&& !dock
->keep_attracted
))
1264 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1265 list
= PLAppendArrayElement(list
, icon_info
);
1266 PLRelease(icon_info
);
1270 dock_state
= PLMakeDictionaryFromEntries(dApplications
, list
, NULL
);
1274 if (dock
->type
== WM_DOCK
) {
1275 sprintf(buffer
, "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0),
1277 value
= PLMakeString(buffer
);
1278 PLInsertDictionaryEntry(dock_state
, dPosition
, value
);
1282 value
= (dock
->lowered
? dYes
: dNo
);
1283 PLInsertDictionaryEntry(dock_state
, dLowered
, value
);
1285 if (dock
->type
== WM_CLIP
) {
1286 value
= (dock
->collapsed
? dYes
: dNo
);
1287 PLInsertDictionaryEntry(dock_state
, dCollapsed
, value
);
1289 value
= (dock
->auto_collapse
? dYes
: dNo
);
1290 PLInsertDictionaryEntry(dock_state
, dAutoCollapse
, value
);
1292 value
= (dock
->attract_icons
? dYes
: dNo
);
1293 PLInsertDictionaryEntry(dock_state
, dAutoAttractIcons
, value
);
1295 value
= (dock
->keep_attracted
? dYes
: dNo
);
1296 PLInsertDictionaryEntry(dock_state
, dKeepAttracted
, value
);
1304 wDockSaveState(WScreen
*scr
)
1306 proplist_t dock_state
;
1308 dock_state
= dockSaveState(scr
->dock
);
1310 PLInsertDictionaryEntry(scr
->session_state
, dDock
, dock_state
);
1312 PLRelease(dock_state
);
1317 wClipSaveState(WScreen
*scr
)
1319 proplist_t clip_state
;
1321 clip_state
= make_icon_state(scr
->clip_icon
);
1323 PLInsertDictionaryEntry(scr
->session_state
, dClip
, clip_state
);
1325 PLRelease(clip_state
);
1330 wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1332 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1337 restore_icon_state(WScreen
*scr
, proplist_t info
, int type
, int index
)
1340 char *wclass
, *winstance
;
1341 proplist_t cmd
, value
;
1345 cmd
= PLGetDictionaryEntry(info
, dCommand
);
1346 if (!cmd
|| !PLIsString(cmd
)) {
1350 /* parse window name */
1351 value
= PLGetDictionaryEntry(info
, dName
);
1355 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1357 if (!winstance
&& !wclass
) {
1364 command
= wstrdup(PLGetString(cmd
));
1368 if (!command
|| strcmp(command
, "-")==0) {
1379 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
,
1386 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1387 if (type
== WM_CLIP
) {
1388 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1389 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1391 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1392 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1396 cmd
= PLGetDictionaryEntry(info
, dDropCommand
);
1398 aicon
->dnd_command
= wstrdup(PLGetString(cmd
));
1401 /* check auto launch */
1402 value
= PLGetDictionaryEntry(info
, dAutoLaunch
);
1404 aicon
->auto_launch
= 0;
1406 if (PLIsString(value
)) {
1407 if (strcasecmp(PLGetString(value
), "YES")==0)
1408 aicon
->auto_launch
= 1;
1410 wwarning(_("bad value in docked icon state info %s"),
1411 PLGetString(dAutoLaunch
));
1415 /* check if it wasn't normally docked */
1416 value
= PLGetDictionaryEntry(info
, dForced
);
1418 aicon
->forced_dock
= 0;
1420 if (PLIsString(value
)) {
1421 if (strcasecmp(PLGetString(value
), "YES")==0)
1422 aicon
->forced_dock
= 1;
1424 wwarning(_("bad value in docked icon state info %s"),
1425 PLGetString(dForced
));
1429 /* check if we can rely on the stuff in the app */
1430 value
= PLGetDictionaryEntry(info
, dBuggyApplication
);
1432 aicon
->buggy_app
= 0;
1434 if (PLIsString(value
)) {
1435 if (strcasecmp(PLGetString(value
), "YES")==0)
1436 aicon
->buggy_app
= 1;
1438 wwarning(_("bad value in docked icon state info %s"),
1439 PLGetString(dBuggyApplication
));
1443 /* get position in the dock */
1444 value
= PLGetDictionaryEntry(info
, dPosition
);
1445 if (value
&& PLIsString(value
)) {
1446 if (sscanf(PLGetString(value
), "%hi,%hi", &aicon
->xindex
,
1448 wwarning(_("bad value in docked icon state info %s"),
1449 PLGetString(dPosition
));
1451 /* check position sanity */
1452 /* incomplete section! */
1453 if (type
== WM_DOCK
) {
1455 if (aicon
->yindex
< 0)
1456 wwarning(_("bad value in docked icon position %i,%i"),
1457 aicon
->xindex
, aicon
->yindex
);
1460 aicon
->yindex
= index
;
1471 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1475 wClipRestoreState(WScreen
*scr
, proplist_t clip_state
)
1481 icon
= mainIconCreate(scr
, WM_CLIP
);
1486 PLRetain(clip_state
);
1488 /* restore position */
1490 value
= PLGetDictionaryEntry(clip_state
, dPosition
);
1493 if (!PLIsString(value
))
1494 COMPLAIN("Position");
1496 if (sscanf(PLGetString(value
), "%i,%i", &icon
->x_pos
,
1498 COMPLAIN("Position");
1500 /* check position sanity */
1501 if (icon
->y_pos
< 0)
1503 else if (icon
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1504 icon
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1506 if (icon
->x_pos
< 0)
1508 else if (icon
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1509 icon
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1514 value
= PLGetDictionaryEntry(clip_state
, dDropCommand
);
1515 if (value
&& PLIsString(value
))
1516 icon
->dnd_command
= wstrdup(PLGetString(value
));
1519 PLRelease(clip_state
);
1526 wDockRestoreState(WScreen
*scr
, proplist_t dock_state
, int type
)
1531 WAppIcon
*aicon
, *old_top
;
1535 dock
= wDockCreate(scr
, type
);
1541 PLRetain(dock_state
);
1544 /* restore position */
1546 value
= PLGetDictionaryEntry(dock_state
, dPosition
);
1549 if (!PLIsString(value
))
1550 COMPLAIN("Position");
1552 if (sscanf(PLGetString(value
), "%i,%i", &dock
->x_pos
,
1554 COMPLAIN("Position");
1556 /* check position sanity */
1557 if (dock
->y_pos
< 0)
1559 else if (dock
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1560 dock
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1562 /* This is no more needed. ??? */
1563 if (type
== WM_CLIP
) {
1564 if (dock
->x_pos
< 0)
1566 else if (dock
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1567 dock
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1570 if (dock
->x_pos
>= 0) {
1571 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1572 dock
->on_right_side
= 0;
1574 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1575 dock
->on_right_side
= 1;
1581 /* restore lowered/raised state */
1585 value
= PLGetDictionaryEntry(dock_state
, dLowered
);
1588 if (!PLIsString(value
))
1589 COMPLAIN("Lowered");
1591 if (strcasecmp(PLGetString(value
), "YES")==0)
1597 /* restore collapsed state */
1599 dock
->collapsed
= 0;
1601 value
= PLGetDictionaryEntry(dock_state
, dCollapsed
);
1604 if (!PLIsString(value
))
1605 COMPLAIN("Collapsed");
1607 if (strcasecmp(PLGetString(value
), "YES")==0)
1608 dock
->collapsed
= 1;
1613 /* restore auto-collapsed state */
1615 value
= PLGetDictionaryEntry(dock_state
, dAutoCollapse
);
1618 if (!PLIsString(value
))
1619 COMPLAIN("AutoCollapse");
1621 if (strcasecmp(PLGetString(value
), "YES")==0) {
1622 dock
->auto_collapse
= 1;
1623 dock
->collapsed
= 1;
1629 /* restore attract icons state */
1631 dock
->attract_icons
= 0;
1633 value
= PLGetDictionaryEntry(dock_state
, dAutoAttractIcons
);
1636 if (!PLIsString(value
))
1637 COMPLAIN("AutoAttractIcons");
1639 if (strcasecmp(PLGetString(value
), "YES")==0)
1640 dock
->attract_icons
= 1;
1645 /* restore keep attracted icons state */
1647 dock
->keep_attracted
= 0;
1649 value
= PLGetDictionaryEntry(dock_state
, dKeepAttracted
);
1652 if (!PLIsString(value
))
1653 COMPLAIN("KeepAttracted");
1655 if (strcasecmp(PLGetString(value
), "YES")==0)
1656 dock
->keep_attracted
= 1;
1661 /* application list */
1663 apps
= PLGetDictionaryEntry(dock_state
, dApplications
);
1669 count
= PLGetNumberOfElements(apps
);
1674 old_top
= dock
->icon_array
[0];
1676 /* dock->icon_count is set to 1 when dock is created.
1677 * Since Clip is already restored, we want to keep it so for clip,
1678 * but for dock we may change the default top tile, so we set it to 0.
1680 if (type
== WM_DOCK
)
1681 dock
->icon_count
= 0;
1683 for (i
=0; i
<count
; i
++) {
1684 if (dock
->icon_count
>= dock
->max_icons
) {
1685 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1689 value
= PLGetArrayElement(apps
, i
);
1690 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1692 dock
->icon_array
[dock
->icon_count
] = aicon
;
1696 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
*ICON_SIZE
);
1697 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
*ICON_SIZE
);
1700 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1702 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1704 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
,
1707 if (!dock
->collapsed
)
1708 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1709 wRaiseFrame(aicon
->icon
->core
);
1712 } else if (dock
->icon_count
==0 && type
==WM_DOCK
)
1716 /* if the first icon is not defined, use the default */
1717 if (dock
->icon_array
[0]==NULL
) {
1718 /* update default icon */
1719 old_top
->x_pos
= dock
->x_pos
;
1720 old_top
->y_pos
= dock
->y_pos
;
1722 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1724 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1725 dock
->icon_array
[0] = old_top
;
1726 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1727 /* we don't need to increment dock->icon_count here because it was
1728 * incremented in the loop above.
1730 } else if (old_top
!=dock
->icon_array
[0]) {
1731 if (old_top
== scr
->clip_icon
)
1732 scr
->clip_icon
= dock
->icon_array
[0];
1733 wAppIconDestroy(old_top
);
1738 PLRelease(dock_state
);
1746 wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1748 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1750 btn
->drop_launch
= 0;
1752 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1755 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1767 wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1773 for (i
=0; i
< dock
->max_icons
; i
++) {
1774 btn
= dock
->icon_array
[i
];
1775 if (!btn
|| !btn
->auto_launch
)
1778 state
= wmalloc(sizeof(WSavedState
));
1779 memset(state
, 0, sizeof(WSavedState
));
1780 state
->workspace
= workspace
;
1781 /* TODO: this is klugy and is very difficult to understand
1782 * what's going on. Try to clean up */
1783 wDockLaunchWithState(dock
, btn
, state
);
1787 #ifdef REDUCE_APPICONS
1789 wDockSimulateLaunch(WDock
*dock
, WAppIcon
*btn
)
1791 if ((btn
== NULL
) || (dock
== NULL
))
1794 if (!btn
->running
) {
1795 if ((btn
->icon
->owner
== NULL
) && (btn
->applist
))
1796 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
1797 if (!btn
->forced_dock
)
1807 findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1813 if ((dock
= scr
->dock
)!=NULL
) {
1814 for (i
=0; i
<dock
->max_icons
; i
++) {
1815 if (dock
->icon_array
[i
]
1816 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1822 if (*icon_pos
<0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
)!=NULL
) {
1823 for (i
=0; i
<dock
->max_icons
; i
++) {
1824 if (dock
->icon_array
[i
]
1825 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1838 wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
1844 dock
= findDock(scr
, event
, &icon_pos
);
1849 * Return True if the drop was on an application icon window.
1850 * In this case, let the ClientMessage handler redirect the
1851 * message to the app.
1853 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!=None
)
1856 if (dock
->icon_array
[icon_pos
]->dnd_command
!=NULL
) {
1857 scr
->flags
.dnd_data_convertion_status
= 0;
1859 btn
= dock
->icon_array
[icon_pos
];
1861 if (!btn
->forced_dock
) {
1862 btn
->relaunching
= btn
->running
;
1865 if (btn
->wm_instance
|| btn
->wm_class
) {
1866 WWindowAttributes attr
;
1867 memset(&attr
, 0, sizeof(WWindowAttributes
));
1868 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
1870 btn
->wm_class
, &attr
, True
);
1872 if (!attr
.no_appicon
)
1878 btn
->drop_launch
= 1;
1879 scr
->last_dock
= dock
;
1880 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1885 if (!btn
->relaunching
) {
1892 #endif /* OFFIX_DND */
1897 wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1904 wwin
= icon
->icon
->owner
;
1905 if (icon
->command
==NULL
) {
1907 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
1909 icon
->command
= FlattenStringList(argv
, argc
);
1910 XFreeStringList(argv
);
1914 /* icon->forced_dock = 1;*/
1915 if (!icon
->attracted
|| dock
->type
!=WM_CLIP
|| dock
->keep_attracted
) {
1917 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
1918 _("Type the command used to launch the application"),
1920 if (command
&& (command
[0]==0 ||
1921 (command
[0]=='-' && command
[1]==0))) {
1925 icon
->command
= command
;
1931 /* If the target is the dock, reject the icon. If
1932 * the target is the clip, make it an attracted icon
1934 if (dock
->type
==WM_CLIP
) {
1935 icon
->attracted
= 1;
1936 if (!icon
->icon
->shadowed
) {
1937 icon
->icon
->shadowed
= 1;
1938 icon
->icon
->force_paint
= 1;
1950 for (index
=1; index
<dock
->max_icons
; index
++)
1951 if (dock
->icon_array
[index
] == NULL
)
1953 /* if (index == dock->max_icons)
1956 assert(index
< dock
->max_icons
);
1958 dock
->icon_array
[index
] = icon
;
1962 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
1963 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
1968 icon
->launching
= 0;
1971 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1972 if (dock
->type
== WM_CLIP
) {
1973 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1974 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1976 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1977 icon
->icon
->core
->descriptor
.parent
= icon
;
1979 MoveInStackListUnder(dock
->icon_array
[index
-1]->icon
->core
,
1981 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
1982 wAppIconPaint(icon
);
1984 if (wPreferences
.auto_arrange_icons
)
1985 wArrangeIcons(dock
->screen_ptr
, True
);
1988 if (icon
->command
&& !icon
->dnd_command
) {
1989 icon
->dnd_command
= wmalloc(strlen(icon
->command
)+8);
1990 sprintf(icon
->dnd_command
, "%s %%d", icon
->command
);
1999 reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2003 for(index
=1; index
<dock
->max_icons
; index
++) {
2004 if(dock
->icon_array
[index
] == icon
)
2007 assert(index
< dock
->max_icons
);
2012 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2013 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2018 moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2028 wwin
= icon
->icon
->owner
;
2031 * For the moment we can't do this if we move icons in Clip from one
2032 * workspace to other, because if we move two or more icons without
2033 * command, the dialog box will not be able to tell us to which of the
2034 * moved icons it applies. -Dan
2036 if ((dest
->type
==WM_DOCK
/*|| dest->keep_attracted*/) && icon
->command
==NULL
) {
2037 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2039 icon
->command
= FlattenStringList(argv
, argc
);
2040 XFreeStringList(argv
);
2045 /* icon->forced_dock = 1;*/
2046 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2047 _("Type the command used to launch the application"),
2049 if (command
&& (command
[0]==0 ||
2050 (command
[0]=='-' && command
[1]==0))) {
2054 icon
->command
= command
;
2065 for(index
=1; index
<src
->max_icons
; index
++) {
2066 if(src
->icon_array
[index
] == icon
)
2069 assert(index
< src
->max_icons
);
2071 src
->icon_array
[index
] = NULL
;
2074 for(index
=1; index
<dest
->max_icons
; index
++) {
2075 if(dest
->icon_array
[index
] == NULL
)
2078 /* if (index == dest->max_icons)
2081 assert(index
< dest
->max_icons
);
2083 dest
->icon_array
[index
] = icon
;
2086 /* deselect the icon */
2087 if (icon
->icon
->selected
)
2088 wIconSelect(icon
->icon
);
2090 if (dest
->type
== WM_DOCK
) {
2091 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2092 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2094 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2095 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2098 /* set it to be kept when moving to dock, or to a clip that keep the
2100 * Unless the icon does not have a command set
2102 if (icon
->command
&& (dest
->type
==WM_DOCK
|| dest
->keep_attracted
)) {
2103 icon
->attracted
= 0;
2104 if (icon
->icon
->shadowed
) {
2105 icon
->icon
->shadowed
= 0;
2106 icon
->icon
->force_paint
= 1;
2110 if (src
->auto_collapse
)
2116 icon
->x_pos
= dest
->x_pos
+ x
*ICON_SIZE
;
2117 icon
->y_pos
= dest
->y_pos
+ y
*ICON_SIZE
;
2121 MoveInStackListUnder(dest
->icon_array
[index
-1]->icon
->core
,
2123 wAppIconPaint(icon
);
2129 wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2133 /* make the settings panel be closed */
2135 DestroyDockAppSettingsPanel(icon
->panel
);
2140 icon
->attracted
= 0;
2141 if (icon
->icon
->shadowed
) {
2142 icon
->icon
->shadowed
= 0;
2143 icon
->icon
->force_paint
= 1;
2146 /* deselect the icon */
2147 if (icon
->icon
->selected
)
2148 wIconSelect(icon
->icon
);
2150 if (icon
->command
) {
2151 free(icon
->command
);
2152 icon
->command
= NULL
;
2155 if (icon
->dnd_command
) {
2156 free(icon
->dnd_command
);
2157 icon
->dnd_command
= NULL
;
2161 for (index
=1; index
<dock
->max_icons
; index
++)
2162 if (dock
->icon_array
[index
] == icon
)
2164 assert(index
< dock
->max_icons
);
2165 dock
->icon_array
[index
] = NULL
;
2170 /* if the dock is not attached to an application or
2171 * the the application did not set the approriate hints yet,
2172 * destroy the icon */
2173 #ifdef REDUCE_APPICONS
2174 if ((icon
->num_apps
== 0) && (!icon
->running
|| !wApplicationOf(icon
->main_window
)) )
2176 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2178 wAppIconDestroy(icon
);
2180 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2181 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2182 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2183 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2184 icon
->icon
->core
->descriptor
.parent
= icon
;
2186 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2188 wAppIconPaint(icon
);
2189 if (wPreferences
.auto_arrange_icons
) {
2190 wArrangeIcons(dock
->screen_ptr
, True
);
2193 if (dock
->auto_collapse
)
2199 * returns the closest Dock slot index for the passed
2202 * Returns False if icon can't be docked.
2205 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2206 int *ret_x
, int *ret_y
, int redocking
)
2208 WScreen
*scr
= dock
->screen_ptr
;
2211 int i
, offset
= ICON_SIZE
/2;
2212 WAppIcon
*aicon
= NULL
;
2213 WAppIcon
*nicon
= NULL
;
2216 if (wPreferences
.flags
.noupdates
)
2222 /* if the dock is full */
2224 (dock
->icon_count
>= dock
->max_icons
)) {
2228 /* exact position */
2230 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2232 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2235 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2237 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2239 /* check if the icon is outside the screen boundaries */
2240 if (dx
+ ex_x
*ICON_SIZE
< -ICON_SIZE
+2 ||
2241 dx
+ ex_x
*ICON_SIZE
> scr
->scr_width
-1 ||
2242 dy
+ ex_y
*ICON_SIZE
< -ICON_SIZE
+2 ||
2243 dy
+ ex_y
*ICON_SIZE
> scr
->scr_height
-1)
2246 if (dock
->type
== WM_DOCK
) {
2247 if (icon
->dock
!= dock
&& ex_x
!= 0)
2250 for (i
=0; i
<dock
->max_icons
; i
++) {
2251 nicon
= dock
->icon_array
[i
];
2252 if (nicon
&& nicon
->yindex
== ex_y
) {
2261 int sig
, done
, closest
;
2263 /* Possible cases when redocking:
2265 * icon dragged out of range of any slot -> false
2266 * icon dragged to range of free slot
2267 * icon dragged to range of same slot
2268 * icon dragged to range of different icon
2270 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2273 if (ex_y
>=0 && (aicon
== icon
|| !aicon
)) {
2280 /* start looking at the upper slot or lower? */
2281 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2288 /* look for closest free slot */
2289 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2293 closest
= sig
*(i
/2) + ex_y
;
2294 /* check if this slot is used */
2296 for (j
= 0; j
<dock
->max_icons
; j
++) {
2297 if (dock
->icon_array
[j
]
2298 && dock
->icon_array
[j
]->yindex
==closest
) {
2299 /* slot is used by someone else */
2300 if (dock
->icon_array
[j
]!=icon
)
2308 if (done
&& closest
>= 0 &&
2309 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2311 (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+1))) {
2317 } else { /* !redocking */
2319 /* if slot is free and the icon is close enough, return it */
2320 if (!aicon
&& ex_x
==0 && ex_y
>=0) {
2328 for (i
=0; i
<dock
->max_icons
; i
++) {
2329 nicon
= dock
->icon_array
[i
];
2330 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2336 for (i
=0; i
<dock
->max_icons
; i
++) {
2337 nicon
= dock
->icon_array
[i
];
2338 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2339 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2340 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2346 if (neighbours
&& (aicon
==NULL
|| (redocking
&& aicon
== icon
))) {
2355 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2356 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2358 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2359 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2360 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2364 * returns true if it can find a free slot in the dock,
2365 * in which case it changes x_pos and y_pos accordingly.
2366 * Else returns false.
2369 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2371 WScreen
*scr
= dock
->screen_ptr
;
2373 unsigned char *slot_map
;
2377 int i
, done
= False
;
2379 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2382 /* if the dock is full */
2383 if (dock
->icon_count
>= dock
->max_icons
) {
2387 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2388 if (scr
->dock
->on_right_side
)
2389 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2391 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2394 if (ex
< dock
->x_pos
)
2396 if (sx
> dock
->x_pos
+ICON_SIZE
)
2397 sx
= dock
->x_pos
+ICON_SIZE
;
2404 /* check if clip is in a corner */
2405 if (dock
->type
==WM_CLIP
) {
2406 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2408 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2410 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2412 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2419 /* If the clip is in the corner, use only slots that are in the border
2421 if (corner
!=C_NONE
) {
2425 hcount
= MIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2426 vcount
= MIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2427 hmap
= wmalloc(hcount
+1);
2428 memset(hmap
, 0, hcount
+1);
2429 vmap
= wmalloc(vcount
+1);
2430 memset(vmap
, 0, vcount
+1);
2432 /* mark used positions */
2435 for (i
=0; i
<dock
->max_icons
; i
++) {
2436 btn
= dock
->icon_array
[i
];
2440 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2441 vmap
[btn
->yindex
] = 1;
2442 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2443 hmap
[btn
->xindex
] = 1;
2446 for (i
=0; i
<dock
->max_icons
; i
++) {
2447 btn
= dock
->icon_array
[i
];
2451 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2452 vmap
[btn
->yindex
] = 1;
2453 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2454 hmap
[-btn
->xindex
] = 1;
2457 for (i
=0; i
<dock
->max_icons
; i
++) {
2458 btn
= dock
->icon_array
[i
];
2462 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2463 vmap
[-btn
->yindex
] = 1;
2464 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2465 hmap
[btn
->xindex
] = 1;
2469 for (i
=0; i
<dock
->max_icons
; i
++) {
2470 btn
= dock
->icon_array
[i
];
2474 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2475 vmap
[-btn
->yindex
] = 1;
2476 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2477 hmap
[-btn
->xindex
] = 1;
2482 /* search a vacant slot */
2483 for (i
=1; i
<MAX(vcount
, hcount
); i
++) {
2484 if (i
< vcount
&& vmap
[i
]==0) {
2490 } else if (i
< hcount
&& hmap
[i
]==0) {
2500 /* If found a slot, translate and return */
2502 if (corner
==C_NW
|| corner
==C_NE
) {
2507 if (corner
==C_NE
|| corner
==C_SE
) {
2514 /* else, try to find a slot somewhere else */
2517 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2518 * placed outside of screen */
2519 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2521 /* In the worst case (the clip is in the corner of the screen),
2522 * the amount of icons that fit in the clip is smaller.
2523 * Double the map to get a safe value.
2529 slot_map
= wmalloc(mwidth
*mwidth
);
2530 memset(slot_map
, 0, mwidth
*mwidth
);
2532 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2534 /* mark used slots in the map. If the slot falls outside the map
2535 * (for example, when all icons are placed in line), ignore them. */
2536 for (i
=0; i
<dock
->max_icons
; i
++) {
2537 btn
= dock
->icon_array
[i
];
2539 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2541 /* Find closest slot from the center that is free by scanning the
2542 * map from the center to outward in circular passes.
2543 * This will not result in a neat layout, but will be optimal
2544 * in the sense that there will not be holes left.
2547 for (i
= 1; i
<= r
&& !done
; i
++) {
2550 /* top and bottom parts of the ring */
2551 for (x
= -i
; x
<= i
&& !done
; x
++) {
2552 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2554 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2555 if (slot_map
[XY2OFS(x
,y
)]==0
2556 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2563 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2564 if (slot_map
[XY2OFS(x
,y
)]==0
2565 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2572 /* left and right parts of the ring */
2573 for (y
= -i
+1; y
<= i
-1; y
++) {
2574 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2576 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2577 if (slot_map
[XY2OFS(x
,y
)]==0
2578 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2585 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2586 if (slot_map
[XY2OFS(x
,y
)]==0
2587 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2602 moveDock(WDock
*dock
, int new_x
, int new_y
)
2607 dock
->x_pos
= new_x
;
2608 dock
->y_pos
= new_y
;
2609 for (i
=0; i
<dock
->max_icons
; i
++) {
2610 btn
= dock
->icon_array
[i
];
2612 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2613 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2614 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2621 swapDock(WDock
*dock
)
2623 WScreen
*scr
= dock
->screen_ptr
;
2628 if (dock
->on_right_side
) {
2629 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2631 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2634 for (i
=0; i
<dock
->max_icons
; i
++) {
2635 btn
= dock
->icon_array
[i
];
2638 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2645 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2647 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2653 cmdline
= ExpandOptions(scr
, command
);
2655 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2663 ParseCommand(cmdline
, &argv
, &argc
);
2673 if ((pid
=fork())==0) {
2677 SetupEnvironment(scr
);
2685 args
= malloc(sizeof(char*)*(argc
+1));
2688 for (i
=0; i
<argc
; i
++) {
2692 execvp(argv
[0], args
);
2701 state
= wmalloc(sizeof(WSavedState
));
2702 memset(state
, 0, sizeof(WSavedState
));
2704 state
->miniaturized
= -1;
2706 if (btn
->dock
== scr
->dock
)
2707 state
->workspace
= -1;
2709 state
->workspace
= scr
->current_workspace
;
2711 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
2713 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
2724 wDockHideIcons(WDock
*dock
)
2732 btn
= dock
->icon_array
[0];
2734 for (i
=1; i
<dock
->max_icons
; i
++) {
2735 if (dock
->icon_array
[i
])
2736 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2745 wDockShowIcons(WDock
*dock
)
2753 btn
= dock
->icon_array
[0];
2754 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2756 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2757 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2759 for (i
=1; i
<dock
->max_icons
; i
++) {
2760 if (dock
->icon_array
[i
]) {
2761 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
2767 if (!dock
->collapsed
) {
2768 for (i
=1; i
<dock
->max_icons
; i
++) {
2769 if (dock
->icon_array
[i
]) {
2770 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2781 wDockLower(WDock
*dock
)
2785 for (i
=0; i
<dock
->max_icons
; i
++) {
2786 if (dock
->icon_array
[i
])
2787 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2793 wDockRaise(WDock
*dock
)
2797 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
2798 if (dock
->icon_array
[i
])
2799 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2805 wDockRaiseLower(WDock
*dock
)
2807 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2808 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2809 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2817 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
2819 icon
->launching
= 0;
2820 icon
->relaunching
= 0;
2821 dockIconPaint(icon
);
2826 wDockFindIconFor(WDock
*dock
, Window window
)
2831 for (i
=0; i
<dock
->max_icons
; i
++) {
2832 icon
= dock
->icon_array
[i
];
2833 if (icon
&& icon
->main_window
== window
)
2841 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
2844 #ifdef REDUCE_APPICONS
2845 WAppIconAppList
*tapplist
;
2847 char *wm_class
, *wm_instance
;
2851 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
2852 (!wm_class
&& !wm_instance
))
2855 for (i
=0; i
<dock
->max_icons
; i
++) {
2856 icon
= dock
->icon_array
[i
];
2860 /* kluge. If this does not exist, some windows attach themselves
2861 * to more than one icon. Find out why */
2862 if (icon
->main_window
== window
) {
2865 if ((icon
->wm_instance
|| icon
->wm_class
)
2867 || (dock
->screen_ptr
->flags
.startup
&& !icon
->running
))) {
2869 if (icon
->wm_instance
&& wm_instance
&&
2870 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
2873 if (icon
->wm_class
&& wm_class
&&
2874 strcmp(icon
->wm_class
, wm_class
)!=0) {
2878 if (!icon
->relaunching
) {
2881 /* Possibly an application that was docked with dockit,
2882 * but the user did not update WMState to indicate that
2883 * it was docked by force */
2884 wapp
= wApplicationOf(window
);
2886 icon
->forced_dock
= 1;
2889 if (!icon
->forced_dock
)
2890 icon
->main_window
= window
;
2891 #ifdef REDUCE_APPICONS
2892 tapplist
= wmalloc(sizeof(WAppIconAppList
));
2893 memset(tapplist
, 0, sizeof(WAppIconAppList
));
2894 tapplist
->next
= icon
->applist
;
2896 icon
->applist
->prev
= tapplist
;
2897 icon
->applist
= tapplist
;
2898 tapplist
->wapp
= wApplicationOf(window
);
2902 wDockFinishLaunch(dock
, icon
);
2916 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
2918 if (!wPreferences
.flags
.noclip
) {
2919 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
2920 if (scr
->current_workspace
!= workspace
) {
2921 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
2923 wDockHideIcons(old_clip
);
2924 if (old_clip
->auto_collapse
&& !old_clip
->collapsed
)
2925 old_clip
->collapsed
= 1;
2926 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
2928 if (scr
->flags
.clip_balloon_mapped
)
2929 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
2936 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
2941 for (i
=0; i
<dock
->max_icons
; i
++) {
2942 icon
= dock
->icon_array
[i
];
2946 if (icon
->launching
&& icon
->pid
== pid
) {
2947 if (!icon
->relaunching
) {
2949 icon
->main_window
= None
;
2951 wDockFinishLaunch(dock
, icon
);
2956 sprintf(msg
, _("Could not execute command \"%s\""),
2957 icon
->drop_launch
&& icon
->dnd_command
2958 ? icon
->dnd_command
: icon
->command
);
2960 sprintf(msg
, _("Could not execute command \"%s\""),
2963 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
2964 _("OK"), NULL
, NULL
);
2973 toggleLowered(WDock
*dock
)
2978 /* lower/raise Dock */
2979 if (!dock
->lowered
) {
2980 newlevel
= WMNormalLevel
;
2983 newlevel
= WMDockLevel
;
2987 for (i
=0; i
<dock
->max_icons
; i
++) {
2988 tmp
= dock
->icon_array
[i
];
2992 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
2994 wLowerFrame(tmp
->icon
->core
);
3000 toggleCollapsed(WDock
*dock
)
3002 if (dock
->collapsed
) {
3003 dock
->collapsed
= 0;
3004 wDockShowIcons(dock
);
3007 dock
->collapsed
= 1;
3008 wDockHideIcons(dock
);
3014 toggleAutoCollapse(WDock
*dock
)
3016 dock
->auto_collapse
= !dock
->auto_collapse
;
3017 if (dock
->auto_collapse_magic
) {
3018 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3019 dock
->auto_collapse_magic
= NULL
;
3025 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3027 WScreen
*scr
= dock
->screen_ptr
;
3028 WObjDescriptor
*desc
;
3032 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3034 if (dock
->type
== WM_DOCK
) {
3036 entry
= dock
->menu
->entries
[index
];
3037 entry
->flags
.indicator_on
= !dock
->lowered
;
3038 entry
->clientdata
= dock
;
3041 if (scr
->clip_options
)
3042 updateClipOptionsMenu(scr
->clip_options
, dock
);
3044 /* Rename Workspace */
3045 entry
= dock
->menu
->entries
[++index
];
3046 entry
->clientdata
= dock
;
3049 entry
= dock
->menu
->entries
[++index
];
3050 entry
->clientdata
= aicon
;
3051 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3053 /* (un)select all icons */
3054 entry
= dock
->menu
->entries
[++index
];
3055 entry
->clientdata
= aicon
;
3056 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3059 entry
= dock
->menu
->entries
[++index
];
3060 entry
->clientdata
= aicon
;
3061 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3063 /* this is the workspace submenu part */
3064 if (scr
->clip_submenu
)
3065 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3068 /* remove icon(s) */
3069 entry
= dock
->menu
->entries
[++index
];
3070 entry
->clientdata
= aicon
;
3071 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3073 /* attract icon(s) */
3074 entry
= dock
->menu
->entries
[++index
];
3075 entry
->clientdata
= aicon
;
3079 entry
= dock
->menu
->entries
[++index
];
3080 entry
->clientdata
= aicon
;
3081 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3084 entry
= dock
->menu
->entries
[++index
];
3085 entry
->clientdata
= aicon
;
3086 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3089 entry
= dock
->menu
->entries
[++index
];
3090 entry
->clientdata
= aicon
;
3091 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3094 entry
= dock
->menu
->entries
[++index
];
3095 entry
->clientdata
= aicon
;
3096 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
3097 && !wPreferences
.flags
.noupdates
);
3100 entry
= dock
->menu
->entries
[++index
];
3101 entry
->clientdata
= aicon
;
3102 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3104 if (!dock
->menu
->flags
.realized
)
3105 wMenuRealize(dock
->menu
);
3107 if (dock
->type
== WM_CLIP
) {
3108 x_pos
= event
->xbutton
.x_root
+2;
3110 x_pos
= dock
->on_right_side
?
3111 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 2 : 0;
3114 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3116 /* allow drag select */
3117 event
->xany
.send_event
= True
;
3118 desc
= &dock
->menu
->menu
->descriptor
;
3119 (*desc
->handle_mousedown
)(desc
, event
);
3124 openClipWorkspaceMenu(WScreen
*scr
, int x
, int y
)
3126 if (!scr
->clip_ws_menu
) {
3127 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3129 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
3130 wMenuMapAt(scr
->clip_ws_menu
, x
, y
, False
);
3134 /******************************************************************/
3136 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3138 WAppIcon
*btn
= desc
->parent
;
3139 WDock
*dock
= btn
->dock
;
3140 WApplication
*wapp
= NULL
;
3143 #ifdef REDUCE_APPICONS
3144 if ((btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) ||
3145 ((btn
->icon
->owner
== NULL
) && (btn
->applist
!= NULL
))) {
3146 if (btn
->icon
->owner
== NULL
)
3147 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
3152 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3154 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3158 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3160 /* go to the last workspace that the user worked on the app */
3162 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3165 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3168 if (event
->xbutton
.state
& MOD_MASK
) {
3169 wHideOtherApplications(btn
->icon
->owner
);
3172 if (event
->xbutton
.button
==Button1
) {
3174 if (event
->xbutton
.state
& MOD_MASK
) {
3175 /* raise/lower dock */
3176 toggleLowered(dock
);
3177 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3178 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3179 toggleCollapsed(dock
);
3181 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3182 } else if (btn
->command
) {
3183 if (!btn
->launching
&&
3184 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3185 launchDockedApplication(btn
);
3194 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3196 WScreen
*scr
= dock
->screen_ptr
;
3197 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3200 int grabbed
= 0, swapped
= 0, done
;
3201 Pixmap ghost
= None
;
3202 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3205 puts("moving dock");
3207 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3208 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3209 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3210 wwarning("pointer grab failed for dock move");
3213 for (x
=0; x
<dock
->max_icons
; x
++) {
3214 if (dock
->icon_array
[x
]!=NULL
&&
3215 dock
->icon_array
[x
]->yindex
> y
)
3216 y
= dock
->icon_array
[x
]->yindex
;
3219 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3223 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3224 |ButtonMotionMask
|ExposureMask
, &ev
);
3232 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3233 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3234 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3235 |ButtonReleaseMask
|ButtonPressMask
,
3236 wCursor
[WCUR_MOVE
], CurrentTime
);
3241 if (dock
->type
== WM_CLIP
) {
3242 if (ev
.xmotion
.x_root
- ofs_x
< 0) {
3244 } else if (ev
.xmotion
.x_root
- ofs_x
+ ICON_SIZE
>
3246 x
= scr
->scr_width
- ICON_SIZE
;
3248 x
= ev
.xmotion
.x_root
- ofs_x
;
3250 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3252 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3254 y
= scr
->scr_height
- ICON_SIZE
;
3256 y
= ev
.xmotion
.y_root
- ofs_y
;
3258 moveDock(dock
, x
, y
);
3261 /* move vertically if pointer is inside the dock*/
3262 if ((dock
->on_right_side
&&
3263 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3264 || (!dock
->on_right_side
&&
3265 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3267 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3269 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3271 y
= scr
->scr_height
- ICON_SIZE
;
3273 y
= ev
.xmotion
.y_root
- ofs_y
;
3275 moveDock(dock
, dock
->x_pos
, y
);
3277 /* move horizontally to change sides */
3278 x
= ev
.xmotion
.x_root
- ofs_x
;
3279 if (!dock
->on_right_side
) {
3283 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3284 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3285 -DOCK_EXTRA_SPACE
, dock
->y_pos
);
3288 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3289 scr
->scr_width
-ICON_SIZE
3292 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3294 XClearWindow(dpy
, scr
->dock_shadow
);
3297 XMapRaised(dpy
, scr
->dock_shadow
);
3300 if (superfluous
&& ghost
!=None
) {
3301 XFreePixmap(dpy
, ghost
);
3304 XUnmapWindow(dpy
, scr
->dock_shadow
);
3309 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3310 XMoveWindow(dpy
, scr
->dock_shadow
,
3311 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3314 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3315 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3316 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3318 XClearWindow(dpy
, scr
->dock_shadow
);
3321 XMapRaised(dpy
, scr
->dock_shadow
);
3324 XUnmapWindow(dpy
, scr
->dock_shadow
);
3326 if (superfluous
&& ghost
!=None
) {
3327 XFreePixmap(dpy
, ghost
);
3339 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3341 XUngrabPointer(dpy
, CurrentTime
);
3342 XUnmapWindow(dpy
, scr
->dock_shadow
);
3343 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3344 if (dock
->type
== WM_DOCK
) {
3347 dock
->on_right_side
= 1;
3349 dock
->on_right_side
= 0;
3351 wArrangeIcons(scr
, False
);
3360 XFreePixmap(dpy
, ghost
);
3361 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3364 puts("End dock move");
3371 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3373 WScreen
*scr
= dock
->screen_ptr
;
3375 WIcon
*icon
= aicon
->icon
;
3376 WDock
*dock2
= NULL
, *last_dock
= dock
;
3377 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3379 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3380 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3381 int shad_x
= x
, shad_y
= y
;
3382 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3384 Pixmap ghost
= None
;
3386 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3388 if (wPreferences
.flags
.noupdates
)
3391 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3392 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3393 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3395 wwarning("pointer grab failed for icon move");
3399 wRaiseFrame(icon
->core
);
3401 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3402 dock2
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3403 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3406 wins
[0] = icon
->core
->window
;
3407 wins
[1] = scr
->dock_shadow
;
3408 XRestackWindows(dpy
, wins
, 2);
3409 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3410 ICON_SIZE
, ICON_SIZE
);
3412 if (icon
->pixmap
!=None
)
3413 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3415 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3417 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3418 XClearWindow(dpy
, scr
->dock_shadow
);
3420 XMapWindow(dpy
, scr
->dock_shadow
);
3426 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3427 |ButtonMotionMask
|ExposureMask
, &ev
);
3435 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3436 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3437 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3438 |ButtonReleaseMask
|ButtonPressMask
,
3439 wCursor
[WCUR_MOVE
], CurrentTime
);
3446 x
= ev
.xmotion
.x_root
- ofs_x
;
3447 y
= ev
.xmotion
.y_root
- ofs_y
;
3448 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3451 if (last_dock
!= dock
&& collapsed
) {
3452 last_dock
->collapsed
= 1;
3453 wDockHideIcons(last_dock
);
3456 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3457 dock
->collapsed
= 0;
3458 wDockShowIcons(dock
);
3463 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3466 if (last_dock
!= dock2
&& collapsed
) {
3467 last_dock
->collapsed
= 1;
3468 wDockHideIcons(last_dock
);
3471 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3472 dock2
->collapsed
= 0;
3473 wDockShowIcons(dock2
);
3478 if (aicon
->launching
3479 || (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3480 || (!aicon
->running
&& tmp
)) {
3481 shad_x
= last_dock
->x_pos
+ ix
*wPreferences
.icon_size
;
3482 shad_y
= last_dock
->y_pos
+ iy
*wPreferences
.icon_size
;
3484 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3487 XMapWindow(dpy
, scr
->dock_shadow
);
3489 if (!collapsed
&& (collapsed
= last_dock
->collapsed
)) {
3490 last_dock
->collapsed
= 0;
3491 wDockShowIcons(last_dock
);
3498 XUnmapWindow(dpy
, scr
->dock_shadow
);
3500 if (last_dock
&& collapsed
&&
3501 aicon
->running
&& (ev
.xmotion
.state
& MOD_MASK
)) {
3502 last_dock
->collapsed
= 1;
3503 wDockHideIcons(last_dock
);
3510 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3517 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3519 XUngrabPointer(dpy
, CurrentTime
);
3521 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3522 XUnmapWindow(dpy
, scr
->dock_shadow
);
3524 reattachIcon(dock
, aicon
, ix
, iy
);
3526 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3528 /* Slide it back if dock rejected it */
3529 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3531 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3533 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3541 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3542 /* We need to deselect it, even if is deselected in
3543 * wDockDetach(), because else DoKaboom() will fail.
3545 if (aicon
->icon
->selected
)
3546 wIconSelect(aicon
->icon
);
3547 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3550 wDockDetach(dock
, aicon
);
3553 last_dock
->collapsed
= 1;
3554 wDockHideIcons(last_dock
);
3559 XFreePixmap(dpy
, ghost
);
3560 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3563 puts("End icon move");
3572 getClipButton(int px
, int py
)
3574 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
3576 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3579 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
3580 return CLIP_FORWARD
;
3581 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
3589 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3592 int done
, direction
, new_ws
;
3594 WDock
*clip
= scr
->clip_icon
->dock
;
3596 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3598 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3599 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3601 wClipIconPaint(scr
->clip_icon
);
3604 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
3605 |ButtonPressMask
, &ev
);
3612 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3613 if (new_dir
!= direction
) {
3614 direction
= new_dir
;
3615 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3616 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3617 wClipIconPaint(scr
->clip_icon
);
3625 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3630 clip
->lclip_button_pushed
= 0;
3631 clip
->rclip_button_pushed
= 0;
3633 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3635 if (direction
== CLIP_FORWARD
) {
3636 if (scr
->current_workspace
< scr
->workspace_count
-1)
3637 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3638 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
3639 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3640 else if (wPreferences
.ws_cycle
)
3641 wWorkspaceChange(scr
, 0);
3643 else if (direction
== CLIP_REWIND
) {
3644 if (scr
->current_workspace
> 0)
3645 wWorkspaceChange(scr
, scr
->current_workspace
-1);
3646 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
3647 wWorkspaceChange(scr
, scr
->workspace_count
-1);
3650 wClipIconPaint(scr
->clip_icon
);
3655 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3657 WAppIcon
*aicon
= desc
->parent
;
3658 WDock
*dock
= aicon
->dock
;
3659 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3664 scr
->last_dock
= dock
;
3666 if (dock
->menu
->flags
.mapped
)
3667 wMenuUnmap(dock
->menu
);
3669 if (IsDoubleClick(scr
, event
)) {
3670 /* double-click was not in the main clip icon */
3671 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
3672 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
3673 iconDblClick(desc
, event
);
3678 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
3679 XUnmapWindow(dpy
, scr
->clip_balloon
);
3680 scr
->flags
.clip_balloon_mapped
= 0;
3684 puts("handling dock");
3686 if (event
->xbutton
.button
== Button1
) {
3687 if (event
->xbutton
.state
& MOD_MASK
)
3692 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
3693 dock
->type
!=WM_DOCK
) {
3694 wIconSelect(aicon
->icon
);
3698 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
3699 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
3700 && dock
->type
==WM_CLIP
)
3701 handleClipChangeWorkspace(scr
, event
);
3703 handleDockMove(dock
, aicon
, event
);
3705 handleIconMove(dock
, aicon
, event
);
3707 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
3708 aicon
->xindex
==0 && aicon
->yindex
==0) {
3709 openClipWorkspaceMenu(scr
, event
->xbutton
.x_root
+2,
3710 event
->xbutton
.y_root
+2);
3711 if (scr
->clip_ws_menu
) {
3713 menu
= scr
->clip_ws_menu
;
3714 desc
= &menu
->menu
->descriptor
;
3716 event
->xany
.send_event
= True
;
3717 (*desc
->handle_mousedown
)(desc
, event
);
3719 } else if (event
->xbutton
.button
== Button3
) {
3720 openDockMenu(dock
, aicon
, event
);
3726 showClipBalloon(WDock
*dock
, int workspace
)
3730 WScreen
*scr
= dock
->screen_ptr
;
3734 scr
->flags
.clip_balloon_mapped
= 1;
3735 XMapWindow(dpy
, scr
->clip_balloon
);
3737 text
= scr
->workspaces
[workspace
]->name
;
3739 w
= wTextWidth(scr
->clip_title_font
->font
, text
, strlen(text
));
3741 h
= scr
->clip_title_font
->height
;
3742 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
3744 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
3745 y
= dock
->y_pos
+ ICON_SIZE
-scr
->clip_title_font
->height
- 3;
3747 if (x
+w
> scr
->scr_width
) {
3748 x
= scr
->scr_width
- w
;
3749 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
3750 y
= dock
->y_pos
- h
- 1;
3752 y
= dock
->y_pos
+ ICON_SIZE
;
3753 XRaiseWindow(dpy
, scr
->clip_balloon
);
3755 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
3756 stack
[1] = scr
->clip_balloon
;
3757 XRestackWindows(dpy
, stack
, 2);
3759 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
3760 XSetForeground(dpy
, scr
->clip_title_gc
,
3761 scr
->clip_title_pixel
[CLIP_NORMAL
]);
3762 XClearWindow(dpy
, scr
->clip_balloon
);
3763 wDrawString(scr
->clip_balloon
, scr
->clip_title_font
, scr
->clip_title_gc
,
3764 0, scr
->clip_title_font
->y
, text
, strlen(text
));
3769 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3771 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
3774 assert(event
->type
==EnterNotify
);
3776 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
3780 if (!dock
|| dock
->type
!=WM_CLIP
)
3783 if (btn
->xindex
== 0 && btn
->yindex
== 0)
3784 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
3786 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
3787 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
3788 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
3791 if (!dock
->auto_collapse
)
3794 if (dock
->auto_collapse_magic
) {
3795 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3796 dock
->auto_collapse_magic
= NULL
;
3799 if (dock
->collapsed
)
3800 toggleCollapsed(dock
);
3805 clipLeave(WDock
*dock
)
3807 if (!dock
|| dock
->type
!=WM_CLIP
|| !dock
->auto_collapse
)
3810 if (dock
->auto_collapse_magic
) {
3811 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3812 dock
->auto_collapse_magic
= NULL
;
3814 if (!dock
->collapsed
) {
3815 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
3823 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
3825 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
3827 assert(event
->type
==LeaveNotify
);
3829 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
3832 clipLeave(btn
->dock
);
3837 clipAutoCollapse(void *cdata
)
3839 WDock
*dock
= (WDock
*)cdata
;
3841 if (dock
->type
!=WM_CLIP
|| !dock
->auto_collapse
)
3844 if (!dock
->collapsed
&& dock
->auto_collapse_magic
!=NULL
) {
3845 toggleCollapsed(dock
);
3847 dock
->auto_collapse_magic
= NULL
;