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.
2311 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2315 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2316 int *ret_x
, int *ret_y
, int redocking
)
2318 WScreen
*scr
= dock
->screen_ptr
;
2321 int i
, offset
= ICON_SIZE
/2;
2322 WAppIcon
*aicon
= NULL
;
2323 WAppIcon
*nicon
= NULL
;
2324 int max_y_icons
, max_x_icons
;
2326 max_x_icons
= scr
->scr_width
/ICON_SIZE
;
2327 max_y_icons
= scr
->scr_height
/ICON_SIZE
-1;
2329 if (wPreferences
.flags
.noupdates
)
2335 /* if the dock is full */
2337 (dock
->icon_count
>= dock
->max_icons
)) {
2341 /* exact position */
2343 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2345 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2348 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2350 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2352 /* check if the icon is outside the screen boundaries */
2353 if (dx
+ ex_x
*ICON_SIZE
< -ICON_SIZE
+2 ||
2354 dx
+ ex_x
*ICON_SIZE
>= scr
->scr_width
-1 ||
2355 dy
+ ex_y
*ICON_SIZE
< -ICON_SIZE
+2 ||
2356 dy
+ ex_y
*ICON_SIZE
>= scr
->scr_height
-1)
2359 if (dock
->type
== WM_DOCK
) {
2360 if (icon
->dock
!= dock
&& ex_x
!= 0)
2363 for (i
=0; i
<dock
->max_icons
; i
++) {
2364 nicon
= dock
->icon_array
[i
];
2365 if (nicon
&& nicon
->yindex
== ex_y
) {
2372 int sig
, done
, closest
;
2374 /* Possible cases when redocking:
2376 * icon dragged out of range of any slot -> false
2377 * icon dragged to range of free slot
2378 * icon dragged to range of same slot
2379 * icon dragged to range of different icon
2381 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2384 if (ex_y
>=0 && ex_y
<=max_y_icons
&& (aicon
==icon
|| !aicon
)) {
2390 /* start looking at the upper slot or lower? */
2391 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2398 /* look for closest free slot */
2399 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2403 closest
= sig
*(i
/2) + ex_y
;
2404 /* check if this slot is used */
2406 for (j
= 0; j
<dock
->max_icons
; j
++) {
2407 if (dock
->icon_array
[j
]
2408 && dock
->icon_array
[j
]->yindex
==closest
) {
2409 /* slot is used by someone else */
2410 if (dock
->icon_array
[j
]!=icon
)
2418 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2419 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2421 (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
) {
2438 for (i
=0; i
<dock
->max_icons
; i
++) {
2439 nicon
= dock
->icon_array
[i
];
2440 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2446 for (i
=0; i
<dock
->max_icons
; i
++) {
2447 nicon
= dock
->icon_array
[i
];
2448 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2449 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2450 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2456 if (neighbours
&& (aicon
==NULL
|| (redocking
&& aicon
== icon
))) {
2465 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2466 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2468 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2469 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2470 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2474 * returns true if it can find a free slot in the dock,
2475 * in which case it changes x_pos and y_pos accordingly.
2476 * Else returns false.
2479 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2481 WScreen
*scr
= dock
->screen_ptr
;
2483 unsigned char *slot_map
;
2487 int i
, done
= False
;
2489 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2492 /* if the dock is full */
2493 if (dock
->icon_count
>= dock
->max_icons
) {
2497 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2498 if (scr
->dock
->on_right_side
)
2499 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2501 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2504 if (ex
< dock
->x_pos
)
2506 if (sx
> dock
->x_pos
+ICON_SIZE
)
2507 sx
= dock
->x_pos
+ICON_SIZE
;
2514 /* check if clip is in a corner */
2515 if (dock
->type
==WM_CLIP
) {
2516 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2518 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2520 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2522 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2529 /* If the clip is in the corner, use only slots that are in the border
2531 if (corner
!=C_NONE
) {
2535 hcount
= MIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2536 vcount
= MIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2537 hmap
= wmalloc(hcount
+1);
2538 memset(hmap
, 0, hcount
+1);
2539 vmap
= wmalloc(vcount
+1);
2540 memset(vmap
, 0, vcount
+1);
2542 /* mark used positions */
2545 for (i
=0; i
<dock
->max_icons
; i
++) {
2546 btn
= dock
->icon_array
[i
];
2550 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2551 vmap
[btn
->yindex
] = 1;
2552 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2553 hmap
[btn
->xindex
] = 1;
2556 for (i
=0; i
<dock
->max_icons
; i
++) {
2557 btn
= dock
->icon_array
[i
];
2561 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2562 vmap
[btn
->yindex
] = 1;
2563 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2564 hmap
[-btn
->xindex
] = 1;
2567 for (i
=0; i
<dock
->max_icons
; i
++) {
2568 btn
= dock
->icon_array
[i
];
2572 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2573 vmap
[-btn
->yindex
] = 1;
2574 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2575 hmap
[btn
->xindex
] = 1;
2579 for (i
=0; i
<dock
->max_icons
; i
++) {
2580 btn
= dock
->icon_array
[i
];
2584 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2585 vmap
[-btn
->yindex
] = 1;
2586 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2587 hmap
[-btn
->xindex
] = 1;
2592 /* search a vacant slot */
2593 for (i
=1; i
<MAX(vcount
, hcount
); i
++) {
2594 if (i
< vcount
&& vmap
[i
]==0) {
2600 } else if (i
< hcount
&& hmap
[i
]==0) {
2610 /* If found a slot, translate and return */
2612 if (corner
==C_NW
|| corner
==C_NE
) {
2617 if (corner
==C_NE
|| corner
==C_SE
) {
2624 /* else, try to find a slot somewhere else */
2627 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2628 * placed outside of screen */
2629 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2631 /* In the worst case (the clip is in the corner of the screen),
2632 * the amount of icons that fit in the clip is smaller.
2633 * Double the map to get a safe value.
2639 slot_map
= wmalloc(mwidth
*mwidth
);
2640 memset(slot_map
, 0, mwidth
*mwidth
);
2642 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2644 /* mark used slots in the map. If the slot falls outside the map
2645 * (for example, when all icons are placed in line), ignore them. */
2646 for (i
=0; i
<dock
->max_icons
; i
++) {
2647 btn
= dock
->icon_array
[i
];
2649 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2651 /* Find closest slot from the center that is free by scanning the
2652 * map from the center to outward in circular passes.
2653 * This will not result in a neat layout, but will be optimal
2654 * in the sense that there will not be holes left.
2657 for (i
= 1; i
<= r
&& !done
; i
++) {
2660 /* top and bottom parts of the ring */
2661 for (x
= -i
; x
<= i
&& !done
; x
++) {
2662 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2664 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2665 if (slot_map
[XY2OFS(x
,y
)]==0
2666 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2673 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2674 if (slot_map
[XY2OFS(x
,y
)]==0
2675 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2682 /* left and right parts of the ring */
2683 for (y
= -i
+1; y
<= i
-1; y
++) {
2684 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2686 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2687 if (slot_map
[XY2OFS(x
,y
)]==0
2688 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2695 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2696 if (slot_map
[XY2OFS(x
,y
)]==0
2697 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2712 moveDock(WDock
*dock
, int new_x
, int new_y
)
2717 dock
->x_pos
= new_x
;
2718 dock
->y_pos
= new_y
;
2719 for (i
=0; i
<dock
->max_icons
; i
++) {
2720 btn
= dock
->icon_array
[i
];
2722 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2723 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2724 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2731 swapDock(WDock
*dock
)
2733 WScreen
*scr
= dock
->screen_ptr
;
2738 if (dock
->on_right_side
) {
2739 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2741 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2744 for (i
=0; i
<dock
->max_icons
; i
++) {
2745 btn
= dock
->icon_array
[i
];
2748 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2752 wScreenUpdateUsableArea(scr
);
2757 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2759 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2765 cmdline
= ExpandOptions(scr
, command
);
2767 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2775 ParseCommand(cmdline
, &argv
, &argc
);
2785 if ((pid
=fork())==0) {
2789 SetupEnvironment(scr
);
2795 args
= malloc(sizeof(char*)*(argc
+1));
2798 for (i
=0; i
<argc
; i
++) {
2802 execvp(argv
[0], args
);
2811 state
= wmalloc(sizeof(WSavedState
));
2812 memset(state
, 0, sizeof(WSavedState
));
2814 state
->miniaturized
= -1;
2816 if (btn
->dock
== scr
->dock
)
2817 state
->workspace
= -1;
2819 state
->workspace
= scr
->current_workspace
;
2821 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
2823 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
2834 wDockHideIcons(WDock
*dock
)
2842 btn
= dock
->icon_array
[0];
2844 for (i
=1; i
<dock
->max_icons
; i
++) {
2845 if (dock
->icon_array
[i
])
2846 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2855 wDockShowIcons(WDock
*dock
)
2863 btn
= dock
->icon_array
[0];
2864 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2866 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2867 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2869 for (i
=1; i
<dock
->max_icons
; i
++) {
2870 if (dock
->icon_array
[i
]) {
2871 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
2877 if (!dock
->collapsed
) {
2878 for (i
=1; i
<dock
->max_icons
; i
++) {
2879 if (dock
->icon_array
[i
]) {
2880 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2891 wDockLower(WDock
*dock
)
2895 for (i
=0; i
<dock
->max_icons
; i
++) {
2896 if (dock
->icon_array
[i
])
2897 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2903 wDockRaise(WDock
*dock
)
2907 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
2908 if (dock
->icon_array
[i
])
2909 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2915 wDockRaiseLower(WDock
*dock
)
2917 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2918 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2919 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2927 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
2929 icon
->launching
= 0;
2930 icon
->relaunching
= 0;
2931 dockIconPaint(icon
);
2936 wDockFindIconFor(WDock
*dock
, Window window
)
2941 for (i
=0; i
<dock
->max_icons
; i
++) {
2942 icon
= dock
->icon_array
[i
];
2943 if (icon
&& icon
->main_window
== window
)
2951 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
2954 #ifdef REDUCE_APPICONS
2955 WAppIconAppList
*tapplist
;
2957 char *wm_class
, *wm_instance
;
2959 Bool firstPass
= True
;
2961 char *command
= NULL
;
2967 if (XGetCommand(dpy
, window
, &argv
, &argc
)) {
2968 if (argc
> 0 && argv
!= NULL
)
2969 command
= FlattenStringList(argv
,argc
);
2971 XFreeStringList(argv
);
2976 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
2977 (!wm_class
&& !wm_instance
))
2981 for (i
=0; i
<dock
->max_icons
; i
++) {
2982 icon
= dock
->icon_array
[i
];
2986 /* app is already attached to icon */
2987 if (icon
->main_window
== window
) {
2992 if ((icon
->wm_instance
|| icon
->wm_class
)
2994 || (dock
->screen_ptr
->flags
.startup
&& !icon
->running
))) {
2996 if (icon
->wm_instance
&& wm_instance
&&
2997 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
3000 if (icon
->wm_class
&& wm_class
&&
3001 strcmp(icon
->wm_class
, wm_class
)!=0) {
3004 if (firstPass
&& command
&& strcmp(icon
->command
, command
)!=0) {
3008 if (!icon
->relaunching
) {
3011 /* Possibly an application that was docked with dockit,
3012 * but the user did not update WMState to indicate that
3013 * it was docked by force */
3014 wapp
= wApplicationOf(window
);
3016 icon
->forced_dock
= 1;
3019 if (!icon
->forced_dock
)
3020 icon
->main_window
= window
;
3022 #ifdef REDUCE_APPICONS
3023 tapplist
= wmalloc(sizeof(WAppIconAppList
));
3024 memset(tapplist
, 0, sizeof(WAppIconAppList
));
3025 tapplist
->next
= icon
->applist
;
3027 icon
->applist
->prev
= tapplist
;
3028 icon
->applist
= tapplist
;
3029 tapplist
->wapp
= wApplicationOf(window
);
3034 wDockFinishLaunch(dock
, icon
);
3039 if (firstPass
&& !found
) {
3056 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3058 if (!wPreferences
.flags
.noclip
) {
3059 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3060 if (scr
->current_workspace
!= workspace
) {
3061 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3063 wDockHideIcons(old_clip
);
3064 if (old_clip
->auto_raise_lower
) {
3065 if (old_clip
->auto_raise_magic
) {
3066 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3067 old_clip
->auto_raise_magic
= NULL
;
3069 wDockLower(old_clip
);
3071 if (old_clip
->auto_collapse
) {
3072 if (old_clip
->auto_expand_magic
) {
3073 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3074 old_clip
->auto_expand_magic
= NULL
;
3076 old_clip
->collapsed
= 1;
3078 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3080 if (scr
->flags
.clip_balloon_mapped
)
3081 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3088 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3093 for (i
=0; i
<dock
->max_icons
; i
++) {
3094 icon
= dock
->icon_array
[i
];
3098 if (icon
->launching
&& icon
->pid
== pid
) {
3099 if (!icon
->relaunching
) {
3101 icon
->main_window
= None
;
3103 wDockFinishLaunch(dock
, icon
);
3108 sprintf(msg
, _("Could not execute command \"%s\""),
3109 icon
->drop_launch
&& icon
->dnd_command
3110 ? icon
->dnd_command
: icon
->command
);
3112 sprintf(msg
, _("Could not execute command \"%s\""),
3115 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
3116 _("OK"), NULL
, NULL
);
3125 toggleLowered(WDock
*dock
)
3130 /* lower/raise Dock */
3131 if (!dock
->lowered
) {
3132 newlevel
= WMNormalLevel
;
3135 newlevel
= WMDockLevel
;
3139 for (i
=0; i
<dock
->max_icons
; i
++) {
3140 tmp
= dock
->icon_array
[i
];
3144 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3146 wLowerFrame(tmp
->icon
->core
);
3149 if (dock
->type
== WM_DOCK
)
3150 wScreenUpdateUsableArea(dock
->screen_ptr
);
3155 toggleCollapsed(WDock
*dock
)
3157 if (dock
->collapsed
) {
3158 dock
->collapsed
= 0;
3159 wDockShowIcons(dock
);
3162 dock
->collapsed
= 1;
3163 wDockHideIcons(dock
);
3169 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3171 WScreen
*scr
= dock
->screen_ptr
;
3172 WObjDescriptor
*desc
;
3174 WApplication
*wapp
= NULL
;
3177 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3179 if (dock
->type
== WM_DOCK
) {
3181 entry
= dock
->menu
->entries
[index
];
3182 entry
->flags
.indicator_on
= !dock
->lowered
;
3183 entry
->clientdata
= dock
;
3186 if (scr
->clip_options
)
3187 updateClipOptionsMenu(scr
->clip_options
, dock
);
3189 /* Rename Workspace */
3190 entry
= dock
->menu
->entries
[++index
];
3191 entry
->clientdata
= dock
;
3194 entry
= dock
->menu
->entries
[++index
];
3195 entry
->clientdata
= aicon
;
3196 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3198 /* (un)select all icons */
3199 entry
= dock
->menu
->entries
[++index
];
3200 entry
->clientdata
= aicon
;
3201 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3204 entry
= dock
->menu
->entries
[++index
];
3205 entry
->clientdata
= aicon
;
3206 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3208 /* this is the workspace submenu part */
3209 if (scr
->clip_submenu
)
3210 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3213 /* remove icon(s) */
3214 entry
= dock
->menu
->entries
[++index
];
3215 entry
->clientdata
= aicon
;
3216 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3218 /* attract icon(s) */
3219 entry
= dock
->menu
->entries
[++index
];
3220 entry
->clientdata
= aicon
;
3224 entry
= dock
->menu
->entries
[++index
];
3225 entry
->clientdata
= aicon
;
3226 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3229 entry
= dock
->menu
->entries
[++index
];
3230 entry
->clientdata
= aicon
;
3231 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3234 entry
= dock
->menu
->entries
[++index
];
3235 entry
->clientdata
= aicon
;
3236 if (aicon
->icon
->owner
) {
3237 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3238 if (wapp
&& wapp
->flags
.hidden
)
3239 entry
->text
= _("Unhide");
3241 entry
->text
= _("Hide");
3243 entry
->text
= _("Hide");
3245 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3248 entry
= dock
->menu
->entries
[++index
];
3249 entry
->clientdata
= aicon
;
3250 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
3251 && !wPreferences
.flags
.noupdates
);
3254 entry
= dock
->menu
->entries
[++index
];
3255 entry
->clientdata
= aicon
;
3256 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3258 if (!dock
->menu
->flags
.realized
)
3259 wMenuRealize(dock
->menu
);
3261 if (dock
->type
== WM_CLIP
) {
3262 x_pos
= event
->xbutton
.x_root
+2;
3264 x_pos
= dock
->on_right_side
?
3265 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 2 : 0;
3268 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3270 /* allow drag select */
3271 event
->xany
.send_event
= True
;
3272 desc
= &dock
->menu
->menu
->descriptor
;
3273 (*desc
->handle_mousedown
)(desc
, event
);
3278 openClipWorkspaceMenu(WScreen
*scr
, int x
, int y
)
3280 if (!scr
->clip_ws_menu
) {
3281 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3283 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
3284 wMenuMapAt(scr
->clip_ws_menu
, x
, y
, False
);
3288 /******************************************************************/
3290 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3292 WAppIcon
*btn
= desc
->parent
;
3293 WDock
*dock
= btn
->dock
;
3294 WApplication
*wapp
= NULL
;
3297 #ifdef REDUCE_APPICONS
3298 if ((btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) ||
3299 ((btn
->icon
->owner
== NULL
) && (btn
->applist
!= NULL
))) {
3300 if (btn
->icon
->owner
== NULL
)
3301 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
3306 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3308 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3312 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3314 /* go to the last workspace that the user worked on the app */
3315 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
3317 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3320 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3323 if (event
->xbutton
.state
& MOD_MASK
) {
3324 wHideOtherApplications(btn
->icon
->owner
);
3327 if (event
->xbutton
.button
==Button1
) {
3329 if (event
->xbutton
.state
& MOD_MASK
) {
3330 /* raise/lower dock */
3331 toggleLowered(dock
);
3332 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3333 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3334 toggleCollapsed(dock
);
3336 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3337 } else if (btn
->command
) {
3338 if (!btn
->launching
&&
3339 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3340 launchDockedApplication(btn
);
3349 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3351 WScreen
*scr
= dock
->screen_ptr
;
3352 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3355 int grabbed
= 0, swapped
= 0, done
;
3356 Pixmap ghost
= None
;
3357 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3360 puts("moving dock");
3362 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3363 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3364 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3365 wwarning("pointer grab failed for dock move");
3368 for (x
=0; x
<dock
->max_icons
; x
++) {
3369 if (dock
->icon_array
[x
]!=NULL
&&
3370 dock
->icon_array
[x
]->yindex
> y
)
3371 y
= dock
->icon_array
[x
]->yindex
;
3374 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3378 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3379 |ButtonMotionMask
|ExposureMask
, &ev
);
3387 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3388 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3389 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3390 |ButtonReleaseMask
|ButtonPressMask
,
3391 wCursor
[WCUR_MOVE
], CurrentTime
);
3396 if (dock
->type
== WM_CLIP
) {
3397 if (ev
.xmotion
.x_root
- ofs_x
< 0) {
3399 } else if (ev
.xmotion
.x_root
- ofs_x
+ ICON_SIZE
>
3401 x
= scr
->scr_width
- ICON_SIZE
;
3403 x
= ev
.xmotion
.x_root
- ofs_x
;
3405 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3407 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3409 y
= scr
->scr_height
- ICON_SIZE
;
3411 y
= ev
.xmotion
.y_root
- ofs_y
;
3413 moveDock(dock
, x
, y
);
3415 /* move vertically if pointer is inside the dock*/
3416 if ((dock
->on_right_side
&&
3417 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3418 || (!dock
->on_right_side
&&
3419 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3421 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3423 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3425 y
= scr
->scr_height
- ICON_SIZE
;
3427 y
= ev
.xmotion
.y_root
- ofs_y
;
3429 moveDock(dock
, dock
->x_pos
, y
);
3431 /* move horizontally to change sides */
3432 x
= ev
.xmotion
.x_root
- ofs_x
;
3433 if (!dock
->on_right_side
) {
3437 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3438 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3439 -DOCK_EXTRA_SPACE
-1, dock
->y_pos
);
3442 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3443 scr
->scr_width
-ICON_SIZE
3444 -DOCK_EXTRA_SPACE
-1,
3446 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3448 XClearWindow(dpy
, scr
->dock_shadow
);
3451 XMapRaised(dpy
, scr
->dock_shadow
);
3454 if (superfluous
&& ghost
!=None
) {
3455 XFreePixmap(dpy
, ghost
);
3458 XUnmapWindow(dpy
, scr
->dock_shadow
);
3463 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3464 XMoveWindow(dpy
, scr
->dock_shadow
,
3465 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3468 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3469 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3470 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3472 XClearWindow(dpy
, scr
->dock_shadow
);
3475 XMapRaised(dpy
, scr
->dock_shadow
);
3478 XUnmapWindow(dpy
, scr
->dock_shadow
);
3480 if (superfluous
&& ghost
!=None
) {
3481 XFreePixmap(dpy
, ghost
);
3493 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3495 XUngrabPointer(dpy
, CurrentTime
);
3496 XUnmapWindow(dpy
, scr
->dock_shadow
);
3497 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3498 if (dock
->type
== WM_DOCK
) {
3501 dock
->on_right_side
= 1;
3503 dock
->on_right_side
= 0;
3505 wArrangeIcons(scr
, False
);
3514 XFreePixmap(dpy
, ghost
);
3515 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3518 puts("End dock move");
3525 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3527 WScreen
*scr
= dock
->screen_ptr
;
3529 WIcon
*icon
= aicon
->icon
;
3530 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3531 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3533 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3534 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3535 int shad_x
= x
, shad_y
= y
;
3536 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3538 Pixmap ghost
= None
;
3540 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3542 if (wPreferences
.flags
.noupdates
)
3545 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3546 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3547 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3549 wwarning("pointer grab failed for icon move");
3553 /* wRaiseFrame(icon->core);*/
3555 if (!wPreferences
.flags
.noclip
)
3556 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3558 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3560 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3563 wins
[0] = icon
->core
->window
;
3564 wins
[1] = scr
->dock_shadow
;
3565 XRestackWindows(dpy
, wins
, 2);
3566 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3567 ICON_SIZE
, ICON_SIZE
);
3569 if (icon
->pixmap
!=None
)
3570 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3572 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3574 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3575 XClearWindow(dpy
, scr
->dock_shadow
);
3577 XMapWindow(dpy
, scr
->dock_shadow
);
3583 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3584 |ButtonMotionMask
|ExposureMask
, &ev
);
3592 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3593 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3594 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3595 |ButtonReleaseMask
|ButtonPressMask
,
3596 wCursor
[WCUR_MOVE
], CurrentTime
);
3603 x
= ev
.xmotion
.x_root
- ofs_x
;
3604 y
= ev
.xmotion
.y_root
- ofs_y
;
3605 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3608 if (last_dock
!= dock
&& collapsed
) {
3609 last_dock
->collapsed
= 1;
3610 wDockHideIcons(last_dock
);
3613 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3614 dock
->collapsed
= 0;
3615 wDockShowIcons(dock
);
3617 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
);
3652 XUnmapWindow(dpy
, scr
->dock_shadow
);
3656 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3663 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3665 XUngrabPointer(dpy
, CurrentTime
);
3667 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3668 XUnmapWindow(dpy
, scr
->dock_shadow
);
3670 reattachIcon(dock
, aicon
, ix
, iy
);
3671 if (clip
&& dock
!=clip
&& clip
->auto_raise_lower
)
3674 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3676 /* Slide it back if dock rejected it */
3677 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3679 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3681 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3689 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3690 /* We need to deselect it, even if is deselected in
3691 * wDockDetach(), because else DoKaboom() will fail.
3693 if (aicon
->icon
->selected
)
3694 wIconSelect(aicon
->icon
);
3695 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3698 if (clip
&& clip
->auto_raise_lower
)
3700 wDockDetach(dock
, aicon
);
3703 last_dock
->collapsed
= 1;
3704 wDockHideIcons(last_dock
);
3709 XFreePixmap(dpy
, ghost
);
3710 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3713 puts("End icon move");
3722 getClipButton(int px
, int py
)
3724 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
3726 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3729 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
3730 return CLIP_FORWARD
;
3731 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
3739 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3742 int done
, direction
, new_ws
;
3744 WDock
*clip
= scr
->clip_icon
->dock
;
3746 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3748 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3749 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3751 wClipIconPaint(scr
->clip_icon
);
3754 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
3755 |ButtonPressMask
, &ev
);
3762 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3763 if (new_dir
!= direction
) {
3764 direction
= new_dir
;
3765 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3766 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3767 wClipIconPaint(scr
->clip_icon
);
3775 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3780 clip
->lclip_button_pushed
= 0;
3781 clip
->rclip_button_pushed
= 0;
3783 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3785 if (direction
== CLIP_FORWARD
) {
3786 if (scr
->current_workspace
< scr
->workspace_count
-1)
3787 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3788 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
3789 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3790 else if (wPreferences
.ws_cycle
)
3791 wWorkspaceChange(scr
, 0);
3793 else if (direction
== CLIP_REWIND
) {
3794 if (scr
->current_workspace
> 0)
3795 wWorkspaceChange(scr
, scr
->current_workspace
-1);
3796 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
3797 wWorkspaceChange(scr
, scr
->workspace_count
-1);
3800 wClipIconPaint(scr
->clip_icon
);
3805 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3807 WAppIcon
*aicon
= desc
->parent
;
3808 WDock
*dock
= aicon
->dock
;
3809 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3811 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3814 scr
->last_dock
= dock
;
3816 if (dock
->menu
->flags
.mapped
)
3817 wMenuUnmap(dock
->menu
);
3819 if (IsDoubleClick(scr
, event
)) {
3820 /* double-click was not in the main clip icon */
3821 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
3822 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
3823 iconDblClick(desc
, event
);
3828 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
3829 XUnmapWindow(dpy
, scr
->clip_balloon
);
3830 scr
->flags
.clip_balloon_mapped
= 0;
3834 puts("handling dock");
3836 if (event
->xbutton
.button
== Button1
) {
3837 if (event
->xbutton
.state
& MOD_MASK
)
3842 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
3843 dock
->type
!=WM_DOCK
) {
3844 wIconSelect(aicon
->icon
);
3848 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
3849 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
3850 && dock
->type
==WM_CLIP
)
3851 handleClipChangeWorkspace(scr
, event
);
3853 handleDockMove(dock
, aicon
, event
);
3855 handleIconMove(dock
, aicon
, event
);
3857 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
3858 aicon
->xindex
==0 && aicon
->yindex
==0) {
3859 openClipWorkspaceMenu(scr
, event
->xbutton
.x_root
+2,
3860 event
->xbutton
.y_root
+2);
3861 if (scr
->clip_ws_menu
) {
3863 menu
= scr
->clip_ws_menu
;
3864 desc
= &menu
->menu
->descriptor
;
3866 event
->xany
.send_event
= True
;
3867 (*desc
->handle_mousedown
)(desc
, event
);
3869 } else if (event
->xbutton
.button
== Button3
) {
3870 openDockMenu(dock
, aicon
, event
);
3876 showClipBalloon(WDock
*dock
, int workspace
)
3880 WScreen
*scr
= dock
->screen_ptr
;
3884 scr
->flags
.clip_balloon_mapped
= 1;
3885 XMapWindow(dpy
, scr
->clip_balloon
);
3887 text
= scr
->workspaces
[workspace
]->name
;
3889 w
= wTextWidth(scr
->clip_title_font
->font
, text
, strlen(text
));
3891 h
= scr
->clip_title_font
->height
;
3892 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
3894 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
3895 y
= dock
->y_pos
+ ICON_SIZE
-scr
->clip_title_font
->height
- 3;
3897 if (x
+w
> scr
->scr_width
) {
3898 x
= scr
->scr_width
- w
;
3899 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
3900 y
= dock
->y_pos
- h
- 1;
3902 y
= dock
->y_pos
+ ICON_SIZE
;
3903 XRaiseWindow(dpy
, scr
->clip_balloon
);
3905 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
3906 stack
[1] = scr
->clip_balloon
;
3907 XRestackWindows(dpy
, stack
, 2);
3909 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
3910 XSetForeground(dpy
, scr
->clip_title_gc
,
3911 scr
->clip_title_pixel
[CLIP_NORMAL
]);
3912 XClearWindow(dpy
, scr
->clip_balloon
);
3913 wDrawString(scr
->clip_balloon
, scr
->clip_title_font
, scr
->clip_title_gc
,
3914 0, scr
->clip_title_font
->y
, text
, strlen(text
));
3919 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3921 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
3924 assert(event
->type
==EnterNotify
);
3926 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
3930 if (!dock
|| dock
->type
!=WM_CLIP
)
3933 /* The auto raise/lower code */
3934 if (dock
->auto_lower_magic
) {
3935 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3936 dock
->auto_lower_magic
= NULL
;
3938 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
3939 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
,
3944 /* The auto expand/collapse code */
3945 if (dock
->auto_collapse_magic
) {
3946 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3947 dock
->auto_collapse_magic
= NULL
;
3949 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
3950 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
,
3955 if (btn
->xindex
== 0 && btn
->yindex
== 0)
3956 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
3958 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
3959 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
3960 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
3967 clipLeave(WDock
*dock
)
3970 WObjDescriptor
*desc
= NULL
;
3972 if (!dock
|| dock
->type
!=WM_CLIP
)
3975 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
)!=False
) {
3976 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3977 (XPointer
*)&desc
)!=XCNOENT
3978 && desc
&& desc
->parent_type
==WCLASS_DOCK_ICON
3979 && ((WAppIcon
*)desc
->parent
)->dock
3980 && ((WAppIcon
*)desc
->parent
)->dock
->type
==WM_CLIP
) {
3981 /* We didn't left the Clip yet */
3982 XPutBackEvent(dpy
, &event
);
3986 XPutBackEvent(dpy
, &event
);
3988 /* We entered a withdrawn window, so we're still in Clip */
3992 if (dock
->auto_raise_magic
) {
3993 WMDeleteTimerHandler(dock
->auto_raise_magic
);
3994 dock
->auto_raise_magic
= NULL
;
3996 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
3997 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
,
4002 if (dock
->auto_expand_magic
) {
4003 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4004 dock
->auto_expand_magic
= NULL
;
4006 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
4007 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
4015 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4017 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4019 assert(event
->type
==LeaveNotify
);
4021 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4024 clipLeave(btn
->dock
);
4029 clipAutoCollapse(void *cdata
)
4031 WDock
*dock
= (WDock
*)cdata
;
4033 if (dock
->type
!=WM_CLIP
)
4036 if (dock
->auto_collapse
) {
4037 dock
->collapsed
= 1;
4038 wDockHideIcons(dock
);
4040 dock
->auto_collapse_magic
= NULL
;
4045 clipAutoExpand(void *cdata
)
4047 WDock
*dock
= (WDock
*)cdata
;
4049 if (dock
->type
!=WM_CLIP
)
4052 if (dock
->auto_collapse
) {
4053 dock
->collapsed
= 0;
4054 wDockShowIcons(dock
);
4056 dock
->auto_expand_magic
= NULL
;
4061 clipAutoLower(void *cdata
)
4063 WDock
*dock
= (WDock
*)cdata
;
4065 if (dock
->type
!=WM_CLIP
)
4068 if (dock
->auto_raise_lower
)
4071 dock
->auto_lower_magic
= NULL
;
4076 clipAutoRaise(void *cdata
)
4078 WDock
*dock
= (WDock
*)cdata
;
4080 if (dock
->type
!=WM_CLIP
)
4083 if (dock
->auto_raise_lower
)
4086 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4087 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4090 dock
->auto_raise_magic
= NULL
;