1 /* dock.c- built-in Dock module for WindowMaker
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 * Copyright (c) 1998, 1999 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
28 #include <X11/Xutil.h>
36 #define PATH_MAX DEFAULT_PATH_MAX
39 #include "WindowMaker.h"
49 #include "properties.h"
53 #include "workspace.h"
55 #include "superfluous.h"
64 /**** Local variables ****/
67 #define CLIP_FORWARD 2
70 /**** Global variables ****/
73 extern void DestroyDockAppSettingsPanel();
75 extern void ShowDockAppSettingsPanel(WAppIcon
*aicon
);
78 extern XContext wWinContext
;
80 extern Cursor wCursor
[WCUR_LAST
];
82 extern WPreferences wPreferences
;
84 extern XContext wWinContext
;
87 extern Atom _XA_DND_PROTOCOL
;
91 #define MOD_MASK wPreferences.modifier_mask
93 extern void appIconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
95 #define ICON_SIZE wPreferences.icon_size
98 /***** Local variables ****/
100 static proplist_t dCommand
=NULL
;
102 static proplist_t dDropCommand
=NULL
;
104 static proplist_t dAutoLaunch
, dLock
;
105 static proplist_t dName
, dForced
, dBuggyApplication
, dYes
, dNo
;
106 static proplist_t dHost
, dDock
, dClip
;
107 static proplist_t dAutoAttractIcons
;
109 static proplist_t dPosition
, dApplications
, dLowered
, dCollapsed
, dAutoCollapse
;
111 static proplist_t dAutoRaiseLower
, dOmnipresent
;
113 static void dockIconPaint(WAppIcon
*btn
);
115 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
117 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
);
119 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
121 static int getClipButton(int px
, int py
);
123 static void toggleLowered(WDock
*dock
);
125 static void toggleCollapsed(WDock
*dock
);
127 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
129 static void clipLeave(WDock
*dock
);
131 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
133 Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
);
135 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
136 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
137 static void clipAutoCollapse(void *cdata
);
138 static void clipAutoExpand(void *cdata
);
139 static void launchDockedApplication(WAppIcon
*btn
);
141 static void clipAutoLower(void *cdata
);
142 static void clipAutoRaise(void *cdata
);
144 static void showClipBalloon(WDock
*dock
, int workspace
);
160 #endif /* OFFIX_DND */
170 dCommand
= PLRetain(PLMakeString("Command"));
172 dDropCommand
= PLRetain(PLMakeString("DropCommand"));
174 dLock
= PLRetain(PLMakeString("Lock"));
175 dAutoLaunch
= PLRetain(PLMakeString("AutoLaunch"));
176 dName
= PLRetain(PLMakeString("Name"));
177 dForced
= PLRetain(PLMakeString("Forced"));
178 dBuggyApplication
= PLRetain(PLMakeString("BuggyApplication"));
179 dYes
= PLRetain(PLMakeString("Yes"));
180 dNo
= PLRetain(PLMakeString("No"));
181 dHost
= PLRetain(PLMakeString("Host"));
183 dPosition
= PLMakeString("Position");
184 dApplications
= PLMakeString("Applications");
185 dLowered
= PLMakeString("Lowered");
186 dCollapsed
= PLMakeString("Collapsed");
187 dAutoCollapse
= PLMakeString("AutoCollapse");
188 dAutoRaiseLower
= PLMakeString("AutoRaiseLower");
189 dAutoAttractIcons
= PLMakeString("AutoAttractIcons");
191 dOmnipresent
= PLMakeString("Omnipresent");
193 dDock
= PLMakeString("Dock");
194 dClip
= PLMakeString("Clip");
200 renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
202 WDock
*dock
= entry
->clientdata
;
207 assert(entry
->clientdata
!=NULL
);
209 wspace
= dock
->screen_ptr
->current_workspace
;
211 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
213 sprintf(buffer
, _("Type the name for workspace %i:"), wspace
+1);
214 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
,
216 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
225 toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
227 assert(entry
->clientdata
!=NULL
);
229 toggleLowered(entry
->clientdata
);
237 killCallback(WMenu
*menu
, WMenuEntry
*entry
)
240 #ifdef REDUCE_APPICONS
241 WAppIconAppList
*tapplist
;
243 extern Atom _XA_WM_DELETE_WINDOW
;
248 if (!WCHECK_STATE(WSTATE_NORMAL
))
251 assert(entry
->clientdata
!=NULL
);
253 icon
= (WAppIcon
*)entry
->clientdata
;
257 WCHANGE_STATE(WSTATE_MODAL
);
259 #ifdef REDUCE_APPICONS
260 /* Send a delete message to the main window of each application
261 * bound to this docked appicon. - cls
263 tapplist
= icon
->applist
;
264 while (tapplist
!= NULL
) {
265 if (tapplist
->wapp
->main_window_desc
!= NULL
) {
266 if (tapplist
->wapp
->main_window_desc
->protocols
.DELETE_WINDOW
) {
267 wClientSendProtocol(tapplist
->wapp
->main_window_desc
,
268 _XA_WM_DELETE_WINDOW
, CurrentTime
);
270 wClientKill(tapplist
->wapp
->main_window_desc
);
273 tapplist
= tapplist
->next
;
276 buffer
= wstrappend(icon
->wm_class
,
277 _(" will be forcibly closed.\n"
278 "Any unsaved changes will be lost.\n"
281 if (wPreferences
.dont_confirm_kill
282 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
283 buffer
, _("Yes"), _("No"), NULL
)==WAPRDefault
) {
284 if (icon
->icon
&& icon
->icon
->owner
) {
285 wClientKill(icon
->icon
->owner
);
288 #endif /* !REDUCE_APPICONS */
292 WCHANGE_STATE(WSTATE_NORMAL
);
296 /* TODO: replace this function with a member of the dock struct */
298 numberOfSelectedIcons(WDock
*dock
)
304 for (i
=1; i
<dock
->max_icons
; i
++) {
305 aicon
= dock
->icon_array
[i
];
306 if (aicon
&& aicon
->icon
->selected
) {
316 getSelected(WDock
*dock
)
318 WMBag
*ret
= WMCreateBag(8);
322 for (i
=1; i
<dock
->max_icons
; i
++) {
323 btn
= dock
->icon_array
[i
];
324 if (btn
&& btn
->icon
->selected
) {
325 WMPutInBag(ret
, btn
);
334 paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
336 Window win
= clipIcon
->icon
->core
->window
;
337 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
339 int pt
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
340 int tp
= ICON_SIZE
- pt
;
341 int as
= pt
- 15; /* 15 = 5+5+5 */
342 GC gc
= scr
->clip_title_gc
;
343 #ifdef GRADIENT_CLIP_ARROW
344 Bool collapsed
= clipIcon
->dock
->collapsed
;
350 p
[1].x
= ICON_SIZE
-2;
352 p
[2].x
= ICON_SIZE
-2;
354 } else if (lpushed
) {
358 p
[1].y
= ICON_SIZE
-2;
360 p
[2].y
= ICON_SIZE
-2;
362 if (lpushed
|| rpushed
) {
363 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
364 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
365 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
367 #ifdef GRADIENT_CLIP_ARROW
369 XSetFillStyle(dpy
, scr
->copy_gc
, FillTiled
);
370 XSetTile(dpy
, scr
->copy_gc
, scr
->clip_arrow_gradient
);
371 XSetClipMask(dpy
, scr
->copy_gc
, None
);
374 #endif /* GRADIENT_CLIP_ARROW */
376 /* top right arrow */
377 p
[0].x
= p
[3].x
= ICON_SIZE
-5-as
;
379 p
[1].x
= ICON_SIZE
-6;
381 p
[2].x
= ICON_SIZE
-6;
384 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
385 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
387 #ifdef GRADIENT_CLIP_ARROW
389 XSetTSOrigin(dpy
, gc
, ICON_SIZE
-6-as
, 5);
391 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
392 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
395 /* bottom left arrow */
397 p
[0].y
= p
[3].y
= ICON_SIZE
-5-as
;
399 p
[1].y
= ICON_SIZE
-6;
401 p
[2].y
= ICON_SIZE
-6;
403 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
404 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
406 #ifdef GRADIENT_CLIP_ARROW
408 XSetTSOrigin(dpy
, gc
, 5, ICON_SIZE
-6-as
);
410 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
411 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
413 #ifdef GRADIENT_CLIP_ARROW
415 XSetFillStyle(dpy
, scr
->copy_gc
, FillSolid
);
421 wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
423 RImage
*tile
= RCloneImage(normalTile
);
430 pt
= CLIP_BUTTON_SIZE
*wPreferences
.icon_size
/64;
431 tp
= wPreferences
.icon_size
-1 - pt
;
435 black
.red
= black
.green
= black
.blue
= 0;
438 dark
.red
= dark
.green
= dark
.blue
= 60;
441 light
.red
= light
.green
= light
.blue
= 80;
445 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
-2,
447 RDrawLine(tile
, tp
-1, 0, wPreferences
.icon_size
-1, pt
+1, &black
);
448 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
-3,
452 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4,
453 ICON_SIZE
- 5, 4, &dark
);
454 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5,
455 ICON_SIZE
- 5, 6 + as
, &dark
);
456 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
,
460 ROperateLine(tile
, RAddOperation
, 2, tp
+2, pt
-2,
461 wPreferences
.icon_size
-3, &dark
);
462 RDrawLine(tile
, 0, tp
-1, pt
+1, wPreferences
.icon_size
-1, &black
);
463 ROperateLine(tile
, RSubtractOperation
, 0, tp
-2, pt
+1,
464 wPreferences
.icon_size
-2, &light
);
467 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4,
468 ICON_SIZE
- 5, &dark
);
469 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
,
470 6 + as
, ICON_SIZE
- 5, &dark
);
471 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5,
479 omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
481 WAppIcon
*clickedIcon
= entry
->clientdata
;
484 WMBag
*selectedIcons
;
488 assert(entry
->clientdata
!=NULL
);
490 dock
= clickedIcon
->dock
;
492 selectedIcons
= getSelected(dock
);
494 if (!WMGetBagItemCount(selectedIcons
))
495 WMPutInBag(selectedIcons
, clickedIcon
);
498 for (i
= 0; i
< WMGetBagItemCount(selectedIcons
); i
++) {
499 aicon
= WMGetFromBag(selectedIcons
, i
);
501 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
503 else if (aicon
->icon
->selected
)
504 wIconSelect(aicon
->icon
);
506 WMFreeBag(selectedIcons
);
509 wMessageDialog(dock
->screen_ptr
, _("Warning"),
510 _("Some icons cannot be made omnipresent. "
511 "Please make sure that no other icon is "
512 "docked in the same positions on the other "
513 "workspaces and the Clip is not full in "
515 _("OK"), NULL
, NULL
);
516 } else if (failed
== 1) {
517 wMessageDialog(dock
->screen_ptr
, _("Warning"),
518 _("Icon cannot be made omnipresent. "
519 "Please make sure that no other icon is "
520 "docked in the same position on the other "
521 "workspaces and the Clip is not full in "
523 _("OK"), NULL
, NULL
);
529 removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
531 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
534 WMBag
*selectedIcons
;
538 assert(clickedIcon
!=NULL
);
540 dock
= clickedIcon
->dock
;
542 selectedIcons
= getSelected(dock
);
544 if (WMGetBagItemCount(selectedIcons
)) {
545 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
546 _("All selected icons will be removed!"),
547 _("OK"), _("Cancel"), NULL
)!=WAPRDefault
) {
548 WMFreeBag(selectedIcons
);
552 if (clickedIcon
->xindex
==0 && clickedIcon
->yindex
==0) {
553 WMFreeBag(selectedIcons
);
556 WMPutInBag(selectedIcons
, clickedIcon
);
559 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 selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
659 WAppIcon
*icon
= (WAppIcon
*)entry
->clientdata
;
663 wIconSelect(icon
->icon
);
670 colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
672 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
675 int x
, y
, x_pos
, y_pos
;
677 assert(entry
->clientdata
!=NULL
);
678 clip
= clickedIcon
->dock
;
680 aicon
= clip
->screen_ptr
->app_icon_list
;
683 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
684 x_pos
= clip
->x_pos
+ x
*ICON_SIZE
;
685 y_pos
= clip
->y_pos
+ y
*ICON_SIZE
;
686 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
688 if (wPreferences
.no_animations
) {
689 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
691 SlideWindow(aicon
->icon
->core
->window
,
692 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
695 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
696 #endif /* ANIMATIONS */
698 aicon
->attracted
= 1;
699 if (!aicon
->icon
->shadowed
) {
700 aicon
->icon
->shadowed
= 1;
701 aicon
->icon
->force_paint
= 1;
702 /* We don't do an wAppIconPaint() here because it's in
703 * wDockAttachIcon(). -Dan
706 wDockAttachIcon(clip
, aicon
, x
, y
);
707 if (clip
->collapsed
|| !clip
->mapped
)
708 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
716 selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
718 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
720 WMBag
*selectedIcons
;
724 assert(clickedIcon
!=NULL
);
725 dock
= clickedIcon
->dock
;
727 selectedIcons
= getSelected(dock
);
729 if (!WMGetBagItemCount(selectedIcons
)) {
730 for (i
=1; i
<dock
->max_icons
; i
++) {
731 btn
= dock
->icon_array
[i
];
732 if (btn
&& !btn
->icon
->selected
) {
733 wIconSelect(btn
->icon
);
737 for (i
= 0; i
< WMGetBagItemCount(selectedIcons
); i
++) {
738 btn
= WMGetFromBag(selectedIcons
, i
);
739 wIconSelect(btn
->icon
);
742 WMFreeBag(selectedIcons
);
749 toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
751 assert(entry
->clientdata
!=NULL
);
753 toggleCollapsed(entry
->clientdata
);
755 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->collapsed
;
762 toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
765 assert(entry
->clientdata
!=NULL
);
767 dock
= (WDock
*) entry
->clientdata
;
769 dock
->auto_collapse
= !dock
->auto_collapse
;
771 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_collapse
;
778 toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
781 assert(entry
->clientdata
!=NULL
);
783 dock
= (WDock
*) entry
->clientdata
;
785 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
787 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_raise_lower
;
794 launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
796 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
798 launchDockedApplication(btn
);
803 settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
805 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
809 ShowDockAppSettingsPanel(btn
);
814 hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
817 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
819 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
821 if (wapp
->flags
.hidden
) {
822 wWorkspaceChange(btn
->icon
->core
->screen_ptr
,wapp
->last_workspace
);
823 wUnhideApplication(wapp
, False
, False
);
825 wHideApplication(wapp
);
831 unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
834 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
836 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
838 wUnhideApplication(wapp
, False
, True
);
843 mainIconCreate(WScreen
*scr
, int type
)
848 if (type
== WM_CLIP
) {
850 return scr
->clip_icon
;
851 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
852 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
853 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
854 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
855 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE;*/
858 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
859 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
865 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
866 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
867 btn
->icon
->core
->descriptor
.parent
= btn
;
868 /*ChangeStackingLevel(btn->icon->core, WMDockLevel);*/
869 XMapWindow(dpy
, btn
->icon
->core
->window
);
874 scr
->clip_icon
= btn
;
881 switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
883 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
884 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
886 WMBag
*selectedIcons
;
889 if (entry
->order
== scr
->current_workspace
)
892 dest
= scr
->workspaces
[entry
->order
]->clip
;
894 selectedIcons
= getSelected(src
);
896 if (WMGetBagItemCount(selectedIcons
)) {
898 for (i
= 0; i
< WMGetBagItemCount(selectedIcons
); i
++) {
899 btn
= WMGetFromBag(selectedIcons
, i
);
900 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
901 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
902 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
905 } else if (icon
!= scr
->clip_icon
) {
906 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
907 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
908 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
911 WMFreeBag(selectedIcons
);
917 launchDockedApplication(WAppIcon
*btn
)
919 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
921 if (!btn
->launching
&& btn
->command
!=NULL
) {
922 if (!btn
->forced_dock
) {
923 btn
->relaunching
= btn
->running
;
926 if (btn
->wm_instance
|| btn
->wm_class
) {
927 WWindowAttributes attr
;
928 memset(&attr
, 0, sizeof(WWindowAttributes
));
929 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
,
932 if (!attr
.no_appicon
&& !btn
->buggy_app
)
937 btn
->drop_launch
= 0;
938 scr
->last_dock
= btn
->dock
;
939 btn
->pid
= execCommand(btn
, btn
->command
, NULL
);
941 if (btn
->buggy_app
) {
942 /* give feedback that the app was launched */
946 WMAddTimerHandler(200, (WMCallback
*)dockIconPaint
, btn
);
951 wwarning(_("could not launch application %s\n"), btn
->command
);
953 if (!btn
->relaunching
)
962 updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
964 WScreen
*scr
= menu
->frame
->screen_ptr
;
965 char title
[MAX_WORKSPACENAME_WIDTH
+1];
971 for (i
=0; i
<scr
->workspace_count
; i
++) {
972 if (i
< menu
->entry_no
) {
973 if (strcmp(menu
->entries
[i
]->text
,scr
->workspaces
[i
]->name
)!=0) {
974 free(menu
->entries
[i
]->text
);
975 strcpy(title
, scr
->workspaces
[i
]->name
);
976 menu
->entries
[i
]->text
= wstrdup(title
);
977 menu
->flags
.realized
= 0;
979 menu
->entries
[i
]->clientdata
= (void*)icon
;
981 strcpy(title
, scr
->workspaces
[i
]->name
);
983 wMenuAddCallback(menu
, title
, switchWSCommand
, (void*)icon
);
985 menu
->flags
.realized
= 0;
987 if (i
== scr
->current_workspace
) {
988 wMenuSetEnabled(menu
, i
, False
);
990 wMenuSetEnabled(menu
, i
, True
);
994 if (!menu
->flags
.realized
)
1000 makeWorkspaceMenu(WScreen
*scr
)
1004 menu
= wMenuCreate(scr
, NULL
, False
);
1006 wwarning(_("could not create workspace submenu for Clip menu"));
1008 wMenuAddCallback(menu
, "", switchWSCommand
, (void*)scr
->clip_icon
);
1010 menu
->flags
.realized
= 0;
1018 updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
1027 entry
= menu
->entries
[index
];
1028 if (dock
->lowered
) {
1029 entry
->text
= _("Keep on Top");
1031 entry
->text
= _("Allow Lowering");
1033 entry
->clientdata
= dock
;
1036 entry
= menu
->entries
[++index
];
1037 entry
->flags
.indicator_on
= dock
->collapsed
;
1038 entry
->clientdata
= dock
;
1041 entry
= menu
->entries
[++index
];
1042 entry
->flags
.indicator_on
= dock
->auto_collapse
;
1043 entry
->clientdata
= dock
;
1045 /* auto-raise/lower */
1046 entry
= menu
->entries
[++index
];
1047 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1048 entry
->clientdata
= dock
;
1051 entry
= menu
->entries
[++index
];
1052 entry
->flags
.indicator_on
= dock
->attract_icons
;
1053 entry
->clientdata
= dock
;
1055 menu
->flags
.realized
= 0;
1061 makeClipOptionsMenu(WScreen
*scr
)
1066 menu
= wMenuCreate(scr
, NULL
, False
);
1068 wwarning(_("could not create options submenu for Clip menu"));
1072 entry
= wMenuAddCallback(menu
, _("Keep on Top"),
1073 toggleLoweredCallback
, NULL
);
1075 entry
= wMenuAddCallback(menu
, _("Collapsed"),
1076 toggleCollapsedCallback
, NULL
);
1077 entry
->flags
.indicator
= 1;
1078 entry
->flags
.indicator_on
= 1;
1079 entry
->flags
.indicator_type
= MI_CHECK
;
1081 entry
= wMenuAddCallback(menu
, _("AutoCollapse"),
1082 toggleAutoCollapseCallback
, NULL
);
1083 entry
->flags
.indicator
= 1;
1084 entry
->flags
.indicator_on
= 1;
1085 entry
->flags
.indicator_type
= MI_CHECK
;
1087 entry
= wMenuAddCallback(menu
, _("AutoRaiseLower"),
1088 toggleAutoRaiseLowerCallback
, NULL
);
1089 entry
->flags
.indicator
= 1;
1090 entry
->flags
.indicator_on
= 1;
1091 entry
->flags
.indicator_type
= MI_CHECK
;
1093 entry
= wMenuAddCallback(menu
, _("AutoAttract Icons"),
1094 toggleAutoAttractCallback
, NULL
);
1095 entry
->flags
.indicator
= 1;
1096 entry
->flags
.indicator_on
= 1;
1097 entry
->flags
.indicator_type
= MI_CHECK
;
1099 menu
->flags
.realized
= 0;
1107 dockMenuCreate(WScreen
*scr
, int type
)
1112 if (type
== WM_CLIP
&& scr
->clip_menu
)
1113 return scr
->clip_menu
;
1115 menu
= wMenuCreate(scr
, NULL
, False
);
1116 if (type
!= WM_CLIP
) {
1117 entry
= wMenuAddCallback(menu
, _("Keep on Top"),
1118 toggleLoweredCallback
, NULL
);
1120 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1121 scr
->clip_options
= makeClipOptionsMenu(scr
);
1122 if (scr
->clip_options
)
1123 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1125 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
,
1128 entry
->text
= _("Rename Workspace");
1130 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1131 entry
->flags
.indicator
= 1;
1132 entry
->flags
.indicator_on
= 1;
1133 entry
->flags
.indicator_type
= MI_CHECK
;
1135 entry
= wMenuAddCallback(menu
, _("Select All Icons"),
1136 selectIconsCallback
, NULL
);
1138 entry
->text
= _("Select All Icons");
1140 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1142 entry
->text
= _("Keep Icon");
1144 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1146 entry
->text
= _("Move Icon To");
1147 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1148 if (scr
->clip_submenu
)
1149 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1151 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
,
1154 entry
->text
= _("Remove Icon");
1156 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1159 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1161 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1163 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1165 entry
->text
= _("Hide");
1167 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1169 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1171 if (type
== WM_CLIP
)
1172 scr
->clip_menu
= menu
;
1179 wDockCreate(WScreen
*scr
, int type
)
1187 dock
= wmalloc(sizeof(WDock
));
1188 memset(dock
, 0, sizeof(WDock
));
1190 if (type
== WM_CLIP
)
1191 icon_count
= CLIP_MAX_ICONS
;
1193 icon_count
= scr
->scr_height
/wPreferences
.icon_size
;
1195 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*)*icon_count
);
1196 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*)*icon_count
);
1198 dock
->max_icons
= icon_count
;
1200 btn
= mainIconCreate(scr
, type
);
1204 dock
->x_pos
= btn
->x_pos
;
1205 dock
->y_pos
= btn
->y_pos
;
1206 dock
->screen_ptr
= scr
;
1208 dock
->icon_count
= 1;
1209 dock
->on_right_side
= 1;
1210 dock
->collapsed
= 0;
1211 dock
->auto_collapse
= 0;
1212 dock
->auto_collapse_magic
= NULL
;
1213 dock
->auto_raise_lower
= 0;
1214 dock
->auto_lower_magic
= NULL
;
1215 dock
->auto_raise_magic
= NULL
;
1216 dock
->attract_icons
= 0;
1218 dock
->icon_array
[0] = btn
;
1219 wRaiseFrame(btn
->icon
->core
);
1220 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1222 /* create dock menu */
1223 dock
->menu
= dockMenuCreate(scr
, type
);
1230 wDockDestroy(WDock
*dock
)
1235 for (i
=(dock
->type
== WM_CLIP
) ? 1 : 0; i
<dock
->max_icons
; i
++) {
1236 aicon
= dock
->icon_array
[i
];
1238 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1239 wDockDetach(dock
, aicon
);
1241 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
1242 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
1243 aicon
->x_pos
, aicon
->y_pos
);
1244 if (!dock
->mapped
|| dock
->collapsed
)
1245 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1249 if (wPreferences
.auto_arrange_icons
)
1250 wArrangeIcons(dock
->screen_ptr
, True
);
1251 free(dock
->icon_array
);
1252 if (dock
->menu
&& dock
->type
!=WM_CLIP
)
1253 wMenuDestroy(dock
->menu
, True
);
1254 if (dock
->screen_ptr
->last_dock
== dock
)
1255 dock
->screen_ptr
->last_dock
= NULL
;
1261 wClipIconPaint(WAppIcon
*aicon
)
1263 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1264 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1266 Window win
= aicon
->icon
->core
->window
;
1267 int length
, nlength
;
1268 char *ws_name
, ws_number
[10];
1271 wIconPaint(aicon
->icon
);
1273 length
= strlen(workspace
->name
);
1274 ws_name
= malloc(length
+ 1);
1275 sprintf(ws_name
, "%s", workspace
->name
);
1276 sprintf(ws_number
, "%i", scr
->current_workspace
+ 1);
1277 nlength
= strlen(ws_number
);
1279 gc
= scr
->clip_title_gc
;
1281 if (!workspace
->clip
->collapsed
)
1282 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_NORMAL
]);
1284 XSetForeground(dpy
, gc
, scr
->clip_title_pixel
[CLIP_COLLAPSED
]);
1286 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1288 tx
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
1290 WMDrawString(scr
->wmscreen
, win
, gc
, scr
->clip_title_font
, tx
,
1291 ty
, ws_name
, length
);
1293 tx
= (ICON_SIZE
/2 - WMWidthOfString(scr
->clip_title_font
, ws_number
,
1296 WMDrawString(scr
->wmscreen
, win
, gc
, scr
->clip_title_font
, tx
,
1297 2, ws_number
, nlength
);
1301 if (aicon
->launching
) {
1302 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1303 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1305 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
,
1306 aicon
->dock
->rclip_button_pushed
);
1311 clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1313 wClipIconPaint(desc
->parent
);
1318 dockIconPaint(WAppIcon
*btn
)
1320 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1321 wClipIconPaint(btn
);
1328 make_icon_state(WAppIcon
*btn
)
1330 proplist_t node
= NULL
;
1331 proplist_t command
, autolaunch
, lock
, name
, forced
, host
, position
, buggy
;
1332 proplist_t omnipresent
;
1338 command
= PLMakeString("-");
1340 command
= PLMakeString(btn
->command
);
1342 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1344 lock
= btn
->lock
? dYes
: dNo
;
1346 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1348 name
= PLMakeString(tmp
);
1352 forced
= btn
->forced_dock
? dYes
: dNo
;
1354 buggy
= btn
->buggy_app
? dYes
: dNo
;
1356 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1357 sprintf(buffer
, "%i,%i", btn
->x_pos
, btn
->y_pos
);
1359 sprintf(buffer
, "%hi,%hi", btn
->xindex
, btn
->yindex
);
1360 position
= PLMakeString(buffer
);
1362 node
= PLMakeDictionaryFromEntries(dCommand
, command
,
1364 dAutoLaunch
, autolaunch
,
1367 dBuggyApplication
, buggy
,
1368 dPosition
, position
,
1372 PLRelease(position
);
1374 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1375 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&&
1376 (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1377 PLInsertDictionaryEntry(node
, dOmnipresent
, omnipresent
);
1380 if (btn
->dnd_command
) {
1381 command
= PLMakeString(btn
->dnd_command
);
1382 PLInsertDictionaryEntry(node
, dDropCommand
, command
);
1385 #endif /* OFFIX_DND */
1387 if (btn
->client_machine
&& btn
->remote_start
) {
1388 host
= PLMakeString(btn
->client_machine
);
1389 PLInsertDictionaryEntry(node
, dHost
, host
);
1399 dockSaveState(WDock
*dock
)
1402 proplist_t icon_info
;
1403 proplist_t list
=NULL
, dock_state
=NULL
;
1404 proplist_t value
, key
;
1407 list
= PLMakeArrayFromElements(NULL
);
1409 for (i
=(dock
->type
==WM_DOCK
? 0 : 1); i
<dock
->max_icons
; i
++) {
1410 WAppIcon
*btn
= dock
->icon_array
[i
];
1412 if (!btn
|| btn
->attracted
)
1415 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1416 list
= PLAppendArrayElement(list
, icon_info
);
1417 PLRelease(icon_info
);
1421 dock_state
= PLMakeDictionaryFromEntries(dApplications
, list
,
1424 if (dock
->type
== WM_DOCK
) {
1425 sprintf(buffer
, "Applications%i", dock
->screen_ptr
->scr_height
);
1426 key
= PLMakeString(buffer
);
1427 PLInsertDictionaryEntry(dock_state
, key
, list
);
1431 sprintf(buffer
, "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0),
1433 value
= PLMakeString(buffer
);
1434 PLInsertDictionaryEntry(dock_state
, dPosition
, value
);
1440 value
= (dock
->lowered
? dYes
: dNo
);
1441 PLInsertDictionaryEntry(dock_state
, dLowered
, value
);
1443 if (dock
->type
== WM_CLIP
) {
1444 value
= (dock
->collapsed
? dYes
: dNo
);
1445 PLInsertDictionaryEntry(dock_state
, dCollapsed
, value
);
1447 value
= (dock
->auto_collapse
? dYes
: dNo
);
1448 PLInsertDictionaryEntry(dock_state
, dAutoCollapse
, value
);
1450 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1451 PLInsertDictionaryEntry(dock_state
, dAutoRaiseLower
, value
);
1453 value
= (dock
->attract_icons
? dYes
: dNo
);
1454 PLInsertDictionaryEntry(dock_state
, dAutoAttractIcons
, value
);
1462 wDockSaveState(WScreen
*scr
, proplist_t old_state
)
1464 proplist_t dock_state
;
1467 dock_state
= dockSaveState(scr
->dock
);
1470 * Copy saved states of docks with different sizes.
1476 keys
= PLGetAllDictionaryKeys(old_state
);
1477 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
1478 tmp
= PLGetArrayElement(keys
, i
);
1480 if (strncasecmp(PLGetString(tmp
), "applications", 12) == 0
1481 && !PLGetDictionaryEntry(dock_state
, tmp
)) {
1483 PLInsertDictionaryEntry(dock_state
,
1485 PLGetDictionaryEntry(old_state
, tmp
));
1492 PLInsertDictionaryEntry(scr
->session_state
, dDock
, dock_state
);
1494 PLRelease(dock_state
);
1499 wClipSaveState(WScreen
*scr
)
1501 proplist_t clip_state
;
1503 clip_state
= make_icon_state(scr
->clip_icon
);
1505 PLInsertDictionaryEntry(scr
->session_state
, dClip
, clip_state
);
1507 PLRelease(clip_state
);
1512 wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1514 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1519 getBooleanDockValue(proplist_t value
, proplist_t key
)
1522 if (PLIsString(value
)) {
1523 if (strcasecmp(PLGetString(value
), "YES")==0)
1526 wwarning(_("bad value in docked icon state info %s"),
1535 restore_icon_state(WScreen
*scr
, proplist_t info
, int type
, int index
)
1538 char *wclass
, *winstance
;
1539 proplist_t cmd
, value
;
1543 cmd
= PLGetDictionaryEntry(info
, dCommand
);
1544 if (!cmd
|| !PLIsString(cmd
)) {
1548 /* parse window name */
1549 value
= PLGetDictionaryEntry(info
, dName
);
1553 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1555 if (!winstance
&& !wclass
) {
1562 command
= wstrdup(PLGetString(cmd
));
1566 if (!command
|| strcmp(command
, "-")==0) {
1577 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
,
1584 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1585 if (type
== WM_CLIP
) {
1586 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1587 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1589 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1590 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1594 cmd
= PLGetDictionaryEntry(info
, dDropCommand
);
1596 aicon
->dnd_command
= wstrdup(PLGetString(cmd
));
1599 /* check auto launch */
1600 value
= PLGetDictionaryEntry(info
, dAutoLaunch
);
1602 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1605 value
= PLGetDictionaryEntry(info
, dLock
);
1607 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1609 /* check if it wasn't normally docked */
1610 value
= PLGetDictionaryEntry(info
, dForced
);
1612 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1614 /* check if we can rely on the stuff in the app */
1615 value
= PLGetDictionaryEntry(info
, dBuggyApplication
);
1617 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1619 /* get position in the dock */
1620 value
= PLGetDictionaryEntry(info
, dPosition
);
1621 if (value
&& PLIsString(value
)) {
1622 if (sscanf(PLGetString(value
), "%hi,%hi", &aicon
->xindex
,
1624 wwarning(_("bad value in docked icon state info %s"),
1625 PLGetString(dPosition
));
1627 /* check position sanity */
1628 /* incomplete section! */
1629 if (type
== WM_DOCK
) {
1631 if (aicon
->yindex
< 0)
1632 wwarning(_("bad value in docked icon position %i,%i"),
1633 aicon
->xindex
, aicon
->yindex
);
1636 aicon
->yindex
= index
;
1640 /* check if icon is omnipresent */
1641 value
= PLGetDictionaryEntry(info
, dOmnipresent
);
1643 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1652 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1656 wClipRestoreState(WScreen
*scr
, proplist_t clip_state
)
1662 icon
= mainIconCreate(scr
, WM_CLIP
);
1667 PLRetain(clip_state
);
1669 /* restore position */
1671 value
= PLGetDictionaryEntry(clip_state
, dPosition
);
1674 if (!PLIsString(value
))
1675 COMPLAIN("Position");
1677 if (sscanf(PLGetString(value
), "%i,%i", &icon
->x_pos
,
1679 COMPLAIN("Position");
1681 /* check position sanity */
1682 if (icon
->y_pos
< 0)
1684 else if (icon
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1685 icon
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1687 if (icon
->x_pos
< 0)
1689 else if (icon
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1690 icon
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1695 value
= PLGetDictionaryEntry(clip_state
, dDropCommand
);
1696 if (value
&& PLIsString(value
))
1697 icon
->dnd_command
= wstrdup(PLGetString(value
));
1700 PLRelease(clip_state
);
1707 wDockRestoreState(WScreen
*scr
, proplist_t dock_state
, int type
)
1712 WAppIcon
*aicon
, *old_top
;
1716 dock
= wDockCreate(scr
, type
);
1722 PLRetain(dock_state
);
1725 /* restore position */
1727 value
= PLGetDictionaryEntry(dock_state
, dPosition
);
1730 if (!PLIsString(value
))
1731 COMPLAIN("Position");
1733 if (sscanf(PLGetString(value
), "%i,%i", &dock
->x_pos
,
1735 COMPLAIN("Position");
1737 /* check position sanity */
1738 if (dock
->y_pos
< 0)
1740 else if (dock
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1741 dock
->y_pos
= scr
->scr_height
- ICON_SIZE
;
1743 /* This is no more needed. ??? */
1744 if (type
== WM_CLIP
) {
1745 if (dock
->x_pos
< 0)
1747 else if (dock
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1748 dock
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1750 if (dock
->x_pos
>= 0) {
1751 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1752 dock
->on_right_side
= 0;
1754 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1755 dock
->on_right_side
= 1;
1761 /* restore lowered/raised state */
1765 value
= PLGetDictionaryEntry(dock_state
, dLowered
);
1768 if (!PLIsString(value
))
1769 COMPLAIN("Lowered");
1771 if (strcasecmp(PLGetString(value
), "YES")==0)
1777 /* restore collapsed state */
1779 dock
->collapsed
= 0;
1781 value
= PLGetDictionaryEntry(dock_state
, dCollapsed
);
1784 if (!PLIsString(value
))
1785 COMPLAIN("Collapsed");
1787 if (strcasecmp(PLGetString(value
), "YES")==0)
1788 dock
->collapsed
= 1;
1793 /* restore auto-collapsed state */
1795 value
= PLGetDictionaryEntry(dock_state
, dAutoCollapse
);
1798 if (!PLIsString(value
))
1799 COMPLAIN("AutoCollapse");
1801 if (strcasecmp(PLGetString(value
), "YES")==0) {
1802 dock
->auto_collapse
= 1;
1803 dock
->collapsed
= 1;
1809 /* restore auto-raise/lower state */
1811 value
= PLGetDictionaryEntry(dock_state
, dAutoRaiseLower
);
1814 if (!PLIsString(value
))
1815 COMPLAIN("AutoRaiseLower");
1817 if (strcasecmp(PLGetString(value
), "YES")==0) {
1818 dock
->auto_raise_lower
= 1;
1823 /* restore attract icons state */
1825 dock
->attract_icons
= 0;
1827 value
= PLGetDictionaryEntry(dock_state
, dAutoAttractIcons
);
1830 if (!PLIsString(value
))
1831 COMPLAIN("AutoAttractIcons");
1833 if (strcasecmp(PLGetString(value
), "YES")==0)
1834 dock
->attract_icons
= 1;
1839 /* application list */
1846 * When saving, it saves the dock state in
1847 * Applications and Applicationsnnn
1849 * When loading, it will first try Applicationsnnn.
1850 * If it does not exist, use Applications as default.
1853 sprintf(buffer
, "Applications%i", scr
->scr_height
);
1855 tmp
= PLMakeString(buffer
);
1856 apps
= PLGetDictionaryEntry(dock_state
, tmp
);
1860 apps
= PLGetDictionaryEntry(dock_state
, dApplications
);
1868 count
= PLGetNumberOfElements(apps
);
1873 old_top
= dock
->icon_array
[0];
1875 /* dock->icon_count is set to 1 when dock is created.
1876 * Since Clip is already restored, we want to keep it so for clip,
1877 * but for dock we may change the default top tile, so we set it to 0.
1879 if (type
== WM_DOCK
)
1880 dock
->icon_count
= 0;
1882 for (i
=0; i
<count
; i
++) {
1883 if (dock
->icon_count
>= dock
->max_icons
) {
1884 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1888 value
= PLGetArrayElement(apps
, i
);
1889 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1891 dock
->icon_array
[dock
->icon_count
] = aicon
;
1895 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
*ICON_SIZE
);
1896 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
*ICON_SIZE
);
1899 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1901 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1903 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
,
1906 if (!dock
->collapsed
)
1907 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1908 wRaiseFrame(aicon
->icon
->core
);
1911 } else if (dock
->icon_count
==0 && type
==WM_DOCK
)
1915 /* if the first icon is not defined, use the default */
1916 if (dock
->icon_array
[0]==NULL
) {
1917 /* update default icon */
1918 old_top
->x_pos
= dock
->x_pos
;
1919 old_top
->y_pos
= dock
->y_pos
;
1921 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1923 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1924 dock
->icon_array
[0] = old_top
;
1925 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1926 /* we don't need to increment dock->icon_count here because it was
1927 * incremented in the loop above.
1929 } else if (old_top
!=dock
->icon_array
[0]) {
1930 if (old_top
== scr
->clip_icon
)
1931 scr
->clip_icon
= dock
->icon_array
[0];
1932 wAppIconDestroy(old_top
);
1937 PLRelease(dock_state
);
1945 wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1947 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1949 btn
->drop_launch
= 0;
1951 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1954 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1966 wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1972 for (i
= 0; i
< dock
->max_icons
; i
++) {
1973 btn
= dock
->icon_array
[i
];
1974 if (!btn
|| !btn
->auto_launch
)
1977 state
= wmalloc(sizeof(WSavedState
));
1978 memset(state
, 0, sizeof(WSavedState
));
1979 state
->workspace
= workspace
;
1980 /* TODO: this is klugy and is very difficult to understand
1981 * what's going on. Try to clean up */
1982 wDockLaunchWithState(dock
, btn
, state
);
1986 #ifdef REDUCE_APPICONS
1988 wDockSimulateLaunch(WDock
*dock
, WAppIcon
*btn
)
1990 if ((btn
== NULL
) || (dock
== NULL
))
1993 if (!btn
->running
) {
1994 if ((btn
->icon
->owner
== NULL
) && (btn
->applist
))
1995 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
1996 if (!btn
->forced_dock
)
2006 findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
2012 if ((dock
= scr
->dock
)!=NULL
) {
2013 for (i
=0; i
<dock
->max_icons
; i
++) {
2014 if (dock
->icon_array
[i
]
2015 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
2021 if (*icon_pos
<0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
)!=NULL
) {
2022 for (i
=0; i
<dock
->max_icons
; i
++) {
2023 if (dock
->icon_array
[i
]
2024 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
2037 wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
2043 dock
= findDock(scr
, event
, &icon_pos
);
2048 * Return True if the drop was on an application icon window.
2049 * In this case, let the ClientMessage handler redirect the
2050 * message to the app.
2052 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!=None
)
2055 if (dock
->icon_array
[icon_pos
]->dnd_command
!=NULL
) {
2056 scr
->flags
.dnd_data_convertion_status
= 0;
2058 btn
= dock
->icon_array
[icon_pos
];
2060 if (!btn
->forced_dock
) {
2061 btn
->relaunching
= btn
->running
;
2064 if (btn
->wm_instance
|| btn
->wm_class
) {
2065 WWindowAttributes attr
;
2066 memset(&attr
, 0, sizeof(WWindowAttributes
));
2067 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
2069 btn
->wm_class
, &attr
, NULL
, True
);
2071 if (!attr
.no_appicon
)
2077 btn
->drop_launch
= 1;
2078 scr
->last_dock
= dock
;
2079 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
2084 if (!btn
->relaunching
) {
2091 #endif /* OFFIX_DND */
2096 wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2103 wwin
= icon
->icon
->owner
;
2104 if (icon
->command
==NULL
) {
2106 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2108 icon
->command
= FlattenStringList(argv
, argc
);
2109 XFreeStringList(argv
);
2113 /* icon->forced_dock = 1;*/
2114 if (dock
->type
!=WM_CLIP
|| !icon
->attracted
) {
2116 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2117 _("Type the command used to launch the application"),
2119 if (command
&& (command
[0]==0 ||
2120 (command
[0]=='-' && command
[1]==0))) {
2124 icon
->command
= command
;
2130 /* If the target is the dock, reject the icon. If
2131 * the target is the clip, make it an attracted icon
2133 if (dock
->type
==WM_CLIP
) {
2134 icon
->attracted
= 1;
2135 if (!icon
->icon
->shadowed
) {
2136 icon
->icon
->shadowed
= 1;
2137 icon
->icon
->force_paint
= 1;
2149 for (index
=1; index
<dock
->max_icons
; index
++)
2150 if (dock
->icon_array
[index
] == NULL
)
2152 /* if (index == dock->max_icons)
2155 assert(index
< dock
->max_icons
);
2157 dock
->icon_array
[index
] = icon
;
2161 icon
->omnipresent
= 0;
2163 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2164 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2169 icon
->launching
= 0;
2172 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2173 if (dock
->type
== WM_CLIP
) {
2174 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2175 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2177 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2178 icon
->icon
->core
->descriptor
.parent
= icon
;
2180 MoveInStackListUnder(dock
->icon_array
[index
-1]->icon
->core
,
2182 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2183 wAppIconPaint(icon
);
2185 if (wPreferences
.auto_arrange_icons
)
2186 wArrangeIcons(dock
->screen_ptr
, True
);
2189 if (icon
->command
&& !icon
->dnd_command
) {
2190 icon
->dnd_command
= wmalloc(strlen(icon
->command
)+8);
2191 sprintf(icon
->dnd_command
, "%s %%d", icon
->command
);
2200 reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2204 for(index
=1; index
<dock
->max_icons
; index
++) {
2205 if(dock
->icon_array
[index
] == icon
)
2208 assert(index
< dock
->max_icons
);
2213 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2214 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2219 moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2227 return True
; /* No move needed, we're already there */
2232 wwin
= icon
->icon
->owner
;
2235 * For the moment we can't do this if we move icons in Clip from one
2236 * workspace to other, because if we move two or more icons without
2237 * command, the dialog box will not be able to tell us to which of the
2238 * moved icons it applies. -Dan
2240 if ((dest
->type
==WM_DOCK
/*|| dest->keep_attracted*/) && icon
->command
==NULL
) {
2241 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2243 icon
->command
= FlattenStringList(argv
, argc
);
2244 XFreeStringList(argv
);
2249 /* icon->forced_dock = 1;*/
2250 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2251 _("Type the command used to launch the application"),
2253 if (command
&& (command
[0]==0 ||
2254 (command
[0]=='-' && command
[1]==0))) {
2258 icon
->command
= command
;
2269 if (dest
->type
== WM_DOCK
)
2270 wClipMakeIconOmnipresent(icon
, False
);
2272 for(index
=1; index
<src
->max_icons
; index
++) {
2273 if(src
->icon_array
[index
] == icon
)
2276 assert(index
< src
->max_icons
);
2278 src
->icon_array
[index
] = NULL
;
2281 for(index
=1; index
<dest
->max_icons
; index
++) {
2282 if(dest
->icon_array
[index
] == NULL
)
2285 /* if (index == dest->max_icons)
2288 assert(index
< dest
->max_icons
);
2290 dest
->icon_array
[index
] = icon
;
2293 /* deselect the icon */
2294 if (icon
->icon
->selected
)
2295 wIconSelect(icon
->icon
);
2297 if (dest
->type
== WM_DOCK
) {
2298 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2299 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2301 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2302 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2305 /* set it to be kept when moving to dock.
2306 * Unless the icon does not have a command set
2308 if (icon
->command
&& dest
->type
==WM_DOCK
) {
2309 icon
->attracted
= 0;
2310 if (icon
->icon
->shadowed
) {
2311 icon
->icon
->shadowed
= 0;
2312 icon
->icon
->force_paint
= 1;
2316 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2322 icon
->x_pos
= dest
->x_pos
+ x
*ICON_SIZE
;
2323 icon
->y_pos
= dest
->y_pos
+ y
*ICON_SIZE
;
2327 MoveInStackListUnder(dest
->icon_array
[index
-1]->icon
->core
,
2329 wAppIconPaint(icon
);
2336 wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2340 /* make the settings panel be closed */
2342 DestroyDockAppSettingsPanel(icon
->panel
);
2345 /* This must be called before icon->dock is set to NULL.
2346 * Don't move it. -Dan
2348 wClipMakeIconOmnipresent(icon
, False
);
2352 icon
->attracted
= 0;
2353 icon
->auto_launch
= 0;
2354 if (icon
->icon
->shadowed
) {
2355 icon
->icon
->shadowed
= 0;
2356 icon
->icon
->force_paint
= 1;
2359 /* deselect the icon */
2360 if (icon
->icon
->selected
)
2361 wIconSelect(icon
->icon
);
2363 if (icon
->command
) {
2364 free(icon
->command
);
2365 icon
->command
= NULL
;
2368 if (icon
->dnd_command
) {
2369 free(icon
->dnd_command
);
2370 icon
->dnd_command
= NULL
;
2374 for (index
=1; index
<dock
->max_icons
; index
++)
2375 if (dock
->icon_array
[index
] == icon
)
2377 assert(index
< dock
->max_icons
);
2378 dock
->icon_array
[index
] = NULL
;
2384 /* if the dock is not attached to an application or
2385 * the the application did not set the approriate hints yet,
2386 * destroy the icon */
2387 #ifdef REDUCE_APPICONS
2388 if ((icon
->num_apps
== 0) && (!icon
->running
|| !wApplicationOf(icon
->main_window
)) )
2390 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2392 wAppIconDestroy(icon
);
2394 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2395 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2396 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2397 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2398 icon
->icon
->core
->descriptor
.parent
= icon
;
2400 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2402 wAppIconPaint(icon
);
2403 if (wPreferences
.auto_arrange_icons
) {
2404 wArrangeIcons(dock
->screen_ptr
, True
);
2407 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2413 * returns the closest Dock slot index for the passed
2416 * Returns False if icon can't be docked.
2418 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2422 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2423 int *ret_x
, int *ret_y
, int redocking
)
2425 WScreen
*scr
= dock
->screen_ptr
;
2428 int i
, offset
= ICON_SIZE
/2;
2429 WAppIcon
*aicon
= NULL
;
2430 WAppIcon
*nicon
= NULL
;
2431 int max_y_icons
, max_x_icons
;
2433 max_x_icons
= scr
->scr_width
/ICON_SIZE
;
2434 max_y_icons
= scr
->scr_height
/ICON_SIZE
-1;
2436 if (wPreferences
.flags
.noupdates
)
2442 /* if the dock is full */
2444 (dock
->icon_count
>= dock
->max_icons
)) {
2448 /* exact position */
2450 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2452 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2455 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2457 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2459 /* check if the icon is outside the screen boundaries */
2460 if (dx
+ ex_x
*ICON_SIZE
< -ICON_SIZE
+2 ||
2461 dx
+ ex_x
*ICON_SIZE
>= scr
->scr_width
-1 ||
2462 dy
+ ex_y
*ICON_SIZE
< -ICON_SIZE
+2 ||
2463 dy
+ ex_y
*ICON_SIZE
>= scr
->scr_height
-1)
2466 if (dock
->type
== WM_DOCK
) {
2467 if (icon
->dock
!= dock
&& ex_x
!= 0)
2471 for (i
=0; i
<dock
->max_icons
; i
++) {
2472 nicon
= dock
->icon_array
[i
];
2473 if (nicon
&& nicon
->yindex
== ex_y
) {
2480 int sig
, done
, closest
;
2482 /* Possible cases when redocking:
2484 * icon dragged out of range of any slot -> false
2485 * icon dragged to range of free slot
2486 * icon dragged to range of same slot
2487 * icon dragged to range of different icon
2489 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2492 if (ex_y
>=0 && ex_y
<=max_y_icons
&& (aicon
==icon
|| !aicon
)) {
2498 /* start looking at the upper slot or lower? */
2499 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2506 /* look for closest free slot */
2507 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2511 closest
= sig
*(i
/2) + ex_y
;
2512 /* check if this slot is used */
2514 for (j
= 0; j
<dock
->max_icons
; j
++) {
2515 if (dock
->icon_array
[j
]
2516 && dock
->icon_array
[j
]->yindex
==closest
) {
2517 /* slot is used by someone else */
2518 if (dock
->icon_array
[j
]!=icon
)
2526 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2527 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2529 (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+1))) {
2534 } else { /* !redocking */
2536 /* if slot is free and the icon is close enough, return it */
2537 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2547 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2548 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+1;
2551 for (k
=start
; k
<stop
; k
++) {
2552 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2555 for (i
=0; i
<tmp
->max_icons
; i
++) {
2556 nicon
= tmp
->icon_array
[i
];
2557 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2565 for (k
=start
; k
<stop
; k
++) {
2566 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2569 for (i
=0; i
<tmp
->max_icons
; i
++) {
2570 nicon
= tmp
->icon_array
[i
];
2571 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2572 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2573 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2582 if (neighbours
&& (aicon
==NULL
|| (redocking
&& aicon
== icon
))) {
2591 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2592 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2594 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2595 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2596 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2600 * returns true if it can find a free slot in the dock,
2601 * in which case it changes x_pos and y_pos accordingly.
2602 * Else returns false.
2605 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2607 WScreen
*scr
= dock
->screen_ptr
;
2609 WAppIconChain
*chain
;
2610 unsigned char *slot_map
;
2614 int i
, done
= False
;
2616 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2619 if (dock
->type
== WM_CLIP
&&
2620 dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2621 extra_count
= scr
->global_icon_count
;
2623 /* if the dock is full */
2624 if (dock
->icon_count
+extra_count
>= dock
->max_icons
) {
2628 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2629 if (scr
->dock
->on_right_side
)
2630 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2632 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2635 if (ex
< dock
->x_pos
)
2637 if (sx
> dock
->x_pos
+ICON_SIZE
)
2638 sx
= dock
->x_pos
+ICON_SIZE
;
2645 /* check if clip is in a corner */
2646 if (dock
->type
==WM_CLIP
) {
2647 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2649 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2651 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2653 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2660 /* If the clip is in the corner, use only slots that are in the border
2662 if (corner
!=C_NONE
) {
2666 hcount
= MIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2667 vcount
= MIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2668 hmap
= wmalloc(hcount
+1);
2669 memset(hmap
, 0, hcount
+1);
2670 vmap
= wmalloc(vcount
+1);
2671 memset(vmap
, 0, vcount
+1);
2673 /* mark used positions */
2676 for (i
=0; i
<dock
->max_icons
; i
++) {
2677 btn
= dock
->icon_array
[i
];
2681 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2682 vmap
[btn
->yindex
] = 1;
2683 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2684 hmap
[btn
->xindex
] = 1;
2686 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2688 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2689 vmap
[btn
->yindex
] = 1;
2690 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2691 hmap
[btn
->xindex
] = 1;
2695 for (i
=0; i
<dock
->max_icons
; i
++) {
2696 btn
= dock
->icon_array
[i
];
2700 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2701 vmap
[btn
->yindex
] = 1;
2702 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2703 hmap
[-btn
->xindex
] = 1;
2705 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2707 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2708 vmap
[btn
->yindex
] = 1;
2709 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2710 hmap
[-btn
->xindex
] = 1;
2714 for (i
=0; i
<dock
->max_icons
; i
++) {
2715 btn
= dock
->icon_array
[i
];
2719 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2720 vmap
[-btn
->yindex
] = 1;
2721 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2722 hmap
[btn
->xindex
] = 1;
2724 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2726 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2727 vmap
[-btn
->yindex
] = 1;
2728 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2729 hmap
[btn
->xindex
] = 1;
2734 for (i
=0; i
<dock
->max_icons
; i
++) {
2735 btn
= dock
->icon_array
[i
];
2739 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2740 vmap
[-btn
->yindex
] = 1;
2741 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2742 hmap
[-btn
->xindex
] = 1;
2744 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2746 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2747 vmap
[-btn
->yindex
] = 1;
2748 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2749 hmap
[-btn
->xindex
] = 1;
2754 /* search a vacant slot */
2755 for (i
=1; i
<MAX(vcount
, hcount
); i
++) {
2756 if (i
< vcount
&& vmap
[i
]==0) {
2762 } else if (i
< hcount
&& hmap
[i
]==0) {
2772 /* If found a slot, translate and return */
2774 if (corner
==C_NW
|| corner
==C_NE
) {
2779 if (corner
==C_NE
|| corner
==C_SE
) {
2786 /* else, try to find a slot somewhere else */
2789 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2790 * placed outside of screen */
2791 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2793 /* In the worst case (the clip is in the corner of the screen),
2794 * the amount of icons that fit in the clip is smaller.
2795 * Double the map to get a safe value.
2801 slot_map
= wmalloc(mwidth
*mwidth
);
2802 memset(slot_map
, 0, mwidth
*mwidth
);
2804 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2806 /* mark used slots in the map. If the slot falls outside the map
2807 * (for example, when all icons are placed in line), ignore them. */
2808 for (i
=0; i
<dock
->max_icons
; i
++) {
2809 btn
= dock
->icon_array
[i
];
2811 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2813 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2814 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2816 /* Find closest slot from the center that is free by scanning the
2817 * map from the center to outward in circular passes.
2818 * This will not result in a neat layout, but will be optimal
2819 * in the sense that there will not be holes left.
2822 for (i
= 1; i
<= r
&& !done
; i
++) {
2825 /* top and bottom parts of the ring */
2826 for (x
= -i
; x
<= i
&& !done
; x
++) {
2827 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2829 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2830 if (slot_map
[XY2OFS(x
,y
)]==0
2831 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2838 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2839 if (slot_map
[XY2OFS(x
,y
)]==0
2840 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2847 /* left and right parts of the ring */
2848 for (y
= -i
+1; y
<= i
-1; y
++) {
2849 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2851 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2852 if (slot_map
[XY2OFS(x
,y
)]==0
2853 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2860 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2861 if (slot_map
[XY2OFS(x
,y
)]==0
2862 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2877 moveDock(WDock
*dock
, int new_x
, int new_y
)
2882 dock
->x_pos
= new_x
;
2883 dock
->y_pos
= new_y
;
2884 for (i
=0; i
<dock
->max_icons
; i
++) {
2885 btn
= dock
->icon_array
[i
];
2887 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2888 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2889 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2896 swapDock(WDock
*dock
)
2898 WScreen
*scr
= dock
->screen_ptr
;
2903 if (dock
->on_right_side
) {
2904 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2906 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2909 for (i
=0; i
<dock
->max_icons
; i
++) {
2910 btn
= dock
->icon_array
[i
];
2913 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2917 wScreenUpdateUsableArea(scr
);
2922 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2924 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2930 cmdline
= ExpandOptions(scr
, command
);
2932 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2940 ParseCommand(cmdline
, &argv
, &argc
);
2950 if ((pid
=fork())==0) {
2954 SetupEnvironment(scr
);
2960 args
= malloc(sizeof(char*)*(argc
+1));
2963 for (i
=0; i
<argc
; i
++) {
2967 execvp(argv
[0], args
);
2976 state
= wmalloc(sizeof(WSavedState
));
2977 memset(state
, 0, sizeof(WSavedState
));
2979 state
->miniaturized
= -1;
2981 if (btn
->dock
==scr
->dock
|| btn
->omnipresent
)
2982 state
->workspace
= -1;
2984 state
->workspace
= scr
->current_workspace
;
2986 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
2988 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
2999 wDockHideIcons(WDock
*dock
)
3006 for (i
=1; i
<dock
->max_icons
; i
++) {
3007 if (dock
->icon_array
[i
])
3008 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3012 dockIconPaint(dock
->icon_array
[0]);
3017 wDockShowIcons(WDock
*dock
)
3025 btn
= dock
->icon_array
[0];
3026 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
3028 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
3029 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
3031 for (i
=1; i
<dock
->max_icons
; i
++) {
3032 if (dock
->icon_array
[i
]) {
3033 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
3039 if (!dock
->collapsed
) {
3040 for (i
=1; i
<dock
->max_icons
; i
++) {
3041 if (dock
->icon_array
[i
]) {
3042 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3053 wDockLower(WDock
*dock
)
3057 for (i
=0; i
<dock
->max_icons
; i
++) {
3058 if (dock
->icon_array
[i
])
3059 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
3065 wDockRaise(WDock
*dock
)
3069 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
3070 if (dock
->icon_array
[i
])
3071 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
3077 wDockRaiseLower(WDock
*dock
)
3079 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
3080 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
3081 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
3089 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
3091 icon
->launching
= 0;
3092 icon
->relaunching
= 0;
3093 dockIconPaint(icon
);
3098 wDockFindIconForWindow(WDock
*dock
, Window window
)
3103 for (i
=0; i
<dock
->max_icons
; i
++) {
3104 icon
= dock
->icon_array
[i
];
3105 if (icon
&& icon
->main_window
== window
)
3113 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
3116 #ifdef REDUCE_APPICONS
3117 WAppIconAppList
*tapplist
;
3119 char *wm_class
, *wm_instance
;
3121 Bool firstPass
= True
;
3123 char *command
= NULL
;
3129 if (XGetCommand(dpy
, window
, &argv
, &argc
)) {
3130 if (argc
> 0 && argv
!= NULL
)
3131 command
= FlattenStringList(argv
,argc
);
3133 XFreeStringList(argv
);
3138 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
3139 (!wm_class
&& !wm_instance
))
3143 for (i
=0; i
<dock
->max_icons
; i
++) {
3144 icon
= dock
->icon_array
[i
];
3148 /* app is already attached to icon */
3149 if (icon
->main_window
== window
) {
3154 if ((icon
->wm_instance
|| icon
->wm_class
)
3156 || (dock
->screen_ptr
->flags
.startup
&& !icon
->running
))) {
3158 if (icon
->wm_instance
&& wm_instance
&&
3159 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
3162 if (icon
->wm_class
&& wm_class
&&
3163 strcmp(icon
->wm_class
, wm_class
)!=0) {
3166 if (firstPass
&& command
&& strcmp(icon
->command
, command
)!=0) {
3170 if (!icon
->relaunching
) {
3173 /* Possibly an application that was docked with dockit,
3174 * but the user did not update WMState to indicate that
3175 * it was docked by force */
3176 wapp
= wApplicationOf(window
);
3178 icon
->forced_dock
= 1;
3181 if (!icon
->forced_dock
)
3182 icon
->main_window
= window
;
3184 #ifdef REDUCE_APPICONS
3185 tapplist
= wmalloc(sizeof(WAppIconAppList
));
3186 memset(tapplist
, 0, sizeof(WAppIconAppList
));
3187 tapplist
->next
= icon
->applist
;
3189 icon
->applist
->prev
= tapplist
;
3190 icon
->applist
= tapplist
;
3191 tapplist
->wapp
= wApplicationOf(window
);
3196 wDockFinishLaunch(dock
, icon
);
3201 if (firstPass
&& !found
) {
3218 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3220 if (!wPreferences
.flags
.noclip
) {
3221 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3222 if (scr
->current_workspace
!= workspace
) {
3223 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3224 WAppIconChain
*chain
= scr
->global_icons
;
3227 moveIconBetweenDocks(chain
->aicon
->dock
,
3228 scr
->workspaces
[workspace
]->clip
,
3229 chain
->aicon
, chain
->aicon
->xindex
,
3230 chain
->aicon
->yindex
);
3231 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
3232 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3233 chain
= chain
->next
;
3236 wDockHideIcons(old_clip
);
3237 if (old_clip
->auto_raise_lower
) {
3238 if (old_clip
->auto_raise_magic
) {
3239 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3240 old_clip
->auto_raise_magic
= NULL
;
3242 wDockLower(old_clip
);
3244 if (old_clip
->auto_collapse
) {
3245 if (old_clip
->auto_expand_magic
) {
3246 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3247 old_clip
->auto_expand_magic
= NULL
;
3249 old_clip
->collapsed
= 1;
3251 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3253 if (scr
->flags
.clip_balloon_mapped
)
3254 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3261 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3266 for (i
=0; i
<dock
->max_icons
; i
++) {
3267 icon
= dock
->icon_array
[i
];
3271 if (icon
->launching
&& icon
->pid
== pid
) {
3272 if (!icon
->relaunching
) {
3274 icon
->main_window
= None
;
3276 wDockFinishLaunch(dock
, icon
);
3281 sprintf(msg
, _("Could not execute command \"%s\""),
3282 icon
->drop_launch
&& icon
->dnd_command
3283 ? icon
->dnd_command
: icon
->command
);
3285 sprintf(msg
, _("Could not execute command \"%s\""),
3288 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
3289 _("OK"), NULL
, NULL
);
3298 toggleLowered(WDock
*dock
)
3303 /* lower/raise Dock */
3304 if (!dock
->lowered
) {
3305 newlevel
= WMNormalLevel
;
3308 newlevel
= WMDockLevel
;
3312 for (i
=0; i
<dock
->max_icons
; i
++) {
3313 tmp
= dock
->icon_array
[i
];
3317 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3319 wLowerFrame(tmp
->icon
->core
);
3322 if (dock
->type
== WM_DOCK
)
3323 wScreenUpdateUsableArea(dock
->screen_ptr
);
3328 toggleCollapsed(WDock
*dock
)
3330 if (dock
->collapsed
) {
3331 dock
->collapsed
= 0;
3332 wDockShowIcons(dock
);
3335 dock
->collapsed
= 1;
3336 wDockHideIcons(dock
);
3342 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3344 WScreen
*scr
= dock
->screen_ptr
;
3345 WObjDescriptor
*desc
;
3347 WApplication
*wapp
= NULL
;
3351 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3353 if (dock
->type
== WM_DOCK
) {
3355 entry
= dock
->menu
->entries
[index
];
3357 if (dock
->lowered
) {
3358 entry
->text
= _("Keep on Top");
3360 entry
->text
= _("Allow Lowering");
3362 entry
->clientdata
= dock
;
3364 dock
->menu
->flags
.realized
= 0;
3367 if (scr
->clip_options
)
3368 updateClipOptionsMenu(scr
->clip_options
, dock
);
3370 n_selected
= numberOfSelectedIcons(dock
);
3372 /* Rename Workspace */
3373 entry
= dock
->menu
->entries
[++index
];
3374 if (aicon
== scr
->clip_icon
) {
3375 entry
->callback
= renameCallback
;
3376 entry
->clientdata
= dock
;
3377 entry
->flags
.indicator
= 0;
3378 entry
->text
= _("Rename Workspace");
3380 entry
->callback
= omnipresentCallback
;
3381 entry
->clientdata
= aicon
;
3382 if (n_selected
> 0) {
3383 entry
->flags
.indicator
= 0;
3384 entry
->text
= _("Toggle Omnipresent");
3386 entry
->flags
.indicator
= 1;
3387 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3388 entry
->flags
.indicator_type
= MI_CHECK
;
3389 entry
->text
= _("Omnipresent");
3393 /* select/unselect icon */
3394 entry
= dock
->menu
->entries
[++index
];
3395 entry
->clientdata
= aicon
;
3396 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3397 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3399 /* select/unselect all icons */
3400 entry
= dock
->menu
->entries
[++index
];
3401 entry
->clientdata
= aicon
;
3403 entry
->text
= _("Unselect All Icons");
3405 entry
->text
= _("Select All Icons");
3406 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3409 entry
= dock
->menu
->entries
[++index
];
3410 entry
->clientdata
= aicon
;
3412 entry
->text
= _("Keep Icons");
3414 entry
->text
= _("Keep Icon");
3415 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3417 /* this is the workspace submenu part */
3418 entry
= dock
->menu
->entries
[++index
];
3420 entry
->text
= _("Move Icons To");
3422 entry
->text
= _("Move Icon To");
3423 if (scr
->clip_submenu
)
3424 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3425 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3427 /* remove icon(s) */
3428 entry
= dock
->menu
->entries
[++index
];
3429 entry
->clientdata
= aicon
;
3431 entry
->text
= _("Remove Icons");
3433 entry
->text
= _("Remove Icon");
3434 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3436 /* attract icon(s) */
3437 entry
= dock
->menu
->entries
[++index
];
3438 entry
->clientdata
= aicon
;
3440 dock
->menu
->flags
.realized
= 0;
3441 wMenuRealize(dock
->menu
);
3445 entry
= dock
->menu
->entries
[++index
];
3446 entry
->clientdata
= aicon
;
3447 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3450 entry
= dock
->menu
->entries
[++index
];
3451 entry
->clientdata
= aicon
;
3452 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3455 entry
= dock
->menu
->entries
[++index
];
3456 entry
->clientdata
= aicon
;
3457 if (aicon
->icon
->owner
) {
3458 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3459 if (wapp
&& wapp
->flags
.hidden
)
3460 entry
->text
= _("Unhide");
3462 entry
->text
= _("Hide");
3464 entry
->text
= _("Hide");
3466 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3469 entry
= dock
->menu
->entries
[++index
];
3470 entry
->clientdata
= aicon
;
3471 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
3472 && !wPreferences
.flags
.noupdates
);
3475 entry
= dock
->menu
->entries
[++index
];
3476 entry
->clientdata
= aicon
;
3477 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3479 if (!dock
->menu
->flags
.realized
)
3480 wMenuRealize(dock
->menu
);
3482 if (dock
->type
== WM_CLIP
) {
3483 x_pos
= event
->xbutton
.x_root
+2;
3485 x_pos
= dock
->on_right_side
?
3486 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 2 : 0;
3489 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3491 /* allow drag select */
3492 event
->xany
.send_event
= True
;
3493 desc
= &dock
->menu
->menu
->descriptor
;
3494 (*desc
->handle_mousedown
)(desc
, event
);
3499 openClipWorkspaceMenu(WScreen
*scr
, int x
, int y
)
3501 if (!scr
->clip_ws_menu
) {
3502 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3504 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
3505 wMenuMapAt(scr
->clip_ws_menu
, x
, y
, False
);
3509 /******************************************************************/
3511 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3513 WAppIcon
*btn
= desc
->parent
;
3514 WDock
*dock
= btn
->dock
;
3515 WApplication
*wapp
= NULL
;
3518 #ifdef REDUCE_APPICONS
3519 if ((btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) ||
3520 ((btn
->icon
->owner
== NULL
) && (btn
->applist
!= NULL
))) {
3521 if (btn
->icon
->owner
== NULL
)
3522 btn
->icon
->owner
= btn
->applist
->wapp
->main_window_desc
;
3524 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3526 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3530 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3532 /* go to the last workspace that the user worked on the app */
3533 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
3535 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3538 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3541 if (event
->xbutton
.state
& MOD_MASK
) {
3542 wHideOtherApplications(btn
->icon
->owner
);
3545 if (event
->xbutton
.button
==Button1
) {
3547 if (event
->xbutton
.state
& MOD_MASK
) {
3548 /* raise/lower dock */
3549 toggleLowered(dock
);
3550 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3551 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3552 toggleCollapsed(dock
);
3554 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3555 } else if (btn
->command
) {
3556 if (!btn
->launching
&&
3557 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3558 launchDockedApplication(btn
);
3560 } else if (btn
->xindex
== 0 && btn
->yindex
== 0
3561 && btn
->dock
->type
== WM_DOCK
) {
3563 wShowGNUstepPanel(dock
->screen_ptr
);
3571 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3573 WScreen
*scr
= dock
->screen_ptr
;
3574 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3577 int grabbed
= 0, swapped
= 0, done
;
3578 Pixmap ghost
= None
;
3579 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3582 puts("moving dock");
3584 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3585 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3586 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3587 wwarning("pointer grab failed for dock move");
3590 for (x
=0; x
<dock
->max_icons
; x
++) {
3591 if (dock
->icon_array
[x
]!=NULL
&&
3592 dock
->icon_array
[x
]->yindex
> y
)
3593 y
= dock
->icon_array
[x
]->yindex
;
3596 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3600 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3601 |ButtonMotionMask
|ExposureMask
, &ev
);
3609 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3610 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3611 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3612 |ButtonReleaseMask
|ButtonPressMask
,
3613 wCursor
[WCUR_MOVE
], CurrentTime
);
3618 if (dock
->type
== WM_CLIP
) {
3619 if (ev
.xmotion
.x_root
- ofs_x
< 0) {
3621 } else if (ev
.xmotion
.x_root
- ofs_x
+ ICON_SIZE
>
3623 x
= scr
->scr_width
- ICON_SIZE
;
3625 x
= ev
.xmotion
.x_root
- ofs_x
;
3627 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3629 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3631 y
= scr
->scr_height
- ICON_SIZE
;
3633 y
= ev
.xmotion
.y_root
- ofs_y
;
3635 moveDock(dock
, x
, y
);
3637 /* move vertically if pointer is inside the dock*/
3638 if ((dock
->on_right_side
&&
3639 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3640 || (!dock
->on_right_side
&&
3641 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3643 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3645 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3647 y
= scr
->scr_height
- ICON_SIZE
;
3649 y
= ev
.xmotion
.y_root
- ofs_y
;
3651 moveDock(dock
, dock
->x_pos
, y
);
3653 /* move horizontally to change sides */
3654 x
= ev
.xmotion
.x_root
- ofs_x
;
3655 if (!dock
->on_right_side
) {
3659 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3660 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3661 -DOCK_EXTRA_SPACE
-1, dock
->y_pos
);
3662 if (superfluous
&& ghost
==None
) {
3663 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3664 scr
->scr_width
-ICON_SIZE
3665 -DOCK_EXTRA_SPACE
-1,
3667 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3669 XClearWindow(dpy
, scr
->dock_shadow
);
3671 XMapRaised(dpy
, scr
->dock_shadow
);
3674 if (superfluous
&& ghost
!=None
) {
3675 XFreePixmap(dpy
, ghost
);
3678 XUnmapWindow(dpy
, scr
->dock_shadow
);
3683 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3684 XMoveWindow(dpy
, scr
->dock_shadow
,
3685 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3686 if (superfluous
&& ghost
==None
) {
3687 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3688 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3689 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3691 XClearWindow(dpy
, scr
->dock_shadow
);
3693 XMapRaised(dpy
, scr
->dock_shadow
);
3696 XUnmapWindow(dpy
, scr
->dock_shadow
);
3698 if (superfluous
&& ghost
!=None
) {
3699 XFreePixmap(dpy
, ghost
);
3711 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3713 XUngrabPointer(dpy
, CurrentTime
);
3714 XUnmapWindow(dpy
, scr
->dock_shadow
);
3715 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3716 if (dock
->type
== WM_DOCK
) {
3719 dock
->on_right_side
= 1;
3721 dock
->on_right_side
= 0;
3723 wArrangeIcons(scr
, False
);
3732 XFreePixmap(dpy
, ghost
);
3733 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3736 puts("End dock move");
3743 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3745 WScreen
*scr
= dock
->screen_ptr
;
3747 WIcon
*icon
= aicon
->icon
;
3748 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3749 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3751 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3752 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3753 int shad_x
= x
, shad_y
= y
;
3754 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3756 Pixmap ghost
= None
;
3758 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3759 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3762 if (wPreferences
.flags
.noupdates
)
3765 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3766 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3767 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3769 wwarning("pointer grab failed for icon move");
3773 if (!(event
->xbutton
.state
& MOD_MASK
))
3774 wRaiseFrame(icon
->core
);
3776 if (!wPreferences
.flags
.noclip
)
3777 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3779 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3781 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3784 wins
[0] = icon
->core
->window
;
3785 wins
[1] = scr
->dock_shadow
;
3786 XRestackWindows(dpy
, wins
, 2);
3787 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3788 ICON_SIZE
, ICON_SIZE
);
3790 if (icon
->pixmap
!=None
)
3791 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3793 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3795 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3796 XClearWindow(dpy
, scr
->dock_shadow
);
3798 XMapWindow(dpy
, scr
->dock_shadow
);
3804 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3805 |ButtonMotionMask
|ExposureMask
, &ev
);
3813 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3814 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3815 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3816 |ButtonReleaseMask
|ButtonPressMask
,
3817 wCursor
[WCUR_MOVE
], CurrentTime
);
3826 for (i
=0; i
<scr
->workspace_count
; i
++) {
3827 if (i
== scr
->current_workspace
)
3829 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3833 x
= ev
.xmotion
.x_root
- ofs_x
;
3834 y
= ev
.xmotion
.y_root
- ofs_y
;
3835 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3838 if (last_dock
!= dock
&& collapsed
) {
3839 last_dock
->collapsed
= 1;
3840 wDockHideIcons(last_dock
);
3843 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3844 dock
->collapsed
= 0;
3845 wDockShowIcons(dock
);
3847 if (dock
->auto_raise_lower
)
3851 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3854 if (last_dock
!= dock2
&& collapsed
) {
3855 last_dock
->collapsed
= 1;
3856 wDockHideIcons(last_dock
);
3859 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3860 dock2
->collapsed
= 0;
3861 wDockShowIcons(dock2
);
3863 if (dock2
->auto_raise_lower
)
3868 if (aicon
->launching
3870 || (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3871 || (!aicon
->running
&& tmp
)) {
3872 shad_x
= last_dock
->x_pos
+ ix
*wPreferences
.icon_size
;
3873 shad_y
= last_dock
->y_pos
+ iy
*wPreferences
.icon_size
;
3875 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3878 XMapWindow(dpy
, scr
->dock_shadow
);
3883 XUnmapWindow(dpy
, scr
->dock_shadow
);
3887 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3894 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3896 XUngrabPointer(dpy
, CurrentTime
);
3898 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3899 XUnmapWindow(dpy
, scr
->dock_shadow
);
3901 reattachIcon(dock
, aicon
, ix
, iy
);
3902 if (clip
&& dock
!=clip
&& clip
->auto_raise_lower
)
3905 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3907 /* Slide it back if dock rejected it */
3908 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3910 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3912 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3920 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3921 /* We need to deselect it, even if is deselected in
3922 * wDockDetach(), because else DoKaboom() will fail.
3924 if (aicon
->icon
->selected
)
3925 wIconSelect(aicon
->icon
);
3928 wSoundPlay(WMSOUND_KABOOM
);
3930 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3933 wSoundPlay(WMSOUND_UNDOCK
);
3938 wSoundPlay(WMSOUND_UNDOCK
);
3941 if (clip
&& clip
->auto_raise_lower
)
3943 wDockDetach(dock
, aicon
);
3946 last_dock
->collapsed
= 1;
3947 wDockHideIcons(last_dock
);
3952 XFreePixmap(dpy
, ghost
);
3953 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3957 for (i
=0; i
<scr
->workspace_count
; i
++) {
3958 if (i
== scr
->current_workspace
)
3960 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3965 puts("End icon move");
3974 getClipButton(int px
, int py
)
3976 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
3978 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3981 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
3982 return CLIP_FORWARD
;
3983 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
3991 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3994 int done
, direction
, new_ws
;
3996 WDock
*clip
= scr
->clip_icon
->dock
;
3998 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
4000 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
4001 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
4003 wClipIconPaint(scr
->clip_icon
);
4006 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
4007 |ButtonPressMask
, &ev
);
4014 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
4015 if (new_dir
!= direction
) {
4016 direction
= new_dir
;
4017 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
4018 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
4019 wClipIconPaint(scr
->clip_icon
);
4027 if (ev
.xbutton
.button
== event
->xbutton
.button
)
4032 clip
->lclip_button_pushed
= 0;
4033 clip
->rclip_button_pushed
= 0;
4035 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
4037 if (direction
== CLIP_FORWARD
) {
4038 if (scr
->current_workspace
< scr
->workspace_count
-1)
4039 wWorkspaceChange(scr
, scr
->current_workspace
+1);
4040 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
4041 wWorkspaceChange(scr
, scr
->current_workspace
+1);
4042 else if (wPreferences
.ws_cycle
)
4043 wWorkspaceChange(scr
, 0);
4045 else if (direction
== CLIP_REWIND
) {
4046 if (scr
->current_workspace
> 0)
4047 wWorkspaceChange(scr
, scr
->current_workspace
-1);
4048 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
4049 wWorkspaceChange(scr
, scr
->workspace_count
-1);
4052 wClipIconPaint(scr
->clip_icon
);
4057 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
4059 WAppIcon
*aicon
= desc
->parent
;
4060 WDock
*dock
= aicon
->dock
;
4061 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4063 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
4066 scr
->last_dock
= dock
;
4068 if (dock
->menu
->flags
.mapped
)
4069 wMenuUnmap(dock
->menu
);
4071 if (IsDoubleClick(scr
, event
)) {
4072 /* double-click was not in the main clip icon */
4073 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
4074 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
4075 iconDblClick(desc
, event
);
4080 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
4081 XUnmapWindow(dpy
, scr
->clip_balloon
);
4082 scr
->flags
.clip_balloon_mapped
= 0;
4086 puts("handling dock");
4088 if (event
->xbutton
.button
== Button1
) {
4089 if (event
->xbutton
.state
& MOD_MASK
)
4094 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
4095 dock
->type
!=WM_DOCK
) {
4096 wIconSelect(aicon
->icon
);
4100 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
4101 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
4102 && dock
->type
==WM_CLIP
)
4103 handleClipChangeWorkspace(scr
, event
);
4105 handleDockMove(dock
, aicon
, event
);
4107 handleIconMove(dock
, aicon
, event
);
4109 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4110 aicon
==scr
->clip_icon
) {
4111 openClipWorkspaceMenu(scr
, event
->xbutton
.x_root
+2,
4112 event
->xbutton
.y_root
+2);
4113 if (scr
->clip_ws_menu
) {
4115 menu
= scr
->clip_ws_menu
;
4116 desc
= &menu
->menu
->descriptor
;
4118 event
->xany
.send_event
= True
;
4119 (*desc
->handle_mousedown
)(desc
, event
);
4121 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4122 (event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
) {
4123 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
4124 } else if (event
->xbutton
.button
== Button3
) {
4125 openDockMenu(dock
, aicon
, event
);
4131 showClipBalloon(WDock
*dock
, int workspace
)
4135 WScreen
*scr
= dock
->screen_ptr
;
4139 scr
->flags
.clip_balloon_mapped
= 1;
4140 XMapWindow(dpy
, scr
->clip_balloon
);
4142 text
= scr
->workspaces
[workspace
]->name
;
4144 w
= WMWidthOfString(scr
->clip_title_font
, text
, strlen(text
));
4146 h
= WMFontHeight(scr
->clip_title_font
);
4147 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
4149 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
4150 y
= dock
->y_pos
+ ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
4152 if (x
+w
> scr
->scr_width
) {
4153 x
= scr
->scr_width
- w
;
4154 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
4155 y
= dock
->y_pos
- h
- 1;
4157 y
= dock
->y_pos
+ ICON_SIZE
;
4158 XRaiseWindow(dpy
, scr
->clip_balloon
);
4160 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
4161 stack
[1] = scr
->clip_balloon
;
4162 XRestackWindows(dpy
, stack
, 2);
4164 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
4165 XSetForeground(dpy
, scr
->clip_title_gc
,
4166 scr
->clip_title_pixel
[CLIP_NORMAL
]);
4167 XClearWindow(dpy
, scr
->clip_balloon
);
4168 WMDrawString(scr
->wmscreen
, scr
->clip_balloon
, scr
->clip_title_gc
,
4169 scr
->clip_title_font
, 0, 0, text
, strlen(text
));
4174 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
4176 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4180 assert(event
->type
==EnterNotify
);
4182 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4185 scr
= btn
->icon
->core
->screen_ptr
;
4186 if (!btn
->omnipresent
)
4189 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
4191 if (!dock
|| dock
->type
!=WM_CLIP
)
4194 /* The auto raise/lower code */
4195 if (dock
->auto_lower_magic
) {
4196 WMDeleteTimerHandler(dock
->auto_lower_magic
);
4197 dock
->auto_lower_magic
= NULL
;
4199 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
4200 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
,
4205 /* The auto expand/collapse code */
4206 if (dock
->auto_collapse_magic
) {
4207 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
4208 dock
->auto_collapse_magic
= NULL
;
4210 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
4211 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
,
4216 if (btn
->xindex
== 0 && btn
->yindex
== 0)
4217 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4219 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4220 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
4221 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
4228 clipLeave(WDock
*dock
)
4231 WObjDescriptor
*desc
= NULL
;
4233 if (!dock
|| dock
->type
!=WM_CLIP
)
4236 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
)!=False
) {
4237 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
4238 (XPointer
*)&desc
)!=XCNOENT
4239 && desc
&& desc
->parent_type
==WCLASS_DOCK_ICON
4240 && ((WAppIcon
*)desc
->parent
)->dock
4241 && ((WAppIcon
*)desc
->parent
)->dock
->type
==WM_CLIP
) {
4242 /* We didn't left the Clip yet */
4243 XPutBackEvent(dpy
, &event
);
4247 XPutBackEvent(dpy
, &event
);
4249 /* We entered a withdrawn window, so we're still in Clip */
4253 if (dock
->auto_raise_magic
) {
4254 WMDeleteTimerHandler(dock
->auto_raise_magic
);
4255 dock
->auto_raise_magic
= NULL
;
4257 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
4258 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
,
4263 if (dock
->auto_expand_magic
) {
4264 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4265 dock
->auto_expand_magic
= NULL
;
4267 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
4268 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
4276 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4278 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4280 assert(event
->type
==LeaveNotify
);
4282 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4285 clipLeave(btn
->dock
);
4290 clipAutoCollapse(void *cdata
)
4292 WDock
*dock
= (WDock
*)cdata
;
4294 if (dock
->type
!=WM_CLIP
)
4297 if (dock
->auto_collapse
) {
4298 dock
->collapsed
= 1;
4299 wDockHideIcons(dock
);
4301 dock
->auto_collapse_magic
= NULL
;
4306 clipAutoExpand(void *cdata
)
4308 WDock
*dock
= (WDock
*)cdata
;
4310 if (dock
->type
!=WM_CLIP
)
4313 if (dock
->auto_collapse
) {
4314 dock
->collapsed
= 0;
4315 wDockShowIcons(dock
);
4317 dock
->auto_expand_magic
= NULL
;
4322 clipAutoLower(void *cdata
)
4324 WDock
*dock
= (WDock
*)cdata
;
4326 if (dock
->type
!=WM_CLIP
)
4329 if (dock
->auto_raise_lower
)
4332 dock
->auto_lower_magic
= NULL
;
4337 clipAutoRaise(void *cdata
)
4339 WDock
*dock
= (WDock
*)cdata
;
4341 if (dock
->type
!=WM_CLIP
)
4344 if (dock
->auto_raise_lower
)
4347 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4348 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4351 dock
->auto_raise_magic
= NULL
;
4356 iconCanBeOmnipresent(WAppIcon
*aicon
)
4358 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4363 for (i
=0; i
<scr
->workspace_count
; i
++) {
4364 clip
= scr
->workspaces
[i
]->clip
;
4366 if (clip
== aicon
->dock
)
4369 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4370 return False
; /* Clip is full in some workspace */
4372 for (j
=0; j
<clip
->max_icons
; j
++) {
4373 btn
= clip
->icon_array
[j
];
4374 if(btn
&& btn
->xindex
==aicon
->xindex
&& btn
->yindex
==aicon
->yindex
)
4384 wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
4386 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4387 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4388 int status
= WO_SUCCESS
;
4390 if ((scr
->dock
&& aicon
->dock
==scr
->dock
) || aicon
==scr
->clip_icon
) {
4391 return WO_NOT_APPLICABLE
;
4394 if (aicon
->omnipresent
== omnipresent
)
4398 if (iconCanBeOmnipresent(aicon
)) {
4399 aicon
->omnipresent
= 1;
4400 new_entry
= wmalloc(sizeof(WAppIconChain
));
4401 new_entry
->aicon
= aicon
;
4402 new_entry
->next
= scr
->global_icons
;
4403 scr
->global_icons
= new_entry
;
4404 scr
->global_icon_count
++;
4406 aicon
->omnipresent
= 0;
4410 aicon
->omnipresent
= 0;
4411 if (aicon
== scr
->global_icons
->aicon
) {
4412 tmp
= scr
->global_icons
->next
;
4413 free(scr
->global_icons
);
4414 scr
->global_icons
= tmp
;
4415 scr
->global_icon_count
--;
4417 tmp
= scr
->global_icons
;
4419 if (tmp
->next
->aicon
== aicon
) {
4420 tmp1
= tmp
->next
->next
;
4423 scr
->global_icon_count
--;
4431 wAppIconPaint(aicon
);