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 */
321 GC gc
= scr
->clip_title_gc
;
322 #ifdef GRADIENT_CLIP_ARROW
323 Bool collapsed
= clipIcon
->dock
->collapsed
;
329 p
[1].x
= ICON_SIZE
-2;
331 p
[2].x
= ICON_SIZE
-2;
333 } else if (lpushed
) {
337 p
[1].y
= ICON_SIZE
-2;
339 p
[2].y
= ICON_SIZE
-2;
341 if (lpushed
|| rpushed
) {
342 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
343 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
344 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
346 #ifdef GRADIENT_CLIP_ARROW
348 XSetFillStyle(dpy
, scr
->copy_gc
, FillTiled
);
349 XSetTile(dpy
, scr
->copy_gc
, scr
->clip_arrow_gradient
);
350 XSetClipMask(dpy
, scr
->copy_gc
, None
);
353 #endif /* GRADIENT_CLIP_ARROW */
355 p
[0].x
= p
[3].x
= ICON_SIZE
-4-as
;
357 p
[1].x
= ICON_SIZE
-7;
359 p
[2].x
= ICON_SIZE
-7;
362 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
363 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
365 #ifdef GRADIENT_CLIP_ARROW
367 XSetTSOrigin(dpy
, gc
, ICON_SIZE
-6-as
, 5);
369 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
370 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
374 p
[0].y
= p
[3].y
= ICON_SIZE
-4-as
;
376 p
[1].y
= ICON_SIZE
-7;
378 p
[2].y
= ICON_SIZE
-7;
380 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
381 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
383 #ifdef GRADIENT_CLIP_ARROW
385 XSetTSOrigin(dpy
, gc
, 5, ICON_SIZE
-6-as
);
387 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
388 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
390 #ifdef GRADIENT_CLIP_ARROW
392 XSetFillStyle(dpy
, scr
->copy_gc
, FillSolid
);
398 wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
400 RImage
*tile
= RCloneImage(normalTile
);
407 pt
= CLIP_BUTTON_SIZE
*wPreferences
.icon_size
/64;
408 tp
= wPreferences
.icon_size
-1 - pt
;
412 black
.red
= black
.green
= black
.blue
= 0;
415 dark
.red
= dark
.green
= dark
.blue
= 60;
418 light
.red
= light
.green
= light
.blue
= 80;
422 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
-2,
424 RDrawLine(tile
, tp
-1, 0, wPreferences
.icon_size
-1, pt
+1, &black
);
425 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
-3,
428 RDrawLine(tile
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 6, 5, &black
);
429 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5,
430 ICON_SIZE
- 7, 4 + as
, &dark
);
431 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 6, 6, ICON_SIZE
- 6, 5 + as
,
436 ROperateLine(tile
, RAddOperation
, 2, tp
+2, pt
-2,
437 wPreferences
.icon_size
-3, &dark
);
438 RDrawLine(tile
, 0, tp
-1, pt
+1, wPreferences
.icon_size
-1, &black
);
439 ROperateLine(tile
, RSubtractOperation
, 0, tp
-2, pt
+1,
440 wPreferences
.icon_size
-2, &light
);
442 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
,
443 4 + as
, ICON_SIZE
- 7, &dark
);
444 RDrawLine(tile
, 5, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 6, &black
);
446 ROperateLine(tile
, RAddOperation
, 6, ICON_SIZE
- 6, 5 + as
, ICON_SIZE
- 6,
455 removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
457 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
460 LinkedList
*selectedIcons
;
463 assert(clickedIcon
!=NULL
);
465 dock
= clickedIcon
->dock
;
467 selectedIcons
= getSelected(dock
);
470 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
471 _("All selected icons will be removed!"),
472 _("OK"), _("Cancel"), NULL
)!=WAPRDefault
) {
476 if (clickedIcon
->xindex
==0 && clickedIcon
->yindex
==0)
478 selectedIcons
= list_cons(clickedIcon
, NULL
);
481 while (selectedIcons
) {
482 aicon
= selectedIcons
->head
;
483 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
484 wDockDetach(dock
, aicon
);
486 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
487 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
488 aicon
->x_pos
, aicon
->y_pos
);
489 if (!dock
->mapped
|| dock
->collapsed
)
490 XMapWindow(dpy
, aicon
->icon
->core
->window
);
492 list_remove_head(&selectedIcons
);
495 if (wPreferences
.auto_arrange_icons
)
496 wArrangeIcons(dock
->screen_ptr
, True
);
501 keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
503 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
506 LinkedList
*selectedIcons
;
508 assert(clickedIcon
!=NULL
);
509 dock
= clickedIcon
->dock
;
511 selectedIcons
= getSelected(dock
);
513 if (!selectedIcons
&& clickedIcon
!=dock
->screen_ptr
->clip_icon
) {
514 char *command
= NULL
;
516 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
517 clickedIcon
->editing
= 1;
518 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
519 _("Type the command used to launch the application"),
521 if (command
&& (command
[0]==0 ||
522 (command
[0]=='-' && command
[1]==0))) {
526 clickedIcon
->command
= command
;
527 clickedIcon
->editing
= 0;
529 clickedIcon
->editing
= 0;
536 selectedIcons
= list_cons(clickedIcon
, NULL
);
539 while (selectedIcons
) {
540 aicon
= selectedIcons
->head
;
541 if (aicon
->icon
->selected
)
542 wIconSelect(aicon
->icon
);
543 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
544 aicon
->attracted
= 0;
545 if (aicon
->icon
->shadowed
) {
546 aicon
->icon
->shadowed
= 0;
547 aicon
->icon
->force_paint
= 1;
548 wAppIconPaint(aicon
);
551 list_remove_head(&selectedIcons
);
559 toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
561 WDock
*dock
= (WDock
*)entry
->clientdata
;
563 assert(entry
->clientdata
!=NULL
);
565 dock
->attract_icons
= !dock
->attract_icons
;
566 /*if (!dock->attract_icons)
567 dock->keep_attracted = 0;*/
569 entry
->flags
.indicator_on
= dock
->attract_icons
;
576 toggleKeepCallback(WMenu
*menu
, WMenuEntry
*entry
)
578 WDock
*dock
= (WDock
*)entry
->clientdata
;
582 assert(entry
->clientdata
!=NULL
);
584 dock
->keep_attracted
= !dock
->keep_attracted
;
586 if (dock
->keep_attracted
) {
587 for (i
=0; i
< dock
->max_icons
; i
++) {
588 btn
= dock
->icon_array
[i
];
589 if (btn
&& btn
->attracted
&& btn
->command
) {
591 if (btn
->icon
->shadowed
) {
592 btn
->icon
->shadowed
= 0;
593 btn
->icon
->force_paint
= 1;
600 entry
->flags
.indicator_on
= dock
->keep_attracted
;
607 selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
609 WAppIcon
*icon
= (WAppIcon
*)entry
->clientdata
;
613 wIconSelect(icon
->icon
);
620 colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
622 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
625 int x
, y
, x_pos
, y_pos
;
627 assert(entry
->clientdata
!=NULL
);
628 clip
= clickedIcon
->dock
;
630 aicon
= clip
->screen_ptr
->app_icon_list
;
633 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
634 x_pos
= clip
->x_pos
+ x
*ICON_SIZE
;
635 y_pos
= clip
->y_pos
+ y
*ICON_SIZE
;
636 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
638 if (wPreferences
.no_animations
) {
639 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
641 SlideWindow(aicon
->icon
->core
->window
,
642 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
645 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
646 #endif /* ANIMATIONS */
648 aicon
->attracted
= 1;
649 if (!clip
->keep_attracted
&& !aicon
->icon
->shadowed
) {
650 aicon
->icon
->shadowed
= 1;
651 aicon
->icon
->force_paint
= 1;
652 /* We don't do an wAppIconPaint() here because it's in
653 * wDockAttachIcon(). -Dan
656 wDockAttachIcon(clip
, aicon
, x
, y
);
657 if (clip
->collapsed
|| !clip
->mapped
)
658 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
666 selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
668 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
670 LinkedList
*selectedIcons
;
674 assert(clickedIcon
!=NULL
);
675 dock
= clickedIcon
->dock
;
677 selectedIcons
= getSelected(dock
);
679 if (!selectedIcons
) {
680 for (i
=1; i
<dock
->max_icons
; i
++) {
681 btn
= dock
->icon_array
[i
];
682 if (btn
&& !btn
->icon
->selected
) {
683 wIconSelect(btn
->icon
);
687 while(selectedIcons
) {
688 btn
= selectedIcons
->head
;
689 wIconSelect(btn
->icon
);
690 list_remove_head(&selectedIcons
);
699 toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
701 assert(entry
->clientdata
!=NULL
);
703 toggleCollapsed(entry
->clientdata
);
705 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->collapsed
;
712 toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
715 assert(entry
->clientdata
!=NULL
);
717 dock
= (WDock
*) entry
->clientdata
;
719 dock
->auto_collapse
= !dock
->auto_collapse
;
721 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_collapse
;
728 toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
731 assert(entry
->clientdata
!=NULL
);
733 dock
= (WDock
*) entry
->clientdata
;
735 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
737 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_raise_lower
;
744 launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
746 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
748 launchDockedApplication(btn
);
753 settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
755 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
759 ShowDockAppSettingsPanel(btn
);
764 hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
767 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
769 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
771 if (wapp
->flags
.hidden
) {
772 wWorkspaceChange(btn
->icon
->core
->screen_ptr
,wapp
->last_workspace
);
773 wUnhideApplication(wapp
, False
, False
);
775 wHideApplication(wapp
);
781 unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
784 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
786 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
788 wUnhideApplication(wapp
, False
, True
);
793 mainIconCreate(WScreen
*scr
, int type
)
798 if (type
== WM_CLIP
) {
800 return scr
->clip_icon
;
801 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
802 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
803 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
804 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
805 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE;*/
808 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
809 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
815 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
816 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
817 btn
->icon
->core
->descriptor
.parent
= btn
;
818 /*ChangeStackingLevel(btn->icon->core, WMDockLevel);*/
819 XMapWindow(dpy
, btn
->icon
->core
->window
);
824 scr
->clip_icon
= btn
;
831 switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
833 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
834 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
836 LinkedList
*selectedIcons
;
839 if (entry
->order
== scr
->current_workspace
)
842 dest
= scr
->workspaces
[entry
->order
]->clip
;
844 selectedIcons
= getSelected(src
);
847 while(selectedIcons
) {
848 btn
= selectedIcons
->head
;
849 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
850 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
851 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
853 list_remove_head(&selectedIcons
);
855 } else if (icon
!= scr
->clip_icon
) {
856 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
857 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
858 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
866 launchDockedApplication(WAppIcon
*btn
)
868 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
870 if (!btn
->launching
&& btn
->command
!=NULL
) {
871 if (!btn
->forced_dock
) {
872 btn
->relaunching
= btn
->running
;
875 if (btn
->wm_instance
|| btn
->wm_class
) {
876 WWindowAttributes attr
;
877 memset(&attr
, 0, sizeof(WWindowAttributes
));
878 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
,
881 if (!attr
.no_appicon
&& !btn
->buggy_app
)
886 btn
->drop_launch
= 0;
887 scr
->last_dock
= btn
->dock
;
888 btn
->pid
= execCommand(btn
, btn
->command
, NULL
);
890 if (btn
->buggy_app
) {
891 /* give feedback that the app was launched */
895 WMAddTimerHandler(200, (WMCallback
*)dockIconPaint
, btn
);
900 wwarning(_("could not launch application %s\n"), btn
->command
);
902 if (!btn
->relaunching
)
911 updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
913 WScreen
*scr
= menu
->frame
->screen_ptr
;
914 char title
[MAX_WORKSPACENAME_WIDTH
+1];
920 for (i
=0; i
<scr
->workspace_count
; i
++) {
921 if (i
< menu
->entry_no
) {
922 if (strcmp(menu
->entries
[i
]->text
,scr
->workspaces
[i
]->name
)!=0) {
923 free(menu
->entries
[i
]->text
);
924 strcpy(title
, scr
->workspaces
[i
]->name
);
925 menu
->entries
[i
]->text
= wstrdup(title
);
926 menu
->flags
.realized
= 0;
928 menu
->entries
[i
]->clientdata
= (void*)icon
;
930 strcpy(title
, scr
->workspaces
[i
]->name
);
932 wMenuAddCallback(menu
, title
, switchWSCommand
, (void*)icon
);
934 menu
->flags
.realized
= 0;
936 if (i
== scr
->current_workspace
) {
937 wMenuSetEnabled(menu
, i
, False
);
939 wMenuSetEnabled(menu
, i
, True
);
943 if (!menu
->flags
.realized
)
949 makeWorkspaceMenu(WScreen
*scr
)
953 menu
= wMenuCreate(scr
, NULL
, False
);
955 wwarning(_("could not create workspace submenu for Clip menu"));
957 wMenuAddCallback(menu
, "", switchWSCommand
, (void*)scr
->clip_icon
);
959 menu
->flags
.realized
= 0;
967 updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
976 entry
= menu
->entries
[index
];
977 entry
->flags
.indicator_on
= !dock
->lowered
;
978 entry
->clientdata
= dock
;
981 entry
= menu
->entries
[++index
];
982 entry
->flags
.indicator_on
= dock
->collapsed
;
983 entry
->clientdata
= dock
;
986 entry
= menu
->entries
[++index
];
987 entry
->flags
.indicator_on
= dock
->auto_collapse
;
988 entry
->clientdata
= dock
;
990 /* auto-raise/lower */
991 entry
= menu
->entries
[++index
];
992 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
993 entry
->clientdata
= dock
;
996 entry
= menu
->entries
[++index
];
997 entry
->flags
.indicator_on
= dock
->attract_icons
;
998 entry
->clientdata
= dock
;
1000 /* keep attracted icons */
1001 entry
= menu
->entries
[++index
];
1002 entry
->flags
.indicator_on
= dock
->keep_attracted
;
1003 entry
->clientdata
= dock
;
1005 menu
->flags
.realized
= 0;
1011 makeClipOptionsMenu(WScreen
*scr
)
1016 menu
= wMenuCreate(scr
, NULL
, False
);
1018 wwarning(_("could not create options submenu for Clip menu"));
1022 entry
= wMenuAddCallback(menu
, _("Keep on top"),
1023 toggleLoweredCallback
, NULL
);
1024 entry
->flags
.indicator
= 1;
1025 entry
->flags
.indicator_on
= 1;
1026 entry
->flags
.indicator_type
= MI_CHECK
;
1028 entry
= wMenuAddCallback(menu
, _("Collapsed"),
1029 toggleCollapsedCallback
, NULL
);
1030 entry
->flags
.indicator
= 1;
1031 entry
->flags
.indicator_on
= 1;
1032 entry
->flags
.indicator_type
= MI_CHECK
;
1034 entry
= wMenuAddCallback(menu
, _("AutoCollapse"),
1035 toggleAutoCollapseCallback
, NULL
);
1036 entry
->flags
.indicator
= 1;
1037 entry
->flags
.indicator_on
= 1;
1038 entry
->flags
.indicator_type
= MI_CHECK
;
1040 entry
= wMenuAddCallback(menu
, _("AutoRaiseLower"),
1041 toggleAutoRaiseLowerCallback
, NULL
);
1042 entry
->flags
.indicator
= 1;
1043 entry
->flags
.indicator_on
= 1;
1044 entry
->flags
.indicator_type
= MI_CHECK
;
1046 entry
= wMenuAddCallback(menu
, _("AutoAttract Icons"),
1047 toggleAutoAttractCallback
, NULL
);
1048 entry
->flags
.indicator
= 1;
1049 entry
->flags
.indicator_on
= 1;
1050 entry
->flags
.indicator_type
= MI_CHECK
;
1052 entry
= wMenuAddCallback(menu
, _("Keep Attracted Icons"),
1053 toggleKeepCallback
, NULL
);
1054 entry
->flags
.indicator
= 1;
1055 entry
->flags
.indicator_on
= 1;
1056 entry
->flags
.indicator_type
= MI_CHECK
;
1058 menu
->flags
.realized
= 0;
1066 dockMenuCreate(WScreen
*scr
, int type
)
1071 if (type
== WM_CLIP
&& scr
->clip_menu
)
1072 return scr
->clip_menu
;
1074 menu
= wMenuCreate(scr
, NULL
, False
);
1075 if (type
!= WM_CLIP
) {
1076 entry
= wMenuAddCallback(menu
, _("Keep on top"),
1077 toggleLoweredCallback
, NULL
);
1078 entry
->flags
.indicator
= 1;
1079 entry
->flags
.indicator_on
= 1;
1080 entry
->flags
.indicator_type
= MI_CHECK
;
1082 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1083 scr
->clip_options
= makeClipOptionsMenu(scr
);
1084 if (scr
->clip_options
)
1085 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1087 wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1089 wMenuAddCallback(menu
, _("(Un)Select Icon"), selectCallback
, NULL
);
1091 wMenuAddCallback(menu
, _("(Un)Select All Icons"), selectIconsCallback
,
1094 wMenuAddCallback(menu
, _("Keep Icon(s)"), keepIconsCallback
, NULL
);
1096 entry
= wMenuAddCallback(menu
, _("Move Icon(s) To"), NULL
, NULL
);
1097 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1098 if (scr
->clip_submenu
)
1099 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1101 wMenuAddCallback(menu
, _("Remove Icon(s)"), removeIconsCallback
, NULL
);
1103 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1106 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1108 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1110 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1112 entry
->text
= _("Hide");
1114 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1116 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1118 if (type
== WM_CLIP
)
1119 scr
->clip_menu
= menu
;
1126 wDockCreate(WScreen
*scr
, int type
)
1134 dock
= wmalloc(sizeof(WDock
));
1135 memset(dock
, 0, sizeof(WDock
));
1137 if (type
== WM_CLIP
)
1138 icon_count
= CLIP_MAX_ICONS
;
1140 icon_count
= scr
->scr_height
/wPreferences
.icon_size
;
1142 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*)*icon_count
);
1143 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*)*icon_count
);
1145 dock
->max_icons
= icon_count
;
1147 btn
= mainIconCreate(scr
, type
);
1151 dock
->x_pos
= btn
->x_pos
;
1152 dock
->y_pos
= btn
->y_pos
;
1153 dock
->screen_ptr
= scr
;
1155 dock
->icon_count
= 1;
1156 dock
->on_right_side
= 1;
1157 dock
->collapsed
= 0;
1158 dock
->auto_collapse
= 0;
1159 dock
->auto_collapse_magic
= NULL
;
1160 dock
->auto_raise_lower
= 0;
1161 dock
->auto_lower_magic
= NULL
;
1162 dock
->auto_raise_magic
= NULL
;
1163 dock
->attract_icons
= 0;
1164 dock
->keep_attracted
= 0;
1166 dock
->icon_array
[0] = btn
;
1167 wRaiseFrame(btn
->icon
->core
);
1168 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1170 /* create dock menu */
1171 dock
->menu
= dockMenuCreate(scr
, type
);
1178 wDockDestroy(WDock
*dock
)
1183 for (i
=(dock
->type
== WM_CLIP
) ? 1 : 0; i
<dock
->max_icons
; i
++) {
1184 aicon
= dock
->icon_array
[i
];
1186 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1187 wDockDetach(dock
, aicon
);
1189 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
1190 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
1191 aicon
->x_pos
, aicon
->y_pos
);
1192 if (!dock
->mapped
|| dock
->collapsed
)
1193 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1197 if (wPreferences
.auto_arrange_icons
)
1198 wArrangeIcons(dock
->screen_ptr
, True
);
1199 free(dock
->icon_array
);
1200 if (dock
->menu
&& dock
->type
!=WM_CLIP
)
1201 wMenuDestroy(dock
->menu
, True
);
1207 wClipIconPaint(WAppIcon
*aicon
)
1209 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1210 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1212 Window win
= aicon
->icon
->core
->window
;
1213 int length
, nlength
;
1214 char *ws_name
, ws_number
[10];
1217 wIconPaint(aicon
->icon
);
1219 length
= strlen(workspace
->name
);
1220 ws_name
= malloc(length
+ 1);
1221 sprintf(ws_name
, "%s", workspace
->name
);
1222 sprintf(ws_number
, "%i", scr
->current_workspace
+ 1);
1223 nlength
= strlen(ws_number
);
1225 gc
= scr
->clip_title_gc
;
1227 if (!workspace
->clip
->collapsed
)
1228 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_NORMAL
]);
1230 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_COLLAPSED
]);
1232 ty
= ICON_SIZE
- scr
->clip_title_font
->height
- 3;
1234 tx
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
1236 wDrawString(win
, scr
->clip_title_font
, gc
, tx
,
1237 ty
+ scr
->clip_title_font
->y
, ws_name
, length
);
1239 tx
= (ICON_SIZE
/2 - wTextWidth(scr
->clip_title_font
->font
, ws_number
, nlength
))/2;
1241 wDrawString(win
, scr
->clip_title_font
, gc
, tx
,
1242 scr
->clip_title_font
->y
+ 2, ws_number
, nlength
);
1246 if (aicon
->launching
) {
1247 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1248 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1250 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
,
1251 aicon
->dock
->rclip_button_pushed
);
1256 clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1258 wClipIconPaint(desc
->parent
);
1263 dockIconPaint(WAppIcon
*btn
)
1265 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1266 wClipIconPaint(btn
);
1273 make_icon_state(WAppIcon
*btn
)
1275 proplist_t node
= NULL
;
1276 proplist_t command
, autolaunch
, name
, forced
, host
, position
, buggy
;
1282 command
= PLMakeString("-");
1284 command
= PLMakeString(btn
->command
);
1286 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1288 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1290 name
= PLMakeString(tmp
);
1294 forced
= btn
->forced_dock
? dYes
: dNo
;
1296 buggy
= btn
->buggy_app
? dYes
: dNo
;
1298 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1299 sprintf(buffer
, "%i,%i", btn
->x_pos
, btn
->y_pos
);
1301 sprintf(buffer
, "%hi,%hi", btn
->xindex
, btn
->yindex
);
1302 position
= PLMakeString(buffer
);
1304 node
= PLMakeDictionaryFromEntries(dCommand
, command
,
1306 dAutoLaunch
, autolaunch
,
1308 dBuggyApplication
, buggy
,
1309 dPosition
, position
,
1313 PLRelease(position
);
1315 if (btn
->dnd_command
) {
1316 command
= PLMakeString(btn
->dnd_command
);
1317 PLInsertDictionaryEntry(node
, dDropCommand
, command
);
1320 #endif /* OFFIX_DND */
1322 if (btn
->client_machine
&& btn
->remote_start
) {
1323 host
= PLMakeString(btn
->client_machine
);
1324 PLInsertDictionaryEntry(node
, dHost
, host
);
1334 dockSaveState(WDock
*dock
)
1337 proplist_t icon_info
;
1338 proplist_t list
=NULL
, dock_state
=NULL
;
1342 list
= PLMakeArrayFromElements(NULL
);
1344 for (i
=(dock
->type
==WM_DOCK
? 0 : 1); i
<dock
->max_icons
; i
++) {
1345 WAppIcon
*btn
= dock
->icon_array
[i
];
1347 if (!btn
|| (btn
->attracted
&& !dock
->keep_attracted
))
1350 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1351 list
= PLAppendArrayElement(list
, icon_info
);
1352 PLRelease(icon_info
);
1356 dock_state
= PLMakeDictionaryFromEntries(dApplications
, list
, NULL
);
1360 if (dock
->type
== WM_DOCK
) {
1361 sprintf(buffer
, "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0),
1363 value
= PLMakeString(buffer
);
1364 PLInsertDictionaryEntry(dock_state
, dPosition
, value
);
1368 value
= (dock
->lowered
? dYes
: dNo
);
1369 PLInsertDictionaryEntry(dock_state
, dLowered
, value
);
1371 if (dock
->type
== WM_CLIP
) {
1372 value
= (dock
->collapsed
? dYes
: dNo
);
1373 PLInsertDictionaryEntry(dock_state
, dCollapsed
, value
);
1375 value
= (dock
->auto_collapse
? dYes
: dNo
);
1376 PLInsertDictionaryEntry(dock_state
, dAutoCollapse
, value
);
1378 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1379 PLInsertDictionaryEntry(dock_state
, dAutoRaiseLower
, value
);
1381 value
= (dock
->attract_icons
? dYes
: dNo
);
1382 PLInsertDictionaryEntry(dock_state
, dAutoAttractIcons
, value
);
1384 value
= (dock
->keep_attracted
? dYes
: dNo
);
1385 PLInsertDictionaryEntry(dock_state
, dKeepAttracted
, value
);
1393 wDockSaveState(WScreen
*scr
)
1395 proplist_t dock_state
;
1397 dock_state
= dockSaveState(scr
->dock
);
1399 PLInsertDictionaryEntry(scr
->session_state
, dDock
, dock_state
);
1401 PLRelease(dock_state
);
1406 wClipSaveState(WScreen
*scr
)
1408 proplist_t clip_state
;
1410 clip_state
= make_icon_state(scr
->clip_icon
);
1412 PLInsertDictionaryEntry(scr
->session_state
, dClip
, clip_state
);
1414 PLRelease(clip_state
);
1419 wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1421 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1426 restore_icon_state(WScreen
*scr
, proplist_t info
, int type
, int index
)
1429 char *wclass
, *winstance
;
1430 proplist_t cmd
, value
;
1434 cmd
= PLGetDictionaryEntry(info
, dCommand
);
1435 if (!cmd
|| !PLIsString(cmd
)) {
1439 /* parse window name */
1440 value
= PLGetDictionaryEntry(info
, dName
);
1444 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1446 if (!winstance
&& !wclass
) {
1453 command
= wstrdup(PLGetString(cmd
));
1457 if (!command
|| strcmp(command
, "-")==0) {
1468 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
,
1475 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1476 if (type
== WM_CLIP
) {
1477 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1478 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1480 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1481 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1485 cmd
= PLGetDictionaryEntry(info
, dDropCommand
);
1487 aicon
->dnd_command
= wstrdup(PLGetString(cmd
));
1490 /* check auto launch */
1491 value
= PLGetDictionaryEntry(info
, dAutoLaunch
);
1493 aicon
->auto_launch
= 0;
1495 if (PLIsString(value
)) {
1496 if (strcasecmp(PLGetString(value
), "YES")==0)
1497 aicon
->auto_launch
= 1;
1499 wwarning(_("bad value in docked icon state info %s"),
1500 PLGetString(dAutoLaunch
));
1504 /* check if it wasn't normally docked */
1505 value
= PLGetDictionaryEntry(info
, dForced
);
1507 aicon
->forced_dock
= 0;
1509 if (PLIsString(value
)) {
1510 if (strcasecmp(PLGetString(value
), "YES")==0)
1511 aicon
->forced_dock
= 1;
1513 wwarning(_("bad value in docked icon state info %s"),
1514 PLGetString(dForced
));
1518 /* check if we can rely on the stuff in the app */
1519 value
= PLGetDictionaryEntry(info
, dBuggyApplication
);
1521 aicon
->buggy_app
= 0;
1523 if (PLIsString(value
)) {
1524 if (strcasecmp(PLGetString(value
), "YES")==0)
1525 aicon
->buggy_app
= 1;
1527 wwarning(_("bad value in docked icon state info %s"),
1528 PLGetString(dBuggyApplication
));
1532 /* get position in the dock */
1533 value
= PLGetDictionaryEntry(info
, dPosition
);
1534 if (value
&& PLIsString(value
)) {
1535 if (sscanf(PLGetString(value
), "%hi,%hi", &aicon
->xindex
,
1537 wwarning(_("bad value in docked icon state info %s"),
1538 PLGetString(dPosition
));
1540 /* check position sanity */
1541 /* incomplete section! */
1542 if (type
== WM_DOCK
) {
1544 if (aicon
->yindex
< 0)
1545 wwarning(_("bad value in docked icon position %i,%i"),
1546 aicon
->xindex
, aicon
->yindex
);
1549 aicon
->yindex
= index
;
1560 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1564 wClipRestoreState(WScreen
*scr
, proplist_t clip_state
)
1570 icon
= mainIconCreate(scr
, WM_CLIP
);
1575 PLRetain(clip_state
);
1577 /* restore position */
1579 value
= PLGetDictionaryEntry(clip_state
, dPosition
);
1582 if (!PLIsString(value
))
1583 COMPLAIN("Position");
1585 if (sscanf(PLGetString(value
), "%i,%i", &icon
->x_pos
,
1587 COMPLAIN("Position");
1589 /* check position sanity */
1590 if (icon
->y_pos
< 0)
1592 else if (icon
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1593 icon
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1595 if (icon
->x_pos
< 0)
1597 else if (icon
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1598 icon
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1603 value
= PLGetDictionaryEntry(clip_state
, dDropCommand
);
1604 if (value
&& PLIsString(value
))
1605 icon
->dnd_command
= wstrdup(PLGetString(value
));
1608 PLRelease(clip_state
);
1615 wDockRestoreState(WScreen
*scr
, proplist_t dock_state
, int type
)
1620 WAppIcon
*aicon
, *old_top
;
1624 dock
= wDockCreate(scr
, type
);
1630 PLRetain(dock_state
);
1633 /* restore position */
1635 value
= PLGetDictionaryEntry(dock_state
, dPosition
);
1638 if (!PLIsString(value
))
1639 COMPLAIN("Position");
1641 if (sscanf(PLGetString(value
), "%i,%i", &dock
->x_pos
,
1643 COMPLAIN("Position");
1645 /* check position sanity */
1646 if (dock
->y_pos
< 0)
1648 else if (dock
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1649 dock
->y_pos
= scr
->scr_height
- ICON_SIZE
;
1651 /* This is no more needed. ??? */
1652 if (type
== WM_CLIP
) {
1653 if (dock
->x_pos
< 0)
1655 else if (dock
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1656 dock
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1658 if (dock
->x_pos
>= 0) {
1659 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1660 dock
->on_right_side
= 0;
1662 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1663 dock
->on_right_side
= 1;
1669 /* restore lowered/raised state */
1673 value
= PLGetDictionaryEntry(dock_state
, dLowered
);
1676 if (!PLIsString(value
))
1677 COMPLAIN("Lowered");
1679 if (strcasecmp(PLGetString(value
), "YES")==0)
1685 /* restore collapsed state */
1687 dock
->collapsed
= 0;
1689 value
= PLGetDictionaryEntry(dock_state
, dCollapsed
);
1692 if (!PLIsString(value
))
1693 COMPLAIN("Collapsed");
1695 if (strcasecmp(PLGetString(value
), "YES")==0)
1696 dock
->collapsed
= 1;
1701 /* restore auto-collapsed state */
1703 value
= PLGetDictionaryEntry(dock_state
, dAutoCollapse
);
1706 if (!PLIsString(value
))
1707 COMPLAIN("AutoCollapse");
1709 if (strcasecmp(PLGetString(value
), "YES")==0) {
1710 dock
->auto_collapse
= 1;
1711 dock
->collapsed
= 1;
1717 /* restore auto-raise/lower state */
1719 value
= PLGetDictionaryEntry(dock_state
, dAutoRaiseLower
);
1722 if (!PLIsString(value
))
1723 COMPLAIN("AutoRaiseLower");
1725 if (strcasecmp(PLGetString(value
), "YES")==0) {
1726 dock
->auto_raise_lower
= 1;
1732 /* restore attract icons state */
1734 dock
->attract_icons
= 0;
1736 value
= PLGetDictionaryEntry(dock_state
, dAutoAttractIcons
);
1739 if (!PLIsString(value
))
1740 COMPLAIN("AutoAttractIcons");
1742 if (strcasecmp(PLGetString(value
), "YES")==0)
1743 dock
->attract_icons
= 1;
1748 /* restore keep attracted icons state */
1750 dock
->keep_attracted
= 0;
1752 value
= PLGetDictionaryEntry(dock_state
, dKeepAttracted
);
1755 if (!PLIsString(value
))
1756 COMPLAIN("KeepAttracted");
1758 if (strcasecmp(PLGetString(value
), "YES")==0)
1759 dock
->keep_attracted
= 1;
1764 /* application list */
1766 apps
= PLGetDictionaryEntry(dock_state
, dApplications
);
1772 count
= PLGetNumberOfElements(apps
);
1777 old_top
= dock
->icon_array
[0];
1779 /* dock->icon_count is set to 1 when dock is created.
1780 * Since Clip is already restored, we want to keep it so for clip,
1781 * but for dock we may change the default top tile, so we set it to 0.
1783 if (type
== WM_DOCK
)
1784 dock
->icon_count
= 0;
1786 for (i
=0; i
<count
; i
++) {
1787 if (dock
->icon_count
>= dock
->max_icons
) {
1788 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1792 value
= PLGetArrayElement(apps
, i
);
1793 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1795 dock
->icon_array
[dock
->icon_count
] = aicon
;
1799 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
*ICON_SIZE
);
1800 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
*ICON_SIZE
);
1803 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1805 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1807 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
,
1810 if (!dock
->collapsed
)
1811 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1812 wRaiseFrame(aicon
->icon
->core
);
1815 } else if (dock
->icon_count
==0 && type
==WM_DOCK
)
1819 /* if the first icon is not defined, use the default */
1820 if (dock
->icon_array
[0]==NULL
) {
1821 /* update default icon */
1822 old_top
->x_pos
= dock
->x_pos
;
1823 old_top
->y_pos
= dock
->y_pos
;
1825 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1827 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1828 dock
->icon_array
[0] = old_top
;
1829 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1830 /* we don't need to increment dock->icon_count here because it was
1831 * incremented in the loop above.
1833 } else if (old_top
!=dock
->icon_array
[0]) {
1834 if (old_top
== scr
->clip_icon
)
1835 scr
->clip_icon
= dock
->icon_array
[0];
1836 wAppIconDestroy(old_top
);
1841 PLRelease(dock_state
);
1849 wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1851 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1853 btn
->drop_launch
= 0;
1855 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1858 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1870 wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1876 for (i
= 0; i
< dock
->max_icons
; i
++) {
1877 btn
= dock
->icon_array
[i
];
1878 if (!btn
|| !btn
->auto_launch
)
1881 state
= wmalloc(sizeof(WSavedState
));
1882 memset(state
, 0, sizeof(WSavedState
));
1883 state
->workspace
= workspace
;
1884 /* TODO: this is klugy and is very difficult to understand
1885 * what's going on. Try to clean up */
1886 wDockLaunchWithState(dock
, btn
, state
);
1890 #ifdef REDUCE_APPICONS
1892 wDockSimulateLaunch(WDock
*dock
, WAppIcon
*btn
)
1894 if ((btn
== NULL
) || (dock
== NULL
))
1897 if (!btn
->running
) {
1898 if ((btn
->icon
->owner
== NULL
) && (btn
->applist
))
1899 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
1900 if (!btn
->forced_dock
)
1910 findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1916 if ((dock
= scr
->dock
)!=NULL
) {
1917 for (i
=0; i
<dock
->max_icons
; i
++) {
1918 if (dock
->icon_array
[i
]
1919 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1925 if (*icon_pos
<0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
)!=NULL
) {
1926 for (i
=0; i
<dock
->max_icons
; i
++) {
1927 if (dock
->icon_array
[i
]
1928 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1941 wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
1947 dock
= findDock(scr
, event
, &icon_pos
);
1952 * Return True if the drop was on an application icon window.
1953 * In this case, let the ClientMessage handler redirect the
1954 * message to the app.
1956 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!=None
)
1959 if (dock
->icon_array
[icon_pos
]->dnd_command
!=NULL
) {
1960 scr
->flags
.dnd_data_convertion_status
= 0;
1962 btn
= dock
->icon_array
[icon_pos
];
1964 if (!btn
->forced_dock
) {
1965 btn
->relaunching
= btn
->running
;
1968 if (btn
->wm_instance
|| btn
->wm_class
) {
1969 WWindowAttributes attr
;
1970 memset(&attr
, 0, sizeof(WWindowAttributes
));
1971 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
1973 btn
->wm_class
, &attr
, NULL
, True
);
1975 if (!attr
.no_appicon
)
1981 btn
->drop_launch
= 1;
1982 scr
->last_dock
= dock
;
1983 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1988 if (!btn
->relaunching
) {
1995 #endif /* OFFIX_DND */
2000 wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2007 wwin
= icon
->icon
->owner
;
2008 if (icon
->command
==NULL
) {
2010 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2012 icon
->command
= FlattenStringList(argv
, argc
);
2013 XFreeStringList(argv
);
2017 /* icon->forced_dock = 1;*/
2018 if (!icon
->attracted
|| dock
->type
!=WM_CLIP
|| dock
->keep_attracted
) {
2020 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2021 _("Type the command used to launch the application"),
2023 if (command
&& (command
[0]==0 ||
2024 (command
[0]=='-' && command
[1]==0))) {
2028 icon
->command
= command
;
2034 /* If the target is the dock, reject the icon. If
2035 * the target is the clip, make it an attracted icon
2037 if (dock
->type
==WM_CLIP
) {
2038 icon
->attracted
= 1;
2039 if (!icon
->icon
->shadowed
) {
2040 icon
->icon
->shadowed
= 1;
2041 icon
->icon
->force_paint
= 1;
2053 for (index
=1; index
<dock
->max_icons
; index
++)
2054 if (dock
->icon_array
[index
] == NULL
)
2056 /* if (index == dock->max_icons)
2059 assert(index
< dock
->max_icons
);
2061 dock
->icon_array
[index
] = icon
;
2065 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2066 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2071 icon
->launching
= 0;
2074 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2075 if (dock
->type
== WM_CLIP
) {
2076 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2077 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2079 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2080 icon
->icon
->core
->descriptor
.parent
= icon
;
2082 MoveInStackListUnder(dock
->icon_array
[index
-1]->icon
->core
,
2084 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2085 wAppIconPaint(icon
);
2087 if (wPreferences
.auto_arrange_icons
)
2088 wArrangeIcons(dock
->screen_ptr
, True
);
2091 if (icon
->command
&& !icon
->dnd_command
) {
2092 icon
->dnd_command
= wmalloc(strlen(icon
->command
)+8);
2093 sprintf(icon
->dnd_command
, "%s %%d", icon
->command
);
2102 reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2106 for(index
=1; index
<dock
->max_icons
; index
++) {
2107 if(dock
->icon_array
[index
] == icon
)
2110 assert(index
< dock
->max_icons
);
2115 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2116 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2121 moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2131 wwin
= icon
->icon
->owner
;
2134 * For the moment we can't do this if we move icons in Clip from one
2135 * workspace to other, because if we move two or more icons without
2136 * command, the dialog box will not be able to tell us to which of the
2137 * moved icons it applies. -Dan
2139 if ((dest
->type
==WM_DOCK
/*|| dest->keep_attracted*/) && icon
->command
==NULL
) {
2140 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2142 icon
->command
= FlattenStringList(argv
, argc
);
2143 XFreeStringList(argv
);
2148 /* icon->forced_dock = 1;*/
2149 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2150 _("Type the command used to launch the application"),
2152 if (command
&& (command
[0]==0 ||
2153 (command
[0]=='-' && command
[1]==0))) {
2157 icon
->command
= command
;
2168 for(index
=1; index
<src
->max_icons
; index
++) {
2169 if(src
->icon_array
[index
] == icon
)
2172 assert(index
< src
->max_icons
);
2174 src
->icon_array
[index
] = NULL
;
2177 for(index
=1; index
<dest
->max_icons
; index
++) {
2178 if(dest
->icon_array
[index
] == NULL
)
2181 /* if (index == dest->max_icons)
2184 assert(index
< dest
->max_icons
);
2186 dest
->icon_array
[index
] = icon
;
2189 /* deselect the icon */
2190 if (icon
->icon
->selected
)
2191 wIconSelect(icon
->icon
);
2193 if (dest
->type
== WM_DOCK
) {
2194 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2195 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2197 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2198 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2201 /* set it to be kept when moving to dock, or to a clip that keep the
2203 * Unless the icon does not have a command set
2205 if (icon
->command
&& (dest
->type
==WM_DOCK
|| dest
->keep_attracted
)) {
2206 icon
->attracted
= 0;
2207 if (icon
->icon
->shadowed
) {
2208 icon
->icon
->shadowed
= 0;
2209 icon
->icon
->force_paint
= 1;
2213 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2219 icon
->x_pos
= dest
->x_pos
+ x
*ICON_SIZE
;
2220 icon
->y_pos
= dest
->y_pos
+ y
*ICON_SIZE
;
2224 MoveInStackListUnder(dest
->icon_array
[index
-1]->icon
->core
,
2226 wAppIconPaint(icon
);
2233 wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2237 /* make the settings panel be closed */
2239 DestroyDockAppSettingsPanel(icon
->panel
);
2244 icon
->attracted
= 0;
2245 if (icon
->icon
->shadowed
) {
2246 icon
->icon
->shadowed
= 0;
2247 icon
->icon
->force_paint
= 1;
2250 /* deselect the icon */
2251 if (icon
->icon
->selected
)
2252 wIconSelect(icon
->icon
);
2254 if (icon
->command
) {
2255 free(icon
->command
);
2256 icon
->command
= NULL
;
2259 if (icon
->dnd_command
) {
2260 free(icon
->dnd_command
);
2261 icon
->dnd_command
= NULL
;
2265 for (index
=1; index
<dock
->max_icons
; index
++)
2266 if (dock
->icon_array
[index
] == icon
)
2268 assert(index
< dock
->max_icons
);
2269 dock
->icon_array
[index
] = NULL
;
2274 /* if the dock is not attached to an application or
2275 * the the application did not set the approriate hints yet,
2276 * destroy the icon */
2277 #ifdef REDUCE_APPICONS
2278 if ((icon
->num_apps
== 0) && (!icon
->running
|| !wApplicationOf(icon
->main_window
)) )
2280 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2282 wAppIconDestroy(icon
);
2284 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2285 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2286 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2287 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2288 icon
->icon
->core
->descriptor
.parent
= icon
;
2290 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2292 wAppIconPaint(icon
);
2293 if (wPreferences
.auto_arrange_icons
) {
2294 wArrangeIcons(dock
->screen_ptr
, True
);
2297 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2303 * returns the closest Dock slot index for the passed
2306 * Returns False if icon can't be docked.
2309 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2310 int *ret_x
, int *ret_y
, int redocking
)
2312 WScreen
*scr
= dock
->screen_ptr
;
2315 int i
, offset
= ICON_SIZE
/2;
2316 WAppIcon
*aicon
= NULL
;
2317 WAppIcon
*nicon
= NULL
;
2318 int max_y_icons
, max_x_icons
;
2320 max_x_icons
= scr
->scr_width
/ICON_SIZE
;
2321 max_y_icons
= scr
->scr_height
/ICON_SIZE
-1;
2323 if (wPreferences
.flags
.noupdates
)
2329 /* if the dock is full */
2331 (dock
->icon_count
>= dock
->max_icons
)) {
2335 /* exact position */
2337 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2339 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2342 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2344 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2346 /* check if the icon is outside the screen boundaries */
2347 if (dx
+ ex_x
*ICON_SIZE
< -ICON_SIZE
+2 ||
2348 dx
+ ex_x
*ICON_SIZE
>= scr
->scr_width
-1 ||
2349 dy
+ ex_y
*ICON_SIZE
< -ICON_SIZE
+2 ||
2350 dy
+ ex_y
*ICON_SIZE
>= scr
->scr_height
-1)
2353 if (dock
->type
== WM_DOCK
) {
2354 if (icon
->dock
!= dock
&& ex_x
!= 0)
2357 for (i
=0; i
<dock
->max_icons
; i
++) {
2358 nicon
= dock
->icon_array
[i
];
2359 if (nicon
&& nicon
->yindex
== ex_y
) {
2368 int sig
, done
, closest
;
2370 /* Possible cases when redocking:
2372 * icon dragged out of range of any slot -> false
2373 * icon dragged to range of free slot
2374 * icon dragged to range of same slot
2375 * icon dragged to range of different icon
2377 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2380 if (ex_y
>= 0 && ex_y
<= max_y_icons
&& (aicon
== icon
|| !aicon
)) {
2388 /* start looking at the upper slot or lower? */
2389 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2396 /* look for closest free slot */
2397 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2401 closest
= sig
*(i
/2) + ex_y
;
2402 /* check if this slot is used */
2404 for (j
= 0; j
<dock
->max_icons
; j
++) {
2405 if (dock
->icon_array
[j
]
2406 && dock
->icon_array
[j
]->yindex
==closest
) {
2407 /* slot is used by someone else */
2408 if (dock
->icon_array
[j
]!=icon
)
2416 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2417 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2419 (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+1))) {
2425 } else { /* !redocking */
2427 /* if slot is free and the icon is close enough, return it */
2428 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2436 for (i
=0; i
<dock
->max_icons
; i
++) {
2437 nicon
= dock
->icon_array
[i
];
2438 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2444 for (i
=0; i
<dock
->max_icons
; i
++) {
2445 nicon
= dock
->icon_array
[i
];
2446 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2447 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2448 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2454 if (neighbours
&& (aicon
==NULL
|| (redocking
&& aicon
== icon
))) {
2463 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2464 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2466 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2467 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2468 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2472 * returns true if it can find a free slot in the dock,
2473 * in which case it changes x_pos and y_pos accordingly.
2474 * Else returns false.
2477 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2479 WScreen
*scr
= dock
->screen_ptr
;
2481 unsigned char *slot_map
;
2485 int i
, done
= False
;
2487 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2490 /* if the dock is full */
2491 if (dock
->icon_count
>= dock
->max_icons
) {
2495 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2496 if (scr
->dock
->on_right_side
)
2497 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2499 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2502 if (ex
< dock
->x_pos
)
2504 if (sx
> dock
->x_pos
+ICON_SIZE
)
2505 sx
= dock
->x_pos
+ICON_SIZE
;
2512 /* check if clip is in a corner */
2513 if (dock
->type
==WM_CLIP
) {
2514 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2516 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2518 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2520 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2527 /* If the clip is in the corner, use only slots that are in the border
2529 if (corner
!=C_NONE
) {
2533 hcount
= MIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2534 vcount
= MIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2535 hmap
= wmalloc(hcount
+1);
2536 memset(hmap
, 0, hcount
+1);
2537 vmap
= wmalloc(vcount
+1);
2538 memset(vmap
, 0, vcount
+1);
2540 /* mark used positions */
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;
2554 for (i
=0; i
<dock
->max_icons
; i
++) {
2555 btn
= dock
->icon_array
[i
];
2559 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2560 vmap
[btn
->yindex
] = 1;
2561 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2562 hmap
[-btn
->xindex
] = 1;
2565 for (i
=0; i
<dock
->max_icons
; i
++) {
2566 btn
= dock
->icon_array
[i
];
2570 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2571 vmap
[-btn
->yindex
] = 1;
2572 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2573 hmap
[btn
->xindex
] = 1;
2577 for (i
=0; i
<dock
->max_icons
; i
++) {
2578 btn
= dock
->icon_array
[i
];
2582 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2583 vmap
[-btn
->yindex
] = 1;
2584 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2585 hmap
[-btn
->xindex
] = 1;
2590 /* search a vacant slot */
2591 for (i
=1; i
<MAX(vcount
, hcount
); i
++) {
2592 if (i
< vcount
&& vmap
[i
]==0) {
2598 } else if (i
< hcount
&& hmap
[i
]==0) {
2608 /* If found a slot, translate and return */
2610 if (corner
==C_NW
|| corner
==C_NE
) {
2615 if (corner
==C_NE
|| corner
==C_SE
) {
2622 /* else, try to find a slot somewhere else */
2625 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2626 * placed outside of screen */
2627 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2629 /* In the worst case (the clip is in the corner of the screen),
2630 * the amount of icons that fit in the clip is smaller.
2631 * Double the map to get a safe value.
2637 slot_map
= wmalloc(mwidth
*mwidth
);
2638 memset(slot_map
, 0, mwidth
*mwidth
);
2640 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2642 /* mark used slots in the map. If the slot falls outside the map
2643 * (for example, when all icons are placed in line), ignore them. */
2644 for (i
=0; i
<dock
->max_icons
; i
++) {
2645 btn
= dock
->icon_array
[i
];
2647 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2649 /* Find closest slot from the center that is free by scanning the
2650 * map from the center to outward in circular passes.
2651 * This will not result in a neat layout, but will be optimal
2652 * in the sense that there will not be holes left.
2655 for (i
= 1; i
<= r
&& !done
; i
++) {
2658 /* top and bottom parts of the ring */
2659 for (x
= -i
; x
<= i
&& !done
; x
++) {
2660 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2662 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2663 if (slot_map
[XY2OFS(x
,y
)]==0
2664 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2671 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2672 if (slot_map
[XY2OFS(x
,y
)]==0
2673 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2680 /* left and right parts of the ring */
2681 for (y
= -i
+1; y
<= i
-1; y
++) {
2682 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2684 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2685 if (slot_map
[XY2OFS(x
,y
)]==0
2686 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2693 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2694 if (slot_map
[XY2OFS(x
,y
)]==0
2695 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2710 moveDock(WDock
*dock
, int new_x
, int new_y
)
2715 dock
->x_pos
= new_x
;
2716 dock
->y_pos
= new_y
;
2717 for (i
=0; i
<dock
->max_icons
; i
++) {
2718 btn
= dock
->icon_array
[i
];
2720 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2721 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2722 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2729 swapDock(WDock
*dock
)
2731 WScreen
*scr
= dock
->screen_ptr
;
2736 if (dock
->on_right_side
) {
2737 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2739 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2742 for (i
=0; i
<dock
->max_icons
; i
++) {
2743 btn
= dock
->icon_array
[i
];
2746 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2750 wScreenUpdateUsableArea(scr
);
2755 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2757 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2763 cmdline
= ExpandOptions(scr
, command
);
2765 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2773 ParseCommand(cmdline
, &argv
, &argc
);
2783 if ((pid
=fork())==0) {
2787 SetupEnvironment(scr
);
2793 args
= malloc(sizeof(char*)*(argc
+1));
2796 for (i
=0; i
<argc
; i
++) {
2800 execvp(argv
[0], args
);
2809 state
= wmalloc(sizeof(WSavedState
));
2810 memset(state
, 0, sizeof(WSavedState
));
2812 state
->miniaturized
= -1;
2814 if (btn
->dock
== scr
->dock
)
2815 state
->workspace
= -1;
2817 state
->workspace
= scr
->current_workspace
;
2819 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
2821 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
2832 wDockHideIcons(WDock
*dock
)
2840 btn
= dock
->icon_array
[0];
2842 for (i
=1; i
<dock
->max_icons
; i
++) {
2843 if (dock
->icon_array
[i
])
2844 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2853 wDockShowIcons(WDock
*dock
)
2861 btn
= dock
->icon_array
[0];
2862 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2864 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2865 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2867 for (i
=1; i
<dock
->max_icons
; i
++) {
2868 if (dock
->icon_array
[i
]) {
2869 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
2875 if (!dock
->collapsed
) {
2876 for (i
=1; i
<dock
->max_icons
; i
++) {
2877 if (dock
->icon_array
[i
]) {
2878 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2889 wDockLower(WDock
*dock
)
2893 for (i
=0; i
<dock
->max_icons
; i
++) {
2894 if (dock
->icon_array
[i
])
2895 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2901 wDockRaise(WDock
*dock
)
2905 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
2906 if (dock
->icon_array
[i
])
2907 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2913 wDockRaiseLower(WDock
*dock
)
2915 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2916 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2917 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2925 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
2927 icon
->launching
= 0;
2928 icon
->relaunching
= 0;
2929 dockIconPaint(icon
);
2934 wDockFindIconFor(WDock
*dock
, Window window
)
2939 for (i
=0; i
<dock
->max_icons
; i
++) {
2940 icon
= dock
->icon_array
[i
];
2941 if (icon
&& icon
->main_window
== window
)
2949 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
2952 #ifdef REDUCE_APPICONS
2953 WAppIconAppList
*tapplist
;
2955 char *wm_class
, *wm_instance
;
2957 Bool firstPass
= True
;
2959 char *command
= NULL
;
2965 if (XGetCommand(dpy
, window
, &argv
, &argc
)) {
2966 if (argc
> 0 && argv
!= NULL
)
2967 command
= FlattenStringList(argv
,argc
);
2969 XFreeStringList(argv
);
2974 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
2975 (!wm_class
&& !wm_instance
))
2979 for (i
=0; i
<dock
->max_icons
; i
++) {
2980 icon
= dock
->icon_array
[i
];
2984 /* app is already attached to icon */
2985 if (icon
->main_window
== window
) {
2990 if ((icon
->wm_instance
|| icon
->wm_class
)
2992 || (dock
->screen_ptr
->flags
.startup
&& !icon
->running
))) {
2994 if (icon
->wm_instance
&& wm_instance
&&
2995 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
2998 if (icon
->wm_class
&& wm_class
&&
2999 strcmp(icon
->wm_class
, wm_class
)!=0) {
3002 if (firstPass
&& command
&& strcmp(icon
->command
, command
)!=0) {
3006 if (!icon
->relaunching
) {
3009 /* Possibly an application that was docked with dockit,
3010 * but the user did not update WMState to indicate that
3011 * it was docked by force */
3012 wapp
= wApplicationOf(window
);
3014 icon
->forced_dock
= 1;
3017 if (!icon
->forced_dock
)
3018 icon
->main_window
= window
;
3020 #ifdef REDUCE_APPICONS
3021 tapplist
= wmalloc(sizeof(WAppIconAppList
));
3022 memset(tapplist
, 0, sizeof(WAppIconAppList
));
3023 tapplist
->next
= icon
->applist
;
3025 icon
->applist
->prev
= tapplist
;
3026 icon
->applist
= tapplist
;
3027 tapplist
->wapp
= wApplicationOf(window
);
3032 wDockFinishLaunch(dock
, icon
);
3037 if (firstPass
&& !found
) {
3054 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3056 if (!wPreferences
.flags
.noclip
) {
3057 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3058 if (scr
->current_workspace
!= workspace
) {
3059 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3061 wDockHideIcons(old_clip
);
3062 if (old_clip
->auto_raise_lower
) {
3063 if (old_clip
->auto_raise_magic
) {
3064 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3065 old_clip
->auto_raise_magic
= NULL
;
3067 wDockLower(old_clip
);
3069 if (old_clip
->auto_collapse
) {
3070 if (old_clip
->auto_expand_magic
) {
3071 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3072 old_clip
->auto_expand_magic
= NULL
;
3074 old_clip
->collapsed
= 1;
3076 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3078 if (scr
->flags
.clip_balloon_mapped
)
3079 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3086 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3091 for (i
=0; i
<dock
->max_icons
; i
++) {
3092 icon
= dock
->icon_array
[i
];
3096 if (icon
->launching
&& icon
->pid
== pid
) {
3097 if (!icon
->relaunching
) {
3099 icon
->main_window
= None
;
3101 wDockFinishLaunch(dock
, icon
);
3106 sprintf(msg
, _("Could not execute command \"%s\""),
3107 icon
->drop_launch
&& icon
->dnd_command
3108 ? icon
->dnd_command
: icon
->command
);
3110 sprintf(msg
, _("Could not execute command \"%s\""),
3113 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
3114 _("OK"), NULL
, NULL
);
3123 toggleLowered(WDock
*dock
)
3128 /* lower/raise Dock */
3129 if (!dock
->lowered
) {
3130 newlevel
= WMNormalLevel
;
3133 newlevel
= WMDockLevel
;
3137 for (i
=0; i
<dock
->max_icons
; i
++) {
3138 tmp
= dock
->icon_array
[i
];
3142 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3144 wLowerFrame(tmp
->icon
->core
);
3147 if (dock
->type
== WM_DOCK
)
3148 wScreenUpdateUsableArea(dock
->screen_ptr
);
3153 toggleCollapsed(WDock
*dock
)
3155 if (dock
->collapsed
) {
3156 dock
->collapsed
= 0;
3157 wDockShowIcons(dock
);
3160 dock
->collapsed
= 1;
3161 wDockHideIcons(dock
);
3167 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3169 WScreen
*scr
= dock
->screen_ptr
;
3170 WObjDescriptor
*desc
;
3172 WApplication
*wapp
= NULL
;
3175 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3177 if (dock
->type
== WM_DOCK
) {
3179 entry
= dock
->menu
->entries
[index
];
3180 entry
->flags
.indicator_on
= !dock
->lowered
;
3181 entry
->clientdata
= dock
;
3184 if (scr
->clip_options
)
3185 updateClipOptionsMenu(scr
->clip_options
, dock
);
3187 /* Rename Workspace */
3188 entry
= dock
->menu
->entries
[++index
];
3189 entry
->clientdata
= dock
;
3192 entry
= dock
->menu
->entries
[++index
];
3193 entry
->clientdata
= aicon
;
3194 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3196 /* (un)select all icons */
3197 entry
= dock
->menu
->entries
[++index
];
3198 entry
->clientdata
= aicon
;
3199 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3202 entry
= dock
->menu
->entries
[++index
];
3203 entry
->clientdata
= aicon
;
3204 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3206 /* this is the workspace submenu part */
3207 if (scr
->clip_submenu
)
3208 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3211 /* remove icon(s) */
3212 entry
= dock
->menu
->entries
[++index
];
3213 entry
->clientdata
= aicon
;
3214 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3216 /* attract icon(s) */
3217 entry
= dock
->menu
->entries
[++index
];
3218 entry
->clientdata
= aicon
;
3222 entry
= dock
->menu
->entries
[++index
];
3223 entry
->clientdata
= aicon
;
3224 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3227 entry
= dock
->menu
->entries
[++index
];
3228 entry
->clientdata
= aicon
;
3229 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3232 entry
= dock
->menu
->entries
[++index
];
3233 entry
->clientdata
= aicon
;
3234 if (aicon
->icon
->owner
) {
3235 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3236 if (wapp
&& wapp
->flags
.hidden
)
3237 entry
->text
= _("Unhide");
3239 entry
->text
= _("Hide");
3241 entry
->text
= _("Hide");
3243 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3246 entry
= dock
->menu
->entries
[++index
];
3247 entry
->clientdata
= aicon
;
3248 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
3249 && !wPreferences
.flags
.noupdates
);
3252 entry
= dock
->menu
->entries
[++index
];
3253 entry
->clientdata
= aicon
;
3254 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3256 if (!dock
->menu
->flags
.realized
)
3257 wMenuRealize(dock
->menu
);
3259 if (dock
->type
== WM_CLIP
) {
3260 x_pos
= event
->xbutton
.x_root
+2;
3262 x_pos
= dock
->on_right_side
?
3263 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 2 : 0;
3266 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3268 /* allow drag select */
3269 event
->xany
.send_event
= True
;
3270 desc
= &dock
->menu
->menu
->descriptor
;
3271 (*desc
->handle_mousedown
)(desc
, event
);
3276 openClipWorkspaceMenu(WScreen
*scr
, int x
, int y
)
3278 if (!scr
->clip_ws_menu
) {
3279 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3281 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
3282 wMenuMapAt(scr
->clip_ws_menu
, x
, y
, False
);
3286 /******************************************************************/
3288 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3290 WAppIcon
*btn
= desc
->parent
;
3291 WDock
*dock
= btn
->dock
;
3292 WApplication
*wapp
= NULL
;
3295 #ifdef REDUCE_APPICONS
3296 if ((btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) ||
3297 ((btn
->icon
->owner
== NULL
) && (btn
->applist
!= NULL
))) {
3298 if (btn
->icon
->owner
== NULL
)
3299 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
3304 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3306 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3310 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3312 /* go to the last workspace that the user worked on the app */
3314 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3317 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3320 if (event
->xbutton
.state
& MOD_MASK
) {
3321 wHideOtherApplications(btn
->icon
->owner
);
3324 if (event
->xbutton
.button
==Button1
) {
3326 if (event
->xbutton
.state
& MOD_MASK
) {
3327 /* raise/lower dock */
3328 toggleLowered(dock
);
3329 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3330 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3331 toggleCollapsed(dock
);
3333 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3334 } else if (btn
->command
) {
3335 if (!btn
->launching
&&
3336 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3337 launchDockedApplication(btn
);
3346 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3348 WScreen
*scr
= dock
->screen_ptr
;
3349 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3352 int grabbed
= 0, swapped
= 0, done
;
3353 Pixmap ghost
= None
;
3354 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3357 puts("moving dock");
3359 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3360 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3361 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3362 wwarning("pointer grab failed for dock move");
3365 for (x
=0; x
<dock
->max_icons
; x
++) {
3366 if (dock
->icon_array
[x
]!=NULL
&&
3367 dock
->icon_array
[x
]->yindex
> y
)
3368 y
= dock
->icon_array
[x
]->yindex
;
3371 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3375 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3376 |ButtonMotionMask
|ExposureMask
, &ev
);
3384 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3385 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3386 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3387 |ButtonReleaseMask
|ButtonPressMask
,
3388 wCursor
[WCUR_MOVE
], CurrentTime
);
3393 if (dock
->type
== WM_CLIP
) {
3394 if (ev
.xmotion
.x_root
- ofs_x
< 0) {
3396 } else if (ev
.xmotion
.x_root
- ofs_x
+ ICON_SIZE
>
3398 x
= scr
->scr_width
- ICON_SIZE
;
3400 x
= ev
.xmotion
.x_root
- ofs_x
;
3402 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3404 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3406 y
= scr
->scr_height
- ICON_SIZE
;
3408 y
= ev
.xmotion
.y_root
- ofs_y
;
3410 moveDock(dock
, x
, y
);
3412 /* move vertically if pointer is inside the dock*/
3413 if ((dock
->on_right_side
&&
3414 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3415 || (!dock
->on_right_side
&&
3416 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3418 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3420 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3422 y
= scr
->scr_height
- ICON_SIZE
;
3424 y
= ev
.xmotion
.y_root
- ofs_y
;
3426 moveDock(dock
, dock
->x_pos
, y
);
3428 /* move horizontally to change sides */
3429 x
= ev
.xmotion
.x_root
- ofs_x
;
3430 if (!dock
->on_right_side
) {
3434 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3435 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3436 -DOCK_EXTRA_SPACE
-1, dock
->y_pos
);
3439 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3440 scr
->scr_width
-ICON_SIZE
3441 -DOCK_EXTRA_SPACE
-1,
3443 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3445 XClearWindow(dpy
, scr
->dock_shadow
);
3448 XMapRaised(dpy
, scr
->dock_shadow
);
3451 if (superfluous
&& ghost
!=None
) {
3452 XFreePixmap(dpy
, ghost
);
3455 XUnmapWindow(dpy
, scr
->dock_shadow
);
3460 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3461 XMoveWindow(dpy
, scr
->dock_shadow
,
3462 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3465 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3466 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3467 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3469 XClearWindow(dpy
, scr
->dock_shadow
);
3472 XMapRaised(dpy
, scr
->dock_shadow
);
3475 XUnmapWindow(dpy
, scr
->dock_shadow
);
3477 if (superfluous
&& ghost
!=None
) {
3478 XFreePixmap(dpy
, ghost
);
3490 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3492 XUngrabPointer(dpy
, CurrentTime
);
3493 XUnmapWindow(dpy
, scr
->dock_shadow
);
3494 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3495 if (dock
->type
== WM_DOCK
) {
3498 dock
->on_right_side
= 1;
3500 dock
->on_right_side
= 0;
3502 wArrangeIcons(scr
, False
);
3511 XFreePixmap(dpy
, ghost
);
3512 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3515 puts("End dock move");
3522 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3524 WScreen
*scr
= dock
->screen_ptr
;
3526 WIcon
*icon
= aicon
->icon
;
3527 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3528 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3530 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3531 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3532 int shad_x
= x
, shad_y
= y
;
3533 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3535 Pixmap ghost
= None
;
3537 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3539 if (wPreferences
.flags
.noupdates
)
3542 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3543 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3544 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3546 wwarning("pointer grab failed for icon move");
3550 wRaiseFrame(icon
->core
);
3552 if (!wPreferences
.flags
.noclip
)
3553 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3555 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3557 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3560 wins
[0] = icon
->core
->window
;
3561 wins
[1] = scr
->dock_shadow
;
3562 XRestackWindows(dpy
, wins
, 2);
3563 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3564 ICON_SIZE
, ICON_SIZE
);
3566 if (icon
->pixmap
!=None
)
3567 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3569 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3571 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3572 XClearWindow(dpy
, scr
->dock_shadow
);
3574 XMapWindow(dpy
, scr
->dock_shadow
);
3580 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3581 |ButtonMotionMask
|ExposureMask
, &ev
);
3589 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3590 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3591 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3592 |ButtonReleaseMask
|ButtonPressMask
,
3593 wCursor
[WCUR_MOVE
], CurrentTime
);
3600 x
= ev
.xmotion
.x_root
- ofs_x
;
3601 y
= ev
.xmotion
.y_root
- ofs_y
;
3602 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3605 if (last_dock
!= dock
&& collapsed
) {
3606 last_dock
->collapsed
= 1;
3607 wDockHideIcons(last_dock
);
3610 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3611 dock
->collapsed
= 0;
3612 wDockShowIcons(dock
);
3614 if (dock
->auto_raise_lower
)
3619 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3622 if (last_dock
!= dock2
&& collapsed
) {
3623 last_dock
->collapsed
= 1;
3624 wDockHideIcons(last_dock
);
3627 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3628 dock2
->collapsed
= 0;
3629 wDockShowIcons(dock2
);
3631 if (dock2
->auto_raise_lower
)
3636 if (aicon
->launching
3637 || (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3638 || (!aicon
->running
&& tmp
)) {
3639 shad_x
= last_dock
->x_pos
+ ix
*wPreferences
.icon_size
;
3640 shad_y
= last_dock
->y_pos
+ iy
*wPreferences
.icon_size
;
3642 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3645 XMapWindow(dpy
, scr
->dock_shadow
);
3647 if (!collapsed
&& (collapsed
= last_dock
->collapsed
)) {
3648 last_dock
->collapsed
= 0;
3649 wDockShowIcons(last_dock
);
3656 XUnmapWindow(dpy
, scr
->dock_shadow
);
3658 if (last_dock
&& collapsed
&&
3659 aicon
->running
&& (ev
.xmotion
.state
& MOD_MASK
)) {
3660 last_dock
->collapsed
= 1;
3661 wDockHideIcons(last_dock
);
3668 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3675 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3677 XUngrabPointer(dpy
, CurrentTime
);
3679 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3680 XUnmapWindow(dpy
, scr
->dock_shadow
);
3682 reattachIcon(dock
, aicon
, ix
, iy
);
3683 if (clip
&& dock
!=clip
&& clip
->auto_raise_lower
)
3686 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3688 /* Slide it back if dock rejected it */
3689 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3691 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3693 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3701 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3702 /* We need to deselect it, even if is deselected in
3703 * wDockDetach(), because else DoKaboom() will fail.
3705 if (aicon
->icon
->selected
)
3706 wIconSelect(aicon
->icon
);
3707 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3710 if (clip
&& clip
->auto_raise_lower
)
3712 wDockDetach(dock
, aicon
);
3715 last_dock
->collapsed
= 1;
3716 wDockHideIcons(last_dock
);
3721 XFreePixmap(dpy
, ghost
);
3722 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3725 puts("End icon move");
3734 getClipButton(int px
, int py
)
3736 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
3738 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3741 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
3742 return CLIP_FORWARD
;
3743 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
3751 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3754 int done
, direction
, new_ws
;
3756 WDock
*clip
= scr
->clip_icon
->dock
;
3758 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3760 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3761 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3763 wClipIconPaint(scr
->clip_icon
);
3766 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
3767 |ButtonPressMask
, &ev
);
3774 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3775 if (new_dir
!= direction
) {
3776 direction
= new_dir
;
3777 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3778 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3779 wClipIconPaint(scr
->clip_icon
);
3787 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3792 clip
->lclip_button_pushed
= 0;
3793 clip
->rclip_button_pushed
= 0;
3795 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3797 if (direction
== CLIP_FORWARD
) {
3798 if (scr
->current_workspace
< scr
->workspace_count
-1)
3799 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3800 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
3801 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3802 else if (wPreferences
.ws_cycle
)
3803 wWorkspaceChange(scr
, 0);
3805 else if (direction
== CLIP_REWIND
) {
3806 if (scr
->current_workspace
> 0)
3807 wWorkspaceChange(scr
, scr
->current_workspace
-1);
3808 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
3809 wWorkspaceChange(scr
, scr
->workspace_count
-1);
3812 wClipIconPaint(scr
->clip_icon
);
3817 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3819 WAppIcon
*aicon
= desc
->parent
;
3820 WDock
*dock
= aicon
->dock
;
3821 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3823 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3826 scr
->last_dock
= dock
;
3828 if (dock
->menu
->flags
.mapped
)
3829 wMenuUnmap(dock
->menu
);
3831 if (IsDoubleClick(scr
, event
)) {
3832 /* double-click was not in the main clip icon */
3833 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
3834 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
3835 iconDblClick(desc
, event
);
3840 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
3841 XUnmapWindow(dpy
, scr
->clip_balloon
);
3842 scr
->flags
.clip_balloon_mapped
= 0;
3846 puts("handling dock");
3848 if (event
->xbutton
.button
== Button1
) {
3849 if (event
->xbutton
.state
& MOD_MASK
)
3854 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
3855 dock
->type
!=WM_DOCK
) {
3856 wIconSelect(aicon
->icon
);
3860 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
3861 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
3862 && dock
->type
==WM_CLIP
)
3863 handleClipChangeWorkspace(scr
, event
);
3865 handleDockMove(dock
, aicon
, event
);
3867 handleIconMove(dock
, aicon
, event
);
3869 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
3870 aicon
->xindex
==0 && aicon
->yindex
==0) {
3871 openClipWorkspaceMenu(scr
, event
->xbutton
.x_root
+2,
3872 event
->xbutton
.y_root
+2);
3873 if (scr
->clip_ws_menu
) {
3875 menu
= scr
->clip_ws_menu
;
3876 desc
= &menu
->menu
->descriptor
;
3878 event
->xany
.send_event
= True
;
3879 (*desc
->handle_mousedown
)(desc
, event
);
3881 } else if (event
->xbutton
.button
== Button3
) {
3882 openDockMenu(dock
, aicon
, event
);
3888 showClipBalloon(WDock
*dock
, int workspace
)
3892 WScreen
*scr
= dock
->screen_ptr
;
3896 scr
->flags
.clip_balloon_mapped
= 1;
3897 XMapWindow(dpy
, scr
->clip_balloon
);
3899 text
= scr
->workspaces
[workspace
]->name
;
3901 w
= wTextWidth(scr
->clip_title_font
->font
, text
, strlen(text
));
3903 h
= scr
->clip_title_font
->height
;
3904 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
3906 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
3907 y
= dock
->y_pos
+ ICON_SIZE
-scr
->clip_title_font
->height
- 3;
3909 if (x
+w
> scr
->scr_width
) {
3910 x
= scr
->scr_width
- w
;
3911 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
3912 y
= dock
->y_pos
- h
- 1;
3914 y
= dock
->y_pos
+ ICON_SIZE
;
3915 XRaiseWindow(dpy
, scr
->clip_balloon
);
3917 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
3918 stack
[1] = scr
->clip_balloon
;
3919 XRestackWindows(dpy
, stack
, 2);
3921 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
3922 XSetForeground(dpy
, scr
->clip_title_gc
,
3923 scr
->clip_title_pixel
[CLIP_NORMAL
]);
3924 XClearWindow(dpy
, scr
->clip_balloon
);
3925 wDrawString(scr
->clip_balloon
, scr
->clip_title_font
, scr
->clip_title_gc
,
3926 0, scr
->clip_title_font
->y
, text
, strlen(text
));
3931 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3933 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
3936 assert(event
->type
==EnterNotify
);
3938 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
3942 if (!dock
|| dock
->type
!=WM_CLIP
)
3945 /* The auto raise/lower code */
3946 if (dock
->auto_lower_magic
) {
3947 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3948 dock
->auto_lower_magic
= NULL
;
3950 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
3951 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
,
3956 /* The auto expand/collapse code */
3957 if (dock
->auto_collapse_magic
) {
3958 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3959 dock
->auto_collapse_magic
= NULL
;
3961 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
3962 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
,
3967 if (btn
->xindex
== 0 && btn
->yindex
== 0)
3968 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
3970 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
3971 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
3972 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
3979 clipLeave(WDock
*dock
)
3982 WObjDescriptor
*desc
= NULL
;
3984 if (!dock
|| dock
->type
!=WM_CLIP
)
3987 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
)!=False
) {
3988 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3989 (XPointer
*)&desc
)!=XCNOENT
3990 && desc
&& desc
->parent_type
==WCLASS_DOCK_ICON
3991 && ((WAppIcon
*)desc
->parent
)->dock
3992 && ((WAppIcon
*)desc
->parent
)->dock
->type
==WM_CLIP
) {
3993 /* We didn't left the Clip yet */
3994 XPutBackEvent(dpy
, &event
);
3998 XPutBackEvent(dpy
, &event
);
4000 /* We entered a withdrawn window, so we're still in Clip */
4004 if (dock
->auto_raise_magic
) {
4005 WMDeleteTimerHandler(dock
->auto_raise_magic
);
4006 dock
->auto_raise_magic
= NULL
;
4008 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
4009 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
,
4014 if (dock
->auto_expand_magic
) {
4015 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4016 dock
->auto_expand_magic
= NULL
;
4018 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
4019 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
4027 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4029 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4031 assert(event
->type
==LeaveNotify
);
4033 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4036 clipLeave(btn
->dock
);
4041 clipAutoCollapse(void *cdata
)
4043 WDock
*dock
= (WDock
*)cdata
;
4045 if (dock
->type
!=WM_CLIP
)
4048 if (dock
->auto_collapse
) {
4049 dock
->collapsed
= 1;
4050 wDockHideIcons(dock
);
4052 dock
->auto_collapse_magic
= NULL
;
4057 clipAutoExpand(void *cdata
)
4059 WDock
*dock
= (WDock
*)cdata
;
4061 if (dock
->type
!=WM_CLIP
)
4064 if (dock
->auto_collapse
) {
4065 dock
->collapsed
= 0;
4066 wDockShowIcons(dock
);
4068 dock
->auto_expand_magic
= NULL
;
4073 clipAutoLower(void *cdata
)
4075 WDock
*dock
= (WDock
*)cdata
;
4077 if (dock
->type
!=WM_CLIP
)
4080 if (dock
->auto_raise_lower
)
4083 dock
->auto_lower_magic
= NULL
;
4088 clipAutoRaise(void *cdata
)
4090 WDock
*dock
= (WDock
*)cdata
;
4092 if (dock
->type
!=WM_CLIP
)
4095 if (dock
->auto_raise_lower
)
4098 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4099 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4102 dock
->auto_raise_magic
= NULL
;