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(scr
, 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
->icon
->core
->screen_ptr
,
1844 btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
1846 if (!attr
.no_appicon
)
1852 btn
->paste_launch
= 0;
1853 btn
->drop_launch
= 1;
1854 scr
->last_dock
= dock
;
1855 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1860 if (!btn
->relaunching
) {
1869 Bool
wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1874 wwin
= icon
->icon
->owner
;
1875 if (icon
->command
== NULL
) {
1880 command
= GetCommandForWindow(wwin
->client_win
);
1882 icon
->command
= command
;
1884 /* icon->forced_dock = 1; */
1885 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
1887 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
1888 _("Type the command used to launch the application"), &command
)) {
1889 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
1893 icon
->command
= command
;
1899 /* If the target is the dock, reject the icon. If
1900 * the target is the clip, make it an attracted icon
1902 if (dock
->type
== WM_CLIP
) {
1903 icon
->attracted
= 1;
1904 if (!icon
->icon
->shadowed
) {
1905 icon
->icon
->shadowed
= 1;
1906 icon
->icon
->force_paint
= 1;
1918 for (index
= 1; index
< dock
->max_icons
; index
++)
1919 if (dock
->icon_array
[index
] == NULL
)
1921 /* if (index == dock->max_icons)
1924 assert(index
< dock
->max_icons
);
1926 dock
->icon_array
[index
] = icon
;
1930 icon
->omnipresent
= 0;
1932 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
1933 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
1938 icon
->launching
= 0;
1941 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1942 if (dock
->type
== WM_CLIP
) {
1943 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1944 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1946 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1947 icon
->icon
->core
->descriptor
.parent
= icon
;
1949 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
1950 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
1951 wAppIconPaint(icon
);
1952 save_appicon(icon
, True
);
1954 if (wPreferences
.auto_arrange_icons
)
1955 wArrangeIcons(dock
->screen_ptr
, True
);
1957 #ifdef XDND /* was OFFIX */
1958 if (icon
->command
&& !icon
->dnd_command
) {
1959 int len
= strlen(icon
->command
) + 8;
1960 icon
->dnd_command
= wmalloc(len
);
1961 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
1965 if (icon
->command
&& !icon
->paste_command
) {
1966 int len
= strlen(icon
->command
) + 8;
1967 icon
->paste_command
= wmalloc(len
);
1968 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
1974 static void reattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1978 for (index
= 1; index
< dock
->max_icons
; index
++) {
1979 if (dock
->icon_array
[index
] == icon
)
1982 assert(index
< dock
->max_icons
);
1987 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
1988 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
1991 static Bool
moveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
1998 return True
; /* No move needed, we're already there */
2003 wwin
= icon
->icon
->owner
;
2006 * For the moment we can't do this if we move icons in Clip from one
2007 * workspace to other, because if we move two or more icons without
2008 * command, the dialog box will not be able to tell us to which of the
2009 * moved icons it applies. -Dan
2011 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
2012 command
= GetCommandForWindow(wwin
->client_win
);
2014 icon
->command
= command
;
2017 /* icon->forced_dock = 1; */
2018 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2019 _("Type the command used to launch the application"), &command
)) {
2020 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2024 icon
->command
= command
;
2035 if (dest
->type
== WM_DOCK
)
2036 wClipMakeIconOmnipresent(icon
, False
);
2038 for (index
= 1; index
< src
->max_icons
; index
++) {
2039 if (src
->icon_array
[index
] == icon
)
2042 assert(index
< src
->max_icons
);
2044 src
->icon_array
[index
] = NULL
;
2047 for (index
= 1; index
< dest
->max_icons
; index
++) {
2048 if (dest
->icon_array
[index
] == NULL
)
2051 /* if (index == dest->max_icons)
2054 assert(index
< dest
->max_icons
);
2056 dest
->icon_array
[index
] = icon
;
2059 /* deselect the icon */
2060 if (icon
->icon
->selected
)
2061 wIconSelect(icon
->icon
);
2063 if (dest
->type
== WM_DOCK
) {
2064 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2065 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2067 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2068 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2071 /* set it to be kept when moving to dock.
2072 * Unless the icon does not have a command set
2074 if (icon
->command
&& dest
->type
== WM_DOCK
) {
2075 icon
->attracted
= 0;
2076 if (icon
->icon
->shadowed
) {
2077 icon
->icon
->shadowed
= 0;
2078 icon
->icon
->force_paint
= 1;
2080 save_appicon(icon
, True
);
2083 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2089 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2090 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2094 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2095 wAppIconPaint(icon
);
2100 void wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2104 /* make the settings panel be closed */
2106 DestroyDockAppSettingsPanel(icon
->panel
);
2109 /* This must be called before icon->dock is set to NULL.
2110 * Don't move it. -Dan
2112 wClipMakeIconOmnipresent(icon
, False
);
2116 icon
->attracted
= 0;
2117 icon
->auto_launch
= 0;
2118 if (icon
->icon
->shadowed
) {
2119 icon
->icon
->shadowed
= 0;
2120 icon
->icon
->force_paint
= 1;
2123 /* deselect the icon */
2124 if (icon
->icon
->selected
)
2125 wIconSelect(icon
->icon
);
2127 if (icon
->command
) {
2128 wfree(icon
->command
);
2129 icon
->command
= NULL
;
2131 #ifdef XDND /* was OFFIX */
2132 if (icon
->dnd_command
) {
2133 wfree(icon
->dnd_command
);
2134 icon
->dnd_command
= NULL
;
2137 if (icon
->paste_command
) {
2138 wfree(icon
->paste_command
);
2139 icon
->paste_command
= NULL
;
2142 for (index
= 1; index
< dock
->max_icons
; index
++)
2143 if (dock
->icon_array
[index
] == icon
)
2145 assert(index
< dock
->max_icons
);
2146 dock
->icon_array
[index
] = NULL
;
2152 /* if the dock is not attached to an application or
2153 * the application did not set the appropriate hints yet,
2154 * destroy the icon */
2155 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2156 wAppIconDestroy(icon
);
2158 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2159 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2160 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2161 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2162 icon
->icon
->core
->descriptor
.parent
= icon
;
2164 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2166 wAppIconPaint(icon
);
2167 if (wPreferences
.auto_arrange_icons
) {
2168 wArrangeIcons(dock
->screen_ptr
, True
);
2171 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2176 * returns the closest Dock slot index for the passed
2179 * Returns False if icon can't be docked.
2181 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2184 Bool
wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2186 WScreen
*scr
= dock
->screen_ptr
;
2189 int i
, offset
= ICON_SIZE
/ 2;
2190 WAppIcon
*aicon
= NULL
;
2191 WAppIcon
*nicon
= NULL
;
2194 /* TODO: XINERAMA, for these */
2195 max_y_icons
= scr
->scr_height
/ ICON_SIZE
- 1;
2197 if (wPreferences
.flags
.noupdates
)
2203 /* if the dock is full */
2204 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
)) {
2208 /* exact position */
2210 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2212 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2215 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2217 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2219 /* check if the icon is outside the screen boundaries */
2224 rect
.pos
.x
= dx
+ ex_x
* ICON_SIZE
;
2225 rect
.pos
.y
= dy
+ ex_y
* ICON_SIZE
;
2226 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2228 wGetRectPlacementInfo(scr
, rect
, &flags
);
2229 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
2233 if (dock
->type
== WM_DOCK
) {
2234 if (icon
->dock
!= dock
&& ex_x
!= 0)
2238 for (i
= 0; i
< dock
->max_icons
; i
++) {
2239 nicon
= dock
->icon_array
[i
];
2240 if (nicon
&& nicon
->yindex
== ex_y
) {
2247 int sig
, done
, closest
;
2249 /* Possible cases when redocking:
2251 * icon dragged out of range of any slot -> false
2252 * icon dragged to range of free slot
2253 * icon dragged to range of same slot
2254 * icon dragged to range of different icon
2256 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2259 if (ex_y
>= 0 && ex_y
<= max_y_icons
&& (aicon
== icon
|| !aicon
)) {
2265 /* start looking at the upper slot or lower? */
2266 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2273 /* look for closest free slot */
2274 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2278 closest
= sig
* (i
/ 2) + ex_y
;
2279 /* check if this slot is used */
2281 for (j
= 0; j
< dock
->max_icons
; j
++) {
2282 if (dock
->icon_array
[j
]
2283 && dock
->icon_array
[j
]->yindex
== closest
) {
2284 /* slot is used by someone else */
2285 if (dock
->icon_array
[j
] != icon
)
2293 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2294 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2295 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2300 } else { /* !redocking */
2302 /* if slot is free and the icon is close enough, return it */
2303 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2313 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2314 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+ 1;
2317 for (k
= start
; k
< stop
; k
++) {
2318 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2321 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2322 nicon
= tmp
->icon_array
[i
];
2323 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2331 for (k
= start
; k
< stop
; k
++) {
2332 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2335 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2336 nicon
= tmp
->icon_array
[i
];
2337 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2338 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2339 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2348 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2357 static int onScreen(WScreen
*scr
, int x
, int y
, int sx
, int ex
, int sy
, int ey
)
2359 WMRect rect
= wmkrect(x
, y
, ICON_SIZE
, ICON_SIZE
);
2362 wGetRectPlacementInfo(scr
, rect
, &flags
);
2364 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2368 * returns true if it can find a free slot in the dock,
2369 * in which case it changes x_pos and y_pos accordingly.
2370 * Else returns false.
2372 Bool
wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2374 WScreen
*scr
= dock
->screen_ptr
;
2376 WAppIconChain
*chain
;
2377 unsigned char *slot_map
;
2381 int i
, done
= False
;
2383 int sx
= 0, sy
= 0, ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2384 int extra_count
= 0;
2386 if (dock
->type
== WM_CLIP
&& dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2387 extra_count
= scr
->global_icon_count
;
2389 /* if the dock is full */
2390 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
) {
2394 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2395 if (scr
->dock
->on_right_side
)
2396 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2398 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2401 if (ex
< dock
->x_pos
)
2403 if (sx
> dock
->x_pos
+ ICON_SIZE
)
2404 sx
= dock
->x_pos
+ ICON_SIZE
;
2411 /* check if clip is in a corner */
2412 if (dock
->type
== WM_CLIP
) {
2413 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2415 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2417 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2419 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2426 /* If the clip is in the corner, use only slots that are in the border
2428 if (corner
!= C_NONE
) {
2432 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2433 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2434 hmap
= wmalloc(hcount
+ 1);
2435 vmap
= wmalloc(vcount
+ 1);
2437 /* mark used positions */
2440 for (i
= 0; i
< dock
->max_icons
; i
++) {
2441 btn
= dock
->icon_array
[i
];
2445 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2446 vmap
[btn
->yindex
] = 1;
2447 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2448 hmap
[btn
->xindex
] = 1;
2450 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2452 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2453 vmap
[btn
->yindex
] = 1;
2454 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2455 hmap
[btn
->xindex
] = 1;
2459 for (i
= 0; i
< dock
->max_icons
; i
++) {
2460 btn
= dock
->icon_array
[i
];
2464 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2465 vmap
[btn
->yindex
] = 1;
2466 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2467 hmap
[-btn
->xindex
] = 1;
2469 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2471 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2472 vmap
[btn
->yindex
] = 1;
2473 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2474 hmap
[-btn
->xindex
] = 1;
2478 for (i
= 0; i
< dock
->max_icons
; i
++) {
2479 btn
= dock
->icon_array
[i
];
2483 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2484 vmap
[-btn
->yindex
] = 1;
2485 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2486 hmap
[btn
->xindex
] = 1;
2488 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2490 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2491 vmap
[-btn
->yindex
] = 1;
2492 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2493 hmap
[btn
->xindex
] = 1;
2498 for (i
= 0; i
< dock
->max_icons
; i
++) {
2499 btn
= dock
->icon_array
[i
];
2503 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2504 vmap
[-btn
->yindex
] = 1;
2505 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2506 hmap
[-btn
->xindex
] = 1;
2508 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2510 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2511 vmap
[-btn
->yindex
] = 1;
2512 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2513 hmap
[-btn
->xindex
] = 1;
2519 /* search a vacant slot */
2520 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2521 if (i
< vcount
&& vmap
[i
] == 0) {
2527 } else if (i
< hcount
&& hmap
[i
] == 0) {
2537 /* If found a slot, translate and return */
2539 if (corner
== C_NW
|| corner
== C_NE
) {
2544 if (corner
== C_NE
|| corner
== C_SE
) {
2551 /* else, try to find a slot somewhere else */
2554 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2555 * placed outside of screen */
2556 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2558 /* In the worst case (the clip is in the corner of the screen),
2559 * the amount of icons that fit in the clip is smaller.
2560 * Double the map to get a safe value.
2564 r
= (mwidth
- 1) / 2;
2566 slot_map
= wmalloc(mwidth
* mwidth
);
2568 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2570 /* mark used slots in the map. If the slot falls outside the map
2571 * (for example, when all icons are placed in line), ignore them. */
2572 for (i
= 0; i
< dock
->max_icons
; i
++) {
2573 btn
= dock
->icon_array
[i
];
2575 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2577 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2578 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2580 /* Find closest slot from the center that is free by scanning the
2581 * map from the center to outward in circular passes.
2582 * This will not result in a neat layout, but will be optimal
2583 * in the sense that there will not be holes left.
2586 for (i
= 1; i
<= r
&& !done
; i
++) {
2589 /* top and bottom parts of the ring */
2590 for (x
= -i
; x
<= i
&& !done
; x
++) {
2591 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2593 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2594 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2601 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2602 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2609 /* left and right parts of the ring */
2610 for (y
= -i
+ 1; y
<= i
- 1; y
++) {
2611 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2613 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2614 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2621 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2622 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2635 static void moveDock(WDock
*dock
, int new_x
, int new_y
)
2640 dock
->x_pos
= new_x
;
2641 dock
->y_pos
= new_y
;
2642 for (i
= 0; i
< dock
->max_icons
; i
++) {
2643 btn
= dock
->icon_array
[i
];
2645 btn
->x_pos
= new_x
+ btn
->xindex
* ICON_SIZE
;
2646 btn
->y_pos
= new_y
+ btn
->yindex
* ICON_SIZE
;
2647 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2652 static void swapDock(WDock
*dock
)
2654 WScreen
*scr
= dock
->screen_ptr
;
2658 if (dock
->on_right_side
) {
2659 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2661 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2664 for (i
= 0; i
< dock
->max_icons
; i
++) {
2665 btn
= dock
->icon_array
[i
];
2668 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2672 wScreenUpdateUsableArea(scr
);
2675 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2677 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2683 cmdline
= ExpandOptions(scr
, command
);
2685 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2693 wtokensplit(cmdline
, &argv
, &argc
);
2703 if ((pid
= fork()) == 0) {
2707 SetupEnvironment(scr
);
2713 args
= malloc(sizeof(char *) * (argc
+ 1));
2716 for (i
= 0; i
< argc
; i
++) {
2720 execvp(argv
[0], args
);
2723 wtokenfree(argv
, argc
);
2727 state
= wmalloc(sizeof(WSavedState
));
2729 state
->miniaturized
= -1;
2731 if (btn
->dock
== scr
->dock
|| btn
->omnipresent
)
2732 state
->workspace
= -1;
2734 state
->workspace
= scr
->current_workspace
;
2736 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
2737 wAddDeathHandler(pid
, (WDeathHandler
*) trackDeadProcess
, btn
->dock
);
2745 void wDockHideIcons(WDock
*dock
)
2752 for (i
= 1; i
< dock
->max_icons
; i
++) {
2753 if (dock
->icon_array
[i
])
2754 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2758 dockIconPaint(dock
->icon_array
[0]);
2761 void wDockShowIcons(WDock
*dock
)
2769 btn
= dock
->icon_array
[0];
2770 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2772 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2773 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2775 for (i
= 1; i
< dock
->max_icons
; i
++) {
2776 if (dock
->icon_array
[i
]) {
2777 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
, btn
->icon
->core
);
2782 if (!dock
->collapsed
) {
2783 for (i
= 1; i
< dock
->max_icons
; i
++) {
2784 if (dock
->icon_array
[i
]) {
2785 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2794 void wDockLower(WDock
*dock
)
2798 for (i
= 0; i
< dock
->max_icons
; i
++) {
2799 if (dock
->icon_array
[i
])
2800 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2804 void wDockRaise(WDock
*dock
)
2808 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
2809 if (dock
->icon_array
[i
])
2810 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2814 void wDockRaiseLower(WDock
*dock
)
2816 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2817 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2818 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2824 void wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
2826 icon
->launching
= 0;
2827 icon
->relaunching
= 0;
2828 dockIconPaint(icon
);
2831 WAppIcon
*wDockFindIconForWindow(WDock
*dock
, Window window
)
2836 for (i
= 0; i
< dock
->max_icons
; i
++) {
2837 icon
= dock
->icon_array
[i
];
2838 if (icon
&& icon
->main_window
== window
)
2844 void wDockTrackWindowLaunch(WDock
*dock
, Window window
)
2847 char *wm_class
, *wm_instance
;
2849 Bool firstPass
= True
;
2851 char *command
= NULL
;
2853 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) || (!wm_class
&& !wm_instance
)) {
2857 command
= GetCommandForWindow(window
);
2859 for (i
= 0; i
< dock
->max_icons
; i
++) {
2860 icon
= dock
->icon_array
[i
];
2864 /* app is already attached to icon */
2865 if (icon
->main_window
== window
) {
2870 if ((icon
->wm_instance
|| icon
->wm_class
)
2871 && (icon
->launching
|| !icon
->running
)) {
2873 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0) {
2876 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0) {
2879 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0) {
2883 if (!icon
->relaunching
) {
2886 /* Possibly an application that was docked with dockit,
2887 * but the user did not update WMState to indicate that
2888 * it was docked by force */
2889 wapp
= wApplicationOf(window
);
2891 icon
->forced_dock
= 1;
2894 if (!icon
->forced_dock
) {
2895 icon
->main_window
= window
;
2899 if (!wPreferences
.no_animations
&& !icon
->launching
&&
2900 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
2904 icon
->launching
= 1;
2905 dockIconPaint(icon
);
2907 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
2908 wm_instance
, wm_class
, TILE_NORMAL
);
2909 /* XXX: can: aicon->icon == NULL ? */
2910 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
2911 wAppIconMove(aicon
, x0
, y0
);
2912 /* Should this always be lowered? -Dan */
2914 wLowerFrame(aicon
->icon
->core
);
2915 XMapWindow(dpy
, aicon
->icon
->core
->window
);
2916 aicon
->launching
= 1;
2917 wAppIconPaint(aicon
);
2918 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
2919 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
2920 wAppIconDestroy(aicon
);
2922 wDockFinishLaunch(dock
, icon
);
2927 if (firstPass
&& !found
) {
2941 void wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
2943 if (!wPreferences
.flags
.noclip
) {
2944 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
2945 if (scr
->current_workspace
!= workspace
) {
2946 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
2947 WAppIconChain
*chain
= scr
->global_icons
;
2950 moveIconBetweenDocks(chain
->aicon
->dock
,
2951 scr
->workspaces
[workspace
]->clip
,
2952 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
2953 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
2954 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
2955 chain
= chain
->next
;
2958 wDockHideIcons(old_clip
);
2959 if (old_clip
->auto_raise_lower
) {
2960 if (old_clip
->auto_raise_magic
) {
2961 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
2962 old_clip
->auto_raise_magic
= NULL
;
2964 wDockLower(old_clip
);
2966 if (old_clip
->auto_collapse
) {
2967 if (old_clip
->auto_expand_magic
) {
2968 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
2969 old_clip
->auto_expand_magic
= NULL
;
2971 old_clip
->collapsed
= 1;
2973 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
2978 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
2983 for (i
= 0; i
< dock
->max_icons
; i
++) {
2984 icon
= dock
->icon_array
[i
];
2988 if (icon
->launching
&& icon
->pid
== pid
) {
2989 if (!icon
->relaunching
) {
2991 icon
->main_window
= None
;
2993 wDockFinishLaunch(dock
, icon
);
2995 if (status
== 111) {
3000 if (icon
->drop_launch
)
3001 cmd
= icon
->dnd_command
;
3004 if (icon
->paste_launch
)
3005 cmd
= icon
->paste_command
;
3007 cmd
= icon
->command
;
3009 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3011 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3018 static void toggleLowered(WDock
*dock
)
3023 /* lower/raise Dock */
3024 if (!dock
->lowered
) {
3025 newlevel
= WMNormalLevel
;
3028 newlevel
= WMDockLevel
;
3032 for (i
= 0; i
< dock
->max_icons
; i
++) {
3033 tmp
= dock
->icon_array
[i
];
3037 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3039 wLowerFrame(tmp
->icon
->core
);
3042 if (dock
->type
== WM_DOCK
)
3043 wScreenUpdateUsableArea(dock
->screen_ptr
);
3046 static void toggleCollapsed(WDock
*dock
)
3048 if (dock
->collapsed
) {
3049 dock
->collapsed
= 0;
3050 wDockShowIcons(dock
);
3052 dock
->collapsed
= 1;
3053 wDockHideIcons(dock
);
3057 static void openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3059 WScreen
*scr
= dock
->screen_ptr
;
3060 WObjDescriptor
*desc
;
3062 WApplication
*wapp
= NULL
;
3066 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3068 if (dock
->type
== WM_DOCK
) {
3070 entry
= dock
->menu
->entries
[index
];
3071 entry
->flags
.indicator_on
= !dock
->lowered
;
3072 entry
->clientdata
= dock
;
3073 dock
->menu
->flags
.realized
= 0;
3076 if (scr
->clip_options
)
3077 updateClipOptionsMenu(scr
->clip_options
, dock
);
3079 n_selected
= numberOfSelectedIcons(dock
);
3081 /* Rename Workspace */
3082 entry
= dock
->menu
->entries
[++index
];
3083 if (aicon
== scr
->clip_icon
) {
3084 entry
->callback
= renameCallback
;
3085 entry
->clientdata
= dock
;
3086 entry
->flags
.indicator
= 0;
3087 entry
->text
= _("Rename Workspace");
3089 entry
->callback
= omnipresentCallback
;
3090 entry
->clientdata
= aicon
;
3091 if (n_selected
> 0) {
3092 entry
->flags
.indicator
= 0;
3093 entry
->text
= _("Toggle Omnipresent");
3095 entry
->flags
.indicator
= 1;
3096 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3097 entry
->flags
.indicator_type
= MI_CHECK
;
3098 entry
->text
= _("Omnipresent");
3102 /* select/unselect icon */
3103 entry
= dock
->menu
->entries
[++index
];
3104 entry
->clientdata
= aicon
;
3105 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3106 wMenuSetEnabled(dock
->menu
, index
, aicon
!= scr
->clip_icon
);
3108 /* select/unselect all icons */
3109 entry
= dock
->menu
->entries
[++index
];
3110 entry
->clientdata
= aicon
;
3112 entry
->text
= _("Unselect All Icons");
3114 entry
->text
= _("Select All Icons");
3115 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3118 entry
= dock
->menu
->entries
[++index
];
3119 entry
->clientdata
= aicon
;
3121 entry
->text
= _("Keep Icons");
3123 entry
->text
= _("Keep Icon");
3124 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3126 /* this is the workspace submenu part */
3127 entry
= dock
->menu
->entries
[++index
];
3129 entry
->text
= _("Move Icons To");
3131 entry
->text
= _("Move Icon To");
3132 if (scr
->clip_submenu
)
3133 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3134 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3136 /* remove icon(s) */
3137 entry
= dock
->menu
->entries
[++index
];
3138 entry
->clientdata
= aicon
;
3140 entry
->text
= _("Remove Icons");
3142 entry
->text
= _("Remove Icon");
3143 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3145 /* attract icon(s) */
3146 entry
= dock
->menu
->entries
[++index
];
3147 entry
->clientdata
= aicon
;
3149 dock
->menu
->flags
.realized
= 0;
3150 wMenuRealize(dock
->menu
);
3153 if (aicon
->icon
->owner
) {
3154 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3160 entry
= dock
->menu
->entries
[++index
];
3161 entry
->clientdata
= aicon
;
3162 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3165 entry
= dock
->menu
->entries
[++index
];
3166 entry
->clientdata
= aicon
;
3167 if (wapp
&& wapp
->flags
.hidden
) {
3168 entry
->text
= _("Unhide Here");
3170 entry
->text
= _("Bring Here");
3172 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3175 entry
= dock
->menu
->entries
[++index
];
3176 entry
->clientdata
= aicon
;
3177 if (wapp
&& wapp
->flags
.hidden
) {
3178 entry
->text
= _("Unhide");
3180 entry
->text
= _("Hide");
3182 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3185 entry
= dock
->menu
->entries
[++index
];
3186 entry
->clientdata
= aicon
;
3187 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3190 entry
= dock
->menu
->entries
[++index
];
3191 entry
->clientdata
= aicon
;
3192 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3194 if (!dock
->menu
->flags
.realized
)
3195 wMenuRealize(dock
->menu
);
3197 if (dock
->type
== WM_CLIP
) {
3198 /*x_pos = event->xbutton.x_root+2; */
3199 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3202 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3203 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3206 x_pos
= dock
->on_right_side
? scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3209 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3211 /* allow drag select */
3212 event
->xany
.send_event
= True
;
3213 desc
= &dock
->menu
->menu
->descriptor
;
3214 (*desc
->handle_mousedown
) (desc
, event
);
3217 /******************************************************************/
3218 static void iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3220 WAppIcon
*btn
= desc
->parent
;
3221 WDock
*dock
= btn
->dock
;
3222 WApplication
*wapp
= NULL
;
3225 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3226 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3228 assert(wapp
!= NULL
);
3230 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3232 /* go to the last workspace that the user worked on the app */
3233 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
&& !unhideHere
) {
3234 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3237 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3239 if (event
->xbutton
.state
& MOD_MASK
) {
3240 wHideOtherApplications(btn
->icon
->owner
);
3243 if (event
->xbutton
.button
== Button1
) {
3245 if (event
->xbutton
.state
& MOD_MASK
) {
3246 /* raise/lower dock */
3247 toggleLowered(dock
);
3248 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3249 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
)
3250 toggleCollapsed(dock
);
3252 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3253 } else if (btn
->command
) {
3254 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3255 launchDockedApplication(btn
, False
);
3261 static void handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3263 WScreen
*scr
= dock
->screen_ptr
;
3264 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3267 int grabbed
= 0, swapped
= 0, done
;
3268 Pixmap ghost
= None
;
3269 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3271 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3272 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3273 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3274 wwarning("pointer grab failed for dock move");
3277 for (x
= 0; x
< dock
->max_icons
; x
++) {
3278 if (dock
->icon_array
[x
] != NULL
&& dock
->icon_array
[x
]->yindex
> y
)
3279 y
= dock
->icon_array
[x
]->yindex
;
3282 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
* y
);
3286 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3287 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3294 /* It means the cursor moved so fast that it entered
3295 * something else (if moving slowly, it would have
3296 * stayed in the dock that is being moved. Ignore such
3297 * "spurious" EnterNotifiy's */
3302 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3303 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3304 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3305 | ButtonReleaseMask
| ButtonPressMask
,
3306 wCursor
[WCUR_MOVE
], CurrentTime
);
3311 if (dock
->type
== WM_CLIP
) {
3312 x
= ev
.xmotion
.x_root
- ofs_x
;
3313 y
= ev
.xmotion
.y_root
- ofs_y
;
3314 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3316 moveDock(dock
, x
, y
);
3318 /* move vertically if pointer is inside the dock */
3319 if ((dock
->on_right_side
&& ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3320 || (!dock
->on_right_side
&& ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
* 2)) {
3322 x
= ev
.xmotion
.x_root
- ofs_x
;
3323 y
= ev
.xmotion
.y_root
- ofs_y
;
3324 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3325 moveDock(dock
, dock
->x_pos
, y
);
3327 /* move horizontally to change sides */
3328 x
= ev
.xmotion
.x_root
- ofs_x
;
3329 if (!dock
->on_right_side
) {
3333 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
* 2) {
3334 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
- ICON_SIZE
3335 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3336 if (superfluous
&& ghost
== None
) {
3337 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3338 scr
->scr_width
- ICON_SIZE
3339 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3340 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3341 XClearWindow(dpy
, scr
->dock_shadow
);
3343 XMapRaised(dpy
, scr
->dock_shadow
);
3346 if (superfluous
&& ghost
!= None
) {
3347 XFreePixmap(dpy
, ghost
);
3350 XUnmapWindow(dpy
, scr
->dock_shadow
);
3355 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3356 XMoveWindow(dpy
, scr
->dock_shadow
, DOCK_EXTRA_SPACE
, dock
->y_pos
);
3357 if (superfluous
&& ghost
== None
) {
3358 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3359 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3360 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3361 XClearWindow(dpy
, scr
->dock_shadow
);
3363 XMapRaised(dpy
, scr
->dock_shadow
);
3366 XUnmapWindow(dpy
, scr
->dock_shadow
);
3368 if (superfluous
&& ghost
!= None
) {
3369 XFreePixmap(dpy
, ghost
);
3381 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3383 XUngrabPointer(dpy
, CurrentTime
);
3384 XUnmapWindow(dpy
, scr
->dock_shadow
);
3385 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3386 if (dock
->type
== WM_DOCK
) {
3389 dock
->on_right_side
= 1;
3391 dock
->on_right_side
= 0;
3393 wArrangeIcons(scr
, False
);
3402 XFreePixmap(dpy
, ghost
);
3403 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3407 static Bool
handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3409 WScreen
*scr
= dock
->screen_ptr
;
3411 WIcon
*icon
= aicon
->icon
;
3412 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3413 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3415 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3416 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3417 int shad_x
= x
, shad_y
= y
;
3418 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3420 Pixmap ghost
= None
;
3422 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3423 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3424 Bool hasMoved
= False
;
3426 if (wPreferences
.flags
.noupdates
)
3429 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3430 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3431 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3434 if (!(event
->xbutton
.state
& MOD_MASK
))
3435 wRaiseFrame(icon
->core
);
3437 if (!wPreferences
.flags
.noclip
)
3438 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3440 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3442 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3445 wins
[0] = icon
->core
->window
;
3446 wins
[1] = scr
->dock_shadow
;
3447 XRestackWindows(dpy
, wins
, 2);
3448 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
3450 if (icon
->pixmap
!= None
)
3451 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3453 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3455 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3456 XClearWindow(dpy
, scr
->dock_shadow
);
3458 XMapWindow(dpy
, scr
->dock_shadow
);
3463 XMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3464 | ButtonMotionMask
| ExposureMask
, &ev
);
3473 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3474 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3475 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3476 | ButtonReleaseMask
| ButtonPressMask
,
3477 wCursor
[WCUR_MOVE
], CurrentTime
);
3486 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3487 if (i
== scr
->current_workspace
)
3489 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3493 x
= ev
.xmotion
.x_root
- ofs_x
;
3494 y
= ev
.xmotion
.y_root
- ofs_y
;
3495 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3498 if (last_dock
!= dock
&& collapsed
) {
3499 last_dock
->collapsed
= 1;
3500 wDockHideIcons(last_dock
);
3503 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3504 dock
->collapsed
= 0;
3505 wDockShowIcons(dock
);
3507 if (dock
->auto_raise_lower
)
3511 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3514 if (last_dock
!= dock2
&& collapsed
) {
3515 last_dock
->collapsed
= 1;
3516 wDockHideIcons(last_dock
);
3519 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3520 dock2
->collapsed
= 0;
3521 wDockShowIcons(dock2
);
3523 if (dock2
->auto_raise_lower
)
3528 if (aicon
->launching
|| aicon
->lock
|| (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3529 || (!aicon
->running
&& tmp
)) {
3530 shad_x
= last_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3531 shad_y
= last_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3533 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3536 XMapWindow(dpy
, scr
->dock_shadow
);
3541 XUnmapWindow(dpy
, scr
->dock_shadow
);
3545 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3552 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3554 XUngrabPointer(dpy
, CurrentTime
);
3556 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3557 XUnmapWindow(dpy
, scr
->dock_shadow
);
3559 reattachIcon(dock
, aicon
, ix
, iy
);
3560 if (clip
&& dock
!= clip
&& clip
->auto_raise_lower
)
3563 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3565 /* Slide it back if dock rejected it */
3566 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
, aicon
->y_pos
);
3567 reattachIcon(dock
, aicon
, aicon
->xindex
, aicon
->yindex
);
3569 if (last_dock
->type
== WM_CLIP
&& last_dock
->auto_collapse
) {
3577 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3578 /* We need to deselect it, even if is deselected in
3579 * wDockDetach(), because else DoKaboom() will fail.
3581 if (aicon
->icon
->selected
)
3582 wIconSelect(aicon
->icon
);
3584 DoKaboom(scr
, aicon
->icon
->core
->window
, x
, y
);
3587 if (clip
&& clip
->auto_raise_lower
)
3589 wDockDetach(dock
, aicon
);
3592 last_dock
->collapsed
= 1;
3593 wDockHideIcons(last_dock
);
3598 XFreePixmap(dpy
, ghost
);
3599 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3603 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3604 if (i
== scr
->current_workspace
)
3606 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3612 return False
; /* never reached */
3615 static int getClipButton(int px
, int py
)
3617 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3619 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3622 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3623 return CLIP_FORWARD
;
3624 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3630 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3633 int done
, direction
, new_ws
;
3635 WDock
*clip
= scr
->clip_icon
->dock
;
3637 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3639 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3640 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3642 wClipIconPaint(scr
->clip_icon
);
3645 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3652 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3653 if (new_dir
!= direction
) {
3654 direction
= new_dir
;
3655 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3656 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3657 wClipIconPaint(scr
->clip_icon
);
3665 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3670 clip
->lclip_button_pushed
= 0;
3671 clip
->rclip_button_pushed
= 0;
3673 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3675 if (direction
== CLIP_FORWARD
) {
3676 if (scr
->current_workspace
< scr
->workspace_count
- 1)
3677 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3678 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
- 1)
3679 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3680 else if (wPreferences
.ws_cycle
)
3681 wWorkspaceChange(scr
, 0);
3682 } else if (direction
== CLIP_REWIND
) {
3683 if (scr
->current_workspace
> 0)
3684 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
3685 else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
)
3686 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
3689 wClipIconPaint(scr
->clip_icon
);
3692 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3694 WAppIcon
*aicon
= desc
->parent
;
3695 WDock
*dock
= aicon
->dock
;
3696 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3698 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3701 scr
->last_dock
= dock
;
3703 if (dock
->menu
->flags
.mapped
)
3704 wMenuUnmap(dock
->menu
);
3706 if (IsDoubleClick(scr
, event
)) {
3707 /* double-click was not in the main clip icon */
3708 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3709 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3710 iconDblClick(desc
, event
);
3715 if (event
->xbutton
.button
== Button1
) {
3716 if (event
->xbutton
.state
& MOD_MASK
)
3721 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
&& dock
->type
!= WM_DOCK
) {
3722 wIconSelect(aicon
->icon
);
3726 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3727 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
3728 && dock
->type
== WM_CLIP
)
3729 handleClipChangeWorkspace(scr
, event
);
3731 handleDockMove(dock
, aicon
, event
);
3733 Bool hasMoved
= handleIconMove(dock
, aicon
, event
);
3734 if (wPreferences
.single_click
&& !hasMoved
)
3735 iconDblClick(desc
, event
);
3737 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&& aicon
== scr
->clip_icon
) {
3738 if (!scr
->clip_ws_menu
) {
3739 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3741 if (scr
->clip_ws_menu
) {
3742 WMenu
*wsMenu
= scr
->clip_ws_menu
;
3745 wWorkspaceMenuUpdate(scr
, wsMenu
);
3747 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
3750 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
3751 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
3753 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
3755 desc
= &wsMenu
->menu
->descriptor
;
3756 event
->xany
.send_event
= True
;
3757 (*desc
->handle_mousedown
) (desc
, event
);
3759 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
3760 (event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
) {
3761 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3762 } else if (event
->xbutton
.button
== Button3
) {
3763 if (event
->xbutton
.send_event
&&
3764 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3765 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3766 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3767 wwarning("pointer grab failed for dockicon menu");
3771 openDockMenu(dock
, aicon
, event
);
3772 } else if (event
->xbutton
.button
== Button2
) {
3773 WAppIcon
*btn
= desc
->parent
;
3775 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3776 launchDockedApplication(btn
, True
);
3781 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3783 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3787 assert(event
->type
== EnterNotify
);
3789 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3792 scr
= btn
->icon
->core
->screen_ptr
;
3793 if (!btn
->omnipresent
)
3796 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3798 if (!dock
|| dock
->type
!= WM_CLIP
)
3801 /* The auto raise/lower code */
3802 if (dock
->auto_lower_magic
) {
3803 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3804 dock
->auto_lower_magic
= NULL
;
3806 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
3807 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
, clipAutoRaise
, (void *)dock
);
3810 /* The auto expand/collapse code */
3811 if (dock
->auto_collapse_magic
) {
3812 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3813 dock
->auto_collapse_magic
= NULL
;
3815 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
3816 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
, clipAutoExpand
, (void *)dock
);
3820 static void clipLeave(WDock
*dock
)
3823 WObjDescriptor
*desc
= NULL
;
3825 if (!dock
|| dock
->type
!= WM_CLIP
)
3828 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
3829 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3830 (XPointer
*) & desc
) != XCNOENT
3831 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
3832 && ((WAppIcon
*) desc
->parent
)->dock
&& ((WAppIcon
*) desc
->parent
)->dock
->type
== WM_CLIP
) {
3833 /* We didn't left the Clip yet */
3834 XPutBackEvent(dpy
, &event
);
3838 XPutBackEvent(dpy
, &event
);
3840 /* We entered a withdrawn window, so we're still in Clip */
3844 if (dock
->auto_raise_magic
) {
3845 WMDeleteTimerHandler(dock
->auto_raise_magic
);
3846 dock
->auto_raise_magic
= NULL
;
3848 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
3849 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
, clipAutoLower
, (void *)dock
);
3852 if (dock
->auto_expand_magic
) {
3853 WMDeleteTimerHandler(dock
->auto_expand_magic
);
3854 dock
->auto_expand_magic
= NULL
;
3856 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
3857 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
, clipAutoCollapse
, (void *)dock
);
3861 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
3863 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3865 assert(event
->type
== LeaveNotify
);
3867 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3870 clipLeave(btn
->dock
);
3873 static void clipAutoCollapse(void *cdata
)
3875 WDock
*dock
= (WDock
*) cdata
;
3877 if (dock
->type
!= WM_CLIP
)
3880 if (dock
->auto_collapse
) {
3881 dock
->collapsed
= 1;
3882 wDockHideIcons(dock
);
3884 dock
->auto_collapse_magic
= NULL
;
3887 static void clipAutoExpand(void *cdata
)
3889 WDock
*dock
= (WDock
*) cdata
;
3891 if (dock
->type
!= WM_CLIP
)
3894 if (dock
->auto_collapse
) {
3895 dock
->collapsed
= 0;
3896 wDockShowIcons(dock
);
3898 dock
->auto_expand_magic
= NULL
;
3901 static void clipAutoLower(void *cdata
)
3903 WDock
*dock
= (WDock
*) cdata
;
3905 if (dock
->type
!= WM_CLIP
)
3908 if (dock
->auto_raise_lower
)
3911 dock
->auto_lower_magic
= NULL
;
3914 static void clipAutoRaise(void *cdata
)
3916 WDock
*dock
= (WDock
*) cdata
;
3918 if (dock
->type
!= WM_CLIP
)
3921 if (dock
->auto_raise_lower
)
3924 dock
->auto_raise_magic
= NULL
;
3927 static Bool
iconCanBeOmnipresent(WAppIcon
*aicon
)
3929 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3934 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3935 clip
= scr
->workspaces
[i
]->clip
;
3937 if (clip
== aicon
->dock
)
3940 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
3941 return False
; /* Clip is full in some workspace */
3943 for (j
= 0; j
< clip
->max_icons
; j
++) {
3944 btn
= clip
->icon_array
[j
];
3945 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
3953 int wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
3955 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3956 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
3957 int status
= WO_SUCCESS
;
3959 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== scr
->clip_icon
) {
3960 return WO_NOT_APPLICABLE
;
3963 if (aicon
->omnipresent
== omnipresent
)
3967 if (iconCanBeOmnipresent(aicon
)) {
3968 aicon
->omnipresent
= 1;
3969 new_entry
= wmalloc(sizeof(WAppIconChain
));
3970 new_entry
->aicon
= aicon
;
3971 new_entry
->next
= scr
->global_icons
;
3972 scr
->global_icons
= new_entry
;
3973 scr
->global_icon_count
++;
3975 aicon
->omnipresent
= 0;
3979 aicon
->omnipresent
= 0;
3980 if (aicon
== scr
->global_icons
->aicon
) {
3981 tmp
= scr
->global_icons
->next
;
3982 wfree(scr
->global_icons
);
3983 scr
->global_icons
= tmp
;
3984 scr
->global_icon_count
--;
3986 tmp
= scr
->global_icons
;
3988 if (tmp
->next
->aicon
== aicon
) {
3989 tmp1
= tmp
->next
->next
;
3992 scr
->global_icon_count
--;
4000 wAppIconPaint(aicon
);