1 /* dock.c- built-in Dock module for WindowMaker
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <X11/Xutil.h>
35 #define PATH_MAX DEFAULT_PATH_MAX
38 #include "WindowMaker.h"
48 #include "properties.h"
52 #include "workspace.h"
54 #include "superfluous.h"
57 /**** Local variables ****/
60 #define CLIP_FORWARD 2
62 /**** Global variables ****/
65 extern void DestroyDockAppSettingsPanel();
66 extern void ShowDockAppSettingsPanel(WAppIcon
* aicon
);
67 extern Cursor wCursor
[WCUR_LAST
];
68 extern WPreferences wPreferences
;
69 extern XContext wWinContext
;
70 extern void appIconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
72 #define MOD_MASK wPreferences.modifier_mask
73 #define ICON_SIZE wPreferences.icon_size
75 /***** Local variables ****/
77 static WMPropList
*dCommand
= NULL
;
78 static WMPropList
*dPasteCommand
= NULL
;
79 #ifdef XDND /* XXX was OFFIX */
80 static WMPropList
*dDropCommand
= NULL
;
82 static WMPropList
*dAutoLaunch
, *dLock
;
83 static WMPropList
*dName
, *dForced
, *dBuggyApplication
, *dYes
, *dNo
;
84 static WMPropList
*dHost
, *dDock
, *dClip
;
85 static WMPropList
*dAutoAttractIcons
;
87 static WMPropList
*dPosition
, *dApplications
, *dLowered
, *dCollapsed
;
89 static WMPropList
*dAutoCollapse
, *dAutoRaiseLower
, *dOmnipresent
;
91 static void dockIconPaint(WAppIcon
*btn
);
93 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
95 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
);
97 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
99 static int getClipButton(int px
, int py
);
101 static void toggleLowered(WDock
*dock
);
103 static void toggleCollapsed(WDock
*dock
);
105 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
107 static void clipLeave(WDock
*dock
);
109 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
111 static Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
);
113 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
114 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
115 static void clipAutoCollapse(void *cdata
);
116 static void clipAutoExpand(void *cdata
);
117 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
);
119 static void clipAutoLower(void *cdata
);
120 static void clipAutoRaise(void *cdata
);
121 static void reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
);
122 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
);
124 static void make_keys(void)
126 if (dCommand
!= NULL
)
129 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
130 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
132 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
134 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
135 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
136 dName
= WMRetainPropList(WMCreatePLString("Name"));
137 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
138 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
139 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
140 dNo
= WMRetainPropList(WMCreatePLString("No"));
141 dHost
= WMRetainPropList(WMCreatePLString("Host"));
143 dPosition
= WMCreatePLString("Position");
144 dApplications
= WMCreatePLString("Applications");
145 dLowered
= WMCreatePLString("Lowered");
146 dCollapsed
= WMCreatePLString("Collapsed");
147 dAutoCollapse
= WMCreatePLString("AutoCollapse");
148 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
149 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
151 dOmnipresent
= WMCreatePLString("Omnipresent");
153 dDock
= WMCreatePLString("Dock");
154 dClip
= WMCreatePLString("Clip");
157 static void renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
159 WDock
*dock
= entry
->clientdata
;
164 assert(entry
->clientdata
!= NULL
);
166 wspace
= dock
->screen_ptr
->current_workspace
;
168 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
170 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+ 1);
171 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
, &name
)) {
172 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
179 static void toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
181 assert(entry
->clientdata
!= NULL
);
183 toggleLowered(entry
->clientdata
);
185 entry
->flags
.indicator_on
= !(((WDock
*) entry
->clientdata
)->lowered
);
190 static int matchWindow(const void *item
, const void *cdata
)
192 return (((WFakeGroupLeader
*) item
)->leader
== (Window
) cdata
);
195 static void killCallback(WMenu
*menu
, WMenuEntry
*entry
)
197 WScreen
*scr
= menu
->menu
->screen_ptr
;
199 WFakeGroupLeader
*fPtr
;
200 char *buffer
, *shortname
, **argv
;
201 char *basename(const char *shortname
);
204 if (!WCHECK_STATE(WSTATE_NORMAL
))
207 assert(entry
->clientdata
!= NULL
);
209 icon
= (WAppIcon
*) entry
->clientdata
;
213 WCHANGE_STATE(WSTATE_MODAL
);
215 /* strip away dir names */
216 shortname
= basename(icon
->command
);
217 /* separate out command options */
218 wtokensplit(shortname
, &argv
, &argc
);
220 buffer
= wstrconcat(argv
[0],
221 _(" will be forcibly closed.\n"
222 "Any unsaved changes will be lost.\n" "Please confirm."));
224 if (icon
->icon
&& icon
->icon
->owner
) {
225 fPtr
= icon
->icon
->owner
->fake_group
;
227 /* is this really necessary? can we kill a non-running dock icon? */
228 Window win
= icon
->main_window
;
231 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)win
);
232 if (index
!= WANotFound
)
233 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
238 if (wPreferences
.dont_confirm_kill
239 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
240 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
242 WWindow
*wwin
, *twin
;
244 wwin
= scr
->focused_window
;
247 if (wwin
->fake_group
== fPtr
) {
252 } else if (icon
->icon
&& icon
->icon
->owner
) {
253 wClientKill(icon
->icon
->owner
);
258 wtokenfree(argv
, argc
);
262 WCHANGE_STATE(WSTATE_NORMAL
);
265 /* TODO: replace this function with a member of the dock struct */
266 static int numberOfSelectedIcons(WDock
*dock
)
272 for (i
= 1; i
< dock
->max_icons
; i
++) {
273 aicon
= dock
->icon_array
[i
];
274 if (aicon
&& aicon
->icon
->selected
) {
282 static WMArray
*getSelected(WDock
*dock
)
284 WMArray
*ret
= WMCreateArray(8);
288 for (i
= 1; i
< dock
->max_icons
; i
++) {
289 btn
= dock
->icon_array
[i
];
290 if (btn
&& btn
->icon
->selected
) {
291 WMAddToArray(ret
, btn
);
298 static void paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
300 Window win
= clipIcon
->icon
->core
->window
;
301 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
303 int pt
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
304 int tp
= ICON_SIZE
- pt
;
305 int as
= pt
- 15; /* 15 = 5+5+5 */
306 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
309 color
= scr
->clip_title_color
[CLIP_NORMAL
];
311 XSetForeground(dpy
, gc
, WMColorPixel(color
));
316 p
[1].x
= ICON_SIZE
- 2;
318 p
[2].x
= ICON_SIZE
- 2;
320 } else if (lpushed
) {
324 p
[1].y
= ICON_SIZE
- 2;
326 p
[2].y
= ICON_SIZE
- 2;
328 if (lpushed
|| rpushed
) {
329 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
330 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
331 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
334 /* top right arrow */
335 p
[0].x
= p
[3].x
= ICON_SIZE
- 5 - as
;
337 p
[1].x
= ICON_SIZE
- 6;
339 p
[2].x
= ICON_SIZE
- 6;
342 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
343 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
345 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
346 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
349 /* bottom left arrow */
351 p
[0].y
= p
[3].y
= ICON_SIZE
- 5 - as
;
353 p
[1].y
= ICON_SIZE
- 6;
355 p
[2].y
= ICON_SIZE
- 6;
357 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
358 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
360 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
361 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
365 RImage
*wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
367 RImage
*tile
= RCloneImage(normalTile
);
374 pt
= CLIP_BUTTON_SIZE
* wPreferences
.icon_size
/ 64;
375 tp
= wPreferences
.icon_size
- 1 - pt
;
379 black
.red
= black
.green
= black
.blue
= 0;
382 dark
.red
= dark
.green
= dark
.blue
= 60;
385 light
.red
= light
.green
= light
.blue
= 80;
388 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
- 2, pt
- 1, &dark
);
389 RDrawLine(tile
, tp
- 1, 0, wPreferences
.icon_size
- 1, pt
+ 1, &black
);
390 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
- 3, pt
, &light
);
393 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, 4, &dark
);
394 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 5, 6 + as
, &dark
);
395 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
, &light
);
398 ROperateLine(tile
, RAddOperation
, 2, tp
+ 2, pt
- 2, wPreferences
.icon_size
- 3, &dark
);
399 RDrawLine(tile
, 0, tp
- 1, pt
+ 1, wPreferences
.icon_size
- 1, &black
);
400 ROperateLine(tile
, RSubtractOperation
, 0, tp
- 2, pt
+ 1, wPreferences
.icon_size
- 2, &light
);
403 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, &dark
);
404 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
, 6 + as
, ICON_SIZE
- 5, &dark
);
405 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5, &light
);
410 static void omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
412 WAppIcon
*clickedIcon
= entry
->clientdata
;
415 WMArray
*selectedIcons
;
416 WMArrayIterator iter
;
419 assert(entry
->clientdata
!= NULL
);
421 dock
= clickedIcon
->dock
;
423 selectedIcons
= getSelected(dock
);
425 if (!WMGetArrayItemCount(selectedIcons
))
426 WMAddToArray(selectedIcons
, clickedIcon
);
429 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
430 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
432 else if (aicon
->icon
->selected
)
433 wIconSelect(aicon
->icon
);
435 WMFreeArray(selectedIcons
);
438 wMessageDialog(dock
->screen_ptr
, _("Warning"),
439 _("Some icons cannot be made omnipresent. "
440 "Please make sure that no other icon is "
441 "docked in the same positions on the other "
442 "workspaces and the Clip is not full in "
443 "some workspace."), _("OK"), NULL
, NULL
);
444 } else if (failed
== 1) {
445 wMessageDialog(dock
->screen_ptr
, _("Warning"),
446 _("Icon cannot be made omnipresent. "
447 "Please make sure that no other icon is "
448 "docked in the same position on the other "
449 "workspaces and the Clip is not full in "
450 "some workspace."), _("OK"), NULL
, NULL
);
454 static void removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
456 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
459 WMArray
*selectedIcons
;
463 assert(clickedIcon
!= NULL
);
465 dock
= clickedIcon
->dock
;
467 selectedIcons
= getSelected(dock
);
469 if (WMGetArrayItemCount(selectedIcons
)) {
470 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
471 _("All selected icons will be removed!"),
472 _("OK"), _("Cancel"), NULL
) != WAPRDefault
) {
473 WMFreeArray(selectedIcons
);
477 if (clickedIcon
->xindex
== 0 && clickedIcon
->yindex
== 0) {
478 WMFreeArray(selectedIcons
);
481 WMAddToArray(selectedIcons
, clickedIcon
);
484 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
485 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
486 wDockDetach(dock
, aicon
);
488 /* XXX: can: aicon->icon == NULL ? */
489 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
490 wGetHeadForWindow(aicon
->icon
->owner
));
491 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
492 if (!dock
->mapped
|| dock
->collapsed
)
493 XMapWindow(dpy
, aicon
->icon
->core
->window
);
496 WMFreeArray(selectedIcons
);
498 if (wPreferences
.auto_arrange_icons
)
499 wArrangeIcons(dock
->screen_ptr
, True
);
502 static void keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
504 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
507 WMArray
*selectedIcons
;
510 assert(clickedIcon
!= NULL
);
511 dock
= clickedIcon
->dock
;
513 selectedIcons
= getSelected(dock
);
515 if (!WMGetArrayItemCount(selectedIcons
)
516 && clickedIcon
!= dock
->screen_ptr
->clip_icon
) {
517 char *command
= NULL
;
519 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
520 clickedIcon
->editing
= 1;
521 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
522 _("Type the command used to launch the application"), &command
)) {
523 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
527 clickedIcon
->command
= command
;
528 clickedIcon
->editing
= 0;
530 clickedIcon
->editing
= 0;
533 WMFreeArray(selectedIcons
);
538 WMAddToArray(selectedIcons
, clickedIcon
);
541 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
542 if (aicon
->icon
->selected
)
543 wIconSelect(aicon
->icon
);
544 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
545 aicon
->attracted
= 0;
546 if (aicon
->icon
->shadowed
) {
547 aicon
->icon
->shadowed
= 0;
548 aicon
->icon
->force_paint
= 1;
549 wAppIconPaint(aicon
);
554 WMFreeArray(selectedIcons
);
557 static void toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
559 WDock
*dock
= (WDock
*) entry
->clientdata
;
561 assert(entry
->clientdata
!= NULL
);
563 dock
->attract_icons
= !dock
->attract_icons
;
564 /*if (!dock->attract_icons)
565 dock->keep_attracted = 0; */
567 entry
->flags
.indicator_on
= dock
->attract_icons
;
572 static void selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
574 WAppIcon
*icon
= (WAppIcon
*) entry
->clientdata
;
576 assert(icon
!= NULL
);
578 wIconSelect(icon
->icon
);
583 static void colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
585 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
588 int x
, y
, x_pos
, y_pos
;
590 assert(entry
->clientdata
!= NULL
);
591 clip
= clickedIcon
->dock
;
593 aicon
= clip
->screen_ptr
->app_icon_list
;
596 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
597 x_pos
= clip
->x_pos
+ x
* ICON_SIZE
;
598 y_pos
= clip
->y_pos
+ y
* ICON_SIZE
;
599 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
601 if (wPreferences
.no_animations
) {
602 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
604 SlideWindow(aicon
->icon
->core
->window
,
605 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
608 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
609 #endif /* ANIMATIONS */
611 aicon
->attracted
= 1;
612 if (!aicon
->icon
->shadowed
) {
613 aicon
->icon
->shadowed
= 1;
614 aicon
->icon
->force_paint
= 1;
615 /* We don't do an wAppIconPaint() here because it's in
616 * wDockAttachIcon(). -Dan
619 wDockAttachIcon(clip
, aicon
, x
, y
);
620 if (clip
->collapsed
|| !clip
->mapped
)
621 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
627 static void selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
629 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
631 WMArray
*selectedIcons
;
632 WMArrayIterator iter
;
636 assert(clickedIcon
!= NULL
);
637 dock
= clickedIcon
->dock
;
639 selectedIcons
= getSelected(dock
);
641 if (!WMGetArrayItemCount(selectedIcons
)) {
642 for (i
= 1; i
< dock
->max_icons
; i
++) {
643 btn
= dock
->icon_array
[i
];
644 if (btn
&& !btn
->icon
->selected
) {
645 wIconSelect(btn
->icon
);
649 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
650 wIconSelect(btn
->icon
);
653 WMFreeArray(selectedIcons
);
658 static void toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
660 assert(entry
->clientdata
!= NULL
);
662 toggleCollapsed(entry
->clientdata
);
664 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->collapsed
;
669 static void toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
672 assert(entry
->clientdata
!= NULL
);
674 dock
= (WDock
*) entry
->clientdata
;
676 dock
->auto_collapse
= !dock
->auto_collapse
;
678 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_collapse
;
683 static void toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
686 assert(entry
->clientdata
!= NULL
);
688 dock
= (WDock
*) entry
->clientdata
;
690 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
692 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_raise_lower
;
697 static void launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
699 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
701 launchDockedApplication(btn
, False
);
704 static void settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
706 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
710 ShowDockAppSettingsPanel(btn
);
713 static void hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
716 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
718 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
720 if (wapp
->flags
.hidden
) {
721 wWorkspaceChange(btn
->icon
->core
->screen_ptr
, wapp
->last_workspace
);
722 wUnhideApplication(wapp
, False
, False
);
724 wHideApplication(wapp
);
728 static void unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
731 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
733 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
735 wUnhideApplication(wapp
, False
, True
);
738 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
)
743 if (type
== WM_CLIP
) {
745 return scr
->clip_icon
;
746 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
747 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
748 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
749 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
750 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE; */
753 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
754 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
760 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
761 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
762 btn
->icon
->core
->descriptor
.parent
= btn
;
763 /*ChangeStackingLevel(btn->icon->core, WMDockLevel); */
764 XMapWindow(dpy
, btn
->icon
->core
->window
);
769 scr
->clip_icon
= btn
;
774 static void switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
776 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
777 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
779 WMArray
*selectedIcons
;
782 if (entry
->order
== scr
->current_workspace
)
785 dest
= scr
->workspaces
[entry
->order
]->clip
;
787 selectedIcons
= getSelected(src
);
789 if (WMGetArrayItemCount(selectedIcons
)) {
790 WMArrayIterator iter
;
792 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
793 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
794 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
795 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
798 } else if (icon
!= scr
->clip_icon
) {
799 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
800 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
801 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
804 WMFreeArray(selectedIcons
);
807 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
)
809 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
811 if (!btn
->launching
&&
812 ((!withSelection
&& btn
->command
!= NULL
) || (withSelection
&& btn
->paste_command
!= NULL
))) {
813 if (!btn
->forced_dock
) {
814 btn
->relaunching
= btn
->running
;
817 if (btn
->wm_instance
|| btn
->wm_class
) {
818 WWindowAttributes attr
;
819 memset(&attr
, 0, sizeof(WWindowAttributes
));
820 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
822 if (!attr
.no_appicon
&& !btn
->buggy_app
)
827 btn
->drop_launch
= 0;
828 btn
->paste_launch
= withSelection
;
829 scr
->last_dock
= btn
->dock
;
830 btn
->pid
= execCommand(btn
, (withSelection
? btn
->paste_command
: btn
->command
), NULL
);
832 if (btn
->buggy_app
) {
833 /* give feedback that the app was launched */
837 WMAddTimerHandler(200, (WMCallback
*) dockIconPaint
, btn
);
842 wwarning(_("could not launch application %s"), btn
->command
);
844 if (!btn
->relaunching
) {
851 static void updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
853 WScreen
*scr
= menu
->frame
->screen_ptr
;
854 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
860 for (i
= 0; i
< scr
->workspace_count
; i
++) {
861 if (i
< menu
->entry_no
) {
862 if (strcmp(menu
->entries
[i
]->text
, scr
->workspaces
[i
]->name
) != 0) {
863 wfree(menu
->entries
[i
]->text
);
864 strcpy(title
, scr
->workspaces
[i
]->name
);
865 menu
->entries
[i
]->text
= wstrdup(title
);
866 menu
->flags
.realized
= 0;
868 menu
->entries
[i
]->clientdata
= (void *)icon
;
870 strcpy(title
, scr
->workspaces
[i
]->name
);
872 wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)icon
);
874 menu
->flags
.realized
= 0;
876 if (i
== scr
->current_workspace
) {
877 wMenuSetEnabled(menu
, i
, False
);
879 wMenuSetEnabled(menu
, i
, True
);
883 if (!menu
->flags
.realized
)
887 static WMenu
*makeWorkspaceMenu(WScreen
*scr
)
891 menu
= wMenuCreate(scr
, NULL
, False
);
893 wwarning(_("could not create workspace submenu for Clip menu"));
895 wMenuAddCallback(menu
, "", switchWSCommand
, (void *)scr
->clip_icon
);
897 menu
->flags
.realized
= 0;
903 static void updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
912 entry
= menu
->entries
[index
];
913 entry
->flags
.indicator_on
= !dock
->lowered
;
914 entry
->clientdata
= dock
;
917 entry
= menu
->entries
[++index
];
918 entry
->flags
.indicator_on
= dock
->collapsed
;
919 entry
->clientdata
= dock
;
922 entry
= menu
->entries
[++index
];
923 entry
->flags
.indicator_on
= dock
->auto_collapse
;
924 entry
->clientdata
= dock
;
926 /* auto-raise/lower */
927 entry
= menu
->entries
[++index
];
928 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
929 entry
->clientdata
= dock
;
930 wMenuSetEnabled(menu
, index
, dock
->lowered
);
933 entry
= menu
->entries
[++index
];
934 entry
->flags
.indicator_on
= dock
->attract_icons
;
935 entry
->clientdata
= dock
;
937 menu
->flags
.realized
= 0;
941 static WMenu
*makeClipOptionsMenu(WScreen
*scr
)
946 menu
= wMenuCreate(scr
, NULL
, False
);
948 wwarning(_("could not create options submenu for Clip menu"));
952 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
953 entry
->flags
.indicator
= 1;
954 entry
->flags
.indicator_on
= 1;
955 entry
->flags
.indicator_type
= MI_CHECK
;
957 entry
= wMenuAddCallback(menu
, _("Collapsed"), toggleCollapsedCallback
, NULL
);
958 entry
->flags
.indicator
= 1;
959 entry
->flags
.indicator_on
= 1;
960 entry
->flags
.indicator_type
= MI_CHECK
;
962 entry
= wMenuAddCallback(menu
, _("Autocollapse"), toggleAutoCollapseCallback
, NULL
);
963 entry
->flags
.indicator
= 1;
964 entry
->flags
.indicator_on
= 1;
965 entry
->flags
.indicator_type
= MI_CHECK
;
967 entry
= wMenuAddCallback(menu
, _("Autoraise"), toggleAutoRaiseLowerCallback
, NULL
);
968 entry
->flags
.indicator
= 1;
969 entry
->flags
.indicator_on
= 1;
970 entry
->flags
.indicator_type
= MI_CHECK
;
972 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"), toggleAutoAttractCallback
, NULL
);
973 entry
->flags
.indicator
= 1;
974 entry
->flags
.indicator_on
= 1;
975 entry
->flags
.indicator_type
= MI_CHECK
;
977 menu
->flags
.realized
= 0;
983 static WMenu
*dockMenuCreate(WScreen
*scr
, int type
)
988 if (type
== WM_CLIP
&& scr
->clip_menu
)
989 return scr
->clip_menu
;
991 menu
= wMenuCreate(scr
, NULL
, False
);
992 if (type
!= WM_CLIP
) {
993 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
994 entry
->flags
.indicator
= 1;
995 entry
->flags
.indicator_on
= 1;
996 entry
->flags
.indicator_type
= MI_CHECK
;
998 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
999 scr
->clip_options
= makeClipOptionsMenu(scr
);
1000 if (scr
->clip_options
)
1001 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1003 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1005 entry
->text
= _("Rename Workspace");
1007 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1008 entry
->flags
.indicator
= 1;
1009 entry
->flags
.indicator_on
= 1;
1010 entry
->flags
.indicator_type
= MI_CHECK
;
1012 entry
= wMenuAddCallback(menu
, _("Select All Icons"), selectIconsCallback
, NULL
);
1014 entry
->text
= _("Select All Icons");
1016 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1018 entry
->text
= _("Keep Icon");
1020 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1022 entry
->text
= _("Move Icon To");
1023 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1024 if (scr
->clip_submenu
)
1025 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1027 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
, NULL
);
1029 entry
->text
= _("Remove Icon");
1031 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1034 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1036 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1038 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1040 entry
->text
= _("Hide");
1042 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1044 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1046 if (type
== WM_CLIP
)
1047 scr
->clip_menu
= menu
;
1052 WDock
*wDockCreate(WScreen
*scr
, int type
)
1059 dock
= wmalloc(sizeof(WDock
));
1060 memset(dock
, 0, sizeof(WDock
));
1062 dock
->max_icons
= DOCK_MAX_ICONS
;
1064 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * dock
->max_icons
);
1065 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*) * dock
->max_icons
);
1067 btn
= mainIconCreate(scr
, type
);
1071 dock
->x_pos
= btn
->x_pos
;
1072 dock
->y_pos
= btn
->y_pos
;
1073 dock
->screen_ptr
= scr
;
1075 dock
->icon_count
= 1;
1076 dock
->on_right_side
= 1;
1077 dock
->collapsed
= 0;
1078 dock
->auto_collapse
= 0;
1079 dock
->auto_collapse_magic
= NULL
;
1080 dock
->auto_raise_lower
= 0;
1081 dock
->auto_lower_magic
= NULL
;
1082 dock
->auto_raise_magic
= NULL
;
1083 dock
->attract_icons
= 0;
1085 dock
->icon_array
[0] = btn
;
1086 wRaiseFrame(btn
->icon
->core
);
1087 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1089 /* create dock menu */
1090 dock
->menu
= dockMenuCreate(scr
, type
);
1095 void wDockDestroy(WDock
*dock
)
1100 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1101 aicon
= dock
->icon_array
[i
];
1103 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1104 wDockDetach(dock
, aicon
);
1106 /* XXX: can: aicon->icon == NULL ? */
1107 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1108 wGetHeadForWindow(aicon
->icon
->owner
));
1109 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1110 if (!dock
->mapped
|| dock
->collapsed
)
1111 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1115 if (wPreferences
.auto_arrange_icons
)
1116 wArrangeIcons(dock
->screen_ptr
, True
);
1117 wfree(dock
->icon_array
);
1118 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1119 wMenuDestroy(dock
->menu
, True
);
1120 if (dock
->screen_ptr
->last_dock
== dock
)
1121 dock
->screen_ptr
->last_dock
= NULL
;
1125 void wClipIconPaint(WAppIcon
*aicon
)
1127 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1128 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1130 Window win
= aicon
->icon
->core
->window
;
1131 int length
, nlength
;
1132 char *ws_name
, ws_number
[10];
1135 wIconPaint(aicon
->icon
);
1137 length
= strlen(workspace
->name
);
1138 ws_name
= wmalloc(length
+ 1);
1139 snprintf(ws_name
, length
+ 1, "%s", workspace
->name
);
1140 snprintf(ws_number
, sizeof(ws_number
), "%i", scr
->current_workspace
+ 1);
1141 nlength
= strlen(ws_number
);
1143 if (!workspace
->clip
->collapsed
)
1144 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1146 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1148 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1150 tx
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
1152 if(wPreferences
.show_clip_title
)
1153 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, ty
, ws_name
, length
);
1155 tx
= (ICON_SIZE
/ 2 - WMWidthOfString(scr
->clip_title_font
, ws_number
, nlength
)) / 2;
1157 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, 2, ws_number
, nlength
);
1161 if (aicon
->launching
) {
1162 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1163 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1165 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
, aicon
->dock
->rclip_button_pushed
);
1168 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1170 wClipIconPaint(desc
->parent
);
1173 static void dockIconPaint(WAppIcon
*btn
)
1175 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1176 wClipIconPaint(btn
);
1183 static WMPropList
*make_icon_state(WAppIcon
*btn
)
1185 WMPropList
*node
= NULL
;
1186 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
;
1187 WMPropList
*position
, *buggy
, *omnipresent
;
1193 command
= WMCreatePLString("-");
1195 command
= WMCreatePLString(btn
->command
);
1197 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1199 lock
= btn
->lock
? dYes
: dNo
;
1201 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1203 name
= WMCreatePLString(tmp
);
1207 forced
= btn
->forced_dock
? dYes
: dNo
;
1209 buggy
= btn
->buggy_app
? dYes
: dNo
;
1211 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1212 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1214 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1215 position
= WMCreatePLString(buffer
);
1217 node
= WMCreatePLDictionary(dCommand
, command
,
1219 dAutoLaunch
, autolaunch
,
1221 dForced
, forced
, dBuggyApplication
, buggy
, dPosition
, position
, NULL
);
1222 WMReleasePropList(command
);
1223 WMReleasePropList(name
);
1224 WMReleasePropList(position
);
1226 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1227 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&& (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1228 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1230 #ifdef XDND /* was OFFIX */
1231 if (btn
->dnd_command
) {
1232 command
= WMCreatePLString(btn
->dnd_command
);
1233 WMPutInPLDictionary(node
, dDropCommand
, command
);
1234 WMReleasePropList(command
);
1238 if (btn
->paste_command
) {
1239 command
= WMCreatePLString(btn
->paste_command
);
1240 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1241 WMReleasePropList(command
);
1248 static WMPropList
*dockSaveState(WDock
*dock
)
1251 WMPropList
*icon_info
;
1252 WMPropList
*list
= NULL
, *dock_state
= NULL
;
1253 WMPropList
*value
, *key
;
1256 list
= WMCreatePLArray(NULL
);
1258 for (i
= (dock
->type
== WM_DOCK
? 0 : 1); i
< dock
->max_icons
; i
++) {
1259 WAppIcon
*btn
= dock
->icon_array
[i
];
1261 if (!btn
|| btn
->attracted
)
1264 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1265 WMAddToPLArray(list
, icon_info
);
1266 WMReleasePropList(icon_info
);
1270 dock_state
= WMCreatePLDictionary(dApplications
, list
, NULL
);
1272 if (dock
->type
== WM_DOCK
) {
1273 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1274 key
= WMCreatePLString(buffer
);
1275 WMPutInPLDictionary(dock_state
, key
, list
);
1276 WMReleasePropList(key
);
1278 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0), dock
->y_pos
);
1279 value
= WMCreatePLString(buffer
);
1280 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1281 WMReleasePropList(value
);
1283 WMReleasePropList(list
);
1285 value
= (dock
->lowered
? dYes
: dNo
);
1286 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1288 if (dock
->type
== WM_CLIP
) {
1289 value
= (dock
->collapsed
? dYes
: dNo
);
1290 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1292 value
= (dock
->auto_collapse
? dYes
: dNo
);
1293 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1295 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1296 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1298 value
= (dock
->attract_icons
? dYes
: dNo
);
1299 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1305 void wDockSaveState(WScreen
*scr
, WMPropList
*old_state
)
1307 WMPropList
*dock_state
;
1310 dock_state
= dockSaveState(scr
->dock
);
1313 * Copy saved states of docks with different sizes.
1319 keys
= WMGetPLDictionaryKeys(old_state
);
1320 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1321 tmp
= WMGetFromPLArray(keys
, i
);
1323 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1324 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1326 WMPutInPLDictionary(dock_state
, tmp
, WMGetFromPLDictionary(old_state
, tmp
));
1329 WMReleasePropList(keys
);
1332 WMPutInPLDictionary(scr
->session_state
, dDock
, dock_state
);
1334 WMReleasePropList(dock_state
);
1337 void wClipSaveState(WScreen
*scr
)
1339 WMPropList
*clip_state
;
1341 clip_state
= make_icon_state(scr
->clip_icon
);
1343 WMPutInPLDictionary(scr
->session_state
, dClip
, clip_state
);
1345 WMReleasePropList(clip_state
);
1348 WMPropList
*wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1350 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1353 static Bool
getBooleanDockValue(WMPropList
*value
, WMPropList
*key
)
1356 if (WMIsPLString(value
)) {
1357 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1360 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1366 static WAppIcon
*restore_icon_state(WScreen
*scr
, WMPropList
*info
, int type
, int index
)
1369 WMPropList
*cmd
, *value
;
1371 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1372 if (!cmd
|| !WMIsPLString(cmd
)) {
1376 /* parse window name */
1377 value
= WMGetFromPLDictionary(info
, dName
);
1382 char *wclass
, *winstance
;
1385 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1387 if (!winstance
&& !wclass
) {
1394 command
= wstrdup(WMGetFromPLString(cmd
));
1398 if (!command
|| strcmp(command
, "-") == 0) {
1409 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1418 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1419 if (type
== WM_CLIP
) {
1420 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1421 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1423 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1424 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1426 #ifdef XDND /* was OFFIX */
1427 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1429 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1432 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1434 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1436 /* check auto launch */
1437 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1439 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1442 value
= WMGetFromPLDictionary(info
, dLock
);
1444 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1446 /* check if it wasn't normally docked */
1447 value
= WMGetFromPLDictionary(info
, dForced
);
1449 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1451 /* check if we can rely on the stuff in the app */
1452 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1454 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1456 /* get position in the dock */
1457 value
= WMGetFromPLDictionary(info
, dPosition
);
1458 if (value
&& WMIsPLString(value
)) {
1459 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1460 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1462 /* check position sanity */
1463 /* incomplete section! */
1464 if (type
== WM_DOCK
) {
1466 if (aicon
->yindex
< 0)
1467 wwarning(_("bad value in docked icon position %i,%i"),
1468 aicon
->xindex
, aicon
->yindex
);
1471 aicon
->yindex
= index
;
1475 /* check if icon is omnipresent */
1476 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1478 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1486 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1488 WAppIcon
*wClipRestoreState(WScreen
*scr
, WMPropList
*clip_state
)
1493 icon
= mainIconCreate(scr
, WM_CLIP
);
1498 WMRetainPropList(clip_state
);
1500 /* restore position */
1502 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1505 if (!WMIsPLString(value
))
1506 COMPLAIN("Position");
1511 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1512 COMPLAIN("Position");
1514 /* check position sanity */
1515 rect
.pos
.x
= icon
->x_pos
;
1516 rect
.pos
.y
= icon
->y_pos
;
1517 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1519 wGetRectPlacementInfo(scr
, rect
, &flags
);
1520 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
1521 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1524 #ifdef XDND /* was OFFIX */
1525 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1526 if (value
&& WMIsPLString(value
))
1527 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1530 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1531 if (value
&& WMIsPLString(value
))
1532 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1534 WMReleasePropList(clip_state
);
1539 WDock
*wDockRestoreState(WScreen
*scr
, WMPropList
*dock_state
, int type
)
1544 WAppIcon
*aicon
, *old_top
;
1547 dock
= wDockCreate(scr
, type
);
1552 WMRetainPropList(dock_state
);
1554 /* restore position */
1555 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1557 if (!WMIsPLString(value
)) {
1558 COMPLAIN("Position");
1563 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1564 COMPLAIN("Position");
1566 /* check position sanity */
1567 rect
.pos
.x
= dock
->x_pos
;
1568 rect
.pos
.y
= dock
->y_pos
;
1569 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1571 wGetRectPlacementInfo(scr
, rect
, &flags
);
1572 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
)) {
1573 int x
= dock
->x_pos
;
1574 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1577 /* Is this needed any more? */
1578 if (type
== WM_CLIP
) {
1579 if (dock
->x_pos
< 0) {
1581 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1582 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1585 if (dock
->x_pos
>= 0) {
1586 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1587 dock
->on_right_side
= 0;
1589 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1590 dock
->on_right_side
= 1;
1596 /* restore lowered/raised state */
1599 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1601 if (!WMIsPLString(value
)) {
1602 COMPLAIN("Lowered");
1604 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1610 /* restore collapsed state */
1611 dock
->collapsed
= 0;
1613 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1615 if (!WMIsPLString(value
)) {
1616 COMPLAIN("Collapsed");
1618 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1619 dock
->collapsed
= 1;
1624 /* restore auto-collapsed state */
1625 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1627 if (!WMIsPLString(value
)) {
1628 COMPLAIN("AutoCollapse");
1630 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1631 dock
->auto_collapse
= 1;
1632 dock
->collapsed
= 1;
1637 /* restore auto-raise/lower state */
1638 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1640 if (!WMIsPLString(value
)) {
1641 COMPLAIN("AutoRaiseLower");
1643 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1644 dock
->auto_raise_lower
= 1;
1648 /* restore attract icons state */
1649 dock
->attract_icons
= 0;
1651 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1653 if (!WMIsPLString(value
)) {
1654 COMPLAIN("AutoAttractIcons");
1656 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1657 dock
->attract_icons
= 1;
1661 /* application list */
1668 * When saving, it saves the dock state in
1669 * Applications and Applicationsnnn
1671 * When loading, it will first try Applicationsnnn.
1672 * If it does not exist, use Applications as default.
1675 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1677 tmp
= WMCreatePLString(buffer
);
1678 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1679 WMReleasePropList(tmp
);
1682 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1688 count
= WMGetPropListItemCount(apps
);
1692 old_top
= dock
->icon_array
[0];
1694 /* dock->icon_count is set to 1 when dock is created.
1695 * Since Clip is already restored, we want to keep it so for clip,
1696 * but for dock we may change the default top tile, so we set it to 0.
1698 if (type
== WM_DOCK
)
1699 dock
->icon_count
= 0;
1701 for (i
= 0; i
< count
; i
++) {
1702 if (dock
->icon_count
>= dock
->max_icons
) {
1703 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1707 value
= WMGetFromPLArray(apps
, i
);
1708 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1710 dock
->icon_array
[dock
->icon_count
] = aicon
;
1714 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1715 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1718 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1720 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1722 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1724 if (!dock
->collapsed
)
1725 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1726 wRaiseFrame(aicon
->icon
->core
);
1729 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
)
1733 /* if the first icon is not defined, use the default */
1734 if (dock
->icon_array
[0] == NULL
) {
1735 /* update default icon */
1736 old_top
->x_pos
= dock
->x_pos
;
1737 old_top
->y_pos
= dock
->y_pos
;
1739 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1741 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1742 dock
->icon_array
[0] = old_top
;
1743 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1744 /* we don't need to increment dock->icon_count here because it was
1745 * incremented in the loop above.
1747 } else if (old_top
!= dock
->icon_array
[0]) {
1748 if (old_top
== scr
->clip_icon
)
1749 scr
->clip_icon
= dock
->icon_array
[0];
1750 wAppIconDestroy(old_top
);
1754 WMReleasePropList(dock_state
);
1759 void wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1761 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1763 btn
->drop_launch
= 0;
1764 btn
->paste_launch
= 0;
1766 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1769 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1779 void wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1785 for (i
= 0; i
< dock
->max_icons
; i
++) {
1786 btn
= dock
->icon_array
[i
];
1787 if (!btn
|| !btn
->auto_launch
)
1790 state
= wmalloc(sizeof(WSavedState
));
1791 memset(state
, 0, sizeof(WSavedState
));
1792 state
->workspace
= workspace
;
1793 /* TODO: this is klugy and is very difficult to understand
1794 * what's going on. Try to clean up */
1795 wDockLaunchWithState(dock
, btn
, state
);
1799 #ifdef XDND /* was OFFIX */
1800 static WDock
*findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1806 if ((dock
= scr
->dock
) != NULL
) {
1807 for (i
= 0; i
< dock
->max_icons
; i
++) {
1808 if (dock
->icon_array
[i
]
1809 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1815 if (*icon_pos
< 0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
) != NULL
) {
1816 for (i
= 0; i
< dock
->max_icons
; i
++) {
1817 if (dock
->icon_array
[i
]
1818 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1829 int wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
1835 dock
= findDock(scr
, event
, &icon_pos
);
1840 * Return True if the drop was on an application icon window.
1841 * In this case, let the ClientMessage handler redirect the
1842 * message to the app.
1844 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
1847 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
1848 scr
->flags
.dnd_data_convertion_status
= 0;
1850 btn
= dock
->icon_array
[icon_pos
];
1852 if (!btn
->forced_dock
) {
1853 btn
->relaunching
= btn
->running
;
1856 if (btn
->wm_instance
|| btn
->wm_class
) {
1857 WWindowAttributes attr
;
1858 memset(&attr
, 0, sizeof(WWindowAttributes
));
1859 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
1860 btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
1862 if (!attr
.no_appicon
)
1868 btn
->paste_launch
= 0;
1869 btn
->drop_launch
= 1;
1870 scr
->last_dock
= dock
;
1871 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1876 if (!btn
->relaunching
) {
1885 Bool
wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1890 wwin
= icon
->icon
->owner
;
1891 if (icon
->command
== NULL
) {
1896 command
= GetCommandForWindow(wwin
->client_win
);
1898 icon
->command
= command
;
1900 /* icon->forced_dock = 1; */
1901 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
1903 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
1904 _("Type the command used to launch the application"), &command
)) {
1905 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
1909 icon
->command
= command
;
1915 /* If the target is the dock, reject the icon. If
1916 * the target is the clip, make it an attracted icon
1918 if (dock
->type
== WM_CLIP
) {
1919 icon
->attracted
= 1;
1920 if (!icon
->icon
->shadowed
) {
1921 icon
->icon
->shadowed
= 1;
1922 icon
->icon
->force_paint
= 1;
1934 for (index
= 1; index
< dock
->max_icons
; index
++)
1935 if (dock
->icon_array
[index
] == NULL
)
1937 /* if (index == dock->max_icons)
1940 assert(index
< dock
->max_icons
);
1942 dock
->icon_array
[index
] = icon
;
1946 icon
->omnipresent
= 0;
1948 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
1949 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
1954 icon
->launching
= 0;
1957 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1958 if (dock
->type
== WM_CLIP
) {
1959 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1960 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1962 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1963 icon
->icon
->core
->descriptor
.parent
= icon
;
1965 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
1966 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
1967 wAppIconPaint(icon
);
1970 if (wPreferences
.auto_arrange_icons
)
1971 wArrangeIcons(dock
->screen_ptr
, True
);
1973 #ifdef XDND /* was OFFIX */
1974 if (icon
->command
&& !icon
->dnd_command
) {
1975 int len
= strlen(icon
->command
) + 8;
1976 icon
->dnd_command
= wmalloc(len
);
1977 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
1981 if (icon
->command
&& !icon
->paste_command
) {
1982 int len
= strlen(icon
->command
) + 8;
1983 icon
->paste_command
= wmalloc(len
);
1984 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
1990 static void reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1994 for (index
= 1; index
< dock
->max_icons
; index
++) {
1995 if (dock
->icon_array
[index
] == icon
)
1998 assert(index
< dock
->max_icons
);
2003 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2004 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2007 static Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2014 return True
; /* No move needed, we're already there */
2019 wwin
= icon
->icon
->owner
;
2022 * For the moment we can't do this if we move icons in Clip from one
2023 * workspace to other, because if we move two or more icons without
2024 * command, the dialog box will not be able to tell us to which of the
2025 * moved icons it applies. -Dan
2027 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
2028 command
= GetCommandForWindow(wwin
->client_win
);
2030 icon
->command
= command
;
2033 /* icon->forced_dock = 1; */
2034 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2035 _("Type the command used to launch the application"), &command
)) {
2036 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2040 icon
->command
= command
;
2051 if (dest
->type
== WM_DOCK
)
2052 wClipMakeIconOmnipresent(icon
, False
);
2054 for (index
= 1; index
< src
->max_icons
; index
++) {
2055 if (src
->icon_array
[index
] == icon
)
2058 assert(index
< src
->max_icons
);
2060 src
->icon_array
[index
] = NULL
;
2063 for (index
= 1; index
< dest
->max_icons
; index
++) {
2064 if (dest
->icon_array
[index
] == NULL
)
2067 /* if (index == dest->max_icons)
2070 assert(index
< dest
->max_icons
);
2072 dest
->icon_array
[index
] = icon
;
2075 /* deselect the icon */
2076 if (icon
->icon
->selected
)
2077 wIconSelect(icon
->icon
);
2079 if (dest
->type
== WM_DOCK
) {
2080 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2081 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2083 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2084 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2087 /* set it to be kept when moving to dock.
2088 * Unless the icon does not have a command set
2090 if (icon
->command
&& dest
->type
== WM_DOCK
) {
2091 icon
->attracted
= 0;
2092 if (icon
->icon
->shadowed
) {
2093 icon
->icon
->shadowed
= 0;
2094 icon
->icon
->force_paint
= 1;
2099 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2105 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2106 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2110 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2111 wAppIconPaint(icon
);
2116 void wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2120 /* make the settings panel be closed */
2122 DestroyDockAppSettingsPanel(icon
->panel
);
2125 /* This must be called before icon->dock is set to NULL.
2126 * Don't move it. -Dan
2128 wClipMakeIconOmnipresent(icon
, False
);
2132 icon
->attracted
= 0;
2133 icon
->auto_launch
= 0;
2134 if (icon
->icon
->shadowed
) {
2135 icon
->icon
->shadowed
= 0;
2136 icon
->icon
->force_paint
= 1;
2139 /* deselect the icon */
2140 if (icon
->icon
->selected
)
2141 wIconSelect(icon
->icon
);
2143 if (icon
->command
) {
2144 wfree(icon
->command
);
2145 icon
->command
= NULL
;
2147 #ifdef XDND /* was OFFIX */
2148 if (icon
->dnd_command
) {
2149 wfree(icon
->dnd_command
);
2150 icon
->dnd_command
= NULL
;
2153 if (icon
->paste_command
) {
2154 wfree(icon
->paste_command
);
2155 icon
->paste_command
= NULL
;
2158 for (index
= 1; index
< dock
->max_icons
; index
++)
2159 if (dock
->icon_array
[index
] == icon
)
2161 assert(index
< dock
->max_icons
);
2162 dock
->icon_array
[index
] = NULL
;
2168 /* if the dock is not attached to an application or
2169 * the the application did not set the approriate hints yet,
2170 * destroy the icon */
2171 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2172 wAppIconDestroy(icon
);
2174 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2175 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2176 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2177 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2178 icon
->icon
->core
->descriptor
.parent
= icon
;
2180 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2182 wAppIconPaint(icon
);
2183 if (wPreferences
.auto_arrange_icons
) {
2184 wArrangeIcons(dock
->screen_ptr
, True
);
2187 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2192 * returns the closest Dock slot index for the passed
2195 * Returns False if icon can't be docked.
2197 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2200 Bool
wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2202 WScreen
*scr
= dock
->screen_ptr
;
2205 int i
, offset
= ICON_SIZE
/ 2;
2206 WAppIcon
*aicon
= NULL
;
2207 WAppIcon
*nicon
= NULL
;
2210 /* TODO: XINERAMA, for these */
2211 max_y_icons
= scr
->scr_height
/ ICON_SIZE
- 1;
2213 if (wPreferences
.flags
.noupdates
)
2219 /* if the dock is full */
2220 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
)) {
2224 /* exact position */
2226 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2228 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2231 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2233 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2235 /* check if the icon is outside the screen boundaries */
2240 rect
.pos
.x
= dx
+ ex_x
* ICON_SIZE
;
2241 rect
.pos
.y
= dy
+ ex_y
* ICON_SIZE
;
2242 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2244 wGetRectPlacementInfo(scr
, rect
, &flags
);
2245 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
2249 if (dock
->type
== WM_DOCK
) {
2250 if (icon
->dock
!= dock
&& ex_x
!= 0)
2254 for (i
= 0; i
< dock
->max_icons
; i
++) {
2255 nicon
= dock
->icon_array
[i
];
2256 if (nicon
&& nicon
->yindex
== ex_y
) {
2263 int sig
, done
, closest
;
2265 /* Possible cases when redocking:
2267 * icon dragged out of range of any slot -> false
2268 * icon dragged to range of free slot
2269 * icon dragged to range of same slot
2270 * icon dragged to range of different icon
2272 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2275 if (ex_y
>= 0 && ex_y
<= max_y_icons
&& (aicon
== icon
|| !aicon
)) {
2281 /* start looking at the upper slot or lower? */
2282 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2289 /* look for closest free slot */
2290 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2294 closest
= sig
* (i
/ 2) + ex_y
;
2295 /* check if this slot is used */
2297 for (j
= 0; j
< dock
->max_icons
; j
++) {
2298 if (dock
->icon_array
[j
]
2299 && dock
->icon_array
[j
]->yindex
== closest
) {
2300 /* slot is used by someone else */
2301 if (dock
->icon_array
[j
] != icon
)
2309 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2310 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2311 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2316 } else { /* !redocking */
2318 /* if slot is free and the icon is close enough, return it */
2319 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2329 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2330 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+ 1;
2333 for (k
= start
; k
< stop
; k
++) {
2334 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2337 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2338 nicon
= tmp
->icon_array
[i
];
2339 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2347 for (k
= start
; k
< stop
; k
++) {
2348 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2351 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2352 nicon
= tmp
->icon_array
[i
];
2353 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2354 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2355 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2364 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2373 static int onScreen(WScreen
*scr
, int x
, int y
, int sx
, int ex
, int sy
, int ey
)
2375 WMRect rect
= wmkrect(x
, y
, ICON_SIZE
, ICON_SIZE
);
2378 wGetRectPlacementInfo(scr
, rect
, &flags
);
2380 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2384 * returns true if it can find a free slot in the dock,
2385 * in which case it changes x_pos and y_pos accordingly.
2386 * Else returns false.
2388 Bool
wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2390 WScreen
*scr
= dock
->screen_ptr
;
2392 WAppIconChain
*chain
;
2393 unsigned char *slot_map
;
2397 int i
, done
= False
;
2399 int sx
= 0, sy
= 0, ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2400 int extra_count
= 0;
2402 if (dock
->type
== WM_CLIP
&& dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2403 extra_count
= scr
->global_icon_count
;
2405 /* if the dock is full */
2406 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
) {
2410 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2411 if (scr
->dock
->on_right_side
)
2412 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2414 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2417 if (ex
< dock
->x_pos
)
2419 if (sx
> dock
->x_pos
+ ICON_SIZE
)
2420 sx
= dock
->x_pos
+ ICON_SIZE
;
2427 /* check if clip is in a corner */
2428 if (dock
->type
== WM_CLIP
) {
2429 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2431 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2433 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2435 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2442 /* If the clip is in the corner, use only slots that are in the border
2444 if (corner
!= C_NONE
) {
2448 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2449 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2450 hmap
= wmalloc(hcount
+ 1);
2451 memset(hmap
, 0, hcount
+ 1);
2452 vmap
= wmalloc(vcount
+ 1);
2453 memset(vmap
, 0, vcount
+ 1);
2455 /* mark used positions */
2458 for (i
= 0; i
< dock
->max_icons
; i
++) {
2459 btn
= dock
->icon_array
[i
];
2463 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2464 vmap
[btn
->yindex
] = 1;
2465 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2466 hmap
[btn
->xindex
] = 1;
2468 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2470 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2471 vmap
[btn
->yindex
] = 1;
2472 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2473 hmap
[btn
->xindex
] = 1;
2477 for (i
= 0; i
< dock
->max_icons
; i
++) {
2478 btn
= dock
->icon_array
[i
];
2482 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2483 vmap
[btn
->yindex
] = 1;
2484 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2485 hmap
[-btn
->xindex
] = 1;
2487 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2489 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2490 vmap
[btn
->yindex
] = 1;
2491 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2492 hmap
[-btn
->xindex
] = 1;
2496 for (i
= 0; i
< dock
->max_icons
; i
++) {
2497 btn
= dock
->icon_array
[i
];
2501 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2502 vmap
[-btn
->yindex
] = 1;
2503 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2504 hmap
[btn
->xindex
] = 1;
2506 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2508 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2509 vmap
[-btn
->yindex
] = 1;
2510 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2511 hmap
[btn
->xindex
] = 1;
2516 for (i
= 0; i
< dock
->max_icons
; i
++) {
2517 btn
= dock
->icon_array
[i
];
2521 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2522 vmap
[-btn
->yindex
] = 1;
2523 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2524 hmap
[-btn
->xindex
] = 1;
2526 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2528 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2529 vmap
[-btn
->yindex
] = 1;
2530 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2531 hmap
[-btn
->xindex
] = 1;
2537 /* search a vacant slot */
2538 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2539 if (i
< vcount
&& vmap
[i
] == 0) {
2545 } else if (i
< hcount
&& hmap
[i
] == 0) {
2555 /* If found a slot, translate and return */
2557 if (corner
== C_NW
|| corner
== C_NE
) {
2562 if (corner
== C_NE
|| corner
== C_SE
) {
2569 /* else, try to find a slot somewhere else */
2572 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2573 * placed outside of screen */
2574 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2576 /* In the worst case (the clip is in the corner of the screen),
2577 * the amount of icons that fit in the clip is smaller.
2578 * Double the map to get a safe value.
2582 r
= (mwidth
- 1) / 2;
2584 slot_map
= wmalloc(mwidth
* mwidth
);
2585 memset(slot_map
, 0, mwidth
* mwidth
);
2587 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2589 /* mark used slots in the map. If the slot falls outside the map
2590 * (for example, when all icons are placed in line), ignore them. */
2591 for (i
= 0; i
< dock
->max_icons
; i
++) {
2592 btn
= dock
->icon_array
[i
];
2594 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2596 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2597 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2599 /* Find closest slot from the center that is free by scanning the
2600 * map from the center to outward in circular passes.
2601 * This will not result in a neat layout, but will be optimal
2602 * in the sense that there will not be holes left.
2605 for (i
= 1; i
<= r
&& !done
; i
++) {
2608 /* top and bottom parts of the ring */
2609 for (x
= -i
; x
<= i
&& !done
; x
++) {
2610 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2612 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2613 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2620 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2621 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2628 /* left and right parts of the ring */
2629 for (y
= -i
+ 1; y
<= i
- 1; y
++) {
2630 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2632 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2633 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2640 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2641 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2654 static void moveDock(WDock
*dock
, int new_x
, int new_y
)
2659 dock
->x_pos
= new_x
;
2660 dock
->y_pos
= new_y
;
2661 for (i
= 0; i
< dock
->max_icons
; i
++) {
2662 btn
= dock
->icon_array
[i
];
2664 btn
->x_pos
= new_x
+ btn
->xindex
* ICON_SIZE
;
2665 btn
->y_pos
= new_y
+ btn
->yindex
* ICON_SIZE
;
2666 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2671 static void swapDock(WDock
*dock
)
2673 WScreen
*scr
= dock
->screen_ptr
;
2677 if (dock
->on_right_side
) {
2678 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2680 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2683 for (i
= 0; i
< dock
->max_icons
; i
++) {
2684 btn
= dock
->icon_array
[i
];
2687 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2691 wScreenUpdateUsableArea(scr
);
2694 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2696 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2702 cmdline
= ExpandOptions(scr
, command
);
2704 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2712 wtokensplit(cmdline
, &argv
, &argc
);
2722 if ((pid
= fork()) == 0) {
2726 SetupEnvironment(scr
);
2732 args
= malloc(sizeof(char *) * (argc
+ 1));
2735 for (i
= 0; i
< argc
; i
++) {
2739 execvp(argv
[0], args
);
2742 wtokenfree(argv
, argc
);
2746 state
= wmalloc(sizeof(WSavedState
));
2747 memset(state
, 0, sizeof(WSavedState
));
2749 state
->miniaturized
= -1;
2751 if (btn
->dock
== scr
->dock
|| btn
->omnipresent
)
2752 state
->workspace
= -1;
2754 state
->workspace
= scr
->current_workspace
;
2756 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
2757 wAddDeathHandler(pid
, (WDeathHandler
*) trackDeadProcess
, btn
->dock
);
2765 void wDockHideIcons(WDock
*dock
)
2772 for (i
= 1; i
< dock
->max_icons
; i
++) {
2773 if (dock
->icon_array
[i
])
2774 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2778 dockIconPaint(dock
->icon_array
[0]);
2781 void wDockShowIcons(WDock
*dock
)
2789 btn
= dock
->icon_array
[0];
2790 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2792 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2793 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2795 for (i
= 1; i
< dock
->max_icons
; i
++) {
2796 if (dock
->icon_array
[i
]) {
2797 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
, btn
->icon
->core
);
2802 if (!dock
->collapsed
) {
2803 for (i
= 1; i
< dock
->max_icons
; i
++) {
2804 if (dock
->icon_array
[i
]) {
2805 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2814 void wDockLower(WDock
*dock
)
2818 for (i
= 0; i
< dock
->max_icons
; i
++) {
2819 if (dock
->icon_array
[i
])
2820 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2824 void wDockRaise(WDock
*dock
)
2828 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
2829 if (dock
->icon_array
[i
])
2830 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2834 void wDockRaiseLower(WDock
*dock
)
2836 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2837 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2838 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2844 void wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
2846 icon
->launching
= 0;
2847 icon
->relaunching
= 0;
2848 dockIconPaint(icon
);
2851 WAppIcon
*wDockFindIconForWindow(WDock
*dock
, Window window
)
2856 for (i
= 0; i
< dock
->max_icons
; i
++) {
2857 icon
= dock
->icon_array
[i
];
2858 if (icon
&& icon
->main_window
== window
)
2864 void wDockTrackWindowLaunch(WDock
*dock
, Window window
)
2867 char *wm_class
, *wm_instance
;
2869 Bool firstPass
= True
;
2871 char *command
= NULL
;
2873 command
= GetCommandForWindow(window
);
2875 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) || (!wm_class
&& !wm_instance
)) {
2883 for (i
= 0; i
< dock
->max_icons
; i
++) {
2884 icon
= dock
->icon_array
[i
];
2888 /* app is already attached to icon */
2889 if (icon
->main_window
== window
) {
2894 if ((icon
->wm_instance
|| icon
->wm_class
)
2895 && (icon
->launching
|| !icon
->running
)) {
2897 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0) {
2900 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0) {
2903 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0) {
2907 if (!icon
->relaunching
) {
2910 /* Possibly an application that was docked with dockit,
2911 * but the user did not update WMState to indicate that
2912 * it was docked by force */
2913 wapp
= wApplicationOf(window
);
2915 icon
->forced_dock
= 1;
2918 if (!icon
->forced_dock
) {
2919 icon
->main_window
= window
;
2923 if (!wPreferences
.no_animations
&& !icon
->launching
&&
2924 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
2928 icon
->launching
= 1;
2929 dockIconPaint(icon
);
2931 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
2932 wm_instance
, wm_class
, TILE_NORMAL
);
2933 /* XXX: can: aicon->icon == NULL ? */
2934 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
2935 wAppIconMove(aicon
, x0
, y0
);
2936 /* Should this always be lowered? -Dan */
2938 wLowerFrame(aicon
->icon
->core
);
2939 XMapWindow(dpy
, aicon
->icon
->core
->window
);
2940 aicon
->launching
= 1;
2941 wAppIconPaint(aicon
);
2942 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
2943 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
2944 wAppIconDestroy(aicon
);
2946 wDockFinishLaunch(dock
, icon
);
2951 if (firstPass
&& !found
) {
2965 void wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
2967 if (!wPreferences
.flags
.noclip
) {
2968 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
2969 if (scr
->current_workspace
!= workspace
) {
2970 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
2971 WAppIconChain
*chain
= scr
->global_icons
;
2974 moveIconBetweenDocks(chain
->aicon
->dock
,
2975 scr
->workspaces
[workspace
]->clip
,
2976 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
2977 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
2978 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
2979 chain
= chain
->next
;
2982 wDockHideIcons(old_clip
);
2983 if (old_clip
->auto_raise_lower
) {
2984 if (old_clip
->auto_raise_magic
) {
2985 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
2986 old_clip
->auto_raise_magic
= NULL
;
2988 wDockLower(old_clip
);
2990 if (old_clip
->auto_collapse
) {
2991 if (old_clip
->auto_expand_magic
) {
2992 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
2993 old_clip
->auto_expand_magic
= NULL
;
2995 old_clip
->collapsed
= 1;
2997 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3002 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3007 for (i
= 0; i
< dock
->max_icons
; i
++) {
3008 icon
= dock
->icon_array
[i
];
3012 if (icon
->launching
&& icon
->pid
== pid
) {
3013 if (!icon
->relaunching
) {
3015 icon
->main_window
= None
;
3017 wDockFinishLaunch(dock
, icon
);
3019 if (status
== 111) {
3024 if (icon
->drop_launch
)
3025 cmd
= icon
->dnd_command
;
3028 if (icon
->paste_launch
)
3029 cmd
= icon
->paste_command
;
3031 cmd
= icon
->command
;
3033 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3035 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3042 static void toggleLowered(WDock
*dock
)
3047 /* lower/raise Dock */
3048 if (!dock
->lowered
) {
3049 newlevel
= WMNormalLevel
;
3052 newlevel
= WMDockLevel
;
3056 for (i
= 0; i
< dock
->max_icons
; i
++) {
3057 tmp
= dock
->icon_array
[i
];
3061 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3063 wLowerFrame(tmp
->icon
->core
);
3066 if (dock
->type
== WM_DOCK
)
3067 wScreenUpdateUsableArea(dock
->screen_ptr
);
3070 static void toggleCollapsed(WDock
*dock
)
3072 if (dock
->collapsed
) {
3073 dock
->collapsed
= 0;
3074 wDockShowIcons(dock
);
3076 dock
->collapsed
= 1;
3077 wDockHideIcons(dock
);
3081 static void openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3083 WScreen
*scr
= dock
->screen_ptr
;
3084 WObjDescriptor
*desc
;
3086 WApplication
*wapp
= NULL
;
3090 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3092 if (dock
->type
== WM_DOCK
) {
3094 entry
= dock
->menu
->entries
[index
];
3095 entry
->flags
.indicator_on
= !dock
->lowered
;
3096 entry
->clientdata
= dock
;
3097 dock
->menu
->flags
.realized
= 0;
3100 if (scr
->clip_options
)
3101 updateClipOptionsMenu(scr
->clip_options
, dock
);
3103 n_selected
= numberOfSelectedIcons(dock
);
3105 /* Rename Workspace */
3106 entry
= dock
->menu
->entries
[++index
];
3107 if (aicon
== scr
->clip_icon
) {
3108 entry
->callback
= renameCallback
;
3109 entry
->clientdata
= dock
;
3110 entry
->flags
.indicator
= 0;
3111 entry
->text
= _("Rename Workspace");
3113 entry
->callback
= omnipresentCallback
;
3114 entry
->clientdata
= aicon
;
3115 if (n_selected
> 0) {
3116 entry
->flags
.indicator
= 0;
3117 entry
->text
= _("Toggle Omnipresent");
3119 entry
->flags
.indicator
= 1;
3120 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3121 entry
->flags
.indicator_type
= MI_CHECK
;
3122 entry
->text
= _("Omnipresent");
3126 /* select/unselect icon */
3127 entry
= dock
->menu
->entries
[++index
];
3128 entry
->clientdata
= aicon
;
3129 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3130 wMenuSetEnabled(dock
->menu
, index
, aicon
!= scr
->clip_icon
);
3132 /* select/unselect all icons */
3133 entry
= dock
->menu
->entries
[++index
];
3134 entry
->clientdata
= aicon
;
3136 entry
->text
= _("Unselect All Icons");
3138 entry
->text
= _("Select All Icons");
3139 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3142 entry
= dock
->menu
->entries
[++index
];
3143 entry
->clientdata
= aicon
;
3145 entry
->text
= _("Keep Icons");
3147 entry
->text
= _("Keep Icon");
3148 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3150 /* this is the workspace submenu part */
3151 entry
= dock
->menu
->entries
[++index
];
3153 entry
->text
= _("Move Icons To");
3155 entry
->text
= _("Move Icon To");
3156 if (scr
->clip_submenu
)
3157 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3158 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3160 /* remove icon(s) */
3161 entry
= dock
->menu
->entries
[++index
];
3162 entry
->clientdata
= aicon
;
3164 entry
->text
= _("Remove Icons");
3166 entry
->text
= _("Remove Icon");
3167 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3169 /* attract icon(s) */
3170 entry
= dock
->menu
->entries
[++index
];
3171 entry
->clientdata
= aicon
;
3173 dock
->menu
->flags
.realized
= 0;
3174 wMenuRealize(dock
->menu
);
3177 if (aicon
->icon
->owner
) {
3178 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3184 entry
= dock
->menu
->entries
[++index
];
3185 entry
->clientdata
= aicon
;
3186 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3189 entry
= dock
->menu
->entries
[++index
];
3190 entry
->clientdata
= aicon
;
3191 if (wapp
&& wapp
->flags
.hidden
) {
3192 entry
->text
= _("Unhide Here");
3194 entry
->text
= _("Bring Here");
3196 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3199 entry
= dock
->menu
->entries
[++index
];
3200 entry
->clientdata
= aicon
;
3201 if (wapp
&& wapp
->flags
.hidden
) {
3202 entry
->text
= _("Unhide");
3204 entry
->text
= _("Hide");
3206 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3209 entry
= dock
->menu
->entries
[++index
];
3210 entry
->clientdata
= aicon
;
3211 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3214 entry
= dock
->menu
->entries
[++index
];
3215 entry
->clientdata
= aicon
;
3216 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3218 if (!dock
->menu
->flags
.realized
)
3219 wMenuRealize(dock
->menu
);
3221 if (dock
->type
== WM_CLIP
) {
3222 /*x_pos = event->xbutton.x_root+2; */
3223 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3226 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3227 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3230 x_pos
= dock
->on_right_side
? scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3233 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3235 /* allow drag select */
3236 event
->xany
.send_event
= True
;
3237 desc
= &dock
->menu
->menu
->descriptor
;
3238 (*desc
->handle_mousedown
) (desc
, event
);
3241 /******************************************************************/
3242 static void iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3244 WAppIcon
*btn
= desc
->parent
;
3245 WDock
*dock
= btn
->dock
;
3246 WApplication
*wapp
= NULL
;
3249 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3250 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3252 assert(wapp
!= NULL
);
3254 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3256 /* go to the last workspace that the user worked on the app */
3257 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
&& !unhideHere
) {
3258 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3261 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3263 if (event
->xbutton
.state
& MOD_MASK
) {
3264 wHideOtherApplications(btn
->icon
->owner
);
3267 if (event
->xbutton
.button
== Button1
) {
3269 if (event
->xbutton
.state
& MOD_MASK
) {
3270 /* raise/lower dock */
3271 toggleLowered(dock
);
3272 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3273 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
)
3274 toggleCollapsed(dock
);
3276 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3277 } else if (btn
->command
) {
3278 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3279 launchDockedApplication(btn
, False
);
3285 static void handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3287 WScreen
*scr
= dock
->screen_ptr
;
3288 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3291 int grabbed
= 0, swapped
= 0, done
;
3292 Pixmap ghost
= None
;
3293 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3295 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3296 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3297 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3298 wwarning("pointer grab failed for dock move");
3301 for (x
= 0; x
< dock
->max_icons
; x
++) {
3302 if (dock
->icon_array
[x
] != NULL
&& dock
->icon_array
[x
]->yindex
> y
)
3303 y
= dock
->icon_array
[x
]->yindex
;
3306 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
* y
);
3310 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3311 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3318 /* It means the cursor moved so fast that it entered
3319 * something else (if moving slowly, it would have
3320 * stayed in the dock that is being moved. Ignore such
3321 * "spurious" EnterNotifiy's */
3326 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3327 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3328 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3329 | ButtonReleaseMask
| ButtonPressMask
,
3330 wCursor
[WCUR_MOVE
], CurrentTime
);
3335 if (dock
->type
== WM_CLIP
) {
3336 x
= ev
.xmotion
.x_root
- ofs_x
;
3337 y
= ev
.xmotion
.y_root
- ofs_y
;
3338 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3340 moveDock(dock
, x
, y
);
3342 /* move vertically if pointer is inside the dock */
3343 if ((dock
->on_right_side
&& ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3344 || (!dock
->on_right_side
&& ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
* 2)) {
3346 x
= ev
.xmotion
.x_root
- ofs_x
;
3347 y
= ev
.xmotion
.y_root
- ofs_y
;
3348 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3349 moveDock(dock
, dock
->x_pos
, y
);
3351 /* move horizontally to change sides */
3352 x
= ev
.xmotion
.x_root
- ofs_x
;
3353 if (!dock
->on_right_side
) {
3357 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
* 2) {
3358 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
- ICON_SIZE
3359 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3360 if (superfluous
&& ghost
== None
) {
3361 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3362 scr
->scr_width
- ICON_SIZE
3363 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3364 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3365 XClearWindow(dpy
, scr
->dock_shadow
);
3367 XMapRaised(dpy
, scr
->dock_shadow
);
3370 if (superfluous
&& ghost
!= None
) {
3371 XFreePixmap(dpy
, ghost
);
3374 XUnmapWindow(dpy
, scr
->dock_shadow
);
3379 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3380 XMoveWindow(dpy
, scr
->dock_shadow
, DOCK_EXTRA_SPACE
, dock
->y_pos
);
3381 if (superfluous
&& ghost
== None
) {
3382 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3383 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3384 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3385 XClearWindow(dpy
, scr
->dock_shadow
);
3387 XMapRaised(dpy
, scr
->dock_shadow
);
3390 XUnmapWindow(dpy
, scr
->dock_shadow
);
3392 if (superfluous
&& ghost
!= None
) {
3393 XFreePixmap(dpy
, ghost
);
3405 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3407 XUngrabPointer(dpy
, CurrentTime
);
3408 XUnmapWindow(dpy
, scr
->dock_shadow
);
3409 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3410 if (dock
->type
== WM_DOCK
) {
3413 dock
->on_right_side
= 1;
3415 dock
->on_right_side
= 0;
3417 wArrangeIcons(scr
, False
);
3426 XFreePixmap(dpy
, ghost
);
3427 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3431 static Bool
handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3433 WScreen
*scr
= dock
->screen_ptr
;
3435 WIcon
*icon
= aicon
->icon
;
3436 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3437 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3439 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3440 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3441 int shad_x
= x
, shad_y
= y
;
3442 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3444 Pixmap ghost
= None
;
3446 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3447 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3448 Bool hasMoved
= False
;
3450 if (wPreferences
.flags
.noupdates
)
3453 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3454 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3455 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3458 if (!(event
->xbutton
.state
& MOD_MASK
))
3459 wRaiseFrame(icon
->core
);
3461 if (!wPreferences
.flags
.noclip
)
3462 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3464 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3466 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3469 wins
[0] = icon
->core
->window
;
3470 wins
[1] = scr
->dock_shadow
;
3471 XRestackWindows(dpy
, wins
, 2);
3472 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
3474 if (icon
->pixmap
!= None
)
3475 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3477 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3479 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3480 XClearWindow(dpy
, scr
->dock_shadow
);
3482 XMapWindow(dpy
, scr
->dock_shadow
);
3487 XMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3488 | ButtonMotionMask
| ExposureMask
, &ev
);
3497 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3498 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3499 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3500 | ButtonReleaseMask
| ButtonPressMask
,
3501 wCursor
[WCUR_MOVE
], CurrentTime
);
3510 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3511 if (i
== scr
->current_workspace
)
3513 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3517 x
= ev
.xmotion
.x_root
- ofs_x
;
3518 y
= ev
.xmotion
.y_root
- ofs_y
;
3519 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3522 if (last_dock
!= dock
&& collapsed
) {
3523 last_dock
->collapsed
= 1;
3524 wDockHideIcons(last_dock
);
3527 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3528 dock
->collapsed
= 0;
3529 wDockShowIcons(dock
);
3531 if (dock
->auto_raise_lower
)
3535 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3538 if (last_dock
!= dock2
&& collapsed
) {
3539 last_dock
->collapsed
= 1;
3540 wDockHideIcons(last_dock
);
3543 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3544 dock2
->collapsed
= 0;
3545 wDockShowIcons(dock2
);
3547 if (dock2
->auto_raise_lower
)
3552 if (aicon
->launching
|| aicon
->lock
|| (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3553 || (!aicon
->running
&& tmp
)) {
3554 shad_x
= last_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3555 shad_y
= last_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3557 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3560 XMapWindow(dpy
, scr
->dock_shadow
);
3565 XUnmapWindow(dpy
, scr
->dock_shadow
);
3569 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3576 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3578 XUngrabPointer(dpy
, CurrentTime
);
3580 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3581 XUnmapWindow(dpy
, scr
->dock_shadow
);
3583 reattachIcon(dock
, aicon
, ix
, iy
);
3584 if (clip
&& dock
!= clip
&& clip
->auto_raise_lower
)
3587 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3589 /* Slide it back if dock rejected it */
3590 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
, aicon
->y_pos
);
3591 reattachIcon(dock
, aicon
, aicon
->xindex
, aicon
->yindex
);
3593 if (last_dock
->type
== WM_CLIP
&& last_dock
->auto_collapse
) {
3601 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3602 /* We need to deselect it, even if is deselected in
3603 * wDockDetach(), because else DoKaboom() will fail.
3605 if (aicon
->icon
->selected
)
3606 wIconSelect(aicon
->icon
);
3608 DoKaboom(scr
, aicon
->icon
->core
->window
, x
, y
);
3611 if (clip
&& clip
->auto_raise_lower
)
3613 wDockDetach(dock
, aicon
);
3616 last_dock
->collapsed
= 1;
3617 wDockHideIcons(last_dock
);
3622 XFreePixmap(dpy
, ghost
);
3623 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3627 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3628 if (i
== scr
->current_workspace
)
3630 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3636 return False
; /* never reached */
3639 static int getClipButton(int px
, int py
)
3641 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3643 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3646 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3647 return CLIP_FORWARD
;
3648 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3654 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3657 int done
, direction
, new_ws
;
3659 WDock
*clip
= scr
->clip_icon
->dock
;
3661 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3663 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3664 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3666 wClipIconPaint(scr
->clip_icon
);
3669 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3676 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3677 if (new_dir
!= direction
) {
3678 direction
= new_dir
;
3679 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3680 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3681 wClipIconPaint(scr
->clip_icon
);
3689 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3694 clip
->lclip_button_pushed
= 0;
3695 clip
->rclip_button_pushed
= 0;
3697 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3699 if (direction
== CLIP_FORWARD
) {
3700 if (scr
->current_workspace
< scr
->workspace_count
- 1)
3701 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3702 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
- 1)
3703 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3704 else if (wPreferences
.ws_cycle
)
3705 wWorkspaceChange(scr
, 0);
3706 } else if (direction
== CLIP_REWIND
) {
3707 if (scr
->current_workspace
> 0)
3708 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
3709 else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
)
3710 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
3713 wClipIconPaint(scr
->clip_icon
);
3716 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3718 WAppIcon
*aicon
= desc
->parent
;
3719 WDock
*dock
= aicon
->dock
;
3720 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3722 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3725 scr
->last_dock
= dock
;
3727 if (dock
->menu
->flags
.mapped
)
3728 wMenuUnmap(dock
->menu
);
3730 if (IsDoubleClick(scr
, event
)) {
3731 /* double-click was not in the main clip icon */
3732 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3733 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3734 iconDblClick(desc
, event
);
3739 if (event
->xbutton
.button
== Button1
) {
3740 if (event
->xbutton
.state
& MOD_MASK
)
3745 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
&& dock
->type
!= WM_DOCK
) {
3746 wIconSelect(aicon
->icon
);
3750 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3751 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
3752 && dock
->type
== WM_CLIP
)
3753 handleClipChangeWorkspace(scr
, event
);
3755 handleDockMove(dock
, aicon
, event
);
3757 Bool hasMoved
= handleIconMove(dock
, aicon
, event
);
3758 if (wPreferences
.single_click
&& !hasMoved
)
3759 iconDblClick(desc
, event
);
3761 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&& aicon
== scr
->clip_icon
) {
3762 if (!scr
->clip_ws_menu
) {
3763 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3765 if (scr
->clip_ws_menu
) {
3766 WMenu
*wsMenu
= scr
->clip_ws_menu
;
3769 wWorkspaceMenuUpdate(scr
, wsMenu
);
3771 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
3774 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
3775 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
3777 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
3779 desc
= &wsMenu
->menu
->descriptor
;
3780 event
->xany
.send_event
= True
;
3781 (*desc
->handle_mousedown
) (desc
, event
);
3783 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
3784 (event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
) {
3785 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3786 } else if (event
->xbutton
.button
== Button3
) {
3787 if (event
->xbutton
.send_event
&&
3788 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3789 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3790 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3791 wwarning("pointer grab failed for dockicon menu");
3795 openDockMenu(dock
, aicon
, event
);
3796 } else if (event
->xbutton
.button
== Button2
) {
3797 WAppIcon
*btn
= desc
->parent
;
3799 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3800 launchDockedApplication(btn
, True
);
3805 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3807 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3811 assert(event
->type
== EnterNotify
);
3813 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3816 scr
= btn
->icon
->core
->screen_ptr
;
3817 if (!btn
->omnipresent
)
3820 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3822 if (!dock
|| dock
->type
!= WM_CLIP
)
3825 /* The auto raise/lower code */
3826 if (dock
->auto_lower_magic
) {
3827 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3828 dock
->auto_lower_magic
= NULL
;
3830 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
3831 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
, clipAutoRaise
, (void *)dock
);
3834 /* The auto expand/collapse code */
3835 if (dock
->auto_collapse_magic
) {
3836 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3837 dock
->auto_collapse_magic
= NULL
;
3839 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
3840 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
, clipAutoExpand
, (void *)dock
);
3844 static void clipLeave(WDock
*dock
)
3847 WObjDescriptor
*desc
= NULL
;
3849 if (!dock
|| dock
->type
!= WM_CLIP
)
3852 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
3853 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3854 (XPointer
*) & desc
) != XCNOENT
3855 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
3856 && ((WAppIcon
*) desc
->parent
)->dock
&& ((WAppIcon
*) desc
->parent
)->dock
->type
== WM_CLIP
) {
3857 /* We didn't left the Clip yet */
3858 XPutBackEvent(dpy
, &event
);
3862 XPutBackEvent(dpy
, &event
);
3864 /* We entered a withdrawn window, so we're still in Clip */
3868 if (dock
->auto_raise_magic
) {
3869 WMDeleteTimerHandler(dock
->auto_raise_magic
);
3870 dock
->auto_raise_magic
= NULL
;
3872 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
3873 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
, clipAutoLower
, (void *)dock
);
3876 if (dock
->auto_expand_magic
) {
3877 WMDeleteTimerHandler(dock
->auto_expand_magic
);
3878 dock
->auto_expand_magic
= NULL
;
3880 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
3881 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
, clipAutoCollapse
, (void *)dock
);
3885 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
3887 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3889 assert(event
->type
== LeaveNotify
);
3891 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3894 clipLeave(btn
->dock
);
3897 static void clipAutoCollapse(void *cdata
)
3899 WDock
*dock
= (WDock
*) cdata
;
3901 if (dock
->type
!= WM_CLIP
)
3904 if (dock
->auto_collapse
) {
3905 dock
->collapsed
= 1;
3906 wDockHideIcons(dock
);
3908 dock
->auto_collapse_magic
= NULL
;
3911 static void clipAutoExpand(void *cdata
)
3913 WDock
*dock
= (WDock
*) cdata
;
3915 if (dock
->type
!= WM_CLIP
)
3918 if (dock
->auto_collapse
) {
3919 dock
->collapsed
= 0;
3920 wDockShowIcons(dock
);
3922 dock
->auto_expand_magic
= NULL
;
3925 static void clipAutoLower(void *cdata
)
3927 WDock
*dock
= (WDock
*) cdata
;
3929 if (dock
->type
!= WM_CLIP
)
3932 if (dock
->auto_raise_lower
)
3935 dock
->auto_lower_magic
= NULL
;
3938 static void clipAutoRaise(void *cdata
)
3940 WDock
*dock
= (WDock
*) cdata
;
3942 if (dock
->type
!= WM_CLIP
)
3945 if (dock
->auto_raise_lower
)
3948 dock
->auto_raise_magic
= NULL
;
3951 static Bool
iconCanBeOmnipresent(WAppIcon
*aicon
)
3953 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3958 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3959 clip
= scr
->workspaces
[i
]->clip
;
3961 if (clip
== aicon
->dock
)
3964 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
3965 return False
; /* Clip is full in some workspace */
3967 for (j
= 0; j
< clip
->max_icons
; j
++) {
3968 btn
= clip
->icon_array
[j
];
3969 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
3977 int wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
3979 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3980 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
3981 int status
= WO_SUCCESS
;
3983 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== scr
->clip_icon
) {
3984 return WO_NOT_APPLICABLE
;
3987 if (aicon
->omnipresent
== omnipresent
)
3991 if (iconCanBeOmnipresent(aicon
)) {
3992 aicon
->omnipresent
= 1;
3993 new_entry
= wmalloc(sizeof(WAppIconChain
));
3994 new_entry
->aicon
= aicon
;
3995 new_entry
->next
= scr
->global_icons
;
3996 scr
->global_icons
= new_entry
;
3997 scr
->global_icon_count
++;
3999 aicon
->omnipresent
= 0;
4003 aicon
->omnipresent
= 0;
4004 if (aicon
== scr
->global_icons
->aicon
) {
4005 tmp
= scr
->global_icons
->next
;
4006 wfree(scr
->global_icons
);
4007 scr
->global_icons
= tmp
;
4008 scr
->global_icon_count
--;
4010 tmp
= scr
->global_icons
;
4012 if (tmp
->next
->aicon
== aicon
) {
4013 tmp1
= tmp
->next
->next
;
4016 scr
->global_icon_count
--;
4024 wAppIconPaint(aicon
);