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"
63 /**** Local variables ****/
66 #define CLIP_FORWARD 2
69 /**** Global variables ****/
72 extern void DestroyDockAppSettingsPanel();
74 extern void ShowDockAppSettingsPanel(WAppIcon
*aicon
);
77 extern XContext wWinContext
;
79 extern Cursor wCursor
[WCUR_LAST
];
81 extern WPreferences wPreferences
;
83 extern XContext wWinContext
;
86 extern Atom _XA_DND_PROTOCOL
;
90 #define MOD_MASK wPreferences.modifier_mask
92 extern void appIconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
94 #define ICON_SIZE wPreferences.icon_size
97 /***** Local variables ****/
99 static proplist_t dCommand
=NULL
;
101 static proplist_t dDropCommand
=NULL
;
103 static proplist_t dAutoLaunch
, dName
, dForced
, dBuggyApplication
, dYes
, dNo
;
104 static proplist_t dHost
, dDock
, dClip
;
105 static proplist_t dAutoAttractIcons
, dKeepAttracted
;
107 static proplist_t dPosition
, dApplications
, dLowered
, dCollapsed
, dAutoCollapse
;
109 static proplist_t dAutoRaiseLower
, dOmnipresent
;
111 static void dockIconPaint(WAppIcon
*btn
);
113 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
115 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
);
117 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
119 static int getClipButton(int px
, int py
);
121 static void toggleLowered(WDock
*dock
);
123 static void toggleCollapsed(WDock
*dock
);
125 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
127 static void clipLeave(WDock
*dock
);
129 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
131 Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
);
133 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
134 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
135 static void clipAutoCollapse(void *cdata
);
136 static void clipAutoExpand(void *cdata
);
137 static void launchDockedApplication(WAppIcon
*btn
);
139 static void clipAutoLower(void *cdata
);
140 static void clipAutoRaise(void *cdata
);
142 static void showClipBalloon(WDock
*dock
, int workspace
);
158 #endif /* OFFIX_DND */
168 dCommand
= PLRetain(PLMakeString("Command"));
170 dDropCommand
= PLRetain(PLMakeString("DropCommand"));
172 dAutoLaunch
= PLRetain(PLMakeString("AutoLaunch"));
173 dName
= PLRetain(PLMakeString("Name"));
174 dForced
= PLRetain(PLMakeString("Forced"));
175 dBuggyApplication
= PLRetain(PLMakeString("BuggyApplication"));
176 dYes
= PLRetain(PLMakeString("Yes"));
177 dNo
= PLRetain(PLMakeString("No"));
178 dHost
= PLRetain(PLMakeString("Host"));
180 dPosition
= PLMakeString("Position");
181 dApplications
= PLMakeString("Applications");
182 dLowered
= PLMakeString("Lowered");
183 dCollapsed
= PLMakeString("Collapsed");
184 dAutoCollapse
= PLMakeString("AutoCollapse");
185 dAutoRaiseLower
= PLMakeString("AutoRaiseLower");
186 dAutoAttractIcons
= PLMakeString("AutoAttractIcons");
187 dKeepAttracted
= PLMakeString("KeepAttracted");
189 dOmnipresent
= PLMakeString("Omnipresent");
191 dDock
= PLMakeString("Dock");
192 dClip
= PLMakeString("Clip");
198 renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
200 WDock
*dock
= entry
->clientdata
;
205 assert(entry
->clientdata
!=NULL
);
207 wspace
= dock
->screen_ptr
->current_workspace
;
209 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
211 sprintf(buffer
, _("Type the name for workspace %i:"), wspace
+1);
212 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
,
214 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
223 toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
225 assert(entry
->clientdata
!=NULL
);
227 toggleLowered(entry
->clientdata
);
229 entry
->flags
.indicator_on
= !((WDock
*)entry
->clientdata
)->lowered
;
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 for (i
= 0; i
< WMGetBagItemCount(selectedIcons
); i
++) {
560 aicon
= WMGetFromBag(selectedIcons
, i
);
561 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
562 wDockDetach(dock
, aicon
);
564 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
565 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
566 aicon
->x_pos
, aicon
->y_pos
);
567 if (!dock
->mapped
|| dock
->collapsed
)
568 XMapWindow(dpy
, aicon
->icon
->core
->window
);
571 WMFreeBag(selectedIcons
);
573 if (wPreferences
.auto_arrange_icons
)
574 wArrangeIcons(dock
->screen_ptr
, True
);
579 keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
581 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
584 WMBag
*selectedIcons
;
587 assert(clickedIcon
!=NULL
);
588 dock
= clickedIcon
->dock
;
590 selectedIcons
= getSelected(dock
);
592 if (!WMGetBagItemCount(selectedIcons
)
593 && clickedIcon
!=dock
->screen_ptr
->clip_icon
) {
594 char *command
= NULL
;
596 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
597 clickedIcon
->editing
= 1;
598 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
599 _("Type the command used to launch the application"),
601 if (command
&& (command
[0]==0 ||
602 (command
[0]=='-' && command
[1]==0))) {
606 clickedIcon
->command
= command
;
607 clickedIcon
->editing
= 0;
609 clickedIcon
->editing
= 0;
612 WMFreeBag(selectedIcons
);
617 WMPutInBag(selectedIcons
, clickedIcon
);
620 for (i
= 0; i
< WMGetBagItemCount(selectedIcons
); i
++) {
621 aicon
= WMGetFromBag(selectedIcons
, i
);
622 if (aicon
->icon
->selected
)
623 wIconSelect(aicon
->icon
);
624 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
625 aicon
->attracted
= 0;
626 if (aicon
->icon
->shadowed
) {
627 aicon
->icon
->shadowed
= 0;
628 aicon
->icon
->force_paint
= 1;
629 wAppIconPaint(aicon
);
633 WMFreeBag(selectedIcons
);
640 toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
642 WDock
*dock
= (WDock
*)entry
->clientdata
;
644 assert(entry
->clientdata
!=NULL
);
646 dock
->attract_icons
= !dock
->attract_icons
;
647 /*if (!dock->attract_icons)
648 dock->keep_attracted = 0;*/
650 entry
->flags
.indicator_on
= dock
->attract_icons
;
657 toggleKeepCallback(WMenu
*menu
, WMenuEntry
*entry
)
659 WDock
*dock
= (WDock
*)entry
->clientdata
;
663 assert(entry
->clientdata
!=NULL
);
665 dock
->keep_attracted
= !dock
->keep_attracted
;
667 if (dock
->keep_attracted
) {
668 for (i
=0; i
< dock
->max_icons
; i
++) {
669 btn
= dock
->icon_array
[i
];
670 if (btn
&& btn
->attracted
&& btn
->command
) {
672 if (btn
->icon
->shadowed
) {
673 btn
->icon
->shadowed
= 0;
674 btn
->icon
->force_paint
= 1;
681 entry
->flags
.indicator_on
= dock
->keep_attracted
;
688 selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
690 WAppIcon
*icon
= (WAppIcon
*)entry
->clientdata
;
694 wIconSelect(icon
->icon
);
701 colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
703 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
706 int x
, y
, x_pos
, y_pos
;
708 assert(entry
->clientdata
!=NULL
);
709 clip
= clickedIcon
->dock
;
711 aicon
= clip
->screen_ptr
->app_icon_list
;
714 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
715 x_pos
= clip
->x_pos
+ x
*ICON_SIZE
;
716 y_pos
= clip
->y_pos
+ y
*ICON_SIZE
;
717 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
719 if (wPreferences
.no_animations
) {
720 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
722 SlideWindow(aicon
->icon
->core
->window
,
723 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
726 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
727 #endif /* ANIMATIONS */
729 aicon
->attracted
= 1;
730 if (!clip
->keep_attracted
&& !aicon
->icon
->shadowed
) {
731 aicon
->icon
->shadowed
= 1;
732 aicon
->icon
->force_paint
= 1;
733 /* We don't do an wAppIconPaint() here because it's in
734 * wDockAttachIcon(). -Dan
737 wDockAttachIcon(clip
, aicon
, x
, y
);
738 if (clip
->collapsed
|| !clip
->mapped
)
739 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
747 selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
749 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
751 WMBag
*selectedIcons
;
755 assert(clickedIcon
!=NULL
);
756 dock
= clickedIcon
->dock
;
758 selectedIcons
= getSelected(dock
);
760 if (!WMGetBagItemCount(selectedIcons
)) {
761 for (i
=1; i
<dock
->max_icons
; i
++) {
762 btn
= dock
->icon_array
[i
];
763 if (btn
&& !btn
->icon
->selected
) {
764 wIconSelect(btn
->icon
);
768 for (i
= 0; i
< WMGetBagItemCount(selectedIcons
); i
++) {
769 btn
= WMGetFromBag(selectedIcons
, i
);
770 wIconSelect(btn
->icon
);
773 WMFreeBag(selectedIcons
);
780 toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
782 assert(entry
->clientdata
!=NULL
);
784 toggleCollapsed(entry
->clientdata
);
786 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->collapsed
;
793 toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
796 assert(entry
->clientdata
!=NULL
);
798 dock
= (WDock
*) entry
->clientdata
;
800 dock
->auto_collapse
= !dock
->auto_collapse
;
802 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_collapse
;
809 toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
812 assert(entry
->clientdata
!=NULL
);
814 dock
= (WDock
*) entry
->clientdata
;
816 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
818 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_raise_lower
;
825 launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
827 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
829 launchDockedApplication(btn
);
834 settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
836 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
840 ShowDockAppSettingsPanel(btn
);
845 hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
848 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
850 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
852 if (wapp
->flags
.hidden
) {
853 wWorkspaceChange(btn
->icon
->core
->screen_ptr
,wapp
->last_workspace
);
854 wUnhideApplication(wapp
, False
, False
);
856 wHideApplication(wapp
);
862 unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
865 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
867 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
869 wUnhideApplication(wapp
, False
, True
);
874 mainIconCreate(WScreen
*scr
, int type
)
879 if (type
== WM_CLIP
) {
881 return scr
->clip_icon
;
882 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
883 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
884 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
885 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
886 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE;*/
889 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
890 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
896 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
897 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
898 btn
->icon
->core
->descriptor
.parent
= btn
;
899 /*ChangeStackingLevel(btn->icon->core, WMDockLevel);*/
900 XMapWindow(dpy
, btn
->icon
->core
->window
);
905 scr
->clip_icon
= btn
;
912 switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
914 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
915 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
917 WMBag
*selectedIcons
;
920 if (entry
->order
== scr
->current_workspace
)
923 dest
= scr
->workspaces
[entry
->order
]->clip
;
925 selectedIcons
= getSelected(src
);
927 if (WMGetBagItemCount(selectedIcons
)) {
929 for (i
= 0; i
< WMGetBagItemCount(selectedIcons
); i
++) {
930 btn
= WMGetFromBag(selectedIcons
, i
);
931 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
932 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
933 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
936 } else if (icon
!= scr
->clip_icon
) {
937 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
938 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
939 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
942 WMFreeBag(selectedIcons
);
948 launchDockedApplication(WAppIcon
*btn
)
950 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
952 if (!btn
->launching
&& btn
->command
!=NULL
) {
953 if (!btn
->forced_dock
) {
954 btn
->relaunching
= btn
->running
;
957 if (btn
->wm_instance
|| btn
->wm_class
) {
958 WWindowAttributes attr
;
959 memset(&attr
, 0, sizeof(WWindowAttributes
));
960 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
,
963 if (!attr
.no_appicon
&& !btn
->buggy_app
)
968 btn
->drop_launch
= 0;
969 scr
->last_dock
= btn
->dock
;
970 btn
->pid
= execCommand(btn
, btn
->command
, NULL
);
972 if (btn
->buggy_app
) {
973 /* give feedback that the app was launched */
977 WMAddTimerHandler(200, (WMCallback
*)dockIconPaint
, btn
);
982 wwarning(_("could not launch application %s\n"), btn
->command
);
984 if (!btn
->relaunching
)
993 updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
995 WScreen
*scr
= menu
->frame
->screen_ptr
;
996 char title
[MAX_WORKSPACENAME_WIDTH
+1];
1002 for (i
=0; i
<scr
->workspace_count
; i
++) {
1003 if (i
< menu
->entry_no
) {
1004 if (strcmp(menu
->entries
[i
]->text
,scr
->workspaces
[i
]->name
)!=0) {
1005 free(menu
->entries
[i
]->text
);
1006 strcpy(title
, scr
->workspaces
[i
]->name
);
1007 menu
->entries
[i
]->text
= wstrdup(title
);
1008 menu
->flags
.realized
= 0;
1010 menu
->entries
[i
]->clientdata
= (void*)icon
;
1012 strcpy(title
, scr
->workspaces
[i
]->name
);
1014 wMenuAddCallback(menu
, title
, switchWSCommand
, (void*)icon
);
1016 menu
->flags
.realized
= 0;
1018 if (i
== scr
->current_workspace
) {
1019 wMenuSetEnabled(menu
, i
, False
);
1021 wMenuSetEnabled(menu
, i
, True
);
1025 if (!menu
->flags
.realized
)
1031 makeWorkspaceMenu(WScreen
*scr
)
1035 menu
= wMenuCreate(scr
, NULL
, False
);
1037 wwarning(_("could not create workspace submenu for Clip menu"));
1039 wMenuAddCallback(menu
, "", switchWSCommand
, (void*)scr
->clip_icon
);
1041 menu
->flags
.realized
= 0;
1049 updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
1058 entry
= menu
->entries
[index
];
1059 entry
->flags
.indicator_on
= !dock
->lowered
;
1060 entry
->clientdata
= dock
;
1063 entry
= menu
->entries
[++index
];
1064 entry
->flags
.indicator_on
= dock
->collapsed
;
1065 entry
->clientdata
= dock
;
1068 entry
= menu
->entries
[++index
];
1069 entry
->flags
.indicator_on
= dock
->auto_collapse
;
1070 entry
->clientdata
= dock
;
1072 /* auto-raise/lower */
1073 entry
= menu
->entries
[++index
];
1074 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1075 entry
->clientdata
= dock
;
1078 entry
= menu
->entries
[++index
];
1079 entry
->flags
.indicator_on
= dock
->attract_icons
;
1080 entry
->clientdata
= dock
;
1082 /* keep attracted icons */
1083 entry
= menu
->entries
[++index
];
1084 entry
->flags
.indicator_on
= dock
->keep_attracted
;
1085 entry
->clientdata
= dock
;
1087 menu
->flags
.realized
= 0;
1093 makeClipOptionsMenu(WScreen
*scr
)
1098 menu
= wMenuCreate(scr
, NULL
, False
);
1100 wwarning(_("could not create options submenu for Clip menu"));
1104 entry
= wMenuAddCallback(menu
, _("Keep on Top"),
1105 toggleLoweredCallback
, NULL
);
1106 entry
->flags
.indicator
= 1;
1107 entry
->flags
.indicator_on
= 1;
1108 entry
->flags
.indicator_type
= MI_CHECK
;
1110 entry
= wMenuAddCallback(menu
, _("Collapsed"),
1111 toggleCollapsedCallback
, NULL
);
1112 entry
->flags
.indicator
= 1;
1113 entry
->flags
.indicator_on
= 1;
1114 entry
->flags
.indicator_type
= MI_CHECK
;
1116 entry
= wMenuAddCallback(menu
, _("AutoCollapse"),
1117 toggleAutoCollapseCallback
, NULL
);
1118 entry
->flags
.indicator
= 1;
1119 entry
->flags
.indicator_on
= 1;
1120 entry
->flags
.indicator_type
= MI_CHECK
;
1122 entry
= wMenuAddCallback(menu
, _("AutoRaiseLower"),
1123 toggleAutoRaiseLowerCallback
, NULL
);
1124 entry
->flags
.indicator
= 1;
1125 entry
->flags
.indicator_on
= 1;
1126 entry
->flags
.indicator_type
= MI_CHECK
;
1128 entry
= wMenuAddCallback(menu
, _("AutoAttract Icons"),
1129 toggleAutoAttractCallback
, NULL
);
1130 entry
->flags
.indicator
= 1;
1131 entry
->flags
.indicator_on
= 1;
1132 entry
->flags
.indicator_type
= MI_CHECK
;
1134 entry
= wMenuAddCallback(menu
, _("Keep Attracted Icons"),
1135 toggleKeepCallback
, NULL
);
1136 entry
->flags
.indicator
= 1;
1137 entry
->flags
.indicator_on
= 1;
1138 entry
->flags
.indicator_type
= MI_CHECK
;
1140 menu
->flags
.realized
= 0;
1148 dockMenuCreate(WScreen
*scr
, int type
)
1153 if (type
== WM_CLIP
&& scr
->clip_menu
)
1154 return scr
->clip_menu
;
1156 menu
= wMenuCreate(scr
, NULL
, False
);
1157 if (type
!= WM_CLIP
) {
1158 entry
= wMenuAddCallback(menu
, _("Keep on top"),
1159 toggleLoweredCallback
, NULL
);
1160 entry
->flags
.indicator
= 1;
1161 entry
->flags
.indicator_on
= 1;
1162 entry
->flags
.indicator_type
= MI_CHECK
;
1164 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1165 scr
->clip_options
= makeClipOptionsMenu(scr
);
1166 if (scr
->clip_options
)
1167 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1169 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
,
1172 entry
->text
= _("Rename Workspace");
1174 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1175 entry
->flags
.indicator
= 1;
1176 entry
->flags
.indicator_on
= 1;
1177 entry
->flags
.indicator_type
= MI_CHECK
;
1179 entry
= wMenuAddCallback(menu
, _("Select All Icons"),
1180 selectIconsCallback
, NULL
);
1182 entry
->text
= _("Select All Icons");
1184 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1186 entry
->text
= _("Keep Icon");
1188 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1190 entry
->text
= _("Move Icon To");
1191 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1192 if (scr
->clip_submenu
)
1193 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1195 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
,
1198 entry
->text
= _("Remove Icon");
1200 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1203 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1205 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1207 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1209 entry
->text
= _("Hide");
1211 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1213 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1215 if (type
== WM_CLIP
)
1216 scr
->clip_menu
= menu
;
1223 wDockCreate(WScreen
*scr
, int type
)
1231 dock
= wmalloc(sizeof(WDock
));
1232 memset(dock
, 0, sizeof(WDock
));
1234 if (type
== WM_CLIP
)
1235 icon_count
= CLIP_MAX_ICONS
;
1237 icon_count
= scr
->scr_height
/wPreferences
.icon_size
;
1239 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*)*icon_count
);
1240 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*)*icon_count
);
1242 dock
->max_icons
= icon_count
;
1244 btn
= mainIconCreate(scr
, type
);
1248 dock
->x_pos
= btn
->x_pos
;
1249 dock
->y_pos
= btn
->y_pos
;
1250 dock
->screen_ptr
= scr
;
1252 dock
->icon_count
= 1;
1253 dock
->on_right_side
= 1;
1254 dock
->collapsed
= 0;
1255 dock
->auto_collapse
= 0;
1256 dock
->auto_collapse_magic
= NULL
;
1257 dock
->auto_raise_lower
= 0;
1258 dock
->auto_lower_magic
= NULL
;
1259 dock
->auto_raise_magic
= NULL
;
1260 dock
->attract_icons
= 0;
1261 dock
->keep_attracted
= 0;
1263 dock
->icon_array
[0] = btn
;
1264 wRaiseFrame(btn
->icon
->core
);
1265 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1267 /* create dock menu */
1268 dock
->menu
= dockMenuCreate(scr
, type
);
1275 wDockDestroy(WDock
*dock
)
1280 for (i
=(dock
->type
== WM_CLIP
) ? 1 : 0; i
<dock
->max_icons
; i
++) {
1281 aicon
= dock
->icon_array
[i
];
1283 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1284 wDockDetach(dock
, aicon
);
1286 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
1287 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
1288 aicon
->x_pos
, aicon
->y_pos
);
1289 if (!dock
->mapped
|| dock
->collapsed
)
1290 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1294 if (wPreferences
.auto_arrange_icons
)
1295 wArrangeIcons(dock
->screen_ptr
, True
);
1296 free(dock
->icon_array
);
1297 if (dock
->menu
&& dock
->type
!=WM_CLIP
)
1298 wMenuDestroy(dock
->menu
, True
);
1304 wClipIconPaint(WAppIcon
*aicon
)
1306 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1307 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1309 Window win
= aicon
->icon
->core
->window
;
1310 int length
, nlength
;
1311 char *ws_name
, ws_number
[10];
1314 wIconPaint(aicon
->icon
);
1316 length
= strlen(workspace
->name
);
1317 ws_name
= malloc(length
+ 1);
1318 sprintf(ws_name
, "%s", workspace
->name
);
1319 sprintf(ws_number
, "%i", scr
->current_workspace
+ 1);
1320 nlength
= strlen(ws_number
);
1322 gc
= scr
->clip_title_gc
;
1324 if (!workspace
->clip
->collapsed
)
1325 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_NORMAL
]);
1327 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_COLLAPSED
]);
1329 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1331 tx
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
1333 WMDrawString(scr
->wmscreen
, win
, gc
, scr
->clip_title_font
, tx
,
1334 ty
, ws_name
, length
);
1336 tx
= (ICON_SIZE
/2 - WMWidthOfString(scr
->clip_title_font
, ws_number
,
1339 WMDrawString(scr
->wmscreen
, win
, gc
, scr
->clip_title_font
, tx
,
1340 2, ws_number
, nlength
);
1344 if (aicon
->launching
) {
1345 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1346 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1348 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
,
1349 aicon
->dock
->rclip_button_pushed
);
1354 clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1356 wClipIconPaint(desc
->parent
);
1361 dockIconPaint(WAppIcon
*btn
)
1363 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1364 wClipIconPaint(btn
);
1371 make_icon_state(WAppIcon
*btn
)
1373 proplist_t node
= NULL
;
1374 proplist_t command
, autolaunch
, name
, forced
, host
, position
, buggy
;
1375 proplist_t omnipresent
;
1381 command
= PLMakeString("-");
1383 command
= PLMakeString(btn
->command
);
1385 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1387 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1389 name
= PLMakeString(tmp
);
1393 forced
= btn
->forced_dock
? dYes
: dNo
;
1395 buggy
= btn
->buggy_app
? dYes
: dNo
;
1397 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1398 sprintf(buffer
, "%i,%i", btn
->x_pos
, btn
->y_pos
);
1400 sprintf(buffer
, "%hi,%hi", btn
->xindex
, btn
->yindex
);
1401 position
= PLMakeString(buffer
);
1403 node
= PLMakeDictionaryFromEntries(dCommand
, command
,
1405 dAutoLaunch
, autolaunch
,
1407 dBuggyApplication
, buggy
,
1408 dPosition
, position
,
1412 PLRelease(position
);
1414 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1415 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&&
1416 (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1417 PLInsertDictionaryEntry(node
, dOmnipresent
, omnipresent
);
1420 if (btn
->dnd_command
) {
1421 command
= PLMakeString(btn
->dnd_command
);
1422 PLInsertDictionaryEntry(node
, dDropCommand
, command
);
1425 #endif /* OFFIX_DND */
1427 if (btn
->client_machine
&& btn
->remote_start
) {
1428 host
= PLMakeString(btn
->client_machine
);
1429 PLInsertDictionaryEntry(node
, dHost
, host
);
1439 dockSaveState(WDock
*dock
)
1442 proplist_t icon_info
;
1443 proplist_t list
=NULL
, dock_state
=NULL
;
1444 proplist_t value
, key
;
1447 list
= PLMakeArrayFromElements(NULL
);
1449 for (i
=(dock
->type
==WM_DOCK
? 0 : 1); i
<dock
->max_icons
; i
++) {
1450 WAppIcon
*btn
= dock
->icon_array
[i
];
1452 if (!btn
|| (btn
->attracted
&& !dock
->keep_attracted
))
1455 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1456 list
= PLAppendArrayElement(list
, icon_info
);
1457 PLRelease(icon_info
);
1461 dock_state
= PLMakeDictionaryFromEntries(dApplications
, list
,
1464 if (dock
->type
== WM_DOCK
) {
1465 sprintf(buffer
, "Applications%i", dock
->screen_ptr
->scr_height
);
1466 key
= PLMakeString(buffer
);
1467 PLInsertDictionaryEntry(dock_state
, key
, list
);
1471 sprintf(buffer
, "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0),
1473 value
= PLMakeString(buffer
);
1474 PLInsertDictionaryEntry(dock_state
, dPosition
, value
);
1480 value
= (dock
->lowered
? dYes
: dNo
);
1481 PLInsertDictionaryEntry(dock_state
, dLowered
, value
);
1483 if (dock
->type
== WM_CLIP
) {
1484 value
= (dock
->collapsed
? dYes
: dNo
);
1485 PLInsertDictionaryEntry(dock_state
, dCollapsed
, value
);
1487 value
= (dock
->auto_collapse
? dYes
: dNo
);
1488 PLInsertDictionaryEntry(dock_state
, dAutoCollapse
, value
);
1490 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1491 PLInsertDictionaryEntry(dock_state
, dAutoRaiseLower
, value
);
1493 value
= (dock
->attract_icons
? dYes
: dNo
);
1494 PLInsertDictionaryEntry(dock_state
, dAutoAttractIcons
, value
);
1496 value
= (dock
->keep_attracted
? dYes
: dNo
);
1497 PLInsertDictionaryEntry(dock_state
, dKeepAttracted
, value
);
1505 wDockSaveState(WScreen
*scr
, proplist_t old_state
)
1507 proplist_t dock_state
;
1510 dock_state
= dockSaveState(scr
->dock
);
1513 * Copy saved states of docks with different sizes.
1519 keys
= PLGetAllDictionaryKeys(old_state
);
1520 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
1521 tmp
= PLGetArrayElement(keys
, i
);
1523 if (strncasecmp(PLGetString(tmp
), "applications", 12) == 0
1524 && !PLGetDictionaryEntry(dock_state
, tmp
)) {
1526 PLInsertDictionaryEntry(dock_state
,
1528 PLGetDictionaryEntry(old_state
, tmp
));
1535 PLInsertDictionaryEntry(scr
->session_state
, dDock
, dock_state
);
1537 PLRelease(dock_state
);
1542 wClipSaveState(WScreen
*scr
)
1544 proplist_t clip_state
;
1546 clip_state
= make_icon_state(scr
->clip_icon
);
1548 PLInsertDictionaryEntry(scr
->session_state
, dClip
, clip_state
);
1550 PLRelease(clip_state
);
1555 wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1557 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1562 restore_icon_state(WScreen
*scr
, proplist_t info
, int type
, int index
)
1565 char *wclass
, *winstance
;
1566 proplist_t cmd
, value
;
1570 cmd
= PLGetDictionaryEntry(info
, dCommand
);
1571 if (!cmd
|| !PLIsString(cmd
)) {
1575 /* parse window name */
1576 value
= PLGetDictionaryEntry(info
, dName
);
1580 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1582 if (!winstance
&& !wclass
) {
1589 command
= wstrdup(PLGetString(cmd
));
1593 if (!command
|| strcmp(command
, "-")==0) {
1604 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
,
1611 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1612 if (type
== WM_CLIP
) {
1613 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1614 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1616 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1617 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1621 cmd
= PLGetDictionaryEntry(info
, dDropCommand
);
1623 aicon
->dnd_command
= wstrdup(PLGetString(cmd
));
1626 /* check auto launch */
1627 value
= PLGetDictionaryEntry(info
, dAutoLaunch
);
1629 aicon
->auto_launch
= 0;
1631 if (PLIsString(value
)) {
1632 if (strcasecmp(PLGetString(value
), "YES")==0)
1633 aicon
->auto_launch
= 1;
1635 wwarning(_("bad value in docked icon state info %s"),
1636 PLGetString(dAutoLaunch
));
1640 /* check if it wasn't normally docked */
1641 value
= PLGetDictionaryEntry(info
, dForced
);
1643 aicon
->forced_dock
= 0;
1645 if (PLIsString(value
)) {
1646 if (strcasecmp(PLGetString(value
), "YES")==0)
1647 aicon
->forced_dock
= 1;
1649 wwarning(_("bad value in docked icon state info %s"),
1650 PLGetString(dForced
));
1654 /* check if we can rely on the stuff in the app */
1655 value
= PLGetDictionaryEntry(info
, dBuggyApplication
);
1657 aicon
->buggy_app
= 0;
1659 if (PLIsString(value
)) {
1660 if (strcasecmp(PLGetString(value
), "YES")==0)
1661 aicon
->buggy_app
= 1;
1663 wwarning(_("bad value in docked icon state info %s"),
1664 PLGetString(dBuggyApplication
));
1668 /* get position in the dock */
1669 value
= PLGetDictionaryEntry(info
, dPosition
);
1670 if (value
&& PLIsString(value
)) {
1671 if (sscanf(PLGetString(value
), "%hi,%hi", &aicon
->xindex
,
1673 wwarning(_("bad value in docked icon state info %s"),
1674 PLGetString(dPosition
));
1676 /* check position sanity */
1677 /* incomplete section! */
1678 if (type
== WM_DOCK
) {
1680 if (aicon
->yindex
< 0)
1681 wwarning(_("bad value in docked icon position %i,%i"),
1682 aicon
->xindex
, aicon
->yindex
);
1685 aicon
->yindex
= index
;
1689 /* check if icon is omnipresent */
1690 value
= PLGetDictionaryEntry(info
, dOmnipresent
);
1692 aicon
->omnipresent
= 0;
1694 if (PLIsString(value
)) {
1695 if (strcasecmp(PLGetString(value
), "YES")==0)
1696 aicon
->omnipresent
= 1;
1698 wwarning(_("bad value in docked icon state info %s"),
1699 PLGetString(dOmnipresent
));
1710 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1714 wClipRestoreState(WScreen
*scr
, proplist_t clip_state
)
1720 icon
= mainIconCreate(scr
, WM_CLIP
);
1725 PLRetain(clip_state
);
1727 /* restore position */
1729 value
= PLGetDictionaryEntry(clip_state
, dPosition
);
1732 if (!PLIsString(value
))
1733 COMPLAIN("Position");
1735 if (sscanf(PLGetString(value
), "%i,%i", &icon
->x_pos
,
1737 COMPLAIN("Position");
1739 /* check position sanity */
1740 if (icon
->y_pos
< 0)
1742 else if (icon
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1743 icon
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1745 if (icon
->x_pos
< 0)
1747 else if (icon
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1748 icon
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1753 value
= PLGetDictionaryEntry(clip_state
, dDropCommand
);
1754 if (value
&& PLIsString(value
))
1755 icon
->dnd_command
= wstrdup(PLGetString(value
));
1758 PLRelease(clip_state
);
1765 wDockRestoreState(WScreen
*scr
, proplist_t dock_state
, int type
)
1770 WAppIcon
*aicon
, *old_top
;
1774 dock
= wDockCreate(scr
, type
);
1780 PLRetain(dock_state
);
1783 /* restore position */
1785 value
= PLGetDictionaryEntry(dock_state
, dPosition
);
1788 if (!PLIsString(value
))
1789 COMPLAIN("Position");
1791 if (sscanf(PLGetString(value
), "%i,%i", &dock
->x_pos
,
1793 COMPLAIN("Position");
1795 /* check position sanity */
1796 if (dock
->y_pos
< 0)
1798 else if (dock
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1799 dock
->y_pos
= scr
->scr_height
- ICON_SIZE
;
1801 /* This is no more needed. ??? */
1802 if (type
== WM_CLIP
) {
1803 if (dock
->x_pos
< 0)
1805 else if (dock
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1806 dock
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1808 if (dock
->x_pos
>= 0) {
1809 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1810 dock
->on_right_side
= 0;
1812 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1813 dock
->on_right_side
= 1;
1819 /* restore lowered/raised state */
1823 value
= PLGetDictionaryEntry(dock_state
, dLowered
);
1826 if (!PLIsString(value
))
1827 COMPLAIN("Lowered");
1829 if (strcasecmp(PLGetString(value
), "YES")==0)
1835 /* restore collapsed state */
1837 dock
->collapsed
= 0;
1839 value
= PLGetDictionaryEntry(dock_state
, dCollapsed
);
1842 if (!PLIsString(value
))
1843 COMPLAIN("Collapsed");
1845 if (strcasecmp(PLGetString(value
), "YES")==0)
1846 dock
->collapsed
= 1;
1851 /* restore auto-collapsed state */
1853 value
= PLGetDictionaryEntry(dock_state
, dAutoCollapse
);
1856 if (!PLIsString(value
))
1857 COMPLAIN("AutoCollapse");
1859 if (strcasecmp(PLGetString(value
), "YES")==0) {
1860 dock
->auto_collapse
= 1;
1861 dock
->collapsed
= 1;
1867 /* restore auto-raise/lower state */
1869 value
= PLGetDictionaryEntry(dock_state
, dAutoRaiseLower
);
1872 if (!PLIsString(value
))
1873 COMPLAIN("AutoRaiseLower");
1875 if (strcasecmp(PLGetString(value
), "YES")==0) {
1876 dock
->auto_raise_lower
= 1;
1881 /* restore attract icons state */
1883 dock
->attract_icons
= 0;
1885 value
= PLGetDictionaryEntry(dock_state
, dAutoAttractIcons
);
1888 if (!PLIsString(value
))
1889 COMPLAIN("AutoAttractIcons");
1891 if (strcasecmp(PLGetString(value
), "YES")==0)
1892 dock
->attract_icons
= 1;
1897 /* restore keep attracted icons state */
1899 dock
->keep_attracted
= 0;
1901 value
= PLGetDictionaryEntry(dock_state
, dKeepAttracted
);
1904 if (!PLIsString(value
))
1905 COMPLAIN("KeepAttracted");
1907 if (strcasecmp(PLGetString(value
), "YES")==0)
1908 dock
->keep_attracted
= 1;
1913 /* application list */
1920 * When saving, it saves the dock state in
1921 * Applications and Applicationsnnn
1923 * When loading, it will first try Applicationsnnn.
1924 * If it does not exist, use Applications as default.
1927 sprintf(buffer
, "Applications%i", scr
->scr_height
);
1929 tmp
= PLMakeString(buffer
);
1930 apps
= PLGetDictionaryEntry(dock_state
, tmp
);
1934 apps
= PLGetDictionaryEntry(dock_state
, dApplications
);
1942 count
= PLGetNumberOfElements(apps
);
1947 old_top
= dock
->icon_array
[0];
1949 /* dock->icon_count is set to 1 when dock is created.
1950 * Since Clip is already restored, we want to keep it so for clip,
1951 * but for dock we may change the default top tile, so we set it to 0.
1953 if (type
== WM_DOCK
)
1954 dock
->icon_count
= 0;
1956 for (i
=0; i
<count
; i
++) {
1957 if (dock
->icon_count
>= dock
->max_icons
) {
1958 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1962 value
= PLGetArrayElement(apps
, i
);
1963 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1965 dock
->icon_array
[dock
->icon_count
] = aicon
;
1969 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
*ICON_SIZE
);
1970 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
*ICON_SIZE
);
1973 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1975 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1977 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
,
1980 if (!dock
->collapsed
)
1981 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1982 wRaiseFrame(aicon
->icon
->core
);
1985 } else if (dock
->icon_count
==0 && type
==WM_DOCK
)
1989 /* if the first icon is not defined, use the default */
1990 if (dock
->icon_array
[0]==NULL
) {
1991 /* update default icon */
1992 old_top
->x_pos
= dock
->x_pos
;
1993 old_top
->y_pos
= dock
->y_pos
;
1995 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1997 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1998 dock
->icon_array
[0] = old_top
;
1999 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
2000 /* we don't need to increment dock->icon_count here because it was
2001 * incremented in the loop above.
2003 } else if (old_top
!=dock
->icon_array
[0]) {
2004 if (old_top
== scr
->clip_icon
)
2005 scr
->clip_icon
= dock
->icon_array
[0];
2006 wAppIconDestroy(old_top
);
2011 PLRelease(dock_state
);
2019 wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
2021 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
2023 btn
->drop_launch
= 0;
2025 btn
->pid
= execCommand(btn
, btn
->command
, state
);
2028 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
2040 wDockDoAutoLaunch(WDock
*dock
, int workspace
)
2046 for (i
= 0; i
< dock
->max_icons
; i
++) {
2047 btn
= dock
->icon_array
[i
];
2048 if (!btn
|| !btn
->auto_launch
)
2051 state
= wmalloc(sizeof(WSavedState
));
2052 memset(state
, 0, sizeof(WSavedState
));
2053 state
->workspace
= workspace
;
2054 /* TODO: this is klugy and is very difficult to understand
2055 * what's going on. Try to clean up */
2056 wDockLaunchWithState(dock
, btn
, state
);
2060 #ifdef REDUCE_APPICONS
2062 wDockSimulateLaunch(WDock
*dock
, WAppIcon
*btn
)
2064 if ((btn
== NULL
) || (dock
== NULL
))
2067 if (!btn
->running
) {
2068 if ((btn
->icon
->owner
== NULL
) && (btn
->applist
))
2069 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
2070 if (!btn
->forced_dock
)
2080 findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
2086 if ((dock
= scr
->dock
)!=NULL
) {
2087 for (i
=0; i
<dock
->max_icons
; i
++) {
2088 if (dock
->icon_array
[i
]
2089 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
2095 if (*icon_pos
<0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
)!=NULL
) {
2096 for (i
=0; i
<dock
->max_icons
; i
++) {
2097 if (dock
->icon_array
[i
]
2098 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
2111 wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
2117 dock
= findDock(scr
, event
, &icon_pos
);
2122 * Return True if the drop was on an application icon window.
2123 * In this case, let the ClientMessage handler redirect the
2124 * message to the app.
2126 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!=None
)
2129 if (dock
->icon_array
[icon_pos
]->dnd_command
!=NULL
) {
2130 scr
->flags
.dnd_data_convertion_status
= 0;
2132 btn
= dock
->icon_array
[icon_pos
];
2134 if (!btn
->forced_dock
) {
2135 btn
->relaunching
= btn
->running
;
2138 if (btn
->wm_instance
|| btn
->wm_class
) {
2139 WWindowAttributes attr
;
2140 memset(&attr
, 0, sizeof(WWindowAttributes
));
2141 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
2143 btn
->wm_class
, &attr
, NULL
, True
);
2145 if (!attr
.no_appicon
)
2151 btn
->drop_launch
= 1;
2152 scr
->last_dock
= dock
;
2153 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
2158 if (!btn
->relaunching
) {
2165 #endif /* OFFIX_DND */
2170 wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2177 wwin
= icon
->icon
->owner
;
2178 if (icon
->command
==NULL
) {
2180 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2182 icon
->command
= FlattenStringList(argv
, argc
);
2183 XFreeStringList(argv
);
2187 /* icon->forced_dock = 1;*/
2188 if (!icon
->attracted
|| dock
->type
!=WM_CLIP
|| dock
->keep_attracted
) {
2190 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2191 _("Type the command used to launch the application"),
2193 if (command
&& (command
[0]==0 ||
2194 (command
[0]=='-' && command
[1]==0))) {
2198 icon
->command
= command
;
2204 /* If the target is the dock, reject the icon. If
2205 * the target is the clip, make it an attracted icon
2207 if (dock
->type
==WM_CLIP
) {
2208 icon
->attracted
= 1;
2209 if (!icon
->icon
->shadowed
) {
2210 icon
->icon
->shadowed
= 1;
2211 icon
->icon
->force_paint
= 1;
2223 for (index
=1; index
<dock
->max_icons
; index
++)
2224 if (dock
->icon_array
[index
] == NULL
)
2226 /* if (index == dock->max_icons)
2229 assert(index
< dock
->max_icons
);
2231 dock
->icon_array
[index
] = icon
;
2235 icon
->omnipresent
= 0;
2237 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2238 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2243 icon
->launching
= 0;
2246 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2247 if (dock
->type
== WM_CLIP
) {
2248 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2249 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2251 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2252 icon
->icon
->core
->descriptor
.parent
= icon
;
2254 MoveInStackListUnder(dock
->icon_array
[index
-1]->icon
->core
,
2256 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2257 wAppIconPaint(icon
);
2259 if (wPreferences
.auto_arrange_icons
)
2260 wArrangeIcons(dock
->screen_ptr
, True
);
2263 if (icon
->command
&& !icon
->dnd_command
) {
2264 icon
->dnd_command
= wmalloc(strlen(icon
->command
)+8);
2265 sprintf(icon
->dnd_command
, "%s %%d", icon
->command
);
2274 reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2278 for(index
=1; index
<dock
->max_icons
; index
++) {
2279 if(dock
->icon_array
[index
] == icon
)
2282 assert(index
< dock
->max_icons
);
2287 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2288 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2293 moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2301 return True
; /* No move needed, we're already there */
2306 wwin
= icon
->icon
->owner
;
2309 * For the moment we can't do this if we move icons in Clip from one
2310 * workspace to other, because if we move two or more icons without
2311 * command, the dialog box will not be able to tell us to which of the
2312 * moved icons it applies. -Dan
2314 if ((dest
->type
==WM_DOCK
/*|| dest->keep_attracted*/) && icon
->command
==NULL
) {
2315 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2317 icon
->command
= FlattenStringList(argv
, argc
);
2318 XFreeStringList(argv
);
2323 /* icon->forced_dock = 1;*/
2324 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2325 _("Type the command used to launch the application"),
2327 if (command
&& (command
[0]==0 ||
2328 (command
[0]=='-' && command
[1]==0))) {
2332 icon
->command
= command
;
2343 if (dest
->type
== WM_DOCK
)
2344 wClipMakeIconOmnipresent(icon
, False
);
2346 for(index
=1; index
<src
->max_icons
; index
++) {
2347 if(src
->icon_array
[index
] == icon
)
2350 assert(index
< src
->max_icons
);
2352 src
->icon_array
[index
] = NULL
;
2355 for(index
=1; index
<dest
->max_icons
; index
++) {
2356 if(dest
->icon_array
[index
] == NULL
)
2359 /* if (index == dest->max_icons)
2362 assert(index
< dest
->max_icons
);
2364 dest
->icon_array
[index
] = icon
;
2367 /* deselect the icon */
2368 if (icon
->icon
->selected
)
2369 wIconSelect(icon
->icon
);
2371 if (dest
->type
== WM_DOCK
) {
2372 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2373 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2375 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2376 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2379 /* set it to be kept when moving to dock, or to a clip that keep the
2381 * Unless the icon does not have a command set
2383 if (icon
->command
&& (dest
->type
==WM_DOCK
|| dest
->keep_attracted
)) {
2384 icon
->attracted
= 0;
2385 if (icon
->icon
->shadowed
) {
2386 icon
->icon
->shadowed
= 0;
2387 icon
->icon
->force_paint
= 1;
2391 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2397 icon
->x_pos
= dest
->x_pos
+ x
*ICON_SIZE
;
2398 icon
->y_pos
= dest
->y_pos
+ y
*ICON_SIZE
;
2402 MoveInStackListUnder(dest
->icon_array
[index
-1]->icon
->core
,
2404 wAppIconPaint(icon
);
2411 wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2415 /* make the settings panel be closed */
2417 DestroyDockAppSettingsPanel(icon
->panel
);
2420 /* This must be called before icon->dock is set to NULL.
2421 * Don't move it. -Dan
2423 wClipMakeIconOmnipresent(icon
, False
);
2427 icon
->attracted
= 0;
2428 if (icon
->icon
->shadowed
) {
2429 icon
->icon
->shadowed
= 0;
2430 icon
->icon
->force_paint
= 1;
2433 /* deselect the icon */
2434 if (icon
->icon
->selected
)
2435 wIconSelect(icon
->icon
);
2437 if (icon
->command
) {
2438 free(icon
->command
);
2439 icon
->command
= NULL
;
2442 if (icon
->dnd_command
) {
2443 free(icon
->dnd_command
);
2444 icon
->dnd_command
= NULL
;
2448 for (index
=1; index
<dock
->max_icons
; index
++)
2449 if (dock
->icon_array
[index
] == icon
)
2451 assert(index
< dock
->max_icons
);
2452 dock
->icon_array
[index
] = NULL
;
2458 /* if the dock is not attached to an application or
2459 * the the application did not set the approriate hints yet,
2460 * destroy the icon */
2461 #ifdef REDUCE_APPICONS
2462 if ((icon
->num_apps
== 0) && (!icon
->running
|| !wApplicationOf(icon
->main_window
)) )
2464 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2466 wAppIconDestroy(icon
);
2468 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2469 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2470 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2471 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2472 icon
->icon
->core
->descriptor
.parent
= icon
;
2474 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2476 wAppIconPaint(icon
);
2477 if (wPreferences
.auto_arrange_icons
) {
2478 wArrangeIcons(dock
->screen_ptr
, True
);
2481 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2487 * returns the closest Dock slot index for the passed
2490 * Returns False if icon can't be docked.
2492 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2496 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2497 int *ret_x
, int *ret_y
, int redocking
)
2499 WScreen
*scr
= dock
->screen_ptr
;
2502 int i
, offset
= ICON_SIZE
/2;
2503 WAppIcon
*aicon
= NULL
;
2504 WAppIcon
*nicon
= NULL
;
2505 int max_y_icons
, max_x_icons
;
2507 max_x_icons
= scr
->scr_width
/ICON_SIZE
;
2508 max_y_icons
= scr
->scr_height
/ICON_SIZE
-1;
2510 if (wPreferences
.flags
.noupdates
)
2516 /* if the dock is full */
2518 (dock
->icon_count
>= dock
->max_icons
)) {
2522 /* exact position */
2524 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2526 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2529 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2531 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2533 /* check if the icon is outside the screen boundaries */
2534 if (dx
+ ex_x
*ICON_SIZE
< -ICON_SIZE
+2 ||
2535 dx
+ ex_x
*ICON_SIZE
>= scr
->scr_width
-1 ||
2536 dy
+ ex_y
*ICON_SIZE
< -ICON_SIZE
+2 ||
2537 dy
+ ex_y
*ICON_SIZE
>= scr
->scr_height
-1)
2540 if (dock
->type
== WM_DOCK
) {
2541 if (icon
->dock
!= dock
&& ex_x
!= 0)
2545 for (i
=0; i
<dock
->max_icons
; i
++) {
2546 nicon
= dock
->icon_array
[i
];
2547 if (nicon
&& nicon
->yindex
== ex_y
) {
2554 int sig
, done
, closest
;
2556 /* Possible cases when redocking:
2558 * icon dragged out of range of any slot -> false
2559 * icon dragged to range of free slot
2560 * icon dragged to range of same slot
2561 * icon dragged to range of different icon
2563 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2566 if (ex_y
>=0 && ex_y
<=max_y_icons
&& (aicon
==icon
|| !aicon
)) {
2572 /* start looking at the upper slot or lower? */
2573 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2580 /* look for closest free slot */
2581 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2585 closest
= sig
*(i
/2) + ex_y
;
2586 /* check if this slot is used */
2588 for (j
= 0; j
<dock
->max_icons
; j
++) {
2589 if (dock
->icon_array
[j
]
2590 && dock
->icon_array
[j
]->yindex
==closest
) {
2591 /* slot is used by someone else */
2592 if (dock
->icon_array
[j
]!=icon
)
2600 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2601 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2603 (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+1))) {
2608 } else { /* !redocking */
2610 /* if slot is free and the icon is close enough, return it */
2611 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2621 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2622 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+1;
2625 for (k
=start
; k
<stop
; k
++) {
2626 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2629 for (i
=0; i
<tmp
->max_icons
; i
++) {
2630 nicon
= tmp
->icon_array
[i
];
2631 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2639 for (k
=start
; k
<stop
; k
++) {
2640 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2643 for (i
=0; i
<tmp
->max_icons
; i
++) {
2644 nicon
= tmp
->icon_array
[i
];
2645 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2646 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2647 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2656 if (neighbours
&& (aicon
==NULL
|| (redocking
&& aicon
== icon
))) {
2665 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2666 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2668 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2669 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2670 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2674 * returns true if it can find a free slot in the dock,
2675 * in which case it changes x_pos and y_pos accordingly.
2676 * Else returns false.
2679 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2681 WScreen
*scr
= dock
->screen_ptr
;
2683 WAppIconChain
*chain
;
2684 unsigned char *slot_map
;
2688 int i
, done
= False
;
2690 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2693 if (dock
->type
== WM_CLIP
&&
2694 dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2695 extra_count
= scr
->global_icon_count
;
2697 /* if the dock is full */
2698 if (dock
->icon_count
+extra_count
>= dock
->max_icons
) {
2702 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2703 if (scr
->dock
->on_right_side
)
2704 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2706 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2709 if (ex
< dock
->x_pos
)
2711 if (sx
> dock
->x_pos
+ICON_SIZE
)
2712 sx
= dock
->x_pos
+ICON_SIZE
;
2719 /* check if clip is in a corner */
2720 if (dock
->type
==WM_CLIP
) {
2721 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2723 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2725 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2727 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2734 /* If the clip is in the corner, use only slots that are in the border
2736 if (corner
!=C_NONE
) {
2740 hcount
= MIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2741 vcount
= MIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2742 hmap
= wmalloc(hcount
+1);
2743 memset(hmap
, 0, hcount
+1);
2744 vmap
= wmalloc(vcount
+1);
2745 memset(vmap
, 0, vcount
+1);
2747 /* mark used positions */
2750 for (i
=0; i
<dock
->max_icons
; i
++) {
2751 btn
= dock
->icon_array
[i
];
2755 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2756 vmap
[btn
->yindex
] = 1;
2757 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2758 hmap
[btn
->xindex
] = 1;
2760 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2762 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2763 vmap
[btn
->yindex
] = 1;
2764 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2765 hmap
[btn
->xindex
] = 1;
2769 for (i
=0; i
<dock
->max_icons
; i
++) {
2770 btn
= dock
->icon_array
[i
];
2774 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2775 vmap
[btn
->yindex
] = 1;
2776 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2777 hmap
[-btn
->xindex
] = 1;
2779 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2781 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2782 vmap
[btn
->yindex
] = 1;
2783 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2784 hmap
[-btn
->xindex
] = 1;
2788 for (i
=0; i
<dock
->max_icons
; i
++) {
2789 btn
= dock
->icon_array
[i
];
2793 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2794 vmap
[-btn
->yindex
] = 1;
2795 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2796 hmap
[btn
->xindex
] = 1;
2798 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2800 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2801 vmap
[-btn
->yindex
] = 1;
2802 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2803 hmap
[btn
->xindex
] = 1;
2808 for (i
=0; i
<dock
->max_icons
; i
++) {
2809 btn
= dock
->icon_array
[i
];
2813 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2814 vmap
[-btn
->yindex
] = 1;
2815 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2816 hmap
[-btn
->xindex
] = 1;
2818 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2820 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2821 vmap
[-btn
->yindex
] = 1;
2822 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2823 hmap
[-btn
->xindex
] = 1;
2828 /* search a vacant slot */
2829 for (i
=1; i
<MAX(vcount
, hcount
); i
++) {
2830 if (i
< vcount
&& vmap
[i
]==0) {
2836 } else if (i
< hcount
&& hmap
[i
]==0) {
2846 /* If found a slot, translate and return */
2848 if (corner
==C_NW
|| corner
==C_NE
) {
2853 if (corner
==C_NE
|| corner
==C_SE
) {
2860 /* else, try to find a slot somewhere else */
2863 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2864 * placed outside of screen */
2865 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2867 /* In the worst case (the clip is in the corner of the screen),
2868 * the amount of icons that fit in the clip is smaller.
2869 * Double the map to get a safe value.
2875 slot_map
= wmalloc(mwidth
*mwidth
);
2876 memset(slot_map
, 0, mwidth
*mwidth
);
2878 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2880 /* mark used slots in the map. If the slot falls outside the map
2881 * (for example, when all icons are placed in line), ignore them. */
2882 for (i
=0; i
<dock
->max_icons
; i
++) {
2883 btn
= dock
->icon_array
[i
];
2885 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2887 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2888 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2890 /* Find closest slot from the center that is free by scanning the
2891 * map from the center to outward in circular passes.
2892 * This will not result in a neat layout, but will be optimal
2893 * in the sense that there will not be holes left.
2896 for (i
= 1; i
<= r
&& !done
; i
++) {
2899 /* top and bottom parts of the ring */
2900 for (x
= -i
; x
<= i
&& !done
; x
++) {
2901 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2903 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2904 if (slot_map
[XY2OFS(x
,y
)]==0
2905 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2912 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2913 if (slot_map
[XY2OFS(x
,y
)]==0
2914 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2921 /* left and right parts of the ring */
2922 for (y
= -i
+1; y
<= i
-1; y
++) {
2923 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2925 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2926 if (slot_map
[XY2OFS(x
,y
)]==0
2927 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2934 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2935 if (slot_map
[XY2OFS(x
,y
)]==0
2936 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2951 moveDock(WDock
*dock
, int new_x
, int new_y
)
2956 dock
->x_pos
= new_x
;
2957 dock
->y_pos
= new_y
;
2958 for (i
=0; i
<dock
->max_icons
; i
++) {
2959 btn
= dock
->icon_array
[i
];
2961 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2962 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2963 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2970 swapDock(WDock
*dock
)
2972 WScreen
*scr
= dock
->screen_ptr
;
2977 if (dock
->on_right_side
) {
2978 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2980 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2983 for (i
=0; i
<dock
->max_icons
; i
++) {
2984 btn
= dock
->icon_array
[i
];
2987 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2991 wScreenUpdateUsableArea(scr
);
2996 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2998 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
3004 cmdline
= ExpandOptions(scr
, command
);
3006 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
3014 ParseCommand(cmdline
, &argv
, &argc
);
3024 if ((pid
=fork())==0) {
3028 SetupEnvironment(scr
);
3034 args
= malloc(sizeof(char*)*(argc
+1));
3037 for (i
=0; i
<argc
; i
++) {
3041 execvp(argv
[0], args
);
3050 state
= wmalloc(sizeof(WSavedState
));
3051 memset(state
, 0, sizeof(WSavedState
));
3053 state
->miniaturized
= -1;
3055 if (btn
->dock
==scr
->dock
|| btn
->omnipresent
)
3056 state
->workspace
= -1;
3058 state
->workspace
= scr
->current_workspace
;
3060 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
3062 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
3073 wDockHideIcons(WDock
*dock
)
3080 for (i
=1; i
<dock
->max_icons
; i
++) {
3081 if (dock
->icon_array
[i
])
3082 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3086 dockIconPaint(dock
->icon_array
[0]);
3091 wDockShowIcons(WDock
*dock
)
3099 btn
= dock
->icon_array
[0];
3100 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
3102 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
3103 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
3105 for (i
=1; i
<dock
->max_icons
; i
++) {
3106 if (dock
->icon_array
[i
]) {
3107 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
3113 if (!dock
->collapsed
) {
3114 for (i
=1; i
<dock
->max_icons
; i
++) {
3115 if (dock
->icon_array
[i
]) {
3116 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3127 wDockLower(WDock
*dock
)
3131 for (i
=0; i
<dock
->max_icons
; i
++) {
3132 if (dock
->icon_array
[i
])
3133 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
3139 wDockRaise(WDock
*dock
)
3143 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
3144 if (dock
->icon_array
[i
])
3145 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
3151 wDockRaiseLower(WDock
*dock
)
3153 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
3154 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
3155 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
3163 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
3165 icon
->launching
= 0;
3166 icon
->relaunching
= 0;
3167 dockIconPaint(icon
);
3172 wDockFindIconFor(WDock
*dock
, Window window
)
3177 for (i
=0; i
<dock
->max_icons
; i
++) {
3178 icon
= dock
->icon_array
[i
];
3179 if (icon
&& icon
->main_window
== window
)
3187 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
3190 #ifdef REDUCE_APPICONS
3191 WAppIconAppList
*tapplist
;
3193 char *wm_class
, *wm_instance
;
3195 Bool firstPass
= True
;
3197 char *command
= NULL
;
3203 if (XGetCommand(dpy
, window
, &argv
, &argc
)) {
3204 if (argc
> 0 && argv
!= NULL
)
3205 command
= FlattenStringList(argv
,argc
);
3207 XFreeStringList(argv
);
3212 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
3213 (!wm_class
&& !wm_instance
))
3217 for (i
=0; i
<dock
->max_icons
; i
++) {
3218 icon
= dock
->icon_array
[i
];
3222 /* app is already attached to icon */
3223 if (icon
->main_window
== window
) {
3228 if ((icon
->wm_instance
|| icon
->wm_class
)
3230 || (dock
->screen_ptr
->flags
.startup
&& !icon
->running
))) {
3232 if (icon
->wm_instance
&& wm_instance
&&
3233 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
3236 if (icon
->wm_class
&& wm_class
&&
3237 strcmp(icon
->wm_class
, wm_class
)!=0) {
3240 if (firstPass
&& command
&& strcmp(icon
->command
, command
)!=0) {
3244 if (!icon
->relaunching
) {
3247 /* Possibly an application that was docked with dockit,
3248 * but the user did not update WMState to indicate that
3249 * it was docked by force */
3250 wapp
= wApplicationOf(window
);
3252 icon
->forced_dock
= 1;
3255 if (!icon
->forced_dock
)
3256 icon
->main_window
= window
;
3258 #ifdef REDUCE_APPICONS
3259 tapplist
= wmalloc(sizeof(WAppIconAppList
));
3260 memset(tapplist
, 0, sizeof(WAppIconAppList
));
3261 tapplist
->next
= icon
->applist
;
3263 icon
->applist
->prev
= tapplist
;
3264 icon
->applist
= tapplist
;
3265 tapplist
->wapp
= wApplicationOf(window
);
3270 wDockFinishLaunch(dock
, icon
);
3275 if (firstPass
&& !found
) {
3292 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3294 if (!wPreferences
.flags
.noclip
) {
3295 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3296 if (scr
->current_workspace
!= workspace
) {
3297 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3298 WAppIconChain
*chain
= scr
->global_icons
;
3301 moveIconBetweenDocks(chain
->aicon
->dock
,
3302 scr
->workspaces
[workspace
]->clip
,
3303 chain
->aicon
, chain
->aicon
->xindex
,
3304 chain
->aicon
->yindex
);
3305 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
3306 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3307 chain
= chain
->next
;
3310 wDockHideIcons(old_clip
);
3311 if (old_clip
->auto_raise_lower
) {
3312 if (old_clip
->auto_raise_magic
) {
3313 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3314 old_clip
->auto_raise_magic
= NULL
;
3316 wDockLower(old_clip
);
3318 if (old_clip
->auto_collapse
) {
3319 if (old_clip
->auto_expand_magic
) {
3320 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3321 old_clip
->auto_expand_magic
= NULL
;
3323 old_clip
->collapsed
= 1;
3325 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3327 if (scr
->flags
.clip_balloon_mapped
)
3328 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3335 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3340 for (i
=0; i
<dock
->max_icons
; i
++) {
3341 icon
= dock
->icon_array
[i
];
3345 if (icon
->launching
&& icon
->pid
== pid
) {
3346 if (!icon
->relaunching
) {
3348 icon
->main_window
= None
;
3350 wDockFinishLaunch(dock
, icon
);
3355 sprintf(msg
, _("Could not execute command \"%s\""),
3356 icon
->drop_launch
&& icon
->dnd_command
3357 ? icon
->dnd_command
: icon
->command
);
3359 sprintf(msg
, _("Could not execute command \"%s\""),
3362 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
3363 _("OK"), NULL
, NULL
);
3372 toggleLowered(WDock
*dock
)
3377 /* lower/raise Dock */
3378 if (!dock
->lowered
) {
3379 newlevel
= WMNormalLevel
;
3382 newlevel
= WMDockLevel
;
3386 for (i
=0; i
<dock
->max_icons
; i
++) {
3387 tmp
= dock
->icon_array
[i
];
3391 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3393 wLowerFrame(tmp
->icon
->core
);
3396 if (dock
->type
== WM_DOCK
)
3397 wScreenUpdateUsableArea(dock
->screen_ptr
);
3402 toggleCollapsed(WDock
*dock
)
3404 if (dock
->collapsed
) {
3405 dock
->collapsed
= 0;
3406 wDockShowIcons(dock
);
3409 dock
->collapsed
= 1;
3410 wDockHideIcons(dock
);
3416 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3418 WScreen
*scr
= dock
->screen_ptr
;
3419 WObjDescriptor
*desc
;
3421 WApplication
*wapp
= NULL
;
3425 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3427 if (dock
->type
== WM_DOCK
) {
3429 entry
= dock
->menu
->entries
[index
];
3430 entry
->flags
.indicator_on
= !dock
->lowered
;
3431 entry
->clientdata
= dock
;
3434 if (scr
->clip_options
)
3435 updateClipOptionsMenu(scr
->clip_options
, dock
);
3437 n_selected
= numberOfSelectedIcons(dock
);
3439 /* Rename Workspace */
3440 entry
= dock
->menu
->entries
[++index
];
3441 if (aicon
== scr
->clip_icon
) {
3442 entry
->callback
= renameCallback
;
3443 entry
->clientdata
= dock
;
3444 entry
->flags
.indicator
= 0;
3445 entry
->text
= _("Rename Workspace");
3447 entry
->callback
= omnipresentCallback
;
3448 entry
->clientdata
= aicon
;
3449 if (n_selected
> 0) {
3450 entry
->flags
.indicator
= 0;
3451 entry
->text
= _("Toggle Omnipresent");
3453 entry
->flags
.indicator
= 1;
3454 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3455 entry
->flags
.indicator_type
= MI_CHECK
;
3456 entry
->text
= _("Omnipresent");
3460 /* select/unselect icon */
3461 entry
= dock
->menu
->entries
[++index
];
3462 entry
->clientdata
= aicon
;
3463 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3464 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3466 /* select/unselect all icons */
3467 entry
= dock
->menu
->entries
[++index
];
3468 entry
->clientdata
= aicon
;
3470 entry
->text
= _("Unselect All Icons");
3472 entry
->text
= _("Select All Icons");
3473 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3476 entry
= dock
->menu
->entries
[++index
];
3477 entry
->clientdata
= aicon
;
3479 entry
->text
= _("Keep Icons");
3481 entry
->text
= _("Keep Icon");
3482 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3484 /* this is the workspace submenu part */
3485 entry
= dock
->menu
->entries
[++index
];
3487 entry
->text
= _("Move Icons To");
3489 entry
->text
= _("Move Icon To");
3490 if (scr
->clip_submenu
)
3491 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3492 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3494 /* remove icon(s) */
3495 entry
= dock
->menu
->entries
[++index
];
3496 entry
->clientdata
= aicon
;
3498 entry
->text
= _("Remove Icons");
3500 entry
->text
= _("Remove Icon");
3501 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3503 /* attract icon(s) */
3504 entry
= dock
->menu
->entries
[++index
];
3505 entry
->clientdata
= aicon
;
3507 dock
->menu
->flags
.realized
= 0;
3508 wMenuRealize(dock
->menu
);
3512 entry
= dock
->menu
->entries
[++index
];
3513 entry
->clientdata
= aicon
;
3514 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3517 entry
= dock
->menu
->entries
[++index
];
3518 entry
->clientdata
= aicon
;
3519 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3522 entry
= dock
->menu
->entries
[++index
];
3523 entry
->clientdata
= aicon
;
3524 if (aicon
->icon
->owner
) {
3525 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3526 if (wapp
&& wapp
->flags
.hidden
)
3527 entry
->text
= _("Unhide");
3529 entry
->text
= _("Hide");
3531 entry
->text
= _("Hide");
3533 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3536 entry
= dock
->menu
->entries
[++index
];
3537 entry
->clientdata
= aicon
;
3538 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
3539 && !wPreferences
.flags
.noupdates
);
3542 entry
= dock
->menu
->entries
[++index
];
3543 entry
->clientdata
= aicon
;
3544 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3546 if (!dock
->menu
->flags
.realized
)
3547 wMenuRealize(dock
->menu
);
3549 if (dock
->type
== WM_CLIP
) {
3550 x_pos
= event
->xbutton
.x_root
+2;
3552 x_pos
= dock
->on_right_side
?
3553 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 2 : 0;
3556 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3558 /* allow drag select */
3559 event
->xany
.send_event
= True
;
3560 desc
= &dock
->menu
->menu
->descriptor
;
3561 (*desc
->handle_mousedown
)(desc
, event
);
3566 openClipWorkspaceMenu(WScreen
*scr
, int x
, int y
)
3568 if (!scr
->clip_ws_menu
) {
3569 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3571 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
3572 wMenuMapAt(scr
->clip_ws_menu
, x
, y
, False
);
3576 /******************************************************************/
3578 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3580 WAppIcon
*btn
= desc
->parent
;
3581 WDock
*dock
= btn
->dock
;
3582 WApplication
*wapp
= NULL
;
3585 #ifdef REDUCE_APPICONS
3586 if ((btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) ||
3587 ((btn
->icon
->owner
== NULL
) && (btn
->applist
!= NULL
))) {
3588 if (btn
->icon
->owner
== NULL
)
3589 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
3591 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3593 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3597 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3599 /* go to the last workspace that the user worked on the app */
3600 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
3602 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3605 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3608 if (event
->xbutton
.state
& MOD_MASK
) {
3609 wHideOtherApplications(btn
->icon
->owner
);
3612 if (event
->xbutton
.button
==Button1
) {
3614 if (event
->xbutton
.state
& MOD_MASK
) {
3615 /* raise/lower dock */
3616 toggleLowered(dock
);
3617 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3618 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3619 toggleCollapsed(dock
);
3621 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3622 } else if (btn
->command
) {
3623 if (!btn
->launching
&&
3624 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3625 launchDockedApplication(btn
);
3627 } else if (btn
->xindex
== 0 && btn
->yindex
== 0
3628 && btn
->dock
->type
== WM_DOCK
) {
3630 wShowGNUstepPanel(dock
->screen_ptr
);
3638 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3640 WScreen
*scr
= dock
->screen_ptr
;
3641 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3644 int grabbed
= 0, swapped
= 0, done
;
3645 Pixmap ghost
= None
;
3646 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3649 puts("moving dock");
3651 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3652 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3653 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3654 wwarning("pointer grab failed for dock move");
3657 for (x
=0; x
<dock
->max_icons
; x
++) {
3658 if (dock
->icon_array
[x
]!=NULL
&&
3659 dock
->icon_array
[x
]->yindex
> y
)
3660 y
= dock
->icon_array
[x
]->yindex
;
3663 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3667 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3668 |ButtonMotionMask
|ExposureMask
, &ev
);
3676 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3677 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3678 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3679 |ButtonReleaseMask
|ButtonPressMask
,
3680 wCursor
[WCUR_MOVE
], CurrentTime
);
3685 if (dock
->type
== WM_CLIP
) {
3686 if (ev
.xmotion
.x_root
- ofs_x
< 0) {
3688 } else if (ev
.xmotion
.x_root
- ofs_x
+ ICON_SIZE
>
3690 x
= scr
->scr_width
- ICON_SIZE
;
3692 x
= ev
.xmotion
.x_root
- ofs_x
;
3694 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3696 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3698 y
= scr
->scr_height
- ICON_SIZE
;
3700 y
= ev
.xmotion
.y_root
- ofs_y
;
3702 moveDock(dock
, x
, y
);
3704 /* move vertically if pointer is inside the dock*/
3705 if ((dock
->on_right_side
&&
3706 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3707 || (!dock
->on_right_side
&&
3708 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3710 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3712 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3714 y
= scr
->scr_height
- ICON_SIZE
;
3716 y
= ev
.xmotion
.y_root
- ofs_y
;
3718 moveDock(dock
, dock
->x_pos
, y
);
3720 /* move horizontally to change sides */
3721 x
= ev
.xmotion
.x_root
- ofs_x
;
3722 if (!dock
->on_right_side
) {
3726 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3727 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3728 -DOCK_EXTRA_SPACE
-1, dock
->y_pos
);
3729 if (superfluous
&& ghost
==None
) {
3730 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3731 scr
->scr_width
-ICON_SIZE
3732 -DOCK_EXTRA_SPACE
-1,
3734 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3736 XClearWindow(dpy
, scr
->dock_shadow
);
3738 XMapRaised(dpy
, scr
->dock_shadow
);
3741 if (superfluous
&& ghost
!=None
) {
3742 XFreePixmap(dpy
, ghost
);
3745 XUnmapWindow(dpy
, scr
->dock_shadow
);
3750 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3751 XMoveWindow(dpy
, scr
->dock_shadow
,
3752 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3753 if (superfluous
&& ghost
==None
) {
3754 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3755 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3756 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3758 XClearWindow(dpy
, scr
->dock_shadow
);
3760 XMapRaised(dpy
, scr
->dock_shadow
);
3763 XUnmapWindow(dpy
, scr
->dock_shadow
);
3765 if (superfluous
&& ghost
!=None
) {
3766 XFreePixmap(dpy
, ghost
);
3778 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3780 XUngrabPointer(dpy
, CurrentTime
);
3781 XUnmapWindow(dpy
, scr
->dock_shadow
);
3782 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3783 if (dock
->type
== WM_DOCK
) {
3786 dock
->on_right_side
= 1;
3788 dock
->on_right_side
= 0;
3790 wArrangeIcons(scr
, False
);
3799 XFreePixmap(dpy
, ghost
);
3800 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3803 puts("End dock move");
3810 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3812 WScreen
*scr
= dock
->screen_ptr
;
3814 WIcon
*icon
= aicon
->icon
;
3815 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3816 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3818 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3819 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3820 int shad_x
= x
, shad_y
= y
;
3821 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3823 Pixmap ghost
= None
;
3825 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3826 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3829 if (wPreferences
.flags
.noupdates
)
3832 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3833 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3834 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3836 wwarning("pointer grab failed for icon move");
3840 if (!(event
->xbutton
.state
& MOD_MASK
))
3841 wRaiseFrame(icon
->core
);
3843 if (!wPreferences
.flags
.noclip
)
3844 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3846 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3848 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3851 wins
[0] = icon
->core
->window
;
3852 wins
[1] = scr
->dock_shadow
;
3853 XRestackWindows(dpy
, wins
, 2);
3854 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3855 ICON_SIZE
, ICON_SIZE
);
3857 if (icon
->pixmap
!=None
)
3858 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3860 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3862 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3863 XClearWindow(dpy
, scr
->dock_shadow
);
3865 XMapWindow(dpy
, scr
->dock_shadow
);
3871 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3872 |ButtonMotionMask
|ExposureMask
, &ev
);
3880 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3881 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3882 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3883 |ButtonReleaseMask
|ButtonPressMask
,
3884 wCursor
[WCUR_MOVE
], CurrentTime
);
3893 for (i
=0; i
<scr
->workspace_count
; i
++) {
3894 if (i
== scr
->current_workspace
)
3896 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3900 x
= ev
.xmotion
.x_root
- ofs_x
;
3901 y
= ev
.xmotion
.y_root
- ofs_y
;
3902 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3905 if (last_dock
!= dock
&& collapsed
) {
3906 last_dock
->collapsed
= 1;
3907 wDockHideIcons(last_dock
);
3910 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3911 dock
->collapsed
= 0;
3912 wDockShowIcons(dock
);
3914 if (dock
->auto_raise_lower
)
3918 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3921 if (last_dock
!= dock2
&& collapsed
) {
3922 last_dock
->collapsed
= 1;
3923 wDockHideIcons(last_dock
);
3926 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3927 dock2
->collapsed
= 0;
3928 wDockShowIcons(dock2
);
3930 if (dock2
->auto_raise_lower
)
3935 if (aicon
->launching
3936 || (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3937 || (!aicon
->running
&& tmp
)) {
3938 shad_x
= last_dock
->x_pos
+ ix
*wPreferences
.icon_size
;
3939 shad_y
= last_dock
->y_pos
+ iy
*wPreferences
.icon_size
;
3941 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3944 XMapWindow(dpy
, scr
->dock_shadow
);
3949 XUnmapWindow(dpy
, scr
->dock_shadow
);
3953 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3960 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3962 XUngrabPointer(dpy
, CurrentTime
);
3964 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3965 XUnmapWindow(dpy
, scr
->dock_shadow
);
3967 reattachIcon(dock
, aicon
, ix
, iy
);
3968 if (clip
&& dock
!=clip
&& clip
->auto_raise_lower
)
3971 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3973 /* Slide it back if dock rejected it */
3974 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3976 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3978 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3986 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3987 /* We need to deselect it, even if is deselected in
3988 * wDockDetach(), because else DoKaboom() will fail.
3990 if (aicon
->icon
->selected
)
3991 wIconSelect(aicon
->icon
);
3992 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3995 if (clip
&& clip
->auto_raise_lower
)
3997 wDockDetach(dock
, aicon
);
4000 last_dock
->collapsed
= 1;
4001 wDockHideIcons(last_dock
);
4006 XFreePixmap(dpy
, ghost
);
4007 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
4011 for (i
=0; i
<scr
->workspace_count
; i
++) {
4012 if (i
== scr
->current_workspace
)
4014 wDockHideIcons(scr
->workspaces
[i
]->clip
);
4019 puts("End icon move");
4028 getClipButton(int px
, int py
)
4030 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
4032 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
4035 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
4036 return CLIP_FORWARD
;
4037 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
4045 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
4048 int done
, direction
, new_ws
;
4050 WDock
*clip
= scr
->clip_icon
->dock
;
4052 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
4054 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
4055 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
4057 wClipIconPaint(scr
->clip_icon
);
4060 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
4061 |ButtonPressMask
, &ev
);
4068 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
4069 if (new_dir
!= direction
) {
4070 direction
= new_dir
;
4071 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
4072 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
4073 wClipIconPaint(scr
->clip_icon
);
4081 if (ev
.xbutton
.button
== event
->xbutton
.button
)
4086 clip
->lclip_button_pushed
= 0;
4087 clip
->rclip_button_pushed
= 0;
4089 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
4091 if (direction
== CLIP_FORWARD
) {
4092 if (scr
->current_workspace
< scr
->workspace_count
-1)
4093 wWorkspaceChange(scr
, scr
->current_workspace
+1);
4094 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
4095 wWorkspaceChange(scr
, scr
->current_workspace
+1);
4096 else if (wPreferences
.ws_cycle
)
4097 wWorkspaceChange(scr
, 0);
4099 else if (direction
== CLIP_REWIND
) {
4100 if (scr
->current_workspace
> 0)
4101 wWorkspaceChange(scr
, scr
->current_workspace
-1);
4102 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
4103 wWorkspaceChange(scr
, scr
->workspace_count
-1);
4106 wClipIconPaint(scr
->clip_icon
);
4111 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
4113 WAppIcon
*aicon
= desc
->parent
;
4114 WDock
*dock
= aicon
->dock
;
4115 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4117 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
4120 scr
->last_dock
= dock
;
4122 if (dock
->menu
->flags
.mapped
)
4123 wMenuUnmap(dock
->menu
);
4125 if (IsDoubleClick(scr
, event
)) {
4126 /* double-click was not in the main clip icon */
4127 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
4128 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
4129 iconDblClick(desc
, event
);
4134 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
4135 XUnmapWindow(dpy
, scr
->clip_balloon
);
4136 scr
->flags
.clip_balloon_mapped
= 0;
4140 puts("handling dock");
4142 if (event
->xbutton
.button
== Button1
) {
4143 if (event
->xbutton
.state
& MOD_MASK
)
4148 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
4149 dock
->type
!=WM_DOCK
) {
4150 wIconSelect(aicon
->icon
);
4154 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
4155 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
4156 && dock
->type
==WM_CLIP
)
4157 handleClipChangeWorkspace(scr
, event
);
4159 handleDockMove(dock
, aicon
, event
);
4161 handleIconMove(dock
, aicon
, event
);
4163 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4164 aicon
==scr
->clip_icon
) {
4165 openClipWorkspaceMenu(scr
, event
->xbutton
.x_root
+2,
4166 event
->xbutton
.y_root
+2);
4167 if (scr
->clip_ws_menu
) {
4169 menu
= scr
->clip_ws_menu
;
4170 desc
= &menu
->menu
->descriptor
;
4172 event
->xany
.send_event
= True
;
4173 (*desc
->handle_mousedown
)(desc
, event
);
4175 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4176 (event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
) {
4177 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
4178 } else if (event
->xbutton
.button
== Button3
) {
4179 openDockMenu(dock
, aicon
, event
);
4185 showClipBalloon(WDock
*dock
, int workspace
)
4189 WScreen
*scr
= dock
->screen_ptr
;
4193 scr
->flags
.clip_balloon_mapped
= 1;
4194 XMapWindow(dpy
, scr
->clip_balloon
);
4196 text
= scr
->workspaces
[workspace
]->name
;
4198 w
= WMWidthOfString(scr
->clip_title_font
, text
, strlen(text
));
4200 h
= WMFontHeight(scr
->clip_title_font
);
4201 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
4203 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
4204 y
= dock
->y_pos
+ ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
4206 if (x
+w
> scr
->scr_width
) {
4207 x
= scr
->scr_width
- w
;
4208 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
4209 y
= dock
->y_pos
- h
- 1;
4211 y
= dock
->y_pos
+ ICON_SIZE
;
4212 XRaiseWindow(dpy
, scr
->clip_balloon
);
4214 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
4215 stack
[1] = scr
->clip_balloon
;
4216 XRestackWindows(dpy
, stack
, 2);
4218 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
4219 XSetForeground(dpy
, scr
->clip_title_gc
,
4220 scr
->clip_title_pixel
[CLIP_NORMAL
]);
4221 XClearWindow(dpy
, scr
->clip_balloon
);
4222 WMDrawString(scr
->wmscreen
, scr
->clip_balloon
, scr
->clip_title_gc
,
4223 scr
->clip_title_font
, 0, 0, text
, strlen(text
));
4228 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
4230 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4234 assert(event
->type
==EnterNotify
);
4236 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4239 scr
= btn
->icon
->core
->screen_ptr
;
4240 if (!btn
->omnipresent
)
4243 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
4245 if (!dock
|| dock
->type
!=WM_CLIP
)
4248 /* The auto raise/lower code */
4249 if (dock
->auto_lower_magic
) {
4250 WMDeleteTimerHandler(dock
->auto_lower_magic
);
4251 dock
->auto_lower_magic
= NULL
;
4253 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
4254 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
,
4259 /* The auto expand/collapse code */
4260 if (dock
->auto_collapse_magic
) {
4261 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
4262 dock
->auto_collapse_magic
= NULL
;
4264 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
4265 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
,
4270 if (btn
->xindex
== 0 && btn
->yindex
== 0)
4271 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4273 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4274 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
4275 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
4282 clipLeave(WDock
*dock
)
4285 WObjDescriptor
*desc
= NULL
;
4287 if (!dock
|| dock
->type
!=WM_CLIP
)
4290 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
)!=False
) {
4291 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
4292 (XPointer
*)&desc
)!=XCNOENT
4293 && desc
&& desc
->parent_type
==WCLASS_DOCK_ICON
4294 && ((WAppIcon
*)desc
->parent
)->dock
4295 && ((WAppIcon
*)desc
->parent
)->dock
->type
==WM_CLIP
) {
4296 /* We didn't left the Clip yet */
4297 XPutBackEvent(dpy
, &event
);
4301 XPutBackEvent(dpy
, &event
);
4303 /* We entered a withdrawn window, so we're still in Clip */
4307 if (dock
->auto_raise_magic
) {
4308 WMDeleteTimerHandler(dock
->auto_raise_magic
);
4309 dock
->auto_raise_magic
= NULL
;
4311 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
4312 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
,
4317 if (dock
->auto_expand_magic
) {
4318 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4319 dock
->auto_expand_magic
= NULL
;
4321 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
4322 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
4330 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4332 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4334 assert(event
->type
==LeaveNotify
);
4336 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4339 clipLeave(btn
->dock
);
4344 clipAutoCollapse(void *cdata
)
4346 WDock
*dock
= (WDock
*)cdata
;
4348 if (dock
->type
!=WM_CLIP
)
4351 if (dock
->auto_collapse
) {
4352 dock
->collapsed
= 1;
4353 wDockHideIcons(dock
);
4355 dock
->auto_collapse_magic
= NULL
;
4360 clipAutoExpand(void *cdata
)
4362 WDock
*dock
= (WDock
*)cdata
;
4364 if (dock
->type
!=WM_CLIP
)
4367 if (dock
->auto_collapse
) {
4368 dock
->collapsed
= 0;
4369 wDockShowIcons(dock
);
4371 dock
->auto_expand_magic
= NULL
;
4376 clipAutoLower(void *cdata
)
4378 WDock
*dock
= (WDock
*)cdata
;
4380 if (dock
->type
!=WM_CLIP
)
4383 if (dock
->auto_raise_lower
)
4386 dock
->auto_lower_magic
= NULL
;
4391 clipAutoRaise(void *cdata
)
4393 WDock
*dock
= (WDock
*)cdata
;
4395 if (dock
->type
!=WM_CLIP
)
4398 if (dock
->auto_raise_lower
)
4401 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4402 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4405 dock
->auto_raise_magic
= NULL
;
4410 iconCanBeOmnipresent(WAppIcon
*aicon
)
4412 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4417 for (i
=0; i
<scr
->workspace_count
; i
++) {
4418 clip
= scr
->workspaces
[i
]->clip
;
4420 if (clip
== aicon
->dock
)
4423 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4424 return False
; /* Clip is full in some workspace */
4426 for (j
=0; j
<clip
->max_icons
; j
++) {
4427 btn
= clip
->icon_array
[j
];
4428 if(btn
&& btn
->xindex
==aicon
->xindex
&& btn
->yindex
==aicon
->yindex
)
4438 wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
4440 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4441 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4442 int status
= WO_SUCCESS
;
4444 if ((scr
->dock
&& aicon
->dock
==scr
->dock
) || aicon
==scr
->clip_icon
) {
4445 return WO_NOT_APPLICABLE
;
4448 if (aicon
->omnipresent
== omnipresent
)
4452 if (iconCanBeOmnipresent(aicon
)) {
4453 aicon
->omnipresent
= 1;
4454 new_entry
= wmalloc(sizeof(WAppIconChain
));
4455 new_entry
->aicon
= aicon
;
4456 new_entry
->next
= scr
->global_icons
;
4457 scr
->global_icons
= new_entry
;
4458 scr
->global_icon_count
++;
4460 aicon
->omnipresent
= 0;
4464 aicon
->omnipresent
= 0;
4465 if (aicon
== scr
->global_icons
->aicon
) {
4466 tmp
= scr
->global_icons
->next
;
4467 free(scr
->global_icons
);
4468 scr
->global_icons
= tmp
;
4469 scr
->global_icon_count
--;
4471 tmp
= scr
->global_icons
;
4473 if (tmp
->next
->aicon
== aicon
) {
4474 tmp1
= tmp
->next
->next
;
4477 scr
->global_icon_count
--;
4485 wAppIconPaint(aicon
);