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 clipAutoExpand(void *cdata
);
143 static void launchDockedApplication(WAppIcon
*btn
);
145 static void clipAutoLower(void *cdata
);
146 static void clipAutoRaise(void *cdata
);
148 static void showClipBalloon(WDock
*dock
, int workspace
);
164 #endif /* OFFIX_DND */
174 dCommand
= PLRetain(PLMakeString("Command"));
176 dDropCommand
= PLRetain(PLMakeString("DropCommand"));
178 dAutoLaunch
= PLRetain(PLMakeString("AutoLaunch"));
179 dName
= PLRetain(PLMakeString("Name"));
180 dForced
= PLRetain(PLMakeString("Forced"));
181 dBuggyApplication
= PLRetain(PLMakeString("BuggyApplication"));
182 dYes
= PLRetain(PLMakeString("Yes"));
183 dNo
= PLRetain(PLMakeString("No"));
184 dHost
= PLRetain(PLMakeString("Host"));
186 dPosition
= PLMakeString("Position");
187 dApplications
= PLMakeString("Applications");
188 dLowered
= PLMakeString("Lowered");
189 dCollapsed
= PLMakeString("Collapsed");
190 dAutoCollapse
= PLMakeString("AutoCollapse");
191 dAutoRaiseLower
= PLMakeString("AutoRaiseLower");
192 dAutoAttractIcons
= PLMakeString("AutoAttractIcons");
193 dKeepAttracted
= PLMakeString("KeepAttracted");
195 dDock
= PLMakeString("Dock");
196 dClip
= PLMakeString("Clip");
202 renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
204 WDock
*dock
= entry
->clientdata
;
209 assert(entry
->clientdata
!=NULL
);
211 wspace
= dock
->screen_ptr
->current_workspace
;
213 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
215 sprintf(buffer
, _("Type the name for workspace %i:"), wspace
+1);
216 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
,
218 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
227 toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
229 assert(entry
->clientdata
!=NULL
);
231 toggleLowered(entry
->clientdata
);
233 entry
->flags
.indicator_on
= !((WDock
*)entry
->clientdata
)->lowered
;
241 killCallback(WMenu
*menu
, WMenuEntry
*entry
)
244 #ifdef REDUCE_APPICONS
245 WAppIconAppList
*tapplist
;
247 extern Atom _XA_WM_DELETE_WINDOW
;
252 if (!WCHECK_STATE(WSTATE_NORMAL
))
255 assert(entry
->clientdata
!=NULL
);
257 icon
= (WAppIcon
*)entry
->clientdata
;
261 WCHANGE_STATE(WSTATE_MODAL
);
263 #ifdef REDUCE_APPICONS
264 /* Send a delete message to the main window of each application
265 * bound to this docked appicon. - cls
267 tapplist
= icon
->applist
;
268 while (tapplist
!= NULL
) {
269 if (tapplist
->wapp
->main_window_desc
!= NULL
) {
270 if (tapplist
->wapp
->main_window_desc
->protocols
.DELETE_WINDOW
) {
271 wClientSendProtocol(tapplist
->wapp
->main_window_desc
,
272 _XA_WM_DELETE_WINDOW
, CurrentTime
);
274 wClientKill(tapplist
->wapp
->main_window_desc
);
277 tapplist
= tapplist
->next
;
280 buffer
= wstrappend(icon
->wm_class
,
281 _(" will be forcibly closed.\n"
282 "Any unsaved changes will be lost.\n"
285 if (wPreferences
.dont_confirm_kill
286 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
287 buffer
, _("Yes"), _("No"), NULL
)==WAPRDefault
) {
288 if (icon
->icon
&& icon
->icon
->owner
) {
289 wClientKill(icon
->icon
->owner
);
292 #endif /* !REDUCE_APPICONS */
296 WCHANGE_STATE(WSTATE_NORMAL
);}
300 getSelected(WDock
*dock
)
302 LinkedList
*ret
=NULL
;
306 for (i
=1; i
<dock
->max_icons
; i
++) {
307 btn
= dock
->icon_array
[i
];
308 if (btn
&& btn
->icon
->selected
) {
309 ret
= list_cons(btn
, ret
);
318 paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
320 Window win
= clipIcon
->icon
->core
->window
;
321 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
323 int pt
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
324 int tp
= ICON_SIZE
- pt
;
325 int as
= pt
- 15; /* 15 = 5+5+5 */
331 p
[1].x
= ICON_SIZE
-2;
333 p
[2].x
= ICON_SIZE
-2;
335 } else if (lpushed
) {
339 p
[1].y
= ICON_SIZE
-2;
341 p
[2].y
= ICON_SIZE
-2;
343 if (lpushed
|| rpushed
) {
344 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
345 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
346 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
349 p
[0].x
= p
[3].x
= ICON_SIZE
-6-as
;
351 p
[1].x
= ICON_SIZE
-6;
353 p
[2].x
= ICON_SIZE
-6;
356 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
357 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
359 XFillPolygon(dpy
, win
, scr
->clip_title_gc
, p
,3,Convex
,CoordModeOrigin
);
360 XDrawLines(dpy
, win
, scr
->clip_title_gc
, p
,4,CoordModeOrigin
);
364 p
[0].y
= p
[3].y
= ICON_SIZE
-6-as
;
366 p
[1].y
= ICON_SIZE
-6;
368 p
[2].y
= ICON_SIZE
-6;
370 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
371 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
373 XFillPolygon(dpy
, win
, scr
->clip_title_gc
, p
,3,Convex
,CoordModeOrigin
);
374 XDrawLines(dpy
, win
, scr
->clip_title_gc
, p
,4,CoordModeOrigin
);
380 wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
382 RImage
*tile
= RCloneImage(normalTile
);
388 pt
= CLIP_BUTTON_SIZE
*wPreferences
.icon_size
/64;
389 tp
= wPreferences
.icon_size
-1 - pt
;
392 black
.red
= black
.green
= black
.blue
= 0;
395 dark
.red
= dark
.green
= dark
.blue
= 80;
398 light
.red
= light
.green
= light
.blue
= 80;
402 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
-2,
404 RDrawLine(tile
, tp
-1, 0, wPreferences
.icon_size
-1, pt
+1, &black
);
405 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
-3,
410 ROperateLine(tile
, RAddOperation
, 2, tp
+2, pt
-2,
411 wPreferences
.icon_size
-3, &dark
);
412 RDrawLine(tile
, 0, tp
-1, pt
+1, wPreferences
.icon_size
-1, &black
);
413 ROperateLine(tile
, RSubtractOperation
, 0, tp
-2, pt
+1,
414 wPreferences
.icon_size
-2, &light
);
421 removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
423 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
426 LinkedList
*selectedIcons
;
429 assert(clickedIcon
!=NULL
);
431 dock
= clickedIcon
->dock
;
433 selectedIcons
= getSelected(dock
);
436 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
437 _("All selected icons will be removed!"),
438 _("OK"), _("Cancel"), NULL
)!=WAPRDefault
) {
442 if (clickedIcon
->xindex
==0 && clickedIcon
->yindex
==0)
444 selectedIcons
= list_cons(clickedIcon
, NULL
);
447 while (selectedIcons
) {
448 aicon
= selectedIcons
->head
;
449 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
450 wDockDetach(dock
, aicon
);
452 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
453 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
454 aicon
->x_pos
, aicon
->y_pos
);
455 if (!dock
->mapped
|| dock
->collapsed
)
456 XMapWindow(dpy
, aicon
->icon
->core
->window
);
458 list_remove_head(&selectedIcons
);
461 if (wPreferences
.auto_arrange_icons
)
462 wArrangeIcons(dock
->screen_ptr
, True
);
467 keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
469 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
472 LinkedList
*selectedIcons
;
474 assert(clickedIcon
!=NULL
);
475 dock
= clickedIcon
->dock
;
477 selectedIcons
= getSelected(dock
);
479 if (!selectedIcons
&& clickedIcon
!=dock
->screen_ptr
->clip_icon
) {
480 char *command
= NULL
;
482 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
483 clickedIcon
->editing
= 1;
484 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
485 _("Type the command used to launch the application"),
487 if (command
&& (command
[0]==0 ||
488 (command
[0]=='-' && command
[1]==0))) {
492 clickedIcon
->command
= command
;
493 clickedIcon
->editing
= 0;
495 clickedIcon
->editing
= 0;
502 selectedIcons
= list_cons(clickedIcon
, NULL
);
505 while (selectedIcons
) {
506 aicon
= selectedIcons
->head
;
507 if (aicon
->icon
->selected
)
508 wIconSelect(aicon
->icon
);
509 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
510 aicon
->attracted
= 0;
511 if (aicon
->icon
->shadowed
) {
512 aicon
->icon
->shadowed
= 0;
513 aicon
->icon
->force_paint
= 1;
514 wAppIconPaint(aicon
);
517 list_remove_head(&selectedIcons
);
525 toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
527 WDock
*dock
= (WDock
*)entry
->clientdata
;
529 assert(entry
->clientdata
!=NULL
);
531 dock
->attract_icons
= !dock
->attract_icons
;
532 /*if (!dock->attract_icons)
533 dock->keep_attracted = 0;*/
535 entry
->flags
.indicator_on
= dock
->attract_icons
;
542 toggleKeepCallback(WMenu
*menu
, WMenuEntry
*entry
)
544 WDock
*dock
= (WDock
*)entry
->clientdata
;
548 assert(entry
->clientdata
!=NULL
);
550 dock
->keep_attracted
= !dock
->keep_attracted
;
552 if (dock
->keep_attracted
) {
553 for (i
=0; i
< dock
->max_icons
; i
++) {
554 btn
= dock
->icon_array
[i
];
555 if (btn
&& btn
->attracted
&& btn
->command
) {
557 if (btn
->icon
->shadowed
) {
558 btn
->icon
->shadowed
= 0;
559 btn
->icon
->force_paint
= 1;
566 entry
->flags
.indicator_on
= dock
->keep_attracted
;
573 selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
575 WAppIcon
*icon
= (WAppIcon
*)entry
->clientdata
;
579 wIconSelect(icon
->icon
);
586 colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
588 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
591 int x
, y
, x_pos
, y_pos
;
593 assert(entry
->clientdata
!=NULL
);
594 clip
= clickedIcon
->dock
;
596 aicon
= clip
->screen_ptr
->app_icon_list
;
599 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
600 x_pos
= clip
->x_pos
+ x
*ICON_SIZE
;
601 y_pos
= clip
->y_pos
+ y
*ICON_SIZE
;
602 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
604 if (wPreferences
.no_animations
) {
605 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
607 SlideWindow(aicon
->icon
->core
->window
,
608 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
611 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
612 #endif /* ANIMATIONS */
614 aicon
->attracted
= 1;
615 if (!clip
->keep_attracted
&& !aicon
->icon
->shadowed
) {
616 aicon
->icon
->shadowed
= 1;
617 aicon
->icon
->force_paint
= 1;
618 /* We don't do an wAppIconPaint() here because it's in
619 * wDockAttachIcon(). -Dan
622 wDockAttachIcon(clip
, aicon
, x
, y
);
623 if (clip
->collapsed
|| !clip
->mapped
)
624 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
632 selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
634 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
636 LinkedList
*selectedIcons
;
640 assert(clickedIcon
!=NULL
);
641 dock
= clickedIcon
->dock
;
643 selectedIcons
= getSelected(dock
);
645 if (!selectedIcons
) {
646 for (i
=1; i
<dock
->max_icons
; i
++) {
647 btn
= dock
->icon_array
[i
];
648 if (btn
&& !btn
->icon
->selected
) {
649 wIconSelect(btn
->icon
);
653 while(selectedIcons
) {
654 btn
= selectedIcons
->head
;
655 wIconSelect(btn
->icon
);
656 list_remove_head(&selectedIcons
);
665 toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
667 assert(entry
->clientdata
!=NULL
);
669 toggleCollapsed(entry
->clientdata
);
671 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->collapsed
;
678 toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
681 assert(entry
->clientdata
!=NULL
);
683 dock
= (WDock
*) entry
->clientdata
;
685 dock
->auto_collapse
= !dock
->auto_collapse
;
687 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_collapse
;
694 toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
697 assert(entry
->clientdata
!=NULL
);
699 dock
= (WDock
*) entry
->clientdata
;
701 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
703 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_raise_lower
;
710 launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
712 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
714 launchDockedApplication(btn
);
719 settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
721 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
725 ShowDockAppSettingsPanel(btn
);
730 hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
733 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
735 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
737 if (wapp
->flags
.hidden
) {
738 wWorkspaceChange(btn
->icon
->core
->screen_ptr
,wapp
->last_workspace
);
739 wUnhideApplication(wapp
, False
, False
);
741 wHideApplication(wapp
);
747 unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
750 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
752 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
754 wUnhideApplication(wapp
, False
, True
);
759 mainIconCreate(WScreen
*scr
, int type
)
764 if (type
== WM_CLIP
) {
766 return scr
->clip_icon
;
767 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
768 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
769 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
770 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
771 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE;*/
774 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
775 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
781 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
782 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
783 btn
->icon
->core
->descriptor
.parent
= btn
;
784 /*ChangeStackingLevel(btn->icon->core, WMDockLevel);*/
785 XMapWindow(dpy
, btn
->icon
->core
->window
);
790 scr
->clip_icon
= btn
;
797 switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
799 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
800 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
802 LinkedList
*selectedIcons
;
805 if (entry
->order
== scr
->current_workspace
)
808 dest
= scr
->workspaces
[entry
->order
]->clip
;
810 selectedIcons
= getSelected(src
);
813 while(selectedIcons
) {
814 btn
= selectedIcons
->head
;
815 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
816 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
817 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
819 list_remove_head(&selectedIcons
);
821 } else if (icon
!= scr
->clip_icon
) {
822 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
823 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
824 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
832 launchDockedApplication(WAppIcon
*btn
)
834 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
836 if (!btn
->launching
&& btn
->command
!=NULL
) {
837 if (!btn
->forced_dock
) {
838 btn
->relaunching
= btn
->running
;
841 if (btn
->wm_instance
|| btn
->wm_class
) {
842 WWindowAttributes attr
;
843 memset(&attr
, 0, sizeof(WWindowAttributes
));
844 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
,
847 if (!attr
.no_appicon
&& !btn
->buggy_app
)
852 btn
->drop_launch
= 0;
853 scr
->last_dock
= btn
->dock
;
854 btn
->pid
= execCommand(btn
, btn
->command
, NULL
);
856 if (btn
->buggy_app
) {
857 /* give feedback that the app was launched */
861 WMAddTimerHandler(200, (WMCallback
*)dockIconPaint
, btn
);
866 wwarning(_("could not launch application %s\n"), btn
->command
);
868 if (!btn
->relaunching
)
877 updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
879 WScreen
*scr
= menu
->frame
->screen_ptr
;
880 char title
[MAX_WORKSPACENAME_WIDTH
+1];
886 for (i
=0; i
<scr
->workspace_count
; i
++) {
887 if (i
< menu
->entry_no
) {
888 if (strcmp(menu
->entries
[i
]->text
,scr
->workspaces
[i
]->name
)!=0) {
889 free(menu
->entries
[i
]->text
);
890 strcpy(title
, scr
->workspaces
[i
]->name
);
891 menu
->entries
[i
]->text
= wstrdup(title
);
892 menu
->flags
.realized
= 0;
894 menu
->entries
[i
]->clientdata
= (void*)icon
;
896 strcpy(title
, scr
->workspaces
[i
]->name
);
898 wMenuAddCallback(menu
, title
, switchWSCommand
, (void*)icon
);
900 menu
->flags
.realized
= 0;
902 if (i
== scr
->current_workspace
) {
903 wMenuSetEnabled(menu
, i
, False
);
905 wMenuSetEnabled(menu
, i
, True
);
909 if (!menu
->flags
.realized
)
915 makeWorkspaceMenu(WScreen
*scr
)
919 menu
= wMenuCreate(scr
, NULL
, False
);
921 wwarning(_("could not create workspace submenu for Clip menu"));
923 wMenuAddCallback(menu
, "", switchWSCommand
, (void*)scr
->clip_icon
);
925 menu
->flags
.realized
= 0;
933 updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
942 entry
= menu
->entries
[index
];
943 entry
->flags
.indicator_on
= !dock
->lowered
;
944 entry
->clientdata
= dock
;
947 entry
= menu
->entries
[++index
];
948 entry
->flags
.indicator_on
= dock
->collapsed
;
949 entry
->clientdata
= dock
;
952 entry
= menu
->entries
[++index
];
953 entry
->flags
.indicator_on
= dock
->auto_collapse
;
954 entry
->clientdata
= dock
;
956 /* auto-raise/lower */
957 entry
= menu
->entries
[++index
];
958 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
959 entry
->clientdata
= dock
;
962 entry
= menu
->entries
[++index
];
963 entry
->flags
.indicator_on
= dock
->attract_icons
;
964 entry
->clientdata
= dock
;
966 /* keep attracted icons */
967 entry
= menu
->entries
[++index
];
968 entry
->flags
.indicator_on
= dock
->keep_attracted
;
969 entry
->clientdata
= dock
;
971 menu
->flags
.realized
= 0;
977 makeClipOptionsMenu(WScreen
*scr
)
982 menu
= wMenuCreate(scr
, NULL
, False
);
984 wwarning(_("could not create options submenu for Clip menu"));
988 entry
= wMenuAddCallback(menu
, _("Keep on top"),
989 toggleLoweredCallback
, NULL
);
990 entry
->flags
.indicator
= 1;
991 entry
->flags
.indicator_on
= 1;
992 entry
->flags
.indicator_type
= MI_CHECK
;
994 entry
= wMenuAddCallback(menu
, _("Collapsed"),
995 toggleCollapsedCallback
, NULL
);
996 entry
->flags
.indicator
= 1;
997 entry
->flags
.indicator_on
= 1;
998 entry
->flags
.indicator_type
= MI_CHECK
;
1000 entry
= wMenuAddCallback(menu
, _("AutoCollapse"),
1001 toggleAutoCollapseCallback
, NULL
);
1002 entry
->flags
.indicator
= 1;
1003 entry
->flags
.indicator_on
= 1;
1004 entry
->flags
.indicator_type
= MI_CHECK
;
1006 entry
= wMenuAddCallback(menu
, _("AutoRaiseLower"),
1007 toggleAutoRaiseLowerCallback
, NULL
);
1008 entry
->flags
.indicator
= 1;
1009 entry
->flags
.indicator_on
= 1;
1010 entry
->flags
.indicator_type
= MI_CHECK
;
1012 entry
= wMenuAddCallback(menu
, _("AutoAttract Icons"),
1013 toggleAutoAttractCallback
, NULL
);
1014 entry
->flags
.indicator
= 1;
1015 entry
->flags
.indicator_on
= 1;
1016 entry
->flags
.indicator_type
= MI_CHECK
;
1018 entry
= wMenuAddCallback(menu
, _("Keep Attracted Icons"),
1019 toggleKeepCallback
, NULL
);
1020 entry
->flags
.indicator
= 1;
1021 entry
->flags
.indicator_on
= 1;
1022 entry
->flags
.indicator_type
= MI_CHECK
;
1024 menu
->flags
.realized
= 0;
1032 dockMenuCreate(WScreen
*scr
, int type
)
1037 if (type
== WM_CLIP
&& scr
->clip_menu
)
1038 return scr
->clip_menu
;
1040 menu
= wMenuCreate(scr
, NULL
, False
);
1041 if (type
!= WM_CLIP
) {
1042 entry
= wMenuAddCallback(menu
, _("Keep on top"),
1043 toggleLoweredCallback
, NULL
);
1044 entry
->flags
.indicator
= 1;
1045 entry
->flags
.indicator_on
= 1;
1046 entry
->flags
.indicator_type
= MI_CHECK
;
1048 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1049 scr
->clip_options
= makeClipOptionsMenu(scr
);
1050 if (scr
->clip_options
)
1051 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1053 wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1055 wMenuAddCallback(menu
, _("(Un)Select Icon"), selectCallback
, NULL
);
1057 wMenuAddCallback(menu
, _("(Un)Select All Icons"), selectIconsCallback
,
1060 wMenuAddCallback(menu
, _("Keep Icon(s)"), keepIconsCallback
, NULL
);
1062 entry
= wMenuAddCallback(menu
, _("Move Icon(s) To"), NULL
, NULL
);
1063 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1064 if (scr
->clip_submenu
)
1065 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1067 wMenuAddCallback(menu
, _("Remove Icon(s)"), removeIconsCallback
, NULL
);
1069 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1072 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1074 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1076 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1078 entry
->text
= _("Hide");
1080 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1082 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1084 if (type
== WM_CLIP
)
1085 scr
->clip_menu
= menu
;
1092 wDockCreate(WScreen
*scr
, int type
)
1100 dock
= wmalloc(sizeof(WDock
));
1101 memset(dock
, 0, sizeof(WDock
));
1103 if (type
== WM_CLIP
)
1104 icon_count
= CLIP_MAX_ICONS
;
1106 icon_count
= scr
->scr_height
/wPreferences
.icon_size
;
1108 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*)*icon_count
);
1109 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*)*icon_count
);
1111 dock
->max_icons
= icon_count
;
1113 btn
= mainIconCreate(scr
, type
);
1117 dock
->x_pos
= btn
->x_pos
;
1118 dock
->y_pos
= btn
->y_pos
;
1119 dock
->screen_ptr
= scr
;
1121 dock
->icon_count
= 1;
1122 dock
->on_right_side
= 1;
1123 dock
->collapsed
= 0;
1124 dock
->auto_collapse
= 0;
1125 dock
->auto_collapse_magic
= NULL
;
1126 dock
->auto_raise_lower
= 0;
1127 dock
->auto_lower_magic
= NULL
;
1128 dock
->auto_raise_magic
= NULL
;
1129 dock
->attract_icons
= 0;
1130 dock
->keep_attracted
= 0;
1132 dock
->icon_array
[0] = btn
;
1133 wRaiseFrame(btn
->icon
->core
);
1134 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1136 /* create dock menu */
1137 dock
->menu
= dockMenuCreate(scr
, type
);
1144 wDockDestroy(WDock
*dock
)
1149 for (i
=(dock
->type
== WM_CLIP
) ? 1 : 0; i
<dock
->max_icons
; i
++) {
1150 aicon
= dock
->icon_array
[i
];
1152 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1153 wDockDetach(dock
, aicon
);
1155 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
1156 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
1157 aicon
->x_pos
, aicon
->y_pos
);
1158 if (!dock
->mapped
|| dock
->collapsed
)
1159 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1163 if (wPreferences
.auto_arrange_icons
)
1164 wArrangeIcons(dock
->screen_ptr
, True
);
1165 free(dock
->icon_array
);
1166 if (dock
->menu
&& dock
->type
!=WM_CLIP
)
1167 wMenuDestroy(dock
->menu
, True
);
1173 wClipIconPaint(WAppIcon
*aicon
)
1175 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1176 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1178 Window win
= aicon
->icon
->core
->window
;
1179 int length
, nlength
;
1180 char *ws_name
, ws_number
[10];
1183 wIconPaint(aicon
->icon
);
1185 length
= strlen(workspace
->name
);
1186 ws_name
= malloc(length
+ 1);
1187 sprintf(ws_name
, "%s", workspace
->name
);
1188 sprintf(ws_number
, "%i", scr
->current_workspace
+ 1);
1189 nlength
= strlen(ws_number
);
1191 gc
= scr
->clip_title_gc
;
1193 if (!workspace
->clip
->collapsed
)
1194 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_NORMAL
]);
1196 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_COLLAPSED
]);
1198 ty
= ICON_SIZE
- scr
->clip_title_font
->height
- 3;
1200 tx
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
1202 wDrawString(win
, scr
->clip_title_font
, gc
, tx
,
1203 ty
+ scr
->clip_title_font
->y
, ws_name
, length
);
1205 tx
= (ICON_SIZE
/2 - wTextWidth(scr
->clip_title_font
->font
, ws_number
, nlength
))/2;
1207 wDrawString(win
, scr
->clip_title_font
, gc
, tx
,
1208 scr
->clip_title_font
->y
+ 2, ws_number
, nlength
);
1212 if (aicon
->launching
) {
1213 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1214 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1216 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
,
1217 aicon
->dock
->rclip_button_pushed
);
1222 clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1224 wClipIconPaint(desc
->parent
);
1229 dockIconPaint(WAppIcon
*btn
)
1231 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1232 wClipIconPaint(btn
);
1239 make_icon_state(WAppIcon
*btn
)
1241 proplist_t node
= NULL
;
1242 proplist_t command
, autolaunch
, name
, forced
, host
, position
, buggy
;
1248 command
= PLMakeString("-");
1250 command
= PLMakeString(btn
->command
);
1252 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1254 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1256 name
= PLMakeString(tmp
);
1260 forced
= btn
->forced_dock
? dYes
: dNo
;
1262 buggy
= btn
->buggy_app
? dYes
: dNo
;
1264 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1265 sprintf(buffer
, "%i,%i", btn
->x_pos
, btn
->y_pos
);
1267 sprintf(buffer
, "%hi,%hi", btn
->xindex
, btn
->yindex
);
1268 position
= PLMakeString(buffer
);
1270 node
= PLMakeDictionaryFromEntries(dCommand
, command
,
1272 dAutoLaunch
, autolaunch
,
1274 dBuggyApplication
, buggy
,
1275 dPosition
, position
,
1279 PLRelease(position
);
1281 if (btn
->dnd_command
) {
1282 command
= PLMakeString(btn
->dnd_command
);
1283 PLInsertDictionaryEntry(node
, dDropCommand
, command
);
1286 #endif /* OFFIX_DND */
1288 if (btn
->client_machine
&& btn
->remote_start
) {
1289 host
= PLMakeString(btn
->client_machine
);
1290 PLInsertDictionaryEntry(node
, dHost
, host
);
1300 dockSaveState(WDock
*dock
)
1303 proplist_t icon_info
;
1304 proplist_t list
=NULL
, dock_state
=NULL
;
1308 list
= PLMakeArrayFromElements(NULL
);
1310 for (i
=(dock
->type
==WM_DOCK
? 0 : 1); i
<dock
->max_icons
; i
++) {
1311 WAppIcon
*btn
= dock
->icon_array
[i
];
1313 if (!btn
|| (btn
->attracted
&& !dock
->keep_attracted
))
1316 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1317 list
= PLAppendArrayElement(list
, icon_info
);
1318 PLRelease(icon_info
);
1322 dock_state
= PLMakeDictionaryFromEntries(dApplications
, list
, NULL
);
1326 if (dock
->type
== WM_DOCK
) {
1327 sprintf(buffer
, "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0),
1329 value
= PLMakeString(buffer
);
1330 PLInsertDictionaryEntry(dock_state
, dPosition
, value
);
1334 value
= (dock
->lowered
? dYes
: dNo
);
1335 PLInsertDictionaryEntry(dock_state
, dLowered
, value
);
1337 if (dock
->type
== WM_CLIP
) {
1338 value
= (dock
->collapsed
? dYes
: dNo
);
1339 PLInsertDictionaryEntry(dock_state
, dCollapsed
, value
);
1341 value
= (dock
->auto_collapse
? dYes
: dNo
);
1342 PLInsertDictionaryEntry(dock_state
, dAutoCollapse
, value
);
1344 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1345 PLInsertDictionaryEntry(dock_state
, dAutoRaiseLower
, value
);
1347 value
= (dock
->attract_icons
? dYes
: dNo
);
1348 PLInsertDictionaryEntry(dock_state
, dAutoAttractIcons
, value
);
1350 value
= (dock
->keep_attracted
? dYes
: dNo
);
1351 PLInsertDictionaryEntry(dock_state
, dKeepAttracted
, value
);
1359 wDockSaveState(WScreen
*scr
)
1361 proplist_t dock_state
;
1363 dock_state
= dockSaveState(scr
->dock
);
1365 PLInsertDictionaryEntry(scr
->session_state
, dDock
, dock_state
);
1367 PLRelease(dock_state
);
1372 wClipSaveState(WScreen
*scr
)
1374 proplist_t clip_state
;
1376 clip_state
= make_icon_state(scr
->clip_icon
);
1378 PLInsertDictionaryEntry(scr
->session_state
, dClip
, clip_state
);
1380 PLRelease(clip_state
);
1385 wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1387 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1392 restore_icon_state(WScreen
*scr
, proplist_t info
, int type
, int index
)
1395 char *wclass
, *winstance
;
1396 proplist_t cmd
, value
;
1400 cmd
= PLGetDictionaryEntry(info
, dCommand
);
1401 if (!cmd
|| !PLIsString(cmd
)) {
1405 /* parse window name */
1406 value
= PLGetDictionaryEntry(info
, dName
);
1410 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1412 if (!winstance
&& !wclass
) {
1419 command
= wstrdup(PLGetString(cmd
));
1423 if (!command
|| strcmp(command
, "-")==0) {
1434 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
,
1441 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1442 if (type
== WM_CLIP
) {
1443 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1444 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1446 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1447 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1451 cmd
= PLGetDictionaryEntry(info
, dDropCommand
);
1453 aicon
->dnd_command
= wstrdup(PLGetString(cmd
));
1456 /* check auto launch */
1457 value
= PLGetDictionaryEntry(info
, dAutoLaunch
);
1459 aicon
->auto_launch
= 0;
1461 if (PLIsString(value
)) {
1462 if (strcasecmp(PLGetString(value
), "YES")==0)
1463 aicon
->auto_launch
= 1;
1465 wwarning(_("bad value in docked icon state info %s"),
1466 PLGetString(dAutoLaunch
));
1470 /* check if it wasn't normally docked */
1471 value
= PLGetDictionaryEntry(info
, dForced
);
1473 aicon
->forced_dock
= 0;
1475 if (PLIsString(value
)) {
1476 if (strcasecmp(PLGetString(value
), "YES")==0)
1477 aicon
->forced_dock
= 1;
1479 wwarning(_("bad value in docked icon state info %s"),
1480 PLGetString(dForced
));
1484 /* check if we can rely on the stuff in the app */
1485 value
= PLGetDictionaryEntry(info
, dBuggyApplication
);
1487 aicon
->buggy_app
= 0;
1489 if (PLIsString(value
)) {
1490 if (strcasecmp(PLGetString(value
), "YES")==0)
1491 aicon
->buggy_app
= 1;
1493 wwarning(_("bad value in docked icon state info %s"),
1494 PLGetString(dBuggyApplication
));
1498 /* get position in the dock */
1499 value
= PLGetDictionaryEntry(info
, dPosition
);
1500 if (value
&& PLIsString(value
)) {
1501 if (sscanf(PLGetString(value
), "%hi,%hi", &aicon
->xindex
,
1503 wwarning(_("bad value in docked icon state info %s"),
1504 PLGetString(dPosition
));
1506 /* check position sanity */
1507 /* incomplete section! */
1508 if (type
== WM_DOCK
) {
1510 if (aicon
->yindex
< 0)
1511 wwarning(_("bad value in docked icon position %i,%i"),
1512 aicon
->xindex
, aicon
->yindex
);
1515 aicon
->yindex
= index
;
1526 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1530 wClipRestoreState(WScreen
*scr
, proplist_t clip_state
)
1536 icon
= mainIconCreate(scr
, WM_CLIP
);
1541 PLRetain(clip_state
);
1543 /* restore position */
1545 value
= PLGetDictionaryEntry(clip_state
, dPosition
);
1548 if (!PLIsString(value
))
1549 COMPLAIN("Position");
1551 if (sscanf(PLGetString(value
), "%i,%i", &icon
->x_pos
,
1553 COMPLAIN("Position");
1555 /* check position sanity */
1556 if (icon
->y_pos
< 0)
1558 else if (icon
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1559 icon
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1561 if (icon
->x_pos
< 0)
1563 else if (icon
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1564 icon
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1569 value
= PLGetDictionaryEntry(clip_state
, dDropCommand
);
1570 if (value
&& PLIsString(value
))
1571 icon
->dnd_command
= wstrdup(PLGetString(value
));
1574 PLRelease(clip_state
);
1581 wDockRestoreState(WScreen
*scr
, proplist_t dock_state
, int type
)
1586 WAppIcon
*aicon
, *old_top
;
1590 dock
= wDockCreate(scr
, type
);
1596 PLRetain(dock_state
);
1599 /* restore position */
1601 value
= PLGetDictionaryEntry(dock_state
, dPosition
);
1604 if (!PLIsString(value
))
1605 COMPLAIN("Position");
1607 if (sscanf(PLGetString(value
), "%i,%i", &dock
->x_pos
,
1609 COMPLAIN("Position");
1611 /* check position sanity */
1612 if (dock
->y_pos
< 0)
1614 else if (dock
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1615 dock
->y_pos
= scr
->scr_height
- ICON_SIZE
;
1617 /* This is no more needed. ??? */
1618 if (type
== WM_CLIP
) {
1619 if (dock
->x_pos
< 0)
1621 else if (dock
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1622 dock
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1624 if (dock
->x_pos
>= 0) {
1625 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1626 dock
->on_right_side
= 0;
1628 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1629 dock
->on_right_side
= 1;
1635 /* restore lowered/raised state */
1639 value
= PLGetDictionaryEntry(dock_state
, dLowered
);
1642 if (!PLIsString(value
))
1643 COMPLAIN("Lowered");
1645 if (strcasecmp(PLGetString(value
), "YES")==0)
1651 /* restore collapsed state */
1653 dock
->collapsed
= 0;
1655 value
= PLGetDictionaryEntry(dock_state
, dCollapsed
);
1658 if (!PLIsString(value
))
1659 COMPLAIN("Collapsed");
1661 if (strcasecmp(PLGetString(value
), "YES")==0)
1662 dock
->collapsed
= 1;
1667 /* restore auto-collapsed state */
1669 value
= PLGetDictionaryEntry(dock_state
, dAutoCollapse
);
1672 if (!PLIsString(value
))
1673 COMPLAIN("AutoCollapse");
1675 if (strcasecmp(PLGetString(value
), "YES")==0) {
1676 dock
->auto_collapse
= 1;
1677 dock
->collapsed
= 1;
1683 /* restore auto-raise/lower state */
1685 value
= PLGetDictionaryEntry(dock_state
, dAutoRaiseLower
);
1688 if (!PLIsString(value
))
1689 COMPLAIN("AutoRaiseLower");
1691 if (strcasecmp(PLGetString(value
), "YES")==0) {
1692 dock
->auto_raise_lower
= 1;
1698 /* restore attract icons state */
1700 dock
->attract_icons
= 0;
1702 value
= PLGetDictionaryEntry(dock_state
, dAutoAttractIcons
);
1705 if (!PLIsString(value
))
1706 COMPLAIN("AutoAttractIcons");
1708 if (strcasecmp(PLGetString(value
), "YES")==0)
1709 dock
->attract_icons
= 1;
1714 /* restore keep attracted icons state */
1716 dock
->keep_attracted
= 0;
1718 value
= PLGetDictionaryEntry(dock_state
, dKeepAttracted
);
1721 if (!PLIsString(value
))
1722 COMPLAIN("KeepAttracted");
1724 if (strcasecmp(PLGetString(value
), "YES")==0)
1725 dock
->keep_attracted
= 1;
1730 /* application list */
1732 apps
= PLGetDictionaryEntry(dock_state
, dApplications
);
1738 count
= PLGetNumberOfElements(apps
);
1743 old_top
= dock
->icon_array
[0];
1745 /* dock->icon_count is set to 1 when dock is created.
1746 * Since Clip is already restored, we want to keep it so for clip,
1747 * but for dock we may change the default top tile, so we set it to 0.
1749 if (type
== WM_DOCK
)
1750 dock
->icon_count
= 0;
1752 for (i
=0; i
<count
; i
++) {
1753 if (dock
->icon_count
>= dock
->max_icons
) {
1754 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1758 value
= PLGetArrayElement(apps
, i
);
1759 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1761 dock
->icon_array
[dock
->icon_count
] = aicon
;
1765 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
*ICON_SIZE
);
1766 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
*ICON_SIZE
);
1769 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1771 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1773 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
,
1776 if (!dock
->collapsed
)
1777 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1778 wRaiseFrame(aicon
->icon
->core
);
1781 } else if (dock
->icon_count
==0 && type
==WM_DOCK
)
1785 /* if the first icon is not defined, use the default */
1786 if (dock
->icon_array
[0]==NULL
) {
1787 /* update default icon */
1788 old_top
->x_pos
= dock
->x_pos
;
1789 old_top
->y_pos
= dock
->y_pos
;
1791 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1793 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1794 dock
->icon_array
[0] = old_top
;
1795 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1796 /* we don't need to increment dock->icon_count here because it was
1797 * incremented in the loop above.
1799 } else if (old_top
!=dock
->icon_array
[0]) {
1800 if (old_top
== scr
->clip_icon
)
1801 scr
->clip_icon
= dock
->icon_array
[0];
1802 wAppIconDestroy(old_top
);
1807 PLRelease(dock_state
);
1815 wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1817 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1819 btn
->drop_launch
= 0;
1821 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1824 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1836 wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1842 for (i
= 0; i
< dock
->max_icons
; i
++) {
1843 btn
= dock
->icon_array
[i
];
1844 if (!btn
|| !btn
->auto_launch
)
1847 state
= wmalloc(sizeof(WSavedState
));
1848 memset(state
, 0, sizeof(WSavedState
));
1849 state
->workspace
= workspace
;
1850 /* TODO: this is klugy and is very difficult to understand
1851 * what's going on. Try to clean up */
1852 wDockLaunchWithState(dock
, btn
, state
);
1856 #ifdef REDUCE_APPICONS
1858 wDockSimulateLaunch(WDock
*dock
, WAppIcon
*btn
)
1860 if ((btn
== NULL
) || (dock
== NULL
))
1863 if (!btn
->running
) {
1864 if ((btn
->icon
->owner
== NULL
) && (btn
->applist
))
1865 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
1866 if (!btn
->forced_dock
)
1876 findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1882 if ((dock
= scr
->dock
)!=NULL
) {
1883 for (i
=0; i
<dock
->max_icons
; i
++) {
1884 if (dock
->icon_array
[i
]
1885 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1891 if (*icon_pos
<0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
)!=NULL
) {
1892 for (i
=0; i
<dock
->max_icons
; i
++) {
1893 if (dock
->icon_array
[i
]
1894 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1907 wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
1913 dock
= findDock(scr
, event
, &icon_pos
);
1918 * Return True if the drop was on an application icon window.
1919 * In this case, let the ClientMessage handler redirect the
1920 * message to the app.
1922 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!=None
)
1925 if (dock
->icon_array
[icon_pos
]->dnd_command
!=NULL
) {
1926 scr
->flags
.dnd_data_convertion_status
= 0;
1928 btn
= dock
->icon_array
[icon_pos
];
1930 if (!btn
->forced_dock
) {
1931 btn
->relaunching
= btn
->running
;
1934 if (btn
->wm_instance
|| btn
->wm_class
) {
1935 WWindowAttributes attr
;
1936 memset(&attr
, 0, sizeof(WWindowAttributes
));
1937 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
1939 btn
->wm_class
, &attr
, NULL
, True
);
1941 if (!attr
.no_appicon
)
1947 btn
->drop_launch
= 1;
1948 scr
->last_dock
= dock
;
1949 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1954 if (!btn
->relaunching
) {
1961 #endif /* OFFIX_DND */
1966 wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1973 wwin
= icon
->icon
->owner
;
1974 if (icon
->command
==NULL
) {
1976 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
1978 icon
->command
= FlattenStringList(argv
, argc
);
1979 XFreeStringList(argv
);
1983 /* icon->forced_dock = 1;*/
1984 if (!icon
->attracted
|| dock
->type
!=WM_CLIP
|| dock
->keep_attracted
) {
1986 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
1987 _("Type the command used to launch the application"),
1989 if (command
&& (command
[0]==0 ||
1990 (command
[0]=='-' && command
[1]==0))) {
1994 icon
->command
= command
;
2000 /* If the target is the dock, reject the icon. If
2001 * the target is the clip, make it an attracted icon
2003 if (dock
->type
==WM_CLIP
) {
2004 icon
->attracted
= 1;
2005 if (!icon
->icon
->shadowed
) {
2006 icon
->icon
->shadowed
= 1;
2007 icon
->icon
->force_paint
= 1;
2019 for (index
=1; index
<dock
->max_icons
; index
++)
2020 if (dock
->icon_array
[index
] == NULL
)
2022 /* if (index == dock->max_icons)
2025 assert(index
< dock
->max_icons
);
2027 dock
->icon_array
[index
] = icon
;
2031 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2032 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2037 icon
->launching
= 0;
2040 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2041 if (dock
->type
== WM_CLIP
) {
2042 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2043 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2045 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2046 icon
->icon
->core
->descriptor
.parent
= icon
;
2048 MoveInStackListUnder(dock
->icon_array
[index
-1]->icon
->core
,
2050 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2051 wAppIconPaint(icon
);
2053 if (wPreferences
.auto_arrange_icons
)
2054 wArrangeIcons(dock
->screen_ptr
, True
);
2057 if (icon
->command
&& !icon
->dnd_command
) {
2058 icon
->dnd_command
= wmalloc(strlen(icon
->command
)+8);
2059 sprintf(icon
->dnd_command
, "%s %%d", icon
->command
);
2068 reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2072 for(index
=1; index
<dock
->max_icons
; index
++) {
2073 if(dock
->icon_array
[index
] == icon
)
2076 assert(index
< dock
->max_icons
);
2081 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2082 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2087 moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2097 wwin
= icon
->icon
->owner
;
2100 * For the moment we can't do this if we move icons in Clip from one
2101 * workspace to other, because if we move two or more icons without
2102 * command, the dialog box will not be able to tell us to which of the
2103 * moved icons it applies. -Dan
2105 if ((dest
->type
==WM_DOCK
/*|| dest->keep_attracted*/) && icon
->command
==NULL
) {
2106 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2108 icon
->command
= FlattenStringList(argv
, argc
);
2109 XFreeStringList(argv
);
2114 /* icon->forced_dock = 1;*/
2115 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2116 _("Type the command used to launch the application"),
2118 if (command
&& (command
[0]==0 ||
2119 (command
[0]=='-' && command
[1]==0))) {
2123 icon
->command
= command
;
2134 for(index
=1; index
<src
->max_icons
; index
++) {
2135 if(src
->icon_array
[index
] == icon
)
2138 assert(index
< src
->max_icons
);
2140 src
->icon_array
[index
] = NULL
;
2143 for(index
=1; index
<dest
->max_icons
; index
++) {
2144 if(dest
->icon_array
[index
] == NULL
)
2147 /* if (index == dest->max_icons)
2150 assert(index
< dest
->max_icons
);
2152 dest
->icon_array
[index
] = icon
;
2155 /* deselect the icon */
2156 if (icon
->icon
->selected
)
2157 wIconSelect(icon
->icon
);
2159 if (dest
->type
== WM_DOCK
) {
2160 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2161 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2163 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2164 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2167 /* set it to be kept when moving to dock, or to a clip that keep the
2169 * Unless the icon does not have a command set
2171 if (icon
->command
&& (dest
->type
==WM_DOCK
|| dest
->keep_attracted
)) {
2172 icon
->attracted
= 0;
2173 if (icon
->icon
->shadowed
) {
2174 icon
->icon
->shadowed
= 0;
2175 icon
->icon
->force_paint
= 1;
2179 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2185 icon
->x_pos
= dest
->x_pos
+ x
*ICON_SIZE
;
2186 icon
->y_pos
= dest
->y_pos
+ y
*ICON_SIZE
;
2190 MoveInStackListUnder(dest
->icon_array
[index
-1]->icon
->core
,
2192 wAppIconPaint(icon
);
2199 wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2203 /* make the settings panel be closed */
2205 DestroyDockAppSettingsPanel(icon
->panel
);
2210 icon
->attracted
= 0;
2211 if (icon
->icon
->shadowed
) {
2212 icon
->icon
->shadowed
= 0;
2213 icon
->icon
->force_paint
= 1;
2216 /* deselect the icon */
2217 if (icon
->icon
->selected
)
2218 wIconSelect(icon
->icon
);
2220 if (icon
->command
) {
2221 free(icon
->command
);
2222 icon
->command
= NULL
;
2225 if (icon
->dnd_command
) {
2226 free(icon
->dnd_command
);
2227 icon
->dnd_command
= NULL
;
2231 for (index
=1; index
<dock
->max_icons
; index
++)
2232 if (dock
->icon_array
[index
] == icon
)
2234 assert(index
< dock
->max_icons
);
2235 dock
->icon_array
[index
] = NULL
;
2240 /* if the dock is not attached to an application or
2241 * the the application did not set the approriate hints yet,
2242 * destroy the icon */
2243 #ifdef REDUCE_APPICONS
2244 if ((icon
->num_apps
== 0) && (!icon
->running
|| !wApplicationOf(icon
->main_window
)) )
2246 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2248 wAppIconDestroy(icon
);
2250 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2251 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2252 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2253 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2254 icon
->icon
->core
->descriptor
.parent
= icon
;
2256 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2258 wAppIconPaint(icon
);
2259 if (wPreferences
.auto_arrange_icons
) {
2260 wArrangeIcons(dock
->screen_ptr
, True
);
2263 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2269 * returns the closest Dock slot index for the passed
2272 * Returns False if icon can't be docked.
2275 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2276 int *ret_x
, int *ret_y
, int redocking
)
2278 WScreen
*scr
= dock
->screen_ptr
;
2281 int i
, offset
= ICON_SIZE
/2;
2282 WAppIcon
*aicon
= NULL
;
2283 WAppIcon
*nicon
= NULL
;
2284 int max_y_icons
, max_x_icons
;
2286 max_x_icons
= scr
->scr_width
/ICON_SIZE
;
2287 max_y_icons
= scr
->scr_height
/ICON_SIZE
-1;
2289 if (wPreferences
.flags
.noupdates
)
2295 /* if the dock is full */
2297 (dock
->icon_count
>= dock
->max_icons
)) {
2301 /* exact position */
2303 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2305 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2308 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2310 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2312 /* check if the icon is outside the screen boundaries */
2313 if (dx
+ ex_x
*ICON_SIZE
< -ICON_SIZE
+2 ||
2314 dx
+ ex_x
*ICON_SIZE
>= scr
->scr_width
-1 ||
2315 dy
+ ex_y
*ICON_SIZE
< -ICON_SIZE
+2 ||
2316 dy
+ ex_y
*ICON_SIZE
>= scr
->scr_height
-1)
2319 if (dock
->type
== WM_DOCK
) {
2320 if (icon
->dock
!= dock
&& ex_x
!= 0)
2323 for (i
=0; i
<dock
->max_icons
; i
++) {
2324 nicon
= dock
->icon_array
[i
];
2325 if (nicon
&& nicon
->yindex
== ex_y
) {
2334 int sig
, done
, closest
;
2336 /* Possible cases when redocking:
2338 * icon dragged out of range of any slot -> false
2339 * icon dragged to range of free slot
2340 * icon dragged to range of same slot
2341 * icon dragged to range of different icon
2343 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2346 if (ex_y
>= 0 && ex_y
<= max_y_icons
&& (aicon
== icon
|| !aicon
)) {
2354 /* start looking at the upper slot or lower? */
2355 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2362 /* look for closest free slot */
2363 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2367 closest
= sig
*(i
/2) + ex_y
;
2368 /* check if this slot is used */
2370 for (j
= 0; j
<dock
->max_icons
; j
++) {
2371 if (dock
->icon_array
[j
]
2372 && dock
->icon_array
[j
]->yindex
==closest
) {
2373 /* slot is used by someone else */
2374 if (dock
->icon_array
[j
]!=icon
)
2382 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2383 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2385 (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+1))) {
2391 } else { /* !redocking */
2393 /* if slot is free and the icon is close enough, return it */
2394 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2402 for (i
=0; i
<dock
->max_icons
; i
++) {
2403 nicon
= dock
->icon_array
[i
];
2404 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2410 for (i
=0; i
<dock
->max_icons
; i
++) {
2411 nicon
= dock
->icon_array
[i
];
2412 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2413 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2414 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2420 if (neighbours
&& (aicon
==NULL
|| (redocking
&& aicon
== icon
))) {
2429 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2430 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2432 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2433 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2434 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2438 * returns true if it can find a free slot in the dock,
2439 * in which case it changes x_pos and y_pos accordingly.
2440 * Else returns false.
2443 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2445 WScreen
*scr
= dock
->screen_ptr
;
2447 unsigned char *slot_map
;
2451 int i
, done
= False
;
2453 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2456 /* if the dock is full */
2457 if (dock
->icon_count
>= dock
->max_icons
) {
2461 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2462 if (scr
->dock
->on_right_side
)
2463 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2465 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2468 if (ex
< dock
->x_pos
)
2470 if (sx
> dock
->x_pos
+ICON_SIZE
)
2471 sx
= dock
->x_pos
+ICON_SIZE
;
2478 /* check if clip is in a corner */
2479 if (dock
->type
==WM_CLIP
) {
2480 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2482 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2484 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2486 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2493 /* If the clip is in the corner, use only slots that are in the border
2495 if (corner
!=C_NONE
) {
2499 hcount
= MIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2500 vcount
= MIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2501 hmap
= wmalloc(hcount
+1);
2502 memset(hmap
, 0, hcount
+1);
2503 vmap
= wmalloc(vcount
+1);
2504 memset(vmap
, 0, vcount
+1);
2506 /* mark used positions */
2509 for (i
=0; i
<dock
->max_icons
; i
++) {
2510 btn
= dock
->icon_array
[i
];
2514 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2515 vmap
[btn
->yindex
] = 1;
2516 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2517 hmap
[btn
->xindex
] = 1;
2520 for (i
=0; i
<dock
->max_icons
; i
++) {
2521 btn
= dock
->icon_array
[i
];
2525 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2526 vmap
[btn
->yindex
] = 1;
2527 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2528 hmap
[-btn
->xindex
] = 1;
2531 for (i
=0; i
<dock
->max_icons
; i
++) {
2532 btn
= dock
->icon_array
[i
];
2536 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2537 vmap
[-btn
->yindex
] = 1;
2538 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2539 hmap
[btn
->xindex
] = 1;
2543 for (i
=0; i
<dock
->max_icons
; i
++) {
2544 btn
= dock
->icon_array
[i
];
2548 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2549 vmap
[-btn
->yindex
] = 1;
2550 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2551 hmap
[-btn
->xindex
] = 1;
2556 /* search a vacant slot */
2557 for (i
=1; i
<MAX(vcount
, hcount
); i
++) {
2558 if (i
< vcount
&& vmap
[i
]==0) {
2564 } else if (i
< hcount
&& hmap
[i
]==0) {
2574 /* If found a slot, translate and return */
2576 if (corner
==C_NW
|| corner
==C_NE
) {
2581 if (corner
==C_NE
|| corner
==C_SE
) {
2588 /* else, try to find a slot somewhere else */
2591 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2592 * placed outside of screen */
2593 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2595 /* In the worst case (the clip is in the corner of the screen),
2596 * the amount of icons that fit in the clip is smaller.
2597 * Double the map to get a safe value.
2603 slot_map
= wmalloc(mwidth
*mwidth
);
2604 memset(slot_map
, 0, mwidth
*mwidth
);
2606 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2608 /* mark used slots in the map. If the slot falls outside the map
2609 * (for example, when all icons are placed in line), ignore them. */
2610 for (i
=0; i
<dock
->max_icons
; i
++) {
2611 btn
= dock
->icon_array
[i
];
2613 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2615 /* Find closest slot from the center that is free by scanning the
2616 * map from the center to outward in circular passes.
2617 * This will not result in a neat layout, but will be optimal
2618 * in the sense that there will not be holes left.
2621 for (i
= 1; i
<= r
&& !done
; i
++) {
2624 /* top and bottom parts of the ring */
2625 for (x
= -i
; x
<= i
&& !done
; x
++) {
2626 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2628 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2629 if (slot_map
[XY2OFS(x
,y
)]==0
2630 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2637 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2638 if (slot_map
[XY2OFS(x
,y
)]==0
2639 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2646 /* left and right parts of the ring */
2647 for (y
= -i
+1; y
<= i
-1; y
++) {
2648 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2650 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2651 if (slot_map
[XY2OFS(x
,y
)]==0
2652 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2659 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2660 if (slot_map
[XY2OFS(x
,y
)]==0
2661 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2676 moveDock(WDock
*dock
, int new_x
, int new_y
)
2681 dock
->x_pos
= new_x
;
2682 dock
->y_pos
= new_y
;
2683 for (i
=0; i
<dock
->max_icons
; i
++) {
2684 btn
= dock
->icon_array
[i
];
2686 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2687 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2688 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2695 swapDock(WDock
*dock
)
2697 WScreen
*scr
= dock
->screen_ptr
;
2702 if (dock
->on_right_side
) {
2703 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2705 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2708 for (i
=0; i
<dock
->max_icons
; i
++) {
2709 btn
= dock
->icon_array
[i
];
2712 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2716 wScreenUpdateUsableArea(scr
);
2721 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2723 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2729 cmdline
= ExpandOptions(scr
, command
);
2731 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2739 ParseCommand(cmdline
, &argv
, &argc
);
2749 if ((pid
=fork())==0) {
2753 SetupEnvironment(scr
);
2759 args
= malloc(sizeof(char*)*(argc
+1));
2762 for (i
=0; i
<argc
; i
++) {
2766 execvp(argv
[0], args
);
2775 state
= wmalloc(sizeof(WSavedState
));
2776 memset(state
, 0, sizeof(WSavedState
));
2778 state
->miniaturized
= -1;
2780 if (btn
->dock
== scr
->dock
)
2781 state
->workspace
= -1;
2783 state
->workspace
= scr
->current_workspace
;
2785 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
2787 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
2798 wDockHideIcons(WDock
*dock
)
2806 btn
= dock
->icon_array
[0];
2808 for (i
=1; i
<dock
->max_icons
; i
++) {
2809 if (dock
->icon_array
[i
])
2810 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2819 wDockShowIcons(WDock
*dock
)
2827 btn
= dock
->icon_array
[0];
2828 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2830 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2831 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2833 for (i
=1; i
<dock
->max_icons
; i
++) {
2834 if (dock
->icon_array
[i
]) {
2835 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
2841 if (!dock
->collapsed
) {
2842 for (i
=1; i
<dock
->max_icons
; i
++) {
2843 if (dock
->icon_array
[i
]) {
2844 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2855 wDockLower(WDock
*dock
)
2859 for (i
=0; i
<dock
->max_icons
; i
++) {
2860 if (dock
->icon_array
[i
])
2861 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2867 wDockRaise(WDock
*dock
)
2871 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
2872 if (dock
->icon_array
[i
])
2873 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2879 wDockRaiseLower(WDock
*dock
)
2881 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2882 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2883 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2891 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
2893 icon
->launching
= 0;
2894 icon
->relaunching
= 0;
2895 dockIconPaint(icon
);
2900 wDockFindIconFor(WDock
*dock
, Window window
)
2905 for (i
=0; i
<dock
->max_icons
; i
++) {
2906 icon
= dock
->icon_array
[i
];
2907 if (icon
&& icon
->main_window
== window
)
2915 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
2918 #ifdef REDUCE_APPICONS
2919 WAppIconAppList
*tapplist
;
2921 char *wm_class
, *wm_instance
;
2923 Bool firstPass
= True
;
2925 char *command
= NULL
;
2931 if (XGetCommand(dpy
, window
, &argv
, &argc
)) {
2932 if (argc
> 0 && argv
!= NULL
)
2933 command
= FlattenStringList(argv
,argc
);
2935 XFreeStringList(argv
);
2940 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
2941 (!wm_class
&& !wm_instance
))
2945 for (i
=0; i
<dock
->max_icons
; i
++) {
2946 icon
= dock
->icon_array
[i
];
2950 /* app is already attached to icon */
2951 if (icon
->main_window
== window
) {
2956 if ((icon
->wm_instance
|| icon
->wm_class
)
2958 || (dock
->screen_ptr
->flags
.startup
&& !icon
->running
))) {
2960 if (icon
->wm_instance
&& wm_instance
&&
2961 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
2964 if (icon
->wm_class
&& wm_class
&&
2965 strcmp(icon
->wm_class
, wm_class
)!=0) {
2968 if (firstPass
&& command
&& strcmp(icon
->command
, command
)!=0) {
2972 if (!icon
->relaunching
) {
2975 /* Possibly an application that was docked with dockit,
2976 * but the user did not update WMState to indicate that
2977 * it was docked by force */
2978 wapp
= wApplicationOf(window
);
2980 icon
->forced_dock
= 1;
2983 if (!icon
->forced_dock
)
2984 icon
->main_window
= window
;
2986 #ifdef REDUCE_APPICONS
2987 tapplist
= wmalloc(sizeof(WAppIconAppList
));
2988 memset(tapplist
, 0, sizeof(WAppIconAppList
));
2989 tapplist
->next
= icon
->applist
;
2991 icon
->applist
->prev
= tapplist
;
2992 icon
->applist
= tapplist
;
2993 tapplist
->wapp
= wApplicationOf(window
);
2998 wDockFinishLaunch(dock
, icon
);
3003 if (firstPass
&& !found
) {
3020 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3022 if (!wPreferences
.flags
.noclip
) {
3023 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3024 if (scr
->current_workspace
!= workspace
) {
3025 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3027 wDockHideIcons(old_clip
);
3028 if (old_clip
->auto_raise_lower
) {
3029 if (old_clip
->auto_raise_magic
) {
3030 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3031 old_clip
->auto_raise_magic
= NULL
;
3033 wDockLower(old_clip
);
3035 if (old_clip
->auto_collapse
) {
3036 if (old_clip
->auto_expand_magic
) {
3037 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3038 old_clip
->auto_expand_magic
= NULL
;
3040 old_clip
->collapsed
= 1;
3042 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3044 if (scr
->flags
.clip_balloon_mapped
)
3045 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3052 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3057 for (i
=0; i
<dock
->max_icons
; i
++) {
3058 icon
= dock
->icon_array
[i
];
3062 if (icon
->launching
&& icon
->pid
== pid
) {
3063 if (!icon
->relaunching
) {
3065 icon
->main_window
= None
;
3067 wDockFinishLaunch(dock
, icon
);
3072 sprintf(msg
, _("Could not execute command \"%s\""),
3073 icon
->drop_launch
&& icon
->dnd_command
3074 ? icon
->dnd_command
: icon
->command
);
3076 sprintf(msg
, _("Could not execute command \"%s\""),
3079 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
3080 _("OK"), NULL
, NULL
);
3089 toggleLowered(WDock
*dock
)
3094 /* lower/raise Dock */
3095 if (!dock
->lowered
) {
3096 newlevel
= WMNormalLevel
;
3099 newlevel
= WMDockLevel
;
3103 for (i
=0; i
<dock
->max_icons
; i
++) {
3104 tmp
= dock
->icon_array
[i
];
3108 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3110 wLowerFrame(tmp
->icon
->core
);
3113 if (dock
->type
== WM_DOCK
)
3114 wScreenUpdateUsableArea(dock
->screen_ptr
);
3119 toggleCollapsed(WDock
*dock
)
3121 if (dock
->collapsed
) {
3122 dock
->collapsed
= 0;
3123 wDockShowIcons(dock
);
3126 dock
->collapsed
= 1;
3127 wDockHideIcons(dock
);
3133 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3135 WScreen
*scr
= dock
->screen_ptr
;
3136 WObjDescriptor
*desc
;
3138 WApplication
*wapp
= NULL
;
3141 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3143 if (dock
->type
== WM_DOCK
) {
3145 entry
= dock
->menu
->entries
[index
];
3146 entry
->flags
.indicator_on
= !dock
->lowered
;
3147 entry
->clientdata
= dock
;
3150 if (scr
->clip_options
)
3151 updateClipOptionsMenu(scr
->clip_options
, dock
);
3153 /* Rename Workspace */
3154 entry
= dock
->menu
->entries
[++index
];
3155 entry
->clientdata
= dock
;
3158 entry
= dock
->menu
->entries
[++index
];
3159 entry
->clientdata
= aicon
;
3160 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3162 /* (un)select all icons */
3163 entry
= dock
->menu
->entries
[++index
];
3164 entry
->clientdata
= aicon
;
3165 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3168 entry
= dock
->menu
->entries
[++index
];
3169 entry
->clientdata
= aicon
;
3170 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3172 /* this is the workspace submenu part */
3173 if (scr
->clip_submenu
)
3174 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3177 /* remove icon(s) */
3178 entry
= dock
->menu
->entries
[++index
];
3179 entry
->clientdata
= aicon
;
3180 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3182 /* attract icon(s) */
3183 entry
= dock
->menu
->entries
[++index
];
3184 entry
->clientdata
= aicon
;
3188 entry
= dock
->menu
->entries
[++index
];
3189 entry
->clientdata
= aicon
;
3190 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3193 entry
= dock
->menu
->entries
[++index
];
3194 entry
->clientdata
= aicon
;
3195 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3198 entry
= dock
->menu
->entries
[++index
];
3199 entry
->clientdata
= aicon
;
3200 if (aicon
->icon
->owner
) {
3201 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3202 if (wapp
&& wapp
->flags
.hidden
)
3203 entry
->text
= _("Unhide");
3205 entry
->text
= _("Hide");
3207 entry
->text
= _("Hide");
3209 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3212 entry
= dock
->menu
->entries
[++index
];
3213 entry
->clientdata
= aicon
;
3214 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
3215 && !wPreferences
.flags
.noupdates
);
3218 entry
= dock
->menu
->entries
[++index
];
3219 entry
->clientdata
= aicon
;
3220 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3222 if (!dock
->menu
->flags
.realized
)
3223 wMenuRealize(dock
->menu
);
3225 if (dock
->type
== WM_CLIP
) {
3226 x_pos
= event
->xbutton
.x_root
+2;
3228 x_pos
= dock
->on_right_side
?
3229 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 2 : 0;
3232 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3234 /* allow drag select */
3235 event
->xany
.send_event
= True
;
3236 desc
= &dock
->menu
->menu
->descriptor
;
3237 (*desc
->handle_mousedown
)(desc
, event
);
3242 openClipWorkspaceMenu(WScreen
*scr
, int x
, int y
)
3244 if (!scr
->clip_ws_menu
) {
3245 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3247 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
3248 wMenuMapAt(scr
->clip_ws_menu
, x
, y
, False
);
3252 /******************************************************************/
3254 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3256 WAppIcon
*btn
= desc
->parent
;
3257 WDock
*dock
= btn
->dock
;
3258 WApplication
*wapp
= NULL
;
3261 #ifdef REDUCE_APPICONS
3262 if ((btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) ||
3263 ((btn
->icon
->owner
== NULL
) && (btn
->applist
!= NULL
))) {
3264 if (btn
->icon
->owner
== NULL
)
3265 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
3270 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3272 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3276 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3278 /* go to the last workspace that the user worked on the app */
3280 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3283 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3286 if (event
->xbutton
.state
& MOD_MASK
) {
3287 wHideOtherApplications(btn
->icon
->owner
);
3290 if (event
->xbutton
.button
==Button1
) {
3292 if (event
->xbutton
.state
& MOD_MASK
) {
3293 /* raise/lower dock */
3294 toggleLowered(dock
);
3295 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3296 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3297 toggleCollapsed(dock
);
3299 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3300 } else if (btn
->command
) {
3301 if (!btn
->launching
&&
3302 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3303 launchDockedApplication(btn
);
3312 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3314 WScreen
*scr
= dock
->screen_ptr
;
3315 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3318 int grabbed
= 0, swapped
= 0, done
;
3319 Pixmap ghost
= None
;
3320 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3323 puts("moving dock");
3325 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3326 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3327 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3328 wwarning("pointer grab failed for dock move");
3331 for (x
=0; x
<dock
->max_icons
; x
++) {
3332 if (dock
->icon_array
[x
]!=NULL
&&
3333 dock
->icon_array
[x
]->yindex
> y
)
3334 y
= dock
->icon_array
[x
]->yindex
;
3337 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3341 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3342 |ButtonMotionMask
|ExposureMask
, &ev
);
3350 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3351 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3352 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3353 |ButtonReleaseMask
|ButtonPressMask
,
3354 wCursor
[WCUR_MOVE
], CurrentTime
);
3359 if (dock
->type
== WM_CLIP
) {
3360 if (ev
.xmotion
.x_root
- ofs_x
< 0) {
3362 } else if (ev
.xmotion
.x_root
- ofs_x
+ ICON_SIZE
>
3364 x
= scr
->scr_width
- ICON_SIZE
;
3366 x
= ev
.xmotion
.x_root
- ofs_x
;
3368 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3370 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3372 y
= scr
->scr_height
- ICON_SIZE
;
3374 y
= ev
.xmotion
.y_root
- ofs_y
;
3376 moveDock(dock
, x
, y
);
3378 /* move vertically if pointer is inside the dock*/
3379 if ((dock
->on_right_side
&&
3380 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3381 || (!dock
->on_right_side
&&
3382 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3384 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3386 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3388 y
= scr
->scr_height
- ICON_SIZE
;
3390 y
= ev
.xmotion
.y_root
- ofs_y
;
3392 moveDock(dock
, dock
->x_pos
, y
);
3394 /* move horizontally to change sides */
3395 x
= ev
.xmotion
.x_root
- ofs_x
;
3396 if (!dock
->on_right_side
) {
3400 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3401 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3402 -DOCK_EXTRA_SPACE
-1, dock
->y_pos
);
3405 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3406 scr
->scr_width
-ICON_SIZE
3407 -DOCK_EXTRA_SPACE
-1,
3409 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3411 XClearWindow(dpy
, scr
->dock_shadow
);
3414 XMapRaised(dpy
, scr
->dock_shadow
);
3417 if (superfluous
&& ghost
!=None
) {
3418 XFreePixmap(dpy
, ghost
);
3421 XUnmapWindow(dpy
, scr
->dock_shadow
);
3426 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3427 XMoveWindow(dpy
, scr
->dock_shadow
,
3428 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3431 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3432 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3433 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3435 XClearWindow(dpy
, scr
->dock_shadow
);
3438 XMapRaised(dpy
, scr
->dock_shadow
);
3441 XUnmapWindow(dpy
, scr
->dock_shadow
);
3443 if (superfluous
&& ghost
!=None
) {
3444 XFreePixmap(dpy
, ghost
);
3456 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3458 XUngrabPointer(dpy
, CurrentTime
);
3459 XUnmapWindow(dpy
, scr
->dock_shadow
);
3460 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3461 if (dock
->type
== WM_DOCK
) {
3464 dock
->on_right_side
= 1;
3466 dock
->on_right_side
= 0;
3468 wArrangeIcons(scr
, False
);
3477 XFreePixmap(dpy
, ghost
);
3478 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3481 puts("End dock move");
3488 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3490 WScreen
*scr
= dock
->screen_ptr
;
3492 WIcon
*icon
= aicon
->icon
;
3493 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3494 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3496 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3497 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3498 int shad_x
= x
, shad_y
= y
;
3499 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3501 Pixmap ghost
= None
;
3503 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3505 if (wPreferences
.flags
.noupdates
)
3508 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3509 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3510 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3512 wwarning("pointer grab failed for icon move");
3516 wRaiseFrame(icon
->core
);
3518 if (!wPreferences
.flags
.noclip
)
3519 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3521 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3523 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3526 wins
[0] = icon
->core
->window
;
3527 wins
[1] = scr
->dock_shadow
;
3528 XRestackWindows(dpy
, wins
, 2);
3529 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3530 ICON_SIZE
, ICON_SIZE
);
3532 if (icon
->pixmap
!=None
)
3533 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3535 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3537 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3538 XClearWindow(dpy
, scr
->dock_shadow
);
3540 XMapWindow(dpy
, scr
->dock_shadow
);
3546 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3547 |ButtonMotionMask
|ExposureMask
, &ev
);
3555 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3556 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3557 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3558 |ButtonReleaseMask
|ButtonPressMask
,
3559 wCursor
[WCUR_MOVE
], CurrentTime
);
3566 x
= ev
.xmotion
.x_root
- ofs_x
;
3567 y
= ev
.xmotion
.y_root
- ofs_y
;
3568 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3571 if (last_dock
!= dock
&& collapsed
) {
3572 last_dock
->collapsed
= 1;
3573 wDockHideIcons(last_dock
);
3576 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3577 dock
->collapsed
= 0;
3578 wDockShowIcons(dock
);
3580 if (dock
->auto_raise_lower
)
3585 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3588 if (last_dock
!= dock2
&& collapsed
) {
3589 last_dock
->collapsed
= 1;
3590 wDockHideIcons(last_dock
);
3593 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3594 dock2
->collapsed
= 0;
3595 wDockShowIcons(dock2
);
3597 if (dock2
->auto_raise_lower
)
3602 if (aicon
->launching
3603 || (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3604 || (!aicon
->running
&& tmp
)) {
3605 shad_x
= last_dock
->x_pos
+ ix
*wPreferences
.icon_size
;
3606 shad_y
= last_dock
->y_pos
+ iy
*wPreferences
.icon_size
;
3608 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3611 XMapWindow(dpy
, scr
->dock_shadow
);
3613 if (!collapsed
&& (collapsed
= last_dock
->collapsed
)) {
3614 last_dock
->collapsed
= 0;
3615 wDockShowIcons(last_dock
);
3622 XUnmapWindow(dpy
, scr
->dock_shadow
);
3624 if (last_dock
&& collapsed
&&
3625 aicon
->running
&& (ev
.xmotion
.state
& MOD_MASK
)) {
3626 last_dock
->collapsed
= 1;
3627 wDockHideIcons(last_dock
);
3634 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3641 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3643 XUngrabPointer(dpy
, CurrentTime
);
3645 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3646 XUnmapWindow(dpy
, scr
->dock_shadow
);
3648 reattachIcon(dock
, aicon
, ix
, iy
);
3649 if (clip
&& dock
!=clip
&& clip
->auto_raise_lower
)
3652 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3654 /* Slide it back if dock rejected it */
3655 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3657 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3659 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3667 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3668 /* We need to deselect it, even if is deselected in
3669 * wDockDetach(), because else DoKaboom() will fail.
3671 if (aicon
->icon
->selected
)
3672 wIconSelect(aicon
->icon
);
3673 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3676 if (clip
&& clip
->auto_raise_lower
)
3678 wDockDetach(dock
, aicon
);
3681 last_dock
->collapsed
= 1;
3682 wDockHideIcons(last_dock
);
3687 XFreePixmap(dpy
, ghost
);
3688 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3691 puts("End icon move");
3700 getClipButton(int px
, int py
)
3702 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
3704 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3707 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
3708 return CLIP_FORWARD
;
3709 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
3717 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3720 int done
, direction
, new_ws
;
3722 WDock
*clip
= scr
->clip_icon
->dock
;
3724 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3726 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3727 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3729 wClipIconPaint(scr
->clip_icon
);
3732 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
3733 |ButtonPressMask
, &ev
);
3740 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3741 if (new_dir
!= direction
) {
3742 direction
= new_dir
;
3743 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3744 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3745 wClipIconPaint(scr
->clip_icon
);
3753 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3758 clip
->lclip_button_pushed
= 0;
3759 clip
->rclip_button_pushed
= 0;
3761 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3763 if (direction
== CLIP_FORWARD
) {
3764 if (scr
->current_workspace
< scr
->workspace_count
-1)
3765 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3766 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
3767 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3768 else if (wPreferences
.ws_cycle
)
3769 wWorkspaceChange(scr
, 0);
3771 else if (direction
== CLIP_REWIND
) {
3772 if (scr
->current_workspace
> 0)
3773 wWorkspaceChange(scr
, scr
->current_workspace
-1);
3774 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
3775 wWorkspaceChange(scr
, scr
->workspace_count
-1);
3778 wClipIconPaint(scr
->clip_icon
);
3783 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3785 WAppIcon
*aicon
= desc
->parent
;
3786 WDock
*dock
= aicon
->dock
;
3787 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3789 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3792 scr
->last_dock
= dock
;
3794 if (dock
->menu
->flags
.mapped
)
3795 wMenuUnmap(dock
->menu
);
3797 if (IsDoubleClick(scr
, event
)) {
3798 /* double-click was not in the main clip icon */
3799 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
3800 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
3801 iconDblClick(desc
, event
);
3806 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
3807 XUnmapWindow(dpy
, scr
->clip_balloon
);
3808 scr
->flags
.clip_balloon_mapped
= 0;
3812 puts("handling dock");
3814 if (event
->xbutton
.button
== Button1
) {
3815 if (event
->xbutton
.state
& MOD_MASK
)
3820 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
3821 dock
->type
!=WM_DOCK
) {
3822 wIconSelect(aicon
->icon
);
3826 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
3827 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
3828 && dock
->type
==WM_CLIP
)
3829 handleClipChangeWorkspace(scr
, event
);
3831 handleDockMove(dock
, aicon
, event
);
3833 handleIconMove(dock
, aicon
, event
);
3835 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
3836 aicon
->xindex
==0 && aicon
->yindex
==0) {
3837 openClipWorkspaceMenu(scr
, event
->xbutton
.x_root
+2,
3838 event
->xbutton
.y_root
+2);
3839 if (scr
->clip_ws_menu
) {
3841 menu
= scr
->clip_ws_menu
;
3842 desc
= &menu
->menu
->descriptor
;
3844 event
->xany
.send_event
= True
;
3845 (*desc
->handle_mousedown
)(desc
, event
);
3847 } else if (event
->xbutton
.button
== Button3
) {
3848 openDockMenu(dock
, aicon
, event
);
3854 showClipBalloon(WDock
*dock
, int workspace
)
3858 WScreen
*scr
= dock
->screen_ptr
;
3862 scr
->flags
.clip_balloon_mapped
= 1;
3863 XMapWindow(dpy
, scr
->clip_balloon
);
3865 text
= scr
->workspaces
[workspace
]->name
;
3867 w
= wTextWidth(scr
->clip_title_font
->font
, text
, strlen(text
));
3869 h
= scr
->clip_title_font
->height
;
3870 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
3872 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
3873 y
= dock
->y_pos
+ ICON_SIZE
-scr
->clip_title_font
->height
- 3;
3875 if (x
+w
> scr
->scr_width
) {
3876 x
= scr
->scr_width
- w
;
3877 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
3878 y
= dock
->y_pos
- h
- 1;
3880 y
= dock
->y_pos
+ ICON_SIZE
;
3881 XRaiseWindow(dpy
, scr
->clip_balloon
);
3883 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
3884 stack
[1] = scr
->clip_balloon
;
3885 XRestackWindows(dpy
, stack
, 2);
3887 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
3888 XSetForeground(dpy
, scr
->clip_title_gc
,
3889 scr
->clip_title_pixel
[CLIP_NORMAL
]);
3890 XClearWindow(dpy
, scr
->clip_balloon
);
3891 wDrawString(scr
->clip_balloon
, scr
->clip_title_font
, scr
->clip_title_gc
,
3892 0, scr
->clip_title_font
->y
, text
, strlen(text
));
3897 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3899 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
3902 assert(event
->type
==EnterNotify
);
3904 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
3908 if (!dock
|| dock
->type
!=WM_CLIP
)
3911 /* The auto raise/lower code */
3912 if (dock
->auto_lower_magic
) {
3913 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3914 dock
->auto_lower_magic
= NULL
;
3916 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
3917 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
,
3922 /* The auto expand/collapse code */
3923 if (dock
->auto_collapse_magic
) {
3924 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3925 dock
->auto_collapse_magic
= NULL
;
3927 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
3928 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
,
3933 if (btn
->xindex
== 0 && btn
->yindex
== 0)
3934 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
3936 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
3937 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
3938 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
3945 clipLeave(WDock
*dock
)
3948 WObjDescriptor
*desc
= NULL
;
3950 if (!dock
|| dock
->type
!=WM_CLIP
)
3953 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
)!=False
) {
3954 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3955 (XPointer
*)&desc
)!=XCNOENT
3956 && desc
&& desc
->parent_type
==WCLASS_DOCK_ICON
3957 && ((WAppIcon
*)desc
->parent
)->dock
3958 && ((WAppIcon
*)desc
->parent
)->dock
->type
==WM_CLIP
) {
3959 /* We didn't left the Clip yet */
3960 XPutBackEvent(dpy
, &event
);
3964 XPutBackEvent(dpy
, &event
);
3966 /* We entered a withdrawn window, so we're still in Clip */
3970 if (dock
->auto_raise_magic
) {
3971 WMDeleteTimerHandler(dock
->auto_raise_magic
);
3972 dock
->auto_raise_magic
= NULL
;
3974 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
3975 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
,
3980 if (dock
->auto_expand_magic
) {
3981 WMDeleteTimerHandler(dock
->auto_expand_magic
);
3982 dock
->auto_expand_magic
= NULL
;
3984 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
3985 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
3993 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
3995 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
3997 assert(event
->type
==LeaveNotify
);
3999 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4002 clipLeave(btn
->dock
);
4007 clipAutoCollapse(void *cdata
)
4009 WDock
*dock
= (WDock
*)cdata
;
4011 if (dock
->type
!=WM_CLIP
)
4014 if (dock
->auto_collapse
) {
4015 dock
->collapsed
= 1;
4016 wDockHideIcons(dock
);
4018 dock
->auto_collapse_magic
= NULL
;
4023 clipAutoExpand(void *cdata
)
4025 WDock
*dock
= (WDock
*)cdata
;
4027 if (dock
->type
!=WM_CLIP
)
4030 if (dock
->auto_collapse
) {
4031 dock
->collapsed
= 0;
4032 wDockShowIcons(dock
);
4034 dock
->auto_expand_magic
= NULL
;
4039 clipAutoLower(void *cdata
)
4041 WDock
*dock
= (WDock
*)cdata
;
4043 if (dock
->type
!=WM_CLIP
)
4046 if (dock
->auto_raise_lower
)
4049 dock
->auto_lower_magic
= NULL
;
4054 clipAutoRaise(void *cdata
)
4056 WDock
*dock
= (WDock
*)cdata
;
4058 if (dock
->type
!=WM_CLIP
)
4061 if (dock
->auto_raise_lower
)
4064 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4065 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4068 dock
->auto_raise_magic
= NULL
;