1 /* dock.c- built-in Dock module for WindowMaker
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 * Copyright (c) 1998, 1999 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
28 #include <X11/Xutil.h>
36 #define PATH_MAX DEFAULT_PATH_MAX
39 #include "WindowMaker.h"
49 #include "properties.h"
53 #include "workspace.h"
55 #include "superfluous.h"
64 /**** Local variables ****/
67 #define CLIP_FORWARD 2
70 /**** Global variables ****/
73 extern void DestroyDockAppSettingsPanel();
75 extern void ShowDockAppSettingsPanel(WAppIcon
*aicon
);
78 extern XContext wWinContext
;
80 extern Cursor wCursor
[WCUR_LAST
];
82 extern WPreferences wPreferences
;
84 extern XContext wWinContext
;
87 extern Atom _XA_DND_PROTOCOL
;
91 #define MOD_MASK wPreferences.modifier_mask
93 extern void appIconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
95 #define ICON_SIZE wPreferences.icon_size
98 /***** Local variables ****/
100 static proplist_t dCommand
=NULL
;
102 static proplist_t dDropCommand
=NULL
;
104 static proplist_t dAutoLaunch
, dLock
;
105 static proplist_t dName
, dForced
, dBuggyApplication
, dYes
, dNo
;
106 static proplist_t dHost
, dDock
, dClip
;
107 static proplist_t dAutoAttractIcons
;
109 static proplist_t dPosition
, dApplications
, dLowered
, dCollapsed
, dAutoCollapse
;
111 static proplist_t dAutoRaiseLower
, dOmnipresent
;
113 static void dockIconPaint(WAppIcon
*btn
);
115 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
117 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
);
119 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
121 static int getClipButton(int px
, int py
);
123 static void toggleLowered(WDock
*dock
);
125 static void toggleCollapsed(WDock
*dock
);
127 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
129 static void clipLeave(WDock
*dock
);
131 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
133 Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
);
135 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
136 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
137 static void clipAutoCollapse(void *cdata
);
138 static void clipAutoExpand(void *cdata
);
139 static void launchDockedApplication(WAppIcon
*btn
);
141 static void clipAutoLower(void *cdata
);
142 static void clipAutoRaise(void *cdata
);
144 static void showClipBalloon(WDock
*dock
, int workspace
);
160 #endif /* OFFIX_DND */
170 dCommand
= PLRetain(PLMakeString("Command"));
172 dDropCommand
= PLRetain(PLMakeString("DropCommand"));
174 dLock
= PLRetain(PLMakeString("Lock"));
175 dAutoLaunch
= PLRetain(PLMakeString("AutoLaunch"));
176 dName
= PLRetain(PLMakeString("Name"));
177 dForced
= PLRetain(PLMakeString("Forced"));
178 dBuggyApplication
= PLRetain(PLMakeString("BuggyApplication"));
179 dYes
= PLRetain(PLMakeString("Yes"));
180 dNo
= PLRetain(PLMakeString("No"));
181 dHost
= PLRetain(PLMakeString("Host"));
183 dPosition
= PLMakeString("Position");
184 dApplications
= PLMakeString("Applications");
185 dLowered
= PLMakeString("Lowered");
186 dCollapsed
= PLMakeString("Collapsed");
187 dAutoCollapse
= PLMakeString("AutoCollapse");
188 dAutoRaiseLower
= PLMakeString("AutoRaiseLower");
189 dAutoAttractIcons
= PLMakeString("AutoAttractIcons");
191 dOmnipresent
= PLMakeString("Omnipresent");
193 dDock
= PLMakeString("Dock");
194 dClip
= PLMakeString("Clip");
200 renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
202 WDock
*dock
= entry
->clientdata
;
207 assert(entry
->clientdata
!=NULL
);
209 wspace
= dock
->screen_ptr
->current_workspace
;
211 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
213 sprintf(buffer
, _("Type the name for workspace %i:"), wspace
+1);
214 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
,
216 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
225 toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
227 assert(entry
->clientdata
!=NULL
);
229 toggleLowered(entry
->clientdata
);
237 killCallback(WMenu
*menu
, WMenuEntry
*entry
)
240 #ifdef REDUCE_APPICONS
241 WAppIconAppList
*tapplist
;
243 extern Atom _XA_WM_DELETE_WINDOW
;
248 if (!WCHECK_STATE(WSTATE_NORMAL
))
251 assert(entry
->clientdata
!=NULL
);
253 icon
= (WAppIcon
*)entry
->clientdata
;
257 WCHANGE_STATE(WSTATE_MODAL
);
259 #ifdef REDUCE_APPICONS
260 /* Send a delete message to the main window of each application
261 * bound to this docked appicon. - cls
263 tapplist
= icon
->applist
;
264 while (tapplist
!= NULL
) {
265 if (tapplist
->wapp
->main_window_desc
!= NULL
) {
266 if (tapplist
->wapp
->main_window_desc
->protocols
.DELETE_WINDOW
) {
267 wClientSendProtocol(tapplist
->wapp
->main_window_desc
,
268 _XA_WM_DELETE_WINDOW
, CurrentTime
);
270 wClientKill(tapplist
->wapp
->main_window_desc
);
273 tapplist
= tapplist
->next
;
276 buffer
= wstrappend(icon
->wm_class
,
277 _(" will be forcibly closed.\n"
278 "Any unsaved changes will be lost.\n"
281 if (wPreferences
.dont_confirm_kill
282 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
283 buffer
, _("Yes"), _("No"), NULL
)==WAPRDefault
) {
284 if (icon
->icon
&& icon
->icon
->owner
) {
285 wClientKill(icon
->icon
->owner
);
288 #endif /* !REDUCE_APPICONS */
292 WCHANGE_STATE(WSTATE_NORMAL
);
296 /* TODO: replace this function with a member of the dock struct */
298 numberOfSelectedIcons(WDock
*dock
)
304 for (i
=1; i
<dock
->max_icons
; i
++) {
305 aicon
= dock
->icon_array
[i
];
306 if (aicon
&& aicon
->icon
->selected
) {
316 getSelected(WDock
*dock
)
318 WMBag
*ret
= WMCreateBag(8);
322 for (i
=1; i
<dock
->max_icons
; i
++) {
323 btn
= dock
->icon_array
[i
];
324 if (btn
&& btn
->icon
->selected
) {
325 WMPutInBag(ret
, btn
);
334 paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
336 Window win
= clipIcon
->icon
->core
->window
;
337 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
339 int pt
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
340 int tp
= ICON_SIZE
- pt
;
341 int as
= pt
- 15; /* 15 = 5+5+5 */
342 GC gc
= scr
->clip_title_gc
;
343 #ifdef GRADIENT_CLIP_ARROW
344 Bool collapsed
= clipIcon
->dock
->collapsed
;
350 p
[1].x
= ICON_SIZE
-2;
352 p
[2].x
= ICON_SIZE
-2;
354 } else if (lpushed
) {
358 p
[1].y
= ICON_SIZE
-2;
360 p
[2].y
= ICON_SIZE
-2;
362 if (lpushed
|| rpushed
) {
363 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
364 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
365 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
367 #ifdef GRADIENT_CLIP_ARROW
369 XSetFillStyle(dpy
, scr
->copy_gc
, FillTiled
);
370 XSetTile(dpy
, scr
->copy_gc
, scr
->clip_arrow_gradient
);
371 XSetClipMask(dpy
, scr
->copy_gc
, None
);
374 #endif /* GRADIENT_CLIP_ARROW */
376 /* top right arrow */
377 p
[0].x
= p
[3].x
= ICON_SIZE
-5-as
;
379 p
[1].x
= ICON_SIZE
-6;
381 p
[2].x
= ICON_SIZE
-6;
384 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
385 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
387 #ifdef GRADIENT_CLIP_ARROW
389 XSetTSOrigin(dpy
, gc
, ICON_SIZE
-6-as
, 5);
391 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
392 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
395 /* bottom left arrow */
397 p
[0].y
= p
[3].y
= ICON_SIZE
-5-as
;
399 p
[1].y
= ICON_SIZE
-6;
401 p
[2].y
= ICON_SIZE
-6;
403 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
404 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
406 #ifdef GRADIENT_CLIP_ARROW
408 XSetTSOrigin(dpy
, gc
, 5, ICON_SIZE
-6-as
);
410 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
411 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
413 #ifdef GRADIENT_CLIP_ARROW
415 XSetFillStyle(dpy
, scr
->copy_gc
, FillSolid
);
421 wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
423 RImage
*tile
= RCloneImage(normalTile
);
430 pt
= CLIP_BUTTON_SIZE
*wPreferences
.icon_size
/64;
431 tp
= wPreferences
.icon_size
-1 - pt
;
435 black
.red
= black
.green
= black
.blue
= 0;
438 dark
.red
= dark
.green
= dark
.blue
= 60;
441 light
.red
= light
.green
= light
.blue
= 80;
445 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
-2,
447 RDrawLine(tile
, tp
-1, 0, wPreferences
.icon_size
-1, pt
+1, &black
);
448 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
-3,
452 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4,
453 ICON_SIZE
- 5, 4, &dark
);
454 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5,
455 ICON_SIZE
- 5, 6 + as
, &dark
);
456 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
,
460 ROperateLine(tile
, RAddOperation
, 2, tp
+2, pt
-2,
461 wPreferences
.icon_size
-3, &dark
);
462 RDrawLine(tile
, 0, tp
-1, pt
+1, wPreferences
.icon_size
-1, &black
);
463 ROperateLine(tile
, RSubtractOperation
, 0, tp
-2, pt
+1,
464 wPreferences
.icon_size
-2, &light
);
467 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4,
468 ICON_SIZE
- 5, &dark
);
469 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
,
470 6 + as
, ICON_SIZE
- 5, &dark
);
471 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5,
479 omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
481 WAppIcon
*clickedIcon
= entry
->clientdata
;
484 WMBag
*selectedIcons
;
488 assert(entry
->clientdata
!=NULL
);
490 dock
= clickedIcon
->dock
;
492 selectedIcons
= getSelected(dock
);
494 if (!WMGetBagItemCount(selectedIcons
))
495 WMPutInBag(selectedIcons
, clickedIcon
);
498 for (i
= 0; i
< WMGetBagItemCount(selectedIcons
); i
++) {
499 aicon
= WMGetFromBag(selectedIcons
, i
);
501 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
503 else if (aicon
->icon
->selected
)
504 wIconSelect(aicon
->icon
);
506 WMFreeBag(selectedIcons
);
509 wMessageDialog(dock
->screen_ptr
, _("Warning"),
510 _("Some icons cannot be made omnipresent. "
511 "Please make sure that no other icon is "
512 "docked in the same positions on the other "
513 "workspaces and the Clip is not full in "
515 _("OK"), NULL
, NULL
);
516 } else if (failed
== 1) {
517 wMessageDialog(dock
->screen_ptr
, _("Warning"),
518 _("Icon cannot be made omnipresent. "
519 "Please make sure that no other icon is "
520 "docked in the same position on the other "
521 "workspaces and the Clip is not full in "
523 _("OK"), NULL
, NULL
);
529 removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
531 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
534 WMBag
*selectedIcons
;
538 assert(clickedIcon
!=NULL
);
540 dock
= clickedIcon
->dock
;
542 selectedIcons
= getSelected(dock
);
544 if (WMGetBagItemCount(selectedIcons
)) {
545 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
546 _("All selected icons will be removed!"),
547 _("OK"), _("Cancel"), NULL
)!=WAPRDefault
) {
548 WMFreeBag(selectedIcons
);
552 if (clickedIcon
->xindex
==0 && clickedIcon
->yindex
==0) {
553 WMFreeBag(selectedIcons
);
556 WMPutInBag(selectedIcons
, clickedIcon
);
559 WM_ITERATE_BAG(selectedIcons
, aicon
, it
) {
560 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
561 wDockDetach(dock
, aicon
);
563 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
564 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
565 aicon
->x_pos
, aicon
->y_pos
);
566 if (!dock
->mapped
|| dock
->collapsed
)
567 XMapWindow(dpy
, aicon
->icon
->core
->window
);
570 WMFreeBag(selectedIcons
);
572 if (wPreferences
.auto_arrange_icons
)
573 wArrangeIcons(dock
->screen_ptr
, True
);
578 keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
580 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
583 WMBag
*selectedIcons
;
586 assert(clickedIcon
!=NULL
);
587 dock
= clickedIcon
->dock
;
589 selectedIcons
= getSelected(dock
);
591 if (!WMGetBagItemCount(selectedIcons
)
592 && clickedIcon
!=dock
->screen_ptr
->clip_icon
) {
593 char *command
= NULL
;
595 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
596 clickedIcon
->editing
= 1;
597 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
598 _("Type the command used to launch the application"),
600 if (command
&& (command
[0]==0 ||
601 (command
[0]=='-' && command
[1]==0))) {
605 clickedIcon
->command
= command
;
606 clickedIcon
->editing
= 0;
608 clickedIcon
->editing
= 0;
611 WMFreeBag(selectedIcons
);
616 WMPutInBag(selectedIcons
, clickedIcon
);
619 WM_ITERATE_BAG(selectedIcons
, aicon
, it
) {
620 if (aicon
->icon
->selected
)
621 wIconSelect(aicon
->icon
);
622 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
623 aicon
->attracted
= 0;
624 if (aicon
->icon
->shadowed
) {
625 aicon
->icon
->shadowed
= 0;
626 aicon
->icon
->force_paint
= 1;
627 wAppIconPaint(aicon
);
631 WMFreeBag(selectedIcons
);
638 toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
640 WDock
*dock
= (WDock
*)entry
->clientdata
;
642 assert(entry
->clientdata
!=NULL
);
644 dock
->attract_icons
= !dock
->attract_icons
;
645 /*if (!dock->attract_icons)
646 dock->keep_attracted = 0;*/
648 entry
->flags
.indicator_on
= dock
->attract_icons
;
655 selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
657 WAppIcon
*icon
= (WAppIcon
*)entry
->clientdata
;
661 wIconSelect(icon
->icon
);
668 colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
670 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
673 int x
, y
, x_pos
, y_pos
;
675 assert(entry
->clientdata
!=NULL
);
676 clip
= clickedIcon
->dock
;
678 aicon
= clip
->screen_ptr
->app_icon_list
;
681 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
682 x_pos
= clip
->x_pos
+ x
*ICON_SIZE
;
683 y_pos
= clip
->y_pos
+ y
*ICON_SIZE
;
684 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
686 if (wPreferences
.no_animations
) {
687 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
689 SlideWindow(aicon
->icon
->core
->window
,
690 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
693 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
694 #endif /* ANIMATIONS */
696 aicon
->attracted
= 1;
697 if (!aicon
->icon
->shadowed
) {
698 aicon
->icon
->shadowed
= 1;
699 aicon
->icon
->force_paint
= 1;
700 /* We don't do an wAppIconPaint() here because it's in
701 * wDockAttachIcon(). -Dan
704 wDockAttachIcon(clip
, aicon
, x
, y
);
705 if (clip
->collapsed
|| !clip
->mapped
)
706 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
714 selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
716 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
718 WMBag
*selectedIcons
;
722 assert(clickedIcon
!=NULL
);
723 dock
= clickedIcon
->dock
;
725 selectedIcons
= getSelected(dock
);
727 if (!WMGetBagItemCount(selectedIcons
)) {
728 for (i
=1; i
<dock
->max_icons
; i
++) {
729 btn
= dock
->icon_array
[i
];
730 if (btn
&& !btn
->icon
->selected
) {
731 wIconSelect(btn
->icon
);
735 for (i
= 0; i
< WMGetBagItemCount(selectedIcons
); i
++) {
736 btn
= WMGetFromBag(selectedIcons
, i
);
737 wIconSelect(btn
->icon
);
740 WMFreeBag(selectedIcons
);
747 toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
749 assert(entry
->clientdata
!=NULL
);
751 toggleCollapsed(entry
->clientdata
);
753 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->collapsed
;
760 toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
763 assert(entry
->clientdata
!=NULL
);
765 dock
= (WDock
*) entry
->clientdata
;
767 dock
->auto_collapse
= !dock
->auto_collapse
;
769 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_collapse
;
776 toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
779 assert(entry
->clientdata
!=NULL
);
781 dock
= (WDock
*) entry
->clientdata
;
783 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
785 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_raise_lower
;
792 launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
794 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
796 launchDockedApplication(btn
);
801 settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
803 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
807 ShowDockAppSettingsPanel(btn
);
812 hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
815 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
817 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
819 if (wapp
->flags
.hidden
) {
820 wWorkspaceChange(btn
->icon
->core
->screen_ptr
,wapp
->last_workspace
);
821 wUnhideApplication(wapp
, False
, False
);
823 wHideApplication(wapp
);
829 unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
832 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
834 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
836 wUnhideApplication(wapp
, False
, True
);
841 mainIconCreate(WScreen
*scr
, int type
)
846 if (type
== WM_CLIP
) {
848 return scr
->clip_icon
;
849 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
850 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
851 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
852 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
853 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE;*/
856 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
857 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
863 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
864 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
865 btn
->icon
->core
->descriptor
.parent
= btn
;
866 /*ChangeStackingLevel(btn->icon->core, WMDockLevel);*/
867 XMapWindow(dpy
, btn
->icon
->core
->window
);
872 scr
->clip_icon
= btn
;
879 switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
881 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
882 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
884 WMBag
*selectedIcons
;
887 if (entry
->order
== scr
->current_workspace
)
890 dest
= scr
->workspaces
[entry
->order
]->clip
;
892 selectedIcons
= getSelected(src
);
894 if (WMGetBagItemCount(selectedIcons
)) {
896 for (i
= 0; i
< WMGetBagItemCount(selectedIcons
); i
++) {
897 btn
= WMGetFromBag(selectedIcons
, i
);
898 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
899 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
900 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
903 } else if (icon
!= scr
->clip_icon
) {
904 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
905 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
906 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
909 WMFreeBag(selectedIcons
);
915 launchDockedApplication(WAppIcon
*btn
)
917 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
919 if (!btn
->launching
&& btn
->command
!=NULL
) {
920 if (!btn
->forced_dock
) {
921 btn
->relaunching
= btn
->running
;
924 if (btn
->wm_instance
|| btn
->wm_class
) {
925 WWindowAttributes attr
;
926 memset(&attr
, 0, sizeof(WWindowAttributes
));
927 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
,
930 if (!attr
.no_appicon
&& !btn
->buggy_app
)
935 btn
->drop_launch
= 0;
936 scr
->last_dock
= btn
->dock
;
937 btn
->pid
= execCommand(btn
, btn
->command
, NULL
);
939 if (btn
->buggy_app
) {
940 /* give feedback that the app was launched */
944 WMAddTimerHandler(200, (WMCallback
*)dockIconPaint
, btn
);
949 wwarning(_("could not launch application %s\n"), btn
->command
);
951 if (!btn
->relaunching
)
960 updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
962 WScreen
*scr
= menu
->frame
->screen_ptr
;
963 char title
[MAX_WORKSPACENAME_WIDTH
+1];
969 for (i
=0; i
<scr
->workspace_count
; i
++) {
970 if (i
< menu
->entry_no
) {
971 if (strcmp(menu
->entries
[i
]->text
,scr
->workspaces
[i
]->name
)!=0) {
972 free(menu
->entries
[i
]->text
);
973 strcpy(title
, scr
->workspaces
[i
]->name
);
974 menu
->entries
[i
]->text
= wstrdup(title
);
975 menu
->flags
.realized
= 0;
977 menu
->entries
[i
]->clientdata
= (void*)icon
;
979 strcpy(title
, scr
->workspaces
[i
]->name
);
981 wMenuAddCallback(menu
, title
, switchWSCommand
, (void*)icon
);
983 menu
->flags
.realized
= 0;
985 if (i
== scr
->current_workspace
) {
986 wMenuSetEnabled(menu
, i
, False
);
988 wMenuSetEnabled(menu
, i
, True
);
992 if (!menu
->flags
.realized
)
998 makeWorkspaceMenu(WScreen
*scr
)
1002 menu
= wMenuCreate(scr
, NULL
, False
);
1004 wwarning(_("could not create workspace submenu for Clip menu"));
1006 wMenuAddCallback(menu
, "", switchWSCommand
, (void*)scr
->clip_icon
);
1008 menu
->flags
.realized
= 0;
1016 updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
1025 entry
= menu
->entries
[index
];
1026 if (dock
->lowered
) {
1027 entry
->text
= _("Keep on Top");
1029 entry
->text
= _("Allow Lowering");
1031 entry
->clientdata
= dock
;
1034 entry
= menu
->entries
[++index
];
1035 entry
->flags
.indicator_on
= dock
->collapsed
;
1036 entry
->clientdata
= dock
;
1039 entry
= menu
->entries
[++index
];
1040 entry
->flags
.indicator_on
= dock
->auto_collapse
;
1041 entry
->clientdata
= dock
;
1043 /* auto-raise/lower */
1044 entry
= menu
->entries
[++index
];
1045 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1046 entry
->clientdata
= dock
;
1049 entry
= menu
->entries
[++index
];
1050 entry
->flags
.indicator_on
= dock
->attract_icons
;
1051 entry
->clientdata
= dock
;
1053 menu
->flags
.realized
= 0;
1059 makeClipOptionsMenu(WScreen
*scr
)
1064 menu
= wMenuCreate(scr
, NULL
, False
);
1066 wwarning(_("could not create options submenu for Clip menu"));
1070 entry
= wMenuAddCallback(menu
, _("Keep on Top"),
1071 toggleLoweredCallback
, NULL
);
1073 entry
= wMenuAddCallback(menu
, _("Collapsed"),
1074 toggleCollapsedCallback
, NULL
);
1075 entry
->flags
.indicator
= 1;
1076 entry
->flags
.indicator_on
= 1;
1077 entry
->flags
.indicator_type
= MI_CHECK
;
1079 entry
= wMenuAddCallback(menu
, _("AutoCollapse"),
1080 toggleAutoCollapseCallback
, NULL
);
1081 entry
->flags
.indicator
= 1;
1082 entry
->flags
.indicator_on
= 1;
1083 entry
->flags
.indicator_type
= MI_CHECK
;
1085 entry
= wMenuAddCallback(menu
, _("AutoRaiseLower"),
1086 toggleAutoRaiseLowerCallback
, NULL
);
1087 entry
->flags
.indicator
= 1;
1088 entry
->flags
.indicator_on
= 1;
1089 entry
->flags
.indicator_type
= MI_CHECK
;
1091 entry
= wMenuAddCallback(menu
, _("AutoAttract Icons"),
1092 toggleAutoAttractCallback
, NULL
);
1093 entry
->flags
.indicator
= 1;
1094 entry
->flags
.indicator_on
= 1;
1095 entry
->flags
.indicator_type
= MI_CHECK
;
1097 menu
->flags
.realized
= 0;
1105 dockMenuCreate(WScreen
*scr
, int type
)
1110 if (type
== WM_CLIP
&& scr
->clip_menu
)
1111 return scr
->clip_menu
;
1113 menu
= wMenuCreate(scr
, NULL
, False
);
1114 if (type
!= WM_CLIP
) {
1115 entry
= wMenuAddCallback(menu
, _("Keep on Top"),
1116 toggleLoweredCallback
, NULL
);
1118 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1119 scr
->clip_options
= makeClipOptionsMenu(scr
);
1120 if (scr
->clip_options
)
1121 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1123 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
,
1126 entry
->text
= _("Rename Workspace");
1128 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1129 entry
->flags
.indicator
= 1;
1130 entry
->flags
.indicator_on
= 1;
1131 entry
->flags
.indicator_type
= MI_CHECK
;
1133 entry
= wMenuAddCallback(menu
, _("Select All Icons"),
1134 selectIconsCallback
, NULL
);
1136 entry
->text
= _("Select All Icons");
1138 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1140 entry
->text
= _("Keep Icon");
1142 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1144 entry
->text
= _("Move Icon To");
1145 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1146 if (scr
->clip_submenu
)
1147 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1149 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
,
1152 entry
->text
= _("Remove Icon");
1154 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1157 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1159 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1161 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1163 entry
->text
= _("Hide");
1165 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1167 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1169 if (type
== WM_CLIP
)
1170 scr
->clip_menu
= menu
;
1177 wDockCreate(WScreen
*scr
, int type
)
1185 dock
= wmalloc(sizeof(WDock
));
1186 memset(dock
, 0, sizeof(WDock
));
1188 if (type
== WM_CLIP
)
1189 icon_count
= CLIP_MAX_ICONS
;
1191 icon_count
= scr
->scr_height
/wPreferences
.icon_size
;
1193 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*)*icon_count
);
1194 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*)*icon_count
);
1196 dock
->max_icons
= icon_count
;
1198 btn
= mainIconCreate(scr
, type
);
1202 dock
->x_pos
= btn
->x_pos
;
1203 dock
->y_pos
= btn
->y_pos
;
1204 dock
->screen_ptr
= scr
;
1206 dock
->icon_count
= 1;
1207 dock
->on_right_side
= 1;
1208 dock
->collapsed
= 0;
1209 dock
->auto_collapse
= 0;
1210 dock
->auto_collapse_magic
= NULL
;
1211 dock
->auto_raise_lower
= 0;
1212 dock
->auto_lower_magic
= NULL
;
1213 dock
->auto_raise_magic
= NULL
;
1214 dock
->attract_icons
= 0;
1216 dock
->icon_array
[0] = btn
;
1217 wRaiseFrame(btn
->icon
->core
);
1218 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1220 /* create dock menu */
1221 dock
->menu
= dockMenuCreate(scr
, type
);
1228 wDockDestroy(WDock
*dock
)
1233 for (i
=(dock
->type
== WM_CLIP
) ? 1 : 0; i
<dock
->max_icons
; i
++) {
1234 aicon
= dock
->icon_array
[i
];
1236 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1237 wDockDetach(dock
, aicon
);
1239 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
1240 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
1241 aicon
->x_pos
, aicon
->y_pos
);
1242 if (!dock
->mapped
|| dock
->collapsed
)
1243 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1247 if (wPreferences
.auto_arrange_icons
)
1248 wArrangeIcons(dock
->screen_ptr
, True
);
1249 free(dock
->icon_array
);
1250 if (dock
->menu
&& dock
->type
!=WM_CLIP
)
1251 wMenuDestroy(dock
->menu
, True
);
1252 if (dock
->screen_ptr
->last_dock
== dock
)
1253 dock
->screen_ptr
->last_dock
= NULL
;
1259 wClipIconPaint(WAppIcon
*aicon
)
1261 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1262 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1264 Window win
= aicon
->icon
->core
->window
;
1265 int length
, nlength
;
1266 char *ws_name
, ws_number
[10];
1269 wIconPaint(aicon
->icon
);
1271 length
= strlen(workspace
->name
);
1272 ws_name
= malloc(length
+ 1);
1273 sprintf(ws_name
, "%s", workspace
->name
);
1274 sprintf(ws_number
, "%i", scr
->current_workspace
+ 1);
1275 nlength
= strlen(ws_number
);
1277 gc
= scr
->clip_title_gc
;
1279 if (!workspace
->clip
->collapsed
)
1280 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_NORMAL
]);
1282 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_COLLAPSED
]);
1284 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1286 tx
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
1288 WMDrawString(scr
->wmscreen
, win
, gc
, scr
->clip_title_font
, tx
,
1289 ty
, ws_name
, length
);
1291 tx
= (ICON_SIZE
/2 - WMWidthOfString(scr
->clip_title_font
, ws_number
,
1294 WMDrawString(scr
->wmscreen
, win
, gc
, scr
->clip_title_font
, tx
,
1295 2, ws_number
, nlength
);
1299 if (aicon
->launching
) {
1300 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1301 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1303 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
,
1304 aicon
->dock
->rclip_button_pushed
);
1309 clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1311 wClipIconPaint(desc
->parent
);
1316 dockIconPaint(WAppIcon
*btn
)
1318 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1319 wClipIconPaint(btn
);
1326 make_icon_state(WAppIcon
*btn
)
1328 proplist_t node
= NULL
;
1329 proplist_t command
, autolaunch
, lock
, name
, forced
, host
, position
, buggy
;
1330 proplist_t omnipresent
;
1336 command
= PLMakeString("-");
1338 command
= PLMakeString(btn
->command
);
1340 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1342 lock
= btn
->lock
? dYes
: dNo
;
1344 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1346 name
= PLMakeString(tmp
);
1350 forced
= btn
->forced_dock
? dYes
: dNo
;
1352 buggy
= btn
->buggy_app
? dYes
: dNo
;
1354 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1355 sprintf(buffer
, "%i,%i", btn
->x_pos
, btn
->y_pos
);
1357 sprintf(buffer
, "%hi,%hi", btn
->xindex
, btn
->yindex
);
1358 position
= PLMakeString(buffer
);
1360 node
= PLMakeDictionaryFromEntries(dCommand
, command
,
1362 dAutoLaunch
, autolaunch
,
1365 dBuggyApplication
, buggy
,
1366 dPosition
, position
,
1370 PLRelease(position
);
1372 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1373 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&&
1374 (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1375 PLInsertDictionaryEntry(node
, dOmnipresent
, omnipresent
);
1378 if (btn
->dnd_command
) {
1379 command
= PLMakeString(btn
->dnd_command
);
1380 PLInsertDictionaryEntry(node
, dDropCommand
, command
);
1383 #endif /* OFFIX_DND */
1385 if (btn
->client_machine
&& btn
->remote_start
) {
1386 host
= PLMakeString(btn
->client_machine
);
1387 PLInsertDictionaryEntry(node
, dHost
, host
);
1397 dockSaveState(WDock
*dock
)
1400 proplist_t icon_info
;
1401 proplist_t list
=NULL
, dock_state
=NULL
;
1402 proplist_t value
, key
;
1405 list
= PLMakeArrayFromElements(NULL
);
1407 for (i
=(dock
->type
==WM_DOCK
? 0 : 1); i
<dock
->max_icons
; i
++) {
1408 WAppIcon
*btn
= dock
->icon_array
[i
];
1410 if (!btn
|| btn
->attracted
)
1413 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1414 list
= PLAppendArrayElement(list
, icon_info
);
1415 PLRelease(icon_info
);
1419 dock_state
= PLMakeDictionaryFromEntries(dApplications
, list
,
1422 if (dock
->type
== WM_DOCK
) {
1423 sprintf(buffer
, "Applications%i", dock
->screen_ptr
->scr_height
);
1424 key
= PLMakeString(buffer
);
1425 PLInsertDictionaryEntry(dock_state
, key
, list
);
1429 sprintf(buffer
, "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0),
1431 value
= PLMakeString(buffer
);
1432 PLInsertDictionaryEntry(dock_state
, dPosition
, value
);
1438 value
= (dock
->lowered
? dYes
: dNo
);
1439 PLInsertDictionaryEntry(dock_state
, dLowered
, value
);
1441 if (dock
->type
== WM_CLIP
) {
1442 value
= (dock
->collapsed
? dYes
: dNo
);
1443 PLInsertDictionaryEntry(dock_state
, dCollapsed
, value
);
1445 value
= (dock
->auto_collapse
? dYes
: dNo
);
1446 PLInsertDictionaryEntry(dock_state
, dAutoCollapse
, value
);
1448 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1449 PLInsertDictionaryEntry(dock_state
, dAutoRaiseLower
, value
);
1451 value
= (dock
->attract_icons
? dYes
: dNo
);
1452 PLInsertDictionaryEntry(dock_state
, dAutoAttractIcons
, value
);
1460 wDockSaveState(WScreen
*scr
, proplist_t old_state
)
1462 proplist_t dock_state
;
1465 dock_state
= dockSaveState(scr
->dock
);
1468 * Copy saved states of docks with different sizes.
1474 keys
= PLGetAllDictionaryKeys(old_state
);
1475 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
1476 tmp
= PLGetArrayElement(keys
, i
);
1478 if (strncasecmp(PLGetString(tmp
), "applications", 12) == 0
1479 && !PLGetDictionaryEntry(dock_state
, tmp
)) {
1481 PLInsertDictionaryEntry(dock_state
,
1483 PLGetDictionaryEntry(old_state
, tmp
));
1490 PLInsertDictionaryEntry(scr
->session_state
, dDock
, dock_state
);
1492 PLRelease(dock_state
);
1497 wClipSaveState(WScreen
*scr
)
1499 proplist_t clip_state
;
1501 clip_state
= make_icon_state(scr
->clip_icon
);
1503 PLInsertDictionaryEntry(scr
->session_state
, dClip
, clip_state
);
1505 PLRelease(clip_state
);
1510 wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1512 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1517 getBooleanDockValue(proplist_t value
, proplist_t key
)
1520 if (PLIsString(value
)) {
1521 if (strcasecmp(PLGetString(value
), "YES")==0)
1524 wwarning(_("bad value in docked icon state info %s"),
1533 restore_icon_state(WScreen
*scr
, proplist_t info
, int type
, int index
)
1536 proplist_t cmd
, value
;
1539 cmd
= PLGetDictionaryEntry(info
, dCommand
);
1540 if (!cmd
|| !PLIsString(cmd
)) {
1544 /* parse window name */
1545 value
= PLGetDictionaryEntry(info
, dName
);
1550 char *wclass
, *winstance
;
1553 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1555 if (!winstance
&& !wclass
) {
1562 command
= wstrdup(PLGetString(cmd
));
1566 if (!command
|| strcmp(command
, "-")==0) {
1577 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
,
1587 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1588 if (type
== WM_CLIP
) {
1589 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1590 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1592 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1593 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1597 cmd
= PLGetDictionaryEntry(info
, dDropCommand
);
1599 aicon
->dnd_command
= wstrdup(PLGetString(cmd
));
1602 /* check auto launch */
1603 value
= PLGetDictionaryEntry(info
, dAutoLaunch
);
1605 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1608 value
= PLGetDictionaryEntry(info
, dLock
);
1610 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1612 /* check if it wasn't normally docked */
1613 value
= PLGetDictionaryEntry(info
, dForced
);
1615 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1617 /* check if we can rely on the stuff in the app */
1618 value
= PLGetDictionaryEntry(info
, dBuggyApplication
);
1620 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1622 /* get position in the dock */
1623 value
= PLGetDictionaryEntry(info
, dPosition
);
1624 if (value
&& PLIsString(value
)) {
1625 if (sscanf(PLGetString(value
), "%hi,%hi", &aicon
->xindex
,
1627 wwarning(_("bad value in docked icon state info %s"),
1628 PLGetString(dPosition
));
1630 /* check position sanity */
1631 /* incomplete section! */
1632 if (type
== WM_DOCK
) {
1634 if (aicon
->yindex
< 0)
1635 wwarning(_("bad value in docked icon position %i,%i"),
1636 aicon
->xindex
, aicon
->yindex
);
1639 aicon
->yindex
= index
;
1643 /* check if icon is omnipresent */
1644 value
= PLGetDictionaryEntry(info
, dOmnipresent
);
1646 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1655 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1659 wClipRestoreState(WScreen
*scr
, proplist_t clip_state
)
1665 icon
= mainIconCreate(scr
, WM_CLIP
);
1670 PLRetain(clip_state
);
1672 /* restore position */
1674 value
= PLGetDictionaryEntry(clip_state
, dPosition
);
1677 if (!PLIsString(value
))
1678 COMPLAIN("Position");
1680 if (sscanf(PLGetString(value
), "%i,%i", &icon
->x_pos
,
1682 COMPLAIN("Position");
1684 /* check position sanity */
1685 if (icon
->y_pos
< 0)
1687 else if (icon
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1688 icon
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1690 if (icon
->x_pos
< 0)
1692 else if (icon
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1693 icon
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1698 value
= PLGetDictionaryEntry(clip_state
, dDropCommand
);
1699 if (value
&& PLIsString(value
))
1700 icon
->dnd_command
= wstrdup(PLGetString(value
));
1703 PLRelease(clip_state
);
1710 wDockRestoreState(WScreen
*scr
, proplist_t dock_state
, int type
)
1715 WAppIcon
*aicon
, *old_top
;
1719 dock
= wDockCreate(scr
, type
);
1725 PLRetain(dock_state
);
1728 /* restore position */
1730 value
= PLGetDictionaryEntry(dock_state
, dPosition
);
1733 if (!PLIsString(value
))
1734 COMPLAIN("Position");
1736 if (sscanf(PLGetString(value
), "%i,%i", &dock
->x_pos
,
1738 COMPLAIN("Position");
1740 /* check position sanity */
1741 if (dock
->y_pos
< 0)
1743 else if (dock
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1744 dock
->y_pos
= scr
->scr_height
- ICON_SIZE
;
1746 /* This is no more needed. ??? */
1747 if (type
== WM_CLIP
) {
1748 if (dock
->x_pos
< 0)
1750 else if (dock
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1751 dock
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1753 if (dock
->x_pos
>= 0) {
1754 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1755 dock
->on_right_side
= 0;
1757 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1758 dock
->on_right_side
= 1;
1764 /* restore lowered/raised state */
1768 value
= PLGetDictionaryEntry(dock_state
, dLowered
);
1771 if (!PLIsString(value
))
1772 COMPLAIN("Lowered");
1774 if (strcasecmp(PLGetString(value
), "YES")==0)
1780 /* restore collapsed state */
1782 dock
->collapsed
= 0;
1784 value
= PLGetDictionaryEntry(dock_state
, dCollapsed
);
1787 if (!PLIsString(value
))
1788 COMPLAIN("Collapsed");
1790 if (strcasecmp(PLGetString(value
), "YES")==0)
1791 dock
->collapsed
= 1;
1796 /* restore auto-collapsed state */
1798 value
= PLGetDictionaryEntry(dock_state
, dAutoCollapse
);
1801 if (!PLIsString(value
))
1802 COMPLAIN("AutoCollapse");
1804 if (strcasecmp(PLGetString(value
), "YES")==0) {
1805 dock
->auto_collapse
= 1;
1806 dock
->collapsed
= 1;
1812 /* restore auto-raise/lower state */
1814 value
= PLGetDictionaryEntry(dock_state
, dAutoRaiseLower
);
1817 if (!PLIsString(value
))
1818 COMPLAIN("AutoRaiseLower");
1820 if (strcasecmp(PLGetString(value
), "YES")==0) {
1821 dock
->auto_raise_lower
= 1;
1826 /* restore attract icons state */
1828 dock
->attract_icons
= 0;
1830 value
= PLGetDictionaryEntry(dock_state
, dAutoAttractIcons
);
1833 if (!PLIsString(value
))
1834 COMPLAIN("AutoAttractIcons");
1836 if (strcasecmp(PLGetString(value
), "YES")==0)
1837 dock
->attract_icons
= 1;
1842 /* application list */
1849 * When saving, it saves the dock state in
1850 * Applications and Applicationsnnn
1852 * When loading, it will first try Applicationsnnn.
1853 * If it does not exist, use Applications as default.
1856 sprintf(buffer
, "Applications%i", scr
->scr_height
);
1858 tmp
= PLMakeString(buffer
);
1859 apps
= PLGetDictionaryEntry(dock_state
, tmp
);
1863 apps
= PLGetDictionaryEntry(dock_state
, dApplications
);
1871 count
= PLGetNumberOfElements(apps
);
1876 old_top
= dock
->icon_array
[0];
1878 /* dock->icon_count is set to 1 when dock is created.
1879 * Since Clip is already restored, we want to keep it so for clip,
1880 * but for dock we may change the default top tile, so we set it to 0.
1882 if (type
== WM_DOCK
)
1883 dock
->icon_count
= 0;
1885 for (i
=0; i
<count
; i
++) {
1886 if (dock
->icon_count
>= dock
->max_icons
) {
1887 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1891 value
= PLGetArrayElement(apps
, i
);
1892 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1894 dock
->icon_array
[dock
->icon_count
] = aicon
;
1898 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
*ICON_SIZE
);
1899 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
*ICON_SIZE
);
1902 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1904 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1906 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
,
1909 if (!dock
->collapsed
)
1910 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1911 wRaiseFrame(aicon
->icon
->core
);
1914 } else if (dock
->icon_count
==0 && type
==WM_DOCK
)
1918 /* if the first icon is not defined, use the default */
1919 if (dock
->icon_array
[0]==NULL
) {
1920 /* update default icon */
1921 old_top
->x_pos
= dock
->x_pos
;
1922 old_top
->y_pos
= dock
->y_pos
;
1924 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1926 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1927 dock
->icon_array
[0] = old_top
;
1928 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1929 /* we don't need to increment dock->icon_count here because it was
1930 * incremented in the loop above.
1932 } else if (old_top
!=dock
->icon_array
[0]) {
1933 if (old_top
== scr
->clip_icon
)
1934 scr
->clip_icon
= dock
->icon_array
[0];
1935 wAppIconDestroy(old_top
);
1940 PLRelease(dock_state
);
1948 wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1950 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1952 btn
->drop_launch
= 0;
1954 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1957 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1969 wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1975 for (i
= 0; i
< dock
->max_icons
; i
++) {
1976 btn
= dock
->icon_array
[i
];
1977 if (!btn
|| !btn
->auto_launch
)
1980 state
= wmalloc(sizeof(WSavedState
));
1981 memset(state
, 0, sizeof(WSavedState
));
1982 state
->workspace
= workspace
;
1983 /* TODO: this is klugy and is very difficult to understand
1984 * what's going on. Try to clean up */
1985 wDockLaunchWithState(dock
, btn
, state
);
1989 #ifdef REDUCE_APPICONS
1991 wDockSimulateLaunch(WDock
*dock
, WAppIcon
*btn
)
1993 if ((btn
== NULL
) || (dock
== NULL
))
1996 if (!btn
->running
) {
1997 if ((btn
->icon
->owner
== NULL
) && (btn
->applist
))
1998 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
1999 if (!btn
->forced_dock
)
2009 findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
2015 if ((dock
= scr
->dock
)!=NULL
) {
2016 for (i
=0; i
<dock
->max_icons
; i
++) {
2017 if (dock
->icon_array
[i
]
2018 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
2024 if (*icon_pos
<0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
)!=NULL
) {
2025 for (i
=0; i
<dock
->max_icons
; i
++) {
2026 if (dock
->icon_array
[i
]
2027 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
2040 wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
2046 dock
= findDock(scr
, event
, &icon_pos
);
2051 * Return True if the drop was on an application icon window.
2052 * In this case, let the ClientMessage handler redirect the
2053 * message to the app.
2055 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!=None
)
2058 if (dock
->icon_array
[icon_pos
]->dnd_command
!=NULL
) {
2059 scr
->flags
.dnd_data_convertion_status
= 0;
2061 btn
= dock
->icon_array
[icon_pos
];
2063 if (!btn
->forced_dock
) {
2064 btn
->relaunching
= btn
->running
;
2067 if (btn
->wm_instance
|| btn
->wm_class
) {
2068 WWindowAttributes attr
;
2069 memset(&attr
, 0, sizeof(WWindowAttributes
));
2070 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
2072 btn
->wm_class
, &attr
, NULL
, True
);
2074 if (!attr
.no_appicon
)
2080 btn
->drop_launch
= 1;
2081 scr
->last_dock
= dock
;
2082 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
2087 if (!btn
->relaunching
) {
2094 #endif /* OFFIX_DND */
2099 wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2106 wwin
= icon
->icon
->owner
;
2107 if (icon
->command
==NULL
) {
2109 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2111 icon
->command
= FlattenStringList(argv
, argc
);
2112 XFreeStringList(argv
);
2116 /* icon->forced_dock = 1;*/
2117 if (dock
->type
!=WM_CLIP
|| !icon
->attracted
) {
2119 if (wInputDialog(dock
->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
;
2133 /* If the target is the dock, reject the icon. If
2134 * the target is the clip, make it an attracted icon
2136 if (dock
->type
==WM_CLIP
) {
2137 icon
->attracted
= 1;
2138 if (!icon
->icon
->shadowed
) {
2139 icon
->icon
->shadowed
= 1;
2140 icon
->icon
->force_paint
= 1;
2152 for (index
=1; index
<dock
->max_icons
; index
++)
2153 if (dock
->icon_array
[index
] == NULL
)
2155 /* if (index == dock->max_icons)
2158 assert(index
< dock
->max_icons
);
2160 dock
->icon_array
[index
] = icon
;
2164 icon
->omnipresent
= 0;
2166 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2167 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2172 icon
->launching
= 0;
2175 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2176 if (dock
->type
== WM_CLIP
) {
2177 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2178 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2180 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2181 icon
->icon
->core
->descriptor
.parent
= icon
;
2183 MoveInStackListUnder(dock
->icon_array
[index
-1]->icon
->core
,
2185 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2186 wAppIconPaint(icon
);
2188 if (wPreferences
.auto_arrange_icons
)
2189 wArrangeIcons(dock
->screen_ptr
, True
);
2192 if (icon
->command
&& !icon
->dnd_command
) {
2193 icon
->dnd_command
= wmalloc(strlen(icon
->command
)+8);
2194 sprintf(icon
->dnd_command
, "%s %%d", icon
->command
);
2203 reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2207 for(index
=1; index
<dock
->max_icons
; index
++) {
2208 if(dock
->icon_array
[index
] == icon
)
2211 assert(index
< dock
->max_icons
);
2216 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2217 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2222 moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2230 return True
; /* No move needed, we're already there */
2235 wwin
= icon
->icon
->owner
;
2238 * For the moment we can't do this if we move icons in Clip from one
2239 * workspace to other, because if we move two or more icons without
2240 * command, the dialog box will not be able to tell us to which of the
2241 * moved icons it applies. -Dan
2243 if ((dest
->type
==WM_DOCK
/*|| dest->keep_attracted*/) && icon
->command
==NULL
) {
2244 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2246 icon
->command
= FlattenStringList(argv
, argc
);
2247 XFreeStringList(argv
);
2252 /* icon->forced_dock = 1;*/
2253 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2254 _("Type the command used to launch the application"),
2256 if (command
&& (command
[0]==0 ||
2257 (command
[0]=='-' && command
[1]==0))) {
2261 icon
->command
= command
;
2272 if (dest
->type
== WM_DOCK
)
2273 wClipMakeIconOmnipresent(icon
, False
);
2275 for(index
=1; index
<src
->max_icons
; index
++) {
2276 if(src
->icon_array
[index
] == icon
)
2279 assert(index
< src
->max_icons
);
2281 src
->icon_array
[index
] = NULL
;
2284 for(index
=1; index
<dest
->max_icons
; index
++) {
2285 if(dest
->icon_array
[index
] == NULL
)
2288 /* if (index == dest->max_icons)
2291 assert(index
< dest
->max_icons
);
2293 dest
->icon_array
[index
] = icon
;
2296 /* deselect the icon */
2297 if (icon
->icon
->selected
)
2298 wIconSelect(icon
->icon
);
2300 if (dest
->type
== WM_DOCK
) {
2301 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2302 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2304 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2305 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2308 /* set it to be kept when moving to dock.
2309 * Unless the icon does not have a command set
2311 if (icon
->command
&& dest
->type
==WM_DOCK
) {
2312 icon
->attracted
= 0;
2313 if (icon
->icon
->shadowed
) {
2314 icon
->icon
->shadowed
= 0;
2315 icon
->icon
->force_paint
= 1;
2319 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2325 icon
->x_pos
= dest
->x_pos
+ x
*ICON_SIZE
;
2326 icon
->y_pos
= dest
->y_pos
+ y
*ICON_SIZE
;
2330 MoveInStackListUnder(dest
->icon_array
[index
-1]->icon
->core
,
2332 wAppIconPaint(icon
);
2339 wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2343 /* make the settings panel be closed */
2345 DestroyDockAppSettingsPanel(icon
->panel
);
2348 /* This must be called before icon->dock is set to NULL.
2349 * Don't move it. -Dan
2351 wClipMakeIconOmnipresent(icon
, False
);
2355 icon
->attracted
= 0;
2356 icon
->auto_launch
= 0;
2357 if (icon
->icon
->shadowed
) {
2358 icon
->icon
->shadowed
= 0;
2359 icon
->icon
->force_paint
= 1;
2362 /* deselect the icon */
2363 if (icon
->icon
->selected
)
2364 wIconSelect(icon
->icon
);
2366 if (icon
->command
) {
2367 free(icon
->command
);
2368 icon
->command
= NULL
;
2371 if (icon
->dnd_command
) {
2372 free(icon
->dnd_command
);
2373 icon
->dnd_command
= NULL
;
2377 for (index
=1; index
<dock
->max_icons
; index
++)
2378 if (dock
->icon_array
[index
] == icon
)
2380 assert(index
< dock
->max_icons
);
2381 dock
->icon_array
[index
] = NULL
;
2387 /* if the dock is not attached to an application or
2388 * the the application did not set the approriate hints yet,
2389 * destroy the icon */
2390 #ifdef REDUCE_APPICONS
2391 if ((icon
->num_apps
== 0) && (!icon
->running
|| !wApplicationOf(icon
->main_window
)) )
2393 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2395 wAppIconDestroy(icon
);
2397 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2398 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2399 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2400 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2401 icon
->icon
->core
->descriptor
.parent
= icon
;
2403 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2405 wAppIconPaint(icon
);
2406 if (wPreferences
.auto_arrange_icons
) {
2407 wArrangeIcons(dock
->screen_ptr
, True
);
2410 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2416 * returns the closest Dock slot index for the passed
2419 * Returns False if icon can't be docked.
2421 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2425 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2426 int *ret_x
, int *ret_y
, int redocking
)
2428 WScreen
*scr
= dock
->screen_ptr
;
2431 int i
, offset
= ICON_SIZE
/2;
2432 WAppIcon
*aicon
= NULL
;
2433 WAppIcon
*nicon
= NULL
;
2434 int max_y_icons
, max_x_icons
;
2436 max_x_icons
= scr
->scr_width
/ICON_SIZE
;
2437 max_y_icons
= scr
->scr_height
/ICON_SIZE
-1;
2439 if (wPreferences
.flags
.noupdates
)
2445 /* if the dock is full */
2447 (dock
->icon_count
>= dock
->max_icons
)) {
2451 /* exact position */
2453 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2455 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2458 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2460 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2462 /* check if the icon is outside the screen boundaries */
2463 if (dx
+ ex_x
*ICON_SIZE
< -ICON_SIZE
+2 ||
2464 dx
+ ex_x
*ICON_SIZE
>= scr
->scr_width
-1 ||
2465 dy
+ ex_y
*ICON_SIZE
< -ICON_SIZE
+2 ||
2466 dy
+ ex_y
*ICON_SIZE
>= scr
->scr_height
-1)
2469 if (dock
->type
== WM_DOCK
) {
2470 if (icon
->dock
!= dock
&& ex_x
!= 0)
2474 for (i
=0; i
<dock
->max_icons
; i
++) {
2475 nicon
= dock
->icon_array
[i
];
2476 if (nicon
&& nicon
->yindex
== ex_y
) {
2483 int sig
, done
, closest
;
2485 /* Possible cases when redocking:
2487 * icon dragged out of range of any slot -> false
2488 * icon dragged to range of free slot
2489 * icon dragged to range of same slot
2490 * icon dragged to range of different icon
2492 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2495 if (ex_y
>=0 && ex_y
<=max_y_icons
&& (aicon
==icon
|| !aicon
)) {
2501 /* start looking at the upper slot or lower? */
2502 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2509 /* look for closest free slot */
2510 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2514 closest
= sig
*(i
/2) + ex_y
;
2515 /* check if this slot is used */
2517 for (j
= 0; j
<dock
->max_icons
; j
++) {
2518 if (dock
->icon_array
[j
]
2519 && dock
->icon_array
[j
]->yindex
==closest
) {
2520 /* slot is used by someone else */
2521 if (dock
->icon_array
[j
]!=icon
)
2529 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2530 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2532 (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+1))) {
2537 } else { /* !redocking */
2539 /* if slot is free and the icon is close enough, return it */
2540 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2550 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2551 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+1;
2554 for (k
=start
; k
<stop
; k
++) {
2555 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2558 for (i
=0; i
<tmp
->max_icons
; i
++) {
2559 nicon
= tmp
->icon_array
[i
];
2560 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2568 for (k
=start
; k
<stop
; k
++) {
2569 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2572 for (i
=0; i
<tmp
->max_icons
; i
++) {
2573 nicon
= tmp
->icon_array
[i
];
2574 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2575 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2576 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2585 if (neighbours
&& (aicon
==NULL
|| (redocking
&& aicon
== icon
))) {
2594 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2595 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2597 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2598 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2599 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2603 * returns true if it can find a free slot in the dock,
2604 * in which case it changes x_pos and y_pos accordingly.
2605 * Else returns false.
2608 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2610 WScreen
*scr
= dock
->screen_ptr
;
2612 WAppIconChain
*chain
;
2613 unsigned char *slot_map
;
2617 int i
, done
= False
;
2619 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2622 if (dock
->type
== WM_CLIP
&&
2623 dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2624 extra_count
= scr
->global_icon_count
;
2626 /* if the dock is full */
2627 if (dock
->icon_count
+extra_count
>= dock
->max_icons
) {
2631 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2632 if (scr
->dock
->on_right_side
)
2633 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2635 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2638 if (ex
< dock
->x_pos
)
2640 if (sx
> dock
->x_pos
+ICON_SIZE
)
2641 sx
= dock
->x_pos
+ICON_SIZE
;
2648 /* check if clip is in a corner */
2649 if (dock
->type
==WM_CLIP
) {
2650 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2652 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2654 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2656 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2663 /* If the clip is in the corner, use only slots that are in the border
2665 if (corner
!=C_NONE
) {
2669 hcount
= MIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2670 vcount
= MIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2671 hmap
= wmalloc(hcount
+1);
2672 memset(hmap
, 0, hcount
+1);
2673 vmap
= wmalloc(vcount
+1);
2674 memset(vmap
, 0, vcount
+1);
2676 /* mark used positions */
2679 for (i
=0; i
<dock
->max_icons
; i
++) {
2680 btn
= dock
->icon_array
[i
];
2684 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2685 vmap
[btn
->yindex
] = 1;
2686 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2687 hmap
[btn
->xindex
] = 1;
2689 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2691 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2692 vmap
[btn
->yindex
] = 1;
2693 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2694 hmap
[btn
->xindex
] = 1;
2698 for (i
=0; i
<dock
->max_icons
; i
++) {
2699 btn
= dock
->icon_array
[i
];
2703 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2704 vmap
[btn
->yindex
] = 1;
2705 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2706 hmap
[-btn
->xindex
] = 1;
2708 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2710 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2711 vmap
[btn
->yindex
] = 1;
2712 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2713 hmap
[-btn
->xindex
] = 1;
2717 for (i
=0; i
<dock
->max_icons
; i
++) {
2718 btn
= dock
->icon_array
[i
];
2722 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2723 vmap
[-btn
->yindex
] = 1;
2724 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2725 hmap
[btn
->xindex
] = 1;
2727 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2729 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2730 vmap
[-btn
->yindex
] = 1;
2731 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2732 hmap
[btn
->xindex
] = 1;
2737 for (i
=0; i
<dock
->max_icons
; i
++) {
2738 btn
= dock
->icon_array
[i
];
2742 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2743 vmap
[-btn
->yindex
] = 1;
2744 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2745 hmap
[-btn
->xindex
] = 1;
2747 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2749 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2750 vmap
[-btn
->yindex
] = 1;
2751 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2752 hmap
[-btn
->xindex
] = 1;
2757 /* search a vacant slot */
2758 for (i
=1; i
<MAX(vcount
, hcount
); i
++) {
2759 if (i
< vcount
&& vmap
[i
]==0) {
2765 } else if (i
< hcount
&& hmap
[i
]==0) {
2775 /* If found a slot, translate and return */
2777 if (corner
==C_NW
|| corner
==C_NE
) {
2782 if (corner
==C_NE
|| corner
==C_SE
) {
2789 /* else, try to find a slot somewhere else */
2792 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2793 * placed outside of screen */
2794 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2796 /* In the worst case (the clip is in the corner of the screen),
2797 * the amount of icons that fit in the clip is smaller.
2798 * Double the map to get a safe value.
2804 slot_map
= wmalloc(mwidth
*mwidth
);
2805 memset(slot_map
, 0, mwidth
*mwidth
);
2807 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2809 /* mark used slots in the map. If the slot falls outside the map
2810 * (for example, when all icons are placed in line), ignore them. */
2811 for (i
=0; i
<dock
->max_icons
; i
++) {
2812 btn
= dock
->icon_array
[i
];
2814 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2816 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2817 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2819 /* Find closest slot from the center that is free by scanning the
2820 * map from the center to outward in circular passes.
2821 * This will not result in a neat layout, but will be optimal
2822 * in the sense that there will not be holes left.
2825 for (i
= 1; i
<= r
&& !done
; i
++) {
2828 /* top and bottom parts of the ring */
2829 for (x
= -i
; x
<= i
&& !done
; x
++) {
2830 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2832 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2833 if (slot_map
[XY2OFS(x
,y
)]==0
2834 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2841 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2842 if (slot_map
[XY2OFS(x
,y
)]==0
2843 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2850 /* left and right parts of the ring */
2851 for (y
= -i
+1; y
<= i
-1; y
++) {
2852 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2854 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2855 if (slot_map
[XY2OFS(x
,y
)]==0
2856 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2863 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2864 if (slot_map
[XY2OFS(x
,y
)]==0
2865 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2880 moveDock(WDock
*dock
, int new_x
, int new_y
)
2885 dock
->x_pos
= new_x
;
2886 dock
->y_pos
= new_y
;
2887 for (i
=0; i
<dock
->max_icons
; i
++) {
2888 btn
= dock
->icon_array
[i
];
2890 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2891 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2892 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2899 swapDock(WDock
*dock
)
2901 WScreen
*scr
= dock
->screen_ptr
;
2906 if (dock
->on_right_side
) {
2907 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2909 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2912 for (i
=0; i
<dock
->max_icons
; i
++) {
2913 btn
= dock
->icon_array
[i
];
2916 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2920 wScreenUpdateUsableArea(scr
);
2925 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2927 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2933 cmdline
= ExpandOptions(scr
, command
);
2935 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2943 ParseCommand(cmdline
, &argv
, &argc
);
2953 if ((pid
=fork())==0) {
2957 SetupEnvironment(scr
);
2963 args
= malloc(sizeof(char*)*(argc
+1));
2966 for (i
=0; i
<argc
; i
++) {
2970 execvp(argv
[0], args
);
2979 state
= wmalloc(sizeof(WSavedState
));
2980 memset(state
, 0, sizeof(WSavedState
));
2982 state
->miniaturized
= -1;
2984 if (btn
->dock
==scr
->dock
|| btn
->omnipresent
)
2985 state
->workspace
= -1;
2987 state
->workspace
= scr
->current_workspace
;
2989 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
2991 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
3002 wDockHideIcons(WDock
*dock
)
3009 for (i
=1; i
<dock
->max_icons
; i
++) {
3010 if (dock
->icon_array
[i
])
3011 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3015 dockIconPaint(dock
->icon_array
[0]);
3020 wDockShowIcons(WDock
*dock
)
3028 btn
= dock
->icon_array
[0];
3029 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
3031 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
3032 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
3034 for (i
=1; i
<dock
->max_icons
; i
++) {
3035 if (dock
->icon_array
[i
]) {
3036 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
3042 if (!dock
->collapsed
) {
3043 for (i
=1; i
<dock
->max_icons
; i
++) {
3044 if (dock
->icon_array
[i
]) {
3045 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3056 wDockLower(WDock
*dock
)
3060 for (i
=0; i
<dock
->max_icons
; i
++) {
3061 if (dock
->icon_array
[i
])
3062 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
3068 wDockRaise(WDock
*dock
)
3072 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
3073 if (dock
->icon_array
[i
])
3074 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
3080 wDockRaiseLower(WDock
*dock
)
3082 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
3083 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
3084 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
3092 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
3094 icon
->launching
= 0;
3095 icon
->relaunching
= 0;
3096 dockIconPaint(icon
);
3101 wDockFindIconForWindow(WDock
*dock
, Window window
)
3106 for (i
=0; i
<dock
->max_icons
; i
++) {
3107 icon
= dock
->icon_array
[i
];
3108 if (icon
&& icon
->main_window
== window
)
3116 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
3119 #ifdef REDUCE_APPICONS
3120 WAppIconAppList
*tapplist
;
3122 char *wm_class
, *wm_instance
;
3124 Bool firstPass
= True
;
3126 char *command
= NULL
;
3132 if (XGetCommand(dpy
, window
, &argv
, &argc
)) {
3133 if (argc
> 0 && argv
!= NULL
)
3134 command
= FlattenStringList(argv
,argc
);
3136 XFreeStringList(argv
);
3141 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
3142 (!wm_class
&& !wm_instance
))
3146 for (i
=0; i
<dock
->max_icons
; i
++) {
3147 icon
= dock
->icon_array
[i
];
3151 /* app is already attached to icon */
3152 if (icon
->main_window
== window
) {
3157 if ((icon
->wm_instance
|| icon
->wm_class
)
3159 || (dock
->screen_ptr
->flags
.startup
&& !icon
->running
))) {
3161 if (icon
->wm_instance
&& wm_instance
&&
3162 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
3165 if (icon
->wm_class
&& wm_class
&&
3166 strcmp(icon
->wm_class
, wm_class
)!=0) {
3169 if (firstPass
&& command
&& strcmp(icon
->command
, command
)!=0) {
3173 if (!icon
->relaunching
) {
3176 /* Possibly an application that was docked with dockit,
3177 * but the user did not update WMState to indicate that
3178 * it was docked by force */
3179 wapp
= wApplicationOf(window
);
3181 icon
->forced_dock
= 1;
3184 if (!icon
->forced_dock
)
3185 icon
->main_window
= window
;
3187 #ifdef REDUCE_APPICONS
3188 tapplist
= wmalloc(sizeof(WAppIconAppList
));
3189 memset(tapplist
, 0, sizeof(WAppIconAppList
));
3190 tapplist
->next
= icon
->applist
;
3192 icon
->applist
->prev
= tapplist
;
3193 icon
->applist
= tapplist
;
3194 tapplist
->wapp
= wApplicationOf(window
);
3199 wDockFinishLaunch(dock
, icon
);
3204 if (firstPass
&& !found
) {
3221 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3223 if (!wPreferences
.flags
.noclip
) {
3224 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3225 if (scr
->current_workspace
!= workspace
) {
3226 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3227 WAppIconChain
*chain
= scr
->global_icons
;
3230 moveIconBetweenDocks(chain
->aicon
->dock
,
3231 scr
->workspaces
[workspace
]->clip
,
3232 chain
->aicon
, chain
->aicon
->xindex
,
3233 chain
->aicon
->yindex
);
3234 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
3235 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3236 chain
= chain
->next
;
3239 wDockHideIcons(old_clip
);
3240 if (old_clip
->auto_raise_lower
) {
3241 if (old_clip
->auto_raise_magic
) {
3242 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3243 old_clip
->auto_raise_magic
= NULL
;
3245 wDockLower(old_clip
);
3247 if (old_clip
->auto_collapse
) {
3248 if (old_clip
->auto_expand_magic
) {
3249 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3250 old_clip
->auto_expand_magic
= NULL
;
3252 old_clip
->collapsed
= 1;
3254 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3256 if (scr
->flags
.clip_balloon_mapped
)
3257 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3264 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3269 for (i
=0; i
<dock
->max_icons
; i
++) {
3270 icon
= dock
->icon_array
[i
];
3274 if (icon
->launching
&& icon
->pid
== pid
) {
3275 if (!icon
->relaunching
) {
3277 icon
->main_window
= None
;
3279 wDockFinishLaunch(dock
, icon
);
3284 sprintf(msg
, _("Could not execute command \"%s\""),
3285 icon
->drop_launch
&& icon
->dnd_command
3286 ? icon
->dnd_command
: icon
->command
);
3288 sprintf(msg
, _("Could not execute command \"%s\""),
3291 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
3292 _("OK"), NULL
, NULL
);
3301 toggleLowered(WDock
*dock
)
3306 /* lower/raise Dock */
3307 if (!dock
->lowered
) {
3308 newlevel
= WMNormalLevel
;
3311 newlevel
= WMDockLevel
;
3315 for (i
=0; i
<dock
->max_icons
; i
++) {
3316 tmp
= dock
->icon_array
[i
];
3320 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3322 wLowerFrame(tmp
->icon
->core
);
3325 if (dock
->type
== WM_DOCK
)
3326 wScreenUpdateUsableArea(dock
->screen_ptr
);
3331 toggleCollapsed(WDock
*dock
)
3333 if (dock
->collapsed
) {
3334 dock
->collapsed
= 0;
3335 wDockShowIcons(dock
);
3338 dock
->collapsed
= 1;
3339 wDockHideIcons(dock
);
3345 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3347 WScreen
*scr
= dock
->screen_ptr
;
3348 WObjDescriptor
*desc
;
3350 WApplication
*wapp
= NULL
;
3354 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3356 if (dock
->type
== WM_DOCK
) {
3358 entry
= dock
->menu
->entries
[index
];
3360 if (dock
->lowered
) {
3361 entry
->text
= _("Keep on Top");
3363 entry
->text
= _("Allow Lowering");
3365 entry
->clientdata
= dock
;
3367 dock
->menu
->flags
.realized
= 0;
3370 if (scr
->clip_options
)
3371 updateClipOptionsMenu(scr
->clip_options
, dock
);
3373 n_selected
= numberOfSelectedIcons(dock
);
3375 /* Rename Workspace */
3376 entry
= dock
->menu
->entries
[++index
];
3377 if (aicon
== scr
->clip_icon
) {
3378 entry
->callback
= renameCallback
;
3379 entry
->clientdata
= dock
;
3380 entry
->flags
.indicator
= 0;
3381 entry
->text
= _("Rename Workspace");
3383 entry
->callback
= omnipresentCallback
;
3384 entry
->clientdata
= aicon
;
3385 if (n_selected
> 0) {
3386 entry
->flags
.indicator
= 0;
3387 entry
->text
= _("Toggle Omnipresent");
3389 entry
->flags
.indicator
= 1;
3390 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3391 entry
->flags
.indicator_type
= MI_CHECK
;
3392 entry
->text
= _("Omnipresent");
3396 /* select/unselect icon */
3397 entry
= dock
->menu
->entries
[++index
];
3398 entry
->clientdata
= aicon
;
3399 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3400 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3402 /* select/unselect all icons */
3403 entry
= dock
->menu
->entries
[++index
];
3404 entry
->clientdata
= aicon
;
3406 entry
->text
= _("Unselect All Icons");
3408 entry
->text
= _("Select All Icons");
3409 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3412 entry
= dock
->menu
->entries
[++index
];
3413 entry
->clientdata
= aicon
;
3415 entry
->text
= _("Keep Icons");
3417 entry
->text
= _("Keep Icon");
3418 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3420 /* this is the workspace submenu part */
3421 entry
= dock
->menu
->entries
[++index
];
3423 entry
->text
= _("Move Icons To");
3425 entry
->text
= _("Move Icon To");
3426 if (scr
->clip_submenu
)
3427 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3428 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3430 /* remove icon(s) */
3431 entry
= dock
->menu
->entries
[++index
];
3432 entry
->clientdata
= aicon
;
3434 entry
->text
= _("Remove Icons");
3436 entry
->text
= _("Remove Icon");
3437 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3439 /* attract icon(s) */
3440 entry
= dock
->menu
->entries
[++index
];
3441 entry
->clientdata
= aicon
;
3443 dock
->menu
->flags
.realized
= 0;
3444 wMenuRealize(dock
->menu
);
3448 if (aicon
->icon
->owner
) {
3449 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3455 entry
= dock
->menu
->entries
[++index
];
3456 entry
->clientdata
= aicon
;
3457 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3460 entry
= dock
->menu
->entries
[++index
];
3461 entry
->clientdata
= aicon
;
3462 if (wapp
&& wapp
->flags
.hidden
) {
3463 entry
->text
= _("Unhide Here");
3465 entry
->text
= _("Bring Here");
3467 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3470 entry
= dock
->menu
->entries
[++index
];
3471 entry
->clientdata
= aicon
;
3472 if (wapp
&& wapp
->flags
.hidden
) {
3473 entry
->text
= _("Unhide");
3475 entry
->text
= _("Hide");
3477 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3480 entry
= dock
->menu
->entries
[++index
];
3481 entry
->clientdata
= aicon
;
3482 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
3483 && !wPreferences
.flags
.noupdates
);
3486 entry
= dock
->menu
->entries
[++index
];
3487 entry
->clientdata
= aicon
;
3488 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3490 if (!dock
->menu
->flags
.realized
)
3491 wMenuRealize(dock
->menu
);
3493 if (dock
->type
== WM_CLIP
) {
3494 x_pos
= event
->xbutton
.x_root
+2;
3496 x_pos
= dock
->on_right_side
?
3497 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 2 : 0;
3500 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3502 /* allow drag select */
3503 event
->xany
.send_event
= True
;
3504 desc
= &dock
->menu
->menu
->descriptor
;
3505 (*desc
->handle_mousedown
)(desc
, event
);
3510 openClipWorkspaceMenu(WScreen
*scr
, int x
, int y
)
3512 if (!scr
->clip_ws_menu
) {
3513 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3515 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
3516 wMenuMapAt(scr
->clip_ws_menu
, x
, y
, False
);
3520 /******************************************************************/
3522 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3524 WAppIcon
*btn
= desc
->parent
;
3525 WDock
*dock
= btn
->dock
;
3526 WApplication
*wapp
= NULL
;
3529 #ifdef REDUCE_APPICONS
3530 if ((btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) ||
3531 ((btn
->icon
->owner
== NULL
) && (btn
->applist
!= NULL
))) {
3532 if (btn
->icon
->owner
== NULL
)
3533 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
3535 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3537 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3541 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3543 /* go to the last workspace that the user worked on the app */
3544 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
3546 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3549 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3552 if (event
->xbutton
.state
& MOD_MASK
) {
3553 wHideOtherApplications(btn
->icon
->owner
);
3556 if (event
->xbutton
.button
==Button1
) {
3558 if (event
->xbutton
.state
& MOD_MASK
) {
3559 /* raise/lower dock */
3560 toggleLowered(dock
);
3561 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3562 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3563 toggleCollapsed(dock
);
3565 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3566 } else if (btn
->command
) {
3567 if (!btn
->launching
&&
3568 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3569 launchDockedApplication(btn
);
3571 } else if (btn
->xindex
== 0 && btn
->yindex
== 0
3572 && btn
->dock
->type
== WM_DOCK
) {
3574 wShowGNUstepPanel(dock
->screen_ptr
);
3582 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3584 WScreen
*scr
= dock
->screen_ptr
;
3585 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3588 int grabbed
= 0, swapped
= 0, done
;
3589 Pixmap ghost
= None
;
3590 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3593 puts("moving dock");
3595 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3596 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3597 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3598 wwarning("pointer grab failed for dock move");
3601 for (x
=0; x
<dock
->max_icons
; x
++) {
3602 if (dock
->icon_array
[x
]!=NULL
&&
3603 dock
->icon_array
[x
]->yindex
> y
)
3604 y
= dock
->icon_array
[x
]->yindex
;
3607 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3611 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3612 |ButtonMotionMask
|ExposureMask
, &ev
);
3620 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3621 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3622 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3623 |ButtonReleaseMask
|ButtonPressMask
,
3624 wCursor
[WCUR_MOVE
], CurrentTime
);
3629 if (dock
->type
== WM_CLIP
) {
3630 if (ev
.xmotion
.x_root
- ofs_x
< 0) {
3632 } else if (ev
.xmotion
.x_root
- ofs_x
+ ICON_SIZE
>
3634 x
= scr
->scr_width
- ICON_SIZE
;
3636 x
= ev
.xmotion
.x_root
- ofs_x
;
3638 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3640 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3642 y
= scr
->scr_height
- ICON_SIZE
;
3644 y
= ev
.xmotion
.y_root
- ofs_y
;
3646 moveDock(dock
, x
, y
);
3648 /* move vertically if pointer is inside the dock*/
3649 if ((dock
->on_right_side
&&
3650 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3651 || (!dock
->on_right_side
&&
3652 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3654 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3656 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3658 y
= scr
->scr_height
- ICON_SIZE
;
3660 y
= ev
.xmotion
.y_root
- ofs_y
;
3662 moveDock(dock
, dock
->x_pos
, y
);
3664 /* move horizontally to change sides */
3665 x
= ev
.xmotion
.x_root
- ofs_x
;
3666 if (!dock
->on_right_side
) {
3670 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3671 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3672 -DOCK_EXTRA_SPACE
-1, dock
->y_pos
);
3673 if (superfluous
&& ghost
==None
) {
3674 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3675 scr
->scr_width
-ICON_SIZE
3676 -DOCK_EXTRA_SPACE
-1,
3678 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3680 XClearWindow(dpy
, scr
->dock_shadow
);
3682 XMapRaised(dpy
, scr
->dock_shadow
);
3685 if (superfluous
&& ghost
!=None
) {
3686 XFreePixmap(dpy
, ghost
);
3689 XUnmapWindow(dpy
, scr
->dock_shadow
);
3694 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3695 XMoveWindow(dpy
, scr
->dock_shadow
,
3696 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3697 if (superfluous
&& ghost
==None
) {
3698 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3699 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3700 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3702 XClearWindow(dpy
, scr
->dock_shadow
);
3704 XMapRaised(dpy
, scr
->dock_shadow
);
3707 XUnmapWindow(dpy
, scr
->dock_shadow
);
3709 if (superfluous
&& ghost
!=None
) {
3710 XFreePixmap(dpy
, ghost
);
3722 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3724 XUngrabPointer(dpy
, CurrentTime
);
3725 XUnmapWindow(dpy
, scr
->dock_shadow
);
3726 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3727 if (dock
->type
== WM_DOCK
) {
3730 dock
->on_right_side
= 1;
3732 dock
->on_right_side
= 0;
3734 wArrangeIcons(scr
, False
);
3743 XFreePixmap(dpy
, ghost
);
3744 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3747 puts("End dock move");
3754 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3756 WScreen
*scr
= dock
->screen_ptr
;
3758 WIcon
*icon
= aicon
->icon
;
3759 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3760 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3762 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3763 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3764 int shad_x
= x
, shad_y
= y
;
3765 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3767 Pixmap ghost
= None
;
3769 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3770 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3773 if (wPreferences
.flags
.noupdates
)
3776 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3777 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3778 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3780 wwarning("pointer grab failed for icon move");
3784 if (!(event
->xbutton
.state
& MOD_MASK
))
3785 wRaiseFrame(icon
->core
);
3787 if (!wPreferences
.flags
.noclip
)
3788 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3790 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3792 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3795 wins
[0] = icon
->core
->window
;
3796 wins
[1] = scr
->dock_shadow
;
3797 XRestackWindows(dpy
, wins
, 2);
3798 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3799 ICON_SIZE
, ICON_SIZE
);
3801 if (icon
->pixmap
!=None
)
3802 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3804 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3806 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3807 XClearWindow(dpy
, scr
->dock_shadow
);
3809 XMapWindow(dpy
, scr
->dock_shadow
);
3815 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3816 |ButtonMotionMask
|ExposureMask
, &ev
);
3824 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3825 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3826 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3827 |ButtonReleaseMask
|ButtonPressMask
,
3828 wCursor
[WCUR_MOVE
], CurrentTime
);
3837 for (i
=0; i
<scr
->workspace_count
; i
++) {
3838 if (i
== scr
->current_workspace
)
3840 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3844 x
= ev
.xmotion
.x_root
- ofs_x
;
3845 y
= ev
.xmotion
.y_root
- ofs_y
;
3846 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3849 if (last_dock
!= dock
&& collapsed
) {
3850 last_dock
->collapsed
= 1;
3851 wDockHideIcons(last_dock
);
3854 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3855 dock
->collapsed
= 0;
3856 wDockShowIcons(dock
);
3858 if (dock
->auto_raise_lower
)
3862 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3865 if (last_dock
!= dock2
&& collapsed
) {
3866 last_dock
->collapsed
= 1;
3867 wDockHideIcons(last_dock
);
3870 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3871 dock2
->collapsed
= 0;
3872 wDockShowIcons(dock2
);
3874 if (dock2
->auto_raise_lower
)
3879 if (aicon
->launching
3881 || (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3882 || (!aicon
->running
&& tmp
)) {
3883 shad_x
= last_dock
->x_pos
+ ix
*wPreferences
.icon_size
;
3884 shad_y
= last_dock
->y_pos
+ iy
*wPreferences
.icon_size
;
3886 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3889 XMapWindow(dpy
, scr
->dock_shadow
);
3894 XUnmapWindow(dpy
, scr
->dock_shadow
);
3898 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3905 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3907 XUngrabPointer(dpy
, CurrentTime
);
3909 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3910 XUnmapWindow(dpy
, scr
->dock_shadow
);
3912 reattachIcon(dock
, aicon
, ix
, iy
);
3913 if (clip
&& dock
!=clip
&& clip
->auto_raise_lower
)
3916 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3918 /* Slide it back if dock rejected it */
3919 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3921 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3923 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3931 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3932 /* We need to deselect it, even if is deselected in
3933 * wDockDetach(), because else DoKaboom() will fail.
3935 if (aicon
->icon
->selected
)
3936 wIconSelect(aicon
->icon
);
3939 wSoundPlay(WMSOUND_KABOOM
);
3941 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3944 wSoundPlay(WMSOUND_UNDOCK
);
3949 wSoundPlay(WMSOUND_UNDOCK
);
3952 if (clip
&& clip
->auto_raise_lower
)
3954 wDockDetach(dock
, aicon
);
3957 last_dock
->collapsed
= 1;
3958 wDockHideIcons(last_dock
);
3963 XFreePixmap(dpy
, ghost
);
3964 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3968 for (i
=0; i
<scr
->workspace_count
; i
++) {
3969 if (i
== scr
->current_workspace
)
3971 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3976 puts("End icon move");
3985 getClipButton(int px
, int py
)
3987 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
3989 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3992 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
3993 return CLIP_FORWARD
;
3994 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
4002 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
4005 int done
, direction
, new_ws
;
4007 WDock
*clip
= scr
->clip_icon
->dock
;
4009 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
4011 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
4012 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
4014 wClipIconPaint(scr
->clip_icon
);
4017 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
4018 |ButtonPressMask
, &ev
);
4025 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
4026 if (new_dir
!= direction
) {
4027 direction
= new_dir
;
4028 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
4029 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
4030 wClipIconPaint(scr
->clip_icon
);
4038 if (ev
.xbutton
.button
== event
->xbutton
.button
)
4043 clip
->lclip_button_pushed
= 0;
4044 clip
->rclip_button_pushed
= 0;
4046 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
4048 if (direction
== CLIP_FORWARD
) {
4049 if (scr
->current_workspace
< scr
->workspace_count
-1)
4050 wWorkspaceChange(scr
, scr
->current_workspace
+1);
4051 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
4052 wWorkspaceChange(scr
, scr
->current_workspace
+1);
4053 else if (wPreferences
.ws_cycle
)
4054 wWorkspaceChange(scr
, 0);
4056 else if (direction
== CLIP_REWIND
) {
4057 if (scr
->current_workspace
> 0)
4058 wWorkspaceChange(scr
, scr
->current_workspace
-1);
4059 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
4060 wWorkspaceChange(scr
, scr
->workspace_count
-1);
4063 wClipIconPaint(scr
->clip_icon
);
4068 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
4070 WAppIcon
*aicon
= desc
->parent
;
4071 WDock
*dock
= aicon
->dock
;
4072 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4074 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
4077 scr
->last_dock
= dock
;
4079 if (dock
->menu
->flags
.mapped
)
4080 wMenuUnmap(dock
->menu
);
4082 if (IsDoubleClick(scr
, event
)) {
4083 /* double-click was not in the main clip icon */
4084 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
4085 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
4086 iconDblClick(desc
, event
);
4091 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
4092 XUnmapWindow(dpy
, scr
->clip_balloon
);
4093 scr
->flags
.clip_balloon_mapped
= 0;
4097 puts("handling dock");
4099 if (event
->xbutton
.button
== Button1
) {
4100 if (event
->xbutton
.state
& MOD_MASK
)
4105 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
4106 dock
->type
!=WM_DOCK
) {
4107 wIconSelect(aicon
->icon
);
4111 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
4112 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
4113 && dock
->type
==WM_CLIP
)
4114 handleClipChangeWorkspace(scr
, event
);
4116 handleDockMove(dock
, aicon
, event
);
4118 handleIconMove(dock
, aicon
, event
);
4120 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4121 aicon
==scr
->clip_icon
) {
4122 openClipWorkspaceMenu(scr
, event
->xbutton
.x_root
+2,
4123 event
->xbutton
.y_root
+2);
4124 if (scr
->clip_ws_menu
) {
4126 menu
= scr
->clip_ws_menu
;
4127 desc
= &menu
->menu
->descriptor
;
4129 event
->xany
.send_event
= True
;
4130 (*desc
->handle_mousedown
)(desc
, event
);
4132 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4133 (event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
) {
4134 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
4135 } else if (event
->xbutton
.button
== Button3
) {
4136 if (event
->xbutton
.send_event
&&
4137 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
4138 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
4139 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
4140 wwarning("pointer grab failed for dockicon menu");
4144 openDockMenu(dock
, aicon
, event
);
4150 showClipBalloon(WDock
*dock
, int workspace
)
4154 WScreen
*scr
= dock
->screen_ptr
;
4158 scr
->flags
.clip_balloon_mapped
= 1;
4159 XMapWindow(dpy
, scr
->clip_balloon
);
4161 text
= scr
->workspaces
[workspace
]->name
;
4163 w
= WMWidthOfString(scr
->clip_title_font
, text
, strlen(text
));
4165 h
= WMFontHeight(scr
->clip_title_font
);
4166 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
4168 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
4169 y
= dock
->y_pos
+ ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
4171 if (x
+w
> scr
->scr_width
) {
4172 x
= scr
->scr_width
- w
;
4173 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
4174 y
= dock
->y_pos
- h
- 1;
4176 y
= dock
->y_pos
+ ICON_SIZE
;
4177 XRaiseWindow(dpy
, scr
->clip_balloon
);
4179 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
4180 stack
[1] = scr
->clip_balloon
;
4181 XRestackWindows(dpy
, stack
, 2);
4183 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
4184 XSetForeground(dpy
, scr
->clip_title_gc
,
4185 scr
->clip_title_pixel
[CLIP_NORMAL
]);
4186 XClearWindow(dpy
, scr
->clip_balloon
);
4187 WMDrawString(scr
->wmscreen
, scr
->clip_balloon
, scr
->clip_title_gc
,
4188 scr
->clip_title_font
, 0, 0, text
, strlen(text
));
4193 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
4195 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4199 assert(event
->type
==EnterNotify
);
4201 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4204 scr
= btn
->icon
->core
->screen_ptr
;
4205 if (!btn
->omnipresent
)
4208 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
4210 if (!dock
|| dock
->type
!=WM_CLIP
)
4213 /* The auto raise/lower code */
4214 if (dock
->auto_lower_magic
) {
4215 WMDeleteTimerHandler(dock
->auto_lower_magic
);
4216 dock
->auto_lower_magic
= NULL
;
4218 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
4219 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
,
4224 /* The auto expand/collapse code */
4225 if (dock
->auto_collapse_magic
) {
4226 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
4227 dock
->auto_collapse_magic
= NULL
;
4229 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
4230 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
,
4235 if (btn
->xindex
== 0 && btn
->yindex
== 0)
4236 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4238 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4239 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
4240 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
4247 clipLeave(WDock
*dock
)
4250 WObjDescriptor
*desc
= NULL
;
4252 if (!dock
|| dock
->type
!=WM_CLIP
)
4255 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
)!=False
) {
4256 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
4257 (XPointer
*)&desc
)!=XCNOENT
4258 && desc
&& desc
->parent_type
==WCLASS_DOCK_ICON
4259 && ((WAppIcon
*)desc
->parent
)->dock
4260 && ((WAppIcon
*)desc
->parent
)->dock
->type
==WM_CLIP
) {
4261 /* We didn't left the Clip yet */
4262 XPutBackEvent(dpy
, &event
);
4266 XPutBackEvent(dpy
, &event
);
4268 /* We entered a withdrawn window, so we're still in Clip */
4272 if (dock
->auto_raise_magic
) {
4273 WMDeleteTimerHandler(dock
->auto_raise_magic
);
4274 dock
->auto_raise_magic
= NULL
;
4276 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
4277 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
,
4282 if (dock
->auto_expand_magic
) {
4283 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4284 dock
->auto_expand_magic
= NULL
;
4286 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
4287 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
4295 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4297 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4299 assert(event
->type
==LeaveNotify
);
4301 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4304 clipLeave(btn
->dock
);
4309 clipAutoCollapse(void *cdata
)
4311 WDock
*dock
= (WDock
*)cdata
;
4313 if (dock
->type
!=WM_CLIP
)
4316 if (dock
->auto_collapse
) {
4317 dock
->collapsed
= 1;
4318 wDockHideIcons(dock
);
4320 dock
->auto_collapse_magic
= NULL
;
4325 clipAutoExpand(void *cdata
)
4327 WDock
*dock
= (WDock
*)cdata
;
4329 if (dock
->type
!=WM_CLIP
)
4332 if (dock
->auto_collapse
) {
4333 dock
->collapsed
= 0;
4334 wDockShowIcons(dock
);
4336 dock
->auto_expand_magic
= NULL
;
4341 clipAutoLower(void *cdata
)
4343 WDock
*dock
= (WDock
*)cdata
;
4345 if (dock
->type
!=WM_CLIP
)
4348 if (dock
->auto_raise_lower
)
4351 dock
->auto_lower_magic
= NULL
;
4356 clipAutoRaise(void *cdata
)
4358 WDock
*dock
= (WDock
*)cdata
;
4360 if (dock
->type
!=WM_CLIP
)
4363 if (dock
->auto_raise_lower
)
4366 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4367 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4370 dock
->auto_raise_magic
= NULL
;
4375 iconCanBeOmnipresent(WAppIcon
*aicon
)
4377 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4382 for (i
=0; i
<scr
->workspace_count
; i
++) {
4383 clip
= scr
->workspaces
[i
]->clip
;
4385 if (clip
== aicon
->dock
)
4388 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4389 return False
; /* Clip is full in some workspace */
4391 for (j
=0; j
<clip
->max_icons
; j
++) {
4392 btn
= clip
->icon_array
[j
];
4393 if(btn
&& btn
->xindex
==aicon
->xindex
&& btn
->yindex
==aicon
->yindex
)
4403 wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
4405 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4406 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4407 int status
= WO_SUCCESS
;
4409 if ((scr
->dock
&& aicon
->dock
==scr
->dock
) || aicon
==scr
->clip_icon
) {
4410 return WO_NOT_APPLICABLE
;
4413 if (aicon
->omnipresent
== omnipresent
)
4417 if (iconCanBeOmnipresent(aicon
)) {
4418 aicon
->omnipresent
= 1;
4419 new_entry
= wmalloc(sizeof(WAppIconChain
));
4420 new_entry
->aicon
= aicon
;
4421 new_entry
->next
= scr
->global_icons
;
4422 scr
->global_icons
= new_entry
;
4423 scr
->global_icon_count
++;
4425 aicon
->omnipresent
= 0;
4429 aicon
->omnipresent
= 0;
4430 if (aicon
== scr
->global_icons
->aicon
) {
4431 tmp
= scr
->global_icons
->next
;
4432 free(scr
->global_icons
);
4433 scr
->global_icons
= tmp
;
4434 scr
->global_icon_count
--;
4436 tmp
= scr
->global_icons
;
4438 if (tmp
->next
->aicon
== aicon
) {
4439 tmp1
= tmp
->next
->next
;
4442 scr
->global_icon_count
--;
4450 wAppIconPaint(aicon
);