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>
35 #define PATH_MAX DEFAULT_PATH_MAX
38 #include "WindowMaker.h"
46 #include "dockedapp.h"
49 #include "properties.h"
53 #include "workspace.h"
55 #include "superfluous.h"
58 /**** Local variables ****/
61 #define CLIP_FORWARD 2
63 /**** Global variables ****/
64 extern Cursor wCursor
[WCUR_LAST
];
65 extern WPreferences wPreferences
;
66 extern XContext wWinContext
;
67 extern void appIconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
69 #define MOD_MASK wPreferences.modifier_mask
70 #define ICON_SIZE wPreferences.icon_size
72 /***** Local variables ****/
74 static WMPropList
*dCommand
= NULL
;
75 static WMPropList
*dPasteCommand
= NULL
;
76 #ifdef XDND /* XXX was OFFIX */
77 static WMPropList
*dDropCommand
= NULL
;
79 static WMPropList
*dAutoLaunch
, *dLock
;
80 static WMPropList
*dName
, *dForced
, *dBuggyApplication
, *dYes
, *dNo
;
81 static WMPropList
*dHost
, *dDock
, *dClip
;
82 static WMPropList
*dAutoAttractIcons
;
84 static WMPropList
*dPosition
, *dApplications
, *dLowered
, *dCollapsed
;
86 static WMPropList
*dAutoCollapse
, *dAutoRaiseLower
, *dOmnipresent
;
88 static void dockIconPaint(WAppIcon
*btn
);
90 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
92 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
);
94 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
96 static int getClipButton(int px
, int py
);
98 static void toggleLowered(WDock
*dock
);
100 static void toggleCollapsed(WDock
*dock
);
102 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
104 static void clipLeave(WDock
*dock
);
106 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
108 static Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
);
110 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
111 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
112 static void clipAutoCollapse(void *cdata
);
113 static void clipAutoExpand(void *cdata
);
114 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
);
116 static void clipAutoLower(void *cdata
);
117 static void clipAutoRaise(void *cdata
);
118 static void reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
);
119 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
);
121 static void make_keys(void)
123 if (dCommand
!= NULL
)
126 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
127 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
129 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
131 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
132 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
133 dName
= WMRetainPropList(WMCreatePLString("Name"));
134 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
135 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
136 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
137 dNo
= WMRetainPropList(WMCreatePLString("No"));
138 dHost
= WMRetainPropList(WMCreatePLString("Host"));
140 dPosition
= WMCreatePLString("Position");
141 dApplications
= WMCreatePLString("Applications");
142 dLowered
= WMCreatePLString("Lowered");
143 dCollapsed
= WMCreatePLString("Collapsed");
144 dAutoCollapse
= WMCreatePLString("AutoCollapse");
145 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
146 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
148 dOmnipresent
= WMCreatePLString("Omnipresent");
150 dDock
= WMCreatePLString("Dock");
151 dClip
= WMCreatePLString("Clip");
154 static void renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
156 WDock
*dock
= entry
->clientdata
;
161 assert(entry
->clientdata
!= NULL
);
163 wspace
= dock
->screen_ptr
->current_workspace
;
165 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
167 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+ 1);
168 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
, &name
)) {
169 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
175 static void toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
177 assert(entry
->clientdata
!= NULL
);
179 toggleLowered(entry
->clientdata
);
181 entry
->flags
.indicator_on
= !(((WDock
*) entry
->clientdata
)->lowered
);
186 static int matchWindow(const void *item
, const void *cdata
)
188 return (((WFakeGroupLeader
*) item
)->leader
== (Window
) cdata
);
191 static void killCallback(WMenu
*menu
, WMenuEntry
*entry
)
193 WScreen
*scr
= menu
->menu
->screen_ptr
;
195 WFakeGroupLeader
*fPtr
;
196 char *buffer
, *shortname
, **argv
;
197 char *basename(const char *shortname
);
200 if (!WCHECK_STATE(WSTATE_NORMAL
))
203 assert(entry
->clientdata
!= NULL
);
205 icon
= (WAppIcon
*) entry
->clientdata
;
209 WCHANGE_STATE(WSTATE_MODAL
);
211 /* strip away dir names */
212 shortname
= basename(icon
->command
);
213 /* separate out command options */
214 wtokensplit(shortname
, &argv
, &argc
);
216 buffer
= wstrconcat(argv
[0],
217 _(" will be forcibly closed.\n"
218 "Any unsaved changes will be lost.\n" "Please confirm."));
220 if (icon
->icon
&& icon
->icon
->owner
) {
221 fPtr
= icon
->icon
->owner
->fake_group
;
223 /* is this really necessary? can we kill a non-running dock icon? */
224 Window win
= icon
->main_window
;
227 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)win
);
228 if (index
!= WANotFound
)
229 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
234 if (wPreferences
.dont_confirm_kill
235 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
236 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
238 WWindow
*wwin
, *twin
;
240 wwin
= scr
->focused_window
;
243 if (wwin
->fake_group
== fPtr
) {
248 } else if (icon
->icon
&& icon
->icon
->owner
) {
249 wClientKill(icon
->icon
->owner
);
254 wtokenfree(argv
, argc
);
258 WCHANGE_STATE(WSTATE_NORMAL
);
261 /* TODO: replace this function with a member of the dock struct */
262 static int numberOfSelectedIcons(WDock
*dock
)
268 for (i
= 1; i
< dock
->max_icons
; i
++) {
269 aicon
= dock
->icon_array
[i
];
270 if (aicon
&& aicon
->icon
->selected
) {
278 static WMArray
*getSelected(WDock
*dock
)
280 WMArray
*ret
= WMCreateArray(8);
284 for (i
= 1; i
< dock
->max_icons
; i
++) {
285 btn
= dock
->icon_array
[i
];
286 if (btn
&& btn
->icon
->selected
) {
287 WMAddToArray(ret
, btn
);
294 static void paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
296 Window win
= clipIcon
->icon
->core
->window
;
297 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
299 int pt
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
300 int tp
= ICON_SIZE
- pt
;
301 int as
= pt
- 15; /* 15 = 5+5+5 */
302 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
305 color
= scr
->clip_title_color
[CLIP_NORMAL
];
307 XSetForeground(dpy
, gc
, WMColorPixel(color
));
312 p
[1].x
= ICON_SIZE
- 2;
314 p
[2].x
= ICON_SIZE
- 2;
316 } else if (lpushed
) {
320 p
[1].y
= ICON_SIZE
- 2;
322 p
[2].y
= ICON_SIZE
- 2;
324 if (lpushed
|| rpushed
) {
325 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
326 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
327 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
330 /* top right arrow */
331 p
[0].x
= p
[3].x
= ICON_SIZE
- 5 - as
;
333 p
[1].x
= ICON_SIZE
- 6;
335 p
[2].x
= ICON_SIZE
- 6;
338 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
339 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
341 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
342 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
345 /* bottom left arrow */
347 p
[0].y
= p
[3].y
= ICON_SIZE
- 5 - as
;
349 p
[1].y
= ICON_SIZE
- 6;
351 p
[2].y
= ICON_SIZE
- 6;
353 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
354 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
356 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
357 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
361 RImage
*wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
363 RImage
*tile
= RCloneImage(normalTile
);
370 pt
= CLIP_BUTTON_SIZE
* wPreferences
.icon_size
/ 64;
371 tp
= wPreferences
.icon_size
- 1 - pt
;
375 black
.red
= black
.green
= black
.blue
= 0;
378 dark
.red
= dark
.green
= dark
.blue
= 60;
381 light
.red
= light
.green
= light
.blue
= 80;
384 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
- 2, pt
- 1, &dark
);
385 RDrawLine(tile
, tp
- 1, 0, wPreferences
.icon_size
- 1, pt
+ 1, &black
);
386 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
- 3, pt
, &light
);
389 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, 4, &dark
);
390 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 5, 6 + as
, &dark
);
391 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
, &light
);
394 ROperateLine(tile
, RAddOperation
, 2, tp
+ 2, pt
- 2, wPreferences
.icon_size
- 3, &dark
);
395 RDrawLine(tile
, 0, tp
- 1, pt
+ 1, wPreferences
.icon_size
- 1, &black
);
396 ROperateLine(tile
, RSubtractOperation
, 0, tp
- 2, pt
+ 1, wPreferences
.icon_size
- 2, &light
);
399 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, &dark
);
400 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
, 6 + as
, ICON_SIZE
- 5, &dark
);
401 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5, &light
);
406 static void omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
408 WAppIcon
*clickedIcon
= entry
->clientdata
;
411 WMArray
*selectedIcons
;
412 WMArrayIterator iter
;
415 assert(entry
->clientdata
!= NULL
);
417 dock
= clickedIcon
->dock
;
419 selectedIcons
= getSelected(dock
);
421 if (!WMGetArrayItemCount(selectedIcons
))
422 WMAddToArray(selectedIcons
, clickedIcon
);
425 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
426 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
428 else if (aicon
->icon
->selected
)
429 wIconSelect(aicon
->icon
);
431 WMFreeArray(selectedIcons
);
434 wMessageDialog(dock
->screen_ptr
, _("Warning"),
435 _("Some icons cannot be made omnipresent. "
436 "Please make sure that no other icon is "
437 "docked in the same positions on the other "
438 "workspaces and the Clip is not full in "
439 "some workspace."), _("OK"), NULL
, NULL
);
440 } else if (failed
== 1) {
441 wMessageDialog(dock
->screen_ptr
, _("Warning"),
442 _("Icon cannot be made omnipresent. "
443 "Please make sure that no other icon is "
444 "docked in the same position on the other "
445 "workspaces and the Clip is not full in "
446 "some workspace."), _("OK"), NULL
, NULL
);
450 static void removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
452 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
455 WMArray
*selectedIcons
;
459 assert(clickedIcon
!= NULL
);
461 dock
= clickedIcon
->dock
;
463 selectedIcons
= getSelected(dock
);
465 if (WMGetArrayItemCount(selectedIcons
)) {
466 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
467 _("All selected icons will be removed!"),
468 _("OK"), _("Cancel"), NULL
) != WAPRDefault
) {
469 WMFreeArray(selectedIcons
);
473 if (clickedIcon
->xindex
== 0 && clickedIcon
->yindex
== 0) {
474 WMFreeArray(selectedIcons
);
477 WMAddToArray(selectedIcons
, clickedIcon
);
480 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
481 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
482 wDockDetach(dock
, aicon
);
484 /* XXX: can: aicon->icon == NULL ? */
485 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
486 wGetHeadForWindow(aicon
->icon
->owner
));
487 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
488 if (!dock
->mapped
|| dock
->collapsed
)
489 XMapWindow(dpy
, aicon
->icon
->core
->window
);
492 WMFreeArray(selectedIcons
);
494 if (wPreferences
.auto_arrange_icons
)
495 wArrangeIcons(dock
->screen_ptr
, True
);
498 static void keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
500 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
503 WMArray
*selectedIcons
;
506 assert(clickedIcon
!= NULL
);
507 dock
= clickedIcon
->dock
;
509 selectedIcons
= getSelected(dock
);
511 if (!WMGetArrayItemCount(selectedIcons
)
512 && clickedIcon
!= dock
->screen_ptr
->clip_icon
) {
513 char *command
= NULL
;
515 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
516 clickedIcon
->editing
= 1;
517 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
518 _("Type the command used to launch the application"), &command
)) {
519 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
523 clickedIcon
->command
= command
;
524 clickedIcon
->editing
= 0;
526 clickedIcon
->editing
= 0;
529 WMFreeArray(selectedIcons
);
534 WMAddToArray(selectedIcons
, clickedIcon
);
537 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
538 if (aicon
->icon
->selected
)
539 wIconSelect(aicon
->icon
);
540 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
541 aicon
->attracted
= 0;
542 if (aicon
->icon
->shadowed
) {
543 aicon
->icon
->shadowed
= 0;
544 aicon
->icon
->force_paint
= 1;
545 wAppIconPaint(aicon
);
548 save_appicon(aicon
, True
);
550 WMFreeArray(selectedIcons
);
553 static void toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
555 WDock
*dock
= (WDock
*) entry
->clientdata
;
557 assert(entry
->clientdata
!= NULL
);
559 dock
->attract_icons
= !dock
->attract_icons
;
560 /*if (!dock->attract_icons)
561 dock->keep_attracted = 0; */
563 entry
->flags
.indicator_on
= dock
->attract_icons
;
568 static void selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
570 WAppIcon
*icon
= (WAppIcon
*) entry
->clientdata
;
572 assert(icon
!= NULL
);
574 wIconSelect(icon
->icon
);
579 static void colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
581 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
584 int x
, y
, x_pos
, y_pos
;
586 assert(entry
->clientdata
!= NULL
);
587 clip
= clickedIcon
->dock
;
589 aicon
= clip
->screen_ptr
->app_icon_list
;
592 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
593 x_pos
= clip
->x_pos
+ x
* ICON_SIZE
;
594 y_pos
= clip
->y_pos
+ y
* ICON_SIZE
;
595 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
597 if (wPreferences
.no_animations
) {
598 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
600 SlideWindow(aicon
->icon
->core
->window
,
601 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
604 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
605 #endif /* ANIMATIONS */
607 aicon
->attracted
= 1;
608 if (!aicon
->icon
->shadowed
) {
609 aicon
->icon
->shadowed
= 1;
610 aicon
->icon
->force_paint
= 1;
611 /* We don't do an wAppIconPaint() here because it's in
612 * wDockAttachIcon(). -Dan
615 wDockAttachIcon(clip
, aicon
, x
, y
);
616 if (clip
->collapsed
|| !clip
->mapped
)
617 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
623 static void selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
625 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
627 WMArray
*selectedIcons
;
628 WMArrayIterator iter
;
632 assert(clickedIcon
!= NULL
);
633 dock
= clickedIcon
->dock
;
635 selectedIcons
= getSelected(dock
);
637 if (!WMGetArrayItemCount(selectedIcons
)) {
638 for (i
= 1; i
< dock
->max_icons
; i
++) {
639 btn
= dock
->icon_array
[i
];
640 if (btn
&& !btn
->icon
->selected
) {
641 wIconSelect(btn
->icon
);
645 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
646 wIconSelect(btn
->icon
);
649 WMFreeArray(selectedIcons
);
654 static void toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
656 assert(entry
->clientdata
!= NULL
);
658 toggleCollapsed(entry
->clientdata
);
660 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->collapsed
;
665 static void toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
668 assert(entry
->clientdata
!= NULL
);
670 dock
= (WDock
*) entry
->clientdata
;
672 dock
->auto_collapse
= !dock
->auto_collapse
;
674 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_collapse
;
679 static void toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
682 assert(entry
->clientdata
!= NULL
);
684 dock
= (WDock
*) entry
->clientdata
;
686 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
688 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_raise_lower
;
693 static void launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
695 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
697 launchDockedApplication(btn
, False
);
700 static void settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
702 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
706 ShowDockAppSettingsPanel(btn
);
709 static void hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
712 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
714 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
716 if (wapp
->flags
.hidden
) {
717 wWorkspaceChange(btn
->icon
->core
->screen_ptr
, wapp
->last_workspace
);
718 wUnhideApplication(wapp
, False
, False
);
720 wHideApplication(wapp
);
724 static void unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
727 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
729 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
731 wUnhideApplication(wapp
, False
, True
);
734 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
)
739 if (type
== WM_CLIP
) {
741 return scr
->clip_icon
;
742 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
743 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
744 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
745 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
746 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE; */
749 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
750 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
756 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
757 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
758 btn
->icon
->core
->descriptor
.parent
= btn
;
759 /*ChangeStackingLevel(btn->icon->core, WMDockLevel); */
760 XMapWindow(dpy
, btn
->icon
->core
->window
);
765 scr
->clip_icon
= btn
;
770 static void switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
772 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
773 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
775 WMArray
*selectedIcons
;
778 if (entry
->order
== scr
->current_workspace
)
781 dest
= scr
->workspaces
[entry
->order
]->clip
;
783 selectedIcons
= getSelected(src
);
785 if (WMGetArrayItemCount(selectedIcons
)) {
786 WMArrayIterator iter
;
788 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
789 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
790 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
791 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
794 } else if (icon
!= scr
->clip_icon
) {
795 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
796 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
797 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
800 WMFreeArray(selectedIcons
);
803 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
)
805 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
807 if (!btn
->launching
&&
808 ((!withSelection
&& btn
->command
!= NULL
) || (withSelection
&& btn
->paste_command
!= NULL
))) {
809 if (!btn
->forced_dock
) {
810 btn
->relaunching
= btn
->running
;
813 if (btn
->wm_instance
|| btn
->wm_class
) {
814 WWindowAttributes attr
;
815 memset(&attr
, 0, sizeof(WWindowAttributes
));
816 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
818 if (!attr
.no_appicon
&& !btn
->buggy_app
)
823 btn
->drop_launch
= 0;
824 btn
->paste_launch
= withSelection
;
825 scr
->last_dock
= btn
->dock
;
826 btn
->pid
= execCommand(btn
, (withSelection
? btn
->paste_command
: btn
->command
), NULL
);
828 if (btn
->buggy_app
) {
829 /* give feedback that the app was launched */
833 WMAddTimerHandler(200, (WMCallback
*) dockIconPaint
, btn
);
838 wwarning(_("could not launch application %s"), btn
->command
);
840 if (!btn
->relaunching
) {
847 static void updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
849 WScreen
*scr
= menu
->frame
->screen_ptr
;
850 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
856 for (i
= 0; i
< scr
->workspace_count
; i
++) {
857 if (i
< menu
->entry_no
) {
858 if (strcmp(menu
->entries
[i
]->text
, scr
->workspaces
[i
]->name
) != 0) {
859 wfree(menu
->entries
[i
]->text
);
860 strcpy(title
, scr
->workspaces
[i
]->name
);
861 menu
->entries
[i
]->text
= wstrdup(title
);
862 menu
->flags
.realized
= 0;
864 menu
->entries
[i
]->clientdata
= (void *)icon
;
866 strcpy(title
, scr
->workspaces
[i
]->name
);
868 wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)icon
);
870 menu
->flags
.realized
= 0;
872 if (i
== scr
->current_workspace
) {
873 wMenuSetEnabled(menu
, i
, False
);
875 wMenuSetEnabled(menu
, i
, True
);
879 if (!menu
->flags
.realized
)
883 static WMenu
*makeWorkspaceMenu(WScreen
*scr
)
887 menu
= wMenuCreate(scr
, NULL
, False
);
889 wwarning(_("could not create workspace submenu for Clip menu"));
891 wMenuAddCallback(menu
, "", switchWSCommand
, (void *)scr
->clip_icon
);
893 menu
->flags
.realized
= 0;
899 static void updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
908 entry
= menu
->entries
[index
];
909 entry
->flags
.indicator_on
= !dock
->lowered
;
910 entry
->clientdata
= dock
;
913 entry
= menu
->entries
[++index
];
914 entry
->flags
.indicator_on
= dock
->collapsed
;
915 entry
->clientdata
= dock
;
918 entry
= menu
->entries
[++index
];
919 entry
->flags
.indicator_on
= dock
->auto_collapse
;
920 entry
->clientdata
= dock
;
922 /* auto-raise/lower */
923 entry
= menu
->entries
[++index
];
924 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
925 entry
->clientdata
= dock
;
926 wMenuSetEnabled(menu
, index
, dock
->lowered
);
929 entry
= menu
->entries
[++index
];
930 entry
->flags
.indicator_on
= dock
->attract_icons
;
931 entry
->clientdata
= dock
;
933 menu
->flags
.realized
= 0;
937 static WMenu
*makeClipOptionsMenu(WScreen
*scr
)
942 menu
= wMenuCreate(scr
, NULL
, False
);
944 wwarning(_("could not create options submenu for Clip menu"));
948 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
949 entry
->flags
.indicator
= 1;
950 entry
->flags
.indicator_on
= 1;
951 entry
->flags
.indicator_type
= MI_CHECK
;
953 entry
= wMenuAddCallback(menu
, _("Collapsed"), toggleCollapsedCallback
, NULL
);
954 entry
->flags
.indicator
= 1;
955 entry
->flags
.indicator_on
= 1;
956 entry
->flags
.indicator_type
= MI_CHECK
;
958 entry
= wMenuAddCallback(menu
, _("Autocollapse"), toggleAutoCollapseCallback
, NULL
);
959 entry
->flags
.indicator
= 1;
960 entry
->flags
.indicator_on
= 1;
961 entry
->flags
.indicator_type
= MI_CHECK
;
963 entry
= wMenuAddCallback(menu
, _("Autoraise"), toggleAutoRaiseLowerCallback
, NULL
);
964 entry
->flags
.indicator
= 1;
965 entry
->flags
.indicator_on
= 1;
966 entry
->flags
.indicator_type
= MI_CHECK
;
968 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"), toggleAutoAttractCallback
, NULL
);
969 entry
->flags
.indicator
= 1;
970 entry
->flags
.indicator_on
= 1;
971 entry
->flags
.indicator_type
= MI_CHECK
;
973 menu
->flags
.realized
= 0;
979 static WMenu
*dockMenuCreate(WScreen
*scr
, int type
)
984 if (type
== WM_CLIP
&& scr
->clip_menu
)
985 return scr
->clip_menu
;
987 menu
= wMenuCreate(scr
, NULL
, False
);
988 if (type
!= WM_CLIP
) {
989 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
990 entry
->flags
.indicator
= 1;
991 entry
->flags
.indicator_on
= 1;
992 entry
->flags
.indicator_type
= MI_CHECK
;
994 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
995 scr
->clip_options
= makeClipOptionsMenu(scr
);
996 if (scr
->clip_options
)
997 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
999 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1001 entry
->text
= _("Rename Workspace");
1003 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1004 entry
->flags
.indicator
= 1;
1005 entry
->flags
.indicator_on
= 1;
1006 entry
->flags
.indicator_type
= MI_CHECK
;
1008 entry
= wMenuAddCallback(menu
, _("Select All Icons"), selectIconsCallback
, NULL
);
1010 entry
->text
= _("Select All Icons");
1012 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1014 entry
->text
= _("Keep Icon");
1016 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1018 entry
->text
= _("Move Icon To");
1019 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1020 if (scr
->clip_submenu
)
1021 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1023 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
, NULL
);
1025 entry
->text
= _("Remove Icon");
1027 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1030 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1032 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1034 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1036 entry
->text
= _("Hide");
1038 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1040 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1042 if (type
== WM_CLIP
)
1043 scr
->clip_menu
= menu
;
1048 WDock
*wDockCreate(WScreen
*scr
, int type
)
1055 dock
= wmalloc(sizeof(WDock
));
1057 dock
->max_icons
= DOCK_MAX_ICONS
;
1059 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * dock
->max_icons
);
1061 btn
= mainIconCreate(scr
, type
);
1065 dock
->x_pos
= btn
->x_pos
;
1066 dock
->y_pos
= btn
->y_pos
;
1067 dock
->screen_ptr
= scr
;
1069 dock
->icon_count
= 1;
1070 dock
->on_right_side
= 1;
1071 dock
->collapsed
= 0;
1072 dock
->auto_collapse
= 0;
1073 dock
->auto_collapse_magic
= NULL
;
1074 dock
->auto_raise_lower
= 0;
1075 dock
->auto_lower_magic
= NULL
;
1076 dock
->auto_raise_magic
= NULL
;
1077 dock
->attract_icons
= 0;
1079 dock
->icon_array
[0] = btn
;
1080 wRaiseFrame(btn
->icon
->core
);
1081 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1083 /* create dock menu */
1084 dock
->menu
= dockMenuCreate(scr
, type
);
1089 void wDockDestroy(WDock
*dock
)
1094 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1095 aicon
= dock
->icon_array
[i
];
1097 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1098 wDockDetach(dock
, aicon
);
1100 /* XXX: can: aicon->icon == NULL ? */
1101 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1102 wGetHeadForWindow(aicon
->icon
->owner
));
1103 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1104 if (!dock
->mapped
|| dock
->collapsed
)
1105 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1109 if (wPreferences
.auto_arrange_icons
)
1110 wArrangeIcons(dock
->screen_ptr
, True
);
1111 wfree(dock
->icon_array
);
1112 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1113 wMenuDestroy(dock
->menu
, True
);
1114 if (dock
->screen_ptr
->last_dock
== dock
)
1115 dock
->screen_ptr
->last_dock
= NULL
;
1119 void wClipIconPaint(WAppIcon
*aicon
)
1121 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1122 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1124 Window win
= aicon
->icon
->core
->window
;
1125 int length
, nlength
;
1126 char *ws_name
, ws_number
[10];
1129 wIconPaint(aicon
->icon
);
1131 length
= strlen(workspace
->name
);
1132 ws_name
= wmalloc(length
+ 1);
1133 snprintf(ws_name
, length
+ 1, "%s", workspace
->name
);
1134 snprintf(ws_number
, sizeof(ws_number
), "%i", scr
->current_workspace
+ 1);
1135 nlength
= strlen(ws_number
);
1137 if (!workspace
->clip
->collapsed
)
1138 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1140 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1142 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1144 tx
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
1146 if(wPreferences
.show_clip_title
)
1147 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, ty
, ws_name
, length
);
1149 tx
= (ICON_SIZE
/ 2 - WMWidthOfString(scr
->clip_title_font
, ws_number
, nlength
)) / 2;
1151 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, 2, ws_number
, nlength
);
1155 if (aicon
->launching
) {
1156 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1157 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1159 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
, aicon
->dock
->rclip_button_pushed
);
1162 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1164 wClipIconPaint(desc
->parent
);
1167 static void dockIconPaint(WAppIcon
*btn
)
1169 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1170 wClipIconPaint(btn
);
1173 save_appicon(btn
, True
);
1177 static WMPropList
*make_icon_state(WAppIcon
*btn
)
1179 WMPropList
*node
= NULL
;
1180 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
;
1181 WMPropList
*position
, *buggy
, *omnipresent
;
1187 command
= WMCreatePLString("-");
1189 command
= WMCreatePLString(btn
->command
);
1191 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1193 lock
= btn
->lock
? dYes
: dNo
;
1195 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1197 name
= WMCreatePLString(tmp
);
1201 forced
= btn
->forced_dock
? dYes
: dNo
;
1203 buggy
= btn
->buggy_app
? dYes
: dNo
;
1205 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1206 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1208 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1209 position
= WMCreatePLString(buffer
);
1211 node
= WMCreatePLDictionary(dCommand
, command
,
1213 dAutoLaunch
, autolaunch
,
1215 dForced
, forced
, dBuggyApplication
, buggy
, dPosition
, position
, NULL
);
1216 WMReleasePropList(command
);
1217 WMReleasePropList(name
);
1218 WMReleasePropList(position
);
1220 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1221 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&& (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1222 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1224 #ifdef XDND /* was OFFIX */
1225 if (btn
->dnd_command
) {
1226 command
= WMCreatePLString(btn
->dnd_command
);
1227 WMPutInPLDictionary(node
, dDropCommand
, command
);
1228 WMReleasePropList(command
);
1232 if (btn
->paste_command
) {
1233 command
= WMCreatePLString(btn
->paste_command
);
1234 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1235 WMReleasePropList(command
);
1242 static WMPropList
*dockSaveState(WDock
*dock
)
1245 WMPropList
*icon_info
;
1246 WMPropList
*list
= NULL
, *dock_state
= NULL
;
1247 WMPropList
*value
, *key
;
1250 list
= WMCreatePLArray(NULL
);
1252 for (i
= (dock
->type
== WM_DOCK
? 0 : 1); i
< dock
->max_icons
; i
++) {
1253 WAppIcon
*btn
= dock
->icon_array
[i
];
1255 if (!btn
|| btn
->attracted
)
1258 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1259 WMAddToPLArray(list
, icon_info
);
1260 WMReleasePropList(icon_info
);
1264 dock_state
= WMCreatePLDictionary(dApplications
, list
, NULL
);
1266 if (dock
->type
== WM_DOCK
) {
1267 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1268 key
= WMCreatePLString(buffer
);
1269 WMPutInPLDictionary(dock_state
, key
, list
);
1270 WMReleasePropList(key
);
1272 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0), dock
->y_pos
);
1273 value
= WMCreatePLString(buffer
);
1274 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1275 WMReleasePropList(value
);
1277 WMReleasePropList(list
);
1279 value
= (dock
->lowered
? dYes
: dNo
);
1280 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1282 if (dock
->type
== WM_CLIP
) {
1283 value
= (dock
->collapsed
? dYes
: dNo
);
1284 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1286 value
= (dock
->auto_collapse
? dYes
: dNo
);
1287 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1289 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1290 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1292 value
= (dock
->attract_icons
? dYes
: dNo
);
1293 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1299 void wDockSaveState(WScreen
*scr
, WMPropList
*old_state
)
1301 WMPropList
*dock_state
;
1304 dock_state
= dockSaveState(scr
->dock
);
1307 * Copy saved states of docks with different sizes.
1313 keys
= WMGetPLDictionaryKeys(old_state
);
1314 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1315 tmp
= WMGetFromPLArray(keys
, i
);
1317 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1318 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1320 WMPutInPLDictionary(dock_state
, tmp
, WMGetFromPLDictionary(old_state
, tmp
));
1323 WMReleasePropList(keys
);
1326 WMPutInPLDictionary(scr
->session_state
, dDock
, dock_state
);
1328 WMReleasePropList(dock_state
);
1331 void wClipSaveState(WScreen
*scr
)
1333 WMPropList
*clip_state
;
1335 clip_state
= make_icon_state(scr
->clip_icon
);
1337 WMPutInPLDictionary(scr
->session_state
, dClip
, clip_state
);
1339 WMReleasePropList(clip_state
);
1342 WMPropList
*wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1344 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1347 static Bool
getBooleanDockValue(WMPropList
*value
, WMPropList
*key
)
1350 if (WMIsPLString(value
)) {
1351 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1354 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1360 static WAppIcon
*restore_icon_state(WScreen
*scr
, WMPropList
*info
, int type
, int index
)
1363 WMPropList
*cmd
, *value
;
1365 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1366 if (!cmd
|| !WMIsPLString(cmd
)) {
1370 /* parse window name */
1371 value
= WMGetFromPLDictionary(info
, dName
);
1376 char *wclass
, *winstance
;
1379 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1381 if (!winstance
&& !wclass
) {
1388 command
= wstrdup(WMGetFromPLString(cmd
));
1392 if (!command
|| strcmp(command
, "-") == 0) {
1403 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1412 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1413 if (type
== WM_CLIP
) {
1414 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1415 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1417 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1418 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1420 #ifdef XDND /* was OFFIX */
1421 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1423 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1426 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1428 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1430 /* check auto launch */
1431 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1433 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1436 value
= WMGetFromPLDictionary(info
, dLock
);
1438 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1440 /* check if it wasn't normally docked */
1441 value
= WMGetFromPLDictionary(info
, dForced
);
1443 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1445 /* check if we can rely on the stuff in the app */
1446 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1448 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1450 /* get position in the dock */
1451 value
= WMGetFromPLDictionary(info
, dPosition
);
1452 if (value
&& WMIsPLString(value
)) {
1453 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1454 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1456 /* check position sanity */
1457 /* incomplete section! */
1458 if (type
== WM_DOCK
) {
1460 if (aicon
->yindex
< 0)
1461 wwarning(_("bad value in docked icon position %i,%i"),
1462 aicon
->xindex
, aicon
->yindex
);
1465 aicon
->yindex
= index
;
1469 /* check if icon is omnipresent */
1470 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1472 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1480 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1482 WAppIcon
*wClipRestoreState(WScreen
*scr
, WMPropList
*clip_state
)
1487 icon
= mainIconCreate(scr
, WM_CLIP
);
1492 WMRetainPropList(clip_state
);
1494 /* restore position */
1496 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1499 if (!WMIsPLString(value
))
1500 COMPLAIN("Position");
1505 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1506 COMPLAIN("Position");
1508 /* check position sanity */
1509 rect
.pos
.x
= icon
->x_pos
;
1510 rect
.pos
.y
= icon
->y_pos
;
1511 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1513 wGetRectPlacementInfo(scr
, rect
, &flags
);
1514 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
1515 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1518 #ifdef XDND /* was OFFIX */
1519 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1520 if (value
&& WMIsPLString(value
))
1521 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1524 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1525 if (value
&& WMIsPLString(value
))
1526 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1528 WMReleasePropList(clip_state
);
1533 WDock
*wDockRestoreState(WScreen
*scr
, WMPropList
*dock_state
, int type
)
1538 WAppIcon
*aicon
, *old_top
;
1541 dock
= wDockCreate(scr
, type
);
1546 WMRetainPropList(dock_state
);
1548 /* restore position */
1549 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1551 if (!WMIsPLString(value
)) {
1552 COMPLAIN("Position");
1557 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1558 COMPLAIN("Position");
1560 /* check position sanity */
1561 rect
.pos
.x
= dock
->x_pos
;
1562 rect
.pos
.y
= dock
->y_pos
;
1563 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1565 wGetRectPlacementInfo(scr
, rect
, &flags
);
1566 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
)) {
1567 int x
= dock
->x_pos
;
1568 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1571 /* Is this needed any more? */
1572 if (type
== WM_CLIP
) {
1573 if (dock
->x_pos
< 0) {
1575 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1576 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1579 if (dock
->x_pos
>= 0) {
1580 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1581 dock
->on_right_side
= 0;
1583 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1584 dock
->on_right_side
= 1;
1590 /* restore lowered/raised state */
1593 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1595 if (!WMIsPLString(value
)) {
1596 COMPLAIN("Lowered");
1598 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1604 /* restore collapsed state */
1605 dock
->collapsed
= 0;
1607 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1609 if (!WMIsPLString(value
)) {
1610 COMPLAIN("Collapsed");
1612 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1613 dock
->collapsed
= 1;
1618 /* restore auto-collapsed state */
1619 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1621 if (!WMIsPLString(value
)) {
1622 COMPLAIN("AutoCollapse");
1624 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1625 dock
->auto_collapse
= 1;
1626 dock
->collapsed
= 1;
1631 /* restore auto-raise/lower state */
1632 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1634 if (!WMIsPLString(value
)) {
1635 COMPLAIN("AutoRaiseLower");
1637 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1638 dock
->auto_raise_lower
= 1;
1642 /* restore attract icons state */
1643 dock
->attract_icons
= 0;
1645 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1647 if (!WMIsPLString(value
)) {
1648 COMPLAIN("AutoAttractIcons");
1650 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1651 dock
->attract_icons
= 1;
1655 /* application list */
1662 * When saving, it saves the dock state in
1663 * Applications and Applicationsnnn
1665 * When loading, it will first try Applicationsnnn.
1666 * If it does not exist, use Applications as default.
1669 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1671 tmp
= WMCreatePLString(buffer
);
1672 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1673 WMReleasePropList(tmp
);
1676 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1682 count
= WMGetPropListItemCount(apps
);
1686 old_top
= dock
->icon_array
[0];
1688 /* dock->icon_count is set to 1 when dock is created.
1689 * Since Clip is already restored, we want to keep it so for clip,
1690 * but for dock we may change the default top tile, so we set it to 0.
1692 if (type
== WM_DOCK
)
1693 dock
->icon_count
= 0;
1695 for (i
= 0; i
< count
; i
++) {
1696 if (dock
->icon_count
>= dock
->max_icons
) {
1697 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1701 value
= WMGetFromPLArray(apps
, i
);
1702 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1704 dock
->icon_array
[dock
->icon_count
] = aicon
;
1708 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1709 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1712 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1714 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1716 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1718 if (!dock
->collapsed
)
1719 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1720 wRaiseFrame(aicon
->icon
->core
);
1723 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
)
1727 /* if the first icon is not defined, use the default */
1728 if (dock
->icon_array
[0] == NULL
) {
1729 /* update default icon */
1730 old_top
->x_pos
= dock
->x_pos
;
1731 old_top
->y_pos
= dock
->y_pos
;
1733 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1735 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1736 dock
->icon_array
[0] = old_top
;
1737 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1738 /* we don't need to increment dock->icon_count here because it was
1739 * incremented in the loop above.
1741 } else if (old_top
!= dock
->icon_array
[0]) {
1742 if (old_top
== scr
->clip_icon
)
1743 scr
->clip_icon
= dock
->icon_array
[0];
1744 wAppIconDestroy(old_top
);
1748 WMReleasePropList(dock_state
);
1753 void wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1755 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1757 btn
->drop_launch
= 0;
1758 btn
->paste_launch
= 0;
1760 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1763 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1773 void wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1779 for (i
= 0; i
< dock
->max_icons
; i
++) {
1780 btn
= dock
->icon_array
[i
];
1781 if (!btn
|| !btn
->auto_launch
)
1784 state
= wmalloc(sizeof(WSavedState
));
1785 state
->workspace
= workspace
;
1786 /* TODO: this is klugy and is very difficult to understand
1787 * what's going on. Try to clean up */
1788 wDockLaunchWithState(dock
, btn
, state
);
1792 #ifdef XDND /* was OFFIX */
1793 static WDock
*findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1799 if ((dock
= scr
->dock
) != NULL
) {
1800 for (i
= 0; i
< dock
->max_icons
; i
++) {
1801 if (dock
->icon_array
[i
]
1802 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1808 if (*icon_pos
< 0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
) != NULL
) {
1809 for (i
= 0; i
< dock
->max_icons
; i
++) {
1810 if (dock
->icon_array
[i
]
1811 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1822 int wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
1828 dock
= findDock(scr
, event
, &icon_pos
);
1833 * Return True if the drop was on an application icon window.
1834 * In this case, let the ClientMessage handler redirect the
1835 * message to the app.
1837 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
1840 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
1841 scr
->flags
.dnd_data_convertion_status
= 0;
1843 btn
= dock
->icon_array
[icon_pos
];
1845 if (!btn
->forced_dock
) {
1846 btn
->relaunching
= btn
->running
;
1849 if (btn
->wm_instance
|| btn
->wm_class
) {
1850 WWindowAttributes attr
;
1851 memset(&attr
, 0, sizeof(WWindowAttributes
));
1852 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
1853 btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
1855 if (!attr
.no_appicon
)
1861 btn
->paste_launch
= 0;
1862 btn
->drop_launch
= 1;
1863 scr
->last_dock
= dock
;
1864 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1869 if (!btn
->relaunching
) {
1878 Bool
wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1883 wwin
= icon
->icon
->owner
;
1884 if (icon
->command
== NULL
) {
1889 command
= GetCommandForWindow(wwin
->client_win
);
1891 icon
->command
= command
;
1893 /* icon->forced_dock = 1; */
1894 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
1896 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
1897 _("Type the command used to launch the application"), &command
)) {
1898 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
1902 icon
->command
= command
;
1908 /* If the target is the dock, reject the icon. If
1909 * the target is the clip, make it an attracted icon
1911 if (dock
->type
== WM_CLIP
) {
1912 icon
->attracted
= 1;
1913 if (!icon
->icon
->shadowed
) {
1914 icon
->icon
->shadowed
= 1;
1915 icon
->icon
->force_paint
= 1;
1927 for (index
= 1; index
< dock
->max_icons
; index
++)
1928 if (dock
->icon_array
[index
] == NULL
)
1930 /* if (index == dock->max_icons)
1933 assert(index
< dock
->max_icons
);
1935 dock
->icon_array
[index
] = icon
;
1939 icon
->omnipresent
= 0;
1941 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
1942 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
1947 icon
->launching
= 0;
1950 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1951 if (dock
->type
== WM_CLIP
) {
1952 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1953 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1955 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1956 icon
->icon
->core
->descriptor
.parent
= icon
;
1958 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
1959 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
1960 wAppIconPaint(icon
);
1961 save_appicon(icon
, True
);
1963 if (wPreferences
.auto_arrange_icons
)
1964 wArrangeIcons(dock
->screen_ptr
, True
);
1966 #ifdef XDND /* was OFFIX */
1967 if (icon
->command
&& !icon
->dnd_command
) {
1968 int len
= strlen(icon
->command
) + 8;
1969 icon
->dnd_command
= wmalloc(len
);
1970 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
1974 if (icon
->command
&& !icon
->paste_command
) {
1975 int len
= strlen(icon
->command
) + 8;
1976 icon
->paste_command
= wmalloc(len
);
1977 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
1983 static void reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1987 for (index
= 1; index
< dock
->max_icons
; index
++) {
1988 if (dock
->icon_array
[index
] == icon
)
1991 assert(index
< dock
->max_icons
);
1996 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
1997 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2000 static Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2007 return True
; /* No move needed, we're already there */
2012 wwin
= icon
->icon
->owner
;
2015 * For the moment we can't do this if we move icons in Clip from one
2016 * workspace to other, because if we move two or more icons without
2017 * command, the dialog box will not be able to tell us to which of the
2018 * moved icons it applies. -Dan
2020 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
2021 command
= GetCommandForWindow(wwin
->client_win
);
2023 icon
->command
= command
;
2026 /* icon->forced_dock = 1; */
2027 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2028 _("Type the command used to launch the application"), &command
)) {
2029 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2033 icon
->command
= command
;
2044 if (dest
->type
== WM_DOCK
)
2045 wClipMakeIconOmnipresent(icon
, False
);
2047 for (index
= 1; index
< src
->max_icons
; index
++) {
2048 if (src
->icon_array
[index
] == icon
)
2051 assert(index
< src
->max_icons
);
2053 src
->icon_array
[index
] = NULL
;
2056 for (index
= 1; index
< dest
->max_icons
; index
++) {
2057 if (dest
->icon_array
[index
] == NULL
)
2060 /* if (index == dest->max_icons)
2063 assert(index
< dest
->max_icons
);
2065 dest
->icon_array
[index
] = icon
;
2068 /* deselect the icon */
2069 if (icon
->icon
->selected
)
2070 wIconSelect(icon
->icon
);
2072 if (dest
->type
== WM_DOCK
) {
2073 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2074 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2076 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2077 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2080 /* set it to be kept when moving to dock.
2081 * Unless the icon does not have a command set
2083 if (icon
->command
&& dest
->type
== WM_DOCK
) {
2084 icon
->attracted
= 0;
2085 if (icon
->icon
->shadowed
) {
2086 icon
->icon
->shadowed
= 0;
2087 icon
->icon
->force_paint
= 1;
2089 save_appicon(icon
, True
);
2092 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2098 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2099 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2103 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2104 wAppIconPaint(icon
);
2109 void wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2113 /* make the settings panel be closed */
2115 DestroyDockAppSettingsPanel(icon
->panel
);
2118 /* This must be called before icon->dock is set to NULL.
2119 * Don't move it. -Dan
2121 wClipMakeIconOmnipresent(icon
, False
);
2125 icon
->attracted
= 0;
2126 icon
->auto_launch
= 0;
2127 if (icon
->icon
->shadowed
) {
2128 icon
->icon
->shadowed
= 0;
2129 icon
->icon
->force_paint
= 1;
2132 /* deselect the icon */
2133 if (icon
->icon
->selected
)
2134 wIconSelect(icon
->icon
);
2136 if (icon
->command
) {
2137 wfree(icon
->command
);
2138 icon
->command
= NULL
;
2140 #ifdef XDND /* was OFFIX */
2141 if (icon
->dnd_command
) {
2142 wfree(icon
->dnd_command
);
2143 icon
->dnd_command
= NULL
;
2146 if (icon
->paste_command
) {
2147 wfree(icon
->paste_command
);
2148 icon
->paste_command
= NULL
;
2151 for (index
= 1; index
< dock
->max_icons
; index
++)
2152 if (dock
->icon_array
[index
] == icon
)
2154 assert(index
< dock
->max_icons
);
2155 dock
->icon_array
[index
] = NULL
;
2161 /* if the dock is not attached to an application or
2162 * the application did not set the appropriate hints yet,
2163 * destroy the icon */
2164 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2165 wAppIconDestroy(icon
);
2167 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2168 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2169 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2170 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2171 icon
->icon
->core
->descriptor
.parent
= icon
;
2173 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2175 wAppIconPaint(icon
);
2176 if (wPreferences
.auto_arrange_icons
) {
2177 wArrangeIcons(dock
->screen_ptr
, True
);
2180 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2185 * returns the closest Dock slot index for the passed
2188 * Returns False if icon can't be docked.
2190 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2193 Bool
wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2195 WScreen
*scr
= dock
->screen_ptr
;
2198 int i
, offset
= ICON_SIZE
/ 2;
2199 WAppIcon
*aicon
= NULL
;
2200 WAppIcon
*nicon
= NULL
;
2203 /* TODO: XINERAMA, for these */
2204 max_y_icons
= scr
->scr_height
/ ICON_SIZE
- 1;
2206 if (wPreferences
.flags
.noupdates
)
2212 /* if the dock is full */
2213 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
)) {
2217 /* exact position */
2219 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2221 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2224 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2226 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2228 /* check if the icon is outside the screen boundaries */
2233 rect
.pos
.x
= dx
+ ex_x
* ICON_SIZE
;
2234 rect
.pos
.y
= dy
+ ex_y
* ICON_SIZE
;
2235 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2237 wGetRectPlacementInfo(scr
, rect
, &flags
);
2238 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
2242 if (dock
->type
== WM_DOCK
) {
2243 if (icon
->dock
!= dock
&& ex_x
!= 0)
2247 for (i
= 0; i
< dock
->max_icons
; i
++) {
2248 nicon
= dock
->icon_array
[i
];
2249 if (nicon
&& nicon
->yindex
== ex_y
) {
2256 int sig
, done
, closest
;
2258 /* Possible cases when redocking:
2260 * icon dragged out of range of any slot -> false
2261 * icon dragged to range of free slot
2262 * icon dragged to range of same slot
2263 * icon dragged to range of different icon
2265 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2268 if (ex_y
>= 0 && ex_y
<= max_y_icons
&& (aicon
== icon
|| !aicon
)) {
2274 /* start looking at the upper slot or lower? */
2275 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2282 /* look for closest free slot */
2283 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2287 closest
= sig
* (i
/ 2) + ex_y
;
2288 /* check if this slot is used */
2290 for (j
= 0; j
< dock
->max_icons
; j
++) {
2291 if (dock
->icon_array
[j
]
2292 && dock
->icon_array
[j
]->yindex
== closest
) {
2293 /* slot is used by someone else */
2294 if (dock
->icon_array
[j
] != icon
)
2302 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2303 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2304 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2309 } else { /* !redocking */
2311 /* if slot is free and the icon is close enough, return it */
2312 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2322 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2323 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+ 1;
2326 for (k
= start
; k
< stop
; k
++) {
2327 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2330 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2331 nicon
= tmp
->icon_array
[i
];
2332 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2340 for (k
= start
; k
< stop
; k
++) {
2341 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2344 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2345 nicon
= tmp
->icon_array
[i
];
2346 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2347 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2348 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2357 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2366 static int onScreen(WScreen
*scr
, int x
, int y
, int sx
, int ex
, int sy
, int ey
)
2368 WMRect rect
= wmkrect(x
, y
, ICON_SIZE
, ICON_SIZE
);
2371 wGetRectPlacementInfo(scr
, rect
, &flags
);
2373 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2377 * returns true if it can find a free slot in the dock,
2378 * in which case it changes x_pos and y_pos accordingly.
2379 * Else returns false.
2381 Bool
wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2383 WScreen
*scr
= dock
->screen_ptr
;
2385 WAppIconChain
*chain
;
2386 unsigned char *slot_map
;
2390 int i
, done
= False
;
2392 int sx
= 0, sy
= 0, ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2393 int extra_count
= 0;
2395 if (dock
->type
== WM_CLIP
&& dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2396 extra_count
= scr
->global_icon_count
;
2398 /* if the dock is full */
2399 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
) {
2403 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2404 if (scr
->dock
->on_right_side
)
2405 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2407 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2410 if (ex
< dock
->x_pos
)
2412 if (sx
> dock
->x_pos
+ ICON_SIZE
)
2413 sx
= dock
->x_pos
+ ICON_SIZE
;
2420 /* check if clip is in a corner */
2421 if (dock
->type
== WM_CLIP
) {
2422 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2424 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2426 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2428 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2435 /* If the clip is in the corner, use only slots that are in the border
2437 if (corner
!= C_NONE
) {
2441 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2442 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2443 hmap
= wmalloc(hcount
+ 1);
2444 vmap
= wmalloc(vcount
+ 1);
2446 /* mark used positions */
2449 for (i
= 0; i
< dock
->max_icons
; i
++) {
2450 btn
= dock
->icon_array
[i
];
2454 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2455 vmap
[btn
->yindex
] = 1;
2456 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2457 hmap
[btn
->xindex
] = 1;
2459 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2461 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2462 vmap
[btn
->yindex
] = 1;
2463 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2464 hmap
[btn
->xindex
] = 1;
2468 for (i
= 0; i
< dock
->max_icons
; i
++) {
2469 btn
= dock
->icon_array
[i
];
2473 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2474 vmap
[btn
->yindex
] = 1;
2475 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2476 hmap
[-btn
->xindex
] = 1;
2478 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2480 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2481 vmap
[btn
->yindex
] = 1;
2482 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2483 hmap
[-btn
->xindex
] = 1;
2487 for (i
= 0; i
< dock
->max_icons
; i
++) {
2488 btn
= dock
->icon_array
[i
];
2492 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2493 vmap
[-btn
->yindex
] = 1;
2494 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2495 hmap
[btn
->xindex
] = 1;
2497 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2499 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2500 vmap
[-btn
->yindex
] = 1;
2501 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2502 hmap
[btn
->xindex
] = 1;
2507 for (i
= 0; i
< dock
->max_icons
; i
++) {
2508 btn
= dock
->icon_array
[i
];
2512 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2513 vmap
[-btn
->yindex
] = 1;
2514 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2515 hmap
[-btn
->xindex
] = 1;
2517 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2519 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2520 vmap
[-btn
->yindex
] = 1;
2521 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2522 hmap
[-btn
->xindex
] = 1;
2528 /* search a vacant slot */
2529 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2530 if (i
< vcount
&& vmap
[i
] == 0) {
2536 } else if (i
< hcount
&& hmap
[i
] == 0) {
2546 /* If found a slot, translate and return */
2548 if (corner
== C_NW
|| corner
== C_NE
) {
2553 if (corner
== C_NE
|| corner
== C_SE
) {
2560 /* else, try to find a slot somewhere else */
2563 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2564 * placed outside of screen */
2565 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2567 /* In the worst case (the clip is in the corner of the screen),
2568 * the amount of icons that fit in the clip is smaller.
2569 * Double the map to get a safe value.
2573 r
= (mwidth
- 1) / 2;
2575 slot_map
= wmalloc(mwidth
* mwidth
);
2577 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2579 /* mark used slots in the map. If the slot falls outside the map
2580 * (for example, when all icons are placed in line), ignore them. */
2581 for (i
= 0; i
< dock
->max_icons
; i
++) {
2582 btn
= dock
->icon_array
[i
];
2584 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2586 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2587 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2589 /* Find closest slot from the center that is free by scanning the
2590 * map from the center to outward in circular passes.
2591 * This will not result in a neat layout, but will be optimal
2592 * in the sense that there will not be holes left.
2595 for (i
= 1; i
<= r
&& !done
; i
++) {
2598 /* top and bottom parts of the ring */
2599 for (x
= -i
; x
<= i
&& !done
; x
++) {
2600 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2602 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2603 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2610 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2611 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2618 /* left and right parts of the ring */
2619 for (y
= -i
+ 1; y
<= i
- 1; y
++) {
2620 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2622 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2623 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2630 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2631 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2644 static void moveDock(WDock
*dock
, int new_x
, int new_y
)
2649 dock
->x_pos
= new_x
;
2650 dock
->y_pos
= new_y
;
2651 for (i
= 0; i
< dock
->max_icons
; i
++) {
2652 btn
= dock
->icon_array
[i
];
2654 btn
->x_pos
= new_x
+ btn
->xindex
* ICON_SIZE
;
2655 btn
->y_pos
= new_y
+ btn
->yindex
* ICON_SIZE
;
2656 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2661 static void swapDock(WDock
*dock
)
2663 WScreen
*scr
= dock
->screen_ptr
;
2667 if (dock
->on_right_side
) {
2668 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2670 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2673 for (i
= 0; i
< dock
->max_icons
; i
++) {
2674 btn
= dock
->icon_array
[i
];
2677 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2681 wScreenUpdateUsableArea(scr
);
2684 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2686 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2692 cmdline
= ExpandOptions(scr
, command
);
2694 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2702 wtokensplit(cmdline
, &argv
, &argc
);
2712 if ((pid
= fork()) == 0) {
2716 SetupEnvironment(scr
);
2722 args
= malloc(sizeof(char *) * (argc
+ 1));
2725 for (i
= 0; i
< argc
; i
++) {
2729 execvp(argv
[0], args
);
2732 wtokenfree(argv
, argc
);
2736 state
= wmalloc(sizeof(WSavedState
));
2738 state
->miniaturized
= -1;
2740 if (btn
->dock
== scr
->dock
|| btn
->omnipresent
)
2741 state
->workspace
= -1;
2743 state
->workspace
= scr
->current_workspace
;
2745 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
2746 wAddDeathHandler(pid
, (WDeathHandler
*) trackDeadProcess
, btn
->dock
);
2754 void wDockHideIcons(WDock
*dock
)
2761 for (i
= 1; i
< dock
->max_icons
; i
++) {
2762 if (dock
->icon_array
[i
])
2763 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2767 dockIconPaint(dock
->icon_array
[0]);
2770 void wDockShowIcons(WDock
*dock
)
2778 btn
= dock
->icon_array
[0];
2779 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2781 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2782 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2784 for (i
= 1; i
< dock
->max_icons
; i
++) {
2785 if (dock
->icon_array
[i
]) {
2786 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
, btn
->icon
->core
);
2791 if (!dock
->collapsed
) {
2792 for (i
= 1; i
< dock
->max_icons
; i
++) {
2793 if (dock
->icon_array
[i
]) {
2794 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2803 void wDockLower(WDock
*dock
)
2807 for (i
= 0; i
< dock
->max_icons
; i
++) {
2808 if (dock
->icon_array
[i
])
2809 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2813 void wDockRaise(WDock
*dock
)
2817 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
2818 if (dock
->icon_array
[i
])
2819 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2823 void wDockRaiseLower(WDock
*dock
)
2825 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2826 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2827 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2833 void wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
2835 icon
->launching
= 0;
2836 icon
->relaunching
= 0;
2837 dockIconPaint(icon
);
2840 WAppIcon
*wDockFindIconForWindow(WDock
*dock
, Window window
)
2845 for (i
= 0; i
< dock
->max_icons
; i
++) {
2846 icon
= dock
->icon_array
[i
];
2847 if (icon
&& icon
->main_window
== window
)
2853 void wDockTrackWindowLaunch(WDock
*dock
, Window window
)
2856 char *wm_class
, *wm_instance
;
2858 Bool firstPass
= True
;
2860 char *command
= NULL
;
2862 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) || (!wm_class
&& !wm_instance
)) {
2866 command
= GetCommandForWindow(window
);
2868 for (i
= 0; i
< dock
->max_icons
; i
++) {
2869 icon
= dock
->icon_array
[i
];
2873 /* app is already attached to icon */
2874 if (icon
->main_window
== window
) {
2879 if ((icon
->wm_instance
|| icon
->wm_class
)
2880 && (icon
->launching
|| !icon
->running
)) {
2882 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0) {
2885 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0) {
2888 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0) {
2892 if (!icon
->relaunching
) {
2895 /* Possibly an application that was docked with dockit,
2896 * but the user did not update WMState to indicate that
2897 * it was docked by force */
2898 wapp
= wApplicationOf(window
);
2900 icon
->forced_dock
= 1;
2903 if (!icon
->forced_dock
) {
2904 icon
->main_window
= window
;
2908 if (!wPreferences
.no_animations
&& !icon
->launching
&&
2909 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
2913 icon
->launching
= 1;
2914 dockIconPaint(icon
);
2916 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
2917 wm_instance
, wm_class
, TILE_NORMAL
);
2918 /* XXX: can: aicon->icon == NULL ? */
2919 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
2920 wAppIconMove(aicon
, x0
, y0
);
2921 /* Should this always be lowered? -Dan */
2923 wLowerFrame(aicon
->icon
->core
);
2924 XMapWindow(dpy
, aicon
->icon
->core
->window
);
2925 aicon
->launching
= 1;
2926 wAppIconPaint(aicon
);
2927 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
2928 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
2929 wAppIconDestroy(aicon
);
2931 wDockFinishLaunch(dock
, icon
);
2936 if (firstPass
&& !found
) {
2950 void wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
2952 if (!wPreferences
.flags
.noclip
) {
2953 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
2954 if (scr
->current_workspace
!= workspace
) {
2955 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
2956 WAppIconChain
*chain
= scr
->global_icons
;
2959 moveIconBetweenDocks(chain
->aicon
->dock
,
2960 scr
->workspaces
[workspace
]->clip
,
2961 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
2962 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
2963 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
2964 chain
= chain
->next
;
2967 wDockHideIcons(old_clip
);
2968 if (old_clip
->auto_raise_lower
) {
2969 if (old_clip
->auto_raise_magic
) {
2970 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
2971 old_clip
->auto_raise_magic
= NULL
;
2973 wDockLower(old_clip
);
2975 if (old_clip
->auto_collapse
) {
2976 if (old_clip
->auto_expand_magic
) {
2977 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
2978 old_clip
->auto_expand_magic
= NULL
;
2980 old_clip
->collapsed
= 1;
2982 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
2987 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
2992 for (i
= 0; i
< dock
->max_icons
; i
++) {
2993 icon
= dock
->icon_array
[i
];
2997 if (icon
->launching
&& icon
->pid
== pid
) {
2998 if (!icon
->relaunching
) {
3000 icon
->main_window
= None
;
3002 wDockFinishLaunch(dock
, icon
);
3004 if (status
== 111) {
3009 if (icon
->drop_launch
)
3010 cmd
= icon
->dnd_command
;
3013 if (icon
->paste_launch
)
3014 cmd
= icon
->paste_command
;
3016 cmd
= icon
->command
;
3018 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3020 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3027 static void toggleLowered(WDock
*dock
)
3032 /* lower/raise Dock */
3033 if (!dock
->lowered
) {
3034 newlevel
= WMNormalLevel
;
3037 newlevel
= WMDockLevel
;
3041 for (i
= 0; i
< dock
->max_icons
; i
++) {
3042 tmp
= dock
->icon_array
[i
];
3046 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3048 wLowerFrame(tmp
->icon
->core
);
3051 if (dock
->type
== WM_DOCK
)
3052 wScreenUpdateUsableArea(dock
->screen_ptr
);
3055 static void toggleCollapsed(WDock
*dock
)
3057 if (dock
->collapsed
) {
3058 dock
->collapsed
= 0;
3059 wDockShowIcons(dock
);
3061 dock
->collapsed
= 1;
3062 wDockHideIcons(dock
);
3066 static void openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3068 WScreen
*scr
= dock
->screen_ptr
;
3069 WObjDescriptor
*desc
;
3071 WApplication
*wapp
= NULL
;
3075 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3077 if (dock
->type
== WM_DOCK
) {
3079 entry
= dock
->menu
->entries
[index
];
3080 entry
->flags
.indicator_on
= !dock
->lowered
;
3081 entry
->clientdata
= dock
;
3082 dock
->menu
->flags
.realized
= 0;
3085 if (scr
->clip_options
)
3086 updateClipOptionsMenu(scr
->clip_options
, dock
);
3088 n_selected
= numberOfSelectedIcons(dock
);
3090 /* Rename Workspace */
3091 entry
= dock
->menu
->entries
[++index
];
3092 if (aicon
== scr
->clip_icon
) {
3093 entry
->callback
= renameCallback
;
3094 entry
->clientdata
= dock
;
3095 entry
->flags
.indicator
= 0;
3096 entry
->text
= _("Rename Workspace");
3098 entry
->callback
= omnipresentCallback
;
3099 entry
->clientdata
= aicon
;
3100 if (n_selected
> 0) {
3101 entry
->flags
.indicator
= 0;
3102 entry
->text
= _("Toggle Omnipresent");
3104 entry
->flags
.indicator
= 1;
3105 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3106 entry
->flags
.indicator_type
= MI_CHECK
;
3107 entry
->text
= _("Omnipresent");
3111 /* select/unselect icon */
3112 entry
= dock
->menu
->entries
[++index
];
3113 entry
->clientdata
= aicon
;
3114 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3115 wMenuSetEnabled(dock
->menu
, index
, aicon
!= scr
->clip_icon
);
3117 /* select/unselect all icons */
3118 entry
= dock
->menu
->entries
[++index
];
3119 entry
->clientdata
= aicon
;
3121 entry
->text
= _("Unselect All Icons");
3123 entry
->text
= _("Select All Icons");
3124 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3127 entry
= dock
->menu
->entries
[++index
];
3128 entry
->clientdata
= aicon
;
3130 entry
->text
= _("Keep Icons");
3132 entry
->text
= _("Keep Icon");
3133 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3135 /* this is the workspace submenu part */
3136 entry
= dock
->menu
->entries
[++index
];
3138 entry
->text
= _("Move Icons To");
3140 entry
->text
= _("Move Icon To");
3141 if (scr
->clip_submenu
)
3142 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3143 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3145 /* remove icon(s) */
3146 entry
= dock
->menu
->entries
[++index
];
3147 entry
->clientdata
= aicon
;
3149 entry
->text
= _("Remove Icons");
3151 entry
->text
= _("Remove Icon");
3152 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3154 /* attract icon(s) */
3155 entry
= dock
->menu
->entries
[++index
];
3156 entry
->clientdata
= aicon
;
3158 dock
->menu
->flags
.realized
= 0;
3159 wMenuRealize(dock
->menu
);
3162 if (aicon
->icon
->owner
) {
3163 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3169 entry
= dock
->menu
->entries
[++index
];
3170 entry
->clientdata
= aicon
;
3171 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3174 entry
= dock
->menu
->entries
[++index
];
3175 entry
->clientdata
= aicon
;
3176 if (wapp
&& wapp
->flags
.hidden
) {
3177 entry
->text
= _("Unhide Here");
3179 entry
->text
= _("Bring Here");
3181 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3184 entry
= dock
->menu
->entries
[++index
];
3185 entry
->clientdata
= aicon
;
3186 if (wapp
&& wapp
->flags
.hidden
) {
3187 entry
->text
= _("Unhide");
3189 entry
->text
= _("Hide");
3191 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3194 entry
= dock
->menu
->entries
[++index
];
3195 entry
->clientdata
= aicon
;
3196 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3199 entry
= dock
->menu
->entries
[++index
];
3200 entry
->clientdata
= aicon
;
3201 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3203 if (!dock
->menu
->flags
.realized
)
3204 wMenuRealize(dock
->menu
);
3206 if (dock
->type
== WM_CLIP
) {
3207 /*x_pos = event->xbutton.x_root+2; */
3208 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3211 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3212 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3215 x_pos
= dock
->on_right_side
? scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3218 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3220 /* allow drag select */
3221 event
->xany
.send_event
= True
;
3222 desc
= &dock
->menu
->menu
->descriptor
;
3223 (*desc
->handle_mousedown
) (desc
, event
);
3226 /******************************************************************/
3227 static void iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3229 WAppIcon
*btn
= desc
->parent
;
3230 WDock
*dock
= btn
->dock
;
3231 WApplication
*wapp
= NULL
;
3234 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3235 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3237 assert(wapp
!= NULL
);
3239 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3241 /* go to the last workspace that the user worked on the app */
3242 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
&& !unhideHere
) {
3243 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3246 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3248 if (event
->xbutton
.state
& MOD_MASK
) {
3249 wHideOtherApplications(btn
->icon
->owner
);
3252 if (event
->xbutton
.button
== Button1
) {
3254 if (event
->xbutton
.state
& MOD_MASK
) {
3255 /* raise/lower dock */
3256 toggleLowered(dock
);
3257 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3258 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
)
3259 toggleCollapsed(dock
);
3261 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3262 } else if (btn
->command
) {
3263 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3264 launchDockedApplication(btn
, False
);
3270 static void handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3272 WScreen
*scr
= dock
->screen_ptr
;
3273 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3276 int grabbed
= 0, swapped
= 0, done
;
3277 Pixmap ghost
= None
;
3278 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3280 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3281 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3282 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3283 wwarning("pointer grab failed for dock move");
3286 for (x
= 0; x
< dock
->max_icons
; x
++) {
3287 if (dock
->icon_array
[x
] != NULL
&& dock
->icon_array
[x
]->yindex
> y
)
3288 y
= dock
->icon_array
[x
]->yindex
;
3291 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
* y
);
3295 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3296 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3303 /* It means the cursor moved so fast that it entered
3304 * something else (if moving slowly, it would have
3305 * stayed in the dock that is being moved. Ignore such
3306 * "spurious" EnterNotifiy's */
3311 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3312 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3313 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3314 | ButtonReleaseMask
| ButtonPressMask
,
3315 wCursor
[WCUR_MOVE
], CurrentTime
);
3320 if (dock
->type
== WM_CLIP
) {
3321 x
= ev
.xmotion
.x_root
- ofs_x
;
3322 y
= ev
.xmotion
.y_root
- ofs_y
;
3323 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3325 moveDock(dock
, x
, y
);
3327 /* move vertically if pointer is inside the dock */
3328 if ((dock
->on_right_side
&& ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3329 || (!dock
->on_right_side
&& ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
* 2)) {
3331 x
= ev
.xmotion
.x_root
- ofs_x
;
3332 y
= ev
.xmotion
.y_root
- ofs_y
;
3333 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3334 moveDock(dock
, dock
->x_pos
, y
);
3336 /* move horizontally to change sides */
3337 x
= ev
.xmotion
.x_root
- ofs_x
;
3338 if (!dock
->on_right_side
) {
3342 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
* 2) {
3343 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
- ICON_SIZE
3344 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3345 if (superfluous
&& ghost
== None
) {
3346 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3347 scr
->scr_width
- ICON_SIZE
3348 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3349 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3350 XClearWindow(dpy
, scr
->dock_shadow
);
3352 XMapRaised(dpy
, scr
->dock_shadow
);
3355 if (superfluous
&& ghost
!= None
) {
3356 XFreePixmap(dpy
, ghost
);
3359 XUnmapWindow(dpy
, scr
->dock_shadow
);
3364 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3365 XMoveWindow(dpy
, scr
->dock_shadow
, DOCK_EXTRA_SPACE
, dock
->y_pos
);
3366 if (superfluous
&& ghost
== None
) {
3367 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3368 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3369 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3370 XClearWindow(dpy
, scr
->dock_shadow
);
3372 XMapRaised(dpy
, scr
->dock_shadow
);
3375 XUnmapWindow(dpy
, scr
->dock_shadow
);
3377 if (superfluous
&& ghost
!= None
) {
3378 XFreePixmap(dpy
, ghost
);
3390 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3392 XUngrabPointer(dpy
, CurrentTime
);
3393 XUnmapWindow(dpy
, scr
->dock_shadow
);
3394 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3395 if (dock
->type
== WM_DOCK
) {
3398 dock
->on_right_side
= 1;
3400 dock
->on_right_side
= 0;
3402 wArrangeIcons(scr
, False
);
3411 XFreePixmap(dpy
, ghost
);
3412 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3416 static Bool
handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3418 WScreen
*scr
= dock
->screen_ptr
;
3420 WIcon
*icon
= aicon
->icon
;
3421 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3422 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3424 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3425 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3426 int shad_x
= x
, shad_y
= y
;
3427 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3429 Pixmap ghost
= None
;
3431 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3432 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3433 Bool hasMoved
= False
;
3435 if (wPreferences
.flags
.noupdates
)
3438 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3439 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3440 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3443 if (!(event
->xbutton
.state
& MOD_MASK
))
3444 wRaiseFrame(icon
->core
);
3446 if (!wPreferences
.flags
.noclip
)
3447 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3449 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3451 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3454 wins
[0] = icon
->core
->window
;
3455 wins
[1] = scr
->dock_shadow
;
3456 XRestackWindows(dpy
, wins
, 2);
3457 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
3459 if (icon
->pixmap
!= None
)
3460 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3462 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3464 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3465 XClearWindow(dpy
, scr
->dock_shadow
);
3467 XMapWindow(dpy
, scr
->dock_shadow
);
3472 XMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3473 | ButtonMotionMask
| ExposureMask
, &ev
);
3482 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3483 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3484 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3485 | ButtonReleaseMask
| ButtonPressMask
,
3486 wCursor
[WCUR_MOVE
], CurrentTime
);
3495 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3496 if (i
== scr
->current_workspace
)
3498 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3502 x
= ev
.xmotion
.x_root
- ofs_x
;
3503 y
= ev
.xmotion
.y_root
- ofs_y
;
3504 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3507 if (last_dock
!= dock
&& collapsed
) {
3508 last_dock
->collapsed
= 1;
3509 wDockHideIcons(last_dock
);
3512 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3513 dock
->collapsed
= 0;
3514 wDockShowIcons(dock
);
3516 if (dock
->auto_raise_lower
)
3520 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3523 if (last_dock
!= dock2
&& collapsed
) {
3524 last_dock
->collapsed
= 1;
3525 wDockHideIcons(last_dock
);
3528 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3529 dock2
->collapsed
= 0;
3530 wDockShowIcons(dock2
);
3532 if (dock2
->auto_raise_lower
)
3537 if (aicon
->launching
|| aicon
->lock
|| (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3538 || (!aicon
->running
&& tmp
)) {
3539 shad_x
= last_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3540 shad_y
= last_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3542 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3545 XMapWindow(dpy
, scr
->dock_shadow
);
3550 XUnmapWindow(dpy
, scr
->dock_shadow
);
3554 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3561 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3563 XUngrabPointer(dpy
, CurrentTime
);
3565 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3566 XUnmapWindow(dpy
, scr
->dock_shadow
);
3568 reattachIcon(dock
, aicon
, ix
, iy
);
3569 if (clip
&& dock
!= clip
&& clip
->auto_raise_lower
)
3572 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3574 /* Slide it back if dock rejected it */
3575 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
, aicon
->y_pos
);
3576 reattachIcon(dock
, aicon
, aicon
->xindex
, aicon
->yindex
);
3578 if (last_dock
->type
== WM_CLIP
&& last_dock
->auto_collapse
) {
3586 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3587 /* We need to deselect it, even if is deselected in
3588 * wDockDetach(), because else DoKaboom() will fail.
3590 if (aicon
->icon
->selected
)
3591 wIconSelect(aicon
->icon
);
3593 DoKaboom(scr
, aicon
->icon
->core
->window
, x
, y
);
3596 if (clip
&& clip
->auto_raise_lower
)
3598 wDockDetach(dock
, aicon
);
3601 last_dock
->collapsed
= 1;
3602 wDockHideIcons(last_dock
);
3607 XFreePixmap(dpy
, ghost
);
3608 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3612 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3613 if (i
== scr
->current_workspace
)
3615 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3621 return False
; /* never reached */
3624 static int getClipButton(int px
, int py
)
3626 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3628 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3631 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3632 return CLIP_FORWARD
;
3633 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3639 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3642 int done
, direction
, new_ws
;
3644 WDock
*clip
= scr
->clip_icon
->dock
;
3646 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3648 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3649 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3651 wClipIconPaint(scr
->clip_icon
);
3654 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3661 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3662 if (new_dir
!= direction
) {
3663 direction
= new_dir
;
3664 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3665 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3666 wClipIconPaint(scr
->clip_icon
);
3674 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3679 clip
->lclip_button_pushed
= 0;
3680 clip
->rclip_button_pushed
= 0;
3682 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3684 if (direction
== CLIP_FORWARD
) {
3685 if (scr
->current_workspace
< scr
->workspace_count
- 1)
3686 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3687 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
- 1)
3688 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3689 else if (wPreferences
.ws_cycle
)
3690 wWorkspaceChange(scr
, 0);
3691 } else if (direction
== CLIP_REWIND
) {
3692 if (scr
->current_workspace
> 0)
3693 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
3694 else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
)
3695 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
3698 wClipIconPaint(scr
->clip_icon
);
3701 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3703 WAppIcon
*aicon
= desc
->parent
;
3704 WDock
*dock
= aicon
->dock
;
3705 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3707 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3710 scr
->last_dock
= dock
;
3712 if (dock
->menu
->flags
.mapped
)
3713 wMenuUnmap(dock
->menu
);
3715 if (IsDoubleClick(scr
, event
)) {
3716 /* double-click was not in the main clip icon */
3717 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3718 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3719 iconDblClick(desc
, event
);
3724 if (event
->xbutton
.button
== Button1
) {
3725 if (event
->xbutton
.state
& MOD_MASK
)
3730 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
&& dock
->type
!= WM_DOCK
) {
3731 wIconSelect(aicon
->icon
);
3735 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3736 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
3737 && dock
->type
== WM_CLIP
)
3738 handleClipChangeWorkspace(scr
, event
);
3740 handleDockMove(dock
, aicon
, event
);
3742 Bool hasMoved
= handleIconMove(dock
, aicon
, event
);
3743 if (wPreferences
.single_click
&& !hasMoved
)
3744 iconDblClick(desc
, event
);
3746 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&& aicon
== scr
->clip_icon
) {
3747 if (!scr
->clip_ws_menu
) {
3748 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3750 if (scr
->clip_ws_menu
) {
3751 WMenu
*wsMenu
= scr
->clip_ws_menu
;
3754 wWorkspaceMenuUpdate(scr
, wsMenu
);
3756 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
3759 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
3760 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
3762 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
3764 desc
= &wsMenu
->menu
->descriptor
;
3765 event
->xany
.send_event
= True
;
3766 (*desc
->handle_mousedown
) (desc
, event
);
3768 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
3769 (event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
) {
3770 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3771 } else if (event
->xbutton
.button
== Button3
) {
3772 if (event
->xbutton
.send_event
&&
3773 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3774 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3775 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3776 wwarning("pointer grab failed for dockicon menu");
3780 openDockMenu(dock
, aicon
, event
);
3781 } else if (event
->xbutton
.button
== Button2
) {
3782 WAppIcon
*btn
= desc
->parent
;
3784 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3785 launchDockedApplication(btn
, True
);
3790 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3792 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3796 assert(event
->type
== EnterNotify
);
3798 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3801 scr
= btn
->icon
->core
->screen_ptr
;
3802 if (!btn
->omnipresent
)
3805 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3807 if (!dock
|| dock
->type
!= WM_CLIP
)
3810 /* The auto raise/lower code */
3811 if (dock
->auto_lower_magic
) {
3812 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3813 dock
->auto_lower_magic
= NULL
;
3815 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
3816 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
, clipAutoRaise
, (void *)dock
);
3819 /* The auto expand/collapse code */
3820 if (dock
->auto_collapse_magic
) {
3821 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3822 dock
->auto_collapse_magic
= NULL
;
3824 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
3825 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
, clipAutoExpand
, (void *)dock
);
3829 static void clipLeave(WDock
*dock
)
3832 WObjDescriptor
*desc
= NULL
;
3834 if (!dock
|| dock
->type
!= WM_CLIP
)
3837 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
3838 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3839 (XPointer
*) & desc
) != XCNOENT
3840 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
3841 && ((WAppIcon
*) desc
->parent
)->dock
&& ((WAppIcon
*) desc
->parent
)->dock
->type
== WM_CLIP
) {
3842 /* We didn't left the Clip yet */
3843 XPutBackEvent(dpy
, &event
);
3847 XPutBackEvent(dpy
, &event
);
3849 /* We entered a withdrawn window, so we're still in Clip */
3853 if (dock
->auto_raise_magic
) {
3854 WMDeleteTimerHandler(dock
->auto_raise_magic
);
3855 dock
->auto_raise_magic
= NULL
;
3857 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
3858 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
, clipAutoLower
, (void *)dock
);
3861 if (dock
->auto_expand_magic
) {
3862 WMDeleteTimerHandler(dock
->auto_expand_magic
);
3863 dock
->auto_expand_magic
= NULL
;
3865 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
3866 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
, clipAutoCollapse
, (void *)dock
);
3870 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
3872 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3874 assert(event
->type
== LeaveNotify
);
3876 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3879 clipLeave(btn
->dock
);
3882 static void clipAutoCollapse(void *cdata
)
3884 WDock
*dock
= (WDock
*) cdata
;
3886 if (dock
->type
!= WM_CLIP
)
3889 if (dock
->auto_collapse
) {
3890 dock
->collapsed
= 1;
3891 wDockHideIcons(dock
);
3893 dock
->auto_collapse_magic
= NULL
;
3896 static void clipAutoExpand(void *cdata
)
3898 WDock
*dock
= (WDock
*) cdata
;
3900 if (dock
->type
!= WM_CLIP
)
3903 if (dock
->auto_collapse
) {
3904 dock
->collapsed
= 0;
3905 wDockShowIcons(dock
);
3907 dock
->auto_expand_magic
= NULL
;
3910 static void clipAutoLower(void *cdata
)
3912 WDock
*dock
= (WDock
*) cdata
;
3914 if (dock
->type
!= WM_CLIP
)
3917 if (dock
->auto_raise_lower
)
3920 dock
->auto_lower_magic
= NULL
;
3923 static void clipAutoRaise(void *cdata
)
3925 WDock
*dock
= (WDock
*) cdata
;
3927 if (dock
->type
!= WM_CLIP
)
3930 if (dock
->auto_raise_lower
)
3933 dock
->auto_raise_magic
= NULL
;
3936 static Bool
iconCanBeOmnipresent(WAppIcon
*aicon
)
3938 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3943 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3944 clip
= scr
->workspaces
[i
]->clip
;
3946 if (clip
== aicon
->dock
)
3949 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
3950 return False
; /* Clip is full in some workspace */
3952 for (j
= 0; j
< clip
->max_icons
; j
++) {
3953 btn
= clip
->icon_array
[j
];
3954 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
3962 int wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
3964 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3965 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
3966 int status
= WO_SUCCESS
;
3968 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== scr
->clip_icon
) {
3969 return WO_NOT_APPLICABLE
;
3972 if (aicon
->omnipresent
== omnipresent
)
3976 if (iconCanBeOmnipresent(aicon
)) {
3977 aicon
->omnipresent
= 1;
3978 new_entry
= wmalloc(sizeof(WAppIconChain
));
3979 new_entry
->aicon
= aicon
;
3980 new_entry
->next
= scr
->global_icons
;
3981 scr
->global_icons
= new_entry
;
3982 scr
->global_icon_count
++;
3984 aicon
->omnipresent
= 0;
3988 aicon
->omnipresent
= 0;
3989 if (aicon
== scr
->global_icons
->aicon
) {
3990 tmp
= scr
->global_icons
->next
;
3991 wfree(scr
->global_icons
);
3992 scr
->global_icons
= tmp
;
3993 scr
->global_icon_count
--;
3995 tmp
= scr
->global_icons
;
3997 if (tmp
->next
->aicon
== aicon
) {
3998 tmp1
= tmp
->next
->next
;
4001 scr
->global_icon_count
--;
4009 wAppIconPaint(aicon
);