1 /* dock.c- built-in Dock module for WindowMaker
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 #include <X11/Xutil.h>
35 #define PATH_MAX DEFAULT_PATH_MAX
38 #include "WindowMaker.h"
48 #include "properties.h"
52 #include "workspace.h"
54 #include "superfluous.h"
67 /**** Local variables ****/
70 #define CLIP_FORWARD 2
72 #define CLIP_BUTTON_SIZE 23
75 /**** Global variables ****/
78 extern void DestroyDockAppSettingsPanel();
80 extern void ShowDockAppSettingsPanel(WAppIcon
*aicon
);
83 extern XContext wWinContext
;
85 extern Cursor wCursor
[WCUR_LAST
];
87 extern WPreferences wPreferences
;
89 extern XContext wWinContext
;
92 extern Atom _XA_DND_PROTOCOL
;
96 #define MOD_MASK wPreferences.modifier_mask
98 extern void appIconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
100 #define ICON_SIZE wPreferences.icon_size
103 /***** Local variables ****/
105 static proplist_t dCommand
=NULL
;
107 static proplist_t dDropCommand
=NULL
;
109 static proplist_t dAutoLaunch
, dName
, dForced
, dBuggyApplication
, dYes
, dNo
;
110 static proplist_t dHost
, dDock
, dClip
;
111 static proplist_t dAutoAttractIcons
, dKeepAttracted
;
113 static proplist_t dPosition
, dApplications
, dLowered
, dCollapsed
, dAutoCollapse
;
115 static proplist_t dAutoRaiseLower
;
117 static void dockIconPaint(WAppIcon
*btn
);
119 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
121 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
);
123 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
125 static int getClipButton(int px
, int py
);
127 static void toggleLowered(WDock
*dock
);
129 static void toggleCollapsed(WDock
*dock
);
131 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
133 static void clipLeave(WDock
*dock
);
135 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
137 Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
);
139 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
140 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
141 static void clipAutoCollapse(void *cdata
);
142 static void launchDockedApplication(WAppIcon
*btn
);
144 static void clipAutoLower(void *cdata
);
145 static void clipAutoRaise(void *cdata
);
147 static void showClipBalloon(WDock
*dock
, int workspace
);
163 #endif /* OFFIX_DND */
173 dCommand
= PLRetain(PLMakeString("Command"));
175 dDropCommand
= PLRetain(PLMakeString("DropCommand"));
177 dAutoLaunch
= PLRetain(PLMakeString("AutoLaunch"));
178 dName
= PLRetain(PLMakeString("Name"));
179 dForced
= PLRetain(PLMakeString("Forced"));
180 dBuggyApplication
= PLRetain(PLMakeString("BuggyApplication"));
181 dYes
= PLRetain(PLMakeString("Yes"));
182 dNo
= PLRetain(PLMakeString("No"));
183 dHost
= PLRetain(PLMakeString("Host"));
185 dPosition
= PLMakeString("Position");
186 dApplications
= PLMakeString("Applications");
187 dLowered
= PLMakeString("Lowered");
188 dCollapsed
= PLMakeString("Collapsed");
189 dAutoCollapse
= PLMakeString("AutoCollapse");
190 dAutoRaiseLower
= PLMakeString("AutoRaiseLower");
191 dAutoAttractIcons
= PLMakeString("AutoAttractIcons");
192 dKeepAttracted
= PLMakeString("KeepAttracted");
194 dDock
= PLMakeString("Dock");
195 dClip
= PLMakeString("Clip");
201 renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
203 WDock
*dock
= entry
->clientdata
;
208 assert(entry
->clientdata
!=NULL
);
210 wspace
= dock
->screen_ptr
->current_workspace
;
212 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
214 sprintf(buffer
, _("Type the name for workspace %i:"), wspace
+1);
215 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
,
217 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
226 toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
228 assert(entry
->clientdata
!=NULL
);
230 toggleLowered(entry
->clientdata
);
232 entry
->flags
.indicator_on
= !((WDock
*)entry
->clientdata
)->lowered
;
240 killCallback(WMenu
*menu
, WMenuEntry
*entry
)
243 #ifdef REDUCE_APPICONS
244 WAppIconAppList
*tapplist
;
246 extern Atom _XA_WM_DELETE_WINDOW
;
251 if (!WCHECK_STATE(WSTATE_NORMAL
))
254 assert(entry
->clientdata
!=NULL
);
256 icon
= (WAppIcon
*)entry
->clientdata
;
260 WCHANGE_STATE(WSTATE_MODAL
);
262 #ifdef REDUCE_APPICONS
263 /* Send a delete message to the main window of each application
264 * bound to this docked appicon. - cls
266 tapplist
= icon
->applist
;
267 while (tapplist
!= NULL
) {
268 if (tapplist
->wapp
->main_window_desc
!= NULL
) {
269 if (tapplist
->wapp
->main_window_desc
->protocols
.DELETE_WINDOW
) {
270 wClientSendProtocol(tapplist
->wapp
->main_window_desc
,
271 _XA_WM_DELETE_WINDOW
, CurrentTime
);
273 wClientKill(tapplist
->wapp
->main_window_desc
);
276 tapplist
= tapplist
->next
;
279 buffer
= wstrappend(icon
->wm_class
,
280 _(" will be forcibly closed.\n"
281 "Any unsaved changes will be lost.\n"
284 if (wPreferences
.dont_confirm_kill
285 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
286 buffer
, _("Yes"), _("No"), NULL
)==WAPRDefault
) {
287 if (icon
->icon
&& icon
->icon
->owner
) {
288 wClientKill(icon
->icon
->owner
);
291 #endif /* !REDUCE_APPICONS */
295 WCHANGE_STATE(WSTATE_NORMAL
);}
299 getSelected(WDock
*dock
)
301 LinkedList
*ret
=NULL
;
305 for (i
=1; i
<dock
->max_icons
; i
++) {
306 btn
= dock
->icon_array
[i
];
307 if (btn
&& btn
->icon
->selected
) {
308 ret
= list_cons(btn
, ret
);
317 paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
319 Window win
= clipIcon
->icon
->core
->window
;
320 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
322 int pt
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
323 int tp
= ICON_SIZE
- pt
;
324 int as
= pt
- 15; /* 15 = 5+5+5 */
330 p
[1].x
= ICON_SIZE
-2;
332 p
[2].x
= ICON_SIZE
-2;
334 } else if (lpushed
) {
338 p
[1].y
= ICON_SIZE
-2;
340 p
[2].y
= ICON_SIZE
-2;
342 if (lpushed
|| rpushed
) {
343 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
344 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
345 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
348 p
[0].x
= p
[3].x
= ICON_SIZE
-6-as
;
350 p
[1].x
= ICON_SIZE
-6;
352 p
[2].x
= ICON_SIZE
-6;
355 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
356 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
358 XFillPolygon(dpy
, win
, scr
->clip_title_gc
, p
,3,Convex
,CoordModeOrigin
);
359 XDrawLines(dpy
, win
, scr
->clip_title_gc
, p
,4,CoordModeOrigin
);
363 p
[0].y
= p
[3].y
= ICON_SIZE
-6-as
;
365 p
[1].y
= ICON_SIZE
-6;
367 p
[2].y
= ICON_SIZE
-6;
369 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
370 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
372 XFillPolygon(dpy
, win
, scr
->clip_title_gc
, p
,3,Convex
,CoordModeOrigin
);
373 XDrawLines(dpy
, win
, scr
->clip_title_gc
, p
,4,CoordModeOrigin
);
379 wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
381 RImage
*tile
= RCloneImage(normalTile
);
387 pt
= CLIP_BUTTON_SIZE
*wPreferences
.icon_size
/64;
388 tp
= wPreferences
.icon_size
-1 - pt
;
391 black
.red
= black
.green
= black
.blue
= 0;
394 dark
.red
= dark
.green
= dark
.blue
= 80;
397 light
.red
= light
.green
= light
.blue
= 80;
401 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
-2,
403 RDrawLine(tile
, tp
-1, 0, wPreferences
.icon_size
-1, pt
+1, &black
);
404 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
-3,
409 ROperateLine(tile
, RAddOperation
, 2, tp
+2, pt
-2,
410 wPreferences
.icon_size
-3, &dark
);
411 RDrawLine(tile
, 0, tp
-1, pt
+1, wPreferences
.icon_size
-1, &black
);
412 ROperateLine(tile
, RSubtractOperation
, 0, tp
-2, pt
+1,
413 wPreferences
.icon_size
-2, &light
);
420 removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
422 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
425 LinkedList
*selectedIcons
;
428 assert(clickedIcon
!=NULL
);
430 dock
= clickedIcon
->dock
;
432 selectedIcons
= getSelected(dock
);
435 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
436 _("All selected icons will be removed!"),
437 _("OK"), _("Cancel"), NULL
)!=WAPRDefault
) {
441 if (clickedIcon
->xindex
==0 && clickedIcon
->yindex
==0)
443 selectedIcons
= list_cons(clickedIcon
, NULL
);
446 while (selectedIcons
) {
447 aicon
= selectedIcons
->head
;
448 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
449 wDockDetach(dock
, aicon
);
451 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
452 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
453 aicon
->x_pos
, aicon
->y_pos
);
454 if (!dock
->mapped
|| dock
->collapsed
)
455 XMapWindow(dpy
, aicon
->icon
->core
->window
);
457 list_remove_head(&selectedIcons
);
460 if (wPreferences
.auto_arrange_icons
)
461 wArrangeIcons(dock
->screen_ptr
, True
);
466 keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
468 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
471 LinkedList
*selectedIcons
;
473 assert(clickedIcon
!=NULL
);
474 dock
= clickedIcon
->dock
;
476 selectedIcons
= getSelected(dock
);
478 if (!selectedIcons
&& clickedIcon
!=dock
->screen_ptr
->clip_icon
) {
479 char *command
= NULL
;
481 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
482 clickedIcon
->editing
= 1;
483 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
484 _("Type the command used to launch the application"),
486 if (command
&& (command
[0]==0 ||
487 (command
[0]=='-' && command
[1]==0))) {
491 clickedIcon
->command
= command
;
492 clickedIcon
->editing
= 0;
494 clickedIcon
->editing
= 0;
501 selectedIcons
= list_cons(clickedIcon
, NULL
);
504 while (selectedIcons
) {
505 aicon
= selectedIcons
->head
;
506 if (aicon
->icon
->selected
)
507 wIconSelect(aicon
->icon
);
508 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
509 aicon
->attracted
= 0;
510 if (aicon
->icon
->shadowed
) {
511 aicon
->icon
->shadowed
= 0;
512 aicon
->icon
->force_paint
= 1;
513 wAppIconPaint(aicon
);
516 list_remove_head(&selectedIcons
);
524 toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
526 WDock
*dock
= (WDock
*)entry
->clientdata
;
528 assert(entry
->clientdata
!=NULL
);
530 dock
->attract_icons
= !dock
->attract_icons
;
531 /*if (!dock->attract_icons)
532 dock->keep_attracted = 0;*/
534 entry
->flags
.indicator_on
= dock
->attract_icons
;
541 toggleKeepCallback(WMenu
*menu
, WMenuEntry
*entry
)
543 WDock
*dock
= (WDock
*)entry
->clientdata
;
547 assert(entry
->clientdata
!=NULL
);
549 dock
->keep_attracted
= !dock
->keep_attracted
;
551 if (dock
->keep_attracted
) {
552 for (i
=0; i
< dock
->max_icons
; i
++) {
553 btn
= dock
->icon_array
[i
];
554 if (btn
&& btn
->attracted
&& btn
->command
) {
556 if (btn
->icon
->shadowed
) {
557 btn
->icon
->shadowed
= 0;
558 btn
->icon
->force_paint
= 1;
565 entry
->flags
.indicator_on
= dock
->keep_attracted
;
572 selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
574 WAppIcon
*icon
= (WAppIcon
*)entry
->clientdata
;
578 wIconSelect(icon
->icon
);
585 colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
587 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
590 int x
, y
, x_pos
, y_pos
;
592 assert(entry
->clientdata
!=NULL
);
593 clip
= clickedIcon
->dock
;
595 aicon
= clip
->screen_ptr
->app_icon_list
;
598 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
599 x_pos
= clip
->x_pos
+ x
*ICON_SIZE
;
600 y_pos
= clip
->y_pos
+ y
*ICON_SIZE
;
601 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
603 if (wPreferences
.no_animations
) {
604 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
606 SlideWindow(aicon
->icon
->core
->window
,
607 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
610 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
611 #endif /* ANIMATIONS */
613 aicon
->attracted
= 1;
614 if (!clip
->keep_attracted
&& !aicon
->icon
->shadowed
) {
615 aicon
->icon
->shadowed
= 1;
616 aicon
->icon
->force_paint
= 1;
617 /* We don't do an wAppIconPaint() here because it's in
618 * wDockAttachIcon(). -Dan
621 wDockAttachIcon(clip
, aicon
, x
, y
);
622 if (clip
->collapsed
|| !clip
->mapped
)
623 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
631 selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
633 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
635 LinkedList
*selectedIcons
;
639 assert(clickedIcon
!=NULL
);
640 dock
= clickedIcon
->dock
;
642 selectedIcons
= getSelected(dock
);
644 if (!selectedIcons
) {
645 for (i
=1; i
<dock
->max_icons
; i
++) {
646 btn
= dock
->icon_array
[i
];
647 if (btn
&& !btn
->icon
->selected
) {
648 wIconSelect(btn
->icon
);
652 while(selectedIcons
) {
653 btn
= selectedIcons
->head
;
654 wIconSelect(btn
->icon
);
655 list_remove_head(&selectedIcons
);
664 toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
666 assert(entry
->clientdata
!=NULL
);
668 toggleCollapsed(entry
->clientdata
);
670 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->collapsed
;
677 toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
680 assert(entry
->clientdata
!=NULL
);
682 dock
= (WDock
*) entry
->clientdata
;
684 dock
->auto_collapse
= !dock
->auto_collapse
;
685 if (dock
->auto_collapse_magic
) {
686 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
687 dock
->auto_collapse_magic
= NULL
;
690 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_collapse
;
697 toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
700 assert(entry
->clientdata
!=NULL
);
702 dock
= (WDock
*) entry
->clientdata
;
704 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
706 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_raise_lower
;
713 launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
715 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
717 launchDockedApplication(btn
);
722 settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
724 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
728 ShowDockAppSettingsPanel(btn
);
733 hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
736 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
738 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
740 if (wapp
->flags
.hidden
) {
741 wWorkspaceChange(btn
->icon
->core
->screen_ptr
,wapp
->last_workspace
);
742 wUnhideApplication(wapp
, False
, False
);
744 wHideApplication(wapp
);
750 unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
753 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
755 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
757 wUnhideApplication(wapp
, False
, True
);
762 mainIconCreate(WScreen
*scr
, int type
)
767 if (type
== WM_CLIP
) {
769 return scr
->clip_icon
;
770 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
771 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
772 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
773 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
774 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE;*/
777 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
778 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
784 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
785 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
786 btn
->icon
->core
->descriptor
.parent
= btn
;
787 /*ChangeStackingLevel(btn->icon->core, WMDockLevel);*/
788 XMapWindow(dpy
, btn
->icon
->core
->window
);
793 scr
->clip_icon
= btn
;
800 switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
802 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
803 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
805 LinkedList
*selectedIcons
;
808 if (entry
->order
== scr
->current_workspace
)
811 dest
= scr
->workspaces
[entry
->order
]->clip
;
813 selectedIcons
= getSelected(src
);
816 while(selectedIcons
) {
817 btn
= selectedIcons
->head
;
818 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
819 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
820 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
822 list_remove_head(&selectedIcons
);
824 } else if (icon
!= scr
->clip_icon
) {
825 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
826 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
827 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
835 launchDockedApplication(WAppIcon
*btn
)
837 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
839 if (!btn
->launching
&& btn
->command
!=NULL
) {
840 if (!btn
->forced_dock
) {
841 btn
->relaunching
= btn
->running
;
844 if (btn
->wm_instance
|| btn
->wm_class
) {
845 WWindowAttributes attr
;
846 memset(&attr
, 0, sizeof(WWindowAttributes
));
847 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
,
850 if (!attr
.no_appicon
&& !btn
->buggy_app
)
855 btn
->drop_launch
= 0;
856 scr
->last_dock
= btn
->dock
;
857 btn
->pid
= execCommand(btn
, btn
->command
, NULL
);
859 if (btn
->buggy_app
) {
860 /* give feedback that the app was launched */
864 WMAddTimerHandler(200, (WMCallback
*)dockIconPaint
, btn
);
869 wwarning(_("could not launch application %s\n"), btn
->command
);
871 if (!btn
->relaunching
)
880 updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
882 WScreen
*scr
= menu
->frame
->screen_ptr
;
883 char title
[MAX_WORKSPACENAME_WIDTH
+1];
889 for (i
=0; i
<scr
->workspace_count
; i
++) {
890 if (i
< menu
->entry_no
) {
891 if (strcmp(menu
->entries
[i
]->text
,scr
->workspaces
[i
]->name
)!=0) {
892 free(menu
->entries
[i
]->text
);
893 strcpy(title
, scr
->workspaces
[i
]->name
);
894 menu
->entries
[i
]->text
= wstrdup(title
);
895 menu
->flags
.realized
= 0;
897 menu
->entries
[i
]->clientdata
= (void*)icon
;
899 strcpy(title
, scr
->workspaces
[i
]->name
);
901 wMenuAddCallback(menu
, title
, switchWSCommand
, (void*)icon
);
903 menu
->flags
.realized
= 0;
905 if (i
== scr
->current_workspace
) {
906 wMenuSetEnabled(menu
, i
, False
);
908 wMenuSetEnabled(menu
, i
, True
);
912 if (!menu
->flags
.realized
)
918 makeWorkspaceMenu(WScreen
*scr
)
922 menu
= wMenuCreate(scr
, NULL
, False
);
924 wwarning(_("could not create workspace submenu for Clip menu"));
926 wMenuAddCallback(menu
, "", switchWSCommand
, (void*)scr
->clip_icon
);
928 menu
->flags
.realized
= 0;
936 updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
945 entry
= menu
->entries
[index
];
946 entry
->flags
.indicator_on
= !dock
->lowered
;
947 entry
->clientdata
= dock
;
950 entry
= menu
->entries
[++index
];
951 entry
->flags
.indicator_on
= dock
->collapsed
;
952 entry
->clientdata
= dock
;
955 entry
= menu
->entries
[++index
];
956 entry
->flags
.indicator_on
= dock
->auto_collapse
;
957 entry
->clientdata
= dock
;
959 /* auto-raise/lower */
960 entry
= menu
->entries
[++index
];
961 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
962 entry
->clientdata
= dock
;
965 entry
= menu
->entries
[++index
];
966 entry
->flags
.indicator_on
= dock
->attract_icons
;
967 entry
->clientdata
= dock
;
969 /* keep attracted icons */
970 entry
= menu
->entries
[++index
];
971 entry
->flags
.indicator_on
= dock
->keep_attracted
;
972 entry
->clientdata
= dock
;
974 menu
->flags
.realized
= 0;
980 makeClipOptionsMenu(WScreen
*scr
)
985 menu
= wMenuCreate(scr
, NULL
, False
);
987 wwarning(_("could not create options submenu for Clip menu"));
991 entry
= wMenuAddCallback(menu
, _("Keep on top"),
992 toggleLoweredCallback
, NULL
);
993 entry
->flags
.indicator
= 1;
994 entry
->flags
.indicator_on
= 1;
995 entry
->flags
.indicator_type
= MI_CHECK
;
997 entry
= wMenuAddCallback(menu
, _("Collapsed"),
998 toggleCollapsedCallback
, NULL
);
999 entry
->flags
.indicator
= 1;
1000 entry
->flags
.indicator_on
= 1;
1001 entry
->flags
.indicator_type
= MI_CHECK
;
1003 entry
= wMenuAddCallback(menu
, _("AutoCollapse"),
1004 toggleAutoCollapseCallback
, NULL
);
1005 entry
->flags
.indicator
= 1;
1006 entry
->flags
.indicator_on
= 1;
1007 entry
->flags
.indicator_type
= MI_CHECK
;
1009 entry
= wMenuAddCallback(menu
, _("AutoRaiseLower"),
1010 toggleAutoRaiseLowerCallback
, NULL
);
1011 entry
->flags
.indicator
= 1;
1012 entry
->flags
.indicator_on
= 1;
1013 entry
->flags
.indicator_type
= MI_CHECK
;
1015 entry
= wMenuAddCallback(menu
, _("AutoAttract Icons"),
1016 toggleAutoAttractCallback
, NULL
);
1017 entry
->flags
.indicator
= 1;
1018 entry
->flags
.indicator_on
= 1;
1019 entry
->flags
.indicator_type
= MI_CHECK
;
1021 entry
= wMenuAddCallback(menu
, _("Keep Attracted Icons"),
1022 toggleKeepCallback
, NULL
);
1023 entry
->flags
.indicator
= 1;
1024 entry
->flags
.indicator_on
= 1;
1025 entry
->flags
.indicator_type
= MI_CHECK
;
1027 menu
->flags
.realized
= 0;
1035 dockMenuCreate(WScreen
*scr
, int type
)
1040 if (type
== WM_CLIP
&& scr
->clip_menu
)
1041 return scr
->clip_menu
;
1043 menu
= wMenuCreate(scr
, NULL
, False
);
1044 if (type
!= WM_CLIP
) {
1045 entry
= wMenuAddCallback(menu
, _("Keep on top"),
1046 toggleLoweredCallback
, NULL
);
1047 entry
->flags
.indicator
= 1;
1048 entry
->flags
.indicator_on
= 1;
1049 entry
->flags
.indicator_type
= MI_CHECK
;
1051 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1052 scr
->clip_options
= makeClipOptionsMenu(scr
);
1053 if (scr
->clip_options
)
1054 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1056 wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1058 wMenuAddCallback(menu
, _("(Un)Select Icon"), selectCallback
, NULL
);
1060 wMenuAddCallback(menu
, _("(Un)Select All Icons"), selectIconsCallback
,
1063 wMenuAddCallback(menu
, _("Keep Icon(s)"), keepIconsCallback
, NULL
);
1065 entry
= wMenuAddCallback(menu
, _("Move Icon(s) To"), NULL
, NULL
);
1066 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1067 if (scr
->clip_submenu
)
1068 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1070 wMenuAddCallback(menu
, _("Remove Icon(s)"), removeIconsCallback
, NULL
);
1072 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1075 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1077 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1079 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1081 entry
->text
= _("Hide");
1083 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1085 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1087 if (type
== WM_CLIP
)
1088 scr
->clip_menu
= menu
;
1095 wDockCreate(WScreen
*scr
, int type
)
1103 dock
= wmalloc(sizeof(WDock
));
1104 memset(dock
, 0, sizeof(WDock
));
1106 if (type
== WM_CLIP
)
1107 icon_count
= CLIP_MAX_ICONS
;
1109 icon_count
= scr
->scr_height
/wPreferences
.icon_size
;
1111 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*)*icon_count
);
1112 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*)*icon_count
);
1114 dock
->max_icons
= icon_count
;
1116 btn
= mainIconCreate(scr
, type
);
1120 dock
->x_pos
= btn
->x_pos
;
1121 dock
->y_pos
= btn
->y_pos
;
1122 dock
->screen_ptr
= scr
;
1124 dock
->icon_count
= 1;
1125 dock
->on_right_side
= 1;
1126 dock
->collapsed
= 0;
1127 dock
->auto_collapse
= 0;
1128 dock
->auto_collapse_magic
= NULL
;
1129 dock
->auto_raise_lower
= 0;
1130 dock
->auto_lower_magic
= NULL
;
1131 dock
->auto_raise_magic
= NULL
;
1132 dock
->attract_icons
= 0;
1133 dock
->keep_attracted
= 0;
1135 dock
->icon_array
[0] = btn
;
1136 wRaiseFrame(btn
->icon
->core
);
1137 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1139 /* create dock menu */
1140 dock
->menu
= dockMenuCreate(scr
, type
);
1147 wDockDestroy(WDock
*dock
)
1152 for (i
=(dock
->type
== WM_CLIP
) ? 1 : 0; i
<dock
->max_icons
; i
++) {
1153 aicon
= dock
->icon_array
[i
];
1155 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1156 wDockDetach(dock
, aicon
);
1158 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
1159 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
1160 aicon
->x_pos
, aicon
->y_pos
);
1161 if (!dock
->mapped
|| dock
->collapsed
)
1162 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1166 if (wPreferences
.auto_arrange_icons
)
1167 wArrangeIcons(dock
->screen_ptr
, True
);
1168 free(dock
->icon_array
);
1169 if (dock
->menu
&& dock
->type
!=WM_CLIP
)
1170 wMenuDestroy(dock
->menu
, True
);
1176 wClipIconPaint(WAppIcon
*aicon
)
1178 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1179 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1181 Window win
= aicon
->icon
->core
->window
;
1182 int length
, nlength
;
1183 char *ws_name
, ws_number
[10];
1186 wIconPaint(aicon
->icon
);
1188 length
= strlen(workspace
->name
);
1189 ws_name
= malloc(length
+ 1);
1190 sprintf(ws_name
, "%s", workspace
->name
);
1191 sprintf(ws_number
, "%i", scr
->current_workspace
+ 1);
1192 nlength
= strlen(ws_number
);
1194 gc
= scr
->clip_title_gc
;
1196 if (!workspace
->clip
->collapsed
)
1197 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_NORMAL
]);
1199 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_COLLAPSED
]);
1201 ty
= ICON_SIZE
- scr
->clip_title_font
->height
- 3;
1203 tx
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
1205 wDrawString(win
, scr
->clip_title_font
, gc
, tx
,
1206 ty
+ scr
->clip_title_font
->y
, ws_name
, length
);
1208 tx
= (ICON_SIZE
/2 - wTextWidth(scr
->clip_title_font
->font
, ws_number
, nlength
))/2;
1210 wDrawString(win
, scr
->clip_title_font
, gc
, tx
,
1211 scr
->clip_title_font
->y
+ 2, ws_number
, nlength
);
1215 if (aicon
->launching
) {
1216 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1217 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1219 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
,
1220 aicon
->dock
->rclip_button_pushed
);
1225 clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1227 wClipIconPaint(desc
->parent
);
1232 dockIconPaint(WAppIcon
*btn
)
1234 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1235 wClipIconPaint(btn
);
1242 make_icon_state(WAppIcon
*btn
)
1244 proplist_t node
= NULL
;
1245 proplist_t command
, autolaunch
, name
, forced
, host
, position
, buggy
;
1251 command
= PLMakeString("-");
1253 command
= PLMakeString(btn
->command
);
1255 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1257 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1259 name
= PLMakeString(tmp
);
1263 forced
= btn
->forced_dock
? dYes
: dNo
;
1265 buggy
= btn
->buggy_app
? dYes
: dNo
;
1267 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1268 sprintf(buffer
, "%i,%i", btn
->x_pos
, btn
->y_pos
);
1270 sprintf(buffer
, "%hi,%hi", btn
->xindex
, btn
->yindex
);
1271 position
= PLMakeString(buffer
);
1273 node
= PLMakeDictionaryFromEntries(dCommand
, command
,
1275 dAutoLaunch
, autolaunch
,
1277 dBuggyApplication
, buggy
,
1278 dPosition
, position
,
1282 PLRelease(position
);
1284 if (btn
->dnd_command
) {
1285 command
= PLMakeString(btn
->dnd_command
);
1286 PLInsertDictionaryEntry(node
, dDropCommand
, command
);
1289 #endif /* OFFIX_DND */
1291 if (btn
->client_machine
&& btn
->remote_start
) {
1292 host
= PLMakeString(btn
->client_machine
);
1293 PLInsertDictionaryEntry(node
, dHost
, host
);
1303 dockSaveState(WDock
*dock
)
1306 proplist_t icon_info
;
1307 proplist_t list
=NULL
, dock_state
=NULL
;
1311 list
= PLMakeArrayFromElements(NULL
);
1313 for (i
=(dock
->type
==WM_DOCK
? 0 : 1); i
<dock
->max_icons
; i
++) {
1314 WAppIcon
*btn
= dock
->icon_array
[i
];
1316 if (!btn
|| (btn
->attracted
&& !dock
->keep_attracted
))
1319 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1320 list
= PLAppendArrayElement(list
, icon_info
);
1321 PLRelease(icon_info
);
1325 dock_state
= PLMakeDictionaryFromEntries(dApplications
, list
, NULL
);
1329 if (dock
->type
== WM_DOCK
) {
1330 sprintf(buffer
, "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0),
1332 value
= PLMakeString(buffer
);
1333 PLInsertDictionaryEntry(dock_state
, dPosition
, value
);
1337 value
= (dock
->lowered
? dYes
: dNo
);
1338 PLInsertDictionaryEntry(dock_state
, dLowered
, value
);
1340 if (dock
->type
== WM_CLIP
) {
1341 value
= (dock
->collapsed
? dYes
: dNo
);
1342 PLInsertDictionaryEntry(dock_state
, dCollapsed
, value
);
1344 value
= (dock
->auto_collapse
? dYes
: dNo
);
1345 PLInsertDictionaryEntry(dock_state
, dAutoCollapse
, value
);
1347 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1348 PLInsertDictionaryEntry(dock_state
, dAutoRaiseLower
, value
);
1350 value
= (dock
->attract_icons
? dYes
: dNo
);
1351 PLInsertDictionaryEntry(dock_state
, dAutoAttractIcons
, value
);
1353 value
= (dock
->keep_attracted
? dYes
: dNo
);
1354 PLInsertDictionaryEntry(dock_state
, dKeepAttracted
, value
);
1362 wDockSaveState(WScreen
*scr
)
1364 proplist_t dock_state
;
1366 dock_state
= dockSaveState(scr
->dock
);
1368 PLInsertDictionaryEntry(scr
->session_state
, dDock
, dock_state
);
1370 PLRelease(dock_state
);
1375 wClipSaveState(WScreen
*scr
)
1377 proplist_t clip_state
;
1379 clip_state
= make_icon_state(scr
->clip_icon
);
1381 PLInsertDictionaryEntry(scr
->session_state
, dClip
, clip_state
);
1383 PLRelease(clip_state
);
1388 wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1390 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1395 restore_icon_state(WScreen
*scr
, proplist_t info
, int type
, int index
)
1398 char *wclass
, *winstance
;
1399 proplist_t cmd
, value
;
1403 cmd
= PLGetDictionaryEntry(info
, dCommand
);
1404 if (!cmd
|| !PLIsString(cmd
)) {
1408 /* parse window name */
1409 value
= PLGetDictionaryEntry(info
, dName
);
1413 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1415 if (!winstance
&& !wclass
) {
1422 command
= wstrdup(PLGetString(cmd
));
1426 if (!command
|| strcmp(command
, "-")==0) {
1437 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
,
1444 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1445 if (type
== WM_CLIP
) {
1446 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1447 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1449 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1450 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1454 cmd
= PLGetDictionaryEntry(info
, dDropCommand
);
1456 aicon
->dnd_command
= wstrdup(PLGetString(cmd
));
1459 /* check auto launch */
1460 value
= PLGetDictionaryEntry(info
, dAutoLaunch
);
1462 aicon
->auto_launch
= 0;
1464 if (PLIsString(value
)) {
1465 if (strcasecmp(PLGetString(value
), "YES")==0)
1466 aicon
->auto_launch
= 1;
1468 wwarning(_("bad value in docked icon state info %s"),
1469 PLGetString(dAutoLaunch
));
1473 /* check if it wasn't normally docked */
1474 value
= PLGetDictionaryEntry(info
, dForced
);
1476 aicon
->forced_dock
= 0;
1478 if (PLIsString(value
)) {
1479 if (strcasecmp(PLGetString(value
), "YES")==0)
1480 aicon
->forced_dock
= 1;
1482 wwarning(_("bad value in docked icon state info %s"),
1483 PLGetString(dForced
));
1487 /* check if we can rely on the stuff in the app */
1488 value
= PLGetDictionaryEntry(info
, dBuggyApplication
);
1490 aicon
->buggy_app
= 0;
1492 if (PLIsString(value
)) {
1493 if (strcasecmp(PLGetString(value
), "YES")==0)
1494 aicon
->buggy_app
= 1;
1496 wwarning(_("bad value in docked icon state info %s"),
1497 PLGetString(dBuggyApplication
));
1501 /* get position in the dock */
1502 value
= PLGetDictionaryEntry(info
, dPosition
);
1503 if (value
&& PLIsString(value
)) {
1504 if (sscanf(PLGetString(value
), "%hi,%hi", &aicon
->xindex
,
1506 wwarning(_("bad value in docked icon state info %s"),
1507 PLGetString(dPosition
));
1509 /* check position sanity */
1510 /* incomplete section! */
1511 if (type
== WM_DOCK
) {
1513 if (aicon
->yindex
< 0)
1514 wwarning(_("bad value in docked icon position %i,%i"),
1515 aicon
->xindex
, aicon
->yindex
);
1518 aicon
->yindex
= index
;
1529 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1533 wClipRestoreState(WScreen
*scr
, proplist_t clip_state
)
1539 icon
= mainIconCreate(scr
, WM_CLIP
);
1544 PLRetain(clip_state
);
1546 /* restore position */
1548 value
= PLGetDictionaryEntry(clip_state
, dPosition
);
1551 if (!PLIsString(value
))
1552 COMPLAIN("Position");
1554 if (sscanf(PLGetString(value
), "%i,%i", &icon
->x_pos
,
1556 COMPLAIN("Position");
1558 /* check position sanity */
1559 if (icon
->y_pos
< 0)
1561 else if (icon
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1562 icon
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1564 if (icon
->x_pos
< 0)
1566 else if (icon
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1567 icon
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1572 value
= PLGetDictionaryEntry(clip_state
, dDropCommand
);
1573 if (value
&& PLIsString(value
))
1574 icon
->dnd_command
= wstrdup(PLGetString(value
));
1577 PLRelease(clip_state
);
1584 wDockRestoreState(WScreen
*scr
, proplist_t dock_state
, int type
)
1589 WAppIcon
*aicon
, *old_top
;
1593 dock
= wDockCreate(scr
, type
);
1599 PLRetain(dock_state
);
1602 /* restore position */
1604 value
= PLGetDictionaryEntry(dock_state
, dPosition
);
1607 if (!PLIsString(value
))
1608 COMPLAIN("Position");
1610 if (sscanf(PLGetString(value
), "%i,%i", &dock
->x_pos
,
1612 COMPLAIN("Position");
1614 /* check position sanity */
1615 if (dock
->y_pos
< 0)
1617 else if (dock
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1618 dock
->y_pos
= scr
->scr_height
- ICON_SIZE
;
1620 /* This is no more needed. ??? */
1621 if (type
== WM_CLIP
) {
1622 if (dock
->x_pos
< 0)
1624 else if (dock
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1625 dock
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1627 if (dock
->x_pos
>= 0) {
1628 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1629 dock
->on_right_side
= 0;
1631 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1632 dock
->on_right_side
= 1;
1638 /* restore lowered/raised state */
1642 value
= PLGetDictionaryEntry(dock_state
, dLowered
);
1645 if (!PLIsString(value
))
1646 COMPLAIN("Lowered");
1648 if (strcasecmp(PLGetString(value
), "YES")==0)
1654 /* restore collapsed state */
1656 dock
->collapsed
= 0;
1658 value
= PLGetDictionaryEntry(dock_state
, dCollapsed
);
1661 if (!PLIsString(value
))
1662 COMPLAIN("Collapsed");
1664 if (strcasecmp(PLGetString(value
), "YES")==0)
1665 dock
->collapsed
= 1;
1670 /* restore auto-collapsed state */
1672 value
= PLGetDictionaryEntry(dock_state
, dAutoCollapse
);
1675 if (!PLIsString(value
))
1676 COMPLAIN("AutoCollapse");
1678 if (strcasecmp(PLGetString(value
), "YES")==0) {
1679 dock
->auto_collapse
= 1;
1680 dock
->collapsed
= 1;
1686 /* restore auto-raise/lower state */
1688 value
= PLGetDictionaryEntry(dock_state
, dAutoRaiseLower
);
1691 if (!PLIsString(value
))
1692 COMPLAIN("AutoRaiseLower");
1694 if (strcasecmp(PLGetString(value
), "YES")==0) {
1695 dock
->auto_raise_lower
= 1;
1701 /* restore attract icons state */
1703 dock
->attract_icons
= 0;
1705 value
= PLGetDictionaryEntry(dock_state
, dAutoAttractIcons
);
1708 if (!PLIsString(value
))
1709 COMPLAIN("AutoAttractIcons");
1711 if (strcasecmp(PLGetString(value
), "YES")==0)
1712 dock
->attract_icons
= 1;
1717 /* restore keep attracted icons state */
1719 dock
->keep_attracted
= 0;
1721 value
= PLGetDictionaryEntry(dock_state
, dKeepAttracted
);
1724 if (!PLIsString(value
))
1725 COMPLAIN("KeepAttracted");
1727 if (strcasecmp(PLGetString(value
), "YES")==0)
1728 dock
->keep_attracted
= 1;
1733 /* application list */
1735 apps
= PLGetDictionaryEntry(dock_state
, dApplications
);
1741 count
= PLGetNumberOfElements(apps
);
1746 old_top
= dock
->icon_array
[0];
1748 /* dock->icon_count is set to 1 when dock is created.
1749 * Since Clip is already restored, we want to keep it so for clip,
1750 * but for dock we may change the default top tile, so we set it to 0.
1752 if (type
== WM_DOCK
)
1753 dock
->icon_count
= 0;
1755 for (i
=0; i
<count
; i
++) {
1756 if (dock
->icon_count
>= dock
->max_icons
) {
1757 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1761 value
= PLGetArrayElement(apps
, i
);
1762 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1764 dock
->icon_array
[dock
->icon_count
] = aicon
;
1768 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
*ICON_SIZE
);
1769 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
*ICON_SIZE
);
1772 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1774 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1776 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
,
1779 if (!dock
->collapsed
)
1780 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1781 wRaiseFrame(aicon
->icon
->core
);
1784 } else if (dock
->icon_count
==0 && type
==WM_DOCK
)
1788 /* if the first icon is not defined, use the default */
1789 if (dock
->icon_array
[0]==NULL
) {
1790 /* update default icon */
1791 old_top
->x_pos
= dock
->x_pos
;
1792 old_top
->y_pos
= dock
->y_pos
;
1794 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1796 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1797 dock
->icon_array
[0] = old_top
;
1798 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1799 /* we don't need to increment dock->icon_count here because it was
1800 * incremented in the loop above.
1802 } else if (old_top
!=dock
->icon_array
[0]) {
1803 if (old_top
== scr
->clip_icon
)
1804 scr
->clip_icon
= dock
->icon_array
[0];
1805 wAppIconDestroy(old_top
);
1810 PLRelease(dock_state
);
1818 wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1820 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1822 btn
->drop_launch
= 0;
1824 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1827 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1839 wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1845 for (i
= 0; i
< dock
->max_icons
; i
++) {
1846 btn
= dock
->icon_array
[i
];
1847 if (!btn
|| !btn
->auto_launch
)
1850 state
= wmalloc(sizeof(WSavedState
));
1851 memset(state
, 0, sizeof(WSavedState
));
1852 state
->workspace
= workspace
;
1853 /* TODO: this is klugy and is very difficult to understand
1854 * what's going on. Try to clean up */
1855 wDockLaunchWithState(dock
, btn
, state
);
1859 #ifdef REDUCE_APPICONS
1861 wDockSimulateLaunch(WDock
*dock
, WAppIcon
*btn
)
1863 if ((btn
== NULL
) || (dock
== NULL
))
1866 if (!btn
->running
) {
1867 if ((btn
->icon
->owner
== NULL
) && (btn
->applist
))
1868 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
1869 if (!btn
->forced_dock
)
1879 findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1885 if ((dock
= scr
->dock
)!=NULL
) {
1886 for (i
=0; i
<dock
->max_icons
; i
++) {
1887 if (dock
->icon_array
[i
]
1888 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1894 if (*icon_pos
<0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
)!=NULL
) {
1895 for (i
=0; i
<dock
->max_icons
; i
++) {
1896 if (dock
->icon_array
[i
]
1897 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1910 wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
1916 dock
= findDock(scr
, event
, &icon_pos
);
1921 * Return True if the drop was on an application icon window.
1922 * In this case, let the ClientMessage handler redirect the
1923 * message to the app.
1925 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!=None
)
1928 if (dock
->icon_array
[icon_pos
]->dnd_command
!=NULL
) {
1929 scr
->flags
.dnd_data_convertion_status
= 0;
1931 btn
= dock
->icon_array
[icon_pos
];
1933 if (!btn
->forced_dock
) {
1934 btn
->relaunching
= btn
->running
;
1937 if (btn
->wm_instance
|| btn
->wm_class
) {
1938 WWindowAttributes attr
;
1939 memset(&attr
, 0, sizeof(WWindowAttributes
));
1940 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
1942 btn
->wm_class
, &attr
, NULL
, True
);
1944 if (!attr
.no_appicon
)
1950 btn
->drop_launch
= 1;
1951 scr
->last_dock
= dock
;
1952 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1957 if (!btn
->relaunching
) {
1964 #endif /* OFFIX_DND */
1969 wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1976 wwin
= icon
->icon
->owner
;
1977 if (icon
->command
==NULL
) {
1979 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
1981 icon
->command
= FlattenStringList(argv
, argc
);
1982 XFreeStringList(argv
);
1986 /* icon->forced_dock = 1;*/
1987 if (!icon
->attracted
|| dock
->type
!=WM_CLIP
|| dock
->keep_attracted
) {
1989 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
1990 _("Type the command used to launch the application"),
1992 if (command
&& (command
[0]==0 ||
1993 (command
[0]=='-' && command
[1]==0))) {
1997 icon
->command
= command
;
2003 /* If the target is the dock, reject the icon. If
2004 * the target is the clip, make it an attracted icon
2006 if (dock
->type
==WM_CLIP
) {
2007 icon
->attracted
= 1;
2008 if (!icon
->icon
->shadowed
) {
2009 icon
->icon
->shadowed
= 1;
2010 icon
->icon
->force_paint
= 1;
2022 for (index
=1; index
<dock
->max_icons
; index
++)
2023 if (dock
->icon_array
[index
] == NULL
)
2025 /* if (index == dock->max_icons)
2028 assert(index
< dock
->max_icons
);
2030 dock
->icon_array
[index
] = icon
;
2034 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2035 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2040 icon
->launching
= 0;
2043 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2044 if (dock
->type
== WM_CLIP
) {
2045 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2046 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2048 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2049 icon
->icon
->core
->descriptor
.parent
= icon
;
2051 MoveInStackListUnder(dock
->icon_array
[index
-1]->icon
->core
,
2053 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2054 wAppIconPaint(icon
);
2056 if (wPreferences
.auto_arrange_icons
)
2057 wArrangeIcons(dock
->screen_ptr
, True
);
2060 if (icon
->command
&& !icon
->dnd_command
) {
2061 icon
->dnd_command
= wmalloc(strlen(icon
->command
)+8);
2062 sprintf(icon
->dnd_command
, "%s %%d", icon
->command
);
2071 reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2075 for(index
=1; index
<dock
->max_icons
; index
++) {
2076 if(dock
->icon_array
[index
] == icon
)
2079 assert(index
< dock
->max_icons
);
2084 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2085 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2090 moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2100 wwin
= icon
->icon
->owner
;
2103 * For the moment we can't do this if we move icons in Clip from one
2104 * workspace to other, because if we move two or more icons without
2105 * command, the dialog box will not be able to tell us to which of the
2106 * moved icons it applies. -Dan
2108 if ((dest
->type
==WM_DOCK
/*|| dest->keep_attracted*/) && icon
->command
==NULL
) {
2109 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2111 icon
->command
= FlattenStringList(argv
, argc
);
2112 XFreeStringList(argv
);
2117 /* icon->forced_dock = 1;*/
2118 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2119 _("Type the command used to launch the application"),
2121 if (command
&& (command
[0]==0 ||
2122 (command
[0]=='-' && command
[1]==0))) {
2126 icon
->command
= command
;
2137 for(index
=1; index
<src
->max_icons
; index
++) {
2138 if(src
->icon_array
[index
] == icon
)
2141 assert(index
< src
->max_icons
);
2143 src
->icon_array
[index
] = NULL
;
2146 for(index
=1; index
<dest
->max_icons
; index
++) {
2147 if(dest
->icon_array
[index
] == NULL
)
2150 /* if (index == dest->max_icons)
2153 assert(index
< dest
->max_icons
);
2155 dest
->icon_array
[index
] = icon
;
2158 /* deselect the icon */
2159 if (icon
->icon
->selected
)
2160 wIconSelect(icon
->icon
);
2162 if (dest
->type
== WM_DOCK
) {
2163 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2164 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2166 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2167 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2170 /* set it to be kept when moving to dock, or to a clip that keep the
2172 * Unless the icon does not have a command set
2174 if (icon
->command
&& (dest
->type
==WM_DOCK
|| dest
->keep_attracted
)) {
2175 icon
->attracted
= 0;
2176 if (icon
->icon
->shadowed
) {
2177 icon
->icon
->shadowed
= 0;
2178 icon
->icon
->force_paint
= 1;
2182 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2188 icon
->x_pos
= dest
->x_pos
+ x
*ICON_SIZE
;
2189 icon
->y_pos
= dest
->y_pos
+ y
*ICON_SIZE
;
2193 MoveInStackListUnder(dest
->icon_array
[index
-1]->icon
->core
,
2195 wAppIconPaint(icon
);
2202 wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2206 /* make the settings panel be closed */
2208 DestroyDockAppSettingsPanel(icon
->panel
);
2213 icon
->attracted
= 0;
2214 if (icon
->icon
->shadowed
) {
2215 icon
->icon
->shadowed
= 0;
2216 icon
->icon
->force_paint
= 1;
2219 /* deselect the icon */
2220 if (icon
->icon
->selected
)
2221 wIconSelect(icon
->icon
);
2223 if (icon
->command
) {
2224 free(icon
->command
);
2225 icon
->command
= NULL
;
2228 if (icon
->dnd_command
) {
2229 free(icon
->dnd_command
);
2230 icon
->dnd_command
= NULL
;
2234 for (index
=1; index
<dock
->max_icons
; index
++)
2235 if (dock
->icon_array
[index
] == icon
)
2237 assert(index
< dock
->max_icons
);
2238 dock
->icon_array
[index
] = NULL
;
2243 /* if the dock is not attached to an application or
2244 * the the application did not set the approriate hints yet,
2245 * destroy the icon */
2246 #ifdef REDUCE_APPICONS
2247 if ((icon
->num_apps
== 0) && (!icon
->running
|| !wApplicationOf(icon
->main_window
)) )
2249 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2251 wAppIconDestroy(icon
);
2253 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2254 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2255 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2256 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2257 icon
->icon
->core
->descriptor
.parent
= icon
;
2259 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2261 wAppIconPaint(icon
);
2262 if (wPreferences
.auto_arrange_icons
) {
2263 wArrangeIcons(dock
->screen_ptr
, True
);
2266 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2272 * returns the closest Dock slot index for the passed
2275 * Returns False if icon can't be docked.
2278 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2279 int *ret_x
, int *ret_y
, int redocking
)
2281 WScreen
*scr
= dock
->screen_ptr
;
2284 int i
, offset
= ICON_SIZE
/2;
2285 WAppIcon
*aicon
= NULL
;
2286 WAppIcon
*nicon
= NULL
;
2287 int max_y_icons
, max_x_icons
;
2289 max_x_icons
= scr
->scr_width
/ICON_SIZE
;
2290 max_y_icons
= scr
->scr_height
/ICON_SIZE
-1;
2292 if (wPreferences
.flags
.noupdates
)
2298 /* if the dock is full */
2300 (dock
->icon_count
>= dock
->max_icons
)) {
2304 /* exact position */
2306 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2308 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2311 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2313 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2315 /* check if the icon is outside the screen boundaries */
2316 if (dx
+ ex_x
*ICON_SIZE
< -ICON_SIZE
+2 ||
2317 dx
+ ex_x
*ICON_SIZE
>= scr
->scr_width
-1 ||
2318 dy
+ ex_y
*ICON_SIZE
< -ICON_SIZE
+2 ||
2319 dy
+ ex_y
*ICON_SIZE
>= scr
->scr_height
-1)
2322 if (dock
->type
== WM_DOCK
) {
2323 if (icon
->dock
!= dock
&& ex_x
!= 0)
2326 for (i
=0; i
<dock
->max_icons
; i
++) {
2327 nicon
= dock
->icon_array
[i
];
2328 if (nicon
&& nicon
->yindex
== ex_y
) {
2337 int sig
, done
, closest
;
2339 /* Possible cases when redocking:
2341 * icon dragged out of range of any slot -> false
2342 * icon dragged to range of free slot
2343 * icon dragged to range of same slot
2344 * icon dragged to range of different icon
2346 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2349 if (ex_y
>= 0 && ex_y
<= max_y_icons
&& (aicon
== icon
|| !aicon
)) {
2357 /* start looking at the upper slot or lower? */
2358 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2365 /* look for closest free slot */
2366 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2370 closest
= sig
*(i
/2) + ex_y
;
2371 /* check if this slot is used */
2373 for (j
= 0; j
<dock
->max_icons
; j
++) {
2374 if (dock
->icon_array
[j
]
2375 && dock
->icon_array
[j
]->yindex
==closest
) {
2376 /* slot is used by someone else */
2377 if (dock
->icon_array
[j
]!=icon
)
2385 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2386 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2388 (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+1))) {
2394 } else { /* !redocking */
2396 /* if slot is free and the icon is close enough, return it */
2397 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2405 for (i
=0; i
<dock
->max_icons
; i
++) {
2406 nicon
= dock
->icon_array
[i
];
2407 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2413 for (i
=0; i
<dock
->max_icons
; i
++) {
2414 nicon
= dock
->icon_array
[i
];
2415 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2416 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2417 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2423 if (neighbours
&& (aicon
==NULL
|| (redocking
&& aicon
== icon
))) {
2432 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2433 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2435 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2436 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2437 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2441 * returns true if it can find a free slot in the dock,
2442 * in which case it changes x_pos and y_pos accordingly.
2443 * Else returns false.
2446 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2448 WScreen
*scr
= dock
->screen_ptr
;
2450 unsigned char *slot_map
;
2454 int i
, done
= False
;
2456 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2459 /* if the dock is full */
2460 if (dock
->icon_count
>= dock
->max_icons
) {
2464 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2465 if (scr
->dock
->on_right_side
)
2466 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2468 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2471 if (ex
< dock
->x_pos
)
2473 if (sx
> dock
->x_pos
+ICON_SIZE
)
2474 sx
= dock
->x_pos
+ICON_SIZE
;
2481 /* check if clip is in a corner */
2482 if (dock
->type
==WM_CLIP
) {
2483 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2485 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2487 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2489 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2496 /* If the clip is in the corner, use only slots that are in the border
2498 if (corner
!=C_NONE
) {
2502 hcount
= MIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2503 vcount
= MIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2504 hmap
= wmalloc(hcount
+1);
2505 memset(hmap
, 0, hcount
+1);
2506 vmap
= wmalloc(vcount
+1);
2507 memset(vmap
, 0, vcount
+1);
2509 /* mark used positions */
2512 for (i
=0; i
<dock
->max_icons
; i
++) {
2513 btn
= dock
->icon_array
[i
];
2517 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2518 vmap
[btn
->yindex
] = 1;
2519 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2520 hmap
[btn
->xindex
] = 1;
2523 for (i
=0; i
<dock
->max_icons
; i
++) {
2524 btn
= dock
->icon_array
[i
];
2528 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2529 vmap
[btn
->yindex
] = 1;
2530 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2531 hmap
[-btn
->xindex
] = 1;
2534 for (i
=0; i
<dock
->max_icons
; i
++) {
2535 btn
= dock
->icon_array
[i
];
2539 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2540 vmap
[-btn
->yindex
] = 1;
2541 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2542 hmap
[btn
->xindex
] = 1;
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;
2559 /* search a vacant slot */
2560 for (i
=1; i
<MAX(vcount
, hcount
); i
++) {
2561 if (i
< vcount
&& vmap
[i
]==0) {
2567 } else if (i
< hcount
&& hmap
[i
]==0) {
2577 /* If found a slot, translate and return */
2579 if (corner
==C_NW
|| corner
==C_NE
) {
2584 if (corner
==C_NE
|| corner
==C_SE
) {
2591 /* else, try to find a slot somewhere else */
2594 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2595 * placed outside of screen */
2596 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2598 /* In the worst case (the clip is in the corner of the screen),
2599 * the amount of icons that fit in the clip is smaller.
2600 * Double the map to get a safe value.
2606 slot_map
= wmalloc(mwidth
*mwidth
);
2607 memset(slot_map
, 0, mwidth
*mwidth
);
2609 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2611 /* mark used slots in the map. If the slot falls outside the map
2612 * (for example, when all icons are placed in line), ignore them. */
2613 for (i
=0; i
<dock
->max_icons
; i
++) {
2614 btn
= dock
->icon_array
[i
];
2616 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2618 /* Find closest slot from the center that is free by scanning the
2619 * map from the center to outward in circular passes.
2620 * This will not result in a neat layout, but will be optimal
2621 * in the sense that there will not be holes left.
2624 for (i
= 1; i
<= r
&& !done
; i
++) {
2627 /* top and bottom parts of the ring */
2628 for (x
= -i
; x
<= i
&& !done
; x
++) {
2629 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2631 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2632 if (slot_map
[XY2OFS(x
,y
)]==0
2633 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2640 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2641 if (slot_map
[XY2OFS(x
,y
)]==0
2642 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2649 /* left and right parts of the ring */
2650 for (y
= -i
+1; y
<= i
-1; y
++) {
2651 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2653 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2654 if (slot_map
[XY2OFS(x
,y
)]==0
2655 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2662 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2663 if (slot_map
[XY2OFS(x
,y
)]==0
2664 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2679 moveDock(WDock
*dock
, int new_x
, int new_y
)
2684 dock
->x_pos
= new_x
;
2685 dock
->y_pos
= new_y
;
2686 for (i
=0; i
<dock
->max_icons
; i
++) {
2687 btn
= dock
->icon_array
[i
];
2689 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2690 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2691 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2698 swapDock(WDock
*dock
)
2700 WScreen
*scr
= dock
->screen_ptr
;
2705 if (dock
->on_right_side
) {
2706 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2708 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2711 for (i
=0; i
<dock
->max_icons
; i
++) {
2712 btn
= dock
->icon_array
[i
];
2715 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2719 wScreenUpdateUsableArea(scr
);
2724 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2726 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2732 cmdline
= ExpandOptions(scr
, command
);
2734 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2742 ParseCommand(cmdline
, &argv
, &argc
);
2752 if ((pid
=fork())==0) {
2756 SetupEnvironment(scr
);
2762 args
= malloc(sizeof(char*)*(argc
+1));
2765 for (i
=0; i
<argc
; i
++) {
2769 execvp(argv
[0], args
);
2778 state
= wmalloc(sizeof(WSavedState
));
2779 memset(state
, 0, sizeof(WSavedState
));
2781 state
->miniaturized
= -1;
2783 if (btn
->dock
== scr
->dock
)
2784 state
->workspace
= -1;
2786 state
->workspace
= scr
->current_workspace
;
2788 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
2790 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
2801 wDockHideIcons(WDock
*dock
)
2809 btn
= dock
->icon_array
[0];
2811 for (i
=1; i
<dock
->max_icons
; i
++) {
2812 if (dock
->icon_array
[i
])
2813 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2822 wDockShowIcons(WDock
*dock
)
2830 btn
= dock
->icon_array
[0];
2831 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2833 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2834 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2836 for (i
=1; i
<dock
->max_icons
; i
++) {
2837 if (dock
->icon_array
[i
]) {
2838 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
2844 if (!dock
->collapsed
) {
2845 for (i
=1; i
<dock
->max_icons
; i
++) {
2846 if (dock
->icon_array
[i
]) {
2847 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2858 wDockLower(WDock
*dock
)
2862 for (i
=0; i
<dock
->max_icons
; i
++) {
2863 if (dock
->icon_array
[i
])
2864 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2870 wDockRaise(WDock
*dock
)
2874 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
2875 if (dock
->icon_array
[i
])
2876 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2882 wDockRaiseLower(WDock
*dock
)
2884 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2885 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2886 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2894 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
2896 icon
->launching
= 0;
2897 icon
->relaunching
= 0;
2898 dockIconPaint(icon
);
2903 wDockFindIconFor(WDock
*dock
, Window window
)
2908 for (i
=0; i
<dock
->max_icons
; i
++) {
2909 icon
= dock
->icon_array
[i
];
2910 if (icon
&& icon
->main_window
== window
)
2918 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
2921 #ifdef REDUCE_APPICONS
2922 WAppIconAppList
*tapplist
;
2924 char *wm_class
, *wm_instance
;
2926 Bool firstPass
= True
;
2928 char *command
= NULL
;
2934 if (XGetCommand(dpy
, window
, &argv
, &argc
)) {
2935 if (argc
> 0 && argv
!= NULL
)
2936 command
= FlattenStringList(argv
,argc
);
2938 XFreeStringList(argv
);
2943 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
2944 (!wm_class
&& !wm_instance
))
2948 for (i
=0; i
<dock
->max_icons
; i
++) {
2949 icon
= dock
->icon_array
[i
];
2953 /* app is already attached to icon */
2954 if (icon
->main_window
== window
) {
2959 if ((icon
->wm_instance
|| icon
->wm_class
)
2961 || (dock
->screen_ptr
->flags
.startup
&& !icon
->running
))) {
2963 if (icon
->wm_instance
&& wm_instance
&&
2964 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
2967 if (icon
->wm_class
&& wm_class
&&
2968 strcmp(icon
->wm_class
, wm_class
)!=0) {
2971 if (firstPass
&& command
&& strcmp(icon
->command
, command
)!=0) {
2975 if (!icon
->relaunching
) {
2978 /* Possibly an application that was docked with dockit,
2979 * but the user did not update WMState to indicate that
2980 * it was docked by force */
2981 wapp
= wApplicationOf(window
);
2983 icon
->forced_dock
= 1;
2986 if (!icon
->forced_dock
)
2987 icon
->main_window
= window
;
2989 #ifdef REDUCE_APPICONS
2990 tapplist
= wmalloc(sizeof(WAppIconAppList
));
2991 memset(tapplist
, 0, sizeof(WAppIconAppList
));
2992 tapplist
->next
= icon
->applist
;
2994 icon
->applist
->prev
= tapplist
;
2995 icon
->applist
= tapplist
;
2996 tapplist
->wapp
= wApplicationOf(window
);
3001 wDockFinishLaunch(dock
, icon
);
3006 if (firstPass
&& !found
) {
3023 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3025 if (!wPreferences
.flags
.noclip
) {
3026 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3027 if (scr
->current_workspace
!= workspace
) {
3028 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3030 wDockHideIcons(old_clip
);
3031 if (old_clip
->auto_raise_lower
)
3032 wDockLower(old_clip
);
3033 if (old_clip
->auto_collapse
&& !old_clip
->collapsed
)
3034 old_clip
->collapsed
= 1;
3035 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3037 if (scr
->flags
.clip_balloon_mapped
)
3038 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3045 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3050 for (i
=0; i
<dock
->max_icons
; i
++) {
3051 icon
= dock
->icon_array
[i
];
3055 if (icon
->launching
&& icon
->pid
== pid
) {
3056 if (!icon
->relaunching
) {
3058 icon
->main_window
= None
;
3060 wDockFinishLaunch(dock
, icon
);
3065 sprintf(msg
, _("Could not execute command \"%s\""),
3066 icon
->drop_launch
&& icon
->dnd_command
3067 ? icon
->dnd_command
: icon
->command
);
3069 sprintf(msg
, _("Could not execute command \"%s\""),
3072 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
3073 _("OK"), NULL
, NULL
);
3082 toggleLowered(WDock
*dock
)
3087 /* lower/raise Dock */
3088 if (!dock
->lowered
) {
3089 newlevel
= WMNormalLevel
;
3092 newlevel
= WMDockLevel
;
3096 for (i
=0; i
<dock
->max_icons
; i
++) {
3097 tmp
= dock
->icon_array
[i
];
3101 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3103 wLowerFrame(tmp
->icon
->core
);
3106 if (dock
->type
== WM_DOCK
)
3107 wScreenUpdateUsableArea(dock
->screen_ptr
);
3112 toggleCollapsed(WDock
*dock
)
3114 if (dock
->collapsed
) {
3115 dock
->collapsed
= 0;
3116 wDockShowIcons(dock
);
3119 dock
->collapsed
= 1;
3120 wDockHideIcons(dock
);
3126 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3128 WScreen
*scr
= dock
->screen_ptr
;
3129 WObjDescriptor
*desc
;
3131 WApplication
*wapp
= NULL
;
3134 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3136 if (dock
->type
== WM_DOCK
) {
3138 entry
= dock
->menu
->entries
[index
];
3139 entry
->flags
.indicator_on
= !dock
->lowered
;
3140 entry
->clientdata
= dock
;
3143 if (scr
->clip_options
)
3144 updateClipOptionsMenu(scr
->clip_options
, dock
);
3146 /* Rename Workspace */
3147 entry
= dock
->menu
->entries
[++index
];
3148 entry
->clientdata
= dock
;
3151 entry
= dock
->menu
->entries
[++index
];
3152 entry
->clientdata
= aicon
;
3153 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3155 /* (un)select all icons */
3156 entry
= dock
->menu
->entries
[++index
];
3157 entry
->clientdata
= aicon
;
3158 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3161 entry
= dock
->menu
->entries
[++index
];
3162 entry
->clientdata
= aicon
;
3163 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3165 /* this is the workspace submenu part */
3166 if (scr
->clip_submenu
)
3167 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3170 /* remove icon(s) */
3171 entry
= dock
->menu
->entries
[++index
];
3172 entry
->clientdata
= aicon
;
3173 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3175 /* attract icon(s) */
3176 entry
= dock
->menu
->entries
[++index
];
3177 entry
->clientdata
= aicon
;
3181 entry
= dock
->menu
->entries
[++index
];
3182 entry
->clientdata
= aicon
;
3183 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3186 entry
= dock
->menu
->entries
[++index
];
3187 entry
->clientdata
= aicon
;
3188 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3191 entry
= dock
->menu
->entries
[++index
];
3192 entry
->clientdata
= aicon
;
3193 if (aicon
->icon
->owner
) {
3194 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3195 if (wapp
&& wapp
->flags
.hidden
)
3196 entry
->text
= _("Unhide");
3198 entry
->text
= _("Hide");
3200 entry
->text
= _("Hide");
3202 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3205 entry
= dock
->menu
->entries
[++index
];
3206 entry
->clientdata
= aicon
;
3207 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
3208 && !wPreferences
.flags
.noupdates
);
3211 entry
= dock
->menu
->entries
[++index
];
3212 entry
->clientdata
= aicon
;
3213 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3215 if (!dock
->menu
->flags
.realized
)
3216 wMenuRealize(dock
->menu
);
3218 if (dock
->type
== WM_CLIP
) {
3219 x_pos
= event
->xbutton
.x_root
+2;
3221 x_pos
= dock
->on_right_side
?
3222 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 2 : 0;
3225 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3227 /* allow drag select */
3228 event
->xany
.send_event
= True
;
3229 desc
= &dock
->menu
->menu
->descriptor
;
3230 (*desc
->handle_mousedown
)(desc
, event
);
3235 openClipWorkspaceMenu(WScreen
*scr
, int x
, int y
)
3237 if (!scr
->clip_ws_menu
) {
3238 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3240 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
3241 wMenuMapAt(scr
->clip_ws_menu
, x
, y
, False
);
3245 /******************************************************************/
3247 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3249 WAppIcon
*btn
= desc
->parent
;
3250 WDock
*dock
= btn
->dock
;
3251 WApplication
*wapp
= NULL
;
3254 #ifdef REDUCE_APPICONS
3255 if ((btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) ||
3256 ((btn
->icon
->owner
== NULL
) && (btn
->applist
!= NULL
))) {
3257 if (btn
->icon
->owner
== NULL
)
3258 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
3263 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3265 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3269 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3271 /* go to the last workspace that the user worked on the app */
3273 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3276 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3279 if (event
->xbutton
.state
& MOD_MASK
) {
3280 wHideOtherApplications(btn
->icon
->owner
);
3283 if (event
->xbutton
.button
==Button1
) {
3285 if (event
->xbutton
.state
& MOD_MASK
) {
3286 /* raise/lower dock */
3287 toggleLowered(dock
);
3288 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3289 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3290 toggleCollapsed(dock
);
3292 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3293 } else if (btn
->command
) {
3294 if (!btn
->launching
&&
3295 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3296 launchDockedApplication(btn
);
3305 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3307 WScreen
*scr
= dock
->screen_ptr
;
3308 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3311 int grabbed
= 0, swapped
= 0, done
;
3312 Pixmap ghost
= None
;
3313 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3316 puts("moving dock");
3318 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3319 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3320 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3321 wwarning("pointer grab failed for dock move");
3324 for (x
=0; x
<dock
->max_icons
; x
++) {
3325 if (dock
->icon_array
[x
]!=NULL
&&
3326 dock
->icon_array
[x
]->yindex
> y
)
3327 y
= dock
->icon_array
[x
]->yindex
;
3330 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3334 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3335 |ButtonMotionMask
|ExposureMask
, &ev
);
3343 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3344 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3345 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3346 |ButtonReleaseMask
|ButtonPressMask
,
3347 wCursor
[WCUR_MOVE
], CurrentTime
);
3352 if (dock
->type
== WM_CLIP
) {
3353 if (ev
.xmotion
.x_root
- ofs_x
< 0) {
3355 } else if (ev
.xmotion
.x_root
- ofs_x
+ ICON_SIZE
>
3357 x
= scr
->scr_width
- ICON_SIZE
;
3359 x
= ev
.xmotion
.x_root
- ofs_x
;
3361 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3363 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3365 y
= scr
->scr_height
- ICON_SIZE
;
3367 y
= ev
.xmotion
.y_root
- ofs_y
;
3369 moveDock(dock
, x
, y
);
3371 /* move vertically if pointer is inside the dock*/
3372 if ((dock
->on_right_side
&&
3373 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3374 || (!dock
->on_right_side
&&
3375 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3377 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3379 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3381 y
= scr
->scr_height
- ICON_SIZE
;
3383 y
= ev
.xmotion
.y_root
- ofs_y
;
3385 moveDock(dock
, dock
->x_pos
, y
);
3387 /* move horizontally to change sides */
3388 x
= ev
.xmotion
.x_root
- ofs_x
;
3389 if (!dock
->on_right_side
) {
3393 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3394 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3395 -DOCK_EXTRA_SPACE
-1, dock
->y_pos
);
3398 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3399 scr
->scr_width
-ICON_SIZE
3400 -DOCK_EXTRA_SPACE
-1,
3402 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3404 XClearWindow(dpy
, scr
->dock_shadow
);
3407 XMapRaised(dpy
, scr
->dock_shadow
);
3410 if (superfluous
&& ghost
!=None
) {
3411 XFreePixmap(dpy
, ghost
);
3414 XUnmapWindow(dpy
, scr
->dock_shadow
);
3419 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3420 XMoveWindow(dpy
, scr
->dock_shadow
,
3421 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3424 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3425 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3426 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3428 XClearWindow(dpy
, scr
->dock_shadow
);
3431 XMapRaised(dpy
, scr
->dock_shadow
);
3434 XUnmapWindow(dpy
, scr
->dock_shadow
);
3436 if (superfluous
&& ghost
!=None
) {
3437 XFreePixmap(dpy
, ghost
);
3449 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3451 XUngrabPointer(dpy
, CurrentTime
);
3452 XUnmapWindow(dpy
, scr
->dock_shadow
);
3453 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3454 if (dock
->type
== WM_DOCK
) {
3457 dock
->on_right_side
= 1;
3459 dock
->on_right_side
= 0;
3461 wArrangeIcons(scr
, False
);
3470 XFreePixmap(dpy
, ghost
);
3471 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3474 puts("End dock move");
3481 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3483 WScreen
*scr
= dock
->screen_ptr
;
3485 WIcon
*icon
= aicon
->icon
;
3486 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3487 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3489 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3490 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3491 int shad_x
= x
, shad_y
= y
;
3492 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3494 Pixmap ghost
= None
;
3496 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3498 if (wPreferences
.flags
.noupdates
)
3501 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3502 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3503 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3505 wwarning("pointer grab failed for icon move");
3509 wRaiseFrame(icon
->core
);
3511 if (!wPreferences
.flags
.noclip
)
3512 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3514 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3516 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3519 wins
[0] = icon
->core
->window
;
3520 wins
[1] = scr
->dock_shadow
;
3521 XRestackWindows(dpy
, wins
, 2);
3522 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3523 ICON_SIZE
, ICON_SIZE
);
3525 if (icon
->pixmap
!=None
)
3526 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3528 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3530 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3531 XClearWindow(dpy
, scr
->dock_shadow
);
3533 XMapWindow(dpy
, scr
->dock_shadow
);
3539 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3540 |ButtonMotionMask
|ExposureMask
, &ev
);
3548 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3549 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3550 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3551 |ButtonReleaseMask
|ButtonPressMask
,
3552 wCursor
[WCUR_MOVE
], CurrentTime
);
3559 x
= ev
.xmotion
.x_root
- ofs_x
;
3560 y
= ev
.xmotion
.y_root
- ofs_y
;
3561 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3564 if (last_dock
!= dock
&& collapsed
) {
3565 last_dock
->collapsed
= 1;
3566 wDockHideIcons(last_dock
);
3569 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3570 dock
->collapsed
= 0;
3571 wDockShowIcons(dock
);
3573 if (dock
->auto_raise_lower
)
3578 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3581 if (last_dock
!= dock2
&& collapsed
) {
3582 last_dock
->collapsed
= 1;
3583 wDockHideIcons(last_dock
);
3586 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3587 dock2
->collapsed
= 0;
3588 wDockShowIcons(dock2
);
3590 if (dock2
->auto_raise_lower
)
3595 if (aicon
->launching
3596 || (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3597 || (!aicon
->running
&& tmp
)) {
3598 shad_x
= last_dock
->x_pos
+ ix
*wPreferences
.icon_size
;
3599 shad_y
= last_dock
->y_pos
+ iy
*wPreferences
.icon_size
;
3601 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3604 XMapWindow(dpy
, scr
->dock_shadow
);
3606 if (!collapsed
&& (collapsed
= last_dock
->collapsed
)) {
3607 last_dock
->collapsed
= 0;
3608 wDockShowIcons(last_dock
);
3615 XUnmapWindow(dpy
, scr
->dock_shadow
);
3617 if (last_dock
&& collapsed
&&
3618 aicon
->running
&& (ev
.xmotion
.state
& MOD_MASK
)) {
3619 last_dock
->collapsed
= 1;
3620 wDockHideIcons(last_dock
);
3627 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3634 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3636 XUngrabPointer(dpy
, CurrentTime
);
3638 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3639 XUnmapWindow(dpy
, scr
->dock_shadow
);
3641 reattachIcon(dock
, aicon
, ix
, iy
);
3642 if (clip
&& dock
!=clip
&& clip
->auto_raise_lower
)
3645 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3647 /* Slide it back if dock rejected it */
3648 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3650 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3652 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3660 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3661 /* We need to deselect it, even if is deselected in
3662 * wDockDetach(), because else DoKaboom() will fail.
3664 if (aicon
->icon
->selected
)
3665 wIconSelect(aicon
->icon
);
3666 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3669 if (clip
&& clip
->auto_raise_lower
)
3671 wDockDetach(dock
, aicon
);
3674 last_dock
->collapsed
= 1;
3675 wDockHideIcons(last_dock
);
3680 XFreePixmap(dpy
, ghost
);
3681 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3684 puts("End icon move");
3693 getClipButton(int px
, int py
)
3695 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
3697 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3700 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
3701 return CLIP_FORWARD
;
3702 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
3710 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3713 int done
, direction
, new_ws
;
3715 WDock
*clip
= scr
->clip_icon
->dock
;
3717 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3719 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3720 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3722 wClipIconPaint(scr
->clip_icon
);
3725 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
3726 |ButtonPressMask
, &ev
);
3733 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3734 if (new_dir
!= direction
) {
3735 direction
= new_dir
;
3736 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3737 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3738 wClipIconPaint(scr
->clip_icon
);
3746 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3751 clip
->lclip_button_pushed
= 0;
3752 clip
->rclip_button_pushed
= 0;
3754 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3756 if (direction
== CLIP_FORWARD
) {
3757 if (scr
->current_workspace
< scr
->workspace_count
-1)
3758 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3759 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
3760 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3761 else if (wPreferences
.ws_cycle
)
3762 wWorkspaceChange(scr
, 0);
3764 else if (direction
== CLIP_REWIND
) {
3765 if (scr
->current_workspace
> 0)
3766 wWorkspaceChange(scr
, scr
->current_workspace
-1);
3767 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
3768 wWorkspaceChange(scr
, scr
->workspace_count
-1);
3771 wClipIconPaint(scr
->clip_icon
);
3776 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3778 WAppIcon
*aicon
= desc
->parent
;
3779 WDock
*dock
= aicon
->dock
;
3780 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3782 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3785 scr
->last_dock
= dock
;
3787 if (dock
->menu
->flags
.mapped
)
3788 wMenuUnmap(dock
->menu
);
3790 if (IsDoubleClick(scr
, event
)) {
3791 /* double-click was not in the main clip icon */
3792 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
3793 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
3794 iconDblClick(desc
, event
);
3799 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
3800 XUnmapWindow(dpy
, scr
->clip_balloon
);
3801 scr
->flags
.clip_balloon_mapped
= 0;
3805 puts("handling dock");
3807 if (event
->xbutton
.button
== Button1
) {
3808 if (event
->xbutton
.state
& MOD_MASK
)
3813 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
3814 dock
->type
!=WM_DOCK
) {
3815 wIconSelect(aicon
->icon
);
3819 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
3820 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
3821 && dock
->type
==WM_CLIP
)
3822 handleClipChangeWorkspace(scr
, event
);
3824 handleDockMove(dock
, aicon
, event
);
3826 handleIconMove(dock
, aicon
, event
);
3828 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
3829 aicon
->xindex
==0 && aicon
->yindex
==0) {
3830 openClipWorkspaceMenu(scr
, event
->xbutton
.x_root
+2,
3831 event
->xbutton
.y_root
+2);
3832 if (scr
->clip_ws_menu
) {
3834 menu
= scr
->clip_ws_menu
;
3835 desc
= &menu
->menu
->descriptor
;
3837 event
->xany
.send_event
= True
;
3838 (*desc
->handle_mousedown
)(desc
, event
);
3840 } else if (event
->xbutton
.button
== Button3
) {
3841 openDockMenu(dock
, aicon
, event
);
3847 showClipBalloon(WDock
*dock
, int workspace
)
3851 WScreen
*scr
= dock
->screen_ptr
;
3855 scr
->flags
.clip_balloon_mapped
= 1;
3856 XMapWindow(dpy
, scr
->clip_balloon
);
3858 text
= scr
->workspaces
[workspace
]->name
;
3860 w
= wTextWidth(scr
->clip_title_font
->font
, text
, strlen(text
));
3862 h
= scr
->clip_title_font
->height
;
3863 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
3865 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
3866 y
= dock
->y_pos
+ ICON_SIZE
-scr
->clip_title_font
->height
- 3;
3868 if (x
+w
> scr
->scr_width
) {
3869 x
= scr
->scr_width
- w
;
3870 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
3871 y
= dock
->y_pos
- h
- 1;
3873 y
= dock
->y_pos
+ ICON_SIZE
;
3874 XRaiseWindow(dpy
, scr
->clip_balloon
);
3876 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
3877 stack
[1] = scr
->clip_balloon
;
3878 XRestackWindows(dpy
, stack
, 2);
3880 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
3881 XSetForeground(dpy
, scr
->clip_title_gc
,
3882 scr
->clip_title_pixel
[CLIP_NORMAL
]);
3883 XClearWindow(dpy
, scr
->clip_balloon
);
3884 wDrawString(scr
->clip_balloon
, scr
->clip_title_font
, scr
->clip_title_gc
,
3885 0, scr
->clip_title_font
->y
, text
, strlen(text
));
3890 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3892 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
3895 assert(event
->type
==EnterNotify
);
3897 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
3901 if (!dock
|| dock
->type
!=WM_CLIP
)
3904 if (dock
->auto_lower_magic
) {
3905 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3906 dock
->auto_lower_magic
= NULL
;
3908 if (dock
->auto_raise_lower
) {
3909 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
,
3914 if (btn
->xindex
== 0 && btn
->yindex
== 0)
3915 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
3917 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
3918 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
3919 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
3922 if (dock
->auto_collapse
) {
3923 if (dock
->auto_collapse_magic
) {
3924 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3925 dock
->auto_collapse_magic
= NULL
;
3928 if (dock
->collapsed
)
3929 toggleCollapsed(dock
);
3935 clipLeave(WDock
*dock
)
3938 WObjDescriptor
*desc
= NULL
;
3940 if (!dock
|| dock
->type
!=WM_CLIP
)
3943 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
)!=False
) {
3944 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3945 (XPointer
*)&desc
)!=XCNOENT
3946 && desc
&& desc
->parent_type
==WCLASS_DOCK_ICON
3947 && ((WAppIcon
*)desc
->parent
)->dock
3948 && ((WAppIcon
*)desc
->parent
)->dock
->type
==WM_CLIP
) {
3949 /* We didn't left the Clip yet */
3950 XPutBackEvent(dpy
, &event
);
3954 XPutBackEvent(dpy
, &event
);
3956 /* We entered a withdrawn window, so we're still in Clip */
3960 if (dock
->auto_raise_magic
) {
3961 WMDeleteTimerHandler(dock
->auto_raise_magic
);
3962 dock
->auto_raise_magic
= NULL
;
3964 if (dock
->auto_raise_lower
) {
3965 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
,
3970 if (dock
->auto_collapse
) {
3971 if (dock
->auto_collapse_magic
) {
3972 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3973 dock
->auto_collapse_magic
= NULL
;
3975 if (!dock
->collapsed
) {
3976 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
3985 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
3987 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
3989 assert(event
->type
==LeaveNotify
);
3991 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
3994 clipLeave(btn
->dock
);
3999 clipAutoCollapse(void *cdata
)
4001 WDock
*dock
= (WDock
*)cdata
;
4003 if (dock
->type
!=WM_CLIP
|| !dock
->auto_collapse
)
4006 if (!dock
->collapsed
&& dock
->auto_collapse_magic
!=NULL
) {
4007 toggleCollapsed(dock
);
4009 dock
->auto_collapse_magic
= NULL
;
4014 clipAutoLower(void *cdata
)
4016 WDock
*dock
= (WDock
*)cdata
;
4018 if (dock
->type
!=WM_CLIP
)
4021 if (dock
->auto_raise_lower
)
4024 dock
->auto_lower_magic
= NULL
;
4029 clipAutoRaise(void *cdata
)
4031 WDock
*dock
= (WDock
*)cdata
;
4033 if (dock
->type
!=WM_CLIP
)
4036 if (dock
->auto_raise_lower
)
4039 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4040 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4043 dock
->auto_raise_magic
= NULL
;