1 /* dock.c- built-in Dock module for WindowMaker
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 * Copyright (c) 1998, 1999 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
28 #include <X11/Xutil.h>
36 #define PATH_MAX DEFAULT_PATH_MAX
39 #include "WindowMaker.h"
49 #include "properties.h"
53 #include "workspace.h"
55 #include "superfluous.h"
64 /**** Local variables ****/
67 #define CLIP_FORWARD 2
70 /**** Global variables ****/
73 extern void DestroyDockAppSettingsPanel();
75 extern void ShowDockAppSettingsPanel(WAppIcon
*aicon
);
78 extern XContext wWinContext
;
80 extern Cursor wCursor
[WCUR_LAST
];
82 extern WPreferences wPreferences
;
84 extern XContext wWinContext
;
87 extern Atom _XA_DND_PROTOCOL
;
91 #define MOD_MASK wPreferences.modifier_mask
93 extern void appIconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
95 #define ICON_SIZE wPreferences.icon_size
98 /***** Local variables ****/
100 static proplist_t dCommand
=NULL
;
102 static proplist_t dDropCommand
=NULL
;
104 static proplist_t dAutoLaunch
, dName
, dForced
, dBuggyApplication
, dYes
, dNo
;
105 static proplist_t dHost
, dDock
, dClip
;
106 static proplist_t dAutoAttractIcons
, dKeepAttracted
;
108 static proplist_t dPosition
, dApplications
, dLowered
, dCollapsed
, dAutoCollapse
;
110 static proplist_t dAutoRaiseLower
;
112 static void dockIconPaint(WAppIcon
*btn
);
114 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
116 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
);
118 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
120 static int getClipButton(int px
, int py
);
122 static void toggleLowered(WDock
*dock
);
124 static void toggleCollapsed(WDock
*dock
);
126 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
128 static void clipLeave(WDock
*dock
);
130 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
132 Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
);
134 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
135 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
136 static void clipAutoCollapse(void *cdata
);
137 static void clipAutoExpand(void *cdata
);
138 static void launchDockedApplication(WAppIcon
*btn
);
140 static void clipAutoLower(void *cdata
);
141 static void clipAutoRaise(void *cdata
);
143 static void showClipBalloon(WDock
*dock
, int workspace
);
159 #endif /* OFFIX_DND */
169 dCommand
= PLRetain(PLMakeString("Command"));
171 dDropCommand
= PLRetain(PLMakeString("DropCommand"));
173 dAutoLaunch
= PLRetain(PLMakeString("AutoLaunch"));
174 dName
= PLRetain(PLMakeString("Name"));
175 dForced
= PLRetain(PLMakeString("Forced"));
176 dBuggyApplication
= PLRetain(PLMakeString("BuggyApplication"));
177 dYes
= PLRetain(PLMakeString("Yes"));
178 dNo
= PLRetain(PLMakeString("No"));
179 dHost
= PLRetain(PLMakeString("Host"));
181 dPosition
= PLMakeString("Position");
182 dApplications
= PLMakeString("Applications");
183 dLowered
= PLMakeString("Lowered");
184 dCollapsed
= PLMakeString("Collapsed");
185 dAutoCollapse
= PLMakeString("AutoCollapse");
186 dAutoRaiseLower
= PLMakeString("AutoRaiseLower");
187 dAutoAttractIcons
= PLMakeString("AutoAttractIcons");
188 dKeepAttracted
= PLMakeString("KeepAttracted");
190 dDock
= PLMakeString("Dock");
191 dClip
= PLMakeString("Clip");
197 renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
199 WDock
*dock
= entry
->clientdata
;
204 assert(entry
->clientdata
!=NULL
);
206 wspace
= dock
->screen_ptr
->current_workspace
;
208 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
210 sprintf(buffer
, _("Type the name for workspace %i:"), wspace
+1);
211 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
,
213 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
222 toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
224 assert(entry
->clientdata
!=NULL
);
226 toggleLowered(entry
->clientdata
);
228 entry
->flags
.indicator_on
= !((WDock
*)entry
->clientdata
)->lowered
;
236 killCallback(WMenu
*menu
, WMenuEntry
*entry
)
239 #ifdef REDUCE_APPICONS
240 WAppIconAppList
*tapplist
;
242 extern Atom _XA_WM_DELETE_WINDOW
;
247 if (!WCHECK_STATE(WSTATE_NORMAL
))
250 assert(entry
->clientdata
!=NULL
);
252 icon
= (WAppIcon
*)entry
->clientdata
;
256 WCHANGE_STATE(WSTATE_MODAL
);
258 #ifdef REDUCE_APPICONS
259 /* Send a delete message to the main window of each application
260 * bound to this docked appicon. - cls
262 tapplist
= icon
->applist
;
263 while (tapplist
!= NULL
) {
264 if (tapplist
->wapp
->main_window_desc
!= NULL
) {
265 if (tapplist
->wapp
->main_window_desc
->protocols
.DELETE_WINDOW
) {
266 wClientSendProtocol(tapplist
->wapp
->main_window_desc
,
267 _XA_WM_DELETE_WINDOW
, CurrentTime
);
269 wClientKill(tapplist
->wapp
->main_window_desc
);
272 tapplist
= tapplist
->next
;
275 buffer
= wstrappend(icon
->wm_class
,
276 _(" will be forcibly closed.\n"
277 "Any unsaved changes will be lost.\n"
280 if (wPreferences
.dont_confirm_kill
281 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
282 buffer
, _("Yes"), _("No"), NULL
)==WAPRDefault
) {
283 if (icon
->icon
&& icon
->icon
->owner
) {
284 wClientKill(icon
->icon
->owner
);
287 #endif /* !REDUCE_APPICONS */
291 WCHANGE_STATE(WSTATE_NORMAL
);}
295 getSelected(WDock
*dock
)
297 LinkedList
*ret
=NULL
;
301 for (i
=1; i
<dock
->max_icons
; i
++) {
302 btn
= dock
->icon_array
[i
];
303 if (btn
&& btn
->icon
->selected
) {
304 ret
= list_cons(btn
, ret
);
313 paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
315 Window win
= clipIcon
->icon
->core
->window
;
316 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
318 int pt
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
319 int tp
= ICON_SIZE
- pt
;
320 int as
= pt
- 15; /* 15 = 5+5+5 */
322 Bool collapsed
= clipIcon
->dock
->collapsed
;
327 p
[1].x
= ICON_SIZE
-2;
329 p
[2].x
= ICON_SIZE
-2;
331 } else if (lpushed
) {
335 p
[1].y
= ICON_SIZE
-2;
337 p
[2].y
= ICON_SIZE
-2;
339 if (lpushed
|| rpushed
) {
340 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
341 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
342 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
345 gc
= scr
->clip_title_gc
;
347 XSetFillStyle(dpy
, scr
->copy_gc
, FillTiled
);
348 XSetTile(dpy
, scr
->copy_gc
, scr
->clip_arrow_gradient
);
349 XSetClipMask(dpy
, scr
->copy_gc
, None
);
353 p
[0].x
= p
[3].x
= ICON_SIZE
-6-as
;
355 p
[1].x
= ICON_SIZE
-6;
357 p
[2].x
= ICON_SIZE
-6;
360 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
361 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
364 XSetTSOrigin(dpy
, gc
, ICON_SIZE
-6-as
, 5);
366 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
367 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
371 p
[0].y
= p
[3].y
= ICON_SIZE
-6-as
;
373 p
[1].y
= ICON_SIZE
-6;
375 p
[2].y
= ICON_SIZE
-6;
377 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
378 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
381 XSetTSOrigin(dpy
, gc
, 5, ICON_SIZE
-6-as
);
383 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
384 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
387 XSetFillStyle(dpy
, scr
->copy_gc
, FillSolid
);
392 wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
394 RImage
*tile
= RCloneImage(normalTile
);
400 pt
= CLIP_BUTTON_SIZE
*wPreferences
.icon_size
/64;
401 tp
= wPreferences
.icon_size
-1 - pt
;
404 black
.red
= black
.green
= black
.blue
= 0;
407 dark
.red
= dark
.green
= dark
.blue
= 80;
410 light
.red
= light
.green
= light
.blue
= 80;
414 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
-2,
416 RDrawLine(tile
, tp
-1, 0, wPreferences
.icon_size
-1, pt
+1, &black
);
417 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
-3,
422 ROperateLine(tile
, RAddOperation
, 2, tp
+2, pt
-2,
423 wPreferences
.icon_size
-3, &dark
);
424 RDrawLine(tile
, 0, tp
-1, pt
+1, wPreferences
.icon_size
-1, &black
);
425 ROperateLine(tile
, RSubtractOperation
, 0, tp
-2, pt
+1,
426 wPreferences
.icon_size
-2, &light
);
433 removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
435 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
438 LinkedList
*selectedIcons
;
441 assert(clickedIcon
!=NULL
);
443 dock
= clickedIcon
->dock
;
445 selectedIcons
= getSelected(dock
);
448 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
449 _("All selected icons will be removed!"),
450 _("OK"), _("Cancel"), NULL
)!=WAPRDefault
) {
454 if (clickedIcon
->xindex
==0 && clickedIcon
->yindex
==0)
456 selectedIcons
= list_cons(clickedIcon
, NULL
);
459 while (selectedIcons
) {
460 aicon
= selectedIcons
->head
;
461 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
462 wDockDetach(dock
, aicon
);
464 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
465 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
466 aicon
->x_pos
, aicon
->y_pos
);
467 if (!dock
->mapped
|| dock
->collapsed
)
468 XMapWindow(dpy
, aicon
->icon
->core
->window
);
470 list_remove_head(&selectedIcons
);
473 if (wPreferences
.auto_arrange_icons
)
474 wArrangeIcons(dock
->screen_ptr
, True
);
479 keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
481 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
484 LinkedList
*selectedIcons
;
486 assert(clickedIcon
!=NULL
);
487 dock
= clickedIcon
->dock
;
489 selectedIcons
= getSelected(dock
);
491 if (!selectedIcons
&& clickedIcon
!=dock
->screen_ptr
->clip_icon
) {
492 char *command
= NULL
;
494 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
495 clickedIcon
->editing
= 1;
496 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
497 _("Type the command used to launch the application"),
499 if (command
&& (command
[0]==0 ||
500 (command
[0]=='-' && command
[1]==0))) {
504 clickedIcon
->command
= command
;
505 clickedIcon
->editing
= 0;
507 clickedIcon
->editing
= 0;
514 selectedIcons
= list_cons(clickedIcon
, NULL
);
517 while (selectedIcons
) {
518 aicon
= selectedIcons
->head
;
519 if (aicon
->icon
->selected
)
520 wIconSelect(aicon
->icon
);
521 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
522 aicon
->attracted
= 0;
523 if (aicon
->icon
->shadowed
) {
524 aicon
->icon
->shadowed
= 0;
525 aicon
->icon
->force_paint
= 1;
526 wAppIconPaint(aicon
);
529 list_remove_head(&selectedIcons
);
537 toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
539 WDock
*dock
= (WDock
*)entry
->clientdata
;
541 assert(entry
->clientdata
!=NULL
);
543 dock
->attract_icons
= !dock
->attract_icons
;
544 /*if (!dock->attract_icons)
545 dock->keep_attracted = 0;*/
547 entry
->flags
.indicator_on
= dock
->attract_icons
;
554 toggleKeepCallback(WMenu
*menu
, WMenuEntry
*entry
)
556 WDock
*dock
= (WDock
*)entry
->clientdata
;
560 assert(entry
->clientdata
!=NULL
);
562 dock
->keep_attracted
= !dock
->keep_attracted
;
564 if (dock
->keep_attracted
) {
565 for (i
=0; i
< dock
->max_icons
; i
++) {
566 btn
= dock
->icon_array
[i
];
567 if (btn
&& btn
->attracted
&& btn
->command
) {
569 if (btn
->icon
->shadowed
) {
570 btn
->icon
->shadowed
= 0;
571 btn
->icon
->force_paint
= 1;
578 entry
->flags
.indicator_on
= dock
->keep_attracted
;
585 selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
587 WAppIcon
*icon
= (WAppIcon
*)entry
->clientdata
;
591 wIconSelect(icon
->icon
);
598 colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
600 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
603 int x
, y
, x_pos
, y_pos
;
605 assert(entry
->clientdata
!=NULL
);
606 clip
= clickedIcon
->dock
;
608 aicon
= clip
->screen_ptr
->app_icon_list
;
611 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
612 x_pos
= clip
->x_pos
+ x
*ICON_SIZE
;
613 y_pos
= clip
->y_pos
+ y
*ICON_SIZE
;
614 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
616 if (wPreferences
.no_animations
) {
617 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
619 SlideWindow(aicon
->icon
->core
->window
,
620 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
623 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
624 #endif /* ANIMATIONS */
626 aicon
->attracted
= 1;
627 if (!clip
->keep_attracted
&& !aicon
->icon
->shadowed
) {
628 aicon
->icon
->shadowed
= 1;
629 aicon
->icon
->force_paint
= 1;
630 /* We don't do an wAppIconPaint() here because it's in
631 * wDockAttachIcon(). -Dan
634 wDockAttachIcon(clip
, aicon
, x
, y
);
635 if (clip
->collapsed
|| !clip
->mapped
)
636 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
644 selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
646 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
648 LinkedList
*selectedIcons
;
652 assert(clickedIcon
!=NULL
);
653 dock
= clickedIcon
->dock
;
655 selectedIcons
= getSelected(dock
);
657 if (!selectedIcons
) {
658 for (i
=1; i
<dock
->max_icons
; i
++) {
659 btn
= dock
->icon_array
[i
];
660 if (btn
&& !btn
->icon
->selected
) {
661 wIconSelect(btn
->icon
);
665 while(selectedIcons
) {
666 btn
= selectedIcons
->head
;
667 wIconSelect(btn
->icon
);
668 list_remove_head(&selectedIcons
);
677 toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
679 assert(entry
->clientdata
!=NULL
);
681 toggleCollapsed(entry
->clientdata
);
683 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->collapsed
;
690 toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
693 assert(entry
->clientdata
!=NULL
);
695 dock
= (WDock
*) entry
->clientdata
;
697 dock
->auto_collapse
= !dock
->auto_collapse
;
699 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_collapse
;
706 toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
709 assert(entry
->clientdata
!=NULL
);
711 dock
= (WDock
*) entry
->clientdata
;
713 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
715 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_raise_lower
;
722 launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
724 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
726 launchDockedApplication(btn
);
731 settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
733 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
737 ShowDockAppSettingsPanel(btn
);
742 hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
745 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
747 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
749 if (wapp
->flags
.hidden
) {
750 wWorkspaceChange(btn
->icon
->core
->screen_ptr
,wapp
->last_workspace
);
751 wUnhideApplication(wapp
, False
, False
);
753 wHideApplication(wapp
);
759 unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
762 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
764 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
766 wUnhideApplication(wapp
, False
, True
);
771 mainIconCreate(WScreen
*scr
, int type
)
776 if (type
== WM_CLIP
) {
778 return scr
->clip_icon
;
779 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
780 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
781 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
782 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
783 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE;*/
786 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
787 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
793 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
794 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
795 btn
->icon
->core
->descriptor
.parent
= btn
;
796 /*ChangeStackingLevel(btn->icon->core, WMDockLevel);*/
797 XMapWindow(dpy
, btn
->icon
->core
->window
);
802 scr
->clip_icon
= btn
;
809 switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
811 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
812 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
814 LinkedList
*selectedIcons
;
817 if (entry
->order
== scr
->current_workspace
)
820 dest
= scr
->workspaces
[entry
->order
]->clip
;
822 selectedIcons
= getSelected(src
);
825 while(selectedIcons
) {
826 btn
= selectedIcons
->head
;
827 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
828 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
829 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
831 list_remove_head(&selectedIcons
);
833 } else if (icon
!= scr
->clip_icon
) {
834 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
835 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
836 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
844 launchDockedApplication(WAppIcon
*btn
)
846 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
848 if (!btn
->launching
&& btn
->command
!=NULL
) {
849 if (!btn
->forced_dock
) {
850 btn
->relaunching
= btn
->running
;
853 if (btn
->wm_instance
|| btn
->wm_class
) {
854 WWindowAttributes attr
;
855 memset(&attr
, 0, sizeof(WWindowAttributes
));
856 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
,
859 if (!attr
.no_appicon
&& !btn
->buggy_app
)
864 btn
->drop_launch
= 0;
865 scr
->last_dock
= btn
->dock
;
866 btn
->pid
= execCommand(btn
, btn
->command
, NULL
);
868 if (btn
->buggy_app
) {
869 /* give feedback that the app was launched */
873 WMAddTimerHandler(200, (WMCallback
*)dockIconPaint
, btn
);
878 wwarning(_("could not launch application %s\n"), btn
->command
);
880 if (!btn
->relaunching
)
889 updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
891 WScreen
*scr
= menu
->frame
->screen_ptr
;
892 char title
[MAX_WORKSPACENAME_WIDTH
+1];
898 for (i
=0; i
<scr
->workspace_count
; i
++) {
899 if (i
< menu
->entry_no
) {
900 if (strcmp(menu
->entries
[i
]->text
,scr
->workspaces
[i
]->name
)!=0) {
901 free(menu
->entries
[i
]->text
);
902 strcpy(title
, scr
->workspaces
[i
]->name
);
903 menu
->entries
[i
]->text
= wstrdup(title
);
904 menu
->flags
.realized
= 0;
906 menu
->entries
[i
]->clientdata
= (void*)icon
;
908 strcpy(title
, scr
->workspaces
[i
]->name
);
910 wMenuAddCallback(menu
, title
, switchWSCommand
, (void*)icon
);
912 menu
->flags
.realized
= 0;
914 if (i
== scr
->current_workspace
) {
915 wMenuSetEnabled(menu
, i
, False
);
917 wMenuSetEnabled(menu
, i
, True
);
921 if (!menu
->flags
.realized
)
927 makeWorkspaceMenu(WScreen
*scr
)
931 menu
= wMenuCreate(scr
, NULL
, False
);
933 wwarning(_("could not create workspace submenu for Clip menu"));
935 wMenuAddCallback(menu
, "", switchWSCommand
, (void*)scr
->clip_icon
);
937 menu
->flags
.realized
= 0;
945 updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
954 entry
= menu
->entries
[index
];
955 entry
->flags
.indicator_on
= !dock
->lowered
;
956 entry
->clientdata
= dock
;
959 entry
= menu
->entries
[++index
];
960 entry
->flags
.indicator_on
= dock
->collapsed
;
961 entry
->clientdata
= dock
;
964 entry
= menu
->entries
[++index
];
965 entry
->flags
.indicator_on
= dock
->auto_collapse
;
966 entry
->clientdata
= dock
;
968 /* auto-raise/lower */
969 entry
= menu
->entries
[++index
];
970 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
971 entry
->clientdata
= dock
;
974 entry
= menu
->entries
[++index
];
975 entry
->flags
.indicator_on
= dock
->attract_icons
;
976 entry
->clientdata
= dock
;
978 /* keep attracted icons */
979 entry
= menu
->entries
[++index
];
980 entry
->flags
.indicator_on
= dock
->keep_attracted
;
981 entry
->clientdata
= dock
;
983 menu
->flags
.realized
= 0;
989 makeClipOptionsMenu(WScreen
*scr
)
994 menu
= wMenuCreate(scr
, NULL
, False
);
996 wwarning(_("could not create options submenu for Clip menu"));
1000 entry
= wMenuAddCallback(menu
, _("Keep on top"),
1001 toggleLoweredCallback
, NULL
);
1002 entry
->flags
.indicator
= 1;
1003 entry
->flags
.indicator_on
= 1;
1004 entry
->flags
.indicator_type
= MI_CHECK
;
1006 entry
= wMenuAddCallback(menu
, _("Collapsed"),
1007 toggleCollapsedCallback
, NULL
);
1008 entry
->flags
.indicator
= 1;
1009 entry
->flags
.indicator_on
= 1;
1010 entry
->flags
.indicator_type
= MI_CHECK
;
1012 entry
= wMenuAddCallback(menu
, _("AutoCollapse"),
1013 toggleAutoCollapseCallback
, NULL
);
1014 entry
->flags
.indicator
= 1;
1015 entry
->flags
.indicator_on
= 1;
1016 entry
->flags
.indicator_type
= MI_CHECK
;
1018 entry
= wMenuAddCallback(menu
, _("AutoRaiseLower"),
1019 toggleAutoRaiseLowerCallback
, NULL
);
1020 entry
->flags
.indicator
= 1;
1021 entry
->flags
.indicator_on
= 1;
1022 entry
->flags
.indicator_type
= MI_CHECK
;
1024 entry
= wMenuAddCallback(menu
, _("AutoAttract Icons"),
1025 toggleAutoAttractCallback
, NULL
);
1026 entry
->flags
.indicator
= 1;
1027 entry
->flags
.indicator_on
= 1;
1028 entry
->flags
.indicator_type
= MI_CHECK
;
1030 entry
= wMenuAddCallback(menu
, _("Keep Attracted Icons"),
1031 toggleKeepCallback
, NULL
);
1032 entry
->flags
.indicator
= 1;
1033 entry
->flags
.indicator_on
= 1;
1034 entry
->flags
.indicator_type
= MI_CHECK
;
1036 menu
->flags
.realized
= 0;
1044 dockMenuCreate(WScreen
*scr
, int type
)
1049 if (type
== WM_CLIP
&& scr
->clip_menu
)
1050 return scr
->clip_menu
;
1052 menu
= wMenuCreate(scr
, NULL
, False
);
1053 if (type
!= WM_CLIP
) {
1054 entry
= wMenuAddCallback(menu
, _("Keep on top"),
1055 toggleLoweredCallback
, NULL
);
1056 entry
->flags
.indicator
= 1;
1057 entry
->flags
.indicator_on
= 1;
1058 entry
->flags
.indicator_type
= MI_CHECK
;
1060 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1061 scr
->clip_options
= makeClipOptionsMenu(scr
);
1062 if (scr
->clip_options
)
1063 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1065 wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1067 wMenuAddCallback(menu
, _("(Un)Select Icon"), selectCallback
, NULL
);
1069 wMenuAddCallback(menu
, _("(Un)Select All Icons"), selectIconsCallback
,
1072 wMenuAddCallback(menu
, _("Keep Icon(s)"), keepIconsCallback
, NULL
);
1074 entry
= wMenuAddCallback(menu
, _("Move Icon(s) To"), NULL
, NULL
);
1075 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1076 if (scr
->clip_submenu
)
1077 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1079 wMenuAddCallback(menu
, _("Remove Icon(s)"), removeIconsCallback
, NULL
);
1081 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1084 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1086 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1088 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1090 entry
->text
= _("Hide");
1092 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1094 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1096 if (type
== WM_CLIP
)
1097 scr
->clip_menu
= menu
;
1104 wDockCreate(WScreen
*scr
, int type
)
1112 dock
= wmalloc(sizeof(WDock
));
1113 memset(dock
, 0, sizeof(WDock
));
1115 if (type
== WM_CLIP
)
1116 icon_count
= CLIP_MAX_ICONS
;
1118 icon_count
= scr
->scr_height
/wPreferences
.icon_size
;
1120 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*)*icon_count
);
1121 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*)*icon_count
);
1123 dock
->max_icons
= icon_count
;
1125 btn
= mainIconCreate(scr
, type
);
1129 dock
->x_pos
= btn
->x_pos
;
1130 dock
->y_pos
= btn
->y_pos
;
1131 dock
->screen_ptr
= scr
;
1133 dock
->icon_count
= 1;
1134 dock
->on_right_side
= 1;
1135 dock
->collapsed
= 0;
1136 dock
->auto_collapse
= 0;
1137 dock
->auto_collapse_magic
= NULL
;
1138 dock
->auto_raise_lower
= 0;
1139 dock
->auto_lower_magic
= NULL
;
1140 dock
->auto_raise_magic
= NULL
;
1141 dock
->attract_icons
= 0;
1142 dock
->keep_attracted
= 0;
1144 dock
->icon_array
[0] = btn
;
1145 wRaiseFrame(btn
->icon
->core
);
1146 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1148 /* create dock menu */
1149 dock
->menu
= dockMenuCreate(scr
, type
);
1156 wDockDestroy(WDock
*dock
)
1161 for (i
=(dock
->type
== WM_CLIP
) ? 1 : 0; i
<dock
->max_icons
; i
++) {
1162 aicon
= dock
->icon_array
[i
];
1164 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1165 wDockDetach(dock
, aicon
);
1167 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
1168 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
1169 aicon
->x_pos
, aicon
->y_pos
);
1170 if (!dock
->mapped
|| dock
->collapsed
)
1171 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1175 if (wPreferences
.auto_arrange_icons
)
1176 wArrangeIcons(dock
->screen_ptr
, True
);
1177 free(dock
->icon_array
);
1178 if (dock
->menu
&& dock
->type
!=WM_CLIP
)
1179 wMenuDestroy(dock
->menu
, True
);
1185 wClipIconPaint(WAppIcon
*aicon
)
1187 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1188 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1190 Window win
= aicon
->icon
->core
->window
;
1191 int length
, nlength
;
1192 char *ws_name
, ws_number
[10];
1195 wIconPaint(aicon
->icon
);
1197 length
= strlen(workspace
->name
);
1198 ws_name
= malloc(length
+ 1);
1199 sprintf(ws_name
, "%s", workspace
->name
);
1200 sprintf(ws_number
, "%i", scr
->current_workspace
+ 1);
1201 nlength
= strlen(ws_number
);
1203 gc
= scr
->clip_title_gc
;
1205 if (!workspace
->clip
->collapsed
)
1206 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_NORMAL
]);
1208 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_COLLAPSED
]);
1210 ty
= ICON_SIZE
- scr
->clip_title_font
->height
- 3;
1212 tx
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
1214 wDrawString(win
, scr
->clip_title_font
, gc
, tx
,
1215 ty
+ scr
->clip_title_font
->y
, ws_name
, length
);
1217 tx
= (ICON_SIZE
/2 - wTextWidth(scr
->clip_title_font
->font
, ws_number
, nlength
))/2;
1219 wDrawString(win
, scr
->clip_title_font
, gc
, tx
,
1220 scr
->clip_title_font
->y
+ 2, ws_number
, nlength
);
1224 if (aicon
->launching
) {
1225 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1226 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1228 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
,
1229 aicon
->dock
->rclip_button_pushed
);
1234 clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1236 wClipIconPaint(desc
->parent
);
1241 dockIconPaint(WAppIcon
*btn
)
1243 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1244 wClipIconPaint(btn
);
1251 make_icon_state(WAppIcon
*btn
)
1253 proplist_t node
= NULL
;
1254 proplist_t command
, autolaunch
, name
, forced
, host
, position
, buggy
;
1260 command
= PLMakeString("-");
1262 command
= PLMakeString(btn
->command
);
1264 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1266 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1268 name
= PLMakeString(tmp
);
1272 forced
= btn
->forced_dock
? dYes
: dNo
;
1274 buggy
= btn
->buggy_app
? dYes
: dNo
;
1276 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1277 sprintf(buffer
, "%i,%i", btn
->x_pos
, btn
->y_pos
);
1279 sprintf(buffer
, "%hi,%hi", btn
->xindex
, btn
->yindex
);
1280 position
= PLMakeString(buffer
);
1282 node
= PLMakeDictionaryFromEntries(dCommand
, command
,
1284 dAutoLaunch
, autolaunch
,
1286 dBuggyApplication
, buggy
,
1287 dPosition
, position
,
1291 PLRelease(position
);
1293 if (btn
->dnd_command
) {
1294 command
= PLMakeString(btn
->dnd_command
);
1295 PLInsertDictionaryEntry(node
, dDropCommand
, command
);
1298 #endif /* OFFIX_DND */
1300 if (btn
->client_machine
&& btn
->remote_start
) {
1301 host
= PLMakeString(btn
->client_machine
);
1302 PLInsertDictionaryEntry(node
, dHost
, host
);
1312 dockSaveState(WDock
*dock
)
1315 proplist_t icon_info
;
1316 proplist_t list
=NULL
, dock_state
=NULL
;
1320 list
= PLMakeArrayFromElements(NULL
);
1322 for (i
=(dock
->type
==WM_DOCK
? 0 : 1); i
<dock
->max_icons
; i
++) {
1323 WAppIcon
*btn
= dock
->icon_array
[i
];
1325 if (!btn
|| (btn
->attracted
&& !dock
->keep_attracted
))
1328 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1329 list
= PLAppendArrayElement(list
, icon_info
);
1330 PLRelease(icon_info
);
1334 dock_state
= PLMakeDictionaryFromEntries(dApplications
, list
, NULL
);
1338 if (dock
->type
== WM_DOCK
) {
1339 sprintf(buffer
, "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0),
1341 value
= PLMakeString(buffer
);
1342 PLInsertDictionaryEntry(dock_state
, dPosition
, value
);
1346 value
= (dock
->lowered
? dYes
: dNo
);
1347 PLInsertDictionaryEntry(dock_state
, dLowered
, value
);
1349 if (dock
->type
== WM_CLIP
) {
1350 value
= (dock
->collapsed
? dYes
: dNo
);
1351 PLInsertDictionaryEntry(dock_state
, dCollapsed
, value
);
1353 value
= (dock
->auto_collapse
? dYes
: dNo
);
1354 PLInsertDictionaryEntry(dock_state
, dAutoCollapse
, value
);
1356 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1357 PLInsertDictionaryEntry(dock_state
, dAutoRaiseLower
, value
);
1359 value
= (dock
->attract_icons
? dYes
: dNo
);
1360 PLInsertDictionaryEntry(dock_state
, dAutoAttractIcons
, value
);
1362 value
= (dock
->keep_attracted
? dYes
: dNo
);
1363 PLInsertDictionaryEntry(dock_state
, dKeepAttracted
, value
);
1371 wDockSaveState(WScreen
*scr
)
1373 proplist_t dock_state
;
1375 dock_state
= dockSaveState(scr
->dock
);
1377 PLInsertDictionaryEntry(scr
->session_state
, dDock
, dock_state
);
1379 PLRelease(dock_state
);
1384 wClipSaveState(WScreen
*scr
)
1386 proplist_t clip_state
;
1388 clip_state
= make_icon_state(scr
->clip_icon
);
1390 PLInsertDictionaryEntry(scr
->session_state
, dClip
, clip_state
);
1392 PLRelease(clip_state
);
1397 wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1399 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1404 restore_icon_state(WScreen
*scr
, proplist_t info
, int type
, int index
)
1407 char *wclass
, *winstance
;
1408 proplist_t cmd
, value
;
1412 cmd
= PLGetDictionaryEntry(info
, dCommand
);
1413 if (!cmd
|| !PLIsString(cmd
)) {
1417 /* parse window name */
1418 value
= PLGetDictionaryEntry(info
, dName
);
1422 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1424 if (!winstance
&& !wclass
) {
1431 command
= wstrdup(PLGetString(cmd
));
1435 if (!command
|| strcmp(command
, "-")==0) {
1446 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
,
1453 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1454 if (type
== WM_CLIP
) {
1455 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1456 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1458 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1459 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1463 cmd
= PLGetDictionaryEntry(info
, dDropCommand
);
1465 aicon
->dnd_command
= wstrdup(PLGetString(cmd
));
1468 /* check auto launch */
1469 value
= PLGetDictionaryEntry(info
, dAutoLaunch
);
1471 aicon
->auto_launch
= 0;
1473 if (PLIsString(value
)) {
1474 if (strcasecmp(PLGetString(value
), "YES")==0)
1475 aicon
->auto_launch
= 1;
1477 wwarning(_("bad value in docked icon state info %s"),
1478 PLGetString(dAutoLaunch
));
1482 /* check if it wasn't normally docked */
1483 value
= PLGetDictionaryEntry(info
, dForced
);
1485 aicon
->forced_dock
= 0;
1487 if (PLIsString(value
)) {
1488 if (strcasecmp(PLGetString(value
), "YES")==0)
1489 aicon
->forced_dock
= 1;
1491 wwarning(_("bad value in docked icon state info %s"),
1492 PLGetString(dForced
));
1496 /* check if we can rely on the stuff in the app */
1497 value
= PLGetDictionaryEntry(info
, dBuggyApplication
);
1499 aicon
->buggy_app
= 0;
1501 if (PLIsString(value
)) {
1502 if (strcasecmp(PLGetString(value
), "YES")==0)
1503 aicon
->buggy_app
= 1;
1505 wwarning(_("bad value in docked icon state info %s"),
1506 PLGetString(dBuggyApplication
));
1510 /* get position in the dock */
1511 value
= PLGetDictionaryEntry(info
, dPosition
);
1512 if (value
&& PLIsString(value
)) {
1513 if (sscanf(PLGetString(value
), "%hi,%hi", &aicon
->xindex
,
1515 wwarning(_("bad value in docked icon state info %s"),
1516 PLGetString(dPosition
));
1518 /* check position sanity */
1519 /* incomplete section! */
1520 if (type
== WM_DOCK
) {
1522 if (aicon
->yindex
< 0)
1523 wwarning(_("bad value in docked icon position %i,%i"),
1524 aicon
->xindex
, aicon
->yindex
);
1527 aicon
->yindex
= index
;
1538 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1542 wClipRestoreState(WScreen
*scr
, proplist_t clip_state
)
1548 icon
= mainIconCreate(scr
, WM_CLIP
);
1553 PLRetain(clip_state
);
1555 /* restore position */
1557 value
= PLGetDictionaryEntry(clip_state
, dPosition
);
1560 if (!PLIsString(value
))
1561 COMPLAIN("Position");
1563 if (sscanf(PLGetString(value
), "%i,%i", &icon
->x_pos
,
1565 COMPLAIN("Position");
1567 /* check position sanity */
1568 if (icon
->y_pos
< 0)
1570 else if (icon
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1571 icon
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1573 if (icon
->x_pos
< 0)
1575 else if (icon
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1576 icon
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1581 value
= PLGetDictionaryEntry(clip_state
, dDropCommand
);
1582 if (value
&& PLIsString(value
))
1583 icon
->dnd_command
= wstrdup(PLGetString(value
));
1586 PLRelease(clip_state
);
1593 wDockRestoreState(WScreen
*scr
, proplist_t dock_state
, int type
)
1598 WAppIcon
*aicon
, *old_top
;
1602 dock
= wDockCreate(scr
, type
);
1608 PLRetain(dock_state
);
1611 /* restore position */
1613 value
= PLGetDictionaryEntry(dock_state
, dPosition
);
1616 if (!PLIsString(value
))
1617 COMPLAIN("Position");
1619 if (sscanf(PLGetString(value
), "%i,%i", &dock
->x_pos
,
1621 COMPLAIN("Position");
1623 /* check position sanity */
1624 if (dock
->y_pos
< 0)
1626 else if (dock
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1627 dock
->y_pos
= scr
->scr_height
- ICON_SIZE
;
1629 /* This is no more needed. ??? */
1630 if (type
== WM_CLIP
) {
1631 if (dock
->x_pos
< 0)
1633 else if (dock
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1634 dock
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1636 if (dock
->x_pos
>= 0) {
1637 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1638 dock
->on_right_side
= 0;
1640 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1641 dock
->on_right_side
= 1;
1647 /* restore lowered/raised state */
1651 value
= PLGetDictionaryEntry(dock_state
, dLowered
);
1654 if (!PLIsString(value
))
1655 COMPLAIN("Lowered");
1657 if (strcasecmp(PLGetString(value
), "YES")==0)
1663 /* restore collapsed state */
1665 dock
->collapsed
= 0;
1667 value
= PLGetDictionaryEntry(dock_state
, dCollapsed
);
1670 if (!PLIsString(value
))
1671 COMPLAIN("Collapsed");
1673 if (strcasecmp(PLGetString(value
), "YES")==0)
1674 dock
->collapsed
= 1;
1679 /* restore auto-collapsed state */
1681 value
= PLGetDictionaryEntry(dock_state
, dAutoCollapse
);
1684 if (!PLIsString(value
))
1685 COMPLAIN("AutoCollapse");
1687 if (strcasecmp(PLGetString(value
), "YES")==0) {
1688 dock
->auto_collapse
= 1;
1689 dock
->collapsed
= 1;
1695 /* restore auto-raise/lower state */
1697 value
= PLGetDictionaryEntry(dock_state
, dAutoRaiseLower
);
1700 if (!PLIsString(value
))
1701 COMPLAIN("AutoRaiseLower");
1703 if (strcasecmp(PLGetString(value
), "YES")==0) {
1704 dock
->auto_raise_lower
= 1;
1710 /* restore attract icons state */
1712 dock
->attract_icons
= 0;
1714 value
= PLGetDictionaryEntry(dock_state
, dAutoAttractIcons
);
1717 if (!PLIsString(value
))
1718 COMPLAIN("AutoAttractIcons");
1720 if (strcasecmp(PLGetString(value
), "YES")==0)
1721 dock
->attract_icons
= 1;
1726 /* restore keep attracted icons state */
1728 dock
->keep_attracted
= 0;
1730 value
= PLGetDictionaryEntry(dock_state
, dKeepAttracted
);
1733 if (!PLIsString(value
))
1734 COMPLAIN("KeepAttracted");
1736 if (strcasecmp(PLGetString(value
), "YES")==0)
1737 dock
->keep_attracted
= 1;
1742 /* application list */
1744 apps
= PLGetDictionaryEntry(dock_state
, dApplications
);
1750 count
= PLGetNumberOfElements(apps
);
1755 old_top
= dock
->icon_array
[0];
1757 /* dock->icon_count is set to 1 when dock is created.
1758 * Since Clip is already restored, we want to keep it so for clip,
1759 * but for dock we may change the default top tile, so we set it to 0.
1761 if (type
== WM_DOCK
)
1762 dock
->icon_count
= 0;
1764 for (i
=0; i
<count
; i
++) {
1765 if (dock
->icon_count
>= dock
->max_icons
) {
1766 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1770 value
= PLGetArrayElement(apps
, i
);
1771 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1773 dock
->icon_array
[dock
->icon_count
] = aicon
;
1777 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
*ICON_SIZE
);
1778 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
*ICON_SIZE
);
1781 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1783 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1785 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
,
1788 if (!dock
->collapsed
)
1789 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1790 wRaiseFrame(aicon
->icon
->core
);
1793 } else if (dock
->icon_count
==0 && type
==WM_DOCK
)
1797 /* if the first icon is not defined, use the default */
1798 if (dock
->icon_array
[0]==NULL
) {
1799 /* update default icon */
1800 old_top
->x_pos
= dock
->x_pos
;
1801 old_top
->y_pos
= dock
->y_pos
;
1803 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1805 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1806 dock
->icon_array
[0] = old_top
;
1807 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1808 /* we don't need to increment dock->icon_count here because it was
1809 * incremented in the loop above.
1811 } else if (old_top
!=dock
->icon_array
[0]) {
1812 if (old_top
== scr
->clip_icon
)
1813 scr
->clip_icon
= dock
->icon_array
[0];
1814 wAppIconDestroy(old_top
);
1819 PLRelease(dock_state
);
1827 wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1829 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1831 btn
->drop_launch
= 0;
1833 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1836 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1848 wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1854 for (i
= 0; i
< dock
->max_icons
; i
++) {
1855 btn
= dock
->icon_array
[i
];
1856 if (!btn
|| !btn
->auto_launch
)
1859 state
= wmalloc(sizeof(WSavedState
));
1860 memset(state
, 0, sizeof(WSavedState
));
1861 state
->workspace
= workspace
;
1862 /* TODO: this is klugy and is very difficult to understand
1863 * what's going on. Try to clean up */
1864 wDockLaunchWithState(dock
, btn
, state
);
1868 #ifdef REDUCE_APPICONS
1870 wDockSimulateLaunch(WDock
*dock
, WAppIcon
*btn
)
1872 if ((btn
== NULL
) || (dock
== NULL
))
1875 if (!btn
->running
) {
1876 if ((btn
->icon
->owner
== NULL
) && (btn
->applist
))
1877 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
1878 if (!btn
->forced_dock
)
1888 findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1894 if ((dock
= scr
->dock
)!=NULL
) {
1895 for (i
=0; i
<dock
->max_icons
; i
++) {
1896 if (dock
->icon_array
[i
]
1897 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1903 if (*icon_pos
<0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
)!=NULL
) {
1904 for (i
=0; i
<dock
->max_icons
; i
++) {
1905 if (dock
->icon_array
[i
]
1906 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1919 wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
1925 dock
= findDock(scr
, event
, &icon_pos
);
1930 * Return True if the drop was on an application icon window.
1931 * In this case, let the ClientMessage handler redirect the
1932 * message to the app.
1934 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!=None
)
1937 if (dock
->icon_array
[icon_pos
]->dnd_command
!=NULL
) {
1938 scr
->flags
.dnd_data_convertion_status
= 0;
1940 btn
= dock
->icon_array
[icon_pos
];
1942 if (!btn
->forced_dock
) {
1943 btn
->relaunching
= btn
->running
;
1946 if (btn
->wm_instance
|| btn
->wm_class
) {
1947 WWindowAttributes attr
;
1948 memset(&attr
, 0, sizeof(WWindowAttributes
));
1949 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
1951 btn
->wm_class
, &attr
, NULL
, True
);
1953 if (!attr
.no_appicon
)
1959 btn
->drop_launch
= 1;
1960 scr
->last_dock
= dock
;
1961 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1966 if (!btn
->relaunching
) {
1973 #endif /* OFFIX_DND */
1978 wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1985 wwin
= icon
->icon
->owner
;
1986 if (icon
->command
==NULL
) {
1988 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
1990 icon
->command
= FlattenStringList(argv
, argc
);
1991 XFreeStringList(argv
);
1995 /* icon->forced_dock = 1;*/
1996 if (!icon
->attracted
|| dock
->type
!=WM_CLIP
|| dock
->keep_attracted
) {
1998 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
1999 _("Type the command used to launch the application"),
2001 if (command
&& (command
[0]==0 ||
2002 (command
[0]=='-' && command
[1]==0))) {
2006 icon
->command
= command
;
2012 /* If the target is the dock, reject the icon. If
2013 * the target is the clip, make it an attracted icon
2015 if (dock
->type
==WM_CLIP
) {
2016 icon
->attracted
= 1;
2017 if (!icon
->icon
->shadowed
) {
2018 icon
->icon
->shadowed
= 1;
2019 icon
->icon
->force_paint
= 1;
2031 for (index
=1; index
<dock
->max_icons
; index
++)
2032 if (dock
->icon_array
[index
] == NULL
)
2034 /* if (index == dock->max_icons)
2037 assert(index
< dock
->max_icons
);
2039 dock
->icon_array
[index
] = icon
;
2043 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2044 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2049 icon
->launching
= 0;
2052 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2053 if (dock
->type
== WM_CLIP
) {
2054 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2055 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2057 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2058 icon
->icon
->core
->descriptor
.parent
= icon
;
2060 MoveInStackListUnder(dock
->icon_array
[index
-1]->icon
->core
,
2062 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2063 wAppIconPaint(icon
);
2065 if (wPreferences
.auto_arrange_icons
)
2066 wArrangeIcons(dock
->screen_ptr
, True
);
2069 if (icon
->command
&& !icon
->dnd_command
) {
2070 icon
->dnd_command
= wmalloc(strlen(icon
->command
)+8);
2071 sprintf(icon
->dnd_command
, "%s %%d", icon
->command
);
2080 reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2084 for(index
=1; index
<dock
->max_icons
; index
++) {
2085 if(dock
->icon_array
[index
] == icon
)
2088 assert(index
< dock
->max_icons
);
2093 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2094 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2099 moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2109 wwin
= icon
->icon
->owner
;
2112 * For the moment we can't do this if we move icons in Clip from one
2113 * workspace to other, because if we move two or more icons without
2114 * command, the dialog box will not be able to tell us to which of the
2115 * moved icons it applies. -Dan
2117 if ((dest
->type
==WM_DOCK
/*|| dest->keep_attracted*/) && icon
->command
==NULL
) {
2118 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2120 icon
->command
= FlattenStringList(argv
, argc
);
2121 XFreeStringList(argv
);
2126 /* icon->forced_dock = 1;*/
2127 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2128 _("Type the command used to launch the application"),
2130 if (command
&& (command
[0]==0 ||
2131 (command
[0]=='-' && command
[1]==0))) {
2135 icon
->command
= command
;
2146 for(index
=1; index
<src
->max_icons
; index
++) {
2147 if(src
->icon_array
[index
] == icon
)
2150 assert(index
< src
->max_icons
);
2152 src
->icon_array
[index
] = NULL
;
2155 for(index
=1; index
<dest
->max_icons
; index
++) {
2156 if(dest
->icon_array
[index
] == NULL
)
2159 /* if (index == dest->max_icons)
2162 assert(index
< dest
->max_icons
);
2164 dest
->icon_array
[index
] = icon
;
2167 /* deselect the icon */
2168 if (icon
->icon
->selected
)
2169 wIconSelect(icon
->icon
);
2171 if (dest
->type
== WM_DOCK
) {
2172 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2173 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2175 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2176 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2179 /* set it to be kept when moving to dock, or to a clip that keep the
2181 * Unless the icon does not have a command set
2183 if (icon
->command
&& (dest
->type
==WM_DOCK
|| dest
->keep_attracted
)) {
2184 icon
->attracted
= 0;
2185 if (icon
->icon
->shadowed
) {
2186 icon
->icon
->shadowed
= 0;
2187 icon
->icon
->force_paint
= 1;
2191 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2197 icon
->x_pos
= dest
->x_pos
+ x
*ICON_SIZE
;
2198 icon
->y_pos
= dest
->y_pos
+ y
*ICON_SIZE
;
2202 MoveInStackListUnder(dest
->icon_array
[index
-1]->icon
->core
,
2204 wAppIconPaint(icon
);
2211 wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2215 /* make the settings panel be closed */
2217 DestroyDockAppSettingsPanel(icon
->panel
);
2222 icon
->attracted
= 0;
2223 if (icon
->icon
->shadowed
) {
2224 icon
->icon
->shadowed
= 0;
2225 icon
->icon
->force_paint
= 1;
2228 /* deselect the icon */
2229 if (icon
->icon
->selected
)
2230 wIconSelect(icon
->icon
);
2232 if (icon
->command
) {
2233 free(icon
->command
);
2234 icon
->command
= NULL
;
2237 if (icon
->dnd_command
) {
2238 free(icon
->dnd_command
);
2239 icon
->dnd_command
= NULL
;
2243 for (index
=1; index
<dock
->max_icons
; index
++)
2244 if (dock
->icon_array
[index
] == icon
)
2246 assert(index
< dock
->max_icons
);
2247 dock
->icon_array
[index
] = NULL
;
2252 /* if the dock is not attached to an application or
2253 * the the application did not set the approriate hints yet,
2254 * destroy the icon */
2255 #ifdef REDUCE_APPICONS
2256 if ((icon
->num_apps
== 0) && (!icon
->running
|| !wApplicationOf(icon
->main_window
)) )
2258 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2260 wAppIconDestroy(icon
);
2262 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2263 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2264 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2265 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2266 icon
->icon
->core
->descriptor
.parent
= icon
;
2268 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2270 wAppIconPaint(icon
);
2271 if (wPreferences
.auto_arrange_icons
) {
2272 wArrangeIcons(dock
->screen_ptr
, True
);
2275 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2281 * returns the closest Dock slot index for the passed
2284 * Returns False if icon can't be docked.
2287 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2288 int *ret_x
, int *ret_y
, int redocking
)
2290 WScreen
*scr
= dock
->screen_ptr
;
2293 int i
, offset
= ICON_SIZE
/2;
2294 WAppIcon
*aicon
= NULL
;
2295 WAppIcon
*nicon
= NULL
;
2296 int max_y_icons
, max_x_icons
;
2298 max_x_icons
= scr
->scr_width
/ICON_SIZE
;
2299 max_y_icons
= scr
->scr_height
/ICON_SIZE
-1;
2301 if (wPreferences
.flags
.noupdates
)
2307 /* if the dock is full */
2309 (dock
->icon_count
>= dock
->max_icons
)) {
2313 /* exact position */
2315 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2317 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2320 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2322 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2324 /* check if the icon is outside the screen boundaries */
2325 if (dx
+ ex_x
*ICON_SIZE
< -ICON_SIZE
+2 ||
2326 dx
+ ex_x
*ICON_SIZE
>= scr
->scr_width
-1 ||
2327 dy
+ ex_y
*ICON_SIZE
< -ICON_SIZE
+2 ||
2328 dy
+ ex_y
*ICON_SIZE
>= scr
->scr_height
-1)
2331 if (dock
->type
== WM_DOCK
) {
2332 if (icon
->dock
!= dock
&& ex_x
!= 0)
2335 for (i
=0; i
<dock
->max_icons
; i
++) {
2336 nicon
= dock
->icon_array
[i
];
2337 if (nicon
&& nicon
->yindex
== ex_y
) {
2346 int sig
, done
, closest
;
2348 /* Possible cases when redocking:
2350 * icon dragged out of range of any slot -> false
2351 * icon dragged to range of free slot
2352 * icon dragged to range of same slot
2353 * icon dragged to range of different icon
2355 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2358 if (ex_y
>= 0 && ex_y
<= max_y_icons
&& (aicon
== icon
|| !aicon
)) {
2366 /* start looking at the upper slot or lower? */
2367 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2374 /* look for closest free slot */
2375 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2379 closest
= sig
*(i
/2) + ex_y
;
2380 /* check if this slot is used */
2382 for (j
= 0; j
<dock
->max_icons
; j
++) {
2383 if (dock
->icon_array
[j
]
2384 && dock
->icon_array
[j
]->yindex
==closest
) {
2385 /* slot is used by someone else */
2386 if (dock
->icon_array
[j
]!=icon
)
2394 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2395 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2397 (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+1))) {
2403 } else { /* !redocking */
2405 /* if slot is free and the icon is close enough, return it */
2406 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2414 for (i
=0; i
<dock
->max_icons
; i
++) {
2415 nicon
= dock
->icon_array
[i
];
2416 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2422 for (i
=0; i
<dock
->max_icons
; i
++) {
2423 nicon
= dock
->icon_array
[i
];
2424 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2425 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2426 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2432 if (neighbours
&& (aicon
==NULL
|| (redocking
&& aicon
== icon
))) {
2441 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2442 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2444 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2445 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2446 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2450 * returns true if it can find a free slot in the dock,
2451 * in which case it changes x_pos and y_pos accordingly.
2452 * Else returns false.
2455 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2457 WScreen
*scr
= dock
->screen_ptr
;
2459 unsigned char *slot_map
;
2463 int i
, done
= False
;
2465 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2468 /* if the dock is full */
2469 if (dock
->icon_count
>= dock
->max_icons
) {
2473 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2474 if (scr
->dock
->on_right_side
)
2475 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2477 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2480 if (ex
< dock
->x_pos
)
2482 if (sx
> dock
->x_pos
+ICON_SIZE
)
2483 sx
= dock
->x_pos
+ICON_SIZE
;
2490 /* check if clip is in a corner */
2491 if (dock
->type
==WM_CLIP
) {
2492 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2494 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2496 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2498 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2505 /* If the clip is in the corner, use only slots that are in the border
2507 if (corner
!=C_NONE
) {
2511 hcount
= MIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2512 vcount
= MIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2513 hmap
= wmalloc(hcount
+1);
2514 memset(hmap
, 0, hcount
+1);
2515 vmap
= wmalloc(vcount
+1);
2516 memset(vmap
, 0, vcount
+1);
2518 /* mark used positions */
2521 for (i
=0; i
<dock
->max_icons
; i
++) {
2522 btn
= dock
->icon_array
[i
];
2526 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2527 vmap
[btn
->yindex
] = 1;
2528 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2529 hmap
[btn
->xindex
] = 1;
2532 for (i
=0; i
<dock
->max_icons
; i
++) {
2533 btn
= dock
->icon_array
[i
];
2537 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2538 vmap
[btn
->yindex
] = 1;
2539 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2540 hmap
[-btn
->xindex
] = 1;
2543 for (i
=0; i
<dock
->max_icons
; i
++) {
2544 btn
= dock
->icon_array
[i
];
2548 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2549 vmap
[-btn
->yindex
] = 1;
2550 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2551 hmap
[btn
->xindex
] = 1;
2555 for (i
=0; i
<dock
->max_icons
; i
++) {
2556 btn
= dock
->icon_array
[i
];
2560 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2561 vmap
[-btn
->yindex
] = 1;
2562 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2563 hmap
[-btn
->xindex
] = 1;
2568 /* search a vacant slot */
2569 for (i
=1; i
<MAX(vcount
, hcount
); i
++) {
2570 if (i
< vcount
&& vmap
[i
]==0) {
2576 } else if (i
< hcount
&& hmap
[i
]==0) {
2586 /* If found a slot, translate and return */
2588 if (corner
==C_NW
|| corner
==C_NE
) {
2593 if (corner
==C_NE
|| corner
==C_SE
) {
2600 /* else, try to find a slot somewhere else */
2603 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2604 * placed outside of screen */
2605 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2607 /* In the worst case (the clip is in the corner of the screen),
2608 * the amount of icons that fit in the clip is smaller.
2609 * Double the map to get a safe value.
2615 slot_map
= wmalloc(mwidth
*mwidth
);
2616 memset(slot_map
, 0, mwidth
*mwidth
);
2618 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2620 /* mark used slots in the map. If the slot falls outside the map
2621 * (for example, when all icons are placed in line), ignore them. */
2622 for (i
=0; i
<dock
->max_icons
; i
++) {
2623 btn
= dock
->icon_array
[i
];
2625 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2627 /* Find closest slot from the center that is free by scanning the
2628 * map from the center to outward in circular passes.
2629 * This will not result in a neat layout, but will be optimal
2630 * in the sense that there will not be holes left.
2633 for (i
= 1; i
<= r
&& !done
; i
++) {
2636 /* top and bottom parts of the ring */
2637 for (x
= -i
; x
<= i
&& !done
; x
++) {
2638 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2640 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2641 if (slot_map
[XY2OFS(x
,y
)]==0
2642 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2649 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2650 if (slot_map
[XY2OFS(x
,y
)]==0
2651 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2658 /* left and right parts of the ring */
2659 for (y
= -i
+1; y
<= i
-1; y
++) {
2660 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2662 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2663 if (slot_map
[XY2OFS(x
,y
)]==0
2664 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2671 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2672 if (slot_map
[XY2OFS(x
,y
)]==0
2673 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2688 moveDock(WDock
*dock
, int new_x
, int new_y
)
2693 dock
->x_pos
= new_x
;
2694 dock
->y_pos
= new_y
;
2695 for (i
=0; i
<dock
->max_icons
; i
++) {
2696 btn
= dock
->icon_array
[i
];
2698 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2699 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2700 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2707 swapDock(WDock
*dock
)
2709 WScreen
*scr
= dock
->screen_ptr
;
2714 if (dock
->on_right_side
) {
2715 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2717 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2720 for (i
=0; i
<dock
->max_icons
; i
++) {
2721 btn
= dock
->icon_array
[i
];
2724 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2728 wScreenUpdateUsableArea(scr
);
2733 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2735 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2741 cmdline
= ExpandOptions(scr
, command
);
2743 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2751 ParseCommand(cmdline
, &argv
, &argc
);
2761 if ((pid
=fork())==0) {
2765 SetupEnvironment(scr
);
2771 args
= malloc(sizeof(char*)*(argc
+1));
2774 for (i
=0; i
<argc
; i
++) {
2778 execvp(argv
[0], args
);
2787 state
= wmalloc(sizeof(WSavedState
));
2788 memset(state
, 0, sizeof(WSavedState
));
2790 state
->miniaturized
= -1;
2792 if (btn
->dock
== scr
->dock
)
2793 state
->workspace
= -1;
2795 state
->workspace
= scr
->current_workspace
;
2797 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
2799 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
2810 wDockHideIcons(WDock
*dock
)
2818 btn
= dock
->icon_array
[0];
2820 for (i
=1; i
<dock
->max_icons
; i
++) {
2821 if (dock
->icon_array
[i
])
2822 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2831 wDockShowIcons(WDock
*dock
)
2839 btn
= dock
->icon_array
[0];
2840 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2842 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2843 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2845 for (i
=1; i
<dock
->max_icons
; i
++) {
2846 if (dock
->icon_array
[i
]) {
2847 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
2853 if (!dock
->collapsed
) {
2854 for (i
=1; i
<dock
->max_icons
; i
++) {
2855 if (dock
->icon_array
[i
]) {
2856 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2867 wDockLower(WDock
*dock
)
2871 for (i
=0; i
<dock
->max_icons
; i
++) {
2872 if (dock
->icon_array
[i
])
2873 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2879 wDockRaise(WDock
*dock
)
2883 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
2884 if (dock
->icon_array
[i
])
2885 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2891 wDockRaiseLower(WDock
*dock
)
2893 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2894 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2895 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2903 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
2905 icon
->launching
= 0;
2906 icon
->relaunching
= 0;
2907 dockIconPaint(icon
);
2912 wDockFindIconFor(WDock
*dock
, Window window
)
2917 for (i
=0; i
<dock
->max_icons
; i
++) {
2918 icon
= dock
->icon_array
[i
];
2919 if (icon
&& icon
->main_window
== window
)
2927 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
2930 #ifdef REDUCE_APPICONS
2931 WAppIconAppList
*tapplist
;
2933 char *wm_class
, *wm_instance
;
2935 Bool firstPass
= True
;
2937 char *command
= NULL
;
2943 if (XGetCommand(dpy
, window
, &argv
, &argc
)) {
2944 if (argc
> 0 && argv
!= NULL
)
2945 command
= FlattenStringList(argv
,argc
);
2947 XFreeStringList(argv
);
2952 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
2953 (!wm_class
&& !wm_instance
))
2957 for (i
=0; i
<dock
->max_icons
; i
++) {
2958 icon
= dock
->icon_array
[i
];
2962 /* app is already attached to icon */
2963 if (icon
->main_window
== window
) {
2968 if ((icon
->wm_instance
|| icon
->wm_class
)
2970 || (dock
->screen_ptr
->flags
.startup
&& !icon
->running
))) {
2972 if (icon
->wm_instance
&& wm_instance
&&
2973 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
2976 if (icon
->wm_class
&& wm_class
&&
2977 strcmp(icon
->wm_class
, wm_class
)!=0) {
2980 if (firstPass
&& command
&& strcmp(icon
->command
, command
)!=0) {
2984 if (!icon
->relaunching
) {
2987 /* Possibly an application that was docked with dockit,
2988 * but the user did not update WMState to indicate that
2989 * it was docked by force */
2990 wapp
= wApplicationOf(window
);
2992 icon
->forced_dock
= 1;
2995 if (!icon
->forced_dock
)
2996 icon
->main_window
= window
;
2998 #ifdef REDUCE_APPICONS
2999 tapplist
= wmalloc(sizeof(WAppIconAppList
));
3000 memset(tapplist
, 0, sizeof(WAppIconAppList
));
3001 tapplist
->next
= icon
->applist
;
3003 icon
->applist
->prev
= tapplist
;
3004 icon
->applist
= tapplist
;
3005 tapplist
->wapp
= wApplicationOf(window
);
3010 wDockFinishLaunch(dock
, icon
);
3015 if (firstPass
&& !found
) {
3032 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3034 if (!wPreferences
.flags
.noclip
) {
3035 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3036 if (scr
->current_workspace
!= workspace
) {
3037 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3039 wDockHideIcons(old_clip
);
3040 if (old_clip
->auto_raise_lower
) {
3041 if (old_clip
->auto_raise_magic
) {
3042 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3043 old_clip
->auto_raise_magic
= NULL
;
3045 wDockLower(old_clip
);
3047 if (old_clip
->auto_collapse
) {
3048 if (old_clip
->auto_expand_magic
) {
3049 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3050 old_clip
->auto_expand_magic
= NULL
;
3052 old_clip
->collapsed
= 1;
3054 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3056 if (scr
->flags
.clip_balloon_mapped
)
3057 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3064 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3069 for (i
=0; i
<dock
->max_icons
; i
++) {
3070 icon
= dock
->icon_array
[i
];
3074 if (icon
->launching
&& icon
->pid
== pid
) {
3075 if (!icon
->relaunching
) {
3077 icon
->main_window
= None
;
3079 wDockFinishLaunch(dock
, icon
);
3084 sprintf(msg
, _("Could not execute command \"%s\""),
3085 icon
->drop_launch
&& icon
->dnd_command
3086 ? icon
->dnd_command
: icon
->command
);
3088 sprintf(msg
, _("Could not execute command \"%s\""),
3091 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
3092 _("OK"), NULL
, NULL
);
3101 toggleLowered(WDock
*dock
)
3106 /* lower/raise Dock */
3107 if (!dock
->lowered
) {
3108 newlevel
= WMNormalLevel
;
3111 newlevel
= WMDockLevel
;
3115 for (i
=0; i
<dock
->max_icons
; i
++) {
3116 tmp
= dock
->icon_array
[i
];
3120 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3122 wLowerFrame(tmp
->icon
->core
);
3125 if (dock
->type
== WM_DOCK
)
3126 wScreenUpdateUsableArea(dock
->screen_ptr
);
3131 toggleCollapsed(WDock
*dock
)
3133 if (dock
->collapsed
) {
3134 dock
->collapsed
= 0;
3135 wDockShowIcons(dock
);
3138 dock
->collapsed
= 1;
3139 wDockHideIcons(dock
);
3145 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3147 WScreen
*scr
= dock
->screen_ptr
;
3148 WObjDescriptor
*desc
;
3150 WApplication
*wapp
= NULL
;
3153 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3155 if (dock
->type
== WM_DOCK
) {
3157 entry
= dock
->menu
->entries
[index
];
3158 entry
->flags
.indicator_on
= !dock
->lowered
;
3159 entry
->clientdata
= dock
;
3162 if (scr
->clip_options
)
3163 updateClipOptionsMenu(scr
->clip_options
, dock
);
3165 /* Rename Workspace */
3166 entry
= dock
->menu
->entries
[++index
];
3167 entry
->clientdata
= dock
;
3170 entry
= dock
->menu
->entries
[++index
];
3171 entry
->clientdata
= aicon
;
3172 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3174 /* (un)select all icons */
3175 entry
= dock
->menu
->entries
[++index
];
3176 entry
->clientdata
= aicon
;
3177 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3180 entry
= dock
->menu
->entries
[++index
];
3181 entry
->clientdata
= aicon
;
3182 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3184 /* this is the workspace submenu part */
3185 if (scr
->clip_submenu
)
3186 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3189 /* remove icon(s) */
3190 entry
= dock
->menu
->entries
[++index
];
3191 entry
->clientdata
= aicon
;
3192 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3194 /* attract icon(s) */
3195 entry
= dock
->menu
->entries
[++index
];
3196 entry
->clientdata
= aicon
;
3200 entry
= dock
->menu
->entries
[++index
];
3201 entry
->clientdata
= aicon
;
3202 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3205 entry
= dock
->menu
->entries
[++index
];
3206 entry
->clientdata
= aicon
;
3207 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3210 entry
= dock
->menu
->entries
[++index
];
3211 entry
->clientdata
= aicon
;
3212 if (aicon
->icon
->owner
) {
3213 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3214 if (wapp
&& wapp
->flags
.hidden
)
3215 entry
->text
= _("Unhide");
3217 entry
->text
= _("Hide");
3219 entry
->text
= _("Hide");
3221 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3224 entry
= dock
->menu
->entries
[++index
];
3225 entry
->clientdata
= aicon
;
3226 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
3227 && !wPreferences
.flags
.noupdates
);
3230 entry
= dock
->menu
->entries
[++index
];
3231 entry
->clientdata
= aicon
;
3232 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3234 if (!dock
->menu
->flags
.realized
)
3235 wMenuRealize(dock
->menu
);
3237 if (dock
->type
== WM_CLIP
) {
3238 x_pos
= event
->xbutton
.x_root
+2;
3240 x_pos
= dock
->on_right_side
?
3241 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 2 : 0;
3244 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3246 /* allow drag select */
3247 event
->xany
.send_event
= True
;
3248 desc
= &dock
->menu
->menu
->descriptor
;
3249 (*desc
->handle_mousedown
)(desc
, event
);
3254 openClipWorkspaceMenu(WScreen
*scr
, int x
, int y
)
3256 if (!scr
->clip_ws_menu
) {
3257 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3259 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
3260 wMenuMapAt(scr
->clip_ws_menu
, x
, y
, False
);
3264 /******************************************************************/
3266 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3268 WAppIcon
*btn
= desc
->parent
;
3269 WDock
*dock
= btn
->dock
;
3270 WApplication
*wapp
= NULL
;
3273 #ifdef REDUCE_APPICONS
3274 if ((btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) ||
3275 ((btn
->icon
->owner
== NULL
) && (btn
->applist
!= NULL
))) {
3276 if (btn
->icon
->owner
== NULL
)
3277 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
3282 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3284 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3288 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3290 /* go to the last workspace that the user worked on the app */
3292 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3295 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3298 if (event
->xbutton
.state
& MOD_MASK
) {
3299 wHideOtherApplications(btn
->icon
->owner
);
3302 if (event
->xbutton
.button
==Button1
) {
3304 if (event
->xbutton
.state
& MOD_MASK
) {
3305 /* raise/lower dock */
3306 toggleLowered(dock
);
3307 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3308 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3309 toggleCollapsed(dock
);
3311 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3312 } else if (btn
->command
) {
3313 if (!btn
->launching
&&
3314 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3315 launchDockedApplication(btn
);
3324 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3326 WScreen
*scr
= dock
->screen_ptr
;
3327 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3330 int grabbed
= 0, swapped
= 0, done
;
3331 Pixmap ghost
= None
;
3332 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3335 puts("moving dock");
3337 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3338 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3339 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3340 wwarning("pointer grab failed for dock move");
3343 for (x
=0; x
<dock
->max_icons
; x
++) {
3344 if (dock
->icon_array
[x
]!=NULL
&&
3345 dock
->icon_array
[x
]->yindex
> y
)
3346 y
= dock
->icon_array
[x
]->yindex
;
3349 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3353 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3354 |ButtonMotionMask
|ExposureMask
, &ev
);
3362 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3363 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3364 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3365 |ButtonReleaseMask
|ButtonPressMask
,
3366 wCursor
[WCUR_MOVE
], CurrentTime
);
3371 if (dock
->type
== WM_CLIP
) {
3372 if (ev
.xmotion
.x_root
- ofs_x
< 0) {
3374 } else if (ev
.xmotion
.x_root
- ofs_x
+ ICON_SIZE
>
3376 x
= scr
->scr_width
- ICON_SIZE
;
3378 x
= ev
.xmotion
.x_root
- ofs_x
;
3380 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3382 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3384 y
= scr
->scr_height
- ICON_SIZE
;
3386 y
= ev
.xmotion
.y_root
- ofs_y
;
3388 moveDock(dock
, x
, y
);
3390 /* move vertically if pointer is inside the dock*/
3391 if ((dock
->on_right_side
&&
3392 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3393 || (!dock
->on_right_side
&&
3394 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3396 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3398 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3400 y
= scr
->scr_height
- ICON_SIZE
;
3402 y
= ev
.xmotion
.y_root
- ofs_y
;
3404 moveDock(dock
, dock
->x_pos
, y
);
3406 /* move horizontally to change sides */
3407 x
= ev
.xmotion
.x_root
- ofs_x
;
3408 if (!dock
->on_right_side
) {
3412 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3413 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3414 -DOCK_EXTRA_SPACE
-1, dock
->y_pos
);
3417 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3418 scr
->scr_width
-ICON_SIZE
3419 -DOCK_EXTRA_SPACE
-1,
3421 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3423 XClearWindow(dpy
, scr
->dock_shadow
);
3426 XMapRaised(dpy
, scr
->dock_shadow
);
3429 if (superfluous
&& ghost
!=None
) {
3430 XFreePixmap(dpy
, ghost
);
3433 XUnmapWindow(dpy
, scr
->dock_shadow
);
3438 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3439 XMoveWindow(dpy
, scr
->dock_shadow
,
3440 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3443 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3444 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3445 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3447 XClearWindow(dpy
, scr
->dock_shadow
);
3450 XMapRaised(dpy
, scr
->dock_shadow
);
3453 XUnmapWindow(dpy
, scr
->dock_shadow
);
3455 if (superfluous
&& ghost
!=None
) {
3456 XFreePixmap(dpy
, ghost
);
3468 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3470 XUngrabPointer(dpy
, CurrentTime
);
3471 XUnmapWindow(dpy
, scr
->dock_shadow
);
3472 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3473 if (dock
->type
== WM_DOCK
) {
3476 dock
->on_right_side
= 1;
3478 dock
->on_right_side
= 0;
3480 wArrangeIcons(scr
, False
);
3489 XFreePixmap(dpy
, ghost
);
3490 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3493 puts("End dock move");
3500 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3502 WScreen
*scr
= dock
->screen_ptr
;
3504 WIcon
*icon
= aicon
->icon
;
3505 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3506 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3508 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3509 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3510 int shad_x
= x
, shad_y
= y
;
3511 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3513 Pixmap ghost
= None
;
3515 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3517 if (wPreferences
.flags
.noupdates
)
3520 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3521 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3522 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3524 wwarning("pointer grab failed for icon move");
3528 wRaiseFrame(icon
->core
);
3530 if (!wPreferences
.flags
.noclip
)
3531 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3533 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3535 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3538 wins
[0] = icon
->core
->window
;
3539 wins
[1] = scr
->dock_shadow
;
3540 XRestackWindows(dpy
, wins
, 2);
3541 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3542 ICON_SIZE
, ICON_SIZE
);
3544 if (icon
->pixmap
!=None
)
3545 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3547 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3549 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3550 XClearWindow(dpy
, scr
->dock_shadow
);
3552 XMapWindow(dpy
, scr
->dock_shadow
);
3558 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3559 |ButtonMotionMask
|ExposureMask
, &ev
);
3567 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3568 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3569 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3570 |ButtonReleaseMask
|ButtonPressMask
,
3571 wCursor
[WCUR_MOVE
], CurrentTime
);
3578 x
= ev
.xmotion
.x_root
- ofs_x
;
3579 y
= ev
.xmotion
.y_root
- ofs_y
;
3580 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3583 if (last_dock
!= dock
&& collapsed
) {
3584 last_dock
->collapsed
= 1;
3585 wDockHideIcons(last_dock
);
3588 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3589 dock
->collapsed
= 0;
3590 wDockShowIcons(dock
);
3592 if (dock
->auto_raise_lower
)
3597 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3600 if (last_dock
!= dock2
&& collapsed
) {
3601 last_dock
->collapsed
= 1;
3602 wDockHideIcons(last_dock
);
3605 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3606 dock2
->collapsed
= 0;
3607 wDockShowIcons(dock2
);
3609 if (dock2
->auto_raise_lower
)
3614 if (aicon
->launching
3615 || (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3616 || (!aicon
->running
&& tmp
)) {
3617 shad_x
= last_dock
->x_pos
+ ix
*wPreferences
.icon_size
;
3618 shad_y
= last_dock
->y_pos
+ iy
*wPreferences
.icon_size
;
3620 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3623 XMapWindow(dpy
, scr
->dock_shadow
);
3625 if (!collapsed
&& (collapsed
= last_dock
->collapsed
)) {
3626 last_dock
->collapsed
= 0;
3627 wDockShowIcons(last_dock
);
3634 XUnmapWindow(dpy
, scr
->dock_shadow
);
3636 if (last_dock
&& collapsed
&&
3637 aicon
->running
&& (ev
.xmotion
.state
& MOD_MASK
)) {
3638 last_dock
->collapsed
= 1;
3639 wDockHideIcons(last_dock
);
3646 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3653 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3655 XUngrabPointer(dpy
, CurrentTime
);
3657 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3658 XUnmapWindow(dpy
, scr
->dock_shadow
);
3660 reattachIcon(dock
, aicon
, ix
, iy
);
3661 if (clip
&& dock
!=clip
&& clip
->auto_raise_lower
)
3664 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3666 /* Slide it back if dock rejected it */
3667 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3669 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3671 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3679 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3680 /* We need to deselect it, even if is deselected in
3681 * wDockDetach(), because else DoKaboom() will fail.
3683 if (aicon
->icon
->selected
)
3684 wIconSelect(aicon
->icon
);
3685 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3688 if (clip
&& clip
->auto_raise_lower
)
3690 wDockDetach(dock
, aicon
);
3693 last_dock
->collapsed
= 1;
3694 wDockHideIcons(last_dock
);
3699 XFreePixmap(dpy
, ghost
);
3700 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3703 puts("End icon move");
3712 getClipButton(int px
, int py
)
3714 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
3716 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3719 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
3720 return CLIP_FORWARD
;
3721 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
3729 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3732 int done
, direction
, new_ws
;
3734 WDock
*clip
= scr
->clip_icon
->dock
;
3736 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3738 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3739 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3741 wClipIconPaint(scr
->clip_icon
);
3744 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
3745 |ButtonPressMask
, &ev
);
3752 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3753 if (new_dir
!= direction
) {
3754 direction
= new_dir
;
3755 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3756 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3757 wClipIconPaint(scr
->clip_icon
);
3765 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3770 clip
->lclip_button_pushed
= 0;
3771 clip
->rclip_button_pushed
= 0;
3773 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3775 if (direction
== CLIP_FORWARD
) {
3776 if (scr
->current_workspace
< scr
->workspace_count
-1)
3777 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3778 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
3779 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3780 else if (wPreferences
.ws_cycle
)
3781 wWorkspaceChange(scr
, 0);
3783 else if (direction
== CLIP_REWIND
) {
3784 if (scr
->current_workspace
> 0)
3785 wWorkspaceChange(scr
, scr
->current_workspace
-1);
3786 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
3787 wWorkspaceChange(scr
, scr
->workspace_count
-1);
3790 wClipIconPaint(scr
->clip_icon
);
3795 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3797 WAppIcon
*aicon
= desc
->parent
;
3798 WDock
*dock
= aicon
->dock
;
3799 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3801 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3804 scr
->last_dock
= dock
;
3806 if (dock
->menu
->flags
.mapped
)
3807 wMenuUnmap(dock
->menu
);
3809 if (IsDoubleClick(scr
, event
)) {
3810 /* double-click was not in the main clip icon */
3811 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
3812 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
3813 iconDblClick(desc
, event
);
3818 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
3819 XUnmapWindow(dpy
, scr
->clip_balloon
);
3820 scr
->flags
.clip_balloon_mapped
= 0;
3824 puts("handling dock");
3826 if (event
->xbutton
.button
== Button1
) {
3827 if (event
->xbutton
.state
& MOD_MASK
)
3832 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
3833 dock
->type
!=WM_DOCK
) {
3834 wIconSelect(aicon
->icon
);
3838 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
3839 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
3840 && dock
->type
==WM_CLIP
)
3841 handleClipChangeWorkspace(scr
, event
);
3843 handleDockMove(dock
, aicon
, event
);
3845 handleIconMove(dock
, aicon
, event
);
3847 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
3848 aicon
->xindex
==0 && aicon
->yindex
==0) {
3849 openClipWorkspaceMenu(scr
, event
->xbutton
.x_root
+2,
3850 event
->xbutton
.y_root
+2);
3851 if (scr
->clip_ws_menu
) {
3853 menu
= scr
->clip_ws_menu
;
3854 desc
= &menu
->menu
->descriptor
;
3856 event
->xany
.send_event
= True
;
3857 (*desc
->handle_mousedown
)(desc
, event
);
3859 } else if (event
->xbutton
.button
== Button3
) {
3860 openDockMenu(dock
, aicon
, event
);
3866 showClipBalloon(WDock
*dock
, int workspace
)
3870 WScreen
*scr
= dock
->screen_ptr
;
3874 scr
->flags
.clip_balloon_mapped
= 1;
3875 XMapWindow(dpy
, scr
->clip_balloon
);
3877 text
= scr
->workspaces
[workspace
]->name
;
3879 w
= wTextWidth(scr
->clip_title_font
->font
, text
, strlen(text
));
3881 h
= scr
->clip_title_font
->height
;
3882 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
3884 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
3885 y
= dock
->y_pos
+ ICON_SIZE
-scr
->clip_title_font
->height
- 3;
3887 if (x
+w
> scr
->scr_width
) {
3888 x
= scr
->scr_width
- w
;
3889 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
3890 y
= dock
->y_pos
- h
- 1;
3892 y
= dock
->y_pos
+ ICON_SIZE
;
3893 XRaiseWindow(dpy
, scr
->clip_balloon
);
3895 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
3896 stack
[1] = scr
->clip_balloon
;
3897 XRestackWindows(dpy
, stack
, 2);
3899 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
3900 XSetForeground(dpy
, scr
->clip_title_gc
,
3901 scr
->clip_title_pixel
[CLIP_NORMAL
]);
3902 XClearWindow(dpy
, scr
->clip_balloon
);
3903 wDrawString(scr
->clip_balloon
, scr
->clip_title_font
, scr
->clip_title_gc
,
3904 0, scr
->clip_title_font
->y
, text
, strlen(text
));
3909 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3911 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
3914 assert(event
->type
==EnterNotify
);
3916 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
3920 if (!dock
|| dock
->type
!=WM_CLIP
)
3923 /* The auto raise/lower code */
3924 if (dock
->auto_lower_magic
) {
3925 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3926 dock
->auto_lower_magic
= NULL
;
3928 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
3929 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
,
3934 /* The auto expand/collapse code */
3935 if (dock
->auto_collapse_magic
) {
3936 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3937 dock
->auto_collapse_magic
= NULL
;
3939 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
3940 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
,
3945 if (btn
->xindex
== 0 && btn
->yindex
== 0)
3946 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
3948 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
3949 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
3950 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
3957 clipLeave(WDock
*dock
)
3960 WObjDescriptor
*desc
= NULL
;
3962 if (!dock
|| dock
->type
!=WM_CLIP
)
3965 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
)!=False
) {
3966 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3967 (XPointer
*)&desc
)!=XCNOENT
3968 && desc
&& desc
->parent_type
==WCLASS_DOCK_ICON
3969 && ((WAppIcon
*)desc
->parent
)->dock
3970 && ((WAppIcon
*)desc
->parent
)->dock
->type
==WM_CLIP
) {
3971 /* We didn't left the Clip yet */
3972 XPutBackEvent(dpy
, &event
);
3976 XPutBackEvent(dpy
, &event
);
3978 /* We entered a withdrawn window, so we're still in Clip */
3982 if (dock
->auto_raise_magic
) {
3983 WMDeleteTimerHandler(dock
->auto_raise_magic
);
3984 dock
->auto_raise_magic
= NULL
;
3986 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
3987 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
,
3992 if (dock
->auto_expand_magic
) {
3993 WMDeleteTimerHandler(dock
->auto_expand_magic
);
3994 dock
->auto_expand_magic
= NULL
;
3996 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
3997 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
4005 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4007 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4009 assert(event
->type
==LeaveNotify
);
4011 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4014 clipLeave(btn
->dock
);
4019 clipAutoCollapse(void *cdata
)
4021 WDock
*dock
= (WDock
*)cdata
;
4023 if (dock
->type
!=WM_CLIP
)
4026 if (dock
->auto_collapse
) {
4027 dock
->collapsed
= 1;
4028 wDockHideIcons(dock
);
4030 dock
->auto_collapse_magic
= NULL
;
4035 clipAutoExpand(void *cdata
)
4037 WDock
*dock
= (WDock
*)cdata
;
4039 if (dock
->type
!=WM_CLIP
)
4042 if (dock
->auto_collapse
) {
4043 dock
->collapsed
= 0;
4044 wDockShowIcons(dock
);
4046 dock
->auto_expand_magic
= NULL
;
4051 clipAutoLower(void *cdata
)
4053 WDock
*dock
= (WDock
*)cdata
;
4055 if (dock
->type
!=WM_CLIP
)
4058 if (dock
->auto_raise_lower
)
4061 dock
->auto_lower_magic
= NULL
;
4066 clipAutoRaise(void *cdata
)
4068 WDock
*dock
= (WDock
*)cdata
;
4070 if (dock
->type
!=WM_CLIP
)
4073 if (dock
->auto_raise_lower
)
4076 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4077 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4080 dock
->auto_raise_magic
= NULL
;