1 /* dock.c- built-in Dock module for WindowMaker
3 * Window Maker window manager
5 * Copyright (c) 1997-2002 Alfredo K. Kojima
6 * Copyright (c) 1998-2002 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"
59 #include <WINGs/WINGsP.h>
64 /**** Local variables ****/
67 #define CLIP_FORWARD 2
70 /**** Global variables ****/
73 extern void DestroyDockAppSettingsPanel();
75 extern void ShowDockAppSettingsPanel(WAppIcon
*aicon
);
78 extern XContext wWinContext
;
80 extern Cursor wCursor
[WCUR_LAST
];
82 extern WPreferences wPreferences
;
84 extern XContext wWinContext
;
87 extern Atom _XA_DND_PROTOCOL
;
91 #define MOD_MASK wPreferences.modifier_mask
93 extern void appIconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
95 #define ICON_SIZE wPreferences.icon_size
98 /***** Local variables ****/
100 static WMPropList
*dCommand
=NULL
;
101 static WMPropList
*dPasteCommand
=NULL
;
103 static WMPropList
*dDropCommand
=NULL
;
105 static WMPropList
*dAutoLaunch
, *dLock
;
106 static WMPropList
*dName
, *dForced
, *dBuggyApplication
, *dYes
, *dNo
;
107 static WMPropList
*dHost
, *dDock
, *dClip
;
108 static WMPropList
*dAutoAttractIcons
;
110 static WMPropList
*dPosition
, *dApplications
, *dLowered
, *dCollapsed
;
112 static WMPropList
*dAutoCollapse
, *dAutoRaiseLower
, *dOmnipresent
;
114 static void dockIconPaint(WAppIcon
*btn
);
116 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
118 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
);
120 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
122 static int getClipButton(int px
, int py
);
124 static void toggleLowered(WDock
*dock
);
126 static void toggleCollapsed(WDock
*dock
);
128 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
130 static void clipLeave(WDock
*dock
);
132 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
134 Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
);
136 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
137 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
138 static void clipAutoCollapse(void *cdata
);
139 static void clipAutoExpand(void *cdata
);
140 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
);
142 static void clipAutoLower(void *cdata
);
143 static void clipAutoRaise(void *cdata
);
145 static void showClipBalloon(WDock
*dock
, int workspace
);
161 #endif /* OFFIX_DND */
171 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
172 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
173 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
174 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
175 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
176 dName
= WMRetainPropList(WMCreatePLString("Name"));
177 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
178 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
179 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
180 dNo
= WMRetainPropList(WMCreatePLString("No"));
181 dHost
= WMRetainPropList(WMCreatePLString("Host"));
183 dPosition
= WMCreatePLString("Position");
184 dApplications
= WMCreatePLString("Applications");
185 dLowered
= WMCreatePLString("Lowered");
186 dCollapsed
= WMCreatePLString("Collapsed");
187 dAutoCollapse
= WMCreatePLString("AutoCollapse");
188 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
189 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
191 dOmnipresent
= WMCreatePLString("Omnipresent");
193 dDock
= WMCreatePLString("Dock");
194 dClip
= WMCreatePLString("Clip");
200 renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
202 WDock
*dock
= entry
->clientdata
;
207 assert(entry
->clientdata
!=NULL
);
209 wspace
= dock
->screen_ptr
->current_workspace
;
211 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
213 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+1);
214 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
,
216 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
225 toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
227 assert(entry
->clientdata
!=NULL
);
229 toggleLowered(entry
->clientdata
);
231 entry
->flags
.indicator_on
= !(((WDock
*)entry
->clientdata
)->lowered
);
238 matchWindow(void *item
, void *cdata
)
240 return (((WFakeGroupLeader
*)item
)->leader
== (Window
)cdata
);
245 killCallback(WMenu
*menu
, WMenuEntry
*entry
)
247 WScreen
*scr
= menu
->menu
->screen_ptr
;
249 WFakeGroupLeader
*fPtr
;
252 if (!WCHECK_STATE(WSTATE_NORMAL
))
255 assert(entry
->clientdata
!=NULL
);
257 icon
= (WAppIcon
*)entry
->clientdata
;
261 WCHANGE_STATE(WSTATE_MODAL
);
263 buffer
= wstrconcat(icon
->wm_class
,
264 _(" will be forcibly closed.\n"
265 "Any unsaved changes will be lost.\n"
268 if (icon
->icon
&& icon
->icon
->owner
) {
269 fPtr
= icon
->icon
->owner
->fake_group
;
271 /* is this really necessary? can we kill a dock icon not running? */
272 Window win
= icon
->main_window
;
275 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void*)win
);
276 if (index
!= WANotFound
)
277 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
282 if (wPreferences
.dont_confirm_kill
283 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
284 buffer
, _("Yes"), _("No"), NULL
)==WAPRDefault
) {
286 WWindow
*wwin
, *twin
;
288 wwin
= scr
->focused_window
;
291 if (wwin
->fake_group
== fPtr
) {
296 } else if (icon
->icon
&& icon
->icon
->owner
) {
297 wClientKill(icon
->icon
->owner
);
305 WCHANGE_STATE(WSTATE_NORMAL
);
309 /* TODO: replace this function with a member of the dock struct */
311 numberOfSelectedIcons(WDock
*dock
)
317 for (i
=1; i
<dock
->max_icons
; i
++) {
318 aicon
= dock
->icon_array
[i
];
319 if (aicon
&& aicon
->icon
->selected
) {
329 getSelected(WDock
*dock
)
331 WMArray
*ret
= WMCreateArray(8);
335 for (i
=1; i
<dock
->max_icons
; i
++) {
336 btn
= dock
->icon_array
[i
];
337 if (btn
&& btn
->icon
->selected
) {
338 WMAddToArray(ret
, btn
);
347 paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
349 Window win
= clipIcon
->icon
->core
->window
;
350 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
352 int pt
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
353 int tp
= ICON_SIZE
- pt
;
354 int as
= pt
- 15; /* 15 = 5+5+5 */
355 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
357 #ifdef GRADIENT_CLIP_ARROW
358 Bool collapsed
= clipIcon
->dock
->collapsed
;
361 if (!clipIcon
->dock
->collapsed
)
362 color
= scr
->clip_title_color
[CLIP_NORMAL
];
364 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
366 XSetForeground(dpy
, gc
, WMColorPixel(color
));
371 p
[1].x
= ICON_SIZE
-2;
373 p
[2].x
= ICON_SIZE
-2;
375 } else if (lpushed
) {
379 p
[1].y
= ICON_SIZE
-2;
381 p
[2].y
= ICON_SIZE
-2;
383 if (lpushed
|| rpushed
) {
384 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
385 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
386 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
388 #ifdef GRADIENT_CLIP_ARROW
390 XSetFillStyle(dpy
, scr
->copy_gc
, FillTiled
);
391 XSetTile(dpy
, scr
->copy_gc
, scr
->clip_arrow_gradient
);
392 XSetClipMask(dpy
, scr
->copy_gc
, None
);
395 #endif /* GRADIENT_CLIP_ARROW */
397 /* top right arrow */
398 p
[0].x
= p
[3].x
= ICON_SIZE
-5-as
;
400 p
[1].x
= ICON_SIZE
-6;
402 p
[2].x
= ICON_SIZE
-6;
405 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
406 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
408 #ifdef GRADIENT_CLIP_ARROW
410 XSetTSOrigin(dpy
, gc
, ICON_SIZE
-6-as
, 5);
412 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
413 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
416 /* bottom left arrow */
418 p
[0].y
= p
[3].y
= ICON_SIZE
-5-as
;
420 p
[1].y
= ICON_SIZE
-6;
422 p
[2].y
= ICON_SIZE
-6;
424 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
425 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
427 #ifdef GRADIENT_CLIP_ARROW
429 XSetTSOrigin(dpy
, gc
, 5, ICON_SIZE
-6-as
);
431 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
432 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
434 #ifdef GRADIENT_CLIP_ARROW
436 XSetFillStyle(dpy
, scr
->copy_gc
, FillSolid
);
442 wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
444 RImage
*tile
= RCloneImage(normalTile
);
451 pt
= CLIP_BUTTON_SIZE
*wPreferences
.icon_size
/64;
452 tp
= wPreferences
.icon_size
-1 - pt
;
456 black
.red
= black
.green
= black
.blue
= 0;
459 dark
.red
= dark
.green
= dark
.blue
= 60;
462 light
.red
= light
.green
= light
.blue
= 80;
466 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
-2,
468 RDrawLine(tile
, tp
-1, 0, wPreferences
.icon_size
-1, pt
+1, &black
);
469 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
-3,
473 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4,
474 ICON_SIZE
- 5, 4, &dark
);
475 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5,
476 ICON_SIZE
- 5, 6 + as
, &dark
);
477 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
,
481 ROperateLine(tile
, RAddOperation
, 2, tp
+2, pt
-2,
482 wPreferences
.icon_size
-3, &dark
);
483 RDrawLine(tile
, 0, tp
-1, pt
+1, wPreferences
.icon_size
-1, &black
);
484 ROperateLine(tile
, RSubtractOperation
, 0, tp
-2, pt
+1,
485 wPreferences
.icon_size
-2, &light
);
488 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4,
489 ICON_SIZE
- 5, &dark
);
490 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
,
491 6 + as
, ICON_SIZE
- 5, &dark
);
492 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5,
500 omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
502 WAppIcon
*clickedIcon
= entry
->clientdata
;
505 WMArray
*selectedIcons
;
506 WMArrayIterator iter
;
509 assert(entry
->clientdata
!=NULL
);
511 dock
= clickedIcon
->dock
;
513 selectedIcons
= getSelected(dock
);
515 if (!WMGetArrayItemCount(selectedIcons
))
516 WMAddToArray(selectedIcons
, clickedIcon
);
519 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
520 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
522 else if (aicon
->icon
->selected
)
523 wIconSelect(aicon
->icon
);
525 WMFreeArray(selectedIcons
);
528 wMessageDialog(dock
->screen_ptr
, _("Warning"),
529 _("Some icons cannot be made omnipresent. "
530 "Please make sure that no other icon is "
531 "docked in the same positions on the other "
532 "workspaces and the Clip is not full in "
534 _("OK"), NULL
, NULL
);
535 } else if (failed
== 1) {
536 wMessageDialog(dock
->screen_ptr
, _("Warning"),
537 _("Icon cannot be made omnipresent. "
538 "Please make sure that no other icon is "
539 "docked in the same position on the other "
540 "workspaces and the Clip is not full in "
542 _("OK"), NULL
, NULL
);
548 removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
550 WAppIcon
*clickedIcon
= (WAppIcon
*)entry
->clientdata
;
553 WMArray
*selectedIcons
;
557 assert(clickedIcon
!=NULL
);
559 dock
= clickedIcon
->dock
;
561 selectedIcons
= getSelected(dock
);
563 if (WMGetArrayItemCount(selectedIcons
)) {
564 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
565 _("All selected icons will be removed!"),
566 _("OK"), _("Cancel"), NULL
)!=WAPRDefault
) {
567 WMFreeArray(selectedIcons
);
571 if (clickedIcon
->xindex
==0 && clickedIcon
->yindex
==0) {
572 WMFreeArray(selectedIcons
);
575 WMAddToArray(selectedIcons
, clickedIcon
);
578 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
579 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
580 wDockDetach(dock
, aicon
);
582 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
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 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
);
1267 XMoveWindow(dpy
, aicon
->icon
->core
->window
,
1268 aicon
->x_pos
, aicon
->y_pos
);
1269 if (!dock
->mapped
|| dock
->collapsed
)
1270 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1274 if (wPreferences
.auto_arrange_icons
)
1275 wArrangeIcons(dock
->screen_ptr
, True
);
1276 wfree(dock
->icon_array
);
1277 if (dock
->menu
&& dock
->type
!=WM_CLIP
)
1278 wMenuDestroy(dock
->menu
, True
);
1279 if (dock
->screen_ptr
->last_dock
== dock
)
1280 dock
->screen_ptr
->last_dock
= NULL
;
1286 wClipIconPaint(WAppIcon
*aicon
)
1288 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1289 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1291 Window win
= aicon
->icon
->core
->window
;
1292 int length
, nlength
;
1293 char *ws_name
, ws_number
[10];
1296 wIconPaint(aicon
->icon
);
1298 length
= strlen(workspace
->name
);
1299 ws_name
= wmalloc(length
+ 1);
1300 snprintf(ws_name
, length
+1, "%s", workspace
->name
);
1301 snprintf(ws_number
, sizeof(ws_number
), "%i", scr
->current_workspace
+ 1);
1302 nlength
= strlen(ws_number
);
1304 if (!workspace
->clip
->collapsed
)
1305 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1307 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1309 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1311 tx
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
1313 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
,
1314 ty
, ws_name
, length
);
1315 /*WMDrawString(scr->wmscreen, win, color, scr->clip_title_font, 4,
1316 2, ws_name, length);*/
1318 tx
= (ICON_SIZE
/2 - WMWidthOfString(scr
->clip_title_font
, ws_number
,
1321 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
,
1322 2, ws_number
, nlength
);
1326 if (aicon
->launching
) {
1327 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1328 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1330 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
,
1331 aicon
->dock
->rclip_button_pushed
);
1336 clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1338 wClipIconPaint(desc
->parent
);
1343 dockIconPaint(WAppIcon
*btn
)
1345 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1346 wClipIconPaint(btn
);
1353 make_icon_state(WAppIcon
*btn
)
1355 WMPropList
*node
= NULL
;
1356 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
, *host
;
1357 WMPropList
*position
, *buggy
, *omnipresent
;
1363 command
= WMCreatePLString("-");
1365 command
= WMCreatePLString(btn
->command
);
1367 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1369 lock
= btn
->lock
? dYes
: dNo
;
1371 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1373 name
= WMCreatePLString(tmp
);
1377 forced
= btn
->forced_dock
? dYes
: dNo
;
1379 buggy
= btn
->buggy_app
? dYes
: dNo
;
1381 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1382 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1384 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1385 position
= WMCreatePLString(buffer
);
1387 node
= WMCreatePLDictionary(dCommand
, command
,
1389 dAutoLaunch
, autolaunch
,
1392 dBuggyApplication
, buggy
,
1393 dPosition
, position
,
1395 WMReleasePropList(command
);
1396 WMReleasePropList(name
);
1397 WMReleasePropList(position
);
1399 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1400 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&&
1401 (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1402 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1405 if (btn
->dnd_command
) {
1406 command
= WMCreatePLString(btn
->dnd_command
);
1407 WMPutInPLDictionary(node
, dDropCommand
, command
);
1408 WMReleasePropList(command
);
1410 #endif /* OFFIX_DND */
1412 if (btn
->paste_command
) {
1413 command
= WMCreatePLString(btn
->paste_command
);
1414 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1415 WMReleasePropList(command
);
1418 if (btn
->client_machine
&& btn
->remote_start
) {
1419 host
= WMCreatePLString(btn
->client_machine
);
1420 WMPutInPLDictionary(node
, dHost
, host
);
1421 WMReleasePropList(host
);
1430 dockSaveState(WDock
*dock
)
1433 WMPropList
*icon_info
;
1434 WMPropList
*list
=NULL
, *dock_state
=NULL
;
1435 WMPropList
*value
, *key
;
1438 list
= WMCreatePLArray(NULL
);
1440 for (i
=(dock
->type
==WM_DOCK
? 0 : 1); i
<dock
->max_icons
; i
++) {
1441 WAppIcon
*btn
= dock
->icon_array
[i
];
1443 if (!btn
|| btn
->attracted
)
1446 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1447 WMAddToPLArray(list
, icon_info
);
1448 WMReleasePropList(icon_info
);
1452 dock_state
= WMCreatePLDictionary(dApplications
, list
,
1455 if (dock
->type
== WM_DOCK
) {
1456 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1457 key
= WMCreatePLString(buffer
);
1458 WMPutInPLDictionary(dock_state
, key
, list
);
1459 WMReleasePropList(key
);
1462 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0),
1464 value
= WMCreatePLString(buffer
);
1465 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1466 WMReleasePropList(value
);
1468 WMReleasePropList(list
);
1471 value
= (dock
->lowered
? dYes
: dNo
);
1472 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1474 if (dock
->type
== WM_CLIP
) {
1475 value
= (dock
->collapsed
? dYes
: dNo
);
1476 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1478 value
= (dock
->auto_collapse
? dYes
: dNo
);
1479 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1481 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1482 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1484 value
= (dock
->attract_icons
? dYes
: dNo
);
1485 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1493 wDockSaveState(WScreen
*scr
, WMPropList
*old_state
)
1495 WMPropList
*dock_state
;
1498 dock_state
= dockSaveState(scr
->dock
);
1501 * Copy saved states of docks with different sizes.
1507 keys
= WMGetPLDictionaryKeys(old_state
);
1508 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1509 tmp
= WMGetFromPLArray(keys
, i
);
1511 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1512 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1514 WMPutInPLDictionary(dock_state
,
1516 WMGetFromPLDictionary(old_state
, tmp
));
1519 WMReleasePropList(keys
);
1523 WMPutInPLDictionary(scr
->session_state
, dDock
, dock_state
);
1525 WMReleasePropList(dock_state
);
1530 wClipSaveState(WScreen
*scr
)
1532 WMPropList
*clip_state
;
1534 clip_state
= make_icon_state(scr
->clip_icon
);
1536 WMPutInPLDictionary(scr
->session_state
, dClip
, clip_state
);
1538 WMReleasePropList(clip_state
);
1543 wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1545 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1550 getBooleanDockValue(WMPropList
*value
, WMPropList
*key
)
1553 if (WMIsPLString(value
)) {
1554 if (strcasecmp(WMGetFromPLString(value
), "YES")==0)
1557 wwarning(_("bad value in docked icon state info %s"),
1558 WMGetFromPLString(key
));
1566 restore_icon_state(WScreen
*scr
, WMPropList
*info
, int type
, int index
)
1569 WMPropList
*cmd
, *value
;
1572 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1573 if (!cmd
|| !WMIsPLString(cmd
)) {
1577 /* parse window name */
1578 value
= WMGetFromPLDictionary(info
, dName
);
1583 char *wclass
, *winstance
;
1586 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1588 if (!winstance
&& !wclass
) {
1595 command
= wstrdup(WMGetFromPLString(cmd
));
1599 if (!command
|| strcmp(command
, "-")==0) {
1610 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
,
1620 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1621 if (type
== WM_CLIP
) {
1622 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1623 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1625 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1626 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1630 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1632 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1635 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1637 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1639 /* check auto launch */
1640 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1642 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1645 value
= WMGetFromPLDictionary(info
, dLock
);
1647 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1649 /* check if it wasn't normally docked */
1650 value
= WMGetFromPLDictionary(info
, dForced
);
1652 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1654 /* check if we can rely on the stuff in the app */
1655 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1657 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1659 /* get position in the dock */
1660 value
= WMGetFromPLDictionary(info
, dPosition
);
1661 if (value
&& WMIsPLString(value
)) {
1662 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
,
1664 wwarning(_("bad value in docked icon state info %s"),
1665 WMGetFromPLString(dPosition
));
1667 /* check position sanity */
1668 /* incomplete section! */
1669 if (type
== WM_DOCK
) {
1671 if (aicon
->yindex
< 0)
1672 wwarning(_("bad value in docked icon position %i,%i"),
1673 aicon
->xindex
, aicon
->yindex
);
1676 aicon
->yindex
= index
;
1680 /* check if icon is omnipresent */
1681 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1683 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1692 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1696 wClipRestoreState(WScreen
*scr
, WMPropList
*clip_state
)
1702 icon
= mainIconCreate(scr
, WM_CLIP
);
1707 WMRetainPropList(clip_state
);
1709 /* restore position */
1711 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1714 if (!WMIsPLString(value
))
1715 COMPLAIN("Position");
1717 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
,
1719 COMPLAIN("Position");
1721 /* check position sanity */
1722 if (icon
->y_pos
< 0)
1724 else if (icon
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1725 icon
->y_pos
= scr
->scr_height
-ICON_SIZE
;
1727 if (icon
->x_pos
< 0)
1729 else if (icon
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1730 icon
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1735 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1736 if (value
&& WMIsPLString(value
))
1737 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1740 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1741 if (value
&& WMIsPLString(value
))
1742 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1744 WMReleasePropList(clip_state
);
1751 wDockRestoreState(WScreen
*scr
, WMPropList
*dock_state
, int type
)
1756 WAppIcon
*aicon
, *old_top
;
1760 dock
= wDockCreate(scr
, type
);
1766 WMRetainPropList(dock_state
);
1769 /* restore position */
1771 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1774 if (!WMIsPLString(value
))
1775 COMPLAIN("Position");
1777 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
,
1779 COMPLAIN("Position");
1781 /* check position sanity */
1782 if (dock
->y_pos
< 0)
1784 else if (dock
->y_pos
> scr
->scr_height
-ICON_SIZE
)
1785 dock
->y_pos
= scr
->scr_height
- ICON_SIZE
;
1787 /* This is no more needed. ??? */
1788 if (type
== WM_CLIP
) {
1789 if (dock
->x_pos
< 0)
1791 else if (dock
->x_pos
> scr
->scr_width
-ICON_SIZE
)
1792 dock
->x_pos
= scr
->scr_width
-ICON_SIZE
;
1794 if (dock
->x_pos
>= 0) {
1795 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1796 dock
->on_right_side
= 0;
1798 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1799 dock
->on_right_side
= 1;
1805 /* restore lowered/raised state */
1809 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1812 if (!WMIsPLString(value
))
1813 COMPLAIN("Lowered");
1815 if (strcasecmp(WMGetFromPLString(value
), "YES")==0)
1821 /* restore collapsed state */
1823 dock
->collapsed
= 0;
1825 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1828 if (!WMIsPLString(value
))
1829 COMPLAIN("Collapsed");
1831 if (strcasecmp(WMGetFromPLString(value
), "YES")==0)
1832 dock
->collapsed
= 1;
1837 /* restore auto-collapsed state */
1839 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1842 if (!WMIsPLString(value
))
1843 COMPLAIN("AutoCollapse");
1845 if (strcasecmp(WMGetFromPLString(value
), "YES")==0) {
1846 dock
->auto_collapse
= 1;
1847 dock
->collapsed
= 1;
1853 /* restore auto-raise/lower state */
1855 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1858 if (!WMIsPLString(value
))
1859 COMPLAIN("AutoRaiseLower");
1861 if (strcasecmp(WMGetFromPLString(value
), "YES")==0) {
1862 dock
->auto_raise_lower
= 1;
1867 /* restore attract icons state */
1869 dock
->attract_icons
= 0;
1871 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1874 if (!WMIsPLString(value
))
1875 COMPLAIN("AutoAttractIcons");
1877 if (strcasecmp(WMGetFromPLString(value
), "YES")==0)
1878 dock
->attract_icons
= 1;
1883 /* application list */
1890 * When saving, it saves the dock state in
1891 * Applications and Applicationsnnn
1893 * When loading, it will first try Applicationsnnn.
1894 * If it does not exist, use Applications as default.
1897 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1899 tmp
= WMCreatePLString(buffer
);
1900 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1901 WMReleasePropList(tmp
);
1904 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1912 count
= WMGetPropListItemCount(apps
);
1917 old_top
= dock
->icon_array
[0];
1919 /* dock->icon_count is set to 1 when dock is created.
1920 * Since Clip is already restored, we want to keep it so for clip,
1921 * but for dock we may change the default top tile, so we set it to 0.
1923 if (type
== WM_DOCK
)
1924 dock
->icon_count
= 0;
1926 for (i
=0; i
<count
; i
++) {
1927 if (dock
->icon_count
>= dock
->max_icons
) {
1928 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1932 value
= WMGetFromPLArray(apps
, i
);
1933 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1935 dock
->icon_array
[dock
->icon_count
] = aicon
;
1939 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
*ICON_SIZE
);
1940 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
*ICON_SIZE
);
1943 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1945 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1947 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
,
1950 if (!dock
->collapsed
)
1951 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1952 wRaiseFrame(aicon
->icon
->core
);
1955 } else if (dock
->icon_count
==0 && type
==WM_DOCK
)
1959 /* if the first icon is not defined, use the default */
1960 if (dock
->icon_array
[0]==NULL
) {
1961 /* update default icon */
1962 old_top
->x_pos
= dock
->x_pos
;
1963 old_top
->y_pos
= dock
->y_pos
;
1965 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1967 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1968 dock
->icon_array
[0] = old_top
;
1969 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1970 /* we don't need to increment dock->icon_count here because it was
1971 * incremented in the loop above.
1973 } else if (old_top
!=dock
->icon_array
[0]) {
1974 if (old_top
== scr
->clip_icon
)
1975 scr
->clip_icon
= dock
->icon_array
[0];
1976 wAppIconDestroy(old_top
);
1981 WMReleasePropList(dock_state
);
1989 wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1991 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1993 btn
->drop_launch
= 0;
1994 btn
->paste_launch
= 0;
1996 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1999 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
2011 wDockDoAutoLaunch(WDock
*dock
, int workspace
)
2017 for (i
= 0; i
< dock
->max_icons
; i
++) {
2018 btn
= dock
->icon_array
[i
];
2019 if (!btn
|| !btn
->auto_launch
)
2022 state
= wmalloc(sizeof(WSavedState
));
2023 memset(state
, 0, sizeof(WSavedState
));
2024 state
->workspace
= workspace
;
2025 /* TODO: this is klugy and is very difficult to understand
2026 * what's going on. Try to clean up */
2027 wDockLaunchWithState(dock
, btn
, state
);
2034 findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
2040 if ((dock
= scr
->dock
)!=NULL
) {
2041 for (i
=0; i
<dock
->max_icons
; i
++) {
2042 if (dock
->icon_array
[i
]
2043 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
2049 if (*icon_pos
<0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
)!=NULL
) {
2050 for (i
=0; i
<dock
->max_icons
; i
++) {
2051 if (dock
->icon_array
[i
]
2052 && dock
->icon_array
[i
]->icon
->core
->window
==event
->xclient
.window
) {
2065 wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
2071 dock
= findDock(scr
, event
, &icon_pos
);
2076 * Return True if the drop was on an application icon window.
2077 * In this case, let the ClientMessage handler redirect the
2078 * message to the app.
2080 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!=None
)
2083 if (dock
->icon_array
[icon_pos
]->dnd_command
!=NULL
) {
2084 scr
->flags
.dnd_data_convertion_status
= 0;
2086 btn
= dock
->icon_array
[icon_pos
];
2088 if (!btn
->forced_dock
) {
2089 btn
->relaunching
= btn
->running
;
2092 if (btn
->wm_instance
|| btn
->wm_class
) {
2093 WWindowAttributes attr
;
2094 memset(&attr
, 0, sizeof(WWindowAttributes
));
2095 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
2097 btn
->wm_class
, &attr
, NULL
, True
);
2099 if (!attr
.no_appicon
)
2105 btn
->paste_launch
= 0;
2106 btn
->drop_launch
= 1;
2107 scr
->last_dock
= dock
;
2108 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
2113 if (!btn
->relaunching
) {
2120 #endif /* OFFIX_DND */
2125 wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2132 wwin
= icon
->icon
->owner
;
2133 if (icon
->command
==NULL
) {
2135 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2137 icon
->command
= wtokenjoin(argv
, argc
);
2138 XFreeStringList(argv
);
2142 /* icon->forced_dock = 1;*/
2143 if (dock
->type
!=WM_CLIP
|| !icon
->attracted
) {
2145 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2146 _("Type the command used to launch the application"),
2148 if (command
&& (command
[0]==0 ||
2149 (command
[0]=='-' && command
[1]==0))) {
2153 icon
->command
= command
;
2159 /* If the target is the dock, reject the icon. If
2160 * the target is the clip, make it an attracted icon
2162 if (dock
->type
==WM_CLIP
) {
2163 icon
->attracted
= 1;
2164 if (!icon
->icon
->shadowed
) {
2165 icon
->icon
->shadowed
= 1;
2166 icon
->icon
->force_paint
= 1;
2178 for (index
=1; index
<dock
->max_icons
; index
++)
2179 if (dock
->icon_array
[index
] == NULL
)
2181 /* if (index == dock->max_icons)
2184 assert(index
< dock
->max_icons
);
2186 dock
->icon_array
[index
] = icon
;
2190 icon
->omnipresent
= 0;
2192 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2193 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2198 icon
->launching
= 0;
2201 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2202 if (dock
->type
== WM_CLIP
) {
2203 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2204 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2206 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2207 icon
->icon
->core
->descriptor
.parent
= icon
;
2209 MoveInStackListUnder(dock
->icon_array
[index
-1]->icon
->core
,
2211 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2212 wAppIconPaint(icon
);
2214 if (wPreferences
.auto_arrange_icons
)
2215 wArrangeIcons(dock
->screen_ptr
, True
);
2218 if (icon
->command
&& !icon
->dnd_command
) {
2219 int len
= strlen(icon
->command
)+8;
2220 icon
->dnd_command
= wmalloc(len
);
2221 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
2225 if (icon
->command
&& !icon
->paste_command
) {
2226 int len
= strlen(icon
->command
)+8;
2227 icon
->paste_command
= wmalloc(len
);
2228 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
2236 reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2240 for(index
=1; index
<dock
->max_icons
; index
++) {
2241 if(dock
->icon_array
[index
] == icon
)
2244 assert(index
< dock
->max_icons
);
2249 icon
->x_pos
= dock
->x_pos
+ x
*ICON_SIZE
;
2250 icon
->y_pos
= dock
->y_pos
+ y
*ICON_SIZE
;
2255 moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2263 return True
; /* No move needed, we're already there */
2268 wwin
= icon
->icon
->owner
;
2271 * For the moment we can't do this if we move icons in Clip from one
2272 * workspace to other, because if we move two or more icons without
2273 * command, the dialog box will not be able to tell us to which of the
2274 * moved icons it applies. -Dan
2276 if ((dest
->type
==WM_DOCK
/*|| dest->keep_attracted*/) && icon
->command
==NULL
) {
2277 if (XGetCommand(dpy
, wwin
->client_win
, &argv
, &argc
) && argc
>0) {
2279 icon
->command
= wtokenjoin(argv
, argc
);
2280 XFreeStringList(argv
);
2285 /* icon->forced_dock = 1;*/
2286 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2287 _("Type the command used to launch the application"),
2289 if (command
&& (command
[0]==0 ||
2290 (command
[0]=='-' && command
[1]==0))) {
2294 icon
->command
= command
;
2305 if (dest
->type
== WM_DOCK
)
2306 wClipMakeIconOmnipresent(icon
, False
);
2308 for(index
=1; index
<src
->max_icons
; index
++) {
2309 if(src
->icon_array
[index
] == icon
)
2312 assert(index
< src
->max_icons
);
2314 src
->icon_array
[index
] = NULL
;
2317 for(index
=1; index
<dest
->max_icons
; index
++) {
2318 if(dest
->icon_array
[index
] == NULL
)
2321 /* if (index == dest->max_icons)
2324 assert(index
< dest
->max_icons
);
2326 dest
->icon_array
[index
] = icon
;
2329 /* deselect the icon */
2330 if (icon
->icon
->selected
)
2331 wIconSelect(icon
->icon
);
2333 if (dest
->type
== WM_DOCK
) {
2334 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2335 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2337 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2338 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2341 /* set it to be kept when moving to dock.
2342 * Unless the icon does not have a command set
2344 if (icon
->command
&& dest
->type
==WM_DOCK
) {
2345 icon
->attracted
= 0;
2346 if (icon
->icon
->shadowed
) {
2347 icon
->icon
->shadowed
= 0;
2348 icon
->icon
->force_paint
= 1;
2352 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2358 icon
->x_pos
= dest
->x_pos
+ x
*ICON_SIZE
;
2359 icon
->y_pos
= dest
->y_pos
+ y
*ICON_SIZE
;
2363 MoveInStackListUnder(dest
->icon_array
[index
-1]->icon
->core
,
2365 wAppIconPaint(icon
);
2372 wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2376 /* make the settings panel be closed */
2378 DestroyDockAppSettingsPanel(icon
->panel
);
2381 /* This must be called before icon->dock is set to NULL.
2382 * Don't move it. -Dan
2384 wClipMakeIconOmnipresent(icon
, False
);
2388 icon
->attracted
= 0;
2389 icon
->auto_launch
= 0;
2390 if (icon
->icon
->shadowed
) {
2391 icon
->icon
->shadowed
= 0;
2392 icon
->icon
->force_paint
= 1;
2395 /* deselect the icon */
2396 if (icon
->icon
->selected
)
2397 wIconSelect(icon
->icon
);
2399 if (icon
->command
) {
2400 wfree(icon
->command
);
2401 icon
->command
= NULL
;
2404 if (icon
->dnd_command
) {
2405 wfree(icon
->dnd_command
);
2406 icon
->dnd_command
= NULL
;
2409 if (icon
->paste_command
) {
2410 wfree(icon
->paste_command
);
2411 icon
->paste_command
= NULL
;
2414 for (index
=1; index
<dock
->max_icons
; index
++)
2415 if (dock
->icon_array
[index
] == icon
)
2417 assert(index
< dock
->max_icons
);
2418 dock
->icon_array
[index
] = NULL
;
2424 /* if the dock is not attached to an application or
2425 * the the application did not set the approriate hints yet,
2426 * destroy the icon */
2427 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2428 wAppIconDestroy(icon
);
2430 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2431 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2432 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2433 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2434 icon
->icon
->core
->descriptor
.parent
= icon
;
2436 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2438 wAppIconPaint(icon
);
2439 if (wPreferences
.auto_arrange_icons
) {
2440 wArrangeIcons(dock
->screen_ptr
, True
);
2443 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2449 * returns the closest Dock slot index for the passed
2452 * Returns False if icon can't be docked.
2454 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2458 wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
,
2459 int *ret_x
, int *ret_y
, int redocking
)
2461 WScreen
*scr
= dock
->screen_ptr
;
2464 int i
, offset
= ICON_SIZE
/2;
2465 WAppIcon
*aicon
= NULL
;
2466 WAppIcon
*nicon
= NULL
;
2467 int max_y_icons
, max_x_icons
;
2469 max_x_icons
= scr
->scr_width
/ICON_SIZE
;
2470 max_y_icons
= scr
->scr_height
/ICON_SIZE
-1;
2472 if (wPreferences
.flags
.noupdates
)
2478 /* if the dock is full */
2480 (dock
->icon_count
>= dock
->max_icons
)) {
2484 /* exact position */
2486 ex_y
= (req_y
- offset
- dy
)/ICON_SIZE
;
2488 ex_y
= (req_y
+ offset
- dy
)/ICON_SIZE
;
2491 ex_x
= (req_x
- offset
- dx
)/ICON_SIZE
;
2493 ex_x
= (req_x
+ offset
- dx
)/ICON_SIZE
;
2495 /* check if the icon is outside the screen boundaries */
2496 if (dx
+ ex_x
*ICON_SIZE
< -ICON_SIZE
+2 ||
2497 dx
+ ex_x
*ICON_SIZE
>= scr
->scr_width
-1 ||
2498 dy
+ ex_y
*ICON_SIZE
< -ICON_SIZE
+2 ||
2499 dy
+ ex_y
*ICON_SIZE
>= scr
->scr_height
-1)
2502 if (dock
->type
== WM_DOCK
) {
2503 if (icon
->dock
!= dock
&& ex_x
!= 0)
2507 for (i
=0; i
<dock
->max_icons
; i
++) {
2508 nicon
= dock
->icon_array
[i
];
2509 if (nicon
&& nicon
->yindex
== ex_y
) {
2516 int sig
, done
, closest
;
2518 /* Possible cases when redocking:
2520 * icon dragged out of range of any slot -> false
2521 * icon dragged to range of free slot
2522 * icon dragged to range of same slot
2523 * icon dragged to range of different icon
2525 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2528 if (ex_y
>=0 && ex_y
<=max_y_icons
&& (aicon
==icon
|| !aicon
)) {
2534 /* start looking at the upper slot or lower? */
2535 if (ex_y
*ICON_SIZE
< (req_y
+ offset
- dy
))
2542 /* look for closest free slot */
2543 for (i
=0; i
<(DOCK_DETTACH_THRESHOLD
+1)*2 && !done
; i
++) {
2547 closest
= sig
*(i
/2) + ex_y
;
2548 /* check if this slot is used */
2550 for (j
= 0; j
<dock
->max_icons
; j
++) {
2551 if (dock
->icon_array
[j
]
2552 && dock
->icon_array
[j
]->yindex
==closest
) {
2553 /* slot is used by someone else */
2554 if (dock
->icon_array
[j
]!=icon
)
2562 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2563 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+1)
2565 (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+1))) {
2570 } else { /* !redocking */
2572 /* if slot is free and the icon is close enough, return it */
2573 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2583 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2584 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+1;
2587 for (k
=start
; k
<stop
; k
++) {
2588 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2591 for (i
=0; i
<tmp
->max_icons
; i
++) {
2592 nicon
= tmp
->icon_array
[i
];
2593 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2601 for (k
=start
; k
<stop
; k
++) {
2602 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2605 for (i
=0; i
<tmp
->max_icons
; i
++) {
2606 nicon
= tmp
->icon_array
[i
];
2607 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2608 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2609 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2618 if (neighbours
&& (aicon
==NULL
|| (redocking
&& aicon
== icon
))) {
2628 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2629 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2630 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2634 * returns true if it can find a free slot in the dock,
2635 * in which case it changes x_pos and y_pos accordingly.
2636 * Else returns false.
2639 wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2641 WScreen
*scr
= dock
->screen_ptr
;
2643 WAppIconChain
*chain
;
2644 unsigned char *slot_map
;
2648 int i
, done
= False
;
2650 int sx
=0, sy
=0, ex
=scr
->scr_width
, ey
=scr
->scr_height
;
2653 if (dock
->type
== WM_CLIP
&&
2654 dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2655 extra_count
= scr
->global_icon_count
;
2657 /* if the dock is full */
2658 if (dock
->icon_count
+extra_count
>= dock
->max_icons
) {
2662 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2663 if (scr
->dock
->on_right_side
)
2664 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2666 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2669 if (ex
< dock
->x_pos
)
2671 if (sx
> dock
->x_pos
+ICON_SIZE
)
2672 sx
= dock
->x_pos
+ICON_SIZE
;
2679 /* check if clip is in a corner */
2680 if (dock
->type
==WM_CLIP
) {
2681 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2683 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
-ICON_SIZE
))
2685 else if (dock
->x_pos
>= (ex
-ICON_SIZE
)&& dock
->y_pos
>= (ey
-ICON_SIZE
))
2687 else if (dock
->x_pos
>= (ex
-ICON_SIZE
) && dock
->y_pos
< 1)
2694 /* If the clip is in the corner, use only slots that are in the border
2696 if (corner
!=C_NONE
) {
2700 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ICON_SIZE
);
2701 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ICON_SIZE
);
2702 hmap
= wmalloc(hcount
+1);
2703 memset(hmap
, 0, hcount
+1);
2704 vmap
= wmalloc(vcount
+1);
2705 memset(vmap
, 0, vcount
+1);
2707 /* mark used positions */
2710 for (i
=0; i
<dock
->max_icons
; i
++) {
2711 btn
= dock
->icon_array
[i
];
2715 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2716 vmap
[btn
->yindex
] = 1;
2717 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2718 hmap
[btn
->xindex
] = 1;
2720 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2722 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2723 vmap
[btn
->yindex
] = 1;
2724 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2725 hmap
[btn
->xindex
] = 1;
2729 for (i
=0; i
<dock
->max_icons
; i
++) {
2730 btn
= dock
->icon_array
[i
];
2734 if (btn
->xindex
==0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2735 vmap
[btn
->yindex
] = 1;
2736 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2737 hmap
[-btn
->xindex
] = 1;
2739 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
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;
2748 for (i
=0; i
<dock
->max_icons
; i
++) {
2749 btn
= dock
->icon_array
[i
];
2753 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2754 vmap
[-btn
->yindex
] = 1;
2755 else if (btn
->yindex
==0 && btn
->xindex
>0 && btn
->xindex
<hcount
)
2756 hmap
[btn
->xindex
] = 1;
2758 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
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;
2768 for (i
=0; i
<dock
->max_icons
; i
++) {
2769 btn
= dock
->icon_array
[i
];
2773 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2774 vmap
[-btn
->yindex
] = 1;
2775 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2776 hmap
[-btn
->xindex
] = 1;
2778 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2780 if (btn
->xindex
==0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2781 vmap
[-btn
->yindex
] = 1;
2782 else if (btn
->yindex
==0 && btn
->xindex
<0 &&btn
->xindex
>-hcount
)
2783 hmap
[-btn
->xindex
] = 1;
2788 /* search a vacant slot */
2789 for (i
=1; i
<WMAX(vcount
, hcount
); i
++) {
2790 if (i
< vcount
&& vmap
[i
]==0) {
2796 } else if (i
< hcount
&& hmap
[i
]==0) {
2806 /* If found a slot, translate and return */
2808 if (corner
==C_NW
|| corner
==C_NE
) {
2813 if (corner
==C_NE
|| corner
==C_SE
) {
2820 /* else, try to find a slot somewhere else */
2823 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2824 * placed outside of screen */
2825 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2827 /* In the worst case (the clip is in the corner of the screen),
2828 * the amount of icons that fit in the clip is smaller.
2829 * Double the map to get a safe value.
2835 slot_map
= wmalloc(mwidth
*mwidth
);
2836 memset(slot_map
, 0, mwidth
*mwidth
);
2838 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2840 /* mark used slots in the map. If the slot falls outside the map
2841 * (for example, when all icons are placed in line), ignore them. */
2842 for (i
=0; i
<dock
->max_icons
; i
++) {
2843 btn
= dock
->icon_array
[i
];
2845 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2847 for (chain
=scr
->global_icons
; chain
!=NULL
; chain
=chain
->next
) {
2848 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2850 /* Find closest slot from the center that is free by scanning the
2851 * map from the center to outward in circular passes.
2852 * This will not result in a neat layout, but will be optimal
2853 * in the sense that there will not be holes left.
2856 for (i
= 1; i
<= r
&& !done
; i
++) {
2859 /* top and bottom parts of the ring */
2860 for (x
= -i
; x
<= i
&& !done
; x
++) {
2861 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2863 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2864 if (slot_map
[XY2OFS(x
,y
)]==0
2865 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2872 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2873 if (slot_map
[XY2OFS(x
,y
)]==0
2874 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2881 /* left and right parts of the ring */
2882 for (y
= -i
+1; y
<= i
-1; y
++) {
2883 ty
= dock
->y_pos
+ y
*ICON_SIZE
;
2885 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2886 if (slot_map
[XY2OFS(x
,y
)]==0
2887 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2894 tx
= dock
->x_pos
+ x
*ICON_SIZE
;
2895 if (slot_map
[XY2OFS(x
,y
)]==0
2896 && ON_SCREEN(tx
, ty
, sx
, ex
, sy
, ey
)) {
2911 moveDock(WDock
*dock
, int new_x
, int new_y
)
2916 dock
->x_pos
= new_x
;
2917 dock
->y_pos
= new_y
;
2918 for (i
=0; i
<dock
->max_icons
; i
++) {
2919 btn
= dock
->icon_array
[i
];
2921 btn
->x_pos
= new_x
+ btn
->xindex
*ICON_SIZE
;
2922 btn
->y_pos
= new_y
+ btn
->yindex
*ICON_SIZE
;
2923 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2930 swapDock(WDock
*dock
)
2932 WScreen
*scr
= dock
->screen_ptr
;
2937 if (dock
->on_right_side
) {
2938 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2940 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2943 for (i
=0; i
<dock
->max_icons
; i
++) {
2944 btn
= dock
->icon_array
[i
];
2947 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2951 wScreenUpdateUsableArea(scr
);
2956 execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2958 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2964 cmdline
= ExpandOptions(scr
, command
);
2966 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2974 wtokensplit(cmdline
, &argv
, &argc
);
2984 if ((pid
=fork())==0) {
2988 SetupEnvironment(scr
);
2994 args
= malloc(sizeof(char*)*(argc
+1));
2997 for (i
=0; i
<argc
; i
++) {
3001 execvp(argv
[0], args
);
3004 wtokenfree(argv
, argc
);
3008 state
= wmalloc(sizeof(WSavedState
));
3009 memset(state
, 0, sizeof(WSavedState
));
3011 state
->miniaturized
= -1;
3013 if (btn
->dock
==scr
->dock
|| btn
->omnipresent
)
3014 state
->workspace
= -1;
3016 state
->workspace
= scr
->current_workspace
;
3018 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
,
3020 wAddDeathHandler(pid
, (WDeathHandler
*)trackDeadProcess
,
3031 wDockHideIcons(WDock
*dock
)
3038 for (i
=1; i
<dock
->max_icons
; i
++) {
3039 if (dock
->icon_array
[i
])
3040 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3044 dockIconPaint(dock
->icon_array
[0]);
3049 wDockShowIcons(WDock
*dock
)
3057 btn
= dock
->icon_array
[0];
3058 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
3060 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
3061 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
3063 for (i
=1; i
<dock
->max_icons
; i
++) {
3064 if (dock
->icon_array
[i
]) {
3065 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
,
3071 if (!dock
->collapsed
) {
3072 for (i
=1; i
<dock
->max_icons
; i
++) {
3073 if (dock
->icon_array
[i
]) {
3074 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3085 wDockLower(WDock
*dock
)
3089 for (i
=0; i
<dock
->max_icons
; i
++) {
3090 if (dock
->icon_array
[i
])
3091 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
3097 wDockRaise(WDock
*dock
)
3101 for (i
=dock
->max_icons
-1; i
>=0; i
--) {
3102 if (dock
->icon_array
[i
])
3103 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
3109 wDockRaiseLower(WDock
*dock
)
3111 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
3112 ||(dock
->icon_array
[0]->icon
->core
->stacking
->window_level
3113 !=dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
3121 wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
3123 icon
->launching
= 0;
3124 icon
->relaunching
= 0;
3125 dockIconPaint(icon
);
3130 wDockFindIconForWindow(WDock
*dock
, Window window
)
3135 for (i
=0; i
<dock
->max_icons
; i
++) {
3136 icon
= dock
->icon_array
[i
];
3137 if (icon
&& icon
->main_window
== window
)
3145 wDockTrackWindowLaunch(WDock
*dock
, Window window
)
3148 char *wm_class
, *wm_instance
;
3150 Bool firstPass
= True
;
3152 char *command
= NULL
;
3158 if (XGetCommand(dpy
, window
, &argv
, &argc
)) {
3159 if (argc
> 0 && argv
!= NULL
)
3160 command
= wtokenjoin(argv
, argc
);
3162 XFreeStringList(argv
);
3167 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) ||
3168 (!wm_class
&& !wm_instance
))
3172 for (i
=0; i
<dock
->max_icons
; i
++) {
3173 icon
= dock
->icon_array
[i
];
3177 /* app is already attached to icon */
3178 if (icon
->main_window
== window
) {
3183 if ((icon
->wm_instance
|| icon
->wm_class
)
3184 && (icon
->launching
|| !icon
->running
)) {
3186 if (icon
->wm_instance
&& wm_instance
&&
3187 strcmp(icon
->wm_instance
, wm_instance
)!=0) {
3190 if (icon
->wm_class
&& wm_class
&&
3191 strcmp(icon
->wm_class
, wm_class
)!=0) {
3194 if (firstPass
&& command
&& strcmp(icon
->command
, command
)!=0) {
3198 if (!icon
->relaunching
) {
3201 /* Possibly an application that was docked with dockit,
3202 * but the user did not update WMState to indicate that
3203 * it was docked by force */
3204 wapp
= wApplicationOf(window
);
3206 icon
->forced_dock
= 1;
3209 if (!icon
->forced_dock
)
3210 icon
->main_window
= window
;
3214 if (!wPreferences
.no_animations
&& !icon
->launching
&&
3215 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
3219 icon
->launching
= 1;
3220 dockIconPaint(icon
);
3222 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
3223 wm_instance
, wm_class
,
3225 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
);
3226 wAppIconMove(aicon
, x0
, y0
);
3227 /* Should this always be lowered? -Dan */
3229 wLowerFrame(aicon
->icon
->core
);
3230 XMapWindow(dpy
, aicon
->icon
->core
->window
);
3231 aicon
->launching
= 1;
3232 wAppIconPaint(aicon
);
3233 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
,
3234 icon
->x_pos
, icon
->y_pos
);
3235 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
3236 wAppIconDestroy(aicon
);
3238 wDockFinishLaunch(dock
, icon
);
3243 if (firstPass
&& !found
) {
3260 wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3262 if (!wPreferences
.flags
.noclip
) {
3263 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3264 if (scr
->current_workspace
!= workspace
) {
3265 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3266 WAppIconChain
*chain
= scr
->global_icons
;
3269 moveIconBetweenDocks(chain
->aicon
->dock
,
3270 scr
->workspaces
[workspace
]->clip
,
3271 chain
->aicon
, chain
->aicon
->xindex
,
3272 chain
->aicon
->yindex
);
3273 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
3274 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3275 chain
= chain
->next
;
3278 wDockHideIcons(old_clip
);
3279 if (old_clip
->auto_raise_lower
) {
3280 if (old_clip
->auto_raise_magic
) {
3281 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3282 old_clip
->auto_raise_magic
= NULL
;
3284 wDockLower(old_clip
);
3286 if (old_clip
->auto_collapse
) {
3287 if (old_clip
->auto_expand_magic
) {
3288 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3289 old_clip
->auto_expand_magic
= NULL
;
3291 old_clip
->collapsed
= 1;
3293 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3295 if (scr
->flags
.clip_balloon_mapped
)
3296 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3303 trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3308 for (i
=0; i
<dock
->max_icons
; i
++) {
3309 icon
= dock
->icon_array
[i
];
3313 if (icon
->launching
&& icon
->pid
== pid
) {
3314 if (!icon
->relaunching
) {
3316 icon
->main_window
= None
;
3318 wDockFinishLaunch(dock
, icon
);
3324 if (icon
->drop_launch
)
3325 cmd
= icon
->dnd_command
;
3326 else if (icon
->paste_launch
)
3327 cmd
= icon
->paste_command
;
3329 cmd
= icon
->command
;
3331 snprintf(msg
, sizeof(msg
),
3332 _("Could not execute command \"%s\""), cmd
);
3334 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
,
3335 _("OK"), NULL
, NULL
);
3344 toggleLowered(WDock
*dock
)
3349 /* lower/raise Dock */
3350 if (!dock
->lowered
) {
3351 newlevel
= WMNormalLevel
;
3354 newlevel
= WMDockLevel
;
3358 for (i
=0; i
<dock
->max_icons
; i
++) {
3359 tmp
= dock
->icon_array
[i
];
3363 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3365 wLowerFrame(tmp
->icon
->core
);
3368 if (dock
->type
== WM_DOCK
)
3369 wScreenUpdateUsableArea(dock
->screen_ptr
);
3374 toggleCollapsed(WDock
*dock
)
3376 if (dock
->collapsed
) {
3377 dock
->collapsed
= 0;
3378 wDockShowIcons(dock
);
3381 dock
->collapsed
= 1;
3382 wDockHideIcons(dock
);
3388 openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3390 WScreen
*scr
= dock
->screen_ptr
;
3391 WObjDescriptor
*desc
;
3393 WApplication
*wapp
= NULL
;
3397 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3399 if (dock
->type
== WM_DOCK
) {
3401 entry
= dock
->menu
->entries
[index
];
3402 entry
->flags
.indicator_on
= !dock
->lowered
;
3403 entry
->clientdata
= dock
;
3404 dock
->menu
->flags
.realized
= 0;
3407 if (scr
->clip_options
)
3408 updateClipOptionsMenu(scr
->clip_options
, dock
);
3410 n_selected
= numberOfSelectedIcons(dock
);
3412 /* Rename Workspace */
3413 entry
= dock
->menu
->entries
[++index
];
3414 if (aicon
== scr
->clip_icon
) {
3415 entry
->callback
= renameCallback
;
3416 entry
->clientdata
= dock
;
3417 entry
->flags
.indicator
= 0;
3418 entry
->text
= _("Rename Workspace");
3420 entry
->callback
= omnipresentCallback
;
3421 entry
->clientdata
= aicon
;
3422 if (n_selected
> 0) {
3423 entry
->flags
.indicator
= 0;
3424 entry
->text
= _("Toggle Omnipresent");
3426 entry
->flags
.indicator
= 1;
3427 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3428 entry
->flags
.indicator_type
= MI_CHECK
;
3429 entry
->text
= _("Omnipresent");
3433 /* select/unselect icon */
3434 entry
= dock
->menu
->entries
[++index
];
3435 entry
->clientdata
= aicon
;
3436 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3437 wMenuSetEnabled(dock
->menu
, index
, aicon
!=scr
->clip_icon
);
3439 /* select/unselect all icons */
3440 entry
= dock
->menu
->entries
[++index
];
3441 entry
->clientdata
= aicon
;
3443 entry
->text
= _("Unselect All Icons");
3445 entry
->text
= _("Select All Icons");
3446 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3449 entry
= dock
->menu
->entries
[++index
];
3450 entry
->clientdata
= aicon
;
3452 entry
->text
= _("Keep Icons");
3454 entry
->text
= _("Keep Icon");
3455 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3457 /* this is the workspace submenu part */
3458 entry
= dock
->menu
->entries
[++index
];
3460 entry
->text
= _("Move Icons To");
3462 entry
->text
= _("Move Icon To");
3463 if (scr
->clip_submenu
)
3464 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3465 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3467 /* remove icon(s) */
3468 entry
= dock
->menu
->entries
[++index
];
3469 entry
->clientdata
= aicon
;
3471 entry
->text
= _("Remove Icons");
3473 entry
->text
= _("Remove Icon");
3474 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3476 /* attract icon(s) */
3477 entry
= dock
->menu
->entries
[++index
];
3478 entry
->clientdata
= aicon
;
3480 dock
->menu
->flags
.realized
= 0;
3481 wMenuRealize(dock
->menu
);
3485 if (aicon
->icon
->owner
) {
3486 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3492 entry
= dock
->menu
->entries
[++index
];
3493 entry
->clientdata
= aicon
;
3494 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!=NULL
);
3497 entry
= dock
->menu
->entries
[++index
];
3498 entry
->clientdata
= aicon
;
3499 if (wapp
&& wapp
->flags
.hidden
) {
3500 entry
->text
= _("Unhide Here");
3502 entry
->text
= _("Bring Here");
3504 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3507 entry
= dock
->menu
->entries
[++index
];
3508 entry
->clientdata
= aicon
;
3509 if (wapp
&& wapp
->flags
.hidden
) {
3510 entry
->text
= _("Unhide");
3512 entry
->text
= _("Hide");
3514 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3517 entry
= dock
->menu
->entries
[++index
];
3518 entry
->clientdata
= aicon
;
3519 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
3520 && !wPreferences
.flags
.noupdates
);
3523 entry
= dock
->menu
->entries
[++index
];
3524 entry
->clientdata
= aicon
;
3525 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3527 if (!dock
->menu
->flags
.realized
)
3528 wMenuRealize(dock
->menu
);
3530 if (dock
->type
== WM_CLIP
) {
3531 /*x_pos = event->xbutton.x_root+2;*/
3532 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/2 - 1;
3535 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
-2) {
3536 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3539 x_pos
= dock
->on_right_side
?
3540 scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3543 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+2, False
);
3545 /* allow drag select */
3546 event
->xany
.send_event
= True
;
3547 desc
= &dock
->menu
->menu
->descriptor
;
3548 (*desc
->handle_mousedown
)(desc
, event
);
3553 openClipWorkspaceMenu(WScreen
*scr
, int x
, int y
)
3555 if (!scr
->clip_ws_menu
) {
3556 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3558 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
3559 wMenuMapAt(scr
->clip_ws_menu
, x
, y
, False
);
3563 /******************************************************************/
3565 iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3567 WAppIcon
*btn
= desc
->parent
;
3568 WDock
*dock
= btn
->dock
;
3569 WApplication
*wapp
= NULL
;
3572 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3573 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3577 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3579 /* go to the last workspace that the user worked on the app */
3580 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
3582 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3585 wUnhideApplication(wapp
, event
->xbutton
.button
==Button2
,
3588 if (event
->xbutton
.state
& MOD_MASK
) {
3589 wHideOtherApplications(btn
->icon
->owner
);
3592 if (event
->xbutton
.button
==Button1
) {
3594 if (event
->xbutton
.state
& MOD_MASK
) {
3595 /* raise/lower dock */
3596 toggleLowered(dock
);
3597 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3598 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
)
3599 toggleCollapsed(dock
);
3601 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3602 } else if (btn
->command
) {
3603 if (!btn
->launching
&&
3604 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3605 launchDockedApplication(btn
, False
);
3607 } else if (btn
->xindex
== 0 && btn
->yindex
== 0
3608 && btn
->dock
->type
== WM_DOCK
) {
3610 wShowGNUstepPanel(dock
->screen_ptr
);
3619 handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3621 WScreen
*scr
= dock
->screen_ptr
;
3622 int ofs_x
=event
->xbutton
.x
, ofs_y
=event
->xbutton
.y
;
3625 int grabbed
= 0, swapped
= 0, done
;
3626 Pixmap ghost
= None
;
3627 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3630 puts("moving dock");
3632 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3633 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3634 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3635 wwarning("pointer grab failed for dock move");
3638 for (x
=0; x
<dock
->max_icons
; x
++) {
3639 if (dock
->icon_array
[x
]!=NULL
&&
3640 dock
->icon_array
[x
]->yindex
> y
)
3641 y
= dock
->icon_array
[x
]->yindex
;
3644 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
*y
);
3648 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3649 |ButtonMotionMask
|ExposureMask
, &ev
);
3657 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3658 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3659 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3660 |ButtonReleaseMask
|ButtonPressMask
,
3661 wCursor
[WCUR_MOVE
], CurrentTime
);
3666 if (dock
->type
== WM_CLIP
) {
3667 if (ev
.xmotion
.x_root
- ofs_x
< 0) {
3669 } else if (ev
.xmotion
.x_root
- ofs_x
+ ICON_SIZE
>
3671 x
= scr
->scr_width
- ICON_SIZE
;
3673 x
= ev
.xmotion
.x_root
- ofs_x
;
3675 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3677 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3679 y
= scr
->scr_height
- ICON_SIZE
;
3681 y
= ev
.xmotion
.y_root
- ofs_y
;
3683 moveDock(dock
, x
, y
);
3685 /* move vertically if pointer is inside the dock*/
3686 if ((dock
->on_right_side
&&
3687 ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3688 || (!dock
->on_right_side
&&
3689 ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
*2)) {
3691 if (ev
.xmotion
.y_root
- ofs_y
< 0) {
3693 } else if (ev
.xmotion
.y_root
- ofs_y
+ ICON_SIZE
>
3695 y
= scr
->scr_height
- ICON_SIZE
;
3697 y
= ev
.xmotion
.y_root
- ofs_y
;
3699 moveDock(dock
, dock
->x_pos
, y
);
3701 /* move horizontally to change sides */
3702 x
= ev
.xmotion
.x_root
- ofs_x
;
3703 if (!dock
->on_right_side
) {
3707 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
*2) {
3708 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
-ICON_SIZE
3709 -DOCK_EXTRA_SPACE
-1, dock
->y_pos
);
3710 if (superfluous
&& ghost
==None
) {
3711 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3712 scr
->scr_width
-ICON_SIZE
3713 -DOCK_EXTRA_SPACE
-1,
3715 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3717 XClearWindow(dpy
, scr
->dock_shadow
);
3719 XMapRaised(dpy
, scr
->dock_shadow
);
3722 if (superfluous
&& ghost
!=None
) {
3723 XFreePixmap(dpy
, ghost
);
3726 XUnmapWindow(dpy
, scr
->dock_shadow
);
3731 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3732 XMoveWindow(dpy
, scr
->dock_shadow
,
3733 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3734 if (superfluous
&& ghost
==None
) {
3735 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3736 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3737 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
,
3739 XClearWindow(dpy
, scr
->dock_shadow
);
3741 XMapRaised(dpy
, scr
->dock_shadow
);
3744 XUnmapWindow(dpy
, scr
->dock_shadow
);
3746 if (superfluous
&& ghost
!=None
) {
3747 XFreePixmap(dpy
, ghost
);
3759 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3761 XUngrabPointer(dpy
, CurrentTime
);
3762 XUnmapWindow(dpy
, scr
->dock_shadow
);
3763 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3764 if (dock
->type
== WM_DOCK
) {
3767 dock
->on_right_side
= 1;
3769 dock
->on_right_side
= 0;
3771 wArrangeIcons(scr
, False
);
3780 XFreePixmap(dpy
, ghost
);
3781 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3784 puts("End dock move");
3791 handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3793 WScreen
*scr
= dock
->screen_ptr
;
3795 WIcon
*icon
= aicon
->icon
;
3796 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3797 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3799 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3800 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3801 int shad_x
= x
, shad_y
= y
;
3802 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3804 Pixmap ghost
= None
;
3806 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3807 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3810 if (wPreferences
.flags
.noupdates
)
3813 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3814 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
3815 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
3817 wwarning("pointer grab failed for icon move");
3821 if (!(event
->xbutton
.state
& MOD_MASK
))
3822 wRaiseFrame(icon
->core
);
3824 if (!wPreferences
.flags
.noclip
)
3825 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3827 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3829 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3832 wins
[0] = icon
->core
->window
;
3833 wins
[1] = scr
->dock_shadow
;
3834 XRestackWindows(dpy
, wins
, 2);
3835 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3836 ICON_SIZE
, ICON_SIZE
);
3838 if (icon
->pixmap
!=None
)
3839 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3841 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3843 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3844 XClearWindow(dpy
, scr
->dock_shadow
);
3846 XMapWindow(dpy
, scr
->dock_shadow
);
3852 XMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
3853 |ButtonMotionMask
|ExposureMask
, &ev
);
3861 if (abs(ofs_x
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
3862 || abs(ofs_y
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
3863 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3864 |ButtonReleaseMask
|ButtonPressMask
,
3865 wCursor
[WCUR_MOVE
], CurrentTime
);
3874 for (i
=0; i
<scr
->workspace_count
; i
++) {
3875 if (i
== scr
->current_workspace
)
3877 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3881 x
= ev
.xmotion
.x_root
- ofs_x
;
3882 y
= ev
.xmotion
.y_root
- ofs_y
;
3883 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3886 if (last_dock
!= dock
&& collapsed
) {
3887 last_dock
->collapsed
= 1;
3888 wDockHideIcons(last_dock
);
3891 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3892 dock
->collapsed
= 0;
3893 wDockShowIcons(dock
);
3895 if (dock
->auto_raise_lower
)
3899 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3902 if (last_dock
!= dock2
&& collapsed
) {
3903 last_dock
->collapsed
= 1;
3904 wDockHideIcons(last_dock
);
3907 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3908 dock2
->collapsed
= 0;
3909 wDockShowIcons(dock2
);
3911 if (dock2
->auto_raise_lower
)
3916 if (aicon
->launching
3918 || (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3919 || (!aicon
->running
&& tmp
)) {
3920 shad_x
= last_dock
->x_pos
+ ix
*wPreferences
.icon_size
;
3921 shad_y
= last_dock
->y_pos
+ iy
*wPreferences
.icon_size
;
3923 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3926 XMapWindow(dpy
, scr
->dock_shadow
);
3931 XUnmapWindow(dpy
, scr
->dock_shadow
);
3935 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3942 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3944 XUngrabPointer(dpy
, CurrentTime
);
3946 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3947 XUnmapWindow(dpy
, scr
->dock_shadow
);
3949 reattachIcon(dock
, aicon
, ix
, iy
);
3950 if (clip
&& dock
!=clip
&& clip
->auto_raise_lower
)
3953 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3955 /* Slide it back if dock rejected it */
3956 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
,
3958 reattachIcon(dock
, aicon
, aicon
->xindex
,aicon
->yindex
);
3960 if (last_dock
->type
==WM_CLIP
&& last_dock
->auto_collapse
) {
3968 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3969 /* We need to deselect it, even if is deselected in
3970 * wDockDetach(), because else DoKaboom() will fail.
3972 if (aicon
->icon
->selected
)
3973 wIconSelect(aicon
->icon
);
3975 wSoundPlay(WSOUND_KABOOM
);
3976 DoKaboom(scr
,aicon
->icon
->core
->window
, x
, y
);
3978 wSoundPlay(WSOUND_UNDOCK
);
3981 wSoundPlay(WSOUND_UNDOCK
);
3983 if (clip
&& clip
->auto_raise_lower
)
3985 wDockDetach(dock
, aicon
);
3988 last_dock
->collapsed
= 1;
3989 wDockHideIcons(last_dock
);
3994 XFreePixmap(dpy
, ghost
);
3995 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3999 for (i
=0; i
<scr
->workspace_count
; i
++) {
4000 if (i
== scr
->current_workspace
)
4002 wDockHideIcons(scr
->workspaces
[i
]->clip
);
4007 puts("End icon move");
4016 getClipButton(int px
, int py
)
4018 int pt
= (CLIP_BUTTON_SIZE
+2)*ICON_SIZE
/64;
4020 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
4023 if (py
<= pt
-((int)ICON_SIZE
-1-px
))
4024 return CLIP_FORWARD
;
4025 else if (px
<= pt
-((int)ICON_SIZE
-1-py
))
4033 handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
4036 int done
, direction
, new_ws
;
4038 WDock
*clip
= scr
->clip_icon
->dock
;
4040 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
4042 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
4043 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
4045 wClipIconPaint(scr
->clip_icon
);
4048 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
4049 |ButtonPressMask
, &ev
);
4056 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
4057 if (new_dir
!= direction
) {
4058 direction
= new_dir
;
4059 clip
->lclip_button_pushed
= direction
==CLIP_REWIND
;
4060 clip
->rclip_button_pushed
= direction
==CLIP_FORWARD
;
4061 wClipIconPaint(scr
->clip_icon
);
4069 if (ev
.xbutton
.button
== event
->xbutton
.button
)
4074 clip
->lclip_button_pushed
= 0;
4075 clip
->rclip_button_pushed
= 0;
4077 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
4079 if (direction
== CLIP_FORWARD
) {
4080 if (scr
->current_workspace
< scr
->workspace_count
-1)
4081 wWorkspaceChange(scr
, scr
->current_workspace
+1);
4082 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
-1)
4083 wWorkspaceChange(scr
, scr
->current_workspace
+1);
4084 else if (wPreferences
.ws_cycle
)
4085 wWorkspaceChange(scr
, 0);
4087 else if (direction
== CLIP_REWIND
) {
4088 if (scr
->current_workspace
> 0)
4089 wWorkspaceChange(scr
, scr
->current_workspace
-1);
4090 else if (scr
->current_workspace
==0 && wPreferences
.ws_cycle
)
4091 wWorkspaceChange(scr
, scr
->workspace_count
-1);
4094 wClipIconPaint(scr
->clip_icon
);
4099 iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
4101 WAppIcon
*aicon
= desc
->parent
;
4102 WDock
*dock
= aicon
->dock
;
4103 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4105 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
4108 scr
->last_dock
= dock
;
4110 if (dock
->menu
->flags
.mapped
)
4111 wMenuUnmap(dock
->menu
);
4113 if (IsDoubleClick(scr
, event
)) {
4114 /* double-click was not in the main clip icon */
4115 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!=0 || aicon
->yindex
!=0
4116 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)==CLIP_IDLE
) {
4117 iconDblClick(desc
, event
);
4122 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
4123 XUnmapWindow(dpy
, scr
->clip_balloon
);
4124 scr
->flags
.clip_balloon_mapped
= 0;
4128 puts("handling dock");
4130 if (event
->xbutton
.button
== Button1
) {
4131 if (event
->xbutton
.state
& MOD_MASK
)
4136 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
&&
4137 dock
->type
!=WM_DOCK
) {
4138 wIconSelect(aicon
->icon
);
4142 if (aicon
->yindex
==0 && aicon
->xindex
==0) {
4143 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
)!=CLIP_IDLE
4144 && dock
->type
==WM_CLIP
)
4145 handleClipChangeWorkspace(scr
, event
);
4147 handleDockMove(dock
, aicon
, event
);
4149 handleIconMove(dock
, aicon
, event
);
4151 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4152 aicon
==scr
->clip_icon
) {
4153 openClipWorkspaceMenu(scr
, event
->xbutton
.x_root
+2,
4154 event
->xbutton
.y_root
+2);
4155 if (scr
->clip_ws_menu
) {
4157 menu
= scr
->clip_ws_menu
;
4158 desc
= &menu
->menu
->descriptor
;
4160 event
->xany
.send_event
= True
;
4161 (*desc
->handle_mousedown
)(desc
, event
);
4163 } else if (event
->xbutton
.button
==Button2
&& dock
->type
==WM_CLIP
&&
4164 (event
->xbutton
.state
& ShiftMask
) && aicon
!=scr
->clip_icon
) {
4165 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
4166 } else if (event
->xbutton
.button
== Button3
) {
4167 if (event
->xbutton
.send_event
&&
4168 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
4169 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
4170 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
4171 wwarning("pointer grab failed for dockicon menu");
4175 openDockMenu(dock
, aicon
, event
);
4176 } else if (event
->xbutton
.button
== Button2
) {
4177 WAppIcon
*btn
= desc
->parent
;
4179 if (!btn
->launching
&&
4180 (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
4181 launchDockedApplication(btn
, True
);
4188 showClipBalloon(WDock
*dock
, int workspace
)
4192 WScreen
*scr
= dock
->screen_ptr
;
4196 scr
->flags
.clip_balloon_mapped
= 1;
4197 XMapWindow(dpy
, scr
->clip_balloon
);
4199 text
= scr
->workspaces
[workspace
]->name
;
4201 w
= WMWidthOfString(scr
->clip_title_font
, text
, strlen(text
));
4203 h
= WMFontHeight(scr
->clip_title_font
);
4204 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
4206 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
4207 y
= dock
->y_pos
+ ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
4209 if (x
+w
> scr
->scr_width
) {
4210 x
= scr
->scr_width
- w
;
4211 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
4212 y
= dock
->y_pos
- h
- 1;
4214 y
= dock
->y_pos
+ ICON_SIZE
;
4215 XRaiseWindow(dpy
, scr
->clip_balloon
);
4217 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
4218 stack
[1] = scr
->clip_balloon
;
4219 XRestackWindows(dpy
, stack
, 2);
4221 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
4222 XClearWindow(dpy
, scr
->clip_balloon
);
4223 WMDrawString(scr
->wmscreen
, scr
->clip_balloon
,
4224 scr
->clip_title_color
[CLIP_NORMAL
],
4225 scr
->clip_title_font
,
4226 0, 0, text
, strlen(text
));
4231 clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
4233 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4237 assert(event
->type
==EnterNotify
);
4239 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4242 scr
= btn
->icon
->core
->screen_ptr
;
4243 if (!btn
->omnipresent
)
4246 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
4248 if (!dock
|| dock
->type
!=WM_CLIP
)
4251 /* The auto raise/lower code */
4252 if (dock
->auto_lower_magic
) {
4253 WMDeleteTimerHandler(dock
->auto_lower_magic
);
4254 dock
->auto_lower_magic
= NULL
;
4256 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
4257 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
,
4262 /* The auto expand/collapse code */
4263 if (dock
->auto_collapse_magic
) {
4264 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
4265 dock
->auto_collapse_magic
= NULL
;
4267 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
4268 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
,
4273 if (btn
->xindex
== 0 && btn
->yindex
== 0)
4274 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4276 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4277 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
4278 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
4285 clipLeave(WDock
*dock
)
4288 WObjDescriptor
*desc
= NULL
;
4290 if (!dock
|| dock
->type
!=WM_CLIP
)
4293 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
)!=False
) {
4294 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
4295 (XPointer
*)&desc
)!=XCNOENT
4296 && desc
&& desc
->parent_type
==WCLASS_DOCK_ICON
4297 && ((WAppIcon
*)desc
->parent
)->dock
4298 && ((WAppIcon
*)desc
->parent
)->dock
->type
==WM_CLIP
) {
4299 /* We didn't left the Clip yet */
4300 XPutBackEvent(dpy
, &event
);
4304 XPutBackEvent(dpy
, &event
);
4306 /* We entered a withdrawn window, so we're still in Clip */
4310 if (dock
->auto_raise_magic
) {
4311 WMDeleteTimerHandler(dock
->auto_raise_magic
);
4312 dock
->auto_raise_magic
= NULL
;
4314 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
4315 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
,
4320 if (dock
->auto_expand_magic
) {
4321 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4322 dock
->auto_expand_magic
= NULL
;
4324 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
4325 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
,
4333 clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4335 WAppIcon
*btn
= (WAppIcon
*)desc
->parent
;
4337 assert(event
->type
==LeaveNotify
);
4339 if(desc
->parent_type
!=WCLASS_DOCK_ICON
)
4342 clipLeave(btn
->dock
);
4347 clipAutoCollapse(void *cdata
)
4349 WDock
*dock
= (WDock
*)cdata
;
4351 if (dock
->type
!=WM_CLIP
)
4354 if (dock
->auto_collapse
) {
4355 dock
->collapsed
= 1;
4356 wDockHideIcons(dock
);
4358 dock
->auto_collapse_magic
= NULL
;
4363 clipAutoExpand(void *cdata
)
4365 WDock
*dock
= (WDock
*)cdata
;
4367 if (dock
->type
!=WM_CLIP
)
4370 if (dock
->auto_collapse
) {
4371 dock
->collapsed
= 0;
4372 wDockShowIcons(dock
);
4374 dock
->auto_expand_magic
= NULL
;
4379 clipAutoLower(void *cdata
)
4381 WDock
*dock
= (WDock
*)cdata
;
4383 if (dock
->type
!=WM_CLIP
)
4386 if (dock
->auto_raise_lower
)
4389 dock
->auto_lower_magic
= NULL
;
4394 clipAutoRaise(void *cdata
)
4396 WDock
*dock
= (WDock
*)cdata
;
4398 if (dock
->type
!=WM_CLIP
)
4401 if (dock
->auto_raise_lower
)
4404 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4405 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4408 dock
->auto_raise_magic
= NULL
;
4413 iconCanBeOmnipresent(WAppIcon
*aicon
)
4415 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4420 for (i
=0; i
<scr
->workspace_count
; i
++) {
4421 clip
= scr
->workspaces
[i
]->clip
;
4423 if (clip
== aicon
->dock
)
4426 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4427 return False
; /* Clip is full in some workspace */
4429 for (j
=0; j
<clip
->max_icons
; j
++) {
4430 btn
= clip
->icon_array
[j
];
4431 if(btn
&& btn
->xindex
==aicon
->xindex
&& btn
->yindex
==aicon
->yindex
)
4441 wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
4443 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4444 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4445 int status
= WO_SUCCESS
;
4447 if ((scr
->dock
&& aicon
->dock
==scr
->dock
) || aicon
==scr
->clip_icon
) {
4448 return WO_NOT_APPLICABLE
;
4451 if (aicon
->omnipresent
== omnipresent
)
4455 if (iconCanBeOmnipresent(aicon
)) {
4456 aicon
->omnipresent
= 1;
4457 new_entry
= wmalloc(sizeof(WAppIconChain
));
4458 new_entry
->aicon
= aicon
;
4459 new_entry
->next
= scr
->global_icons
;
4460 scr
->global_icons
= new_entry
;
4461 scr
->global_icon_count
++;
4463 aicon
->omnipresent
= 0;
4467 aicon
->omnipresent
= 0;
4468 if (aicon
== scr
->global_icons
->aicon
) {
4469 tmp
= scr
->global_icons
->next
;
4470 wfree(scr
->global_icons
);
4471 scr
->global_icons
= tmp
;
4472 scr
->global_icon_count
--;
4474 tmp
= scr
->global_icons
;
4476 if (tmp
->next
->aicon
== aicon
) {
4477 tmp1
= tmp
->next
->next
;
4480 scr
->global_icon_count
--;
4488 wAppIconPaint(aicon
);