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
);
174 static void toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
176 assert(entry
->clientdata
!= NULL
);
178 toggleLowered(entry
->clientdata
);
180 entry
->flags
.indicator_on
= !(((WDock
*) entry
->clientdata
)->lowered
);
185 static int matchWindow(const void *item
, const void *cdata
)
187 return (((WFakeGroupLeader
*) item
)->leader
== (Window
) cdata
);
190 static void killCallback(WMenu
*menu
, WMenuEntry
*entry
)
192 WScreen
*scr
= menu
->menu
->screen_ptr
;
194 WFakeGroupLeader
*fPtr
;
195 char *buffer
, *shortname
, **argv
;
196 char *basename(const char *shortname
);
199 if (!WCHECK_STATE(WSTATE_NORMAL
))
202 assert(entry
->clientdata
!= NULL
);
204 icon
= (WAppIcon
*) entry
->clientdata
;
208 WCHANGE_STATE(WSTATE_MODAL
);
210 /* strip away dir names */
211 shortname
= basename(icon
->command
);
212 /* separate out command options */
213 wtokensplit(shortname
, &argv
, &argc
);
215 buffer
= wstrconcat(argv
[0],
216 _(" will be forcibly closed.\n"
217 "Any unsaved changes will be lost.\n" "Please confirm."));
219 if (icon
->icon
&& icon
->icon
->owner
) {
220 fPtr
= icon
->icon
->owner
->fake_group
;
222 /* is this really necessary? can we kill a non-running dock icon? */
223 Window win
= icon
->main_window
;
226 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)win
);
227 if (index
!= WANotFound
)
228 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
233 if (wPreferences
.dont_confirm_kill
234 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
235 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
237 WWindow
*wwin
, *twin
;
239 wwin
= scr
->focused_window
;
242 if (wwin
->fake_group
== fPtr
)
247 } else if (icon
->icon
&& icon
->icon
->owner
) {
248 wClientKill(icon
->icon
->owner
);
253 wtokenfree(argv
, argc
);
257 WCHANGE_STATE(WSTATE_NORMAL
);
260 /* TODO: replace this function with a member of the dock struct */
261 static int numberOfSelectedIcons(WDock
*dock
)
267 for (i
= 1; i
< dock
->max_icons
; i
++) {
268 aicon
= dock
->icon_array
[i
];
269 if (aicon
&& aicon
->icon
->selected
)
276 static WMArray
*getSelected(WDock
*dock
)
278 WMArray
*ret
= WMCreateArray(8);
282 for (i
= 1; i
< dock
->max_icons
; i
++) {
283 btn
= dock
->icon_array
[i
];
284 if (btn
&& btn
->icon
->selected
)
285 WMAddToArray(ret
, btn
);
291 static void paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
293 Window win
= clipIcon
->icon
->core
->window
;
294 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
296 int pt
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
297 int tp
= ICON_SIZE
- pt
;
298 int as
= pt
- 15; /* 15 = 5+5+5 */
299 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
302 color
= scr
->clip_title_color
[CLIP_NORMAL
];
304 XSetForeground(dpy
, gc
, WMColorPixel(color
));
309 p
[1].x
= ICON_SIZE
- 2;
311 p
[2].x
= ICON_SIZE
- 2;
313 } else if (lpushed
) {
317 p
[1].y
= ICON_SIZE
- 2;
319 p
[2].y
= ICON_SIZE
- 2;
321 if (lpushed
|| rpushed
) {
322 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
323 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
324 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
327 /* top right arrow */
328 p
[0].x
= p
[3].x
= ICON_SIZE
- 5 - as
;
330 p
[1].x
= ICON_SIZE
- 6;
332 p
[2].x
= ICON_SIZE
- 6;
335 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
336 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
338 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
339 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
342 /* bottom left arrow */
344 p
[0].y
= p
[3].y
= ICON_SIZE
- 5 - as
;
346 p
[1].y
= ICON_SIZE
- 6;
348 p
[2].y
= ICON_SIZE
- 6;
350 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
351 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
353 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
354 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
358 RImage
*wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
360 RImage
*tile
= RCloneImage(normalTile
);
367 pt
= CLIP_BUTTON_SIZE
* wPreferences
.icon_size
/ 64;
368 tp
= wPreferences
.icon_size
- 1 - pt
;
372 black
.red
= black
.green
= black
.blue
= 0;
375 dark
.red
= dark
.green
= dark
.blue
= 60;
378 light
.red
= light
.green
= light
.blue
= 80;
381 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
- 2, pt
- 1, &dark
);
382 RDrawLine(tile
, tp
- 1, 0, wPreferences
.icon_size
- 1, pt
+ 1, &black
);
383 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
- 3, pt
, &light
);
386 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, 4, &dark
);
387 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 5, 6 + as
, &dark
);
388 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
, &light
);
391 ROperateLine(tile
, RAddOperation
, 2, tp
+ 2, pt
- 2, wPreferences
.icon_size
- 3, &dark
);
392 RDrawLine(tile
, 0, tp
- 1, pt
+ 1, wPreferences
.icon_size
- 1, &black
);
393 ROperateLine(tile
, RSubtractOperation
, 0, tp
- 2, pt
+ 1, wPreferences
.icon_size
- 2, &light
);
396 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, &dark
);
397 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
, 6 + as
, ICON_SIZE
- 5, &dark
);
398 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5, &light
);
403 static void omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
405 WAppIcon
*clickedIcon
= entry
->clientdata
;
408 WMArray
*selectedIcons
;
409 WMArrayIterator iter
;
412 assert(entry
->clientdata
!= NULL
);
414 dock
= clickedIcon
->dock
;
416 selectedIcons
= getSelected(dock
);
418 if (!WMGetArrayItemCount(selectedIcons
))
419 WMAddToArray(selectedIcons
, clickedIcon
);
422 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
423 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
425 else if (aicon
->icon
->selected
)
426 wIconSelect(aicon
->icon
);
428 WMFreeArray(selectedIcons
);
431 wMessageDialog(dock
->screen_ptr
, _("Warning"),
432 _("Some icons cannot be made omnipresent. "
433 "Please make sure that no other icon is "
434 "docked in the same positions on the other "
435 "workspaces and the Clip is not full in "
436 "some workspace."), _("OK"), NULL
, NULL
);
437 } else if (failed
== 1) {
438 wMessageDialog(dock
->screen_ptr
, _("Warning"),
439 _("Icon cannot be made omnipresent. "
440 "Please make sure that no other icon is "
441 "docked in the same position on the other "
442 "workspaces and the Clip is not full in "
443 "some workspace."), _("OK"), NULL
, NULL
);
447 static void removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
449 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
452 WMArray
*selectedIcons
;
456 assert(clickedIcon
!= NULL
);
458 dock
= clickedIcon
->dock
;
460 selectedIcons
= getSelected(dock
);
462 if (WMGetArrayItemCount(selectedIcons
)) {
463 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
464 _("All selected icons will be removed!"),
465 _("OK"), _("Cancel"), NULL
) != WAPRDefault
) {
466 WMFreeArray(selectedIcons
);
470 if (clickedIcon
->xindex
== 0 && clickedIcon
->yindex
== 0) {
471 WMFreeArray(selectedIcons
);
474 WMAddToArray(selectedIcons
, clickedIcon
);
477 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
478 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
479 wDockDetach(dock
, aicon
);
481 /* XXX: can: aicon->icon == NULL ? */
482 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
483 wGetHeadForWindow(aicon
->icon
->owner
));
484 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
485 if (!dock
->mapped
|| dock
->collapsed
)
486 XMapWindow(dpy
, aicon
->icon
->core
->window
);
489 WMFreeArray(selectedIcons
);
491 if (wPreferences
.auto_arrange_icons
)
492 wArrangeIcons(dock
->screen_ptr
, True
);
495 static void keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
497 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
500 WMArray
*selectedIcons
;
503 assert(clickedIcon
!= NULL
);
504 dock
= clickedIcon
->dock
;
506 selectedIcons
= getSelected(dock
);
508 if (!WMGetArrayItemCount(selectedIcons
)
509 && clickedIcon
!= dock
->screen_ptr
->clip_icon
) {
510 char *command
= NULL
;
512 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
513 clickedIcon
->editing
= 1;
514 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
515 _("Type the command used to launch the application"), &command
)) {
516 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
520 clickedIcon
->command
= command
;
521 clickedIcon
->editing
= 0;
523 clickedIcon
->editing
= 0;
526 WMFreeArray(selectedIcons
);
531 WMAddToArray(selectedIcons
, clickedIcon
);
534 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
535 if (aicon
->icon
->selected
)
536 wIconSelect(aicon
->icon
);
538 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
539 aicon
->attracted
= 0;
540 if (aicon
->icon
->shadowed
) {
541 aicon
->icon
->shadowed
= 0;
543 /* Update the icon images */
544 wIconUpdate(aicon
->icon
);
547 wAppIconPaint(aicon
);
550 save_appicon(aicon
, True
);
552 WMFreeArray(selectedIcons
);
555 static void toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
557 WDock
*dock
= (WDock
*) entry
->clientdata
;
559 assert(entry
->clientdata
!= NULL
);
561 dock
->attract_icons
= !dock
->attract_icons
;
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
;
585 Bool update_icon
= False
;
587 assert(entry
->clientdata
!= NULL
);
588 clip
= clickedIcon
->dock
;
590 aicon
= clip
->screen_ptr
->app_icon_list
;
593 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
594 x_pos
= clip
->x_pos
+ x
* ICON_SIZE
;
595 y_pos
= clip
->y_pos
+ y
* ICON_SIZE
;
596 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
)
597 move_window(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
599 aicon
->attracted
= 1;
600 if (!aicon
->icon
->shadowed
) {
601 aicon
->icon
->shadowed
= 1;
604 wDockAttachIcon(clip
, aicon
, x
, y
, update_icon
);
605 if (clip
->collapsed
|| !clip
->mapped
)
606 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
612 static void selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
614 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
616 WMArray
*selectedIcons
;
617 WMArrayIterator iter
;
621 assert(clickedIcon
!= NULL
);
622 dock
= clickedIcon
->dock
;
624 selectedIcons
= getSelected(dock
);
626 if (!WMGetArrayItemCount(selectedIcons
)) {
627 for (i
= 1; i
< dock
->max_icons
; i
++) {
628 btn
= dock
->icon_array
[i
];
629 if (btn
&& !btn
->icon
->selected
)
630 wIconSelect(btn
->icon
);
633 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
634 wIconSelect(btn
->icon
);
637 WMFreeArray(selectedIcons
);
642 static void toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
644 assert(entry
->clientdata
!= NULL
);
646 toggleCollapsed(entry
->clientdata
);
648 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->collapsed
;
653 static void toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
656 assert(entry
->clientdata
!= NULL
);
658 dock
= (WDock
*) entry
->clientdata
;
660 dock
->auto_collapse
= !dock
->auto_collapse
;
662 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_collapse
;
667 static void toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
670 assert(entry
->clientdata
!= NULL
);
672 dock
= (WDock
*) entry
->clientdata
;
674 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
676 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_raise_lower
;
681 static void launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
683 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
685 launchDockedApplication(btn
, False
);
688 static void settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
690 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
694 ShowDockAppSettingsPanel(btn
);
697 static void hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
700 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
702 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
704 if (wapp
->flags
.hidden
) {
705 wWorkspaceChange(btn
->icon
->core
->screen_ptr
, wapp
->last_workspace
);
706 wUnhideApplication(wapp
, False
, False
);
708 wHideApplication(wapp
);
712 static void unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
715 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
717 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
719 wUnhideApplication(wapp
, False
, True
);
722 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
)
727 if (type
== WM_CLIP
) {
729 return scr
->clip_icon
;
730 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
731 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
732 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
733 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
736 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
737 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
743 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
744 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
745 btn
->icon
->core
->descriptor
.parent
= btn
;
746 XMapWindow(dpy
, btn
->icon
->core
->window
);
751 scr
->clip_icon
= btn
;
756 static void switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
758 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
759 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
761 WMArray
*selectedIcons
;
764 if (entry
->order
== scr
->current_workspace
)
767 dest
= scr
->workspaces
[entry
->order
]->clip
;
769 selectedIcons
= getSelected(src
);
771 if (WMGetArrayItemCount(selectedIcons
)) {
772 WMArrayIterator iter
;
774 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
775 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
776 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
777 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
780 } else if (icon
!= scr
->clip_icon
) {
781 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
782 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
783 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
786 WMFreeArray(selectedIcons
);
789 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
)
791 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
793 if (!btn
->launching
&&
794 ((!withSelection
&& btn
->command
!= NULL
) || (withSelection
&& btn
->paste_command
!= NULL
))) {
795 if (!btn
->forced_dock
) {
796 btn
->relaunching
= btn
->running
;
799 if (btn
->wm_instance
|| btn
->wm_class
) {
800 WWindowAttributes attr
;
801 memset(&attr
, 0, sizeof(WWindowAttributes
));
802 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
804 if (!attr
.no_appicon
&& !btn
->buggy_app
)
809 btn
->drop_launch
= 0;
810 btn
->paste_launch
= withSelection
;
811 scr
->last_dock
= btn
->dock
;
812 btn
->pid
= execCommand(btn
, (withSelection
? btn
->paste_command
: btn
->command
), NULL
);
814 if (btn
->buggy_app
) {
815 /* give feedback that the app was launched */
819 WMAddTimerHandler(200, (WMCallback
*) dockIconPaint
, btn
);
824 wwarning(_("could not launch application %s"), btn
->command
);
826 if (!btn
->relaunching
)
832 static void updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
834 WScreen
*scr
= menu
->frame
->screen_ptr
;
835 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
841 for (i
= 0; i
< scr
->workspace_count
; i
++) {
842 if (i
< menu
->entry_no
) {
843 if (strcmp(menu
->entries
[i
]->text
, scr
->workspaces
[i
]->name
) != 0) {
844 wfree(menu
->entries
[i
]->text
);
845 strcpy(title
, scr
->workspaces
[i
]->name
);
846 menu
->entries
[i
]->text
= wstrdup(title
);
847 menu
->flags
.realized
= 0;
849 menu
->entries
[i
]->clientdata
= (void *)icon
;
851 strcpy(title
, scr
->workspaces
[i
]->name
);
853 wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)icon
);
855 menu
->flags
.realized
= 0;
858 if (i
== scr
->current_workspace
)
859 wMenuSetEnabled(menu
, i
, False
);
861 wMenuSetEnabled(menu
, i
, True
);
864 if (!menu
->flags
.realized
)
868 static WMenu
*makeWorkspaceMenu(WScreen
*scr
)
872 menu
= wMenuCreate(scr
, NULL
, False
);
874 wwarning(_("could not create workspace submenu for Clip menu"));
876 wMenuAddCallback(menu
, "", switchWSCommand
, (void *)scr
->clip_icon
);
878 menu
->flags
.realized
= 0;
884 static void updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
893 entry
= menu
->entries
[index
];
894 entry
->flags
.indicator_on
= !dock
->lowered
;
895 entry
->clientdata
= dock
;
898 entry
= menu
->entries
[++index
];
899 entry
->flags
.indicator_on
= dock
->collapsed
;
900 entry
->clientdata
= dock
;
903 entry
= menu
->entries
[++index
];
904 entry
->flags
.indicator_on
= dock
->auto_collapse
;
905 entry
->clientdata
= dock
;
907 /* auto-raise/lower */
908 entry
= menu
->entries
[++index
];
909 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
910 entry
->clientdata
= dock
;
911 wMenuSetEnabled(menu
, index
, dock
->lowered
);
914 entry
= menu
->entries
[++index
];
915 entry
->flags
.indicator_on
= dock
->attract_icons
;
916 entry
->clientdata
= dock
;
918 menu
->flags
.realized
= 0;
922 static WMenu
*makeClipOptionsMenu(WScreen
*scr
)
927 menu
= wMenuCreate(scr
, NULL
, False
);
929 wwarning(_("could not create options submenu for Clip menu"));
933 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
934 entry
->flags
.indicator
= 1;
935 entry
->flags
.indicator_on
= 1;
936 entry
->flags
.indicator_type
= MI_CHECK
;
938 entry
= wMenuAddCallback(menu
, _("Collapsed"), toggleCollapsedCallback
, NULL
);
939 entry
->flags
.indicator
= 1;
940 entry
->flags
.indicator_on
= 1;
941 entry
->flags
.indicator_type
= MI_CHECK
;
943 entry
= wMenuAddCallback(menu
, _("Autocollapse"), toggleAutoCollapseCallback
, NULL
);
944 entry
->flags
.indicator
= 1;
945 entry
->flags
.indicator_on
= 1;
946 entry
->flags
.indicator_type
= MI_CHECK
;
948 entry
= wMenuAddCallback(menu
, _("Autoraise"), toggleAutoRaiseLowerCallback
, NULL
);
949 entry
->flags
.indicator
= 1;
950 entry
->flags
.indicator_on
= 1;
951 entry
->flags
.indicator_type
= MI_CHECK
;
953 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"), toggleAutoAttractCallback
, NULL
);
954 entry
->flags
.indicator
= 1;
955 entry
->flags
.indicator_on
= 1;
956 entry
->flags
.indicator_type
= MI_CHECK
;
958 menu
->flags
.realized
= 0;
964 static WMenu
*dockMenuCreate(WScreen
*scr
, int type
)
969 if (type
== WM_CLIP
&& scr
->clip_menu
)
970 return scr
->clip_menu
;
972 menu
= wMenuCreate(scr
, NULL
, False
);
973 if (type
!= WM_CLIP
) {
974 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
975 entry
->flags
.indicator
= 1;
976 entry
->flags
.indicator_on
= 1;
977 entry
->flags
.indicator_type
= MI_CHECK
;
979 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
980 scr
->clip_options
= makeClipOptionsMenu(scr
);
981 if (scr
->clip_options
)
982 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
984 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
986 entry
->text
= _("Rename Workspace");
988 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
989 entry
->flags
.indicator
= 1;
990 entry
->flags
.indicator_on
= 1;
991 entry
->flags
.indicator_type
= MI_CHECK
;
993 entry
= wMenuAddCallback(menu
, _("Select All Icons"), selectIconsCallback
, NULL
);
995 entry
->text
= _("Select All Icons");
997 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
999 entry
->text
= _("Keep Icon");
1001 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1003 entry
->text
= _("Move Icon To");
1004 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1005 if (scr
->clip_submenu
)
1006 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1008 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
, NULL
);
1010 entry
->text
= _("Remove Icon");
1012 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1015 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1017 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1019 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1021 entry
->text
= _("Hide");
1023 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1025 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1027 if (type
== WM_CLIP
)
1028 scr
->clip_menu
= menu
;
1033 WDock
*wDockCreate(WScreen
*scr
, int type
)
1040 dock
= wmalloc(sizeof(WDock
));
1042 dock
->max_icons
= DOCK_MAX_ICONS
;
1044 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * dock
->max_icons
);
1046 btn
= mainIconCreate(scr
, type
);
1050 dock
->x_pos
= btn
->x_pos
;
1051 dock
->y_pos
= btn
->y_pos
;
1052 dock
->screen_ptr
= scr
;
1054 dock
->icon_count
= 1;
1055 dock
->on_right_side
= 1;
1056 dock
->collapsed
= 0;
1057 dock
->auto_collapse
= 0;
1058 dock
->auto_collapse_magic
= NULL
;
1059 dock
->auto_raise_lower
= 0;
1060 dock
->auto_lower_magic
= NULL
;
1061 dock
->auto_raise_magic
= NULL
;
1062 dock
->attract_icons
= 0;
1064 dock
->icon_array
[0] = btn
;
1065 wRaiseFrame(btn
->icon
->core
);
1066 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1068 /* create dock menu */
1069 dock
->menu
= dockMenuCreate(scr
, type
);
1074 void wDockDestroy(WDock
*dock
)
1079 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1080 aicon
= dock
->icon_array
[i
];
1082 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1083 wDockDetach(dock
, aicon
);
1085 /* XXX: can: aicon->icon == NULL ? */
1086 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1087 wGetHeadForWindow(aicon
->icon
->owner
));
1088 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1089 if (!dock
->mapped
|| dock
->collapsed
)
1090 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1094 if (wPreferences
.auto_arrange_icons
)
1095 wArrangeIcons(dock
->screen_ptr
, True
);
1096 wfree(dock
->icon_array
);
1097 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1098 wMenuDestroy(dock
->menu
, True
);
1099 if (dock
->screen_ptr
->last_dock
== dock
)
1100 dock
->screen_ptr
->last_dock
= NULL
;
1104 void wClipIconPaint(WAppIcon
*aicon
)
1106 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1107 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1109 Window win
= aicon
->icon
->core
->window
;
1110 int length
, nlength
;
1111 char *ws_name
, ws_number
[10];
1114 wIconPaint(aicon
->icon
);
1116 length
= strlen(workspace
->name
);
1117 ws_name
= wmalloc(length
+ 1);
1118 snprintf(ws_name
, length
+ 1, "%s", workspace
->name
);
1119 snprintf(ws_number
, sizeof(ws_number
), "%i", scr
->current_workspace
+ 1);
1120 nlength
= strlen(ws_number
);
1122 if (!workspace
->clip
->collapsed
)
1123 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1125 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1127 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1129 tx
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
1131 if(wPreferences
.show_clip_title
)
1132 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, ty
, ws_name
, length
);
1134 tx
= (ICON_SIZE
/ 2 - WMWidthOfString(scr
->clip_title_font
, ws_number
, nlength
)) / 2;
1136 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, 2, ws_number
, nlength
);
1140 if (aicon
->launching
)
1141 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1142 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1144 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
, aicon
->dock
->rclip_button_pushed
);
1147 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1149 wClipIconPaint(desc
->parent
);
1152 static void dockIconPaint(WAppIcon
*btn
)
1154 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
) {
1155 wClipIconPaint(btn
);
1158 save_appicon(btn
, True
);
1162 static WMPropList
*make_icon_state(WAppIcon
*btn
)
1164 WMPropList
*node
= NULL
;
1165 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
;
1166 WMPropList
*position
, *buggy
, *omnipresent
;
1172 command
= WMCreatePLString("-");
1174 command
= WMCreatePLString(btn
->command
);
1176 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1178 lock
= btn
->lock
? dYes
: dNo
;
1180 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1182 name
= WMCreatePLString(tmp
);
1186 forced
= btn
->forced_dock
? dYes
: dNo
;
1188 buggy
= btn
->buggy_app
? dYes
: dNo
;
1190 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1191 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1193 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1194 position
= WMCreatePLString(buffer
);
1196 node
= WMCreatePLDictionary(dCommand
, command
,
1198 dAutoLaunch
, autolaunch
,
1200 dForced
, forced
, dBuggyApplication
, buggy
, dPosition
, position
, NULL
);
1201 WMReleasePropList(command
);
1202 WMReleasePropList(name
);
1203 WMReleasePropList(position
);
1205 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1206 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&& (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1207 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1209 #ifdef XDND /* was OFFIX */
1210 if (btn
->dnd_command
) {
1211 command
= WMCreatePLString(btn
->dnd_command
);
1212 WMPutInPLDictionary(node
, dDropCommand
, command
);
1213 WMReleasePropList(command
);
1217 if (btn
->paste_command
) {
1218 command
= WMCreatePLString(btn
->paste_command
);
1219 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1220 WMReleasePropList(command
);
1227 static WMPropList
*dockSaveState(WDock
*dock
)
1230 WMPropList
*icon_info
;
1231 WMPropList
*list
= NULL
, *dock_state
= NULL
;
1232 WMPropList
*value
, *key
;
1235 list
= WMCreatePLArray(NULL
);
1237 for (i
= (dock
->type
== WM_DOCK
? 0 : 1); i
< dock
->max_icons
; i
++) {
1238 WAppIcon
*btn
= dock
->icon_array
[i
];
1240 if (!btn
|| btn
->attracted
)
1243 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1244 WMAddToPLArray(list
, icon_info
);
1245 WMReleasePropList(icon_info
);
1249 dock_state
= WMCreatePLDictionary(dApplications
, list
, NULL
);
1251 if (dock
->type
== WM_DOCK
) {
1252 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1253 key
= WMCreatePLString(buffer
);
1254 WMPutInPLDictionary(dock_state
, key
, list
);
1255 WMReleasePropList(key
);
1257 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0), dock
->y_pos
);
1258 value
= WMCreatePLString(buffer
);
1259 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1260 WMReleasePropList(value
);
1262 WMReleasePropList(list
);
1264 value
= (dock
->lowered
? dYes
: dNo
);
1265 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1267 if (dock
->type
== WM_CLIP
) {
1268 value
= (dock
->collapsed
? dYes
: dNo
);
1269 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1271 value
= (dock
->auto_collapse
? dYes
: dNo
);
1272 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1274 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1275 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1277 value
= (dock
->attract_icons
? dYes
: dNo
);
1278 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1284 void wDockSaveState(WScreen
*scr
, WMPropList
*old_state
)
1286 WMPropList
*dock_state
;
1289 dock_state
= dockSaveState(scr
->dock
);
1292 * Copy saved states of docks with different sizes.
1298 keys
= WMGetPLDictionaryKeys(old_state
);
1299 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1300 tmp
= WMGetFromPLArray(keys
, i
);
1302 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1303 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1305 WMPutInPLDictionary(dock_state
, tmp
, WMGetFromPLDictionary(old_state
, tmp
));
1308 WMReleasePropList(keys
);
1311 WMPutInPLDictionary(scr
->session_state
, dDock
, dock_state
);
1313 WMReleasePropList(dock_state
);
1316 void wClipSaveState(WScreen
*scr
)
1318 WMPropList
*clip_state
;
1320 clip_state
= make_icon_state(scr
->clip_icon
);
1322 WMPutInPLDictionary(scr
->session_state
, dClip
, clip_state
);
1324 WMReleasePropList(clip_state
);
1327 WMPropList
*wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1329 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1332 static Bool
getBooleanDockValue(WMPropList
*value
, WMPropList
*key
)
1335 if (WMIsPLString(value
)) {
1336 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1339 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1345 static WAppIcon
*restore_icon_state(WScreen
*scr
, WMPropList
*info
, int type
, int index
)
1348 WMPropList
*cmd
, *value
;
1349 char *wclass
, *winstance
, *command
;
1351 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1352 if (!cmd
|| !WMIsPLString(cmd
))
1355 /* parse window name */
1356 value
= WMGetFromPLDictionary(info
, dName
);
1360 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1362 if (!winstance
&& !wclass
)
1367 command
= wstrdup(WMGetFromPLString(cmd
));
1371 if (!command
|| strcmp(command
, "-") == 0) {
1382 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1390 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1391 if (type
== WM_CLIP
) {
1392 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1393 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1395 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1396 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1398 #ifdef XDND /* was OFFIX */
1399 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1401 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1404 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1406 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1408 /* check auto launch */
1409 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1411 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1414 value
= WMGetFromPLDictionary(info
, dLock
);
1416 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1418 /* check if it wasn't normally docked */
1419 value
= WMGetFromPLDictionary(info
, dForced
);
1421 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1423 /* check if we can rely on the stuff in the app */
1424 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1426 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1428 /* get position in the dock */
1429 value
= WMGetFromPLDictionary(info
, dPosition
);
1430 if (value
&& WMIsPLString(value
)) {
1431 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1432 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1434 /* check position sanity */
1435 /* incomplete section! */
1436 if (type
== WM_DOCK
) {
1438 if (aicon
->yindex
< 0)
1439 wwarning(_("bad value in docked icon position %i,%i"),
1440 aicon
->xindex
, aicon
->yindex
);
1443 aicon
->yindex
= index
;
1447 /* check if icon is omnipresent */
1448 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1450 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1458 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1460 WAppIcon
*wClipRestoreState(WScreen
*scr
, WMPropList
*clip_state
)
1465 icon
= mainIconCreate(scr
, WM_CLIP
);
1470 WMRetainPropList(clip_state
);
1472 /* restore position */
1474 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1477 if (!WMIsPLString(value
)) {
1478 COMPLAIN("Position");
1483 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1484 COMPLAIN("Position");
1486 /* check position sanity */
1487 rect
.pos
.x
= icon
->x_pos
;
1488 rect
.pos
.y
= icon
->y_pos
;
1489 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1491 wGetRectPlacementInfo(scr
, rect
, &flags
);
1492 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
1493 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1496 #ifdef XDND /* was OFFIX */
1497 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1498 if (value
&& WMIsPLString(value
))
1499 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1502 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1503 if (value
&& WMIsPLString(value
))
1504 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1506 WMReleasePropList(clip_state
);
1511 WDock
*wDockRestoreState(WScreen
*scr
, WMPropList
*dock_state
, int type
)
1516 WAppIcon
*aicon
, *old_top
;
1519 dock
= wDockCreate(scr
, type
);
1524 WMRetainPropList(dock_state
);
1526 /* restore position */
1527 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1529 if (!WMIsPLString(value
)) {
1530 COMPLAIN("Position");
1535 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1536 COMPLAIN("Position");
1538 /* check position sanity */
1539 rect
.pos
.x
= dock
->x_pos
;
1540 rect
.pos
.y
= dock
->y_pos
;
1541 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1543 wGetRectPlacementInfo(scr
, rect
, &flags
);
1544 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
)) {
1545 int x
= dock
->x_pos
;
1546 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1549 /* Is this needed any more? */
1550 if (type
== WM_CLIP
) {
1551 if (dock
->x_pos
< 0) {
1553 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1554 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1557 if (dock
->x_pos
>= 0) {
1558 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1559 dock
->on_right_side
= 0;
1561 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1562 dock
->on_right_side
= 1;
1568 /* restore lowered/raised state */
1571 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1573 if (!WMIsPLString(value
)) {
1574 COMPLAIN("Lowered");
1576 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1581 /* restore collapsed state */
1582 dock
->collapsed
= 0;
1584 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1586 if (!WMIsPLString(value
)) {
1587 COMPLAIN("Collapsed");
1589 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1590 dock
->collapsed
= 1;
1594 /* restore auto-collapsed state */
1595 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1597 if (!WMIsPLString(value
)) {
1598 COMPLAIN("AutoCollapse");
1600 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1601 dock
->auto_collapse
= 1;
1602 dock
->collapsed
= 1;
1607 /* restore auto-raise/lower state */
1608 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1610 if (!WMIsPLString(value
)) {
1611 COMPLAIN("AutoRaiseLower");
1613 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1614 dock
->auto_raise_lower
= 1;
1618 /* restore attract icons state */
1619 dock
->attract_icons
= 0;
1621 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1623 if (!WMIsPLString(value
)) {
1624 COMPLAIN("AutoAttractIcons");
1626 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1627 dock
->attract_icons
= 1;
1631 /* application list */
1638 * When saving, it saves the dock state in
1639 * Applications and Applicationsnnn
1641 * When loading, it will first try Applicationsnnn.
1642 * If it does not exist, use Applications as default.
1645 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1647 tmp
= WMCreatePLString(buffer
);
1648 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1649 WMReleasePropList(tmp
);
1652 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1658 count
= WMGetPropListItemCount(apps
);
1662 old_top
= dock
->icon_array
[0];
1664 /* dock->icon_count is set to 1 when dock is created.
1665 * Since Clip is already restored, we want to keep it so for clip,
1666 * but for dock we may change the default top tile, so we set it to 0.
1668 if (type
== WM_DOCK
)
1669 dock
->icon_count
= 0;
1671 for (i
= 0; i
< count
; i
++) {
1672 if (dock
->icon_count
>= dock
->max_icons
) {
1673 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1677 value
= WMGetFromPLArray(apps
, i
);
1678 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1680 dock
->icon_array
[dock
->icon_count
] = aicon
;
1684 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1685 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1688 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1690 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1692 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1693 if (!dock
->collapsed
)
1694 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1696 wRaiseFrame(aicon
->icon
->core
);
1699 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
) {
1704 /* if the first icon is not defined, use the default */
1705 if (dock
->icon_array
[0] == NULL
) {
1706 /* update default icon */
1707 old_top
->x_pos
= dock
->x_pos
;
1708 old_top
->y_pos
= dock
->y_pos
;
1710 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1712 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1714 dock
->icon_array
[0] = old_top
;
1715 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1716 /* we don't need to increment dock->icon_count here because it was
1717 * incremented in the loop above.
1719 } else if (old_top
!= dock
->icon_array
[0]) {
1720 if (old_top
== scr
->clip_icon
)
1721 scr
->clip_icon
= dock
->icon_array
[0];
1723 wAppIconDestroy(old_top
);
1727 WMReleasePropList(dock_state
);
1732 void wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1734 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1735 btn
->drop_launch
= 0;
1736 btn
->paste_launch
= 0;
1738 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1741 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1751 void wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1757 for (i
= 0; i
< dock
->max_icons
; i
++) {
1758 btn
= dock
->icon_array
[i
];
1759 if (!btn
|| !btn
->auto_launch
)
1762 state
= wmalloc(sizeof(WSavedState
));
1763 state
->workspace
= workspace
;
1764 /* TODO: this is klugy and is very difficult to understand
1765 * what's going on. Try to clean up */
1766 wDockLaunchWithState(dock
, btn
, state
);
1770 #ifdef XDND /* was OFFIX */
1771 static WDock
*findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1777 if ((dock
= scr
->dock
) != NULL
) {
1778 for (i
= 0; i
< dock
->max_icons
; i
++) {
1779 if (dock
->icon_array
[i
]
1780 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1786 if (*icon_pos
< 0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
) != NULL
) {
1787 for (i
= 0; i
< dock
->max_icons
; i
++) {
1788 if (dock
->icon_array
[i
]
1789 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1800 int wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
1806 dock
= findDock(scr
, event
, &icon_pos
);
1811 * Return True if the drop was on an application icon window.
1812 * In this case, let the ClientMessage handler redirect the
1813 * message to the app.
1815 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
1818 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
1819 scr
->flags
.dnd_data_convertion_status
= 0;
1821 btn
= dock
->icon_array
[icon_pos
];
1823 if (!btn
->forced_dock
) {
1824 btn
->relaunching
= btn
->running
;
1827 if (btn
->wm_instance
|| btn
->wm_class
) {
1828 WWindowAttributes attr
;
1829 memset(&attr
, 0, sizeof(WWindowAttributes
));
1830 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
1832 if (!attr
.no_appicon
)
1838 btn
->paste_launch
= 0;
1839 btn
->drop_launch
= 1;
1840 scr
->last_dock
= dock
;
1841 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1846 if (!btn
->relaunching
)
1854 Bool
wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
, Bool update_icon
)
1857 Bool lupdate_icon
= False
;
1860 wwin
= icon
->icon
->owner
;
1864 lupdate_icon
= True
;
1866 if (icon
->command
== NULL
) {
1869 command
= GetCommandForWindow(wwin
->client_win
);
1871 icon
->command
= command
;
1873 /* icon->forced_dock = 1; */
1874 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
1876 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
1877 _("Type the command used to launch the application"), &command
)) {
1878 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
1882 icon
->command
= command
;
1888 /* If the target is the dock, reject the icon. If
1889 * the target is the clip, make it an attracted icon
1891 if (dock
->type
== WM_CLIP
) {
1892 icon
->attracted
= 1;
1893 if (!icon
->icon
->shadowed
) {
1894 icon
->icon
->shadowed
= 1;
1895 lupdate_icon
= True
;
1905 for (index
= 1; index
< dock
->max_icons
; index
++)
1906 if (dock
->icon_array
[index
] == NULL
)
1908 /* if (index == dock->max_icons)
1911 assert(index
< dock
->max_icons
);
1913 dock
->icon_array
[index
] = icon
;
1917 icon
->omnipresent
= 0;
1919 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
1920 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
1925 icon
->launching
= 0;
1928 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1929 if (dock
->type
== WM_CLIP
) {
1930 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1931 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1933 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1934 icon
->icon
->core
->descriptor
.parent
= icon
;
1936 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
1937 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
1939 /* Update the icon images */
1941 wIconUpdate(icon
->icon
);
1944 wAppIconPaint(icon
);
1947 save_appicon(icon
, True
);
1949 if (wPreferences
.auto_arrange_icons
)
1950 wArrangeIcons(dock
->screen_ptr
, True
);
1952 #ifdef XDND /* was OFFIX */
1953 if (icon
->command
&& !icon
->dnd_command
) {
1954 int len
= strlen(icon
->command
) + 8;
1955 icon
->dnd_command
= wmalloc(len
);
1956 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
1960 if (icon
->command
&& !icon
->paste_command
) {
1961 int len
= strlen(icon
->command
) + 8;
1962 icon
->paste_command
= wmalloc(len
);
1963 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
1969 static void reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1973 for (index
= 1; index
< dock
->max_icons
; index
++) {
1974 if (dock
->icon_array
[index
] == icon
)
1977 assert(index
< dock
->max_icons
);
1982 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
1983 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
1986 static Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
1991 Bool update_icon
= False
;
1994 return True
; /* No move needed, we're already there */
1999 wwin
= icon
->icon
->owner
;
2002 * For the moment we can't do this if we move icons in Clip from one
2003 * workspace to other, because if we move two or more icons without
2004 * command, the dialog box will not be able to tell us to which of the
2005 * moved icons it applies. -Dan
2007 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
2008 command
= GetCommandForWindow(wwin
->client_win
);
2010 icon
->command
= command
;
2013 /* icon->forced_dock = 1; */
2014 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2015 _("Type the command used to launch the application"), &command
)) {
2016 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2020 icon
->command
= command
;
2031 if (dest
->type
== WM_DOCK
)
2032 wClipMakeIconOmnipresent(icon
, False
);
2034 for (index
= 1; index
< src
->max_icons
; index
++) {
2035 if (src
->icon_array
[index
] == icon
)
2038 assert(index
< src
->max_icons
);
2040 src
->icon_array
[index
] = NULL
;
2043 for (index
= 1; index
< dest
->max_icons
; index
++) {
2044 if (dest
->icon_array
[index
] == NULL
)
2048 assert(index
< dest
->max_icons
);
2050 dest
->icon_array
[index
] = icon
;
2053 /* deselect the icon */
2054 if (icon
->icon
->selected
)
2055 wIconSelect(icon
->icon
);
2057 if (dest
->type
== WM_DOCK
) {
2058 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2059 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2061 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2062 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2065 /* set it to be kept when moving to dock.
2066 * Unless the icon does not have a command set
2068 if (icon
->command
&& dest
->type
== WM_DOCK
) {
2069 icon
->attracted
= 0;
2070 if (icon
->icon
->shadowed
) {
2071 icon
->icon
->shadowed
= 0;
2074 save_appicon(icon
, True
);
2077 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2083 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2084 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2088 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2090 /* Update the icon images */
2092 wIconUpdate(icon
->icon
);
2095 wAppIconPaint(icon
);
2100 void wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2103 Bool update_icon
= False
;
2105 /* make the settings panel be closed */
2107 DestroyDockAppSettingsPanel(icon
->panel
);
2109 /* This must be called before icon->dock is set to NULL.
2110 * Don't move it. -Dan
2112 wClipMakeIconOmnipresent(icon
, False
);
2116 icon
->attracted
= 0;
2117 icon
->auto_launch
= 0;
2118 if (icon
->icon
->shadowed
) {
2119 icon
->icon
->shadowed
= 0;
2123 /* deselect the icon */
2124 if (icon
->icon
->selected
)
2125 wIconSelect(icon
->icon
);
2127 if (icon
->command
) {
2128 wfree(icon
->command
);
2129 icon
->command
= NULL
;
2131 #ifdef XDND /* was OFFIX */
2132 if (icon
->dnd_command
) {
2133 wfree(icon
->dnd_command
);
2134 icon
->dnd_command
= NULL
;
2137 if (icon
->paste_command
) {
2138 wfree(icon
->paste_command
);
2139 icon
->paste_command
= NULL
;
2142 for (index
= 1; index
< dock
->max_icons
; index
++)
2143 if (dock
->icon_array
[index
] == icon
)
2146 assert(index
< dock
->max_icons
);
2147 dock
->icon_array
[index
] = NULL
;
2153 /* if the dock is not attached to an application or
2154 * the application did not set the appropriate hints yet,
2155 * destroy the icon */
2156 if (!icon
->running
|| !wApplicationOf(icon
->main_window
)) {
2157 wAppIconDestroy(icon
);
2159 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2160 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2161 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2162 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2163 icon
->icon
->core
->descriptor
.parent
= icon
;
2165 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2167 /* Update the icon images */
2169 wIconUpdate(icon
->icon
);
2172 wAppIconPaint(icon
);
2174 if (wPreferences
.auto_arrange_icons
)
2175 wArrangeIcons(dock
->screen_ptr
, True
);
2177 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2182 * returns the closest Dock slot index for the passed
2185 * Returns False if icon can't be docked.
2187 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2190 Bool
wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2192 WScreen
*scr
= dock
->screen_ptr
;
2195 int i
, offset
= ICON_SIZE
/ 2;
2196 WAppIcon
*aicon
= NULL
;
2197 WAppIcon
*nicon
= NULL
;
2200 /* TODO: XINERAMA, for these */
2201 max_y_icons
= scr
->scr_height
/ ICON_SIZE
- 1;
2203 if (wPreferences
.flags
.noupdates
)
2209 /* if the dock is full */
2210 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
))
2213 /* exact position */
2215 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2217 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2220 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2222 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2224 /* check if the icon is outside the screen boundaries */
2229 rect
.pos
.x
= dx
+ ex_x
* ICON_SIZE
;
2230 rect
.pos
.y
= dy
+ ex_y
* ICON_SIZE
;
2231 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2233 wGetRectPlacementInfo(scr
, rect
, &flags
);
2234 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
2238 if (dock
->type
== WM_DOCK
) {
2239 if (icon
->dock
!= dock
&& ex_x
!= 0)
2243 for (i
= 0; i
< dock
->max_icons
; i
++) {
2244 nicon
= dock
->icon_array
[i
];
2245 if (nicon
&& nicon
->yindex
== ex_y
) {
2252 int sig
, done
, closest
;
2254 /* Possible cases when redocking:
2256 * icon dragged out of range of any slot -> false
2257 * icon dragged to range of free slot
2258 * icon dragged to range of same slot
2259 * icon dragged to range of different icon
2261 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2264 if (ex_y
>= 0 && ex_y
<= max_y_icons
&& (aicon
== icon
|| !aicon
)) {
2270 /* start looking at the upper slot or lower? */
2271 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2278 /* look for closest free slot */
2279 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2283 closest
= sig
* (i
/ 2) + ex_y
;
2284 /* check if this slot is used */
2286 for (j
= 0; j
< dock
->max_icons
; j
++) {
2287 if (dock
->icon_array
[j
]
2288 && dock
->icon_array
[j
]->yindex
== closest
) {
2289 /* slot is used by someone else */
2290 if (dock
->icon_array
[j
] != icon
)
2298 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2299 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2300 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2305 } else { /* !redocking */
2307 /* if slot is free and the icon is close enough, return it */
2308 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2318 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2319 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+ 1;
2322 for (k
= start
; k
< stop
; k
++) {
2323 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2326 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2327 nicon
= tmp
->icon_array
[i
];
2328 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2336 for (k
= start
; k
< stop
; k
++) {
2337 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2340 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2341 nicon
= tmp
->icon_array
[i
];
2342 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2343 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2344 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2353 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2362 static int onScreen(WScreen
*scr
, int x
, int y
, int sx
, int ex
, int sy
, int ey
)
2364 WMRect rect
= wmkrect(x
, y
, ICON_SIZE
, ICON_SIZE
);
2367 wGetRectPlacementInfo(scr
, rect
, &flags
);
2369 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2373 * returns true if it can find a free slot in the dock,
2374 * in which case it changes x_pos and y_pos accordingly.
2375 * Else returns false.
2377 Bool
wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2379 WScreen
*scr
= dock
->screen_ptr
;
2381 WAppIconChain
*chain
;
2382 unsigned char *slot_map
;
2386 int i
, done
= False
;
2388 int sx
= 0, sy
= 0, ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2389 int extra_count
= 0;
2391 if (dock
->type
== WM_CLIP
&& dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2392 extra_count
= scr
->global_icon_count
;
2394 /* if the dock is full */
2395 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
)
2398 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2399 if (scr
->dock
->on_right_side
)
2400 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2402 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2405 if (ex
< dock
->x_pos
)
2407 if (sx
> dock
->x_pos
+ ICON_SIZE
)
2408 sx
= dock
->x_pos
+ ICON_SIZE
;
2415 /* check if clip is in a corner */
2416 if (dock
->type
== WM_CLIP
) {
2417 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2419 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2421 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2423 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2431 /* If the clip is in the corner, use only slots that are in the border
2433 if (corner
!= C_NONE
) {
2437 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2438 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2439 hmap
= wmalloc(hcount
+ 1);
2440 vmap
= wmalloc(vcount
+ 1);
2442 /* mark used positions */
2445 for (i
= 0; i
< dock
->max_icons
; i
++) {
2446 btn
= dock
->icon_array
[i
];
2450 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2451 vmap
[btn
->yindex
] = 1;
2452 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2453 hmap
[btn
->xindex
] = 1;
2455 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2457 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2458 vmap
[btn
->yindex
] = 1;
2459 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2460 hmap
[btn
->xindex
] = 1;
2464 for (i
= 0; i
< dock
->max_icons
; i
++) {
2465 btn
= dock
->icon_array
[i
];
2469 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2470 vmap
[btn
->yindex
] = 1;
2471 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2472 hmap
[-btn
->xindex
] = 1;
2474 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2476 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2477 vmap
[btn
->yindex
] = 1;
2478 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2479 hmap
[-btn
->xindex
] = 1;
2483 for (i
= 0; i
< dock
->max_icons
; i
++) {
2484 btn
= dock
->icon_array
[i
];
2488 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2489 vmap
[-btn
->yindex
] = 1;
2490 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2491 hmap
[btn
->xindex
] = 1;
2493 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2495 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2496 vmap
[-btn
->yindex
] = 1;
2497 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2498 hmap
[btn
->xindex
] = 1;
2503 for (i
= 0; i
< dock
->max_icons
; i
++) {
2504 btn
= dock
->icon_array
[i
];
2508 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2509 vmap
[-btn
->yindex
] = 1;
2510 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2511 hmap
[-btn
->xindex
] = 1;
2513 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2515 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2516 vmap
[-btn
->yindex
] = 1;
2517 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2518 hmap
[-btn
->xindex
] = 1;
2524 /* search a vacant slot */
2525 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2526 if (i
< vcount
&& vmap
[i
] == 0) {
2532 } else if (i
< hcount
&& hmap
[i
] == 0) {
2542 /* If found a slot, translate and return */
2544 if (corner
== C_NW
|| corner
== C_NE
)
2549 if (corner
== C_NE
|| corner
== C_SE
)
2556 /* else, try to find a slot somewhere else */
2559 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2560 * placed outside of screen */
2561 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2563 /* In the worst case (the clip is in the corner of the screen),
2564 * the amount of icons that fit in the clip is smaller.
2565 * Double the map to get a safe value.
2569 r
= (mwidth
- 1) / 2;
2571 slot_map
= wmalloc(mwidth
* mwidth
);
2573 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2575 /* mark used slots in the map. If the slot falls outside the map
2576 * (for example, when all icons are placed in line), ignore them. */
2577 for (i
= 0; i
< dock
->max_icons
; i
++) {
2578 btn
= dock
->icon_array
[i
];
2580 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2583 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
)
2584 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2586 /* Find closest slot from the center that is free by scanning the
2587 * map from the center to outward in circular passes.
2588 * This will not result in a neat layout, but will be optimal
2589 * in the sense that there will not be holes left.
2592 for (i
= 1; i
<= r
&& !done
; i
++) {
2595 /* top and bottom parts of the ring */
2596 for (x
= -i
; x
<= i
&& !done
; x
++) {
2597 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2599 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2600 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2607 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2608 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2615 /* left and right parts of the ring */
2616 for (y
= -i
+ 1; y
<= i
- 1; y
++) {
2617 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2619 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2620 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2627 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2628 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2641 static void moveDock(WDock
*dock
, int new_x
, int new_y
)
2646 dock
->x_pos
= new_x
;
2647 dock
->y_pos
= new_y
;
2648 for (i
= 0; i
< dock
->max_icons
; i
++) {
2649 btn
= dock
->icon_array
[i
];
2651 btn
->x_pos
= new_x
+ btn
->xindex
* ICON_SIZE
;
2652 btn
->y_pos
= new_y
+ btn
->yindex
* ICON_SIZE
;
2653 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2658 static void swapDock(WDock
*dock
)
2660 WScreen
*scr
= dock
->screen_ptr
;
2664 if (dock
->on_right_side
)
2665 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2667 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2669 for (i
= 0; i
< dock
->max_icons
; i
++) {
2670 btn
= dock
->icon_array
[i
];
2673 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2677 wScreenUpdateUsableArea(scr
);
2680 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2682 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2688 cmdline
= ExpandOptions(scr
, command
);
2690 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2698 wtokensplit(cmdline
, &argv
, &argc
);
2708 if ((pid
= fork()) == 0) {
2712 SetupEnvironment(scr
);
2718 args
= malloc(sizeof(char *) * (argc
+ 1));
2722 for (i
= 0; i
< argc
; i
++)
2726 execvp(argv
[0], args
);
2729 wtokenfree(argv
, argc
);
2733 state
= wmalloc(sizeof(WSavedState
));
2735 state
->miniaturized
= -1;
2737 if (btn
->dock
== scr
->dock
|| btn
->omnipresent
)
2738 state
->workspace
= -1;
2740 state
->workspace
= scr
->current_workspace
;
2742 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
2743 wAddDeathHandler(pid
, (WDeathHandler
*) trackDeadProcess
, btn
->dock
);
2751 void wDockHideIcons(WDock
*dock
)
2758 for (i
= 1; i
< dock
->max_icons
; i
++) {
2759 if (dock
->icon_array
[i
])
2760 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2764 dockIconPaint(dock
->icon_array
[0]);
2767 void wDockShowIcons(WDock
*dock
)
2775 btn
= dock
->icon_array
[0];
2776 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2778 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2779 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2781 for (i
= 1; i
< dock
->max_icons
; i
++) {
2782 if (dock
->icon_array
[i
]) {
2783 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
, btn
->icon
->core
);
2788 if (!dock
->collapsed
) {
2789 for (i
= 1; i
< dock
->max_icons
; i
++) {
2790 if (dock
->icon_array
[i
])
2791 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2799 void wDockLower(WDock
*dock
)
2803 for (i
= 0; i
< dock
->max_icons
; i
++) {
2804 if (dock
->icon_array
[i
])
2805 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2809 void wDockRaise(WDock
*dock
)
2813 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
2814 if (dock
->icon_array
[i
])
2815 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2819 void wDockRaiseLower(WDock
*dock
)
2821 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2822 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2823 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2829 void wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
2831 icon
->launching
= 0;
2832 icon
->relaunching
= 0;
2833 dockIconPaint(icon
);
2836 WAppIcon
*wDockFindIconForWindow(WDock
*dock
, Window window
)
2841 for (i
= 0; i
< dock
->max_icons
; i
++) {
2842 icon
= dock
->icon_array
[i
];
2843 if (icon
&& icon
->main_window
== window
)
2849 void wDockTrackWindowLaunch(WDock
*dock
, Window window
)
2852 char *wm_class
, *wm_instance
;
2854 Bool firstPass
= True
;
2856 char *command
= NULL
;
2858 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) || (!wm_class
&& !wm_instance
))
2861 command
= GetCommandForWindow(window
);
2863 for (i
= 0; i
< dock
->max_icons
; i
++) {
2864 icon
= dock
->icon_array
[i
];
2868 /* app is already attached to icon */
2869 if (icon
->main_window
== window
) {
2874 if ((icon
->wm_instance
|| icon
->wm_class
)
2875 && (icon
->launching
|| !icon
->running
)) {
2877 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0)
2880 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0)
2883 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0)
2886 if (!icon
->relaunching
) {
2889 /* Possibly an application that was docked with dockit,
2890 * but the user did not update WMState to indicate that
2891 * it was docked by force */
2892 wapp
= wApplicationOf(window
);
2894 icon
->forced_dock
= 1;
2897 if (!icon
->forced_dock
)
2898 icon
->main_window
= window
;
2901 if (!wPreferences
.no_animations
&& !icon
->launching
&&
2902 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
2906 icon
->launching
= 1;
2907 dockIconPaint(icon
);
2909 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
2910 wm_instance
, wm_class
, TILE_NORMAL
);
2911 /* XXX: can: aicon->icon == NULL ? */
2912 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
2913 wAppIconMove(aicon
, x0
, y0
);
2914 /* Should this always be lowered? -Dan */
2916 wLowerFrame(aicon
->icon
->core
);
2917 XMapWindow(dpy
, aicon
->icon
->core
->window
);
2918 aicon
->launching
= 1;
2919 wAppIconPaint(aicon
);
2920 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
2921 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
2922 wAppIconDestroy(aicon
);
2924 wDockFinishLaunch(dock
, icon
);
2929 if (firstPass
&& !found
) {
2943 void wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
2945 if (!wPreferences
.flags
.noclip
) {
2946 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
2947 if (scr
->current_workspace
!= workspace
) {
2948 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
2949 WAppIconChain
*chain
= scr
->global_icons
;
2952 moveIconBetweenDocks(chain
->aicon
->dock
,
2953 scr
->workspaces
[workspace
]->clip
,
2954 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
2955 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
2956 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
2957 chain
= chain
->next
;
2960 wDockHideIcons(old_clip
);
2961 if (old_clip
->auto_raise_lower
) {
2962 if (old_clip
->auto_raise_magic
) {
2963 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
2964 old_clip
->auto_raise_magic
= NULL
;
2966 wDockLower(old_clip
);
2968 if (old_clip
->auto_collapse
) {
2969 if (old_clip
->auto_expand_magic
) {
2970 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
2971 old_clip
->auto_expand_magic
= NULL
;
2973 old_clip
->collapsed
= 1;
2975 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
2980 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
2985 for (i
= 0; i
< dock
->max_icons
; i
++) {
2986 icon
= dock
->icon_array
[i
];
2990 if (icon
->launching
&& icon
->pid
== pid
) {
2991 if (!icon
->relaunching
) {
2993 icon
->main_window
= None
;
2995 wDockFinishLaunch(dock
, icon
);
2997 if (status
== 111) {
3002 if (icon
->drop_launch
)
3003 cmd
= icon
->dnd_command
;
3006 if (icon
->paste_launch
)
3007 cmd
= icon
->paste_command
;
3009 cmd
= icon
->command
;
3011 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3013 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3020 static void toggleLowered(WDock
*dock
)
3025 /* lower/raise Dock */
3026 if (!dock
->lowered
) {
3027 newlevel
= WMNormalLevel
;
3030 newlevel
= WMDockLevel
;
3034 for (i
= 0; i
< dock
->max_icons
; i
++) {
3035 tmp
= dock
->icon_array
[i
];
3039 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3041 wLowerFrame(tmp
->icon
->core
);
3044 if (dock
->type
== WM_DOCK
)
3045 wScreenUpdateUsableArea(dock
->screen_ptr
);
3048 static void toggleCollapsed(WDock
*dock
)
3050 if (dock
->collapsed
) {
3051 dock
->collapsed
= 0;
3052 wDockShowIcons(dock
);
3054 dock
->collapsed
= 1;
3055 wDockHideIcons(dock
);
3059 static void openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3061 WScreen
*scr
= dock
->screen_ptr
;
3062 WObjDescriptor
*desc
;
3064 WApplication
*wapp
= NULL
;
3068 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3070 if (dock
->type
== WM_DOCK
) {
3072 entry
= dock
->menu
->entries
[index
];
3073 entry
->flags
.indicator_on
= !dock
->lowered
;
3074 entry
->clientdata
= dock
;
3075 dock
->menu
->flags
.realized
= 0;
3078 if (scr
->clip_options
)
3079 updateClipOptionsMenu(scr
->clip_options
, dock
);
3081 n_selected
= numberOfSelectedIcons(dock
);
3083 /* Rename Workspace */
3084 entry
= dock
->menu
->entries
[++index
];
3085 if (aicon
== scr
->clip_icon
) {
3086 entry
->callback
= renameCallback
;
3087 entry
->clientdata
= dock
;
3088 entry
->flags
.indicator
= 0;
3089 entry
->text
= _("Rename Workspace");
3091 entry
->callback
= omnipresentCallback
;
3092 entry
->clientdata
= aicon
;
3093 if (n_selected
> 0) {
3094 entry
->flags
.indicator
= 0;
3095 entry
->text
= _("Toggle Omnipresent");
3097 entry
->flags
.indicator
= 1;
3098 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3099 entry
->flags
.indicator_type
= MI_CHECK
;
3100 entry
->text
= _("Omnipresent");
3104 /* select/unselect icon */
3105 entry
= dock
->menu
->entries
[++index
];
3106 entry
->clientdata
= aicon
;
3107 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3108 wMenuSetEnabled(dock
->menu
, index
, aicon
!= scr
->clip_icon
);
3110 /* select/unselect all icons */
3111 entry
= dock
->menu
->entries
[++index
];
3112 entry
->clientdata
= aicon
;
3114 entry
->text
= _("Unselect All Icons");
3116 entry
->text
= _("Select All Icons");
3118 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3121 entry
= dock
->menu
->entries
[++index
];
3122 entry
->clientdata
= aicon
;
3124 entry
->text
= _("Keep Icons");
3126 entry
->text
= _("Keep Icon");
3128 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3130 /* this is the workspace submenu part */
3131 entry
= dock
->menu
->entries
[++index
];
3133 entry
->text
= _("Move Icons To");
3135 entry
->text
= _("Move Icon To");
3137 if (scr
->clip_submenu
)
3138 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3140 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3142 /* remove icon(s) */
3143 entry
= dock
->menu
->entries
[++index
];
3144 entry
->clientdata
= aicon
;
3146 entry
->text
= _("Remove Icons");
3148 entry
->text
= _("Remove Icon");
3150 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3152 /* attract icon(s) */
3153 entry
= dock
->menu
->entries
[++index
];
3154 entry
->clientdata
= aicon
;
3156 dock
->menu
->flags
.realized
= 0;
3157 wMenuRealize(dock
->menu
);
3160 if (aicon
->icon
->owner
)
3161 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3166 entry
= dock
->menu
->entries
[++index
];
3167 entry
->clientdata
= aicon
;
3168 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3171 entry
= dock
->menu
->entries
[++index
];
3172 entry
->clientdata
= aicon
;
3173 if (wapp
&& wapp
->flags
.hidden
)
3174 entry
->text
= _("Unhide Here");
3176 entry
->text
= _("Bring Here");
3178 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3181 entry
= dock
->menu
->entries
[++index
];
3182 entry
->clientdata
= aicon
;
3183 if (wapp
&& wapp
->flags
.hidden
)
3184 entry
->text
= _("Unhide");
3186 entry
->text
= _("Hide");
3188 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3191 entry
= dock
->menu
->entries
[++index
];
3192 entry
->clientdata
= aicon
;
3193 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3196 entry
= dock
->menu
->entries
[++index
];
3197 entry
->clientdata
= aicon
;
3198 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3200 if (!dock
->menu
->flags
.realized
)
3201 wMenuRealize(dock
->menu
);
3203 if (dock
->type
== WM_CLIP
) {
3204 /*x_pos = event->xbutton.x_root+2; */
3205 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3208 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3209 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3212 x_pos
= dock
->on_right_side
? scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3215 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3217 /* allow drag select */
3218 event
->xany
.send_event
= True
;
3219 desc
= &dock
->menu
->menu
->descriptor
;
3220 (*desc
->handle_mousedown
) (desc
, event
);
3223 /******************************************************************/
3224 static void iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3226 WAppIcon
*btn
= desc
->parent
;
3227 WDock
*dock
= btn
->dock
;
3228 WApplication
*wapp
= NULL
;
3231 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3232 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3234 assert(wapp
!= NULL
);
3236 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3238 /* go to the last workspace that the user worked on the app */
3239 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
&& !unhideHere
)
3240 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3242 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3244 if (event
->xbutton
.state
& MOD_MASK
)
3245 wHideOtherApplications(btn
->icon
->owner
);
3247 if (event
->xbutton
.button
== Button1
) {
3248 if (event
->xbutton
.state
& MOD_MASK
) {
3249 /* raise/lower dock */
3250 toggleLowered(dock
);
3251 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3252 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
)
3253 toggleCollapsed(dock
);
3255 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3256 } else if (btn
->command
) {
3257 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3258 launchDockedApplication(btn
, False
);
3264 static void handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3266 WScreen
*scr
= dock
->screen_ptr
;
3267 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3270 int grabbed
= 0, swapped
= 0, done
;
3271 Pixmap ghost
= None
;
3272 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3274 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3275 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3276 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
)
3277 wwarning("pointer grab failed for dock move");
3280 for (x
= 0; x
< dock
->max_icons
; x
++) {
3281 if (dock
->icon_array
[x
] != NULL
&& dock
->icon_array
[x
]->yindex
> y
)
3282 y
= dock
->icon_array
[x
]->yindex
;
3285 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
* y
);
3289 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3290 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3297 /* It means the cursor moved so fast that it entered
3298 * something else (if moving slowly, it would have
3299 * stayed in the dock that is being moved. Ignore such
3300 * "spurious" EnterNotifiy's */
3305 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3306 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3307 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3308 | ButtonReleaseMask
| ButtonPressMask
,
3309 wCursor
[WCUR_MOVE
], CurrentTime
);
3314 if (dock
->type
== WM_CLIP
) {
3315 x
= ev
.xmotion
.x_root
- ofs_x
;
3316 y
= ev
.xmotion
.y_root
- ofs_y
;
3317 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3319 moveDock(dock
, x
, y
);
3321 /* move vertically if pointer is inside the dock */
3322 if ((dock
->on_right_side
&& ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3323 || (!dock
->on_right_side
&& ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
* 2)) {
3325 x
= ev
.xmotion
.x_root
- ofs_x
;
3326 y
= ev
.xmotion
.y_root
- ofs_y
;
3327 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3328 moveDock(dock
, dock
->x_pos
, y
);
3330 /* move horizontally to change sides */
3331 x
= ev
.xmotion
.x_root
- ofs_x
;
3332 if (!dock
->on_right_side
) {
3335 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
* 2) {
3336 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
- ICON_SIZE
3337 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3338 if (superfluous
&& ghost
== None
) {
3339 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3340 scr
->scr_width
- ICON_SIZE
3341 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3342 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3343 XClearWindow(dpy
, scr
->dock_shadow
);
3345 XMapRaised(dpy
, scr
->dock_shadow
);
3348 if (superfluous
&& ghost
!= None
) {
3349 XFreePixmap(dpy
, ghost
);
3352 XUnmapWindow(dpy
, scr
->dock_shadow
);
3357 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3358 XMoveWindow(dpy
, scr
->dock_shadow
, DOCK_EXTRA_SPACE
, dock
->y_pos
);
3359 if (superfluous
&& ghost
== None
) {
3360 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3361 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3362 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3363 XClearWindow(dpy
, scr
->dock_shadow
);
3365 XMapRaised(dpy
, scr
->dock_shadow
);
3368 XUnmapWindow(dpy
, scr
->dock_shadow
);
3370 if (superfluous
&& ghost
!= None
) {
3371 XFreePixmap(dpy
, ghost
);
3383 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3385 XUngrabPointer(dpy
, CurrentTime
);
3386 XUnmapWindow(dpy
, scr
->dock_shadow
);
3387 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3388 if (dock
->type
== WM_DOCK
) {
3391 dock
->on_right_side
= 1;
3393 dock
->on_right_side
= 0;
3395 wArrangeIcons(scr
, False
);
3404 XFreePixmap(dpy
, ghost
);
3405 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3409 static Bool
handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3411 WScreen
*scr
= dock
->screen_ptr
;
3413 WIcon
*icon
= aicon
->icon
;
3414 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3415 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3417 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3418 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3419 int shad_x
= x
, shad_y
= y
;
3420 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3422 Pixmap ghost
= None
;
3424 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3425 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3426 Bool hasMoved
= False
;
3428 if (wPreferences
.flags
.noupdates
)
3431 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3432 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3433 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3436 if (!(event
->xbutton
.state
& MOD_MASK
))
3437 wRaiseFrame(icon
->core
);
3439 if (!wPreferences
.flags
.noclip
)
3440 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3442 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3444 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3447 wins
[0] = icon
->core
->window
;
3448 wins
[1] = scr
->dock_shadow
;
3449 XRestackWindows(dpy
, wins
, 2);
3450 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
3452 if (icon
->pixmap
!= None
)
3453 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3455 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3457 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3458 XClearWindow(dpy
, scr
->dock_shadow
);
3460 XMapWindow(dpy
, scr
->dock_shadow
);
3465 XMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3466 | ButtonMotionMask
| ExposureMask
, &ev
);
3475 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3476 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3477 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3478 | ButtonReleaseMask
| ButtonPressMask
,
3479 wCursor
[WCUR_MOVE
], CurrentTime
);
3488 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3489 if (i
== scr
->current_workspace
)
3491 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3495 x
= ev
.xmotion
.x_root
- ofs_x
;
3496 y
= ev
.xmotion
.y_root
- ofs_y
;
3497 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3500 if (last_dock
!= dock
&& collapsed
) {
3501 last_dock
->collapsed
= 1;
3502 wDockHideIcons(last_dock
);
3505 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3506 dock
->collapsed
= 0;
3507 wDockShowIcons(dock
);
3509 if (dock
->auto_raise_lower
)
3513 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3516 if (last_dock
!= dock2
&& collapsed
) {
3517 last_dock
->collapsed
= 1;
3518 wDockHideIcons(last_dock
);
3521 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3522 dock2
->collapsed
= 0;
3523 wDockShowIcons(dock2
);
3525 if (dock2
->auto_raise_lower
)
3530 if (aicon
->launching
|| aicon
->lock
|| (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3531 || (!aicon
->running
&& tmp
)) {
3532 shad_x
= last_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3533 shad_y
= last_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3535 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3538 XMapWindow(dpy
, scr
->dock_shadow
);
3543 XUnmapWindow(dpy
, scr
->dock_shadow
);
3547 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3554 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3556 XUngrabPointer(dpy
, CurrentTime
);
3558 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3559 XUnmapWindow(dpy
, scr
->dock_shadow
);
3561 reattachIcon(dock
, aicon
, ix
, iy
);
3562 if (clip
&& dock
!= clip
&& clip
->auto_raise_lower
)
3565 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3567 /* Slide it back if dock rejected it */
3568 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
, aicon
->y_pos
);
3569 reattachIcon(dock
, aicon
, aicon
->xindex
, aicon
->yindex
);
3571 if (last_dock
->type
== WM_CLIP
&& last_dock
->auto_collapse
)
3578 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3579 /* We need to deselect it, even if is deselected in
3580 * wDockDetach(), because else DoKaboom() will fail.
3582 if (aicon
->icon
->selected
)
3583 wIconSelect(aicon
->icon
);
3585 DoKaboom(scr
, aicon
->icon
->core
->window
, x
, y
);
3588 if (clip
&& clip
->auto_raise_lower
)
3590 wDockDetach(dock
, aicon
);
3593 last_dock
->collapsed
= 1;
3594 wDockHideIcons(last_dock
);
3599 XFreePixmap(dpy
, ghost
);
3600 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3604 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3605 if (i
== scr
->current_workspace
)
3607 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3613 return False
; /* never reached */
3616 static int getClipButton(int px
, int py
)
3618 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3620 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3623 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3624 return CLIP_FORWARD
;
3625 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3631 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3634 int done
, direction
, new_ws
;
3636 WDock
*clip
= scr
->clip_icon
->dock
;
3638 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3640 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3641 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3643 wClipIconPaint(scr
->clip_icon
);
3646 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3653 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3654 if (new_dir
!= direction
) {
3655 direction
= new_dir
;
3656 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3657 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3658 wClipIconPaint(scr
->clip_icon
);
3666 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3671 clip
->lclip_button_pushed
= 0;
3672 clip
->rclip_button_pushed
= 0;
3674 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3676 if (direction
== CLIP_FORWARD
) {
3677 if (scr
->current_workspace
< scr
->workspace_count
- 1)
3678 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3679 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
- 1)
3680 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3681 else if (wPreferences
.ws_cycle
)
3682 wWorkspaceChange(scr
, 0);
3683 } else if (direction
== CLIP_REWIND
) {
3684 if (scr
->current_workspace
> 0)
3685 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
3686 else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
)
3687 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
3690 wClipIconPaint(scr
->clip_icon
);
3693 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3695 WAppIcon
*aicon
= desc
->parent
;
3696 WDock
*dock
= aicon
->dock
;
3697 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3699 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3702 scr
->last_dock
= dock
;
3704 if (dock
->menu
->flags
.mapped
)
3705 wMenuUnmap(dock
->menu
);
3707 if (IsDoubleClick(scr
, event
)) {
3708 /* double-click was not in the main clip icon */
3709 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3710 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3711 iconDblClick(desc
, event
);
3716 if (event
->xbutton
.button
== Button1
) {
3717 if (event
->xbutton
.state
& MOD_MASK
)
3722 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
&& dock
->type
!= WM_DOCK
) {
3723 wIconSelect(aicon
->icon
);
3727 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3728 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
3729 && dock
->type
== WM_CLIP
)
3730 handleClipChangeWorkspace(scr
, event
);
3732 handleDockMove(dock
, aicon
, event
);
3734 Bool hasMoved
= handleIconMove(dock
, aicon
, event
);
3735 if (wPreferences
.single_click
&& !hasMoved
)
3736 iconDblClick(desc
, event
);
3738 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&& aicon
== scr
->clip_icon
) {
3739 if (!scr
->clip_ws_menu
) {
3740 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3742 if (scr
->clip_ws_menu
) {
3743 WMenu
*wsMenu
= scr
->clip_ws_menu
;
3746 wWorkspaceMenuUpdate(scr
, wsMenu
);
3748 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
3751 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
3752 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
3754 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
3756 desc
= &wsMenu
->menu
->descriptor
;
3757 event
->xany
.send_event
= True
;
3758 (*desc
->handle_mousedown
) (desc
, event
);
3760 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
3761 (event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
) {
3762 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3763 } else if (event
->xbutton
.button
== Button3
) {
3764 if (event
->xbutton
.send_event
&&
3765 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3766 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3767 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3768 wwarning("pointer grab failed for dockicon menu");
3772 openDockMenu(dock
, aicon
, event
);
3773 } else if (event
->xbutton
.button
== Button2
) {
3774 WAppIcon
*btn
= desc
->parent
;
3776 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3777 launchDockedApplication(btn
, True
);
3781 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3783 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3787 assert(event
->type
== EnterNotify
);
3789 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3792 scr
= btn
->icon
->core
->screen_ptr
;
3793 if (!btn
->omnipresent
)
3796 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3798 if (!dock
|| dock
->type
!= WM_CLIP
)
3801 /* The auto raise/lower code */
3802 if (dock
->auto_lower_magic
) {
3803 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3804 dock
->auto_lower_magic
= NULL
;
3806 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
)
3807 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
, clipAutoRaise
, (void *)dock
);
3809 /* The auto expand/collapse code */
3810 if (dock
->auto_collapse_magic
) {
3811 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3812 dock
->auto_collapse_magic
= NULL
;
3814 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
)
3815 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
, clipAutoExpand
, (void *)dock
);
3818 static void clipLeave(WDock
*dock
)
3821 WObjDescriptor
*desc
= NULL
;
3823 if (!dock
|| dock
->type
!= WM_CLIP
)
3826 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
3827 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3828 (XPointer
*) & desc
) != XCNOENT
3829 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
3830 && ((WAppIcon
*) desc
->parent
)->dock
&& ((WAppIcon
*) desc
->parent
)->dock
->type
== WM_CLIP
) {
3831 /* We didn't left the Clip yet */
3832 XPutBackEvent(dpy
, &event
);
3836 XPutBackEvent(dpy
, &event
);
3838 /* We entered a withdrawn window, so we're still in Clip */
3842 if (dock
->auto_raise_magic
) {
3843 WMDeleteTimerHandler(dock
->auto_raise_magic
);
3844 dock
->auto_raise_magic
= NULL
;
3846 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
)
3847 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
, clipAutoLower
, (void *)dock
);
3849 if (dock
->auto_expand_magic
) {
3850 WMDeleteTimerHandler(dock
->auto_expand_magic
);
3851 dock
->auto_expand_magic
= NULL
;
3853 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
)
3854 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
, clipAutoCollapse
, (void *)dock
);
3857 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
3859 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3861 assert(event
->type
== LeaveNotify
);
3863 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3866 clipLeave(btn
->dock
);
3869 static void clipAutoCollapse(void *cdata
)
3871 WDock
*dock
= (WDock
*) cdata
;
3873 if (dock
->type
!= WM_CLIP
)
3876 if (dock
->auto_collapse
) {
3877 dock
->collapsed
= 1;
3878 wDockHideIcons(dock
);
3880 dock
->auto_collapse_magic
= NULL
;
3883 static void clipAutoExpand(void *cdata
)
3885 WDock
*dock
= (WDock
*) cdata
;
3887 if (dock
->type
!= WM_CLIP
)
3890 if (dock
->auto_collapse
) {
3891 dock
->collapsed
= 0;
3892 wDockShowIcons(dock
);
3894 dock
->auto_expand_magic
= NULL
;
3897 static void clipAutoLower(void *cdata
)
3899 WDock
*dock
= (WDock
*) cdata
;
3901 if (dock
->type
!= WM_CLIP
)
3904 if (dock
->auto_raise_lower
)
3907 dock
->auto_lower_magic
= NULL
;
3910 static void clipAutoRaise(void *cdata
)
3912 WDock
*dock
= (WDock
*) cdata
;
3914 if (dock
->type
!= WM_CLIP
)
3917 if (dock
->auto_raise_lower
)
3920 dock
->auto_raise_magic
= NULL
;
3923 static Bool
iconCanBeOmnipresent(WAppIcon
*aicon
)
3925 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3930 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3931 clip
= scr
->workspaces
[i
]->clip
;
3933 if (clip
== aicon
->dock
)
3936 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
3937 return False
; /* Clip is full in some workspace */
3939 for (j
= 0; j
< clip
->max_icons
; j
++) {
3940 btn
= clip
->icon_array
[j
];
3941 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
3949 int wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
3951 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3952 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
3953 int status
= WO_SUCCESS
;
3955 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== scr
->clip_icon
)
3956 return WO_NOT_APPLICABLE
;
3958 if (aicon
->omnipresent
== omnipresent
)
3962 if (iconCanBeOmnipresent(aicon
)) {
3963 aicon
->omnipresent
= 1;
3964 new_entry
= wmalloc(sizeof(WAppIconChain
));
3965 new_entry
->aicon
= aicon
;
3966 new_entry
->next
= scr
->global_icons
;
3967 scr
->global_icons
= new_entry
;
3968 scr
->global_icon_count
++;
3970 aicon
->omnipresent
= 0;
3974 aicon
->omnipresent
= 0;
3975 if (aicon
== scr
->global_icons
->aicon
) {
3976 tmp
= scr
->global_icons
->next
;
3977 wfree(scr
->global_icons
);
3978 scr
->global_icons
= tmp
;
3979 scr
->global_icon_count
--;
3981 tmp
= scr
->global_icons
;
3983 if (tmp
->next
->aicon
== aicon
) {
3984 tmp1
= tmp
->next
->next
;
3987 scr
->global_icon_count
--;
3995 wAppIconPaint(aicon
);