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 /* top right arrow */
356 p
[0].x
= p
[3].x
= ICON_SIZE
-5-as
;
358 p
[1].x
= ICON_SIZE
-6;
360 p
[2].x
= ICON_SIZE
-6;
363 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
364 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
366 #ifdef GRADIENT_CLIP_ARROW
368 XSetTSOrigin(dpy
, gc
, ICON_SIZE
-6-as
, 5);
370 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
371 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
374 /* bottom left arrow */
376 p
[0].y
= p
[3].y
= ICON_SIZE
-5-as
;
378 p
[1].y
= ICON_SIZE
-6;
380 p
[2].y
= ICON_SIZE
-6;
382 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
383 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
385 #ifdef GRADIENT_CLIP_ARROW
387 XSetTSOrigin(dpy
, gc
, 5, ICON_SIZE
-6-as
);
389 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
390 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
392 #ifdef GRADIENT_CLIP_ARROW
394 XSetFillStyle(dpy
, scr
->copy_gc
, FillSolid
);
400 wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
402 RImage
*tile
= RCloneImage(normalTile
);
409 pt
= CLIP_BUTTON_SIZE
*wPreferences
.icon_size
/64;
410 tp
= wPreferences
.icon_size
-1 - pt
;
414 black
.red
= black
.green
= black
.blue
= 0;
417 dark
.red
= dark
.green
= dark
.blue
= 60;
420 light
.red
= light
.green
= light
.blue
= 80;
424 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
-2,
426 RDrawLine(tile
, tp
-1, 0, wPreferences
.icon_size
-1, pt
+1, &black
);
427 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
-3,
431 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4,
432 ICON_SIZE
- 5, 4, &dark
);
433 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5,
434 ICON_SIZE
- 5, 6 + as
, &dark
);
435 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
,
439 ROperateLine(tile
, RAddOperation
, 2, tp
+2, pt
-2,
440 wPreferences
.icon_size
-3, &dark
);
441 RDrawLine(tile
, 0, tp
-1, pt
+1, wPreferences
.icon_size
-1, &black
);
442 ROperateLine(tile
, RSubtractOperation
, 0, tp
-2, pt
+1,
443 wPreferences
.icon_size
-2, &light
);
446 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4,
447 ICON_SIZE
- 5, &dark
);
448 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
,
449 6 + as
, ICON_SIZE
- 5, &dark
);
450 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5,
458 removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
460 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
463 LinkedList
*selectedIcons
;
466 assert(clickedIcon
!=NULL
);
468 dock
= clickedIcon
->dock
;
470 selectedIcons
= getSelected(dock
);
473 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
474 _("All selected icons will be removed!"),
475 _("OK"), _("Cancel"), NULL
)!=WAPRDefault
) {
479 if (clickedIcon
->xindex
==0 && clickedIcon
->yindex
==0)
481 selectedIcons
= list_cons(clickedIcon
, NULL
);
484 while (selectedIcons
) {
485 aicon
= selectedIcons
->head
;
486 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
487 wDockDetach(dock
, aicon
);
489 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
490 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
491 aicon
->x_pos
, aicon
->y_pos
);
492 if (!dock
->mapped
|| dock
->collapsed
)
493 XMapWindow(dpy
, aicon
->icon
->core
->window
);
495 list_remove_head(&selectedIcons
);
498 if (wPreferences
.auto_arrange_icons
)
499 wArrangeIcons(dock
->screen_ptr
, True
);
504 keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
506 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
509 LinkedList
*selectedIcons
;
511 assert(clickedIcon
!=NULL
);
512 dock
= clickedIcon
->dock
;
514 selectedIcons
= getSelected(dock
);
516 if (!selectedIcons
&& clickedIcon
!=dock
->screen_ptr
->clip_icon
) {
517 char *command
= NULL
;
519 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
520 clickedIcon
->editing
= 1;
521 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
522 _("Type the command used to launch the application"),
524 if (command
&& (command
[0]==0 ||
525 (command
[0]=='-' && command
[1]==0))) {
529 clickedIcon
->command
= command
;
530 clickedIcon
->editing
= 0;
532 clickedIcon
->editing
= 0;
539 selectedIcons
= list_cons(clickedIcon
, NULL
);
542 while (selectedIcons
) {
543 aicon
= selectedIcons
->head
;
544 if (aicon
->icon
->selected
)
545 wIconSelect(aicon
->icon
);
546 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
547 aicon
->attracted
= 0;
548 if (aicon
->icon
->shadowed
) {
549 aicon
->icon
->shadowed
= 0;
550 aicon
->icon
->force_paint
= 1;
551 wAppIconPaint(aicon
);
554 list_remove_head(&selectedIcons
);
562 toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
564 WDock
*dock
= (WDock
*)entry
->clientdata
;
566 assert(entry
->clientdata
!=NULL
);
568 dock
->attract_icons
= !dock
->attract_icons
;
569 /*if (!dock->attract_icons)
570 dock->keep_attracted = 0;*/
572 entry
->flags
.indicator_on
= dock
->attract_icons
;
579 toggleKeepCallback(WMenu
*menu
, WMenuEntry
*entry
)
581 WDock
*dock
= (WDock
*)entry
->clientdata
;
585 assert(entry
->clientdata
!=NULL
);
587 dock
->keep_attracted
= !dock
->keep_attracted
;
589 if (dock
->keep_attracted
) {
590 for (i
=0; i
< dock
->max_icons
; i
++) {
591 btn
= dock
->icon_array
[i
];
592 if (btn
&& btn
->attracted
&& btn
->command
) {
594 if (btn
->icon
->shadowed
) {
595 btn
->icon
->shadowed
= 0;
596 btn
->icon
->force_paint
= 1;
603 entry
->flags
.indicator_on
= dock
->keep_attracted
;
610 selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
612 WAppIcon
*icon
= (WAppIcon
*)entry
->clientdata
;
616 wIconSelect(icon
->icon
);
623 colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
625 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
628 int x
, y
, x_pos
, y_pos
;
630 assert(entry
->clientdata
!=NULL
);
631 clip
= clickedIcon
->dock
;
633 aicon
= clip
->screen_ptr
->app_icon_list
;
636 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
637 x_pos
= clip
->x_pos
+ x
*ICON_SIZE
;
638 y_pos
= clip
->y_pos
+ y
*ICON_SIZE
;
639 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
641 if (wPreferences
.no_animations
) {
642 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
644 SlideWindow(aicon
->icon
->core
->window
,
645 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
648 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
649 #endif /* ANIMATIONS */
651 aicon
->attracted
= 1;
652 if (!clip
->keep_attracted
&& !aicon
->icon
->shadowed
) {
653 aicon
->icon
->shadowed
= 1;
654 aicon
->icon
->force_paint
= 1;
655 /* We don't do an wAppIconPaint() here because it's in
656 * wDockAttachIcon(). -Dan
659 wDockAttachIcon(clip
, aicon
, x
, y
);
660 if (clip
->collapsed
|| !clip
->mapped
)
661 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
669 selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
671 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
673 LinkedList
*selectedIcons
;
677 assert(clickedIcon
!=NULL
);
678 dock
= clickedIcon
->dock
;
680 selectedIcons
= getSelected(dock
);
682 if (!selectedIcons
) {
683 for (i
=1; i
<dock
->max_icons
; i
++) {
684 btn
= dock
->icon_array
[i
];
685 if (btn
&& !btn
->icon
->selected
) {
686 wIconSelect(btn
->icon
);
690 while(selectedIcons
) {
691 btn
= selectedIcons
->head
;
692 wIconSelect(btn
->icon
);
693 list_remove_head(&selectedIcons
);
702 toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
704 assert(entry
->clientdata
!=NULL
);
706 toggleCollapsed(entry
->clientdata
);
708 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->collapsed
;
715 toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
718 assert(entry
->clientdata
!=NULL
);
720 dock
= (WDock
*) entry
->clientdata
;
722 dock
->auto_collapse
= !dock
->auto_collapse
;
724 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_collapse
;
731 toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
734 assert(entry
->clientdata
!=NULL
);
736 dock
= (WDock
*) entry
->clientdata
;
738 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
740 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_raise_lower
;
747 launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
749 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
751 launchDockedApplication(btn
);
756 settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
758 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
762 ShowDockAppSettingsPanel(btn
);
767 hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
770 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
772 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
774 if (wapp
->flags
.hidden
) {
775 wWorkspaceChange(btn
->icon
->core
->screen_ptr
,wapp
->last_workspace
);
776 wUnhideApplication(wapp
, False
, False
);
778 wHideApplication(wapp
);
784 unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
787 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
789 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
791 wUnhideApplication(wapp
, False
, True
);
796 mainIconCreate(WScreen
*scr
, int type
)
801 if (type
== WM_CLIP
) {
803 return scr
->clip_icon
;
804 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
805 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
806 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
807 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
808 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE;*/
811 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
812 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
818 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
819 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
820 btn
->icon
->core
->descriptor
.parent
= btn
;
821 /*ChangeStackingLevel(btn->icon->core, WMDockLevel);*/
822 XMapWindow(dpy
, btn
->icon
->core
->window
);
827 scr
->clip_icon
= btn
;
834 switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
836 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
837 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
839 LinkedList
*selectedIcons
;
842 if (entry
->order
== scr
->current_workspace
)
845 dest
= scr
->workspaces
[entry
->order
]->clip
;
847 selectedIcons
= getSelected(src
);
850 while(selectedIcons
) {
851 btn
= selectedIcons
->head
;
852 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
853 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
854 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
856 list_remove_head(&selectedIcons
);
858 } else if (icon
!= scr
->clip_icon
) {
859 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
860 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
861 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
869 launchDockedApplication(WAppIcon
*btn
)
871 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
873 if (!btn
->launching
&& btn
->command
!=NULL
) {
874 if (!btn
->forced_dock
) {
875 btn
->relaunching
= btn
->running
;
878 if (btn
->wm_instance
|| btn
->wm_class
) {
879 WWindowAttributes attr
;
880 memset(&attr
, 0, sizeof(WWindowAttributes
));
881 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
,
884 if (!attr
.no_appicon
&& !btn
->buggy_app
)
889 btn
->drop_launch
= 0;
890 scr
->last_dock
= btn
->dock
;
891 btn
->pid
= execCommand(btn
, btn
->command
, NULL
);
893 if (btn
->buggy_app
) {
894 /* give feedback that the app was launched */
898 WMAddTimerHandler(200, (WMCallback
*)dockIconPaint
, btn
);
903 wwarning(_("could not launch application %s\n"), btn
->command
);
905 if (!btn
->relaunching
)
914 updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
916 WScreen
*scr
= menu
->frame
->screen_ptr
;
917 char title
[MAX_WORKSPACENAME_WIDTH
+1];
923 for (i
=0; i
<scr
->workspace_count
; i
++) {
924 if (i
< menu
->entry_no
) {
925 if (strcmp(menu
->entries
[i
]->text
,scr
->workspaces
[i
]->name
)!=0) {
926 free(menu
->entries
[i
]->text
);
927 strcpy(title
, scr
->workspaces
[i
]->name
);
928 menu
->entries
[i
]->text
= wstrdup(title
);
929 menu
->flags
.realized
= 0;
931 menu
->entries
[i
]->clientdata
= (void*)icon
;
933 strcpy(title
, scr
->workspaces
[i
]->name
);
935 wMenuAddCallback(menu
, title
, switchWSCommand
, (void*)icon
);
937 menu
->flags
.realized
= 0;
939 if (i
== scr
->current_workspace
) {
940 wMenuSetEnabled(menu
, i
, False
);
942 wMenuSetEnabled(menu
, i
, True
);
946 if (!menu
->flags
.realized
)
952 makeWorkspaceMenu(WScreen
*scr
)
956 menu
= wMenuCreate(scr
, NULL
, False
);
958 wwarning(_("could not create workspace submenu for Clip menu"));
960 wMenuAddCallback(menu
, "", switchWSCommand
, (void*)scr
->clip_icon
);
962 menu
->flags
.realized
= 0;
970 updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
979 entry
= menu
->entries
[index
];
980 entry
->flags
.indicator_on
= !dock
->lowered
;
981 entry
->clientdata
= dock
;
984 entry
= menu
->entries
[++index
];
985 entry
->flags
.indicator_on
= dock
->collapsed
;
986 entry
->clientdata
= dock
;
989 entry
= menu
->entries
[++index
];
990 entry
->flags
.indicator_on
= dock
->auto_collapse
;
991 entry
->clientdata
= dock
;
993 /* auto-raise/lower */
994 entry
= menu
->entries
[++index
];
995 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
996 entry
->clientdata
= dock
;
999 entry
= menu
->entries
[++index
];
1000 entry
->flags
.indicator_on
= dock
->attract_icons
;
1001 entry
->clientdata
= dock
;
1003 /* keep attracted icons */
1004 entry
= menu
->entries
[++index
];
1005 entry
->flags
.indicator_on
= dock
->keep_attracted
;
1006 entry
->clientdata
= dock
;
1008 menu
->flags
.realized
= 0;
1014 makeClipOptionsMenu(WScreen
*scr
)
1019 menu
= wMenuCreate(scr
, NULL
, False
);
1021 wwarning(_("could not create options submenu for Clip menu"));
1025 entry
= wMenuAddCallback(menu
, _("Keep on top"),
1026 toggleLoweredCallback
, NULL
);
1027 entry
->flags
.indicator
= 1;
1028 entry
->flags
.indicator_on
= 1;
1029 entry
->flags
.indicator_type
= MI_CHECK
;
1031 entry
= wMenuAddCallback(menu
, _("Collapsed"),
1032 toggleCollapsedCallback
, NULL
);
1033 entry
->flags
.indicator
= 1;
1034 entry
->flags
.indicator_on
= 1;
1035 entry
->flags
.indicator_type
= MI_CHECK
;
1037 entry
= wMenuAddCallback(menu
, _("AutoCollapse"),
1038 toggleAutoCollapseCallback
, NULL
);
1039 entry
->flags
.indicator
= 1;
1040 entry
->flags
.indicator_on
= 1;
1041 entry
->flags
.indicator_type
= MI_CHECK
;
1043 entry
= wMenuAddCallback(menu
, _("AutoRaiseLower"),
1044 toggleAutoRaiseLowerCallback
, NULL
);
1045 entry
->flags
.indicator
= 1;
1046 entry
->flags
.indicator_on
= 1;
1047 entry
->flags
.indicator_type
= MI_CHECK
;
1049 entry
= wMenuAddCallback(menu
, _("AutoAttract Icons"),
1050 toggleAutoAttractCallback
, NULL
);
1051 entry
->flags
.indicator
= 1;
1052 entry
->flags
.indicator_on
= 1;
1053 entry
->flags
.indicator_type
= MI_CHECK
;
1055 entry
= wMenuAddCallback(menu
, _("Keep Attracted Icons"),
1056 toggleKeepCallback
, NULL
);
1057 entry
->flags
.indicator
= 1;
1058 entry
->flags
.indicator_on
= 1;
1059 entry
->flags
.indicator_type
= MI_CHECK
;
1061 menu
->flags
.realized
= 0;
1069 dockMenuCreate(WScreen
*scr
, int type
)
1074 if (type
== WM_CLIP
&& scr
->clip_menu
)
1075 return scr
->clip_menu
;
1077 menu
= wMenuCreate(scr
, NULL
, False
);
1078 if (type
!= WM_CLIP
) {
1079 entry
= wMenuAddCallback(menu
, _("Keep on top"),
1080 toggleLoweredCallback
, NULL
);
1081 entry
->flags
.indicator
= 1;
1082 entry
->flags
.indicator_on
= 1;
1083 entry
->flags
.indicator_type
= MI_CHECK
;
1085 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1086 scr
->clip_options
= makeClipOptionsMenu(scr
);
1087 if (scr
->clip_options
)
1088 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1090 wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1092 wMenuAddCallback(menu
, _("(Un)Select Icon"), selectCallback
, NULL
);
1094 wMenuAddCallback(menu
, _("(Un)Select All Icons"), selectIconsCallback
,
1097 wMenuAddCallback(menu
, _("Keep Icon(s)"), keepIconsCallback
, NULL
);
1099 entry
= wMenuAddCallback(menu
, _("Move Icon(s) To"), NULL
, NULL
);
1100 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1101 if (scr
->clip_submenu
)
1102 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1104 wMenuAddCallback(menu
, _("Remove Icon(s)"), removeIconsCallback
, NULL
);
1106 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1109 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1111 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1113 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1115 entry
->text
= _("Hide");
1117 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1119 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1121 if (type
== WM_CLIP
)
1122 scr
->clip_menu
= menu
;
1129 wDockCreate(WScreen
*scr
, int type
)
1137 dock
= wmalloc(sizeof(WDock
));
1138 memset(dock
, 0, sizeof(WDock
));
1140 if (type
== WM_CLIP
)
1141 icon_count
= CLIP_MAX_ICONS
;
1143 icon_count
= scr
->scr_height
/wPreferences
.icon_size
;
1145 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*)*icon_count
);
1146 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*)*icon_count
);
1148 dock
->max_icons
= icon_count
;
1150 btn
= mainIconCreate(scr
, type
);
1154 dock
->x_pos
= btn
->x_pos
;
1155 dock
->y_pos
= btn
->y_pos
;
1156 dock
->screen_ptr
= scr
;
1158 dock
->icon_count
= 1;
1159 dock
->on_right_side
= 1;
1160 dock
->collapsed
= 0;
1161 dock
->auto_collapse
= 0;
1162 dock
->auto_collapse_magic
= NULL
;
1163 dock
->auto_raise_lower
= 0;
1164 dock
->auto_lower_magic
= NULL
;
1165 dock
->auto_raise_magic
= NULL
;
1166 dock
->attract_icons
= 0;
1167 dock
->keep_attracted
= 0;
1169 dock
->icon_array
[0] = btn
;
1170 wRaiseFrame(btn
->icon
->core
);
1171 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1173 /* create dock menu */
1174 dock
->menu
= dockMenuCreate(scr
, type
);
1181 wDockDestroy(WDock
*dock
)
1186 for (i
=(dock
->type
== WM_CLIP
) ? 1 : 0; i
<dock
->max_icons
; i
++) {
1187 aicon
= dock
->icon_array
[i
];
1189 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1190 wDockDetach(dock
, aicon
);
1192 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
1193 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
1194 aicon
->x_pos
, aicon
->y_pos
);
1195 if (!dock
->mapped
|| dock
->collapsed
)
1196 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1200 if (wPreferences
.auto_arrange_icons
)
1201 wArrangeIcons(dock
->screen_ptr
, True
);
1202 free(dock
->icon_array
);
1203 if (dock
->menu
&& dock
->type
!=WM_CLIP
)
1204 wMenuDestroy(dock
->menu
, True
);
1210 wClipIconPaint(WAppIcon
*aicon
)
1212 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1213 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1215 Window win
= aicon
->icon
->core
->window
;
1216 int length
, nlength
;
1217 char *ws_name
, ws_number
[10];
1220 wIconPaint(aicon
->icon
);
1222 length
= strlen(workspace
->name
);
1223 ws_name
= malloc(length
+ 1);
1224 sprintf(ws_name
, "%s", workspace
->name
);
1225 sprintf(ws_number
, "%i", scr
->current_workspace
+ 1);
1226 nlength
= strlen(ws_number
);
1228 gc
= scr
->clip_title_gc
;
1230 if (!workspace
->clip
->collapsed
)
1231 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_NORMAL
]);
1233 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_COLLAPSED
]);
1235 ty
= ICON_SIZE
- scr
->clip_title_font
->height
- 3;
1237 tx
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
1239 wDrawString(win
, scr
->clip_title_font
, gc
, tx
,
1240 ty
+ scr
->clip_title_font
->y
, ws_name
, length
);
1242 tx
= (ICON_SIZE
/2 - wTextWidth(scr
->clip_title_font
->font
, ws_number
, nlength
))/2;
1244 wDrawString(win
, scr
->clip_title_font
, gc
, tx
,
1245 scr
->clip_title_font
->y
+ 2, ws_number
, nlength
);
1249 if (aicon
->launching
) {
1250 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1251 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1253 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
,
1254 aicon
->dock
->rclip_button_pushed
);
1259 clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1261 wClipIconPaint(desc
->parent
);
1266 dockIconPaint(WAppIcon
*btn
)
1268 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1269 wClipIconPaint(btn
);
1276 make_icon_state(WAppIcon
*btn
)
1278 proplist_t node
= NULL
;
1279 proplist_t command
, autolaunch
, name
, forced
, host
, position
, buggy
;
1285 command
= PLMakeString("-");
1287 command
= PLMakeString(btn
->command
);
1289 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1291 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1293 name
= PLMakeString(tmp
);
1297 forced
= btn
->forced_dock
? dYes
: dNo
;
1299 buggy
= btn
->buggy_app
? dYes
: dNo
;
1301 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1302 sprintf(buffer
, "%i,%i", btn
->x_pos
, btn
->y_pos
);
1304 sprintf(buffer
, "%hi,%hi", btn
->xindex
, btn
->yindex
);
1305 position
= PLMakeString(buffer
);
1307 node
= PLMakeDictionaryFromEntries(dCommand
, command
,
1309 dAutoLaunch
, autolaunch
,
1311 dBuggyApplication
, buggy
,
1312 dPosition
, position
,
1316 PLRelease(position
);
1318 if (btn
->dnd_command
) {
1319 command
= PLMakeString(btn
->dnd_command
);
1320 PLInsertDictionaryEntry(node
, dDropCommand
, command
);
1323 #endif /* OFFIX_DND */
1325 if (btn
->client_machine
&& btn
->remote_start
) {
1326 host
= PLMakeString(btn
->client_machine
);
1327 PLInsertDictionaryEntry(node
, dHost
, host
);
1337 dockSaveState(WDock
*dock
)
1340 proplist_t icon_info
;
1341 proplist_t list
=NULL
, dock_state
=NULL
;
1345 list
= PLMakeArrayFromElements(NULL
);
1347 for (i
=(dock
->type
==WM_DOCK
? 0 : 1); i
<dock
->max_icons
; i
++) {
1348 WAppIcon
*btn
= dock
->icon_array
[i
];
1350 if (!btn
|| (btn
->attracted
&& !dock
->keep_attracted
))
1353 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1354 list
= PLAppendArrayElement(list
, icon_info
);
1355 PLRelease(icon_info
);
1359 dock_state
= PLMakeDictionaryFromEntries(dApplications
, list
, NULL
);
1363 if (dock
->type
== WM_DOCK
) {
1364 sprintf(buffer
, "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0),
1366 value
= PLMakeString(buffer
);
1367 PLInsertDictionaryEntry(dock_state
, dPosition
, value
);
1371 value
= (dock
->lowered
? dYes
: dNo
);
1372 PLInsertDictionaryEntry(dock_state
, dLowered
, value
);
1374 if (dock
->type
== WM_CLIP
) {
1375 value
= (dock
->collapsed
? dYes
: dNo
);
1376 PLInsertDictionaryEntry(dock_state
, dCollapsed
, value
);
1378 value
= (dock
->auto_collapse
? dYes
: dNo
);
1379 PLInsertDictionaryEntry(dock_state
, dAutoCollapse
, value
);
1381 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1382 PLInsertDictionaryEntry(dock_state
, dAutoRaiseLower
, value
);
1384 value
= (dock
->attract_icons
? dYes
: dNo
);
1385 PLInsertDictionaryEntry(dock_state
, dAutoAttractIcons
, value
);
1387 value
= (dock
->keep_attracted
? dYes
: dNo
);
1388 PLInsertDictionaryEntry(dock_state
, dKeepAttracted
, value
);
1396 wDockSaveState(WScreen
*scr
)
1398 proplist_t dock_state
;
1400 dock_state
= dockSaveState(scr
->dock
);
1402 PLInsertDictionaryEntry(scr
->session_state
, dDock
, dock_state
);
1404 PLRelease(dock_state
);
1409 wClipSaveState(WScreen
*scr
)
1411 proplist_t clip_state
;
1413 clip_state
= make_icon_state(scr
->clip_icon
);
1415 PLInsertDictionaryEntry(scr
->session_state
, dClip
, clip_state
);
1417 PLRelease(clip_state
);
1422 wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1424 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1429 restore_icon_state(WScreen
*scr
, proplist_t info
, int type
, int index
)
1432 char *wclass
, *winstance
;
1433 proplist_t cmd
, value
;
1437 cmd
= PLGetDictionaryEntry(info
, dCommand
);
1438 if (!cmd
|| !PLIsString(cmd
)) {
1442 /* parse window name */
1443 value
= PLGetDictionaryEntry(info
, dName
);
1447 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1449 if (!winstance
&& !wclass
) {
1456 command
= wstrdup(PLGetString(cmd
));
1460 if (!command
|| strcmp(command
, "-")==0) {
1471 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
,
1478 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1479 if (type
== WM_CLIP
) {
1480 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1481 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1483 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1484 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1488 cmd
= PLGetDictionaryEntry(info
, dDropCommand
);
1490 aicon
->dnd_command
= wstrdup(PLGetString(cmd
));
1493 /* check auto launch */
1494 value
= PLGetDictionaryEntry(info
, dAutoLaunch
);
1496 aicon
->auto_launch
= 0;
1498 if (PLIsString(value
)) {
1499 if (strcasecmp(PLGetString(value
), "YES")==0)
1500 aicon
->auto_launch
= 1;
1502 wwarning(_("bad value in docked icon state info %s"),
1503 PLGetString(dAutoLaunch
));
1507 /* check if it wasn't normally docked */
1508 value
= PLGetDictionaryEntry(info
, dForced
);
1510 aicon
->forced_dock
= 0;
1512 if (PLIsString(value
)) {
1513 if (strcasecmp(PLGetString(value
), "YES")==0)
1514 aicon
->forced_dock
= 1;
1516 wwarning(_("bad value in docked icon state info %s"),
1517 PLGetString(dForced
));
1521 /* check if we can rely on the stuff in the app */
1522 value
= PLGetDictionaryEntry(info
, dBuggyApplication
);
1524 aicon
->buggy_app
= 0;
1526 if (PLIsString(value
)) {
1527 if (strcasecmp(PLGetString(value
), "YES")==0)
1528 aicon
->buggy_app
= 1;
1530 wwarning(_("bad value in docked icon state info %s"),
1531 PLGetString(dBuggyApplication
));
1535 /* get position in the dock */
1536 value
= PLGetDictionaryEntry(info
, dPosition
);
1537 if (value
&& PLIsString(value
)) {
1538 if (sscanf(PLGetString(value
), "%hi,%hi", &aicon
->xindex
,
1540 wwarning(_("bad value in docked icon state info %s"),
1541 PLGetString(dPosition
));
1543 /* check position sanity */
1544 /* incomplete section! */
1545 if (type
== WM_DOCK
) {
1547 if (aicon
->yindex
< 0)
1548 wwarning(_("bad value in docked icon position %i,%i"),
1549 aicon
->xindex
, aicon
->yindex
);
1552 aicon
->yindex
= index
;
1563 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1567 wClipRestoreState(WScreen
*scr
, proplist_t clip_state
)
1573 icon
= mainIconCreate(scr
, WM_CLIP
);
1578 PLRetain(clip_state
);
1580 /* restore position */
1582 value
= PLGetDictionaryEntry(clip_state
, dPosition
);
1585 if (!PLIsString(value
))
1586 COMPLAIN("Position");
1588 if (sscanf(PLGetString(value
), "%i,%i", &icon
->x_pos
,
1590 COMPLAIN("Position");
1592 /* check position sanity */
1593 if (icon
->y_pos
< 0)
1595 else if (icon
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1596 icon
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1598 if (icon
->x_pos
< 0)
1600 else if (icon
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1601 icon
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1606 value
= PLGetDictionaryEntry(clip_state
, dDropCommand
);
1607 if (value
&& PLIsString(value
))
1608 icon
->dnd_command
= wstrdup(PLGetString(value
));
1611 PLRelease(clip_state
);
1618 wDockRestoreState(WScreen
*scr
, proplist_t dock_state
, int type
)
1623 WAppIcon
*aicon
, *old_top
;
1627 dock
= wDockCreate(scr
, type
);
1633 PLRetain(dock_state
);
1636 /* restore position */
1638 value
= PLGetDictionaryEntry(dock_state
, dPosition
);
1641 if (!PLIsString(value
))
1642 COMPLAIN("Position");
1644 if (sscanf(PLGetString(value
), "%i,%i", &dock
->x_pos
,
1646 COMPLAIN("Position");
1648 /* check position sanity */
1649 if (dock
->y_pos
< 0)
1651 else if (dock
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1652 dock
->y_pos
= scr
->scr_height
- ICON_SIZE
;
1654 /* This is no more needed. ??? */
1655 if (type
== WM_CLIP
) {
1656 if (dock
->x_pos
< 0)
1658 else if (dock
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1659 dock
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1661 if (dock
->x_pos
>= 0) {
1662 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1663 dock
->on_right_side
= 0;
1665 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1666 dock
->on_right_side
= 1;
1672 /* restore lowered/raised state */
1676 value
= PLGetDictionaryEntry(dock_state
, dLowered
);
1679 if (!PLIsString(value
))
1680 COMPLAIN("Lowered");
1682 if (strcasecmp(PLGetString(value
), "YES")==0)
1688 /* restore collapsed state */
1690 dock
->collapsed
= 0;
1692 value
= PLGetDictionaryEntry(dock_state
, dCollapsed
);
1695 if (!PLIsString(value
))
1696 COMPLAIN("Collapsed");
1698 if (strcasecmp(PLGetString(value
), "YES")==0)
1699 dock
->collapsed
= 1;
1704 /* restore auto-collapsed state */
1706 value
= PLGetDictionaryEntry(dock_state
, dAutoCollapse
);
1709 if (!PLIsString(value
))
1710 COMPLAIN("AutoCollapse");
1712 if (strcasecmp(PLGetString(value
), "YES")==0) {
1713 dock
->auto_collapse
= 1;
1714 dock
->collapsed
= 1;
1720 /* restore auto-raise/lower state */
1722 value
= PLGetDictionaryEntry(dock_state
, dAutoRaiseLower
);
1725 if (!PLIsString(value
))
1726 COMPLAIN("AutoRaiseLower");
1728 if (strcasecmp(PLGetString(value
), "YES")==0) {
1729 dock
->auto_raise_lower
= 1;
1735 /* restore attract icons state */
1737 dock
->attract_icons
= 0;
1739 value
= PLGetDictionaryEntry(dock_state
, dAutoAttractIcons
);
1742 if (!PLIsString(value
))
1743 COMPLAIN("AutoAttractIcons");
1745 if (strcasecmp(PLGetString(value
), "YES")==0)
1746 dock
->attract_icons
= 1;
1751 /* restore keep attracted icons state */
1753 dock
->keep_attracted
= 0;
1755 value
= PLGetDictionaryEntry(dock_state
, dKeepAttracted
);
1758 if (!PLIsString(value
))
1759 COMPLAIN("KeepAttracted");
1761 if (strcasecmp(PLGetString(value
), "YES")==0)
1762 dock
->keep_attracted
= 1;
1767 /* application list */
1769 apps
= PLGetDictionaryEntry(dock_state
, dApplications
);
1775 count
= PLGetNumberOfElements(apps
);
1780 old_top
= dock
->icon_array
[0];
1782 /* dock->icon_count is set to 1 when dock is created.
1783 * Since Clip is already restored, we want to keep it so for clip,
1784 * but for dock we may change the default top tile, so we set it to 0.
1786 if (type
== WM_DOCK
)
1787 dock
->icon_count
= 0;
1789 for (i
=0; i
<count
; i
++) {
1790 if (dock
->icon_count
>= dock
->max_icons
) {
1791 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1795 value
= PLGetArrayElement(apps
, i
);
1796 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1798 dock
->icon_array
[dock
->icon_count
] = aicon
;
1802 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
*ICON_SIZE
);
1803 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
*ICON_SIZE
);
1806 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1808 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1810 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
,
1813 if (!dock
->collapsed
)
1814 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1815 wRaiseFrame(aicon
->icon
->core
);
1818 } else if (dock
->icon_count
==0 && type
==WM_DOCK
)
1822 /* if the first icon is not defined, use the default */
1823 if (dock
->icon_array
[0]==NULL
) {
1824 /* update default icon */
1825 old_top
->x_pos
= dock
->x_pos
;
1826 old_top
->y_pos
= dock
->y_pos
;
1828 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1830 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1831 dock
->icon_array
[0] = old_top
;
1832 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1833 /* we don't need to increment dock->icon_count here because it was
1834 * incremented in the loop above.
1836 } else if (old_top
!=dock
->icon_array
[0]) {
1837 if (old_top
== scr
->clip_icon
)
1838 scr
->clip_icon
= dock
->icon_array
[0];
1839 wAppIconDestroy(old_top
);
1844 PLRelease(dock_state
);
1852 wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1854 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1856 btn
->drop_launch
= 0;
1858 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1861 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1873 wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1879 for (i
= 0; i
< dock
->max_icons
; i
++) {
1880 btn
= dock
->icon_array
[i
];
1881 if (!btn
|| !btn
->auto_launch
)
1884 state
= wmalloc(sizeof(WSavedState
));
1885 memset(state
, 0, sizeof(WSavedState
));
1886 state
->workspace
= workspace
;
1887 /* TODO: this is klugy and is very difficult to understand
1888 * what's going on. Try to clean up */
1889 wDockLaunchWithState(dock
, btn
, state
);
1893 #ifdef REDUCE_APPICONS
1895 wDockSimulateLaunch(WDock
*dock
, WAppIcon
*btn
)
1897 if ((btn
== NULL
) || (dock
== NULL
))
1900 if (!btn
->running
) {
1901 if ((btn
->icon
->owner
== NULL
) && (btn
->applist
))
1902 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
1903 if (!btn
->forced_dock
)
1913 findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1919 if ((dock
= scr
->dock
)!=NULL
) {
1920 for (i
=0; i
<dock
->max_icons
; i
++) {
1921 if (dock
->icon_array
[i
]
1922 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1928 if (*icon_pos
<0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
)!=NULL
) {
1929 for (i
=0; i
<dock
->max_icons
; i
++) {
1930 if (dock
->icon_array
[i
]
1931 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1944 wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
1950 dock
= findDock(scr
, event
, &icon_pos
);
1955 * Return True if the drop was on an application icon window.
1956 * In this case, let the ClientMessage handler redirect the
1957 * message to the app.
1959 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!=None
)
1962 if (dock
->icon_array
[icon_pos
]->dnd_command
!=NULL
) {
1963 scr
->flags
.dnd_data_convertion_status
= 0;
1965 btn
= dock
->icon_array
[icon_pos
];
1967 if (!btn
->forced_dock
) {
1968 btn
->relaunching
= btn
->running
;
1971 if (btn
->wm_instance
|| btn
->wm_class
) {
1972 WWindowAttributes attr
;
1973 memset(&attr
, 0, sizeof(WWindowAttributes
));
1974 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
1976 btn
->wm_class
, &attr
, NULL
, True
);
1978 if (!attr
.no_appicon
)
1984 btn
->drop_launch
= 1;
1985 scr
->last_dock
= dock
;
1986 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1991 if (!btn
->relaunching
) {
1998 #endif /* OFFIX_DND */
2003 wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2010 wwin
= icon
->icon
->owner
;
2011 if (icon
->command
==NULL
) {
2013 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2015 icon
->command
= FlattenStringList(argv
, argc
);
2016 XFreeStringList(argv
);
2020 /* icon->forced_dock = 1;*/
2021 if (!icon
->attracted
|| dock
->type
!=WM_CLIP
|| dock
->keep_attracted
) {
2023 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2024 _("Type the command used to launch the application"),
2026 if (command
&& (command
[0]==0 ||
2027 (command
[0]=='-' && command
[1]==0))) {
2031 icon
->command
= command
;
2037 /* If the target is the dock, reject the icon. If
2038 * the target is the clip, make it an attracted icon
2040 if (dock
->type
==WM_CLIP
) {
2041 icon
->attracted
= 1;
2042 if (!icon
->icon
->shadowed
) {
2043 icon
->icon
->shadowed
= 1;
2044 icon
->icon
->force_paint
= 1;
2056 for (index
=1; index
<dock
->max_icons
; index
++)
2057 if (dock
->icon_array
[index
] == NULL
)
2059 /* if (index == dock->max_icons)
2062 assert(index
< dock
->max_icons
);
2064 dock
->icon_array
[index
] = icon
;
2068 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2069 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2074 icon
->launching
= 0;
2077 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2078 if (dock
->type
== WM_CLIP
) {
2079 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2080 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2082 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2083 icon
->icon
->core
->descriptor
.parent
= icon
;
2085 MoveInStackListUnder(dock
->icon_array
[index
-1]->icon
->core
,
2087 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2088 wAppIconPaint(icon
);
2090 if (wPreferences
.auto_arrange_icons
)
2091 wArrangeIcons(dock
->screen_ptr
, True
);
2094 if (icon
->command
&& !icon
->dnd_command
) {
2095 icon
->dnd_command
= wmalloc(strlen(icon
->command
)+8);
2096 sprintf(icon
->dnd_command
, "%s %%d", icon
->command
);
2105 reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2109 for(index
=1; index
<dock
->max_icons
; index
++) {
2110 if(dock
->icon_array
[index
] == icon
)
2113 assert(index
< dock
->max_icons
);
2118 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2119 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2124 moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2134 wwin
= icon
->icon
->owner
;
2137 * For the moment we can't do this if we move icons in Clip from one
2138 * workspace to other, because if we move two or more icons without
2139 * command, the dialog box will not be able to tell us to which of the
2140 * moved icons it applies. -Dan
2142 if ((dest
->type
==WM_DOCK
/*|| dest->keep_attracted*/) && icon
->command
==NULL
) {
2143 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2145 icon
->command
= FlattenStringList(argv
, argc
);
2146 XFreeStringList(argv
);
2151 /* icon->forced_dock = 1;*/
2152 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2153 _("Type the command used to launch the application"),
2155 if (command
&& (command
[0]==0 ||
2156 (command
[0]=='-' && command
[1]==0))) {
2160 icon
->command
= command
;
2171 for(index
=1; index
<src
->max_icons
; index
++) {
2172 if(src
->icon_array
[index
] == icon
)
2175 assert(index
< src
->max_icons
);
2177 src
->icon_array
[index
] = NULL
;
2180 for(index
=1; index
<dest
->max_icons
; index
++) {
2181 if(dest
->icon_array
[index
] == NULL
)
2184 /* if (index == dest->max_icons)
2187 assert(index
< dest
->max_icons
);
2189 dest
->icon_array
[index
] = icon
;
2192 /* deselect the icon */
2193 if (icon
->icon
->selected
)
2194 wIconSelect(icon
->icon
);
2196 if (dest
->type
== WM_DOCK
) {
2197 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2198 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2200 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2201 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2204 /* set it to be kept when moving to dock, or to a clip that keep the
2206 * Unless the icon does not have a command set
2208 if (icon
->command
&& (dest
->type
==WM_DOCK
|| dest
->keep_attracted
)) {
2209 icon
->attracted
= 0;
2210 if (icon
->icon
->shadowed
) {
2211 icon
->icon
->shadowed
= 0;
2212 icon
->icon
->force_paint
= 1;
2216 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2222 icon
->x_pos
= dest
->x_pos
+ x
*ICON_SIZE
;
2223 icon
->y_pos
= dest
->y_pos
+ y
*ICON_SIZE
;
2227 MoveInStackListUnder(dest
->icon_array
[index
-1]->icon
->core
,
2229 wAppIconPaint(icon
);
2236 wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2240 /* make the settings panel be closed */
2242 DestroyDockAppSettingsPanel(icon
->panel
);
2247 icon
->attracted
= 0;
2248 if (icon
->icon
->shadowed
) {
2249 icon
->icon
->shadowed
= 0;
2250 icon
->icon
->force_paint
= 1;
2253 /* deselect the icon */
2254 if (icon
->icon
->selected
)
2255 wIconSelect(icon
->icon
);
2257 if (icon
->command
) {
2258 free(icon
->command
);
2259 icon
->command
= NULL
;
2262 if (icon
->dnd_command
) {
2263 free(icon
->dnd_command
);
2264 icon
->dnd_command
= NULL
;
2268 for (index
=1; index
<dock
->max_icons
; index
++)
2269 if (dock
->icon_array
[index
] == icon
)
2271 assert(index
< dock
->max_icons
);
2272 dock
->icon_array
[index
] = NULL
;
2277 /* if the dock is not attached to an application or
2278 * the the application did not set the approriate hints yet,
2279 * destroy the icon */
2280 #ifdef REDUCE_APPICONS
2281 if ((icon
->num_apps
== 0) && (!icon
->running
|| !wApplicationOf(icon
->main_window
)) )
2283 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2285 wAppIconDestroy(icon
);
2287 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2288 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2289 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2290 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2291 icon
->icon
->core
->descriptor
.parent
= icon
;
2293 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2295 wAppIconPaint(icon
);
2296 if (wPreferences
.auto_arrange_icons
) {
2297 wArrangeIcons(dock
->screen_ptr
, True
);
2300 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2306 * returns the closest Dock slot index for the passed
2309 * Returns False if icon can't be docked.
2312 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2313 int *ret_x
, int *ret_y
, int redocking
)
2315 WScreen
*scr
= dock
->screen_ptr
;
2318 int i
, offset
= ICON_SIZE
/2;
2319 WAppIcon
*aicon
= NULL
;
2320 WAppIcon
*nicon
= NULL
;
2321 int max_y_icons
, max_x_icons
;
2323 max_x_icons
= scr
->scr_width
/ICON_SIZE
;
2324 max_y_icons
= scr
->scr_height
/ICON_SIZE
-1;
2326 if (wPreferences
.flags
.noupdates
)
2332 /* if the dock is full */
2334 (dock
->icon_count
>= dock
->max_icons
)) {
2338 /* exact position */
2340 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2342 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2345 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2347 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2349 /* check if the icon is outside the screen boundaries */
2350 if (dx
+ ex_x
*ICON_SIZE
< -ICON_SIZE
+2 ||
2351 dx
+ ex_x
*ICON_SIZE
>= scr
->scr_width
-1 ||
2352 dy
+ ex_y
*ICON_SIZE
< -ICON_SIZE
+2 ||
2353 dy
+ ex_y
*ICON_SIZE
>= scr
->scr_height
-1)
2356 if (dock
->type
== WM_DOCK
) {
2357 if (icon
->dock
!= dock
&& ex_x
!= 0)
2360 for (i
=0; i
<dock
->max_icons
; i
++) {
2361 nicon
= dock
->icon_array
[i
];
2362 if (nicon
&& nicon
->yindex
== ex_y
) {
2371 int sig
, done
, closest
;
2373 /* Possible cases when redocking:
2375 * icon dragged out of range of any slot -> false
2376 * icon dragged to range of free slot
2377 * icon dragged to range of same slot
2378 * icon dragged to range of different icon
2380 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2383 if (ex_y
>= 0 && ex_y
<= max_y_icons
&& (aicon
== icon
|| !aicon
)) {
2391 /* start looking at the upper slot or lower? */
2392 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2399 /* look for closest free slot */
2400 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2404 closest
= sig
*(i
/2) + ex_y
;
2405 /* check if this slot is used */
2407 for (j
= 0; j
<dock
->max_icons
; j
++) {
2408 if (dock
->icon_array
[j
]
2409 && dock
->icon_array
[j
]->yindex
==closest
) {
2410 /* slot is used by someone else */
2411 if (dock
->icon_array
[j
]!=icon
)
2419 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2420 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2422 (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+1))) {
2428 } else { /* !redocking */
2430 /* if slot is free and the icon is close enough, return it */
2431 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2439 for (i
=0; i
<dock
->max_icons
; i
++) {
2440 nicon
= dock
->icon_array
[i
];
2441 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2447 for (i
=0; i
<dock
->max_icons
; i
++) {
2448 nicon
= dock
->icon_array
[i
];
2449 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2450 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2451 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2457 if (neighbours
&& (aicon
==NULL
|| (redocking
&& aicon
== icon
))) {
2466 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2467 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2469 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2470 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2471 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2475 * returns true if it can find a free slot in the dock,
2476 * in which case it changes x_pos and y_pos accordingly.
2477 * Else returns false.
2480 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2482 WScreen
*scr
= dock
->screen_ptr
;
2484 unsigned char *slot_map
;
2488 int i
, done
= False
;
2490 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2493 /* if the dock is full */
2494 if (dock
->icon_count
>= dock
->max_icons
) {
2498 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2499 if (scr
->dock
->on_right_side
)
2500 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2502 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2505 if (ex
< dock
->x_pos
)
2507 if (sx
> dock
->x_pos
+ICON_SIZE
)
2508 sx
= dock
->x_pos
+ICON_SIZE
;
2515 /* check if clip is in a corner */
2516 if (dock
->type
==WM_CLIP
) {
2517 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2519 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2521 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2523 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2530 /* If the clip is in the corner, use only slots that are in the border
2532 if (corner
!=C_NONE
) {
2536 hcount
= MIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2537 vcount
= MIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2538 hmap
= wmalloc(hcount
+1);
2539 memset(hmap
, 0, hcount
+1);
2540 vmap
= wmalloc(vcount
+1);
2541 memset(vmap
, 0, vcount
+1);
2543 /* mark used positions */
2546 for (i
=0; i
<dock
->max_icons
; i
++) {
2547 btn
= dock
->icon_array
[i
];
2551 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2552 vmap
[btn
->yindex
] = 1;
2553 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2554 hmap
[btn
->xindex
] = 1;
2557 for (i
=0; i
<dock
->max_icons
; i
++) {
2558 btn
= dock
->icon_array
[i
];
2562 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2563 vmap
[btn
->yindex
] = 1;
2564 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2565 hmap
[-btn
->xindex
] = 1;
2568 for (i
=0; i
<dock
->max_icons
; i
++) {
2569 btn
= dock
->icon_array
[i
];
2573 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2574 vmap
[-btn
->yindex
] = 1;
2575 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2576 hmap
[btn
->xindex
] = 1;
2580 for (i
=0; i
<dock
->max_icons
; i
++) {
2581 btn
= dock
->icon_array
[i
];
2585 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2586 vmap
[-btn
->yindex
] = 1;
2587 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2588 hmap
[-btn
->xindex
] = 1;
2593 /* search a vacant slot */
2594 for (i
=1; i
<MAX(vcount
, hcount
); i
++) {
2595 if (i
< vcount
&& vmap
[i
]==0) {
2601 } else if (i
< hcount
&& hmap
[i
]==0) {
2611 /* If found a slot, translate and return */
2613 if (corner
==C_NW
|| corner
==C_NE
) {
2618 if (corner
==C_NE
|| corner
==C_SE
) {
2625 /* else, try to find a slot somewhere else */
2628 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2629 * placed outside of screen */
2630 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2632 /* In the worst case (the clip is in the corner of the screen),
2633 * the amount of icons that fit in the clip is smaller.
2634 * Double the map to get a safe value.
2640 slot_map
= wmalloc(mwidth
*mwidth
);
2641 memset(slot_map
, 0, mwidth
*mwidth
);
2643 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2645 /* mark used slots in the map. If the slot falls outside the map
2646 * (for example, when all icons are placed in line), ignore them. */
2647 for (i
=0; i
<dock
->max_icons
; i
++) {
2648 btn
= dock
->icon_array
[i
];
2650 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2652 /* Find closest slot from the center that is free by scanning the
2653 * map from the center to outward in circular passes.
2654 * This will not result in a neat layout, but will be optimal
2655 * in the sense that there will not be holes left.
2658 for (i
= 1; i
<= r
&& !done
; i
++) {
2661 /* top and bottom parts of the ring */
2662 for (x
= -i
; x
<= i
&& !done
; x
++) {
2663 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2665 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2666 if (slot_map
[XY2OFS(x
,y
)]==0
2667 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2674 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2675 if (slot_map
[XY2OFS(x
,y
)]==0
2676 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2683 /* left and right parts of the ring */
2684 for (y
= -i
+1; y
<= i
-1; y
++) {
2685 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2687 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2688 if (slot_map
[XY2OFS(x
,y
)]==0
2689 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2696 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2697 if (slot_map
[XY2OFS(x
,y
)]==0
2698 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2713 moveDock(WDock
*dock
, int new_x
, int new_y
)
2718 dock
->x_pos
= new_x
;
2719 dock
->y_pos
= new_y
;
2720 for (i
=0; i
<dock
->max_icons
; i
++) {
2721 btn
= dock
->icon_array
[i
];
2723 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2724 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2725 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2732 swapDock(WDock
*dock
)
2734 WScreen
*scr
= dock
->screen_ptr
;
2739 if (dock
->on_right_side
) {
2740 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2742 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2745 for (i
=0; i
<dock
->max_icons
; i
++) {
2746 btn
= dock
->icon_array
[i
];
2749 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2753 wScreenUpdateUsableArea(scr
);
2758 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2760 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2766 cmdline
= ExpandOptions(scr
, command
);
2768 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2776 ParseCommand(cmdline
, &argv
, &argc
);
2786 if ((pid
=fork())==0) {
2790 SetupEnvironment(scr
);
2796 args
= malloc(sizeof(char*)*(argc
+1));
2799 for (i
=0; i
<argc
; i
++) {
2803 execvp(argv
[0], args
);
2812 state
= wmalloc(sizeof(WSavedState
));
2813 memset(state
, 0, sizeof(WSavedState
));
2815 state
->miniaturized
= -1;
2817 if (btn
->dock
== scr
->dock
)
2818 state
->workspace
= -1;
2820 state
->workspace
= scr
->current_workspace
;
2822 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
2824 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
2835 wDockHideIcons(WDock
*dock
)
2843 btn
= dock
->icon_array
[0];
2845 for (i
=1; i
<dock
->max_icons
; i
++) {
2846 if (dock
->icon_array
[i
])
2847 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2856 wDockShowIcons(WDock
*dock
)
2864 btn
= dock
->icon_array
[0];
2865 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2867 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2868 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2870 for (i
=1; i
<dock
->max_icons
; i
++) {
2871 if (dock
->icon_array
[i
]) {
2872 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
2878 if (!dock
->collapsed
) {
2879 for (i
=1; i
<dock
->max_icons
; i
++) {
2880 if (dock
->icon_array
[i
]) {
2881 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2892 wDockLower(WDock
*dock
)
2896 for (i
=0; i
<dock
->max_icons
; i
++) {
2897 if (dock
->icon_array
[i
])
2898 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2904 wDockRaise(WDock
*dock
)
2908 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
2909 if (dock
->icon_array
[i
])
2910 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2916 wDockRaiseLower(WDock
*dock
)
2918 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2919 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2920 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2928 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
2930 icon
->launching
= 0;
2931 icon
->relaunching
= 0;
2932 dockIconPaint(icon
);
2937 wDockFindIconFor(WDock
*dock
, Window window
)
2942 for (i
=0; i
<dock
->max_icons
; i
++) {
2943 icon
= dock
->icon_array
[i
];
2944 if (icon
&& icon
->main_window
== window
)
2952 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
2955 #ifdef REDUCE_APPICONS
2956 WAppIconAppList
*tapplist
;
2958 char *wm_class
, *wm_instance
;
2960 Bool firstPass
= True
;
2962 char *command
= NULL
;
2968 if (XGetCommand(dpy
, window
, &argv
, &argc
)) {
2969 if (argc
> 0 && argv
!= NULL
)
2970 command
= FlattenStringList(argv
,argc
);
2972 XFreeStringList(argv
);
2977 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
2978 (!wm_class
&& !wm_instance
))
2982 for (i
=0; i
<dock
->max_icons
; i
++) {
2983 icon
= dock
->icon_array
[i
];
2987 /* app is already attached to icon */
2988 if (icon
->main_window
== window
) {
2993 if ((icon
->wm_instance
|| icon
->wm_class
)
2995 || (dock
->screen_ptr
->flags
.startup
&& !icon
->running
))) {
2997 if (icon
->wm_instance
&& wm_instance
&&
2998 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
3001 if (icon
->wm_class
&& wm_class
&&
3002 strcmp(icon
->wm_class
, wm_class
)!=0) {
3005 if (firstPass
&& command
&& strcmp(icon
->command
, command
)!=0) {
3009 if (!icon
->relaunching
) {
3012 /* Possibly an application that was docked with dockit,
3013 * but the user did not update WMState to indicate that
3014 * it was docked by force */
3015 wapp
= wApplicationOf(window
);
3017 icon
->forced_dock
= 1;
3020 if (!icon
->forced_dock
)
3021 icon
->main_window
= window
;
3023 #ifdef REDUCE_APPICONS
3024 tapplist
= wmalloc(sizeof(WAppIconAppList
));
3025 memset(tapplist
, 0, sizeof(WAppIconAppList
));
3026 tapplist
->next
= icon
->applist
;
3028 icon
->applist
->prev
= tapplist
;
3029 icon
->applist
= tapplist
;
3030 tapplist
->wapp
= wApplicationOf(window
);
3035 wDockFinishLaunch(dock
, icon
);
3040 if (firstPass
&& !found
) {
3057 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3059 if (!wPreferences
.flags
.noclip
) {
3060 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3061 if (scr
->current_workspace
!= workspace
) {
3062 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3064 wDockHideIcons(old_clip
);
3065 if (old_clip
->auto_raise_lower
) {
3066 if (old_clip
->auto_raise_magic
) {
3067 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3068 old_clip
->auto_raise_magic
= NULL
;
3070 wDockLower(old_clip
);
3072 if (old_clip
->auto_collapse
) {
3073 if (old_clip
->auto_expand_magic
) {
3074 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3075 old_clip
->auto_expand_magic
= NULL
;
3077 old_clip
->collapsed
= 1;
3079 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3081 if (scr
->flags
.clip_balloon_mapped
)
3082 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3089 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3094 for (i
=0; i
<dock
->max_icons
; i
++) {
3095 icon
= dock
->icon_array
[i
];
3099 if (icon
->launching
&& icon
->pid
== pid
) {
3100 if (!icon
->relaunching
) {
3102 icon
->main_window
= None
;
3104 wDockFinishLaunch(dock
, icon
);
3109 sprintf(msg
, _("Could not execute command \"%s\""),
3110 icon
->drop_launch
&& icon
->dnd_command
3111 ? icon
->dnd_command
: icon
->command
);
3113 sprintf(msg
, _("Could not execute command \"%s\""),
3116 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
3117 _("OK"), NULL
, NULL
);
3126 toggleLowered(WDock
*dock
)
3131 /* lower/raise Dock */
3132 if (!dock
->lowered
) {
3133 newlevel
= WMNormalLevel
;
3136 newlevel
= WMDockLevel
;
3140 for (i
=0; i
<dock
->max_icons
; i
++) {
3141 tmp
= dock
->icon_array
[i
];
3145 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3147 wLowerFrame(tmp
->icon
->core
);
3150 if (dock
->type
== WM_DOCK
)
3151 wScreenUpdateUsableArea(dock
->screen_ptr
);
3156 toggleCollapsed(WDock
*dock
)
3158 if (dock
->collapsed
) {
3159 dock
->collapsed
= 0;
3160 wDockShowIcons(dock
);
3163 dock
->collapsed
= 1;
3164 wDockHideIcons(dock
);
3170 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3172 WScreen
*scr
= dock
->screen_ptr
;
3173 WObjDescriptor
*desc
;
3175 WApplication
*wapp
= NULL
;
3178 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3180 if (dock
->type
== WM_DOCK
) {
3182 entry
= dock
->menu
->entries
[index
];
3183 entry
->flags
.indicator_on
= !dock
->lowered
;
3184 entry
->clientdata
= dock
;
3187 if (scr
->clip_options
)
3188 updateClipOptionsMenu(scr
->clip_options
, dock
);
3190 /* Rename Workspace */
3191 entry
= dock
->menu
->entries
[++index
];
3192 entry
->clientdata
= dock
;
3195 entry
= dock
->menu
->entries
[++index
];
3196 entry
->clientdata
= aicon
;
3197 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3199 /* (un)select all icons */
3200 entry
= dock
->menu
->entries
[++index
];
3201 entry
->clientdata
= aicon
;
3202 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3205 entry
= dock
->menu
->entries
[++index
];
3206 entry
->clientdata
= aicon
;
3207 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3209 /* this is the workspace submenu part */
3210 if (scr
->clip_submenu
)
3211 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3214 /* remove icon(s) */
3215 entry
= dock
->menu
->entries
[++index
];
3216 entry
->clientdata
= aicon
;
3217 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3219 /* attract icon(s) */
3220 entry
= dock
->menu
->entries
[++index
];
3221 entry
->clientdata
= aicon
;
3225 entry
= dock
->menu
->entries
[++index
];
3226 entry
->clientdata
= aicon
;
3227 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3230 entry
= dock
->menu
->entries
[++index
];
3231 entry
->clientdata
= aicon
;
3232 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3235 entry
= dock
->menu
->entries
[++index
];
3236 entry
->clientdata
= aicon
;
3237 if (aicon
->icon
->owner
) {
3238 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3239 if (wapp
&& wapp
->flags
.hidden
)
3240 entry
->text
= _("Unhide");
3242 entry
->text
= _("Hide");
3244 entry
->text
= _("Hide");
3246 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3249 entry
= dock
->menu
->entries
[++index
];
3250 entry
->clientdata
= aicon
;
3251 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
3252 && !wPreferences
.flags
.noupdates
);
3255 entry
= dock
->menu
->entries
[++index
];
3256 entry
->clientdata
= aicon
;
3257 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3259 if (!dock
->menu
->flags
.realized
)
3260 wMenuRealize(dock
->menu
);
3262 if (dock
->type
== WM_CLIP
) {
3263 x_pos
= event
->xbutton
.x_root
+2;
3265 x_pos
= dock
->on_right_side
?
3266 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 2 : 0;
3269 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3271 /* allow drag select */
3272 event
->xany
.send_event
= True
;
3273 desc
= &dock
->menu
->menu
->descriptor
;
3274 (*desc
->handle_mousedown
)(desc
, event
);
3279 openClipWorkspaceMenu(WScreen
*scr
, int x
, int y
)
3281 if (!scr
->clip_ws_menu
) {
3282 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3284 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
3285 wMenuMapAt(scr
->clip_ws_menu
, x
, y
, False
);
3289 /******************************************************************/
3291 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3293 WAppIcon
*btn
= desc
->parent
;
3294 WDock
*dock
= btn
->dock
;
3295 WApplication
*wapp
= NULL
;
3298 #ifdef REDUCE_APPICONS
3299 if ((btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) ||
3300 ((btn
->icon
->owner
== NULL
) && (btn
->applist
!= NULL
))) {
3301 if (btn
->icon
->owner
== NULL
)
3302 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
3307 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3309 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3313 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3315 /* go to the last workspace that the user worked on the app */
3316 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
3318 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3321 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3324 if (event
->xbutton
.state
& MOD_MASK
) {
3325 wHideOtherApplications(btn
->icon
->owner
);
3328 if (event
->xbutton
.button
==Button1
) {
3330 if (event
->xbutton
.state
& MOD_MASK
) {
3331 /* raise/lower dock */
3332 toggleLowered(dock
);
3333 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3334 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3335 toggleCollapsed(dock
);
3337 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3338 } else if (btn
->command
) {
3339 if (!btn
->launching
&&
3340 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3341 launchDockedApplication(btn
);
3350 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3352 WScreen
*scr
= dock
->screen_ptr
;
3353 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3356 int grabbed
= 0, swapped
= 0, done
;
3357 Pixmap ghost
= None
;
3358 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3361 puts("moving dock");
3363 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3364 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3365 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3366 wwarning("pointer grab failed for dock move");
3369 for (x
=0; x
<dock
->max_icons
; x
++) {
3370 if (dock
->icon_array
[x
]!=NULL
&&
3371 dock
->icon_array
[x
]->yindex
> y
)
3372 y
= dock
->icon_array
[x
]->yindex
;
3375 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3379 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3380 |ButtonMotionMask
|ExposureMask
, &ev
);
3388 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3389 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3390 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3391 |ButtonReleaseMask
|ButtonPressMask
,
3392 wCursor
[WCUR_MOVE
], CurrentTime
);
3397 if (dock
->type
== WM_CLIP
) {
3398 if (ev
.xmotion
.x_root
- ofs_x
< 0) {
3400 } else if (ev
.xmotion
.x_root
- ofs_x
+ ICON_SIZE
>
3402 x
= scr
->scr_width
- ICON_SIZE
;
3404 x
= ev
.xmotion
.x_root
- ofs_x
;
3406 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3408 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3410 y
= scr
->scr_height
- ICON_SIZE
;
3412 y
= ev
.xmotion
.y_root
- ofs_y
;
3414 moveDock(dock
, x
, y
);
3416 /* move vertically if pointer is inside the dock*/
3417 if ((dock
->on_right_side
&&
3418 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3419 || (!dock
->on_right_side
&&
3420 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3422 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3424 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3426 y
= scr
->scr_height
- ICON_SIZE
;
3428 y
= ev
.xmotion
.y_root
- ofs_y
;
3430 moveDock(dock
, dock
->x_pos
, y
);
3432 /* move horizontally to change sides */
3433 x
= ev
.xmotion
.x_root
- ofs_x
;
3434 if (!dock
->on_right_side
) {
3438 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3439 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3440 -DOCK_EXTRA_SPACE
-1, dock
->y_pos
);
3443 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3444 scr
->scr_width
-ICON_SIZE
3445 -DOCK_EXTRA_SPACE
-1,
3447 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3449 XClearWindow(dpy
, scr
->dock_shadow
);
3452 XMapRaised(dpy
, scr
->dock_shadow
);
3455 if (superfluous
&& ghost
!=None
) {
3456 XFreePixmap(dpy
, ghost
);
3459 XUnmapWindow(dpy
, scr
->dock_shadow
);
3464 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3465 XMoveWindow(dpy
, scr
->dock_shadow
,
3466 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3469 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3470 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3471 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3473 XClearWindow(dpy
, scr
->dock_shadow
);
3476 XMapRaised(dpy
, scr
->dock_shadow
);
3479 XUnmapWindow(dpy
, scr
->dock_shadow
);
3481 if (superfluous
&& ghost
!=None
) {
3482 XFreePixmap(dpy
, ghost
);
3494 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3496 XUngrabPointer(dpy
, CurrentTime
);
3497 XUnmapWindow(dpy
, scr
->dock_shadow
);
3498 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3499 if (dock
->type
== WM_DOCK
) {
3502 dock
->on_right_side
= 1;
3504 dock
->on_right_side
= 0;
3506 wArrangeIcons(scr
, False
);
3515 XFreePixmap(dpy
, ghost
);
3516 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3519 puts("End dock move");
3526 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3528 WScreen
*scr
= dock
->screen_ptr
;
3530 WIcon
*icon
= aicon
->icon
;
3531 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3532 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3534 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3535 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3536 int shad_x
= x
, shad_y
= y
;
3537 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3539 Pixmap ghost
= None
;
3541 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3543 if (wPreferences
.flags
.noupdates
)
3546 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3547 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3548 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3550 wwarning("pointer grab failed for icon move");
3554 wRaiseFrame(icon
->core
);
3556 if (!wPreferences
.flags
.noclip
)
3557 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3559 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3561 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3564 wins
[0] = icon
->core
->window
;
3565 wins
[1] = scr
->dock_shadow
;
3566 XRestackWindows(dpy
, wins
, 2);
3567 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3568 ICON_SIZE
, ICON_SIZE
);
3570 if (icon
->pixmap
!=None
)
3571 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3573 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3575 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3576 XClearWindow(dpy
, scr
->dock_shadow
);
3578 XMapWindow(dpy
, scr
->dock_shadow
);
3584 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3585 |ButtonMotionMask
|ExposureMask
, &ev
);
3593 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3594 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3595 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3596 |ButtonReleaseMask
|ButtonPressMask
,
3597 wCursor
[WCUR_MOVE
], CurrentTime
);
3604 x
= ev
.xmotion
.x_root
- ofs_x
;
3605 y
= ev
.xmotion
.y_root
- ofs_y
;
3606 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3609 if (last_dock
!= dock
&& collapsed
) {
3610 last_dock
->collapsed
= 1;
3611 wDockHideIcons(last_dock
);
3614 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3615 dock
->collapsed
= 0;
3616 wDockShowIcons(dock
);
3618 if (dock
->auto_raise_lower
)
3623 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3626 if (last_dock
!= dock2
&& collapsed
) {
3627 last_dock
->collapsed
= 1;
3628 wDockHideIcons(last_dock
);
3631 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3632 dock2
->collapsed
= 0;
3633 wDockShowIcons(dock2
);
3635 if (dock2
->auto_raise_lower
)
3640 if (aicon
->launching
3641 || (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3642 || (!aicon
->running
&& tmp
)) {
3643 shad_x
= last_dock
->x_pos
+ ix
*wPreferences
.icon_size
;
3644 shad_y
= last_dock
->y_pos
+ iy
*wPreferences
.icon_size
;
3646 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3649 XMapWindow(dpy
, scr
->dock_shadow
);
3651 if (!collapsed
&& (collapsed
= last_dock
->collapsed
)) {
3652 last_dock
->collapsed
= 0;
3653 wDockShowIcons(last_dock
);
3660 XUnmapWindow(dpy
, scr
->dock_shadow
);
3662 if (last_dock
&& collapsed
&&
3663 aicon
->running
&& (ev
.xmotion
.state
& MOD_MASK
)) {
3664 last_dock
->collapsed
= 1;
3665 wDockHideIcons(last_dock
);
3672 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3679 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3681 XUngrabPointer(dpy
, CurrentTime
);
3683 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3684 XUnmapWindow(dpy
, scr
->dock_shadow
);
3686 reattachIcon(dock
, aicon
, ix
, iy
);
3687 if (clip
&& dock
!=clip
&& clip
->auto_raise_lower
)
3690 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3692 /* Slide it back if dock rejected it */
3693 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3695 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3697 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3705 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3706 /* We need to deselect it, even if is deselected in
3707 * wDockDetach(), because else DoKaboom() will fail.
3709 if (aicon
->icon
->selected
)
3710 wIconSelect(aicon
->icon
);
3711 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3714 if (clip
&& clip
->auto_raise_lower
)
3716 wDockDetach(dock
, aicon
);
3719 last_dock
->collapsed
= 1;
3720 wDockHideIcons(last_dock
);
3725 XFreePixmap(dpy
, ghost
);
3726 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3729 puts("End icon move");
3738 getClipButton(int px
, int py
)
3740 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
3742 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3745 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
3746 return CLIP_FORWARD
;
3747 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
3755 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3758 int done
, direction
, new_ws
;
3760 WDock
*clip
= scr
->clip_icon
->dock
;
3762 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3764 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3765 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3767 wClipIconPaint(scr
->clip_icon
);
3770 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
3771 |ButtonPressMask
, &ev
);
3778 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3779 if (new_dir
!= direction
) {
3780 direction
= new_dir
;
3781 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3782 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3783 wClipIconPaint(scr
->clip_icon
);
3791 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3796 clip
->lclip_button_pushed
= 0;
3797 clip
->rclip_button_pushed
= 0;
3799 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3801 if (direction
== CLIP_FORWARD
) {
3802 if (scr
->current_workspace
< scr
->workspace_count
-1)
3803 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3804 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
3805 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3806 else if (wPreferences
.ws_cycle
)
3807 wWorkspaceChange(scr
, 0);
3809 else if (direction
== CLIP_REWIND
) {
3810 if (scr
->current_workspace
> 0)
3811 wWorkspaceChange(scr
, scr
->current_workspace
-1);
3812 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
3813 wWorkspaceChange(scr
, scr
->workspace_count
-1);
3816 wClipIconPaint(scr
->clip_icon
);
3821 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3823 WAppIcon
*aicon
= desc
->parent
;
3824 WDock
*dock
= aicon
->dock
;
3825 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3827 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3830 scr
->last_dock
= dock
;
3832 if (dock
->menu
->flags
.mapped
)
3833 wMenuUnmap(dock
->menu
);
3835 if (IsDoubleClick(scr
, event
)) {
3836 /* double-click was not in the main clip icon */
3837 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
3838 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
3839 iconDblClick(desc
, event
);
3844 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
3845 XUnmapWindow(dpy
, scr
->clip_balloon
);
3846 scr
->flags
.clip_balloon_mapped
= 0;
3850 puts("handling dock");
3852 if (event
->xbutton
.button
== Button1
) {
3853 if (event
->xbutton
.state
& MOD_MASK
)
3858 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
3859 dock
->type
!=WM_DOCK
) {
3860 wIconSelect(aicon
->icon
);
3864 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
3865 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
3866 && dock
->type
==WM_CLIP
)
3867 handleClipChangeWorkspace(scr
, event
);
3869 handleDockMove(dock
, aicon
, event
);
3871 handleIconMove(dock
, aicon
, event
);
3873 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
3874 aicon
->xindex
==0 && aicon
->yindex
==0) {
3875 openClipWorkspaceMenu(scr
, event
->xbutton
.x_root
+2,
3876 event
->xbutton
.y_root
+2);
3877 if (scr
->clip_ws_menu
) {
3879 menu
= scr
->clip_ws_menu
;
3880 desc
= &menu
->menu
->descriptor
;
3882 event
->xany
.send_event
= True
;
3883 (*desc
->handle_mousedown
)(desc
, event
);
3885 } else if (event
->xbutton
.button
== Button3
) {
3886 openDockMenu(dock
, aicon
, event
);
3892 showClipBalloon(WDock
*dock
, int workspace
)
3896 WScreen
*scr
= dock
->screen_ptr
;
3900 scr
->flags
.clip_balloon_mapped
= 1;
3901 XMapWindow(dpy
, scr
->clip_balloon
);
3903 text
= scr
->workspaces
[workspace
]->name
;
3905 w
= wTextWidth(scr
->clip_title_font
->font
, text
, strlen(text
));
3907 h
= scr
->clip_title_font
->height
;
3908 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
3910 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
3911 y
= dock
->y_pos
+ ICON_SIZE
-scr
->clip_title_font
->height
- 3;
3913 if (x
+w
> scr
->scr_width
) {
3914 x
= scr
->scr_width
- w
;
3915 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
3916 y
= dock
->y_pos
- h
- 1;
3918 y
= dock
->y_pos
+ ICON_SIZE
;
3919 XRaiseWindow(dpy
, scr
->clip_balloon
);
3921 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
3922 stack
[1] = scr
->clip_balloon
;
3923 XRestackWindows(dpy
, stack
, 2);
3925 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
3926 XSetForeground(dpy
, scr
->clip_title_gc
,
3927 scr
->clip_title_pixel
[CLIP_NORMAL
]);
3928 XClearWindow(dpy
, scr
->clip_balloon
);
3929 wDrawString(scr
->clip_balloon
, scr
->clip_title_font
, scr
->clip_title_gc
,
3930 0, scr
->clip_title_font
->y
, text
, strlen(text
));
3935 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3937 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
3940 assert(event
->type
==EnterNotify
);
3942 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
3946 if (!dock
|| dock
->type
!=WM_CLIP
)
3949 /* The auto raise/lower code */
3950 if (dock
->auto_lower_magic
) {
3951 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3952 dock
->auto_lower_magic
= NULL
;
3954 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
3955 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
,
3960 /* The auto expand/collapse code */
3961 if (dock
->auto_collapse_magic
) {
3962 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3963 dock
->auto_collapse_magic
= NULL
;
3965 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
3966 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
,
3971 if (btn
->xindex
== 0 && btn
->yindex
== 0)
3972 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
3974 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
3975 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
3976 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
3983 clipLeave(WDock
*dock
)
3986 WObjDescriptor
*desc
= NULL
;
3988 if (!dock
|| dock
->type
!=WM_CLIP
)
3991 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
)!=False
) {
3992 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3993 (XPointer
*)&desc
)!=XCNOENT
3994 && desc
&& desc
->parent_type
==WCLASS_DOCK_ICON
3995 && ((WAppIcon
*)desc
->parent
)->dock
3996 && ((WAppIcon
*)desc
->parent
)->dock
->type
==WM_CLIP
) {
3997 /* We didn't left the Clip yet */
3998 XPutBackEvent(dpy
, &event
);
4002 XPutBackEvent(dpy
, &event
);
4004 /* We entered a withdrawn window, so we're still in Clip */
4008 if (dock
->auto_raise_magic
) {
4009 WMDeleteTimerHandler(dock
->auto_raise_magic
);
4010 dock
->auto_raise_magic
= NULL
;
4012 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
4013 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
,
4018 if (dock
->auto_expand_magic
) {
4019 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4020 dock
->auto_expand_magic
= NULL
;
4022 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
4023 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
4031 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4033 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4035 assert(event
->type
==LeaveNotify
);
4037 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4040 clipLeave(btn
->dock
);
4045 clipAutoCollapse(void *cdata
)
4047 WDock
*dock
= (WDock
*)cdata
;
4049 if (dock
->type
!=WM_CLIP
)
4052 if (dock
->auto_collapse
) {
4053 dock
->collapsed
= 1;
4054 wDockHideIcons(dock
);
4056 dock
->auto_collapse_magic
= NULL
;
4061 clipAutoExpand(void *cdata
)
4063 WDock
*dock
= (WDock
*)cdata
;
4065 if (dock
->type
!=WM_CLIP
)
4068 if (dock
->auto_collapse
) {
4069 dock
->collapsed
= 0;
4070 wDockShowIcons(dock
);
4072 dock
->auto_expand_magic
= NULL
;
4077 clipAutoLower(void *cdata
)
4079 WDock
*dock
= (WDock
*)cdata
;
4081 if (dock
->type
!=WM_CLIP
)
4084 if (dock
->auto_raise_lower
)
4087 dock
->auto_lower_magic
= NULL
;
4092 clipAutoRaise(void *cdata
)
4094 WDock
*dock
= (WDock
*)cdata
;
4096 if (dock
->type
!=WM_CLIP
)
4099 if (dock
->auto_raise_lower
)
4102 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4103 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4106 dock
->auto_raise_magic
= NULL
;