1 /* dock.c- built-in Dock module for WindowMaker
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 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"
62 /**** Local variables ****/
65 #define CLIP_FORWARD 2
68 /**** Global variables ****/
71 extern void DestroyDockAppSettingsPanel();
73 extern void ShowDockAppSettingsPanel(WAppIcon
*aicon
);
76 extern XContext wWinContext
;
78 extern Cursor wCursor
[WCUR_LAST
];
80 extern WPreferences wPreferences
;
82 extern XContext wWinContext
;
85 extern Atom _XA_DND_PROTOCOL
;
89 #define MOD_MASK wPreferences.modifier_mask
91 extern void appIconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
93 #define ICON_SIZE wPreferences.icon_size
96 /***** Local variables ****/
98 static WMPropList
*dCommand
=NULL
;
99 static WMPropList
*dPasteCommand
=NULL
;
101 static WMPropList
*dDropCommand
=NULL
;
103 static WMPropList
*dAutoLaunch
, *dLock
;
104 static WMPropList
*dName
, *dForced
, *dBuggyApplication
, *dYes
, *dNo
;
105 static WMPropList
*dHost
, *dDock
, *dClip
;
106 static WMPropList
*dAutoAttractIcons
;
108 static WMPropList
*dPosition
, *dApplications
, *dLowered
, *dCollapsed
;
110 static WMPropList
*dAutoCollapse
, *dAutoRaiseLower
, *dOmnipresent
;
112 static void dockIconPaint(WAppIcon
*btn
);
114 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
116 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
);
118 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
120 static int getClipButton(int px
, int py
);
122 static void toggleLowered(WDock
*dock
);
124 static void toggleCollapsed(WDock
*dock
);
126 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
128 static void clipLeave(WDock
*dock
);
130 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
132 Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
);
134 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
135 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
136 static void clipAutoCollapse(void *cdata
);
137 static void clipAutoExpand(void *cdata
);
138 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
);
140 static void clipAutoLower(void *cdata
);
141 static void clipAutoRaise(void *cdata
);
143 static void showClipBalloon(WDock
*dock
, int workspace
);
159 #endif /* OFFIX_DND */
169 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
170 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
171 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
172 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
173 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
174 dName
= WMRetainPropList(WMCreatePLString("Name"));
175 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
176 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
177 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
178 dNo
= WMRetainPropList(WMCreatePLString("No"));
179 dHost
= WMRetainPropList(WMCreatePLString("Host"));
181 dPosition
= WMCreatePLString("Position");
182 dApplications
= WMCreatePLString("Applications");
183 dLowered
= WMCreatePLString("Lowered");
184 dCollapsed
= WMCreatePLString("Collapsed");
185 dAutoCollapse
= WMCreatePLString("AutoCollapse");
186 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
187 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
189 dOmnipresent
= WMCreatePLString("Omnipresent");
191 dDock
= WMCreatePLString("Dock");
192 dClip
= WMCreatePLString("Clip");
198 renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
200 WDock
*dock
= entry
->clientdata
;
205 assert(entry
->clientdata
!=NULL
);
207 wspace
= dock
->screen_ptr
->current_workspace
;
209 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
211 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+1);
212 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
,
214 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
223 toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
225 assert(entry
->clientdata
!=NULL
);
227 toggleLowered(entry
->clientdata
);
229 entry
->flags
.indicator_on
= !(((WDock
*)entry
->clientdata
)->lowered
);
236 matchWindow(void *item
, void *cdata
)
238 return (((WFakeGroupLeader
*)item
)->leader
== (Window
)cdata
);
243 killCallback(WMenu
*menu
, WMenuEntry
*entry
)
245 WScreen
*scr
= menu
->menu
->screen_ptr
;
247 WFakeGroupLeader
*fPtr
;
250 if (!WCHECK_STATE(WSTATE_NORMAL
))
253 assert(entry
->clientdata
!=NULL
);
255 icon
= (WAppIcon
*)entry
->clientdata
;
259 WCHANGE_STATE(WSTATE_MODAL
);
261 buffer
= wstrconcat(icon
->wm_class
,
262 _(" will be forcibly closed.\n"
263 "Any unsaved changes will be lost.\n"
266 if (icon
->icon
&& icon
->icon
->owner
) {
267 fPtr
= icon
->icon
->owner
->fake_group
;
269 /* is this really necessary? can we kill a non-running dock icon? */
270 Window win
= icon
->main_window
;
273 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void*)win
);
274 if (index
!= WANotFound
)
275 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
280 if (wPreferences
.dont_confirm_kill
281 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
282 buffer
, _("Yes"), _("No"), NULL
)==WAPRDefault
) {
284 WWindow
*wwin
, *twin
;
286 wwin
= scr
->focused_window
;
289 if (wwin
->fake_group
== fPtr
) {
294 } else if (icon
->icon
&& icon
->icon
->owner
) {
295 wClientKill(icon
->icon
->owner
);
303 WCHANGE_STATE(WSTATE_NORMAL
);
307 /* TODO: replace this function with a member of the dock struct */
309 numberOfSelectedIcons(WDock
*dock
)
315 for (i
=1; i
<dock
->max_icons
; i
++) {
316 aicon
= dock
->icon_array
[i
];
317 if (aicon
&& aicon
->icon
->selected
) {
327 getSelected(WDock
*dock
)
329 WMArray
*ret
= WMCreateArray(8);
333 for (i
=1; i
<dock
->max_icons
; i
++) {
334 btn
= dock
->icon_array
[i
];
335 if (btn
&& btn
->icon
->selected
) {
336 WMAddToArray(ret
, btn
);
345 paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
347 Window win
= clipIcon
->icon
->core
->window
;
348 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
350 int pt
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
351 int tp
= ICON_SIZE
- pt
;
352 int as
= pt
- 15; /* 15 = 5+5+5 */
353 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
355 #ifdef GRADIENT_CLIP_ARROW
356 Bool collapsed
= clipIcon
->dock
->collapsed
;
359 //if (!clipIcon->dock->collapsed)
360 // color = scr->clip_title_color[CLIP_NORMAL];
362 // color = scr->clip_title_color[CLIP_COLLAPSED];
363 color
= scr
->clip_title_color
[CLIP_NORMAL
];
365 XSetForeground(dpy
, gc
, WMColorPixel(color
));
370 p
[1].x
= ICON_SIZE
-2;
372 p
[2].x
= ICON_SIZE
-2;
374 } else if (lpushed
) {
378 p
[1].y
= ICON_SIZE
-2;
380 p
[2].y
= ICON_SIZE
-2;
382 if (lpushed
|| rpushed
) {
383 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
384 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
385 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
387 #ifdef GRADIENT_CLIP_ARROW
389 XSetFillStyle(dpy
, scr
->copy_gc
, FillTiled
);
390 XSetTile(dpy
, scr
->copy_gc
, scr
->clip_arrow_gradient
);
391 XSetClipMask(dpy
, scr
->copy_gc
, None
);
394 #endif /* GRADIENT_CLIP_ARROW */
396 /* top right arrow */
397 p
[0].x
= p
[3].x
= ICON_SIZE
-5-as
;
399 p
[1].x
= ICON_SIZE
-6;
401 p
[2].x
= ICON_SIZE
-6;
404 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
405 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
407 #ifdef GRADIENT_CLIP_ARROW
409 XSetTSOrigin(dpy
, gc
, ICON_SIZE
-6-as
, 5);
411 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
412 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
415 /* bottom left arrow */
417 p
[0].y
= p
[3].y
= ICON_SIZE
-5-as
;
419 p
[1].y
= ICON_SIZE
-6;
421 p
[2].y
= ICON_SIZE
-6;
423 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
424 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
426 #ifdef GRADIENT_CLIP_ARROW
428 XSetTSOrigin(dpy
, gc
, 5, ICON_SIZE
-6-as
);
430 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
431 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
433 #ifdef GRADIENT_CLIP_ARROW
435 XSetFillStyle(dpy
, scr
->copy_gc
, FillSolid
);
441 wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
443 RImage
*tile
= RCloneImage(normalTile
);
450 pt
= CLIP_BUTTON_SIZE
*wPreferences
.icon_size
/64;
451 tp
= wPreferences
.icon_size
-1 - pt
;
455 black
.red
= black
.green
= black
.blue
= 0;
458 dark
.red
= dark
.green
= dark
.blue
= 60;
461 light
.red
= light
.green
= light
.blue
= 80;
465 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
-2,
467 RDrawLine(tile
, tp
-1, 0, wPreferences
.icon_size
-1, pt
+1, &black
);
468 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
-3,
472 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4,
473 ICON_SIZE
- 5, 4, &dark
);
474 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5,
475 ICON_SIZE
- 5, 6 + as
, &dark
);
476 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
,
480 ROperateLine(tile
, RAddOperation
, 2, tp
+2, pt
-2,
481 wPreferences
.icon_size
-3, &dark
);
482 RDrawLine(tile
, 0, tp
-1, pt
+1, wPreferences
.icon_size
-1, &black
);
483 ROperateLine(tile
, RSubtractOperation
, 0, tp
-2, pt
+1,
484 wPreferences
.icon_size
-2, &light
);
487 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4,
488 ICON_SIZE
- 5, &dark
);
489 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
,
490 6 + as
, ICON_SIZE
- 5, &dark
);
491 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5,
499 omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
501 WAppIcon
*clickedIcon
= entry
->clientdata
;
504 WMArray
*selectedIcons
;
505 WMArrayIterator iter
;
508 assert(entry
->clientdata
!=NULL
);
510 dock
= clickedIcon
->dock
;
512 selectedIcons
= getSelected(dock
);
514 if (!WMGetArrayItemCount(selectedIcons
))
515 WMAddToArray(selectedIcons
, clickedIcon
);
518 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
519 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
521 else if (aicon
->icon
->selected
)
522 wIconSelect(aicon
->icon
);
524 WMFreeArray(selectedIcons
);
527 wMessageDialog(dock
->screen_ptr
, _("Warning"),
528 _("Some icons cannot be made omnipresent. "
529 "Please make sure that no other icon is "
530 "docked in the same positions on the other "
531 "workspaces and the Clip is not full in "
533 _("OK"), NULL
, NULL
);
534 } else if (failed
== 1) {
535 wMessageDialog(dock
->screen_ptr
, _("Warning"),
536 _("Icon cannot be made omnipresent. "
537 "Please make sure that no other icon is "
538 "docked in the same position on the other "
539 "workspaces and the Clip is not full in "
541 _("OK"), NULL
, NULL
);
547 removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
549 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
552 WMArray
*selectedIcons
;
556 assert(clickedIcon
!=NULL
);
558 dock
= clickedIcon
->dock
;
560 selectedIcons
= getSelected(dock
);
562 if (WMGetArrayItemCount(selectedIcons
)) {
563 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
564 _("All selected icons will be removed!"),
565 _("OK"), _("Cancel"), NULL
)!=WAPRDefault
) {
566 WMFreeArray(selectedIcons
);
570 if (clickedIcon
->xindex
==0 && clickedIcon
->yindex
==0) {
571 WMFreeArray(selectedIcons
);
574 WMAddToArray(selectedIcons
, clickedIcon
);
577 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
578 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
579 wDockDetach(dock
, aicon
);
581 /* XXX: can: aicon->icon == NULL ? */
582 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
, wGetHeadForWindow(aicon
->icon
->owner
));
583 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
584 aicon
->x_pos
, aicon
->y_pos
);
585 if (!dock
->mapped
|| dock
->collapsed
)
586 XMapWindow(dpy
, aicon
->icon
->core
->window
);
589 WMFreeArray(selectedIcons
);
591 if (wPreferences
.auto_arrange_icons
)
592 wArrangeIcons(dock
->screen_ptr
, True
);
597 keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
599 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
602 WMArray
*selectedIcons
;
605 assert(clickedIcon
!=NULL
);
606 dock
= clickedIcon
->dock
;
608 selectedIcons
= getSelected(dock
);
610 if (!WMGetArrayItemCount(selectedIcons
)
611 && clickedIcon
!=dock
->screen_ptr
->clip_icon
) {
612 char *command
= NULL
;
614 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
615 clickedIcon
->editing
= 1;
616 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
617 _("Type the command used to launch the application"),
619 if (command
&& (command
[0]==0 ||
620 (command
[0]=='-' && command
[1]==0))) {
624 clickedIcon
->command
= command
;
625 clickedIcon
->editing
= 0;
627 clickedIcon
->editing
= 0;
630 WMFreeArray(selectedIcons
);
635 WMAddToArray(selectedIcons
, clickedIcon
);
638 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
639 if (aicon
->icon
->selected
)
640 wIconSelect(aicon
->icon
);
641 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
642 aicon
->attracted
= 0;
643 if (aicon
->icon
->shadowed
) {
644 aicon
->icon
->shadowed
= 0;
645 aicon
->icon
->force_paint
= 1;
646 wAppIconPaint(aicon
);
650 WMFreeArray(selectedIcons
);
657 toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
659 WDock
*dock
= (WDock
*)entry
->clientdata
;
661 assert(entry
->clientdata
!=NULL
);
663 dock
->attract_icons
= !dock
->attract_icons
;
664 /*if (!dock->attract_icons)
665 dock->keep_attracted = 0;*/
667 entry
->flags
.indicator_on
= dock
->attract_icons
;
674 selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
676 WAppIcon
*icon
= (WAppIcon
*)entry
->clientdata
;
680 wIconSelect(icon
->icon
);
687 colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
689 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
692 int x
, y
, x_pos
, y_pos
;
694 assert(entry
->clientdata
!=NULL
);
695 clip
= clickedIcon
->dock
;
697 aicon
= clip
->screen_ptr
->app_icon_list
;
700 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
701 x_pos
= clip
->x_pos
+ x
*ICON_SIZE
;
702 y_pos
= clip
->y_pos
+ y
*ICON_SIZE
;
703 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
705 if (wPreferences
.no_animations
) {
706 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
708 SlideWindow(aicon
->icon
->core
->window
,
709 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
712 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
713 #endif /* ANIMATIONS */
715 aicon
->attracted
= 1;
716 if (!aicon
->icon
->shadowed
) {
717 aicon
->icon
->shadowed
= 1;
718 aicon
->icon
->force_paint
= 1;
719 /* We don't do an wAppIconPaint() here because it's in
720 * wDockAttachIcon(). -Dan
723 wDockAttachIcon(clip
, aicon
, x
, y
);
724 if (clip
->collapsed
|| !clip
->mapped
)
725 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
733 selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
735 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
737 WMArray
*selectedIcons
;
738 WMArrayIterator iter
;
742 assert(clickedIcon
!=NULL
);
743 dock
= clickedIcon
->dock
;
745 selectedIcons
= getSelected(dock
);
747 if (!WMGetArrayItemCount(selectedIcons
)) {
748 for (i
=1; i
<dock
->max_icons
; i
++) {
749 btn
= dock
->icon_array
[i
];
750 if (btn
&& !btn
->icon
->selected
) {
751 wIconSelect(btn
->icon
);
755 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
756 wIconSelect(btn
->icon
);
759 WMFreeArray(selectedIcons
);
766 toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
768 assert(entry
->clientdata
!=NULL
);
770 toggleCollapsed(entry
->clientdata
);
772 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->collapsed
;
779 toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
782 assert(entry
->clientdata
!=NULL
);
784 dock
= (WDock
*) entry
->clientdata
;
786 dock
->auto_collapse
= !dock
->auto_collapse
;
788 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_collapse
;
795 toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
798 assert(entry
->clientdata
!=NULL
);
800 dock
= (WDock
*) entry
->clientdata
;
802 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
804 entry
->flags
.indicator_on
= ((WDock
*)entry
->clientdata
)->auto_raise_lower
;
811 launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
813 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
815 launchDockedApplication(btn
, False
);
820 settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
822 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
826 ShowDockAppSettingsPanel(btn
);
831 hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
834 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
836 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
838 if (wapp
->flags
.hidden
) {
839 wWorkspaceChange(btn
->icon
->core
->screen_ptr
, wapp
->last_workspace
);
840 wUnhideApplication(wapp
, False
, False
);
842 wHideApplication(wapp
);
848 unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
851 WAppIcon
*btn
= (WAppIcon
*)entry
->clientdata
;
853 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
855 wUnhideApplication(wapp
, False
, True
);
860 mainIconCreate(WScreen
*scr
, int type
)
865 if (type
== WM_CLIP
) {
867 return scr
->clip_icon
;
868 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
869 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
870 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
871 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
872 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE;*/
875 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
876 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
882 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
883 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
884 btn
->icon
->core
->descriptor
.parent
= btn
;
885 /*ChangeStackingLevel(btn->icon->core, WMDockLevel);*/
886 XMapWindow(dpy
, btn
->icon
->core
->window
);
891 scr
->clip_icon
= btn
;
898 switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
900 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
901 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
903 WMArray
*selectedIcons
;
906 if (entry
->order
== scr
->current_workspace
)
909 dest
= scr
->workspaces
[entry
->order
]->clip
;
911 selectedIcons
= getSelected(src
);
913 if (WMGetArrayItemCount(selectedIcons
)) {
914 WMArrayIterator iter
;
916 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
917 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
918 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
919 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
922 } else if (icon
!= scr
->clip_icon
) {
923 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
924 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
925 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
928 WMFreeArray(selectedIcons
);
934 launchDockedApplication(WAppIcon
*btn
, Bool withSelection
)
936 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
938 if (!btn
->launching
&&
939 ((!withSelection
&& btn
->command
!=NULL
) ||
940 (withSelection
&& btn
->paste_command
!=NULL
))) {
941 if (!btn
->forced_dock
) {
942 btn
->relaunching
= btn
->running
;
945 if (btn
->wm_instance
|| btn
->wm_class
) {
946 WWindowAttributes attr
;
947 memset(&attr
, 0, sizeof(WWindowAttributes
));
948 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
,
951 if (!attr
.no_appicon
&& !btn
->buggy_app
)
956 btn
->drop_launch
= 0;
957 btn
->paste_launch
= withSelection
;
958 scr
->last_dock
= btn
->dock
;
959 btn
->pid
= execCommand(btn
,
960 withSelection
? btn
->paste_command
: btn
->command
,
963 if (btn
->buggy_app
) {
964 /* give feedback that the app was launched */
968 WMAddTimerHandler(200, (WMCallback
*)dockIconPaint
, btn
);
973 wwarning(_("could not launch application %s\n"), btn
->command
);
975 if (!btn
->relaunching
)
984 updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
986 WScreen
*scr
= menu
->frame
->screen_ptr
;
987 char title
[MAX_WORKSPACENAME_WIDTH
+1];
993 for (i
=0; i
<scr
->workspace_count
; i
++) {
994 if (i
< menu
->entry_no
) {
995 if (strcmp(menu
->entries
[i
]->text
,scr
->workspaces
[i
]->name
)!=0) {
996 wfree(menu
->entries
[i
]->text
);
997 strcpy(title
, scr
->workspaces
[i
]->name
);
998 menu
->entries
[i
]->text
= wstrdup(title
);
999 menu
->flags
.realized
= 0;
1001 menu
->entries
[i
]->clientdata
= (void*)icon
;
1003 strcpy(title
, scr
->workspaces
[i
]->name
);
1005 wMenuAddCallback(menu
, title
, switchWSCommand
, (void*)icon
);
1007 menu
->flags
.realized
= 0;
1009 if (i
== scr
->current_workspace
) {
1010 wMenuSetEnabled(menu
, i
, False
);
1012 wMenuSetEnabled(menu
, i
, True
);
1016 if (!menu
->flags
.realized
)
1022 makeWorkspaceMenu(WScreen
*scr
)
1026 menu
= wMenuCreate(scr
, NULL
, False
);
1028 wwarning(_("could not create workspace submenu for Clip menu"));
1030 wMenuAddCallback(menu
, "", switchWSCommand
, (void*)scr
->clip_icon
);
1032 menu
->flags
.realized
= 0;
1040 updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
1049 entry
= menu
->entries
[index
];
1050 entry
->flags
.indicator_on
= !dock
->lowered
;
1051 entry
->clientdata
= dock
;
1054 entry
= menu
->entries
[++index
];
1055 entry
->flags
.indicator_on
= dock
->collapsed
;
1056 entry
->clientdata
= dock
;
1059 entry
= menu
->entries
[++index
];
1060 entry
->flags
.indicator_on
= dock
->auto_collapse
;
1061 entry
->clientdata
= dock
;
1063 /* auto-raise/lower */
1064 entry
= menu
->entries
[++index
];
1065 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1066 entry
->clientdata
= dock
;
1067 wMenuSetEnabled(menu
, index
, dock
->lowered
);
1070 entry
= menu
->entries
[++index
];
1071 entry
->flags
.indicator_on
= dock
->attract_icons
;
1072 entry
->clientdata
= dock
;
1074 menu
->flags
.realized
= 0;
1080 makeClipOptionsMenu(WScreen
*scr
)
1085 menu
= wMenuCreate(scr
, NULL
, False
);
1087 wwarning(_("could not create options submenu for Clip menu"));
1091 entry
= wMenuAddCallback(menu
, _("Keep on Top"),
1092 toggleLoweredCallback
, NULL
);
1093 entry
->flags
.indicator
= 1;
1094 entry
->flags
.indicator_on
= 1;
1095 entry
->flags
.indicator_type
= MI_CHECK
;
1097 entry
= wMenuAddCallback(menu
, _("Collapsed"),
1098 toggleCollapsedCallback
, NULL
);
1099 entry
->flags
.indicator
= 1;
1100 entry
->flags
.indicator_on
= 1;
1101 entry
->flags
.indicator_type
= MI_CHECK
;
1103 entry
= wMenuAddCallback(menu
, _("Autocollapse"),
1104 toggleAutoCollapseCallback
, NULL
);
1105 entry
->flags
.indicator
= 1;
1106 entry
->flags
.indicator_on
= 1;
1107 entry
->flags
.indicator_type
= MI_CHECK
;
1109 entry
= wMenuAddCallback(menu
, _("Autoraise"),
1110 toggleAutoRaiseLowerCallback
, NULL
);
1111 entry
->flags
.indicator
= 1;
1112 entry
->flags
.indicator_on
= 1;
1113 entry
->flags
.indicator_type
= MI_CHECK
;
1115 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"),
1116 toggleAutoAttractCallback
, NULL
);
1117 entry
->flags
.indicator
= 1;
1118 entry
->flags
.indicator_on
= 1;
1119 entry
->flags
.indicator_type
= MI_CHECK
;
1121 menu
->flags
.realized
= 0;
1129 dockMenuCreate(WScreen
*scr
, int type
)
1134 if (type
== WM_CLIP
&& scr
->clip_menu
)
1135 return scr
->clip_menu
;
1137 menu
= wMenuCreate(scr
, NULL
, False
);
1138 if (type
!= WM_CLIP
) {
1139 entry
= wMenuAddCallback(menu
, _("Keep on Top"),
1140 toggleLoweredCallback
, NULL
);
1141 entry
->flags
.indicator
= 1;
1142 entry
->flags
.indicator_on
= 1;
1143 entry
->flags
.indicator_type
= MI_CHECK
;
1145 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1146 scr
->clip_options
= makeClipOptionsMenu(scr
);
1147 if (scr
->clip_options
)
1148 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1150 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
,
1153 entry
->text
= _("Rename Workspace");
1155 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1156 entry
->flags
.indicator
= 1;
1157 entry
->flags
.indicator_on
= 1;
1158 entry
->flags
.indicator_type
= MI_CHECK
;
1160 entry
= wMenuAddCallback(menu
, _("Select All Icons"),
1161 selectIconsCallback
, NULL
);
1163 entry
->text
= _("Select All Icons");
1165 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1167 entry
->text
= _("Keep Icon");
1169 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1171 entry
->text
= _("Move Icon To");
1172 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1173 if (scr
->clip_submenu
)
1174 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1176 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
,
1179 entry
->text
= _("Remove Icon");
1181 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1184 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1186 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1188 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1190 entry
->text
= _("Hide");
1192 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1194 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1196 if (type
== WM_CLIP
)
1197 scr
->clip_menu
= menu
;
1204 wDockCreate(WScreen
*scr
, int type
)
1212 dock
= wmalloc(sizeof(WDock
));
1213 memset(dock
, 0, sizeof(WDock
));
1215 if (type
== WM_CLIP
)
1216 icon_count
= CLIP_MAX_ICONS
;
1218 icon_count
= scr
->scr_height
/wPreferences
.icon_size
;
1220 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*)*icon_count
);
1221 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*)*icon_count
);
1223 dock
->max_icons
= icon_count
;
1225 btn
= mainIconCreate(scr
, type
);
1229 dock
->x_pos
= btn
->x_pos
;
1230 dock
->y_pos
= btn
->y_pos
;
1231 dock
->screen_ptr
= scr
;
1233 dock
->icon_count
= 1;
1234 dock
->on_right_side
= 1;
1235 dock
->collapsed
= 0;
1236 dock
->auto_collapse
= 0;
1237 dock
->auto_collapse_magic
= NULL
;
1238 dock
->auto_raise_lower
= 0;
1239 dock
->auto_lower_magic
= NULL
;
1240 dock
->auto_raise_magic
= NULL
;
1241 dock
->attract_icons
= 0;
1243 dock
->icon_array
[0] = btn
;
1244 wRaiseFrame(btn
->icon
->core
);
1245 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1247 /* create dock menu */
1248 dock
->menu
= dockMenuCreate(scr
, type
);
1255 wDockDestroy(WDock
*dock
)
1260 for (i
=(dock
->type
== WM_CLIP
) ? 1 : 0; i
<dock
->max_icons
; i
++) {
1261 aicon
= dock
->icon_array
[i
];
1263 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1264 wDockDetach(dock
, aicon
);
1266 /* XXX: can: aicon->icon == NULL ? */
1267 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
, wGetHeadForWindow(aicon
->icon
->owner
));
1268 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
1269 aicon
->x_pos
, aicon
->y_pos
);
1270 if (!dock
->mapped
|| dock
->collapsed
)
1271 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1275 if (wPreferences
.auto_arrange_icons
)
1276 wArrangeIcons(dock
->screen_ptr
, True
);
1277 wfree(dock
->icon_array
);
1278 if (dock
->menu
&& dock
->type
!=WM_CLIP
)
1279 wMenuDestroy(dock
->menu
, True
);
1280 if (dock
->screen_ptr
->last_dock
== dock
)
1281 dock
->screen_ptr
->last_dock
= NULL
;
1287 wClipIconPaint(WAppIcon
*aicon
)
1289 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1290 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1292 Window win
= aicon
->icon
->core
->window
;
1293 int length
, nlength
;
1294 char *ws_name
, ws_number
[10];
1297 wIconPaint(aicon
->icon
);
1299 length
= strlen(workspace
->name
);
1300 ws_name
= wmalloc(length
+ 1);
1301 snprintf(ws_name
, length
+1, "%s", workspace
->name
);
1302 snprintf(ws_number
, sizeof(ws_number
), "%i", scr
->current_workspace
+ 1);
1303 nlength
= strlen(ws_number
);
1305 if (!workspace
->clip
->collapsed
)
1306 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1308 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1310 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1312 tx
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
1314 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
,
1315 ty
, ws_name
, length
);
1316 /*WMDrawString(scr->wmscreen, win, color, scr->clip_title_font, 4,
1317 2, ws_name, length);*/
1319 tx
= (ICON_SIZE
/2 - WMWidthOfString(scr
->clip_title_font
, ws_number
,
1322 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
,
1323 2, ws_number
, nlength
);
1327 if (aicon
->launching
) {
1328 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1329 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1331 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
,
1332 aicon
->dock
->rclip_button_pushed
);
1337 clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1339 wClipIconPaint(desc
->parent
);
1344 dockIconPaint(WAppIcon
*btn
)
1346 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1347 wClipIconPaint(btn
);
1354 make_icon_state(WAppIcon
*btn
)
1356 WMPropList
*node
= NULL
;
1357 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
, *host
;
1358 WMPropList
*position
, *buggy
, *omnipresent
;
1364 command
= WMCreatePLString("-");
1366 command
= WMCreatePLString(btn
->command
);
1368 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1370 lock
= btn
->lock
? dYes
: dNo
;
1372 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1374 name
= WMCreatePLString(tmp
);
1378 forced
= btn
->forced_dock
? dYes
: dNo
;
1380 buggy
= btn
->buggy_app
? dYes
: dNo
;
1382 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1383 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1385 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1386 position
= WMCreatePLString(buffer
);
1388 node
= WMCreatePLDictionary(dCommand
, command
,
1390 dAutoLaunch
, autolaunch
,
1393 dBuggyApplication
, buggy
,
1394 dPosition
, position
,
1396 WMReleasePropList(command
);
1397 WMReleasePropList(name
);
1398 WMReleasePropList(position
);
1400 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1401 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&&
1402 (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1403 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1406 if (btn
->dnd_command
) {
1407 command
= WMCreatePLString(btn
->dnd_command
);
1408 WMPutInPLDictionary(node
, dDropCommand
, command
);
1409 WMReleasePropList(command
);
1411 #endif /* OFFIX_DND */
1413 if (btn
->paste_command
) {
1414 command
= WMCreatePLString(btn
->paste_command
);
1415 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1416 WMReleasePropList(command
);
1419 if (btn
->client_machine
&& btn
->remote_start
) {
1420 host
= WMCreatePLString(btn
->client_machine
);
1421 WMPutInPLDictionary(node
, dHost
, host
);
1422 WMReleasePropList(host
);
1431 dockSaveState(WDock
*dock
)
1434 WMPropList
*icon_info
;
1435 WMPropList
*list
=NULL
, *dock_state
=NULL
;
1436 WMPropList
*value
, *key
;
1439 list
= WMCreatePLArray(NULL
);
1441 for (i
=(dock
->type
==WM_DOCK
? 0 : 1); i
<dock
->max_icons
; i
++) {
1442 WAppIcon
*btn
= dock
->icon_array
[i
];
1444 if (!btn
|| btn
->attracted
)
1447 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1448 WMAddToPLArray(list
, icon_info
);
1449 WMReleasePropList(icon_info
);
1453 dock_state
= WMCreatePLDictionary(dApplications
, list
,
1456 if (dock
->type
== WM_DOCK
) {
1457 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1458 key
= WMCreatePLString(buffer
);
1459 WMPutInPLDictionary(dock_state
, key
, list
);
1460 WMReleasePropList(key
);
1463 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0),
1465 value
= WMCreatePLString(buffer
);
1466 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1467 WMReleasePropList(value
);
1469 WMReleasePropList(list
);
1472 value
= (dock
->lowered
? dYes
: dNo
);
1473 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1475 if (dock
->type
== WM_CLIP
) {
1476 value
= (dock
->collapsed
? dYes
: dNo
);
1477 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1479 value
= (dock
->auto_collapse
? dYes
: dNo
);
1480 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1482 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1483 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1485 value
= (dock
->attract_icons
? dYes
: dNo
);
1486 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1494 wDockSaveState(WScreen
*scr
, WMPropList
*old_state
)
1496 WMPropList
*dock_state
;
1499 dock_state
= dockSaveState(scr
->dock
);
1502 * Copy saved states of docks with different sizes.
1508 keys
= WMGetPLDictionaryKeys(old_state
);
1509 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1510 tmp
= WMGetFromPLArray(keys
, i
);
1512 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1513 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1515 WMPutInPLDictionary(dock_state
,
1517 WMGetFromPLDictionary(old_state
, tmp
));
1520 WMReleasePropList(keys
);
1524 WMPutInPLDictionary(scr
->session_state
, dDock
, dock_state
);
1526 WMReleasePropList(dock_state
);
1531 wClipSaveState(WScreen
*scr
)
1533 WMPropList
*clip_state
;
1535 clip_state
= make_icon_state(scr
->clip_icon
);
1537 WMPutInPLDictionary(scr
->session_state
, dClip
, clip_state
);
1539 WMReleasePropList(clip_state
);
1544 wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1546 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1551 getBooleanDockValue(WMPropList
*value
, WMPropList
*key
)
1554 if (WMIsPLString(value
)) {
1555 if (strcasecmp(WMGetFromPLString(value
), "YES")==0)
1558 wwarning(_("bad value in docked icon state info %s"),
1559 WMGetFromPLString(key
));
1567 restore_icon_state(WScreen
*scr
, WMPropList
*info
, int type
, int index
)
1570 WMPropList
*cmd
, *value
;
1573 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1574 if (!cmd
|| !WMIsPLString(cmd
)) {
1578 /* parse window name */
1579 value
= WMGetFromPLDictionary(info
, dName
);
1584 char *wclass
, *winstance
;
1587 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1589 if (!winstance
&& !wclass
) {
1596 command
= wstrdup(WMGetFromPLString(cmd
));
1600 if (!command
|| strcmp(command
, "-")==0) {
1611 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
,
1621 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1622 if (type
== WM_CLIP
) {
1623 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1624 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1626 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1627 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1631 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1633 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1636 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1638 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1640 /* check auto launch */
1641 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1643 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1646 value
= WMGetFromPLDictionary(info
, dLock
);
1648 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1650 /* check if it wasn't normally docked */
1651 value
= WMGetFromPLDictionary(info
, dForced
);
1653 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1655 /* check if we can rely on the stuff in the app */
1656 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1658 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1660 /* get position in the dock */
1661 value
= WMGetFromPLDictionary(info
, dPosition
);
1662 if (value
&& WMIsPLString(value
)) {
1663 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
,
1665 wwarning(_("bad value in docked icon state info %s"),
1666 WMGetFromPLString(dPosition
));
1668 /* check position sanity */
1669 /* incomplete section! */
1670 if (type
== WM_DOCK
) {
1672 if (aicon
->yindex
< 0)
1673 wwarning(_("bad value in docked icon position %i,%i"),
1674 aicon
->xindex
, aicon
->yindex
);
1677 aicon
->yindex
= index
;
1681 /* check if icon is omnipresent */
1682 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1684 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1693 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1697 wClipRestoreState(WScreen
*scr
, WMPropList
*clip_state
)
1703 icon
= mainIconCreate(scr
, WM_CLIP
);
1708 WMRetainPropList(clip_state
);
1710 /* restore position */
1712 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1715 if (!WMIsPLString(value
))
1716 COMPLAIN("Position");
1721 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
,
1723 COMPLAIN("Position");
1725 /* check position sanity */
1726 rect
.pos
.x
= icon
->x_pos
;
1727 rect
.pos
.y
= icon
->y_pos
;
1728 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1730 wGetRectPlacementInfo(scr
, rect
, &flags
);
1731 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
1732 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
,
1733 ICON_SIZE
, ICON_SIZE
);
1738 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1739 if (value
&& WMIsPLString(value
))
1740 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1743 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1744 if (value
&& WMIsPLString(value
))
1745 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1747 WMReleasePropList(clip_state
);
1754 wDockRestoreState(WScreen
*scr
, WMPropList
*dock_state
, int type
)
1759 WAppIcon
*aicon
, *old_top
;
1763 dock
= wDockCreate(scr
, type
);
1769 WMRetainPropList(dock_state
);
1772 /* restore position */
1774 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1777 if (!WMIsPLString(value
))
1778 COMPLAIN("Position");
1783 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
,
1785 COMPLAIN("Position");
1787 /* check position sanity */
1788 rect
.pos
.x
= dock
->x_pos
;
1789 rect
.pos
.y
= dock
->y_pos
;
1790 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1792 wGetRectPlacementInfo(scr
, rect
, &flags
);
1793 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
)) {
1794 int x
= dock
->x_pos
;
1795 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1798 /* This is no more needed. ??? */
1799 if (type
== WM_CLIP
) {
1800 if (dock
->x_pos
< 0)
1802 else if (dock
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1803 dock
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1805 if (dock
->x_pos
>= 0) {
1806 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1807 dock
->on_right_side
= 0;
1809 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1810 dock
->on_right_side
= 1;
1816 /* restore lowered/raised state */
1820 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1823 if (!WMIsPLString(value
))
1824 COMPLAIN("Lowered");
1826 if (strcasecmp(WMGetFromPLString(value
), "YES")==0)
1832 /* restore collapsed state */
1834 dock
->collapsed
= 0;
1836 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1839 if (!WMIsPLString(value
))
1840 COMPLAIN("Collapsed");
1842 if (strcasecmp(WMGetFromPLString(value
), "YES")==0)
1843 dock
->collapsed
= 1;
1848 /* restore auto-collapsed state */
1850 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1853 if (!WMIsPLString(value
))
1854 COMPLAIN("AutoCollapse");
1856 if (strcasecmp(WMGetFromPLString(value
), "YES")==0) {
1857 dock
->auto_collapse
= 1;
1858 dock
->collapsed
= 1;
1864 /* restore auto-raise/lower state */
1866 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1869 if (!WMIsPLString(value
))
1870 COMPLAIN("AutoRaiseLower");
1872 if (strcasecmp(WMGetFromPLString(value
), "YES")==0) {
1873 dock
->auto_raise_lower
= 1;
1878 /* restore attract icons state */
1880 dock
->attract_icons
= 0;
1882 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1885 if (!WMIsPLString(value
))
1886 COMPLAIN("AutoAttractIcons");
1888 if (strcasecmp(WMGetFromPLString(value
), "YES")==0)
1889 dock
->attract_icons
= 1;
1894 /* application list */
1901 * When saving, it saves the dock state in
1902 * Applications and Applicationsnnn
1904 * When loading, it will first try Applicationsnnn.
1905 * If it does not exist, use Applications as default.
1908 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1910 tmp
= WMCreatePLString(buffer
);
1911 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1912 WMReleasePropList(tmp
);
1915 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1923 count
= WMGetPropListItemCount(apps
);
1928 old_top
= dock
->icon_array
[0];
1930 /* dock->icon_count is set to 1 when dock is created.
1931 * Since Clip is already restored, we want to keep it so for clip,
1932 * but for dock we may change the default top tile, so we set it to 0.
1934 if (type
== WM_DOCK
)
1935 dock
->icon_count
= 0;
1937 for (i
=0; i
<count
; i
++) {
1938 if (dock
->icon_count
>= dock
->max_icons
) {
1939 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1943 value
= WMGetFromPLArray(apps
, i
);
1944 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1946 dock
->icon_array
[dock
->icon_count
] = aicon
;
1950 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
*ICON_SIZE
);
1951 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
*ICON_SIZE
);
1954 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1956 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1958 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
,
1961 if (!dock
->collapsed
)
1962 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1963 wRaiseFrame(aicon
->icon
->core
);
1966 } else if (dock
->icon_count
==0 && type
==WM_DOCK
)
1970 /* if the first icon is not defined, use the default */
1971 if (dock
->icon_array
[0]==NULL
) {
1972 /* update default icon */
1973 old_top
->x_pos
= dock
->x_pos
;
1974 old_top
->y_pos
= dock
->y_pos
;
1976 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1978 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1979 dock
->icon_array
[0] = old_top
;
1980 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1981 /* we don't need to increment dock->icon_count here because it was
1982 * incremented in the loop above.
1984 } else if (old_top
!=dock
->icon_array
[0]) {
1985 if (old_top
== scr
->clip_icon
)
1986 scr
->clip_icon
= dock
->icon_array
[0];
1987 wAppIconDestroy(old_top
);
1992 WMReleasePropList(dock_state
);
2000 wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
2002 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
2004 btn
->drop_launch
= 0;
2005 btn
->paste_launch
= 0;
2007 btn
->pid
= execCommand(btn
, btn
->command
, state
);
2010 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
2022 wDockDoAutoLaunch(WDock
*dock
, int workspace
)
2028 for (i
= 0; i
< dock
->max_icons
; i
++) {
2029 btn
= dock
->icon_array
[i
];
2030 if (!btn
|| !btn
->auto_launch
)
2033 state
= wmalloc(sizeof(WSavedState
));
2034 memset(state
, 0, sizeof(WSavedState
));
2035 state
->workspace
= workspace
;
2036 /* TODO: this is klugy and is very difficult to understand
2037 * what's going on. Try to clean up */
2038 wDockLaunchWithState(dock
, btn
, state
);
2045 findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
2051 if ((dock
= scr
->dock
)!=NULL
) {
2052 for (i
=0; i
<dock
->max_icons
; i
++) {
2053 if (dock
->icon_array
[i
]
2054 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
2060 if (*icon_pos
<0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
)!=NULL
) {
2061 for (i
=0; i
<dock
->max_icons
; i
++) {
2062 if (dock
->icon_array
[i
]
2063 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
2076 wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
2082 dock
= findDock(scr
, event
, &icon_pos
);
2087 * Return True if the drop was on an application icon window.
2088 * In this case, let the ClientMessage handler redirect the
2089 * message to the app.
2091 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!=None
)
2094 if (dock
->icon_array
[icon_pos
]->dnd_command
!=NULL
) {
2095 scr
->flags
.dnd_data_convertion_status
= 0;
2097 btn
= dock
->icon_array
[icon_pos
];
2099 if (!btn
->forced_dock
) {
2100 btn
->relaunching
= btn
->running
;
2103 if (btn
->wm_instance
|| btn
->wm_class
) {
2104 WWindowAttributes attr
;
2105 memset(&attr
, 0, sizeof(WWindowAttributes
));
2106 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
2108 btn
->wm_class
, &attr
, NULL
, True
);
2110 if (!attr
.no_appicon
)
2116 btn
->paste_launch
= 0;
2117 btn
->drop_launch
= 1;
2118 scr
->last_dock
= dock
;
2119 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
2124 if (!btn
->relaunching
) {
2131 #endif /* OFFIX_DND */
2136 wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2143 wwin
= icon
->icon
->owner
;
2144 if (icon
->command
==NULL
) {
2146 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2148 icon
->command
= wtokenjoin(argv
, argc
);
2149 XFreeStringList(argv
);
2153 /* icon->forced_dock = 1;*/
2154 if (dock
->type
!=WM_CLIP
|| !icon
->attracted
) {
2156 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2157 _("Type the command used to launch the application"),
2159 if (command
&& (command
[0]==0 ||
2160 (command
[0]=='-' && command
[1]==0))) {
2164 icon
->command
= command
;
2170 /* If the target is the dock, reject the icon. If
2171 * the target is the clip, make it an attracted icon
2173 if (dock
->type
==WM_CLIP
) {
2174 icon
->attracted
= 1;
2175 if (!icon
->icon
->shadowed
) {
2176 icon
->icon
->shadowed
= 1;
2177 icon
->icon
->force_paint
= 1;
2189 for (index
=1; index
<dock
->max_icons
; index
++)
2190 if (dock
->icon_array
[index
] == NULL
)
2192 /* if (index == dock->max_icons)
2195 assert(index
< dock
->max_icons
);
2197 dock
->icon_array
[index
] = icon
;
2201 icon
->omnipresent
= 0;
2203 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2204 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2209 icon
->launching
= 0;
2212 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2213 if (dock
->type
== WM_CLIP
) {
2214 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2215 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2217 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2218 icon
->icon
->core
->descriptor
.parent
= icon
;
2220 MoveInStackListUnder(dock
->icon_array
[index
-1]->icon
->core
,
2222 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2223 wAppIconPaint(icon
);
2225 if (wPreferences
.auto_arrange_icons
)
2226 wArrangeIcons(dock
->screen_ptr
, True
);
2229 if (icon
->command
&& !icon
->dnd_command
) {
2230 int len
= strlen(icon
->command
)+8;
2231 icon
->dnd_command
= wmalloc(len
);
2232 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
2236 if (icon
->command
&& !icon
->paste_command
) {
2237 int len
= strlen(icon
->command
)+8;
2238 icon
->paste_command
= wmalloc(len
);
2239 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
2247 reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2251 for(index
=1; index
<dock
->max_icons
; index
++) {
2252 if(dock
->icon_array
[index
] == icon
)
2255 assert(index
< dock
->max_icons
);
2260 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2261 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2266 moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2274 return True
; /* No move needed, we're already there */
2279 wwin
= icon
->icon
->owner
;
2282 * For the moment we can't do this if we move icons in Clip from one
2283 * workspace to other, because if we move two or more icons without
2284 * command, the dialog box will not be able to tell us to which of the
2285 * moved icons it applies. -Dan
2287 if ((dest
->type
==WM_DOCK
/*|| dest->keep_attracted*/) && icon
->command
==NULL
) {
2288 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2290 icon
->command
= wtokenjoin(argv
, argc
);
2291 XFreeStringList(argv
);
2296 /* icon->forced_dock = 1;*/
2297 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2298 _("Type the command used to launch the application"),
2300 if (command
&& (command
[0]==0 ||
2301 (command
[0]=='-' && command
[1]==0))) {
2305 icon
->command
= command
;
2316 if (dest
->type
== WM_DOCK
)
2317 wClipMakeIconOmnipresent(icon
, False
);
2319 for(index
=1; index
<src
->max_icons
; index
++) {
2320 if(src
->icon_array
[index
] == icon
)
2323 assert(index
< src
->max_icons
);
2325 src
->icon_array
[index
] = NULL
;
2328 for(index
=1; index
<dest
->max_icons
; index
++) {
2329 if(dest
->icon_array
[index
] == NULL
)
2332 /* if (index == dest->max_icons)
2335 assert(index
< dest
->max_icons
);
2337 dest
->icon_array
[index
] = icon
;
2340 /* deselect the icon */
2341 if (icon
->icon
->selected
)
2342 wIconSelect(icon
->icon
);
2344 if (dest
->type
== WM_DOCK
) {
2345 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2346 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2348 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2349 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2352 /* set it to be kept when moving to dock.
2353 * Unless the icon does not have a command set
2355 if (icon
->command
&& dest
->type
==WM_DOCK
) {
2356 icon
->attracted
= 0;
2357 if (icon
->icon
->shadowed
) {
2358 icon
->icon
->shadowed
= 0;
2359 icon
->icon
->force_paint
= 1;
2363 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2369 icon
->x_pos
= dest
->x_pos
+ x
*ICON_SIZE
;
2370 icon
->y_pos
= dest
->y_pos
+ y
*ICON_SIZE
;
2374 MoveInStackListUnder(dest
->icon_array
[index
-1]->icon
->core
,
2376 wAppIconPaint(icon
);
2383 wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2387 /* make the settings panel be closed */
2389 DestroyDockAppSettingsPanel(icon
->panel
);
2392 /* This must be called before icon->dock is set to NULL.
2393 * Don't move it. -Dan
2395 wClipMakeIconOmnipresent(icon
, False
);
2399 icon
->attracted
= 0;
2400 icon
->auto_launch
= 0;
2401 if (icon
->icon
->shadowed
) {
2402 icon
->icon
->shadowed
= 0;
2403 icon
->icon
->force_paint
= 1;
2406 /* deselect the icon */
2407 if (icon
->icon
->selected
)
2408 wIconSelect(icon
->icon
);
2410 if (icon
->command
) {
2411 wfree(icon
->command
);
2412 icon
->command
= NULL
;
2415 if (icon
->dnd_command
) {
2416 wfree(icon
->dnd_command
);
2417 icon
->dnd_command
= NULL
;
2420 if (icon
->paste_command
) {
2421 wfree(icon
->paste_command
);
2422 icon
->paste_command
= NULL
;
2425 for (index
=1; index
<dock
->max_icons
; index
++)
2426 if (dock
->icon_array
[index
] == icon
)
2428 assert(index
< dock
->max_icons
);
2429 dock
->icon_array
[index
] = NULL
;
2435 /* if the dock is not attached to an application or
2436 * the the application did not set the approriate hints yet,
2437 * destroy the icon */
2438 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2439 wAppIconDestroy(icon
);
2441 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2442 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2443 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2444 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2445 icon
->icon
->core
->descriptor
.parent
= icon
;
2447 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2449 wAppIconPaint(icon
);
2450 if (wPreferences
.auto_arrange_icons
) {
2451 wArrangeIcons(dock
->screen_ptr
, True
);
2454 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2460 * returns the closest Dock slot index for the passed
2463 * Returns False if icon can't be docked.
2465 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2469 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2470 int *ret_x
, int *ret_y
, int redocking
)
2472 WScreen
*scr
= dock
->screen_ptr
;
2475 int i
, offset
= ICON_SIZE
/2;
2476 WAppIcon
*aicon
= NULL
;
2477 WAppIcon
*nicon
= NULL
;
2478 int max_y_icons
, max_x_icons
;
2480 /* TODO: XINERAMA, for these */
2481 max_x_icons
= scr
->scr_width
/ICON_SIZE
;
2482 max_y_icons
= scr
->scr_height
/ICON_SIZE
-1;
2484 if (wPreferences
.flags
.noupdates
)
2490 /* if the dock is full */
2492 (dock
->icon_count
>= dock
->max_icons
)) {
2496 /* exact position */
2498 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2500 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2503 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2505 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2507 /* check if the icon is outside the screen boundaries */
2512 rect
.pos
.x
= dx
+ ex_x
*ICON_SIZE
;
2513 rect
.pos
.y
= dy
+ ex_y
*ICON_SIZE
;
2514 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2516 wGetRectPlacementInfo(scr
, rect
, &flags
);
2517 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
2521 if (dock
->type
== WM_DOCK
) {
2522 if (icon
->dock
!= dock
&& ex_x
!= 0)
2526 for (i
=0; i
<dock
->max_icons
; i
++) {
2527 nicon
= dock
->icon_array
[i
];
2528 if (nicon
&& nicon
->yindex
== ex_y
) {
2535 int sig
, done
, closest
;
2537 /* Possible cases when redocking:
2539 * icon dragged out of range of any slot -> false
2540 * icon dragged to range of free slot
2541 * icon dragged to range of same slot
2542 * icon dragged to range of different icon
2544 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2547 if (ex_y
>=0 && ex_y
<=max_y_icons
&& (aicon
==icon
|| !aicon
)) {
2553 /* start looking at the upper slot or lower? */
2554 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2561 /* look for closest free slot */
2562 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2566 closest
= sig
*(i
/2) + ex_y
;
2567 /* check if this slot is used */
2569 for (j
= 0; j
<dock
->max_icons
; j
++) {
2570 if (dock
->icon_array
[j
]
2571 && dock
->icon_array
[j
]->yindex
==closest
) {
2572 /* slot is used by someone else */
2573 if (dock
->icon_array
[j
]!=icon
)
2581 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2582 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2584 (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+1))) {
2589 } else { /* !redocking */
2591 /* if slot is free and the icon is close enough, return it */
2592 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2602 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2603 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+1;
2606 for (k
=start
; k
<stop
; k
++) {
2607 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2610 for (i
=0; i
<tmp
->max_icons
; i
++) {
2611 nicon
= tmp
->icon_array
[i
];
2612 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2620 for (k
=start
; k
<stop
; k
++) {
2621 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2624 for (i
=0; i
<tmp
->max_icons
; i
++) {
2625 nicon
= tmp
->icon_array
[i
];
2626 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2627 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2628 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2637 if (neighbours
&& (aicon
==NULL
|| (redocking
&& aicon
== icon
))) {
2648 onScreen(WScreen
*scr
, int x
, int y
, int sx
, int ex
, int sy
, int ey
)
2650 WMRect rect
= wmkrect(x
, y
, ICON_SIZE
, ICON_SIZE
);
2653 wGetRectPlacementInfo(scr
, rect
, &flags
);
2655 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2660 * returns true if it can find a free slot in the dock,
2661 * in which case it changes x_pos and y_pos accordingly.
2662 * Else returns false.
2665 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2667 WScreen
*scr
= dock
->screen_ptr
;
2669 WAppIconChain
*chain
;
2670 unsigned char *slot_map
;
2674 int i
, done
= False
;
2676 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2679 if (dock
->type
== WM_CLIP
&&
2680 dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2681 extra_count
= scr
->global_icon_count
;
2683 /* if the dock is full */
2684 if (dock
->icon_count
+extra_count
>= dock
->max_icons
) {
2688 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2689 if (scr
->dock
->on_right_side
)
2690 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2692 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2695 if (ex
< dock
->x_pos
)
2697 if (sx
> dock
->x_pos
+ICON_SIZE
)
2698 sx
= dock
->x_pos
+ICON_SIZE
;
2705 /* check if clip is in a corner */
2706 if (dock
->type
==WM_CLIP
) {
2707 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2709 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2711 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2713 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2720 /* If the clip is in the corner, use only slots that are in the border
2722 if (corner
!=C_NONE
) {
2726 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2727 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2728 hmap
= wmalloc(hcount
+1);
2729 memset(hmap
, 0, hcount
+1);
2730 vmap
= wmalloc(vcount
+1);
2731 memset(vmap
, 0, vcount
+1);
2733 /* mark used positions */
2736 for (i
=0; i
<dock
->max_icons
; i
++) {
2737 btn
= dock
->icon_array
[i
];
2741 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2742 vmap
[btn
->yindex
] = 1;
2743 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2744 hmap
[btn
->xindex
] = 1;
2746 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2748 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2749 vmap
[btn
->yindex
] = 1;
2750 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2751 hmap
[btn
->xindex
] = 1;
2755 for (i
=0; i
<dock
->max_icons
; i
++) {
2756 btn
= dock
->icon_array
[i
];
2760 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2761 vmap
[btn
->yindex
] = 1;
2762 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2763 hmap
[-btn
->xindex
] = 1;
2765 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2767 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2768 vmap
[btn
->yindex
] = 1;
2769 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2770 hmap
[-btn
->xindex
] = 1;
2774 for (i
=0; i
<dock
->max_icons
; i
++) {
2775 btn
= dock
->icon_array
[i
];
2779 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2780 vmap
[-btn
->yindex
] = 1;
2781 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2782 hmap
[btn
->xindex
] = 1;
2784 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2786 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2787 vmap
[-btn
->yindex
] = 1;
2788 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2789 hmap
[btn
->xindex
] = 1;
2794 for (i
=0; i
<dock
->max_icons
; i
++) {
2795 btn
= dock
->icon_array
[i
];
2799 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2800 vmap
[-btn
->yindex
] = 1;
2801 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2802 hmap
[-btn
->xindex
] = 1;
2804 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2806 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2807 vmap
[-btn
->yindex
] = 1;
2808 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2809 hmap
[-btn
->xindex
] = 1;
2814 /* search a vacant slot */
2815 for (i
=1; i
<WMAX(vcount
, hcount
); i
++) {
2816 if (i
< vcount
&& vmap
[i
]==0) {
2822 } else if (i
< hcount
&& hmap
[i
]==0) {
2832 /* If found a slot, translate and return */
2834 if (corner
==C_NW
|| corner
==C_NE
) {
2839 if (corner
==C_NE
|| corner
==C_SE
) {
2846 /* else, try to find a slot somewhere else */
2849 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2850 * placed outside of screen */
2851 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2853 /* In the worst case (the clip is in the corner of the screen),
2854 * the amount of icons that fit in the clip is smaller.
2855 * Double the map to get a safe value.
2861 slot_map
= wmalloc(mwidth
*mwidth
);
2862 memset(slot_map
, 0, mwidth
*mwidth
);
2864 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2866 /* mark used slots in the map. If the slot falls outside the map
2867 * (for example, when all icons are placed in line), ignore them. */
2868 for (i
=0; i
<dock
->max_icons
; i
++) {
2869 btn
= dock
->icon_array
[i
];
2871 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2873 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2874 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2876 /* Find closest slot from the center that is free by scanning the
2877 * map from the center to outward in circular passes.
2878 * This will not result in a neat layout, but will be optimal
2879 * in the sense that there will not be holes left.
2882 for (i
= 1; i
<= r
&& !done
; i
++) {
2885 /* top and bottom parts of the ring */
2886 for (x
= -i
; x
<= i
&& !done
; x
++) {
2887 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2889 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2890 if (slot_map
[XY2OFS(x
,y
)]==0
2891 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2898 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2899 if (slot_map
[XY2OFS(x
,y
)]==0
2900 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2907 /* left and right parts of the ring */
2908 for (y
= -i
+1; y
<= i
-1; y
++) {
2909 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2911 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2912 if (slot_map
[XY2OFS(x
,y
)]==0
2913 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2920 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2921 if (slot_map
[XY2OFS(x
,y
)]==0
2922 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2937 moveDock(WDock
*dock
, int new_x
, int new_y
)
2942 dock
->x_pos
= new_x
;
2943 dock
->y_pos
= new_y
;
2944 for (i
=0; i
<dock
->max_icons
; i
++) {
2945 btn
= dock
->icon_array
[i
];
2947 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2948 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2949 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2956 swapDock(WDock
*dock
)
2958 WScreen
*scr
= dock
->screen_ptr
;
2963 if (dock
->on_right_side
) {
2964 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2966 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2969 for (i
=0; i
<dock
->max_icons
; i
++) {
2970 btn
= dock
->icon_array
[i
];
2973 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2977 wScreenUpdateUsableArea(scr
);
2982 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2984 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2990 cmdline
= ExpandOptions(scr
, command
);
2992 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
3000 wtokensplit(cmdline
, &argv
, &argc
);
3010 if ((pid
=fork())==0) {
3014 SetupEnvironment(scr
);
3020 args
= malloc(sizeof(char*)*(argc
+1));
3023 for (i
=0; i
<argc
; i
++) {
3027 execvp(argv
[0], args
);
3030 wtokenfree(argv
, argc
);
3034 state
= wmalloc(sizeof(WSavedState
));
3035 memset(state
, 0, sizeof(WSavedState
));
3037 state
->miniaturized
= -1;
3039 if (btn
->dock
==scr
->dock
|| btn
->omnipresent
)
3040 state
->workspace
= -1;
3042 state
->workspace
= scr
->current_workspace
;
3044 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
3046 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
3057 wDockHideIcons(WDock
*dock
)
3064 for (i
=1; i
<dock
->max_icons
; i
++) {
3065 if (dock
->icon_array
[i
])
3066 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3070 dockIconPaint(dock
->icon_array
[0]);
3075 wDockShowIcons(WDock
*dock
)
3083 btn
= dock
->icon_array
[0];
3084 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
3086 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
3087 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
3089 for (i
=1; i
<dock
->max_icons
; i
++) {
3090 if (dock
->icon_array
[i
]) {
3091 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
3097 if (!dock
->collapsed
) {
3098 for (i
=1; i
<dock
->max_icons
; i
++) {
3099 if (dock
->icon_array
[i
]) {
3100 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3111 wDockLower(WDock
*dock
)
3115 for (i
=0; i
<dock
->max_icons
; i
++) {
3116 if (dock
->icon_array
[i
])
3117 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
3123 wDockRaise(WDock
*dock
)
3127 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
3128 if (dock
->icon_array
[i
])
3129 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
3135 wDockRaiseLower(WDock
*dock
)
3137 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
3138 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
3139 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
3147 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
3149 icon
->launching
= 0;
3150 icon
->relaunching
= 0;
3151 dockIconPaint(icon
);
3156 wDockFindIconForWindow(WDock
*dock
, Window window
)
3161 for (i
=0; i
<dock
->max_icons
; i
++) {
3162 icon
= dock
->icon_array
[i
];
3163 if (icon
&& icon
->main_window
== window
)
3171 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
3174 char *wm_class
, *wm_instance
;
3176 Bool firstPass
= True
;
3178 char *command
= NULL
;
3184 if (XGetCommand(dpy
, window
, &argv
, &argc
)) {
3185 if (argc
> 0 && argv
!= NULL
)
3186 command
= wtokenjoin(argv
, argc
);
3188 XFreeStringList(argv
);
3193 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
3194 (!wm_class
&& !wm_instance
))
3198 for (i
=0; i
<dock
->max_icons
; i
++) {
3199 icon
= dock
->icon_array
[i
];
3203 /* app is already attached to icon */
3204 if (icon
->main_window
== window
) {
3209 if ((icon
->wm_instance
|| icon
->wm_class
)
3210 && (icon
->launching
|| !icon
->running
)) {
3212 if (icon
->wm_instance
&& wm_instance
&&
3213 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
3216 if (icon
->wm_class
&& wm_class
&&
3217 strcmp(icon
->wm_class
, wm_class
)!=0) {
3220 if (firstPass
&& command
&& strcmp(icon
->command
, command
)!=0) {
3224 if (!icon
->relaunching
) {
3227 /* Possibly an application that was docked with dockit,
3228 * but the user did not update WMState to indicate that
3229 * it was docked by force */
3230 wapp
= wApplicationOf(window
);
3232 icon
->forced_dock
= 1;
3235 if (!icon
->forced_dock
)
3236 icon
->main_window
= window
;
3240 if (!wPreferences
.no_animations
&& !icon
->launching
&&
3241 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
3245 icon
->launching
= 1;
3246 dockIconPaint(icon
);
3248 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
3249 wm_instance
, wm_class
,
3251 /* XXX: can: aicon->icon == NULL ? */
3252 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
3253 wAppIconMove(aicon
, x0
, y0
);
3254 /* Should this always be lowered? -Dan */
3256 wLowerFrame(aicon
->icon
->core
);
3257 XMapWindow(dpy
, aicon
->icon
->core
->window
);
3258 aicon
->launching
= 1;
3259 wAppIconPaint(aicon
);
3260 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
,
3261 icon
->x_pos
, icon
->y_pos
);
3262 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
3263 wAppIconDestroy(aicon
);
3265 wDockFinishLaunch(dock
, icon
);
3270 if (firstPass
&& !found
) {
3287 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3289 if (!wPreferences
.flags
.noclip
) {
3290 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3291 if (scr
->current_workspace
!= workspace
) {
3292 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3293 WAppIconChain
*chain
= scr
->global_icons
;
3296 moveIconBetweenDocks(chain
->aicon
->dock
,
3297 scr
->workspaces
[workspace
]->clip
,
3298 chain
->aicon
, chain
->aicon
->xindex
,
3299 chain
->aicon
->yindex
);
3300 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
3301 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3302 chain
= chain
->next
;
3305 wDockHideIcons(old_clip
);
3306 if (old_clip
->auto_raise_lower
) {
3307 if (old_clip
->auto_raise_magic
) {
3308 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3309 old_clip
->auto_raise_magic
= NULL
;
3311 wDockLower(old_clip
);
3313 if (old_clip
->auto_collapse
) {
3314 if (old_clip
->auto_expand_magic
) {
3315 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3316 old_clip
->auto_expand_magic
= NULL
;
3318 old_clip
->collapsed
= 1;
3320 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3322 if (scr
->flags
.clip_balloon_mapped
)
3323 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3330 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3335 for (i
=0; i
<dock
->max_icons
; i
++) {
3336 icon
= dock
->icon_array
[i
];
3340 if (icon
->launching
&& icon
->pid
== pid
) {
3341 if (!icon
->relaunching
) {
3343 icon
->main_window
= None
;
3345 wDockFinishLaunch(dock
, icon
);
3351 if (icon
->drop_launch
)
3352 cmd
= icon
->dnd_command
;
3353 else if (icon
->paste_launch
)
3354 cmd
= icon
->paste_command
;
3356 cmd
= icon
->command
;
3358 snprintf(msg
, sizeof(msg
),
3359 _("Could not execute command \"%s\""), cmd
);
3361 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
3362 _("OK"), NULL
, NULL
);
3371 toggleLowered(WDock
*dock
)
3376 /* lower/raise Dock */
3377 if (!dock
->lowered
) {
3378 newlevel
= WMNormalLevel
;
3381 newlevel
= WMDockLevel
;
3385 for (i
=0; i
<dock
->max_icons
; i
++) {
3386 tmp
= dock
->icon_array
[i
];
3390 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3392 wLowerFrame(tmp
->icon
->core
);
3395 if (dock
->type
== WM_DOCK
)
3396 wScreenUpdateUsableArea(dock
->screen_ptr
);
3401 toggleCollapsed(WDock
*dock
)
3403 if (dock
->collapsed
) {
3404 dock
->collapsed
= 0;
3405 wDockShowIcons(dock
);
3408 dock
->collapsed
= 1;
3409 wDockHideIcons(dock
);
3415 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3417 WScreen
*scr
= dock
->screen_ptr
;
3418 WObjDescriptor
*desc
;
3420 WApplication
*wapp
= NULL
;
3424 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3426 if (dock
->type
== WM_DOCK
) {
3428 entry
= dock
->menu
->entries
[index
];
3429 entry
->flags
.indicator_on
= !dock
->lowered
;
3430 entry
->clientdata
= dock
;
3431 dock
->menu
->flags
.realized
= 0;
3434 if (scr
->clip_options
)
3435 updateClipOptionsMenu(scr
->clip_options
, dock
);
3437 n_selected
= numberOfSelectedIcons(dock
);
3439 /* Rename Workspace */
3440 entry
= dock
->menu
->entries
[++index
];
3441 if (aicon
== scr
->clip_icon
) {
3442 entry
->callback
= renameCallback
;
3443 entry
->clientdata
= dock
;
3444 entry
->flags
.indicator
= 0;
3445 entry
->text
= _("Rename Workspace");
3447 entry
->callback
= omnipresentCallback
;
3448 entry
->clientdata
= aicon
;
3449 if (n_selected
> 0) {
3450 entry
->flags
.indicator
= 0;
3451 entry
->text
= _("Toggle Omnipresent");
3453 entry
->flags
.indicator
= 1;
3454 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3455 entry
->flags
.indicator_type
= MI_CHECK
;
3456 entry
->text
= _("Omnipresent");
3460 /* select/unselect icon */
3461 entry
= dock
->menu
->entries
[++index
];
3462 entry
->clientdata
= aicon
;
3463 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3464 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3466 /* select/unselect all icons */
3467 entry
= dock
->menu
->entries
[++index
];
3468 entry
->clientdata
= aicon
;
3470 entry
->text
= _("Unselect All Icons");
3472 entry
->text
= _("Select All Icons");
3473 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3476 entry
= dock
->menu
->entries
[++index
];
3477 entry
->clientdata
= aicon
;
3479 entry
->text
= _("Keep Icons");
3481 entry
->text
= _("Keep Icon");
3482 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3484 /* this is the workspace submenu part */
3485 entry
= dock
->menu
->entries
[++index
];
3487 entry
->text
= _("Move Icons To");
3489 entry
->text
= _("Move Icon To");
3490 if (scr
->clip_submenu
)
3491 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3492 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3494 /* remove icon(s) */
3495 entry
= dock
->menu
->entries
[++index
];
3496 entry
->clientdata
= aicon
;
3498 entry
->text
= _("Remove Icons");
3500 entry
->text
= _("Remove Icon");
3501 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3503 /* attract icon(s) */
3504 entry
= dock
->menu
->entries
[++index
];
3505 entry
->clientdata
= aicon
;
3507 dock
->menu
->flags
.realized
= 0;
3508 wMenuRealize(dock
->menu
);
3512 if (aicon
->icon
->owner
) {
3513 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3519 entry
= dock
->menu
->entries
[++index
];
3520 entry
->clientdata
= aicon
;
3521 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3524 entry
= dock
->menu
->entries
[++index
];
3525 entry
->clientdata
= aicon
;
3526 if (wapp
&& wapp
->flags
.hidden
) {
3527 entry
->text
= _("Unhide Here");
3529 entry
->text
= _("Bring Here");
3531 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3534 entry
= dock
->menu
->entries
[++index
];
3535 entry
->clientdata
= aicon
;
3536 if (wapp
&& wapp
->flags
.hidden
) {
3537 entry
->text
= _("Unhide");
3539 entry
->text
= _("Hide");
3541 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3544 entry
= dock
->menu
->entries
[++index
];
3545 entry
->clientdata
= aicon
;
3546 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
3547 && !wPreferences
.flags
.noupdates
);
3550 entry
= dock
->menu
->entries
[++index
];
3551 entry
->clientdata
= aicon
;
3552 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3554 if (!dock
->menu
->flags
.realized
)
3555 wMenuRealize(dock
->menu
);
3557 if (dock
->type
== WM_CLIP
) {
3558 /*x_pos = event->xbutton.x_root+2;*/
3559 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/2 - 1;
3562 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
-2) {
3563 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3566 x_pos
= dock
->on_right_side
?
3567 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3570 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3572 /* allow drag select */
3573 event
->xany
.send_event
= True
;
3574 desc
= &dock
->menu
->menu
->descriptor
;
3575 (*desc
->handle_mousedown
)(desc
, event
);
3579 /******************************************************************/
3581 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3583 WAppIcon
*btn
= desc
->parent
;
3584 WDock
*dock
= btn
->dock
;
3585 WApplication
*wapp
= NULL
;
3588 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3589 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3593 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3595 /* go to the last workspace that the user worked on the app */
3596 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
3598 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3601 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3604 if (event
->xbutton
.state
& MOD_MASK
) {
3605 wHideOtherApplications(btn
->icon
->owner
);
3608 if (event
->xbutton
.button
==Button1
) {
3610 if (event
->xbutton
.state
& MOD_MASK
) {
3611 /* raise/lower dock */
3612 toggleLowered(dock
);
3613 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3614 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3615 toggleCollapsed(dock
);
3617 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3618 } else if (btn
->command
) {
3619 if (!btn
->launching
&&
3620 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3621 launchDockedApplication(btn
, False
);
3623 } else if (btn
->xindex
== 0 && btn
->yindex
== 0
3624 && btn
->dock
->type
== WM_DOCK
) {
3626 wShowGNUstepPanel(dock
->screen_ptr
);
3635 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3637 WScreen
*scr
= dock
->screen_ptr
;
3638 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3641 int grabbed
= 0, swapped
= 0, done
;
3642 Pixmap ghost
= None
;
3643 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3646 puts("moving dock");
3648 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3649 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3650 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3651 wwarning("pointer grab failed for dock move");
3654 for (x
=0; x
<dock
->max_icons
; x
++) {
3655 if (dock
->icon_array
[x
]!=NULL
&&
3656 dock
->icon_array
[x
]->yindex
> y
)
3657 y
= dock
->icon_array
[x
]->yindex
;
3660 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3664 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3665 |ButtonMotionMask
|ExposureMask
, &ev
);
3673 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3674 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3675 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3676 |ButtonReleaseMask
|ButtonPressMask
,
3677 wCursor
[WCUR_MOVE
], CurrentTime
);
3682 if (dock
->type
== WM_CLIP
) {
3683 x
= ev
.xmotion
.x_root
- ofs_x
;
3684 y
= ev
.xmotion
.y_root
- ofs_y
;
3685 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3687 moveDock(dock
, x
, y
);
3689 /* move vertically if pointer is inside the dock*/
3690 if ((dock
->on_right_side
&&
3691 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3692 || (!dock
->on_right_side
&&
3693 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3695 x
= ev
.xmotion
.x_root
- ofs_x
;
3696 y
= ev
.xmotion
.y_root
- ofs_y
;
3697 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3698 moveDock(dock
, dock
->x_pos
, y
);
3700 /* move horizontally to change sides */
3701 x
= ev
.xmotion
.x_root
- ofs_x
;
3702 if (!dock
->on_right_side
) {
3706 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3707 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3708 -DOCK_EXTRA_SPACE
-1, dock
->y_pos
);
3709 if (superfluous
&& ghost
==None
) {
3710 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3711 scr
->scr_width
-ICON_SIZE
3712 -DOCK_EXTRA_SPACE
-1,
3714 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3716 XClearWindow(dpy
, scr
->dock_shadow
);
3718 XMapRaised(dpy
, scr
->dock_shadow
);
3721 if (superfluous
&& ghost
!=None
) {
3722 XFreePixmap(dpy
, ghost
);
3725 XUnmapWindow(dpy
, scr
->dock_shadow
);
3730 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3731 XMoveWindow(dpy
, scr
->dock_shadow
,
3732 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3733 if (superfluous
&& ghost
==None
) {
3734 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3735 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3736 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3738 XClearWindow(dpy
, scr
->dock_shadow
);
3740 XMapRaised(dpy
, scr
->dock_shadow
);
3743 XUnmapWindow(dpy
, scr
->dock_shadow
);
3745 if (superfluous
&& ghost
!=None
) {
3746 XFreePixmap(dpy
, ghost
);
3758 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3760 XUngrabPointer(dpy
, CurrentTime
);
3761 XUnmapWindow(dpy
, scr
->dock_shadow
);
3762 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3763 if (dock
->type
== WM_DOCK
) {
3766 dock
->on_right_side
= 1;
3768 dock
->on_right_side
= 0;
3770 wArrangeIcons(scr
, False
);
3779 XFreePixmap(dpy
, ghost
);
3780 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3783 puts("End dock move");
3790 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3792 WScreen
*scr
= dock
->screen_ptr
;
3794 WIcon
*icon
= aicon
->icon
;
3795 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3796 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3798 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3799 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3800 int shad_x
= x
, shad_y
= y
;
3801 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3803 Pixmap ghost
= None
;
3805 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3806 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3809 if (wPreferences
.flags
.noupdates
)
3812 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3813 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3814 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3816 wwarning("pointer grab failed for icon move");
3820 if (!(event
->xbutton
.state
& MOD_MASK
))
3821 wRaiseFrame(icon
->core
);
3823 if (!wPreferences
.flags
.noclip
)
3824 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3826 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3828 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3831 wins
[0] = icon
->core
->window
;
3832 wins
[1] = scr
->dock_shadow
;
3833 XRestackWindows(dpy
, wins
, 2);
3834 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3835 ICON_SIZE
, ICON_SIZE
);
3837 if (icon
->pixmap
!=None
)
3838 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3840 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3842 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3843 XClearWindow(dpy
, scr
->dock_shadow
);
3845 XMapWindow(dpy
, scr
->dock_shadow
);
3851 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3852 |ButtonMotionMask
|ExposureMask
, &ev
);
3860 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3861 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3862 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3863 |ButtonReleaseMask
|ButtonPressMask
,
3864 wCursor
[WCUR_MOVE
], CurrentTime
);
3873 for (i
=0; i
<scr
->workspace_count
; i
++) {
3874 if (i
== scr
->current_workspace
)
3876 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3880 x
= ev
.xmotion
.x_root
- ofs_x
;
3881 y
= ev
.xmotion
.y_root
- ofs_y
;
3882 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3885 if (last_dock
!= dock
&& collapsed
) {
3886 last_dock
->collapsed
= 1;
3887 wDockHideIcons(last_dock
);
3890 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3891 dock
->collapsed
= 0;
3892 wDockShowIcons(dock
);
3894 if (dock
->auto_raise_lower
)
3898 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3901 if (last_dock
!= dock2
&& collapsed
) {
3902 last_dock
->collapsed
= 1;
3903 wDockHideIcons(last_dock
);
3906 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3907 dock2
->collapsed
= 0;
3908 wDockShowIcons(dock2
);
3910 if (dock2
->auto_raise_lower
)
3915 if (aicon
->launching
3917 || (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3918 || (!aicon
->running
&& tmp
)) {
3919 shad_x
= last_dock
->x_pos
+ ix
*wPreferences
.icon_size
;
3920 shad_y
= last_dock
->y_pos
+ iy
*wPreferences
.icon_size
;
3922 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3925 XMapWindow(dpy
, scr
->dock_shadow
);
3930 XUnmapWindow(dpy
, scr
->dock_shadow
);
3934 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3941 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3943 XUngrabPointer(dpy
, CurrentTime
);
3945 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3946 XUnmapWindow(dpy
, scr
->dock_shadow
);
3948 reattachIcon(dock
, aicon
, ix
, iy
);
3949 if (clip
&& dock
!=clip
&& clip
->auto_raise_lower
)
3952 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3954 /* Slide it back if dock rejected it */
3955 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3957 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3959 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3967 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3968 /* We need to deselect it, even if is deselected in
3969 * wDockDetach(), because else DoKaboom() will fail.
3971 if (aicon
->icon
->selected
)
3972 wIconSelect(aicon
->icon
);
3974 wSoundPlay(WSOUND_KABOOM
);
3975 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3977 wSoundPlay(WSOUND_UNDOCK
);
3980 wSoundPlay(WSOUND_UNDOCK
);
3982 if (clip
&& clip
->auto_raise_lower
)
3984 wDockDetach(dock
, aicon
);
3987 last_dock
->collapsed
= 1;
3988 wDockHideIcons(last_dock
);
3993 XFreePixmap(dpy
, ghost
);
3994 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3998 for (i
=0; i
<scr
->workspace_count
; i
++) {
3999 if (i
== scr
->current_workspace
)
4001 wDockHideIcons(scr
->workspaces
[i
]->clip
);
4006 puts("End icon move");
4015 getClipButton(int px
, int py
)
4017 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
4019 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
4022 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
4023 return CLIP_FORWARD
;
4024 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
4032 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
4035 int done
, direction
, new_ws
;
4037 WDock
*clip
= scr
->clip_icon
->dock
;
4039 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
4041 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
4042 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
4044 wClipIconPaint(scr
->clip_icon
);
4047 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
4048 |ButtonPressMask
, &ev
);
4055 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
4056 if (new_dir
!= direction
) {
4057 direction
= new_dir
;
4058 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
4059 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
4060 wClipIconPaint(scr
->clip_icon
);
4068 if (ev
.xbutton
.button
== event
->xbutton
.button
)
4073 clip
->lclip_button_pushed
= 0;
4074 clip
->rclip_button_pushed
= 0;
4076 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
4078 if (direction
== CLIP_FORWARD
) {
4079 if (scr
->current_workspace
< scr
->workspace_count
-1)
4080 wWorkspaceChange(scr
, scr
->current_workspace
+1);
4081 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
4082 wWorkspaceChange(scr
, scr
->current_workspace
+1);
4083 else if (wPreferences
.ws_cycle
)
4084 wWorkspaceChange(scr
, 0);
4086 else if (direction
== CLIP_REWIND
) {
4087 if (scr
->current_workspace
> 0)
4088 wWorkspaceChange(scr
, scr
->current_workspace
-1);
4089 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
4090 wWorkspaceChange(scr
, scr
->workspace_count
-1);
4093 wClipIconPaint(scr
->clip_icon
);
4098 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
4100 WAppIcon
*aicon
= desc
->parent
;
4101 WDock
*dock
= aicon
->dock
;
4102 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4104 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
4107 scr
->last_dock
= dock
;
4109 if (dock
->menu
->flags
.mapped
)
4110 wMenuUnmap(dock
->menu
);
4112 if (IsDoubleClick(scr
, event
)) {
4113 /* double-click was not in the main clip icon */
4114 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
4115 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
4116 iconDblClick(desc
, event
);
4121 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
4122 XUnmapWindow(dpy
, scr
->clip_balloon
);
4123 scr
->flags
.clip_balloon_mapped
= 0;
4127 puts("handling dock");
4129 if (event
->xbutton
.button
== Button1
) {
4130 if (event
->xbutton
.state
& MOD_MASK
)
4135 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
4136 dock
->type
!=WM_DOCK
) {
4137 wIconSelect(aicon
->icon
);
4141 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
4142 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
4143 && dock
->type
==WM_CLIP
)
4144 handleClipChangeWorkspace(scr
, event
);
4146 handleDockMove(dock
, aicon
, event
);
4148 handleIconMove(dock
, aicon
, event
);
4150 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4151 aicon
==scr
->clip_icon
) {
4152 if (!scr
->clip_ws_menu
) {
4153 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
4155 if (scr
->clip_ws_menu
) {
4156 WMenu
*wsMenu
= scr
->clip_ws_menu
;
4159 wWorkspaceMenuUpdate(scr
, wsMenu
);
4161 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/2 - 1;
4164 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
-2) {
4165 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
4167 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+2, False
);
4169 desc
= &wsMenu
->menu
->descriptor
;
4170 event
->xany
.send_event
= True
;
4171 (*desc
->handle_mousedown
)(desc
, event
);
4173 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4174 (event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
) {
4175 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
4176 } else if (event
->xbutton
.button
== Button3
) {
4177 if (event
->xbutton
.send_event
&&
4178 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
4179 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
4180 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
4181 wwarning("pointer grab failed for dockicon menu");
4185 openDockMenu(dock
, aicon
, event
);
4186 } else if (event
->xbutton
.button
== Button2
) {
4187 WAppIcon
*btn
= desc
->parent
;
4189 if (!btn
->launching
&&
4190 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
4191 launchDockedApplication(btn
, True
);
4198 showClipBalloon(WDock
*dock
, int workspace
)
4202 WScreen
*scr
= dock
->screen_ptr
;
4206 scr
->flags
.clip_balloon_mapped
= 1;
4207 XMapWindow(dpy
, scr
->clip_balloon
);
4209 text
= scr
->workspaces
[workspace
]->name
;
4211 w
= WMWidthOfString(scr
->clip_title_font
, text
, strlen(text
));
4213 h
= WMFontHeight(scr
->clip_title_font
);
4214 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
4216 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
4217 y
= dock
->y_pos
+ ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
4219 if (x
+w
> scr
->scr_width
) {
4220 x
= scr
->scr_width
- w
;
4221 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
4222 y
= dock
->y_pos
- h
- 1;
4224 y
= dock
->y_pos
+ ICON_SIZE
;
4225 XRaiseWindow(dpy
, scr
->clip_balloon
);
4227 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
4228 stack
[1] = scr
->clip_balloon
;
4229 XRestackWindows(dpy
, stack
, 2);
4231 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
4232 XClearWindow(dpy
, scr
->clip_balloon
);
4233 WMDrawString(scr
->wmscreen
, scr
->clip_balloon
,
4234 scr
->clip_title_color
[CLIP_NORMAL
],
4235 scr
->clip_title_font
,
4236 0, 0, text
, strlen(text
));
4241 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
4243 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4247 assert(event
->type
==EnterNotify
);
4249 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4252 scr
= btn
->icon
->core
->screen_ptr
;
4253 if (!btn
->omnipresent
)
4256 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
4258 if (!dock
|| dock
->type
!=WM_CLIP
)
4261 /* The auto raise/lower code */
4262 if (dock
->auto_lower_magic
) {
4263 WMDeleteTimerHandler(dock
->auto_lower_magic
);
4264 dock
->auto_lower_magic
= NULL
;
4266 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
4267 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
,
4272 /* The auto expand/collapse code */
4273 if (dock
->auto_collapse_magic
) {
4274 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
4275 dock
->auto_collapse_magic
= NULL
;
4277 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
4278 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
,
4283 if (btn
->xindex
== 0 && btn
->yindex
== 0)
4284 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4286 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4287 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
4288 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
4295 clipLeave(WDock
*dock
)
4298 WObjDescriptor
*desc
= NULL
;
4300 if (!dock
|| dock
->type
!=WM_CLIP
)
4303 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
)!=False
) {
4304 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
4305 (XPointer
*)&desc
)!=XCNOENT
4306 && desc
&& desc
->parent_type
==WCLASS_DOCK_ICON
4307 && ((WAppIcon
*)desc
->parent
)->dock
4308 && ((WAppIcon
*)desc
->parent
)->dock
->type
==WM_CLIP
) {
4309 /* We didn't left the Clip yet */
4310 XPutBackEvent(dpy
, &event
);
4314 XPutBackEvent(dpy
, &event
);
4316 /* We entered a withdrawn window, so we're still in Clip */
4320 if (dock
->auto_raise_magic
) {
4321 WMDeleteTimerHandler(dock
->auto_raise_magic
);
4322 dock
->auto_raise_magic
= NULL
;
4324 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
4325 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
,
4330 if (dock
->auto_expand_magic
) {
4331 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4332 dock
->auto_expand_magic
= NULL
;
4334 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
4335 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
4343 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4345 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4347 assert(event
->type
==LeaveNotify
);
4349 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4352 clipLeave(btn
->dock
);
4357 clipAutoCollapse(void *cdata
)
4359 WDock
*dock
= (WDock
*)cdata
;
4361 if (dock
->type
!=WM_CLIP
)
4364 if (dock
->auto_collapse
) {
4365 dock
->collapsed
= 1;
4366 wDockHideIcons(dock
);
4368 dock
->auto_collapse_magic
= NULL
;
4373 clipAutoExpand(void *cdata
)
4375 WDock
*dock
= (WDock
*)cdata
;
4377 if (dock
->type
!=WM_CLIP
)
4380 if (dock
->auto_collapse
) {
4381 dock
->collapsed
= 0;
4382 wDockShowIcons(dock
);
4384 dock
->auto_expand_magic
= NULL
;
4389 clipAutoLower(void *cdata
)
4391 WDock
*dock
= (WDock
*)cdata
;
4393 if (dock
->type
!=WM_CLIP
)
4396 if (dock
->auto_raise_lower
)
4399 dock
->auto_lower_magic
= NULL
;
4404 clipAutoRaise(void *cdata
)
4406 WDock
*dock
= (WDock
*)cdata
;
4408 if (dock
->type
!=WM_CLIP
)
4411 if (dock
->auto_raise_lower
)
4414 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4415 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4418 dock
->auto_raise_magic
= NULL
;
4423 iconCanBeOmnipresent(WAppIcon
*aicon
)
4425 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4430 for (i
=0; i
<scr
->workspace_count
; i
++) {
4431 clip
= scr
->workspaces
[i
]->clip
;
4433 if (clip
== aicon
->dock
)
4436 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4437 return False
; /* Clip is full in some workspace */
4439 for (j
=0; j
<clip
->max_icons
; j
++) {
4440 btn
= clip
->icon_array
[j
];
4441 if(btn
&& btn
->xindex
==aicon
->xindex
&& btn
->yindex
==aicon
->yindex
)
4451 wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
4453 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4454 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4455 int status
= WO_SUCCESS
;
4457 if ((scr
->dock
&& aicon
->dock
==scr
->dock
) || aicon
==scr
->clip_icon
) {
4458 return WO_NOT_APPLICABLE
;
4461 if (aicon
->omnipresent
== omnipresent
)
4465 if (iconCanBeOmnipresent(aicon
)) {
4466 aicon
->omnipresent
= 1;
4467 new_entry
= wmalloc(sizeof(WAppIconChain
));
4468 new_entry
->aicon
= aicon
;
4469 new_entry
->next
= scr
->global_icons
;
4470 scr
->global_icons
= new_entry
;
4471 scr
->global_icon_count
++;
4473 aicon
->omnipresent
= 0;
4477 aicon
->omnipresent
= 0;
4478 if (aicon
== scr
->global_icons
->aicon
) {
4479 tmp
= scr
->global_icons
->next
;
4480 wfree(scr
->global_icons
);
4481 scr
->global_icons
= tmp
;
4482 scr
->global_icon_count
--;
4484 tmp
= scr
->global_icons
;
4486 if (tmp
->next
->aicon
== aicon
) {
4487 tmp1
= tmp
->next
->next
;
4490 scr
->global_icon_count
--;
4498 wAppIconPaint(aicon
);