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"
48 #include "properties.h"
52 #include "workspace.h"
54 #include "superfluous.h"
57 /**** Local variables ****/
60 #define CLIP_FORWARD 2
62 /**** Global variables ****/
65 extern void DestroyDockAppSettingsPanel();
66 extern void ShowDockAppSettingsPanel(WAppIcon
* aicon
);
67 extern Cursor wCursor
[WCUR_LAST
];
68 extern WPreferences wPreferences
;
69 extern XContext wWinContext
;
70 extern void appIconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
72 #define MOD_MASK wPreferences.modifier_mask
73 #define ICON_SIZE wPreferences.icon_size
75 /***** Local variables ****/
77 static WMPropList
*dCommand
= NULL
;
78 static WMPropList
*dPasteCommand
= NULL
;
79 #ifdef XDND /* XXX was OFFIX */
80 static WMPropList
*dDropCommand
= NULL
;
82 static WMPropList
*dAutoLaunch
, *dLock
;
83 static WMPropList
*dName
, *dForced
, *dBuggyApplication
, *dYes
, *dNo
;
84 static WMPropList
*dHost
, *dDock
, *dClip
;
85 static WMPropList
*dAutoAttractIcons
;
87 static WMPropList
*dPosition
, *dApplications
, *dLowered
, *dCollapsed
;
89 static WMPropList
*dAutoCollapse
, *dAutoRaiseLower
, *dOmnipresent
;
91 static void dockIconPaint(WAppIcon
*btn
);
93 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
95 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
);
97 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
99 static int getClipButton(int px
, int py
);
101 static void toggleLowered(WDock
*dock
);
103 static void toggleCollapsed(WDock
*dock
);
105 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
107 static void clipLeave(WDock
*dock
);
109 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
111 static Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
);
113 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
114 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
115 static void clipAutoCollapse(void *cdata
);
116 static void clipAutoExpand(void *cdata
);
117 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
);
119 static void clipAutoLower(void *cdata
);
120 static void clipAutoRaise(void *cdata
);
121 static void reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
);
122 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
);
124 static void make_keys(void)
126 if (dCommand
!= NULL
)
129 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
130 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
132 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
134 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
135 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
136 dName
= WMRetainPropList(WMCreatePLString("Name"));
137 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
138 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
139 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
140 dNo
= WMRetainPropList(WMCreatePLString("No"));
141 dHost
= WMRetainPropList(WMCreatePLString("Host"));
143 dPosition
= WMCreatePLString("Position");
144 dApplications
= WMCreatePLString("Applications");
145 dLowered
= WMCreatePLString("Lowered");
146 dCollapsed
= WMCreatePLString("Collapsed");
147 dAutoCollapse
= WMCreatePLString("AutoCollapse");
148 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
149 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
151 dOmnipresent
= WMCreatePLString("Omnipresent");
153 dDock
= WMCreatePLString("Dock");
154 dClip
= WMCreatePLString("Clip");
157 static void renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
159 WDock
*dock
= entry
->clientdata
;
164 assert(entry
->clientdata
!= NULL
);
166 wspace
= dock
->screen_ptr
->current_workspace
;
168 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
170 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+ 1);
171 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
, &name
)) {
172 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
179 static void toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
181 assert(entry
->clientdata
!= NULL
);
183 toggleLowered(entry
->clientdata
);
185 entry
->flags
.indicator_on
= !(((WDock
*) entry
->clientdata
)->lowered
);
190 static int matchWindow(const void *item
, const void *cdata
)
192 return (((WFakeGroupLeader
*) item
)->leader
== (Window
) cdata
);
195 static void killCallback(WMenu
*menu
, WMenuEntry
*entry
)
197 WScreen
*scr
= menu
->menu
->screen_ptr
;
199 WFakeGroupLeader
*fPtr
;
200 char *buffer
, *shortname
, **argv
;
201 char *basename(const char *shortname
);
204 if (!WCHECK_STATE(WSTATE_NORMAL
))
207 assert(entry
->clientdata
!= NULL
);
209 icon
= (WAppIcon
*) entry
->clientdata
;
213 WCHANGE_STATE(WSTATE_MODAL
);
215 /* strip away dir names */
216 shortname
= basename(icon
->command
);
217 /* separate out command options */
218 wtokensplit(shortname
, &argv
, &argc
);
220 buffer
= wstrconcat(argv
[0],
221 _(" will be forcibly closed.\n"
222 "Any unsaved changes will be lost.\n" "Please confirm."));
224 if (icon
->icon
&& icon
->icon
->owner
) {
225 fPtr
= icon
->icon
->owner
->fake_group
;
227 /* is this really necessary? can we kill a non-running dock icon? */
228 Window win
= icon
->main_window
;
231 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)win
);
232 if (index
!= WANotFound
)
233 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
238 if (wPreferences
.dont_confirm_kill
239 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
240 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
242 WWindow
*wwin
, *twin
;
244 wwin
= scr
->focused_window
;
247 if (wwin
->fake_group
== fPtr
) {
252 } else if (icon
->icon
&& icon
->icon
->owner
) {
253 wClientKill(icon
->icon
->owner
);
258 wtokenfree(argv
, argc
);
262 WCHANGE_STATE(WSTATE_NORMAL
);
265 /* TODO: replace this function with a member of the dock struct */
266 static int numberOfSelectedIcons(WDock
*dock
)
272 for (i
= 1; i
< dock
->max_icons
; i
++) {
273 aicon
= dock
->icon_array
[i
];
274 if (aicon
&& aicon
->icon
->selected
) {
282 static WMArray
*getSelected(WDock
*dock
)
284 WMArray
*ret
= WMCreateArray(8);
288 for (i
= 1; i
< dock
->max_icons
; i
++) {
289 btn
= dock
->icon_array
[i
];
290 if (btn
&& btn
->icon
->selected
) {
291 WMAddToArray(ret
, btn
);
298 static void paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
300 Window win
= clipIcon
->icon
->core
->window
;
301 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
303 int pt
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
304 int tp
= ICON_SIZE
- pt
;
305 int as
= pt
- 15; /* 15 = 5+5+5 */
306 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
309 color
= scr
->clip_title_color
[CLIP_NORMAL
];
311 XSetForeground(dpy
, gc
, WMColorPixel(color
));
316 p
[1].x
= ICON_SIZE
- 2;
318 p
[2].x
= ICON_SIZE
- 2;
320 } else if (lpushed
) {
324 p
[1].y
= ICON_SIZE
- 2;
326 p
[2].y
= ICON_SIZE
- 2;
328 if (lpushed
|| rpushed
) {
329 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
330 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
331 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
334 /* top right arrow */
335 p
[0].x
= p
[3].x
= ICON_SIZE
- 5 - as
;
337 p
[1].x
= ICON_SIZE
- 6;
339 p
[2].x
= ICON_SIZE
- 6;
342 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
343 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
345 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
346 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
349 /* bottom left arrow */
351 p
[0].y
= p
[3].y
= ICON_SIZE
- 5 - as
;
353 p
[1].y
= ICON_SIZE
- 6;
355 p
[2].y
= ICON_SIZE
- 6;
357 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
358 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
360 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
361 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
365 RImage
*wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
367 RImage
*tile
= RCloneImage(normalTile
);
374 pt
= CLIP_BUTTON_SIZE
* wPreferences
.icon_size
/ 64;
375 tp
= wPreferences
.icon_size
- 1 - pt
;
379 black
.red
= black
.green
= black
.blue
= 0;
382 dark
.red
= dark
.green
= dark
.blue
= 60;
385 light
.red
= light
.green
= light
.blue
= 80;
388 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
- 2, pt
- 1, &dark
);
389 RDrawLine(tile
, tp
- 1, 0, wPreferences
.icon_size
- 1, pt
+ 1, &black
);
390 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
- 3, pt
, &light
);
393 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, 4, &dark
);
394 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 5, 6 + as
, &dark
);
395 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
, &light
);
398 ROperateLine(tile
, RAddOperation
, 2, tp
+ 2, pt
- 2, wPreferences
.icon_size
- 3, &dark
);
399 RDrawLine(tile
, 0, tp
- 1, pt
+ 1, wPreferences
.icon_size
- 1, &black
);
400 ROperateLine(tile
, RSubtractOperation
, 0, tp
- 2, pt
+ 1, wPreferences
.icon_size
- 2, &light
);
403 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, &dark
);
404 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
, 6 + as
, ICON_SIZE
- 5, &dark
);
405 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5, &light
);
410 static void omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
412 WAppIcon
*clickedIcon
= entry
->clientdata
;
415 WMArray
*selectedIcons
;
416 WMArrayIterator iter
;
419 assert(entry
->clientdata
!= NULL
);
421 dock
= clickedIcon
->dock
;
423 selectedIcons
= getSelected(dock
);
425 if (!WMGetArrayItemCount(selectedIcons
))
426 WMAddToArray(selectedIcons
, clickedIcon
);
429 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
430 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
432 else if (aicon
->icon
->selected
)
433 wIconSelect(aicon
->icon
);
435 WMFreeArray(selectedIcons
);
438 wMessageDialog(dock
->screen_ptr
, _("Warning"),
439 _("Some icons cannot be made omnipresent. "
440 "Please make sure that no other icon is "
441 "docked in the same positions on the other "
442 "workspaces and the Clip is not full in "
443 "some workspace."), _("OK"), NULL
, NULL
);
444 } else if (failed
== 1) {
445 wMessageDialog(dock
->screen_ptr
, _("Warning"),
446 _("Icon cannot be made omnipresent. "
447 "Please make sure that no other icon is "
448 "docked in the same position on the other "
449 "workspaces and the Clip is not full in "
450 "some workspace."), _("OK"), NULL
, NULL
);
454 static void removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
456 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
459 WMArray
*selectedIcons
;
463 assert(clickedIcon
!= NULL
);
465 dock
= clickedIcon
->dock
;
467 selectedIcons
= getSelected(dock
);
469 if (WMGetArrayItemCount(selectedIcons
)) {
470 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
471 _("All selected icons will be removed!"),
472 _("OK"), _("Cancel"), NULL
) != WAPRDefault
) {
473 WMFreeArray(selectedIcons
);
477 if (clickedIcon
->xindex
== 0 && clickedIcon
->yindex
== 0) {
478 WMFreeArray(selectedIcons
);
481 WMAddToArray(selectedIcons
, clickedIcon
);
484 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
485 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
486 wDockDetach(dock
, aicon
);
488 /* XXX: can: aicon->icon == NULL ? */
489 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
490 wGetHeadForWindow(aicon
->icon
->owner
));
491 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
492 if (!dock
->mapped
|| dock
->collapsed
)
493 XMapWindow(dpy
, aicon
->icon
->core
->window
);
496 WMFreeArray(selectedIcons
);
498 if (wPreferences
.auto_arrange_icons
)
499 wArrangeIcons(dock
->screen_ptr
, True
);
502 static void keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
504 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
507 WMArray
*selectedIcons
;
510 assert(clickedIcon
!= NULL
);
511 dock
= clickedIcon
->dock
;
513 selectedIcons
= getSelected(dock
);
515 if (!WMGetArrayItemCount(selectedIcons
)
516 && clickedIcon
!= dock
->screen_ptr
->clip_icon
) {
517 char *command
= NULL
;
519 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
520 clickedIcon
->editing
= 1;
521 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
522 _("Type the command used to launch the application"), &command
)) {
523 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
527 clickedIcon
->command
= command
;
528 clickedIcon
->editing
= 0;
530 clickedIcon
->editing
= 0;
533 WMFreeArray(selectedIcons
);
538 WMAddToArray(selectedIcons
, clickedIcon
);
541 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
542 if (aicon
->icon
->selected
)
543 wIconSelect(aicon
->icon
);
544 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
545 aicon
->attracted
= 0;
546 if (aicon
->icon
->shadowed
) {
547 aicon
->icon
->shadowed
= 0;
548 aicon
->icon
->force_paint
= 1;
549 wAppIconPaint(aicon
);
554 WMFreeArray(selectedIcons
);
557 static void toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
559 WDock
*dock
= (WDock
*) entry
->clientdata
;
561 assert(entry
->clientdata
!= NULL
);
563 dock
->attract_icons
= !dock
->attract_icons
;
564 /*if (!dock->attract_icons)
565 dock->keep_attracted = 0; */
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
;
590 assert(entry
->clientdata
!= NULL
);
591 clip
= clickedIcon
->dock
;
593 aicon
= clip
->screen_ptr
->app_icon_list
;
596 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
597 x_pos
= clip
->x_pos
+ x
* ICON_SIZE
;
598 y_pos
= clip
->y_pos
+ y
* ICON_SIZE
;
599 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
601 if (wPreferences
.no_animations
) {
602 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
604 SlideWindow(aicon
->icon
->core
->window
,
605 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
608 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
609 #endif /* ANIMATIONS */
611 aicon
->attracted
= 1;
612 if (!aicon
->icon
->shadowed
) {
613 aicon
->icon
->shadowed
= 1;
614 aicon
->icon
->force_paint
= 1;
615 /* We don't do an wAppIconPaint() here because it's in
616 * wDockAttachIcon(). -Dan
619 wDockAttachIcon(clip
, aicon
, x
, y
);
620 if (clip
->collapsed
|| !clip
->mapped
)
621 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
627 static void selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
629 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
631 WMArray
*selectedIcons
;
632 WMArrayIterator iter
;
636 assert(clickedIcon
!= NULL
);
637 dock
= clickedIcon
->dock
;
639 selectedIcons
= getSelected(dock
);
641 if (!WMGetArrayItemCount(selectedIcons
)) {
642 for (i
= 1; i
< dock
->max_icons
; i
++) {
643 btn
= dock
->icon_array
[i
];
644 if (btn
&& !btn
->icon
->selected
) {
645 wIconSelect(btn
->icon
);
649 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
650 wIconSelect(btn
->icon
);
653 WMFreeArray(selectedIcons
);
658 static void toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
660 assert(entry
->clientdata
!= NULL
);
662 toggleCollapsed(entry
->clientdata
);
664 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->collapsed
;
669 static void toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
672 assert(entry
->clientdata
!= NULL
);
674 dock
= (WDock
*) entry
->clientdata
;
676 dock
->auto_collapse
= !dock
->auto_collapse
;
678 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_collapse
;
683 static void toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
686 assert(entry
->clientdata
!= NULL
);
688 dock
= (WDock
*) entry
->clientdata
;
690 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
692 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_raise_lower
;
697 static void launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
699 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
701 launchDockedApplication(btn
, False
);
704 static void settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
706 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
710 ShowDockAppSettingsPanel(btn
);
713 static void hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
716 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
718 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
720 if (wapp
->flags
.hidden
) {
721 wWorkspaceChange(btn
->icon
->core
->screen_ptr
, wapp
->last_workspace
);
722 wUnhideApplication(wapp
, False
, False
);
724 wHideApplication(wapp
);
728 static void unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
731 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
733 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
735 wUnhideApplication(wapp
, False
, True
);
738 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
)
743 if (type
== WM_CLIP
) {
745 return scr
->clip_icon
;
746 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
747 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
748 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
749 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
750 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE; */
753 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
754 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
760 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
761 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
762 btn
->icon
->core
->descriptor
.parent
= btn
;
763 /*ChangeStackingLevel(btn->icon->core, WMDockLevel); */
764 XMapWindow(dpy
, btn
->icon
->core
->window
);
769 scr
->clip_icon
= btn
;
774 static void switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
776 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
777 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
779 WMArray
*selectedIcons
;
782 if (entry
->order
== scr
->current_workspace
)
785 dest
= scr
->workspaces
[entry
->order
]->clip
;
787 selectedIcons
= getSelected(src
);
789 if (WMGetArrayItemCount(selectedIcons
)) {
790 WMArrayIterator iter
;
792 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
793 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
794 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
795 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
798 } else if (icon
!= scr
->clip_icon
) {
799 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
800 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
801 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
804 WMFreeArray(selectedIcons
);
807 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
)
809 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
811 if (!btn
->launching
&&
812 ((!withSelection
&& btn
->command
!= NULL
) || (withSelection
&& btn
->paste_command
!= NULL
))) {
813 if (!btn
->forced_dock
) {
814 btn
->relaunching
= btn
->running
;
817 if (btn
->wm_instance
|| btn
->wm_class
) {
818 WWindowAttributes attr
;
819 memset(&attr
, 0, sizeof(WWindowAttributes
));
820 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
822 if (!attr
.no_appicon
&& !btn
->buggy_app
)
827 btn
->drop_launch
= 0;
828 btn
->paste_launch
= withSelection
;
829 scr
->last_dock
= btn
->dock
;
830 btn
->pid
= execCommand(btn
, (withSelection
? btn
->paste_command
: btn
->command
), NULL
);
832 if (btn
->buggy_app
) {
833 /* give feedback that the app was launched */
837 WMAddTimerHandler(200, (WMCallback
*) dockIconPaint
, btn
);
842 wwarning(_("could not launch application %s"), btn
->command
);
844 if (!btn
->relaunching
) {
851 static void updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
853 WScreen
*scr
= menu
->frame
->screen_ptr
;
854 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
860 for (i
= 0; i
< scr
->workspace_count
; i
++) {
861 if (i
< menu
->entry_no
) {
862 if (strcmp(menu
->entries
[i
]->text
, scr
->workspaces
[i
]->name
) != 0) {
863 wfree(menu
->entries
[i
]->text
);
864 strcpy(title
, scr
->workspaces
[i
]->name
);
865 menu
->entries
[i
]->text
= wstrdup(title
);
866 menu
->flags
.realized
= 0;
868 menu
->entries
[i
]->clientdata
= (void *)icon
;
870 strcpy(title
, scr
->workspaces
[i
]->name
);
872 wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)icon
);
874 menu
->flags
.realized
= 0;
876 if (i
== scr
->current_workspace
) {
877 wMenuSetEnabled(menu
, i
, False
);
879 wMenuSetEnabled(menu
, i
, True
);
883 if (!menu
->flags
.realized
)
887 static WMenu
*makeWorkspaceMenu(WScreen
*scr
)
891 menu
= wMenuCreate(scr
, NULL
, False
);
893 wwarning(_("could not create workspace submenu for Clip menu"));
895 wMenuAddCallback(menu
, "", switchWSCommand
, (void *)scr
->clip_icon
);
897 menu
->flags
.realized
= 0;
903 static void updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
912 entry
= menu
->entries
[index
];
913 entry
->flags
.indicator_on
= !dock
->lowered
;
914 entry
->clientdata
= dock
;
917 entry
= menu
->entries
[++index
];
918 entry
->flags
.indicator_on
= dock
->collapsed
;
919 entry
->clientdata
= dock
;
922 entry
= menu
->entries
[++index
];
923 entry
->flags
.indicator_on
= dock
->auto_collapse
;
924 entry
->clientdata
= dock
;
926 /* auto-raise/lower */
927 entry
= menu
->entries
[++index
];
928 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
929 entry
->clientdata
= dock
;
930 wMenuSetEnabled(menu
, index
, dock
->lowered
);
933 entry
= menu
->entries
[++index
];
934 entry
->flags
.indicator_on
= dock
->attract_icons
;
935 entry
->clientdata
= dock
;
937 menu
->flags
.realized
= 0;
941 static WMenu
*makeClipOptionsMenu(WScreen
*scr
)
946 menu
= wMenuCreate(scr
, NULL
, False
);
948 wwarning(_("could not create options submenu for Clip menu"));
952 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
953 entry
->flags
.indicator
= 1;
954 entry
->flags
.indicator_on
= 1;
955 entry
->flags
.indicator_type
= MI_CHECK
;
957 entry
= wMenuAddCallback(menu
, _("Collapsed"), toggleCollapsedCallback
, NULL
);
958 entry
->flags
.indicator
= 1;
959 entry
->flags
.indicator_on
= 1;
960 entry
->flags
.indicator_type
= MI_CHECK
;
962 entry
= wMenuAddCallback(menu
, _("Autocollapse"), toggleAutoCollapseCallback
, NULL
);
963 entry
->flags
.indicator
= 1;
964 entry
->flags
.indicator_on
= 1;
965 entry
->flags
.indicator_type
= MI_CHECK
;
967 entry
= wMenuAddCallback(menu
, _("Autoraise"), toggleAutoRaiseLowerCallback
, NULL
);
968 entry
->flags
.indicator
= 1;
969 entry
->flags
.indicator_on
= 1;
970 entry
->flags
.indicator_type
= MI_CHECK
;
972 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"), toggleAutoAttractCallback
, NULL
);
973 entry
->flags
.indicator
= 1;
974 entry
->flags
.indicator_on
= 1;
975 entry
->flags
.indicator_type
= MI_CHECK
;
977 menu
->flags
.realized
= 0;
983 static WMenu
*dockMenuCreate(WScreen
*scr
, int type
)
988 if (type
== WM_CLIP
&& scr
->clip_menu
)
989 return scr
->clip_menu
;
991 menu
= wMenuCreate(scr
, NULL
, False
);
992 if (type
!= WM_CLIP
) {
993 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
994 entry
->flags
.indicator
= 1;
995 entry
->flags
.indicator_on
= 1;
996 entry
->flags
.indicator_type
= MI_CHECK
;
998 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
999 scr
->clip_options
= makeClipOptionsMenu(scr
);
1000 if (scr
->clip_options
)
1001 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1003 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1005 entry
->text
= _("Rename Workspace");
1007 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1008 entry
->flags
.indicator
= 1;
1009 entry
->flags
.indicator_on
= 1;
1010 entry
->flags
.indicator_type
= MI_CHECK
;
1012 entry
= wMenuAddCallback(menu
, _("Select All Icons"), selectIconsCallback
, NULL
);
1014 entry
->text
= _("Select All Icons");
1016 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1018 entry
->text
= _("Keep Icon");
1020 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1022 entry
->text
= _("Move Icon To");
1023 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1024 if (scr
->clip_submenu
)
1025 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1027 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
, NULL
);
1029 entry
->text
= _("Remove Icon");
1031 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1034 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1036 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1038 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1040 entry
->text
= _("Hide");
1042 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1044 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1046 if (type
== WM_CLIP
)
1047 scr
->clip_menu
= menu
;
1052 WDock
*wDockCreate(WScreen
*scr
, int type
)
1059 dock
= wmalloc(sizeof(WDock
));
1060 memset(dock
, 0, sizeof(WDock
));
1062 dock
->max_icons
= DOCK_MAX_ICONS
;
1064 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * dock
->max_icons
);
1065 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*) * dock
->max_icons
);
1067 btn
= mainIconCreate(scr
, type
);
1071 dock
->x_pos
= btn
->x_pos
;
1072 dock
->y_pos
= btn
->y_pos
;
1073 dock
->screen_ptr
= scr
;
1075 dock
->icon_count
= 1;
1076 dock
->on_right_side
= 1;
1077 dock
->collapsed
= 0;
1078 dock
->auto_collapse
= 0;
1079 dock
->auto_collapse_magic
= NULL
;
1080 dock
->auto_raise_lower
= 0;
1081 dock
->auto_lower_magic
= NULL
;
1082 dock
->auto_raise_magic
= NULL
;
1083 dock
->attract_icons
= 0;
1085 dock
->icon_array
[0] = btn
;
1086 wRaiseFrame(btn
->icon
->core
);
1087 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1089 /* create dock menu */
1090 dock
->menu
= dockMenuCreate(scr
, type
);
1095 void wDockDestroy(WDock
*dock
)
1100 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1101 aicon
= dock
->icon_array
[i
];
1103 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1104 wDockDetach(dock
, aicon
);
1106 /* XXX: can: aicon->icon == NULL ? */
1107 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1108 wGetHeadForWindow(aicon
->icon
->owner
));
1109 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1110 if (!dock
->mapped
|| dock
->collapsed
)
1111 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1115 if (wPreferences
.auto_arrange_icons
)
1116 wArrangeIcons(dock
->screen_ptr
, True
);
1117 wfree(dock
->icon_array
);
1118 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1119 wMenuDestroy(dock
->menu
, True
);
1120 if (dock
->screen_ptr
->last_dock
== dock
)
1121 dock
->screen_ptr
->last_dock
= NULL
;
1125 void wClipIconPaint(WAppIcon
*aicon
)
1127 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1128 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1130 Window win
= aicon
->icon
->core
->window
;
1131 int length
, nlength
;
1132 char *ws_name
, ws_number
[10];
1135 wIconPaint(aicon
->icon
);
1137 length
= strlen(workspace
->name
);
1138 ws_name
= wmalloc(length
+ 1);
1139 snprintf(ws_name
, length
+ 1, "%s", workspace
->name
);
1140 snprintf(ws_number
, sizeof(ws_number
), "%i", scr
->current_workspace
+ 1);
1141 nlength
= strlen(ws_number
);
1143 if (!workspace
->clip
->collapsed
)
1144 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1146 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1148 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1150 tx
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
1152 if(wPreferences
.show_clip_title
)
1153 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, ty
, ws_name
, length
);
1155 tx
= (ICON_SIZE
/ 2 - WMWidthOfString(scr
->clip_title_font
, ws_number
, nlength
)) / 2;
1157 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, 2, ws_number
, nlength
);
1161 if (aicon
->launching
) {
1162 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1163 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1165 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
, aicon
->dock
->rclip_button_pushed
);
1168 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1170 wClipIconPaint(desc
->parent
);
1173 static void dockIconPaint(WAppIcon
*btn
)
1175 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1176 wClipIconPaint(btn
);
1183 static WMPropList
*make_icon_state(WAppIcon
*btn
)
1185 WMPropList
*node
= NULL
;
1186 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
, *host
;
1187 WMPropList
*position
, *buggy
, *omnipresent
;
1193 command
= WMCreatePLString("-");
1195 command
= WMCreatePLString(btn
->command
);
1197 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1199 lock
= btn
->lock
? dYes
: dNo
;
1201 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1203 name
= WMCreatePLString(tmp
);
1207 forced
= btn
->forced_dock
? dYes
: dNo
;
1209 buggy
= btn
->buggy_app
? dYes
: dNo
;
1211 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1212 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1214 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1215 position
= WMCreatePLString(buffer
);
1217 node
= WMCreatePLDictionary(dCommand
, command
,
1219 dAutoLaunch
, autolaunch
,
1221 dForced
, forced
, dBuggyApplication
, buggy
, dPosition
, position
, NULL
);
1222 WMReleasePropList(command
);
1223 WMReleasePropList(name
);
1224 WMReleasePropList(position
);
1226 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1227 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&& (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1228 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1230 #ifdef XDND /* was OFFIX */
1231 if (btn
->dnd_command
) {
1232 command
= WMCreatePLString(btn
->dnd_command
);
1233 WMPutInPLDictionary(node
, dDropCommand
, command
);
1234 WMReleasePropList(command
);
1238 if (btn
->paste_command
) {
1239 command
= WMCreatePLString(btn
->paste_command
);
1240 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1241 WMReleasePropList(command
);
1244 if (btn
->client_machine
&& btn
->remote_start
) {
1245 host
= WMCreatePLString(btn
->client_machine
);
1246 WMPutInPLDictionary(node
, dHost
, host
);
1247 WMReleasePropList(host
);
1254 static WMPropList
*dockSaveState(WDock
*dock
)
1257 WMPropList
*icon_info
;
1258 WMPropList
*list
= NULL
, *dock_state
= NULL
;
1259 WMPropList
*value
, *key
;
1262 list
= WMCreatePLArray(NULL
);
1264 for (i
= (dock
->type
== WM_DOCK
? 0 : 1); i
< dock
->max_icons
; i
++) {
1265 WAppIcon
*btn
= dock
->icon_array
[i
];
1267 if (!btn
|| btn
->attracted
)
1270 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1271 WMAddToPLArray(list
, icon_info
);
1272 WMReleasePropList(icon_info
);
1276 dock_state
= WMCreatePLDictionary(dApplications
, list
, NULL
);
1278 if (dock
->type
== WM_DOCK
) {
1279 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1280 key
= WMCreatePLString(buffer
);
1281 WMPutInPLDictionary(dock_state
, key
, list
);
1282 WMReleasePropList(key
);
1284 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0), dock
->y_pos
);
1285 value
= WMCreatePLString(buffer
);
1286 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1287 WMReleasePropList(value
);
1289 WMReleasePropList(list
);
1291 value
= (dock
->lowered
? dYes
: dNo
);
1292 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1294 if (dock
->type
== WM_CLIP
) {
1295 value
= (dock
->collapsed
? dYes
: dNo
);
1296 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1298 value
= (dock
->auto_collapse
? dYes
: dNo
);
1299 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1301 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1302 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1304 value
= (dock
->attract_icons
? dYes
: dNo
);
1305 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1311 void wDockSaveState(WScreen
*scr
, WMPropList
*old_state
)
1313 WMPropList
*dock_state
;
1316 dock_state
= dockSaveState(scr
->dock
);
1319 * Copy saved states of docks with different sizes.
1325 keys
= WMGetPLDictionaryKeys(old_state
);
1326 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1327 tmp
= WMGetFromPLArray(keys
, i
);
1329 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1330 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1332 WMPutInPLDictionary(dock_state
, tmp
, WMGetFromPLDictionary(old_state
, tmp
));
1335 WMReleasePropList(keys
);
1338 WMPutInPLDictionary(scr
->session_state
, dDock
, dock_state
);
1340 WMReleasePropList(dock_state
);
1343 void wClipSaveState(WScreen
*scr
)
1345 WMPropList
*clip_state
;
1347 clip_state
= make_icon_state(scr
->clip_icon
);
1349 WMPutInPLDictionary(scr
->session_state
, dClip
, clip_state
);
1351 WMReleasePropList(clip_state
);
1354 WMPropList
*wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1356 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1359 static Bool
getBooleanDockValue(WMPropList
*value
, WMPropList
*key
)
1362 if (WMIsPLString(value
)) {
1363 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1366 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1372 static WAppIcon
*restore_icon_state(WScreen
*scr
, WMPropList
*info
, int type
, int index
)
1375 WMPropList
*cmd
, *value
;
1377 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1378 if (!cmd
|| !WMIsPLString(cmd
)) {
1382 /* parse window name */
1383 value
= WMGetFromPLDictionary(info
, dName
);
1388 char *wclass
, *winstance
;
1391 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1393 if (!winstance
&& !wclass
) {
1400 command
= wstrdup(WMGetFromPLString(cmd
));
1404 if (!command
|| strcmp(command
, "-") == 0) {
1415 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1424 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1425 if (type
== WM_CLIP
) {
1426 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1427 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1429 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1430 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1432 #ifdef XDND /* was OFFIX */
1433 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1435 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1438 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1440 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1442 /* check auto launch */
1443 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1445 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1448 value
= WMGetFromPLDictionary(info
, dLock
);
1450 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1452 /* check if it wasn't normally docked */
1453 value
= WMGetFromPLDictionary(info
, dForced
);
1455 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1457 /* check if we can rely on the stuff in the app */
1458 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1460 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1462 /* get position in the dock */
1463 value
= WMGetFromPLDictionary(info
, dPosition
);
1464 if (value
&& WMIsPLString(value
)) {
1465 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1466 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1468 /* check position sanity */
1469 /* incomplete section! */
1470 if (type
== WM_DOCK
) {
1472 if (aicon
->yindex
< 0)
1473 wwarning(_("bad value in docked icon position %i,%i"),
1474 aicon
->xindex
, aicon
->yindex
);
1477 aicon
->yindex
= index
;
1481 /* check if icon is omnipresent */
1482 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1484 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1492 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1494 WAppIcon
*wClipRestoreState(WScreen
*scr
, WMPropList
*clip_state
)
1499 icon
= mainIconCreate(scr
, WM_CLIP
);
1504 WMRetainPropList(clip_state
);
1506 /* restore position */
1508 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1511 if (!WMIsPLString(value
))
1512 COMPLAIN("Position");
1517 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1518 COMPLAIN("Position");
1520 /* check position sanity */
1521 rect
.pos
.x
= icon
->x_pos
;
1522 rect
.pos
.y
= icon
->y_pos
;
1523 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1525 wGetRectPlacementInfo(scr
, rect
, &flags
);
1526 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
1527 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1530 #ifdef XDND /* was OFFIX */
1531 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1532 if (value
&& WMIsPLString(value
))
1533 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1536 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1537 if (value
&& WMIsPLString(value
))
1538 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1540 WMReleasePropList(clip_state
);
1545 WDock
*wDockRestoreState(WScreen
*scr
, WMPropList
*dock_state
, int type
)
1550 WAppIcon
*aicon
, *old_top
;
1553 dock
= wDockCreate(scr
, type
);
1558 WMRetainPropList(dock_state
);
1560 /* restore position */
1561 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1563 if (!WMIsPLString(value
)) {
1564 COMPLAIN("Position");
1569 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1570 COMPLAIN("Position");
1572 /* check position sanity */
1573 rect
.pos
.x
= dock
->x_pos
;
1574 rect
.pos
.y
= dock
->y_pos
;
1575 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1577 wGetRectPlacementInfo(scr
, rect
, &flags
);
1578 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
)) {
1579 int x
= dock
->x_pos
;
1580 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1583 /* Is this needed any more? */
1584 if (type
== WM_CLIP
) {
1585 if (dock
->x_pos
< 0) {
1587 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1588 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1591 if (dock
->x_pos
>= 0) {
1592 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1593 dock
->on_right_side
= 0;
1595 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1596 dock
->on_right_side
= 1;
1602 /* restore lowered/raised state */
1605 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1607 if (!WMIsPLString(value
)) {
1608 COMPLAIN("Lowered");
1610 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1616 /* restore collapsed state */
1617 dock
->collapsed
= 0;
1619 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1621 if (!WMIsPLString(value
)) {
1622 COMPLAIN("Collapsed");
1624 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1625 dock
->collapsed
= 1;
1630 /* restore auto-collapsed state */
1631 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1633 if (!WMIsPLString(value
)) {
1634 COMPLAIN("AutoCollapse");
1636 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1637 dock
->auto_collapse
= 1;
1638 dock
->collapsed
= 1;
1643 /* restore auto-raise/lower state */
1644 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1646 if (!WMIsPLString(value
)) {
1647 COMPLAIN("AutoRaiseLower");
1649 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1650 dock
->auto_raise_lower
= 1;
1654 /* restore attract icons state */
1655 dock
->attract_icons
= 0;
1657 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1659 if (!WMIsPLString(value
)) {
1660 COMPLAIN("AutoAttractIcons");
1662 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1663 dock
->attract_icons
= 1;
1667 /* application list */
1674 * When saving, it saves the dock state in
1675 * Applications and Applicationsnnn
1677 * When loading, it will first try Applicationsnnn.
1678 * If it does not exist, use Applications as default.
1681 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1683 tmp
= WMCreatePLString(buffer
);
1684 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1685 WMReleasePropList(tmp
);
1688 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1694 count
= WMGetPropListItemCount(apps
);
1698 old_top
= dock
->icon_array
[0];
1700 /* dock->icon_count is set to 1 when dock is created.
1701 * Since Clip is already restored, we want to keep it so for clip,
1702 * but for dock we may change the default top tile, so we set it to 0.
1704 if (type
== WM_DOCK
)
1705 dock
->icon_count
= 0;
1707 for (i
= 0; i
< count
; i
++) {
1708 if (dock
->icon_count
>= dock
->max_icons
) {
1709 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1713 value
= WMGetFromPLArray(apps
, i
);
1714 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1716 dock
->icon_array
[dock
->icon_count
] = aicon
;
1720 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1721 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1724 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1726 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1728 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1730 if (!dock
->collapsed
)
1731 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1732 wRaiseFrame(aicon
->icon
->core
);
1735 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
)
1739 /* if the first icon is not defined, use the default */
1740 if (dock
->icon_array
[0] == NULL
) {
1741 /* update default icon */
1742 old_top
->x_pos
= dock
->x_pos
;
1743 old_top
->y_pos
= dock
->y_pos
;
1745 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1747 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1748 dock
->icon_array
[0] = old_top
;
1749 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1750 /* we don't need to increment dock->icon_count here because it was
1751 * incremented in the loop above.
1753 } else if (old_top
!= dock
->icon_array
[0]) {
1754 if (old_top
== scr
->clip_icon
)
1755 scr
->clip_icon
= dock
->icon_array
[0];
1756 wAppIconDestroy(old_top
);
1760 WMReleasePropList(dock_state
);
1765 void wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1767 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1769 btn
->drop_launch
= 0;
1770 btn
->paste_launch
= 0;
1772 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1775 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1785 void wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1791 for (i
= 0; i
< dock
->max_icons
; i
++) {
1792 btn
= dock
->icon_array
[i
];
1793 if (!btn
|| !btn
->auto_launch
)
1796 state
= wmalloc(sizeof(WSavedState
));
1797 memset(state
, 0, sizeof(WSavedState
));
1798 state
->workspace
= workspace
;
1799 /* TODO: this is klugy and is very difficult to understand
1800 * what's going on. Try to clean up */
1801 wDockLaunchWithState(dock
, btn
, state
);
1805 #ifdef XDND /* was OFFIX */
1806 static WDock
*findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1812 if ((dock
= scr
->dock
) != NULL
) {
1813 for (i
= 0; i
< dock
->max_icons
; i
++) {
1814 if (dock
->icon_array
[i
]
1815 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1821 if (*icon_pos
< 0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
) != NULL
) {
1822 for (i
= 0; i
< dock
->max_icons
; i
++) {
1823 if (dock
->icon_array
[i
]
1824 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1835 int wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
1841 dock
= findDock(scr
, event
, &icon_pos
);
1846 * Return True if the drop was on an application icon window.
1847 * In this case, let the ClientMessage handler redirect the
1848 * message to the app.
1850 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
1853 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
1854 scr
->flags
.dnd_data_convertion_status
= 0;
1856 btn
= dock
->icon_array
[icon_pos
];
1858 if (!btn
->forced_dock
) {
1859 btn
->relaunching
= btn
->running
;
1862 if (btn
->wm_instance
|| btn
->wm_class
) {
1863 WWindowAttributes attr
;
1864 memset(&attr
, 0, sizeof(WWindowAttributes
));
1865 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
1866 btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
1868 if (!attr
.no_appicon
)
1874 btn
->paste_launch
= 0;
1875 btn
->drop_launch
= 1;
1876 scr
->last_dock
= dock
;
1877 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1882 if (!btn
->relaunching
) {
1891 Bool
wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1896 wwin
= icon
->icon
->owner
;
1897 if (icon
->command
== NULL
) {
1902 command
= GetCommandForWindow(wwin
->client_win
);
1904 icon
->command
= command
;
1906 /* icon->forced_dock = 1; */
1907 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
1909 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
1910 _("Type the command used to launch the application"), &command
)) {
1911 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
1915 icon
->command
= command
;
1921 /* If the target is the dock, reject the icon. If
1922 * the target is the clip, make it an attracted icon
1924 if (dock
->type
== WM_CLIP
) {
1925 icon
->attracted
= 1;
1926 if (!icon
->icon
->shadowed
) {
1927 icon
->icon
->shadowed
= 1;
1928 icon
->icon
->force_paint
= 1;
1940 for (index
= 1; index
< dock
->max_icons
; index
++)
1941 if (dock
->icon_array
[index
] == NULL
)
1943 /* if (index == dock->max_icons)
1946 assert(index
< dock
->max_icons
);
1948 dock
->icon_array
[index
] = icon
;
1952 icon
->omnipresent
= 0;
1954 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
1955 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
1960 icon
->launching
= 0;
1963 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1964 if (dock
->type
== WM_CLIP
) {
1965 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1966 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1968 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1969 icon
->icon
->core
->descriptor
.parent
= icon
;
1971 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
1972 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
1973 wAppIconPaint(icon
);
1976 if (wPreferences
.auto_arrange_icons
)
1977 wArrangeIcons(dock
->screen_ptr
, True
);
1979 #ifdef XDND /* was OFFIX */
1980 if (icon
->command
&& !icon
->dnd_command
) {
1981 int len
= strlen(icon
->command
) + 8;
1982 icon
->dnd_command
= wmalloc(len
);
1983 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
1987 if (icon
->command
&& !icon
->paste_command
) {
1988 int len
= strlen(icon
->command
) + 8;
1989 icon
->paste_command
= wmalloc(len
);
1990 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
1996 static void reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2000 for (index
= 1; index
< dock
->max_icons
; index
++) {
2001 if (dock
->icon_array
[index
] == icon
)
2004 assert(index
< dock
->max_icons
);
2009 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2010 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2013 static Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2020 return True
; /* No move needed, we're already there */
2025 wwin
= icon
->icon
->owner
;
2028 * For the moment we can't do this if we move icons in Clip from one
2029 * workspace to other, because if we move two or more icons without
2030 * command, the dialog box will not be able to tell us to which of the
2031 * moved icons it applies. -Dan
2033 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
2034 command
= GetCommandForWindow(wwin
->client_win
);
2036 icon
->command
= command
;
2039 /* icon->forced_dock = 1; */
2040 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2041 _("Type the command used to launch the application"), &command
)) {
2042 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2046 icon
->command
= command
;
2057 if (dest
->type
== WM_DOCK
)
2058 wClipMakeIconOmnipresent(icon
, False
);
2060 for (index
= 1; index
< src
->max_icons
; index
++) {
2061 if (src
->icon_array
[index
] == icon
)
2064 assert(index
< src
->max_icons
);
2066 src
->icon_array
[index
] = NULL
;
2069 for (index
= 1; index
< dest
->max_icons
; index
++) {
2070 if (dest
->icon_array
[index
] == NULL
)
2073 /* if (index == dest->max_icons)
2076 assert(index
< dest
->max_icons
);
2078 dest
->icon_array
[index
] = icon
;
2081 /* deselect the icon */
2082 if (icon
->icon
->selected
)
2083 wIconSelect(icon
->icon
);
2085 if (dest
->type
== WM_DOCK
) {
2086 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2087 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2089 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2090 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2093 /* set it to be kept when moving to dock.
2094 * Unless the icon does not have a command set
2096 if (icon
->command
&& dest
->type
== WM_DOCK
) {
2097 icon
->attracted
= 0;
2098 if (icon
->icon
->shadowed
) {
2099 icon
->icon
->shadowed
= 0;
2100 icon
->icon
->force_paint
= 1;
2105 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2111 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2112 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2116 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2117 wAppIconPaint(icon
);
2122 void wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2126 /* make the settings panel be closed */
2128 DestroyDockAppSettingsPanel(icon
->panel
);
2131 /* This must be called before icon->dock is set to NULL.
2132 * Don't move it. -Dan
2134 wClipMakeIconOmnipresent(icon
, False
);
2138 icon
->attracted
= 0;
2139 icon
->auto_launch
= 0;
2140 if (icon
->icon
->shadowed
) {
2141 icon
->icon
->shadowed
= 0;
2142 icon
->icon
->force_paint
= 1;
2145 /* deselect the icon */
2146 if (icon
->icon
->selected
)
2147 wIconSelect(icon
->icon
);
2149 if (icon
->command
) {
2150 wfree(icon
->command
);
2151 icon
->command
= NULL
;
2153 #ifdef XDND /* was OFFIX */
2154 if (icon
->dnd_command
) {
2155 wfree(icon
->dnd_command
);
2156 icon
->dnd_command
= NULL
;
2159 if (icon
->paste_command
) {
2160 wfree(icon
->paste_command
);
2161 icon
->paste_command
= NULL
;
2164 for (index
= 1; index
< dock
->max_icons
; index
++)
2165 if (dock
->icon_array
[index
] == icon
)
2167 assert(index
< dock
->max_icons
);
2168 dock
->icon_array
[index
] = NULL
;
2174 /* if the dock is not attached to an application or
2175 * the the application did not set the approriate hints yet,
2176 * destroy the icon */
2177 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2178 wAppIconDestroy(icon
);
2180 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2181 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2182 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2183 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2184 icon
->icon
->core
->descriptor
.parent
= icon
;
2186 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2188 wAppIconPaint(icon
);
2189 if (wPreferences
.auto_arrange_icons
) {
2190 wArrangeIcons(dock
->screen_ptr
, True
);
2193 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2198 * returns the closest Dock slot index for the passed
2201 * Returns False if icon can't be docked.
2203 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2206 Bool
wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2208 WScreen
*scr
= dock
->screen_ptr
;
2211 int i
, offset
= ICON_SIZE
/ 2;
2212 WAppIcon
*aicon
= NULL
;
2213 WAppIcon
*nicon
= NULL
;
2216 /* TODO: XINERAMA, for these */
2217 max_y_icons
= scr
->scr_height
/ ICON_SIZE
- 1;
2219 if (wPreferences
.flags
.noupdates
)
2225 /* if the dock is full */
2226 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
)) {
2230 /* exact position */
2232 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2234 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2237 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2239 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2241 /* check if the icon is outside the screen boundaries */
2246 rect
.pos
.x
= dx
+ ex_x
* ICON_SIZE
;
2247 rect
.pos
.y
= dy
+ ex_y
* ICON_SIZE
;
2248 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2250 wGetRectPlacementInfo(scr
, rect
, &flags
);
2251 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
2255 if (dock
->type
== WM_DOCK
) {
2256 if (icon
->dock
!= dock
&& ex_x
!= 0)
2260 for (i
= 0; i
< dock
->max_icons
; i
++) {
2261 nicon
= dock
->icon_array
[i
];
2262 if (nicon
&& nicon
->yindex
== ex_y
) {
2269 int sig
, done
, closest
;
2271 /* Possible cases when redocking:
2273 * icon dragged out of range of any slot -> false
2274 * icon dragged to range of free slot
2275 * icon dragged to range of same slot
2276 * icon dragged to range of different icon
2278 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2281 if (ex_y
>= 0 && ex_y
<= max_y_icons
&& (aicon
== icon
|| !aicon
)) {
2287 /* start looking at the upper slot or lower? */
2288 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2295 /* look for closest free slot */
2296 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2300 closest
= sig
* (i
/ 2) + ex_y
;
2301 /* check if this slot is used */
2303 for (j
= 0; j
< dock
->max_icons
; j
++) {
2304 if (dock
->icon_array
[j
]
2305 && dock
->icon_array
[j
]->yindex
== closest
) {
2306 /* slot is used by someone else */
2307 if (dock
->icon_array
[j
] != icon
)
2315 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2316 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2317 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2322 } else { /* !redocking */
2324 /* if slot is free and the icon is close enough, return it */
2325 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2335 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2336 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+ 1;
2339 for (k
= start
; k
< stop
; k
++) {
2340 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2343 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2344 nicon
= tmp
->icon_array
[i
];
2345 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2353 for (k
= start
; k
< stop
; k
++) {
2354 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2357 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2358 nicon
= tmp
->icon_array
[i
];
2359 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2360 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2361 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2370 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2379 static int onScreen(WScreen
*scr
, int x
, int y
, int sx
, int ex
, int sy
, int ey
)
2381 WMRect rect
= wmkrect(x
, y
, ICON_SIZE
, ICON_SIZE
);
2384 wGetRectPlacementInfo(scr
, rect
, &flags
);
2386 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2390 * returns true if it can find a free slot in the dock,
2391 * in which case it changes x_pos and y_pos accordingly.
2392 * Else returns false.
2394 Bool
wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2396 WScreen
*scr
= dock
->screen_ptr
;
2398 WAppIconChain
*chain
;
2399 unsigned char *slot_map
;
2403 int i
, done
= False
;
2405 int sx
= 0, sy
= 0, ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2406 int extra_count
= 0;
2408 if (dock
->type
== WM_CLIP
&& dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2409 extra_count
= scr
->global_icon_count
;
2411 /* if the dock is full */
2412 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
) {
2416 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2417 if (scr
->dock
->on_right_side
)
2418 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2420 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2423 if (ex
< dock
->x_pos
)
2425 if (sx
> dock
->x_pos
+ ICON_SIZE
)
2426 sx
= dock
->x_pos
+ ICON_SIZE
;
2433 /* check if clip is in a corner */
2434 if (dock
->type
== WM_CLIP
) {
2435 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2437 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2439 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2441 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2448 /* If the clip is in the corner, use only slots that are in the border
2450 if (corner
!= C_NONE
) {
2454 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2455 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2456 hmap
= wmalloc(hcount
+ 1);
2457 memset(hmap
, 0, hcount
+ 1);
2458 vmap
= wmalloc(vcount
+ 1);
2459 memset(vmap
, 0, 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
);
2591 memset(slot_map
, 0, mwidth
* mwidth
);
2593 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2595 /* mark used slots in the map. If the slot falls outside the map
2596 * (for example, when all icons are placed in line), ignore them. */
2597 for (i
= 0; i
< dock
->max_icons
; i
++) {
2598 btn
= dock
->icon_array
[i
];
2600 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
;
2689 for (i
= 0; i
< dock
->max_icons
; i
++) {
2690 btn
= dock
->icon_array
[i
];
2693 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2697 wScreenUpdateUsableArea(scr
);
2700 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2702 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2708 cmdline
= ExpandOptions(scr
, command
);
2710 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2718 wtokensplit(cmdline
, &argv
, &argc
);
2728 if ((pid
= fork()) == 0) {
2732 SetupEnvironment(scr
);
2738 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
));
2753 memset(state
, 0, sizeof(WSavedState
));
2755 state
->miniaturized
= -1;
2757 if (btn
->dock
== scr
->dock
|| btn
->omnipresent
)
2758 state
->workspace
= -1;
2760 state
->workspace
= scr
->current_workspace
;
2762 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
2763 wAddDeathHandler(pid
, (WDeathHandler
*) trackDeadProcess
, btn
->dock
);
2771 void wDockHideIcons(WDock
*dock
)
2778 for (i
= 1; i
< dock
->max_icons
; i
++) {
2779 if (dock
->icon_array
[i
])
2780 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2784 dockIconPaint(dock
->icon_array
[0]);
2787 void wDockShowIcons(WDock
*dock
)
2795 btn
= dock
->icon_array
[0];
2796 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2798 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2799 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2801 for (i
= 1; i
< dock
->max_icons
; i
++) {
2802 if (dock
->icon_array
[i
]) {
2803 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
, btn
->icon
->core
);
2808 if (!dock
->collapsed
) {
2809 for (i
= 1; i
< dock
->max_icons
; i
++) {
2810 if (dock
->icon_array
[i
]) {
2811 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2820 void wDockLower(WDock
*dock
)
2824 for (i
= 0; i
< dock
->max_icons
; i
++) {
2825 if (dock
->icon_array
[i
])
2826 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2830 void wDockRaise(WDock
*dock
)
2834 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
2835 if (dock
->icon_array
[i
])
2836 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2840 void wDockRaiseLower(WDock
*dock
)
2842 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2843 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2844 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2850 void wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
2852 icon
->launching
= 0;
2853 icon
->relaunching
= 0;
2854 dockIconPaint(icon
);
2857 WAppIcon
*wDockFindIconForWindow(WDock
*dock
, Window window
)
2862 for (i
= 0; i
< dock
->max_icons
; i
++) {
2863 icon
= dock
->icon_array
[i
];
2864 if (icon
&& icon
->main_window
== window
)
2870 void wDockTrackWindowLaunch(WDock
*dock
, Window window
)
2873 char *wm_class
, *wm_instance
;
2875 Bool firstPass
= True
;
2877 char *command
= NULL
;
2879 command
= GetCommandForWindow(window
);
2881 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) || (!wm_class
&& !wm_instance
)) {
2889 for (i
= 0; i
< dock
->max_icons
; i
++) {
2890 icon
= dock
->icon_array
[i
];
2894 /* app is already attached to icon */
2895 if (icon
->main_window
== window
) {
2900 if ((icon
->wm_instance
|| icon
->wm_class
)
2901 && (icon
->launching
|| !icon
->running
)) {
2903 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0) {
2906 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0) {
2909 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0) {
2913 if (!icon
->relaunching
) {
2916 /* Possibly an application that was docked with dockit,
2917 * but the user did not update WMState to indicate that
2918 * it was docked by force */
2919 wapp
= wApplicationOf(window
);
2921 icon
->forced_dock
= 1;
2924 if (!icon
->forced_dock
) {
2925 icon
->main_window
= window
;
2929 if (!wPreferences
.no_animations
&& !icon
->launching
&&
2930 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
2934 icon
->launching
= 1;
2935 dockIconPaint(icon
);
2937 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
2938 wm_instance
, wm_class
, TILE_NORMAL
);
2939 /* XXX: can: aicon->icon == NULL ? */
2940 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
2941 wAppIconMove(aicon
, x0
, y0
);
2942 /* Should this always be lowered? -Dan */
2944 wLowerFrame(aicon
->icon
->core
);
2945 XMapWindow(dpy
, aicon
->icon
->core
->window
);
2946 aicon
->launching
= 1;
2947 wAppIconPaint(aicon
);
2948 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
2949 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
2950 wAppIconDestroy(aicon
);
2952 wDockFinishLaunch(dock
, icon
);
2957 if (firstPass
&& !found
) {
2971 void wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
2973 if (!wPreferences
.flags
.noclip
) {
2974 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
2975 if (scr
->current_workspace
!= workspace
) {
2976 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
2977 WAppIconChain
*chain
= scr
->global_icons
;
2980 moveIconBetweenDocks(chain
->aicon
->dock
,
2981 scr
->workspaces
[workspace
]->clip
,
2982 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
2983 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
2984 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
2985 chain
= chain
->next
;
2988 wDockHideIcons(old_clip
);
2989 if (old_clip
->auto_raise_lower
) {
2990 if (old_clip
->auto_raise_magic
) {
2991 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
2992 old_clip
->auto_raise_magic
= NULL
;
2994 wDockLower(old_clip
);
2996 if (old_clip
->auto_collapse
) {
2997 if (old_clip
->auto_expand_magic
) {
2998 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
2999 old_clip
->auto_expand_magic
= NULL
;
3001 old_clip
->collapsed
= 1;
3003 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3008 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3013 for (i
= 0; i
< dock
->max_icons
; i
++) {
3014 icon
= dock
->icon_array
[i
];
3018 if (icon
->launching
&& icon
->pid
== pid
) {
3019 if (!icon
->relaunching
) {
3021 icon
->main_window
= None
;
3023 wDockFinishLaunch(dock
, icon
);
3025 if (status
== 111) {
3030 if (icon
->drop_launch
)
3031 cmd
= icon
->dnd_command
;
3034 if (icon
->paste_launch
)
3035 cmd
= icon
->paste_command
;
3037 cmd
= icon
->command
;
3039 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3041 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3048 static void toggleLowered(WDock
*dock
)
3053 /* lower/raise Dock */
3054 if (!dock
->lowered
) {
3055 newlevel
= WMNormalLevel
;
3058 newlevel
= WMDockLevel
;
3062 for (i
= 0; i
< dock
->max_icons
; i
++) {
3063 tmp
= dock
->icon_array
[i
];
3067 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3069 wLowerFrame(tmp
->icon
->core
);
3072 if (dock
->type
== WM_DOCK
)
3073 wScreenUpdateUsableArea(dock
->screen_ptr
);
3076 static void toggleCollapsed(WDock
*dock
)
3078 if (dock
->collapsed
) {
3079 dock
->collapsed
= 0;
3080 wDockShowIcons(dock
);
3082 dock
->collapsed
= 1;
3083 wDockHideIcons(dock
);
3087 static void openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3089 WScreen
*scr
= dock
->screen_ptr
;
3090 WObjDescriptor
*desc
;
3092 WApplication
*wapp
= NULL
;
3096 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3098 if (dock
->type
== WM_DOCK
) {
3100 entry
= dock
->menu
->entries
[index
];
3101 entry
->flags
.indicator_on
= !dock
->lowered
;
3102 entry
->clientdata
= dock
;
3103 dock
->menu
->flags
.realized
= 0;
3106 if (scr
->clip_options
)
3107 updateClipOptionsMenu(scr
->clip_options
, dock
);
3109 n_selected
= numberOfSelectedIcons(dock
);
3111 /* Rename Workspace */
3112 entry
= dock
->menu
->entries
[++index
];
3113 if (aicon
== scr
->clip_icon
) {
3114 entry
->callback
= renameCallback
;
3115 entry
->clientdata
= dock
;
3116 entry
->flags
.indicator
= 0;
3117 entry
->text
= _("Rename Workspace");
3119 entry
->callback
= omnipresentCallback
;
3120 entry
->clientdata
= aicon
;
3121 if (n_selected
> 0) {
3122 entry
->flags
.indicator
= 0;
3123 entry
->text
= _("Toggle Omnipresent");
3125 entry
->flags
.indicator
= 1;
3126 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3127 entry
->flags
.indicator_type
= MI_CHECK
;
3128 entry
->text
= _("Omnipresent");
3132 /* select/unselect icon */
3133 entry
= dock
->menu
->entries
[++index
];
3134 entry
->clientdata
= aicon
;
3135 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3136 wMenuSetEnabled(dock
->menu
, index
, aicon
!= scr
->clip_icon
);
3138 /* select/unselect all icons */
3139 entry
= dock
->menu
->entries
[++index
];
3140 entry
->clientdata
= aicon
;
3142 entry
->text
= _("Unselect All Icons");
3144 entry
->text
= _("Select All Icons");
3145 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3148 entry
= dock
->menu
->entries
[++index
];
3149 entry
->clientdata
= aicon
;
3151 entry
->text
= _("Keep Icons");
3153 entry
->text
= _("Keep Icon");
3154 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3156 /* this is the workspace submenu part */
3157 entry
= dock
->menu
->entries
[++index
];
3159 entry
->text
= _("Move Icons To");
3161 entry
->text
= _("Move Icon To");
3162 if (scr
->clip_submenu
)
3163 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3164 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3166 /* remove icon(s) */
3167 entry
= dock
->menu
->entries
[++index
];
3168 entry
->clientdata
= aicon
;
3170 entry
->text
= _("Remove Icons");
3172 entry
->text
= _("Remove Icon");
3173 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3175 /* attract icon(s) */
3176 entry
= dock
->menu
->entries
[++index
];
3177 entry
->clientdata
= aicon
;
3179 dock
->menu
->flags
.realized
= 0;
3180 wMenuRealize(dock
->menu
);
3183 if (aicon
->icon
->owner
) {
3184 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3190 entry
= dock
->menu
->entries
[++index
];
3191 entry
->clientdata
= aicon
;
3192 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3195 entry
= dock
->menu
->entries
[++index
];
3196 entry
->clientdata
= aicon
;
3197 if (wapp
&& wapp
->flags
.hidden
) {
3198 entry
->text
= _("Unhide Here");
3200 entry
->text
= _("Bring Here");
3202 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3205 entry
= dock
->menu
->entries
[++index
];
3206 entry
->clientdata
= aicon
;
3207 if (wapp
&& wapp
->flags
.hidden
) {
3208 entry
->text
= _("Unhide");
3210 entry
->text
= _("Hide");
3212 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3215 entry
= dock
->menu
->entries
[++index
];
3216 entry
->clientdata
= aicon
;
3217 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3220 entry
= dock
->menu
->entries
[++index
];
3221 entry
->clientdata
= aicon
;
3222 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3224 if (!dock
->menu
->flags
.realized
)
3225 wMenuRealize(dock
->menu
);
3227 if (dock
->type
== WM_CLIP
) {
3228 /*x_pos = event->xbutton.x_root+2; */
3229 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3232 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3233 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3236 x_pos
= dock
->on_right_side
? scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3239 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3241 /* allow drag select */
3242 event
->xany
.send_event
= True
;
3243 desc
= &dock
->menu
->menu
->descriptor
;
3244 (*desc
->handle_mousedown
) (desc
, event
);
3247 /******************************************************************/
3248 static void iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3250 WAppIcon
*btn
= desc
->parent
;
3251 WDock
*dock
= btn
->dock
;
3252 WApplication
*wapp
= NULL
;
3255 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3256 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3258 assert(wapp
!= NULL
);
3260 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3262 /* go to the last workspace that the user worked on the app */
3263 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
&& !unhideHere
) {
3264 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3267 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3269 if (event
->xbutton
.state
& MOD_MASK
) {
3270 wHideOtherApplications(btn
->icon
->owner
);
3273 if (event
->xbutton
.button
== Button1
) {
3275 if (event
->xbutton
.state
& MOD_MASK
) {
3276 /* raise/lower dock */
3277 toggleLowered(dock
);
3278 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3279 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
)
3280 toggleCollapsed(dock
);
3282 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3283 } else if (btn
->command
) {
3284 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3285 launchDockedApplication(btn
, False
);
3291 static void handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3293 WScreen
*scr
= dock
->screen_ptr
;
3294 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3297 int grabbed
= 0, swapped
= 0, done
;
3298 Pixmap ghost
= None
;
3299 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3301 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3302 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3303 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3304 wwarning("pointer grab failed for dock move");
3307 for (x
= 0; x
< dock
->max_icons
; x
++) {
3308 if (dock
->icon_array
[x
] != NULL
&& dock
->icon_array
[x
]->yindex
> y
)
3309 y
= dock
->icon_array
[x
]->yindex
;
3312 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
* y
);
3316 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3317 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3324 /* It means the cursor moved so fast that it entered
3325 * something else (if moving slowly, it would have
3326 * stayed in the dock that is being moved. Ignore such
3327 * "spurious" EnterNotifiy's */
3332 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3333 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3334 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3335 | ButtonReleaseMask
| ButtonPressMask
,
3336 wCursor
[WCUR_MOVE
], CurrentTime
);
3341 if (dock
->type
== WM_CLIP
) {
3342 x
= ev
.xmotion
.x_root
- ofs_x
;
3343 y
= ev
.xmotion
.y_root
- ofs_y
;
3344 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3346 moveDock(dock
, x
, y
);
3348 /* move vertically if pointer is inside the dock */
3349 if ((dock
->on_right_side
&& ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3350 || (!dock
->on_right_side
&& ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
* 2)) {
3352 x
= ev
.xmotion
.x_root
- ofs_x
;
3353 y
= ev
.xmotion
.y_root
- ofs_y
;
3354 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3355 moveDock(dock
, dock
->x_pos
, y
);
3357 /* move horizontally to change sides */
3358 x
= ev
.xmotion
.x_root
- ofs_x
;
3359 if (!dock
->on_right_side
) {
3363 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
* 2) {
3364 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
- ICON_SIZE
3365 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3366 if (superfluous
&& ghost
== None
) {
3367 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3368 scr
->scr_width
- ICON_SIZE
3369 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3370 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3371 XClearWindow(dpy
, scr
->dock_shadow
);
3373 XMapRaised(dpy
, scr
->dock_shadow
);
3376 if (superfluous
&& ghost
!= None
) {
3377 XFreePixmap(dpy
, ghost
);
3380 XUnmapWindow(dpy
, scr
->dock_shadow
);
3385 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3386 XMoveWindow(dpy
, scr
->dock_shadow
, DOCK_EXTRA_SPACE
, dock
->y_pos
);
3387 if (superfluous
&& ghost
== None
) {
3388 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3389 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3390 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3391 XClearWindow(dpy
, scr
->dock_shadow
);
3393 XMapRaised(dpy
, scr
->dock_shadow
);
3396 XUnmapWindow(dpy
, scr
->dock_shadow
);
3398 if (superfluous
&& ghost
!= None
) {
3399 XFreePixmap(dpy
, ghost
);
3411 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3413 XUngrabPointer(dpy
, CurrentTime
);
3414 XUnmapWindow(dpy
, scr
->dock_shadow
);
3415 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3416 if (dock
->type
== WM_DOCK
) {
3419 dock
->on_right_side
= 1;
3421 dock
->on_right_side
= 0;
3423 wArrangeIcons(scr
, False
);
3432 XFreePixmap(dpy
, ghost
);
3433 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3437 static Bool
handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3439 WScreen
*scr
= dock
->screen_ptr
;
3441 WIcon
*icon
= aicon
->icon
;
3442 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3443 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3445 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3446 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3447 int shad_x
= x
, shad_y
= y
;
3448 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3450 Pixmap ghost
= None
;
3452 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3453 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3454 Bool hasMoved
= False
;
3456 if (wPreferences
.flags
.noupdates
)
3459 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3460 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3461 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3464 if (!(event
->xbutton
.state
& MOD_MASK
))
3465 wRaiseFrame(icon
->core
);
3467 if (!wPreferences
.flags
.noclip
)
3468 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3470 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3472 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3475 wins
[0] = icon
->core
->window
;
3476 wins
[1] = scr
->dock_shadow
;
3477 XRestackWindows(dpy
, wins
, 2);
3478 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
3480 if (icon
->pixmap
!= None
)
3481 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3483 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3485 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3486 XClearWindow(dpy
, scr
->dock_shadow
);
3488 XMapWindow(dpy
, scr
->dock_shadow
);
3493 XMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3494 | ButtonMotionMask
| ExposureMask
, &ev
);
3503 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3504 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3505 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3506 | ButtonReleaseMask
| ButtonPressMask
,
3507 wCursor
[WCUR_MOVE
], CurrentTime
);
3516 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3517 if (i
== scr
->current_workspace
)
3519 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3523 x
= ev
.xmotion
.x_root
- ofs_x
;
3524 y
= ev
.xmotion
.y_root
- ofs_y
;
3525 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3528 if (last_dock
!= dock
&& collapsed
) {
3529 last_dock
->collapsed
= 1;
3530 wDockHideIcons(last_dock
);
3533 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3534 dock
->collapsed
= 0;
3535 wDockShowIcons(dock
);
3537 if (dock
->auto_raise_lower
)
3541 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3544 if (last_dock
!= dock2
&& collapsed
) {
3545 last_dock
->collapsed
= 1;
3546 wDockHideIcons(last_dock
);
3549 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3550 dock2
->collapsed
= 0;
3551 wDockShowIcons(dock2
);
3553 if (dock2
->auto_raise_lower
)
3558 if (aicon
->launching
|| aicon
->lock
|| (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3559 || (!aicon
->running
&& tmp
)) {
3560 shad_x
= last_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3561 shad_y
= last_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3563 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3566 XMapWindow(dpy
, scr
->dock_shadow
);
3571 XUnmapWindow(dpy
, scr
->dock_shadow
);
3575 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3582 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3584 XUngrabPointer(dpy
, CurrentTime
);
3586 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3587 XUnmapWindow(dpy
, scr
->dock_shadow
);
3589 reattachIcon(dock
, aicon
, ix
, iy
);
3590 if (clip
&& dock
!= clip
&& clip
->auto_raise_lower
)
3593 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3595 /* Slide it back if dock rejected it */
3596 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
, aicon
->y_pos
);
3597 reattachIcon(dock
, aicon
, aicon
->xindex
, aicon
->yindex
);
3599 if (last_dock
->type
== WM_CLIP
&& last_dock
->auto_collapse
) {
3607 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3608 /* We need to deselect it, even if is deselected in
3609 * wDockDetach(), because else DoKaboom() will fail.
3611 if (aicon
->icon
->selected
)
3612 wIconSelect(aicon
->icon
);
3614 DoKaboom(scr
, aicon
->icon
->core
->window
, x
, y
);
3617 if (clip
&& clip
->auto_raise_lower
)
3619 wDockDetach(dock
, aicon
);
3622 last_dock
->collapsed
= 1;
3623 wDockHideIcons(last_dock
);
3628 XFreePixmap(dpy
, ghost
);
3629 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3633 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3634 if (i
== scr
->current_workspace
)
3636 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3642 return False
; /* never reached */
3645 static int getClipButton(int px
, int py
)
3647 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3649 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3652 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3653 return CLIP_FORWARD
;
3654 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3660 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3663 int done
, direction
, new_ws
;
3665 WDock
*clip
= scr
->clip_icon
->dock
;
3667 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3669 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3670 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3672 wClipIconPaint(scr
->clip_icon
);
3675 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3682 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3683 if (new_dir
!= direction
) {
3684 direction
= new_dir
;
3685 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3686 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3687 wClipIconPaint(scr
->clip_icon
);
3695 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3700 clip
->lclip_button_pushed
= 0;
3701 clip
->rclip_button_pushed
= 0;
3703 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3705 if (direction
== CLIP_FORWARD
) {
3706 if (scr
->current_workspace
< scr
->workspace_count
- 1)
3707 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3708 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
- 1)
3709 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3710 else if (wPreferences
.ws_cycle
)
3711 wWorkspaceChange(scr
, 0);
3712 } else if (direction
== CLIP_REWIND
) {
3713 if (scr
->current_workspace
> 0)
3714 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
3715 else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
)
3716 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
3719 wClipIconPaint(scr
->clip_icon
);
3722 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3724 WAppIcon
*aicon
= desc
->parent
;
3725 WDock
*dock
= aicon
->dock
;
3726 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3728 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3731 scr
->last_dock
= dock
;
3733 if (dock
->menu
->flags
.mapped
)
3734 wMenuUnmap(dock
->menu
);
3736 if (IsDoubleClick(scr
, event
)) {
3737 /* double-click was not in the main clip icon */
3738 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3739 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3740 iconDblClick(desc
, event
);
3745 if (event
->xbutton
.button
== Button1
) {
3746 if (event
->xbutton
.state
& MOD_MASK
)
3751 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
&& dock
->type
!= WM_DOCK
) {
3752 wIconSelect(aicon
->icon
);
3756 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3757 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
3758 && dock
->type
== WM_CLIP
)
3759 handleClipChangeWorkspace(scr
, event
);
3761 handleDockMove(dock
, aicon
, event
);
3763 Bool hasMoved
= handleIconMove(dock
, aicon
, event
);
3764 if (wPreferences
.single_click
&& !hasMoved
)
3765 iconDblClick(desc
, event
);
3767 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&& aicon
== scr
->clip_icon
) {
3768 if (!scr
->clip_ws_menu
) {
3769 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3771 if (scr
->clip_ws_menu
) {
3772 WMenu
*wsMenu
= scr
->clip_ws_menu
;
3775 wWorkspaceMenuUpdate(scr
, wsMenu
);
3777 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
3780 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
3781 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
3783 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
3785 desc
= &wsMenu
->menu
->descriptor
;
3786 event
->xany
.send_event
= True
;
3787 (*desc
->handle_mousedown
) (desc
, event
);
3789 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
3790 (event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
) {
3791 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3792 } else if (event
->xbutton
.button
== Button3
) {
3793 if (event
->xbutton
.send_event
&&
3794 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3795 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3796 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3797 wwarning("pointer grab failed for dockicon menu");
3801 openDockMenu(dock
, aicon
, event
);
3802 } else if (event
->xbutton
.button
== Button2
) {
3803 WAppIcon
*btn
= desc
->parent
;
3805 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3806 launchDockedApplication(btn
, True
);
3811 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3813 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3817 assert(event
->type
== EnterNotify
);
3819 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3822 scr
= btn
->icon
->core
->screen_ptr
;
3823 if (!btn
->omnipresent
)
3826 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3828 if (!dock
|| dock
->type
!= WM_CLIP
)
3831 /* The auto raise/lower code */
3832 if (dock
->auto_lower_magic
) {
3833 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3834 dock
->auto_lower_magic
= NULL
;
3836 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
3837 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
, clipAutoRaise
, (void *)dock
);
3840 /* The auto expand/collapse code */
3841 if (dock
->auto_collapse_magic
) {
3842 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3843 dock
->auto_collapse_magic
= NULL
;
3845 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
3846 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
, clipAutoExpand
, (void *)dock
);
3850 static void clipLeave(WDock
*dock
)
3853 WObjDescriptor
*desc
= NULL
;
3855 if (!dock
|| dock
->type
!= WM_CLIP
)
3858 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
3859 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3860 (XPointer
*) & desc
) != XCNOENT
3861 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
3862 && ((WAppIcon
*) desc
->parent
)->dock
&& ((WAppIcon
*) desc
->parent
)->dock
->type
== WM_CLIP
) {
3863 /* We didn't left the Clip yet */
3864 XPutBackEvent(dpy
, &event
);
3868 XPutBackEvent(dpy
, &event
);
3870 /* We entered a withdrawn window, so we're still in Clip */
3874 if (dock
->auto_raise_magic
) {
3875 WMDeleteTimerHandler(dock
->auto_raise_magic
);
3876 dock
->auto_raise_magic
= NULL
;
3878 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
3879 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
, clipAutoLower
, (void *)dock
);
3882 if (dock
->auto_expand_magic
) {
3883 WMDeleteTimerHandler(dock
->auto_expand_magic
);
3884 dock
->auto_expand_magic
= NULL
;
3886 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
3887 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
, clipAutoCollapse
, (void *)dock
);
3891 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
3893 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3895 assert(event
->type
== LeaveNotify
);
3897 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3900 clipLeave(btn
->dock
);
3903 static void clipAutoCollapse(void *cdata
)
3905 WDock
*dock
= (WDock
*) cdata
;
3907 if (dock
->type
!= WM_CLIP
)
3910 if (dock
->auto_collapse
) {
3911 dock
->collapsed
= 1;
3912 wDockHideIcons(dock
);
3914 dock
->auto_collapse_magic
= NULL
;
3917 static void clipAutoExpand(void *cdata
)
3919 WDock
*dock
= (WDock
*) cdata
;
3921 if (dock
->type
!= WM_CLIP
)
3924 if (dock
->auto_collapse
) {
3925 dock
->collapsed
= 0;
3926 wDockShowIcons(dock
);
3928 dock
->auto_expand_magic
= NULL
;
3931 static void clipAutoLower(void *cdata
)
3933 WDock
*dock
= (WDock
*) cdata
;
3935 if (dock
->type
!= WM_CLIP
)
3938 if (dock
->auto_raise_lower
)
3941 dock
->auto_lower_magic
= NULL
;
3944 static void clipAutoRaise(void *cdata
)
3946 WDock
*dock
= (WDock
*) cdata
;
3948 if (dock
->type
!= WM_CLIP
)
3951 if (dock
->auto_raise_lower
)
3954 dock
->auto_raise_magic
= NULL
;
3957 static Bool
iconCanBeOmnipresent(WAppIcon
*aicon
)
3959 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3964 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3965 clip
= scr
->workspaces
[i
]->clip
;
3967 if (clip
== aicon
->dock
)
3970 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
3971 return False
; /* Clip is full in some workspace */
3973 for (j
= 0; j
< clip
->max_icons
; j
++) {
3974 btn
= clip
->icon_array
[j
];
3975 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
3983 int wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
3985 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3986 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
3987 int status
= WO_SUCCESS
;
3989 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== scr
->clip_icon
) {
3990 return WO_NOT_APPLICABLE
;
3993 if (aicon
->omnipresent
== omnipresent
)
3997 if (iconCanBeOmnipresent(aicon
)) {
3998 aicon
->omnipresent
= 1;
3999 new_entry
= wmalloc(sizeof(WAppIconChain
));
4000 new_entry
->aicon
= aicon
;
4001 new_entry
->next
= scr
->global_icons
;
4002 scr
->global_icons
= new_entry
;
4003 scr
->global_icon_count
++;
4005 aicon
->omnipresent
= 0;
4009 aicon
->omnipresent
= 0;
4010 if (aicon
== scr
->global_icons
->aicon
) {
4011 tmp
= scr
->global_icons
->next
;
4012 wfree(scr
->global_icons
);
4013 scr
->global_icons
= tmp
;
4014 scr
->global_icon_count
--;
4016 tmp
= scr
->global_icons
;
4018 if (tmp
->next
->aicon
== aicon
) {
4019 tmp1
= tmp
->next
->next
;
4022 scr
->global_icon_count
--;
4030 wAppIconPaint(aicon
);