1 /* dock.c- built-in Dock module for WindowMaker
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <X11/Xutil.h>
35 #define PATH_MAX DEFAULT_PATH_MAX
38 #include "WindowMaker.h"
46 #include "dockedapp.h"
49 #include "properties.h"
53 #include "workspace.h"
55 #include "superfluous.h"
57 #include "placement.h"
59 /**** Local variables ****/
62 #define CLIP_FORWARD 2
64 /**** Global variables ****/
65 extern Cursor wCursor
[WCUR_LAST
];
66 extern WPreferences wPreferences
;
67 extern XContext wWinContext
;
68 extern void appIconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
70 #define MOD_MASK wPreferences.modifier_mask
71 #define ICON_SIZE wPreferences.icon_size
73 /***** Local variables ****/
75 static WMPropList
*dCommand
= NULL
;
76 static WMPropList
*dPasteCommand
= NULL
;
77 #ifdef XDND /* XXX was OFFIX */
78 static WMPropList
*dDropCommand
= NULL
;
80 static WMPropList
*dAutoLaunch
, *dLock
;
81 static WMPropList
*dName
, *dForced
, *dBuggyApplication
, *dYes
, *dNo
;
82 static WMPropList
*dHost
, *dDock
, *dClip
;
83 static WMPropList
*dAutoAttractIcons
;
85 static WMPropList
*dPosition
, *dApplications
, *dLowered
, *dCollapsed
;
87 static WMPropList
*dAutoCollapse
, *dAutoRaiseLower
, *dOmnipresent
;
89 static void dockIconPaint(WAppIcon
*btn
);
91 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
93 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
);
95 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
97 static int getClipButton(int px
, int py
);
99 static void toggleLowered(WDock
*dock
);
101 static void toggleCollapsed(WDock
*dock
);
103 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
105 static void clipLeave(WDock
*dock
);
107 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
109 static Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
);
111 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
112 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
113 static void clipAutoCollapse(void *cdata
);
114 static void clipAutoExpand(void *cdata
);
115 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
);
117 static void clipAutoLower(void *cdata
);
118 static void clipAutoRaise(void *cdata
);
119 static void reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
);
120 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
);
122 static void make_keys(void)
124 if (dCommand
!= NULL
)
127 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
128 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
130 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
132 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
133 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
134 dName
= WMRetainPropList(WMCreatePLString("Name"));
135 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
136 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
137 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
138 dNo
= WMRetainPropList(WMCreatePLString("No"));
139 dHost
= WMRetainPropList(WMCreatePLString("Host"));
141 dPosition
= WMCreatePLString("Position");
142 dApplications
= WMCreatePLString("Applications");
143 dLowered
= WMCreatePLString("Lowered");
144 dCollapsed
= WMCreatePLString("Collapsed");
145 dAutoCollapse
= WMCreatePLString("AutoCollapse");
146 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
147 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
149 dOmnipresent
= WMCreatePLString("Omnipresent");
151 dDock
= WMCreatePLString("Dock");
152 dClip
= WMCreatePLString("Clip");
155 static void renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
157 WDock
*dock
= entry
->clientdata
;
162 assert(entry
->clientdata
!= NULL
);
164 wspace
= dock
->screen_ptr
->current_workspace
;
166 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
168 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+ 1);
169 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
, &name
))
170 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
175 static void toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
177 assert(entry
->clientdata
!= NULL
);
179 toggleLowered(entry
->clientdata
);
181 entry
->flags
.indicator_on
= !(((WDock
*) entry
->clientdata
)->lowered
);
186 static int matchWindow(const void *item
, const void *cdata
)
188 return (((WFakeGroupLeader
*) item
)->leader
== (Window
) cdata
);
191 static void killCallback(WMenu
*menu
, WMenuEntry
*entry
)
193 WScreen
*scr
= menu
->menu
->screen_ptr
;
195 WFakeGroupLeader
*fPtr
;
196 char *buffer
, *shortname
, **argv
;
197 char *basename(const char *shortname
);
200 if (!WCHECK_STATE(WSTATE_NORMAL
))
203 assert(entry
->clientdata
!= NULL
);
205 icon
= (WAppIcon
*) entry
->clientdata
;
209 WCHANGE_STATE(WSTATE_MODAL
);
211 /* strip away dir names */
212 shortname
= basename(icon
->command
);
213 /* separate out command options */
214 wtokensplit(shortname
, &argv
, &argc
);
216 buffer
= wstrconcat(argv
[0],
217 _(" will be forcibly closed.\n"
218 "Any unsaved changes will be lost.\n" "Please confirm."));
220 if (icon
->icon
&& icon
->icon
->owner
) {
221 fPtr
= icon
->icon
->owner
->fake_group
;
223 /* is this really necessary? can we kill a non-running dock icon? */
224 Window win
= icon
->main_window
;
227 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)win
);
228 if (index
!= WANotFound
)
229 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
234 if (wPreferences
.dont_confirm_kill
235 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
236 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
238 WWindow
*wwin
, *twin
;
240 wwin
= scr
->focused_window
;
243 if (wwin
->fake_group
== fPtr
)
248 } else if (icon
->icon
&& icon
->icon
->owner
) {
249 wClientKill(icon
->icon
->owner
);
254 wtokenfree(argv
, argc
);
258 WCHANGE_STATE(WSTATE_NORMAL
);
261 /* TODO: replace this function with a member of the dock struct */
262 static int numberOfSelectedIcons(WDock
*dock
)
268 for (i
= 1; i
< dock
->max_icons
; i
++) {
269 aicon
= dock
->icon_array
[i
];
270 if (aicon
&& aicon
->icon
->selected
)
277 static WMArray
*getSelected(WDock
*dock
)
279 WMArray
*ret
= WMCreateArray(8);
283 for (i
= 1; i
< dock
->max_icons
; i
++) {
284 btn
= dock
->icon_array
[i
];
285 if (btn
&& btn
->icon
->selected
)
286 WMAddToArray(ret
, btn
);
292 static void paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
294 Window win
= clipIcon
->icon
->core
->window
;
295 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
297 int pt
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
298 int tp
= ICON_SIZE
- pt
;
299 int as
= pt
- 15; /* 15 = 5+5+5 */
300 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
303 color
= scr
->clip_title_color
[CLIP_NORMAL
];
305 XSetForeground(dpy
, gc
, WMColorPixel(color
));
310 p
[1].x
= ICON_SIZE
- 2;
312 p
[2].x
= ICON_SIZE
- 2;
314 } else if (lpushed
) {
318 p
[1].y
= ICON_SIZE
- 2;
320 p
[2].y
= ICON_SIZE
- 2;
322 if (lpushed
|| rpushed
) {
323 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
324 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
325 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
328 /* top right arrow */
329 p
[0].x
= p
[3].x
= ICON_SIZE
- 5 - as
;
331 p
[1].x
= ICON_SIZE
- 6;
333 p
[2].x
= ICON_SIZE
- 6;
336 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
337 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
339 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
340 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
343 /* bottom left arrow */
345 p
[0].y
= p
[3].y
= ICON_SIZE
- 5 - as
;
347 p
[1].y
= ICON_SIZE
- 6;
349 p
[2].y
= ICON_SIZE
- 6;
351 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
352 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
354 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
355 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
359 RImage
*wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
361 RImage
*tile
= RCloneImage(normalTile
);
368 pt
= CLIP_BUTTON_SIZE
* wPreferences
.icon_size
/ 64;
369 tp
= wPreferences
.icon_size
- 1 - pt
;
373 black
.red
= black
.green
= black
.blue
= 0;
376 dark
.red
= dark
.green
= dark
.blue
= 60;
379 light
.red
= light
.green
= light
.blue
= 80;
382 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
- 2, pt
- 1, &dark
);
383 RDrawLine(tile
, tp
- 1, 0, wPreferences
.icon_size
- 1, pt
+ 1, &black
);
384 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
- 3, pt
, &light
);
387 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, 4, &dark
);
388 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 5, 6 + as
, &dark
);
389 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
, &light
);
392 ROperateLine(tile
, RAddOperation
, 2, tp
+ 2, pt
- 2, wPreferences
.icon_size
- 3, &dark
);
393 RDrawLine(tile
, 0, tp
- 1, pt
+ 1, wPreferences
.icon_size
- 1, &black
);
394 ROperateLine(tile
, RSubtractOperation
, 0, tp
- 2, pt
+ 1, wPreferences
.icon_size
- 2, &light
);
397 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, &dark
);
398 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
, 6 + as
, ICON_SIZE
- 5, &dark
);
399 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5, &light
);
404 static void omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
406 WAppIcon
*clickedIcon
= entry
->clientdata
;
409 WMArray
*selectedIcons
;
410 WMArrayIterator iter
;
413 assert(entry
->clientdata
!= NULL
);
415 dock
= clickedIcon
->dock
;
417 selectedIcons
= getSelected(dock
);
419 if (!WMGetArrayItemCount(selectedIcons
))
420 WMAddToArray(selectedIcons
, clickedIcon
);
423 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
424 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
426 else if (aicon
->icon
->selected
)
427 wIconSelect(aicon
->icon
);
429 WMFreeArray(selectedIcons
);
432 wMessageDialog(dock
->screen_ptr
, _("Warning"),
433 _("Some icons cannot be made omnipresent. "
434 "Please make sure that no other icon is "
435 "docked in the same positions on the other "
436 "workspaces and the Clip is not full in "
437 "some workspace."), _("OK"), NULL
, NULL
);
438 } else if (failed
== 1) {
439 wMessageDialog(dock
->screen_ptr
, _("Warning"),
440 _("Icon cannot be made omnipresent. "
441 "Please make sure that no other icon is "
442 "docked in the same position on the other "
443 "workspaces and the Clip is not full in "
444 "some workspace."), _("OK"), NULL
, NULL
);
448 static void removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
450 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
453 WMArray
*selectedIcons
;
457 assert(clickedIcon
!= NULL
);
459 dock
= clickedIcon
->dock
;
461 selectedIcons
= getSelected(dock
);
463 if (WMGetArrayItemCount(selectedIcons
)) {
464 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
465 _("All selected icons will be removed!"),
466 _("OK"), _("Cancel"), NULL
) != WAPRDefault
) {
467 WMFreeArray(selectedIcons
);
471 if (clickedIcon
->xindex
== 0 && clickedIcon
->yindex
== 0) {
472 WMFreeArray(selectedIcons
);
475 WMAddToArray(selectedIcons
, clickedIcon
);
478 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
479 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
480 wDockDetach(dock
, aicon
);
482 /* XXX: can: aicon->icon == NULL ? */
483 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
484 wGetHeadForWindow(aicon
->icon
->owner
));
485 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
486 if (!dock
->mapped
|| dock
->collapsed
)
487 XMapWindow(dpy
, aicon
->icon
->core
->window
);
490 WMFreeArray(selectedIcons
);
492 if (wPreferences
.auto_arrange_icons
)
493 wArrangeIcons(dock
->screen_ptr
, True
);
496 static void keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
498 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
501 WMArray
*selectedIcons
;
504 assert(clickedIcon
!= NULL
);
505 dock
= clickedIcon
->dock
;
507 selectedIcons
= getSelected(dock
);
509 if (!WMGetArrayItemCount(selectedIcons
)
510 && clickedIcon
!= dock
->screen_ptr
->clip_icon
) {
511 char *command
= NULL
;
513 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
514 clickedIcon
->editing
= 1;
515 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
516 _("Type the command used to launch the application"), &command
)) {
517 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
521 clickedIcon
->command
= command
;
522 clickedIcon
->editing
= 0;
524 clickedIcon
->editing
= 0;
527 WMFreeArray(selectedIcons
);
532 WMAddToArray(selectedIcons
, clickedIcon
);
535 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
536 if (aicon
->icon
->selected
)
537 wIconSelect(aicon
->icon
);
539 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
540 aicon
->attracted
= 0;
541 if (aicon
->icon
->shadowed
) {
542 aicon
->icon
->shadowed
= 0;
544 /* Update the icon images */
545 wIconUpdate(aicon
->icon
);
548 wAppIconPaint(aicon
);
551 save_appicon(aicon
, True
);
553 WMFreeArray(selectedIcons
);
556 static void toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
558 WDock
*dock
= (WDock
*) entry
->clientdata
;
560 assert(entry
->clientdata
!= NULL
);
562 dock
->attract_icons
= !dock
->attract_icons
;
564 entry
->flags
.indicator_on
= dock
->attract_icons
;
569 static void selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
571 WAppIcon
*icon
= (WAppIcon
*) entry
->clientdata
;
573 assert(icon
!= NULL
);
575 wIconSelect(icon
->icon
);
580 static void colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
582 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
585 int x
, y
, x_pos
, y_pos
;
586 Bool update_icon
= False
;
588 assert(entry
->clientdata
!= NULL
);
589 clip
= clickedIcon
->dock
;
591 aicon
= clip
->screen_ptr
->app_icon_list
;
594 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
595 x_pos
= clip
->x_pos
+ x
* ICON_SIZE
;
596 y_pos
= clip
->y_pos
+ y
* ICON_SIZE
;
597 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
)
598 move_window(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
600 aicon
->attracted
= 1;
601 if (!aicon
->icon
->shadowed
) {
602 aicon
->icon
->shadowed
= 1;
605 wDockAttachIcon(clip
, aicon
, x
, y
, update_icon
);
606 if (clip
->collapsed
|| !clip
->mapped
)
607 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
613 static void selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
615 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
617 WMArray
*selectedIcons
;
618 WMArrayIterator iter
;
622 assert(clickedIcon
!= NULL
);
623 dock
= clickedIcon
->dock
;
625 selectedIcons
= getSelected(dock
);
627 if (!WMGetArrayItemCount(selectedIcons
)) {
628 for (i
= 1; i
< dock
->max_icons
; i
++) {
629 btn
= dock
->icon_array
[i
];
630 if (btn
&& !btn
->icon
->selected
)
631 wIconSelect(btn
->icon
);
634 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
635 wIconSelect(btn
->icon
);
638 WMFreeArray(selectedIcons
);
643 static void toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
645 assert(entry
->clientdata
!= NULL
);
647 toggleCollapsed(entry
->clientdata
);
649 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->collapsed
;
654 static void toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
657 assert(entry
->clientdata
!= NULL
);
659 dock
= (WDock
*) entry
->clientdata
;
661 dock
->auto_collapse
= !dock
->auto_collapse
;
663 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_collapse
;
668 static void toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
671 assert(entry
->clientdata
!= NULL
);
673 dock
= (WDock
*) entry
->clientdata
;
675 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
677 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_raise_lower
;
682 static void launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
684 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
686 launchDockedApplication(btn
, False
);
689 static void settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
691 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
695 ShowDockAppSettingsPanel(btn
);
698 static void hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
701 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
703 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
705 if (wapp
->flags
.hidden
) {
706 wWorkspaceChange(btn
->icon
->core
->screen_ptr
, wapp
->last_workspace
);
707 wUnhideApplication(wapp
, False
, False
);
709 wHideApplication(wapp
);
713 static void unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
716 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
718 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
720 wUnhideApplication(wapp
, False
, True
);
723 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
)
728 if (type
== WM_CLIP
) {
730 return scr
->clip_icon
;
731 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
732 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
733 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
734 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
737 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
738 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
744 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
745 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
746 btn
->icon
->core
->descriptor
.parent
= btn
;
747 XMapWindow(dpy
, btn
->icon
->core
->window
);
752 scr
->clip_icon
= btn
;
757 static void switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
759 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
760 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
762 WMArray
*selectedIcons
;
765 if (entry
->order
== scr
->current_workspace
)
768 dest
= scr
->workspaces
[entry
->order
]->clip
;
770 selectedIcons
= getSelected(src
);
772 if (WMGetArrayItemCount(selectedIcons
)) {
773 WMArrayIterator iter
;
775 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
776 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
777 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
778 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
781 } else if (icon
!= scr
->clip_icon
) {
782 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
783 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
784 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
787 WMFreeArray(selectedIcons
);
790 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
)
792 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
794 if (!btn
->launching
&&
795 ((!withSelection
&& btn
->command
!= NULL
) || (withSelection
&& btn
->paste_command
!= NULL
))) {
796 if (!btn
->forced_dock
) {
797 btn
->relaunching
= btn
->running
;
800 if (btn
->wm_instance
|| btn
->wm_class
) {
801 WWindowAttributes attr
;
802 memset(&attr
, 0, sizeof(WWindowAttributes
));
803 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
805 if (!attr
.no_appicon
&& !btn
->buggy_app
)
810 btn
->drop_launch
= 0;
811 btn
->paste_launch
= withSelection
;
812 scr
->last_dock
= btn
->dock
;
813 btn
->pid
= execCommand(btn
, (withSelection
? btn
->paste_command
: btn
->command
), NULL
);
815 if (btn
->buggy_app
) {
816 /* give feedback that the app was launched */
820 WMAddTimerHandler(200, (WMCallback
*) dockIconPaint
, btn
);
825 wwarning(_("could not launch application %s"), btn
->command
);
827 if (!btn
->relaunching
)
833 static void updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
835 WScreen
*scr
= menu
->frame
->screen_ptr
;
836 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
842 for (i
= 0; i
< scr
->workspace_count
; i
++) {
843 if (i
< menu
->entry_no
) {
844 if (strcmp(menu
->entries
[i
]->text
, scr
->workspaces
[i
]->name
) != 0) {
845 wfree(menu
->entries
[i
]->text
);
846 strcpy(title
, scr
->workspaces
[i
]->name
);
847 menu
->entries
[i
]->text
= wstrdup(title
);
848 menu
->flags
.realized
= 0;
850 menu
->entries
[i
]->clientdata
= (void *)icon
;
852 strcpy(title
, scr
->workspaces
[i
]->name
);
854 wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)icon
);
856 menu
->flags
.realized
= 0;
859 if (i
== scr
->current_workspace
)
860 wMenuSetEnabled(menu
, i
, False
);
862 wMenuSetEnabled(menu
, i
, True
);
865 if (!menu
->flags
.realized
)
869 static WMenu
*makeWorkspaceMenu(WScreen
*scr
)
873 menu
= wMenuCreate(scr
, NULL
, False
);
875 wwarning(_("could not create workspace submenu for Clip menu"));
877 wMenuAddCallback(menu
, "", switchWSCommand
, (void *)scr
->clip_icon
);
879 menu
->flags
.realized
= 0;
885 static void updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
894 entry
= menu
->entries
[index
];
895 entry
->flags
.indicator_on
= !dock
->lowered
;
896 entry
->clientdata
= dock
;
899 entry
= menu
->entries
[++index
];
900 entry
->flags
.indicator_on
= dock
->collapsed
;
901 entry
->clientdata
= dock
;
904 entry
= menu
->entries
[++index
];
905 entry
->flags
.indicator_on
= dock
->auto_collapse
;
906 entry
->clientdata
= dock
;
908 /* auto-raise/lower */
909 entry
= menu
->entries
[++index
];
910 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
911 entry
->clientdata
= dock
;
912 wMenuSetEnabled(menu
, index
, dock
->lowered
);
915 entry
= menu
->entries
[++index
];
916 entry
->flags
.indicator_on
= dock
->attract_icons
;
917 entry
->clientdata
= dock
;
919 menu
->flags
.realized
= 0;
923 static WMenu
*makeClipOptionsMenu(WScreen
*scr
)
928 menu
= wMenuCreate(scr
, NULL
, False
);
930 wwarning(_("could not create options submenu for Clip menu"));
934 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
935 entry
->flags
.indicator
= 1;
936 entry
->flags
.indicator_on
= 1;
937 entry
->flags
.indicator_type
= MI_CHECK
;
939 entry
= wMenuAddCallback(menu
, _("Collapsed"), toggleCollapsedCallback
, NULL
);
940 entry
->flags
.indicator
= 1;
941 entry
->flags
.indicator_on
= 1;
942 entry
->flags
.indicator_type
= MI_CHECK
;
944 entry
= wMenuAddCallback(menu
, _("Autocollapse"), toggleAutoCollapseCallback
, NULL
);
945 entry
->flags
.indicator
= 1;
946 entry
->flags
.indicator_on
= 1;
947 entry
->flags
.indicator_type
= MI_CHECK
;
949 entry
= wMenuAddCallback(menu
, _("Autoraise"), toggleAutoRaiseLowerCallback
, NULL
);
950 entry
->flags
.indicator
= 1;
951 entry
->flags
.indicator_on
= 1;
952 entry
->flags
.indicator_type
= MI_CHECK
;
954 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"), toggleAutoAttractCallback
, NULL
);
955 entry
->flags
.indicator
= 1;
956 entry
->flags
.indicator_on
= 1;
957 entry
->flags
.indicator_type
= MI_CHECK
;
959 menu
->flags
.realized
= 0;
965 static WMenu
*dockMenuCreate(WScreen
*scr
, int type
)
970 if (type
== WM_CLIP
&& scr
->clip_menu
)
971 return scr
->clip_menu
;
973 menu
= wMenuCreate(scr
, NULL
, False
);
974 if (type
!= WM_CLIP
) {
975 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
976 entry
->flags
.indicator
= 1;
977 entry
->flags
.indicator_on
= 1;
978 entry
->flags
.indicator_type
= MI_CHECK
;
980 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
981 scr
->clip_options
= makeClipOptionsMenu(scr
);
982 if (scr
->clip_options
)
983 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
985 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
987 entry
->text
= _("Rename Workspace");
989 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
990 entry
->flags
.indicator
= 1;
991 entry
->flags
.indicator_on
= 1;
992 entry
->flags
.indicator_type
= MI_CHECK
;
994 entry
= wMenuAddCallback(menu
, _("Select All Icons"), selectIconsCallback
, NULL
);
996 entry
->text
= _("Select All Icons");
998 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1000 entry
->text
= _("Keep Icon");
1002 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1004 entry
->text
= _("Move Icon To");
1005 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1006 if (scr
->clip_submenu
)
1007 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1009 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
, NULL
);
1011 entry
->text
= _("Remove Icon");
1013 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1016 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1018 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1020 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1022 entry
->text
= _("Hide");
1024 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1026 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1028 if (type
== WM_CLIP
)
1029 scr
->clip_menu
= menu
;
1034 WDock
*wDockCreate(WScreen
*scr
, int type
)
1041 dock
= wmalloc(sizeof(WDock
));
1043 dock
->max_icons
= DOCK_MAX_ICONS
;
1045 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * dock
->max_icons
);
1047 btn
= mainIconCreate(scr
, type
);
1051 dock
->x_pos
= btn
->x_pos
;
1052 dock
->y_pos
= btn
->y_pos
;
1053 dock
->screen_ptr
= scr
;
1055 dock
->icon_count
= 1;
1056 dock
->on_right_side
= 1;
1057 dock
->collapsed
= 0;
1058 dock
->auto_collapse
= 0;
1059 dock
->auto_collapse_magic
= NULL
;
1060 dock
->auto_raise_lower
= 0;
1061 dock
->auto_lower_magic
= NULL
;
1062 dock
->auto_raise_magic
= NULL
;
1063 dock
->attract_icons
= 0;
1065 dock
->icon_array
[0] = btn
;
1066 wRaiseFrame(btn
->icon
->core
);
1067 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1069 /* create dock menu */
1070 dock
->menu
= dockMenuCreate(scr
, type
);
1075 void wDockDestroy(WDock
*dock
)
1080 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1081 aicon
= dock
->icon_array
[i
];
1083 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1084 wDockDetach(dock
, aicon
);
1086 /* XXX: can: aicon->icon == NULL ? */
1087 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1088 wGetHeadForWindow(aicon
->icon
->owner
));
1089 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1090 if (!dock
->mapped
|| dock
->collapsed
)
1091 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1095 if (wPreferences
.auto_arrange_icons
)
1096 wArrangeIcons(dock
->screen_ptr
, True
);
1097 wfree(dock
->icon_array
);
1098 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1099 wMenuDestroy(dock
->menu
, True
);
1100 if (dock
->screen_ptr
->last_dock
== dock
)
1101 dock
->screen_ptr
->last_dock
= NULL
;
1105 void wClipIconPaint(WAppIcon
*aicon
)
1107 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1108 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1110 Window win
= aicon
->icon
->core
->window
;
1111 int length
, nlength
;
1112 char *ws_name
, ws_number
[10];
1115 wIconPaint(aicon
->icon
);
1117 length
= strlen(workspace
->name
);
1118 ws_name
= wmalloc(length
+ 1);
1119 snprintf(ws_name
, length
+ 1, "%s", workspace
->name
);
1120 snprintf(ws_number
, sizeof(ws_number
), "%i", scr
->current_workspace
+ 1);
1121 nlength
= strlen(ws_number
);
1123 if (!workspace
->clip
->collapsed
)
1124 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1126 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1128 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1130 tx
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
1132 if(wPreferences
.show_clip_title
)
1133 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, ty
, ws_name
, length
);
1135 tx
= (ICON_SIZE
/ 2 - WMWidthOfString(scr
->clip_title_font
, ws_number
, nlength
)) / 2;
1137 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, 2, ws_number
, nlength
);
1141 if (aicon
->launching
)
1142 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1143 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1145 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
, aicon
->dock
->rclip_button_pushed
);
1148 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1150 wClipIconPaint(desc
->parent
);
1153 static void dockIconPaint(WAppIcon
*btn
)
1155 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
) {
1156 wClipIconPaint(btn
);
1159 save_appicon(btn
, True
);
1163 static WMPropList
*make_icon_state(WAppIcon
*btn
)
1165 WMPropList
*node
= NULL
;
1166 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
;
1167 WMPropList
*position
, *buggy
, *omnipresent
;
1173 command
= WMCreatePLString("-");
1175 command
= WMCreatePLString(btn
->command
);
1177 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1179 lock
= btn
->lock
? dYes
: dNo
;
1181 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1183 name
= WMCreatePLString(tmp
);
1187 forced
= btn
->forced_dock
? dYes
: dNo
;
1189 buggy
= btn
->buggy_app
? dYes
: dNo
;
1191 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1192 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1194 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1195 position
= WMCreatePLString(buffer
);
1197 node
= WMCreatePLDictionary(dCommand
, command
,
1199 dAutoLaunch
, autolaunch
,
1201 dForced
, forced
, dBuggyApplication
, buggy
, dPosition
, position
, NULL
);
1202 WMReleasePropList(command
);
1203 WMReleasePropList(name
);
1204 WMReleasePropList(position
);
1206 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1207 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&& (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1208 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1210 #ifdef XDND /* was OFFIX */
1211 if (btn
->dnd_command
) {
1212 command
= WMCreatePLString(btn
->dnd_command
);
1213 WMPutInPLDictionary(node
, dDropCommand
, command
);
1214 WMReleasePropList(command
);
1218 if (btn
->paste_command
) {
1219 command
= WMCreatePLString(btn
->paste_command
);
1220 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1221 WMReleasePropList(command
);
1228 static WMPropList
*dockSaveState(WDock
*dock
)
1231 WMPropList
*icon_info
;
1232 WMPropList
*list
= NULL
, *dock_state
= NULL
;
1233 WMPropList
*value
, *key
;
1236 list
= WMCreatePLArray(NULL
);
1238 for (i
= (dock
->type
== WM_DOCK
? 0 : 1); i
< dock
->max_icons
; i
++) {
1239 WAppIcon
*btn
= dock
->icon_array
[i
];
1241 if (!btn
|| btn
->attracted
)
1244 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1245 WMAddToPLArray(list
, icon_info
);
1246 WMReleasePropList(icon_info
);
1250 dock_state
= WMCreatePLDictionary(dApplications
, list
, NULL
);
1252 if (dock
->type
== WM_DOCK
) {
1253 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1254 key
= WMCreatePLString(buffer
);
1255 WMPutInPLDictionary(dock_state
, key
, list
);
1256 WMReleasePropList(key
);
1258 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0), dock
->y_pos
);
1259 value
= WMCreatePLString(buffer
);
1260 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1261 WMReleasePropList(value
);
1263 WMReleasePropList(list
);
1265 value
= (dock
->lowered
? dYes
: dNo
);
1266 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1268 if (dock
->type
== WM_CLIP
) {
1269 value
= (dock
->collapsed
? dYes
: dNo
);
1270 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1272 value
= (dock
->auto_collapse
? dYes
: dNo
);
1273 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1275 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1276 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1278 value
= (dock
->attract_icons
? dYes
: dNo
);
1279 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1285 void wDockSaveState(WScreen
*scr
, WMPropList
*old_state
)
1287 WMPropList
*dock_state
;
1290 dock_state
= dockSaveState(scr
->dock
);
1293 * Copy saved states of docks with different sizes.
1299 keys
= WMGetPLDictionaryKeys(old_state
);
1300 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1301 tmp
= WMGetFromPLArray(keys
, i
);
1303 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1304 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1306 WMPutInPLDictionary(dock_state
, tmp
, WMGetFromPLDictionary(old_state
, tmp
));
1309 WMReleasePropList(keys
);
1312 WMPutInPLDictionary(scr
->session_state
, dDock
, dock_state
);
1314 WMReleasePropList(dock_state
);
1317 void wClipSaveState(WScreen
*scr
)
1319 WMPropList
*clip_state
;
1321 clip_state
= make_icon_state(scr
->clip_icon
);
1323 WMPutInPLDictionary(scr
->session_state
, dClip
, clip_state
);
1325 WMReleasePropList(clip_state
);
1328 WMPropList
*wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1330 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1333 static Bool
getBooleanDockValue(WMPropList
*value
, WMPropList
*key
)
1336 if (WMIsPLString(value
)) {
1337 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1340 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1346 static WAppIcon
*restore_icon_state(WScreen
*scr
, WMPropList
*info
, int type
, int index
)
1349 WMPropList
*cmd
, *value
;
1350 char *wclass
, *winstance
, *command
;
1352 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1353 if (!cmd
|| !WMIsPLString(cmd
))
1356 /* parse window name */
1357 value
= WMGetFromPLDictionary(info
, dName
);
1361 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1363 if (!winstance
&& !wclass
)
1368 command
= wstrdup(WMGetFromPLString(cmd
));
1372 if (!command
|| strcmp(command
, "-") == 0) {
1383 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1391 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1392 if (type
== WM_CLIP
) {
1393 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1394 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1396 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1397 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1399 #ifdef XDND /* was OFFIX */
1400 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1402 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1405 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1407 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1409 /* check auto launch */
1410 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1412 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1415 value
= WMGetFromPLDictionary(info
, dLock
);
1417 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1419 /* check if it wasn't normally docked */
1420 value
= WMGetFromPLDictionary(info
, dForced
);
1422 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1424 /* check if we can rely on the stuff in the app */
1425 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1427 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1429 /* get position in the dock */
1430 value
= WMGetFromPLDictionary(info
, dPosition
);
1431 if (value
&& WMIsPLString(value
)) {
1432 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1433 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1435 /* check position sanity */
1436 /* incomplete section! */
1437 if (type
== WM_DOCK
) {
1439 if (aicon
->yindex
< 0)
1440 wwarning(_("bad value in docked icon position %i,%i"),
1441 aicon
->xindex
, aicon
->yindex
);
1444 aicon
->yindex
= index
;
1448 /* check if icon is omnipresent */
1449 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1451 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1459 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1461 WAppIcon
*wClipRestoreState(WScreen
*scr
, WMPropList
*clip_state
)
1466 icon
= mainIconCreate(scr
, WM_CLIP
);
1471 WMRetainPropList(clip_state
);
1473 /* restore position */
1475 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1478 if (!WMIsPLString(value
)) {
1479 COMPLAIN("Position");
1484 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1485 COMPLAIN("Position");
1487 /* check position sanity */
1488 rect
.pos
.x
= icon
->x_pos
;
1489 rect
.pos
.y
= icon
->y_pos
;
1490 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1492 wGetRectPlacementInfo(scr
, rect
, &flags
);
1493 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
1494 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1497 #ifdef XDND /* was OFFIX */
1498 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1499 if (value
&& WMIsPLString(value
))
1500 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1503 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1504 if (value
&& WMIsPLString(value
))
1505 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1507 WMReleasePropList(clip_state
);
1512 WDock
*wDockRestoreState(WScreen
*scr
, WMPropList
*dock_state
, int type
)
1517 WAppIcon
*aicon
, *old_top
;
1520 dock
= wDockCreate(scr
, type
);
1525 WMRetainPropList(dock_state
);
1527 /* restore position */
1528 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1530 if (!WMIsPLString(value
)) {
1531 COMPLAIN("Position");
1536 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1537 COMPLAIN("Position");
1539 /* check position sanity */
1540 rect
.pos
.x
= dock
->x_pos
;
1541 rect
.pos
.y
= dock
->y_pos
;
1542 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1544 wGetRectPlacementInfo(scr
, rect
, &flags
);
1545 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
)) {
1546 int x
= dock
->x_pos
;
1547 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1550 /* Is this needed any more? */
1551 if (type
== WM_CLIP
) {
1552 if (dock
->x_pos
< 0) {
1554 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1555 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1558 if (dock
->x_pos
>= 0) {
1559 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1560 dock
->on_right_side
= 0;
1562 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1563 dock
->on_right_side
= 1;
1569 /* restore lowered/raised state */
1572 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1574 if (!WMIsPLString(value
)) {
1575 COMPLAIN("Lowered");
1577 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1582 /* restore collapsed state */
1583 dock
->collapsed
= 0;
1585 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1587 if (!WMIsPLString(value
)) {
1588 COMPLAIN("Collapsed");
1590 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1591 dock
->collapsed
= 1;
1595 /* restore auto-collapsed state */
1596 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1598 if (!WMIsPLString(value
)) {
1599 COMPLAIN("AutoCollapse");
1601 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1602 dock
->auto_collapse
= 1;
1603 dock
->collapsed
= 1;
1608 /* restore auto-raise/lower state */
1609 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1611 if (!WMIsPLString(value
)) {
1612 COMPLAIN("AutoRaiseLower");
1614 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1615 dock
->auto_raise_lower
= 1;
1619 /* restore attract icons state */
1620 dock
->attract_icons
= 0;
1622 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1624 if (!WMIsPLString(value
)) {
1625 COMPLAIN("AutoAttractIcons");
1627 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1628 dock
->attract_icons
= 1;
1632 /* application list */
1639 * When saving, it saves the dock state in
1640 * Applications and Applicationsnnn
1642 * When loading, it will first try Applicationsnnn.
1643 * If it does not exist, use Applications as default.
1646 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1648 tmp
= WMCreatePLString(buffer
);
1649 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1650 WMReleasePropList(tmp
);
1653 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1659 count
= WMGetPropListItemCount(apps
);
1663 old_top
= dock
->icon_array
[0];
1665 /* dock->icon_count is set to 1 when dock is created.
1666 * Since Clip is already restored, we want to keep it so for clip,
1667 * but for dock we may change the default top tile, so we set it to 0.
1669 if (type
== WM_DOCK
)
1670 dock
->icon_count
= 0;
1672 for (i
= 0; i
< count
; i
++) {
1673 if (dock
->icon_count
>= dock
->max_icons
) {
1674 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1678 value
= WMGetFromPLArray(apps
, i
);
1679 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1681 dock
->icon_array
[dock
->icon_count
] = aicon
;
1685 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1686 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1689 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1691 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1693 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1694 if (!dock
->collapsed
)
1695 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1697 wRaiseFrame(aicon
->icon
->core
);
1700 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
) {
1705 /* if the first icon is not defined, use the default */
1706 if (dock
->icon_array
[0] == NULL
) {
1707 /* update default icon */
1708 old_top
->x_pos
= dock
->x_pos
;
1709 old_top
->y_pos
= dock
->y_pos
;
1711 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1713 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1715 dock
->icon_array
[0] = old_top
;
1716 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1717 /* we don't need to increment dock->icon_count here because it was
1718 * incremented in the loop above.
1720 } else if (old_top
!= dock
->icon_array
[0]) {
1721 if (old_top
== scr
->clip_icon
)
1722 scr
->clip_icon
= dock
->icon_array
[0];
1724 wAppIconDestroy(old_top
);
1728 WMReleasePropList(dock_state
);
1733 void wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1735 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1736 btn
->drop_launch
= 0;
1737 btn
->paste_launch
= 0;
1739 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1742 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1752 void wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1758 for (i
= 0; i
< dock
->max_icons
; i
++) {
1759 btn
= dock
->icon_array
[i
];
1760 if (!btn
|| !btn
->auto_launch
)
1763 state
= wmalloc(sizeof(WSavedState
));
1764 state
->workspace
= workspace
;
1765 /* TODO: this is klugy and is very difficult to understand
1766 * what's going on. Try to clean up */
1767 wDockLaunchWithState(dock
, btn
, state
);
1771 #ifdef XDND /* was OFFIX */
1772 static WDock
*findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1778 if ((dock
= scr
->dock
) != NULL
) {
1779 for (i
= 0; i
< dock
->max_icons
; i
++) {
1780 if (dock
->icon_array
[i
]
1781 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1787 if (*icon_pos
< 0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
) != NULL
) {
1788 for (i
= 0; i
< dock
->max_icons
; i
++) {
1789 if (dock
->icon_array
[i
]
1790 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1801 int wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
1807 dock
= findDock(scr
, event
, &icon_pos
);
1812 * Return True if the drop was on an application icon window.
1813 * In this case, let the ClientMessage handler redirect the
1814 * message to the app.
1816 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
1819 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
1820 scr
->flags
.dnd_data_convertion_status
= 0;
1822 btn
= dock
->icon_array
[icon_pos
];
1824 if (!btn
->forced_dock
) {
1825 btn
->relaunching
= btn
->running
;
1828 if (btn
->wm_instance
|| btn
->wm_class
) {
1829 WWindowAttributes attr
;
1830 memset(&attr
, 0, sizeof(WWindowAttributes
));
1831 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
1833 if (!attr
.no_appicon
)
1839 btn
->paste_launch
= 0;
1840 btn
->drop_launch
= 1;
1841 scr
->last_dock
= dock
;
1842 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1847 if (!btn
->relaunching
)
1855 Bool
wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
, Bool update_icon
)
1858 Bool lupdate_icon
= False
;
1859 char *command
= NULL
;
1865 lupdate_icon
= True
;
1867 if (icon
->command
== NULL
) {
1868 /* If icon->owner exists, it means the application is running */
1869 if (icon
->icon
->owner
) {
1870 wwin
= icon
->icon
->owner
;
1871 command
= GetCommandForWindow(wwin
->client_win
);
1875 icon
->command
= command
;
1877 /* icon->forced_dock = 1; */
1878 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
1880 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
1881 _("Type the command used to launch the application"), &command
)) {
1882 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
1886 icon
->command
= command
;
1892 /* If the target is the dock, reject the icon. If
1893 * the target is the clip, make it an attracted icon
1895 if (dock
->type
== WM_CLIP
) {
1896 icon
->attracted
= 1;
1897 if (!icon
->icon
->shadowed
) {
1898 icon
->icon
->shadowed
= 1;
1899 lupdate_icon
= True
;
1909 for (index
= 1; index
< dock
->max_icons
; index
++)
1910 if (dock
->icon_array
[index
] == NULL
)
1912 /* if (index == dock->max_icons)
1915 assert(index
< dock
->max_icons
);
1917 dock
->icon_array
[index
] = icon
;
1921 icon
->omnipresent
= 0;
1923 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
1924 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
1929 icon
->launching
= 0;
1932 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1933 if (dock
->type
== WM_CLIP
) {
1934 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1935 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1937 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1938 icon
->icon
->core
->descriptor
.parent
= icon
;
1940 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
1941 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
1943 /* Update the icon images */
1945 wIconUpdate(icon
->icon
);
1948 wAppIconPaint(icon
);
1951 save_appicon(icon
, True
);
1953 if (wPreferences
.auto_arrange_icons
)
1954 wArrangeIcons(dock
->screen_ptr
, True
);
1956 #ifdef XDND /* was OFFIX */
1957 if (icon
->command
&& !icon
->dnd_command
) {
1958 int len
= strlen(icon
->command
) + 8;
1959 icon
->dnd_command
= wmalloc(len
);
1960 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
1964 if (icon
->command
&& !icon
->paste_command
) {
1965 int len
= strlen(icon
->command
) + 8;
1966 icon
->paste_command
= wmalloc(len
);
1967 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
1973 static void reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1977 for (index
= 1; index
< dock
->max_icons
; index
++) {
1978 if (dock
->icon_array
[index
] == icon
)
1981 assert(index
< dock
->max_icons
);
1986 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
1987 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
1990 static Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
1993 char *command
= NULL
;
1995 Bool update_icon
= False
;
1998 return True
; /* No move needed, we're already there */
2004 * For the moment we can't do this if we move icons in Clip from one
2005 * workspace to other, because if we move two or more icons without
2006 * command, the dialog box will not be able to tell us to which of the
2007 * moved icons it applies. -Dan
2009 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
2010 /* If icon->owner exists, it means the application is running */
2011 if (icon
->icon
->owner
) {
2012 wwin
= icon
->icon
->owner
;
2013 command
= GetCommandForWindow(wwin
->client_win
);
2017 icon
->command
= command
;
2020 /* icon->forced_dock = 1; */
2021 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2022 _("Type the command used to launch the application"), &command
)) {
2023 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2027 icon
->command
= command
;
2038 if (dest
->type
== WM_DOCK
)
2039 wClipMakeIconOmnipresent(icon
, False
);
2041 for (index
= 1; index
< src
->max_icons
; index
++) {
2042 if (src
->icon_array
[index
] == icon
)
2045 assert(index
< src
->max_icons
);
2047 src
->icon_array
[index
] = NULL
;
2050 for (index
= 1; index
< dest
->max_icons
; index
++) {
2051 if (dest
->icon_array
[index
] == NULL
)
2055 assert(index
< dest
->max_icons
);
2057 dest
->icon_array
[index
] = icon
;
2060 /* deselect the icon */
2061 if (icon
->icon
->selected
)
2062 wIconSelect(icon
->icon
);
2064 if (dest
->type
== WM_DOCK
) {
2065 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2066 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2068 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2069 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2072 /* set it to be kept when moving to dock.
2073 * Unless the icon does not have a command set
2075 if (icon
->command
&& dest
->type
== WM_DOCK
) {
2076 icon
->attracted
= 0;
2077 if (icon
->icon
->shadowed
) {
2078 icon
->icon
->shadowed
= 0;
2081 save_appicon(icon
, True
);
2084 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2090 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2091 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2095 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2097 /* Update the icon images */
2099 wIconUpdate(icon
->icon
);
2102 wAppIconPaint(icon
);
2107 void wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2110 Bool update_icon
= False
;
2112 /* make the settings panel be closed */
2114 DestroyDockAppSettingsPanel(icon
->panel
);
2116 /* This must be called before icon->dock is set to NULL.
2117 * Don't move it. -Dan
2119 wClipMakeIconOmnipresent(icon
, False
);
2123 icon
->attracted
= 0;
2124 icon
->auto_launch
= 0;
2125 if (icon
->icon
->shadowed
) {
2126 icon
->icon
->shadowed
= 0;
2130 /* deselect the icon */
2131 if (icon
->icon
->selected
)
2132 wIconSelect(icon
->icon
);
2134 if (icon
->command
) {
2135 wfree(icon
->command
);
2136 icon
->command
= NULL
;
2138 #ifdef XDND /* was OFFIX */
2139 if (icon
->dnd_command
) {
2140 wfree(icon
->dnd_command
);
2141 icon
->dnd_command
= NULL
;
2144 if (icon
->paste_command
) {
2145 wfree(icon
->paste_command
);
2146 icon
->paste_command
= NULL
;
2149 for (index
= 1; index
< dock
->max_icons
; index
++)
2150 if (dock
->icon_array
[index
] == icon
)
2153 assert(index
< dock
->max_icons
);
2154 dock
->icon_array
[index
] = NULL
;
2160 /* if the dock is not attached to an application or
2161 * the application did not set the appropriate hints yet,
2162 * destroy the icon */
2163 if (!icon
->running
|| !wApplicationOf(icon
->main_window
)) {
2164 wAppIconDestroy(icon
);
2166 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2167 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2168 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2169 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2170 icon
->icon
->core
->descriptor
.parent
= icon
;
2172 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2174 /* Update the icon images */
2176 wIconUpdate(icon
->icon
);
2179 wAppIconPaint(icon
);
2181 if (wPreferences
.auto_arrange_icons
)
2182 wArrangeIcons(dock
->screen_ptr
, True
);
2184 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2189 * returns the closest Dock slot index for the passed
2192 * Returns False if icon can't be docked.
2194 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2197 Bool
wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2199 WScreen
*scr
= dock
->screen_ptr
;
2202 int i
, offset
= ICON_SIZE
/ 2;
2203 WAppIcon
*aicon
= NULL
;
2204 WAppIcon
*nicon
= NULL
;
2207 /* TODO: XINERAMA, for these */
2208 max_y_icons
= scr
->scr_height
/ ICON_SIZE
- 1;
2210 if (wPreferences
.flags
.noupdates
)
2216 /* if the dock is full */
2217 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
))
2220 /* exact position */
2222 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2224 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2227 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2229 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2231 /* check if the icon is outside the screen boundaries */
2236 rect
.pos
.x
= dx
+ ex_x
* ICON_SIZE
;
2237 rect
.pos
.y
= dy
+ ex_y
* ICON_SIZE
;
2238 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2240 wGetRectPlacementInfo(scr
, rect
, &flags
);
2241 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
2245 if (dock
->type
== WM_DOCK
) {
2246 if (icon
->dock
!= dock
&& ex_x
!= 0)
2250 for (i
= 0; i
< dock
->max_icons
; i
++) {
2251 nicon
= dock
->icon_array
[i
];
2252 if (nicon
&& nicon
->yindex
== ex_y
) {
2259 int sig
, done
, closest
;
2261 /* Possible cases when redocking:
2263 * icon dragged out of range of any slot -> false
2264 * icon dragged to range of free slot
2265 * icon dragged to range of same slot
2266 * icon dragged to range of different icon
2268 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2271 if (ex_y
>= 0 && ex_y
<= max_y_icons
&& (aicon
== icon
|| !aicon
)) {
2277 /* start looking at the upper slot or lower? */
2278 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2285 /* look for closest free slot */
2286 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2290 closest
= sig
* (i
/ 2) + ex_y
;
2291 /* check if this slot is used */
2293 for (j
= 0; j
< dock
->max_icons
; j
++) {
2294 if (dock
->icon_array
[j
]
2295 && dock
->icon_array
[j
]->yindex
== closest
) {
2296 /* slot is used by someone else */
2297 if (dock
->icon_array
[j
] != icon
)
2305 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2306 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2307 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2312 } else { /* !redocking */
2314 /* if slot is free and the icon is close enough, return it */
2315 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2325 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2326 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+ 1;
2329 for (k
= start
; k
< stop
; k
++) {
2330 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2333 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2334 nicon
= tmp
->icon_array
[i
];
2335 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2343 for (k
= start
; k
< stop
; k
++) {
2344 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2347 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2348 nicon
= tmp
->icon_array
[i
];
2349 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2350 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2351 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2360 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2369 static int onScreen(WScreen
*scr
, int x
, int y
, int sx
, int ex
, int sy
, int ey
)
2371 WMRect rect
= wmkrect(x
, y
, ICON_SIZE
, ICON_SIZE
);
2374 wGetRectPlacementInfo(scr
, rect
, &flags
);
2376 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2380 * returns true if it can find a free slot in the dock,
2381 * in which case it changes x_pos and y_pos accordingly.
2382 * Else returns false.
2384 Bool
wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2386 WScreen
*scr
= dock
->screen_ptr
;
2388 WAppIconChain
*chain
;
2389 unsigned char *slot_map
;
2393 int i
, done
= False
;
2395 int sx
= 0, sy
= 0, ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2396 int extra_count
= 0;
2398 if (dock
->type
== WM_CLIP
&& dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2399 extra_count
= scr
->global_icon_count
;
2401 /* if the dock is full */
2402 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
)
2405 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2406 if (scr
->dock
->on_right_side
)
2407 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2409 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2412 if (ex
< dock
->x_pos
)
2414 if (sx
> dock
->x_pos
+ ICON_SIZE
)
2415 sx
= dock
->x_pos
+ ICON_SIZE
;
2422 /* check if clip is in a corner */
2423 if (dock
->type
== WM_CLIP
) {
2424 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2426 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2428 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2430 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2438 /* If the clip is in the corner, use only slots that are in the border
2440 if (corner
!= C_NONE
) {
2444 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2445 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2446 hmap
= wmalloc(hcount
+ 1);
2447 vmap
= wmalloc(vcount
+ 1);
2449 /* mark used positions */
2452 for (i
= 0; i
< dock
->max_icons
; i
++) {
2453 btn
= dock
->icon_array
[i
];
2457 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2458 vmap
[btn
->yindex
] = 1;
2459 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2460 hmap
[btn
->xindex
] = 1;
2462 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2464 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2465 vmap
[btn
->yindex
] = 1;
2466 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2467 hmap
[btn
->xindex
] = 1;
2471 for (i
= 0; i
< dock
->max_icons
; i
++) {
2472 btn
= dock
->icon_array
[i
];
2476 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2477 vmap
[btn
->yindex
] = 1;
2478 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2479 hmap
[-btn
->xindex
] = 1;
2481 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2483 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2484 vmap
[btn
->yindex
] = 1;
2485 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2486 hmap
[-btn
->xindex
] = 1;
2490 for (i
= 0; i
< dock
->max_icons
; i
++) {
2491 btn
= dock
->icon_array
[i
];
2495 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2496 vmap
[-btn
->yindex
] = 1;
2497 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2498 hmap
[btn
->xindex
] = 1;
2500 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2502 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2503 vmap
[-btn
->yindex
] = 1;
2504 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2505 hmap
[btn
->xindex
] = 1;
2510 for (i
= 0; i
< dock
->max_icons
; i
++) {
2511 btn
= dock
->icon_array
[i
];
2515 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2516 vmap
[-btn
->yindex
] = 1;
2517 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2518 hmap
[-btn
->xindex
] = 1;
2520 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2522 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2523 vmap
[-btn
->yindex
] = 1;
2524 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2525 hmap
[-btn
->xindex
] = 1;
2531 /* search a vacant slot */
2532 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2533 if (i
< vcount
&& vmap
[i
] == 0) {
2539 } else if (i
< hcount
&& hmap
[i
] == 0) {
2549 /* If found a slot, translate and return */
2551 if (corner
== C_NW
|| corner
== C_NE
)
2556 if (corner
== C_NE
|| corner
== C_SE
)
2563 /* else, try to find a slot somewhere else */
2566 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2567 * placed outside of screen */
2568 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2570 /* In the worst case (the clip is in the corner of the screen),
2571 * the amount of icons that fit in the clip is smaller.
2572 * Double the map to get a safe value.
2576 r
= (mwidth
- 1) / 2;
2578 slot_map
= wmalloc(mwidth
* mwidth
);
2580 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2582 /* mark used slots in the map. If the slot falls outside the map
2583 * (for example, when all icons are placed in line), ignore them. */
2584 for (i
= 0; i
< dock
->max_icons
; i
++) {
2585 btn
= dock
->icon_array
[i
];
2587 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2590 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
)
2591 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2593 /* Find closest slot from the center that is free by scanning the
2594 * map from the center to outward in circular passes.
2595 * This will not result in a neat layout, but will be optimal
2596 * in the sense that there will not be holes left.
2599 for (i
= 1; i
<= r
&& !done
; i
++) {
2602 /* top and bottom parts of the ring */
2603 for (x
= -i
; x
<= i
&& !done
; x
++) {
2604 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2606 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2607 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2614 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2615 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2622 /* left and right parts of the ring */
2623 for (y
= -i
+ 1; y
<= i
- 1; y
++) {
2624 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2626 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2627 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2634 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2635 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2648 static void moveDock(WDock
*dock
, int new_x
, int new_y
)
2653 dock
->x_pos
= new_x
;
2654 dock
->y_pos
= new_y
;
2655 for (i
= 0; i
< dock
->max_icons
; i
++) {
2656 btn
= dock
->icon_array
[i
];
2658 btn
->x_pos
= new_x
+ btn
->xindex
* ICON_SIZE
;
2659 btn
->y_pos
= new_y
+ btn
->yindex
* ICON_SIZE
;
2660 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2665 static void swapDock(WDock
*dock
)
2667 WScreen
*scr
= dock
->screen_ptr
;
2671 if (dock
->on_right_side
)
2672 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2674 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2676 for (i
= 0; i
< dock
->max_icons
; i
++) {
2677 btn
= dock
->icon_array
[i
];
2680 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2684 wScreenUpdateUsableArea(scr
);
2687 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2689 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2695 cmdline
= ExpandOptions(scr
, command
);
2697 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2705 wtokensplit(cmdline
, &argv
, &argc
);
2715 if ((pid
= fork()) == 0) {
2719 SetupEnvironment(scr
);
2725 args
= malloc(sizeof(char *) * (argc
+ 1));
2729 for (i
= 0; i
< argc
; i
++)
2733 execvp(argv
[0], args
);
2736 wtokenfree(argv
, argc
);
2740 state
= wmalloc(sizeof(WSavedState
));
2742 state
->miniaturized
= -1;
2744 if (btn
->dock
== scr
->dock
|| btn
->omnipresent
)
2745 state
->workspace
= -1;
2747 state
->workspace
= scr
->current_workspace
;
2749 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
2750 wAddDeathHandler(pid
, (WDeathHandler
*) trackDeadProcess
, btn
->dock
);
2758 void wDockHideIcons(WDock
*dock
)
2765 for (i
= 1; i
< dock
->max_icons
; i
++) {
2766 if (dock
->icon_array
[i
])
2767 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2771 dockIconPaint(dock
->icon_array
[0]);
2774 void wDockShowIcons(WDock
*dock
)
2782 btn
= dock
->icon_array
[0];
2783 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2785 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2786 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2788 for (i
= 1; i
< dock
->max_icons
; i
++) {
2789 if (dock
->icon_array
[i
]) {
2790 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
, btn
->icon
->core
);
2795 if (!dock
->collapsed
) {
2796 for (i
= 1; i
< dock
->max_icons
; i
++) {
2797 if (dock
->icon_array
[i
])
2798 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2806 void wDockLower(WDock
*dock
)
2810 for (i
= 0; i
< dock
->max_icons
; i
++) {
2811 if (dock
->icon_array
[i
])
2812 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2816 void wDockRaise(WDock
*dock
)
2820 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
2821 if (dock
->icon_array
[i
])
2822 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2826 void wDockRaiseLower(WDock
*dock
)
2828 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2829 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2830 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2836 void wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
2838 icon
->launching
= 0;
2839 icon
->relaunching
= 0;
2840 dockIconPaint(icon
);
2843 WAppIcon
*wDockFindIconForWindow(WDock
*dock
, Window window
)
2848 for (i
= 0; i
< dock
->max_icons
; i
++) {
2849 icon
= dock
->icon_array
[i
];
2850 if (icon
&& icon
->main_window
== window
)
2856 void wDockTrackWindowLaunch(WDock
*dock
, Window window
)
2859 char *wm_class
, *wm_instance
;
2861 Bool firstPass
= True
;
2863 char *command
= NULL
;
2865 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) || (!wm_class
&& !wm_instance
))
2868 command
= GetCommandForWindow(window
);
2870 for (i
= 0; i
< dock
->max_icons
; i
++) {
2871 icon
= dock
->icon_array
[i
];
2875 /* app is already attached to icon */
2876 if (icon
->main_window
== window
) {
2881 if ((icon
->wm_instance
|| icon
->wm_class
)
2882 && (icon
->launching
|| !icon
->running
)) {
2884 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0)
2887 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0)
2890 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0)
2893 if (!icon
->relaunching
) {
2896 /* Possibly an application that was docked with dockit,
2897 * but the user did not update WMState to indicate that
2898 * it was docked by force */
2899 wapp
= wApplicationOf(window
);
2901 icon
->forced_dock
= 1;
2904 if (!icon
->forced_dock
)
2905 icon
->main_window
= window
;
2908 if (!wPreferences
.no_animations
&& !icon
->launching
&&
2909 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
2913 icon
->launching
= 1;
2914 dockIconPaint(icon
);
2916 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
2917 wm_instance
, wm_class
, TILE_NORMAL
);
2918 /* XXX: can: aicon->icon == NULL ? */
2919 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
2920 wAppIconMove(aicon
, x0
, y0
);
2921 /* Should this always be lowered? -Dan */
2923 wLowerFrame(aicon
->icon
->core
);
2924 XMapWindow(dpy
, aicon
->icon
->core
->window
);
2925 aicon
->launching
= 1;
2926 wAppIconPaint(aicon
);
2927 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
2928 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
2929 wAppIconDestroy(aicon
);
2931 wDockFinishLaunch(dock
, icon
);
2936 if (firstPass
&& !found
) {
2950 void wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
2952 if (!wPreferences
.flags
.noclip
) {
2953 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
2954 if (scr
->current_workspace
!= workspace
) {
2955 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
2956 WAppIconChain
*chain
= scr
->global_icons
;
2959 moveIconBetweenDocks(chain
->aicon
->dock
,
2960 scr
->workspaces
[workspace
]->clip
,
2961 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
2962 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
2963 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
2964 chain
= chain
->next
;
2967 wDockHideIcons(old_clip
);
2968 if (old_clip
->auto_raise_lower
) {
2969 if (old_clip
->auto_raise_magic
) {
2970 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
2971 old_clip
->auto_raise_magic
= NULL
;
2973 wDockLower(old_clip
);
2975 if (old_clip
->auto_collapse
) {
2976 if (old_clip
->auto_expand_magic
) {
2977 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
2978 old_clip
->auto_expand_magic
= NULL
;
2980 old_clip
->collapsed
= 1;
2982 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
2987 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
2992 for (i
= 0; i
< dock
->max_icons
; i
++) {
2993 icon
= dock
->icon_array
[i
];
2997 if (icon
->launching
&& icon
->pid
== pid
) {
2998 if (!icon
->relaunching
) {
3000 icon
->main_window
= None
;
3002 wDockFinishLaunch(dock
, icon
);
3004 if (status
== 111) {
3009 if (icon
->drop_launch
)
3010 cmd
= icon
->dnd_command
;
3013 if (icon
->paste_launch
)
3014 cmd
= icon
->paste_command
;
3016 cmd
= icon
->command
;
3018 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3020 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3027 static void toggleLowered(WDock
*dock
)
3032 /* lower/raise Dock */
3033 if (!dock
->lowered
) {
3034 newlevel
= WMNormalLevel
;
3037 newlevel
= WMDockLevel
;
3041 for (i
= 0; i
< dock
->max_icons
; i
++) {
3042 tmp
= dock
->icon_array
[i
];
3046 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3048 wLowerFrame(tmp
->icon
->core
);
3051 if (dock
->type
== WM_DOCK
)
3052 wScreenUpdateUsableArea(dock
->screen_ptr
);
3055 static void toggleCollapsed(WDock
*dock
)
3057 if (dock
->collapsed
) {
3058 dock
->collapsed
= 0;
3059 wDockShowIcons(dock
);
3061 dock
->collapsed
= 1;
3062 wDockHideIcons(dock
);
3066 static void openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3068 WScreen
*scr
= dock
->screen_ptr
;
3069 WObjDescriptor
*desc
;
3071 WApplication
*wapp
= NULL
;
3075 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3077 if (dock
->type
== WM_DOCK
) {
3079 entry
= dock
->menu
->entries
[index
];
3080 entry
->flags
.indicator_on
= !dock
->lowered
;
3081 entry
->clientdata
= dock
;
3082 dock
->menu
->flags
.realized
= 0;
3085 if (scr
->clip_options
)
3086 updateClipOptionsMenu(scr
->clip_options
, dock
);
3088 n_selected
= numberOfSelectedIcons(dock
);
3090 /* Rename Workspace */
3091 entry
= dock
->menu
->entries
[++index
];
3092 if (aicon
== scr
->clip_icon
) {
3093 entry
->callback
= renameCallback
;
3094 entry
->clientdata
= dock
;
3095 entry
->flags
.indicator
= 0;
3096 entry
->text
= _("Rename Workspace");
3098 entry
->callback
= omnipresentCallback
;
3099 entry
->clientdata
= aicon
;
3100 if (n_selected
> 0) {
3101 entry
->flags
.indicator
= 0;
3102 entry
->text
= _("Toggle Omnipresent");
3104 entry
->flags
.indicator
= 1;
3105 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3106 entry
->flags
.indicator_type
= MI_CHECK
;
3107 entry
->text
= _("Omnipresent");
3111 /* select/unselect icon */
3112 entry
= dock
->menu
->entries
[++index
];
3113 entry
->clientdata
= aicon
;
3114 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3115 wMenuSetEnabled(dock
->menu
, index
, aicon
!= scr
->clip_icon
);
3117 /* select/unselect all icons */
3118 entry
= dock
->menu
->entries
[++index
];
3119 entry
->clientdata
= aicon
;
3121 entry
->text
= _("Unselect All Icons");
3123 entry
->text
= _("Select All Icons");
3125 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3128 entry
= dock
->menu
->entries
[++index
];
3129 entry
->clientdata
= aicon
;
3131 entry
->text
= _("Keep Icons");
3133 entry
->text
= _("Keep Icon");
3135 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3137 /* this is the workspace submenu part */
3138 entry
= dock
->menu
->entries
[++index
];
3140 entry
->text
= _("Move Icons To");
3142 entry
->text
= _("Move Icon To");
3144 if (scr
->clip_submenu
)
3145 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3147 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3149 /* remove icon(s) */
3150 entry
= dock
->menu
->entries
[++index
];
3151 entry
->clientdata
= aicon
;
3153 entry
->text
= _("Remove Icons");
3155 entry
->text
= _("Remove Icon");
3157 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3159 /* attract icon(s) */
3160 entry
= dock
->menu
->entries
[++index
];
3161 entry
->clientdata
= aicon
;
3163 dock
->menu
->flags
.realized
= 0;
3164 wMenuRealize(dock
->menu
);
3167 if (aicon
->icon
->owner
)
3168 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3173 entry
= dock
->menu
->entries
[++index
];
3174 entry
->clientdata
= aicon
;
3175 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3178 entry
= dock
->menu
->entries
[++index
];
3179 entry
->clientdata
= aicon
;
3180 if (wapp
&& wapp
->flags
.hidden
)
3181 entry
->text
= _("Unhide Here");
3183 entry
->text
= _("Bring Here");
3185 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3188 entry
= dock
->menu
->entries
[++index
];
3189 entry
->clientdata
= aicon
;
3190 if (wapp
&& wapp
->flags
.hidden
)
3191 entry
->text
= _("Unhide");
3193 entry
->text
= _("Hide");
3195 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3198 entry
= dock
->menu
->entries
[++index
];
3199 entry
->clientdata
= aicon
;
3200 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3203 entry
= dock
->menu
->entries
[++index
];
3204 entry
->clientdata
= aicon
;
3205 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3207 if (!dock
->menu
->flags
.realized
)
3208 wMenuRealize(dock
->menu
);
3210 if (dock
->type
== WM_CLIP
) {
3211 /*x_pos = event->xbutton.x_root+2; */
3212 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3215 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3216 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3219 x_pos
= dock
->on_right_side
? scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3222 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3224 /* allow drag select */
3225 event
->xany
.send_event
= True
;
3226 desc
= &dock
->menu
->menu
->descriptor
;
3227 (*desc
->handle_mousedown
) (desc
, event
);
3230 /******************************************************************/
3231 static void iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3233 WAppIcon
*btn
= desc
->parent
;
3234 WDock
*dock
= btn
->dock
;
3235 WApplication
*wapp
= NULL
;
3238 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3239 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3241 assert(wapp
!= NULL
);
3243 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3245 /* go to the last workspace that the user worked on the app */
3246 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
&& !unhideHere
)
3247 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3249 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3251 if (event
->xbutton
.state
& MOD_MASK
)
3252 wHideOtherApplications(btn
->icon
->owner
);
3254 if (event
->xbutton
.button
== Button1
) {
3255 if (event
->xbutton
.state
& MOD_MASK
) {
3256 /* raise/lower dock */
3257 toggleLowered(dock
);
3258 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3259 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
)
3260 toggleCollapsed(dock
);
3262 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3263 } else if (btn
->command
) {
3264 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3265 launchDockedApplication(btn
, False
);
3271 static void handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3273 WScreen
*scr
= dock
->screen_ptr
;
3274 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3277 int grabbed
= 0, swapped
= 0, done
;
3278 Pixmap ghost
= None
;
3279 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3281 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3282 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3283 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
)
3284 wwarning("pointer grab failed for dock move");
3287 for (x
= 0; x
< dock
->max_icons
; x
++) {
3288 if (dock
->icon_array
[x
] != NULL
&& dock
->icon_array
[x
]->yindex
> y
)
3289 y
= dock
->icon_array
[x
]->yindex
;
3292 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
* y
);
3296 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3297 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3304 /* It means the cursor moved so fast that it entered
3305 * something else (if moving slowly, it would have
3306 * stayed in the dock that is being moved. Ignore such
3307 * "spurious" EnterNotifiy's */
3312 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3313 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3314 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3315 | ButtonReleaseMask
| ButtonPressMask
,
3316 wCursor
[WCUR_MOVE
], CurrentTime
);
3321 if (dock
->type
== WM_CLIP
) {
3322 x
= ev
.xmotion
.x_root
- ofs_x
;
3323 y
= ev
.xmotion
.y_root
- ofs_y
;
3324 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3326 moveDock(dock
, x
, y
);
3328 /* move vertically if pointer is inside the dock */
3329 if ((dock
->on_right_side
&& ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3330 || (!dock
->on_right_side
&& ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
* 2)) {
3332 x
= ev
.xmotion
.x_root
- ofs_x
;
3333 y
= ev
.xmotion
.y_root
- ofs_y
;
3334 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3335 moveDock(dock
, dock
->x_pos
, y
);
3337 /* move horizontally to change sides */
3338 x
= ev
.xmotion
.x_root
- ofs_x
;
3339 if (!dock
->on_right_side
) {
3342 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
* 2) {
3343 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
- ICON_SIZE
3344 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3345 if (superfluous
&& ghost
== None
) {
3346 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3347 scr
->scr_width
- ICON_SIZE
3348 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3349 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3350 XClearWindow(dpy
, scr
->dock_shadow
);
3352 XMapRaised(dpy
, scr
->dock_shadow
);
3355 if (superfluous
&& ghost
!= None
) {
3356 XFreePixmap(dpy
, ghost
);
3359 XUnmapWindow(dpy
, scr
->dock_shadow
);
3364 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3365 XMoveWindow(dpy
, scr
->dock_shadow
, DOCK_EXTRA_SPACE
, dock
->y_pos
);
3366 if (superfluous
&& ghost
== None
) {
3367 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3368 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3369 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3370 XClearWindow(dpy
, scr
->dock_shadow
);
3372 XMapRaised(dpy
, scr
->dock_shadow
);
3375 XUnmapWindow(dpy
, scr
->dock_shadow
);
3377 if (superfluous
&& ghost
!= None
) {
3378 XFreePixmap(dpy
, ghost
);
3390 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3392 XUngrabPointer(dpy
, CurrentTime
);
3393 XUnmapWindow(dpy
, scr
->dock_shadow
);
3394 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3395 if (dock
->type
== WM_DOCK
) {
3398 dock
->on_right_side
= 1;
3400 dock
->on_right_side
= 0;
3402 wArrangeIcons(scr
, False
);
3411 XFreePixmap(dpy
, ghost
);
3412 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3416 static Bool
handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3418 WScreen
*scr
= dock
->screen_ptr
;
3420 WIcon
*icon
= aicon
->icon
;
3421 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3422 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3424 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3425 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3426 int shad_x
= x
, shad_y
= y
;
3427 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3429 Pixmap ghost
= None
;
3431 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3432 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3433 Bool hasMoved
= False
;
3435 if (wPreferences
.flags
.noupdates
)
3438 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3439 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3440 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3443 if (!(event
->xbutton
.state
& MOD_MASK
))
3444 wRaiseFrame(icon
->core
);
3446 if (!wPreferences
.flags
.noclip
)
3447 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3449 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3451 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3454 wins
[0] = icon
->core
->window
;
3455 wins
[1] = scr
->dock_shadow
;
3456 XRestackWindows(dpy
, wins
, 2);
3457 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
3459 if (icon
->pixmap
!= None
)
3460 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3462 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3464 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3465 XClearWindow(dpy
, scr
->dock_shadow
);
3467 XMapWindow(dpy
, scr
->dock_shadow
);
3472 XMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3473 | ButtonMotionMask
| ExposureMask
, &ev
);
3482 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3483 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3484 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3485 | ButtonReleaseMask
| ButtonPressMask
,
3486 wCursor
[WCUR_MOVE
], CurrentTime
);
3495 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3496 if (i
== scr
->current_workspace
)
3498 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3502 x
= ev
.xmotion
.x_root
- ofs_x
;
3503 y
= ev
.xmotion
.y_root
- ofs_y
;
3504 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3507 if (last_dock
!= dock
&& collapsed
) {
3508 last_dock
->collapsed
= 1;
3509 wDockHideIcons(last_dock
);
3512 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3513 dock
->collapsed
= 0;
3514 wDockShowIcons(dock
);
3516 if (dock
->auto_raise_lower
)
3520 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3523 if (last_dock
!= dock2
&& collapsed
) {
3524 last_dock
->collapsed
= 1;
3525 wDockHideIcons(last_dock
);
3528 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3529 dock2
->collapsed
= 0;
3530 wDockShowIcons(dock2
);
3532 if (dock2
->auto_raise_lower
)
3537 if (aicon
->launching
|| aicon
->lock
|| (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3538 || (!aicon
->running
&& tmp
)) {
3539 shad_x
= last_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3540 shad_y
= last_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3542 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3545 XMapWindow(dpy
, scr
->dock_shadow
);
3550 XUnmapWindow(dpy
, scr
->dock_shadow
);
3554 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3561 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3563 XUngrabPointer(dpy
, CurrentTime
);
3565 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3566 XUnmapWindow(dpy
, scr
->dock_shadow
);
3568 reattachIcon(dock
, aicon
, ix
, iy
);
3569 if (clip
&& dock
!= clip
&& clip
->auto_raise_lower
)
3572 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3574 /* Slide it back if dock rejected it */
3575 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
, aicon
->y_pos
);
3576 reattachIcon(dock
, aicon
, aicon
->xindex
, aicon
->yindex
);
3578 if (last_dock
->type
== WM_CLIP
&& last_dock
->auto_collapse
)
3585 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3586 /* We need to deselect it, even if is deselected in
3587 * wDockDetach(), because else DoKaboom() will fail.
3589 if (aicon
->icon
->selected
)
3590 wIconSelect(aicon
->icon
);
3592 DoKaboom(scr
, aicon
->icon
->core
->window
, x
, y
);
3595 if (clip
&& clip
->auto_raise_lower
)
3597 wDockDetach(dock
, aicon
);
3600 last_dock
->collapsed
= 1;
3601 wDockHideIcons(last_dock
);
3606 XFreePixmap(dpy
, ghost
);
3607 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3611 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3612 if (i
== scr
->current_workspace
)
3614 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3620 return False
; /* never reached */
3623 static int getClipButton(int px
, int py
)
3625 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3627 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3630 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3631 return CLIP_FORWARD
;
3632 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3638 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3641 int done
, direction
, new_ws
;
3643 WDock
*clip
= scr
->clip_icon
->dock
;
3645 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3647 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3648 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3650 wClipIconPaint(scr
->clip_icon
);
3653 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3660 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3661 if (new_dir
!= direction
) {
3662 direction
= new_dir
;
3663 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3664 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3665 wClipIconPaint(scr
->clip_icon
);
3673 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3678 clip
->lclip_button_pushed
= 0;
3679 clip
->rclip_button_pushed
= 0;
3681 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3683 if (direction
== CLIP_FORWARD
) {
3684 if (scr
->current_workspace
< scr
->workspace_count
- 1)
3685 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3686 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
- 1)
3687 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3688 else if (wPreferences
.ws_cycle
)
3689 wWorkspaceChange(scr
, 0);
3690 } else if (direction
== CLIP_REWIND
) {
3691 if (scr
->current_workspace
> 0)
3692 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
3693 else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
)
3694 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
3697 wClipIconPaint(scr
->clip_icon
);
3700 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3702 WAppIcon
*aicon
= desc
->parent
;
3703 WDock
*dock
= aicon
->dock
;
3704 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3706 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3709 scr
->last_dock
= dock
;
3711 if (dock
->menu
->flags
.mapped
)
3712 wMenuUnmap(dock
->menu
);
3714 if (IsDoubleClick(scr
, event
)) {
3715 /* double-click was not in the main clip icon */
3716 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3717 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3718 iconDblClick(desc
, event
);
3723 if (event
->xbutton
.button
== Button1
) {
3724 if (event
->xbutton
.state
& MOD_MASK
)
3729 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
&& dock
->type
!= WM_DOCK
) {
3730 wIconSelect(aicon
->icon
);
3734 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3735 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
3736 && dock
->type
== WM_CLIP
)
3737 handleClipChangeWorkspace(scr
, event
);
3739 handleDockMove(dock
, aicon
, event
);
3741 Bool hasMoved
= handleIconMove(dock
, aicon
, event
);
3742 if (wPreferences
.single_click
&& !hasMoved
)
3743 iconDblClick(desc
, event
);
3745 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&& aicon
== scr
->clip_icon
) {
3746 if (!scr
->clip_ws_menu
) {
3747 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3749 if (scr
->clip_ws_menu
) {
3750 WMenu
*wsMenu
= scr
->clip_ws_menu
;
3753 wWorkspaceMenuUpdate(scr
, wsMenu
);
3755 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
3758 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
3759 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
3761 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
3763 desc
= &wsMenu
->menu
->descriptor
;
3764 event
->xany
.send_event
= True
;
3765 (*desc
->handle_mousedown
) (desc
, event
);
3767 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
3768 (event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
) {
3769 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3770 } else if (event
->xbutton
.button
== Button3
) {
3771 if (event
->xbutton
.send_event
&&
3772 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3773 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3774 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3775 wwarning("pointer grab failed for dockicon menu");
3779 openDockMenu(dock
, aicon
, event
);
3780 } else if (event
->xbutton
.button
== Button2
) {
3781 WAppIcon
*btn
= desc
->parent
;
3783 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3784 launchDockedApplication(btn
, True
);
3788 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3790 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3794 assert(event
->type
== EnterNotify
);
3796 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3799 scr
= btn
->icon
->core
->screen_ptr
;
3800 if (!btn
->omnipresent
)
3803 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3805 if (!dock
|| dock
->type
!= WM_CLIP
)
3808 /* The auto raise/lower code */
3809 if (dock
->auto_lower_magic
) {
3810 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3811 dock
->auto_lower_magic
= NULL
;
3813 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
)
3814 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
, clipAutoRaise
, (void *)dock
);
3816 /* The auto expand/collapse code */
3817 if (dock
->auto_collapse_magic
) {
3818 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3819 dock
->auto_collapse_magic
= NULL
;
3821 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
)
3822 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
, clipAutoExpand
, (void *)dock
);
3825 static void clipLeave(WDock
*dock
)
3828 WObjDescriptor
*desc
= NULL
;
3830 if (!dock
|| dock
->type
!= WM_CLIP
)
3833 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
3834 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3835 (XPointer
*) & desc
) != XCNOENT
3836 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
3837 && ((WAppIcon
*) desc
->parent
)->dock
&& ((WAppIcon
*) desc
->parent
)->dock
->type
== WM_CLIP
) {
3838 /* We didn't left the Clip yet */
3839 XPutBackEvent(dpy
, &event
);
3843 XPutBackEvent(dpy
, &event
);
3845 /* We entered a withdrawn window, so we're still in Clip */
3849 if (dock
->auto_raise_magic
) {
3850 WMDeleteTimerHandler(dock
->auto_raise_magic
);
3851 dock
->auto_raise_magic
= NULL
;
3853 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
)
3854 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
, clipAutoLower
, (void *)dock
);
3856 if (dock
->auto_expand_magic
) {
3857 WMDeleteTimerHandler(dock
->auto_expand_magic
);
3858 dock
->auto_expand_magic
= NULL
;
3860 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
)
3861 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
, clipAutoCollapse
, (void *)dock
);
3864 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
3866 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3868 assert(event
->type
== LeaveNotify
);
3870 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3873 clipLeave(btn
->dock
);
3876 static void clipAutoCollapse(void *cdata
)
3878 WDock
*dock
= (WDock
*) cdata
;
3880 if (dock
->type
!= WM_CLIP
)
3883 if (dock
->auto_collapse
) {
3884 dock
->collapsed
= 1;
3885 wDockHideIcons(dock
);
3887 dock
->auto_collapse_magic
= NULL
;
3890 static void clipAutoExpand(void *cdata
)
3892 WDock
*dock
= (WDock
*) cdata
;
3894 if (dock
->type
!= WM_CLIP
)
3897 if (dock
->auto_collapse
) {
3898 dock
->collapsed
= 0;
3899 wDockShowIcons(dock
);
3901 dock
->auto_expand_magic
= NULL
;
3904 static void clipAutoLower(void *cdata
)
3906 WDock
*dock
= (WDock
*) cdata
;
3908 if (dock
->type
!= WM_CLIP
)
3911 if (dock
->auto_raise_lower
)
3914 dock
->auto_lower_magic
= NULL
;
3917 static void clipAutoRaise(void *cdata
)
3919 WDock
*dock
= (WDock
*) cdata
;
3921 if (dock
->type
!= WM_CLIP
)
3924 if (dock
->auto_raise_lower
)
3927 dock
->auto_raise_magic
= NULL
;
3930 static Bool
iconCanBeOmnipresent(WAppIcon
*aicon
)
3932 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3937 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3938 clip
= scr
->workspaces
[i
]->clip
;
3940 if (clip
== aicon
->dock
)
3943 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
3944 return False
; /* Clip is full in some workspace */
3946 for (j
= 0; j
< clip
->max_icons
; j
++) {
3947 btn
= clip
->icon_array
[j
];
3948 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
3956 int wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
3958 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3959 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
3960 int status
= WO_SUCCESS
;
3962 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== scr
->clip_icon
)
3963 return WO_NOT_APPLICABLE
;
3965 if (aicon
->omnipresent
== omnipresent
)
3969 if (iconCanBeOmnipresent(aicon
)) {
3970 aicon
->omnipresent
= 1;
3971 new_entry
= wmalloc(sizeof(WAppIconChain
));
3972 new_entry
->aicon
= aicon
;
3973 new_entry
->next
= scr
->global_icons
;
3974 scr
->global_icons
= new_entry
;
3975 scr
->global_icon_count
++;
3977 aicon
->omnipresent
= 0;
3981 aicon
->omnipresent
= 0;
3982 if (aicon
== scr
->global_icons
->aicon
) {
3983 tmp
= scr
->global_icons
->next
;
3984 wfree(scr
->global_icons
);
3985 scr
->global_icons
= tmp
;
3986 scr
->global_icon_count
--;
3988 tmp
= scr
->global_icons
;
3990 if (tmp
->next
->aicon
== aicon
) {
3991 tmp1
= tmp
->next
->next
;
3994 scr
->global_icon_count
--;
4002 wAppIconPaint(aicon
);