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"
58 /**** Local variables ****/
61 #define CLIP_FORWARD 2
63 /**** Global variables ****/
64 extern Cursor wCursor
[WCUR_LAST
];
65 extern WPreferences wPreferences
;
66 extern XContext wWinContext
;
67 extern void appIconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
69 #define MOD_MASK wPreferences.modifier_mask
70 #define ICON_SIZE wPreferences.icon_size
72 /***** Local variables ****/
74 static WMPropList
*dCommand
= NULL
;
75 static WMPropList
*dPasteCommand
= NULL
;
76 #ifdef XDND /* XXX was OFFIX */
77 static WMPropList
*dDropCommand
= NULL
;
79 static WMPropList
*dAutoLaunch
, *dLock
;
80 static WMPropList
*dName
, *dForced
, *dBuggyApplication
, *dYes
, *dNo
;
81 static WMPropList
*dHost
, *dDock
, *dClip
;
82 static WMPropList
*dAutoAttractIcons
;
84 static WMPropList
*dPosition
, *dApplications
, *dLowered
, *dCollapsed
;
86 static WMPropList
*dAutoCollapse
, *dAutoRaiseLower
, *dOmnipresent
;
88 static void dockIconPaint(WAppIcon
*btn
);
90 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
92 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
);
94 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
96 static int getClipButton(int px
, int py
);
98 static void toggleLowered(WDock
*dock
);
100 static void toggleCollapsed(WDock
*dock
);
102 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
104 static void clipLeave(WDock
*dock
);
106 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
108 static Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
);
110 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
111 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
112 static void clipAutoCollapse(void *cdata
);
113 static void clipAutoExpand(void *cdata
);
114 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
);
116 static void clipAutoLower(void *cdata
);
117 static void clipAutoRaise(void *cdata
);
118 static void reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
);
119 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
);
121 static void make_keys(void)
123 if (dCommand
!= NULL
)
126 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
127 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
129 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
131 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
132 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
133 dName
= WMRetainPropList(WMCreatePLString("Name"));
134 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
135 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
136 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
137 dNo
= WMRetainPropList(WMCreatePLString("No"));
138 dHost
= WMRetainPropList(WMCreatePLString("Host"));
140 dPosition
= WMCreatePLString("Position");
141 dApplications
= WMCreatePLString("Applications");
142 dLowered
= WMCreatePLString("Lowered");
143 dCollapsed
= WMCreatePLString("Collapsed");
144 dAutoCollapse
= WMCreatePLString("AutoCollapse");
145 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
146 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
148 dOmnipresent
= WMCreatePLString("Omnipresent");
150 dDock
= WMCreatePLString("Dock");
151 dClip
= WMCreatePLString("Clip");
154 static void renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
156 WDock
*dock
= entry
->clientdata
;
161 assert(entry
->clientdata
!= NULL
);
163 wspace
= dock
->screen_ptr
->current_workspace
;
165 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
167 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+ 1);
168 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
, &name
)) {
169 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
) {
278 static WMArray
*getSelected(WDock
*dock
)
280 WMArray
*ret
= WMCreateArray(8);
284 for (i
= 1; i
< dock
->max_icons
; i
++) {
285 btn
= dock
->icon_array
[i
];
286 if (btn
&& btn
->icon
->selected
) {
287 WMAddToArray(ret
, btn
);
294 static void paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
296 Window win
= clipIcon
->icon
->core
->window
;
297 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
299 int pt
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
300 int tp
= ICON_SIZE
- pt
;
301 int as
= pt
- 15; /* 15 = 5+5+5 */
302 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
305 color
= scr
->clip_title_color
[CLIP_NORMAL
];
307 XSetForeground(dpy
, gc
, WMColorPixel(color
));
312 p
[1].x
= ICON_SIZE
- 2;
314 p
[2].x
= ICON_SIZE
- 2;
316 } else if (lpushed
) {
320 p
[1].y
= ICON_SIZE
- 2;
322 p
[2].y
= ICON_SIZE
- 2;
324 if (lpushed
|| rpushed
) {
325 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
326 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
327 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
330 /* top right arrow */
331 p
[0].x
= p
[3].x
= ICON_SIZE
- 5 - as
;
333 p
[1].x
= ICON_SIZE
- 6;
335 p
[2].x
= ICON_SIZE
- 6;
338 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
339 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
341 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
342 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
345 /* bottom left arrow */
347 p
[0].y
= p
[3].y
= ICON_SIZE
- 5 - as
;
349 p
[1].y
= ICON_SIZE
- 6;
351 p
[2].y
= ICON_SIZE
- 6;
353 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
354 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
356 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
357 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
361 RImage
*wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
363 RImage
*tile
= RCloneImage(normalTile
);
370 pt
= CLIP_BUTTON_SIZE
* wPreferences
.icon_size
/ 64;
371 tp
= wPreferences
.icon_size
- 1 - pt
;
375 black
.red
= black
.green
= black
.blue
= 0;
378 dark
.red
= dark
.green
= dark
.blue
= 60;
381 light
.red
= light
.green
= light
.blue
= 80;
384 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
- 2, pt
- 1, &dark
);
385 RDrawLine(tile
, tp
- 1, 0, wPreferences
.icon_size
- 1, pt
+ 1, &black
);
386 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
- 3, pt
, &light
);
389 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, 4, &dark
);
390 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 5, 6 + as
, &dark
);
391 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
, &light
);
394 ROperateLine(tile
, RAddOperation
, 2, tp
+ 2, pt
- 2, wPreferences
.icon_size
- 3, &dark
);
395 RDrawLine(tile
, 0, tp
- 1, pt
+ 1, wPreferences
.icon_size
- 1, &black
);
396 ROperateLine(tile
, RSubtractOperation
, 0, tp
- 2, pt
+ 1, wPreferences
.icon_size
- 2, &light
);
399 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, &dark
);
400 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
, 6 + as
, ICON_SIZE
- 5, &dark
);
401 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5, &light
);
406 static void omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
408 WAppIcon
*clickedIcon
= entry
->clientdata
;
411 WMArray
*selectedIcons
;
412 WMArrayIterator iter
;
415 assert(entry
->clientdata
!= NULL
);
417 dock
= clickedIcon
->dock
;
419 selectedIcons
= getSelected(dock
);
421 if (!WMGetArrayItemCount(selectedIcons
))
422 WMAddToArray(selectedIcons
, clickedIcon
);
425 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
426 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
428 else if (aicon
->icon
->selected
)
429 wIconSelect(aicon
->icon
);
431 WMFreeArray(selectedIcons
);
434 wMessageDialog(dock
->screen_ptr
, _("Warning"),
435 _("Some icons cannot be made omnipresent. "
436 "Please make sure that no other icon is "
437 "docked in the same positions on the other "
438 "workspaces and the Clip is not full in "
439 "some workspace."), _("OK"), NULL
, NULL
);
440 } else if (failed
== 1) {
441 wMessageDialog(dock
->screen_ptr
, _("Warning"),
442 _("Icon cannot be made omnipresent. "
443 "Please make sure that no other icon is "
444 "docked in the same position on the other "
445 "workspaces and the Clip is not full in "
446 "some workspace."), _("OK"), NULL
, NULL
);
450 static void removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
452 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
455 WMArray
*selectedIcons
;
459 assert(clickedIcon
!= NULL
);
461 dock
= clickedIcon
->dock
;
463 selectedIcons
= getSelected(dock
);
465 if (WMGetArrayItemCount(selectedIcons
)) {
466 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
467 _("All selected icons will be removed!"),
468 _("OK"), _("Cancel"), NULL
) != WAPRDefault
) {
469 WMFreeArray(selectedIcons
);
473 if (clickedIcon
->xindex
== 0 && clickedIcon
->yindex
== 0) {
474 WMFreeArray(selectedIcons
);
477 WMAddToArray(selectedIcons
, clickedIcon
);
480 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
481 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
482 wDockDetach(dock
, aicon
);
484 /* XXX: can: aicon->icon == NULL ? */
485 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
486 wGetHeadForWindow(aicon
->icon
->owner
));
487 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
488 if (!dock
->mapped
|| dock
->collapsed
)
489 XMapWindow(dpy
, aicon
->icon
->core
->window
);
492 WMFreeArray(selectedIcons
);
494 if (wPreferences
.auto_arrange_icons
)
495 wArrangeIcons(dock
->screen_ptr
, True
);
498 static void keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
500 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
503 WMArray
*selectedIcons
;
506 assert(clickedIcon
!= NULL
);
507 dock
= clickedIcon
->dock
;
509 selectedIcons
= getSelected(dock
);
511 if (!WMGetArrayItemCount(selectedIcons
)
512 && clickedIcon
!= dock
->screen_ptr
->clip_icon
) {
513 char *command
= NULL
;
515 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
516 clickedIcon
->editing
= 1;
517 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
518 _("Type the command used to launch the application"), &command
)) {
519 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
523 clickedIcon
->command
= command
;
524 clickedIcon
->editing
= 0;
526 clickedIcon
->editing
= 0;
529 WMFreeArray(selectedIcons
);
534 WMAddToArray(selectedIcons
, clickedIcon
);
537 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
538 if (aicon
->icon
->selected
)
539 wIconSelect(aicon
->icon
);
540 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
541 aicon
->attracted
= 0;
542 if (aicon
->icon
->shadowed
) {
543 aicon
->icon
->shadowed
= 0;
544 aicon
->icon
->force_paint
= 1;
545 wAppIconPaint(aicon
);
548 save_appicon(aicon
, True
);
550 WMFreeArray(selectedIcons
);
553 static void toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
555 WDock
*dock
= (WDock
*) entry
->clientdata
;
557 assert(entry
->clientdata
!= NULL
);
559 dock
->attract_icons
= !dock
->attract_icons
;
560 /*if (!dock->attract_icons)
561 dock->keep_attracted = 0; */
563 entry
->flags
.indicator_on
= dock
->attract_icons
;
568 static void selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
570 WAppIcon
*icon
= (WAppIcon
*) entry
->clientdata
;
572 assert(icon
!= NULL
);
574 wIconSelect(icon
->icon
);
579 static void colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
581 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
584 int x
, y
, x_pos
, y_pos
;
586 assert(entry
->clientdata
!= NULL
);
587 clip
= clickedIcon
->dock
;
589 aicon
= clip
->screen_ptr
->app_icon_list
;
592 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
593 x_pos
= clip
->x_pos
+ x
* ICON_SIZE
;
594 y_pos
= clip
->y_pos
+ y
* ICON_SIZE
;
595 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
)
596 move_window(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
598 aicon
->attracted
= 1;
599 if (!aicon
->icon
->shadowed
) {
600 aicon
->icon
->shadowed
= 1;
601 aicon
->icon
->force_paint
= 1;
602 /* We don't do an wAppIconPaint() here because it's in
603 * wDockAttachIcon(). -Dan
606 wDockAttachIcon(clip
, aicon
, x
, y
);
607 if (clip
->collapsed
|| !clip
->mapped
)
608 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
614 static void selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
616 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
618 WMArray
*selectedIcons
;
619 WMArrayIterator iter
;
623 assert(clickedIcon
!= NULL
);
624 dock
= clickedIcon
->dock
;
626 selectedIcons
= getSelected(dock
);
628 if (!WMGetArrayItemCount(selectedIcons
)) {
629 for (i
= 1; i
< dock
->max_icons
; i
++) {
630 btn
= dock
->icon_array
[i
];
631 if (btn
&& !btn
->icon
->selected
) {
632 wIconSelect(btn
->icon
);
636 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
637 wIconSelect(btn
->icon
);
640 WMFreeArray(selectedIcons
);
645 static void toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
647 assert(entry
->clientdata
!= NULL
);
649 toggleCollapsed(entry
->clientdata
);
651 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->collapsed
;
656 static void toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
659 assert(entry
->clientdata
!= NULL
);
661 dock
= (WDock
*) entry
->clientdata
;
663 dock
->auto_collapse
= !dock
->auto_collapse
;
665 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_collapse
;
670 static void toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
673 assert(entry
->clientdata
!= NULL
);
675 dock
= (WDock
*) entry
->clientdata
;
677 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
679 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_raise_lower
;
684 static void launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
686 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
688 launchDockedApplication(btn
, False
);
691 static void settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
693 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
697 ShowDockAppSettingsPanel(btn
);
700 static void hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
703 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
705 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
707 if (wapp
->flags
.hidden
) {
708 wWorkspaceChange(btn
->icon
->core
->screen_ptr
, wapp
->last_workspace
);
709 wUnhideApplication(wapp
, False
, False
);
711 wHideApplication(wapp
);
715 static void unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
718 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
720 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
722 wUnhideApplication(wapp
, False
, True
);
725 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
)
730 if (type
== WM_CLIP
) {
732 return scr
->clip_icon
;
733 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
734 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
735 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
736 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
737 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE; */
740 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
741 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
747 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
748 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
749 btn
->icon
->core
->descriptor
.parent
= btn
;
750 /*ChangeStackingLevel(btn->icon->core, WMDockLevel); */
751 XMapWindow(dpy
, btn
->icon
->core
->window
);
756 scr
->clip_icon
= btn
;
761 static void switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
763 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
764 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
766 WMArray
*selectedIcons
;
769 if (entry
->order
== scr
->current_workspace
)
772 dest
= scr
->workspaces
[entry
->order
]->clip
;
774 selectedIcons
= getSelected(src
);
776 if (WMGetArrayItemCount(selectedIcons
)) {
777 WMArrayIterator iter
;
779 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
780 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
781 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
782 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
785 } else if (icon
!= scr
->clip_icon
) {
786 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
787 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
788 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
791 WMFreeArray(selectedIcons
);
794 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
)
796 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
798 if (!btn
->launching
&&
799 ((!withSelection
&& btn
->command
!= NULL
) || (withSelection
&& btn
->paste_command
!= NULL
))) {
800 if (!btn
->forced_dock
) {
801 btn
->relaunching
= btn
->running
;
804 if (btn
->wm_instance
|| btn
->wm_class
) {
805 WWindowAttributes attr
;
806 memset(&attr
, 0, sizeof(WWindowAttributes
));
807 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
809 if (!attr
.no_appicon
&& !btn
->buggy_app
)
814 btn
->drop_launch
= 0;
815 btn
->paste_launch
= withSelection
;
816 scr
->last_dock
= btn
->dock
;
817 btn
->pid
= execCommand(btn
, (withSelection
? btn
->paste_command
: btn
->command
), NULL
);
819 if (btn
->buggy_app
) {
820 /* give feedback that the app was launched */
824 WMAddTimerHandler(200, (WMCallback
*) dockIconPaint
, btn
);
829 wwarning(_("could not launch application %s"), btn
->command
);
831 if (!btn
->relaunching
) {
838 static void updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
840 WScreen
*scr
= menu
->frame
->screen_ptr
;
841 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
847 for (i
= 0; i
< scr
->workspace_count
; i
++) {
848 if (i
< menu
->entry_no
) {
849 if (strcmp(menu
->entries
[i
]->text
, scr
->workspaces
[i
]->name
) != 0) {
850 wfree(menu
->entries
[i
]->text
);
851 strcpy(title
, scr
->workspaces
[i
]->name
);
852 menu
->entries
[i
]->text
= wstrdup(title
);
853 menu
->flags
.realized
= 0;
855 menu
->entries
[i
]->clientdata
= (void *)icon
;
857 strcpy(title
, scr
->workspaces
[i
]->name
);
859 wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)icon
);
861 menu
->flags
.realized
= 0;
863 if (i
== scr
->current_workspace
) {
864 wMenuSetEnabled(menu
, i
, False
);
866 wMenuSetEnabled(menu
, i
, True
);
870 if (!menu
->flags
.realized
)
874 static WMenu
*makeWorkspaceMenu(WScreen
*scr
)
878 menu
= wMenuCreate(scr
, NULL
, False
);
880 wwarning(_("could not create workspace submenu for Clip menu"));
882 wMenuAddCallback(menu
, "", switchWSCommand
, (void *)scr
->clip_icon
);
884 menu
->flags
.realized
= 0;
890 static void updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
899 entry
= menu
->entries
[index
];
900 entry
->flags
.indicator_on
= !dock
->lowered
;
901 entry
->clientdata
= dock
;
904 entry
= menu
->entries
[++index
];
905 entry
->flags
.indicator_on
= dock
->collapsed
;
906 entry
->clientdata
= dock
;
909 entry
= menu
->entries
[++index
];
910 entry
->flags
.indicator_on
= dock
->auto_collapse
;
911 entry
->clientdata
= dock
;
913 /* auto-raise/lower */
914 entry
= menu
->entries
[++index
];
915 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
916 entry
->clientdata
= dock
;
917 wMenuSetEnabled(menu
, index
, dock
->lowered
);
920 entry
= menu
->entries
[++index
];
921 entry
->flags
.indicator_on
= dock
->attract_icons
;
922 entry
->clientdata
= dock
;
924 menu
->flags
.realized
= 0;
928 static WMenu
*makeClipOptionsMenu(WScreen
*scr
)
933 menu
= wMenuCreate(scr
, NULL
, False
);
935 wwarning(_("could not create options submenu for Clip menu"));
939 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
940 entry
->flags
.indicator
= 1;
941 entry
->flags
.indicator_on
= 1;
942 entry
->flags
.indicator_type
= MI_CHECK
;
944 entry
= wMenuAddCallback(menu
, _("Collapsed"), toggleCollapsedCallback
, NULL
);
945 entry
->flags
.indicator
= 1;
946 entry
->flags
.indicator_on
= 1;
947 entry
->flags
.indicator_type
= MI_CHECK
;
949 entry
= wMenuAddCallback(menu
, _("Autocollapse"), toggleAutoCollapseCallback
, NULL
);
950 entry
->flags
.indicator
= 1;
951 entry
->flags
.indicator_on
= 1;
952 entry
->flags
.indicator_type
= MI_CHECK
;
954 entry
= wMenuAddCallback(menu
, _("Autoraise"), toggleAutoRaiseLowerCallback
, NULL
);
955 entry
->flags
.indicator
= 1;
956 entry
->flags
.indicator_on
= 1;
957 entry
->flags
.indicator_type
= MI_CHECK
;
959 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"), toggleAutoAttractCallback
, NULL
);
960 entry
->flags
.indicator
= 1;
961 entry
->flags
.indicator_on
= 1;
962 entry
->flags
.indicator_type
= MI_CHECK
;
964 menu
->flags
.realized
= 0;
970 static WMenu
*dockMenuCreate(WScreen
*scr
, int type
)
975 if (type
== WM_CLIP
&& scr
->clip_menu
)
976 return scr
->clip_menu
;
978 menu
= wMenuCreate(scr
, NULL
, False
);
979 if (type
!= WM_CLIP
) {
980 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
981 entry
->flags
.indicator
= 1;
982 entry
->flags
.indicator_on
= 1;
983 entry
->flags
.indicator_type
= MI_CHECK
;
985 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
986 scr
->clip_options
= makeClipOptionsMenu(scr
);
987 if (scr
->clip_options
)
988 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
990 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
992 entry
->text
= _("Rename Workspace");
994 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
995 entry
->flags
.indicator
= 1;
996 entry
->flags
.indicator_on
= 1;
997 entry
->flags
.indicator_type
= MI_CHECK
;
999 entry
= wMenuAddCallback(menu
, _("Select All Icons"), selectIconsCallback
, NULL
);
1001 entry
->text
= _("Select All Icons");
1003 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1005 entry
->text
= _("Keep Icon");
1007 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1009 entry
->text
= _("Move Icon To");
1010 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1011 if (scr
->clip_submenu
)
1012 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1014 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
, NULL
);
1016 entry
->text
= _("Remove Icon");
1018 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1021 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1023 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1025 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1027 entry
->text
= _("Hide");
1029 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1031 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1033 if (type
== WM_CLIP
)
1034 scr
->clip_menu
= menu
;
1039 WDock
*wDockCreate(WScreen
*scr
, int type
)
1046 dock
= wmalloc(sizeof(WDock
));
1048 dock
->max_icons
= DOCK_MAX_ICONS
;
1050 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * dock
->max_icons
);
1052 btn
= mainIconCreate(scr
, type
);
1056 dock
->x_pos
= btn
->x_pos
;
1057 dock
->y_pos
= btn
->y_pos
;
1058 dock
->screen_ptr
= scr
;
1060 dock
->icon_count
= 1;
1061 dock
->on_right_side
= 1;
1062 dock
->collapsed
= 0;
1063 dock
->auto_collapse
= 0;
1064 dock
->auto_collapse_magic
= NULL
;
1065 dock
->auto_raise_lower
= 0;
1066 dock
->auto_lower_magic
= NULL
;
1067 dock
->auto_raise_magic
= NULL
;
1068 dock
->attract_icons
= 0;
1070 dock
->icon_array
[0] = btn
;
1071 wRaiseFrame(btn
->icon
->core
);
1072 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1074 /* create dock menu */
1075 dock
->menu
= dockMenuCreate(scr
, type
);
1080 void wDockDestroy(WDock
*dock
)
1085 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1086 aicon
= dock
->icon_array
[i
];
1088 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1089 wDockDetach(dock
, aicon
);
1091 /* XXX: can: aicon->icon == NULL ? */
1092 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1093 wGetHeadForWindow(aicon
->icon
->owner
));
1094 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1095 if (!dock
->mapped
|| dock
->collapsed
)
1096 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1100 if (wPreferences
.auto_arrange_icons
)
1101 wArrangeIcons(dock
->screen_ptr
, True
);
1102 wfree(dock
->icon_array
);
1103 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1104 wMenuDestroy(dock
->menu
, True
);
1105 if (dock
->screen_ptr
->last_dock
== dock
)
1106 dock
->screen_ptr
->last_dock
= NULL
;
1110 void wClipIconPaint(WAppIcon
*aicon
)
1112 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1113 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1115 Window win
= aicon
->icon
->core
->window
;
1116 int length
, nlength
;
1117 char *ws_name
, ws_number
[10];
1120 wIconPaint(aicon
->icon
);
1122 length
= strlen(workspace
->name
);
1123 ws_name
= wmalloc(length
+ 1);
1124 snprintf(ws_name
, length
+ 1, "%s", workspace
->name
);
1125 snprintf(ws_number
, sizeof(ws_number
), "%i", scr
->current_workspace
+ 1);
1126 nlength
= strlen(ws_number
);
1128 if (!workspace
->clip
->collapsed
)
1129 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1131 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1133 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1135 tx
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
1137 if(wPreferences
.show_clip_title
)
1138 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, ty
, ws_name
, length
);
1140 tx
= (ICON_SIZE
/ 2 - WMWidthOfString(scr
->clip_title_font
, ws_number
, nlength
)) / 2;
1142 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, 2, ws_number
, nlength
);
1146 if (aicon
->launching
) {
1147 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1148 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1150 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
, aicon
->dock
->rclip_button_pushed
);
1153 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1155 wClipIconPaint(desc
->parent
);
1158 static void dockIconPaint(WAppIcon
*btn
)
1160 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1161 wClipIconPaint(btn
);
1164 save_appicon(btn
, True
);
1168 static WMPropList
*make_icon_state(WAppIcon
*btn
)
1170 WMPropList
*node
= NULL
;
1171 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
;
1172 WMPropList
*position
, *buggy
, *omnipresent
;
1178 command
= WMCreatePLString("-");
1180 command
= WMCreatePLString(btn
->command
);
1182 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1184 lock
= btn
->lock
? dYes
: dNo
;
1186 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1188 name
= WMCreatePLString(tmp
);
1192 forced
= btn
->forced_dock
? dYes
: dNo
;
1194 buggy
= btn
->buggy_app
? dYes
: dNo
;
1196 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1197 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1199 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1200 position
= WMCreatePLString(buffer
);
1202 node
= WMCreatePLDictionary(dCommand
, command
,
1204 dAutoLaunch
, autolaunch
,
1206 dForced
, forced
, dBuggyApplication
, buggy
, dPosition
, position
, NULL
);
1207 WMReleasePropList(command
);
1208 WMReleasePropList(name
);
1209 WMReleasePropList(position
);
1211 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1212 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&& (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1213 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1215 #ifdef XDND /* was OFFIX */
1216 if (btn
->dnd_command
) {
1217 command
= WMCreatePLString(btn
->dnd_command
);
1218 WMPutInPLDictionary(node
, dDropCommand
, command
);
1219 WMReleasePropList(command
);
1223 if (btn
->paste_command
) {
1224 command
= WMCreatePLString(btn
->paste_command
);
1225 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1226 WMReleasePropList(command
);
1233 static WMPropList
*dockSaveState(WDock
*dock
)
1236 WMPropList
*icon_info
;
1237 WMPropList
*list
= NULL
, *dock_state
= NULL
;
1238 WMPropList
*value
, *key
;
1241 list
= WMCreatePLArray(NULL
);
1243 for (i
= (dock
->type
== WM_DOCK
? 0 : 1); i
< dock
->max_icons
; i
++) {
1244 WAppIcon
*btn
= dock
->icon_array
[i
];
1246 if (!btn
|| btn
->attracted
)
1249 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1250 WMAddToPLArray(list
, icon_info
);
1251 WMReleasePropList(icon_info
);
1255 dock_state
= WMCreatePLDictionary(dApplications
, list
, NULL
);
1257 if (dock
->type
== WM_DOCK
) {
1258 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1259 key
= WMCreatePLString(buffer
);
1260 WMPutInPLDictionary(dock_state
, key
, list
);
1261 WMReleasePropList(key
);
1263 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0), dock
->y_pos
);
1264 value
= WMCreatePLString(buffer
);
1265 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1266 WMReleasePropList(value
);
1268 WMReleasePropList(list
);
1270 value
= (dock
->lowered
? dYes
: dNo
);
1271 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1273 if (dock
->type
== WM_CLIP
) {
1274 value
= (dock
->collapsed
? dYes
: dNo
);
1275 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1277 value
= (dock
->auto_collapse
? dYes
: dNo
);
1278 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1280 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1281 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1283 value
= (dock
->attract_icons
? dYes
: dNo
);
1284 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1290 void wDockSaveState(WScreen
*scr
, WMPropList
*old_state
)
1292 WMPropList
*dock_state
;
1295 dock_state
= dockSaveState(scr
->dock
);
1298 * Copy saved states of docks with different sizes.
1304 keys
= WMGetPLDictionaryKeys(old_state
);
1305 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1306 tmp
= WMGetFromPLArray(keys
, i
);
1308 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1309 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1311 WMPutInPLDictionary(dock_state
, tmp
, WMGetFromPLDictionary(old_state
, tmp
));
1314 WMReleasePropList(keys
);
1317 WMPutInPLDictionary(scr
->session_state
, dDock
, dock_state
);
1319 WMReleasePropList(dock_state
);
1322 void wClipSaveState(WScreen
*scr
)
1324 WMPropList
*clip_state
;
1326 clip_state
= make_icon_state(scr
->clip_icon
);
1328 WMPutInPLDictionary(scr
->session_state
, dClip
, clip_state
);
1330 WMReleasePropList(clip_state
);
1333 WMPropList
*wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1335 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1338 static Bool
getBooleanDockValue(WMPropList
*value
, WMPropList
*key
)
1341 if (WMIsPLString(value
)) {
1342 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1345 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1351 static WAppIcon
*restore_icon_state(WScreen
*scr
, WMPropList
*info
, int type
, int index
)
1354 WMPropList
*cmd
, *value
;
1356 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1357 if (!cmd
|| !WMIsPLString(cmd
)) {
1361 /* parse window name */
1362 value
= WMGetFromPLDictionary(info
, dName
);
1367 char *wclass
, *winstance
;
1370 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1372 if (!winstance
&& !wclass
) {
1379 command
= wstrdup(WMGetFromPLString(cmd
));
1383 if (!command
|| strcmp(command
, "-") == 0) {
1394 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1403 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1404 if (type
== WM_CLIP
) {
1405 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1406 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1408 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1409 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1411 #ifdef XDND /* was OFFIX */
1412 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1414 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1417 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1419 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1421 /* check auto launch */
1422 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1424 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1427 value
= WMGetFromPLDictionary(info
, dLock
);
1429 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1431 /* check if it wasn't normally docked */
1432 value
= WMGetFromPLDictionary(info
, dForced
);
1434 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1436 /* check if we can rely on the stuff in the app */
1437 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1439 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1441 /* get position in the dock */
1442 value
= WMGetFromPLDictionary(info
, dPosition
);
1443 if (value
&& WMIsPLString(value
)) {
1444 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1445 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1447 /* check position sanity */
1448 /* incomplete section! */
1449 if (type
== WM_DOCK
) {
1451 if (aicon
->yindex
< 0)
1452 wwarning(_("bad value in docked icon position %i,%i"),
1453 aicon
->xindex
, aicon
->yindex
);
1456 aicon
->yindex
= index
;
1460 /* check if icon is omnipresent */
1461 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1463 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1471 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1473 WAppIcon
*wClipRestoreState(WScreen
*scr
, WMPropList
*clip_state
)
1478 icon
= mainIconCreate(scr
, WM_CLIP
);
1483 WMRetainPropList(clip_state
);
1485 /* restore position */
1487 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1490 if (!WMIsPLString(value
))
1491 COMPLAIN("Position");
1496 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1497 COMPLAIN("Position");
1499 /* check position sanity */
1500 rect
.pos
.x
= icon
->x_pos
;
1501 rect
.pos
.y
= icon
->y_pos
;
1502 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1504 wGetRectPlacementInfo(scr
, rect
, &flags
);
1505 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
1506 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1509 #ifdef XDND /* was OFFIX */
1510 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1511 if (value
&& WMIsPLString(value
))
1512 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1515 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1516 if (value
&& WMIsPLString(value
))
1517 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1519 WMReleasePropList(clip_state
);
1524 WDock
*wDockRestoreState(WScreen
*scr
, WMPropList
*dock_state
, int type
)
1529 WAppIcon
*aicon
, *old_top
;
1532 dock
= wDockCreate(scr
, type
);
1537 WMRetainPropList(dock_state
);
1539 /* restore position */
1540 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1542 if (!WMIsPLString(value
)) {
1543 COMPLAIN("Position");
1548 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1549 COMPLAIN("Position");
1551 /* check position sanity */
1552 rect
.pos
.x
= dock
->x_pos
;
1553 rect
.pos
.y
= dock
->y_pos
;
1554 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1556 wGetRectPlacementInfo(scr
, rect
, &flags
);
1557 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
)) {
1558 int x
= dock
->x_pos
;
1559 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1562 /* Is this needed any more? */
1563 if (type
== WM_CLIP
) {
1564 if (dock
->x_pos
< 0) {
1566 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1567 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1570 if (dock
->x_pos
>= 0) {
1571 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1572 dock
->on_right_side
= 0;
1574 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1575 dock
->on_right_side
= 1;
1581 /* restore lowered/raised state */
1584 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1586 if (!WMIsPLString(value
)) {
1587 COMPLAIN("Lowered");
1589 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1595 /* restore collapsed state */
1596 dock
->collapsed
= 0;
1598 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1600 if (!WMIsPLString(value
)) {
1601 COMPLAIN("Collapsed");
1603 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1604 dock
->collapsed
= 1;
1609 /* restore auto-collapsed state */
1610 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1612 if (!WMIsPLString(value
)) {
1613 COMPLAIN("AutoCollapse");
1615 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1616 dock
->auto_collapse
= 1;
1617 dock
->collapsed
= 1;
1622 /* restore auto-raise/lower state */
1623 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1625 if (!WMIsPLString(value
)) {
1626 COMPLAIN("AutoRaiseLower");
1628 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1629 dock
->auto_raise_lower
= 1;
1633 /* restore attract icons state */
1634 dock
->attract_icons
= 0;
1636 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1638 if (!WMIsPLString(value
)) {
1639 COMPLAIN("AutoAttractIcons");
1641 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1642 dock
->attract_icons
= 1;
1646 /* application list */
1653 * When saving, it saves the dock state in
1654 * Applications and Applicationsnnn
1656 * When loading, it will first try Applicationsnnn.
1657 * If it does not exist, use Applications as default.
1660 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1662 tmp
= WMCreatePLString(buffer
);
1663 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1664 WMReleasePropList(tmp
);
1667 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1673 count
= WMGetPropListItemCount(apps
);
1677 old_top
= dock
->icon_array
[0];
1679 /* dock->icon_count is set to 1 when dock is created.
1680 * Since Clip is already restored, we want to keep it so for clip,
1681 * but for dock we may change the default top tile, so we set it to 0.
1683 if (type
== WM_DOCK
)
1684 dock
->icon_count
= 0;
1686 for (i
= 0; i
< count
; i
++) {
1687 if (dock
->icon_count
>= dock
->max_icons
) {
1688 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1692 value
= WMGetFromPLArray(apps
, i
);
1693 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1695 dock
->icon_array
[dock
->icon_count
] = aicon
;
1699 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1700 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1703 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1705 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1707 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1709 if (!dock
->collapsed
)
1710 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1711 wRaiseFrame(aicon
->icon
->core
);
1714 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
)
1718 /* if the first icon is not defined, use the default */
1719 if (dock
->icon_array
[0] == NULL
) {
1720 /* update default icon */
1721 old_top
->x_pos
= dock
->x_pos
;
1722 old_top
->y_pos
= dock
->y_pos
;
1724 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1726 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1727 dock
->icon_array
[0] = old_top
;
1728 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1729 /* we don't need to increment dock->icon_count here because it was
1730 * incremented in the loop above.
1732 } else if (old_top
!= dock
->icon_array
[0]) {
1733 if (old_top
== scr
->clip_icon
)
1734 scr
->clip_icon
= dock
->icon_array
[0];
1735 wAppIconDestroy(old_top
);
1739 WMReleasePropList(dock_state
);
1744 void wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1746 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1748 btn
->drop_launch
= 0;
1749 btn
->paste_launch
= 0;
1751 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1754 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1764 void wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1770 for (i
= 0; i
< dock
->max_icons
; i
++) {
1771 btn
= dock
->icon_array
[i
];
1772 if (!btn
|| !btn
->auto_launch
)
1775 state
= wmalloc(sizeof(WSavedState
));
1776 state
->workspace
= workspace
;
1777 /* TODO: this is klugy and is very difficult to understand
1778 * what's going on. Try to clean up */
1779 wDockLaunchWithState(dock
, btn
, state
);
1783 #ifdef XDND /* was OFFIX */
1784 static WDock
*findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1790 if ((dock
= scr
->dock
) != NULL
) {
1791 for (i
= 0; i
< dock
->max_icons
; i
++) {
1792 if (dock
->icon_array
[i
]
1793 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1799 if (*icon_pos
< 0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
) != NULL
) {
1800 for (i
= 0; i
< dock
->max_icons
; i
++) {
1801 if (dock
->icon_array
[i
]
1802 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1813 int wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
1819 dock
= findDock(scr
, event
, &icon_pos
);
1824 * Return True if the drop was on an application icon window.
1825 * In this case, let the ClientMessage handler redirect the
1826 * message to the app.
1828 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
1831 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
1832 scr
->flags
.dnd_data_convertion_status
= 0;
1834 btn
= dock
->icon_array
[icon_pos
];
1836 if (!btn
->forced_dock
) {
1837 btn
->relaunching
= btn
->running
;
1840 if (btn
->wm_instance
|| btn
->wm_class
) {
1841 WWindowAttributes attr
;
1842 memset(&attr
, 0, sizeof(WWindowAttributes
));
1843 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
1845 if (!attr
.no_appicon
)
1851 btn
->paste_launch
= 0;
1852 btn
->drop_launch
= 1;
1853 scr
->last_dock
= dock
;
1854 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1859 if (!btn
->relaunching
) {
1868 Bool
wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1873 wwin
= icon
->icon
->owner
;
1874 if (icon
->command
== NULL
) {
1879 command
= GetCommandForWindow(wwin
->client_win
);
1881 icon
->command
= command
;
1883 /* icon->forced_dock = 1; */
1884 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
1886 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
1887 _("Type the command used to launch the application"), &command
)) {
1888 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
1892 icon
->command
= command
;
1898 /* If the target is the dock, reject the icon. If
1899 * the target is the clip, make it an attracted icon
1901 if (dock
->type
== WM_CLIP
) {
1902 icon
->attracted
= 1;
1903 if (!icon
->icon
->shadowed
) {
1904 icon
->icon
->shadowed
= 1;
1905 icon
->icon
->force_paint
= 1;
1917 for (index
= 1; index
< dock
->max_icons
; index
++)
1918 if (dock
->icon_array
[index
] == NULL
)
1920 /* if (index == dock->max_icons)
1923 assert(index
< dock
->max_icons
);
1925 dock
->icon_array
[index
] = icon
;
1929 icon
->omnipresent
= 0;
1931 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
1932 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
1937 icon
->launching
= 0;
1940 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1941 if (dock
->type
== WM_CLIP
) {
1942 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1943 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1945 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1946 icon
->icon
->core
->descriptor
.parent
= icon
;
1948 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
1949 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
1950 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
)
1997 return True
; /* No move needed, we're already there */
2002 wwin
= icon
->icon
->owner
;
2005 * For the moment we can't do this if we move icons in Clip from one
2006 * workspace to other, because if we move two or more icons without
2007 * command, the dialog box will not be able to tell us to which of the
2008 * moved icons it applies. -Dan
2010 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
2011 command
= GetCommandForWindow(wwin
->client_win
);
2013 icon
->command
= command
;
2016 /* icon->forced_dock = 1; */
2017 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2018 _("Type the command used to launch the application"), &command
)) {
2019 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2023 icon
->command
= command
;
2034 if (dest
->type
== WM_DOCK
)
2035 wClipMakeIconOmnipresent(icon
, False
);
2037 for (index
= 1; index
< src
->max_icons
; index
++) {
2038 if (src
->icon_array
[index
] == icon
)
2041 assert(index
< src
->max_icons
);
2043 src
->icon_array
[index
] = NULL
;
2046 for (index
= 1; index
< dest
->max_icons
; index
++) {
2047 if (dest
->icon_array
[index
] == NULL
)
2050 /* if (index == dest->max_icons)
2053 assert(index
< dest
->max_icons
);
2055 dest
->icon_array
[index
] = icon
;
2058 /* deselect the icon */
2059 if (icon
->icon
->selected
)
2060 wIconSelect(icon
->icon
);
2062 if (dest
->type
== WM_DOCK
) {
2063 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2064 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2066 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2067 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2070 /* set it to be kept when moving to dock.
2071 * Unless the icon does not have a command set
2073 if (icon
->command
&& dest
->type
== WM_DOCK
) {
2074 icon
->attracted
= 0;
2075 if (icon
->icon
->shadowed
) {
2076 icon
->icon
->shadowed
= 0;
2077 icon
->icon
->force_paint
= 1;
2079 save_appicon(icon
, True
);
2082 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2088 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2089 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2093 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2094 wAppIconPaint(icon
);
2099 void wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2103 /* make the settings panel be closed */
2105 DestroyDockAppSettingsPanel(icon
->panel
);
2108 /* This must be called before icon->dock is set to NULL.
2109 * Don't move it. -Dan
2111 wClipMakeIconOmnipresent(icon
, False
);
2115 icon
->attracted
= 0;
2116 icon
->auto_launch
= 0;
2117 if (icon
->icon
->shadowed
) {
2118 icon
->icon
->shadowed
= 0;
2119 icon
->icon
->force_paint
= 1;
2122 /* deselect the icon */
2123 if (icon
->icon
->selected
)
2124 wIconSelect(icon
->icon
);
2126 if (icon
->command
) {
2127 wfree(icon
->command
);
2128 icon
->command
= NULL
;
2130 #ifdef XDND /* was OFFIX */
2131 if (icon
->dnd_command
) {
2132 wfree(icon
->dnd_command
);
2133 icon
->dnd_command
= NULL
;
2136 if (icon
->paste_command
) {
2137 wfree(icon
->paste_command
);
2138 icon
->paste_command
= NULL
;
2141 for (index
= 1; index
< dock
->max_icons
; index
++)
2142 if (dock
->icon_array
[index
] == icon
)
2144 assert(index
< dock
->max_icons
);
2145 dock
->icon_array
[index
] = NULL
;
2151 /* if the dock is not attached to an application or
2152 * the application did not set the appropriate hints yet,
2153 * destroy the icon */
2154 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2155 wAppIconDestroy(icon
);
2157 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2158 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2159 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2160 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2161 icon
->icon
->core
->descriptor
.parent
= icon
;
2163 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2165 wAppIconPaint(icon
);
2166 if (wPreferences
.auto_arrange_icons
) {
2167 wArrangeIcons(dock
->screen_ptr
, True
);
2170 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2175 * returns the closest Dock slot index for the passed
2178 * Returns False if icon can't be docked.
2180 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2183 Bool
wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2185 WScreen
*scr
= dock
->screen_ptr
;
2188 int i
, offset
= ICON_SIZE
/ 2;
2189 WAppIcon
*aicon
= NULL
;
2190 WAppIcon
*nicon
= NULL
;
2193 /* TODO: XINERAMA, for these */
2194 max_y_icons
= scr
->scr_height
/ ICON_SIZE
- 1;
2196 if (wPreferences
.flags
.noupdates
)
2202 /* if the dock is full */
2203 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
)) {
2207 /* exact position */
2209 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2211 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2214 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2216 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2218 /* check if the icon is outside the screen boundaries */
2223 rect
.pos
.x
= dx
+ ex_x
* ICON_SIZE
;
2224 rect
.pos
.y
= dy
+ ex_y
* ICON_SIZE
;
2225 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2227 wGetRectPlacementInfo(scr
, rect
, &flags
);
2228 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
2232 if (dock
->type
== WM_DOCK
) {
2233 if (icon
->dock
!= dock
&& ex_x
!= 0)
2237 for (i
= 0; i
< dock
->max_icons
; i
++) {
2238 nicon
= dock
->icon_array
[i
];
2239 if (nicon
&& nicon
->yindex
== ex_y
) {
2246 int sig
, done
, closest
;
2248 /* Possible cases when redocking:
2250 * icon dragged out of range of any slot -> false
2251 * icon dragged to range of free slot
2252 * icon dragged to range of same slot
2253 * icon dragged to range of different icon
2255 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2258 if (ex_y
>= 0 && ex_y
<= max_y_icons
&& (aicon
== icon
|| !aicon
)) {
2264 /* start looking at the upper slot or lower? */
2265 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2272 /* look for closest free slot */
2273 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2277 closest
= sig
* (i
/ 2) + ex_y
;
2278 /* check if this slot is used */
2280 for (j
= 0; j
< dock
->max_icons
; j
++) {
2281 if (dock
->icon_array
[j
]
2282 && dock
->icon_array
[j
]->yindex
== closest
) {
2283 /* slot is used by someone else */
2284 if (dock
->icon_array
[j
] != icon
)
2292 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2293 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2294 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2299 } else { /* !redocking */
2301 /* if slot is free and the icon is close enough, return it */
2302 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2312 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2313 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+ 1;
2316 for (k
= start
; k
< stop
; k
++) {
2317 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2320 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2321 nicon
= tmp
->icon_array
[i
];
2322 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2330 for (k
= start
; k
< stop
; k
++) {
2331 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2334 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2335 nicon
= tmp
->icon_array
[i
];
2336 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2337 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2338 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2347 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2356 static int onScreen(WScreen
*scr
, int x
, int y
, int sx
, int ex
, int sy
, int ey
)
2358 WMRect rect
= wmkrect(x
, y
, ICON_SIZE
, ICON_SIZE
);
2361 wGetRectPlacementInfo(scr
, rect
, &flags
);
2363 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2367 * returns true if it can find a free slot in the dock,
2368 * in which case it changes x_pos and y_pos accordingly.
2369 * Else returns false.
2371 Bool
wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2373 WScreen
*scr
= dock
->screen_ptr
;
2375 WAppIconChain
*chain
;
2376 unsigned char *slot_map
;
2380 int i
, done
= False
;
2382 int sx
= 0, sy
= 0, ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2383 int extra_count
= 0;
2385 if (dock
->type
== WM_CLIP
&& dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2386 extra_count
= scr
->global_icon_count
;
2388 /* if the dock is full */
2389 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
) {
2393 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2394 if (scr
->dock
->on_right_side
)
2395 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2397 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2400 if (ex
< dock
->x_pos
)
2402 if (sx
> dock
->x_pos
+ ICON_SIZE
)
2403 sx
= dock
->x_pos
+ ICON_SIZE
;
2410 /* check if clip is in a corner */
2411 if (dock
->type
== WM_CLIP
) {
2412 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2414 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2416 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2418 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2425 /* If the clip is in the corner, use only slots that are in the border
2427 if (corner
!= C_NONE
) {
2431 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2432 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2433 hmap
= wmalloc(hcount
+ 1);
2434 vmap
= wmalloc(vcount
+ 1);
2436 /* mark used positions */
2439 for (i
= 0; i
< dock
->max_icons
; i
++) {
2440 btn
= dock
->icon_array
[i
];
2444 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2445 vmap
[btn
->yindex
] = 1;
2446 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2447 hmap
[btn
->xindex
] = 1;
2449 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2451 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2452 vmap
[btn
->yindex
] = 1;
2453 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2454 hmap
[btn
->xindex
] = 1;
2458 for (i
= 0; i
< dock
->max_icons
; i
++) {
2459 btn
= dock
->icon_array
[i
];
2463 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2464 vmap
[btn
->yindex
] = 1;
2465 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2466 hmap
[-btn
->xindex
] = 1;
2468 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2470 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2471 vmap
[btn
->yindex
] = 1;
2472 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2473 hmap
[-btn
->xindex
] = 1;
2477 for (i
= 0; i
< dock
->max_icons
; i
++) {
2478 btn
= dock
->icon_array
[i
];
2482 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2483 vmap
[-btn
->yindex
] = 1;
2484 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2485 hmap
[btn
->xindex
] = 1;
2487 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2489 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2490 vmap
[-btn
->yindex
] = 1;
2491 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2492 hmap
[btn
->xindex
] = 1;
2497 for (i
= 0; i
< dock
->max_icons
; i
++) {
2498 btn
= dock
->icon_array
[i
];
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;
2507 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2509 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2510 vmap
[-btn
->yindex
] = 1;
2511 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2512 hmap
[-btn
->xindex
] = 1;
2518 /* search a vacant slot */
2519 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2520 if (i
< vcount
&& vmap
[i
] == 0) {
2526 } else if (i
< hcount
&& hmap
[i
] == 0) {
2536 /* If found a slot, translate and return */
2538 if (corner
== C_NW
|| corner
== C_NE
) {
2543 if (corner
== C_NE
|| corner
== C_SE
) {
2550 /* else, try to find a slot somewhere else */
2553 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2554 * placed outside of screen */
2555 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2557 /* In the worst case (the clip is in the corner of the screen),
2558 * the amount of icons that fit in the clip is smaller.
2559 * Double the map to get a safe value.
2563 r
= (mwidth
- 1) / 2;
2565 slot_map
= wmalloc(mwidth
* mwidth
);
2567 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2569 /* mark used slots in the map. If the slot falls outside the map
2570 * (for example, when all icons are placed in line), ignore them. */
2571 for (i
= 0; i
< dock
->max_icons
; i
++) {
2572 btn
= dock
->icon_array
[i
];
2574 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2576 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2577 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2579 /* Find closest slot from the center that is free by scanning the
2580 * map from the center to outward in circular passes.
2581 * This will not result in a neat layout, but will be optimal
2582 * in the sense that there will not be holes left.
2585 for (i
= 1; i
<= r
&& !done
; i
++) {
2588 /* top and bottom parts of the ring */
2589 for (x
= -i
; x
<= i
&& !done
; x
++) {
2590 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2592 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2593 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2600 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2601 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2608 /* left and right parts of the ring */
2609 for (y
= -i
+ 1; y
<= i
- 1; y
++) {
2610 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2612 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2613 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2620 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2621 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2634 static void moveDock(WDock
*dock
, int new_x
, int new_y
)
2639 dock
->x_pos
= new_x
;
2640 dock
->y_pos
= new_y
;
2641 for (i
= 0; i
< dock
->max_icons
; i
++) {
2642 btn
= dock
->icon_array
[i
];
2644 btn
->x_pos
= new_x
+ btn
->xindex
* ICON_SIZE
;
2645 btn
->y_pos
= new_y
+ btn
->yindex
* ICON_SIZE
;
2646 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2651 static void swapDock(WDock
*dock
)
2653 WScreen
*scr
= dock
->screen_ptr
;
2657 if (dock
->on_right_side
) {
2658 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2660 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2663 for (i
= 0; i
< dock
->max_icons
; i
++) {
2664 btn
= dock
->icon_array
[i
];
2667 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2671 wScreenUpdateUsableArea(scr
);
2674 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2676 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2682 cmdline
= ExpandOptions(scr
, command
);
2684 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2692 wtokensplit(cmdline
, &argv
, &argc
);
2702 if ((pid
= fork()) == 0) {
2706 SetupEnvironment(scr
);
2712 args
= malloc(sizeof(char *) * (argc
+ 1));
2715 for (i
= 0; i
< argc
; i
++) {
2719 execvp(argv
[0], args
);
2722 wtokenfree(argv
, argc
);
2726 state
= wmalloc(sizeof(WSavedState
));
2728 state
->miniaturized
= -1;
2730 if (btn
->dock
== scr
->dock
|| btn
->omnipresent
)
2731 state
->workspace
= -1;
2733 state
->workspace
= scr
->current_workspace
;
2735 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
2736 wAddDeathHandler(pid
, (WDeathHandler
*) trackDeadProcess
, btn
->dock
);
2744 void wDockHideIcons(WDock
*dock
)
2751 for (i
= 1; i
< dock
->max_icons
; i
++) {
2752 if (dock
->icon_array
[i
])
2753 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2757 dockIconPaint(dock
->icon_array
[0]);
2760 void wDockShowIcons(WDock
*dock
)
2768 btn
= dock
->icon_array
[0];
2769 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2771 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2772 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2774 for (i
= 1; i
< dock
->max_icons
; i
++) {
2775 if (dock
->icon_array
[i
]) {
2776 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
, btn
->icon
->core
);
2781 if (!dock
->collapsed
) {
2782 for (i
= 1; i
< dock
->max_icons
; i
++) {
2783 if (dock
->icon_array
[i
]) {
2784 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2793 void wDockLower(WDock
*dock
)
2797 for (i
= 0; i
< dock
->max_icons
; i
++) {
2798 if (dock
->icon_array
[i
])
2799 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2803 void wDockRaise(WDock
*dock
)
2807 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
2808 if (dock
->icon_array
[i
])
2809 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2813 void wDockRaiseLower(WDock
*dock
)
2815 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2816 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2817 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2823 void wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
2825 icon
->launching
= 0;
2826 icon
->relaunching
= 0;
2827 dockIconPaint(icon
);
2830 WAppIcon
*wDockFindIconForWindow(WDock
*dock
, Window window
)
2835 for (i
= 0; i
< dock
->max_icons
; i
++) {
2836 icon
= dock
->icon_array
[i
];
2837 if (icon
&& icon
->main_window
== window
)
2843 void wDockTrackWindowLaunch(WDock
*dock
, Window window
)
2846 char *wm_class
, *wm_instance
;
2848 Bool firstPass
= True
;
2850 char *command
= NULL
;
2852 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) || (!wm_class
&& !wm_instance
)) {
2856 command
= GetCommandForWindow(window
);
2858 for (i
= 0; i
< dock
->max_icons
; i
++) {
2859 icon
= dock
->icon_array
[i
];
2863 /* app is already attached to icon */
2864 if (icon
->main_window
== window
) {
2869 if ((icon
->wm_instance
|| icon
->wm_class
)
2870 && (icon
->launching
|| !icon
->running
)) {
2872 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0) {
2875 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0) {
2878 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0) {
2882 if (!icon
->relaunching
) {
2885 /* Possibly an application that was docked with dockit,
2886 * but the user did not update WMState to indicate that
2887 * it was docked by force */
2888 wapp
= wApplicationOf(window
);
2890 icon
->forced_dock
= 1;
2893 if (!icon
->forced_dock
) {
2894 icon
->main_window
= window
;
2898 if (!wPreferences
.no_animations
&& !icon
->launching
&&
2899 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
2903 icon
->launching
= 1;
2904 dockIconPaint(icon
);
2906 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
2907 wm_instance
, wm_class
, TILE_NORMAL
);
2908 /* XXX: can: aicon->icon == NULL ? */
2909 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
2910 wAppIconMove(aicon
, x0
, y0
);
2911 /* Should this always be lowered? -Dan */
2913 wLowerFrame(aicon
->icon
->core
);
2914 XMapWindow(dpy
, aicon
->icon
->core
->window
);
2915 aicon
->launching
= 1;
2916 wAppIconPaint(aicon
);
2917 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
2918 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
2919 wAppIconDestroy(aicon
);
2921 wDockFinishLaunch(dock
, icon
);
2926 if (firstPass
&& !found
) {
2940 void wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
2942 if (!wPreferences
.flags
.noclip
) {
2943 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
2944 if (scr
->current_workspace
!= workspace
) {
2945 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
2946 WAppIconChain
*chain
= scr
->global_icons
;
2949 moveIconBetweenDocks(chain
->aicon
->dock
,
2950 scr
->workspaces
[workspace
]->clip
,
2951 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
2952 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
2953 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
2954 chain
= chain
->next
;
2957 wDockHideIcons(old_clip
);
2958 if (old_clip
->auto_raise_lower
) {
2959 if (old_clip
->auto_raise_magic
) {
2960 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
2961 old_clip
->auto_raise_magic
= NULL
;
2963 wDockLower(old_clip
);
2965 if (old_clip
->auto_collapse
) {
2966 if (old_clip
->auto_expand_magic
) {
2967 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
2968 old_clip
->auto_expand_magic
= NULL
;
2970 old_clip
->collapsed
= 1;
2972 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
2977 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
2982 for (i
= 0; i
< dock
->max_icons
; i
++) {
2983 icon
= dock
->icon_array
[i
];
2987 if (icon
->launching
&& icon
->pid
== pid
) {
2988 if (!icon
->relaunching
) {
2990 icon
->main_window
= None
;
2992 wDockFinishLaunch(dock
, icon
);
2994 if (status
== 111) {
2999 if (icon
->drop_launch
)
3000 cmd
= icon
->dnd_command
;
3003 if (icon
->paste_launch
)
3004 cmd
= icon
->paste_command
;
3006 cmd
= icon
->command
;
3008 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3010 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3017 static void toggleLowered(WDock
*dock
)
3022 /* lower/raise Dock */
3023 if (!dock
->lowered
) {
3024 newlevel
= WMNormalLevel
;
3027 newlevel
= WMDockLevel
;
3031 for (i
= 0; i
< dock
->max_icons
; i
++) {
3032 tmp
= dock
->icon_array
[i
];
3036 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3038 wLowerFrame(tmp
->icon
->core
);
3041 if (dock
->type
== WM_DOCK
)
3042 wScreenUpdateUsableArea(dock
->screen_ptr
);
3045 static void toggleCollapsed(WDock
*dock
)
3047 if (dock
->collapsed
) {
3048 dock
->collapsed
= 0;
3049 wDockShowIcons(dock
);
3051 dock
->collapsed
= 1;
3052 wDockHideIcons(dock
);
3056 static void openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3058 WScreen
*scr
= dock
->screen_ptr
;
3059 WObjDescriptor
*desc
;
3061 WApplication
*wapp
= NULL
;
3065 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3067 if (dock
->type
== WM_DOCK
) {
3069 entry
= dock
->menu
->entries
[index
];
3070 entry
->flags
.indicator_on
= !dock
->lowered
;
3071 entry
->clientdata
= dock
;
3072 dock
->menu
->flags
.realized
= 0;
3075 if (scr
->clip_options
)
3076 updateClipOptionsMenu(scr
->clip_options
, dock
);
3078 n_selected
= numberOfSelectedIcons(dock
);
3080 /* Rename Workspace */
3081 entry
= dock
->menu
->entries
[++index
];
3082 if (aicon
== scr
->clip_icon
) {
3083 entry
->callback
= renameCallback
;
3084 entry
->clientdata
= dock
;
3085 entry
->flags
.indicator
= 0;
3086 entry
->text
= _("Rename Workspace");
3088 entry
->callback
= omnipresentCallback
;
3089 entry
->clientdata
= aicon
;
3090 if (n_selected
> 0) {
3091 entry
->flags
.indicator
= 0;
3092 entry
->text
= _("Toggle Omnipresent");
3094 entry
->flags
.indicator
= 1;
3095 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3096 entry
->flags
.indicator_type
= MI_CHECK
;
3097 entry
->text
= _("Omnipresent");
3101 /* select/unselect icon */
3102 entry
= dock
->menu
->entries
[++index
];
3103 entry
->clientdata
= aicon
;
3104 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3105 wMenuSetEnabled(dock
->menu
, index
, aicon
!= scr
->clip_icon
);
3107 /* select/unselect all icons */
3108 entry
= dock
->menu
->entries
[++index
];
3109 entry
->clientdata
= aicon
;
3111 entry
->text
= _("Unselect All Icons");
3113 entry
->text
= _("Select All Icons");
3114 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3117 entry
= dock
->menu
->entries
[++index
];
3118 entry
->clientdata
= aicon
;
3120 entry
->text
= _("Keep Icons");
3122 entry
->text
= _("Keep Icon");
3123 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3125 /* this is the workspace submenu part */
3126 entry
= dock
->menu
->entries
[++index
];
3128 entry
->text
= _("Move Icons To");
3130 entry
->text
= _("Move Icon To");
3131 if (scr
->clip_submenu
)
3132 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3133 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3135 /* remove icon(s) */
3136 entry
= dock
->menu
->entries
[++index
];
3137 entry
->clientdata
= aicon
;
3139 entry
->text
= _("Remove Icons");
3141 entry
->text
= _("Remove Icon");
3142 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3144 /* attract icon(s) */
3145 entry
= dock
->menu
->entries
[++index
];
3146 entry
->clientdata
= aicon
;
3148 dock
->menu
->flags
.realized
= 0;
3149 wMenuRealize(dock
->menu
);
3152 if (aicon
->icon
->owner
) {
3153 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3159 entry
= dock
->menu
->entries
[++index
];
3160 entry
->clientdata
= aicon
;
3161 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3164 entry
= dock
->menu
->entries
[++index
];
3165 entry
->clientdata
= aicon
;
3166 if (wapp
&& wapp
->flags
.hidden
) {
3167 entry
->text
= _("Unhide Here");
3169 entry
->text
= _("Bring Here");
3171 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3174 entry
= dock
->menu
->entries
[++index
];
3175 entry
->clientdata
= aicon
;
3176 if (wapp
&& wapp
->flags
.hidden
) {
3177 entry
->text
= _("Unhide");
3179 entry
->text
= _("Hide");
3181 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3184 entry
= dock
->menu
->entries
[++index
];
3185 entry
->clientdata
= aicon
;
3186 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3189 entry
= dock
->menu
->entries
[++index
];
3190 entry
->clientdata
= aicon
;
3191 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3193 if (!dock
->menu
->flags
.realized
)
3194 wMenuRealize(dock
->menu
);
3196 if (dock
->type
== WM_CLIP
) {
3197 /*x_pos = event->xbutton.x_root+2; */
3198 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3201 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3202 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3205 x_pos
= dock
->on_right_side
? scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3208 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3210 /* allow drag select */
3211 event
->xany
.send_event
= True
;
3212 desc
= &dock
->menu
->menu
->descriptor
;
3213 (*desc
->handle_mousedown
) (desc
, event
);
3216 /******************************************************************/
3217 static void iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3219 WAppIcon
*btn
= desc
->parent
;
3220 WDock
*dock
= btn
->dock
;
3221 WApplication
*wapp
= NULL
;
3224 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3225 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3227 assert(wapp
!= NULL
);
3229 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3231 /* go to the last workspace that the user worked on the app */
3232 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
&& !unhideHere
) {
3233 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3236 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3238 if (event
->xbutton
.state
& MOD_MASK
) {
3239 wHideOtherApplications(btn
->icon
->owner
);
3242 if (event
->xbutton
.button
== Button1
) {
3244 if (event
->xbutton
.state
& MOD_MASK
) {
3245 /* raise/lower dock */
3246 toggleLowered(dock
);
3247 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3248 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
)
3249 toggleCollapsed(dock
);
3251 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3252 } else if (btn
->command
) {
3253 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3254 launchDockedApplication(btn
, False
);
3260 static void handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3262 WScreen
*scr
= dock
->screen_ptr
;
3263 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3266 int grabbed
= 0, swapped
= 0, done
;
3267 Pixmap ghost
= None
;
3268 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3270 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3271 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3272 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3273 wwarning("pointer grab failed for dock move");
3276 for (x
= 0; x
< dock
->max_icons
; x
++) {
3277 if (dock
->icon_array
[x
] != NULL
&& dock
->icon_array
[x
]->yindex
> y
)
3278 y
= dock
->icon_array
[x
]->yindex
;
3281 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
* y
);
3285 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3286 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3293 /* It means the cursor moved so fast that it entered
3294 * something else (if moving slowly, it would have
3295 * stayed in the dock that is being moved. Ignore such
3296 * "spurious" EnterNotifiy's */
3301 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3302 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3303 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3304 | ButtonReleaseMask
| ButtonPressMask
,
3305 wCursor
[WCUR_MOVE
], CurrentTime
);
3310 if (dock
->type
== WM_CLIP
) {
3311 x
= ev
.xmotion
.x_root
- ofs_x
;
3312 y
= ev
.xmotion
.y_root
- ofs_y
;
3313 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3315 moveDock(dock
, x
, y
);
3317 /* move vertically if pointer is inside the dock */
3318 if ((dock
->on_right_side
&& ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3319 || (!dock
->on_right_side
&& ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
* 2)) {
3321 x
= ev
.xmotion
.x_root
- ofs_x
;
3322 y
= ev
.xmotion
.y_root
- ofs_y
;
3323 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3324 moveDock(dock
, dock
->x_pos
, y
);
3326 /* move horizontally to change sides */
3327 x
= ev
.xmotion
.x_root
- ofs_x
;
3328 if (!dock
->on_right_side
) {
3332 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
* 2) {
3333 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
- ICON_SIZE
3334 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3335 if (superfluous
&& ghost
== None
) {
3336 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3337 scr
->scr_width
- ICON_SIZE
3338 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3339 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3340 XClearWindow(dpy
, scr
->dock_shadow
);
3342 XMapRaised(dpy
, scr
->dock_shadow
);
3345 if (superfluous
&& ghost
!= None
) {
3346 XFreePixmap(dpy
, ghost
);
3349 XUnmapWindow(dpy
, scr
->dock_shadow
);
3354 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3355 XMoveWindow(dpy
, scr
->dock_shadow
, DOCK_EXTRA_SPACE
, dock
->y_pos
);
3356 if (superfluous
&& ghost
== None
) {
3357 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3358 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3359 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3360 XClearWindow(dpy
, scr
->dock_shadow
);
3362 XMapRaised(dpy
, scr
->dock_shadow
);
3365 XUnmapWindow(dpy
, scr
->dock_shadow
);
3367 if (superfluous
&& ghost
!= None
) {
3368 XFreePixmap(dpy
, ghost
);
3380 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3382 XUngrabPointer(dpy
, CurrentTime
);
3383 XUnmapWindow(dpy
, scr
->dock_shadow
);
3384 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3385 if (dock
->type
== WM_DOCK
) {
3388 dock
->on_right_side
= 1;
3390 dock
->on_right_side
= 0;
3392 wArrangeIcons(scr
, False
);
3401 XFreePixmap(dpy
, ghost
);
3402 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3406 static Bool
handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3408 WScreen
*scr
= dock
->screen_ptr
;
3410 WIcon
*icon
= aicon
->icon
;
3411 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3412 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3414 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3415 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3416 int shad_x
= x
, shad_y
= y
;
3417 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3419 Pixmap ghost
= None
;
3421 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3422 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3423 Bool hasMoved
= False
;
3425 if (wPreferences
.flags
.noupdates
)
3428 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3429 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3430 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3433 if (!(event
->xbutton
.state
& MOD_MASK
))
3434 wRaiseFrame(icon
->core
);
3436 if (!wPreferences
.flags
.noclip
)
3437 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3439 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3441 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3444 wins
[0] = icon
->core
->window
;
3445 wins
[1] = scr
->dock_shadow
;
3446 XRestackWindows(dpy
, wins
, 2);
3447 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
3449 if (icon
->pixmap
!= None
)
3450 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3452 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3454 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3455 XClearWindow(dpy
, scr
->dock_shadow
);
3457 XMapWindow(dpy
, scr
->dock_shadow
);
3462 XMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3463 | ButtonMotionMask
| ExposureMask
, &ev
);
3472 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3473 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3474 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3475 | ButtonReleaseMask
| ButtonPressMask
,
3476 wCursor
[WCUR_MOVE
], CurrentTime
);
3485 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3486 if (i
== scr
->current_workspace
)
3488 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3492 x
= ev
.xmotion
.x_root
- ofs_x
;
3493 y
= ev
.xmotion
.y_root
- ofs_y
;
3494 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3497 if (last_dock
!= dock
&& collapsed
) {
3498 last_dock
->collapsed
= 1;
3499 wDockHideIcons(last_dock
);
3502 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3503 dock
->collapsed
= 0;
3504 wDockShowIcons(dock
);
3506 if (dock
->auto_raise_lower
)
3510 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3513 if (last_dock
!= dock2
&& collapsed
) {
3514 last_dock
->collapsed
= 1;
3515 wDockHideIcons(last_dock
);
3518 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3519 dock2
->collapsed
= 0;
3520 wDockShowIcons(dock2
);
3522 if (dock2
->auto_raise_lower
)
3527 if (aicon
->launching
|| aicon
->lock
|| (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3528 || (!aicon
->running
&& tmp
)) {
3529 shad_x
= last_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3530 shad_y
= last_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3532 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3535 XMapWindow(dpy
, scr
->dock_shadow
);
3540 XUnmapWindow(dpy
, scr
->dock_shadow
);
3544 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3551 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3553 XUngrabPointer(dpy
, CurrentTime
);
3555 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3556 XUnmapWindow(dpy
, scr
->dock_shadow
);
3558 reattachIcon(dock
, aicon
, ix
, iy
);
3559 if (clip
&& dock
!= clip
&& clip
->auto_raise_lower
)
3562 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3564 /* Slide it back if dock rejected it */
3565 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
, aicon
->y_pos
);
3566 reattachIcon(dock
, aicon
, aicon
->xindex
, aicon
->yindex
);
3568 if (last_dock
->type
== WM_CLIP
&& last_dock
->auto_collapse
) {
3576 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3577 /* We need to deselect it, even if is deselected in
3578 * wDockDetach(), because else DoKaboom() will fail.
3580 if (aicon
->icon
->selected
)
3581 wIconSelect(aicon
->icon
);
3583 DoKaboom(scr
, aicon
->icon
->core
->window
, x
, y
);
3586 if (clip
&& clip
->auto_raise_lower
)
3588 wDockDetach(dock
, aicon
);
3591 last_dock
->collapsed
= 1;
3592 wDockHideIcons(last_dock
);
3597 XFreePixmap(dpy
, ghost
);
3598 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3602 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3603 if (i
== scr
->current_workspace
)
3605 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3611 return False
; /* never reached */
3614 static int getClipButton(int px
, int py
)
3616 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3618 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3621 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3622 return CLIP_FORWARD
;
3623 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3629 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3632 int done
, direction
, new_ws
;
3634 WDock
*clip
= scr
->clip_icon
->dock
;
3636 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3638 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3639 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3641 wClipIconPaint(scr
->clip_icon
);
3644 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3651 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3652 if (new_dir
!= direction
) {
3653 direction
= new_dir
;
3654 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3655 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3656 wClipIconPaint(scr
->clip_icon
);
3664 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3669 clip
->lclip_button_pushed
= 0;
3670 clip
->rclip_button_pushed
= 0;
3672 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3674 if (direction
== CLIP_FORWARD
) {
3675 if (scr
->current_workspace
< scr
->workspace_count
- 1)
3676 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3677 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
- 1)
3678 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3679 else if (wPreferences
.ws_cycle
)
3680 wWorkspaceChange(scr
, 0);
3681 } else if (direction
== CLIP_REWIND
) {
3682 if (scr
->current_workspace
> 0)
3683 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
3684 else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
)
3685 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
3688 wClipIconPaint(scr
->clip_icon
);
3691 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3693 WAppIcon
*aicon
= desc
->parent
;
3694 WDock
*dock
= aicon
->dock
;
3695 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3697 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3700 scr
->last_dock
= dock
;
3702 if (dock
->menu
->flags
.mapped
)
3703 wMenuUnmap(dock
->menu
);
3705 if (IsDoubleClick(scr
, event
)) {
3706 /* double-click was not in the main clip icon */
3707 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3708 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3709 iconDblClick(desc
, event
);
3714 if (event
->xbutton
.button
== Button1
) {
3715 if (event
->xbutton
.state
& MOD_MASK
)
3720 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
&& dock
->type
!= WM_DOCK
) {
3721 wIconSelect(aicon
->icon
);
3725 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3726 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
3727 && dock
->type
== WM_CLIP
)
3728 handleClipChangeWorkspace(scr
, event
);
3730 handleDockMove(dock
, aicon
, event
);
3732 Bool hasMoved
= handleIconMove(dock
, aicon
, event
);
3733 if (wPreferences
.single_click
&& !hasMoved
)
3734 iconDblClick(desc
, event
);
3736 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&& aicon
== scr
->clip_icon
) {
3737 if (!scr
->clip_ws_menu
) {
3738 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3740 if (scr
->clip_ws_menu
) {
3741 WMenu
*wsMenu
= scr
->clip_ws_menu
;
3744 wWorkspaceMenuUpdate(scr
, wsMenu
);
3746 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
3749 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
3750 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
3752 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
3754 desc
= &wsMenu
->menu
->descriptor
;
3755 event
->xany
.send_event
= True
;
3756 (*desc
->handle_mousedown
) (desc
, event
);
3758 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
3759 (event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
) {
3760 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3761 } else if (event
->xbutton
.button
== Button3
) {
3762 if (event
->xbutton
.send_event
&&
3763 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3764 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3765 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3766 wwarning("pointer grab failed for dockicon menu");
3770 openDockMenu(dock
, aicon
, event
);
3771 } else if (event
->xbutton
.button
== Button2
) {
3772 WAppIcon
*btn
= desc
->parent
;
3774 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3775 launchDockedApplication(btn
, True
);
3780 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3782 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3786 assert(event
->type
== EnterNotify
);
3788 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3791 scr
= btn
->icon
->core
->screen_ptr
;
3792 if (!btn
->omnipresent
)
3795 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3797 if (!dock
|| dock
->type
!= WM_CLIP
)
3800 /* The auto raise/lower code */
3801 if (dock
->auto_lower_magic
) {
3802 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3803 dock
->auto_lower_magic
= NULL
;
3805 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
3806 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
, clipAutoRaise
, (void *)dock
);
3809 /* The auto expand/collapse code */
3810 if (dock
->auto_collapse_magic
) {
3811 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3812 dock
->auto_collapse_magic
= NULL
;
3814 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
3815 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
, clipAutoExpand
, (void *)dock
);
3819 static void clipLeave(WDock
*dock
)
3822 WObjDescriptor
*desc
= NULL
;
3824 if (!dock
|| dock
->type
!= WM_CLIP
)
3827 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
3828 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3829 (XPointer
*) & desc
) != XCNOENT
3830 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
3831 && ((WAppIcon
*) desc
->parent
)->dock
&& ((WAppIcon
*) desc
->parent
)->dock
->type
== WM_CLIP
) {
3832 /* We didn't left the Clip yet */
3833 XPutBackEvent(dpy
, &event
);
3837 XPutBackEvent(dpy
, &event
);
3839 /* We entered a withdrawn window, so we're still in Clip */
3843 if (dock
->auto_raise_magic
) {
3844 WMDeleteTimerHandler(dock
->auto_raise_magic
);
3845 dock
->auto_raise_magic
= NULL
;
3847 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
3848 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
, clipAutoLower
, (void *)dock
);
3851 if (dock
->auto_expand_magic
) {
3852 WMDeleteTimerHandler(dock
->auto_expand_magic
);
3853 dock
->auto_expand_magic
= NULL
;
3855 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
3856 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
, clipAutoCollapse
, (void *)dock
);
3860 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
3862 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3864 assert(event
->type
== LeaveNotify
);
3866 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3869 clipLeave(btn
->dock
);
3872 static void clipAutoCollapse(void *cdata
)
3874 WDock
*dock
= (WDock
*) cdata
;
3876 if (dock
->type
!= WM_CLIP
)
3879 if (dock
->auto_collapse
) {
3880 dock
->collapsed
= 1;
3881 wDockHideIcons(dock
);
3883 dock
->auto_collapse_magic
= NULL
;
3886 static void clipAutoExpand(void *cdata
)
3888 WDock
*dock
= (WDock
*) cdata
;
3890 if (dock
->type
!= WM_CLIP
)
3893 if (dock
->auto_collapse
) {
3894 dock
->collapsed
= 0;
3895 wDockShowIcons(dock
);
3897 dock
->auto_expand_magic
= NULL
;
3900 static void clipAutoLower(void *cdata
)
3902 WDock
*dock
= (WDock
*) cdata
;
3904 if (dock
->type
!= WM_CLIP
)
3907 if (dock
->auto_raise_lower
)
3910 dock
->auto_lower_magic
= NULL
;
3913 static void clipAutoRaise(void *cdata
)
3915 WDock
*dock
= (WDock
*) cdata
;
3917 if (dock
->type
!= WM_CLIP
)
3920 if (dock
->auto_raise_lower
)
3923 dock
->auto_raise_magic
= NULL
;
3926 static Bool
iconCanBeOmnipresent(WAppIcon
*aicon
)
3928 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3933 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3934 clip
= scr
->workspaces
[i
]->clip
;
3936 if (clip
== aicon
->dock
)
3939 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
3940 return False
; /* Clip is full in some workspace */
3942 for (j
= 0; j
< clip
->max_icons
; j
++) {
3943 btn
= clip
->icon_array
[j
];
3944 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
3952 int wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
3954 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3955 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
3956 int status
= WO_SUCCESS
;
3958 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== scr
->clip_icon
) {
3959 return WO_NOT_APPLICABLE
;
3962 if (aicon
->omnipresent
== omnipresent
)
3966 if (iconCanBeOmnipresent(aicon
)) {
3967 aicon
->omnipresent
= 1;
3968 new_entry
= wmalloc(sizeof(WAppIconChain
));
3969 new_entry
->aicon
= aicon
;
3970 new_entry
->next
= scr
->global_icons
;
3971 scr
->global_icons
= new_entry
;
3972 scr
->global_icon_count
++;
3974 aicon
->omnipresent
= 0;
3978 aicon
->omnipresent
= 0;
3979 if (aicon
== scr
->global_icons
->aicon
) {
3980 tmp
= scr
->global_icons
->next
;
3981 wfree(scr
->global_icons
);
3982 scr
->global_icons
= tmp
;
3983 scr
->global_icon_count
--;
3985 tmp
= scr
->global_icons
;
3987 if (tmp
->next
->aicon
== aicon
) {
3988 tmp1
= tmp
->next
->next
;
3991 scr
->global_icon_count
--;
3999 wAppIconPaint(aicon
);