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
));
1061 dock
->max_icons
= DOCK_MAX_ICONS
;
1063 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * dock
->max_icons
);
1065 btn
= mainIconCreate(scr
, type
);
1069 dock
->x_pos
= btn
->x_pos
;
1070 dock
->y_pos
= btn
->y_pos
;
1071 dock
->screen_ptr
= scr
;
1073 dock
->icon_count
= 1;
1074 dock
->on_right_side
= 1;
1075 dock
->collapsed
= 0;
1076 dock
->auto_collapse
= 0;
1077 dock
->auto_collapse_magic
= NULL
;
1078 dock
->auto_raise_lower
= 0;
1079 dock
->auto_lower_magic
= NULL
;
1080 dock
->auto_raise_magic
= NULL
;
1081 dock
->attract_icons
= 0;
1083 dock
->icon_array
[0] = btn
;
1084 wRaiseFrame(btn
->icon
->core
);
1085 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1087 /* create dock menu */
1088 dock
->menu
= dockMenuCreate(scr
, type
);
1093 void wDockDestroy(WDock
*dock
)
1098 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1099 aicon
= dock
->icon_array
[i
];
1101 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1102 wDockDetach(dock
, aicon
);
1104 /* XXX: can: aicon->icon == NULL ? */
1105 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1106 wGetHeadForWindow(aicon
->icon
->owner
));
1107 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1108 if (!dock
->mapped
|| dock
->collapsed
)
1109 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1113 if (wPreferences
.auto_arrange_icons
)
1114 wArrangeIcons(dock
->screen_ptr
, True
);
1115 wfree(dock
->icon_array
);
1116 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1117 wMenuDestroy(dock
->menu
, True
);
1118 if (dock
->screen_ptr
->last_dock
== dock
)
1119 dock
->screen_ptr
->last_dock
= NULL
;
1123 void wClipIconPaint(WAppIcon
*aicon
)
1125 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1126 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1128 Window win
= aicon
->icon
->core
->window
;
1129 int length
, nlength
;
1130 char *ws_name
, ws_number
[10];
1133 wIconPaint(aicon
->icon
);
1135 length
= strlen(workspace
->name
);
1136 ws_name
= wmalloc(length
+ 1);
1137 snprintf(ws_name
, length
+ 1, "%s", workspace
->name
);
1138 snprintf(ws_number
, sizeof(ws_number
), "%i", scr
->current_workspace
+ 1);
1139 nlength
= strlen(ws_number
);
1141 if (!workspace
->clip
->collapsed
)
1142 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1144 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1146 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1148 tx
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
1150 if(wPreferences
.show_clip_title
)
1151 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, ty
, ws_name
, length
);
1153 tx
= (ICON_SIZE
/ 2 - WMWidthOfString(scr
->clip_title_font
, ws_number
, nlength
)) / 2;
1155 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, 2, ws_number
, nlength
);
1159 if (aicon
->launching
) {
1160 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1161 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1163 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
, aicon
->dock
->rclip_button_pushed
);
1166 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1168 wClipIconPaint(desc
->parent
);
1171 static void dockIconPaint(WAppIcon
*btn
)
1173 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1174 wClipIconPaint(btn
);
1181 static WMPropList
*make_icon_state(WAppIcon
*btn
)
1183 WMPropList
*node
= NULL
;
1184 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
;
1185 WMPropList
*position
, *buggy
, *omnipresent
;
1191 command
= WMCreatePLString("-");
1193 command
= WMCreatePLString(btn
->command
);
1195 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1197 lock
= btn
->lock
? dYes
: dNo
;
1199 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1201 name
= WMCreatePLString(tmp
);
1205 forced
= btn
->forced_dock
? dYes
: dNo
;
1207 buggy
= btn
->buggy_app
? dYes
: dNo
;
1209 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1210 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1212 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1213 position
= WMCreatePLString(buffer
);
1215 node
= WMCreatePLDictionary(dCommand
, command
,
1217 dAutoLaunch
, autolaunch
,
1219 dForced
, forced
, dBuggyApplication
, buggy
, dPosition
, position
, NULL
);
1220 WMReleasePropList(command
);
1221 WMReleasePropList(name
);
1222 WMReleasePropList(position
);
1224 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1225 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&& (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1226 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1228 #ifdef XDND /* was OFFIX */
1229 if (btn
->dnd_command
) {
1230 command
= WMCreatePLString(btn
->dnd_command
);
1231 WMPutInPLDictionary(node
, dDropCommand
, command
);
1232 WMReleasePropList(command
);
1236 if (btn
->paste_command
) {
1237 command
= WMCreatePLString(btn
->paste_command
);
1238 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1239 WMReleasePropList(command
);
1246 static WMPropList
*dockSaveState(WDock
*dock
)
1249 WMPropList
*icon_info
;
1250 WMPropList
*list
= NULL
, *dock_state
= NULL
;
1251 WMPropList
*value
, *key
;
1254 list
= WMCreatePLArray(NULL
);
1256 for (i
= (dock
->type
== WM_DOCK
? 0 : 1); i
< dock
->max_icons
; i
++) {
1257 WAppIcon
*btn
= dock
->icon_array
[i
];
1259 if (!btn
|| btn
->attracted
)
1262 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1263 WMAddToPLArray(list
, icon_info
);
1264 WMReleasePropList(icon_info
);
1268 dock_state
= WMCreatePLDictionary(dApplications
, list
, NULL
);
1270 if (dock
->type
== WM_DOCK
) {
1271 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1272 key
= WMCreatePLString(buffer
);
1273 WMPutInPLDictionary(dock_state
, key
, list
);
1274 WMReleasePropList(key
);
1276 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0), dock
->y_pos
);
1277 value
= WMCreatePLString(buffer
);
1278 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1279 WMReleasePropList(value
);
1281 WMReleasePropList(list
);
1283 value
= (dock
->lowered
? dYes
: dNo
);
1284 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1286 if (dock
->type
== WM_CLIP
) {
1287 value
= (dock
->collapsed
? dYes
: dNo
);
1288 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1290 value
= (dock
->auto_collapse
? dYes
: dNo
);
1291 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1293 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1294 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1296 value
= (dock
->attract_icons
? dYes
: dNo
);
1297 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1303 void wDockSaveState(WScreen
*scr
, WMPropList
*old_state
)
1305 WMPropList
*dock_state
;
1308 dock_state
= dockSaveState(scr
->dock
);
1311 * Copy saved states of docks with different sizes.
1317 keys
= WMGetPLDictionaryKeys(old_state
);
1318 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1319 tmp
= WMGetFromPLArray(keys
, i
);
1321 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1322 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1324 WMPutInPLDictionary(dock_state
, tmp
, WMGetFromPLDictionary(old_state
, tmp
));
1327 WMReleasePropList(keys
);
1330 WMPutInPLDictionary(scr
->session_state
, dDock
, dock_state
);
1332 WMReleasePropList(dock_state
);
1335 void wClipSaveState(WScreen
*scr
)
1337 WMPropList
*clip_state
;
1339 clip_state
= make_icon_state(scr
->clip_icon
);
1341 WMPutInPLDictionary(scr
->session_state
, dClip
, clip_state
);
1343 WMReleasePropList(clip_state
);
1346 WMPropList
*wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1348 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1351 static Bool
getBooleanDockValue(WMPropList
*value
, WMPropList
*key
)
1354 if (WMIsPLString(value
)) {
1355 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1358 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1364 static WAppIcon
*restore_icon_state(WScreen
*scr
, WMPropList
*info
, int type
, int index
)
1367 WMPropList
*cmd
, *value
;
1369 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1370 if (!cmd
|| !WMIsPLString(cmd
)) {
1374 /* parse window name */
1375 value
= WMGetFromPLDictionary(info
, dName
);
1380 char *wclass
, *winstance
;
1383 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1385 if (!winstance
&& !wclass
) {
1392 command
= wstrdup(WMGetFromPLString(cmd
));
1396 if (!command
|| strcmp(command
, "-") == 0) {
1407 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1416 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1417 if (type
== WM_CLIP
) {
1418 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1419 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1421 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1422 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1424 #ifdef XDND /* was OFFIX */
1425 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1427 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1430 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1432 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1434 /* check auto launch */
1435 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1437 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1440 value
= WMGetFromPLDictionary(info
, dLock
);
1442 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1444 /* check if it wasn't normally docked */
1445 value
= WMGetFromPLDictionary(info
, dForced
);
1447 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1449 /* check if we can rely on the stuff in the app */
1450 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1452 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1454 /* get position in the dock */
1455 value
= WMGetFromPLDictionary(info
, dPosition
);
1456 if (value
&& WMIsPLString(value
)) {
1457 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1458 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1460 /* check position sanity */
1461 /* incomplete section! */
1462 if (type
== WM_DOCK
) {
1464 if (aicon
->yindex
< 0)
1465 wwarning(_("bad value in docked icon position %i,%i"),
1466 aicon
->xindex
, aicon
->yindex
);
1469 aicon
->yindex
= index
;
1473 /* check if icon is omnipresent */
1474 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1476 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1484 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1486 WAppIcon
*wClipRestoreState(WScreen
*scr
, WMPropList
*clip_state
)
1491 icon
= mainIconCreate(scr
, WM_CLIP
);
1496 WMRetainPropList(clip_state
);
1498 /* restore position */
1500 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1503 if (!WMIsPLString(value
))
1504 COMPLAIN("Position");
1509 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1510 COMPLAIN("Position");
1512 /* check position sanity */
1513 rect
.pos
.x
= icon
->x_pos
;
1514 rect
.pos
.y
= icon
->y_pos
;
1515 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1517 wGetRectPlacementInfo(scr
, rect
, &flags
);
1518 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
1519 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1522 #ifdef XDND /* was OFFIX */
1523 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1524 if (value
&& WMIsPLString(value
))
1525 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1528 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1529 if (value
&& WMIsPLString(value
))
1530 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1532 WMReleasePropList(clip_state
);
1537 WDock
*wDockRestoreState(WScreen
*scr
, WMPropList
*dock_state
, int type
)
1542 WAppIcon
*aicon
, *old_top
;
1545 dock
= wDockCreate(scr
, type
);
1550 WMRetainPropList(dock_state
);
1552 /* restore position */
1553 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1555 if (!WMIsPLString(value
)) {
1556 COMPLAIN("Position");
1561 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1562 COMPLAIN("Position");
1564 /* check position sanity */
1565 rect
.pos
.x
= dock
->x_pos
;
1566 rect
.pos
.y
= dock
->y_pos
;
1567 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1569 wGetRectPlacementInfo(scr
, rect
, &flags
);
1570 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
)) {
1571 int x
= dock
->x_pos
;
1572 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1575 /* Is this needed any more? */
1576 if (type
== WM_CLIP
) {
1577 if (dock
->x_pos
< 0) {
1579 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1580 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1583 if (dock
->x_pos
>= 0) {
1584 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1585 dock
->on_right_side
= 0;
1587 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1588 dock
->on_right_side
= 1;
1594 /* restore lowered/raised state */
1597 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1599 if (!WMIsPLString(value
)) {
1600 COMPLAIN("Lowered");
1602 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1608 /* restore collapsed state */
1609 dock
->collapsed
= 0;
1611 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1613 if (!WMIsPLString(value
)) {
1614 COMPLAIN("Collapsed");
1616 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1617 dock
->collapsed
= 1;
1622 /* restore auto-collapsed state */
1623 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1625 if (!WMIsPLString(value
)) {
1626 COMPLAIN("AutoCollapse");
1628 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1629 dock
->auto_collapse
= 1;
1630 dock
->collapsed
= 1;
1635 /* restore auto-raise/lower state */
1636 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1638 if (!WMIsPLString(value
)) {
1639 COMPLAIN("AutoRaiseLower");
1641 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1642 dock
->auto_raise_lower
= 1;
1646 /* restore attract icons state */
1647 dock
->attract_icons
= 0;
1649 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1651 if (!WMIsPLString(value
)) {
1652 COMPLAIN("AutoAttractIcons");
1654 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1655 dock
->attract_icons
= 1;
1659 /* application list */
1666 * When saving, it saves the dock state in
1667 * Applications and Applicationsnnn
1669 * When loading, it will first try Applicationsnnn.
1670 * If it does not exist, use Applications as default.
1673 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1675 tmp
= WMCreatePLString(buffer
);
1676 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1677 WMReleasePropList(tmp
);
1680 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1686 count
= WMGetPropListItemCount(apps
);
1690 old_top
= dock
->icon_array
[0];
1692 /* dock->icon_count is set to 1 when dock is created.
1693 * Since Clip is already restored, we want to keep it so for clip,
1694 * but for dock we may change the default top tile, so we set it to 0.
1696 if (type
== WM_DOCK
)
1697 dock
->icon_count
= 0;
1699 for (i
= 0; i
< count
; i
++) {
1700 if (dock
->icon_count
>= dock
->max_icons
) {
1701 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1705 value
= WMGetFromPLArray(apps
, i
);
1706 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1708 dock
->icon_array
[dock
->icon_count
] = aicon
;
1712 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1713 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1716 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1718 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1720 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1722 if (!dock
->collapsed
)
1723 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1724 wRaiseFrame(aicon
->icon
->core
);
1727 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
)
1731 /* if the first icon is not defined, use the default */
1732 if (dock
->icon_array
[0] == NULL
) {
1733 /* update default icon */
1734 old_top
->x_pos
= dock
->x_pos
;
1735 old_top
->y_pos
= dock
->y_pos
;
1737 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1739 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1740 dock
->icon_array
[0] = old_top
;
1741 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1742 /* we don't need to increment dock->icon_count here because it was
1743 * incremented in the loop above.
1745 } else if (old_top
!= dock
->icon_array
[0]) {
1746 if (old_top
== scr
->clip_icon
)
1747 scr
->clip_icon
= dock
->icon_array
[0];
1748 wAppIconDestroy(old_top
);
1752 WMReleasePropList(dock_state
);
1757 void wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1759 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1761 btn
->drop_launch
= 0;
1762 btn
->paste_launch
= 0;
1764 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1767 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1777 void wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1783 for (i
= 0; i
< dock
->max_icons
; i
++) {
1784 btn
= dock
->icon_array
[i
];
1785 if (!btn
|| !btn
->auto_launch
)
1788 state
= wmalloc(sizeof(WSavedState
));
1789 state
->workspace
= workspace
;
1790 /* TODO: this is klugy and is very difficult to understand
1791 * what's going on. Try to clean up */
1792 wDockLaunchWithState(dock
, btn
, state
);
1796 #ifdef XDND /* was OFFIX */
1797 static WDock
*findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1803 if ((dock
= scr
->dock
) != NULL
) {
1804 for (i
= 0; i
< dock
->max_icons
; i
++) {
1805 if (dock
->icon_array
[i
]
1806 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1812 if (*icon_pos
< 0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
) != 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
) {
1826 int wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
1832 dock
= findDock(scr
, event
, &icon_pos
);
1837 * Return True if the drop was on an application icon window.
1838 * In this case, let the ClientMessage handler redirect the
1839 * message to the app.
1841 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
1844 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
1845 scr
->flags
.dnd_data_convertion_status
= 0;
1847 btn
= dock
->icon_array
[icon_pos
];
1849 if (!btn
->forced_dock
) {
1850 btn
->relaunching
= btn
->running
;
1853 if (btn
->wm_instance
|| btn
->wm_class
) {
1854 WWindowAttributes attr
;
1855 memset(&attr
, 0, sizeof(WWindowAttributes
));
1856 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
1857 btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
1859 if (!attr
.no_appicon
)
1865 btn
->paste_launch
= 0;
1866 btn
->drop_launch
= 1;
1867 scr
->last_dock
= dock
;
1868 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1873 if (!btn
->relaunching
) {
1882 Bool
wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1887 wwin
= icon
->icon
->owner
;
1888 if (icon
->command
== NULL
) {
1893 command
= GetCommandForWindow(wwin
->client_win
);
1895 icon
->command
= command
;
1897 /* icon->forced_dock = 1; */
1898 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
1900 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
1901 _("Type the command used to launch the application"), &command
)) {
1902 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
1906 icon
->command
= command
;
1912 /* If the target is the dock, reject the icon. If
1913 * the target is the clip, make it an attracted icon
1915 if (dock
->type
== WM_CLIP
) {
1916 icon
->attracted
= 1;
1917 if (!icon
->icon
->shadowed
) {
1918 icon
->icon
->shadowed
= 1;
1919 icon
->icon
->force_paint
= 1;
1931 for (index
= 1; index
< dock
->max_icons
; index
++)
1932 if (dock
->icon_array
[index
] == NULL
)
1934 /* if (index == dock->max_icons)
1937 assert(index
< dock
->max_icons
);
1939 dock
->icon_array
[index
] = icon
;
1943 icon
->omnipresent
= 0;
1945 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
1946 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
1951 icon
->launching
= 0;
1954 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1955 if (dock
->type
== WM_CLIP
) {
1956 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1957 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1959 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1960 icon
->icon
->core
->descriptor
.parent
= icon
;
1962 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
1963 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
1964 wAppIconPaint(icon
);
1967 if (wPreferences
.auto_arrange_icons
)
1968 wArrangeIcons(dock
->screen_ptr
, True
);
1970 #ifdef XDND /* was OFFIX */
1971 if (icon
->command
&& !icon
->dnd_command
) {
1972 int len
= strlen(icon
->command
) + 8;
1973 icon
->dnd_command
= wmalloc(len
);
1974 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
1978 if (icon
->command
&& !icon
->paste_command
) {
1979 int len
= strlen(icon
->command
) + 8;
1980 icon
->paste_command
= wmalloc(len
);
1981 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
1987 static void reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1991 for (index
= 1; index
< dock
->max_icons
; index
++) {
1992 if (dock
->icon_array
[index
] == icon
)
1995 assert(index
< dock
->max_icons
);
2000 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2001 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2004 static Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2011 return True
; /* No move needed, we're already there */
2016 wwin
= icon
->icon
->owner
;
2019 * For the moment we can't do this if we move icons in Clip from one
2020 * workspace to other, because if we move two or more icons without
2021 * command, the dialog box will not be able to tell us to which of the
2022 * moved icons it applies. -Dan
2024 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
2025 command
= GetCommandForWindow(wwin
->client_win
);
2027 icon
->command
= command
;
2030 /* icon->forced_dock = 1; */
2031 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2032 _("Type the command used to launch the application"), &command
)) {
2033 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2037 icon
->command
= command
;
2048 if (dest
->type
== WM_DOCK
)
2049 wClipMakeIconOmnipresent(icon
, False
);
2051 for (index
= 1; index
< src
->max_icons
; index
++) {
2052 if (src
->icon_array
[index
] == icon
)
2055 assert(index
< src
->max_icons
);
2057 src
->icon_array
[index
] = NULL
;
2060 for (index
= 1; index
< dest
->max_icons
; index
++) {
2061 if (dest
->icon_array
[index
] == NULL
)
2064 /* if (index == dest->max_icons)
2067 assert(index
< dest
->max_icons
);
2069 dest
->icon_array
[index
] = icon
;
2072 /* deselect the icon */
2073 if (icon
->icon
->selected
)
2074 wIconSelect(icon
->icon
);
2076 if (dest
->type
== WM_DOCK
) {
2077 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2078 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2080 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2081 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2084 /* set it to be kept when moving to dock.
2085 * Unless the icon does not have a command set
2087 if (icon
->command
&& dest
->type
== WM_DOCK
) {
2088 icon
->attracted
= 0;
2089 if (icon
->icon
->shadowed
) {
2090 icon
->icon
->shadowed
= 0;
2091 icon
->icon
->force_paint
= 1;
2096 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2102 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2103 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2107 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2108 wAppIconPaint(icon
);
2113 void wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2117 /* make the settings panel be closed */
2119 DestroyDockAppSettingsPanel(icon
->panel
);
2122 /* This must be called before icon->dock is set to NULL.
2123 * Don't move it. -Dan
2125 wClipMakeIconOmnipresent(icon
, False
);
2129 icon
->attracted
= 0;
2130 icon
->auto_launch
= 0;
2131 if (icon
->icon
->shadowed
) {
2132 icon
->icon
->shadowed
= 0;
2133 icon
->icon
->force_paint
= 1;
2136 /* deselect the icon */
2137 if (icon
->icon
->selected
)
2138 wIconSelect(icon
->icon
);
2140 if (icon
->command
) {
2141 wfree(icon
->command
);
2142 icon
->command
= NULL
;
2144 #ifdef XDND /* was OFFIX */
2145 if (icon
->dnd_command
) {
2146 wfree(icon
->dnd_command
);
2147 icon
->dnd_command
= NULL
;
2150 if (icon
->paste_command
) {
2151 wfree(icon
->paste_command
);
2152 icon
->paste_command
= NULL
;
2155 for (index
= 1; index
< dock
->max_icons
; index
++)
2156 if (dock
->icon_array
[index
] == icon
)
2158 assert(index
< dock
->max_icons
);
2159 dock
->icon_array
[index
] = NULL
;
2165 /* if the dock is not attached to an application or
2166 * the application did not set the appropriate hints yet,
2167 * destroy the icon */
2168 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2169 wAppIconDestroy(icon
);
2171 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2172 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2173 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2174 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2175 icon
->icon
->core
->descriptor
.parent
= icon
;
2177 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2179 wAppIconPaint(icon
);
2180 if (wPreferences
.auto_arrange_icons
) {
2181 wArrangeIcons(dock
->screen_ptr
, True
);
2184 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2189 * returns the closest Dock slot index for the passed
2192 * Returns False if icon can't be docked.
2194 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2197 Bool
wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2199 WScreen
*scr
= dock
->screen_ptr
;
2202 int i
, offset
= ICON_SIZE
/ 2;
2203 WAppIcon
*aicon
= NULL
;
2204 WAppIcon
*nicon
= NULL
;
2207 /* TODO: XINERAMA, for these */
2208 max_y_icons
= scr
->scr_height
/ ICON_SIZE
- 1;
2210 if (wPreferences
.flags
.noupdates
)
2216 /* if the dock is full */
2217 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
)) {
2221 /* exact position */
2223 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2225 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2228 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2230 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2232 /* check if the icon is outside the screen boundaries */
2237 rect
.pos
.x
= dx
+ ex_x
* ICON_SIZE
;
2238 rect
.pos
.y
= dy
+ ex_y
* ICON_SIZE
;
2239 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2241 wGetRectPlacementInfo(scr
, rect
, &flags
);
2242 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
2246 if (dock
->type
== WM_DOCK
) {
2247 if (icon
->dock
!= dock
&& ex_x
!= 0)
2251 for (i
= 0; i
< dock
->max_icons
; i
++) {
2252 nicon
= dock
->icon_array
[i
];
2253 if (nicon
&& nicon
->yindex
== ex_y
) {
2260 int sig
, done
, closest
;
2262 /* Possible cases when redocking:
2264 * icon dragged out of range of any slot -> false
2265 * icon dragged to range of free slot
2266 * icon dragged to range of same slot
2267 * icon dragged to range of different icon
2269 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2272 if (ex_y
>= 0 && ex_y
<= max_y_icons
&& (aicon
== icon
|| !aicon
)) {
2278 /* start looking at the upper slot or lower? */
2279 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2286 /* look for closest free slot */
2287 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2291 closest
= sig
* (i
/ 2) + ex_y
;
2292 /* check if this slot is used */
2294 for (j
= 0; j
< dock
->max_icons
; j
++) {
2295 if (dock
->icon_array
[j
]
2296 && dock
->icon_array
[j
]->yindex
== closest
) {
2297 /* slot is used by someone else */
2298 if (dock
->icon_array
[j
] != icon
)
2306 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2307 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2308 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2313 } else { /* !redocking */
2315 /* if slot is free and the icon is close enough, return it */
2316 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2326 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2327 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+ 1;
2330 for (k
= start
; k
< stop
; k
++) {
2331 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2334 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2335 nicon
= tmp
->icon_array
[i
];
2336 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2344 for (k
= start
; k
< stop
; k
++) {
2345 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2348 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2349 nicon
= tmp
->icon_array
[i
];
2350 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2351 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2352 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2361 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2370 static int onScreen(WScreen
*scr
, int x
, int y
, int sx
, int ex
, int sy
, int ey
)
2372 WMRect rect
= wmkrect(x
, y
, ICON_SIZE
, ICON_SIZE
);
2375 wGetRectPlacementInfo(scr
, rect
, &flags
);
2377 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2381 * returns true if it can find a free slot in the dock,
2382 * in which case it changes x_pos and y_pos accordingly.
2383 * Else returns false.
2385 Bool
wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2387 WScreen
*scr
= dock
->screen_ptr
;
2389 WAppIconChain
*chain
;
2390 unsigned char *slot_map
;
2394 int i
, done
= False
;
2396 int sx
= 0, sy
= 0, ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2397 int extra_count
= 0;
2399 if (dock
->type
== WM_CLIP
&& dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2400 extra_count
= scr
->global_icon_count
;
2402 /* if the dock is full */
2403 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
) {
2407 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2408 if (scr
->dock
->on_right_side
)
2409 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2411 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2414 if (ex
< dock
->x_pos
)
2416 if (sx
> dock
->x_pos
+ ICON_SIZE
)
2417 sx
= dock
->x_pos
+ ICON_SIZE
;
2424 /* check if clip is in a corner */
2425 if (dock
->type
== WM_CLIP
) {
2426 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2428 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2430 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2432 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2439 /* If the clip is in the corner, use only slots that are in the border
2441 if (corner
!= C_NONE
) {
2445 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2446 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2447 hmap
= wmalloc(hcount
+ 1);
2448 vmap
= wmalloc(vcount
+ 1);
2450 /* mark used positions */
2453 for (i
= 0; i
< dock
->max_icons
; i
++) {
2454 btn
= dock
->icon_array
[i
];
2458 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2459 vmap
[btn
->yindex
] = 1;
2460 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2461 hmap
[btn
->xindex
] = 1;
2463 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2465 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2466 vmap
[btn
->yindex
] = 1;
2467 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2468 hmap
[btn
->xindex
] = 1;
2472 for (i
= 0; i
< dock
->max_icons
; i
++) {
2473 btn
= dock
->icon_array
[i
];
2477 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2478 vmap
[btn
->yindex
] = 1;
2479 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2480 hmap
[-btn
->xindex
] = 1;
2482 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2484 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2485 vmap
[btn
->yindex
] = 1;
2486 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2487 hmap
[-btn
->xindex
] = 1;
2491 for (i
= 0; i
< dock
->max_icons
; i
++) {
2492 btn
= dock
->icon_array
[i
];
2496 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2497 vmap
[-btn
->yindex
] = 1;
2498 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2499 hmap
[btn
->xindex
] = 1;
2501 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2503 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2504 vmap
[-btn
->yindex
] = 1;
2505 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2506 hmap
[btn
->xindex
] = 1;
2511 for (i
= 0; i
< dock
->max_icons
; i
++) {
2512 btn
= dock
->icon_array
[i
];
2516 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2517 vmap
[-btn
->yindex
] = 1;
2518 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2519 hmap
[-btn
->xindex
] = 1;
2521 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2523 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2524 vmap
[-btn
->yindex
] = 1;
2525 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2526 hmap
[-btn
->xindex
] = 1;
2532 /* search a vacant slot */
2533 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2534 if (i
< vcount
&& vmap
[i
] == 0) {
2540 } else if (i
< hcount
&& hmap
[i
] == 0) {
2550 /* If found a slot, translate and return */
2552 if (corner
== C_NW
|| corner
== C_NE
) {
2557 if (corner
== C_NE
|| corner
== C_SE
) {
2564 /* else, try to find a slot somewhere else */
2567 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2568 * placed outside of screen */
2569 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2571 /* In the worst case (the clip is in the corner of the screen),
2572 * the amount of icons that fit in the clip is smaller.
2573 * Double the map to get a safe value.
2577 r
= (mwidth
- 1) / 2;
2579 slot_map
= wmalloc(mwidth
* mwidth
);
2581 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2583 /* mark used slots in the map. If the slot falls outside the map
2584 * (for example, when all icons are placed in line), ignore them. */
2585 for (i
= 0; i
< dock
->max_icons
; i
++) {
2586 btn
= dock
->icon_array
[i
];
2588 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2590 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2591 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2593 /* Find closest slot from the center that is free by scanning the
2594 * map from the center to outward in circular passes.
2595 * This will not result in a neat layout, but will be optimal
2596 * in the sense that there will not be holes left.
2599 for (i
= 1; i
<= r
&& !done
; i
++) {
2602 /* top and bottom parts of the ring */
2603 for (x
= -i
; x
<= i
&& !done
; x
++) {
2604 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2606 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2607 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2614 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2615 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2622 /* left and right parts of the ring */
2623 for (y
= -i
+ 1; y
<= i
- 1; y
++) {
2624 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2626 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2627 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2634 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2635 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2648 static void moveDock(WDock
*dock
, int new_x
, int new_y
)
2653 dock
->x_pos
= new_x
;
2654 dock
->y_pos
= new_y
;
2655 for (i
= 0; i
< dock
->max_icons
; i
++) {
2656 btn
= dock
->icon_array
[i
];
2658 btn
->x_pos
= new_x
+ btn
->xindex
* ICON_SIZE
;
2659 btn
->y_pos
= new_y
+ btn
->yindex
* ICON_SIZE
;
2660 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2665 static void swapDock(WDock
*dock
)
2667 WScreen
*scr
= dock
->screen_ptr
;
2671 if (dock
->on_right_side
) {
2672 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2674 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2677 for (i
= 0; i
< dock
->max_icons
; i
++) {
2678 btn
= dock
->icon_array
[i
];
2681 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2685 wScreenUpdateUsableArea(scr
);
2688 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2690 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2696 cmdline
= ExpandOptions(scr
, command
);
2698 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2706 wtokensplit(cmdline
, &argv
, &argc
);
2716 if ((pid
= fork()) == 0) {
2720 SetupEnvironment(scr
);
2726 args
= malloc(sizeof(char *) * (argc
+ 1));
2729 for (i
= 0; i
< argc
; i
++) {
2733 execvp(argv
[0], args
);
2736 wtokenfree(argv
, argc
);
2740 state
= wmalloc(sizeof(WSavedState
));
2742 state
->miniaturized
= -1;
2744 if (btn
->dock
== scr
->dock
|| btn
->omnipresent
)
2745 state
->workspace
= -1;
2747 state
->workspace
= scr
->current_workspace
;
2749 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
2750 wAddDeathHandler(pid
, (WDeathHandler
*) trackDeadProcess
, btn
->dock
);
2758 void wDockHideIcons(WDock
*dock
)
2765 for (i
= 1; i
< dock
->max_icons
; i
++) {
2766 if (dock
->icon_array
[i
])
2767 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2771 dockIconPaint(dock
->icon_array
[0]);
2774 void wDockShowIcons(WDock
*dock
)
2782 btn
= dock
->icon_array
[0];
2783 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2785 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2786 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2788 for (i
= 1; i
< dock
->max_icons
; i
++) {
2789 if (dock
->icon_array
[i
]) {
2790 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
, btn
->icon
->core
);
2795 if (!dock
->collapsed
) {
2796 for (i
= 1; i
< dock
->max_icons
; i
++) {
2797 if (dock
->icon_array
[i
]) {
2798 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2807 void wDockLower(WDock
*dock
)
2811 for (i
= 0; i
< dock
->max_icons
; i
++) {
2812 if (dock
->icon_array
[i
])
2813 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2817 void wDockRaise(WDock
*dock
)
2821 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
2822 if (dock
->icon_array
[i
])
2823 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2827 void wDockRaiseLower(WDock
*dock
)
2829 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2830 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2831 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2837 void wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
2839 icon
->launching
= 0;
2840 icon
->relaunching
= 0;
2841 dockIconPaint(icon
);
2844 WAppIcon
*wDockFindIconForWindow(WDock
*dock
, Window window
)
2849 for (i
= 0; i
< dock
->max_icons
; i
++) {
2850 icon
= dock
->icon_array
[i
];
2851 if (icon
&& icon
->main_window
== window
)
2857 void wDockTrackWindowLaunch(WDock
*dock
, Window window
)
2860 char *wm_class
, *wm_instance
;
2862 Bool firstPass
= True
;
2864 char *command
= NULL
;
2866 command
= GetCommandForWindow(window
);
2868 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) || (!wm_class
&& !wm_instance
)) {
2876 for (i
= 0; i
< dock
->max_icons
; i
++) {
2877 icon
= dock
->icon_array
[i
];
2881 /* app is already attached to icon */
2882 if (icon
->main_window
== window
) {
2887 if ((icon
->wm_instance
|| icon
->wm_class
)
2888 && (icon
->launching
|| !icon
->running
)) {
2890 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0) {
2893 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0) {
2896 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0) {
2900 if (!icon
->relaunching
) {
2903 /* Possibly an application that was docked with dockit,
2904 * but the user did not update WMState to indicate that
2905 * it was docked by force */
2906 wapp
= wApplicationOf(window
);
2908 icon
->forced_dock
= 1;
2911 if (!icon
->forced_dock
) {
2912 icon
->main_window
= window
;
2916 if (!wPreferences
.no_animations
&& !icon
->launching
&&
2917 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
2921 icon
->launching
= 1;
2922 dockIconPaint(icon
);
2924 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
2925 wm_instance
, wm_class
, TILE_NORMAL
);
2926 /* XXX: can: aicon->icon == NULL ? */
2927 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
2928 wAppIconMove(aicon
, x0
, y0
);
2929 /* Should this always be lowered? -Dan */
2931 wLowerFrame(aicon
->icon
->core
);
2932 XMapWindow(dpy
, aicon
->icon
->core
->window
);
2933 aicon
->launching
= 1;
2934 wAppIconPaint(aicon
);
2935 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
2936 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
2937 wAppIconDestroy(aicon
);
2939 wDockFinishLaunch(dock
, icon
);
2944 if (firstPass
&& !found
) {
2958 void wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
2960 if (!wPreferences
.flags
.noclip
) {
2961 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
2962 if (scr
->current_workspace
!= workspace
) {
2963 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
2964 WAppIconChain
*chain
= scr
->global_icons
;
2967 moveIconBetweenDocks(chain
->aicon
->dock
,
2968 scr
->workspaces
[workspace
]->clip
,
2969 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
2970 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
2971 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
2972 chain
= chain
->next
;
2975 wDockHideIcons(old_clip
);
2976 if (old_clip
->auto_raise_lower
) {
2977 if (old_clip
->auto_raise_magic
) {
2978 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
2979 old_clip
->auto_raise_magic
= NULL
;
2981 wDockLower(old_clip
);
2983 if (old_clip
->auto_collapse
) {
2984 if (old_clip
->auto_expand_magic
) {
2985 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
2986 old_clip
->auto_expand_magic
= NULL
;
2988 old_clip
->collapsed
= 1;
2990 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
2995 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3000 for (i
= 0; i
< dock
->max_icons
; i
++) {
3001 icon
= dock
->icon_array
[i
];
3005 if (icon
->launching
&& icon
->pid
== pid
) {
3006 if (!icon
->relaunching
) {
3008 icon
->main_window
= None
;
3010 wDockFinishLaunch(dock
, icon
);
3012 if (status
== 111) {
3017 if (icon
->drop_launch
)
3018 cmd
= icon
->dnd_command
;
3021 if (icon
->paste_launch
)
3022 cmd
= icon
->paste_command
;
3024 cmd
= icon
->command
;
3026 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3028 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3035 static void toggleLowered(WDock
*dock
)
3040 /* lower/raise Dock */
3041 if (!dock
->lowered
) {
3042 newlevel
= WMNormalLevel
;
3045 newlevel
= WMDockLevel
;
3049 for (i
= 0; i
< dock
->max_icons
; i
++) {
3050 tmp
= dock
->icon_array
[i
];
3054 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3056 wLowerFrame(tmp
->icon
->core
);
3059 if (dock
->type
== WM_DOCK
)
3060 wScreenUpdateUsableArea(dock
->screen_ptr
);
3063 static void toggleCollapsed(WDock
*dock
)
3065 if (dock
->collapsed
) {
3066 dock
->collapsed
= 0;
3067 wDockShowIcons(dock
);
3069 dock
->collapsed
= 1;
3070 wDockHideIcons(dock
);
3074 static void openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3076 WScreen
*scr
= dock
->screen_ptr
;
3077 WObjDescriptor
*desc
;
3079 WApplication
*wapp
= NULL
;
3083 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3085 if (dock
->type
== WM_DOCK
) {
3087 entry
= dock
->menu
->entries
[index
];
3088 entry
->flags
.indicator_on
= !dock
->lowered
;
3089 entry
->clientdata
= dock
;
3090 dock
->menu
->flags
.realized
= 0;
3093 if (scr
->clip_options
)
3094 updateClipOptionsMenu(scr
->clip_options
, dock
);
3096 n_selected
= numberOfSelectedIcons(dock
);
3098 /* Rename Workspace */
3099 entry
= dock
->menu
->entries
[++index
];
3100 if (aicon
== scr
->clip_icon
) {
3101 entry
->callback
= renameCallback
;
3102 entry
->clientdata
= dock
;
3103 entry
->flags
.indicator
= 0;
3104 entry
->text
= _("Rename Workspace");
3106 entry
->callback
= omnipresentCallback
;
3107 entry
->clientdata
= aicon
;
3108 if (n_selected
> 0) {
3109 entry
->flags
.indicator
= 0;
3110 entry
->text
= _("Toggle Omnipresent");
3112 entry
->flags
.indicator
= 1;
3113 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3114 entry
->flags
.indicator_type
= MI_CHECK
;
3115 entry
->text
= _("Omnipresent");
3119 /* select/unselect icon */
3120 entry
= dock
->menu
->entries
[++index
];
3121 entry
->clientdata
= aicon
;
3122 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3123 wMenuSetEnabled(dock
->menu
, index
, aicon
!= scr
->clip_icon
);
3125 /* select/unselect all icons */
3126 entry
= dock
->menu
->entries
[++index
];
3127 entry
->clientdata
= aicon
;
3129 entry
->text
= _("Unselect All Icons");
3131 entry
->text
= _("Select All Icons");
3132 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3135 entry
= dock
->menu
->entries
[++index
];
3136 entry
->clientdata
= aicon
;
3138 entry
->text
= _("Keep Icons");
3140 entry
->text
= _("Keep Icon");
3141 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3143 /* this is the workspace submenu part */
3144 entry
= dock
->menu
->entries
[++index
];
3146 entry
->text
= _("Move Icons To");
3148 entry
->text
= _("Move Icon To");
3149 if (scr
->clip_submenu
)
3150 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3151 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3153 /* remove icon(s) */
3154 entry
= dock
->menu
->entries
[++index
];
3155 entry
->clientdata
= aicon
;
3157 entry
->text
= _("Remove Icons");
3159 entry
->text
= _("Remove Icon");
3160 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3162 /* attract icon(s) */
3163 entry
= dock
->menu
->entries
[++index
];
3164 entry
->clientdata
= aicon
;
3166 dock
->menu
->flags
.realized
= 0;
3167 wMenuRealize(dock
->menu
);
3170 if (aicon
->icon
->owner
) {
3171 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3177 entry
= dock
->menu
->entries
[++index
];
3178 entry
->clientdata
= aicon
;
3179 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3182 entry
= dock
->menu
->entries
[++index
];
3183 entry
->clientdata
= aicon
;
3184 if (wapp
&& wapp
->flags
.hidden
) {
3185 entry
->text
= _("Unhide Here");
3187 entry
->text
= _("Bring Here");
3189 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3192 entry
= dock
->menu
->entries
[++index
];
3193 entry
->clientdata
= aicon
;
3194 if (wapp
&& wapp
->flags
.hidden
) {
3195 entry
->text
= _("Unhide");
3197 entry
->text
= _("Hide");
3199 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3202 entry
= dock
->menu
->entries
[++index
];
3203 entry
->clientdata
= aicon
;
3204 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3207 entry
= dock
->menu
->entries
[++index
];
3208 entry
->clientdata
= aicon
;
3209 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3211 if (!dock
->menu
->flags
.realized
)
3212 wMenuRealize(dock
->menu
);
3214 if (dock
->type
== WM_CLIP
) {
3215 /*x_pos = event->xbutton.x_root+2; */
3216 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3219 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3220 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3223 x_pos
= dock
->on_right_side
? scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3226 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3228 /* allow drag select */
3229 event
->xany
.send_event
= True
;
3230 desc
= &dock
->menu
->menu
->descriptor
;
3231 (*desc
->handle_mousedown
) (desc
, event
);
3234 /******************************************************************/
3235 static void iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3237 WAppIcon
*btn
= desc
->parent
;
3238 WDock
*dock
= btn
->dock
;
3239 WApplication
*wapp
= NULL
;
3242 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3243 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3245 assert(wapp
!= NULL
);
3247 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3249 /* go to the last workspace that the user worked on the app */
3250 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
&& !unhideHere
) {
3251 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3254 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3256 if (event
->xbutton
.state
& MOD_MASK
) {
3257 wHideOtherApplications(btn
->icon
->owner
);
3260 if (event
->xbutton
.button
== Button1
) {
3262 if (event
->xbutton
.state
& MOD_MASK
) {
3263 /* raise/lower dock */
3264 toggleLowered(dock
);
3265 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3266 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
)
3267 toggleCollapsed(dock
);
3269 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3270 } else if (btn
->command
) {
3271 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3272 launchDockedApplication(btn
, False
);
3278 static void handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3280 WScreen
*scr
= dock
->screen_ptr
;
3281 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3284 int grabbed
= 0, swapped
= 0, done
;
3285 Pixmap ghost
= None
;
3286 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3288 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3289 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3290 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3291 wwarning("pointer grab failed for dock move");
3294 for (x
= 0; x
< dock
->max_icons
; x
++) {
3295 if (dock
->icon_array
[x
] != NULL
&& dock
->icon_array
[x
]->yindex
> y
)
3296 y
= dock
->icon_array
[x
]->yindex
;
3299 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
* y
);
3303 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3304 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3311 /* It means the cursor moved so fast that it entered
3312 * something else (if moving slowly, it would have
3313 * stayed in the dock that is being moved. Ignore such
3314 * "spurious" EnterNotifiy's */
3319 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3320 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3321 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3322 | ButtonReleaseMask
| ButtonPressMask
,
3323 wCursor
[WCUR_MOVE
], CurrentTime
);
3328 if (dock
->type
== WM_CLIP
) {
3329 x
= ev
.xmotion
.x_root
- ofs_x
;
3330 y
= ev
.xmotion
.y_root
- ofs_y
;
3331 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3333 moveDock(dock
, x
, y
);
3335 /* move vertically if pointer is inside the dock */
3336 if ((dock
->on_right_side
&& ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3337 || (!dock
->on_right_side
&& ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
* 2)) {
3339 x
= ev
.xmotion
.x_root
- ofs_x
;
3340 y
= ev
.xmotion
.y_root
- ofs_y
;
3341 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3342 moveDock(dock
, dock
->x_pos
, y
);
3344 /* move horizontally to change sides */
3345 x
= ev
.xmotion
.x_root
- ofs_x
;
3346 if (!dock
->on_right_side
) {
3350 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
* 2) {
3351 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
- ICON_SIZE
3352 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3353 if (superfluous
&& ghost
== None
) {
3354 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3355 scr
->scr_width
- ICON_SIZE
3356 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3357 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3358 XClearWindow(dpy
, scr
->dock_shadow
);
3360 XMapRaised(dpy
, scr
->dock_shadow
);
3363 if (superfluous
&& ghost
!= None
) {
3364 XFreePixmap(dpy
, ghost
);
3367 XUnmapWindow(dpy
, scr
->dock_shadow
);
3372 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3373 XMoveWindow(dpy
, scr
->dock_shadow
, DOCK_EXTRA_SPACE
, dock
->y_pos
);
3374 if (superfluous
&& ghost
== None
) {
3375 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3376 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3377 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3378 XClearWindow(dpy
, scr
->dock_shadow
);
3380 XMapRaised(dpy
, scr
->dock_shadow
);
3383 XUnmapWindow(dpy
, scr
->dock_shadow
);
3385 if (superfluous
&& ghost
!= None
) {
3386 XFreePixmap(dpy
, ghost
);
3398 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3400 XUngrabPointer(dpy
, CurrentTime
);
3401 XUnmapWindow(dpy
, scr
->dock_shadow
);
3402 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3403 if (dock
->type
== WM_DOCK
) {
3406 dock
->on_right_side
= 1;
3408 dock
->on_right_side
= 0;
3410 wArrangeIcons(scr
, False
);
3419 XFreePixmap(dpy
, ghost
);
3420 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3424 static Bool
handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3426 WScreen
*scr
= dock
->screen_ptr
;
3428 WIcon
*icon
= aicon
->icon
;
3429 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3430 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3432 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3433 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3434 int shad_x
= x
, shad_y
= y
;
3435 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3437 Pixmap ghost
= None
;
3439 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3440 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3441 Bool hasMoved
= False
;
3443 if (wPreferences
.flags
.noupdates
)
3446 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3447 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3448 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3451 if (!(event
->xbutton
.state
& MOD_MASK
))
3452 wRaiseFrame(icon
->core
);
3454 if (!wPreferences
.flags
.noclip
)
3455 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3457 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3459 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3462 wins
[0] = icon
->core
->window
;
3463 wins
[1] = scr
->dock_shadow
;
3464 XRestackWindows(dpy
, wins
, 2);
3465 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
3467 if (icon
->pixmap
!= None
)
3468 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3470 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3472 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3473 XClearWindow(dpy
, scr
->dock_shadow
);
3475 XMapWindow(dpy
, scr
->dock_shadow
);
3480 XMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3481 | ButtonMotionMask
| ExposureMask
, &ev
);
3490 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3491 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3492 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3493 | ButtonReleaseMask
| ButtonPressMask
,
3494 wCursor
[WCUR_MOVE
], CurrentTime
);
3503 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3504 if (i
== scr
->current_workspace
)
3506 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3510 x
= ev
.xmotion
.x_root
- ofs_x
;
3511 y
= ev
.xmotion
.y_root
- ofs_y
;
3512 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3515 if (last_dock
!= dock
&& collapsed
) {
3516 last_dock
->collapsed
= 1;
3517 wDockHideIcons(last_dock
);
3520 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3521 dock
->collapsed
= 0;
3522 wDockShowIcons(dock
);
3524 if (dock
->auto_raise_lower
)
3528 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3531 if (last_dock
!= dock2
&& collapsed
) {
3532 last_dock
->collapsed
= 1;
3533 wDockHideIcons(last_dock
);
3536 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3537 dock2
->collapsed
= 0;
3538 wDockShowIcons(dock2
);
3540 if (dock2
->auto_raise_lower
)
3545 if (aicon
->launching
|| aicon
->lock
|| (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3546 || (!aicon
->running
&& tmp
)) {
3547 shad_x
= last_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3548 shad_y
= last_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3550 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3553 XMapWindow(dpy
, scr
->dock_shadow
);
3558 XUnmapWindow(dpy
, scr
->dock_shadow
);
3562 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3569 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3571 XUngrabPointer(dpy
, CurrentTime
);
3573 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3574 XUnmapWindow(dpy
, scr
->dock_shadow
);
3576 reattachIcon(dock
, aicon
, ix
, iy
);
3577 if (clip
&& dock
!= clip
&& clip
->auto_raise_lower
)
3580 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3582 /* Slide it back if dock rejected it */
3583 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
, aicon
->y_pos
);
3584 reattachIcon(dock
, aicon
, aicon
->xindex
, aicon
->yindex
);
3586 if (last_dock
->type
== WM_CLIP
&& last_dock
->auto_collapse
) {
3594 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3595 /* We need to deselect it, even if is deselected in
3596 * wDockDetach(), because else DoKaboom() will fail.
3598 if (aicon
->icon
->selected
)
3599 wIconSelect(aicon
->icon
);
3601 DoKaboom(scr
, aicon
->icon
->core
->window
, x
, y
);
3604 if (clip
&& clip
->auto_raise_lower
)
3606 wDockDetach(dock
, aicon
);
3609 last_dock
->collapsed
= 1;
3610 wDockHideIcons(last_dock
);
3615 XFreePixmap(dpy
, ghost
);
3616 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3620 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3621 if (i
== scr
->current_workspace
)
3623 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3629 return False
; /* never reached */
3632 static int getClipButton(int px
, int py
)
3634 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3636 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3639 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3640 return CLIP_FORWARD
;
3641 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3647 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3650 int done
, direction
, new_ws
;
3652 WDock
*clip
= scr
->clip_icon
->dock
;
3654 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3656 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3657 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3659 wClipIconPaint(scr
->clip_icon
);
3662 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3669 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3670 if (new_dir
!= direction
) {
3671 direction
= new_dir
;
3672 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3673 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3674 wClipIconPaint(scr
->clip_icon
);
3682 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3687 clip
->lclip_button_pushed
= 0;
3688 clip
->rclip_button_pushed
= 0;
3690 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3692 if (direction
== CLIP_FORWARD
) {
3693 if (scr
->current_workspace
< scr
->workspace_count
- 1)
3694 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3695 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
- 1)
3696 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3697 else if (wPreferences
.ws_cycle
)
3698 wWorkspaceChange(scr
, 0);
3699 } else if (direction
== CLIP_REWIND
) {
3700 if (scr
->current_workspace
> 0)
3701 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
3702 else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
)
3703 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
3706 wClipIconPaint(scr
->clip_icon
);
3709 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3711 WAppIcon
*aicon
= desc
->parent
;
3712 WDock
*dock
= aicon
->dock
;
3713 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3715 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3718 scr
->last_dock
= dock
;
3720 if (dock
->menu
->flags
.mapped
)
3721 wMenuUnmap(dock
->menu
);
3723 if (IsDoubleClick(scr
, event
)) {
3724 /* double-click was not in the main clip icon */
3725 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3726 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3727 iconDblClick(desc
, event
);
3732 if (event
->xbutton
.button
== Button1
) {
3733 if (event
->xbutton
.state
& MOD_MASK
)
3738 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
&& dock
->type
!= WM_DOCK
) {
3739 wIconSelect(aicon
->icon
);
3743 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3744 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
3745 && dock
->type
== WM_CLIP
)
3746 handleClipChangeWorkspace(scr
, event
);
3748 handleDockMove(dock
, aicon
, event
);
3750 Bool hasMoved
= handleIconMove(dock
, aicon
, event
);
3751 if (wPreferences
.single_click
&& !hasMoved
)
3752 iconDblClick(desc
, event
);
3754 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&& aicon
== scr
->clip_icon
) {
3755 if (!scr
->clip_ws_menu
) {
3756 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3758 if (scr
->clip_ws_menu
) {
3759 WMenu
*wsMenu
= scr
->clip_ws_menu
;
3762 wWorkspaceMenuUpdate(scr
, wsMenu
);
3764 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
3767 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
3768 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
3770 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
3772 desc
= &wsMenu
->menu
->descriptor
;
3773 event
->xany
.send_event
= True
;
3774 (*desc
->handle_mousedown
) (desc
, event
);
3776 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
3777 (event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
) {
3778 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3779 } else if (event
->xbutton
.button
== Button3
) {
3780 if (event
->xbutton
.send_event
&&
3781 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3782 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3783 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3784 wwarning("pointer grab failed for dockicon menu");
3788 openDockMenu(dock
, aicon
, event
);
3789 } else if (event
->xbutton
.button
== Button2
) {
3790 WAppIcon
*btn
= desc
->parent
;
3792 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3793 launchDockedApplication(btn
, True
);
3798 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3800 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3804 assert(event
->type
== EnterNotify
);
3806 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3809 scr
= btn
->icon
->core
->screen_ptr
;
3810 if (!btn
->omnipresent
)
3813 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3815 if (!dock
|| dock
->type
!= WM_CLIP
)
3818 /* The auto raise/lower code */
3819 if (dock
->auto_lower_magic
) {
3820 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3821 dock
->auto_lower_magic
= NULL
;
3823 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
3824 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
, clipAutoRaise
, (void *)dock
);
3827 /* The auto expand/collapse code */
3828 if (dock
->auto_collapse_magic
) {
3829 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3830 dock
->auto_collapse_magic
= NULL
;
3832 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
3833 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
, clipAutoExpand
, (void *)dock
);
3837 static void clipLeave(WDock
*dock
)
3840 WObjDescriptor
*desc
= NULL
;
3842 if (!dock
|| dock
->type
!= WM_CLIP
)
3845 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
3846 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3847 (XPointer
*) & desc
) != XCNOENT
3848 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
3849 && ((WAppIcon
*) desc
->parent
)->dock
&& ((WAppIcon
*) desc
->parent
)->dock
->type
== WM_CLIP
) {
3850 /* We didn't left the Clip yet */
3851 XPutBackEvent(dpy
, &event
);
3855 XPutBackEvent(dpy
, &event
);
3857 /* We entered a withdrawn window, so we're still in Clip */
3861 if (dock
->auto_raise_magic
) {
3862 WMDeleteTimerHandler(dock
->auto_raise_magic
);
3863 dock
->auto_raise_magic
= NULL
;
3865 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
3866 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
, clipAutoLower
, (void *)dock
);
3869 if (dock
->auto_expand_magic
) {
3870 WMDeleteTimerHandler(dock
->auto_expand_magic
);
3871 dock
->auto_expand_magic
= NULL
;
3873 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
3874 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
, clipAutoCollapse
, (void *)dock
);
3878 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
3880 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3882 assert(event
->type
== LeaveNotify
);
3884 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3887 clipLeave(btn
->dock
);
3890 static void clipAutoCollapse(void *cdata
)
3892 WDock
*dock
= (WDock
*) cdata
;
3894 if (dock
->type
!= WM_CLIP
)
3897 if (dock
->auto_collapse
) {
3898 dock
->collapsed
= 1;
3899 wDockHideIcons(dock
);
3901 dock
->auto_collapse_magic
= NULL
;
3904 static void clipAutoExpand(void *cdata
)
3906 WDock
*dock
= (WDock
*) cdata
;
3908 if (dock
->type
!= WM_CLIP
)
3911 if (dock
->auto_collapse
) {
3912 dock
->collapsed
= 0;
3913 wDockShowIcons(dock
);
3915 dock
->auto_expand_magic
= NULL
;
3918 static void clipAutoLower(void *cdata
)
3920 WDock
*dock
= (WDock
*) cdata
;
3922 if (dock
->type
!= WM_CLIP
)
3925 if (dock
->auto_raise_lower
)
3928 dock
->auto_lower_magic
= NULL
;
3931 static void clipAutoRaise(void *cdata
)
3933 WDock
*dock
= (WDock
*) cdata
;
3935 if (dock
->type
!= WM_CLIP
)
3938 if (dock
->auto_raise_lower
)
3941 dock
->auto_raise_magic
= NULL
;
3944 static Bool
iconCanBeOmnipresent(WAppIcon
*aicon
)
3946 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3951 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3952 clip
= scr
->workspaces
[i
]->clip
;
3954 if (clip
== aicon
->dock
)
3957 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
3958 return False
; /* Clip is full in some workspace */
3960 for (j
= 0; j
< clip
->max_icons
; j
++) {
3961 btn
= clip
->icon_array
[j
];
3962 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
3970 int wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
3972 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3973 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
3974 int status
= WO_SUCCESS
;
3976 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== scr
->clip_icon
) {
3977 return WO_NOT_APPLICABLE
;
3980 if (aicon
->omnipresent
== omnipresent
)
3984 if (iconCanBeOmnipresent(aicon
)) {
3985 aicon
->omnipresent
= 1;
3986 new_entry
= wmalloc(sizeof(WAppIconChain
));
3987 new_entry
->aicon
= aicon
;
3988 new_entry
->next
= scr
->global_icons
;
3989 scr
->global_icons
= new_entry
;
3990 scr
->global_icon_count
++;
3992 aicon
->omnipresent
= 0;
3996 aicon
->omnipresent
= 0;
3997 if (aicon
== scr
->global_icons
->aicon
) {
3998 tmp
= scr
->global_icons
->next
;
3999 wfree(scr
->global_icons
);
4000 scr
->global_icons
= tmp
;
4001 scr
->global_icon_count
--;
4003 tmp
= scr
->global_icons
;
4005 if (tmp
->next
->aicon
== aicon
) {
4006 tmp1
= tmp
->next
->next
;
4009 scr
->global_icon_count
--;
4017 wAppIconPaint(aicon
);