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 int onScreen(WScreen
*scr
, int x
, int y
);
123 static void make_keys(void)
125 if (dCommand
!= NULL
)
128 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
129 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
131 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
133 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
134 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
135 dName
= WMRetainPropList(WMCreatePLString("Name"));
136 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
137 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
138 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
139 dNo
= WMRetainPropList(WMCreatePLString("No"));
140 dHost
= WMRetainPropList(WMCreatePLString("Host"));
142 dPosition
= WMCreatePLString("Position");
143 dApplications
= WMCreatePLString("Applications");
144 dLowered
= WMCreatePLString("Lowered");
145 dCollapsed
= WMCreatePLString("Collapsed");
146 dAutoCollapse
= WMCreatePLString("AutoCollapse");
147 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
148 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
150 dOmnipresent
= WMCreatePLString("Omnipresent");
152 dDock
= WMCreatePLString("Dock");
153 dClip
= WMCreatePLString("Clip");
156 static void renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
158 WDock
*dock
= entry
->clientdata
;
163 assert(entry
->clientdata
!= NULL
);
165 wspace
= dock
->screen_ptr
->current_workspace
;
167 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
169 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+ 1);
170 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
, &name
))
171 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
176 static void toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
178 assert(entry
->clientdata
!= NULL
);
180 toggleLowered(entry
->clientdata
);
182 entry
->flags
.indicator_on
= !(((WDock
*) entry
->clientdata
)->lowered
);
187 static int matchWindow(const void *item
, const void *cdata
)
189 return (((WFakeGroupLeader
*) item
)->leader
== (Window
) cdata
);
192 static void killCallback(WMenu
*menu
, WMenuEntry
*entry
)
194 WScreen
*scr
= menu
->menu
->screen_ptr
;
196 WFakeGroupLeader
*fPtr
;
197 char *buffer
, *shortname
, **argv
;
198 char *basename(const char *shortname
);
201 if (!WCHECK_STATE(WSTATE_NORMAL
))
204 assert(entry
->clientdata
!= NULL
);
206 icon
= (WAppIcon
*) entry
->clientdata
;
210 WCHANGE_STATE(WSTATE_MODAL
);
212 /* strip away dir names */
213 shortname
= basename(icon
->command
);
214 /* separate out command options */
215 wtokensplit(shortname
, &argv
, &argc
);
217 buffer
= wstrconcat(argv
[0],
218 _(" will be forcibly closed.\n"
219 "Any unsaved changes will be lost.\n" "Please confirm."));
221 if (icon
->icon
&& icon
->icon
->owner
) {
222 fPtr
= icon
->icon
->owner
->fake_group
;
224 /* is this really necessary? can we kill a non-running dock icon? */
225 Window win
= icon
->main_window
;
228 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)win
);
229 if (index
!= WANotFound
)
230 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
235 if (wPreferences
.dont_confirm_kill
236 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
237 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
239 WWindow
*wwin
, *twin
;
241 wwin
= scr
->focused_window
;
244 if (wwin
->fake_group
== fPtr
)
249 } else if (icon
->icon
&& icon
->icon
->owner
) {
250 wClientKill(icon
->icon
->owner
);
255 wtokenfree(argv
, argc
);
259 WCHANGE_STATE(WSTATE_NORMAL
);
262 /* TODO: replace this function with a member of the dock struct */
263 static int numberOfSelectedIcons(WDock
*dock
)
269 for (i
= 1; i
< dock
->max_icons
; i
++) {
270 aicon
= dock
->icon_array
[i
];
271 if (aicon
&& aicon
->icon
->selected
)
278 static WMArray
*getSelected(WDock
*dock
)
280 WMArray
*ret
= WMCreateArray(8);
284 for (i
= 1; i
< dock
->max_icons
; i
++) {
285 btn
= dock
->icon_array
[i
];
286 if (btn
&& btn
->icon
->selected
)
287 WMAddToArray(ret
, btn
);
293 static void paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
295 Window win
= clipIcon
->icon
->core
->window
;
296 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
298 int pt
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
299 int tp
= ICON_SIZE
- pt
;
300 int as
= pt
- 15; /* 15 = 5+5+5 */
301 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
304 color
= scr
->clip_title_color
[CLIP_NORMAL
];
306 XSetForeground(dpy
, gc
, WMColorPixel(color
));
311 p
[1].x
= ICON_SIZE
- 2;
313 p
[2].x
= ICON_SIZE
- 2;
315 } else if (lpushed
) {
319 p
[1].y
= ICON_SIZE
- 2;
321 p
[2].y
= ICON_SIZE
- 2;
323 if (lpushed
|| rpushed
) {
324 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
325 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
326 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
329 /* top right arrow */
330 p
[0].x
= p
[3].x
= ICON_SIZE
- 5 - as
;
332 p
[1].x
= ICON_SIZE
- 6;
334 p
[2].x
= ICON_SIZE
- 6;
337 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
338 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
340 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
341 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
344 /* bottom left arrow */
346 p
[0].y
= p
[3].y
= ICON_SIZE
- 5 - as
;
348 p
[1].y
= ICON_SIZE
- 6;
350 p
[2].y
= ICON_SIZE
- 6;
352 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
353 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
355 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
356 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
360 RImage
*wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
362 RImage
*tile
= RCloneImage(normalTile
);
369 pt
= CLIP_BUTTON_SIZE
* wPreferences
.icon_size
/ 64;
370 tp
= wPreferences
.icon_size
- 1 - pt
;
374 black
.red
= black
.green
= black
.blue
= 0;
377 dark
.red
= dark
.green
= dark
.blue
= 60;
380 light
.red
= light
.green
= light
.blue
= 80;
383 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
- 2, pt
- 1, &dark
);
384 RDrawLine(tile
, tp
- 1, 0, wPreferences
.icon_size
- 1, pt
+ 1, &black
);
385 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
- 3, pt
, &light
);
388 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, 4, &dark
);
389 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 5, 6 + as
, &dark
);
390 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
, &light
);
393 ROperateLine(tile
, RAddOperation
, 2, tp
+ 2, pt
- 2, wPreferences
.icon_size
- 3, &dark
);
394 RDrawLine(tile
, 0, tp
- 1, pt
+ 1, wPreferences
.icon_size
- 1, &black
);
395 ROperateLine(tile
, RSubtractOperation
, 0, tp
- 2, pt
+ 1, wPreferences
.icon_size
- 2, &light
);
398 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, &dark
);
399 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
, 6 + as
, ICON_SIZE
- 5, &dark
);
400 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5, &light
);
405 static void omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
407 WAppIcon
*clickedIcon
= entry
->clientdata
;
410 WMArray
*selectedIcons
;
411 WMArrayIterator iter
;
414 assert(entry
->clientdata
!= NULL
);
416 dock
= clickedIcon
->dock
;
418 selectedIcons
= getSelected(dock
);
420 if (!WMGetArrayItemCount(selectedIcons
))
421 WMAddToArray(selectedIcons
, clickedIcon
);
424 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
425 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
427 else if (aicon
->icon
->selected
)
428 wIconSelect(aicon
->icon
);
430 WMFreeArray(selectedIcons
);
433 wMessageDialog(dock
->screen_ptr
, _("Warning"),
434 _("Some icons cannot be made omnipresent. "
435 "Please make sure that no other icon is "
436 "docked in the same positions on the other "
437 "workspaces and the Clip is not full in "
438 "some workspace."), _("OK"), NULL
, NULL
);
439 } else if (failed
== 1) {
440 wMessageDialog(dock
->screen_ptr
, _("Warning"),
441 _("Icon cannot be made omnipresent. "
442 "Please make sure that no other icon is "
443 "docked in the same position on the other "
444 "workspaces and the Clip is not full in "
445 "some workspace."), _("OK"), NULL
, NULL
);
449 static void removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
451 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
454 WMArray
*selectedIcons
;
458 assert(clickedIcon
!= NULL
);
460 dock
= clickedIcon
->dock
;
462 selectedIcons
= getSelected(dock
);
464 if (WMGetArrayItemCount(selectedIcons
)) {
465 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
466 _("All selected icons will be removed!"),
467 _("OK"), _("Cancel"), NULL
) != WAPRDefault
) {
468 WMFreeArray(selectedIcons
);
472 if (clickedIcon
->xindex
== 0 && clickedIcon
->yindex
== 0) {
473 WMFreeArray(selectedIcons
);
476 WMAddToArray(selectedIcons
, clickedIcon
);
479 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
480 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
481 wDockDetach(dock
, aicon
);
483 /* XXX: can: aicon->icon == NULL ? */
484 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
485 wGetHeadForWindow(aicon
->icon
->owner
));
486 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
487 if (!dock
->mapped
|| dock
->collapsed
)
488 XMapWindow(dpy
, aicon
->icon
->core
->window
);
491 WMFreeArray(selectedIcons
);
493 if (wPreferences
.auto_arrange_icons
)
494 wArrangeIcons(dock
->screen_ptr
, True
);
497 static void keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
499 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
502 WMArray
*selectedIcons
;
505 assert(clickedIcon
!= NULL
);
506 dock
= clickedIcon
->dock
;
508 selectedIcons
= getSelected(dock
);
510 if (!WMGetArrayItemCount(selectedIcons
)
511 && clickedIcon
!= dock
->screen_ptr
->clip_icon
) {
512 char *command
= NULL
;
514 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
515 clickedIcon
->editing
= 1;
516 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
517 _("Type the command used to launch the application"), &command
)) {
518 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
522 clickedIcon
->command
= command
;
523 clickedIcon
->editing
= 0;
525 clickedIcon
->editing
= 0;
528 WMFreeArray(selectedIcons
);
533 WMAddToArray(selectedIcons
, clickedIcon
);
536 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
537 if (aicon
->icon
->selected
)
538 wIconSelect(aicon
->icon
);
540 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
541 aicon
->attracted
= 0;
542 if (aicon
->icon
->shadowed
) {
543 aicon
->icon
->shadowed
= 0;
545 /* Update the icon images */
546 wIconUpdate(aicon
->icon
, NULL
);
549 wAppIconPaint(aicon
);
552 save_appicon(aicon
, True
);
554 WMFreeArray(selectedIcons
);
557 static void toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
559 WDock
*dock
= (WDock
*) entry
->clientdata
;
561 assert(entry
->clientdata
!= NULL
);
563 dock
->attract_icons
= !dock
->attract_icons
;
565 entry
->flags
.indicator_on
= dock
->attract_icons
;
570 static void selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
572 WAppIcon
*icon
= (WAppIcon
*) entry
->clientdata
;
574 assert(icon
!= NULL
);
576 wIconSelect(icon
->icon
);
581 static void colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
583 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
586 int x
, y
, x_pos
, y_pos
;
587 Bool update_icon
= False
;
589 assert(entry
->clientdata
!= NULL
);
590 clip
= clickedIcon
->dock
;
592 aicon
= clip
->screen_ptr
->app_icon_list
;
595 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
596 x_pos
= clip
->x_pos
+ x
* ICON_SIZE
;
597 y_pos
= clip
->y_pos
+ y
* ICON_SIZE
;
598 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
)
599 move_window(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
601 aicon
->attracted
= 1;
602 if (!aicon
->icon
->shadowed
) {
603 aicon
->icon
->shadowed
= 1;
606 wDockAttachIcon(clip
, aicon
, x
, y
, update_icon
);
607 if (clip
->collapsed
|| !clip
->mapped
)
608 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
614 static void selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
616 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
618 WMArray
*selectedIcons
;
619 WMArrayIterator iter
;
623 assert(clickedIcon
!= NULL
);
624 dock
= clickedIcon
->dock
;
626 selectedIcons
= getSelected(dock
);
628 if (!WMGetArrayItemCount(selectedIcons
)) {
629 for (i
= 1; i
< dock
->max_icons
; i
++) {
630 btn
= dock
->icon_array
[i
];
631 if (btn
&& !btn
->icon
->selected
)
632 wIconSelect(btn
->icon
);
635 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
636 wIconSelect(btn
->icon
);
639 WMFreeArray(selectedIcons
);
644 static void toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
646 assert(entry
->clientdata
!= NULL
);
648 toggleCollapsed(entry
->clientdata
);
650 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->collapsed
;
655 static void toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
658 assert(entry
->clientdata
!= NULL
);
660 dock
= (WDock
*) entry
->clientdata
;
662 dock
->auto_collapse
= !dock
->auto_collapse
;
664 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_collapse
;
669 static void toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
672 assert(entry
->clientdata
!= NULL
);
674 dock
= (WDock
*) entry
->clientdata
;
676 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
678 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_raise_lower
;
683 static void launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
685 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
687 launchDockedApplication(btn
, False
);
690 static void settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
692 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
696 ShowDockAppSettingsPanel(btn
);
699 static void hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
702 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
704 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
706 if (wapp
->flags
.hidden
) {
707 wWorkspaceChange(btn
->icon
->core
->screen_ptr
, wapp
->last_workspace
);
708 wUnhideApplication(wapp
, False
, False
);
710 wHideApplication(wapp
);
714 static void unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
717 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
719 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
721 wUnhideApplication(wapp
, False
, True
);
724 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
)
729 if (type
== WM_CLIP
) {
731 return scr
->clip_icon
;
732 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
733 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
734 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
735 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
738 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
739 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
745 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
746 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
747 btn
->icon
->core
->descriptor
.parent
= btn
;
748 XMapWindow(dpy
, btn
->icon
->core
->window
);
753 scr
->clip_icon
= btn
;
758 static void switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
760 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
761 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
763 WMArray
*selectedIcons
;
766 if (entry
->order
== scr
->current_workspace
)
769 dest
= scr
->workspaces
[entry
->order
]->clip
;
771 selectedIcons
= getSelected(src
);
773 if (WMGetArrayItemCount(selectedIcons
)) {
774 WMArrayIterator iter
;
776 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
777 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
778 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
779 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
782 } else if (icon
!= scr
->clip_icon
) {
783 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
784 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
785 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
788 WMFreeArray(selectedIcons
);
791 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
)
793 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
795 if (!btn
->launching
&&
796 ((!withSelection
&& btn
->command
!= NULL
) || (withSelection
&& btn
->paste_command
!= NULL
))) {
797 if (!btn
->forced_dock
) {
798 btn
->relaunching
= btn
->running
;
801 if (btn
->wm_instance
|| btn
->wm_class
) {
802 WWindowAttributes attr
;
803 memset(&attr
, 0, sizeof(WWindowAttributes
));
804 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
806 if (!attr
.no_appicon
&& !btn
->buggy_app
)
811 btn
->drop_launch
= 0;
812 btn
->paste_launch
= withSelection
;
813 scr
->last_dock
= btn
->dock
;
814 btn
->pid
= execCommand(btn
, (withSelection
? btn
->paste_command
: btn
->command
), NULL
);
816 if (btn
->buggy_app
) {
817 /* give feedback that the app was launched */
821 WMAddTimerHandler(200, (WMCallback
*) dockIconPaint
, btn
);
826 wwarning(_("could not launch application %s"), btn
->command
);
828 if (!btn
->relaunching
)
834 static void updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
836 WScreen
*scr
= menu
->frame
->screen_ptr
;
837 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
843 for (i
= 0; i
< scr
->workspace_count
; i
++) {
844 if (i
< menu
->entry_no
) {
845 if (strcmp(menu
->entries
[i
]->text
, scr
->workspaces
[i
]->name
) != 0) {
846 wfree(menu
->entries
[i
]->text
);
847 strcpy(title
, scr
->workspaces
[i
]->name
);
848 menu
->entries
[i
]->text
= wstrdup(title
);
849 menu
->flags
.realized
= 0;
851 menu
->entries
[i
]->clientdata
= (void *)icon
;
853 strcpy(title
, scr
->workspaces
[i
]->name
);
855 wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)icon
);
857 menu
->flags
.realized
= 0;
860 if (i
== scr
->current_workspace
)
861 wMenuSetEnabled(menu
, i
, False
);
863 wMenuSetEnabled(menu
, i
, True
);
866 if (!menu
->flags
.realized
)
870 static WMenu
*makeWorkspaceMenu(WScreen
*scr
)
874 menu
= wMenuCreate(scr
, NULL
, False
);
876 wwarning(_("could not create workspace submenu for Clip menu"));
878 wMenuAddCallback(menu
, "", switchWSCommand
, (void *)scr
->clip_icon
);
880 menu
->flags
.realized
= 0;
886 static void updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
895 entry
= menu
->entries
[index
];
896 entry
->flags
.indicator_on
= !dock
->lowered
;
897 entry
->clientdata
= dock
;
900 entry
= menu
->entries
[++index
];
901 entry
->flags
.indicator_on
= dock
->collapsed
;
902 entry
->clientdata
= dock
;
905 entry
= menu
->entries
[++index
];
906 entry
->flags
.indicator_on
= dock
->auto_collapse
;
907 entry
->clientdata
= dock
;
909 /* auto-raise/lower */
910 entry
= menu
->entries
[++index
];
911 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
912 entry
->clientdata
= dock
;
913 wMenuSetEnabled(menu
, index
, dock
->lowered
);
916 entry
= menu
->entries
[++index
];
917 entry
->flags
.indicator_on
= dock
->attract_icons
;
918 entry
->clientdata
= dock
;
920 menu
->flags
.realized
= 0;
924 static WMenu
*makeClipOptionsMenu(WScreen
*scr
)
929 menu
= wMenuCreate(scr
, NULL
, False
);
931 wwarning(_("could not create options submenu for Clip menu"));
935 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
936 entry
->flags
.indicator
= 1;
937 entry
->flags
.indicator_on
= 1;
938 entry
->flags
.indicator_type
= MI_CHECK
;
940 entry
= wMenuAddCallback(menu
, _("Collapsed"), toggleCollapsedCallback
, NULL
);
941 entry
->flags
.indicator
= 1;
942 entry
->flags
.indicator_on
= 1;
943 entry
->flags
.indicator_type
= MI_CHECK
;
945 entry
= wMenuAddCallback(menu
, _("Autocollapse"), toggleAutoCollapseCallback
, NULL
);
946 entry
->flags
.indicator
= 1;
947 entry
->flags
.indicator_on
= 1;
948 entry
->flags
.indicator_type
= MI_CHECK
;
950 entry
= wMenuAddCallback(menu
, _("Autoraise"), toggleAutoRaiseLowerCallback
, NULL
);
951 entry
->flags
.indicator
= 1;
952 entry
->flags
.indicator_on
= 1;
953 entry
->flags
.indicator_type
= MI_CHECK
;
955 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"), toggleAutoAttractCallback
, NULL
);
956 entry
->flags
.indicator
= 1;
957 entry
->flags
.indicator_on
= 1;
958 entry
->flags
.indicator_type
= MI_CHECK
;
960 menu
->flags
.realized
= 0;
966 static WMenu
*dockMenuCreate(WScreen
*scr
, int type
)
971 if (type
== WM_CLIP
&& scr
->clip_menu
)
972 return scr
->clip_menu
;
974 menu
= wMenuCreate(scr
, NULL
, False
);
975 if (type
!= WM_CLIP
) {
976 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
977 entry
->flags
.indicator
= 1;
978 entry
->flags
.indicator_on
= 1;
979 entry
->flags
.indicator_type
= MI_CHECK
;
981 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
982 scr
->clip_options
= makeClipOptionsMenu(scr
);
983 if (scr
->clip_options
)
984 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
986 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
988 entry
->text
= _("Rename Workspace");
990 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
991 entry
->flags
.indicator
= 1;
992 entry
->flags
.indicator_on
= 1;
993 entry
->flags
.indicator_type
= MI_CHECK
;
995 entry
= wMenuAddCallback(menu
, _("Select All Icons"), selectIconsCallback
, NULL
);
997 entry
->text
= _("Select All Icons");
999 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1001 entry
->text
= _("Keep Icon");
1003 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1005 entry
->text
= _("Move Icon To");
1006 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1007 if (scr
->clip_submenu
)
1008 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1010 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
, NULL
);
1012 entry
->text
= _("Remove Icon");
1014 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1017 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1019 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1021 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1023 entry
->text
= _("Hide");
1025 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1027 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1029 if (type
== WM_CLIP
)
1030 scr
->clip_menu
= menu
;
1035 WDock
*wDockCreate(WScreen
*scr
, int type
)
1042 dock
= wmalloc(sizeof(WDock
));
1044 dock
->max_icons
= DOCK_MAX_ICONS
;
1046 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * dock
->max_icons
);
1048 btn
= mainIconCreate(scr
, type
);
1052 dock
->x_pos
= btn
->x_pos
;
1053 dock
->y_pos
= btn
->y_pos
;
1054 dock
->screen_ptr
= scr
;
1056 dock
->icon_count
= 1;
1057 dock
->on_right_side
= 1;
1058 dock
->collapsed
= 0;
1059 dock
->auto_collapse
= 0;
1060 dock
->auto_collapse_magic
= NULL
;
1061 dock
->auto_raise_lower
= 0;
1062 dock
->auto_lower_magic
= NULL
;
1063 dock
->auto_raise_magic
= NULL
;
1064 dock
->attract_icons
= 0;
1066 dock
->icon_array
[0] = btn
;
1067 wRaiseFrame(btn
->icon
->core
);
1068 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1070 /* create dock menu */
1071 dock
->menu
= dockMenuCreate(scr
, type
);
1076 void wDockDestroy(WDock
*dock
)
1081 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1082 aicon
= dock
->icon_array
[i
];
1084 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1085 wDockDetach(dock
, aicon
);
1087 /* XXX: can: aicon->icon == NULL ? */
1088 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1089 wGetHeadForWindow(aicon
->icon
->owner
));
1090 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1091 if (!dock
->mapped
|| dock
->collapsed
)
1092 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1096 if (wPreferences
.auto_arrange_icons
)
1097 wArrangeIcons(dock
->screen_ptr
, True
);
1098 wfree(dock
->icon_array
);
1099 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1100 wMenuDestroy(dock
->menu
, True
);
1101 if (dock
->screen_ptr
->last_dock
== dock
)
1102 dock
->screen_ptr
->last_dock
= NULL
;
1106 void wClipIconPaint(WAppIcon
*aicon
)
1108 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1109 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1111 Window win
= aicon
->icon
->core
->window
;
1112 int length
, nlength
;
1113 char *ws_name
, ws_number
[10];
1116 wIconPaint(aicon
->icon
);
1118 length
= strlen(workspace
->name
);
1119 ws_name
= wmalloc(length
+ 1);
1120 snprintf(ws_name
, length
+ 1, "%s", workspace
->name
);
1121 snprintf(ws_number
, sizeof(ws_number
), "%i", scr
->current_workspace
+ 1);
1122 nlength
= strlen(ws_number
);
1124 if (!workspace
->clip
->collapsed
)
1125 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1127 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1129 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1131 tx
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
1133 if(wPreferences
.show_clip_title
)
1134 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, ty
, ws_name
, length
);
1136 tx
= (ICON_SIZE
/ 2 - WMWidthOfString(scr
->clip_title_font
, ws_number
, nlength
)) / 2;
1138 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, 2, ws_number
, nlength
);
1142 if (aicon
->launching
)
1143 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1144 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1146 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
, aicon
->dock
->rclip_button_pushed
);
1149 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1151 wClipIconPaint(desc
->parent
);
1154 static void dockIconPaint(WAppIcon
*btn
)
1156 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
) {
1157 wClipIconPaint(btn
);
1160 save_appicon(btn
, True
);
1164 static WMPropList
*make_icon_state(WAppIcon
*btn
)
1166 WMPropList
*node
= NULL
;
1167 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
;
1168 WMPropList
*position
, *buggy
, *omnipresent
;
1174 command
= WMCreatePLString("-");
1176 command
= WMCreatePLString(btn
->command
);
1178 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1180 lock
= btn
->lock
? dYes
: dNo
;
1182 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1184 name
= WMCreatePLString(tmp
);
1188 forced
= btn
->forced_dock
? dYes
: dNo
;
1190 buggy
= btn
->buggy_app
? dYes
: dNo
;
1192 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1193 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1195 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1196 position
= WMCreatePLString(buffer
);
1198 node
= WMCreatePLDictionary(dCommand
, command
,
1200 dAutoLaunch
, autolaunch
,
1202 dForced
, forced
, dBuggyApplication
, buggy
, dPosition
, position
, NULL
);
1203 WMReleasePropList(command
);
1204 WMReleasePropList(name
);
1205 WMReleasePropList(position
);
1207 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1208 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&& (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1209 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1211 #ifdef XDND /* was OFFIX */
1212 if (btn
->dnd_command
) {
1213 command
= WMCreatePLString(btn
->dnd_command
);
1214 WMPutInPLDictionary(node
, dDropCommand
, command
);
1215 WMReleasePropList(command
);
1219 if (btn
->paste_command
) {
1220 command
= WMCreatePLString(btn
->paste_command
);
1221 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1222 WMReleasePropList(command
);
1229 static WMPropList
*dockSaveState(WDock
*dock
)
1232 WMPropList
*icon_info
;
1233 WMPropList
*list
= NULL
, *dock_state
= NULL
;
1234 WMPropList
*value
, *key
;
1237 list
= WMCreatePLArray(NULL
);
1239 for (i
= (dock
->type
== WM_DOCK
? 0 : 1); i
< dock
->max_icons
; i
++) {
1240 WAppIcon
*btn
= dock
->icon_array
[i
];
1242 if (!btn
|| btn
->attracted
)
1245 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1246 WMAddToPLArray(list
, icon_info
);
1247 WMReleasePropList(icon_info
);
1251 dock_state
= WMCreatePLDictionary(dApplications
, list
, NULL
);
1253 if (dock
->type
== WM_DOCK
) {
1254 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1255 key
= WMCreatePLString(buffer
);
1256 WMPutInPLDictionary(dock_state
, key
, list
);
1257 WMReleasePropList(key
);
1259 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0), dock
->y_pos
);
1260 value
= WMCreatePLString(buffer
);
1261 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1262 WMReleasePropList(value
);
1264 WMReleasePropList(list
);
1266 value
= (dock
->lowered
? dYes
: dNo
);
1267 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1269 if (dock
->type
== WM_CLIP
) {
1270 value
= (dock
->collapsed
? dYes
: dNo
);
1271 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1273 value
= (dock
->auto_collapse
? dYes
: dNo
);
1274 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1276 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1277 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1279 value
= (dock
->attract_icons
? dYes
: dNo
);
1280 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1286 void wDockSaveState(WScreen
*scr
, WMPropList
*old_state
)
1288 WMPropList
*dock_state
;
1291 dock_state
= dockSaveState(scr
->dock
);
1294 * Copy saved states of docks with different sizes.
1300 keys
= WMGetPLDictionaryKeys(old_state
);
1301 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1302 tmp
= WMGetFromPLArray(keys
, i
);
1304 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1305 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1307 WMPutInPLDictionary(dock_state
, tmp
, WMGetFromPLDictionary(old_state
, tmp
));
1310 WMReleasePropList(keys
);
1313 WMPutInPLDictionary(scr
->session_state
, dDock
, dock_state
);
1315 WMReleasePropList(dock_state
);
1318 void wClipSaveState(WScreen
*scr
)
1320 WMPropList
*clip_state
;
1322 clip_state
= make_icon_state(scr
->clip_icon
);
1324 WMPutInPLDictionary(scr
->session_state
, dClip
, clip_state
);
1326 WMReleasePropList(clip_state
);
1329 WMPropList
*wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1331 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1334 static Bool
getBooleanDockValue(WMPropList
*value
, WMPropList
*key
)
1337 if (WMIsPLString(value
)) {
1338 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1341 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1347 static WAppIcon
*restore_icon_state(WScreen
*scr
, WMPropList
*info
, int type
, int index
)
1350 WMPropList
*cmd
, *value
;
1351 char *wclass
, *winstance
, *command
;
1353 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1354 if (!cmd
|| !WMIsPLString(cmd
))
1357 /* parse window name */
1358 value
= WMGetFromPLDictionary(info
, dName
);
1362 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1364 if (!winstance
&& !wclass
)
1369 command
= wstrdup(WMGetFromPLString(cmd
));
1373 if (!command
|| strcmp(command
, "-") == 0) {
1384 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1392 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1393 if (type
== WM_CLIP
) {
1394 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1395 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1397 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1398 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1400 #ifdef XDND /* was OFFIX */
1401 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1403 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1406 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1408 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1410 /* check auto launch */
1411 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1413 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1416 value
= WMGetFromPLDictionary(info
, dLock
);
1418 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1420 /* check if it wasn't normally docked */
1421 value
= WMGetFromPLDictionary(info
, dForced
);
1423 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1425 /* check if we can rely on the stuff in the app */
1426 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1428 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1430 /* get position in the dock */
1431 value
= WMGetFromPLDictionary(info
, dPosition
);
1432 if (value
&& WMIsPLString(value
)) {
1433 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1434 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1436 /* check position sanity */
1437 /* incomplete section! */
1438 if (type
== WM_DOCK
) {
1440 if (aicon
->yindex
< 0)
1441 wwarning(_("bad value in docked icon position %i,%i"),
1442 aicon
->xindex
, aicon
->yindex
);
1445 aicon
->yindex
= index
;
1449 /* check if icon is omnipresent */
1450 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1452 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1460 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1462 WAppIcon
*wClipRestoreState(WScreen
*scr
, WMPropList
*clip_state
)
1467 icon
= mainIconCreate(scr
, WM_CLIP
);
1472 WMRetainPropList(clip_state
);
1474 /* restore position */
1476 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1479 if (!WMIsPLString(value
)) {
1480 COMPLAIN("Position");
1482 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1483 COMPLAIN("Position");
1485 /* check position sanity */
1486 if (!onScreen(scr
, icon
->x_pos
, icon
->y_pos
))
1487 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1490 #ifdef XDND /* was OFFIX */
1491 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1492 if (value
&& WMIsPLString(value
))
1493 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1496 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1497 if (value
&& WMIsPLString(value
))
1498 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1500 WMReleasePropList(clip_state
);
1505 WDock
*wDockRestoreState(WScreen
*scr
, WMPropList
*dock_state
, int type
)
1510 WAppIcon
*aicon
, *old_top
;
1513 dock
= wDockCreate(scr
, type
);
1518 WMRetainPropList(dock_state
);
1520 /* restore position */
1521 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1523 if (!WMIsPLString(value
)) {
1524 COMPLAIN("Position");
1526 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1527 COMPLAIN("Position");
1529 /* check position sanity */
1530 if (!onScreen(scr
, dock
->x_pos
, dock
->y_pos
)) {
1531 int x
= dock
->x_pos
;
1532 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1535 /* Is this needed any more? */
1536 if (type
== WM_CLIP
) {
1537 if (dock
->x_pos
< 0) {
1539 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1540 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1543 if (dock
->x_pos
>= 0) {
1544 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1545 dock
->on_right_side
= 0;
1547 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1548 dock
->on_right_side
= 1;
1554 /* restore lowered/raised state */
1557 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1559 if (!WMIsPLString(value
)) {
1560 COMPLAIN("Lowered");
1562 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1567 /* restore collapsed state */
1568 dock
->collapsed
= 0;
1570 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1572 if (!WMIsPLString(value
)) {
1573 COMPLAIN("Collapsed");
1575 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1576 dock
->collapsed
= 1;
1580 /* restore auto-collapsed state */
1581 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1583 if (!WMIsPLString(value
)) {
1584 COMPLAIN("AutoCollapse");
1586 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1587 dock
->auto_collapse
= 1;
1588 dock
->collapsed
= 1;
1593 /* restore auto-raise/lower state */
1594 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1596 if (!WMIsPLString(value
)) {
1597 COMPLAIN("AutoRaiseLower");
1599 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1600 dock
->auto_raise_lower
= 1;
1604 /* restore attract icons state */
1605 dock
->attract_icons
= 0;
1607 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1609 if (!WMIsPLString(value
)) {
1610 COMPLAIN("AutoAttractIcons");
1612 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1613 dock
->attract_icons
= 1;
1617 /* application list */
1624 * When saving, it saves the dock state in
1625 * Applications and Applicationsnnn
1627 * When loading, it will first try Applicationsnnn.
1628 * If it does not exist, use Applications as default.
1631 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1633 tmp
= WMCreatePLString(buffer
);
1634 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1635 WMReleasePropList(tmp
);
1638 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1644 count
= WMGetPropListItemCount(apps
);
1648 old_top
= dock
->icon_array
[0];
1650 /* dock->icon_count is set to 1 when dock is created.
1651 * Since Clip is already restored, we want to keep it so for clip,
1652 * but for dock we may change the default top tile, so we set it to 0.
1654 if (type
== WM_DOCK
)
1655 dock
->icon_count
= 0;
1657 for (i
= 0; i
< count
; i
++) {
1658 if (dock
->icon_count
>= dock
->max_icons
) {
1659 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1663 value
= WMGetFromPLArray(apps
, i
);
1664 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1666 dock
->icon_array
[dock
->icon_count
] = aicon
;
1670 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1671 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1674 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1676 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1678 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1679 if (!dock
->collapsed
)
1680 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1682 wRaiseFrame(aicon
->icon
->core
);
1685 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
) {
1690 /* if the first icon is not defined, use the default */
1691 if (dock
->icon_array
[0] == NULL
) {
1692 /* update default icon */
1693 old_top
->x_pos
= dock
->x_pos
;
1694 old_top
->y_pos
= dock
->y_pos
;
1696 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1698 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1700 dock
->icon_array
[0] = old_top
;
1701 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1702 /* we don't need to increment dock->icon_count here because it was
1703 * incremented in the loop above.
1705 } else if (old_top
!= dock
->icon_array
[0]) {
1706 if (old_top
== scr
->clip_icon
)
1707 scr
->clip_icon
= dock
->icon_array
[0];
1709 wAppIconDestroy(old_top
);
1713 WMReleasePropList(dock_state
);
1718 void wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1720 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1721 btn
->drop_launch
= 0;
1722 btn
->paste_launch
= 0;
1724 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1727 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1737 void wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1743 for (i
= 0; i
< dock
->max_icons
; i
++) {
1744 btn
= dock
->icon_array
[i
];
1745 if (!btn
|| !btn
->auto_launch
)
1748 state
= wmalloc(sizeof(WSavedState
));
1749 state
->workspace
= workspace
;
1750 /* TODO: this is klugy and is very difficult to understand
1751 * what's going on. Try to clean up */
1752 wDockLaunchWithState(dock
, btn
, state
);
1756 #ifdef XDND /* was OFFIX */
1757 static WDock
*findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1763 if ((dock
= scr
->dock
) != NULL
) {
1764 for (i
= 0; i
< dock
->max_icons
; i
++) {
1765 if (dock
->icon_array
[i
]
1766 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1772 if (*icon_pos
< 0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
) != NULL
) {
1773 for (i
= 0; i
< dock
->max_icons
; i
++) {
1774 if (dock
->icon_array
[i
]
1775 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1786 int wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
1792 dock
= findDock(scr
, event
, &icon_pos
);
1797 * Return True if the drop was on an application icon window.
1798 * In this case, let the ClientMessage handler redirect the
1799 * message to the app.
1801 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
1804 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
1805 scr
->flags
.dnd_data_convertion_status
= 0;
1807 btn
= dock
->icon_array
[icon_pos
];
1809 if (!btn
->forced_dock
) {
1810 btn
->relaunching
= btn
->running
;
1813 if (btn
->wm_instance
|| btn
->wm_class
) {
1814 WWindowAttributes attr
;
1815 memset(&attr
, 0, sizeof(WWindowAttributes
));
1816 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
1818 if (!attr
.no_appicon
)
1824 btn
->paste_launch
= 0;
1825 btn
->drop_launch
= 1;
1826 scr
->last_dock
= dock
;
1827 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1832 if (!btn
->relaunching
)
1840 Bool
wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
, Bool update_icon
)
1843 Bool lupdate_icon
= False
;
1844 char *command
= NULL
;
1850 lupdate_icon
= True
;
1852 if (icon
->command
== NULL
) {
1853 /* If icon->owner exists, it means the application is running */
1854 if (icon
->icon
->owner
) {
1855 wwin
= icon
->icon
->owner
;
1856 command
= GetCommandForWindow(wwin
->client_win
);
1860 icon
->command
= command
;
1862 /* icon->forced_dock = 1; */
1863 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
1865 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
1866 _("Type the command used to launch the application"), &command
)) {
1867 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
1871 icon
->command
= command
;
1877 /* If the target is the dock, reject the icon. If
1878 * the target is the clip, make it an attracted icon
1880 if (dock
->type
== WM_CLIP
) {
1881 icon
->attracted
= 1;
1882 if (!icon
->icon
->shadowed
) {
1883 icon
->icon
->shadowed
= 1;
1884 lupdate_icon
= True
;
1894 for (index
= 1; index
< dock
->max_icons
; index
++)
1895 if (dock
->icon_array
[index
] == NULL
)
1897 /* if (index == dock->max_icons)
1900 assert(index
< dock
->max_icons
);
1902 dock
->icon_array
[index
] = icon
;
1906 icon
->omnipresent
= 0;
1908 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
1909 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
1914 icon
->launching
= 0;
1917 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1918 if (dock
->type
== WM_CLIP
) {
1919 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1920 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1922 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1923 icon
->icon
->core
->descriptor
.parent
= icon
;
1925 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
1926 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
1928 /* Update the icon images */
1930 wIconUpdate(icon
->icon
, NULL
);
1933 wAppIconPaint(icon
);
1936 save_appicon(icon
, True
);
1938 if (wPreferences
.auto_arrange_icons
)
1939 wArrangeIcons(dock
->screen_ptr
, True
);
1941 #ifdef XDND /* was OFFIX */
1942 if (icon
->command
&& !icon
->dnd_command
) {
1943 int len
= strlen(icon
->command
) + 8;
1944 icon
->dnd_command
= wmalloc(len
);
1945 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
1949 if (icon
->command
&& !icon
->paste_command
) {
1950 int len
= strlen(icon
->command
) + 8;
1951 icon
->paste_command
= wmalloc(len
);
1952 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
1958 static void reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1962 for (index
= 1; index
< dock
->max_icons
; index
++) {
1963 if (dock
->icon_array
[index
] == icon
)
1966 assert(index
< dock
->max_icons
);
1971 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
1972 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
1975 static Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
1978 char *command
= NULL
;
1980 Bool update_icon
= False
;
1983 return True
; /* No move needed, we're already there */
1989 * For the moment we can't do this if we move icons in Clip from one
1990 * workspace to other, because if we move two or more icons without
1991 * command, the dialog box will not be able to tell us to which of the
1992 * moved icons it applies. -Dan
1994 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
1995 /* If icon->owner exists, it means the application is running */
1996 if (icon
->icon
->owner
) {
1997 wwin
= icon
->icon
->owner
;
1998 command
= GetCommandForWindow(wwin
->client_win
);
2002 icon
->command
= command
;
2005 /* icon->forced_dock = 1; */
2006 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2007 _("Type the command used to launch the application"), &command
)) {
2008 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2012 icon
->command
= command
;
2023 if (dest
->type
== WM_DOCK
)
2024 wClipMakeIconOmnipresent(icon
, False
);
2026 for (index
= 1; index
< src
->max_icons
; index
++) {
2027 if (src
->icon_array
[index
] == icon
)
2030 assert(index
< src
->max_icons
);
2032 src
->icon_array
[index
] = NULL
;
2035 for (index
= 1; index
< dest
->max_icons
; index
++) {
2036 if (dest
->icon_array
[index
] == NULL
)
2040 assert(index
< dest
->max_icons
);
2042 dest
->icon_array
[index
] = icon
;
2045 /* deselect the icon */
2046 if (icon
->icon
->selected
)
2047 wIconSelect(icon
->icon
);
2049 if (dest
->type
== WM_DOCK
) {
2050 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2051 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2053 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2054 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2057 /* set it to be kept when moving to dock.
2058 * Unless the icon does not have a command set
2060 if (icon
->command
&& dest
->type
== WM_DOCK
) {
2061 icon
->attracted
= 0;
2062 if (icon
->icon
->shadowed
) {
2063 icon
->icon
->shadowed
= 0;
2066 save_appicon(icon
, True
);
2069 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2075 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2076 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2080 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2082 /* Update the icon images */
2084 wIconUpdate(icon
->icon
, NULL
);
2087 wAppIconPaint(icon
);
2092 void wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2095 Bool update_icon
= False
;
2097 /* make the settings panel be closed */
2099 DestroyDockAppSettingsPanel(icon
->panel
);
2101 /* This must be called before icon->dock is set to NULL.
2102 * Don't move it. -Dan
2104 wClipMakeIconOmnipresent(icon
, False
);
2108 icon
->attracted
= 0;
2109 icon
->auto_launch
= 0;
2110 if (icon
->icon
->shadowed
) {
2111 icon
->icon
->shadowed
= 0;
2115 /* deselect the icon */
2116 if (icon
->icon
->selected
)
2117 wIconSelect(icon
->icon
);
2119 if (icon
->command
) {
2120 wfree(icon
->command
);
2121 icon
->command
= NULL
;
2123 #ifdef XDND /* was OFFIX */
2124 if (icon
->dnd_command
) {
2125 wfree(icon
->dnd_command
);
2126 icon
->dnd_command
= NULL
;
2129 if (icon
->paste_command
) {
2130 wfree(icon
->paste_command
);
2131 icon
->paste_command
= NULL
;
2134 for (index
= 1; index
< dock
->max_icons
; index
++)
2135 if (dock
->icon_array
[index
] == icon
)
2138 assert(index
< dock
->max_icons
);
2139 dock
->icon_array
[index
] = NULL
;
2145 /* if the dock is not attached to an application or
2146 * the application did not set the appropriate hints yet,
2147 * destroy the icon */
2148 if (!icon
->running
|| !wApplicationOf(icon
->main_window
)) {
2149 wAppIconDestroy(icon
);
2151 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2152 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2153 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2154 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2155 icon
->icon
->core
->descriptor
.parent
= icon
;
2157 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2159 /* Update the icon images */
2161 wIconUpdate(icon
->icon
, NULL
);
2164 wAppIconPaint(icon
);
2166 if (wPreferences
.auto_arrange_icons
)
2167 wArrangeIcons(dock
->screen_ptr
, True
);
2169 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2174 * returns the closest Dock slot index for the passed
2177 * Returns False if icon can't be docked.
2179 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2182 Bool
wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2184 WScreen
*scr
= dock
->screen_ptr
;
2187 int i
, offset
= ICON_SIZE
/ 2;
2188 WAppIcon
*aicon
= NULL
;
2189 WAppIcon
*nicon
= NULL
;
2192 /* TODO: XINERAMA, for these */
2193 max_y_icons
= scr
->scr_height
/ ICON_SIZE
- 1;
2195 if (wPreferences
.flags
.noupdates
)
2201 /* if the dock is full */
2202 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
))
2205 /* exact position */
2207 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2209 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2212 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2214 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2216 /* check if the icon is outside the screen boundaries */
2217 if (!onScreen(scr
, dx
+ ex_x
* ICON_SIZE
, dy
+ ex_y
* ICON_SIZE
))
2220 if (dock
->type
== WM_DOCK
) {
2221 if (icon
->dock
!= dock
&& ex_x
!= 0)
2225 for (i
= 0; i
< dock
->max_icons
; i
++) {
2226 nicon
= dock
->icon_array
[i
];
2227 if (nicon
&& nicon
->yindex
== ex_y
) {
2234 int sig
, done
, closest
;
2236 /* Possible cases when redocking:
2238 * icon dragged out of range of any slot -> false
2239 * icon dragged to range of free slot
2240 * icon dragged to range of same slot
2241 * icon dragged to range of different icon
2243 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2246 if (ex_y
>= 0 && ex_y
<= max_y_icons
&& (aicon
== icon
|| !aicon
)) {
2252 /* start looking at the upper slot or lower? */
2253 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2260 /* look for closest free slot */
2261 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2265 closest
= sig
* (i
/ 2) + ex_y
;
2266 /* check if this slot is used */
2268 for (j
= 0; j
< dock
->max_icons
; j
++) {
2269 if (dock
->icon_array
[j
]
2270 && dock
->icon_array
[j
]->yindex
== closest
) {
2271 /* slot is used by someone else */
2272 if (dock
->icon_array
[j
] != icon
)
2280 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2281 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2282 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2287 } else { /* !redocking */
2289 /* if slot is free and the icon is close enough, return it */
2290 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2300 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2301 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+ 1;
2304 for (k
= start
; k
< stop
; k
++) {
2305 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2308 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2309 nicon
= tmp
->icon_array
[i
];
2310 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2318 for (k
= start
; k
< stop
; k
++) {
2319 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2322 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2323 nicon
= tmp
->icon_array
[i
];
2324 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2325 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2326 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2335 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2344 static int onScreen(WScreen
*scr
, int x
, int y
)
2351 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2353 wGetRectPlacementInfo(scr
, rect
, &flags
);
2355 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2359 * returns true if it can find a free slot in the dock,
2360 * in which case it changes x_pos and y_pos accordingly.
2361 * Else returns false.
2363 Bool
wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2365 WScreen
*scr
= dock
->screen_ptr
;
2367 WAppIconChain
*chain
;
2368 unsigned char *slot_map
;
2372 int i
, done
= False
;
2374 int sx
= 0, ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2375 int extra_count
= 0;
2377 if (dock
->type
== WM_CLIP
&& dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2378 extra_count
= scr
->global_icon_count
;
2380 /* if the dock is full */
2381 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
)
2384 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2385 if (scr
->dock
->on_right_side
)
2386 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2388 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2391 if (ex
< dock
->x_pos
)
2393 if (sx
> dock
->x_pos
+ ICON_SIZE
)
2394 sx
= dock
->x_pos
+ ICON_SIZE
;
2401 /* check if clip is in a corner */
2402 if (dock
->type
== WM_CLIP
) {
2403 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2405 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2407 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2409 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2417 /* If the clip is in the corner, use only slots that are in the border
2419 if (corner
!= C_NONE
) {
2423 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2424 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2425 hmap
= wmalloc(hcount
+ 1);
2426 vmap
= wmalloc(vcount
+ 1);
2428 /* mark used positions */
2431 for (i
= 0; i
< dock
->max_icons
; i
++) {
2432 btn
= dock
->icon_array
[i
];
2436 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2437 vmap
[btn
->yindex
] = 1;
2438 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2439 hmap
[btn
->xindex
] = 1;
2441 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2443 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2444 vmap
[btn
->yindex
] = 1;
2445 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2446 hmap
[btn
->xindex
] = 1;
2450 for (i
= 0; i
< dock
->max_icons
; i
++) {
2451 btn
= dock
->icon_array
[i
];
2455 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2456 vmap
[btn
->yindex
] = 1;
2457 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2458 hmap
[-btn
->xindex
] = 1;
2460 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2462 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2463 vmap
[btn
->yindex
] = 1;
2464 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2465 hmap
[-btn
->xindex
] = 1;
2469 for (i
= 0; i
< dock
->max_icons
; i
++) {
2470 btn
= dock
->icon_array
[i
];
2474 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2475 vmap
[-btn
->yindex
] = 1;
2476 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2477 hmap
[btn
->xindex
] = 1;
2479 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2481 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2482 vmap
[-btn
->yindex
] = 1;
2483 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2484 hmap
[btn
->xindex
] = 1;
2489 for (i
= 0; i
< dock
->max_icons
; i
++) {
2490 btn
= dock
->icon_array
[i
];
2494 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2495 vmap
[-btn
->yindex
] = 1;
2496 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2497 hmap
[-btn
->xindex
] = 1;
2499 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2501 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2502 vmap
[-btn
->yindex
] = 1;
2503 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2504 hmap
[-btn
->xindex
] = 1;
2510 /* search a vacant slot */
2511 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2512 if (i
< vcount
&& vmap
[i
] == 0) {
2518 } else if (i
< hcount
&& hmap
[i
] == 0) {
2528 /* If found a slot, translate and return */
2530 if (corner
== C_NW
|| corner
== C_NE
)
2535 if (corner
== C_NE
|| corner
== C_SE
)
2542 /* else, try to find a slot somewhere else */
2545 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2546 * placed outside of screen */
2547 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2549 /* In the worst case (the clip is in the corner of the screen),
2550 * the amount of icons that fit in the clip is smaller.
2551 * Double the map to get a safe value.
2555 r
= (mwidth
- 1) / 2;
2557 slot_map
= wmalloc(mwidth
* mwidth
);
2559 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2561 /* mark used slots in the map. If the slot falls outside the map
2562 * (for example, when all icons are placed in line), ignore them. */
2563 for (i
= 0; i
< dock
->max_icons
; i
++) {
2564 btn
= dock
->icon_array
[i
];
2566 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2569 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
)
2570 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2572 /* Find closest slot from the center that is free by scanning the
2573 * map from the center to outward in circular passes.
2574 * This will not result in a neat layout, but will be optimal
2575 * in the sense that there will not be holes left.
2578 for (i
= 1; i
<= r
&& !done
; i
++) {
2581 /* top and bottom parts of the ring */
2582 for (x
= -i
; x
<= i
&& !done
; x
++) {
2583 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2585 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2586 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2593 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2594 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2601 /* left and right parts of the ring */
2602 for (y
= -i
+ 1; y
<= i
- 1; y
++) {
2603 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2605 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2606 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2613 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2614 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2627 static void moveDock(WDock
*dock
, int new_x
, int new_y
)
2632 dock
->x_pos
= new_x
;
2633 dock
->y_pos
= new_y
;
2634 for (i
= 0; i
< dock
->max_icons
; i
++) {
2635 btn
= dock
->icon_array
[i
];
2637 btn
->x_pos
= new_x
+ btn
->xindex
* ICON_SIZE
;
2638 btn
->y_pos
= new_y
+ btn
->yindex
* ICON_SIZE
;
2639 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2644 static void swapDock(WDock
*dock
)
2646 WScreen
*scr
= dock
->screen_ptr
;
2650 if (dock
->on_right_side
)
2651 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2653 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2655 for (i
= 0; i
< dock
->max_icons
; i
++) {
2656 btn
= dock
->icon_array
[i
];
2659 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2663 wScreenUpdateUsableArea(scr
);
2666 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2668 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2674 cmdline
= ExpandOptions(scr
, command
);
2676 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2684 wtokensplit(cmdline
, &argv
, &argc
);
2694 if ((pid
= fork()) == 0) {
2698 SetupEnvironment(scr
);
2704 args
= malloc(sizeof(char *) * (argc
+ 1));
2708 for (i
= 0; i
< argc
; i
++)
2712 execvp(argv
[0], args
);
2715 wtokenfree(argv
, argc
);
2719 state
= wmalloc(sizeof(WSavedState
));
2721 state
->miniaturized
= -1;
2723 if (btn
->dock
== scr
->dock
|| btn
->omnipresent
)
2724 state
->workspace
= -1;
2726 state
->workspace
= scr
->current_workspace
;
2728 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
2729 wAddDeathHandler(pid
, (WDeathHandler
*) trackDeadProcess
, btn
->dock
);
2737 void wDockHideIcons(WDock
*dock
)
2744 for (i
= 1; i
< dock
->max_icons
; i
++) {
2745 if (dock
->icon_array
[i
])
2746 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2750 dockIconPaint(dock
->icon_array
[0]);
2753 void wDockShowIcons(WDock
*dock
)
2761 btn
= dock
->icon_array
[0];
2762 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2764 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2765 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2767 for (i
= 1; i
< dock
->max_icons
; i
++) {
2768 if (dock
->icon_array
[i
]) {
2769 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
, btn
->icon
->core
);
2774 if (!dock
->collapsed
) {
2775 for (i
= 1; i
< dock
->max_icons
; i
++) {
2776 if (dock
->icon_array
[i
])
2777 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2785 void wDockLower(WDock
*dock
)
2789 for (i
= 0; i
< dock
->max_icons
; i
++) {
2790 if (dock
->icon_array
[i
])
2791 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2795 void wDockRaise(WDock
*dock
)
2799 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
2800 if (dock
->icon_array
[i
])
2801 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2805 void wDockRaiseLower(WDock
*dock
)
2807 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2808 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2809 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2815 void wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
2817 icon
->launching
= 0;
2818 icon
->relaunching
= 0;
2819 dockIconPaint(icon
);
2822 WAppIcon
*wDockFindIconForWindow(WDock
*dock
, Window window
)
2827 for (i
= 0; i
< dock
->max_icons
; i
++) {
2828 icon
= dock
->icon_array
[i
];
2829 if (icon
&& icon
->main_window
== window
)
2835 void wDockTrackWindowLaunch(WDock
*dock
, Window window
)
2838 char *wm_class
, *wm_instance
;
2840 Bool firstPass
= True
;
2842 char *command
= NULL
;
2844 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) || (!wm_class
&& !wm_instance
))
2847 command
= GetCommandForWindow(window
);
2849 for (i
= 0; i
< dock
->max_icons
; i
++) {
2850 icon
= dock
->icon_array
[i
];
2854 /* app is already attached to icon */
2855 if (icon
->main_window
== window
) {
2860 if ((icon
->wm_instance
|| icon
->wm_class
)
2861 && (icon
->launching
|| !icon
->running
)) {
2863 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0)
2866 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0)
2869 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0)
2872 if (!icon
->relaunching
) {
2875 /* Possibly an application that was docked with dockit,
2876 * but the user did not update WMState to indicate that
2877 * it was docked by force */
2878 wapp
= wApplicationOf(window
);
2880 icon
->forced_dock
= 1;
2883 if (!icon
->forced_dock
)
2884 icon
->main_window
= window
;
2887 if (!wPreferences
.no_animations
&& !icon
->launching
&&
2888 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
2892 icon
->launching
= 1;
2893 dockIconPaint(icon
);
2895 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
2896 wm_instance
, wm_class
, TILE_NORMAL
);
2897 /* XXX: can: aicon->icon == NULL ? */
2898 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
2899 wAppIconMove(aicon
, x0
, y0
);
2900 /* Should this always be lowered? -Dan */
2902 wLowerFrame(aicon
->icon
->core
);
2903 XMapWindow(dpy
, aicon
->icon
->core
->window
);
2904 aicon
->launching
= 1;
2905 wAppIconPaint(aicon
);
2906 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
2907 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
2908 wAppIconDestroy(aicon
);
2910 wDockFinishLaunch(dock
, icon
);
2915 if (firstPass
&& !found
) {
2929 void wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
2931 if (!wPreferences
.flags
.noclip
) {
2932 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
2933 if (scr
->current_workspace
!= workspace
) {
2934 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
2935 WAppIconChain
*chain
= scr
->global_icons
;
2938 moveIconBetweenDocks(chain
->aicon
->dock
,
2939 scr
->workspaces
[workspace
]->clip
,
2940 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
2941 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
2942 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
2943 chain
= chain
->next
;
2946 wDockHideIcons(old_clip
);
2947 if (old_clip
->auto_raise_lower
) {
2948 if (old_clip
->auto_raise_magic
) {
2949 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
2950 old_clip
->auto_raise_magic
= NULL
;
2952 wDockLower(old_clip
);
2954 if (old_clip
->auto_collapse
) {
2955 if (old_clip
->auto_expand_magic
) {
2956 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
2957 old_clip
->auto_expand_magic
= NULL
;
2959 old_clip
->collapsed
= 1;
2961 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
2966 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
2971 for (i
= 0; i
< dock
->max_icons
; i
++) {
2972 icon
= dock
->icon_array
[i
];
2976 if (icon
->launching
&& icon
->pid
== pid
) {
2977 if (!icon
->relaunching
) {
2979 icon
->main_window
= None
;
2981 wDockFinishLaunch(dock
, icon
);
2983 if (status
== 111) {
2988 if (icon
->drop_launch
)
2989 cmd
= icon
->dnd_command
;
2992 if (icon
->paste_launch
)
2993 cmd
= icon
->paste_command
;
2995 cmd
= icon
->command
;
2997 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
2999 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3006 static void toggleLowered(WDock
*dock
)
3011 /* lower/raise Dock */
3012 if (!dock
->lowered
) {
3013 newlevel
= WMNormalLevel
;
3016 newlevel
= WMDockLevel
;
3020 for (i
= 0; i
< dock
->max_icons
; i
++) {
3021 tmp
= dock
->icon_array
[i
];
3025 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3027 wLowerFrame(tmp
->icon
->core
);
3030 if (dock
->type
== WM_DOCK
)
3031 wScreenUpdateUsableArea(dock
->screen_ptr
);
3034 static void toggleCollapsed(WDock
*dock
)
3036 if (dock
->collapsed
) {
3037 dock
->collapsed
= 0;
3038 wDockShowIcons(dock
);
3040 dock
->collapsed
= 1;
3041 wDockHideIcons(dock
);
3045 static void openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3047 WScreen
*scr
= dock
->screen_ptr
;
3048 WObjDescriptor
*desc
;
3050 WApplication
*wapp
= NULL
;
3054 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3056 if (dock
->type
== WM_DOCK
) {
3058 entry
= dock
->menu
->entries
[index
];
3059 entry
->flags
.indicator_on
= !dock
->lowered
;
3060 entry
->clientdata
= dock
;
3061 dock
->menu
->flags
.realized
= 0;
3064 if (scr
->clip_options
)
3065 updateClipOptionsMenu(scr
->clip_options
, dock
);
3067 n_selected
= numberOfSelectedIcons(dock
);
3069 /* Rename Workspace */
3070 entry
= dock
->menu
->entries
[++index
];
3071 if (aicon
== scr
->clip_icon
) {
3072 entry
->callback
= renameCallback
;
3073 entry
->clientdata
= dock
;
3074 entry
->flags
.indicator
= 0;
3075 entry
->text
= _("Rename Workspace");
3077 entry
->callback
= omnipresentCallback
;
3078 entry
->clientdata
= aicon
;
3079 if (n_selected
> 0) {
3080 entry
->flags
.indicator
= 0;
3081 entry
->text
= _("Toggle Omnipresent");
3083 entry
->flags
.indicator
= 1;
3084 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3085 entry
->flags
.indicator_type
= MI_CHECK
;
3086 entry
->text
= _("Omnipresent");
3090 /* select/unselect icon */
3091 entry
= dock
->menu
->entries
[++index
];
3092 entry
->clientdata
= aicon
;
3093 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3094 wMenuSetEnabled(dock
->menu
, index
, aicon
!= scr
->clip_icon
);
3096 /* select/unselect all icons */
3097 entry
= dock
->menu
->entries
[++index
];
3098 entry
->clientdata
= aicon
;
3100 entry
->text
= _("Unselect All Icons");
3102 entry
->text
= _("Select All Icons");
3104 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3107 entry
= dock
->menu
->entries
[++index
];
3108 entry
->clientdata
= aicon
;
3110 entry
->text
= _("Keep Icons");
3112 entry
->text
= _("Keep Icon");
3114 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3116 /* this is the workspace submenu part */
3117 entry
= dock
->menu
->entries
[++index
];
3119 entry
->text
= _("Move Icons To");
3121 entry
->text
= _("Move Icon To");
3123 if (scr
->clip_submenu
)
3124 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3126 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3128 /* remove icon(s) */
3129 entry
= dock
->menu
->entries
[++index
];
3130 entry
->clientdata
= aicon
;
3132 entry
->text
= _("Remove Icons");
3134 entry
->text
= _("Remove Icon");
3136 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3138 /* attract icon(s) */
3139 entry
= dock
->menu
->entries
[++index
];
3140 entry
->clientdata
= aicon
;
3142 dock
->menu
->flags
.realized
= 0;
3143 wMenuRealize(dock
->menu
);
3146 if (aicon
->icon
->owner
)
3147 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3152 entry
= dock
->menu
->entries
[++index
];
3153 entry
->clientdata
= aicon
;
3154 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3157 entry
= dock
->menu
->entries
[++index
];
3158 entry
->clientdata
= aicon
;
3159 if (wapp
&& wapp
->flags
.hidden
)
3160 entry
->text
= _("Unhide Here");
3162 entry
->text
= _("Bring Here");
3164 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3167 entry
= dock
->menu
->entries
[++index
];
3168 entry
->clientdata
= aicon
;
3169 if (wapp
&& wapp
->flags
.hidden
)
3170 entry
->text
= _("Unhide");
3172 entry
->text
= _("Hide");
3174 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3177 entry
= dock
->menu
->entries
[++index
];
3178 entry
->clientdata
= aicon
;
3179 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3182 entry
= dock
->menu
->entries
[++index
];
3183 entry
->clientdata
= aicon
;
3184 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3186 if (!dock
->menu
->flags
.realized
)
3187 wMenuRealize(dock
->menu
);
3189 if (dock
->type
== WM_CLIP
) {
3190 /*x_pos = event->xbutton.x_root+2; */
3191 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3194 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3195 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3198 x_pos
= dock
->on_right_side
? scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3201 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3203 /* allow drag select */
3204 event
->xany
.send_event
= True
;
3205 desc
= &dock
->menu
->menu
->descriptor
;
3206 (*desc
->handle_mousedown
) (desc
, event
);
3209 /******************************************************************/
3210 static void iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3212 WAppIcon
*btn
= desc
->parent
;
3213 WDock
*dock
= btn
->dock
;
3214 WApplication
*wapp
= NULL
;
3217 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3218 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3220 assert(wapp
!= NULL
);
3222 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3224 /* go to the last workspace that the user worked on the app */
3225 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
&& !unhideHere
)
3226 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3228 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3230 if (event
->xbutton
.state
& MOD_MASK
)
3231 wHideOtherApplications(btn
->icon
->owner
);
3233 if (event
->xbutton
.button
== Button1
) {
3234 if (event
->xbutton
.state
& MOD_MASK
) {
3235 /* raise/lower dock */
3236 toggleLowered(dock
);
3237 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3238 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
)
3239 toggleCollapsed(dock
);
3241 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3242 } else if (btn
->command
) {
3243 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3244 launchDockedApplication(btn
, False
);
3245 } else if (btn
->xindex
== 0 && btn
->yindex
== 0 && btn
->dock
->type
== WM_DOCK
) {
3246 wShowInfoPanel(dock
->screen_ptr
);
3252 static void handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3254 WScreen
*scr
= dock
->screen_ptr
;
3255 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3258 int grabbed
= 0, swapped
= 0, done
;
3259 Pixmap ghost
= None
;
3260 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3262 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3263 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3264 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
)
3265 wwarning("pointer grab failed for dock move");
3268 for (x
= 0; x
< dock
->max_icons
; x
++) {
3269 if (dock
->icon_array
[x
] != NULL
&& dock
->icon_array
[x
]->yindex
> y
)
3270 y
= dock
->icon_array
[x
]->yindex
;
3273 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
* y
);
3277 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3278 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3285 /* It means the cursor moved so fast that it entered
3286 * something else (if moving slowly, it would have
3287 * stayed in the dock that is being moved. Ignore such
3288 * "spurious" EnterNotifiy's */
3293 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3294 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3295 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3296 | ButtonReleaseMask
| ButtonPressMask
,
3297 wCursor
[WCUR_MOVE
], CurrentTime
);
3302 if (dock
->type
== WM_CLIP
) {
3303 x
= ev
.xmotion
.x_root
- ofs_x
;
3304 y
= ev
.xmotion
.y_root
- ofs_y
;
3305 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3307 moveDock(dock
, x
, y
);
3309 /* move vertically if pointer is inside the dock */
3310 if ((dock
->on_right_side
&& ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3311 || (!dock
->on_right_side
&& ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
* 2)) {
3313 x
= ev
.xmotion
.x_root
- ofs_x
;
3314 y
= ev
.xmotion
.y_root
- ofs_y
;
3315 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3316 moveDock(dock
, dock
->x_pos
, y
);
3318 /* move horizontally to change sides */
3319 x
= ev
.xmotion
.x_root
- ofs_x
;
3320 if (!dock
->on_right_side
) {
3323 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
* 2) {
3324 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
- ICON_SIZE
3325 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3326 if (superfluous
&& ghost
== None
) {
3327 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3328 scr
->scr_width
- ICON_SIZE
3329 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3330 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3331 XClearWindow(dpy
, scr
->dock_shadow
);
3333 XMapRaised(dpy
, scr
->dock_shadow
);
3336 if (superfluous
&& ghost
!= None
) {
3337 XFreePixmap(dpy
, ghost
);
3340 XUnmapWindow(dpy
, scr
->dock_shadow
);
3345 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3346 XMoveWindow(dpy
, scr
->dock_shadow
, DOCK_EXTRA_SPACE
, dock
->y_pos
);
3347 if (superfluous
&& ghost
== None
) {
3348 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3349 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3350 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3351 XClearWindow(dpy
, scr
->dock_shadow
);
3353 XMapRaised(dpy
, scr
->dock_shadow
);
3356 XUnmapWindow(dpy
, scr
->dock_shadow
);
3358 if (superfluous
&& ghost
!= None
) {
3359 XFreePixmap(dpy
, ghost
);
3371 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3373 XUngrabPointer(dpy
, CurrentTime
);
3374 XUnmapWindow(dpy
, scr
->dock_shadow
);
3375 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3376 if (dock
->type
== WM_DOCK
) {
3379 dock
->on_right_side
= 1;
3381 dock
->on_right_side
= 0;
3383 wArrangeIcons(scr
, False
);
3392 XFreePixmap(dpy
, ghost
);
3393 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3397 static Bool
handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3399 WScreen
*scr
= dock
->screen_ptr
;
3401 WIcon
*icon
= aicon
->icon
;
3402 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3403 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3405 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3406 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3407 int shad_x
= x
, shad_y
= y
;
3408 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3410 Pixmap ghost
= None
;
3412 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3413 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3414 Bool showed_all_clips
= False
;
3415 Bool hasMoved
= False
;
3417 if (wPreferences
.flags
.noupdates
)
3420 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3421 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3422 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3425 if (!(event
->xbutton
.state
& MOD_MASK
))
3426 wRaiseFrame(icon
->core
);
3428 if (!wPreferences
.flags
.noclip
)
3429 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3431 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3433 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3436 wins
[0] = icon
->core
->window
;
3437 wins
[1] = scr
->dock_shadow
;
3438 XRestackWindows(dpy
, wins
, 2);
3439 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
3441 if (icon
->pixmap
!= None
)
3442 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3444 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3446 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3447 XClearWindow(dpy
, scr
->dock_shadow
);
3449 XMapWindow(dpy
, scr
->dock_shadow
);
3454 XMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3455 | ButtonMotionMask
| ExposureMask
, &ev
);
3464 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3465 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3466 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3467 | ButtonReleaseMask
| ButtonPressMask
,
3468 wCursor
[WCUR_MOVE
], CurrentTime
);
3475 if (omnipresent
&& !showed_all_clips
) {
3477 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3478 if (i
== scr
->current_workspace
)
3480 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3481 /* Note: if dock is collapsed (for instance,
3482 because it auto-collapses), its icons
3483 still won't show up */
3485 showed_all_clips
= True
; /* To prevent flickering */
3488 x
= ev
.xmotion
.x_root
- ofs_x
;
3489 y
= ev
.xmotion
.y_root
- ofs_y
;
3490 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3493 if (last_dock
!= dock
&& collapsed
) {
3494 last_dock
->collapsed
= 1;
3495 wDockHideIcons(last_dock
);
3498 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3499 dock
->collapsed
= 0;
3500 wDockShowIcons(dock
);
3502 if (dock
->auto_raise_lower
)
3506 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3509 if (last_dock
!= dock2
&& collapsed
) {
3510 last_dock
->collapsed
= 1;
3511 wDockHideIcons(last_dock
);
3514 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3515 dock2
->collapsed
= 0;
3516 wDockShowIcons(dock2
);
3518 if (dock2
->auto_raise_lower
)
3523 if (aicon
->launching
|| aicon
->lock
|| (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3524 || (!aicon
->running
&& tmp
)) {
3525 shad_x
= last_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3526 shad_y
= last_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3528 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3531 XMapWindow(dpy
, scr
->dock_shadow
);
3536 XUnmapWindow(dpy
, scr
->dock_shadow
);
3540 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3547 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3549 XUngrabPointer(dpy
, CurrentTime
);
3551 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3552 XUnmapWindow(dpy
, scr
->dock_shadow
);
3554 reattachIcon(dock
, aicon
, ix
, iy
);
3555 if (clip
&& dock
!= clip
&& clip
->auto_raise_lower
)
3558 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3560 /* Slide it back if dock rejected it */
3561 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
, aicon
->y_pos
);
3562 reattachIcon(dock
, aicon
, aicon
->xindex
, aicon
->yindex
);
3564 if (last_dock
->type
== WM_CLIP
&& last_dock
->auto_collapse
)
3571 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3572 /* We need to deselect it, even if is deselected in
3573 * wDockDetach(), because else DoKaboom() will fail.
3575 if (aicon
->icon
->selected
)
3576 wIconSelect(aicon
->icon
);
3578 DoKaboom(scr
, aicon
->icon
->core
->window
, x
, y
);
3581 if (clip
&& clip
->auto_raise_lower
)
3583 wDockDetach(dock
, aicon
);
3586 last_dock
->collapsed
= 1;
3587 wDockHideIcons(last_dock
);
3592 XFreePixmap(dpy
, ghost
);
3593 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3595 if (showed_all_clips
) {
3597 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3598 if (i
== scr
->current_workspace
)
3600 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3606 return False
; /* never reached */
3609 static int getClipButton(int px
, int py
)
3611 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3613 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3616 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3617 return CLIP_FORWARD
;
3618 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3624 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3627 int done
, direction
, new_ws
;
3629 WDock
*clip
= scr
->clip_icon
->dock
;
3631 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3633 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3634 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3636 wClipIconPaint(scr
->clip_icon
);
3639 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3646 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3647 if (new_dir
!= direction
) {
3648 direction
= new_dir
;
3649 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3650 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3651 wClipIconPaint(scr
->clip_icon
);
3659 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3664 clip
->lclip_button_pushed
= 0;
3665 clip
->rclip_button_pushed
= 0;
3667 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3669 if (direction
== CLIP_FORWARD
) {
3670 if (scr
->current_workspace
< scr
->workspace_count
- 1)
3671 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3672 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
- 1)
3673 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3674 else if (wPreferences
.ws_cycle
)
3675 wWorkspaceChange(scr
, 0);
3676 } else if (direction
== CLIP_REWIND
) {
3677 if (scr
->current_workspace
> 0)
3678 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
3679 else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
)
3680 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
3683 wClipIconPaint(scr
->clip_icon
);
3686 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3688 WAppIcon
*aicon
= desc
->parent
;
3689 WDock
*dock
= aicon
->dock
;
3690 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3692 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3695 scr
->last_dock
= dock
;
3697 if (dock
->menu
->flags
.mapped
)
3698 wMenuUnmap(dock
->menu
);
3700 if (IsDoubleClick(scr
, event
)) {
3701 /* double-click was not in the main clip icon */
3702 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3703 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3704 iconDblClick(desc
, event
);
3709 if (event
->xbutton
.button
== Button1
) {
3710 if (event
->xbutton
.state
& MOD_MASK
)
3715 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
&& dock
->type
!= WM_DOCK
) {
3716 wIconSelect(aicon
->icon
);
3720 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3721 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
3722 && dock
->type
== WM_CLIP
)
3723 handleClipChangeWorkspace(scr
, event
);
3725 handleDockMove(dock
, aicon
, event
);
3727 Bool hasMoved
= handleIconMove(dock
, aicon
, event
);
3728 if (wPreferences
.single_click
&& !hasMoved
)
3729 iconDblClick(desc
, event
);
3731 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&& aicon
== scr
->clip_icon
) {
3732 if (!scr
->clip_ws_menu
) {
3733 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3735 if (scr
->clip_ws_menu
) {
3736 WMenu
*wsMenu
= scr
->clip_ws_menu
;
3739 wWorkspaceMenuUpdate(scr
, wsMenu
);
3741 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
3744 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
3745 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
3747 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
3749 desc
= &wsMenu
->menu
->descriptor
;
3750 event
->xany
.send_event
= True
;
3751 (*desc
->handle_mousedown
) (desc
, event
);
3753 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
3754 (event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
) {
3755 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3756 } else if (event
->xbutton
.button
== Button3
) {
3757 if (event
->xbutton
.send_event
&&
3758 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3759 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3760 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3761 wwarning("pointer grab failed for dockicon menu");
3765 openDockMenu(dock
, aicon
, event
);
3766 } else if (event
->xbutton
.button
== Button2
) {
3767 WAppIcon
*btn
= desc
->parent
;
3769 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3770 launchDockedApplication(btn
, True
);
3774 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3776 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3780 assert(event
->type
== EnterNotify
);
3782 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3785 scr
= btn
->icon
->core
->screen_ptr
;
3788 if (!dock
|| dock
->type
!= WM_CLIP
)
3791 /* The auto raise/lower code */
3792 if (dock
->auto_lower_magic
) {
3793 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3794 dock
->auto_lower_magic
= NULL
;
3796 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
)
3797 dock
->auto_raise_magic
= WMAddTimerHandler(wPreferences
.clip_auto_raise_delay
, clipAutoRaise
, (void *)dock
);
3799 /* The auto expand/collapse code */
3800 if (dock
->auto_collapse_magic
) {
3801 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3802 dock
->auto_collapse_magic
= NULL
;
3804 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
)
3805 dock
->auto_expand_magic
= WMAddTimerHandler(wPreferences
.clip_auto_expand_delay
, clipAutoExpand
, (void *)dock
);
3808 static void clipLeave(WDock
*dock
)
3811 WObjDescriptor
*desc
= NULL
;
3813 if (!dock
|| dock
->type
!= WM_CLIP
)
3816 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
3817 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3818 (XPointer
*) & desc
) != XCNOENT
3819 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
3820 && ((WAppIcon
*) desc
->parent
)->dock
&& ((WAppIcon
*) desc
->parent
)->dock
->type
== WM_CLIP
) {
3821 /* We didn't left the Clip yet */
3822 XPutBackEvent(dpy
, &event
);
3826 XPutBackEvent(dpy
, &event
);
3828 /* We entered a withdrawn window, so we're still in Clip */
3832 if (dock
->auto_raise_magic
) {
3833 WMDeleteTimerHandler(dock
->auto_raise_magic
);
3834 dock
->auto_raise_magic
= NULL
;
3836 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
)
3837 dock
->auto_lower_magic
= WMAddTimerHandler(wPreferences
.clip_auto_lower_delay
, clipAutoLower
, (void *)dock
);
3839 if (dock
->auto_expand_magic
) {
3840 WMDeleteTimerHandler(dock
->auto_expand_magic
);
3841 dock
->auto_expand_magic
= NULL
;
3843 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
)
3844 dock
->auto_collapse_magic
= WMAddTimerHandler(wPreferences
.clip_auto_collapse_delay
, clipAutoCollapse
, (void *)dock
);
3847 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
3849 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3851 assert(event
->type
== LeaveNotify
);
3853 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3856 clipLeave(btn
->dock
);
3859 static void clipAutoCollapse(void *cdata
)
3861 WDock
*dock
= (WDock
*) cdata
;
3863 if (dock
->type
!= WM_CLIP
)
3866 if (dock
->auto_collapse
) {
3867 dock
->collapsed
= 1;
3868 wDockHideIcons(dock
);
3870 dock
->auto_collapse_magic
= NULL
;
3873 static void clipAutoExpand(void *cdata
)
3875 WDock
*dock
= (WDock
*) cdata
;
3877 if (dock
->type
!= WM_CLIP
)
3880 if (dock
->auto_collapse
) {
3881 dock
->collapsed
= 0;
3882 wDockShowIcons(dock
);
3884 dock
->auto_expand_magic
= NULL
;
3887 static void clipAutoLower(void *cdata
)
3889 WDock
*dock
= (WDock
*) cdata
;
3891 if (dock
->type
!= WM_CLIP
)
3894 if (dock
->auto_raise_lower
)
3897 dock
->auto_lower_magic
= NULL
;
3900 static void clipAutoRaise(void *cdata
)
3902 WDock
*dock
= (WDock
*) cdata
;
3904 if (dock
->type
!= WM_CLIP
)
3907 if (dock
->auto_raise_lower
)
3910 dock
->auto_raise_magic
= NULL
;
3913 static Bool
iconCanBeOmnipresent(WAppIcon
*aicon
)
3915 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3920 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3921 clip
= scr
->workspaces
[i
]->clip
;
3923 if (clip
== aicon
->dock
)
3926 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
3927 return False
; /* Clip is full in some workspace */
3929 for (j
= 0; j
< clip
->max_icons
; j
++) {
3930 btn
= clip
->icon_array
[j
];
3931 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
3939 int wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
3941 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3942 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
3943 int status
= WO_SUCCESS
;
3945 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== scr
->clip_icon
)
3946 return WO_NOT_APPLICABLE
;
3948 if (aicon
->omnipresent
== omnipresent
)
3952 if (iconCanBeOmnipresent(aicon
)) {
3953 aicon
->omnipresent
= 1;
3954 new_entry
= wmalloc(sizeof(WAppIconChain
));
3955 new_entry
->aicon
= aicon
;
3956 new_entry
->next
= scr
->global_icons
;
3957 scr
->global_icons
= new_entry
;
3958 scr
->global_icon_count
++;
3960 aicon
->omnipresent
= 0;
3964 aicon
->omnipresent
= 0;
3965 if (aicon
== scr
->global_icons
->aicon
) {
3966 tmp
= scr
->global_icons
->next
;
3967 wfree(scr
->global_icons
);
3968 scr
->global_icons
= tmp
;
3969 scr
->global_icon_count
--;
3971 tmp
= scr
->global_icons
;
3973 if (tmp
->next
->aicon
== aicon
) {
3974 tmp1
= tmp
->next
->next
;
3977 scr
->global_icon_count
--;
3985 wAppIconPaint(aicon
);