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
;
686 //if (dock->auto_collapse_magic) {
687 // WMDeleteTimerHandler(dock->auto_collapse_magic);
688 // dock->auto_collapse_magic = NULL;
691 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_collapse
;
698 toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
701 assert(entry
->clientdata
!=NULL
);
703 dock
= (WDock
*) entry
->clientdata
;
705 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
707 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_raise_lower
;
714 launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
716 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
718 launchDockedApplication(btn
);
723 settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
725 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
729 ShowDockAppSettingsPanel(btn
);
734 hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
737 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
739 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
741 if (wapp
->flags
.hidden
) {
742 wWorkspaceChange(btn
->icon
->core
->screen_ptr
,wapp
->last_workspace
);
743 wUnhideApplication(wapp
, False
, False
);
745 wHideApplication(wapp
);
751 unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
754 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
756 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
758 wUnhideApplication(wapp
, False
, True
);
763 mainIconCreate(WScreen
*scr
, int type
)
768 if (type
== WM_CLIP
) {
770 return scr
->clip_icon
;
771 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
772 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
773 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
774 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
775 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE;*/
778 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
779 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
785 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
786 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
787 btn
->icon
->core
->descriptor
.parent
= btn
;
788 /*ChangeStackingLevel(btn->icon->core, WMDockLevel);*/
789 XMapWindow(dpy
, btn
->icon
->core
->window
);
794 scr
->clip_icon
= btn
;
801 switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
803 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
804 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
806 LinkedList
*selectedIcons
;
809 if (entry
->order
== scr
->current_workspace
)
812 dest
= scr
->workspaces
[entry
->order
]->clip
;
814 selectedIcons
= getSelected(src
);
817 while(selectedIcons
) {
818 btn
= selectedIcons
->head
;
819 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
820 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
821 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
823 list_remove_head(&selectedIcons
);
825 } else if (icon
!= scr
->clip_icon
) {
826 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
827 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
828 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
836 launchDockedApplication(WAppIcon
*btn
)
838 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
840 if (!btn
->launching
&& btn
->command
!=NULL
) {
841 if (!btn
->forced_dock
) {
842 btn
->relaunching
= btn
->running
;
845 if (btn
->wm_instance
|| btn
->wm_class
) {
846 WWindowAttributes attr
;
847 memset(&attr
, 0, sizeof(WWindowAttributes
));
848 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
,
851 if (!attr
.no_appicon
&& !btn
->buggy_app
)
856 btn
->drop_launch
= 0;
857 scr
->last_dock
= btn
->dock
;
858 btn
->pid
= execCommand(btn
, btn
->command
, NULL
);
860 if (btn
->buggy_app
) {
861 /* give feedback that the app was launched */
865 WMAddTimerHandler(200, (WMCallback
*)dockIconPaint
, btn
);
870 wwarning(_("could not launch application %s\n"), btn
->command
);
872 if (!btn
->relaunching
)
881 updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
883 WScreen
*scr
= menu
->frame
->screen_ptr
;
884 char title
[MAX_WORKSPACENAME_WIDTH
+1];
890 for (i
=0; i
<scr
->workspace_count
; i
++) {
891 if (i
< menu
->entry_no
) {
892 if (strcmp(menu
->entries
[i
]->text
,scr
->workspaces
[i
]->name
)!=0) {
893 free(menu
->entries
[i
]->text
);
894 strcpy(title
, scr
->workspaces
[i
]->name
);
895 menu
->entries
[i
]->text
= wstrdup(title
);
896 menu
->flags
.realized
= 0;
898 menu
->entries
[i
]->clientdata
= (void*)icon
;
900 strcpy(title
, scr
->workspaces
[i
]->name
);
902 wMenuAddCallback(menu
, title
, switchWSCommand
, (void*)icon
);
904 menu
->flags
.realized
= 0;
906 if (i
== scr
->current_workspace
) {
907 wMenuSetEnabled(menu
, i
, False
);
909 wMenuSetEnabled(menu
, i
, True
);
913 if (!menu
->flags
.realized
)
919 makeWorkspaceMenu(WScreen
*scr
)
923 menu
= wMenuCreate(scr
, NULL
, False
);
925 wwarning(_("could not create workspace submenu for Clip menu"));
927 wMenuAddCallback(menu
, "", switchWSCommand
, (void*)scr
->clip_icon
);
929 menu
->flags
.realized
= 0;
937 updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
946 entry
= menu
->entries
[index
];
947 entry
->flags
.indicator_on
= !dock
->lowered
;
948 entry
->clientdata
= dock
;
951 entry
= menu
->entries
[++index
];
952 entry
->flags
.indicator_on
= dock
->collapsed
;
953 entry
->clientdata
= dock
;
956 entry
= menu
->entries
[++index
];
957 entry
->flags
.indicator_on
= dock
->auto_collapse
;
958 entry
->clientdata
= dock
;
960 /* auto-raise/lower */
961 entry
= menu
->entries
[++index
];
962 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
963 entry
->clientdata
= dock
;
966 entry
= menu
->entries
[++index
];
967 entry
->flags
.indicator_on
= dock
->attract_icons
;
968 entry
->clientdata
= dock
;
970 /* keep attracted icons */
971 entry
= menu
->entries
[++index
];
972 entry
->flags
.indicator_on
= dock
->keep_attracted
;
973 entry
->clientdata
= dock
;
975 menu
->flags
.realized
= 0;
981 makeClipOptionsMenu(WScreen
*scr
)
986 menu
= wMenuCreate(scr
, NULL
, False
);
988 wwarning(_("could not create options submenu for Clip menu"));
992 entry
= wMenuAddCallback(menu
, _("Keep on top"),
993 toggleLoweredCallback
, NULL
);
994 entry
->flags
.indicator
= 1;
995 entry
->flags
.indicator_on
= 1;
996 entry
->flags
.indicator_type
= MI_CHECK
;
998 entry
= wMenuAddCallback(menu
, _("Collapsed"),
999 toggleCollapsedCallback
, NULL
);
1000 entry
->flags
.indicator
= 1;
1001 entry
->flags
.indicator_on
= 1;
1002 entry
->flags
.indicator_type
= MI_CHECK
;
1004 entry
= wMenuAddCallback(menu
, _("AutoCollapse"),
1005 toggleAutoCollapseCallback
, NULL
);
1006 entry
->flags
.indicator
= 1;
1007 entry
->flags
.indicator_on
= 1;
1008 entry
->flags
.indicator_type
= MI_CHECK
;
1010 entry
= wMenuAddCallback(menu
, _("AutoRaiseLower"),
1011 toggleAutoRaiseLowerCallback
, NULL
);
1012 entry
->flags
.indicator
= 1;
1013 entry
->flags
.indicator_on
= 1;
1014 entry
->flags
.indicator_type
= MI_CHECK
;
1016 entry
= wMenuAddCallback(menu
, _("AutoAttract Icons"),
1017 toggleAutoAttractCallback
, NULL
);
1018 entry
->flags
.indicator
= 1;
1019 entry
->flags
.indicator_on
= 1;
1020 entry
->flags
.indicator_type
= MI_CHECK
;
1022 entry
= wMenuAddCallback(menu
, _("Keep Attracted Icons"),
1023 toggleKeepCallback
, NULL
);
1024 entry
->flags
.indicator
= 1;
1025 entry
->flags
.indicator_on
= 1;
1026 entry
->flags
.indicator_type
= MI_CHECK
;
1028 menu
->flags
.realized
= 0;
1036 dockMenuCreate(WScreen
*scr
, int type
)
1041 if (type
== WM_CLIP
&& scr
->clip_menu
)
1042 return scr
->clip_menu
;
1044 menu
= wMenuCreate(scr
, NULL
, False
);
1045 if (type
!= WM_CLIP
) {
1046 entry
= wMenuAddCallback(menu
, _("Keep on top"),
1047 toggleLoweredCallback
, NULL
);
1048 entry
->flags
.indicator
= 1;
1049 entry
->flags
.indicator_on
= 1;
1050 entry
->flags
.indicator_type
= MI_CHECK
;
1052 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1053 scr
->clip_options
= makeClipOptionsMenu(scr
);
1054 if (scr
->clip_options
)
1055 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1057 wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1059 wMenuAddCallback(menu
, _("(Un)Select Icon"), selectCallback
, NULL
);
1061 wMenuAddCallback(menu
, _("(Un)Select All Icons"), selectIconsCallback
,
1064 wMenuAddCallback(menu
, _("Keep Icon(s)"), keepIconsCallback
, NULL
);
1066 entry
= wMenuAddCallback(menu
, _("Move Icon(s) To"), NULL
, NULL
);
1067 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1068 if (scr
->clip_submenu
)
1069 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1071 wMenuAddCallback(menu
, _("Remove Icon(s)"), removeIconsCallback
, NULL
);
1073 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1076 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1078 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1080 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1082 entry
->text
= _("Hide");
1084 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1086 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1088 if (type
== WM_CLIP
)
1089 scr
->clip_menu
= menu
;
1096 wDockCreate(WScreen
*scr
, int type
)
1104 dock
= wmalloc(sizeof(WDock
));
1105 memset(dock
, 0, sizeof(WDock
));
1107 if (type
== WM_CLIP
)
1108 icon_count
= CLIP_MAX_ICONS
;
1110 icon_count
= scr
->scr_height
/wPreferences
.icon_size
;
1112 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*)*icon_count
);
1113 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*)*icon_count
);
1115 dock
->max_icons
= icon_count
;
1117 btn
= mainIconCreate(scr
, type
);
1121 dock
->x_pos
= btn
->x_pos
;
1122 dock
->y_pos
= btn
->y_pos
;
1123 dock
->screen_ptr
= scr
;
1125 dock
->icon_count
= 1;
1126 dock
->on_right_side
= 1;
1127 dock
->collapsed
= 0;
1128 dock
->auto_collapse
= 0;
1129 dock
->auto_collapse_magic
= NULL
;
1130 dock
->auto_raise_lower
= 0;
1131 dock
->auto_lower_magic
= NULL
;
1132 dock
->auto_raise_magic
= NULL
;
1133 dock
->attract_icons
= 0;
1134 dock
->keep_attracted
= 0;
1136 dock
->icon_array
[0] = btn
;
1137 wRaiseFrame(btn
->icon
->core
);
1138 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1140 /* create dock menu */
1141 dock
->menu
= dockMenuCreate(scr
, type
);
1148 wDockDestroy(WDock
*dock
)
1153 for (i
=(dock
->type
== WM_CLIP
) ? 1 : 0; i
<dock
->max_icons
; i
++) {
1154 aicon
= dock
->icon_array
[i
];
1156 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1157 wDockDetach(dock
, aicon
);
1159 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
1160 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
1161 aicon
->x_pos
, aicon
->y_pos
);
1162 if (!dock
->mapped
|| dock
->collapsed
)
1163 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1167 if (wPreferences
.auto_arrange_icons
)
1168 wArrangeIcons(dock
->screen_ptr
, True
);
1169 free(dock
->icon_array
);
1170 if (dock
->menu
&& dock
->type
!=WM_CLIP
)
1171 wMenuDestroy(dock
->menu
, True
);
1177 wClipIconPaint(WAppIcon
*aicon
)
1179 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1180 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1182 Window win
= aicon
->icon
->core
->window
;
1183 int length
, nlength
;
1184 char *ws_name
, ws_number
[10];
1187 wIconPaint(aicon
->icon
);
1189 length
= strlen(workspace
->name
);
1190 ws_name
= malloc(length
+ 1);
1191 sprintf(ws_name
, "%s", workspace
->name
);
1192 sprintf(ws_number
, "%i", scr
->current_workspace
+ 1);
1193 nlength
= strlen(ws_number
);
1195 gc
= scr
->clip_title_gc
;
1197 if (!workspace
->clip
->collapsed
)
1198 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_NORMAL
]);
1200 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_COLLAPSED
]);
1202 ty
= ICON_SIZE
- scr
->clip_title_font
->height
- 3;
1204 tx
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
1206 wDrawString(win
, scr
->clip_title_font
, gc
, tx
,
1207 ty
+ scr
->clip_title_font
->y
, ws_name
, length
);
1209 tx
= (ICON_SIZE
/2 - wTextWidth(scr
->clip_title_font
->font
, ws_number
, nlength
))/2;
1211 wDrawString(win
, scr
->clip_title_font
, gc
, tx
,
1212 scr
->clip_title_font
->y
+ 2, ws_number
, nlength
);
1216 if (aicon
->launching
) {
1217 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1218 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1220 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
,
1221 aicon
->dock
->rclip_button_pushed
);
1226 clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1228 wClipIconPaint(desc
->parent
);
1233 dockIconPaint(WAppIcon
*btn
)
1235 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1236 wClipIconPaint(btn
);
1243 make_icon_state(WAppIcon
*btn
)
1245 proplist_t node
= NULL
;
1246 proplist_t command
, autolaunch
, name
, forced
, host
, position
, buggy
;
1252 command
= PLMakeString("-");
1254 command
= PLMakeString(btn
->command
);
1256 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1258 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1260 name
= PLMakeString(tmp
);
1264 forced
= btn
->forced_dock
? dYes
: dNo
;
1266 buggy
= btn
->buggy_app
? dYes
: dNo
;
1268 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1269 sprintf(buffer
, "%i,%i", btn
->x_pos
, btn
->y_pos
);
1271 sprintf(buffer
, "%hi,%hi", btn
->xindex
, btn
->yindex
);
1272 position
= PLMakeString(buffer
);
1274 node
= PLMakeDictionaryFromEntries(dCommand
, command
,
1276 dAutoLaunch
, autolaunch
,
1278 dBuggyApplication
, buggy
,
1279 dPosition
, position
,
1283 PLRelease(position
);
1285 if (btn
->dnd_command
) {
1286 command
= PLMakeString(btn
->dnd_command
);
1287 PLInsertDictionaryEntry(node
, dDropCommand
, command
);
1290 #endif /* OFFIX_DND */
1292 if (btn
->client_machine
&& btn
->remote_start
) {
1293 host
= PLMakeString(btn
->client_machine
);
1294 PLInsertDictionaryEntry(node
, dHost
, host
);
1304 dockSaveState(WDock
*dock
)
1307 proplist_t icon_info
;
1308 proplist_t list
=NULL
, dock_state
=NULL
;
1312 list
= PLMakeArrayFromElements(NULL
);
1314 for (i
=(dock
->type
==WM_DOCK
? 0 : 1); i
<dock
->max_icons
; i
++) {
1315 WAppIcon
*btn
= dock
->icon_array
[i
];
1317 if (!btn
|| (btn
->attracted
&& !dock
->keep_attracted
))
1320 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1321 list
= PLAppendArrayElement(list
, icon_info
);
1322 PLRelease(icon_info
);
1326 dock_state
= PLMakeDictionaryFromEntries(dApplications
, list
, NULL
);
1330 if (dock
->type
== WM_DOCK
) {
1331 sprintf(buffer
, "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0),
1333 value
= PLMakeString(buffer
);
1334 PLInsertDictionaryEntry(dock_state
, dPosition
, value
);
1338 value
= (dock
->lowered
? dYes
: dNo
);
1339 PLInsertDictionaryEntry(dock_state
, dLowered
, value
);
1341 if (dock
->type
== WM_CLIP
) {
1342 value
= (dock
->collapsed
? dYes
: dNo
);
1343 PLInsertDictionaryEntry(dock_state
, dCollapsed
, value
);
1345 value
= (dock
->auto_collapse
? dYes
: dNo
);
1346 PLInsertDictionaryEntry(dock_state
, dAutoCollapse
, value
);
1348 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1349 PLInsertDictionaryEntry(dock_state
, dAutoRaiseLower
, value
);
1351 value
= (dock
->attract_icons
? dYes
: dNo
);
1352 PLInsertDictionaryEntry(dock_state
, dAutoAttractIcons
, value
);
1354 value
= (dock
->keep_attracted
? dYes
: dNo
);
1355 PLInsertDictionaryEntry(dock_state
, dKeepAttracted
, value
);
1363 wDockSaveState(WScreen
*scr
)
1365 proplist_t dock_state
;
1367 dock_state
= dockSaveState(scr
->dock
);
1369 PLInsertDictionaryEntry(scr
->session_state
, dDock
, dock_state
);
1371 PLRelease(dock_state
);
1376 wClipSaveState(WScreen
*scr
)
1378 proplist_t clip_state
;
1380 clip_state
= make_icon_state(scr
->clip_icon
);
1382 PLInsertDictionaryEntry(scr
->session_state
, dClip
, clip_state
);
1384 PLRelease(clip_state
);
1389 wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1391 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1396 restore_icon_state(WScreen
*scr
, proplist_t info
, int type
, int index
)
1399 char *wclass
, *winstance
;
1400 proplist_t cmd
, value
;
1404 cmd
= PLGetDictionaryEntry(info
, dCommand
);
1405 if (!cmd
|| !PLIsString(cmd
)) {
1409 /* parse window name */
1410 value
= PLGetDictionaryEntry(info
, dName
);
1414 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1416 if (!winstance
&& !wclass
) {
1423 command
= wstrdup(PLGetString(cmd
));
1427 if (!command
|| strcmp(command
, "-")==0) {
1438 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
,
1445 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1446 if (type
== WM_CLIP
) {
1447 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1448 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1450 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1451 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1455 cmd
= PLGetDictionaryEntry(info
, dDropCommand
);
1457 aicon
->dnd_command
= wstrdup(PLGetString(cmd
));
1460 /* check auto launch */
1461 value
= PLGetDictionaryEntry(info
, dAutoLaunch
);
1463 aicon
->auto_launch
= 0;
1465 if (PLIsString(value
)) {
1466 if (strcasecmp(PLGetString(value
), "YES")==0)
1467 aicon
->auto_launch
= 1;
1469 wwarning(_("bad value in docked icon state info %s"),
1470 PLGetString(dAutoLaunch
));
1474 /* check if it wasn't normally docked */
1475 value
= PLGetDictionaryEntry(info
, dForced
);
1477 aicon
->forced_dock
= 0;
1479 if (PLIsString(value
)) {
1480 if (strcasecmp(PLGetString(value
), "YES")==0)
1481 aicon
->forced_dock
= 1;
1483 wwarning(_("bad value in docked icon state info %s"),
1484 PLGetString(dForced
));
1488 /* check if we can rely on the stuff in the app */
1489 value
= PLGetDictionaryEntry(info
, dBuggyApplication
);
1491 aicon
->buggy_app
= 0;
1493 if (PLIsString(value
)) {
1494 if (strcasecmp(PLGetString(value
), "YES")==0)
1495 aicon
->buggy_app
= 1;
1497 wwarning(_("bad value in docked icon state info %s"),
1498 PLGetString(dBuggyApplication
));
1502 /* get position in the dock */
1503 value
= PLGetDictionaryEntry(info
, dPosition
);
1504 if (value
&& PLIsString(value
)) {
1505 if (sscanf(PLGetString(value
), "%hi,%hi", &aicon
->xindex
,
1507 wwarning(_("bad value in docked icon state info %s"),
1508 PLGetString(dPosition
));
1510 /* check position sanity */
1511 /* incomplete section! */
1512 if (type
== WM_DOCK
) {
1514 if (aicon
->yindex
< 0)
1515 wwarning(_("bad value in docked icon position %i,%i"),
1516 aicon
->xindex
, aicon
->yindex
);
1519 aicon
->yindex
= index
;
1530 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1534 wClipRestoreState(WScreen
*scr
, proplist_t clip_state
)
1540 icon
= mainIconCreate(scr
, WM_CLIP
);
1545 PLRetain(clip_state
);
1547 /* restore position */
1549 value
= PLGetDictionaryEntry(clip_state
, dPosition
);
1552 if (!PLIsString(value
))
1553 COMPLAIN("Position");
1555 if (sscanf(PLGetString(value
), "%i,%i", &icon
->x_pos
,
1557 COMPLAIN("Position");
1559 /* check position sanity */
1560 if (icon
->y_pos
< 0)
1562 else if (icon
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1563 icon
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1565 if (icon
->x_pos
< 0)
1567 else if (icon
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1568 icon
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1573 value
= PLGetDictionaryEntry(clip_state
, dDropCommand
);
1574 if (value
&& PLIsString(value
))
1575 icon
->dnd_command
= wstrdup(PLGetString(value
));
1578 PLRelease(clip_state
);
1585 wDockRestoreState(WScreen
*scr
, proplist_t dock_state
, int type
)
1590 WAppIcon
*aicon
, *old_top
;
1594 dock
= wDockCreate(scr
, type
);
1600 PLRetain(dock_state
);
1603 /* restore position */
1605 value
= PLGetDictionaryEntry(dock_state
, dPosition
);
1608 if (!PLIsString(value
))
1609 COMPLAIN("Position");
1611 if (sscanf(PLGetString(value
), "%i,%i", &dock
->x_pos
,
1613 COMPLAIN("Position");
1615 /* check position sanity */
1616 if (dock
->y_pos
< 0)
1618 else if (dock
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1619 dock
->y_pos
= scr
->scr_height
- ICON_SIZE
;
1621 /* This is no more needed. ??? */
1622 if (type
== WM_CLIP
) {
1623 if (dock
->x_pos
< 0)
1625 else if (dock
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1626 dock
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1628 if (dock
->x_pos
>= 0) {
1629 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1630 dock
->on_right_side
= 0;
1632 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1633 dock
->on_right_side
= 1;
1639 /* restore lowered/raised state */
1643 value
= PLGetDictionaryEntry(dock_state
, dLowered
);
1646 if (!PLIsString(value
))
1647 COMPLAIN("Lowered");
1649 if (strcasecmp(PLGetString(value
), "YES")==0)
1655 /* restore collapsed state */
1657 dock
->collapsed
= 0;
1659 value
= PLGetDictionaryEntry(dock_state
, dCollapsed
);
1662 if (!PLIsString(value
))
1663 COMPLAIN("Collapsed");
1665 if (strcasecmp(PLGetString(value
), "YES")==0)
1666 dock
->collapsed
= 1;
1671 /* restore auto-collapsed state */
1673 value
= PLGetDictionaryEntry(dock_state
, dAutoCollapse
);
1676 if (!PLIsString(value
))
1677 COMPLAIN("AutoCollapse");
1679 if (strcasecmp(PLGetString(value
), "YES")==0) {
1680 dock
->auto_collapse
= 1;
1681 dock
->collapsed
= 1;
1687 /* restore auto-raise/lower state */
1689 value
= PLGetDictionaryEntry(dock_state
, dAutoRaiseLower
);
1692 if (!PLIsString(value
))
1693 COMPLAIN("AutoRaiseLower");
1695 if (strcasecmp(PLGetString(value
), "YES")==0) {
1696 dock
->auto_raise_lower
= 1;
1702 /* restore attract icons state */
1704 dock
->attract_icons
= 0;
1706 value
= PLGetDictionaryEntry(dock_state
, dAutoAttractIcons
);
1709 if (!PLIsString(value
))
1710 COMPLAIN("AutoAttractIcons");
1712 if (strcasecmp(PLGetString(value
), "YES")==0)
1713 dock
->attract_icons
= 1;
1718 /* restore keep attracted icons state */
1720 dock
->keep_attracted
= 0;
1722 value
= PLGetDictionaryEntry(dock_state
, dKeepAttracted
);
1725 if (!PLIsString(value
))
1726 COMPLAIN("KeepAttracted");
1728 if (strcasecmp(PLGetString(value
), "YES")==0)
1729 dock
->keep_attracted
= 1;
1734 /* application list */
1736 apps
= PLGetDictionaryEntry(dock_state
, dApplications
);
1742 count
= PLGetNumberOfElements(apps
);
1747 old_top
= dock
->icon_array
[0];
1749 /* dock->icon_count is set to 1 when dock is created.
1750 * Since Clip is already restored, we want to keep it so for clip,
1751 * but for dock we may change the default top tile, so we set it to 0.
1753 if (type
== WM_DOCK
)
1754 dock
->icon_count
= 0;
1756 for (i
=0; i
<count
; i
++) {
1757 if (dock
->icon_count
>= dock
->max_icons
) {
1758 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1762 value
= PLGetArrayElement(apps
, i
);
1763 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1765 dock
->icon_array
[dock
->icon_count
] = aicon
;
1769 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
*ICON_SIZE
);
1770 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
*ICON_SIZE
);
1773 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1775 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1777 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
,
1780 if (!dock
->collapsed
)
1781 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1782 wRaiseFrame(aicon
->icon
->core
);
1785 } else if (dock
->icon_count
==0 && type
==WM_DOCK
)
1789 /* if the first icon is not defined, use the default */
1790 if (dock
->icon_array
[0]==NULL
) {
1791 /* update default icon */
1792 old_top
->x_pos
= dock
->x_pos
;
1793 old_top
->y_pos
= dock
->y_pos
;
1795 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1797 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1798 dock
->icon_array
[0] = old_top
;
1799 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1800 /* we don't need to increment dock->icon_count here because it was
1801 * incremented in the loop above.
1803 } else if (old_top
!=dock
->icon_array
[0]) {
1804 if (old_top
== scr
->clip_icon
)
1805 scr
->clip_icon
= dock
->icon_array
[0];
1806 wAppIconDestroy(old_top
);
1811 PLRelease(dock_state
);
1819 wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1821 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1823 btn
->drop_launch
= 0;
1825 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1828 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1840 wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1846 for (i
= 0; i
< dock
->max_icons
; i
++) {
1847 btn
= dock
->icon_array
[i
];
1848 if (!btn
|| !btn
->auto_launch
)
1851 state
= wmalloc(sizeof(WSavedState
));
1852 memset(state
, 0, sizeof(WSavedState
));
1853 state
->workspace
= workspace
;
1854 /* TODO: this is klugy and is very difficult to understand
1855 * what's going on. Try to clean up */
1856 wDockLaunchWithState(dock
, btn
, state
);
1860 #ifdef REDUCE_APPICONS
1862 wDockSimulateLaunch(WDock
*dock
, WAppIcon
*btn
)
1864 if ((btn
== NULL
) || (dock
== NULL
))
1867 if (!btn
->running
) {
1868 if ((btn
->icon
->owner
== NULL
) && (btn
->applist
))
1869 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
1870 if (!btn
->forced_dock
)
1880 findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1886 if ((dock
= scr
->dock
)!=NULL
) {
1887 for (i
=0; i
<dock
->max_icons
; i
++) {
1888 if (dock
->icon_array
[i
]
1889 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1895 if (*icon_pos
<0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
)!=NULL
) {
1896 for (i
=0; i
<dock
->max_icons
; i
++) {
1897 if (dock
->icon_array
[i
]
1898 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
1911 wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
1917 dock
= findDock(scr
, event
, &icon_pos
);
1922 * Return True if the drop was on an application icon window.
1923 * In this case, let the ClientMessage handler redirect the
1924 * message to the app.
1926 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!=None
)
1929 if (dock
->icon_array
[icon_pos
]->dnd_command
!=NULL
) {
1930 scr
->flags
.dnd_data_convertion_status
= 0;
1932 btn
= dock
->icon_array
[icon_pos
];
1934 if (!btn
->forced_dock
) {
1935 btn
->relaunching
= btn
->running
;
1938 if (btn
->wm_instance
|| btn
->wm_class
) {
1939 WWindowAttributes attr
;
1940 memset(&attr
, 0, sizeof(WWindowAttributes
));
1941 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
1943 btn
->wm_class
, &attr
, NULL
, True
);
1945 if (!attr
.no_appicon
)
1951 btn
->drop_launch
= 1;
1952 scr
->last_dock
= dock
;
1953 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1958 if (!btn
->relaunching
) {
1965 #endif /* OFFIX_DND */
1970 wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1977 wwin
= icon
->icon
->owner
;
1978 if (icon
->command
==NULL
) {
1980 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
1982 icon
->command
= FlattenStringList(argv
, argc
);
1983 XFreeStringList(argv
);
1987 /* icon->forced_dock = 1;*/
1988 if (!icon
->attracted
|| dock
->type
!=WM_CLIP
|| dock
->keep_attracted
) {
1990 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
1991 _("Type the command used to launch the application"),
1993 if (command
&& (command
[0]==0 ||
1994 (command
[0]=='-' && command
[1]==0))) {
1998 icon
->command
= command
;
2004 /* If the target is the dock, reject the icon. If
2005 * the target is the clip, make it an attracted icon
2007 if (dock
->type
==WM_CLIP
) {
2008 icon
->attracted
= 1;
2009 if (!icon
->icon
->shadowed
) {
2010 icon
->icon
->shadowed
= 1;
2011 icon
->icon
->force_paint
= 1;
2023 for (index
=1; index
<dock
->max_icons
; index
++)
2024 if (dock
->icon_array
[index
] == NULL
)
2026 /* if (index == dock->max_icons)
2029 assert(index
< dock
->max_icons
);
2031 dock
->icon_array
[index
] = icon
;
2035 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2036 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2041 icon
->launching
= 0;
2044 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2045 if (dock
->type
== WM_CLIP
) {
2046 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2047 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2049 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2050 icon
->icon
->core
->descriptor
.parent
= icon
;
2052 MoveInStackListUnder(dock
->icon_array
[index
-1]->icon
->core
,
2054 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2055 wAppIconPaint(icon
);
2057 if (wPreferences
.auto_arrange_icons
)
2058 wArrangeIcons(dock
->screen_ptr
, True
);
2061 if (icon
->command
&& !icon
->dnd_command
) {
2062 icon
->dnd_command
= wmalloc(strlen(icon
->command
)+8);
2063 sprintf(icon
->dnd_command
, "%s %%d", icon
->command
);
2072 reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2076 for(index
=1; index
<dock
->max_icons
; index
++) {
2077 if(dock
->icon_array
[index
] == icon
)
2080 assert(index
< dock
->max_icons
);
2085 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2086 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2091 moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2101 wwin
= icon
->icon
->owner
;
2104 * For the moment we can't do this if we move icons in Clip from one
2105 * workspace to other, because if we move two or more icons without
2106 * command, the dialog box will not be able to tell us to which of the
2107 * moved icons it applies. -Dan
2109 if ((dest
->type
==WM_DOCK
/*|| dest->keep_attracted*/) && icon
->command
==NULL
) {
2110 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2112 icon
->command
= FlattenStringList(argv
, argc
);
2113 XFreeStringList(argv
);
2118 /* icon->forced_dock = 1;*/
2119 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2120 _("Type the command used to launch the application"),
2122 if (command
&& (command
[0]==0 ||
2123 (command
[0]=='-' && command
[1]==0))) {
2127 icon
->command
= command
;
2138 for(index
=1; index
<src
->max_icons
; index
++) {
2139 if(src
->icon_array
[index
] == icon
)
2142 assert(index
< src
->max_icons
);
2144 src
->icon_array
[index
] = NULL
;
2147 for(index
=1; index
<dest
->max_icons
; index
++) {
2148 if(dest
->icon_array
[index
] == NULL
)
2151 /* if (index == dest->max_icons)
2154 assert(index
< dest
->max_icons
);
2156 dest
->icon_array
[index
] = icon
;
2159 /* deselect the icon */
2160 if (icon
->icon
->selected
)
2161 wIconSelect(icon
->icon
);
2163 if (dest
->type
== WM_DOCK
) {
2164 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2165 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2167 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2168 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2171 /* set it to be kept when moving to dock, or to a clip that keep the
2173 * Unless the icon does not have a command set
2175 if (icon
->command
&& (dest
->type
==WM_DOCK
|| dest
->keep_attracted
)) {
2176 icon
->attracted
= 0;
2177 if (icon
->icon
->shadowed
) {
2178 icon
->icon
->shadowed
= 0;
2179 icon
->icon
->force_paint
= 1;
2183 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2189 icon
->x_pos
= dest
->x_pos
+ x
*ICON_SIZE
;
2190 icon
->y_pos
= dest
->y_pos
+ y
*ICON_SIZE
;
2194 MoveInStackListUnder(dest
->icon_array
[index
-1]->icon
->core
,
2196 wAppIconPaint(icon
);
2203 wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2207 /* make the settings panel be closed */
2209 DestroyDockAppSettingsPanel(icon
->panel
);
2214 icon
->attracted
= 0;
2215 if (icon
->icon
->shadowed
) {
2216 icon
->icon
->shadowed
= 0;
2217 icon
->icon
->force_paint
= 1;
2220 /* deselect the icon */
2221 if (icon
->icon
->selected
)
2222 wIconSelect(icon
->icon
);
2224 if (icon
->command
) {
2225 free(icon
->command
);
2226 icon
->command
= NULL
;
2229 if (icon
->dnd_command
) {
2230 free(icon
->dnd_command
);
2231 icon
->dnd_command
= NULL
;
2235 for (index
=1; index
<dock
->max_icons
; index
++)
2236 if (dock
->icon_array
[index
] == icon
)
2238 assert(index
< dock
->max_icons
);
2239 dock
->icon_array
[index
] = NULL
;
2244 /* if the dock is not attached to an application or
2245 * the the application did not set the approriate hints yet,
2246 * destroy the icon */
2247 #ifdef REDUCE_APPICONS
2248 if ((icon
->num_apps
== 0) && (!icon
->running
|| !wApplicationOf(icon
->main_window
)) )
2250 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2252 wAppIconDestroy(icon
);
2254 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2255 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2256 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2257 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2258 icon
->icon
->core
->descriptor
.parent
= icon
;
2260 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2262 wAppIconPaint(icon
);
2263 if (wPreferences
.auto_arrange_icons
) {
2264 wArrangeIcons(dock
->screen_ptr
, True
);
2267 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2273 * returns the closest Dock slot index for the passed
2276 * Returns False if icon can't be docked.
2279 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2280 int *ret_x
, int *ret_y
, int redocking
)
2282 WScreen
*scr
= dock
->screen_ptr
;
2285 int i
, offset
= ICON_SIZE
/2;
2286 WAppIcon
*aicon
= NULL
;
2287 WAppIcon
*nicon
= NULL
;
2288 int max_y_icons
, max_x_icons
;
2290 max_x_icons
= scr
->scr_width
/ICON_SIZE
;
2291 max_y_icons
= scr
->scr_height
/ICON_SIZE
-1;
2293 if (wPreferences
.flags
.noupdates
)
2299 /* if the dock is full */
2301 (dock
->icon_count
>= dock
->max_icons
)) {
2305 /* exact position */
2307 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2309 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2312 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2314 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2316 /* check if the icon is outside the screen boundaries */
2317 if (dx
+ ex_x
*ICON_SIZE
< -ICON_SIZE
+2 ||
2318 dx
+ ex_x
*ICON_SIZE
>= scr
->scr_width
-1 ||
2319 dy
+ ex_y
*ICON_SIZE
< -ICON_SIZE
+2 ||
2320 dy
+ ex_y
*ICON_SIZE
>= scr
->scr_height
-1)
2323 if (dock
->type
== WM_DOCK
) {
2324 if (icon
->dock
!= dock
&& ex_x
!= 0)
2327 for (i
=0; i
<dock
->max_icons
; i
++) {
2328 nicon
= dock
->icon_array
[i
];
2329 if (nicon
&& nicon
->yindex
== ex_y
) {
2338 int sig
, done
, closest
;
2340 /* Possible cases when redocking:
2342 * icon dragged out of range of any slot -> false
2343 * icon dragged to range of free slot
2344 * icon dragged to range of same slot
2345 * icon dragged to range of different icon
2347 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2350 if (ex_y
>= 0 && ex_y
<= max_y_icons
&& (aicon
== icon
|| !aicon
)) {
2358 /* start looking at the upper slot or lower? */
2359 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2366 /* look for closest free slot */
2367 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2371 closest
= sig
*(i
/2) + ex_y
;
2372 /* check if this slot is used */
2374 for (j
= 0; j
<dock
->max_icons
; j
++) {
2375 if (dock
->icon_array
[j
]
2376 && dock
->icon_array
[j
]->yindex
==closest
) {
2377 /* slot is used by someone else */
2378 if (dock
->icon_array
[j
]!=icon
)
2386 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2387 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2389 (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+1))) {
2395 } else { /* !redocking */
2397 /* if slot is free and the icon is close enough, return it */
2398 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2406 for (i
=0; i
<dock
->max_icons
; i
++) {
2407 nicon
= dock
->icon_array
[i
];
2408 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2414 for (i
=0; i
<dock
->max_icons
; i
++) {
2415 nicon
= dock
->icon_array
[i
];
2416 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2417 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2418 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2424 if (neighbours
&& (aicon
==NULL
|| (redocking
&& aicon
== icon
))) {
2433 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2434 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2436 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2437 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2438 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2442 * returns true if it can find a free slot in the dock,
2443 * in which case it changes x_pos and y_pos accordingly.
2444 * Else returns false.
2447 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2449 WScreen
*scr
= dock
->screen_ptr
;
2451 unsigned char *slot_map
;
2455 int i
, done
= False
;
2457 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2460 /* if the dock is full */
2461 if (dock
->icon_count
>= dock
->max_icons
) {
2465 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2466 if (scr
->dock
->on_right_side
)
2467 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2469 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2472 if (ex
< dock
->x_pos
)
2474 if (sx
> dock
->x_pos
+ICON_SIZE
)
2475 sx
= dock
->x_pos
+ICON_SIZE
;
2482 /* check if clip is in a corner */
2483 if (dock
->type
==WM_CLIP
) {
2484 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2486 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2488 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2490 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2497 /* If the clip is in the corner, use only slots that are in the border
2499 if (corner
!=C_NONE
) {
2503 hcount
= MIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2504 vcount
= MIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2505 hmap
= wmalloc(hcount
+1);
2506 memset(hmap
, 0, hcount
+1);
2507 vmap
= wmalloc(vcount
+1);
2508 memset(vmap
, 0, vcount
+1);
2510 /* mark used positions */
2513 for (i
=0; i
<dock
->max_icons
; i
++) {
2514 btn
= dock
->icon_array
[i
];
2518 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2519 vmap
[btn
->yindex
] = 1;
2520 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2521 hmap
[btn
->xindex
] = 1;
2524 for (i
=0; i
<dock
->max_icons
; i
++) {
2525 btn
= dock
->icon_array
[i
];
2529 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2530 vmap
[btn
->yindex
] = 1;
2531 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2532 hmap
[-btn
->xindex
] = 1;
2535 for (i
=0; i
<dock
->max_icons
; i
++) {
2536 btn
= dock
->icon_array
[i
];
2540 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2541 vmap
[-btn
->yindex
] = 1;
2542 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2543 hmap
[btn
->xindex
] = 1;
2547 for (i
=0; i
<dock
->max_icons
; i
++) {
2548 btn
= dock
->icon_array
[i
];
2552 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2553 vmap
[-btn
->yindex
] = 1;
2554 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2555 hmap
[-btn
->xindex
] = 1;
2560 /* search a vacant slot */
2561 for (i
=1; i
<MAX(vcount
, hcount
); i
++) {
2562 if (i
< vcount
&& vmap
[i
]==0) {
2568 } else if (i
< hcount
&& hmap
[i
]==0) {
2578 /* If found a slot, translate and return */
2580 if (corner
==C_NW
|| corner
==C_NE
) {
2585 if (corner
==C_NE
|| corner
==C_SE
) {
2592 /* else, try to find a slot somewhere else */
2595 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2596 * placed outside of screen */
2597 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2599 /* In the worst case (the clip is in the corner of the screen),
2600 * the amount of icons that fit in the clip is smaller.
2601 * Double the map to get a safe value.
2607 slot_map
= wmalloc(mwidth
*mwidth
);
2608 memset(slot_map
, 0, mwidth
*mwidth
);
2610 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2612 /* mark used slots in the map. If the slot falls outside the map
2613 * (for example, when all icons are placed in line), ignore them. */
2614 for (i
=0; i
<dock
->max_icons
; i
++) {
2615 btn
= dock
->icon_array
[i
];
2617 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2619 /* Find closest slot from the center that is free by scanning the
2620 * map from the center to outward in circular passes.
2621 * This will not result in a neat layout, but will be optimal
2622 * in the sense that there will not be holes left.
2625 for (i
= 1; i
<= r
&& !done
; i
++) {
2628 /* top and bottom parts of the ring */
2629 for (x
= -i
; x
<= i
&& !done
; x
++) {
2630 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2632 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2633 if (slot_map
[XY2OFS(x
,y
)]==0
2634 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2641 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2642 if (slot_map
[XY2OFS(x
,y
)]==0
2643 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2650 /* left and right parts of the ring */
2651 for (y
= -i
+1; y
<= i
-1; y
++) {
2652 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2654 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2655 if (slot_map
[XY2OFS(x
,y
)]==0
2656 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2663 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2664 if (slot_map
[XY2OFS(x
,y
)]==0
2665 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2680 moveDock(WDock
*dock
, int new_x
, int new_y
)
2685 dock
->x_pos
= new_x
;
2686 dock
->y_pos
= new_y
;
2687 for (i
=0; i
<dock
->max_icons
; i
++) {
2688 btn
= dock
->icon_array
[i
];
2690 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2691 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2692 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2699 swapDock(WDock
*dock
)
2701 WScreen
*scr
= dock
->screen_ptr
;
2706 if (dock
->on_right_side
) {
2707 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2709 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2712 for (i
=0; i
<dock
->max_icons
; i
++) {
2713 btn
= dock
->icon_array
[i
];
2716 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2720 wScreenUpdateUsableArea(scr
);
2725 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2727 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2733 cmdline
= ExpandOptions(scr
, command
);
2735 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2743 ParseCommand(cmdline
, &argv
, &argc
);
2753 if ((pid
=fork())==0) {
2757 SetupEnvironment(scr
);
2763 args
= malloc(sizeof(char*)*(argc
+1));
2766 for (i
=0; i
<argc
; i
++) {
2770 execvp(argv
[0], args
);
2779 state
= wmalloc(sizeof(WSavedState
));
2780 memset(state
, 0, sizeof(WSavedState
));
2782 state
->miniaturized
= -1;
2784 if (btn
->dock
== scr
->dock
)
2785 state
->workspace
= -1;
2787 state
->workspace
= scr
->current_workspace
;
2789 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
2791 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
2802 wDockHideIcons(WDock
*dock
)
2810 btn
= dock
->icon_array
[0];
2812 for (i
=1; i
<dock
->max_icons
; i
++) {
2813 if (dock
->icon_array
[i
])
2814 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2823 wDockShowIcons(WDock
*dock
)
2831 btn
= dock
->icon_array
[0];
2832 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2834 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2835 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2837 for (i
=1; i
<dock
->max_icons
; i
++) {
2838 if (dock
->icon_array
[i
]) {
2839 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
2845 if (!dock
->collapsed
) {
2846 for (i
=1; i
<dock
->max_icons
; i
++) {
2847 if (dock
->icon_array
[i
]) {
2848 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2859 wDockLower(WDock
*dock
)
2863 for (i
=0; i
<dock
->max_icons
; i
++) {
2864 if (dock
->icon_array
[i
])
2865 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2871 wDockRaise(WDock
*dock
)
2875 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
2876 if (dock
->icon_array
[i
])
2877 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2883 wDockRaiseLower(WDock
*dock
)
2885 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2886 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2887 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2895 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
2897 icon
->launching
= 0;
2898 icon
->relaunching
= 0;
2899 dockIconPaint(icon
);
2904 wDockFindIconFor(WDock
*dock
, Window window
)
2909 for (i
=0; i
<dock
->max_icons
; i
++) {
2910 icon
= dock
->icon_array
[i
];
2911 if (icon
&& icon
->main_window
== window
)
2919 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
2922 #ifdef REDUCE_APPICONS
2923 WAppIconAppList
*tapplist
;
2925 char *wm_class
, *wm_instance
;
2927 Bool firstPass
= True
;
2929 char *command
= NULL
;
2935 if (XGetCommand(dpy
, window
, &argv
, &argc
)) {
2936 if (argc
> 0 && argv
!= NULL
)
2937 command
= FlattenStringList(argv
,argc
);
2939 XFreeStringList(argv
);
2944 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
2945 (!wm_class
&& !wm_instance
))
2949 for (i
=0; i
<dock
->max_icons
; i
++) {
2950 icon
= dock
->icon_array
[i
];
2954 /* app is already attached to icon */
2955 if (icon
->main_window
== window
) {
2960 if ((icon
->wm_instance
|| icon
->wm_class
)
2962 || (dock
->screen_ptr
->flags
.startup
&& !icon
->running
))) {
2964 if (icon
->wm_instance
&& wm_instance
&&
2965 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
2968 if (icon
->wm_class
&& wm_class
&&
2969 strcmp(icon
->wm_class
, wm_class
)!=0) {
2972 if (firstPass
&& command
&& strcmp(icon
->command
, command
)!=0) {
2976 if (!icon
->relaunching
) {
2979 /* Possibly an application that was docked with dockit,
2980 * but the user did not update WMState to indicate that
2981 * it was docked by force */
2982 wapp
= wApplicationOf(window
);
2984 icon
->forced_dock
= 1;
2987 if (!icon
->forced_dock
)
2988 icon
->main_window
= window
;
2990 #ifdef REDUCE_APPICONS
2991 tapplist
= wmalloc(sizeof(WAppIconAppList
));
2992 memset(tapplist
, 0, sizeof(WAppIconAppList
));
2993 tapplist
->next
= icon
->applist
;
2995 icon
->applist
->prev
= tapplist
;
2996 icon
->applist
= tapplist
;
2997 tapplist
->wapp
= wApplicationOf(window
);
3002 wDockFinishLaunch(dock
, icon
);
3007 if (firstPass
&& !found
) {
3024 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3026 if (!wPreferences
.flags
.noclip
) {
3027 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3028 if (scr
->current_workspace
!= workspace
) {
3029 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3031 wDockHideIcons(old_clip
);
3032 if (old_clip
->auto_raise_lower
) {
3033 if (old_clip
->auto_raise_magic
) {
3034 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3035 old_clip
->auto_raise_magic
= NULL
;
3037 wDockLower(old_clip
);
3039 if (old_clip
->auto_collapse
) {
3040 if (old_clip
->auto_expand_magic
) {
3041 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3042 old_clip
->auto_expand_magic
= NULL
;
3044 old_clip
->collapsed
= 1;
3046 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3048 if (scr
->flags
.clip_balloon_mapped
)
3049 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3056 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3061 for (i
=0; i
<dock
->max_icons
; i
++) {
3062 icon
= dock
->icon_array
[i
];
3066 if (icon
->launching
&& icon
->pid
== pid
) {
3067 if (!icon
->relaunching
) {
3069 icon
->main_window
= None
;
3071 wDockFinishLaunch(dock
, icon
);
3076 sprintf(msg
, _("Could not execute command \"%s\""),
3077 icon
->drop_launch
&& icon
->dnd_command
3078 ? icon
->dnd_command
: icon
->command
);
3080 sprintf(msg
, _("Could not execute command \"%s\""),
3083 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
3084 _("OK"), NULL
, NULL
);
3093 toggleLowered(WDock
*dock
)
3098 /* lower/raise Dock */
3099 if (!dock
->lowered
) {
3100 newlevel
= WMNormalLevel
;
3103 newlevel
= WMDockLevel
;
3107 for (i
=0; i
<dock
->max_icons
; i
++) {
3108 tmp
= dock
->icon_array
[i
];
3112 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3114 wLowerFrame(tmp
->icon
->core
);
3117 if (dock
->type
== WM_DOCK
)
3118 wScreenUpdateUsableArea(dock
->screen_ptr
);
3123 toggleCollapsed(WDock
*dock
)
3125 if (dock
->collapsed
) {
3126 dock
->collapsed
= 0;
3127 wDockShowIcons(dock
);
3130 dock
->collapsed
= 1;
3131 wDockHideIcons(dock
);
3137 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3139 WScreen
*scr
= dock
->screen_ptr
;
3140 WObjDescriptor
*desc
;
3142 WApplication
*wapp
= NULL
;
3145 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3147 if (dock
->type
== WM_DOCK
) {
3149 entry
= dock
->menu
->entries
[index
];
3150 entry
->flags
.indicator_on
= !dock
->lowered
;
3151 entry
->clientdata
= dock
;
3154 if (scr
->clip_options
)
3155 updateClipOptionsMenu(scr
->clip_options
, dock
);
3157 /* Rename Workspace */
3158 entry
= dock
->menu
->entries
[++index
];
3159 entry
->clientdata
= dock
;
3162 entry
= dock
->menu
->entries
[++index
];
3163 entry
->clientdata
= aicon
;
3164 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3166 /* (un)select all icons */
3167 entry
= dock
->menu
->entries
[++index
];
3168 entry
->clientdata
= aicon
;
3169 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3172 entry
= dock
->menu
->entries
[++index
];
3173 entry
->clientdata
= aicon
;
3174 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3176 /* this is the workspace submenu part */
3177 if (scr
->clip_submenu
)
3178 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3181 /* remove icon(s) */
3182 entry
= dock
->menu
->entries
[++index
];
3183 entry
->clientdata
= aicon
;
3184 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3186 /* attract icon(s) */
3187 entry
= dock
->menu
->entries
[++index
];
3188 entry
->clientdata
= aicon
;
3192 entry
= dock
->menu
->entries
[++index
];
3193 entry
->clientdata
= aicon
;
3194 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3197 entry
= dock
->menu
->entries
[++index
];
3198 entry
->clientdata
= aicon
;
3199 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3202 entry
= dock
->menu
->entries
[++index
];
3203 entry
->clientdata
= aicon
;
3204 if (aicon
->icon
->owner
) {
3205 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3206 if (wapp
&& wapp
->flags
.hidden
)
3207 entry
->text
= _("Unhide");
3209 entry
->text
= _("Hide");
3211 entry
->text
= _("Hide");
3213 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3216 entry
= dock
->menu
->entries
[++index
];
3217 entry
->clientdata
= aicon
;
3218 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
3219 && !wPreferences
.flags
.noupdates
);
3222 entry
= dock
->menu
->entries
[++index
];
3223 entry
->clientdata
= aicon
;
3224 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3226 if (!dock
->menu
->flags
.realized
)
3227 wMenuRealize(dock
->menu
);
3229 if (dock
->type
== WM_CLIP
) {
3230 x_pos
= event
->xbutton
.x_root
+2;
3232 x_pos
= dock
->on_right_side
?
3233 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 2 : 0;
3236 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3238 /* allow drag select */
3239 event
->xany
.send_event
= True
;
3240 desc
= &dock
->menu
->menu
->descriptor
;
3241 (*desc
->handle_mousedown
)(desc
, event
);
3246 openClipWorkspaceMenu(WScreen
*scr
, int x
, int y
)
3248 if (!scr
->clip_ws_menu
) {
3249 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3251 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
3252 wMenuMapAt(scr
->clip_ws_menu
, x
, y
, False
);
3256 /******************************************************************/
3258 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3260 WAppIcon
*btn
= desc
->parent
;
3261 WDock
*dock
= btn
->dock
;
3262 WApplication
*wapp
= NULL
;
3265 #ifdef REDUCE_APPICONS
3266 if ((btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) ||
3267 ((btn
->icon
->owner
== NULL
) && (btn
->applist
!= NULL
))) {
3268 if (btn
->icon
->owner
== NULL
)
3269 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
3274 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3276 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3280 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3282 /* go to the last workspace that the user worked on the app */
3284 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3287 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3290 if (event
->xbutton
.state
& MOD_MASK
) {
3291 wHideOtherApplications(btn
->icon
->owner
);
3294 if (event
->xbutton
.button
==Button1
) {
3296 if (event
->xbutton
.state
& MOD_MASK
) {
3297 /* raise/lower dock */
3298 toggleLowered(dock
);
3299 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3300 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3301 toggleCollapsed(dock
);
3303 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3304 } else if (btn
->command
) {
3305 if (!btn
->launching
&&
3306 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3307 launchDockedApplication(btn
);
3316 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3318 WScreen
*scr
= dock
->screen_ptr
;
3319 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3322 int grabbed
= 0, swapped
= 0, done
;
3323 Pixmap ghost
= None
;
3324 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3327 puts("moving dock");
3329 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3330 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3331 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3332 wwarning("pointer grab failed for dock move");
3335 for (x
=0; x
<dock
->max_icons
; x
++) {
3336 if (dock
->icon_array
[x
]!=NULL
&&
3337 dock
->icon_array
[x
]->yindex
> y
)
3338 y
= dock
->icon_array
[x
]->yindex
;
3341 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3345 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3346 |ButtonMotionMask
|ExposureMask
, &ev
);
3354 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3355 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3356 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3357 |ButtonReleaseMask
|ButtonPressMask
,
3358 wCursor
[WCUR_MOVE
], CurrentTime
);
3363 if (dock
->type
== WM_CLIP
) {
3364 if (ev
.xmotion
.x_root
- ofs_x
< 0) {
3366 } else if (ev
.xmotion
.x_root
- ofs_x
+ ICON_SIZE
>
3368 x
= scr
->scr_width
- ICON_SIZE
;
3370 x
= ev
.xmotion
.x_root
- ofs_x
;
3372 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3374 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3376 y
= scr
->scr_height
- ICON_SIZE
;
3378 y
= ev
.xmotion
.y_root
- ofs_y
;
3380 moveDock(dock
, x
, y
);
3382 /* move vertically if pointer is inside the dock*/
3383 if ((dock
->on_right_side
&&
3384 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3385 || (!dock
->on_right_side
&&
3386 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3388 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3390 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3392 y
= scr
->scr_height
- ICON_SIZE
;
3394 y
= ev
.xmotion
.y_root
- ofs_y
;
3396 moveDock(dock
, dock
->x_pos
, y
);
3398 /* move horizontally to change sides */
3399 x
= ev
.xmotion
.x_root
- ofs_x
;
3400 if (!dock
->on_right_side
) {
3404 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3405 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3406 -DOCK_EXTRA_SPACE
-1, dock
->y_pos
);
3409 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3410 scr
->scr_width
-ICON_SIZE
3411 -DOCK_EXTRA_SPACE
-1,
3413 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3415 XClearWindow(dpy
, scr
->dock_shadow
);
3418 XMapRaised(dpy
, scr
->dock_shadow
);
3421 if (superfluous
&& ghost
!=None
) {
3422 XFreePixmap(dpy
, ghost
);
3425 XUnmapWindow(dpy
, scr
->dock_shadow
);
3430 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3431 XMoveWindow(dpy
, scr
->dock_shadow
,
3432 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3435 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3436 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3437 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3439 XClearWindow(dpy
, scr
->dock_shadow
);
3442 XMapRaised(dpy
, scr
->dock_shadow
);
3445 XUnmapWindow(dpy
, scr
->dock_shadow
);
3447 if (superfluous
&& ghost
!=None
) {
3448 XFreePixmap(dpy
, ghost
);
3460 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3462 XUngrabPointer(dpy
, CurrentTime
);
3463 XUnmapWindow(dpy
, scr
->dock_shadow
);
3464 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3465 if (dock
->type
== WM_DOCK
) {
3468 dock
->on_right_side
= 1;
3470 dock
->on_right_side
= 0;
3472 wArrangeIcons(scr
, False
);
3481 XFreePixmap(dpy
, ghost
);
3482 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3485 puts("End dock move");
3492 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3494 WScreen
*scr
= dock
->screen_ptr
;
3496 WIcon
*icon
= aicon
->icon
;
3497 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3498 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3500 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3501 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3502 int shad_x
= x
, shad_y
= y
;
3503 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3505 Pixmap ghost
= None
;
3507 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3509 if (wPreferences
.flags
.noupdates
)
3512 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3513 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3514 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3516 wwarning("pointer grab failed for icon move");
3520 wRaiseFrame(icon
->core
);
3522 if (!wPreferences
.flags
.noclip
)
3523 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3525 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3527 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3530 wins
[0] = icon
->core
->window
;
3531 wins
[1] = scr
->dock_shadow
;
3532 XRestackWindows(dpy
, wins
, 2);
3533 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3534 ICON_SIZE
, ICON_SIZE
);
3536 if (icon
->pixmap
!=None
)
3537 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3539 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3541 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3542 XClearWindow(dpy
, scr
->dock_shadow
);
3544 XMapWindow(dpy
, scr
->dock_shadow
);
3550 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3551 |ButtonMotionMask
|ExposureMask
, &ev
);
3559 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3560 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3561 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3562 |ButtonReleaseMask
|ButtonPressMask
,
3563 wCursor
[WCUR_MOVE
], CurrentTime
);
3570 x
= ev
.xmotion
.x_root
- ofs_x
;
3571 y
= ev
.xmotion
.y_root
- ofs_y
;
3572 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3575 if (last_dock
!= dock
&& collapsed
) {
3576 last_dock
->collapsed
= 1;
3577 wDockHideIcons(last_dock
);
3580 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3581 dock
->collapsed
= 0;
3582 wDockShowIcons(dock
);
3584 if (dock
->auto_raise_lower
)
3589 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3592 if (last_dock
!= dock2
&& collapsed
) {
3593 last_dock
->collapsed
= 1;
3594 wDockHideIcons(last_dock
);
3597 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3598 dock2
->collapsed
= 0;
3599 wDockShowIcons(dock2
);
3601 if (dock2
->auto_raise_lower
)
3606 if (aicon
->launching
3607 || (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3608 || (!aicon
->running
&& tmp
)) {
3609 shad_x
= last_dock
->x_pos
+ ix
*wPreferences
.icon_size
;
3610 shad_y
= last_dock
->y_pos
+ iy
*wPreferences
.icon_size
;
3612 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3615 XMapWindow(dpy
, scr
->dock_shadow
);
3617 if (!collapsed
&& (collapsed
= last_dock
->collapsed
)) {
3618 last_dock
->collapsed
= 0;
3619 wDockShowIcons(last_dock
);
3626 XUnmapWindow(dpy
, scr
->dock_shadow
);
3628 if (last_dock
&& collapsed
&&
3629 aicon
->running
&& (ev
.xmotion
.state
& MOD_MASK
)) {
3630 last_dock
->collapsed
= 1;
3631 wDockHideIcons(last_dock
);
3638 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3645 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3647 XUngrabPointer(dpy
, CurrentTime
);
3649 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3650 XUnmapWindow(dpy
, scr
->dock_shadow
);
3652 reattachIcon(dock
, aicon
, ix
, iy
);
3653 if (clip
&& dock
!=clip
&& clip
->auto_raise_lower
)
3656 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3658 /* Slide it back if dock rejected it */
3659 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3661 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3663 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3671 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3672 /* We need to deselect it, even if is deselected in
3673 * wDockDetach(), because else DoKaboom() will fail.
3675 if (aicon
->icon
->selected
)
3676 wIconSelect(aicon
->icon
);
3677 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3680 if (clip
&& clip
->auto_raise_lower
)
3682 wDockDetach(dock
, aicon
);
3685 last_dock
->collapsed
= 1;
3686 wDockHideIcons(last_dock
);
3691 XFreePixmap(dpy
, ghost
);
3692 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3695 puts("End icon move");
3704 getClipButton(int px
, int py
)
3706 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
3708 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3711 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
3712 return CLIP_FORWARD
;
3713 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
3721 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3724 int done
, direction
, new_ws
;
3726 WDock
*clip
= scr
->clip_icon
->dock
;
3728 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3730 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3731 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3733 wClipIconPaint(scr
->clip_icon
);
3736 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
3737 |ButtonPressMask
, &ev
);
3744 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3745 if (new_dir
!= direction
) {
3746 direction
= new_dir
;
3747 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
3748 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
3749 wClipIconPaint(scr
->clip_icon
);
3757 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3762 clip
->lclip_button_pushed
= 0;
3763 clip
->rclip_button_pushed
= 0;
3765 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3767 if (direction
== CLIP_FORWARD
) {
3768 if (scr
->current_workspace
< scr
->workspace_count
-1)
3769 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3770 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
3771 wWorkspaceChange(scr
, scr
->current_workspace
+1);
3772 else if (wPreferences
.ws_cycle
)
3773 wWorkspaceChange(scr
, 0);
3775 else if (direction
== CLIP_REWIND
) {
3776 if (scr
->current_workspace
> 0)
3777 wWorkspaceChange(scr
, scr
->current_workspace
-1);
3778 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
3779 wWorkspaceChange(scr
, scr
->workspace_count
-1);
3782 wClipIconPaint(scr
->clip_icon
);
3787 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3789 WAppIcon
*aicon
= desc
->parent
;
3790 WDock
*dock
= aicon
->dock
;
3791 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3793 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3796 scr
->last_dock
= dock
;
3798 if (dock
->menu
->flags
.mapped
)
3799 wMenuUnmap(dock
->menu
);
3801 if (IsDoubleClick(scr
, event
)) {
3802 /* double-click was not in the main clip icon */
3803 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
3804 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
3805 iconDblClick(desc
, event
);
3810 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
3811 XUnmapWindow(dpy
, scr
->clip_balloon
);
3812 scr
->flags
.clip_balloon_mapped
= 0;
3816 puts("handling dock");
3818 if (event
->xbutton
.button
== Button1
) {
3819 if (event
->xbutton
.state
& MOD_MASK
)
3824 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
3825 dock
->type
!=WM_DOCK
) {
3826 wIconSelect(aicon
->icon
);
3830 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
3831 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
3832 && dock
->type
==WM_CLIP
)
3833 handleClipChangeWorkspace(scr
, event
);
3835 handleDockMove(dock
, aicon
, event
);
3837 handleIconMove(dock
, aicon
, event
);
3839 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
3840 aicon
->xindex
==0 && aicon
->yindex
==0) {
3841 openClipWorkspaceMenu(scr
, event
->xbutton
.x_root
+2,
3842 event
->xbutton
.y_root
+2);
3843 if (scr
->clip_ws_menu
) {
3845 menu
= scr
->clip_ws_menu
;
3846 desc
= &menu
->menu
->descriptor
;
3848 event
->xany
.send_event
= True
;
3849 (*desc
->handle_mousedown
)(desc
, event
);
3851 } else if (event
->xbutton
.button
== Button3
) {
3852 openDockMenu(dock
, aicon
, event
);
3858 showClipBalloon(WDock
*dock
, int workspace
)
3862 WScreen
*scr
= dock
->screen_ptr
;
3866 scr
->flags
.clip_balloon_mapped
= 1;
3867 XMapWindow(dpy
, scr
->clip_balloon
);
3869 text
= scr
->workspaces
[workspace
]->name
;
3871 w
= wTextWidth(scr
->clip_title_font
->font
, text
, strlen(text
));
3873 h
= scr
->clip_title_font
->height
;
3874 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
3876 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
3877 y
= dock
->y_pos
+ ICON_SIZE
-scr
->clip_title_font
->height
- 3;
3879 if (x
+w
> scr
->scr_width
) {
3880 x
= scr
->scr_width
- w
;
3881 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
3882 y
= dock
->y_pos
- h
- 1;
3884 y
= dock
->y_pos
+ ICON_SIZE
;
3885 XRaiseWindow(dpy
, scr
->clip_balloon
);
3887 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
3888 stack
[1] = scr
->clip_balloon
;
3889 XRestackWindows(dpy
, stack
, 2);
3891 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
3892 XSetForeground(dpy
, scr
->clip_title_gc
,
3893 scr
->clip_title_pixel
[CLIP_NORMAL
]);
3894 XClearWindow(dpy
, scr
->clip_balloon
);
3895 wDrawString(scr
->clip_balloon
, scr
->clip_title_font
, scr
->clip_title_gc
,
3896 0, scr
->clip_title_font
->y
, text
, strlen(text
));
3901 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3903 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
3906 assert(event
->type
==EnterNotify
);
3908 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
3912 if (!dock
|| dock
->type
!=WM_CLIP
)
3915 /* The auto raise/lower code */
3916 if (dock
->auto_lower_magic
) {
3917 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3918 dock
->auto_lower_magic
= NULL
;
3920 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
3921 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
,
3926 /* The auto expand/collapse code */
3927 if (dock
->auto_collapse_magic
) {
3928 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3929 dock
->auto_collapse_magic
= NULL
;
3931 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
3932 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
,
3937 if (btn
->xindex
== 0 && btn
->yindex
== 0)
3938 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
3940 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
3941 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
3942 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
3949 clipLeave(WDock
*dock
)
3952 WObjDescriptor
*desc
= NULL
;
3954 if (!dock
|| dock
->type
!=WM_CLIP
)
3957 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
)!=False
) {
3958 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3959 (XPointer
*)&desc
)!=XCNOENT
3960 && desc
&& desc
->parent_type
==WCLASS_DOCK_ICON
3961 && ((WAppIcon
*)desc
->parent
)->dock
3962 && ((WAppIcon
*)desc
->parent
)->dock
->type
==WM_CLIP
) {
3963 /* We didn't left the Clip yet */
3964 XPutBackEvent(dpy
, &event
);
3968 XPutBackEvent(dpy
, &event
);
3970 /* We entered a withdrawn window, so we're still in Clip */
3974 if (dock
->auto_raise_magic
) {
3975 WMDeleteTimerHandler(dock
->auto_raise_magic
);
3976 dock
->auto_raise_magic
= NULL
;
3978 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
3979 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
,
3984 if (dock
->auto_expand_magic
) {
3985 WMDeleteTimerHandler(dock
->auto_expand_magic
);
3986 dock
->auto_expand_magic
= NULL
;
3988 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
3989 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
3997 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
3999 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4001 assert(event
->type
==LeaveNotify
);
4003 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4006 clipLeave(btn
->dock
);
4011 clipAutoCollapse(void *cdata
)
4013 WDock
*dock
= (WDock
*)cdata
;
4015 if (dock
->type
!=WM_CLIP
|| !dock
->auto_collapse
)
4018 if (dock
->auto_collapse_magic
) {
4019 dock
->collapsed
= 1;
4020 wDockHideIcons(dock
);
4022 dock
->auto_collapse_magic
= NULL
;
4027 clipAutoExpand(void *cdata
)
4029 WDock
*dock
= (WDock
*)cdata
;
4031 if (dock
->type
!=WM_CLIP
|| !dock
->auto_collapse
)
4034 if (dock
->auto_expand_magic
) {
4035 dock
->collapsed
= 0;
4036 wDockShowIcons(dock
);
4038 dock
->auto_expand_magic
= NULL
;
4043 clipAutoLower(void *cdata
)
4045 WDock
*dock
= (WDock
*)cdata
;
4047 if (dock
->type
!=WM_CLIP
)
4050 if (dock
->auto_raise_lower
)
4053 dock
->auto_lower_magic
= NULL
;
4058 clipAutoRaise(void *cdata
)
4060 WDock
*dock
= (WDock
*)cdata
;
4062 if (dock
->type
!=WM_CLIP
)
4065 if (dock
->auto_raise_lower
)
4068 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4069 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4072 dock
->auto_raise_magic
= NULL
;