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"
57 #include "placement.h"
59 /**** Local variables ****/
62 #define CLIP_FORWARD 2
64 /**** Global variables ****/
65 extern Cursor wCursor
[WCUR_LAST
];
66 extern WPreferences wPreferences
;
67 extern XContext wWinContext
;
68 extern void appIconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
70 #define MOD_MASK wPreferences.modifier_mask
71 #define ICON_SIZE wPreferences.icon_size
73 /***** Local variables ****/
75 static WMPropList
*dCommand
= NULL
;
76 static WMPropList
*dPasteCommand
= NULL
;
77 #ifdef XDND /* XXX was OFFIX */
78 static WMPropList
*dDropCommand
= NULL
;
80 static WMPropList
*dAutoLaunch
, *dLock
;
81 static WMPropList
*dName
, *dForced
, *dBuggyApplication
, *dYes
, *dNo
;
82 static WMPropList
*dHost
, *dDock
, *dClip
;
83 static WMPropList
*dAutoAttractIcons
;
85 static WMPropList
*dPosition
, *dApplications
, *dLowered
, *dCollapsed
;
87 static WMPropList
*dAutoCollapse
, *dAutoRaiseLower
, *dOmnipresent
;
89 static void dockIconPaint(WAppIcon
*btn
);
91 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
93 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
);
95 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
97 static int getClipButton(int px
, int py
);
99 static void toggleLowered(WDock
*dock
);
101 static void toggleCollapsed(WDock
*dock
);
103 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
105 static void clipLeave(WDock
*dock
);
107 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
109 static Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
);
111 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
112 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
113 static void clipAutoCollapse(void *cdata
);
114 static void clipAutoExpand(void *cdata
);
115 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
);
117 static void clipAutoLower(void *cdata
);
118 static void clipAutoRaise(void *cdata
);
119 static void reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
);
120 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
);
122 static void make_keys(void)
124 if (dCommand
!= NULL
)
127 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
128 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
130 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
132 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
133 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
134 dName
= WMRetainPropList(WMCreatePLString("Name"));
135 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
136 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
137 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
138 dNo
= WMRetainPropList(WMCreatePLString("No"));
139 dHost
= WMRetainPropList(WMCreatePLString("Host"));
141 dPosition
= WMCreatePLString("Position");
142 dApplications
= WMCreatePLString("Applications");
143 dLowered
= WMCreatePLString("Lowered");
144 dCollapsed
= WMCreatePLString("Collapsed");
145 dAutoCollapse
= WMCreatePLString("AutoCollapse");
146 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
147 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
149 dOmnipresent
= WMCreatePLString("Omnipresent");
151 dDock
= WMCreatePLString("Dock");
152 dClip
= WMCreatePLString("Clip");
155 static void renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
157 WDock
*dock
= entry
->clientdata
;
162 assert(entry
->clientdata
!= NULL
);
164 wspace
= dock
->screen_ptr
->current_workspace
;
166 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
168 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+ 1);
169 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
, &name
))
170 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
175 static void toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
177 assert(entry
->clientdata
!= NULL
);
179 toggleLowered(entry
->clientdata
);
181 entry
->flags
.indicator_on
= !(((WDock
*) entry
->clientdata
)->lowered
);
186 static int matchWindow(const void *item
, const void *cdata
)
188 return (((WFakeGroupLeader
*) item
)->leader
== (Window
) cdata
);
191 static void killCallback(WMenu
*menu
, WMenuEntry
*entry
)
193 WScreen
*scr
= menu
->menu
->screen_ptr
;
195 WFakeGroupLeader
*fPtr
;
196 char *buffer
, *shortname
, **argv
;
197 char *basename(const char *shortname
);
200 if (!WCHECK_STATE(WSTATE_NORMAL
))
203 assert(entry
->clientdata
!= NULL
);
205 icon
= (WAppIcon
*) entry
->clientdata
;
209 WCHANGE_STATE(WSTATE_MODAL
);
211 /* strip away dir names */
212 shortname
= basename(icon
->command
);
213 /* separate out command options */
214 wtokensplit(shortname
, &argv
, &argc
);
216 buffer
= wstrconcat(argv
[0],
217 _(" will be forcibly closed.\n"
218 "Any unsaved changes will be lost.\n" "Please confirm."));
220 if (icon
->icon
&& icon
->icon
->owner
) {
221 fPtr
= icon
->icon
->owner
->fake_group
;
223 /* is this really necessary? can we kill a non-running dock icon? */
224 Window win
= icon
->main_window
;
227 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)win
);
228 if (index
!= WANotFound
)
229 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
234 if (wPreferences
.dont_confirm_kill
235 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
236 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
238 WWindow
*wwin
, *twin
;
240 wwin
= scr
->focused_window
;
243 if (wwin
->fake_group
== fPtr
)
248 } else if (icon
->icon
&& icon
->icon
->owner
) {
249 wClientKill(icon
->icon
->owner
);
254 wtokenfree(argv
, argc
);
258 WCHANGE_STATE(WSTATE_NORMAL
);
261 /* TODO: replace this function with a member of the dock struct */
262 static int numberOfSelectedIcons(WDock
*dock
)
268 for (i
= 1; i
< dock
->max_icons
; i
++) {
269 aicon
= dock
->icon_array
[i
];
270 if (aicon
&& aicon
->icon
->selected
)
277 static WMArray
*getSelected(WDock
*dock
)
279 WMArray
*ret
= WMCreateArray(8);
283 for (i
= 1; i
< dock
->max_icons
; i
++) {
284 btn
= dock
->icon_array
[i
];
285 if (btn
&& btn
->icon
->selected
)
286 WMAddToArray(ret
, btn
);
292 static void paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
294 Window win
= clipIcon
->icon
->core
->window
;
295 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
297 int pt
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
298 int tp
= ICON_SIZE
- pt
;
299 int as
= pt
- 15; /* 15 = 5+5+5 */
300 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
303 color
= scr
->clip_title_color
[CLIP_NORMAL
];
305 XSetForeground(dpy
, gc
, WMColorPixel(color
));
310 p
[1].x
= ICON_SIZE
- 2;
312 p
[2].x
= ICON_SIZE
- 2;
314 } else if (lpushed
) {
318 p
[1].y
= ICON_SIZE
- 2;
320 p
[2].y
= ICON_SIZE
- 2;
322 if (lpushed
|| rpushed
) {
323 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
324 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
325 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
328 /* top right arrow */
329 p
[0].x
= p
[3].x
= ICON_SIZE
- 5 - as
;
331 p
[1].x
= ICON_SIZE
- 6;
333 p
[2].x
= ICON_SIZE
- 6;
336 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
337 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
339 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
340 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
343 /* bottom left arrow */
345 p
[0].y
= p
[3].y
= ICON_SIZE
- 5 - as
;
347 p
[1].y
= ICON_SIZE
- 6;
349 p
[2].y
= ICON_SIZE
- 6;
351 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
352 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
354 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
355 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
359 RImage
*wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
361 RImage
*tile
= RCloneImage(normalTile
);
368 pt
= CLIP_BUTTON_SIZE
* wPreferences
.icon_size
/ 64;
369 tp
= wPreferences
.icon_size
- 1 - pt
;
373 black
.red
= black
.green
= black
.blue
= 0;
376 dark
.red
= dark
.green
= dark
.blue
= 60;
379 light
.red
= light
.green
= light
.blue
= 80;
382 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
- 2, pt
- 1, &dark
);
383 RDrawLine(tile
, tp
- 1, 0, wPreferences
.icon_size
- 1, pt
+ 1, &black
);
384 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
- 3, pt
, &light
);
387 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, 4, &dark
);
388 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 5, 6 + as
, &dark
);
389 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
, &light
);
392 ROperateLine(tile
, RAddOperation
, 2, tp
+ 2, pt
- 2, wPreferences
.icon_size
- 3, &dark
);
393 RDrawLine(tile
, 0, tp
- 1, pt
+ 1, wPreferences
.icon_size
- 1, &black
);
394 ROperateLine(tile
, RSubtractOperation
, 0, tp
- 2, pt
+ 1, wPreferences
.icon_size
- 2, &light
);
397 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, &dark
);
398 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
, 6 + as
, ICON_SIZE
- 5, &dark
);
399 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5, &light
);
404 static void omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
406 WAppIcon
*clickedIcon
= entry
->clientdata
;
409 WMArray
*selectedIcons
;
410 WMArrayIterator iter
;
413 assert(entry
->clientdata
!= NULL
);
415 dock
= clickedIcon
->dock
;
417 selectedIcons
= getSelected(dock
);
419 if (!WMGetArrayItemCount(selectedIcons
))
420 WMAddToArray(selectedIcons
, clickedIcon
);
423 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
424 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
426 else if (aicon
->icon
->selected
)
427 wIconSelect(aicon
->icon
);
429 WMFreeArray(selectedIcons
);
432 wMessageDialog(dock
->screen_ptr
, _("Warning"),
433 _("Some icons cannot be made omnipresent. "
434 "Please make sure that no other icon is "
435 "docked in the same positions on the other "
436 "workspaces and the Clip is not full in "
437 "some workspace."), _("OK"), NULL
, NULL
);
438 } else if (failed
== 1) {
439 wMessageDialog(dock
->screen_ptr
, _("Warning"),
440 _("Icon cannot be made omnipresent. "
441 "Please make sure that no other icon is "
442 "docked in the same position on the other "
443 "workspaces and the Clip is not full in "
444 "some workspace."), _("OK"), NULL
, NULL
);
448 static void removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
450 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
453 WMArray
*selectedIcons
;
457 assert(clickedIcon
!= NULL
);
459 dock
= clickedIcon
->dock
;
461 selectedIcons
= getSelected(dock
);
463 if (WMGetArrayItemCount(selectedIcons
)) {
464 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
465 _("All selected icons will be removed!"),
466 _("OK"), _("Cancel"), NULL
) != WAPRDefault
) {
467 WMFreeArray(selectedIcons
);
471 if (clickedIcon
->xindex
== 0 && clickedIcon
->yindex
== 0) {
472 WMFreeArray(selectedIcons
);
475 WMAddToArray(selectedIcons
, clickedIcon
);
478 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
479 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
480 wDockDetach(dock
, aicon
);
482 /* XXX: can: aicon->icon == NULL ? */
483 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
484 wGetHeadForWindow(aicon
->icon
->owner
));
485 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
486 if (!dock
->mapped
|| dock
->collapsed
)
487 XMapWindow(dpy
, aicon
->icon
->core
->window
);
490 WMFreeArray(selectedIcons
);
492 if (wPreferences
.auto_arrange_icons
)
493 wArrangeIcons(dock
->screen_ptr
, True
);
496 static void keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
498 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
501 WMArray
*selectedIcons
;
504 assert(clickedIcon
!= NULL
);
505 dock
= clickedIcon
->dock
;
507 selectedIcons
= getSelected(dock
);
509 if (!WMGetArrayItemCount(selectedIcons
)
510 && clickedIcon
!= dock
->screen_ptr
->clip_icon
) {
511 char *command
= NULL
;
513 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
514 clickedIcon
->editing
= 1;
515 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
516 _("Type the command used to launch the application"), &command
)) {
517 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
521 clickedIcon
->command
= command
;
522 clickedIcon
->editing
= 0;
524 clickedIcon
->editing
= 0;
527 WMFreeArray(selectedIcons
);
532 WMAddToArray(selectedIcons
, clickedIcon
);
535 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
536 if (aicon
->icon
->selected
)
537 wIconSelect(aicon
->icon
);
539 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
540 aicon
->attracted
= 0;
541 if (aicon
->icon
->shadowed
) {
542 aicon
->icon
->shadowed
= 0;
545 * Update icon pixmap, RImage doesn't change,
546 * so call wIconUpdate is not needed
548 update_icon_pixmap(aicon
->icon
);
551 wAppIconPaint(aicon
);
554 save_appicon(aicon
, True
);
556 WMFreeArray(selectedIcons
);
559 static void toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
561 WDock
*dock
= (WDock
*) entry
->clientdata
;
563 assert(entry
->clientdata
!= NULL
);
565 dock
->attract_icons
= !dock
->attract_icons
;
567 entry
->flags
.indicator_on
= dock
->attract_icons
;
572 static void selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
574 WAppIcon
*icon
= (WAppIcon
*) entry
->clientdata
;
576 assert(icon
!= NULL
);
578 wIconSelect(icon
->icon
);
583 static void colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
585 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
588 int x
, y
, x_pos
, y_pos
;
589 Bool update_icon
= False
;
591 assert(entry
->clientdata
!= NULL
);
592 clip
= clickedIcon
->dock
;
594 aicon
= clip
->screen_ptr
->app_icon_list
;
597 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
598 x_pos
= clip
->x_pos
+ x
* ICON_SIZE
;
599 y_pos
= clip
->y_pos
+ y
* ICON_SIZE
;
600 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
)
601 move_window(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
603 aicon
->attracted
= 1;
604 if (!aicon
->icon
->shadowed
) {
605 aicon
->icon
->shadowed
= 1;
608 wDockAttachIcon(clip
, aicon
, x
, y
, update_icon
);
609 if (clip
->collapsed
|| !clip
->mapped
)
610 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
616 static void selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
618 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
620 WMArray
*selectedIcons
;
621 WMArrayIterator iter
;
625 assert(clickedIcon
!= NULL
);
626 dock
= clickedIcon
->dock
;
628 selectedIcons
= getSelected(dock
);
630 if (!WMGetArrayItemCount(selectedIcons
)) {
631 for (i
= 1; i
< dock
->max_icons
; i
++) {
632 btn
= dock
->icon_array
[i
];
633 if (btn
&& !btn
->icon
->selected
)
634 wIconSelect(btn
->icon
);
637 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
638 wIconSelect(btn
->icon
);
641 WMFreeArray(selectedIcons
);
646 static void toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
648 assert(entry
->clientdata
!= NULL
);
650 toggleCollapsed(entry
->clientdata
);
652 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->collapsed
;
657 static void toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
660 assert(entry
->clientdata
!= NULL
);
662 dock
= (WDock
*) entry
->clientdata
;
664 dock
->auto_collapse
= !dock
->auto_collapse
;
666 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_collapse
;
671 static void toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
674 assert(entry
->clientdata
!= NULL
);
676 dock
= (WDock
*) entry
->clientdata
;
678 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
680 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_raise_lower
;
685 static void launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
687 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
689 launchDockedApplication(btn
, False
);
692 static void settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
694 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
698 ShowDockAppSettingsPanel(btn
);
701 static void hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
704 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
706 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
708 if (wapp
->flags
.hidden
) {
709 wWorkspaceChange(btn
->icon
->core
->screen_ptr
, wapp
->last_workspace
);
710 wUnhideApplication(wapp
, False
, False
);
712 wHideApplication(wapp
);
716 static void unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
719 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
721 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
723 wUnhideApplication(wapp
, False
, True
);
726 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
)
731 if (type
== WM_CLIP
) {
733 return scr
->clip_icon
;
734 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
735 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
736 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
737 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
740 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
741 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
747 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
748 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
749 btn
->icon
->core
->descriptor
.parent
= btn
;
750 XMapWindow(dpy
, btn
->icon
->core
->window
);
755 scr
->clip_icon
= btn
;
760 static void switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
762 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
763 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
765 WMArray
*selectedIcons
;
768 if (entry
->order
== scr
->current_workspace
)
771 dest
= scr
->workspaces
[entry
->order
]->clip
;
773 selectedIcons
= getSelected(src
);
775 if (WMGetArrayItemCount(selectedIcons
)) {
776 WMArrayIterator iter
;
778 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
779 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
780 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
781 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
784 } else if (icon
!= scr
->clip_icon
) {
785 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
786 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
787 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
790 WMFreeArray(selectedIcons
);
793 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
)
795 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
797 if (!btn
->launching
&&
798 ((!withSelection
&& btn
->command
!= NULL
) || (withSelection
&& btn
->paste_command
!= NULL
))) {
799 if (!btn
->forced_dock
) {
800 btn
->relaunching
= btn
->running
;
803 if (btn
->wm_instance
|| btn
->wm_class
) {
804 WWindowAttributes attr
;
805 memset(&attr
, 0, sizeof(WWindowAttributes
));
806 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
808 if (!attr
.no_appicon
&& !btn
->buggy_app
)
813 btn
->drop_launch
= 0;
814 btn
->paste_launch
= withSelection
;
815 scr
->last_dock
= btn
->dock
;
816 btn
->pid
= execCommand(btn
, (withSelection
? btn
->paste_command
: btn
->command
), NULL
);
818 if (btn
->buggy_app
) {
819 /* give feedback that the app was launched */
823 WMAddTimerHandler(200, (WMCallback
*) dockIconPaint
, btn
);
828 wwarning(_("could not launch application %s"), btn
->command
);
830 if (!btn
->relaunching
)
836 static void updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
838 WScreen
*scr
= menu
->frame
->screen_ptr
;
839 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
845 for (i
= 0; i
< scr
->workspace_count
; i
++) {
846 if (i
< menu
->entry_no
) {
847 if (strcmp(menu
->entries
[i
]->text
, scr
->workspaces
[i
]->name
) != 0) {
848 wfree(menu
->entries
[i
]->text
);
849 strcpy(title
, scr
->workspaces
[i
]->name
);
850 menu
->entries
[i
]->text
= wstrdup(title
);
851 menu
->flags
.realized
= 0;
853 menu
->entries
[i
]->clientdata
= (void *)icon
;
855 strcpy(title
, scr
->workspaces
[i
]->name
);
857 wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)icon
);
859 menu
->flags
.realized
= 0;
862 if (i
== scr
->current_workspace
)
863 wMenuSetEnabled(menu
, i
, False
);
865 wMenuSetEnabled(menu
, i
, True
);
868 if (!menu
->flags
.realized
)
872 static WMenu
*makeWorkspaceMenu(WScreen
*scr
)
876 menu
= wMenuCreate(scr
, NULL
, False
);
878 wwarning(_("could not create workspace submenu for Clip menu"));
880 wMenuAddCallback(menu
, "", switchWSCommand
, (void *)scr
->clip_icon
);
882 menu
->flags
.realized
= 0;
888 static void updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
897 entry
= menu
->entries
[index
];
898 entry
->flags
.indicator_on
= !dock
->lowered
;
899 entry
->clientdata
= dock
;
902 entry
= menu
->entries
[++index
];
903 entry
->flags
.indicator_on
= dock
->collapsed
;
904 entry
->clientdata
= dock
;
907 entry
= menu
->entries
[++index
];
908 entry
->flags
.indicator_on
= dock
->auto_collapse
;
909 entry
->clientdata
= dock
;
911 /* auto-raise/lower */
912 entry
= menu
->entries
[++index
];
913 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
914 entry
->clientdata
= dock
;
915 wMenuSetEnabled(menu
, index
, dock
->lowered
);
918 entry
= menu
->entries
[++index
];
919 entry
->flags
.indicator_on
= dock
->attract_icons
;
920 entry
->clientdata
= dock
;
922 menu
->flags
.realized
= 0;
926 static WMenu
*makeClipOptionsMenu(WScreen
*scr
)
931 menu
= wMenuCreate(scr
, NULL
, False
);
933 wwarning(_("could not create options submenu for Clip menu"));
937 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
938 entry
->flags
.indicator
= 1;
939 entry
->flags
.indicator_on
= 1;
940 entry
->flags
.indicator_type
= MI_CHECK
;
942 entry
= wMenuAddCallback(menu
, _("Collapsed"), toggleCollapsedCallback
, NULL
);
943 entry
->flags
.indicator
= 1;
944 entry
->flags
.indicator_on
= 1;
945 entry
->flags
.indicator_type
= MI_CHECK
;
947 entry
= wMenuAddCallback(menu
, _("Autocollapse"), toggleAutoCollapseCallback
, NULL
);
948 entry
->flags
.indicator
= 1;
949 entry
->flags
.indicator_on
= 1;
950 entry
->flags
.indicator_type
= MI_CHECK
;
952 entry
= wMenuAddCallback(menu
, _("Autoraise"), toggleAutoRaiseLowerCallback
, NULL
);
953 entry
->flags
.indicator
= 1;
954 entry
->flags
.indicator_on
= 1;
955 entry
->flags
.indicator_type
= MI_CHECK
;
957 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"), toggleAutoAttractCallback
, NULL
);
958 entry
->flags
.indicator
= 1;
959 entry
->flags
.indicator_on
= 1;
960 entry
->flags
.indicator_type
= MI_CHECK
;
962 menu
->flags
.realized
= 0;
968 static WMenu
*dockMenuCreate(WScreen
*scr
, int type
)
973 if (type
== WM_CLIP
&& scr
->clip_menu
)
974 return scr
->clip_menu
;
976 menu
= wMenuCreate(scr
, NULL
, False
);
977 if (type
!= WM_CLIP
) {
978 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
979 entry
->flags
.indicator
= 1;
980 entry
->flags
.indicator_on
= 1;
981 entry
->flags
.indicator_type
= MI_CHECK
;
983 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
984 scr
->clip_options
= makeClipOptionsMenu(scr
);
985 if (scr
->clip_options
)
986 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
988 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
990 entry
->text
= _("Rename Workspace");
992 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
993 entry
->flags
.indicator
= 1;
994 entry
->flags
.indicator_on
= 1;
995 entry
->flags
.indicator_type
= MI_CHECK
;
997 entry
= wMenuAddCallback(menu
, _("Select All Icons"), selectIconsCallback
, NULL
);
999 entry
->text
= _("Select All Icons");
1001 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1003 entry
->text
= _("Keep Icon");
1005 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1007 entry
->text
= _("Move Icon To");
1008 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1009 if (scr
->clip_submenu
)
1010 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1012 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
, NULL
);
1014 entry
->text
= _("Remove Icon");
1016 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1019 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1021 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1023 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1025 entry
->text
= _("Hide");
1027 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1029 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1031 if (type
== WM_CLIP
)
1032 scr
->clip_menu
= menu
;
1037 WDock
*wDockCreate(WScreen
*scr
, int type
)
1044 dock
= wmalloc(sizeof(WDock
));
1046 dock
->max_icons
= DOCK_MAX_ICONS
;
1048 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * dock
->max_icons
);
1050 btn
= mainIconCreate(scr
, type
);
1054 dock
->x_pos
= btn
->x_pos
;
1055 dock
->y_pos
= btn
->y_pos
;
1056 dock
->screen_ptr
= scr
;
1058 dock
->icon_count
= 1;
1059 dock
->on_right_side
= 1;
1060 dock
->collapsed
= 0;
1061 dock
->auto_collapse
= 0;
1062 dock
->auto_collapse_magic
= NULL
;
1063 dock
->auto_raise_lower
= 0;
1064 dock
->auto_lower_magic
= NULL
;
1065 dock
->auto_raise_magic
= NULL
;
1066 dock
->attract_icons
= 0;
1068 dock
->icon_array
[0] = btn
;
1069 wRaiseFrame(btn
->icon
->core
);
1070 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1072 /* create dock menu */
1073 dock
->menu
= dockMenuCreate(scr
, type
);
1078 void wDockDestroy(WDock
*dock
)
1083 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1084 aicon
= dock
->icon_array
[i
];
1086 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1087 wDockDetach(dock
, aicon
);
1089 /* XXX: can: aicon->icon == NULL ? */
1090 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1091 wGetHeadForWindow(aicon
->icon
->owner
));
1092 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1093 if (!dock
->mapped
|| dock
->collapsed
)
1094 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1098 if (wPreferences
.auto_arrange_icons
)
1099 wArrangeIcons(dock
->screen_ptr
, True
);
1100 wfree(dock
->icon_array
);
1101 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1102 wMenuDestroy(dock
->menu
, True
);
1103 if (dock
->screen_ptr
->last_dock
== dock
)
1104 dock
->screen_ptr
->last_dock
= NULL
;
1108 void wClipIconPaint(WAppIcon
*aicon
)
1110 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1111 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1113 Window win
= aicon
->icon
->core
->window
;
1114 int length
, nlength
;
1115 char *ws_name
, ws_number
[10];
1118 wIconPaint(aicon
->icon
);
1120 length
= strlen(workspace
->name
);
1121 ws_name
= wmalloc(length
+ 1);
1122 snprintf(ws_name
, length
+ 1, "%s", workspace
->name
);
1123 snprintf(ws_number
, sizeof(ws_number
), "%i", scr
->current_workspace
+ 1);
1124 nlength
= strlen(ws_number
);
1126 if (!workspace
->clip
->collapsed
)
1127 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1129 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1131 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1133 tx
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
1135 if(wPreferences
.show_clip_title
)
1136 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, ty
, ws_name
, length
);
1138 tx
= (ICON_SIZE
/ 2 - WMWidthOfString(scr
->clip_title_font
, ws_number
, nlength
)) / 2;
1140 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, 2, ws_number
, nlength
);
1144 if (aicon
->launching
)
1145 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1146 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1148 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
, aicon
->dock
->rclip_button_pushed
);
1151 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1153 wClipIconPaint(desc
->parent
);
1156 static void dockIconPaint(WAppIcon
*btn
)
1158 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
) {
1159 wClipIconPaint(btn
);
1162 save_appicon(btn
, True
);
1166 static WMPropList
*make_icon_state(WAppIcon
*btn
)
1168 WMPropList
*node
= NULL
;
1169 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
;
1170 WMPropList
*position
, *buggy
, *omnipresent
;
1176 command
= WMCreatePLString("-");
1178 command
= WMCreatePLString(btn
->command
);
1180 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1182 lock
= btn
->lock
? dYes
: dNo
;
1184 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1186 name
= WMCreatePLString(tmp
);
1190 forced
= btn
->forced_dock
? dYes
: dNo
;
1192 buggy
= btn
->buggy_app
? dYes
: dNo
;
1194 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1195 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1197 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1198 position
= WMCreatePLString(buffer
);
1200 node
= WMCreatePLDictionary(dCommand
, command
,
1202 dAutoLaunch
, autolaunch
,
1204 dForced
, forced
, dBuggyApplication
, buggy
, dPosition
, position
, NULL
);
1205 WMReleasePropList(command
);
1206 WMReleasePropList(name
);
1207 WMReleasePropList(position
);
1209 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1210 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&& (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1211 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1213 #ifdef XDND /* was OFFIX */
1214 if (btn
->dnd_command
) {
1215 command
= WMCreatePLString(btn
->dnd_command
);
1216 WMPutInPLDictionary(node
, dDropCommand
, command
);
1217 WMReleasePropList(command
);
1221 if (btn
->paste_command
) {
1222 command
= WMCreatePLString(btn
->paste_command
);
1223 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1224 WMReleasePropList(command
);
1231 static WMPropList
*dockSaveState(WDock
*dock
)
1234 WMPropList
*icon_info
;
1235 WMPropList
*list
= NULL
, *dock_state
= NULL
;
1236 WMPropList
*value
, *key
;
1239 list
= WMCreatePLArray(NULL
);
1241 for (i
= (dock
->type
== WM_DOCK
? 0 : 1); i
< dock
->max_icons
; i
++) {
1242 WAppIcon
*btn
= dock
->icon_array
[i
];
1244 if (!btn
|| btn
->attracted
)
1247 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1248 WMAddToPLArray(list
, icon_info
);
1249 WMReleasePropList(icon_info
);
1253 dock_state
= WMCreatePLDictionary(dApplications
, list
, NULL
);
1255 if (dock
->type
== WM_DOCK
) {
1256 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1257 key
= WMCreatePLString(buffer
);
1258 WMPutInPLDictionary(dock_state
, key
, list
);
1259 WMReleasePropList(key
);
1261 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0), dock
->y_pos
);
1262 value
= WMCreatePLString(buffer
);
1263 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1264 WMReleasePropList(value
);
1266 WMReleasePropList(list
);
1268 value
= (dock
->lowered
? dYes
: dNo
);
1269 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1271 if (dock
->type
== WM_CLIP
) {
1272 value
= (dock
->collapsed
? dYes
: dNo
);
1273 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1275 value
= (dock
->auto_collapse
? dYes
: dNo
);
1276 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1278 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1279 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1281 value
= (dock
->attract_icons
? dYes
: dNo
);
1282 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1288 void wDockSaveState(WScreen
*scr
, WMPropList
*old_state
)
1290 WMPropList
*dock_state
;
1293 dock_state
= dockSaveState(scr
->dock
);
1296 * Copy saved states of docks with different sizes.
1302 keys
= WMGetPLDictionaryKeys(old_state
);
1303 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1304 tmp
= WMGetFromPLArray(keys
, i
);
1306 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1307 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1309 WMPutInPLDictionary(dock_state
, tmp
, WMGetFromPLDictionary(old_state
, tmp
));
1312 WMReleasePropList(keys
);
1315 WMPutInPLDictionary(scr
->session_state
, dDock
, dock_state
);
1317 WMReleasePropList(dock_state
);
1320 void wClipSaveState(WScreen
*scr
)
1322 WMPropList
*clip_state
;
1324 clip_state
= make_icon_state(scr
->clip_icon
);
1326 WMPutInPLDictionary(scr
->session_state
, dClip
, clip_state
);
1328 WMReleasePropList(clip_state
);
1331 WMPropList
*wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1333 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1336 static Bool
getBooleanDockValue(WMPropList
*value
, WMPropList
*key
)
1339 if (WMIsPLString(value
)) {
1340 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1343 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1349 static WAppIcon
*restore_icon_state(WScreen
*scr
, WMPropList
*info
, int type
, int index
)
1352 WMPropList
*cmd
, *value
;
1353 char *wclass
, *winstance
, *command
;
1355 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1356 if (!cmd
|| !WMIsPLString(cmd
))
1359 /* parse window name */
1360 value
= WMGetFromPLDictionary(info
, dName
);
1364 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1366 if (!winstance
&& !wclass
)
1371 command
= wstrdup(WMGetFromPLString(cmd
));
1375 if (!command
|| strcmp(command
, "-") == 0) {
1386 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1394 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1395 if (type
== WM_CLIP
) {
1396 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1397 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1399 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1400 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1402 #ifdef XDND /* was OFFIX */
1403 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1405 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1408 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1410 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1412 /* check auto launch */
1413 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1415 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1418 value
= WMGetFromPLDictionary(info
, dLock
);
1420 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1422 /* check if it wasn't normally docked */
1423 value
= WMGetFromPLDictionary(info
, dForced
);
1425 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1427 /* check if we can rely on the stuff in the app */
1428 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1430 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1432 /* get position in the dock */
1433 value
= WMGetFromPLDictionary(info
, dPosition
);
1434 if (value
&& WMIsPLString(value
)) {
1435 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1436 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1438 /* check position sanity */
1439 /* incomplete section! */
1440 if (type
== WM_DOCK
) {
1442 if (aicon
->yindex
< 0)
1443 wwarning(_("bad value in docked icon position %i,%i"),
1444 aicon
->xindex
, aicon
->yindex
);
1447 aicon
->yindex
= index
;
1451 /* check if icon is omnipresent */
1452 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1454 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1462 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1464 WAppIcon
*wClipRestoreState(WScreen
*scr
, WMPropList
*clip_state
)
1469 icon
= mainIconCreate(scr
, WM_CLIP
);
1474 WMRetainPropList(clip_state
);
1476 /* restore position */
1478 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1481 if (!WMIsPLString(value
)) {
1482 COMPLAIN("Position");
1487 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1488 COMPLAIN("Position");
1490 /* check position sanity */
1491 rect
.pos
.x
= icon
->x_pos
;
1492 rect
.pos
.y
= icon
->y_pos
;
1493 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1495 wGetRectPlacementInfo(scr
, rect
, &flags
);
1496 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
1497 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1500 #ifdef XDND /* was OFFIX */
1501 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1502 if (value
&& WMIsPLString(value
))
1503 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1506 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1507 if (value
&& WMIsPLString(value
))
1508 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1510 WMReleasePropList(clip_state
);
1515 WDock
*wDockRestoreState(WScreen
*scr
, WMPropList
*dock_state
, int type
)
1520 WAppIcon
*aicon
, *old_top
;
1523 dock
= wDockCreate(scr
, type
);
1528 WMRetainPropList(dock_state
);
1530 /* restore position */
1531 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1533 if (!WMIsPLString(value
)) {
1534 COMPLAIN("Position");
1539 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1540 COMPLAIN("Position");
1542 /* check position sanity */
1543 rect
.pos
.x
= dock
->x_pos
;
1544 rect
.pos
.y
= dock
->y_pos
;
1545 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1547 wGetRectPlacementInfo(scr
, rect
, &flags
);
1548 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
)) {
1549 int x
= dock
->x_pos
;
1550 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1553 /* Is this needed any more? */
1554 if (type
== WM_CLIP
) {
1555 if (dock
->x_pos
< 0) {
1557 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1558 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1561 if (dock
->x_pos
>= 0) {
1562 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1563 dock
->on_right_side
= 0;
1565 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1566 dock
->on_right_side
= 1;
1572 /* restore lowered/raised state */
1575 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1577 if (!WMIsPLString(value
)) {
1578 COMPLAIN("Lowered");
1580 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1585 /* restore collapsed state */
1586 dock
->collapsed
= 0;
1588 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1590 if (!WMIsPLString(value
)) {
1591 COMPLAIN("Collapsed");
1593 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1594 dock
->collapsed
= 1;
1598 /* restore auto-collapsed state */
1599 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1601 if (!WMIsPLString(value
)) {
1602 COMPLAIN("AutoCollapse");
1604 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1605 dock
->auto_collapse
= 1;
1606 dock
->collapsed
= 1;
1611 /* restore auto-raise/lower state */
1612 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1614 if (!WMIsPLString(value
)) {
1615 COMPLAIN("AutoRaiseLower");
1617 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1618 dock
->auto_raise_lower
= 1;
1622 /* restore attract icons state */
1623 dock
->attract_icons
= 0;
1625 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1627 if (!WMIsPLString(value
)) {
1628 COMPLAIN("AutoAttractIcons");
1630 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1631 dock
->attract_icons
= 1;
1635 /* application list */
1642 * When saving, it saves the dock state in
1643 * Applications and Applicationsnnn
1645 * When loading, it will first try Applicationsnnn.
1646 * If it does not exist, use Applications as default.
1649 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1651 tmp
= WMCreatePLString(buffer
);
1652 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1653 WMReleasePropList(tmp
);
1656 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1662 count
= WMGetPropListItemCount(apps
);
1666 old_top
= dock
->icon_array
[0];
1668 /* dock->icon_count is set to 1 when dock is created.
1669 * Since Clip is already restored, we want to keep it so for clip,
1670 * but for dock we may change the default top tile, so we set it to 0.
1672 if (type
== WM_DOCK
)
1673 dock
->icon_count
= 0;
1675 for (i
= 0; i
< count
; i
++) {
1676 if (dock
->icon_count
>= dock
->max_icons
) {
1677 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1681 value
= WMGetFromPLArray(apps
, i
);
1682 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1684 dock
->icon_array
[dock
->icon_count
] = aicon
;
1688 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1689 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1692 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1694 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1696 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1697 if (!dock
->collapsed
)
1698 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1700 wRaiseFrame(aicon
->icon
->core
);
1703 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
) {
1708 /* if the first icon is not defined, use the default */
1709 if (dock
->icon_array
[0] == NULL
) {
1710 /* update default icon */
1711 old_top
->x_pos
= dock
->x_pos
;
1712 old_top
->y_pos
= dock
->y_pos
;
1714 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1716 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1718 dock
->icon_array
[0] = old_top
;
1719 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1720 /* we don't need to increment dock->icon_count here because it was
1721 * incremented in the loop above.
1723 } else if (old_top
!= dock
->icon_array
[0]) {
1724 if (old_top
== scr
->clip_icon
)
1725 scr
->clip_icon
= dock
->icon_array
[0];
1727 wAppIconDestroy(old_top
);
1731 WMReleasePropList(dock_state
);
1736 void wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1738 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1739 btn
->drop_launch
= 0;
1740 btn
->paste_launch
= 0;
1742 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1745 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1755 void wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1761 for (i
= 0; i
< dock
->max_icons
; i
++) {
1762 btn
= dock
->icon_array
[i
];
1763 if (!btn
|| !btn
->auto_launch
)
1766 state
= wmalloc(sizeof(WSavedState
));
1767 state
->workspace
= workspace
;
1768 /* TODO: this is klugy and is very difficult to understand
1769 * what's going on. Try to clean up */
1770 wDockLaunchWithState(dock
, btn
, state
);
1774 #ifdef XDND /* was OFFIX */
1775 static WDock
*findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1781 if ((dock
= scr
->dock
) != NULL
) {
1782 for (i
= 0; i
< dock
->max_icons
; i
++) {
1783 if (dock
->icon_array
[i
]
1784 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1790 if (*icon_pos
< 0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
) != NULL
) {
1791 for (i
= 0; i
< dock
->max_icons
; i
++) {
1792 if (dock
->icon_array
[i
]
1793 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1804 int wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
1810 dock
= findDock(scr
, event
, &icon_pos
);
1815 * Return True if the drop was on an application icon window.
1816 * In this case, let the ClientMessage handler redirect the
1817 * message to the app.
1819 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
1822 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
1823 scr
->flags
.dnd_data_convertion_status
= 0;
1825 btn
= dock
->icon_array
[icon_pos
];
1827 if (!btn
->forced_dock
) {
1828 btn
->relaunching
= btn
->running
;
1831 if (btn
->wm_instance
|| btn
->wm_class
) {
1832 WWindowAttributes attr
;
1833 memset(&attr
, 0, sizeof(WWindowAttributes
));
1834 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
1836 if (!attr
.no_appicon
)
1842 btn
->paste_launch
= 0;
1843 btn
->drop_launch
= 1;
1844 scr
->last_dock
= dock
;
1845 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1850 if (!btn
->relaunching
)
1858 Bool
wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
, Bool update_icon
)
1861 Bool lupdate_icon
= False
;
1862 char *command
= NULL
;
1868 lupdate_icon
= True
;
1870 if (icon
->command
== NULL
) {
1871 /* If icon->owner exists, it means the application is running */
1872 if (icon
->icon
->owner
) {
1873 wwin
= icon
->icon
->owner
;
1874 command
= GetCommandForWindow(wwin
->client_win
);
1878 icon
->command
= command
;
1880 /* icon->forced_dock = 1; */
1881 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
1883 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
1884 _("Type the command used to launch the application"), &command
)) {
1885 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
1889 icon
->command
= command
;
1895 /* If the target is the dock, reject the icon. If
1896 * the target is the clip, make it an attracted icon
1898 if (dock
->type
== WM_CLIP
) {
1899 icon
->attracted
= 1;
1900 if (!icon
->icon
->shadowed
) {
1901 icon
->icon
->shadowed
= 1;
1902 lupdate_icon
= True
;
1912 for (index
= 1; index
< dock
->max_icons
; index
++)
1913 if (dock
->icon_array
[index
] == NULL
)
1915 /* if (index == dock->max_icons)
1918 assert(index
< dock
->max_icons
);
1920 dock
->icon_array
[index
] = icon
;
1924 icon
->omnipresent
= 0;
1926 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
1927 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
1932 icon
->launching
= 0;
1935 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1936 if (dock
->type
== WM_CLIP
) {
1937 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1938 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1940 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1941 icon
->icon
->core
->descriptor
.parent
= icon
;
1943 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
1944 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
1947 * Update icon pixmap, RImage doesn't change,
1948 * so call wIconUpdate is not needed
1951 update_icon_pixmap(icon
->icon
);
1954 wAppIconPaint(icon
);
1957 save_appicon(icon
, True
);
1959 if (wPreferences
.auto_arrange_icons
)
1960 wArrangeIcons(dock
->screen_ptr
, True
);
1962 #ifdef XDND /* was OFFIX */
1963 if (icon
->command
&& !icon
->dnd_command
) {
1964 int len
= strlen(icon
->command
) + 8;
1965 icon
->dnd_command
= wmalloc(len
);
1966 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
1970 if (icon
->command
&& !icon
->paste_command
) {
1971 int len
= strlen(icon
->command
) + 8;
1972 icon
->paste_command
= wmalloc(len
);
1973 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
1979 static void reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1983 for (index
= 1; index
< dock
->max_icons
; index
++) {
1984 if (dock
->icon_array
[index
] == icon
)
1987 assert(index
< dock
->max_icons
);
1992 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
1993 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
1996 static Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
1999 char *command
= NULL
;
2001 Bool update_icon
= False
;
2004 return True
; /* No move needed, we're already there */
2010 * For the moment we can't do this if we move icons in Clip from one
2011 * workspace to other, because if we move two or more icons without
2012 * command, the dialog box will not be able to tell us to which of the
2013 * moved icons it applies. -Dan
2015 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
2016 /* If icon->owner exists, it means the application is running */
2017 if (icon
->icon
->owner
) {
2018 wwin
= icon
->icon
->owner
;
2019 command
= GetCommandForWindow(wwin
->client_win
);
2023 icon
->command
= command
;
2026 /* icon->forced_dock = 1; */
2027 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2028 _("Type the command used to launch the application"), &command
)) {
2029 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2033 icon
->command
= command
;
2044 if (dest
->type
== WM_DOCK
)
2045 wClipMakeIconOmnipresent(icon
, False
);
2047 for (index
= 1; index
< src
->max_icons
; index
++) {
2048 if (src
->icon_array
[index
] == icon
)
2051 assert(index
< src
->max_icons
);
2053 src
->icon_array
[index
] = NULL
;
2056 for (index
= 1; index
< dest
->max_icons
; index
++) {
2057 if (dest
->icon_array
[index
] == NULL
)
2061 assert(index
< dest
->max_icons
);
2063 dest
->icon_array
[index
] = icon
;
2066 /* deselect the icon */
2067 if (icon
->icon
->selected
)
2068 wIconSelect(icon
->icon
);
2070 if (dest
->type
== WM_DOCK
) {
2071 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2072 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2074 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2075 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2078 /* set it to be kept when moving to dock.
2079 * Unless the icon does not have a command set
2081 if (icon
->command
&& dest
->type
== WM_DOCK
) {
2082 icon
->attracted
= 0;
2083 if (icon
->icon
->shadowed
) {
2084 icon
->icon
->shadowed
= 0;
2087 save_appicon(icon
, True
);
2090 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2096 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2097 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2101 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2104 * Update icon pixmap, RImage doesn't change,
2105 * so call wIconUpdate is not needed
2108 update_icon_pixmap(icon
->icon
);
2111 wAppIconPaint(icon
);
2116 void wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2119 Bool update_icon
= False
;
2121 /* make the settings panel be closed */
2123 DestroyDockAppSettingsPanel(icon
->panel
);
2125 /* This must be called before icon->dock is set to NULL.
2126 * Don't move it. -Dan
2128 wClipMakeIconOmnipresent(icon
, False
);
2132 icon
->attracted
= 0;
2133 icon
->auto_launch
= 0;
2134 if (icon
->icon
->shadowed
) {
2135 icon
->icon
->shadowed
= 0;
2139 /* deselect the icon */
2140 if (icon
->icon
->selected
)
2141 wIconSelect(icon
->icon
);
2143 if (icon
->command
) {
2144 wfree(icon
->command
);
2145 icon
->command
= NULL
;
2147 #ifdef XDND /* was OFFIX */
2148 if (icon
->dnd_command
) {
2149 wfree(icon
->dnd_command
);
2150 icon
->dnd_command
= NULL
;
2153 if (icon
->paste_command
) {
2154 wfree(icon
->paste_command
);
2155 icon
->paste_command
= NULL
;
2158 for (index
= 1; index
< dock
->max_icons
; index
++)
2159 if (dock
->icon_array
[index
] == icon
)
2162 assert(index
< dock
->max_icons
);
2163 dock
->icon_array
[index
] = NULL
;
2169 /* if the dock is not attached to an application or
2170 * the application did not set the appropriate hints yet,
2171 * destroy the icon */
2172 if (!icon
->running
|| !wApplicationOf(icon
->main_window
)) {
2173 wAppIconDestroy(icon
);
2175 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2176 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2177 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2178 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2179 icon
->icon
->core
->descriptor
.parent
= icon
;
2181 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2184 * Update icon pixmap, RImage doesn't change,
2185 * so call wIconUpdate is not needed
2188 update_icon_pixmap(icon
->icon
);
2191 wAppIconPaint(icon
);
2193 if (wPreferences
.auto_arrange_icons
)
2194 wArrangeIcons(dock
->screen_ptr
, True
);
2196 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2201 * returns the closest Dock slot index for the passed
2204 * Returns False if icon can't be docked.
2206 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2209 Bool
wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2211 WScreen
*scr
= dock
->screen_ptr
;
2214 int i
, offset
= ICON_SIZE
/ 2;
2215 WAppIcon
*aicon
= NULL
;
2216 WAppIcon
*nicon
= NULL
;
2219 /* TODO: XINERAMA, for these */
2220 max_y_icons
= scr
->scr_height
/ ICON_SIZE
- 1;
2222 if (wPreferences
.flags
.noupdates
)
2228 /* if the dock is full */
2229 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
))
2232 /* exact position */
2234 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2236 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2239 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2241 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2243 /* check if the icon is outside the screen boundaries */
2248 rect
.pos
.x
= dx
+ ex_x
* ICON_SIZE
;
2249 rect
.pos
.y
= dy
+ ex_y
* ICON_SIZE
;
2250 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2252 wGetRectPlacementInfo(scr
, rect
, &flags
);
2253 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
2257 if (dock
->type
== WM_DOCK
) {
2258 if (icon
->dock
!= dock
&& ex_x
!= 0)
2262 for (i
= 0; i
< dock
->max_icons
; i
++) {
2263 nicon
= dock
->icon_array
[i
];
2264 if (nicon
&& nicon
->yindex
== ex_y
) {
2271 int sig
, done
, closest
;
2273 /* Possible cases when redocking:
2275 * icon dragged out of range of any slot -> false
2276 * icon dragged to range of free slot
2277 * icon dragged to range of same slot
2278 * icon dragged to range of different icon
2280 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2283 if (ex_y
>= 0 && ex_y
<= max_y_icons
&& (aicon
== icon
|| !aicon
)) {
2289 /* start looking at the upper slot or lower? */
2290 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2297 /* look for closest free slot */
2298 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2302 closest
= sig
* (i
/ 2) + ex_y
;
2303 /* check if this slot is used */
2305 for (j
= 0; j
< dock
->max_icons
; j
++) {
2306 if (dock
->icon_array
[j
]
2307 && dock
->icon_array
[j
]->yindex
== closest
) {
2308 /* slot is used by someone else */
2309 if (dock
->icon_array
[j
] != icon
)
2317 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2318 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2319 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2324 } else { /* !redocking */
2326 /* if slot is free and the icon is close enough, return it */
2327 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2337 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2338 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+ 1;
2341 for (k
= start
; k
< stop
; k
++) {
2342 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2345 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2346 nicon
= tmp
->icon_array
[i
];
2347 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2355 for (k
= start
; k
< stop
; k
++) {
2356 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2359 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2360 nicon
= tmp
->icon_array
[i
];
2361 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2362 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2363 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2372 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2381 static int onScreen(WScreen
*scr
, int x
, int y
, int sx
, int ex
, int sy
, int ey
)
2383 WMRect rect
= wmkrect(x
, y
, ICON_SIZE
, ICON_SIZE
);
2386 wGetRectPlacementInfo(scr
, rect
, &flags
);
2388 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2392 * returns true if it can find a free slot in the dock,
2393 * in which case it changes x_pos and y_pos accordingly.
2394 * Else returns false.
2396 Bool
wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2398 WScreen
*scr
= dock
->screen_ptr
;
2400 WAppIconChain
*chain
;
2401 unsigned char *slot_map
;
2405 int i
, done
= False
;
2407 int sx
= 0, sy
= 0, ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2408 int extra_count
= 0;
2410 if (dock
->type
== WM_CLIP
&& dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2411 extra_count
= scr
->global_icon_count
;
2413 /* if the dock is full */
2414 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
)
2417 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2418 if (scr
->dock
->on_right_side
)
2419 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2421 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2424 if (ex
< dock
->x_pos
)
2426 if (sx
> dock
->x_pos
+ ICON_SIZE
)
2427 sx
= dock
->x_pos
+ ICON_SIZE
;
2434 /* check if clip is in a corner */
2435 if (dock
->type
== WM_CLIP
) {
2436 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2438 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2440 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2442 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2450 /* If the clip is in the corner, use only slots that are in the border
2452 if (corner
!= C_NONE
) {
2456 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2457 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2458 hmap
= wmalloc(hcount
+ 1);
2459 vmap
= wmalloc(vcount
+ 1);
2461 /* mark used positions */
2464 for (i
= 0; i
< dock
->max_icons
; i
++) {
2465 btn
= dock
->icon_array
[i
];
2469 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2470 vmap
[btn
->yindex
] = 1;
2471 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2472 hmap
[btn
->xindex
] = 1;
2474 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2476 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2477 vmap
[btn
->yindex
] = 1;
2478 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2479 hmap
[btn
->xindex
] = 1;
2483 for (i
= 0; i
< dock
->max_icons
; i
++) {
2484 btn
= dock
->icon_array
[i
];
2488 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2489 vmap
[btn
->yindex
] = 1;
2490 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2491 hmap
[-btn
->xindex
] = 1;
2493 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2495 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2496 vmap
[btn
->yindex
] = 1;
2497 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2498 hmap
[-btn
->xindex
] = 1;
2502 for (i
= 0; i
< dock
->max_icons
; i
++) {
2503 btn
= dock
->icon_array
[i
];
2507 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2508 vmap
[-btn
->yindex
] = 1;
2509 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2510 hmap
[btn
->xindex
] = 1;
2512 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2514 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2515 vmap
[-btn
->yindex
] = 1;
2516 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2517 hmap
[btn
->xindex
] = 1;
2522 for (i
= 0; i
< dock
->max_icons
; i
++) {
2523 btn
= dock
->icon_array
[i
];
2527 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2528 vmap
[-btn
->yindex
] = 1;
2529 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2530 hmap
[-btn
->xindex
] = 1;
2532 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2534 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2535 vmap
[-btn
->yindex
] = 1;
2536 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2537 hmap
[-btn
->xindex
] = 1;
2543 /* search a vacant slot */
2544 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2545 if (i
< vcount
&& vmap
[i
] == 0) {
2551 } else if (i
< hcount
&& hmap
[i
] == 0) {
2561 /* If found a slot, translate and return */
2563 if (corner
== C_NW
|| corner
== C_NE
)
2568 if (corner
== C_NE
|| corner
== C_SE
)
2575 /* else, try to find a slot somewhere else */
2578 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2579 * placed outside of screen */
2580 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2582 /* In the worst case (the clip is in the corner of the screen),
2583 * the amount of icons that fit in the clip is smaller.
2584 * Double the map to get a safe value.
2588 r
= (mwidth
- 1) / 2;
2590 slot_map
= wmalloc(mwidth
* mwidth
);
2592 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2594 /* mark used slots in the map. If the slot falls outside the map
2595 * (for example, when all icons are placed in line), ignore them. */
2596 for (i
= 0; i
< dock
->max_icons
; i
++) {
2597 btn
= dock
->icon_array
[i
];
2599 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2602 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
)
2603 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2605 /* Find closest slot from the center that is free by scanning the
2606 * map from the center to outward in circular passes.
2607 * This will not result in a neat layout, but will be optimal
2608 * in the sense that there will not be holes left.
2611 for (i
= 1; i
<= r
&& !done
; i
++) {
2614 /* top and bottom parts of the ring */
2615 for (x
= -i
; x
<= i
&& !done
; x
++) {
2616 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2618 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2619 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2626 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2627 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2634 /* left and right parts of the ring */
2635 for (y
= -i
+ 1; y
<= i
- 1; y
++) {
2636 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2638 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2639 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2646 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2647 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2660 static void moveDock(WDock
*dock
, int new_x
, int new_y
)
2665 dock
->x_pos
= new_x
;
2666 dock
->y_pos
= new_y
;
2667 for (i
= 0; i
< dock
->max_icons
; i
++) {
2668 btn
= dock
->icon_array
[i
];
2670 btn
->x_pos
= new_x
+ btn
->xindex
* ICON_SIZE
;
2671 btn
->y_pos
= new_y
+ btn
->yindex
* ICON_SIZE
;
2672 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2677 static void swapDock(WDock
*dock
)
2679 WScreen
*scr
= dock
->screen_ptr
;
2683 if (dock
->on_right_side
)
2684 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2686 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2688 for (i
= 0; i
< dock
->max_icons
; i
++) {
2689 btn
= dock
->icon_array
[i
];
2692 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2696 wScreenUpdateUsableArea(scr
);
2699 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2701 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2707 cmdline
= ExpandOptions(scr
, command
);
2709 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2717 wtokensplit(cmdline
, &argv
, &argc
);
2727 if ((pid
= fork()) == 0) {
2731 SetupEnvironment(scr
);
2737 args
= malloc(sizeof(char *) * (argc
+ 1));
2741 for (i
= 0; i
< argc
; i
++)
2745 execvp(argv
[0], args
);
2748 wtokenfree(argv
, argc
);
2752 state
= wmalloc(sizeof(WSavedState
));
2754 state
->miniaturized
= -1;
2756 if (btn
->dock
== scr
->dock
|| btn
->omnipresent
)
2757 state
->workspace
= -1;
2759 state
->workspace
= scr
->current_workspace
;
2761 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
2762 wAddDeathHandler(pid
, (WDeathHandler
*) trackDeadProcess
, btn
->dock
);
2770 void wDockHideIcons(WDock
*dock
)
2777 for (i
= 1; i
< dock
->max_icons
; i
++) {
2778 if (dock
->icon_array
[i
])
2779 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2783 dockIconPaint(dock
->icon_array
[0]);
2786 void wDockShowIcons(WDock
*dock
)
2794 btn
= dock
->icon_array
[0];
2795 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2797 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2798 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2800 for (i
= 1; i
< dock
->max_icons
; i
++) {
2801 if (dock
->icon_array
[i
]) {
2802 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
, btn
->icon
->core
);
2807 if (!dock
->collapsed
) {
2808 for (i
= 1; i
< dock
->max_icons
; i
++) {
2809 if (dock
->icon_array
[i
])
2810 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2818 void wDockLower(WDock
*dock
)
2822 for (i
= 0; i
< dock
->max_icons
; i
++) {
2823 if (dock
->icon_array
[i
])
2824 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2828 void wDockRaise(WDock
*dock
)
2832 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
2833 if (dock
->icon_array
[i
])
2834 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2838 void wDockRaiseLower(WDock
*dock
)
2840 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2841 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2842 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2848 void wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
2850 icon
->launching
= 0;
2851 icon
->relaunching
= 0;
2852 dockIconPaint(icon
);
2855 WAppIcon
*wDockFindIconForWindow(WDock
*dock
, Window window
)
2860 for (i
= 0; i
< dock
->max_icons
; i
++) {
2861 icon
= dock
->icon_array
[i
];
2862 if (icon
&& icon
->main_window
== window
)
2868 void wDockTrackWindowLaunch(WDock
*dock
, Window window
)
2871 char *wm_class
, *wm_instance
;
2873 Bool firstPass
= True
;
2875 char *command
= NULL
;
2877 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) || (!wm_class
&& !wm_instance
))
2880 command
= GetCommandForWindow(window
);
2882 for (i
= 0; i
< dock
->max_icons
; i
++) {
2883 icon
= dock
->icon_array
[i
];
2887 /* app is already attached to icon */
2888 if (icon
->main_window
== window
) {
2893 if ((icon
->wm_instance
|| icon
->wm_class
)
2894 && (icon
->launching
|| !icon
->running
)) {
2896 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0)
2899 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0)
2902 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0)
2905 if (!icon
->relaunching
) {
2908 /* Possibly an application that was docked with dockit,
2909 * but the user did not update WMState to indicate that
2910 * it was docked by force */
2911 wapp
= wApplicationOf(window
);
2913 icon
->forced_dock
= 1;
2916 if (!icon
->forced_dock
)
2917 icon
->main_window
= window
;
2920 if (!wPreferences
.no_animations
&& !icon
->launching
&&
2921 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
2925 icon
->launching
= 1;
2926 dockIconPaint(icon
);
2928 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
2929 wm_instance
, wm_class
, TILE_NORMAL
);
2930 /* XXX: can: aicon->icon == NULL ? */
2931 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
2932 wAppIconMove(aicon
, x0
, y0
);
2933 /* Should this always be lowered? -Dan */
2935 wLowerFrame(aicon
->icon
->core
);
2936 XMapWindow(dpy
, aicon
->icon
->core
->window
);
2937 aicon
->launching
= 1;
2938 wAppIconPaint(aicon
);
2939 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
2940 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
2941 wAppIconDestroy(aicon
);
2943 wDockFinishLaunch(dock
, icon
);
2948 if (firstPass
&& !found
) {
2962 void wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
2964 if (!wPreferences
.flags
.noclip
) {
2965 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
2966 if (scr
->current_workspace
!= workspace
) {
2967 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
2968 WAppIconChain
*chain
= scr
->global_icons
;
2971 moveIconBetweenDocks(chain
->aicon
->dock
,
2972 scr
->workspaces
[workspace
]->clip
,
2973 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
2974 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
2975 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
2976 chain
= chain
->next
;
2979 wDockHideIcons(old_clip
);
2980 if (old_clip
->auto_raise_lower
) {
2981 if (old_clip
->auto_raise_magic
) {
2982 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
2983 old_clip
->auto_raise_magic
= NULL
;
2985 wDockLower(old_clip
);
2987 if (old_clip
->auto_collapse
) {
2988 if (old_clip
->auto_expand_magic
) {
2989 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
2990 old_clip
->auto_expand_magic
= NULL
;
2992 old_clip
->collapsed
= 1;
2994 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
2999 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3004 for (i
= 0; i
< dock
->max_icons
; i
++) {
3005 icon
= dock
->icon_array
[i
];
3009 if (icon
->launching
&& icon
->pid
== pid
) {
3010 if (!icon
->relaunching
) {
3012 icon
->main_window
= None
;
3014 wDockFinishLaunch(dock
, icon
);
3016 if (status
== 111) {
3021 if (icon
->drop_launch
)
3022 cmd
= icon
->dnd_command
;
3025 if (icon
->paste_launch
)
3026 cmd
= icon
->paste_command
;
3028 cmd
= icon
->command
;
3030 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3032 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3039 static void toggleLowered(WDock
*dock
)
3044 /* lower/raise Dock */
3045 if (!dock
->lowered
) {
3046 newlevel
= WMNormalLevel
;
3049 newlevel
= WMDockLevel
;
3053 for (i
= 0; i
< dock
->max_icons
; i
++) {
3054 tmp
= dock
->icon_array
[i
];
3058 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3060 wLowerFrame(tmp
->icon
->core
);
3063 if (dock
->type
== WM_DOCK
)
3064 wScreenUpdateUsableArea(dock
->screen_ptr
);
3067 static void toggleCollapsed(WDock
*dock
)
3069 if (dock
->collapsed
) {
3070 dock
->collapsed
= 0;
3071 wDockShowIcons(dock
);
3073 dock
->collapsed
= 1;
3074 wDockHideIcons(dock
);
3078 static void openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3080 WScreen
*scr
= dock
->screen_ptr
;
3081 WObjDescriptor
*desc
;
3083 WApplication
*wapp
= NULL
;
3087 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3089 if (dock
->type
== WM_DOCK
) {
3091 entry
= dock
->menu
->entries
[index
];
3092 entry
->flags
.indicator_on
= !dock
->lowered
;
3093 entry
->clientdata
= dock
;
3094 dock
->menu
->flags
.realized
= 0;
3097 if (scr
->clip_options
)
3098 updateClipOptionsMenu(scr
->clip_options
, dock
);
3100 n_selected
= numberOfSelectedIcons(dock
);
3102 /* Rename Workspace */
3103 entry
= dock
->menu
->entries
[++index
];
3104 if (aicon
== scr
->clip_icon
) {
3105 entry
->callback
= renameCallback
;
3106 entry
->clientdata
= dock
;
3107 entry
->flags
.indicator
= 0;
3108 entry
->text
= _("Rename Workspace");
3110 entry
->callback
= omnipresentCallback
;
3111 entry
->clientdata
= aicon
;
3112 if (n_selected
> 0) {
3113 entry
->flags
.indicator
= 0;
3114 entry
->text
= _("Toggle Omnipresent");
3116 entry
->flags
.indicator
= 1;
3117 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3118 entry
->flags
.indicator_type
= MI_CHECK
;
3119 entry
->text
= _("Omnipresent");
3123 /* select/unselect icon */
3124 entry
= dock
->menu
->entries
[++index
];
3125 entry
->clientdata
= aicon
;
3126 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3127 wMenuSetEnabled(dock
->menu
, index
, aicon
!= scr
->clip_icon
);
3129 /* select/unselect all icons */
3130 entry
= dock
->menu
->entries
[++index
];
3131 entry
->clientdata
= aicon
;
3133 entry
->text
= _("Unselect All Icons");
3135 entry
->text
= _("Select All Icons");
3137 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3140 entry
= dock
->menu
->entries
[++index
];
3141 entry
->clientdata
= aicon
;
3143 entry
->text
= _("Keep Icons");
3145 entry
->text
= _("Keep Icon");
3147 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3149 /* this is the workspace submenu part */
3150 entry
= dock
->menu
->entries
[++index
];
3152 entry
->text
= _("Move Icons To");
3154 entry
->text
= _("Move Icon To");
3156 if (scr
->clip_submenu
)
3157 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3159 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3161 /* remove icon(s) */
3162 entry
= dock
->menu
->entries
[++index
];
3163 entry
->clientdata
= aicon
;
3165 entry
->text
= _("Remove Icons");
3167 entry
->text
= _("Remove Icon");
3169 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3171 /* attract icon(s) */
3172 entry
= dock
->menu
->entries
[++index
];
3173 entry
->clientdata
= aicon
;
3175 dock
->menu
->flags
.realized
= 0;
3176 wMenuRealize(dock
->menu
);
3179 if (aicon
->icon
->owner
)
3180 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3185 entry
= dock
->menu
->entries
[++index
];
3186 entry
->clientdata
= aicon
;
3187 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3190 entry
= dock
->menu
->entries
[++index
];
3191 entry
->clientdata
= aicon
;
3192 if (wapp
&& wapp
->flags
.hidden
)
3193 entry
->text
= _("Unhide Here");
3195 entry
->text
= _("Bring Here");
3197 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3200 entry
= dock
->menu
->entries
[++index
];
3201 entry
->clientdata
= aicon
;
3202 if (wapp
&& wapp
->flags
.hidden
)
3203 entry
->text
= _("Unhide");
3205 entry
->text
= _("Hide");
3207 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3210 entry
= dock
->menu
->entries
[++index
];
3211 entry
->clientdata
= aicon
;
3212 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3215 entry
= dock
->menu
->entries
[++index
];
3216 entry
->clientdata
= aicon
;
3217 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3219 if (!dock
->menu
->flags
.realized
)
3220 wMenuRealize(dock
->menu
);
3222 if (dock
->type
== WM_CLIP
) {
3223 /*x_pos = event->xbutton.x_root+2; */
3224 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3227 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3228 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3231 x_pos
= dock
->on_right_side
? scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3234 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3236 /* allow drag select */
3237 event
->xany
.send_event
= True
;
3238 desc
= &dock
->menu
->menu
->descriptor
;
3239 (*desc
->handle_mousedown
) (desc
, event
);
3242 /******************************************************************/
3243 static void iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3245 WAppIcon
*btn
= desc
->parent
;
3246 WDock
*dock
= btn
->dock
;
3247 WApplication
*wapp
= NULL
;
3250 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3251 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3253 assert(wapp
!= NULL
);
3255 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3257 /* go to the last workspace that the user worked on the app */
3258 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
&& !unhideHere
)
3259 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3261 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3263 if (event
->xbutton
.state
& MOD_MASK
)
3264 wHideOtherApplications(btn
->icon
->owner
);
3266 if (event
->xbutton
.button
== Button1
) {
3267 if (event
->xbutton
.state
& MOD_MASK
) {
3268 /* raise/lower dock */
3269 toggleLowered(dock
);
3270 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3271 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
)
3272 toggleCollapsed(dock
);
3274 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3275 } else if (btn
->command
) {
3276 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3277 launchDockedApplication(btn
, False
);
3283 static void handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3285 WScreen
*scr
= dock
->screen_ptr
;
3286 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3289 int grabbed
= 0, swapped
= 0, done
;
3290 Pixmap ghost
= None
;
3291 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3293 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3294 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3295 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
)
3296 wwarning("pointer grab failed for dock move");
3299 for (x
= 0; x
< dock
->max_icons
; x
++) {
3300 if (dock
->icon_array
[x
] != NULL
&& dock
->icon_array
[x
]->yindex
> y
)
3301 y
= dock
->icon_array
[x
]->yindex
;
3304 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
* y
);
3308 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3309 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3316 /* It means the cursor moved so fast that it entered
3317 * something else (if moving slowly, it would have
3318 * stayed in the dock that is being moved. Ignore such
3319 * "spurious" EnterNotifiy's */
3324 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3325 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3326 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3327 | ButtonReleaseMask
| ButtonPressMask
,
3328 wCursor
[WCUR_MOVE
], CurrentTime
);
3333 if (dock
->type
== WM_CLIP
) {
3334 x
= ev
.xmotion
.x_root
- ofs_x
;
3335 y
= ev
.xmotion
.y_root
- ofs_y
;
3336 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3338 moveDock(dock
, x
, y
);
3340 /* move vertically if pointer is inside the dock */
3341 if ((dock
->on_right_side
&& ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3342 || (!dock
->on_right_side
&& ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
* 2)) {
3344 x
= ev
.xmotion
.x_root
- ofs_x
;
3345 y
= ev
.xmotion
.y_root
- ofs_y
;
3346 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3347 moveDock(dock
, dock
->x_pos
, y
);
3349 /* move horizontally to change sides */
3350 x
= ev
.xmotion
.x_root
- ofs_x
;
3351 if (!dock
->on_right_side
) {
3354 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
* 2) {
3355 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
- ICON_SIZE
3356 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3357 if (superfluous
&& ghost
== None
) {
3358 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3359 scr
->scr_width
- ICON_SIZE
3360 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3361 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3362 XClearWindow(dpy
, scr
->dock_shadow
);
3364 XMapRaised(dpy
, scr
->dock_shadow
);
3367 if (superfluous
&& ghost
!= None
) {
3368 XFreePixmap(dpy
, ghost
);
3371 XUnmapWindow(dpy
, scr
->dock_shadow
);
3376 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3377 XMoveWindow(dpy
, scr
->dock_shadow
, DOCK_EXTRA_SPACE
, dock
->y_pos
);
3378 if (superfluous
&& ghost
== None
) {
3379 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3380 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3381 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3382 XClearWindow(dpy
, scr
->dock_shadow
);
3384 XMapRaised(dpy
, scr
->dock_shadow
);
3387 XUnmapWindow(dpy
, scr
->dock_shadow
);
3389 if (superfluous
&& ghost
!= None
) {
3390 XFreePixmap(dpy
, ghost
);
3402 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3404 XUngrabPointer(dpy
, CurrentTime
);
3405 XUnmapWindow(dpy
, scr
->dock_shadow
);
3406 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3407 if (dock
->type
== WM_DOCK
) {
3410 dock
->on_right_side
= 1;
3412 dock
->on_right_side
= 0;
3414 wArrangeIcons(scr
, False
);
3423 XFreePixmap(dpy
, ghost
);
3424 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3428 static Bool
handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3430 WScreen
*scr
= dock
->screen_ptr
;
3432 WIcon
*icon
= aicon
->icon
;
3433 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3434 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3436 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3437 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3438 int shad_x
= x
, shad_y
= y
;
3439 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3441 Pixmap ghost
= None
;
3443 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3444 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3445 Bool hasMoved
= False
;
3447 if (wPreferences
.flags
.noupdates
)
3450 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3451 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3452 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3455 if (!(event
->xbutton
.state
& MOD_MASK
))
3456 wRaiseFrame(icon
->core
);
3458 if (!wPreferences
.flags
.noclip
)
3459 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3461 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3463 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3466 wins
[0] = icon
->core
->window
;
3467 wins
[1] = scr
->dock_shadow
;
3468 XRestackWindows(dpy
, wins
, 2);
3469 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
3471 if (icon
->pixmap
!= None
)
3472 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3474 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3476 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3477 XClearWindow(dpy
, scr
->dock_shadow
);
3479 XMapWindow(dpy
, scr
->dock_shadow
);
3484 XMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3485 | ButtonMotionMask
| ExposureMask
, &ev
);
3494 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3495 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3496 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3497 | ButtonReleaseMask
| ButtonPressMask
,
3498 wCursor
[WCUR_MOVE
], CurrentTime
);
3507 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3508 if (i
== scr
->current_workspace
)
3510 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3514 x
= ev
.xmotion
.x_root
- ofs_x
;
3515 y
= ev
.xmotion
.y_root
- ofs_y
;
3516 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3519 if (last_dock
!= dock
&& collapsed
) {
3520 last_dock
->collapsed
= 1;
3521 wDockHideIcons(last_dock
);
3524 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3525 dock
->collapsed
= 0;
3526 wDockShowIcons(dock
);
3528 if (dock
->auto_raise_lower
)
3532 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3535 if (last_dock
!= dock2
&& collapsed
) {
3536 last_dock
->collapsed
= 1;
3537 wDockHideIcons(last_dock
);
3540 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3541 dock2
->collapsed
= 0;
3542 wDockShowIcons(dock2
);
3544 if (dock2
->auto_raise_lower
)
3549 if (aicon
->launching
|| aicon
->lock
|| (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3550 || (!aicon
->running
&& tmp
)) {
3551 shad_x
= last_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3552 shad_y
= last_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3554 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3557 XMapWindow(dpy
, scr
->dock_shadow
);
3562 XUnmapWindow(dpy
, scr
->dock_shadow
);
3566 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3573 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3575 XUngrabPointer(dpy
, CurrentTime
);
3577 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3578 XUnmapWindow(dpy
, scr
->dock_shadow
);
3580 reattachIcon(dock
, aicon
, ix
, iy
);
3581 if (clip
&& dock
!= clip
&& clip
->auto_raise_lower
)
3584 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3586 /* Slide it back if dock rejected it */
3587 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
, aicon
->y_pos
);
3588 reattachIcon(dock
, aicon
, aicon
->xindex
, aicon
->yindex
);
3590 if (last_dock
->type
== WM_CLIP
&& last_dock
->auto_collapse
)
3597 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3598 /* We need to deselect it, even if is deselected in
3599 * wDockDetach(), because else DoKaboom() will fail.
3601 if (aicon
->icon
->selected
)
3602 wIconSelect(aicon
->icon
);
3604 DoKaboom(scr
, aicon
->icon
->core
->window
, x
, y
);
3607 if (clip
&& clip
->auto_raise_lower
)
3609 wDockDetach(dock
, aicon
);
3612 last_dock
->collapsed
= 1;
3613 wDockHideIcons(last_dock
);
3618 XFreePixmap(dpy
, ghost
);
3619 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3623 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3624 if (i
== scr
->current_workspace
)
3626 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3632 return False
; /* never reached */
3635 static int getClipButton(int px
, int py
)
3637 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3639 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3642 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3643 return CLIP_FORWARD
;
3644 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3650 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3653 int done
, direction
, new_ws
;
3655 WDock
*clip
= scr
->clip_icon
->dock
;
3657 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3659 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3660 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3662 wClipIconPaint(scr
->clip_icon
);
3665 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3672 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3673 if (new_dir
!= direction
) {
3674 direction
= new_dir
;
3675 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3676 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3677 wClipIconPaint(scr
->clip_icon
);
3685 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3690 clip
->lclip_button_pushed
= 0;
3691 clip
->rclip_button_pushed
= 0;
3693 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3695 if (direction
== CLIP_FORWARD
) {
3696 if (scr
->current_workspace
< scr
->workspace_count
- 1)
3697 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3698 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
- 1)
3699 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3700 else if (wPreferences
.ws_cycle
)
3701 wWorkspaceChange(scr
, 0);
3702 } else if (direction
== CLIP_REWIND
) {
3703 if (scr
->current_workspace
> 0)
3704 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
3705 else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
)
3706 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
3709 wClipIconPaint(scr
->clip_icon
);
3712 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3714 WAppIcon
*aicon
= desc
->parent
;
3715 WDock
*dock
= aicon
->dock
;
3716 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3718 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3721 scr
->last_dock
= dock
;
3723 if (dock
->menu
->flags
.mapped
)
3724 wMenuUnmap(dock
->menu
);
3726 if (IsDoubleClick(scr
, event
)) {
3727 /* double-click was not in the main clip icon */
3728 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3729 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3730 iconDblClick(desc
, event
);
3735 if (event
->xbutton
.button
== Button1
) {
3736 if (event
->xbutton
.state
& MOD_MASK
)
3741 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
&& dock
->type
!= WM_DOCK
) {
3742 wIconSelect(aicon
->icon
);
3746 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3747 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
3748 && dock
->type
== WM_CLIP
)
3749 handleClipChangeWorkspace(scr
, event
);
3751 handleDockMove(dock
, aicon
, event
);
3753 Bool hasMoved
= handleIconMove(dock
, aicon
, event
);
3754 if (wPreferences
.single_click
&& !hasMoved
)
3755 iconDblClick(desc
, event
);
3757 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&& aicon
== scr
->clip_icon
) {
3758 if (!scr
->clip_ws_menu
) {
3759 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3761 if (scr
->clip_ws_menu
) {
3762 WMenu
*wsMenu
= scr
->clip_ws_menu
;
3765 wWorkspaceMenuUpdate(scr
, wsMenu
);
3767 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
3770 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
3771 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
3773 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
3775 desc
= &wsMenu
->menu
->descriptor
;
3776 event
->xany
.send_event
= True
;
3777 (*desc
->handle_mousedown
) (desc
, event
);
3779 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
3780 (event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
) {
3781 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3782 } else if (event
->xbutton
.button
== Button3
) {
3783 if (event
->xbutton
.send_event
&&
3784 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3785 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3786 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3787 wwarning("pointer grab failed for dockicon menu");
3791 openDockMenu(dock
, aicon
, event
);
3792 } else if (event
->xbutton
.button
== Button2
) {
3793 WAppIcon
*btn
= desc
->parent
;
3795 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3796 launchDockedApplication(btn
, True
);
3800 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3802 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3806 assert(event
->type
== EnterNotify
);
3808 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3811 scr
= btn
->icon
->core
->screen_ptr
;
3812 if (!btn
->omnipresent
)
3815 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3817 if (!dock
|| dock
->type
!= WM_CLIP
)
3820 /* The auto raise/lower code */
3821 if (dock
->auto_lower_magic
) {
3822 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3823 dock
->auto_lower_magic
= NULL
;
3825 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
)
3826 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
, clipAutoRaise
, (void *)dock
);
3828 /* The auto expand/collapse code */
3829 if (dock
->auto_collapse_magic
) {
3830 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3831 dock
->auto_collapse_magic
= NULL
;
3833 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
)
3834 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
, clipAutoExpand
, (void *)dock
);
3837 static void clipLeave(WDock
*dock
)
3840 WObjDescriptor
*desc
= NULL
;
3842 if (!dock
|| dock
->type
!= WM_CLIP
)
3845 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
3846 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3847 (XPointer
*) & desc
) != XCNOENT
3848 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
3849 && ((WAppIcon
*) desc
->parent
)->dock
&& ((WAppIcon
*) desc
->parent
)->dock
->type
== WM_CLIP
) {
3850 /* We didn't left the Clip yet */
3851 XPutBackEvent(dpy
, &event
);
3855 XPutBackEvent(dpy
, &event
);
3857 /* We entered a withdrawn window, so we're still in Clip */
3861 if (dock
->auto_raise_magic
) {
3862 WMDeleteTimerHandler(dock
->auto_raise_magic
);
3863 dock
->auto_raise_magic
= NULL
;
3865 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
)
3866 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
, clipAutoLower
, (void *)dock
);
3868 if (dock
->auto_expand_magic
) {
3869 WMDeleteTimerHandler(dock
->auto_expand_magic
);
3870 dock
->auto_expand_magic
= NULL
;
3872 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
)
3873 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
, clipAutoCollapse
, (void *)dock
);
3876 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
3878 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3880 assert(event
->type
== LeaveNotify
);
3882 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3885 clipLeave(btn
->dock
);
3888 static void clipAutoCollapse(void *cdata
)
3890 WDock
*dock
= (WDock
*) cdata
;
3892 if (dock
->type
!= WM_CLIP
)
3895 if (dock
->auto_collapse
) {
3896 dock
->collapsed
= 1;
3897 wDockHideIcons(dock
);
3899 dock
->auto_collapse_magic
= NULL
;
3902 static void clipAutoExpand(void *cdata
)
3904 WDock
*dock
= (WDock
*) cdata
;
3906 if (dock
->type
!= WM_CLIP
)
3909 if (dock
->auto_collapse
) {
3910 dock
->collapsed
= 0;
3911 wDockShowIcons(dock
);
3913 dock
->auto_expand_magic
= NULL
;
3916 static void clipAutoLower(void *cdata
)
3918 WDock
*dock
= (WDock
*) cdata
;
3920 if (dock
->type
!= WM_CLIP
)
3923 if (dock
->auto_raise_lower
)
3926 dock
->auto_lower_magic
= NULL
;
3929 static void clipAutoRaise(void *cdata
)
3931 WDock
*dock
= (WDock
*) cdata
;
3933 if (dock
->type
!= WM_CLIP
)
3936 if (dock
->auto_raise_lower
)
3939 dock
->auto_raise_magic
= NULL
;
3942 static Bool
iconCanBeOmnipresent(WAppIcon
*aicon
)
3944 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3949 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3950 clip
= scr
->workspaces
[i
]->clip
;
3952 if (clip
== aicon
->dock
)
3955 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
3956 return False
; /* Clip is full in some workspace */
3958 for (j
= 0; j
< clip
->max_icons
; j
++) {
3959 btn
= clip
->icon_array
[j
];
3960 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
3968 int wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
3970 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3971 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
3972 int status
= WO_SUCCESS
;
3974 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== scr
->clip_icon
)
3975 return WO_NOT_APPLICABLE
;
3977 if (aicon
->omnipresent
== omnipresent
)
3981 if (iconCanBeOmnipresent(aicon
)) {
3982 aicon
->omnipresent
= 1;
3983 new_entry
= wmalloc(sizeof(WAppIconChain
));
3984 new_entry
->aicon
= aicon
;
3985 new_entry
->next
= scr
->global_icons
;
3986 scr
->global_icons
= new_entry
;
3987 scr
->global_icon_count
++;
3989 aicon
->omnipresent
= 0;
3993 aicon
->omnipresent
= 0;
3994 if (aicon
== scr
->global_icons
->aicon
) {
3995 tmp
= scr
->global_icons
->next
;
3996 wfree(scr
->global_icons
);
3997 scr
->global_icons
= tmp
;
3998 scr
->global_icon_count
--;
4000 tmp
= scr
->global_icons
;
4002 if (tmp
->next
->aicon
== aicon
) {
4003 tmp1
= tmp
->next
->next
;
4006 scr
->global_icon_count
--;
4014 wAppIconPaint(aicon
);