1 /* dock.c- built-in Dock module for WindowMaker
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <X11/Xutil.h>
34 #define PATH_MAX DEFAULT_PATH_MAX
37 #include "WindowMaker.h"
47 #include "properties.h"
51 #include "workspace.h"
53 #include "superfluous.h"
56 /**** Local variables ****/
59 #define CLIP_FORWARD 2
61 /**** Global variables ****/
64 extern void DestroyDockAppSettingsPanel();
65 extern void ShowDockAppSettingsPanel(WAppIcon
* aicon
);
66 extern Cursor wCursor
[WCUR_LAST
];
67 extern WPreferences wPreferences
;
68 extern XContext wWinContext
;
69 extern void appIconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
71 #define MOD_MASK wPreferences.modifier_mask
72 #define ICON_SIZE wPreferences.icon_size
74 /***** Local variables ****/
76 static WMPropList
*dCommand
= NULL
;
77 static WMPropList
*dPasteCommand
= NULL
;
78 #ifdef XDND /* XXX was OFFIX */
79 static WMPropList
*dDropCommand
= NULL
;
81 static WMPropList
*dAutoLaunch
, *dLock
;
82 static WMPropList
*dName
, *dForced
, *dBuggyApplication
, *dYes
, *dNo
;
83 static WMPropList
*dHost
, *dDock
, *dClip
;
84 static WMPropList
*dAutoAttractIcons
;
86 static WMPropList
*dPosition
, *dApplications
, *dLowered
, *dCollapsed
;
88 static WMPropList
*dAutoCollapse
, *dAutoRaiseLower
, *dOmnipresent
;
90 static void dockIconPaint(WAppIcon
* btn
);
92 static void iconMouseDown(WObjDescriptor
* desc
, XEvent
* event
);
94 static pid_t
execCommand(WAppIcon
* btn
, char *command
, WSavedState
* state
);
96 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
* dock
);
98 static int getClipButton(int px
, int py
);
100 static void toggleLowered(WDock
* dock
);
102 static void toggleCollapsed(WDock
* dock
);
104 static void clipIconExpose(WObjDescriptor
* desc
, XEvent
* event
);
106 static void clipLeave(WDock
* dock
);
108 static void handleClipChangeWorkspace(WScreen
* scr
, XEvent
* event
);
110 Bool
moveIconBetweenDocks(WDock
* src
, WDock
* dest
, WAppIcon
* icon
, int x
, int y
);
112 static void clipEnterNotify(WObjDescriptor
* desc
, XEvent
* event
);
113 static void clipLeaveNotify(WObjDescriptor
* desc
, XEvent
* event
);
114 static void clipAutoCollapse(void *cdata
);
115 static void clipAutoExpand(void *cdata
);
116 static void launchDockedApplication(WAppIcon
* btn
, Bool withSelection
);
118 static void clipAutoLower(void *cdata
);
119 static void clipAutoRaise(void *cdata
);
121 static void showClipBalloon(WDock
* dock
, int workspace
);
123 static void make_keys(void)
125 if (dCommand
!= NULL
)
128 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
129 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
131 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
133 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
134 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
135 dName
= WMRetainPropList(WMCreatePLString("Name"));
136 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
137 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
138 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
139 dNo
= WMRetainPropList(WMCreatePLString("No"));
140 dHost
= WMRetainPropList(WMCreatePLString("Host"));
142 dPosition
= WMCreatePLString("Position");
143 dApplications
= WMCreatePLString("Applications");
144 dLowered
= WMCreatePLString("Lowered");
145 dCollapsed
= WMCreatePLString("Collapsed");
146 dAutoCollapse
= WMCreatePLString("AutoCollapse");
147 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
148 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
150 dOmnipresent
= WMCreatePLString("Omnipresent");
152 dDock
= WMCreatePLString("Dock");
153 dClip
= WMCreatePLString("Clip");
156 static void renameCallback(WMenu
* menu
, WMenuEntry
* entry
)
158 WDock
*dock
= entry
->clientdata
;
163 assert(entry
->clientdata
!= NULL
);
165 wspace
= dock
->screen_ptr
->current_workspace
;
167 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
169 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+ 1);
170 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
, &name
)) {
171 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
178 static void toggleLoweredCallback(WMenu
* menu
, WMenuEntry
* entry
)
180 assert(entry
->clientdata
!= NULL
);
182 toggleLowered(entry
->clientdata
);
184 entry
->flags
.indicator_on
= !(((WDock
*) entry
->clientdata
)->lowered
);
189 static int matchWindow(const void *item
, const void *cdata
)
191 return (((WFakeGroupLeader
*) item
)->leader
== (Window
) cdata
);
194 static void killCallback(WMenu
* menu
, WMenuEntry
* entry
)
196 WScreen
*scr
= menu
->menu
->screen_ptr
;
198 WFakeGroupLeader
*fPtr
;
199 char *buffer
, *shortname
, **argv
;
200 char *basename(const char *shortname
);
203 if (!WCHECK_STATE(WSTATE_NORMAL
))
206 assert(entry
->clientdata
!= NULL
);
208 icon
= (WAppIcon
*) entry
->clientdata
;
212 WCHANGE_STATE(WSTATE_MODAL
);
214 /* strip away dir names */
215 shortname
= basename(icon
->command
);
216 /* separate out command options */
217 wtokensplit(shortname
, &argv
, &argc
);
219 buffer
= wstrconcat(argv
[0],
220 _(" will be forcibly closed.\n"
221 "Any unsaved changes will be lost.\n" "Please confirm."));
223 if (icon
->icon
&& icon
->icon
->owner
) {
224 fPtr
= icon
->icon
->owner
->fake_group
;
226 /* is this really necessary? can we kill a non-running dock icon? */
227 Window win
= icon
->main_window
;
230 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)win
);
231 if (index
!= WANotFound
)
232 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
237 if (wPreferences
.dont_confirm_kill
238 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
239 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
241 WWindow
*wwin
, *twin
;
243 wwin
= scr
->focused_window
;
246 if (wwin
->fake_group
== fPtr
) {
251 } else if (icon
->icon
&& icon
->icon
->owner
) {
252 wClientKill(icon
->icon
->owner
);
257 wtokenfree(argv
, argc
);
261 WCHANGE_STATE(WSTATE_NORMAL
);
264 /* TODO: replace this function with a member of the dock struct */
265 static int numberOfSelectedIcons(WDock
* dock
)
271 for (i
= 1; i
< dock
->max_icons
; i
++) {
272 aicon
= dock
->icon_array
[i
];
273 if (aicon
&& aicon
->icon
->selected
) {
281 static WMArray
*getSelected(WDock
* dock
)
283 WMArray
*ret
= WMCreateArray(8);
287 for (i
= 1; i
< dock
->max_icons
; i
++) {
288 btn
= dock
->icon_array
[i
];
289 if (btn
&& btn
->icon
->selected
) {
290 WMAddToArray(ret
, btn
);
297 static void paintClipButtons(WAppIcon
* clipIcon
, Bool lpushed
, Bool rpushed
)
299 Window win
= clipIcon
->icon
->core
->window
;
300 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
302 int pt
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
303 int tp
= ICON_SIZE
- pt
;
304 int as
= pt
- 15; /* 15 = 5+5+5 */
305 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
307 #ifdef GRADIENT_CLIP_ARROW
308 Bool collapsed
= clipIcon
->dock
->collapsed
;
311 /*if (!clipIcon->dock->collapsed)
312 color = scr->clip_title_color[CLIP_NORMAL];
314 color = scr->clip_title_color[CLIP_COLLAPSED]; */
315 color
= scr
->clip_title_color
[CLIP_NORMAL
];
317 XSetForeground(dpy
, gc
, WMColorPixel(color
));
322 p
[1].x
= ICON_SIZE
- 2;
324 p
[2].x
= ICON_SIZE
- 2;
326 } else if (lpushed
) {
330 p
[1].y
= ICON_SIZE
- 2;
332 p
[2].y
= ICON_SIZE
- 2;
334 if (lpushed
|| rpushed
) {
335 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
336 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
337 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
339 #ifdef GRADIENT_CLIP_ARROW
341 XSetFillStyle(dpy
, scr
->copy_gc
, FillTiled
);
342 XSetTile(dpy
, scr
->copy_gc
, scr
->clip_arrow_gradient
);
343 XSetClipMask(dpy
, scr
->copy_gc
, None
);
346 #endif /* GRADIENT_CLIP_ARROW */
348 /* top right arrow */
349 p
[0].x
= p
[3].x
= ICON_SIZE
- 5 - as
;
351 p
[1].x
= ICON_SIZE
- 6;
353 p
[2].x
= ICON_SIZE
- 6;
356 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
357 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
359 #ifdef GRADIENT_CLIP_ARROW
361 XSetTSOrigin(dpy
, gc
, ICON_SIZE
- 6 - as
, 5);
363 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
364 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
367 /* bottom left arrow */
369 p
[0].y
= p
[3].y
= ICON_SIZE
- 5 - as
;
371 p
[1].y
= ICON_SIZE
- 6;
373 p
[2].y
= ICON_SIZE
- 6;
375 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
376 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
378 #ifdef GRADIENT_CLIP_ARROW
380 XSetTSOrigin(dpy
, gc
, 5, ICON_SIZE
- 6 - as
);
382 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
383 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
385 #ifdef GRADIENT_CLIP_ARROW
387 XSetFillStyle(dpy
, scr
->copy_gc
, FillSolid
);
391 RImage
*wClipMakeTile(WScreen
* scr
, RImage
* normalTile
)
393 RImage
*tile
= RCloneImage(normalTile
);
400 pt
= CLIP_BUTTON_SIZE
* wPreferences
.icon_size
/ 64;
401 tp
= wPreferences
.icon_size
- 1 - pt
;
405 black
.red
= black
.green
= black
.blue
= 0;
408 dark
.red
= dark
.green
= dark
.blue
= 60;
411 light
.red
= light
.green
= light
.blue
= 80;
414 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
- 2, pt
- 1, &dark
);
415 RDrawLine(tile
, tp
- 1, 0, wPreferences
.icon_size
- 1, pt
+ 1, &black
);
416 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
- 3, pt
, &light
);
419 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, 4, &dark
);
420 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 5, 6 + as
, &dark
);
421 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
, &light
);
424 ROperateLine(tile
, RAddOperation
, 2, tp
+ 2, pt
- 2, wPreferences
.icon_size
- 3, &dark
);
425 RDrawLine(tile
, 0, tp
- 1, pt
+ 1, wPreferences
.icon_size
- 1, &black
);
426 ROperateLine(tile
, RSubtractOperation
, 0, tp
- 2, pt
+ 1, wPreferences
.icon_size
- 2, &light
);
429 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, &dark
);
430 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
, 6 + as
, ICON_SIZE
- 5, &dark
);
431 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5, &light
);
436 static void omnipresentCallback(WMenu
* menu
, WMenuEntry
* entry
)
438 WAppIcon
*clickedIcon
= entry
->clientdata
;
441 WMArray
*selectedIcons
;
442 WMArrayIterator iter
;
445 assert(entry
->clientdata
!= NULL
);
447 dock
= clickedIcon
->dock
;
449 selectedIcons
= getSelected(dock
);
451 if (!WMGetArrayItemCount(selectedIcons
))
452 WMAddToArray(selectedIcons
, clickedIcon
);
455 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
456 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
458 else if (aicon
->icon
->selected
)
459 wIconSelect(aicon
->icon
);
461 WMFreeArray(selectedIcons
);
464 wMessageDialog(dock
->screen_ptr
, _("Warning"),
465 _("Some icons cannot be made omnipresent. "
466 "Please make sure that no other icon is "
467 "docked in the same positions on the other "
468 "workspaces and the Clip is not full in "
469 "some workspace."), _("OK"), NULL
, NULL
);
470 } else if (failed
== 1) {
471 wMessageDialog(dock
->screen_ptr
, _("Warning"),
472 _("Icon cannot be made omnipresent. "
473 "Please make sure that no other icon is "
474 "docked in the same position on the other "
475 "workspaces and the Clip is not full in "
476 "some workspace."), _("OK"), NULL
, NULL
);
480 static void removeIconsCallback(WMenu
* menu
, WMenuEntry
* entry
)
482 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
485 WMArray
*selectedIcons
;
489 assert(clickedIcon
!= NULL
);
491 dock
= clickedIcon
->dock
;
493 selectedIcons
= getSelected(dock
);
495 if (WMGetArrayItemCount(selectedIcons
)) {
496 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
497 _("All selected icons will be removed!"),
498 _("OK"), _("Cancel"), NULL
) != WAPRDefault
) {
499 WMFreeArray(selectedIcons
);
503 if (clickedIcon
->xindex
== 0 && clickedIcon
->yindex
== 0) {
504 WMFreeArray(selectedIcons
);
507 WMAddToArray(selectedIcons
, clickedIcon
);
510 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
511 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
512 wDockDetach(dock
, aicon
);
514 /* XXX: can: aicon->icon == NULL ? */
515 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
516 wGetHeadForWindow(aicon
->icon
->owner
));
517 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
518 if (!dock
->mapped
|| dock
->collapsed
)
519 XMapWindow(dpy
, aicon
->icon
->core
->window
);
522 WMFreeArray(selectedIcons
);
524 if (wPreferences
.auto_arrange_icons
)
525 wArrangeIcons(dock
->screen_ptr
, True
);
528 static void keepIconsCallback(WMenu
* menu
, WMenuEntry
* entry
)
530 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
533 WMArray
*selectedIcons
;
536 assert(clickedIcon
!= NULL
);
537 dock
= clickedIcon
->dock
;
539 selectedIcons
= getSelected(dock
);
541 if (!WMGetArrayItemCount(selectedIcons
)
542 && clickedIcon
!= dock
->screen_ptr
->clip_icon
) {
543 char *command
= NULL
;
545 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
546 clickedIcon
->editing
= 1;
547 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
548 _("Type the command used to launch the application"), &command
)) {
549 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
553 clickedIcon
->command
= command
;
554 clickedIcon
->editing
= 0;
556 clickedIcon
->editing
= 0;
559 WMFreeArray(selectedIcons
);
564 WMAddToArray(selectedIcons
, clickedIcon
);
567 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
568 if (aicon
->icon
->selected
)
569 wIconSelect(aicon
->icon
);
570 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
571 aicon
->attracted
= 0;
572 if (aicon
->icon
->shadowed
) {
573 aicon
->icon
->shadowed
= 0;
574 aicon
->icon
->force_paint
= 1;
575 wAppIconPaint(aicon
);
579 WMFreeArray(selectedIcons
);
582 static void toggleAutoAttractCallback(WMenu
* menu
, WMenuEntry
* entry
)
584 WDock
*dock
= (WDock
*) entry
->clientdata
;
586 assert(entry
->clientdata
!= NULL
);
588 dock
->attract_icons
= !dock
->attract_icons
;
589 /*if (!dock->attract_icons)
590 dock->keep_attracted = 0; */
592 entry
->flags
.indicator_on
= dock
->attract_icons
;
597 static void selectCallback(WMenu
* menu
, WMenuEntry
* entry
)
599 WAppIcon
*icon
= (WAppIcon
*) entry
->clientdata
;
601 assert(icon
!= NULL
);
603 wIconSelect(icon
->icon
);
608 static void colectIconsCallback(WMenu
* menu
, WMenuEntry
* entry
)
610 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
613 int x
, y
, x_pos
, y_pos
;
615 assert(entry
->clientdata
!= NULL
);
616 clip
= clickedIcon
->dock
;
618 aicon
= clip
->screen_ptr
->app_icon_list
;
621 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
622 x_pos
= clip
->x_pos
+ x
* ICON_SIZE
;
623 y_pos
= clip
->y_pos
+ y
* ICON_SIZE
;
624 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
626 if (wPreferences
.no_animations
) {
627 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
629 SlideWindow(aicon
->icon
->core
->window
,
630 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
633 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
634 #endif /* ANIMATIONS */
636 aicon
->attracted
= 1;
637 if (!aicon
->icon
->shadowed
) {
638 aicon
->icon
->shadowed
= 1;
639 aicon
->icon
->force_paint
= 1;
640 /* We don't do an wAppIconPaint() here because it's in
641 * wDockAttachIcon(). -Dan
644 wDockAttachIcon(clip
, aicon
, x
, y
);
645 if (clip
->collapsed
|| !clip
->mapped
)
646 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
652 static void selectIconsCallback(WMenu
* menu
, WMenuEntry
* entry
)
654 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
656 WMArray
*selectedIcons
;
657 WMArrayIterator iter
;
661 assert(clickedIcon
!= NULL
);
662 dock
= clickedIcon
->dock
;
664 selectedIcons
= getSelected(dock
);
666 if (!WMGetArrayItemCount(selectedIcons
)) {
667 for (i
= 1; i
< dock
->max_icons
; i
++) {
668 btn
= dock
->icon_array
[i
];
669 if (btn
&& !btn
->icon
->selected
) {
670 wIconSelect(btn
->icon
);
674 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
675 wIconSelect(btn
->icon
);
678 WMFreeArray(selectedIcons
);
683 static void toggleCollapsedCallback(WMenu
* menu
, WMenuEntry
* entry
)
685 assert(entry
->clientdata
!= NULL
);
687 toggleCollapsed(entry
->clientdata
);
689 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->collapsed
;
694 static void toggleAutoCollapseCallback(WMenu
* menu
, WMenuEntry
* entry
)
697 assert(entry
->clientdata
!= NULL
);
699 dock
= (WDock
*) entry
->clientdata
;
701 dock
->auto_collapse
= !dock
->auto_collapse
;
703 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_collapse
;
708 static void toggleAutoRaiseLowerCallback(WMenu
* menu
, WMenuEntry
* entry
)
711 assert(entry
->clientdata
!= NULL
);
713 dock
= (WDock
*) entry
->clientdata
;
715 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
717 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_raise_lower
;
722 static void launchCallback(WMenu
* menu
, WMenuEntry
* entry
)
724 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
726 launchDockedApplication(btn
, False
);
729 static void settingsCallback(WMenu
* menu
, WMenuEntry
* entry
)
731 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
735 ShowDockAppSettingsPanel(btn
);
738 static void hideCallback(WMenu
* menu
, WMenuEntry
* entry
)
741 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
743 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
745 if (wapp
->flags
.hidden
) {
746 wWorkspaceChange(btn
->icon
->core
->screen_ptr
, wapp
->last_workspace
);
747 wUnhideApplication(wapp
, False
, False
);
749 wHideApplication(wapp
);
753 static void unhideHereCallback(WMenu
* menu
, WMenuEntry
* entry
)
756 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
758 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
760 wUnhideApplication(wapp
, False
, True
);
763 WAppIcon
*mainIconCreate(WScreen
* scr
, int type
)
768 if (type
== WM_CLIP
) {
770 return scr
->clip_icon
;
771 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
772 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
773 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
774 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
775 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE; */
778 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
779 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
785 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
786 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
787 btn
->icon
->core
->descriptor
.parent
= btn
;
788 /*ChangeStackingLevel(btn->icon->core, WMDockLevel); */
789 XMapWindow(dpy
, btn
->icon
->core
->window
);
794 scr
->clip_icon
= btn
;
799 static void switchWSCommand(WMenu
* menu
, WMenuEntry
* entry
)
801 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
802 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
804 WMArray
*selectedIcons
;
807 if (entry
->order
== scr
->current_workspace
)
810 dest
= scr
->workspaces
[entry
->order
]->clip
;
812 selectedIcons
= getSelected(src
);
814 if (WMGetArrayItemCount(selectedIcons
)) {
815 WMArrayIterator iter
;
817 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
818 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
819 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
820 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
823 } else if (icon
!= scr
->clip_icon
) {
824 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
825 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
826 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
829 WMFreeArray(selectedIcons
);
832 static void launchDockedApplication(WAppIcon
* btn
, Bool withSelection
)
834 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
836 if (!btn
->launching
&&
837 ((!withSelection
&& btn
->command
!= NULL
) || (withSelection
&& btn
->paste_command
!= NULL
))) {
838 if (!btn
->forced_dock
) {
839 btn
->relaunching
= btn
->running
;
842 if (btn
->wm_instance
|| btn
->wm_class
) {
843 WWindowAttributes attr
;
844 memset(&attr
, 0, sizeof(WWindowAttributes
));
845 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
847 if (!attr
.no_appicon
&& !btn
->buggy_app
)
852 btn
->drop_launch
= 0;
853 btn
->paste_launch
= withSelection
;
854 scr
->last_dock
= btn
->dock
;
855 btn
->pid
= execCommand(btn
, (withSelection
? btn
->paste_command
: btn
->command
), NULL
);
857 if (btn
->buggy_app
) {
858 /* give feedback that the app was launched */
862 WMAddTimerHandler(200, (WMCallback
*) dockIconPaint
, btn
);
867 wwarning(_("could not launch application %s"), btn
->command
);
869 if (!btn
->relaunching
) {
876 static void updateWorkspaceMenu(WMenu
* menu
, WAppIcon
* icon
)
878 WScreen
*scr
= menu
->frame
->screen_ptr
;
879 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
885 for (i
= 0; i
< scr
->workspace_count
; i
++) {
886 if (i
< menu
->entry_no
) {
887 if (strcmp(menu
->entries
[i
]->text
, scr
->workspaces
[i
]->name
) != 0) {
888 wfree(menu
->entries
[i
]->text
);
889 strcpy(title
, scr
->workspaces
[i
]->name
);
890 menu
->entries
[i
]->text
= wstrdup(title
);
891 menu
->flags
.realized
= 0;
893 menu
->entries
[i
]->clientdata
= (void *)icon
;
895 strcpy(title
, scr
->workspaces
[i
]->name
);
897 wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)icon
);
899 menu
->flags
.realized
= 0;
901 if (i
== scr
->current_workspace
) {
902 wMenuSetEnabled(menu
, i
, False
);
904 wMenuSetEnabled(menu
, i
, True
);
908 if (!menu
->flags
.realized
)
912 static WMenu
*makeWorkspaceMenu(WScreen
* scr
)
916 menu
= wMenuCreate(scr
, NULL
, False
);
918 wwarning(_("could not create workspace submenu for Clip menu"));
920 wMenuAddCallback(menu
, "", switchWSCommand
, (void *)scr
->clip_icon
);
922 menu
->flags
.realized
= 0;
928 static void updateClipOptionsMenu(WMenu
* menu
, WDock
* dock
)
937 entry
= menu
->entries
[index
];
938 entry
->flags
.indicator_on
= !dock
->lowered
;
939 entry
->clientdata
= dock
;
942 entry
= menu
->entries
[++index
];
943 entry
->flags
.indicator_on
= dock
->collapsed
;
944 entry
->clientdata
= dock
;
947 entry
= menu
->entries
[++index
];
948 entry
->flags
.indicator_on
= dock
->auto_collapse
;
949 entry
->clientdata
= dock
;
951 /* auto-raise/lower */
952 entry
= menu
->entries
[++index
];
953 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
954 entry
->clientdata
= dock
;
955 wMenuSetEnabled(menu
, index
, dock
->lowered
);
958 entry
= menu
->entries
[++index
];
959 entry
->flags
.indicator_on
= dock
->attract_icons
;
960 entry
->clientdata
= dock
;
962 menu
->flags
.realized
= 0;
966 static WMenu
*makeClipOptionsMenu(WScreen
* scr
)
971 menu
= wMenuCreate(scr
, NULL
, False
);
973 wwarning(_("could not create options submenu for Clip menu"));
977 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
978 entry
->flags
.indicator
= 1;
979 entry
->flags
.indicator_on
= 1;
980 entry
->flags
.indicator_type
= MI_CHECK
;
982 entry
= wMenuAddCallback(menu
, _("Collapsed"), toggleCollapsedCallback
, NULL
);
983 entry
->flags
.indicator
= 1;
984 entry
->flags
.indicator_on
= 1;
985 entry
->flags
.indicator_type
= MI_CHECK
;
987 entry
= wMenuAddCallback(menu
, _("Autocollapse"), toggleAutoCollapseCallback
, NULL
);
988 entry
->flags
.indicator
= 1;
989 entry
->flags
.indicator_on
= 1;
990 entry
->flags
.indicator_type
= MI_CHECK
;
992 entry
= wMenuAddCallback(menu
, _("Autoraise"), toggleAutoRaiseLowerCallback
, NULL
);
993 entry
->flags
.indicator
= 1;
994 entry
->flags
.indicator_on
= 1;
995 entry
->flags
.indicator_type
= MI_CHECK
;
997 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"), toggleAutoAttractCallback
, NULL
);
998 entry
->flags
.indicator
= 1;
999 entry
->flags
.indicator_on
= 1;
1000 entry
->flags
.indicator_type
= MI_CHECK
;
1002 menu
->flags
.realized
= 0;
1008 static WMenu
*dockMenuCreate(WScreen
* scr
, int type
)
1013 if (type
== WM_CLIP
&& scr
->clip_menu
)
1014 return scr
->clip_menu
;
1016 menu
= wMenuCreate(scr
, NULL
, False
);
1017 if (type
!= WM_CLIP
) {
1018 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
1019 entry
->flags
.indicator
= 1;
1020 entry
->flags
.indicator_on
= 1;
1021 entry
->flags
.indicator_type
= MI_CHECK
;
1023 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1024 scr
->clip_options
= makeClipOptionsMenu(scr
);
1025 if (scr
->clip_options
)
1026 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1028 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1030 entry
->text
= _("Rename Workspace");
1032 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1033 entry
->flags
.indicator
= 1;
1034 entry
->flags
.indicator_on
= 1;
1035 entry
->flags
.indicator_type
= MI_CHECK
;
1037 entry
= wMenuAddCallback(menu
, _("Select All Icons"), selectIconsCallback
, NULL
);
1039 entry
->text
= _("Select All Icons");
1041 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1043 entry
->text
= _("Keep Icon");
1045 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1047 entry
->text
= _("Move Icon To");
1048 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1049 if (scr
->clip_submenu
)
1050 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1052 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
, NULL
);
1054 entry
->text
= _("Remove Icon");
1056 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1059 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1061 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1063 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1065 entry
->text
= _("Hide");
1067 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1069 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1071 if (type
== WM_CLIP
)
1072 scr
->clip_menu
= menu
;
1077 WDock
*wDockCreate(WScreen
* scr
, int type
)
1085 dock
= wmalloc(sizeof(WDock
));
1086 memset(dock
, 0, sizeof(WDock
));
1088 if (type
== WM_CLIP
)
1089 icon_count
= CLIP_MAX_ICONS
;
1091 icon_count
= scr
->scr_height
/ wPreferences
.icon_size
;
1093 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * icon_count
);
1094 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*) * icon_count
);
1096 dock
->max_icons
= icon_count
;
1098 btn
= mainIconCreate(scr
, type
);
1102 dock
->x_pos
= btn
->x_pos
;
1103 dock
->y_pos
= btn
->y_pos
;
1104 dock
->screen_ptr
= scr
;
1106 dock
->icon_count
= 1;
1107 dock
->on_right_side
= 1;
1108 dock
->collapsed
= 0;
1109 dock
->auto_collapse
= 0;
1110 dock
->auto_collapse_magic
= NULL
;
1111 dock
->auto_raise_lower
= 0;
1112 dock
->auto_lower_magic
= NULL
;
1113 dock
->auto_raise_magic
= NULL
;
1114 dock
->attract_icons
= 0;
1116 dock
->icon_array
[0] = btn
;
1117 wRaiseFrame(btn
->icon
->core
);
1118 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1120 /* create dock menu */
1121 dock
->menu
= dockMenuCreate(scr
, type
);
1126 void wDockDestroy(WDock
* dock
)
1131 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1132 aicon
= dock
->icon_array
[i
];
1134 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1135 wDockDetach(dock
, aicon
);
1137 /* XXX: can: aicon->icon == NULL ? */
1138 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1139 wGetHeadForWindow(aicon
->icon
->owner
));
1140 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1141 if (!dock
->mapped
|| dock
->collapsed
)
1142 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1146 if (wPreferences
.auto_arrange_icons
)
1147 wArrangeIcons(dock
->screen_ptr
, True
);
1148 wfree(dock
->icon_array
);
1149 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1150 wMenuDestroy(dock
->menu
, True
);
1151 if (dock
->screen_ptr
->last_dock
== dock
)
1152 dock
->screen_ptr
->last_dock
= NULL
;
1156 void wClipIconPaint(WAppIcon
* aicon
)
1158 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1159 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1161 Window win
= aicon
->icon
->core
->window
;
1162 int length
, nlength
;
1163 char *ws_name
, ws_number
[10];
1166 wIconPaint(aicon
->icon
);
1168 length
= strlen(workspace
->name
);
1169 ws_name
= wmalloc(length
+ 1);
1170 snprintf(ws_name
, length
+ 1, "%s", workspace
->name
);
1171 snprintf(ws_number
, sizeof(ws_number
), "%i", scr
->current_workspace
+ 1);
1172 nlength
= strlen(ws_number
);
1174 if (!workspace
->clip
->collapsed
)
1175 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1177 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1179 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1181 tx
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
1183 if(wPreferences
.show_clip_title
)
1184 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, ty
, ws_name
, length
);
1185 /*WMDrawString(scr->wmscreen, win, color, scr->clip_title_font, 4,
1186 2, ws_name, length); */
1188 tx
= (ICON_SIZE
/ 2 - WMWidthOfString(scr
->clip_title_font
, ws_number
, nlength
)) / 2;
1190 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, 2, ws_number
, nlength
);
1194 if (aicon
->launching
) {
1195 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1196 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1198 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
, aicon
->dock
->rclip_button_pushed
);
1201 static void clipIconExpose(WObjDescriptor
* desc
, XEvent
* event
)
1203 wClipIconPaint(desc
->parent
);
1206 static void dockIconPaint(WAppIcon
* btn
)
1208 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1209 wClipIconPaint(btn
);
1214 static WMPropList
*make_icon_state(WAppIcon
* btn
)
1216 WMPropList
*node
= NULL
;
1217 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
, *host
;
1218 WMPropList
*position
, *buggy
, *omnipresent
;
1224 command
= WMCreatePLString("-");
1226 command
= WMCreatePLString(btn
->command
);
1228 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1230 lock
= btn
->lock
? dYes
: dNo
;
1232 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1234 name
= WMCreatePLString(tmp
);
1238 forced
= btn
->forced_dock
? dYes
: dNo
;
1240 buggy
= btn
->buggy_app
? dYes
: dNo
;
1242 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1243 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1245 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1246 position
= WMCreatePLString(buffer
);
1248 node
= WMCreatePLDictionary(dCommand
, command
,
1250 dAutoLaunch
, autolaunch
,
1252 dForced
, forced
, dBuggyApplication
, buggy
, dPosition
, position
, NULL
);
1253 WMReleasePropList(command
);
1254 WMReleasePropList(name
);
1255 WMReleasePropList(position
);
1257 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1258 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&& (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1259 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1261 #ifdef XDND /* was OFFIX */
1262 if (btn
->dnd_command
) {
1263 command
= WMCreatePLString(btn
->dnd_command
);
1264 WMPutInPLDictionary(node
, dDropCommand
, command
);
1265 WMReleasePropList(command
);
1269 if (btn
->paste_command
) {
1270 command
= WMCreatePLString(btn
->paste_command
);
1271 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1272 WMReleasePropList(command
);
1275 if (btn
->client_machine
&& btn
->remote_start
) {
1276 host
= WMCreatePLString(btn
->client_machine
);
1277 WMPutInPLDictionary(node
, dHost
, host
);
1278 WMReleasePropList(host
);
1285 static WMPropList
*dockSaveState(WDock
* dock
)
1288 WMPropList
*icon_info
;
1289 WMPropList
*list
= NULL
, *dock_state
= NULL
;
1290 WMPropList
*value
, *key
;
1293 list
= WMCreatePLArray(NULL
);
1295 for (i
= (dock
->type
== WM_DOCK
? 0 : 1); i
< dock
->max_icons
; i
++) {
1296 WAppIcon
*btn
= dock
->icon_array
[i
];
1298 if (!btn
|| btn
->attracted
)
1301 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1302 WMAddToPLArray(list
, icon_info
);
1303 WMReleasePropList(icon_info
);
1307 dock_state
= WMCreatePLDictionary(dApplications
, list
, NULL
);
1309 if (dock
->type
== WM_DOCK
) {
1310 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1311 key
= WMCreatePLString(buffer
);
1312 WMPutInPLDictionary(dock_state
, key
, list
);
1313 WMReleasePropList(key
);
1315 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0), dock
->y_pos
);
1316 value
= WMCreatePLString(buffer
);
1317 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1318 WMReleasePropList(value
);
1320 WMReleasePropList(list
);
1322 value
= (dock
->lowered
? dYes
: dNo
);
1323 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1325 if (dock
->type
== WM_CLIP
) {
1326 value
= (dock
->collapsed
? dYes
: dNo
);
1327 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1329 value
= (dock
->auto_collapse
? dYes
: dNo
);
1330 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1332 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1333 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1335 value
= (dock
->attract_icons
? dYes
: dNo
);
1336 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1342 void wDockSaveState(WScreen
* scr
, WMPropList
* old_state
)
1344 WMPropList
*dock_state
;
1347 dock_state
= dockSaveState(scr
->dock
);
1350 * Copy saved states of docks with different sizes.
1356 keys
= WMGetPLDictionaryKeys(old_state
);
1357 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1358 tmp
= WMGetFromPLArray(keys
, i
);
1360 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1361 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1363 WMPutInPLDictionary(dock_state
, tmp
, WMGetFromPLDictionary(old_state
, tmp
));
1366 WMReleasePropList(keys
);
1369 WMPutInPLDictionary(scr
->session_state
, dDock
, dock_state
);
1371 WMReleasePropList(dock_state
);
1374 void wClipSaveState(WScreen
* scr
)
1376 WMPropList
*clip_state
;
1378 clip_state
= make_icon_state(scr
->clip_icon
);
1380 WMPutInPLDictionary(scr
->session_state
, dClip
, clip_state
);
1382 WMReleasePropList(clip_state
);
1385 WMPropList
*wClipSaveWorkspaceState(WScreen
* scr
, int workspace
)
1387 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1390 static Bool
getBooleanDockValue(WMPropList
* value
, WMPropList
* key
)
1393 if (WMIsPLString(value
)) {
1394 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1397 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1403 static WAppIcon
*restore_icon_state(WScreen
* scr
, WMPropList
* info
, int type
, int index
)
1406 WMPropList
*cmd
, *value
;
1408 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1409 if (!cmd
|| !WMIsPLString(cmd
)) {
1413 /* parse window name */
1414 value
= WMGetFromPLDictionary(info
, dName
);
1419 char *wclass
, *winstance
;
1422 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1424 if (!winstance
&& !wclass
) {
1431 command
= wstrdup(WMGetFromPLString(cmd
));
1435 if (!command
|| strcmp(command
, "-") == 0) {
1446 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1455 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1456 if (type
== WM_CLIP
) {
1457 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1458 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1460 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1461 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1463 #ifdef XDND /* was OFFIX */
1464 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1466 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1469 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1471 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1473 /* check auto launch */
1474 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1476 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1479 value
= WMGetFromPLDictionary(info
, dLock
);
1481 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1483 /* check if it wasn't normally docked */
1484 value
= WMGetFromPLDictionary(info
, dForced
);
1486 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1488 /* check if we can rely on the stuff in the app */
1489 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1491 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1493 /* get position in the dock */
1494 value
= WMGetFromPLDictionary(info
, dPosition
);
1495 if (value
&& WMIsPLString(value
)) {
1496 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1497 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1499 /* check position sanity */
1500 /* incomplete section! */
1501 if (type
== WM_DOCK
) {
1503 if (aicon
->yindex
< 0)
1504 wwarning(_("bad value in docked icon position %i,%i"),
1505 aicon
->xindex
, aicon
->yindex
);
1508 aicon
->yindex
= index
;
1512 /* check if icon is omnipresent */
1513 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1515 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1523 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1525 WAppIcon
*wClipRestoreState(WScreen
* scr
, WMPropList
* clip_state
)
1530 icon
= mainIconCreate(scr
, WM_CLIP
);
1535 WMRetainPropList(clip_state
);
1537 /* restore position */
1539 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1542 if (!WMIsPLString(value
))
1543 COMPLAIN("Position");
1548 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1549 COMPLAIN("Position");
1551 /* check position sanity */
1552 rect
.pos
.x
= icon
->x_pos
;
1553 rect
.pos
.y
= icon
->y_pos
;
1554 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1556 wGetRectPlacementInfo(scr
, rect
, &flags
);
1557 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
1558 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1561 #ifdef XDND /* was OFFIX */
1562 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1563 if (value
&& WMIsPLString(value
))
1564 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1567 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1568 if (value
&& WMIsPLString(value
))
1569 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1571 WMReleasePropList(clip_state
);
1576 WDock
*wDockRestoreState(WScreen
* scr
, WMPropList
* dock_state
, int type
)
1581 WAppIcon
*aicon
, *old_top
;
1584 dock
= wDockCreate(scr
, type
);
1589 WMRetainPropList(dock_state
);
1591 /* restore position */
1593 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1596 if (!WMIsPLString(value
)) {
1597 COMPLAIN("Position");
1602 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1603 COMPLAIN("Position");
1605 /* check position sanity */
1606 rect
.pos
.x
= dock
->x_pos
;
1607 rect
.pos
.y
= dock
->y_pos
;
1608 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1610 wGetRectPlacementInfo(scr
, rect
, &flags
);
1611 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
)) {
1612 int x
= dock
->x_pos
;
1613 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1616 /* Is this needed any more? */
1617 if (type
== WM_CLIP
) {
1618 if (dock
->x_pos
< 0) {
1620 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1621 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1624 if (dock
->x_pos
>= 0) {
1625 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1626 dock
->on_right_side
= 0;
1628 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1629 dock
->on_right_side
= 1;
1635 /* restore lowered/raised state */
1639 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1642 if (!WMIsPLString(value
)) {
1643 COMPLAIN("Lowered");
1645 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1651 /* restore collapsed state */
1653 dock
->collapsed
= 0;
1655 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1658 if (!WMIsPLString(value
)) {
1659 COMPLAIN("Collapsed");
1661 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1662 dock
->collapsed
= 1;
1667 /* restore auto-collapsed state */
1669 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1672 if (!WMIsPLString(value
)) {
1673 COMPLAIN("AutoCollapse");
1675 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1676 dock
->auto_collapse
= 1;
1677 dock
->collapsed
= 1;
1682 /* restore auto-raise/lower state */
1684 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1687 if (!WMIsPLString(value
)) {
1688 COMPLAIN("AutoRaiseLower");
1690 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1691 dock
->auto_raise_lower
= 1;
1696 /* restore attract icons state */
1698 dock
->attract_icons
= 0;
1700 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1703 if (!WMIsPLString(value
)) {
1704 COMPLAIN("AutoAttractIcons");
1706 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1707 dock
->attract_icons
= 1;
1712 /* application list */
1719 * When saving, it saves the dock state in
1720 * Applications and Applicationsnnn
1722 * When loading, it will first try Applicationsnnn.
1723 * If it does not exist, use Applications as default.
1726 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1728 tmp
= WMCreatePLString(buffer
);
1729 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1730 WMReleasePropList(tmp
);
1733 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1741 count
= WMGetPropListItemCount(apps
);
1746 old_top
= dock
->icon_array
[0];
1748 /* dock->icon_count is set to 1 when dock is created.
1749 * Since Clip is already restored, we want to keep it so for clip,
1750 * but for dock we may change the default top tile, so we set it to 0.
1752 if (type
== WM_DOCK
)
1753 dock
->icon_count
= 0;
1755 for (i
= 0; i
< count
; i
++) {
1756 if (dock
->icon_count
>= dock
->max_icons
) {
1757 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1761 value
= WMGetFromPLArray(apps
, i
);
1762 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1764 dock
->icon_array
[dock
->icon_count
] = aicon
;
1768 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1769 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1772 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1774 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1776 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1778 if (!dock
->collapsed
)
1779 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1780 wRaiseFrame(aicon
->icon
->core
);
1783 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
)
1787 /* if the first icon is not defined, use the default */
1788 if (dock
->icon_array
[0] == NULL
) {
1789 /* update default icon */
1790 old_top
->x_pos
= dock
->x_pos
;
1791 old_top
->y_pos
= dock
->y_pos
;
1793 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1795 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1796 dock
->icon_array
[0] = old_top
;
1797 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1798 /* we don't need to increment dock->icon_count here because it was
1799 * incremented in the loop above.
1801 } else if (old_top
!= dock
->icon_array
[0]) {
1802 if (old_top
== scr
->clip_icon
)
1803 scr
->clip_icon
= dock
->icon_array
[0];
1804 wAppIconDestroy(old_top
);
1808 WMReleasePropList(dock_state
);
1813 void wDockLaunchWithState(WDock
* dock
, WAppIcon
* btn
, WSavedState
* state
)
1815 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1817 btn
->drop_launch
= 0;
1818 btn
->paste_launch
= 0;
1820 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1823 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1833 void wDockDoAutoLaunch(WDock
* dock
, int workspace
)
1839 for (i
= 0; i
< dock
->max_icons
; i
++) {
1840 btn
= dock
->icon_array
[i
];
1841 if (!btn
|| !btn
->auto_launch
)
1844 state
= wmalloc(sizeof(WSavedState
));
1845 memset(state
, 0, sizeof(WSavedState
));
1846 state
->workspace
= workspace
;
1847 /* TODO: this is klugy and is very difficult to understand
1848 * what's going on. Try to clean up */
1849 wDockLaunchWithState(dock
, btn
, state
);
1853 #ifdef XDND /* was OFFIX */
1854 static WDock
*findDock(WScreen
* scr
, XEvent
* event
, int *icon_pos
)
1860 if ((dock
= scr
->dock
) != NULL
) {
1861 for (i
= 0; i
< dock
->max_icons
; i
++) {
1862 if (dock
->icon_array
[i
]
1863 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1869 if (*icon_pos
< 0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
) != NULL
) {
1870 for (i
= 0; i
< dock
->max_icons
; i
++) {
1871 if (dock
->icon_array
[i
]
1872 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1883 int wDockReceiveDNDDrop(WScreen
* scr
, XEvent
* event
)
1889 dock
= findDock(scr
, event
, &icon_pos
);
1894 * Return True if the drop was on an application icon window.
1895 * In this case, let the ClientMessage handler redirect the
1896 * message to the app.
1898 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
1901 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
1902 scr
->flags
.dnd_data_convertion_status
= 0;
1904 btn
= dock
->icon_array
[icon_pos
];
1906 if (!btn
->forced_dock
) {
1907 btn
->relaunching
= btn
->running
;
1910 if (btn
->wm_instance
|| btn
->wm_class
) {
1911 WWindowAttributes attr
;
1912 memset(&attr
, 0, sizeof(WWindowAttributes
));
1913 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
1914 btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
1916 if (!attr
.no_appicon
)
1922 btn
->paste_launch
= 0;
1923 btn
->drop_launch
= 1;
1924 scr
->last_dock
= dock
;
1925 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1930 if (!btn
->relaunching
) {
1939 Bool
wDockAttachIcon(WDock
* dock
, WAppIcon
* icon
, int x
, int y
)
1944 wwin
= icon
->icon
->owner
;
1945 if (icon
->command
== NULL
) {
1950 command
= GetCommandForWindow(wwin
->client_win
);
1952 icon
->command
= command
;
1954 /* icon->forced_dock = 1; */
1955 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
1957 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
1958 _("Type the command used to launch the application"), &command
)) {
1959 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
1963 icon
->command
= command
;
1969 /* If the target is the dock, reject the icon. If
1970 * the target is the clip, make it an attracted icon
1972 if (dock
->type
== WM_CLIP
) {
1973 icon
->attracted
= 1;
1974 if (!icon
->icon
->shadowed
) {
1975 icon
->icon
->shadowed
= 1;
1976 icon
->icon
->force_paint
= 1;
1988 for (index
= 1; index
< dock
->max_icons
; index
++)
1989 if (dock
->icon_array
[index
] == NULL
)
1991 /* if (index == dock->max_icons)
1994 assert(index
< dock
->max_icons
);
1996 dock
->icon_array
[index
] = icon
;
2000 icon
->omnipresent
= 0;
2002 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2003 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2008 icon
->launching
= 0;
2011 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2012 if (dock
->type
== WM_CLIP
) {
2013 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2014 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2016 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2017 icon
->icon
->core
->descriptor
.parent
= icon
;
2019 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2020 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2021 wAppIconPaint(icon
);
2023 if (wPreferences
.auto_arrange_icons
)
2024 wArrangeIcons(dock
->screen_ptr
, True
);
2026 #ifdef XDND /* was OFFIX */
2027 if (icon
->command
&& !icon
->dnd_command
) {
2028 int len
= strlen(icon
->command
) + 8;
2029 icon
->dnd_command
= wmalloc(len
);
2030 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
2034 if (icon
->command
&& !icon
->paste_command
) {
2035 int len
= strlen(icon
->command
) + 8;
2036 icon
->paste_command
= wmalloc(len
);
2037 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
2043 void reattachIcon(WDock
* dock
, WAppIcon
* icon
, int x
, int y
)
2047 for (index
= 1; index
< dock
->max_icons
; index
++) {
2048 if (dock
->icon_array
[index
] == icon
)
2051 assert(index
< dock
->max_icons
);
2056 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2057 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2060 Bool
moveIconBetweenDocks(WDock
* src
, WDock
* dest
, WAppIcon
* icon
, int x
, int y
)
2067 return True
; /* No move needed, we're already there */
2072 wwin
= icon
->icon
->owner
;
2075 * For the moment we can't do this if we move icons in Clip from one
2076 * workspace to other, because if we move two or more icons without
2077 * command, the dialog box will not be able to tell us to which of the
2078 * moved icons it applies. -Dan
2080 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
2081 command
= GetCommandForWindow(wwin
->client_win
);
2083 icon
->command
= command
;
2086 /* icon->forced_dock = 1; */
2087 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2088 _("Type the command used to launch the application"), &command
)) {
2089 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2093 icon
->command
= command
;
2104 if (dest
->type
== WM_DOCK
)
2105 wClipMakeIconOmnipresent(icon
, False
);
2107 for (index
= 1; index
< src
->max_icons
; index
++) {
2108 if (src
->icon_array
[index
] == icon
)
2111 assert(index
< src
->max_icons
);
2113 src
->icon_array
[index
] = NULL
;
2116 for (index
= 1; index
< dest
->max_icons
; index
++) {
2117 if (dest
->icon_array
[index
] == NULL
)
2120 /* if (index == dest->max_icons)
2123 assert(index
< dest
->max_icons
);
2125 dest
->icon_array
[index
] = icon
;
2128 /* deselect the icon */
2129 if (icon
->icon
->selected
)
2130 wIconSelect(icon
->icon
);
2132 if (dest
->type
== WM_DOCK
) {
2133 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2134 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2136 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2137 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2140 /* set it to be kept when moving to dock.
2141 * Unless the icon does not have a command set
2143 if (icon
->command
&& dest
->type
== WM_DOCK
) {
2144 icon
->attracted
= 0;
2145 if (icon
->icon
->shadowed
) {
2146 icon
->icon
->shadowed
= 0;
2147 icon
->icon
->force_paint
= 1;
2151 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2157 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2158 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2162 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2163 wAppIconPaint(icon
);
2168 void wDockDetach(WDock
* dock
, WAppIcon
* icon
)
2172 /* make the settings panel be closed */
2174 DestroyDockAppSettingsPanel(icon
->panel
);
2177 /* This must be called before icon->dock is set to NULL.
2178 * Don't move it. -Dan
2180 wClipMakeIconOmnipresent(icon
, False
);
2184 icon
->attracted
= 0;
2185 icon
->auto_launch
= 0;
2186 if (icon
->icon
->shadowed
) {
2187 icon
->icon
->shadowed
= 0;
2188 icon
->icon
->force_paint
= 1;
2191 /* deselect the icon */
2192 if (icon
->icon
->selected
)
2193 wIconSelect(icon
->icon
);
2195 if (icon
->command
) {
2196 wfree(icon
->command
);
2197 icon
->command
= NULL
;
2199 #ifdef XDND /* was OFFIX */
2200 if (icon
->dnd_command
) {
2201 wfree(icon
->dnd_command
);
2202 icon
->dnd_command
= NULL
;
2205 if (icon
->paste_command
) {
2206 wfree(icon
->paste_command
);
2207 icon
->paste_command
= NULL
;
2210 for (index
= 1; index
< dock
->max_icons
; index
++)
2211 if (dock
->icon_array
[index
] == icon
)
2213 assert(index
< dock
->max_icons
);
2214 dock
->icon_array
[index
] = NULL
;
2220 /* if the dock is not attached to an application or
2221 * the the application did not set the approriate hints yet,
2222 * destroy the icon */
2223 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2224 wAppIconDestroy(icon
);
2226 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2227 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2228 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2229 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2230 icon
->icon
->core
->descriptor
.parent
= icon
;
2232 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2234 wAppIconPaint(icon
);
2235 if (wPreferences
.auto_arrange_icons
) {
2236 wArrangeIcons(dock
->screen_ptr
, True
);
2239 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2244 * returns the closest Dock slot index for the passed
2247 * Returns False if icon can't be docked.
2249 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2252 Bool
wDockSnapIcon(WDock
* dock
, WAppIcon
* icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2254 WScreen
*scr
= dock
->screen_ptr
;
2257 int i
, offset
= ICON_SIZE
/ 2;
2258 WAppIcon
*aicon
= NULL
;
2259 WAppIcon
*nicon
= NULL
;
2260 int max_y_icons
, max_x_icons
;
2262 /* TODO: XINERAMA, for these */
2263 max_x_icons
= scr
->scr_width
/ ICON_SIZE
;
2264 max_y_icons
= scr
->scr_height
/ ICON_SIZE
- 1;
2266 if (wPreferences
.flags
.noupdates
)
2272 /* if the dock is full */
2273 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
)) {
2277 /* exact position */
2279 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2281 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2284 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2286 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2288 /* check if the icon is outside the screen boundaries */
2293 rect
.pos
.x
= dx
+ ex_x
* ICON_SIZE
;
2294 rect
.pos
.y
= dy
+ ex_y
* ICON_SIZE
;
2295 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2297 wGetRectPlacementInfo(scr
, rect
, &flags
);
2298 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
2302 if (dock
->type
== WM_DOCK
) {
2303 if (icon
->dock
!= dock
&& ex_x
!= 0)
2307 for (i
= 0; i
< dock
->max_icons
; i
++) {
2308 nicon
= dock
->icon_array
[i
];
2309 if (nicon
&& nicon
->yindex
== ex_y
) {
2316 int sig
, done
, closest
;
2318 /* Possible cases when redocking:
2320 * icon dragged out of range of any slot -> false
2321 * icon dragged to range of free slot
2322 * icon dragged to range of same slot
2323 * icon dragged to range of different icon
2325 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2328 if (ex_y
>= 0 && ex_y
<= max_y_icons
&& (aicon
== icon
|| !aicon
)) {
2334 /* start looking at the upper slot or lower? */
2335 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2342 /* look for closest free slot */
2343 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2347 closest
= sig
* (i
/ 2) + ex_y
;
2348 /* check if this slot is used */
2350 for (j
= 0; j
< dock
->max_icons
; j
++) {
2351 if (dock
->icon_array
[j
]
2352 && dock
->icon_array
[j
]->yindex
== closest
) {
2353 /* slot is used by someone else */
2354 if (dock
->icon_array
[j
] != icon
)
2362 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2363 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2364 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2369 } else { /* !redocking */
2371 /* if slot is free and the icon is close enough, return it */
2372 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2382 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2383 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+ 1;
2386 for (k
= start
; k
< stop
; k
++) {
2387 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2390 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2391 nicon
= tmp
->icon_array
[i
];
2392 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2400 for (k
= start
; k
< stop
; k
++) {
2401 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2404 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2405 nicon
= tmp
->icon_array
[i
];
2406 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2407 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2408 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2417 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2426 static int onScreen(WScreen
* scr
, int x
, int y
, int sx
, int ex
, int sy
, int ey
)
2428 WMRect rect
= wmkrect(x
, y
, ICON_SIZE
, ICON_SIZE
);
2431 wGetRectPlacementInfo(scr
, rect
, &flags
);
2433 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2437 * returns true if it can find a free slot in the dock,
2438 * in which case it changes x_pos and y_pos accordingly.
2439 * Else returns false.
2441 Bool
wDockFindFreeSlot(WDock
* dock
, int *x_pos
, int *y_pos
)
2443 WScreen
*scr
= dock
->screen_ptr
;
2445 WAppIconChain
*chain
;
2446 unsigned char *slot_map
;
2450 int i
, done
= False
;
2452 int sx
= 0, sy
= 0, ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2453 int extra_count
= 0;
2455 if (dock
->type
== WM_CLIP
&& dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2456 extra_count
= scr
->global_icon_count
;
2458 /* if the dock is full */
2459 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
) {
2463 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2464 if (scr
->dock
->on_right_side
)
2465 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2467 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2470 if (ex
< dock
->x_pos
)
2472 if (sx
> dock
->x_pos
+ ICON_SIZE
)
2473 sx
= dock
->x_pos
+ ICON_SIZE
;
2480 /* check if clip is in a corner */
2481 if (dock
->type
== WM_CLIP
) {
2482 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2484 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2486 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2488 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2495 /* If the clip is in the corner, use only slots that are in the border
2497 if (corner
!= C_NONE
) {
2501 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2502 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2503 hmap
= wmalloc(hcount
+ 1);
2504 memset(hmap
, 0, hcount
+ 1);
2505 vmap
= wmalloc(vcount
+ 1);
2506 memset(vmap
, 0, vcount
+ 1);
2508 /* mark used positions */
2511 for (i
= 0; i
< dock
->max_icons
; i
++) {
2512 btn
= dock
->icon_array
[i
];
2516 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2517 vmap
[btn
->yindex
] = 1;
2518 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2519 hmap
[btn
->xindex
] = 1;
2521 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2523 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2524 vmap
[btn
->yindex
] = 1;
2525 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2526 hmap
[btn
->xindex
] = 1;
2530 for (i
= 0; i
< dock
->max_icons
; i
++) {
2531 btn
= dock
->icon_array
[i
];
2535 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2536 vmap
[btn
->yindex
] = 1;
2537 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2538 hmap
[-btn
->xindex
] = 1;
2540 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2542 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2543 vmap
[btn
->yindex
] = 1;
2544 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2545 hmap
[-btn
->xindex
] = 1;
2549 for (i
= 0; i
< dock
->max_icons
; i
++) {
2550 btn
= dock
->icon_array
[i
];
2554 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2555 vmap
[-btn
->yindex
] = 1;
2556 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2557 hmap
[btn
->xindex
] = 1;
2559 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2561 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2562 vmap
[-btn
->yindex
] = 1;
2563 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2564 hmap
[btn
->xindex
] = 1;
2569 for (i
= 0; i
< dock
->max_icons
; i
++) {
2570 btn
= dock
->icon_array
[i
];
2574 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2575 vmap
[-btn
->yindex
] = 1;
2576 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2577 hmap
[-btn
->xindex
] = 1;
2579 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2581 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2582 vmap
[-btn
->yindex
] = 1;
2583 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2584 hmap
[-btn
->xindex
] = 1;
2590 /* search a vacant slot */
2591 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2592 if (i
< vcount
&& vmap
[i
] == 0) {
2598 } else if (i
< hcount
&& hmap
[i
] == 0) {
2608 /* If found a slot, translate and return */
2610 if (corner
== C_NW
|| corner
== C_NE
) {
2615 if (corner
== C_NE
|| corner
== C_SE
) {
2622 /* else, try to find a slot somewhere else */
2625 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2626 * placed outside of screen */
2627 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2629 /* In the worst case (the clip is in the corner of the screen),
2630 * the amount of icons that fit in the clip is smaller.
2631 * Double the map to get a safe value.
2635 r
= (mwidth
- 1) / 2;
2637 slot_map
= wmalloc(mwidth
* mwidth
);
2638 memset(slot_map
, 0, mwidth
* mwidth
);
2640 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2642 /* mark used slots in the map. If the slot falls outside the map
2643 * (for example, when all icons are placed in line), ignore them. */
2644 for (i
= 0; i
< dock
->max_icons
; i
++) {
2645 btn
= dock
->icon_array
[i
];
2647 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2649 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2650 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2652 /* Find closest slot from the center that is free by scanning the
2653 * map from the center to outward in circular passes.
2654 * This will not result in a neat layout, but will be optimal
2655 * in the sense that there will not be holes left.
2658 for (i
= 1; i
<= r
&& !done
; i
++) {
2661 /* top and bottom parts of the ring */
2662 for (x
= -i
; x
<= i
&& !done
; x
++) {
2663 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2665 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2666 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2673 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2674 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2681 /* left and right parts of the ring */
2682 for (y
= -i
+ 1; y
<= i
- 1; y
++) {
2683 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2685 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2686 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2693 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2694 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2707 static void moveDock(WDock
* dock
, int new_x
, int new_y
)
2712 dock
->x_pos
= new_x
;
2713 dock
->y_pos
= new_y
;
2714 for (i
= 0; i
< dock
->max_icons
; i
++) {
2715 btn
= dock
->icon_array
[i
];
2717 btn
->x_pos
= new_x
+ btn
->xindex
* ICON_SIZE
;
2718 btn
->y_pos
= new_y
+ btn
->yindex
* ICON_SIZE
;
2719 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2724 static void swapDock(WDock
* dock
)
2726 WScreen
*scr
= dock
->screen_ptr
;
2730 if (dock
->on_right_side
) {
2731 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2733 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2736 for (i
= 0; i
< dock
->max_icons
; i
++) {
2737 btn
= dock
->icon_array
[i
];
2740 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2744 wScreenUpdateUsableArea(scr
);
2747 static pid_t
execCommand(WAppIcon
* btn
, char *command
, WSavedState
* state
)
2749 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2755 cmdline
= ExpandOptions(scr
, command
);
2757 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2765 wtokensplit(cmdline
, &argv
, &argc
);
2775 if ((pid
= fork()) == 0) {
2779 SetupEnvironment(scr
);
2785 args
= malloc(sizeof(char *) * (argc
+ 1));
2788 for (i
= 0; i
< argc
; i
++) {
2792 execvp(argv
[0], args
);
2795 wtokenfree(argv
, argc
);
2799 state
= wmalloc(sizeof(WSavedState
));
2800 memset(state
, 0, sizeof(WSavedState
));
2802 state
->miniaturized
= -1;
2804 if (btn
->dock
== scr
->dock
|| btn
->omnipresent
)
2805 state
->workspace
= -1;
2807 state
->workspace
= scr
->current_workspace
;
2809 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
2810 wAddDeathHandler(pid
, (WDeathHandler
*) trackDeadProcess
, btn
->dock
);
2818 void wDockHideIcons(WDock
* dock
)
2825 for (i
= 1; i
< dock
->max_icons
; i
++) {
2826 if (dock
->icon_array
[i
])
2827 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2831 dockIconPaint(dock
->icon_array
[0]);
2834 void wDockShowIcons(WDock
* dock
)
2842 btn
= dock
->icon_array
[0];
2843 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2845 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2846 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2848 for (i
= 1; i
< dock
->max_icons
; i
++) {
2849 if (dock
->icon_array
[i
]) {
2850 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
, btn
->icon
->core
);
2855 if (!dock
->collapsed
) {
2856 for (i
= 1; i
< dock
->max_icons
; i
++) {
2857 if (dock
->icon_array
[i
]) {
2858 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2867 void wDockLower(WDock
* dock
)
2871 for (i
= 0; i
< dock
->max_icons
; i
++) {
2872 if (dock
->icon_array
[i
])
2873 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2877 void wDockRaise(WDock
* dock
)
2881 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
2882 if (dock
->icon_array
[i
])
2883 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2887 void wDockRaiseLower(WDock
* dock
)
2889 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2890 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2891 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2897 void wDockFinishLaunch(WDock
* dock
, WAppIcon
* icon
)
2899 icon
->launching
= 0;
2900 icon
->relaunching
= 0;
2901 dockIconPaint(icon
);
2904 WAppIcon
*wDockFindIconForWindow(WDock
* dock
, Window window
)
2909 for (i
= 0; i
< dock
->max_icons
; i
++) {
2910 icon
= dock
->icon_array
[i
];
2911 if (icon
&& icon
->main_window
== window
)
2917 void wDockTrackWindowLaunch(WDock
* dock
, Window window
)
2920 char *wm_class
, *wm_instance
;
2922 Bool firstPass
= True
;
2924 char *command
= NULL
;
2926 command
= GetCommandForWindow(window
);
2928 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) || (!wm_class
&& !wm_instance
)) {
2936 for (i
= 0; i
< dock
->max_icons
; i
++) {
2937 icon
= dock
->icon_array
[i
];
2941 /* app is already attached to icon */
2942 if (icon
->main_window
== window
) {
2947 if ((icon
->wm_instance
|| icon
->wm_class
)
2948 && (icon
->launching
|| !icon
->running
)) {
2950 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0) {
2953 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0) {
2956 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0) {
2960 if (!icon
->relaunching
) {
2963 /* Possibly an application that was docked with dockit,
2964 * but the user did not update WMState to indicate that
2965 * it was docked by force */
2966 wapp
= wApplicationOf(window
);
2968 icon
->forced_dock
= 1;
2971 if (!icon
->forced_dock
) {
2972 icon
->main_window
= window
;
2976 if (!wPreferences
.no_animations
&& !icon
->launching
&&
2977 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
2981 icon
->launching
= 1;
2982 dockIconPaint(icon
);
2984 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
2985 wm_instance
, wm_class
, TILE_NORMAL
);
2986 /* XXX: can: aicon->icon == NULL ? */
2987 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
2988 wAppIconMove(aicon
, x0
, y0
);
2989 /* Should this always be lowered? -Dan */
2991 wLowerFrame(aicon
->icon
->core
);
2992 XMapWindow(dpy
, aicon
->icon
->core
->window
);
2993 aicon
->launching
= 1;
2994 wAppIconPaint(aicon
);
2995 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
2996 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
2997 wAppIconDestroy(aicon
);
2999 wDockFinishLaunch(dock
, icon
);
3004 if (firstPass
&& !found
) {
3018 void wClipUpdateForWorkspaceChange(WScreen
* scr
, int workspace
)
3020 if (!wPreferences
.flags
.noclip
) {
3021 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3022 if (scr
->current_workspace
!= workspace
) {
3023 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3024 WAppIconChain
*chain
= scr
->global_icons
;
3027 moveIconBetweenDocks(chain
->aicon
->dock
,
3028 scr
->workspaces
[workspace
]->clip
,
3029 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
3030 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
3031 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3032 chain
= chain
->next
;
3035 wDockHideIcons(old_clip
);
3036 if (old_clip
->auto_raise_lower
) {
3037 if (old_clip
->auto_raise_magic
) {
3038 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3039 old_clip
->auto_raise_magic
= NULL
;
3041 wDockLower(old_clip
);
3043 if (old_clip
->auto_collapse
) {
3044 if (old_clip
->auto_expand_magic
) {
3045 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3046 old_clip
->auto_expand_magic
= NULL
;
3048 old_clip
->collapsed
= 1;
3050 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3052 if (scr
->flags
.clip_balloon_mapped
)
3053 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3057 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
* dock
)
3062 for (i
= 0; i
< dock
->max_icons
; i
++) {
3063 icon
= dock
->icon_array
[i
];
3067 if (icon
->launching
&& icon
->pid
== pid
) {
3068 if (!icon
->relaunching
) {
3070 icon
->main_window
= None
;
3072 wDockFinishLaunch(dock
, icon
);
3074 if (status
== 111) {
3079 if (icon
->drop_launch
)
3080 cmd
= icon
->dnd_command
;
3083 if (icon
->paste_launch
)
3084 cmd
= icon
->paste_command
;
3086 cmd
= icon
->command
;
3088 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3090 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3097 static void toggleLowered(WDock
* dock
)
3102 /* lower/raise Dock */
3103 if (!dock
->lowered
) {
3104 newlevel
= WMNormalLevel
;
3107 newlevel
= WMDockLevel
;
3111 for (i
= 0; i
< dock
->max_icons
; i
++) {
3112 tmp
= dock
->icon_array
[i
];
3116 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3118 wLowerFrame(tmp
->icon
->core
);
3121 if (dock
->type
== WM_DOCK
)
3122 wScreenUpdateUsableArea(dock
->screen_ptr
);
3125 static void toggleCollapsed(WDock
* dock
)
3127 if (dock
->collapsed
) {
3128 dock
->collapsed
= 0;
3129 wDockShowIcons(dock
);
3131 dock
->collapsed
= 1;
3132 wDockHideIcons(dock
);
3136 static void openDockMenu(WDock
* dock
, WAppIcon
* aicon
, XEvent
* event
)
3138 WScreen
*scr
= dock
->screen_ptr
;
3139 WObjDescriptor
*desc
;
3141 WApplication
*wapp
= NULL
;
3145 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3147 if (dock
->type
== WM_DOCK
) {
3149 entry
= dock
->menu
->entries
[index
];
3150 entry
->flags
.indicator_on
= !dock
->lowered
;
3151 entry
->clientdata
= dock
;
3152 dock
->menu
->flags
.realized
= 0;
3155 if (scr
->clip_options
)
3156 updateClipOptionsMenu(scr
->clip_options
, dock
);
3158 n_selected
= numberOfSelectedIcons(dock
);
3160 /* Rename Workspace */
3161 entry
= dock
->menu
->entries
[++index
];
3162 if (aicon
== scr
->clip_icon
) {
3163 entry
->callback
= renameCallback
;
3164 entry
->clientdata
= dock
;
3165 entry
->flags
.indicator
= 0;
3166 entry
->text
= _("Rename Workspace");
3168 entry
->callback
= omnipresentCallback
;
3169 entry
->clientdata
= aicon
;
3170 if (n_selected
> 0) {
3171 entry
->flags
.indicator
= 0;
3172 entry
->text
= _("Toggle Omnipresent");
3174 entry
->flags
.indicator
= 1;
3175 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3176 entry
->flags
.indicator_type
= MI_CHECK
;
3177 entry
->text
= _("Omnipresent");
3181 /* select/unselect icon */
3182 entry
= dock
->menu
->entries
[++index
];
3183 entry
->clientdata
= aicon
;
3184 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3185 wMenuSetEnabled(dock
->menu
, index
, aicon
!= scr
->clip_icon
);
3187 /* select/unselect all icons */
3188 entry
= dock
->menu
->entries
[++index
];
3189 entry
->clientdata
= aicon
;
3191 entry
->text
= _("Unselect All Icons");
3193 entry
->text
= _("Select All Icons");
3194 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3197 entry
= dock
->menu
->entries
[++index
];
3198 entry
->clientdata
= aicon
;
3200 entry
->text
= _("Keep Icons");
3202 entry
->text
= _("Keep Icon");
3203 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3205 /* this is the workspace submenu part */
3206 entry
= dock
->menu
->entries
[++index
];
3208 entry
->text
= _("Move Icons To");
3210 entry
->text
= _("Move Icon To");
3211 if (scr
->clip_submenu
)
3212 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3213 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3215 /* remove icon(s) */
3216 entry
= dock
->menu
->entries
[++index
];
3217 entry
->clientdata
= aicon
;
3219 entry
->text
= _("Remove Icons");
3221 entry
->text
= _("Remove Icon");
3222 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3224 /* attract icon(s) */
3225 entry
= dock
->menu
->entries
[++index
];
3226 entry
->clientdata
= aicon
;
3228 dock
->menu
->flags
.realized
= 0;
3229 wMenuRealize(dock
->menu
);
3232 if (aicon
->icon
->owner
) {
3233 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3239 entry
= dock
->menu
->entries
[++index
];
3240 entry
->clientdata
= aicon
;
3241 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3244 entry
= dock
->menu
->entries
[++index
];
3245 entry
->clientdata
= aicon
;
3246 if (wapp
&& wapp
->flags
.hidden
) {
3247 entry
->text
= _("Unhide Here");
3249 entry
->text
= _("Bring Here");
3251 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3254 entry
= dock
->menu
->entries
[++index
];
3255 entry
->clientdata
= aicon
;
3256 if (wapp
&& wapp
->flags
.hidden
) {
3257 entry
->text
= _("Unhide");
3259 entry
->text
= _("Hide");
3261 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3264 entry
= dock
->menu
->entries
[++index
];
3265 entry
->clientdata
= aicon
;
3266 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3269 entry
= dock
->menu
->entries
[++index
];
3270 entry
->clientdata
= aicon
;
3271 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3273 if (!dock
->menu
->flags
.realized
)
3274 wMenuRealize(dock
->menu
);
3276 if (dock
->type
== WM_CLIP
) {
3277 /*x_pos = event->xbutton.x_root+2; */
3278 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3281 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3282 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3285 x_pos
= dock
->on_right_side
? scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3288 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3290 /* allow drag select */
3291 event
->xany
.send_event
= True
;
3292 desc
= &dock
->menu
->menu
->descriptor
;
3293 (*desc
->handle_mousedown
) (desc
, event
);
3296 /******************************************************************/
3297 static void iconDblClick(WObjDescriptor
* desc
, XEvent
* event
)
3299 WAppIcon
*btn
= desc
->parent
;
3300 WDock
*dock
= btn
->dock
;
3301 WApplication
*wapp
= NULL
;
3304 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3305 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3307 assert(wapp
!= NULL
);
3309 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3311 /* go to the last workspace that the user worked on the app */
3312 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
&& !unhideHere
) {
3313 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3316 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3318 if (event
->xbutton
.state
& MOD_MASK
) {
3319 wHideOtherApplications(btn
->icon
->owner
);
3322 if (event
->xbutton
.button
== Button1
) {
3324 if (event
->xbutton
.state
& MOD_MASK
) {
3325 /* raise/lower dock */
3326 toggleLowered(dock
);
3327 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3328 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
)
3329 toggleCollapsed(dock
);
3331 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3332 } else if (btn
->command
) {
3333 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3334 launchDockedApplication(btn
, False
);
3336 } else if (btn
->xindex
== 0 && btn
->yindex
== 0 && btn
->dock
->type
== WM_DOCK
) {
3337 wShowGNUstepPanel(dock
->screen_ptr
);
3343 static void handleDockMove(WDock
* dock
, WAppIcon
* aicon
, XEvent
* event
)
3345 WScreen
*scr
= dock
->screen_ptr
;
3346 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3349 int grabbed
= 0, swapped
= 0, done
;
3350 Pixmap ghost
= None
;
3351 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3353 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3354 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3355 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3356 wwarning("pointer grab failed for dock move");
3359 for (x
= 0; x
< dock
->max_icons
; x
++) {
3360 if (dock
->icon_array
[x
] != NULL
&& dock
->icon_array
[x
]->yindex
> y
)
3361 y
= dock
->icon_array
[x
]->yindex
;
3364 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
* y
);
3368 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3369 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3376 /* It means the cursor moved so fast that it entered
3377 * something else (if moving slowly, it would have
3378 * stayed in the dock that is being moved. Ignore such
3379 * "spurious" EnterNotifiy's */
3384 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3385 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3386 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3387 | ButtonReleaseMask
| ButtonPressMask
,
3388 wCursor
[WCUR_MOVE
], CurrentTime
);
3393 if (dock
->type
== WM_CLIP
) {
3394 x
= ev
.xmotion
.x_root
- ofs_x
;
3395 y
= ev
.xmotion
.y_root
- ofs_y
;
3396 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3398 moveDock(dock
, x
, y
);
3400 /* move vertically if pointer is inside the dock */
3401 if ((dock
->on_right_side
&& ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3402 || (!dock
->on_right_side
&& ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
* 2)) {
3404 x
= ev
.xmotion
.x_root
- ofs_x
;
3405 y
= ev
.xmotion
.y_root
- ofs_y
;
3406 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3407 moveDock(dock
, dock
->x_pos
, y
);
3409 /* move horizontally to change sides */
3410 x
= ev
.xmotion
.x_root
- ofs_x
;
3411 if (!dock
->on_right_side
) {
3415 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
* 2) {
3416 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
- ICON_SIZE
3417 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3418 if (superfluous
&& ghost
== None
) {
3419 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3420 scr
->scr_width
- ICON_SIZE
3421 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3422 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3423 XClearWindow(dpy
, scr
->dock_shadow
);
3425 XMapRaised(dpy
, scr
->dock_shadow
);
3428 if (superfluous
&& ghost
!= None
) {
3429 XFreePixmap(dpy
, ghost
);
3432 XUnmapWindow(dpy
, scr
->dock_shadow
);
3437 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3438 XMoveWindow(dpy
, scr
->dock_shadow
, DOCK_EXTRA_SPACE
, dock
->y_pos
);
3439 if (superfluous
&& ghost
== None
) {
3440 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3441 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3442 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3443 XClearWindow(dpy
, scr
->dock_shadow
);
3445 XMapRaised(dpy
, scr
->dock_shadow
);
3448 XUnmapWindow(dpy
, scr
->dock_shadow
);
3450 if (superfluous
&& ghost
!= None
) {
3451 XFreePixmap(dpy
, ghost
);
3463 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3465 XUngrabPointer(dpy
, CurrentTime
);
3466 XUnmapWindow(dpy
, scr
->dock_shadow
);
3467 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3468 if (dock
->type
== WM_DOCK
) {
3471 dock
->on_right_side
= 1;
3473 dock
->on_right_side
= 0;
3475 wArrangeIcons(scr
, False
);
3484 XFreePixmap(dpy
, ghost
);
3485 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3489 static Bool
handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3491 WScreen
*scr
= dock
->screen_ptr
;
3493 WIcon
*icon
= aicon
->icon
;
3494 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3495 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3497 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3498 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3499 int shad_x
= x
, shad_y
= y
;
3500 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3502 Pixmap ghost
= None
;
3504 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3505 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3506 Bool hasMoved
= False
;
3508 if (wPreferences
.flags
.noupdates
)
3511 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3512 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3513 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3516 if (!(event
->xbutton
.state
& MOD_MASK
))
3517 wRaiseFrame(icon
->core
);
3519 if (!wPreferences
.flags
.noclip
)
3520 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3522 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3524 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3527 wins
[0] = icon
->core
->window
;
3528 wins
[1] = scr
->dock_shadow
;
3529 XRestackWindows(dpy
, wins
, 2);
3530 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
3532 if (icon
->pixmap
!= None
)
3533 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3535 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3537 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3538 XClearWindow(dpy
, scr
->dock_shadow
);
3540 XMapWindow(dpy
, scr
->dock_shadow
);
3545 XMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3546 | ButtonMotionMask
| ExposureMask
, &ev
);
3555 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3556 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3557 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3558 | ButtonReleaseMask
| ButtonPressMask
,
3559 wCursor
[WCUR_MOVE
], CurrentTime
);
3568 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3569 if (i
== scr
->current_workspace
)
3571 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3575 x
= ev
.xmotion
.x_root
- ofs_x
;
3576 y
= ev
.xmotion
.y_root
- ofs_y
;
3577 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3580 if (last_dock
!= dock
&& collapsed
) {
3581 last_dock
->collapsed
= 1;
3582 wDockHideIcons(last_dock
);
3585 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3586 dock
->collapsed
= 0;
3587 wDockShowIcons(dock
);
3589 if (dock
->auto_raise_lower
)
3593 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3596 if (last_dock
!= dock2
&& collapsed
) {
3597 last_dock
->collapsed
= 1;
3598 wDockHideIcons(last_dock
);
3601 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3602 dock2
->collapsed
= 0;
3603 wDockShowIcons(dock2
);
3605 if (dock2
->auto_raise_lower
)
3610 if (aicon
->launching
|| aicon
->lock
|| (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3611 || (!aicon
->running
&& tmp
)) {
3612 shad_x
= last_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3613 shad_y
= last_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3615 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3618 XMapWindow(dpy
, scr
->dock_shadow
);
3623 XUnmapWindow(dpy
, scr
->dock_shadow
);
3627 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3634 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3636 XUngrabPointer(dpy
, CurrentTime
);
3638 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3639 XUnmapWindow(dpy
, scr
->dock_shadow
);
3641 reattachIcon(dock
, aicon
, ix
, iy
);
3642 if (clip
&& dock
!= clip
&& clip
->auto_raise_lower
)
3645 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3647 /* Slide it back if dock rejected it */
3648 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
, aicon
->y_pos
);
3649 reattachIcon(dock
, aicon
, aicon
->xindex
, aicon
->yindex
);
3651 if (last_dock
->type
== WM_CLIP
&& last_dock
->auto_collapse
) {
3659 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3660 /* We need to deselect it, even if is deselected in
3661 * wDockDetach(), because else DoKaboom() will fail.
3663 if (aicon
->icon
->selected
)
3664 wIconSelect(aicon
->icon
);
3666 DoKaboom(scr
, aicon
->icon
->core
->window
, x
, y
);
3669 if (clip
&& clip
->auto_raise_lower
)
3671 wDockDetach(dock
, aicon
);
3674 last_dock
->collapsed
= 1;
3675 wDockHideIcons(last_dock
);
3680 XFreePixmap(dpy
, ghost
);
3681 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3685 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3686 if (i
== scr
->current_workspace
)
3688 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3694 return False
; /* never reached */
3697 static int getClipButton(int px
, int py
)
3699 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3701 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3704 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3705 return CLIP_FORWARD
;
3706 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3712 static void handleClipChangeWorkspace(WScreen
* scr
, XEvent
* event
)
3715 int done
, direction
, new_ws
;
3717 WDock
*clip
= scr
->clip_icon
->dock
;
3719 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3721 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3722 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3724 wClipIconPaint(scr
->clip_icon
);
3727 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3734 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3735 if (new_dir
!= direction
) {
3736 direction
= new_dir
;
3737 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3738 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3739 wClipIconPaint(scr
->clip_icon
);
3747 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3752 clip
->lclip_button_pushed
= 0;
3753 clip
->rclip_button_pushed
= 0;
3755 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3757 if (direction
== CLIP_FORWARD
) {
3758 if (scr
->current_workspace
< scr
->workspace_count
- 1)
3759 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3760 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
- 1)
3761 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3762 else if (wPreferences
.ws_cycle
)
3763 wWorkspaceChange(scr
, 0);
3764 } else if (direction
== CLIP_REWIND
) {
3765 if (scr
->current_workspace
> 0)
3766 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
3767 else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
)
3768 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
3771 wClipIconPaint(scr
->clip_icon
);
3774 static void iconMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
3776 WAppIcon
*aicon
= desc
->parent
;
3777 WDock
*dock
= aicon
->dock
;
3778 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3780 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3783 scr
->last_dock
= dock
;
3785 if (dock
->menu
->flags
.mapped
)
3786 wMenuUnmap(dock
->menu
);
3788 if (IsDoubleClick(scr
, event
)) {
3789 /* double-click was not in the main clip icon */
3790 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3791 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3792 iconDblClick(desc
, event
);
3797 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
3798 XUnmapWindow(dpy
, scr
->clip_balloon
);
3799 scr
->flags
.clip_balloon_mapped
= 0;
3801 if (event
->xbutton
.button
== Button1
) {
3802 if (event
->xbutton
.state
& MOD_MASK
)
3807 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
&& dock
->type
!= WM_DOCK
) {
3808 wIconSelect(aicon
->icon
);
3812 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3813 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
3814 && dock
->type
== WM_CLIP
)
3815 handleClipChangeWorkspace(scr
, event
);
3817 handleDockMove(dock
, aicon
, event
);
3819 Bool hasMoved
= handleIconMove(dock
, aicon
, event
);
3820 if (wPreferences
.single_click
&& !hasMoved
)
3821 iconDblClick(desc
, event
);
3823 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&& aicon
== scr
->clip_icon
) {
3824 if (!scr
->clip_ws_menu
) {
3825 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3827 if (scr
->clip_ws_menu
) {
3828 WMenu
*wsMenu
= scr
->clip_ws_menu
;
3831 wWorkspaceMenuUpdate(scr
, wsMenu
);
3833 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
3836 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
3837 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
3839 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
3841 desc
= &wsMenu
->menu
->descriptor
;
3842 event
->xany
.send_event
= True
;
3843 (*desc
->handle_mousedown
) (desc
, event
);
3845 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
3846 (event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
) {
3847 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3848 } else if (event
->xbutton
.button
== Button3
) {
3849 if (event
->xbutton
.send_event
&&
3850 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3851 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3852 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3853 wwarning("pointer grab failed for dockicon menu");
3857 openDockMenu(dock
, aicon
, event
);
3858 } else if (event
->xbutton
.button
== Button2
) {
3859 WAppIcon
*btn
= desc
->parent
;
3861 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3862 launchDockedApplication(btn
, True
);
3867 static void showClipBalloon(WDock
* dock
, int workspace
)
3871 WScreen
*scr
= dock
->screen_ptr
;
3875 scr
->flags
.clip_balloon_mapped
= 1;
3876 XMapWindow(dpy
, scr
->clip_balloon
);
3878 text
= scr
->workspaces
[workspace
]->name
;
3880 w
= WMWidthOfString(scr
->clip_title_font
, text
, strlen(text
));
3882 h
= WMFontHeight(scr
->clip_title_font
);
3883 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
3885 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
3886 y
= dock
->y_pos
+ ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
3888 if (x
+ w
> scr
->scr_width
) {
3889 x
= scr
->scr_width
- w
;
3890 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
3891 y
= dock
->y_pos
- h
- 1;
3893 y
= dock
->y_pos
+ ICON_SIZE
;
3894 XRaiseWindow(dpy
, scr
->clip_balloon
);
3896 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
3897 stack
[1] = scr
->clip_balloon
;
3898 XRestackWindows(dpy
, stack
, 2);
3900 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
3901 XClearWindow(dpy
, scr
->clip_balloon
);
3902 WMDrawString(scr
->wmscreen
, scr
->clip_balloon
,
3903 scr
->clip_title_color
[CLIP_NORMAL
], scr
->clip_title_font
, 0, 0, text
, strlen(text
));
3906 static void clipEnterNotify(WObjDescriptor
* desc
, XEvent
* event
)
3908 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3912 assert(event
->type
== EnterNotify
);
3914 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3917 scr
= btn
->icon
->core
->screen_ptr
;
3918 if (!btn
->omnipresent
)
3921 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3923 if (!dock
|| dock
->type
!= WM_CLIP
)
3926 /* The auto raise/lower code */
3927 if (dock
->auto_lower_magic
) {
3928 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3929 dock
->auto_lower_magic
= NULL
;
3931 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
3932 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
, clipAutoRaise
, (void *)dock
);
3935 /* The auto expand/collapse code */
3936 if (dock
->auto_collapse_magic
) {
3937 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3938 dock
->auto_collapse_magic
= NULL
;
3940 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
3941 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
, clipAutoExpand
, (void *)dock
);
3944 if (btn
->xindex
== 0 && btn
->yindex
== 0)
3945 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
3947 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
3948 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
3949 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
3954 static void clipLeave(WDock
* dock
)
3957 WObjDescriptor
*desc
= NULL
;
3959 if (!dock
|| dock
->type
!= WM_CLIP
)
3962 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
3963 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3964 (XPointer
*) & desc
) != XCNOENT
3965 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
3966 && ((WAppIcon
*) desc
->parent
)->dock
&& ((WAppIcon
*) desc
->parent
)->dock
->type
== WM_CLIP
) {
3967 /* We didn't left the Clip yet */
3968 XPutBackEvent(dpy
, &event
);
3972 XPutBackEvent(dpy
, &event
);
3974 /* We entered a withdrawn window, so we're still in Clip */
3978 if (dock
->auto_raise_magic
) {
3979 WMDeleteTimerHandler(dock
->auto_raise_magic
);
3980 dock
->auto_raise_magic
= NULL
;
3982 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
3983 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
, clipAutoLower
, (void *)dock
);
3986 if (dock
->auto_expand_magic
) {
3987 WMDeleteTimerHandler(dock
->auto_expand_magic
);
3988 dock
->auto_expand_magic
= NULL
;
3990 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
3991 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
, clipAutoCollapse
, (void *)dock
);
3995 static void clipLeaveNotify(WObjDescriptor
* desc
, XEvent
* event
)
3997 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3999 assert(event
->type
== LeaveNotify
);
4001 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
4004 clipLeave(btn
->dock
);
4007 static void clipAutoCollapse(void *cdata
)
4009 WDock
*dock
= (WDock
*) cdata
;
4011 if (dock
->type
!= WM_CLIP
)
4014 if (dock
->auto_collapse
) {
4015 dock
->collapsed
= 1;
4016 wDockHideIcons(dock
);
4018 dock
->auto_collapse_magic
= NULL
;
4021 static void clipAutoExpand(void *cdata
)
4023 WDock
*dock
= (WDock
*) cdata
;
4025 if (dock
->type
!= WM_CLIP
)
4028 if (dock
->auto_collapse
) {
4029 dock
->collapsed
= 0;
4030 wDockShowIcons(dock
);
4032 dock
->auto_expand_magic
= NULL
;
4035 static void clipAutoLower(void *cdata
)
4037 WDock
*dock
= (WDock
*) cdata
;
4039 if (dock
->type
!= WM_CLIP
)
4042 if (dock
->auto_raise_lower
)
4045 dock
->auto_lower_magic
= NULL
;
4048 static void clipAutoRaise(void *cdata
)
4050 WDock
*dock
= (WDock
*) cdata
;
4052 if (dock
->type
!= WM_CLIP
)
4055 if (dock
->auto_raise_lower
)
4058 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4059 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4062 dock
->auto_raise_magic
= NULL
;
4065 static Bool
iconCanBeOmnipresent(WAppIcon
* aicon
)
4067 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4072 for (i
= 0; i
< scr
->workspace_count
; i
++) {
4073 clip
= scr
->workspaces
[i
]->clip
;
4075 if (clip
== aicon
->dock
)
4078 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4079 return False
; /* Clip is full in some workspace */
4081 for (j
= 0; j
< clip
->max_icons
; j
++) {
4082 btn
= clip
->icon_array
[j
];
4083 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
4091 int wClipMakeIconOmnipresent(WAppIcon
* aicon
, int omnipresent
)
4093 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4094 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4095 int status
= WO_SUCCESS
;
4097 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== scr
->clip_icon
) {
4098 return WO_NOT_APPLICABLE
;
4101 if (aicon
->omnipresent
== omnipresent
)
4105 if (iconCanBeOmnipresent(aicon
)) {
4106 aicon
->omnipresent
= 1;
4107 new_entry
= wmalloc(sizeof(WAppIconChain
));
4108 new_entry
->aicon
= aicon
;
4109 new_entry
->next
= scr
->global_icons
;
4110 scr
->global_icons
= new_entry
;
4111 scr
->global_icon_count
++;
4113 aicon
->omnipresent
= 0;
4117 aicon
->omnipresent
= 0;
4118 if (aicon
== scr
->global_icons
->aicon
) {
4119 tmp
= scr
->global_icons
->next
;
4120 wfree(scr
->global_icons
);
4121 scr
->global_icons
= tmp
;
4122 scr
->global_icon_count
--;
4124 tmp
= scr
->global_icons
;
4126 if (tmp
->next
->aicon
== aicon
) {
4127 tmp1
= tmp
->next
->next
;
4130 scr
->global_icon_count
--;
4138 wAppIconPaint(aicon
);