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,
429 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 5 - as
, 5,
430 ICON_SIZE
- 6, 5, &dark
);
431 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5,
432 ICON_SIZE
- 6, 5 + as
, &dark
);
433 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 6, 5, ICON_SIZE
- 6, 5 + as
,
437 ROperateLine(tile
, RAddOperation
, 2, tp
+2, pt
-2,
438 wPreferences
.icon_size
-3, &dark
);
439 RDrawLine(tile
, 0, tp
-1, pt
+1, wPreferences
.icon_size
-1, &black
);
440 ROperateLine(tile
, RSubtractOperation
, 0, tp
-2, pt
+1,
441 wPreferences
.icon_size
-2, &light
);
444 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
,
445 5 + as
, ICON_SIZE
- 6, &dark
);
446 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 5 - as
, 5,
447 ICON_SIZE
- 6, &dark
);
448 ROperateLine(tile
, RAddOperation
, 5, ICON_SIZE
- 6, 5 + as
, ICON_SIZE
- 6,
456 removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
458 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
461 LinkedList
*selectedIcons
;
464 assert(clickedIcon
!=NULL
);
466 dock
= clickedIcon
->dock
;
468 selectedIcons
= getSelected(dock
);
471 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
472 _("All selected icons will be removed!"),
473 _("OK"), _("Cancel"), NULL
)!=WAPRDefault
) {
477 if (clickedIcon
->xindex
==0 && clickedIcon
->yindex
==0)
479 selectedIcons
= list_cons(clickedIcon
, NULL
);
482 while (selectedIcons
) {
483 aicon
= selectedIcons
->head
;
484 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
485 wDockDetach(dock
, aicon
);
487 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
488 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
489 aicon
->x_pos
, aicon
->y_pos
);
490 if (!dock
->mapped
|| dock
->collapsed
)
491 XMapWindow(dpy
, aicon
->icon
->core
->window
);
493 list_remove_head(&selectedIcons
);
496 if (wPreferences
.auto_arrange_icons
)
497 wArrangeIcons(dock
->screen_ptr
, True
);
502 keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
504 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
507 LinkedList
*selectedIcons
;
509 assert(clickedIcon
!=NULL
);
510 dock
= clickedIcon
->dock
;
512 selectedIcons
= getSelected(dock
);
514 if (!selectedIcons
&& clickedIcon
!=dock
->screen_ptr
->clip_icon
) {
515 char *command
= NULL
;
517 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
518 clickedIcon
->editing
= 1;
519 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
520 _("Type the command used to launch the application"),
522 if (command
&& (command
[0]==0 ||
523 (command
[0]=='-' && command
[1]==0))) {
527 clickedIcon
->command
= command
;
528 clickedIcon
->editing
= 0;
530 clickedIcon
->editing
= 0;
537 selectedIcons
= list_cons(clickedIcon
, NULL
);
540 while (selectedIcons
) {
541 aicon
= selectedIcons
->head
;
542 if (aicon
->icon
->selected
)
543 wIconSelect(aicon
->icon
);
544 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
545 aicon
->attracted
= 0;
546 if (aicon
->icon
->shadowed
) {
547 aicon
->icon
->shadowed
= 0;
548 aicon
->icon
->force_paint
= 1;
549 wAppIconPaint(aicon
);
552 list_remove_head(&selectedIcons
);
560 toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
562 WDock
*dock
= (WDock
*)entry
->clientdata
;
564 assert(entry
->clientdata
!=NULL
);
566 dock
->attract_icons
= !dock
->attract_icons
;
567 /*if (!dock->attract_icons)
568 dock->keep_attracted = 0;*/
570 entry
->flags
.indicator_on
= dock
->attract_icons
;
577 toggleKeepCallback(WMenu
*menu
, WMenuEntry
*entry
)
579 WDock
*dock
= (WDock
*)entry
->clientdata
;
583 assert(entry
->clientdata
!=NULL
);
585 dock
->keep_attracted
= !dock
->keep_attracted
;
587 if (dock
->keep_attracted
) {
588 for (i
=0; i
< dock
->max_icons
; i
++) {
589 btn
= dock
->icon_array
[i
];
590 if (btn
&& btn
->attracted
&& btn
->command
) {
592 if (btn
->icon
->shadowed
) {
593 btn
->icon
->shadowed
= 0;
594 btn
->icon
->force_paint
= 1;
601 entry
->flags
.indicator_on
= dock
->keep_attracted
;
608 selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
610 WAppIcon
*icon
= (WAppIcon
*)entry
->clientdata
;
614 wIconSelect(icon
->icon
);
621 colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
623 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
626 int x
, y
, x_pos
, y_pos
;
628 assert(entry
->clientdata
!=NULL
);
629 clip
= clickedIcon
->dock
;
631 aicon
= clip
->screen_ptr
->app_icon_list
;
634 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
635 x_pos
= clip
->x_pos
+ x
*ICON_SIZE
;
636 y_pos
= clip
->y_pos
+ y
*ICON_SIZE
;
637 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
639 if (wPreferences
.no_animations
) {
640 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
642 SlideWindow(aicon
->icon
->core
->window
,
643 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
646 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
647 #endif /* ANIMATIONS */
649 aicon
->attracted
= 1;
650 if (!clip
->keep_attracted
&& !aicon
->icon
->shadowed
) {
651 aicon
->icon
->shadowed
= 1;
652 aicon
->icon
->force_paint
= 1;
653 /* We don't do an wAppIconPaint() here because it's in
654 * wDockAttachIcon(). -Dan
657 wDockAttachIcon(clip
, aicon
, x
, y
);
658 if (clip
->collapsed
|| !clip
->mapped
)
659 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
667 selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
669 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
671 LinkedList
*selectedIcons
;
675 assert(clickedIcon
!=NULL
);
676 dock
= clickedIcon
->dock
;
678 selectedIcons
= getSelected(dock
);
680 if (!selectedIcons
) {
681 for (i
=1; i
<dock
->max_icons
; i
++) {
682 btn
= dock
->icon_array
[i
];
683 if (btn
&& !btn
->icon
->selected
) {
684 wIconSelect(btn
->icon
);
688 while(selectedIcons
) {
689 btn
= selectedIcons
->head
;
690 wIconSelect(btn
->icon
);
691 list_remove_head(&selectedIcons
);
700 toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
702 assert(entry
->clientdata
!=NULL
);
704 toggleCollapsed(entry
->clientdata
);
706 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->collapsed
;
713 toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
716 assert(entry
->clientdata
!=NULL
);
718 dock
= (WDock
*) entry
->clientdata
;
720 dock
->auto_collapse
= !dock
->auto_collapse
;
722 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_collapse
;
729 toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
732 assert(entry
->clientdata
!=NULL
);
734 dock
= (WDock
*) entry
->clientdata
;
736 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
738 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_raise_lower
;
745 launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
747 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
749 launchDockedApplication(btn
);
754 settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
756 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
760 ShowDockAppSettingsPanel(btn
);
765 hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
768 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
770 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
772 if (wapp
->flags
.hidden
) {
773 wWorkspaceChange(btn
->icon
->core
->screen_ptr
,wapp
->last_workspace
);
774 wUnhideApplication(wapp
, False
, False
);
776 wHideApplication(wapp
);
782 unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
785 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
787 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
789 wUnhideApplication(wapp
, False
, True
);
794 mainIconCreate(WScreen
*scr
, int type
)
799 if (type
== WM_CLIP
) {
801 return scr
->clip_icon
;
802 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
803 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
804 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
805 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
806 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE;*/
809 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
810 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
816 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
817 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
818 btn
->icon
->core
->descriptor
.parent
= btn
;
819 /*ChangeStackingLevel(btn->icon->core, WMDockLevel);*/
820 XMapWindow(dpy
, btn
->icon
->core
->window
);
825 scr
->clip_icon
= btn
;
832 switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
834 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
835 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
837 LinkedList
*selectedIcons
;
840 if (entry
->order
== scr
->current_workspace
)
843 dest
= scr
->workspaces
[entry
->order
]->clip
;
845 selectedIcons
= getSelected(src
);
848 while(selectedIcons
) {
849 btn
= selectedIcons
->head
;
850 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
851 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
852 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
854 list_remove_head(&selectedIcons
);
856 } else if (icon
!= scr
->clip_icon
) {
857 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
858 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
859 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
867 launchDockedApplication(WAppIcon
*btn
)
869 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
871 if (!btn
->launching
&& btn
->command
!=NULL
) {
872 if (!btn
->forced_dock
) {
873 btn
->relaunching
= btn
->running
;
876 if (btn
->wm_instance
|| btn
->wm_class
) {
877 WWindowAttributes attr
;
878 memset(&attr
, 0, sizeof(WWindowAttributes
));
879 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
,
882 if (!attr
.no_appicon
&& !btn
->buggy_app
)
887 btn
->drop_launch
= 0;
888 scr
->last_dock
= btn
->dock
;
889 btn
->pid
= execCommand(btn
, btn
->command
, NULL
);
891 if (btn
->buggy_app
) {
892 /* give feedback that the app was launched */
896 WMAddTimerHandler(200, (WMCallback
*)dockIconPaint
, btn
);
901 wwarning(_("could not launch application %s\n"), btn
->command
);
903 if (!btn
->relaunching
)
912 updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
914 WScreen
*scr
= menu
->frame
->screen_ptr
;
915 char title
[MAX_WORKSPACENAME_WIDTH
+1];
921 for (i
=0; i
<scr
->workspace_count
; i
++) {
922 if (i
< menu
->entry_no
) {
923 if (strcmp(menu
->entries
[i
]->text
,scr
->workspaces
[i
]->name
)!=0) {
924 free(menu
->entries
[i
]->text
);
925 strcpy(title
, scr
->workspaces
[i
]->name
);
926 menu
->entries
[i
]->text
= wstrdup(title
);
927 menu
->flags
.realized
= 0;
929 menu
->entries
[i
]->clientdata
= (void*)icon
;
931 strcpy(title
, scr
->workspaces
[i
]->name
);
933 wMenuAddCallback(menu
, title
, switchWSCommand
, (void*)icon
);
935 menu
->flags
.realized
= 0;
937 if (i
== scr
->current_workspace
) {
938 wMenuSetEnabled(menu
, i
, False
);
940 wMenuSetEnabled(menu
, i
, True
);
944 if (!menu
->flags
.realized
)
950 makeWorkspaceMenu(WScreen
*scr
)
954 menu
= wMenuCreate(scr
, NULL
, False
);
956 wwarning(_("could not create workspace submenu for Clip menu"));
958 wMenuAddCallback(menu
, "", switchWSCommand
, (void*)scr
->clip_icon
);
960 menu
->flags
.realized
= 0;
968 updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
977 entry
= menu
->entries
[index
];
978 entry
->flags
.indicator_on
= !dock
->lowered
;
979 entry
->clientdata
= dock
;
982 entry
= menu
->entries
[++index
];
983 entry
->flags
.indicator_on
= dock
->collapsed
;
984 entry
->clientdata
= dock
;
987 entry
= menu
->entries
[++index
];
988 entry
->flags
.indicator_on
= dock
->auto_collapse
;
989 entry
->clientdata
= dock
;
991 /* auto-raise/lower */
992 entry
= menu
->entries
[++index
];
993 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
994 entry
->clientdata
= dock
;
997 entry
= menu
->entries
[++index
];
998 entry
->flags
.indicator_on
= dock
->attract_icons
;
999 entry
->clientdata
= dock
;
1001 /* keep attracted icons */
1002 entry
= menu
->entries
[++index
];
1003 entry
->flags
.indicator_on
= dock
->keep_attracted
;
1004 entry
->clientdata
= dock
;
1006 menu
->flags
.realized
= 0;
1012 makeClipOptionsMenu(WScreen
*scr
)
1017 menu
= wMenuCreate(scr
, NULL
, False
);
1019 wwarning(_("could not create options submenu for Clip menu"));
1023 entry
= wMenuAddCallback(menu
, _("Keep on top"),
1024 toggleLoweredCallback
, NULL
);
1025 entry
->flags
.indicator
= 1;
1026 entry
->flags
.indicator_on
= 1;
1027 entry
->flags
.indicator_type
= MI_CHECK
;
1029 entry
= wMenuAddCallback(menu
, _("Collapsed"),
1030 toggleCollapsedCallback
, NULL
);
1031 entry
->flags
.indicator
= 1;
1032 entry
->flags
.indicator_on
= 1;
1033 entry
->flags
.indicator_type
= MI_CHECK
;
1035 entry
= wMenuAddCallback(menu
, _("AutoCollapse"),
1036 toggleAutoCollapseCallback
, NULL
);
1037 entry
->flags
.indicator
= 1;
1038 entry
->flags
.indicator_on
= 1;
1039 entry
->flags
.indicator_type
= MI_CHECK
;
1041 entry
= wMenuAddCallback(menu
, _("AutoRaiseLower"),
1042 toggleAutoRaiseLowerCallback
, NULL
);
1043 entry
->flags
.indicator
= 1;
1044 entry
->flags
.indicator_on
= 1;
1045 entry
->flags
.indicator_type
= MI_CHECK
;
1047 entry
= wMenuAddCallback(menu
, _("AutoAttract Icons"),
1048 toggleAutoAttractCallback
, NULL
);
1049 entry
->flags
.indicator
= 1;
1050 entry
->flags
.indicator_on
= 1;
1051 entry
->flags
.indicator_type
= MI_CHECK
;
1053 entry
= wMenuAddCallback(menu
, _("Keep Attracted Icons"),
1054 toggleKeepCallback
, NULL
);
1055 entry
->flags
.indicator
= 1;
1056 entry
->flags
.indicator_on
= 1;
1057 entry
->flags
.indicator_type
= MI_CHECK
;
1059 menu
->flags
.realized
= 0;
1067 dockMenuCreate(WScreen
*scr
, int type
)
1072 if (type
== WM_CLIP
&& scr
->clip_menu
)
1073 return scr
->clip_menu
;
1075 menu
= wMenuCreate(scr
, NULL
, False
);
1076 if (type
!= WM_CLIP
) {
1077 entry
= wMenuAddCallback(menu
, _("Keep on top"),
1078 toggleLoweredCallback
, NULL
);
1079 entry
->flags
.indicator
= 1;
1080 entry
->flags
.indicator_on
= 1;
1081 entry
->flags
.indicator_type
= MI_CHECK
;
1083 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1084 scr
->clip_options
= makeClipOptionsMenu(scr
);
1085 if (scr
->clip_options
)
1086 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1088 wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1090 wMenuAddCallback(menu
, _("(Un)Select Icon"), selectCallback
, NULL
);
1092 wMenuAddCallback(menu
, _("(Un)Select All Icons"), selectIconsCallback
,
1095 wMenuAddCallback(menu
, _("Keep Icon(s)"), keepIconsCallback
, NULL
);
1097 entry
= wMenuAddCallback(menu
, _("Move Icon(s) To"), NULL
, NULL
);
1098 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1099 if (scr
->clip_submenu
)
1100 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1102 wMenuAddCallback(menu
, _("Remove Icon(s)"), removeIconsCallback
, NULL
);
1104 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1107 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1109 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1111 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1113 entry
->text
= _("Hide");
1115 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1117 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1119 if (type
== WM_CLIP
)
1120 scr
->clip_menu
= menu
;
1127 wDockCreate(WScreen
*scr
, int type
)
1135 dock
= wmalloc(sizeof(WDock
));
1136 memset(dock
, 0, sizeof(WDock
));
1138 if (type
== WM_CLIP
)
1139 icon_count
= CLIP_MAX_ICONS
;
1141 icon_count
= scr
->scr_height
/wPreferences
.icon_size
;
1143 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*)*icon_count
);
1144 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*)*icon_count
);
1146 dock
->max_icons
= icon_count
;
1148 btn
= mainIconCreate(scr
, type
);
1152 dock
->x_pos
= btn
->x_pos
;
1153 dock
->y_pos
= btn
->y_pos
;
1154 dock
->screen_ptr
= scr
;
1156 dock
->icon_count
= 1;
1157 dock
->on_right_side
= 1;
1158 dock
->collapsed
= 0;
1159 dock
->auto_collapse
= 0;
1160 dock
->auto_collapse_magic
= NULL
;
1161 dock
->auto_raise_lower
= 0;
1162 dock
->auto_lower_magic
= NULL
;
1163 dock
->auto_raise_magic
= NULL
;
1164 dock
->attract_icons
= 0;
1165 dock
->keep_attracted
= 0;
1167 dock
->icon_array
[0] = btn
;
1168 wRaiseFrame(btn
->icon
->core
);
1169 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1171 /* create dock menu */
1172 dock
->menu
= dockMenuCreate(scr
, type
);
1179 wDockDestroy(WDock
*dock
)
1184 for (i
=(dock
->type
== WM_CLIP
) ? 1 : 0; i
<dock
->max_icons
; i
++) {
1185 aicon
= dock
->icon_array
[i
];
1187 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1188 wDockDetach(dock
, aicon
);
1190 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
1191 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
1192 aicon
->x_pos
, aicon
->y_pos
);
1193 if (!dock
->mapped
|| dock
->collapsed
)
1194 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1198 if (wPreferences
.auto_arrange_icons
)
1199 wArrangeIcons(dock
->screen_ptr
, True
);
1200 free(dock
->icon_array
);
1201 if (dock
->menu
&& dock
->type
!=WM_CLIP
)
1202 wMenuDestroy(dock
->menu
, True
);
1208 wClipIconPaint(WAppIcon
*aicon
)
1210 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1211 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1213 Window win
= aicon
->icon
->core
->window
;
1214 int length
, nlength
;
1215 char *ws_name
, ws_number
[10];
1218 wIconPaint(aicon
->icon
);
1220 length
= strlen(workspace
->name
);
1221 ws_name
= malloc(length
+ 1);
1222 sprintf(ws_name
, "%s", workspace
->name
);
1223 sprintf(ws_number
, "%i", scr
->current_workspace
+ 1);
1224 nlength
= strlen(ws_number
);
1226 gc
= scr
->clip_title_gc
;
1228 if (!workspace
->clip
->collapsed
)
1229 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_NORMAL
]);
1231 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_COLLAPSED
]);
1233 ty
= ICON_SIZE
- scr
->clip_title_font
->height
- 3;
1235 tx
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
1237 wDrawString(win
, scr
->clip_title_font
, gc
, tx
,
1238 ty
+ scr
->clip_title_font
->y
, ws_name
, length
);
1240 tx
= (ICON_SIZE
/2 - wTextWidth(scr
->clip_title_font
->font
, ws_number
, nlength
))/2;
1242 wDrawString(win
, scr
->clip_title_font
, gc
, tx
,
1243 scr
->clip_title_font
->y
+ 2, ws_number
, nlength
);
1247 if (aicon
->launching
) {
1248 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1249 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1251 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
,
1252 aicon
->dock
->rclip_button_pushed
);
1257 clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1259 wClipIconPaint(desc
->parent
);
1264 dockIconPaint(WAppIcon
*btn
)
1266 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1267 wClipIconPaint(btn
);
1274 make_icon_state(WAppIcon
*btn
)
1276 proplist_t node
= NULL
;
1277 proplist_t command
, autolaunch
, name
, forced
, host
, position
, buggy
;
1283 command
= PLMakeString("-");
1285 command
= PLMakeString(btn
->command
);
1287 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1289 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1291 name
= PLMakeString(tmp
);
1295 forced
= btn
->forced_dock
? dYes
: dNo
;
1297 buggy
= btn
->buggy_app
? dYes
: dNo
;
1299 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1300 sprintf(buffer
, "%i,%i", btn
->x_pos
, btn
->y_pos
);
1302 sprintf(buffer
, "%hi,%hi", btn
->xindex
, btn
->yindex
);
1303 position
= PLMakeString(buffer
);
1305 node
= PLMakeDictionaryFromEntries(dCommand
, command
,
1307 dAutoLaunch
, autolaunch
,
1309 dBuggyApplication
, buggy
,
1310 dPosition
, position
,
1314 PLRelease(position
);
1316 if (btn
->dnd_command
) {
1317 command
= PLMakeString(btn
->dnd_command
);
1318 PLInsertDictionaryEntry(node
, dDropCommand
, command
);
1321 #endif /* OFFIX_DND */
1323 if (btn
->client_machine
&& btn
->remote_start
) {
1324 host
= PLMakeString(btn
->client_machine
);
1325 PLInsertDictionaryEntry(node
, dHost
, host
);
1335 dockSaveState(WDock
*dock
)
1338 proplist_t icon_info
;
1339 proplist_t list
=NULL
, dock_state
=NULL
;
1343 list
= PLMakeArrayFromElements(NULL
);
1345 for (i
=(dock
->type
==WM_DOCK
? 0 : 1); i
<dock
->max_icons
; i
++) {
1346 WAppIcon
*btn
= dock
->icon_array
[i
];
1348 if (!btn
|| (btn
->attracted
&& !dock
->keep_attracted
))
1351 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1352 list
= PLAppendArrayElement(list
, icon_info
);
1353 PLRelease(icon_info
);
1357 dock_state
= PLMakeDictionaryFromEntries(dApplications
, list
, NULL
);
1361 if (dock
->type
== WM_DOCK
) {
1362 sprintf(buffer
, "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0),
1364 value
= PLMakeString(buffer
);
1365 PLInsertDictionaryEntry(dock_state
, dPosition
, value
);
1369 value
= (dock
->lowered
? dYes
: dNo
);
1370 PLInsertDictionaryEntry(dock_state
, dLowered
, value
);
1372 if (dock
->type
== WM_CLIP
) {
1373 value
= (dock
->collapsed
? dYes
: dNo
);
1374 PLInsertDictionaryEntry(dock_state
, dCollapsed
, value
);
1376 value
= (dock
->auto_collapse
? dYes
: dNo
);
1377 PLInsertDictionaryEntry(dock_state
, dAutoCollapse
, value
);
1379 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1380 PLInsertDictionaryEntry(dock_state
, dAutoRaiseLower
, value
);
1382 value
= (dock
->attract_icons
? dYes
: dNo
);
1383 PLInsertDictionaryEntry(dock_state
, dAutoAttractIcons
, value
);
1385 value
= (dock
->keep_attracted
? dYes
: dNo
);
1386 PLInsertDictionaryEntry(dock_state
, dKeepAttracted
, value
);
1394 wDockSaveState(WScreen
*scr
)
1396 proplist_t dock_state
;
1398 dock_state
= dockSaveState(scr
->dock
);
1400 PLInsertDictionaryEntry(scr
->session_state
, dDock
, dock_state
);
1402 PLRelease(dock_state
);
1407 wClipSaveState(WScreen
*scr
)
1409 proplist_t clip_state
;
1411 clip_state
= make_icon_state(scr
->clip_icon
);
1413 PLInsertDictionaryEntry(scr
->session_state
, dClip
, clip_state
);
1415 PLRelease(clip_state
);
1420 wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1422 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1427 restore_icon_state(WScreen
*scr
, proplist_t info
, int type
, int index
)
1430 char *wclass
, *winstance
;
1431 proplist_t cmd
, value
;
1435 cmd
= PLGetDictionaryEntry(info
, dCommand
);
1436 if (!cmd
|| !PLIsString(cmd
)) {
1440 /* parse window name */
1441 value
= PLGetDictionaryEntry(info
, dName
);
1445 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1447 if (!winstance
&& !wclass
) {
1454 command
= wstrdup(PLGetString(cmd
));
1458 if (!command
|| strcmp(command
, "-")==0) {
1469 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
,
1476 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1477 if (type
== WM_CLIP
) {
1478 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1479 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1481 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1482 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1486 cmd
= PLGetDictionaryEntry(info
, dDropCommand
);
1488 aicon
->dnd_command
= wstrdup(PLGetString(cmd
));
1491 /* check auto launch */
1492 value
= PLGetDictionaryEntry(info
, dAutoLaunch
);
1494 aicon
->auto_launch
= 0;
1496 if (PLIsString(value
)) {
1497 if (strcasecmp(PLGetString(value
), "YES")==0)
1498 aicon
->auto_launch
= 1;
1500 wwarning(_("bad value in docked icon state info %s"),
1501 PLGetString(dAutoLaunch
));
1505 /* check if it wasn't normally docked */
1506 value
= PLGetDictionaryEntry(info
, dForced
);
1508 aicon
->forced_dock
= 0;
1510 if (PLIsString(value
)) {
1511 if (strcasecmp(PLGetString(value
), "YES")==0)
1512 aicon
->forced_dock
= 1;
1514 wwarning(_("bad value in docked icon state info %s"),
1515 PLGetString(dForced
));
1519 /* check if we can rely on the stuff in the app */
1520 value
= PLGetDictionaryEntry(info
, dBuggyApplication
);
1522 aicon
->buggy_app
= 0;
1524 if (PLIsString(value
)) {
1525 if (strcasecmp(PLGetString(value
), "YES")==0)
1526 aicon
->buggy_app
= 1;
1528 wwarning(_("bad value in docked icon state info %s"),
1529 PLGetString(dBuggyApplication
));
1533 /* get position in the dock */
1534 value
= PLGetDictionaryEntry(info
, dPosition
);
1535 if (value
&& PLIsString(value
)) {
1536 if (sscanf(PLGetString(value
), "%hi,%hi", &aicon
->xindex
,
1538 wwarning(_("bad value in docked icon state info %s"),
1539 PLGetString(dPosition
));
1541 /* check position sanity */
1542 /* incomplete section! */
1543 if (type
== WM_DOCK
) {
1545 if (aicon
->yindex
< 0)
1546 wwarning(_("bad value in docked icon position %i,%i"),
1547 aicon
->xindex
, aicon
->yindex
);
1550 aicon
->yindex
= index
;
1561 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1565 wClipRestoreState(WScreen
*scr
, proplist_t clip_state
)
1571 icon
= mainIconCreate(scr
, WM_CLIP
);
1576 PLRetain(clip_state
);
1578 /* restore position */
1580 value
= PLGetDictionaryEntry(clip_state
, dPosition
);
1583 if (!PLIsString(value
))
1584 COMPLAIN("Position");
1586 if (sscanf(PLGetString(value
), "%i,%i", &icon
->x_pos
,
1588 COMPLAIN("Position");
1590 /* check position sanity */
1591 if (icon
->y_pos
< 0)
1593 else if (icon
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1594 icon
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1596 if (icon
->x_pos
< 0)
1598 else if (icon
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1599 icon
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1604 value
= PLGetDictionaryEntry(clip_state
, dDropCommand
);
1605 if (value
&& PLIsString(value
))
1606 icon
->dnd_command
= wstrdup(PLGetString(value
));
1609 PLRelease(clip_state
);
1616 wDockRestoreState(WScreen
*scr
, proplist_t dock_state
, int type
)
1621 WAppIcon
*aicon
, *old_top
;
1625 dock
= wDockCreate(scr
, type
);
1631 PLRetain(dock_state
);
1634 /* restore position */
1636 value
= PLGetDictionaryEntry(dock_state
, dPosition
);
1639 if (!PLIsString(value
))
1640 COMPLAIN("Position");
1642 if (sscanf(PLGetString(value
), "%i,%i", &dock
->x_pos
,
1644 COMPLAIN("Position");
1646 /* check position sanity */
1647 if (dock
->y_pos
< 0)
1649 else if (dock
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1650 dock
->y_pos
= scr
->scr_height
- ICON_SIZE
;
1652 /* This is no more needed. ??? */
1653 if (type
== WM_CLIP
) {
1654 if (dock
->x_pos
< 0)
1656 else if (dock
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1657 dock
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1659 if (dock
->x_pos
>= 0) {
1660 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1661 dock
->on_right_side
= 0;
1663 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1664 dock
->on_right_side
= 1;
1670 /* restore lowered/raised state */
1674 value
= PLGetDictionaryEntry(dock_state
, dLowered
);
1677 if (!PLIsString(value
))
1678 COMPLAIN("Lowered");
1680 if (strcasecmp(PLGetString(value
), "YES")==0)
1686 /* restore collapsed state */
1688 dock
->collapsed
= 0;
1690 value
= PLGetDictionaryEntry(dock_state
, dCollapsed
);
1693 if (!PLIsString(value
))
1694 COMPLAIN("Collapsed");
1696 if (strcasecmp(PLGetString(value
), "YES")==0)
1697 dock
->collapsed
= 1;
1702 /* restore auto-collapsed state */
1704 value
= PLGetDictionaryEntry(dock_state
, dAutoCollapse
);
1707 if (!PLIsString(value
))
1708 COMPLAIN("AutoCollapse");
1710 if (strcasecmp(PLGetString(value
), "YES")==0) {
1711 dock
->auto_collapse
= 1;
1712 dock
->collapsed
= 1;
1718 /* restore auto-raise/lower state */
1720 value
= PLGetDictionaryEntry(dock_state
, dAutoRaiseLower
);
1723 if (!PLIsString(value
))
1724 COMPLAIN("AutoRaiseLower");
1726 if (strcasecmp(PLGetString(value
), "YES")==0) {
1727 dock
->auto_raise_lower
= 1;
1733 /* restore attract icons state */
1735 dock
->attract_icons
= 0;
1737 value
= PLGetDictionaryEntry(dock_state
, dAutoAttractIcons
);
1740 if (!PLIsString(value
))
1741 COMPLAIN("AutoAttractIcons");
1743 if (strcasecmp(PLGetString(value
), "YES")==0)
1744 dock
->attract_icons
= 1;
1749 /* restore keep attracted icons state */
1751 dock
->keep_attracted
= 0;
1753 value
= PLGetDictionaryEntry(dock_state
, dKeepAttracted
);
1756 if (!PLIsString(value
))
1757 COMPLAIN("KeepAttracted");
1759 if (strcasecmp(PLGetString(value
), "YES")==0)
1760 dock
->keep_attracted
= 1;
1765 /* application list */
1767 apps
= PLGetDictionaryEntry(dock_state
, dApplications
);
1773 count
= PLGetNumberOfElements(apps
);
1778 old_top
= dock
->icon_array
[0];
1780 /* dock->icon_count is set to 1 when dock is created.
1781 * Since Clip is already restored, we want to keep it so for clip,
1782 * but for dock we may change the default top tile, so we set it to 0.
1784 if (type
== WM_DOCK
)
1785 dock
->icon_count
= 0;
1787 for (i
=0; i
<count
; i
++) {
1788 if (dock
->icon_count
>= dock
->max_icons
) {
1789 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1793 value
= PLGetArrayElement(apps
, i
);
1794 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1796 dock
->icon_array
[dock
->icon_count
] = aicon
;
1800 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
*ICON_SIZE
);
1801 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
*ICON_SIZE
);
1804 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1806 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1808 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
,
1811 if (!dock
->collapsed
)
1812 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1813 wRaiseFrame(aicon
->icon
->core
);
1816 } else if (dock
->icon_count
==0 && type
==WM_DOCK
)
1820 /* if the first icon is not defined, use the default */
1821 if (dock
->icon_array
[0]==NULL
) {
1822 /* update default icon */
1823 old_top
->x_pos
= dock
->x_pos
;
1824 old_top
->y_pos
= dock
->y_pos
;
1826 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1828 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1829 dock
->icon_array
[0] = old_top
;
1830 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1831 /* we don't need to increment dock->icon_count here because it was
1832 * incremented in the loop above.
1834 } else if (old_top
!=dock
->icon_array
[0]) {
1835 if (old_top
== scr
->clip_icon
)
1836 scr
->clip_icon
= dock
->icon_array
[0];
1837 wAppIconDestroy(old_top
);
1842 PLRelease(dock_state
);
1850 wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1852 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1854 btn
->drop_launch
= 0;
1856 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1859 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1871 wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1877 for (i
= 0; i
< dock
->max_icons
; i
++) {
1878 btn
= dock
->icon_array
[i
];
1879 if (!btn
|| !btn
->auto_launch
)
1882 state
= wmalloc(sizeof(WSavedState
));
1883 memset(state
, 0, sizeof(WSavedState
));
1884 state
->workspace
= workspace
;
1885 /* TODO: this is klugy and is very difficult to understand
1886 * what's going on. Try to clean up */
1887 wDockLaunchWithState(dock
, btn
, state
);
1891 #ifdef REDUCE_APPICONS
1893 wDockSimulateLaunch(WDock
*dock
, WAppIcon
*btn
)
1895 if ((btn
== NULL
) || (dock
== NULL
))
1898 if (!btn
->running
) {
1899 if ((btn
->icon
->owner
== NULL
) && (btn
->applist
))
1900 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
1901 if (!btn
->forced_dock
)
1911 findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1917 if ((dock
= scr
->dock
)!=NULL
) {
1918 for (i
=0; i
<dock
->max_icons
; i
++) {
1919 if (dock
->icon_array
[i
]
1920 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1926 if (*icon_pos
<0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
)!=NULL
) {
1927 for (i
=0; i
<dock
->max_icons
; i
++) {
1928 if (dock
->icon_array
[i
]
1929 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1942 wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
1948 dock
= findDock(scr
, event
, &icon_pos
);
1953 * Return True if the drop was on an application icon window.
1954 * In this case, let the ClientMessage handler redirect the
1955 * message to the app.
1957 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!=None
)
1960 if (dock
->icon_array
[icon_pos
]->dnd_command
!=NULL
) {
1961 scr
->flags
.dnd_data_convertion_status
= 0;
1963 btn
= dock
->icon_array
[icon_pos
];
1965 if (!btn
->forced_dock
) {
1966 btn
->relaunching
= btn
->running
;
1969 if (btn
->wm_instance
|| btn
->wm_class
) {
1970 WWindowAttributes attr
;
1971 memset(&attr
, 0, sizeof(WWindowAttributes
));
1972 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
1974 btn
->wm_class
, &attr
, NULL
, True
);
1976 if (!attr
.no_appicon
)
1982 btn
->drop_launch
= 1;
1983 scr
->last_dock
= dock
;
1984 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1989 if (!btn
->relaunching
) {
1996 #endif /* OFFIX_DND */
2001 wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2008 wwin
= icon
->icon
->owner
;
2009 if (icon
->command
==NULL
) {
2011 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2013 icon
->command
= FlattenStringList(argv
, argc
);
2014 XFreeStringList(argv
);
2018 /* icon->forced_dock = 1;*/
2019 if (!icon
->attracted
|| dock
->type
!=WM_CLIP
|| dock
->keep_attracted
) {
2021 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2022 _("Type the command used to launch the application"),
2024 if (command
&& (command
[0]==0 ||
2025 (command
[0]=='-' && command
[1]==0))) {
2029 icon
->command
= command
;
2035 /* If the target is the dock, reject the icon. If
2036 * the target is the clip, make it an attracted icon
2038 if (dock
->type
==WM_CLIP
) {
2039 icon
->attracted
= 1;
2040 if (!icon
->icon
->shadowed
) {
2041 icon
->icon
->shadowed
= 1;
2042 icon
->icon
->force_paint
= 1;
2054 for (index
=1; index
<dock
->max_icons
; index
++)
2055 if (dock
->icon_array
[index
] == NULL
)
2057 /* if (index == dock->max_icons)
2060 assert(index
< dock
->max_icons
);
2062 dock
->icon_array
[index
] = icon
;
2066 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2067 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2072 icon
->launching
= 0;
2075 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2076 if (dock
->type
== WM_CLIP
) {
2077 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2078 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2080 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2081 icon
->icon
->core
->descriptor
.parent
= icon
;
2083 MoveInStackListUnder(dock
->icon_array
[index
-1]->icon
->core
,
2085 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2086 wAppIconPaint(icon
);
2088 if (wPreferences
.auto_arrange_icons
)
2089 wArrangeIcons(dock
->screen_ptr
, True
);
2092 if (icon
->command
&& !icon
->dnd_command
) {
2093 icon
->dnd_command
= wmalloc(strlen(icon
->command
)+8);
2094 sprintf(icon
->dnd_command
, "%s %%d", icon
->command
);
2103 reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2107 for(index
=1; index
<dock
->max_icons
; index
++) {
2108 if(dock
->icon_array
[index
] == icon
)
2111 assert(index
< dock
->max_icons
);
2116 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2117 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2122 moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2132 wwin
= icon
->icon
->owner
;
2135 * For the moment we can't do this if we move icons in Clip from one
2136 * workspace to other, because if we move two or more icons without
2137 * command, the dialog box will not be able to tell us to which of the
2138 * moved icons it applies. -Dan
2140 if ((dest
->type
==WM_DOCK
/*|| dest->keep_attracted*/) && icon
->command
==NULL
) {
2141 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2143 icon
->command
= FlattenStringList(argv
, argc
);
2144 XFreeStringList(argv
);
2149 /* icon->forced_dock = 1;*/
2150 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2151 _("Type the command used to launch the application"),
2153 if (command
&& (command
[0]==0 ||
2154 (command
[0]=='-' && command
[1]==0))) {
2158 icon
->command
= command
;
2169 for(index
=1; index
<src
->max_icons
; index
++) {
2170 if(src
->icon_array
[index
] == icon
)
2173 assert(index
< src
->max_icons
);
2175 src
->icon_array
[index
] = NULL
;
2178 for(index
=1; index
<dest
->max_icons
; index
++) {
2179 if(dest
->icon_array
[index
] == NULL
)
2182 /* if (index == dest->max_icons)
2185 assert(index
< dest
->max_icons
);
2187 dest
->icon_array
[index
] = icon
;
2190 /* deselect the icon */
2191 if (icon
->icon
->selected
)
2192 wIconSelect(icon
->icon
);
2194 if (dest
->type
== WM_DOCK
) {
2195 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2196 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2198 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2199 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2202 /* set it to be kept when moving to dock, or to a clip that keep the
2204 * Unless the icon does not have a command set
2206 if (icon
->command
&& (dest
->type
==WM_DOCK
|| dest
->keep_attracted
)) {
2207 icon
->attracted
= 0;
2208 if (icon
->icon
->shadowed
) {
2209 icon
->icon
->shadowed
= 0;
2210 icon
->icon
->force_paint
= 1;
2214 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2220 icon
->x_pos
= dest
->x_pos
+ x
*ICON_SIZE
;
2221 icon
->y_pos
= dest
->y_pos
+ y
*ICON_SIZE
;
2225 MoveInStackListUnder(dest
->icon_array
[index
-1]->icon
->core
,
2227 wAppIconPaint(icon
);
2234 wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2238 /* make the settings panel be closed */
2240 DestroyDockAppSettingsPanel(icon
->panel
);
2245 icon
->attracted
= 0;
2246 if (icon
->icon
->shadowed
) {
2247 icon
->icon
->shadowed
= 0;
2248 icon
->icon
->force_paint
= 1;
2251 /* deselect the icon */
2252 if (icon
->icon
->selected
)
2253 wIconSelect(icon
->icon
);
2255 if (icon
->command
) {
2256 free(icon
->command
);
2257 icon
->command
= NULL
;
2260 if (icon
->dnd_command
) {
2261 free(icon
->dnd_command
);
2262 icon
->dnd_command
= NULL
;
2266 for (index
=1; index
<dock
->max_icons
; index
++)
2267 if (dock
->icon_array
[index
] == icon
)
2269 assert(index
< dock
->max_icons
);
2270 dock
->icon_array
[index
] = NULL
;
2275 /* if the dock is not attached to an application or
2276 * the the application did not set the approriate hints yet,
2277 * destroy the icon */
2278 #ifdef REDUCE_APPICONS
2279 if ((icon
->num_apps
== 0) && (!icon
->running
|| !wApplicationOf(icon
->main_window
)) )
2281 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2283 wAppIconDestroy(icon
);
2285 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2286 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2287 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2288 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2289 icon
->icon
->core
->descriptor
.parent
= icon
;
2291 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2293 wAppIconPaint(icon
);
2294 if (wPreferences
.auto_arrange_icons
) {
2295 wArrangeIcons(dock
->screen_ptr
, True
);
2298 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2304 * returns the closest Dock slot index for the passed
2307 * Returns False if icon can't be docked.
2310 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2311 int *ret_x
, int *ret_y
, int redocking
)
2313 WScreen
*scr
= dock
->screen_ptr
;
2316 int i
, offset
= ICON_SIZE
/2;
2317 WAppIcon
*aicon
= NULL
;
2318 WAppIcon
*nicon
= NULL
;
2319 int max_y_icons
, max_x_icons
;
2321 max_x_icons
= scr
->scr_width
/ICON_SIZE
;
2322 max_y_icons
= scr
->scr_height
/ICON_SIZE
-1;
2324 if (wPreferences
.flags
.noupdates
)
2330 /* if the dock is full */
2332 (dock
->icon_count
>= dock
->max_icons
)) {
2336 /* exact position */
2338 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2340 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2343 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2345 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2347 /* check if the icon is outside the screen boundaries */
2348 if (dx
+ ex_x
*ICON_SIZE
< -ICON_SIZE
+2 ||
2349 dx
+ ex_x
*ICON_SIZE
>= scr
->scr_width
-1 ||
2350 dy
+ ex_y
*ICON_SIZE
< -ICON_SIZE
+2 ||
2351 dy
+ ex_y
*ICON_SIZE
>= scr
->scr_height
-1)
2354 if (dock
->type
== WM_DOCK
) {
2355 if (icon
->dock
!= dock
&& ex_x
!= 0)
2358 for (i
=0; i
<dock
->max_icons
; i
++) {
2359 nicon
= dock
->icon_array
[i
];
2360 if (nicon
&& nicon
->yindex
== ex_y
) {
2369 int sig
, done
, closest
;
2371 /* Possible cases when redocking:
2373 * icon dragged out of range of any slot -> false
2374 * icon dragged to range of free slot
2375 * icon dragged to range of same slot
2376 * icon dragged to range of different icon
2378 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2381 if (ex_y
>= 0 && ex_y
<= max_y_icons
&& (aicon
== icon
|| !aicon
)) {
2389 /* start looking at the upper slot or lower? */
2390 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2397 /* look for closest free slot */
2398 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2402 closest
= sig
*(i
/2) + ex_y
;
2403 /* check if this slot is used */
2405 for (j
= 0; j
<dock
->max_icons
; j
++) {
2406 if (dock
->icon_array
[j
]
2407 && dock
->icon_array
[j
]->yindex
==closest
) {
2408 /* slot is used by someone else */
2409 if (dock
->icon_array
[j
]!=icon
)
2417 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2418 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2420 (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+1))) {
2426 } else { /* !redocking */
2428 /* if slot is free and the icon is close enough, return it */
2429 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2437 for (i
=0; i
<dock
->max_icons
; i
++) {
2438 nicon
= dock
->icon_array
[i
];
2439 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2445 for (i
=0; i
<dock
->max_icons
; i
++) {
2446 nicon
= dock
->icon_array
[i
];
2447 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2448 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2449 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2455 if (neighbours
&& (aicon
==NULL
|| (redocking
&& aicon
== icon
))) {
2464 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2465 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2467 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2468 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2469 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2473 * returns true if it can find a free slot in the dock,
2474 * in which case it changes x_pos and y_pos accordingly.
2475 * Else returns false.
2478 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2480 WScreen
*scr
= dock
->screen_ptr
;
2482 unsigned char *slot_map
;
2486 int i
, done
= False
;
2488 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2491 /* if the dock is full */
2492 if (dock
->icon_count
>= dock
->max_icons
) {
2496 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2497 if (scr
->dock
->on_right_side
)
2498 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2500 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2503 if (ex
< dock
->x_pos
)
2505 if (sx
> dock
->x_pos
+ICON_SIZE
)
2506 sx
= dock
->x_pos
+ICON_SIZE
;
2513 /* check if clip is in a corner */
2514 if (dock
->type
==WM_CLIP
) {
2515 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2517 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2519 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2521 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2528 /* If the clip is in the corner, use only slots that are in the border
2530 if (corner
!=C_NONE
) {
2534 hcount
= MIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2535 vcount
= MIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2536 hmap
= wmalloc(hcount
+1);
2537 memset(hmap
, 0, hcount
+1);
2538 vmap
= wmalloc(vcount
+1);
2539 memset(vmap
, 0, vcount
+1);
2541 /* mark used positions */
2544 for (i
=0; i
<dock
->max_icons
; i
++) {
2545 btn
= dock
->icon_array
[i
];
2549 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2550 vmap
[btn
->yindex
] = 1;
2551 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2552 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;
2566 for (i
=0; i
<dock
->max_icons
; i
++) {
2567 btn
= dock
->icon_array
[i
];
2571 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2572 vmap
[-btn
->yindex
] = 1;
2573 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2574 hmap
[btn
->xindex
] = 1;
2578 for (i
=0; i
<dock
->max_icons
; i
++) {
2579 btn
= dock
->icon_array
[i
];
2583 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2584 vmap
[-btn
->yindex
] = 1;
2585 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2586 hmap
[-btn
->xindex
] = 1;
2591 /* search a vacant slot */
2592 for (i
=1; i
<MAX(vcount
, hcount
); i
++) {
2593 if (i
< vcount
&& vmap
[i
]==0) {
2599 } else if (i
< hcount
&& hmap
[i
]==0) {
2609 /* If found a slot, translate and return */
2611 if (corner
==C_NW
|| corner
==C_NE
) {
2616 if (corner
==C_NE
|| corner
==C_SE
) {
2623 /* else, try to find a slot somewhere else */
2626 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2627 * placed outside of screen */
2628 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2630 /* In the worst case (the clip is in the corner of the screen),
2631 * the amount of icons that fit in the clip is smaller.
2632 * Double the map to get a safe value.
2638 slot_map
= wmalloc(mwidth
*mwidth
);
2639 memset(slot_map
, 0, mwidth
*mwidth
);
2641 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2643 /* mark used slots in the map. If the slot falls outside the map
2644 * (for example, when all icons are placed in line), ignore them. */
2645 for (i
=0; i
<dock
->max_icons
; i
++) {
2646 btn
= dock
->icon_array
[i
];
2648 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2650 /* Find closest slot from the center that is free by scanning the
2651 * map from the center to outward in circular passes.
2652 * This will not result in a neat layout, but will be optimal
2653 * in the sense that there will not be holes left.
2656 for (i
= 1; i
<= r
&& !done
; i
++) {
2659 /* top and bottom parts of the ring */
2660 for (x
= -i
; x
<= i
&& !done
; x
++) {
2661 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2663 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2664 if (slot_map
[XY2OFS(x
,y
)]==0
2665 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2672 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2673 if (slot_map
[XY2OFS(x
,y
)]==0
2674 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2681 /* left and right parts of the ring */
2682 for (y
= -i
+1; y
<= i
-1; y
++) {
2683 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2685 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2686 if (slot_map
[XY2OFS(x
,y
)]==0
2687 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2694 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2695 if (slot_map
[XY2OFS(x
,y
)]==0
2696 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2711 moveDock(WDock
*dock
, int new_x
, int new_y
)
2716 dock
->x_pos
= new_x
;
2717 dock
->y_pos
= new_y
;
2718 for (i
=0; i
<dock
->max_icons
; i
++) {
2719 btn
= dock
->icon_array
[i
];
2721 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2722 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2723 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2730 swapDock(WDock
*dock
)
2732 WScreen
*scr
= dock
->screen_ptr
;
2737 if (dock
->on_right_side
) {
2738 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2740 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2743 for (i
=0; i
<dock
->max_icons
; i
++) {
2744 btn
= dock
->icon_array
[i
];
2747 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2751 wScreenUpdateUsableArea(scr
);
2756 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2758 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2764 cmdline
= ExpandOptions(scr
, command
);
2766 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2774 ParseCommand(cmdline
, &argv
, &argc
);
2784 if ((pid
=fork())==0) {
2788 SetupEnvironment(scr
);
2794 args
= malloc(sizeof(char*)*(argc
+1));
2797 for (i
=0; i
<argc
; i
++) {
2801 execvp(argv
[0], args
);
2810 state
= wmalloc(sizeof(WSavedState
));
2811 memset(state
, 0, sizeof(WSavedState
));
2813 state
->miniaturized
= -1;
2815 if (btn
->dock
== scr
->dock
)
2816 state
->workspace
= -1;
2818 state
->workspace
= scr
->current_workspace
;
2820 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
2822 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
2833 wDockHideIcons(WDock
*dock
)
2841 btn
= dock
->icon_array
[0];
2843 for (i
=1; i
<dock
->max_icons
; i
++) {
2844 if (dock
->icon_array
[i
])
2845 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2854 wDockShowIcons(WDock
*dock
)
2862 btn
= dock
->icon_array
[0];
2863 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2865 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2866 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2868 for (i
=1; i
<dock
->max_icons
; i
++) {
2869 if (dock
->icon_array
[i
]) {
2870 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
2876 if (!dock
->collapsed
) {
2877 for (i
=1; i
<dock
->max_icons
; i
++) {
2878 if (dock
->icon_array
[i
]) {
2879 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2890 wDockLower(WDock
*dock
)
2894 for (i
=0; i
<dock
->max_icons
; i
++) {
2895 if (dock
->icon_array
[i
])
2896 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2902 wDockRaise(WDock
*dock
)
2906 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
2907 if (dock
->icon_array
[i
])
2908 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2914 wDockRaiseLower(WDock
*dock
)
2916 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2917 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2918 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2926 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
2928 icon
->launching
= 0;
2929 icon
->relaunching
= 0;
2930 dockIconPaint(icon
);
2935 wDockFindIconFor(WDock
*dock
, Window window
)
2940 for (i
=0; i
<dock
->max_icons
; i
++) {
2941 icon
= dock
->icon_array
[i
];
2942 if (icon
&& icon
->main_window
== window
)
2950 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
2953 #ifdef REDUCE_APPICONS
2954 WAppIconAppList
*tapplist
;
2956 char *wm_class
, *wm_instance
;
2958 Bool firstPass
= True
;
2960 char *command
= NULL
;
2966 if (XGetCommand(dpy
, window
, &argv
, &argc
)) {
2967 if (argc
> 0 && argv
!= NULL
)
2968 command
= FlattenStringList(argv
,argc
);
2970 XFreeStringList(argv
);
2975 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
2976 (!wm_class
&& !wm_instance
))
2980 for (i
=0; i
<dock
->max_icons
; i
++) {
2981 icon
= dock
->icon_array
[i
];
2985 /* app is already attached to icon */
2986 if (icon
->main_window
== window
) {
2991 if ((icon
->wm_instance
|| icon
->wm_class
)
2993 || (dock
->screen_ptr
->flags
.startup
&& !icon
->running
))) {
2995 if (icon
->wm_instance
&& wm_instance
&&
2996 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
2999 if (icon
->wm_class
&& wm_class
&&
3000 strcmp(icon
->wm_class
, wm_class
)!=0) {
3003 if (firstPass
&& command
&& strcmp(icon
->command
, command
)!=0) {
3007 if (!icon
->relaunching
) {
3010 /* Possibly an application that was docked with dockit,
3011 * but the user did not update WMState to indicate that
3012 * it was docked by force */
3013 wapp
= wApplicationOf(window
);
3015 icon
->forced_dock
= 1;
3018 if (!icon
->forced_dock
)
3019 icon
->main_window
= window
;
3021 #ifdef REDUCE_APPICONS
3022 tapplist
= wmalloc(sizeof(WAppIconAppList
));
3023 memset(tapplist
, 0, sizeof(WAppIconAppList
));
3024 tapplist
->next
= icon
->applist
;
3026 icon
->applist
->prev
= tapplist
;
3027 icon
->applist
= tapplist
;
3028 tapplist
->wapp
= wApplicationOf(window
);
3033 wDockFinishLaunch(dock
, icon
);
3038 if (firstPass
&& !found
) {
3055 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3057 if (!wPreferences
.flags
.noclip
) {
3058 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3059 if (scr
->current_workspace
!= workspace
) {
3060 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3062 wDockHideIcons(old_clip
);
3063 if (old_clip
->auto_raise_lower
) {
3064 if (old_clip
->auto_raise_magic
) {
3065 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3066 old_clip
->auto_raise_magic
= NULL
;
3068 wDockLower(old_clip
);
3070 if (old_clip
->auto_collapse
) {
3071 if (old_clip
->auto_expand_magic
) {
3072 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3073 old_clip
->auto_expand_magic
= NULL
;
3075 old_clip
->collapsed
= 1;
3077 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3079 if (scr
->flags
.clip_balloon_mapped
)
3080 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3087 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3092 for (i
=0; i
<dock
->max_icons
; i
++) {
3093 icon
= dock
->icon_array
[i
];
3097 if (icon
->launching
&& icon
->pid
== pid
) {
3098 if (!icon
->relaunching
) {
3100 icon
->main_window
= None
;
3102 wDockFinishLaunch(dock
, icon
);
3107 sprintf(msg
, _("Could not execute command \"%s\""),
3108 icon
->drop_launch
&& icon
->dnd_command
3109 ? icon
->dnd_command
: icon
->command
);
3111 sprintf(msg
, _("Could not execute command \"%s\""),
3114 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
3115 _("OK"), NULL
, NULL
);
3124 toggleLowered(WDock
*dock
)
3129 /* lower/raise Dock */
3130 if (!dock
->lowered
) {
3131 newlevel
= WMNormalLevel
;
3134 newlevel
= WMDockLevel
;
3138 for (i
=0; i
<dock
->max_icons
; i
++) {
3139 tmp
= dock
->icon_array
[i
];
3143 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3145 wLowerFrame(tmp
->icon
->core
);
3148 if (dock
->type
== WM_DOCK
)
3149 wScreenUpdateUsableArea(dock
->screen_ptr
);
3154 toggleCollapsed(WDock
*dock
)
3156 if (dock
->collapsed
) {
3157 dock
->collapsed
= 0;
3158 wDockShowIcons(dock
);
3161 dock
->collapsed
= 1;
3162 wDockHideIcons(dock
);
3168 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3170 WScreen
*scr
= dock
->screen_ptr
;
3171 WObjDescriptor
*desc
;
3173 WApplication
*wapp
= NULL
;
3176 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3178 if (dock
->type
== WM_DOCK
) {
3180 entry
= dock
->menu
->entries
[index
];
3181 entry
->flags
.indicator_on
= !dock
->lowered
;
3182 entry
->clientdata
= dock
;
3185 if (scr
->clip_options
)
3186 updateClipOptionsMenu(scr
->clip_options
, dock
);
3188 /* Rename Workspace */
3189 entry
= dock
->menu
->entries
[++index
];
3190 entry
->clientdata
= dock
;
3193 entry
= dock
->menu
->entries
[++index
];
3194 entry
->clientdata
= aicon
;
3195 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3197 /* (un)select all icons */
3198 entry
= dock
->menu
->entries
[++index
];
3199 entry
->clientdata
= aicon
;
3200 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3203 entry
= dock
->menu
->entries
[++index
];
3204 entry
->clientdata
= aicon
;
3205 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3207 /* this is the workspace submenu part */
3208 if (scr
->clip_submenu
)
3209 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3212 /* remove icon(s) */
3213 entry
= dock
->menu
->entries
[++index
];
3214 entry
->clientdata
= aicon
;
3215 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3217 /* attract icon(s) */
3218 entry
= dock
->menu
->entries
[++index
];
3219 entry
->clientdata
= aicon
;
3223 entry
= dock
->menu
->entries
[++index
];
3224 entry
->clientdata
= aicon
;
3225 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3228 entry
= dock
->menu
->entries
[++index
];
3229 entry
->clientdata
= aicon
;
3230 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3233 entry
= dock
->menu
->entries
[++index
];
3234 entry
->clientdata
= aicon
;
3235 if (aicon
->icon
->owner
) {
3236 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3237 if (wapp
&& wapp
->flags
.hidden
)
3238 entry
->text
= _("Unhide");
3240 entry
->text
= _("Hide");
3242 entry
->text
= _("Hide");
3244 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3247 entry
= dock
->menu
->entries
[++index
];
3248 entry
->clientdata
= aicon
;
3249 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
3250 && !wPreferences
.flags
.noupdates
);
3253 entry
= dock
->menu
->entries
[++index
];
3254 entry
->clientdata
= aicon
;
3255 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3257 if (!dock
->menu
->flags
.realized
)
3258 wMenuRealize(dock
->menu
);
3260 if (dock
->type
== WM_CLIP
) {
3261 x_pos
= event
->xbutton
.x_root
+2;
3263 x_pos
= dock
->on_right_side
?
3264 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 2 : 0;
3267 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3269 /* allow drag select */
3270 event
->xany
.send_event
= True
;
3271 desc
= &dock
->menu
->menu
->descriptor
;
3272 (*desc
->handle_mousedown
)(desc
, event
);
3277 openClipWorkspaceMenu(WScreen
*scr
, int x
, int y
)
3279 if (!scr
->clip_ws_menu
) {
3280 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3282 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
3283 wMenuMapAt(scr
->clip_ws_menu
, x
, y
, False
);
3287 /******************************************************************/
3289 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3291 WAppIcon
*btn
= desc
->parent
;
3292 WDock
*dock
= btn
->dock
;
3293 WApplication
*wapp
= NULL
;
3296 #ifdef REDUCE_APPICONS
3297 if ((btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) ||
3298 ((btn
->icon
->owner
== NULL
) && (btn
->applist
!= NULL
))) {
3299 if (btn
->icon
->owner
== NULL
)
3300 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
3305 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3307 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3311 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3313 /* go to the last workspace that the user worked on the app */
3314 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
3316 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3319 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3322 if (event
->xbutton
.state
& MOD_MASK
) {
3323 wHideOtherApplications(btn
->icon
->owner
);
3326 if (event
->xbutton
.button
==Button1
) {
3328 if (event
->xbutton
.state
& MOD_MASK
) {
3329 /* raise/lower dock */
3330 toggleLowered(dock
);
3331 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3332 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3333 toggleCollapsed(dock
);
3335 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3336 } else if (btn
->command
) {
3337 if (!btn
->launching
&&
3338 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3339 launchDockedApplication(btn
);
3348 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3350 WScreen
*scr
= dock
->screen_ptr
;
3351 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3354 int grabbed
= 0, swapped
= 0, done
;
3355 Pixmap ghost
= None
;
3356 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3359 puts("moving dock");
3361 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3362 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3363 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3364 wwarning("pointer grab failed for dock move");
3367 for (x
=0; x
<dock
->max_icons
; x
++) {
3368 if (dock
->icon_array
[x
]!=NULL
&&
3369 dock
->icon_array
[x
]->yindex
> y
)
3370 y
= dock
->icon_array
[x
]->yindex
;
3373 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3377 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3378 |ButtonMotionMask
|ExposureMask
, &ev
);
3386 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3387 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3388 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3389 |ButtonReleaseMask
|ButtonPressMask
,
3390 wCursor
[WCUR_MOVE
], CurrentTime
);
3395 if (dock
->type
== WM_CLIP
) {
3396 if (ev
.xmotion
.x_root
- ofs_x
< 0) {
3398 } else if (ev
.xmotion
.x_root
- ofs_x
+ ICON_SIZE
>
3400 x
= scr
->scr_width
- ICON_SIZE
;
3402 x
= ev
.xmotion
.x_root
- ofs_x
;
3404 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3406 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3408 y
= scr
->scr_height
- ICON_SIZE
;
3410 y
= ev
.xmotion
.y_root
- ofs_y
;
3412 moveDock(dock
, x
, y
);
3414 /* move vertically if pointer is inside the dock*/
3415 if ((dock
->on_right_side
&&
3416 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3417 || (!dock
->on_right_side
&&
3418 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3420 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3422 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3424 y
= scr
->scr_height
- ICON_SIZE
;
3426 y
= ev
.xmotion
.y_root
- ofs_y
;
3428 moveDock(dock
, dock
->x_pos
, y
);
3430 /* move horizontally to change sides */
3431 x
= ev
.xmotion
.x_root
- ofs_x
;
3432 if (!dock
->on_right_side
) {
3436 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3437 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3438 -DOCK_EXTRA_SPACE
-1, dock
->y_pos
);
3441 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3442 scr
->scr_width
-ICON_SIZE
3443 -DOCK_EXTRA_SPACE
-1,
3445 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3447 XClearWindow(dpy
, scr
->dock_shadow
);
3450 XMapRaised(dpy
, scr
->dock_shadow
);
3453 if (superfluous
&& ghost
!=None
) {
3454 XFreePixmap(dpy
, ghost
);
3457 XUnmapWindow(dpy
, scr
->dock_shadow
);
3462 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3463 XMoveWindow(dpy
, scr
->dock_shadow
,
3464 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3467 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3468 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3469 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3471 XClearWindow(dpy
, scr
->dock_shadow
);
3474 XMapRaised(dpy
, scr
->dock_shadow
);
3477 XUnmapWindow(dpy
, scr
->dock_shadow
);
3479 if (superfluous
&& ghost
!=None
) {
3480 XFreePixmap(dpy
, ghost
);
3492 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3494 XUngrabPointer(dpy
, CurrentTime
);
3495 XUnmapWindow(dpy
, scr
->dock_shadow
);
3496 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3497 if (dock
->type
== WM_DOCK
) {
3500 dock
->on_right_side
= 1;
3502 dock
->on_right_side
= 0;
3504 wArrangeIcons(scr
, False
);
3513 XFreePixmap(dpy
, ghost
);
3514 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3517 puts("End dock move");
3524 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3526 WScreen
*scr
= dock
->screen_ptr
;
3528 WIcon
*icon
= aicon
->icon
;
3529 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3530 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3532 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3533 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3534 int shad_x
= x
, shad_y
= y
;
3535 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3537 Pixmap ghost
= None
;
3539 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3541 if (wPreferences
.flags
.noupdates
)
3544 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3545 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3546 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3548 wwarning("pointer grab failed for icon move");
3552 wRaiseFrame(icon
->core
);
3554 if (!wPreferences
.flags
.noclip
)
3555 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3557 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3559 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3562 wins
[0] = icon
->core
->window
;
3563 wins
[1] = scr
->dock_shadow
;
3564 XRestackWindows(dpy
, wins
, 2);
3565 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3566 ICON_SIZE
, ICON_SIZE
);
3568 if (icon
->pixmap
!=None
)
3569 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3571 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3573 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3574 XClearWindow(dpy
, scr
->dock_shadow
);
3576 XMapWindow(dpy
, scr
->dock_shadow
);
3582 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3583 |ButtonMotionMask
|ExposureMask
, &ev
);
3591 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3592 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3593 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3594 |ButtonReleaseMask
|ButtonPressMask
,
3595 wCursor
[WCUR_MOVE
], CurrentTime
);
3602 x
= ev
.xmotion
.x_root
- ofs_x
;
3603 y
= ev
.xmotion
.y_root
- ofs_y
;
3604 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3607 if (last_dock
!= dock
&& collapsed
) {
3608 last_dock
->collapsed
= 1;
3609 wDockHideIcons(last_dock
);
3612 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3613 dock
->collapsed
= 0;
3614 wDockShowIcons(dock
);
3616 if (dock
->auto_raise_lower
)
3621 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3624 if (last_dock
!= dock2
&& collapsed
) {
3625 last_dock
->collapsed
= 1;
3626 wDockHideIcons(last_dock
);
3629 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3630 dock2
->collapsed
= 0;
3631 wDockShowIcons(dock2
);
3633 if (dock2
->auto_raise_lower
)
3638 if (aicon
->launching
3639 || (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3640 || (!aicon
->running
&& tmp
)) {
3641 shad_x
= last_dock
->x_pos
+ ix
*wPreferences
.icon_size
;
3642 shad_y
= last_dock
->y_pos
+ iy
*wPreferences
.icon_size
;
3644 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3647 XMapWindow(dpy
, scr
->dock_shadow
);
3649 if (!collapsed
&& (collapsed
= last_dock
->collapsed
)) {
3650 last_dock
->collapsed
= 0;
3651 wDockShowIcons(last_dock
);
3658 XUnmapWindow(dpy
, scr
->dock_shadow
);
3660 if (last_dock
&& collapsed
&&
3661 aicon
->running
&& (ev
.xmotion
.state
& MOD_MASK
)) {
3662 last_dock
->collapsed
= 1;
3663 wDockHideIcons(last_dock
);
3670 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3677 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3679 XUngrabPointer(dpy
, CurrentTime
);
3681 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3682 XUnmapWindow(dpy
, scr
->dock_shadow
);
3684 reattachIcon(dock
, aicon
, ix
, iy
);
3685 if (clip
&& dock
!=clip
&& clip
->auto_raise_lower
)
3688 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3690 /* Slide it back if dock rejected it */
3691 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3693 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3695 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3703 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3704 /* We need to deselect it, even if is deselected in
3705 * wDockDetach(), because else DoKaboom() will fail.
3707 if (aicon
->icon
->selected
)
3708 wIconSelect(aicon
->icon
);
3709 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3712 if (clip
&& clip
->auto_raise_lower
)
3714 wDockDetach(dock
, aicon
);
3717 last_dock
->collapsed
= 1;
3718 wDockHideIcons(last_dock
);
3723 XFreePixmap(dpy
, ghost
);
3724 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3727 puts("End icon move");
3736 getClipButton(int px
, int py
)
3738 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
3740 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3743 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
3744 return CLIP_FORWARD
;
3745 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
3753 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3756 int done
, direction
, new_ws
;
3758 WDock
*clip
= scr
->clip_icon
->dock
;
3760 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3762 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3763 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3765 wClipIconPaint(scr
->clip_icon
);
3768 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
3769 |ButtonPressMask
, &ev
);
3776 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3777 if (new_dir
!= direction
) {
3778 direction
= new_dir
;
3779 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3780 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3781 wClipIconPaint(scr
->clip_icon
);
3789 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3794 clip
->lclip_button_pushed
= 0;
3795 clip
->rclip_button_pushed
= 0;
3797 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3799 if (direction
== CLIP_FORWARD
) {
3800 if (scr
->current_workspace
< scr
->workspace_count
-1)
3801 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3802 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
3803 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3804 else if (wPreferences
.ws_cycle
)
3805 wWorkspaceChange(scr
, 0);
3807 else if (direction
== CLIP_REWIND
) {
3808 if (scr
->current_workspace
> 0)
3809 wWorkspaceChange(scr
, scr
->current_workspace
-1);
3810 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
3811 wWorkspaceChange(scr
, scr
->workspace_count
-1);
3814 wClipIconPaint(scr
->clip_icon
);
3819 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3821 WAppIcon
*aicon
= desc
->parent
;
3822 WDock
*dock
= aicon
->dock
;
3823 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3825 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3828 scr
->last_dock
= dock
;
3830 if (dock
->menu
->flags
.mapped
)
3831 wMenuUnmap(dock
->menu
);
3833 if (IsDoubleClick(scr
, event
)) {
3834 /* double-click was not in the main clip icon */
3835 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
3836 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
3837 iconDblClick(desc
, event
);
3842 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
3843 XUnmapWindow(dpy
, scr
->clip_balloon
);
3844 scr
->flags
.clip_balloon_mapped
= 0;
3848 puts("handling dock");
3850 if (event
->xbutton
.button
== Button1
) {
3851 if (event
->xbutton
.state
& MOD_MASK
)
3856 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
3857 dock
->type
!=WM_DOCK
) {
3858 wIconSelect(aicon
->icon
);
3862 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
3863 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
3864 && dock
->type
==WM_CLIP
)
3865 handleClipChangeWorkspace(scr
, event
);
3867 handleDockMove(dock
, aicon
, event
);
3869 handleIconMove(dock
, aicon
, event
);
3871 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
3872 aicon
->xindex
==0 && aicon
->yindex
==0) {
3873 openClipWorkspaceMenu(scr
, event
->xbutton
.x_root
+2,
3874 event
->xbutton
.y_root
+2);
3875 if (scr
->clip_ws_menu
) {
3877 menu
= scr
->clip_ws_menu
;
3878 desc
= &menu
->menu
->descriptor
;
3880 event
->xany
.send_event
= True
;
3881 (*desc
->handle_mousedown
)(desc
, event
);
3883 } else if (event
->xbutton
.button
== Button3
) {
3884 openDockMenu(dock
, aicon
, event
);
3890 showClipBalloon(WDock
*dock
, int workspace
)
3894 WScreen
*scr
= dock
->screen_ptr
;
3898 scr
->flags
.clip_balloon_mapped
= 1;
3899 XMapWindow(dpy
, scr
->clip_balloon
);
3901 text
= scr
->workspaces
[workspace
]->name
;
3903 w
= wTextWidth(scr
->clip_title_font
->font
, text
, strlen(text
));
3905 h
= scr
->clip_title_font
->height
;
3906 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
3908 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
3909 y
= dock
->y_pos
+ ICON_SIZE
-scr
->clip_title_font
->height
- 3;
3911 if (x
+w
> scr
->scr_width
) {
3912 x
= scr
->scr_width
- w
;
3913 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
3914 y
= dock
->y_pos
- h
- 1;
3916 y
= dock
->y_pos
+ ICON_SIZE
;
3917 XRaiseWindow(dpy
, scr
->clip_balloon
);
3919 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
3920 stack
[1] = scr
->clip_balloon
;
3921 XRestackWindows(dpy
, stack
, 2);
3923 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
3924 XSetForeground(dpy
, scr
->clip_title_gc
,
3925 scr
->clip_title_pixel
[CLIP_NORMAL
]);
3926 XClearWindow(dpy
, scr
->clip_balloon
);
3927 wDrawString(scr
->clip_balloon
, scr
->clip_title_font
, scr
->clip_title_gc
,
3928 0, scr
->clip_title_font
->y
, text
, strlen(text
));
3933 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3935 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
3938 assert(event
->type
==EnterNotify
);
3940 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
3944 if (!dock
|| dock
->type
!=WM_CLIP
)
3947 /* The auto raise/lower code */
3948 if (dock
->auto_lower_magic
) {
3949 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3950 dock
->auto_lower_magic
= NULL
;
3952 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
3953 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
,
3958 /* The auto expand/collapse code */
3959 if (dock
->auto_collapse_magic
) {
3960 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3961 dock
->auto_collapse_magic
= NULL
;
3963 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
3964 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
,
3969 if (btn
->xindex
== 0 && btn
->yindex
== 0)
3970 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
3972 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
3973 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
3974 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
3981 clipLeave(WDock
*dock
)
3984 WObjDescriptor
*desc
= NULL
;
3986 if (!dock
|| dock
->type
!=WM_CLIP
)
3989 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
)!=False
) {
3990 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3991 (XPointer
*)&desc
)!=XCNOENT
3992 && desc
&& desc
->parent_type
==WCLASS_DOCK_ICON
3993 && ((WAppIcon
*)desc
->parent
)->dock
3994 && ((WAppIcon
*)desc
->parent
)->dock
->type
==WM_CLIP
) {
3995 /* We didn't left the Clip yet */
3996 XPutBackEvent(dpy
, &event
);
4000 XPutBackEvent(dpy
, &event
);
4002 /* We entered a withdrawn window, so we're still in Clip */
4006 if (dock
->auto_raise_magic
) {
4007 WMDeleteTimerHandler(dock
->auto_raise_magic
);
4008 dock
->auto_raise_magic
= NULL
;
4010 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
4011 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
,
4016 if (dock
->auto_expand_magic
) {
4017 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4018 dock
->auto_expand_magic
= NULL
;
4020 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
4021 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
4029 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4031 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4033 assert(event
->type
==LeaveNotify
);
4035 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4038 clipLeave(btn
->dock
);
4043 clipAutoCollapse(void *cdata
)
4045 WDock
*dock
= (WDock
*)cdata
;
4047 if (dock
->type
!=WM_CLIP
)
4050 if (dock
->auto_collapse
) {
4051 dock
->collapsed
= 1;
4052 wDockHideIcons(dock
);
4054 dock
->auto_collapse_magic
= NULL
;
4059 clipAutoExpand(void *cdata
)
4061 WDock
*dock
= (WDock
*)cdata
;
4063 if (dock
->type
!=WM_CLIP
)
4066 if (dock
->auto_collapse
) {
4067 dock
->collapsed
= 0;
4068 wDockShowIcons(dock
);
4070 dock
->auto_expand_magic
= NULL
;
4075 clipAutoLower(void *cdata
)
4077 WDock
*dock
= (WDock
*)cdata
;
4079 if (dock
->type
!=WM_CLIP
)
4082 if (dock
->auto_raise_lower
)
4085 dock
->auto_lower_magic
= NULL
;
4090 clipAutoRaise(void *cdata
)
4092 WDock
*dock
= (WDock
*)cdata
;
4094 if (dock
->type
!=WM_CLIP
)
4097 if (dock
->auto_raise_lower
)
4100 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4101 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4104 dock
->auto_raise_magic
= NULL
;