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
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 #include <X11/Xutil.h>
35 #define PATH_MAX DEFAULT_PATH_MAX
38 #include "WindowMaker.h"
48 #include "properties.h"
52 #include "workspace.h"
54 #include "superfluous.h"
58 /**** Local variables ****/
61 #define CLIP_FORWARD 2
63 /**** Global variables ****/
66 extern void DestroyDockAppSettingsPanel();
68 extern void ShowDockAppSettingsPanel(WAppIcon
* aicon
);
70 extern XContext wWinContext
;
72 extern Cursor wCursor
[WCUR_LAST
];
74 extern WPreferences wPreferences
;
76 extern XContext wWinContext
;
78 #define MOD_MASK wPreferences.modifier_mask
80 extern void appIconMouseDown(WObjDescriptor
* desc
, XEvent
* event
);
82 #define ICON_SIZE wPreferences.icon_size
84 /***** Local variables ****/
86 static WMPropList
*dCommand
= NULL
;
87 static WMPropList
*dPasteCommand
= NULL
;
88 #ifdef XDND /* XXX was OFFIX */
89 static WMPropList
*dDropCommand
= NULL
;
91 static WMPropList
*dAutoLaunch
, *dLock
;
92 static WMPropList
*dName
, *dForced
, *dBuggyApplication
, *dYes
, *dNo
;
93 static WMPropList
*dHost
, *dDock
, *dClip
;
94 static WMPropList
*dAutoAttractIcons
;
96 static WMPropList
*dPosition
, *dApplications
, *dLowered
, *dCollapsed
;
98 static WMPropList
*dAutoCollapse
, *dAutoRaiseLower
, *dOmnipresent
;
100 static void dockIconPaint(WAppIcon
* btn
);
102 static void iconMouseDown(WObjDescriptor
* desc
, XEvent
* event
);
104 static pid_t
execCommand(WAppIcon
* btn
, char *command
, WSavedState
* state
);
106 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
* dock
);
108 static int getClipButton(int px
, int py
);
110 static void toggleLowered(WDock
* dock
);
112 static void toggleCollapsed(WDock
* dock
);
114 static void clipIconExpose(WObjDescriptor
* desc
, XEvent
* event
);
116 static void clipLeave(WDock
* dock
);
118 static void handleClipChangeWorkspace(WScreen
* scr
, XEvent
* event
);
120 Bool
moveIconBetweenDocks(WDock
* src
, WDock
* dest
, WAppIcon
* icon
, int x
, int y
);
122 static void clipEnterNotify(WObjDescriptor
* desc
, XEvent
* event
);
123 static void clipLeaveNotify(WObjDescriptor
* desc
, XEvent
* event
);
124 static void clipAutoCollapse(void *cdata
);
125 static void clipAutoExpand(void *cdata
);
126 static void launchDockedApplication(WAppIcon
* btn
, Bool withSelection
);
128 static void clipAutoLower(void *cdata
);
129 static void clipAutoRaise(void *cdata
);
131 static void showClipBalloon(WDock
* dock
, int workspace
);
133 static void make_keys()
135 if (dCommand
!= NULL
)
138 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
139 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
141 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
143 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
144 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
145 dName
= WMRetainPropList(WMCreatePLString("Name"));
146 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
147 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
148 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
149 dNo
= WMRetainPropList(WMCreatePLString("No"));
150 dHost
= WMRetainPropList(WMCreatePLString("Host"));
152 dPosition
= WMCreatePLString("Position");
153 dApplications
= WMCreatePLString("Applications");
154 dLowered
= WMCreatePLString("Lowered");
155 dCollapsed
= WMCreatePLString("Collapsed");
156 dAutoCollapse
= WMCreatePLString("AutoCollapse");
157 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
158 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
160 dOmnipresent
= WMCreatePLString("Omnipresent");
162 dDock
= WMCreatePLString("Dock");
163 dClip
= WMCreatePLString("Clip");
166 static void renameCallback(WMenu
* menu
, WMenuEntry
* entry
)
168 WDock
*dock
= entry
->clientdata
;
173 assert(entry
->clientdata
!= NULL
);
175 wspace
= dock
->screen_ptr
->current_workspace
;
177 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
179 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+ 1);
180 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
, &name
)) {
181 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
188 static void toggleLoweredCallback(WMenu
* menu
, WMenuEntry
* entry
)
190 assert(entry
->clientdata
!= NULL
);
192 toggleLowered(entry
->clientdata
);
194 entry
->flags
.indicator_on
= !(((WDock
*) entry
->clientdata
)->lowered
);
199 static int matchWindow(void *item
, void *cdata
)
201 return (((WFakeGroupLeader
*) item
)->leader
== (Window
) cdata
);
204 static void killCallback(WMenu
* menu
, WMenuEntry
* entry
)
206 WScreen
*scr
= menu
->menu
->screen_ptr
;
208 WFakeGroupLeader
*fPtr
;
209 char *buffer
, *shortname
, **argv
;
210 char *basename(const char *shortname
);
213 if (!WCHECK_STATE(WSTATE_NORMAL
))
216 assert(entry
->clientdata
!= NULL
);
218 icon
= (WAppIcon
*) entry
->clientdata
;
222 WCHANGE_STATE(WSTATE_MODAL
);
224 /* strip away dir names */
225 shortname
= basename(icon
->command
);
226 /* separate out command options */
227 wtokensplit(shortname
, &argv
, &argc
);
229 buffer
= wstrconcat(argv
[0],
230 _(" will be forcibly closed.\n"
231 "Any unsaved changes will be lost.\n" "Please confirm."));
233 if (icon
->icon
&& icon
->icon
->owner
) {
234 fPtr
= icon
->icon
->owner
->fake_group
;
236 /* is this really necessary? can we kill a non-running dock icon? */
237 Window win
= icon
->main_window
;
240 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)win
);
241 if (index
!= WANotFound
)
242 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
247 if (wPreferences
.dont_confirm_kill
248 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
249 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
251 WWindow
*wwin
, *twin
;
253 wwin
= scr
->focused_window
;
256 if (wwin
->fake_group
== fPtr
) {
261 } else if (icon
->icon
&& icon
->icon
->owner
) {
262 wClientKill(icon
->icon
->owner
);
267 wtokenfree(argv
, argc
);
271 WCHANGE_STATE(WSTATE_NORMAL
);
274 /* TODO: replace this function with a member of the dock struct */
275 static int numberOfSelectedIcons(WDock
* dock
)
281 for (i
= 1; i
< dock
->max_icons
; i
++) {
282 aicon
= dock
->icon_array
[i
];
283 if (aicon
&& aicon
->icon
->selected
) {
291 static WMArray
*getSelected(WDock
* dock
)
293 WMArray
*ret
= WMCreateArray(8);
297 for (i
= 1; i
< dock
->max_icons
; i
++) {
298 btn
= dock
->icon_array
[i
];
299 if (btn
&& btn
->icon
->selected
) {
300 WMAddToArray(ret
, btn
);
307 static void paintClipButtons(WAppIcon
* clipIcon
, Bool lpushed
, Bool rpushed
)
309 Window win
= clipIcon
->icon
->core
->window
;
310 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
312 int pt
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
313 int tp
= ICON_SIZE
- pt
;
314 int as
= pt
- 15; /* 15 = 5+5+5 */
315 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
317 #ifdef GRADIENT_CLIP_ARROW
318 Bool collapsed
= clipIcon
->dock
->collapsed
;
321 /*if (!clipIcon->dock->collapsed)
322 color = scr->clip_title_color[CLIP_NORMAL];
324 color = scr->clip_title_color[CLIP_COLLAPSED]; */
325 color
= scr
->clip_title_color
[CLIP_NORMAL
];
327 XSetForeground(dpy
, gc
, WMColorPixel(color
));
332 p
[1].x
= ICON_SIZE
- 2;
334 p
[2].x
= ICON_SIZE
- 2;
336 } else if (lpushed
) {
340 p
[1].y
= ICON_SIZE
- 2;
342 p
[2].y
= ICON_SIZE
- 2;
344 if (lpushed
|| rpushed
) {
345 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
346 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
347 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
349 #ifdef GRADIENT_CLIP_ARROW
351 XSetFillStyle(dpy
, scr
->copy_gc
, FillTiled
);
352 XSetTile(dpy
, scr
->copy_gc
, scr
->clip_arrow_gradient
);
353 XSetClipMask(dpy
, scr
->copy_gc
, None
);
356 #endif /* GRADIENT_CLIP_ARROW */
358 /* top right arrow */
359 p
[0].x
= p
[3].x
= ICON_SIZE
- 5 - as
;
361 p
[1].x
= ICON_SIZE
- 6;
363 p
[2].x
= ICON_SIZE
- 6;
366 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
367 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
369 #ifdef GRADIENT_CLIP_ARROW
371 XSetTSOrigin(dpy
, gc
, ICON_SIZE
- 6 - as
, 5);
373 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
374 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
377 /* bottom left arrow */
379 p
[0].y
= p
[3].y
= ICON_SIZE
- 5 - as
;
381 p
[1].y
= ICON_SIZE
- 6;
383 p
[2].y
= ICON_SIZE
- 6;
385 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
386 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
388 #ifdef GRADIENT_CLIP_ARROW
390 XSetTSOrigin(dpy
, gc
, 5, ICON_SIZE
- 6 - as
);
392 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
393 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
395 #ifdef GRADIENT_CLIP_ARROW
397 XSetFillStyle(dpy
, scr
->copy_gc
, FillSolid
);
401 RImage
*wClipMakeTile(WScreen
* scr
, RImage
* normalTile
)
403 RImage
*tile
= RCloneImage(normalTile
);
410 pt
= CLIP_BUTTON_SIZE
* wPreferences
.icon_size
/ 64;
411 tp
= wPreferences
.icon_size
- 1 - pt
;
415 black
.red
= black
.green
= black
.blue
= 0;
418 dark
.red
= dark
.green
= dark
.blue
= 60;
421 light
.red
= light
.green
= light
.blue
= 80;
424 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
- 2, pt
- 1, &dark
);
425 RDrawLine(tile
, tp
- 1, 0, wPreferences
.icon_size
- 1, pt
+ 1, &black
);
426 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
- 3, pt
, &light
);
429 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, 4, &dark
);
430 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 5, 6 + as
, &dark
);
431 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
, &light
);
434 ROperateLine(tile
, RAddOperation
, 2, tp
+ 2, pt
- 2, wPreferences
.icon_size
- 3, &dark
);
435 RDrawLine(tile
, 0, tp
- 1, pt
+ 1, wPreferences
.icon_size
- 1, &black
);
436 ROperateLine(tile
, RSubtractOperation
, 0, tp
- 2, pt
+ 1, wPreferences
.icon_size
- 2, &light
);
439 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, &dark
);
440 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
, 6 + as
, ICON_SIZE
- 5, &dark
);
441 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5, &light
);
446 static void omnipresentCallback(WMenu
* menu
, WMenuEntry
* entry
)
448 WAppIcon
*clickedIcon
= entry
->clientdata
;
451 WMArray
*selectedIcons
;
452 WMArrayIterator iter
;
455 assert(entry
->clientdata
!= NULL
);
457 dock
= clickedIcon
->dock
;
459 selectedIcons
= getSelected(dock
);
461 if (!WMGetArrayItemCount(selectedIcons
))
462 WMAddToArray(selectedIcons
, clickedIcon
);
465 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
466 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
468 else if (aicon
->icon
->selected
)
469 wIconSelect(aicon
->icon
);
471 WMFreeArray(selectedIcons
);
474 wMessageDialog(dock
->screen_ptr
, _("Warning"),
475 _("Some icons cannot be made omnipresent. "
476 "Please make sure that no other icon is "
477 "docked in the same positions on the other "
478 "workspaces and the Clip is not full in "
479 "some workspace."), _("OK"), NULL
, NULL
);
480 } else if (failed
== 1) {
481 wMessageDialog(dock
->screen_ptr
, _("Warning"),
482 _("Icon cannot be made omnipresent. "
483 "Please make sure that no other icon is "
484 "docked in the same position on the other "
485 "workspaces and the Clip is not full in "
486 "some workspace."), _("OK"), NULL
, NULL
);
490 static void removeIconsCallback(WMenu
* menu
, WMenuEntry
* entry
)
492 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
495 WMArray
*selectedIcons
;
499 assert(clickedIcon
!= NULL
);
501 dock
= clickedIcon
->dock
;
503 selectedIcons
= getSelected(dock
);
505 if (WMGetArrayItemCount(selectedIcons
)) {
506 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
507 _("All selected icons will be removed!"),
508 _("OK"), _("Cancel"), NULL
) != WAPRDefault
) {
509 WMFreeArray(selectedIcons
);
513 if (clickedIcon
->xindex
== 0 && clickedIcon
->yindex
== 0) {
514 WMFreeArray(selectedIcons
);
517 WMAddToArray(selectedIcons
, clickedIcon
);
520 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
521 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
522 wDockDetach(dock
, aicon
);
524 /* XXX: can: aicon->icon == NULL ? */
525 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
526 wGetHeadForWindow(aicon
->icon
->owner
));
527 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
528 if (!dock
->mapped
|| dock
->collapsed
)
529 XMapWindow(dpy
, aicon
->icon
->core
->window
);
532 WMFreeArray(selectedIcons
);
534 if (wPreferences
.auto_arrange_icons
)
535 wArrangeIcons(dock
->screen_ptr
, True
);
538 static void keepIconsCallback(WMenu
* menu
, WMenuEntry
* entry
)
540 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
543 WMArray
*selectedIcons
;
546 assert(clickedIcon
!= NULL
);
547 dock
= clickedIcon
->dock
;
549 selectedIcons
= getSelected(dock
);
551 if (!WMGetArrayItemCount(selectedIcons
)
552 && clickedIcon
!= dock
->screen_ptr
->clip_icon
) {
553 char *command
= NULL
;
555 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
556 clickedIcon
->editing
= 1;
557 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
558 _("Type the command used to launch the application"), &command
)) {
559 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
563 clickedIcon
->command
= command
;
564 clickedIcon
->editing
= 0;
566 clickedIcon
->editing
= 0;
569 WMFreeArray(selectedIcons
);
574 WMAddToArray(selectedIcons
, clickedIcon
);
577 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
578 if (aicon
->icon
->selected
)
579 wIconSelect(aicon
->icon
);
580 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
581 aicon
->attracted
= 0;
582 if (aicon
->icon
->shadowed
) {
583 aicon
->icon
->shadowed
= 0;
584 aicon
->icon
->force_paint
= 1;
585 wAppIconPaint(aicon
);
589 WMFreeArray(selectedIcons
);
592 static void toggleAutoAttractCallback(WMenu
* menu
, WMenuEntry
* entry
)
594 WDock
*dock
= (WDock
*) entry
->clientdata
;
596 assert(entry
->clientdata
!= NULL
);
598 dock
->attract_icons
= !dock
->attract_icons
;
599 /*if (!dock->attract_icons)
600 dock->keep_attracted = 0; */
602 entry
->flags
.indicator_on
= dock
->attract_icons
;
607 static void selectCallback(WMenu
* menu
, WMenuEntry
* entry
)
609 WAppIcon
*icon
= (WAppIcon
*) entry
->clientdata
;
611 assert(icon
!= NULL
);
613 wIconSelect(icon
->icon
);
618 static void colectIconsCallback(WMenu
* menu
, WMenuEntry
* entry
)
620 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
623 int x
, y
, x_pos
, y_pos
;
625 assert(entry
->clientdata
!= NULL
);
626 clip
= clickedIcon
->dock
;
628 aicon
= clip
->screen_ptr
->app_icon_list
;
631 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
632 x_pos
= clip
->x_pos
+ x
* ICON_SIZE
;
633 y_pos
= clip
->y_pos
+ y
* ICON_SIZE
;
634 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
636 if (wPreferences
.no_animations
) {
637 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
639 SlideWindow(aicon
->icon
->core
->window
,
640 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
643 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
644 #endif /* ANIMATIONS */
646 aicon
->attracted
= 1;
647 if (!aicon
->icon
->shadowed
) {
648 aicon
->icon
->shadowed
= 1;
649 aicon
->icon
->force_paint
= 1;
650 /* We don't do an wAppIconPaint() here because it's in
651 * wDockAttachIcon(). -Dan
654 wDockAttachIcon(clip
, aicon
, x
, y
);
655 if (clip
->collapsed
|| !clip
->mapped
)
656 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
662 static void selectIconsCallback(WMenu
* menu
, WMenuEntry
* entry
)
664 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
666 WMArray
*selectedIcons
;
667 WMArrayIterator iter
;
671 assert(clickedIcon
!= NULL
);
672 dock
= clickedIcon
->dock
;
674 selectedIcons
= getSelected(dock
);
676 if (!WMGetArrayItemCount(selectedIcons
)) {
677 for (i
= 1; i
< dock
->max_icons
; i
++) {
678 btn
= dock
->icon_array
[i
];
679 if (btn
&& !btn
->icon
->selected
) {
680 wIconSelect(btn
->icon
);
684 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
685 wIconSelect(btn
->icon
);
688 WMFreeArray(selectedIcons
);
693 static void toggleCollapsedCallback(WMenu
* menu
, WMenuEntry
* entry
)
695 assert(entry
->clientdata
!= NULL
);
697 toggleCollapsed(entry
->clientdata
);
699 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->collapsed
;
704 static void toggleAutoCollapseCallback(WMenu
* menu
, WMenuEntry
* entry
)
707 assert(entry
->clientdata
!= NULL
);
709 dock
= (WDock
*) entry
->clientdata
;
711 dock
->auto_collapse
= !dock
->auto_collapse
;
713 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_collapse
;
718 static void toggleAutoRaiseLowerCallback(WMenu
* menu
, WMenuEntry
* entry
)
721 assert(entry
->clientdata
!= NULL
);
723 dock
= (WDock
*) entry
->clientdata
;
725 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
727 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_raise_lower
;
732 static void launchCallback(WMenu
* menu
, WMenuEntry
* entry
)
734 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
736 launchDockedApplication(btn
, False
);
739 static void settingsCallback(WMenu
* menu
, WMenuEntry
* entry
)
741 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
745 ShowDockAppSettingsPanel(btn
);
748 static void hideCallback(WMenu
* menu
, WMenuEntry
* entry
)
751 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
753 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
755 if (wapp
->flags
.hidden
) {
756 wWorkspaceChange(btn
->icon
->core
->screen_ptr
, wapp
->last_workspace
);
757 wUnhideApplication(wapp
, False
, False
);
759 wHideApplication(wapp
);
763 static void unhideHereCallback(WMenu
* menu
, WMenuEntry
* entry
)
766 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
768 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
770 wUnhideApplication(wapp
, False
, True
);
773 WAppIcon
*mainIconCreate(WScreen
* scr
, int type
)
778 if (type
== WM_CLIP
) {
780 return scr
->clip_icon
;
781 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
782 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
783 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
784 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
785 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE; */
788 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
789 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
795 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
796 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
797 btn
->icon
->core
->descriptor
.parent
= btn
;
798 /*ChangeStackingLevel(btn->icon->core, WMDockLevel); */
799 XMapWindow(dpy
, btn
->icon
->core
->window
);
804 scr
->clip_icon
= btn
;
809 static void switchWSCommand(WMenu
* menu
, WMenuEntry
* entry
)
811 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
812 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
814 WMArray
*selectedIcons
;
817 if (entry
->order
== scr
->current_workspace
)
820 dest
= scr
->workspaces
[entry
->order
]->clip
;
822 selectedIcons
= getSelected(src
);
824 if (WMGetArrayItemCount(selectedIcons
)) {
825 WMArrayIterator iter
;
827 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
828 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
829 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
830 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
833 } else if (icon
!= scr
->clip_icon
) {
834 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
835 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
836 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
839 WMFreeArray(selectedIcons
);
842 static void launchDockedApplication(WAppIcon
* btn
, Bool withSelection
)
844 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
846 if (!btn
->launching
&&
847 ((!withSelection
&& btn
->command
!= NULL
) || (withSelection
&& btn
->paste_command
!= NULL
))) {
848 if (!btn
->forced_dock
) {
849 btn
->relaunching
= btn
->running
;
852 if (btn
->wm_instance
|| btn
->wm_class
) {
853 WWindowAttributes attr
;
854 memset(&attr
, 0, sizeof(WWindowAttributes
));
855 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
857 if (!attr
.no_appicon
&& !btn
->buggy_app
)
862 btn
->drop_launch
= 0;
863 btn
->paste_launch
= withSelection
;
864 scr
->last_dock
= btn
->dock
;
865 btn
->pid
= execCommand(btn
, (withSelection
? btn
->paste_command
: btn
->command
), NULL
);
867 if (btn
->buggy_app
) {
868 /* give feedback that the app was launched */
872 WMAddTimerHandler(200, (WMCallback
*) dockIconPaint
, btn
);
877 wwarning(_("could not launch application %s\n"), btn
->command
);
879 if (!btn
->relaunching
) {
886 static void updateWorkspaceMenu(WMenu
* menu
, WAppIcon
* icon
)
888 WScreen
*scr
= menu
->frame
->screen_ptr
;
889 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
895 for (i
= 0; i
< scr
->workspace_count
; i
++) {
896 if (i
< menu
->entry_no
) {
897 if (strcmp(menu
->entries
[i
]->text
, scr
->workspaces
[i
]->name
) != 0) {
898 wfree(menu
->entries
[i
]->text
);
899 strcpy(title
, scr
->workspaces
[i
]->name
);
900 menu
->entries
[i
]->text
= wstrdup(title
);
901 menu
->flags
.realized
= 0;
903 menu
->entries
[i
]->clientdata
= (void *)icon
;
905 strcpy(title
, scr
->workspaces
[i
]->name
);
907 wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)icon
);
909 menu
->flags
.realized
= 0;
911 if (i
== scr
->current_workspace
) {
912 wMenuSetEnabled(menu
, i
, False
);
914 wMenuSetEnabled(menu
, i
, True
);
918 if (!menu
->flags
.realized
)
922 static WMenu
*makeWorkspaceMenu(WScreen
* scr
)
926 menu
= wMenuCreate(scr
, NULL
, False
);
928 wwarning(_("could not create workspace submenu for Clip menu"));
930 wMenuAddCallback(menu
, "", switchWSCommand
, (void *)scr
->clip_icon
);
932 menu
->flags
.realized
= 0;
938 static void updateClipOptionsMenu(WMenu
* menu
, WDock
* dock
)
947 entry
= menu
->entries
[index
];
948 entry
->flags
.indicator_on
= !dock
->lowered
;
949 entry
->clientdata
= dock
;
952 entry
= menu
->entries
[++index
];
953 entry
->flags
.indicator_on
= dock
->collapsed
;
954 entry
->clientdata
= dock
;
957 entry
= menu
->entries
[++index
];
958 entry
->flags
.indicator_on
= dock
->auto_collapse
;
959 entry
->clientdata
= dock
;
961 /* auto-raise/lower */
962 entry
= menu
->entries
[++index
];
963 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
964 entry
->clientdata
= dock
;
965 wMenuSetEnabled(menu
, index
, dock
->lowered
);
968 entry
= menu
->entries
[++index
];
969 entry
->flags
.indicator_on
= dock
->attract_icons
;
970 entry
->clientdata
= dock
;
972 menu
->flags
.realized
= 0;
976 static WMenu
*makeClipOptionsMenu(WScreen
* scr
)
981 menu
= wMenuCreate(scr
, NULL
, False
);
983 wwarning(_("could not create options submenu for Clip menu"));
987 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
988 entry
->flags
.indicator
= 1;
989 entry
->flags
.indicator_on
= 1;
990 entry
->flags
.indicator_type
= MI_CHECK
;
992 entry
= wMenuAddCallback(menu
, _("Collapsed"), toggleCollapsedCallback
, NULL
);
993 entry
->flags
.indicator
= 1;
994 entry
->flags
.indicator_on
= 1;
995 entry
->flags
.indicator_type
= MI_CHECK
;
997 entry
= wMenuAddCallback(menu
, _("Autocollapse"), toggleAutoCollapseCallback
, NULL
);
998 entry
->flags
.indicator
= 1;
999 entry
->flags
.indicator_on
= 1;
1000 entry
->flags
.indicator_type
= MI_CHECK
;
1002 entry
= wMenuAddCallback(menu
, _("Autoraise"), toggleAutoRaiseLowerCallback
, NULL
);
1003 entry
->flags
.indicator
= 1;
1004 entry
->flags
.indicator_on
= 1;
1005 entry
->flags
.indicator_type
= MI_CHECK
;
1007 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"), toggleAutoAttractCallback
, NULL
);
1008 entry
->flags
.indicator
= 1;
1009 entry
->flags
.indicator_on
= 1;
1010 entry
->flags
.indicator_type
= MI_CHECK
;
1012 menu
->flags
.realized
= 0;
1018 static WMenu
*dockMenuCreate(WScreen
* scr
, int type
)
1023 if (type
== WM_CLIP
&& scr
->clip_menu
)
1024 return scr
->clip_menu
;
1026 menu
= wMenuCreate(scr
, NULL
, False
);
1027 if (type
!= WM_CLIP
) {
1028 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
1029 entry
->flags
.indicator
= 1;
1030 entry
->flags
.indicator_on
= 1;
1031 entry
->flags
.indicator_type
= MI_CHECK
;
1033 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1034 scr
->clip_options
= makeClipOptionsMenu(scr
);
1035 if (scr
->clip_options
)
1036 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1038 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1040 entry
->text
= _("Rename Workspace");
1042 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1043 entry
->flags
.indicator
= 1;
1044 entry
->flags
.indicator_on
= 1;
1045 entry
->flags
.indicator_type
= MI_CHECK
;
1047 entry
= wMenuAddCallback(menu
, _("Select All Icons"), selectIconsCallback
, NULL
);
1049 entry
->text
= _("Select All Icons");
1051 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1053 entry
->text
= _("Keep Icon");
1055 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1057 entry
->text
= _("Move Icon To");
1058 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1059 if (scr
->clip_submenu
)
1060 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1062 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
, NULL
);
1064 entry
->text
= _("Remove Icon");
1066 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1069 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1071 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1073 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1075 entry
->text
= _("Hide");
1077 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1079 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1081 if (type
== WM_CLIP
)
1082 scr
->clip_menu
= menu
;
1087 WDock
*wDockCreate(WScreen
* scr
, int type
)
1095 dock
= wmalloc(sizeof(WDock
));
1096 memset(dock
, 0, sizeof(WDock
));
1098 if (type
== WM_CLIP
)
1099 icon_count
= CLIP_MAX_ICONS
;
1101 icon_count
= scr
->scr_height
/ wPreferences
.icon_size
;
1103 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * icon_count
);
1104 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*) * icon_count
);
1106 dock
->max_icons
= icon_count
;
1108 btn
= mainIconCreate(scr
, type
);
1112 dock
->x_pos
= btn
->x_pos
;
1113 dock
->y_pos
= btn
->y_pos
;
1114 dock
->screen_ptr
= scr
;
1116 dock
->icon_count
= 1;
1117 dock
->on_right_side
= 1;
1118 dock
->collapsed
= 0;
1119 dock
->auto_collapse
= 0;
1120 dock
->auto_collapse_magic
= NULL
;
1121 dock
->auto_raise_lower
= 0;
1122 dock
->auto_lower_magic
= NULL
;
1123 dock
->auto_raise_magic
= NULL
;
1124 dock
->attract_icons
= 0;
1126 dock
->icon_array
[0] = btn
;
1127 wRaiseFrame(btn
->icon
->core
);
1128 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1130 /* create dock menu */
1131 dock
->menu
= dockMenuCreate(scr
, type
);
1136 void wDockDestroy(WDock
* dock
)
1141 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1142 aicon
= dock
->icon_array
[i
];
1144 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1145 wDockDetach(dock
, aicon
);
1147 /* XXX: can: aicon->icon == NULL ? */
1148 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1149 wGetHeadForWindow(aicon
->icon
->owner
));
1150 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1151 if (!dock
->mapped
|| dock
->collapsed
)
1152 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1156 if (wPreferences
.auto_arrange_icons
)
1157 wArrangeIcons(dock
->screen_ptr
, True
);
1158 wfree(dock
->icon_array
);
1159 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1160 wMenuDestroy(dock
->menu
, True
);
1161 if (dock
->screen_ptr
->last_dock
== dock
)
1162 dock
->screen_ptr
->last_dock
= NULL
;
1166 void wClipIconPaint(WAppIcon
* aicon
)
1168 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1169 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1171 Window win
= aicon
->icon
->core
->window
;
1172 int length
, nlength
;
1173 char *ws_name
, ws_number
[10];
1176 wIconPaint(aicon
->icon
);
1178 length
= strlen(workspace
->name
);
1179 ws_name
= wmalloc(length
+ 1);
1180 snprintf(ws_name
, length
+ 1, "%s", workspace
->name
);
1181 snprintf(ws_number
, sizeof(ws_number
), "%i", scr
->current_workspace
+ 1);
1182 nlength
= strlen(ws_number
);
1184 if (!workspace
->clip
->collapsed
)
1185 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1187 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1189 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1191 tx
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
1193 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, ty
, ws_name
, length
);
1194 /*WMDrawString(scr->wmscreen, win, color, scr->clip_title_font, 4,
1195 2, ws_name, length); */
1197 tx
= (ICON_SIZE
/ 2 - WMWidthOfString(scr
->clip_title_font
, ws_number
, nlength
)) / 2;
1199 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, 2, ws_number
, nlength
);
1203 if (aicon
->launching
) {
1204 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1205 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1207 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
, aicon
->dock
->rclip_button_pushed
);
1210 static void clipIconExpose(WObjDescriptor
* desc
, XEvent
* event
)
1212 wClipIconPaint(desc
->parent
);
1215 static void dockIconPaint(WAppIcon
* btn
)
1217 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1218 wClipIconPaint(btn
);
1223 static WMPropList
*make_icon_state(WAppIcon
* btn
)
1225 WMPropList
*node
= NULL
;
1226 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
, *host
;
1227 WMPropList
*position
, *buggy
, *omnipresent
;
1233 command
= WMCreatePLString("-");
1235 command
= WMCreatePLString(btn
->command
);
1237 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1239 lock
= btn
->lock
? dYes
: dNo
;
1241 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1243 name
= WMCreatePLString(tmp
);
1247 forced
= btn
->forced_dock
? dYes
: dNo
;
1249 buggy
= btn
->buggy_app
? dYes
: dNo
;
1251 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1252 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1254 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1255 position
= WMCreatePLString(buffer
);
1257 node
= WMCreatePLDictionary(dCommand
, command
,
1259 dAutoLaunch
, autolaunch
,
1261 dForced
, forced
, dBuggyApplication
, buggy
, dPosition
, position
, NULL
);
1262 WMReleasePropList(command
);
1263 WMReleasePropList(name
);
1264 WMReleasePropList(position
);
1266 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1267 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&& (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1268 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1270 #ifdef XDND /* was OFFIX */
1271 if (btn
->dnd_command
) {
1272 command
= WMCreatePLString(btn
->dnd_command
);
1273 WMPutInPLDictionary(node
, dDropCommand
, command
);
1274 WMReleasePropList(command
);
1278 if (btn
->paste_command
) {
1279 command
= WMCreatePLString(btn
->paste_command
);
1280 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1281 WMReleasePropList(command
);
1284 if (btn
->client_machine
&& btn
->remote_start
) {
1285 host
= WMCreatePLString(btn
->client_machine
);
1286 WMPutInPLDictionary(node
, dHost
, host
);
1287 WMReleasePropList(host
);
1294 static WMPropList
*dockSaveState(WDock
* dock
)
1297 WMPropList
*icon_info
;
1298 WMPropList
*list
= NULL
, *dock_state
= NULL
;
1299 WMPropList
*value
, *key
;
1302 list
= WMCreatePLArray(NULL
);
1304 for (i
= (dock
->type
== WM_DOCK
? 0 : 1); i
< dock
->max_icons
; i
++) {
1305 WAppIcon
*btn
= dock
->icon_array
[i
];
1307 if (!btn
|| btn
->attracted
)
1310 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1311 WMAddToPLArray(list
, icon_info
);
1312 WMReleasePropList(icon_info
);
1316 dock_state
= WMCreatePLDictionary(dApplications
, list
, NULL
);
1318 if (dock
->type
== WM_DOCK
) {
1319 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1320 key
= WMCreatePLString(buffer
);
1321 WMPutInPLDictionary(dock_state
, key
, list
);
1322 WMReleasePropList(key
);
1324 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0), dock
->y_pos
);
1325 value
= WMCreatePLString(buffer
);
1326 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1327 WMReleasePropList(value
);
1329 WMReleasePropList(list
);
1331 value
= (dock
->lowered
? dYes
: dNo
);
1332 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1334 if (dock
->type
== WM_CLIP
) {
1335 value
= (dock
->collapsed
? dYes
: dNo
);
1336 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1338 value
= (dock
->auto_collapse
? dYes
: dNo
);
1339 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1341 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1342 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1344 value
= (dock
->attract_icons
? dYes
: dNo
);
1345 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1351 void wDockSaveState(WScreen
* scr
, WMPropList
* old_state
)
1353 WMPropList
*dock_state
;
1356 dock_state
= dockSaveState(scr
->dock
);
1359 * Copy saved states of docks with different sizes.
1365 keys
= WMGetPLDictionaryKeys(old_state
);
1366 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1367 tmp
= WMGetFromPLArray(keys
, i
);
1369 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1370 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1372 WMPutInPLDictionary(dock_state
, tmp
, WMGetFromPLDictionary(old_state
, tmp
));
1375 WMReleasePropList(keys
);
1378 WMPutInPLDictionary(scr
->session_state
, dDock
, dock_state
);
1380 WMReleasePropList(dock_state
);
1383 void wClipSaveState(WScreen
* scr
)
1385 WMPropList
*clip_state
;
1387 clip_state
= make_icon_state(scr
->clip_icon
);
1389 WMPutInPLDictionary(scr
->session_state
, dClip
, clip_state
);
1391 WMReleasePropList(clip_state
);
1394 WMPropList
*wClipSaveWorkspaceState(WScreen
* scr
, int workspace
)
1396 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1399 static Bool
getBooleanDockValue(WMPropList
* value
, WMPropList
* key
)
1402 if (WMIsPLString(value
)) {
1403 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1406 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1412 static WAppIcon
*restore_icon_state(WScreen
* scr
, WMPropList
* info
, int type
, int index
)
1415 WMPropList
*cmd
, *value
;
1417 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1418 if (!cmd
|| !WMIsPLString(cmd
)) {
1422 /* parse window name */
1423 value
= WMGetFromPLDictionary(info
, dName
);
1428 char *wclass
, *winstance
;
1431 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1433 if (!winstance
&& !wclass
) {
1440 command
= wstrdup(WMGetFromPLString(cmd
));
1444 if (!command
|| strcmp(command
, "-") == 0) {
1455 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1464 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1465 if (type
== WM_CLIP
) {
1466 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1467 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1469 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1470 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1472 #ifdef XDND /* was OFFIX */
1473 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1475 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1478 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1480 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1482 /* check auto launch */
1483 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1485 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1488 value
= WMGetFromPLDictionary(info
, dLock
);
1490 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1492 /* check if it wasn't normally docked */
1493 value
= WMGetFromPLDictionary(info
, dForced
);
1495 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1497 /* check if we can rely on the stuff in the app */
1498 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1500 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1502 /* get position in the dock */
1503 value
= WMGetFromPLDictionary(info
, dPosition
);
1504 if (value
&& WMIsPLString(value
)) {
1505 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1506 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1508 /* check position sanity */
1509 /* incomplete section! */
1510 if (type
== WM_DOCK
) {
1512 if (aicon
->yindex
< 0)
1513 wwarning(_("bad value in docked icon position %i,%i"),
1514 aicon
->xindex
, aicon
->yindex
);
1517 aicon
->yindex
= index
;
1521 /* check if icon is omnipresent */
1522 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1524 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1532 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1534 WAppIcon
*wClipRestoreState(WScreen
* scr
, WMPropList
* clip_state
)
1539 icon
= mainIconCreate(scr
, WM_CLIP
);
1544 WMRetainPropList(clip_state
);
1546 /* restore position */
1548 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1551 if (!WMIsPLString(value
))
1552 COMPLAIN("Position");
1557 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1558 COMPLAIN("Position");
1560 /* check position sanity */
1561 rect
.pos
.x
= icon
->x_pos
;
1562 rect
.pos
.y
= icon
->y_pos
;
1563 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1565 wGetRectPlacementInfo(scr
, rect
, &flags
);
1566 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
1567 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1570 #ifdef XDND /* was OFFIX */
1571 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1572 if (value
&& WMIsPLString(value
))
1573 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1576 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1577 if (value
&& WMIsPLString(value
))
1578 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1580 WMReleasePropList(clip_state
);
1585 WDock
*wDockRestoreState(WScreen
* scr
, WMPropList
* dock_state
, int type
)
1590 WAppIcon
*aicon
, *old_top
;
1593 dock
= wDockCreate(scr
, type
);
1598 WMRetainPropList(dock_state
);
1600 /* restore position */
1602 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1605 if (!WMIsPLString(value
)) {
1606 COMPLAIN("Position");
1611 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1612 COMPLAIN("Position");
1614 /* check position sanity */
1615 rect
.pos
.x
= dock
->x_pos
;
1616 rect
.pos
.y
= dock
->y_pos
;
1617 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1619 wGetRectPlacementInfo(scr
, rect
, &flags
);
1620 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
)) {
1621 int x
= dock
->x_pos
;
1622 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1625 /* Is this needed any more? */
1626 if (type
== WM_CLIP
) {
1627 if (dock
->x_pos
< 0) {
1629 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1630 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1633 if (dock
->x_pos
>= 0) {
1634 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1635 dock
->on_right_side
= 0;
1637 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1638 dock
->on_right_side
= 1;
1644 /* restore lowered/raised state */
1648 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1651 if (!WMIsPLString(value
)) {
1652 COMPLAIN("Lowered");
1654 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1660 /* restore collapsed state */
1662 dock
->collapsed
= 0;
1664 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1667 if (!WMIsPLString(value
)) {
1668 COMPLAIN("Collapsed");
1670 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1671 dock
->collapsed
= 1;
1676 /* restore auto-collapsed state */
1678 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1681 if (!WMIsPLString(value
)) {
1682 COMPLAIN("AutoCollapse");
1684 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1685 dock
->auto_collapse
= 1;
1686 dock
->collapsed
= 1;
1691 /* restore auto-raise/lower state */
1693 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1696 if (!WMIsPLString(value
)) {
1697 COMPLAIN("AutoRaiseLower");
1699 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1700 dock
->auto_raise_lower
= 1;
1705 /* restore attract icons state */
1707 dock
->attract_icons
= 0;
1709 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1712 if (!WMIsPLString(value
)) {
1713 COMPLAIN("AutoAttractIcons");
1715 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1716 dock
->attract_icons
= 1;
1721 /* application list */
1728 * When saving, it saves the dock state in
1729 * Applications and Applicationsnnn
1731 * When loading, it will first try Applicationsnnn.
1732 * If it does not exist, use Applications as default.
1735 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1737 tmp
= WMCreatePLString(buffer
);
1738 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1739 WMReleasePropList(tmp
);
1742 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1750 count
= WMGetPropListItemCount(apps
);
1755 old_top
= dock
->icon_array
[0];
1757 /* dock->icon_count is set to 1 when dock is created.
1758 * Since Clip is already restored, we want to keep it so for clip,
1759 * but for dock we may change the default top tile, so we set it to 0.
1761 if (type
== WM_DOCK
)
1762 dock
->icon_count
= 0;
1764 for (i
= 0; i
< count
; i
++) {
1765 if (dock
->icon_count
>= dock
->max_icons
) {
1766 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1770 value
= WMGetFromPLArray(apps
, i
);
1771 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1773 dock
->icon_array
[dock
->icon_count
] = aicon
;
1777 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1778 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1781 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1783 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1785 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1787 if (!dock
->collapsed
)
1788 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1789 wRaiseFrame(aicon
->icon
->core
);
1792 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
)
1796 /* if the first icon is not defined, use the default */
1797 if (dock
->icon_array
[0] == NULL
) {
1798 /* update default icon */
1799 old_top
->x_pos
= dock
->x_pos
;
1800 old_top
->y_pos
= dock
->y_pos
;
1802 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1804 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1805 dock
->icon_array
[0] = old_top
;
1806 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1807 /* we don't need to increment dock->icon_count here because it was
1808 * incremented in the loop above.
1810 } else if (old_top
!= dock
->icon_array
[0]) {
1811 if (old_top
== scr
->clip_icon
)
1812 scr
->clip_icon
= dock
->icon_array
[0];
1813 wAppIconDestroy(old_top
);
1817 WMReleasePropList(dock_state
);
1822 void wDockLaunchWithState(WDock
* dock
, WAppIcon
* btn
, WSavedState
* state
)
1824 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1826 btn
->drop_launch
= 0;
1827 btn
->paste_launch
= 0;
1829 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1832 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1842 void wDockDoAutoLaunch(WDock
* dock
, int workspace
)
1848 for (i
= 0; i
< dock
->max_icons
; i
++) {
1849 btn
= dock
->icon_array
[i
];
1850 if (!btn
|| !btn
->auto_launch
)
1853 state
= wmalloc(sizeof(WSavedState
));
1854 memset(state
, 0, sizeof(WSavedState
));
1855 state
->workspace
= workspace
;
1856 /* TODO: this is klugy and is very difficult to understand
1857 * what's going on. Try to clean up */
1858 wDockLaunchWithState(dock
, btn
, state
);
1862 #ifdef XDND /* was OFFIX */
1863 static WDock
*findDock(WScreen
* scr
, XEvent
* event
, int *icon_pos
)
1869 if ((dock
= scr
->dock
) != NULL
) {
1870 for (i
= 0; i
< dock
->max_icons
; i
++) {
1871 if (dock
->icon_array
[i
]
1872 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1878 if (*icon_pos
< 0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
) != NULL
) {
1879 for (i
= 0; i
< dock
->max_icons
; i
++) {
1880 if (dock
->icon_array
[i
]
1881 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1892 int wDockReceiveDNDDrop(WScreen
* scr
, XEvent
* event
)
1898 dock
= findDock(scr
, event
, &icon_pos
);
1903 * Return True if the drop was on an application icon window.
1904 * In this case, let the ClientMessage handler redirect the
1905 * message to the app.
1907 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
1910 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
1911 scr
->flags
.dnd_data_convertion_status
= 0;
1913 btn
= dock
->icon_array
[icon_pos
];
1915 if (!btn
->forced_dock
) {
1916 btn
->relaunching
= btn
->running
;
1919 if (btn
->wm_instance
|| btn
->wm_class
) {
1920 WWindowAttributes attr
;
1921 memset(&attr
, 0, sizeof(WWindowAttributes
));
1922 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
1923 btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
1925 if (!attr
.no_appicon
)
1931 btn
->paste_launch
= 0;
1932 btn
->drop_launch
= 1;
1933 scr
->last_dock
= dock
;
1934 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1939 if (!btn
->relaunching
) {
1948 Bool
wDockAttachIcon(WDock
* dock
, WAppIcon
* icon
, int x
, int y
)
1953 wwin
= icon
->icon
->owner
;
1954 if (icon
->command
== NULL
) {
1959 command
= GetCommandForWindow(wwin
->client_win
);
1961 icon
->command
= command
;
1963 /* icon->forced_dock = 1; */
1964 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
1966 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
1967 _("Type the command used to launch the application"), &command
)) {
1968 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
1972 icon
->command
= command
;
1978 /* If the target is the dock, reject the icon. If
1979 * the target is the clip, make it an attracted icon
1981 if (dock
->type
== WM_CLIP
) {
1982 icon
->attracted
= 1;
1983 if (!icon
->icon
->shadowed
) {
1984 icon
->icon
->shadowed
= 1;
1985 icon
->icon
->force_paint
= 1;
1997 for (index
= 1; index
< dock
->max_icons
; index
++)
1998 if (dock
->icon_array
[index
] == NULL
)
2000 /* if (index == dock->max_icons)
2003 assert(index
< dock
->max_icons
);
2005 dock
->icon_array
[index
] = icon
;
2009 icon
->omnipresent
= 0;
2011 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2012 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2017 icon
->launching
= 0;
2020 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2021 if (dock
->type
== WM_CLIP
) {
2022 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2023 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2025 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2026 icon
->icon
->core
->descriptor
.parent
= icon
;
2028 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2029 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2030 wAppIconPaint(icon
);
2032 if (wPreferences
.auto_arrange_icons
)
2033 wArrangeIcons(dock
->screen_ptr
, True
);
2035 #ifdef XDND /* was OFFIX */
2036 if (icon
->command
&& !icon
->dnd_command
) {
2037 int len
= strlen(icon
->command
) + 8;
2038 icon
->dnd_command
= wmalloc(len
);
2039 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
2043 if (icon
->command
&& !icon
->paste_command
) {
2044 int len
= strlen(icon
->command
) + 8;
2045 icon
->paste_command
= wmalloc(len
);
2046 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
2052 void reattachIcon(WDock
* dock
, WAppIcon
* icon
, int x
, int y
)
2056 for (index
= 1; index
< dock
->max_icons
; index
++) {
2057 if (dock
->icon_array
[index
] == icon
)
2060 assert(index
< dock
->max_icons
);
2065 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2066 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2069 Bool
moveIconBetweenDocks(WDock
* src
, WDock
* dest
, WAppIcon
* icon
, int x
, int y
)
2076 return True
; /* No move needed, we're already there */
2081 wwin
= icon
->icon
->owner
;
2084 * For the moment we can't do this if we move icons in Clip from one
2085 * workspace to other, because if we move two or more icons without
2086 * command, the dialog box will not be able to tell us to which of the
2087 * moved icons it applies. -Dan
2089 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
2090 command
= GetCommandForWindow(wwin
->client_win
);
2092 icon
->command
= command
;
2095 /* icon->forced_dock = 1; */
2096 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2097 _("Type the command used to launch the application"), &command
)) {
2098 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2102 icon
->command
= command
;
2113 if (dest
->type
== WM_DOCK
)
2114 wClipMakeIconOmnipresent(icon
, False
);
2116 for (index
= 1; index
< src
->max_icons
; index
++) {
2117 if (src
->icon_array
[index
] == icon
)
2120 assert(index
< src
->max_icons
);
2122 src
->icon_array
[index
] = NULL
;
2125 for (index
= 1; index
< dest
->max_icons
; index
++) {
2126 if (dest
->icon_array
[index
] == NULL
)
2129 /* if (index == dest->max_icons)
2132 assert(index
< dest
->max_icons
);
2134 dest
->icon_array
[index
] = icon
;
2137 /* deselect the icon */
2138 if (icon
->icon
->selected
)
2139 wIconSelect(icon
->icon
);
2141 if (dest
->type
== WM_DOCK
) {
2142 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2143 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2145 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2146 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2149 /* set it to be kept when moving to dock.
2150 * Unless the icon does not have a command set
2152 if (icon
->command
&& dest
->type
== WM_DOCK
) {
2153 icon
->attracted
= 0;
2154 if (icon
->icon
->shadowed
) {
2155 icon
->icon
->shadowed
= 0;
2156 icon
->icon
->force_paint
= 1;
2160 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2166 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2167 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2171 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2172 wAppIconPaint(icon
);
2177 void wDockDetach(WDock
* dock
, WAppIcon
* icon
)
2181 /* make the settings panel be closed */
2183 DestroyDockAppSettingsPanel(icon
->panel
);
2186 /* This must be called before icon->dock is set to NULL.
2187 * Don't move it. -Dan
2189 wClipMakeIconOmnipresent(icon
, False
);
2193 icon
->attracted
= 0;
2194 icon
->auto_launch
= 0;
2195 if (icon
->icon
->shadowed
) {
2196 icon
->icon
->shadowed
= 0;
2197 icon
->icon
->force_paint
= 1;
2200 /* deselect the icon */
2201 if (icon
->icon
->selected
)
2202 wIconSelect(icon
->icon
);
2204 if (icon
->command
) {
2205 wfree(icon
->command
);
2206 icon
->command
= NULL
;
2208 #ifdef XDND /* was OFFIX */
2209 if (icon
->dnd_command
) {
2210 wfree(icon
->dnd_command
);
2211 icon
->dnd_command
= NULL
;
2214 if (icon
->paste_command
) {
2215 wfree(icon
->paste_command
);
2216 icon
->paste_command
= NULL
;
2219 for (index
= 1; index
< dock
->max_icons
; index
++)
2220 if (dock
->icon_array
[index
] == icon
)
2222 assert(index
< dock
->max_icons
);
2223 dock
->icon_array
[index
] = NULL
;
2229 /* if the dock is not attached to an application or
2230 * the the application did not set the approriate hints yet,
2231 * destroy the icon */
2232 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2233 wAppIconDestroy(icon
);
2235 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2236 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2237 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2238 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2239 icon
->icon
->core
->descriptor
.parent
= icon
;
2241 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2243 wAppIconPaint(icon
);
2244 if (wPreferences
.auto_arrange_icons
) {
2245 wArrangeIcons(dock
->screen_ptr
, True
);
2248 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2253 * returns the closest Dock slot index for the passed
2256 * Returns False if icon can't be docked.
2258 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2261 Bool
wDockSnapIcon(WDock
* dock
, WAppIcon
* icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2263 WScreen
*scr
= dock
->screen_ptr
;
2266 int i
, offset
= ICON_SIZE
/ 2;
2267 WAppIcon
*aicon
= NULL
;
2268 WAppIcon
*nicon
= NULL
;
2269 int max_y_icons
, max_x_icons
;
2271 /* TODO: XINERAMA, for these */
2272 max_x_icons
= scr
->scr_width
/ ICON_SIZE
;
2273 max_y_icons
= scr
->scr_height
/ ICON_SIZE
- 1;
2275 if (wPreferences
.flags
.noupdates
)
2281 /* if the dock is full */
2282 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
)) {
2286 /* exact position */
2288 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2290 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2293 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2295 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2297 /* check if the icon is outside the screen boundaries */
2302 rect
.pos
.x
= dx
+ ex_x
* ICON_SIZE
;
2303 rect
.pos
.y
= dy
+ ex_y
* ICON_SIZE
;
2304 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2306 wGetRectPlacementInfo(scr
, rect
, &flags
);
2307 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
2311 if (dock
->type
== WM_DOCK
) {
2312 if (icon
->dock
!= dock
&& ex_x
!= 0)
2316 for (i
= 0; i
< dock
->max_icons
; i
++) {
2317 nicon
= dock
->icon_array
[i
];
2318 if (nicon
&& nicon
->yindex
== ex_y
) {
2325 int sig
, done
, closest
;
2327 /* Possible cases when redocking:
2329 * icon dragged out of range of any slot -> false
2330 * icon dragged to range of free slot
2331 * icon dragged to range of same slot
2332 * icon dragged to range of different icon
2334 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2337 if (ex_y
>= 0 && ex_y
<= max_y_icons
&& (aicon
== icon
|| !aicon
)) {
2343 /* start looking at the upper slot or lower? */
2344 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2351 /* look for closest free slot */
2352 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2356 closest
= sig
* (i
/ 2) + ex_y
;
2357 /* check if this slot is used */
2359 for (j
= 0; j
< dock
->max_icons
; j
++) {
2360 if (dock
->icon_array
[j
]
2361 && dock
->icon_array
[j
]->yindex
== closest
) {
2362 /* slot is used by someone else */
2363 if (dock
->icon_array
[j
] != icon
)
2371 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2372 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2373 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2378 } else { /* !redocking */
2380 /* if slot is free and the icon is close enough, return it */
2381 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2391 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2392 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+ 1;
2395 for (k
= start
; k
< stop
; k
++) {
2396 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2399 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2400 nicon
= tmp
->icon_array
[i
];
2401 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2409 for (k
= start
; k
< stop
; k
++) {
2410 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2413 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2414 nicon
= tmp
->icon_array
[i
];
2415 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2416 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2417 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2426 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2435 static int onScreen(WScreen
* scr
, int x
, int y
, int sx
, int ex
, int sy
, int ey
)
2437 WMRect rect
= wmkrect(x
, y
, ICON_SIZE
, ICON_SIZE
);
2440 wGetRectPlacementInfo(scr
, rect
, &flags
);
2442 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2446 * returns true if it can find a free slot in the dock,
2447 * in which case it changes x_pos and y_pos accordingly.
2448 * Else returns false.
2450 Bool
wDockFindFreeSlot(WDock
* dock
, int *x_pos
, int *y_pos
)
2452 WScreen
*scr
= dock
->screen_ptr
;
2454 WAppIconChain
*chain
;
2455 unsigned char *slot_map
;
2459 int i
, done
= False
;
2461 int sx
= 0, sy
= 0, ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2462 int extra_count
= 0;
2464 if (dock
->type
== WM_CLIP
&& dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2465 extra_count
= scr
->global_icon_count
;
2467 /* if the dock is full */
2468 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
) {
2472 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2473 if (scr
->dock
->on_right_side
)
2474 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2476 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2479 if (ex
< dock
->x_pos
)
2481 if (sx
> dock
->x_pos
+ ICON_SIZE
)
2482 sx
= dock
->x_pos
+ ICON_SIZE
;
2489 /* check if clip is in a corner */
2490 if (dock
->type
== WM_CLIP
) {
2491 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2493 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2495 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2497 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2504 /* If the clip is in the corner, use only slots that are in the border
2506 if (corner
!= C_NONE
) {
2510 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2511 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2512 hmap
= wmalloc(hcount
+ 1);
2513 memset(hmap
, 0, hcount
+ 1);
2514 vmap
= wmalloc(vcount
+ 1);
2515 memset(vmap
, 0, vcount
+ 1);
2517 /* mark used positions */
2520 for (i
= 0; i
< dock
->max_icons
; i
++) {
2521 btn
= dock
->icon_array
[i
];
2525 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2526 vmap
[btn
->yindex
] = 1;
2527 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2528 hmap
[btn
->xindex
] = 1;
2530 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2532 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2533 vmap
[btn
->yindex
] = 1;
2534 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2535 hmap
[btn
->xindex
] = 1;
2539 for (i
= 0; i
< dock
->max_icons
; i
++) {
2540 btn
= dock
->icon_array
[i
];
2544 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2545 vmap
[btn
->yindex
] = 1;
2546 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2547 hmap
[-btn
->xindex
] = 1;
2549 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2551 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2552 vmap
[btn
->yindex
] = 1;
2553 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2554 hmap
[-btn
->xindex
] = 1;
2558 for (i
= 0; i
< dock
->max_icons
; i
++) {
2559 btn
= dock
->icon_array
[i
];
2563 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2564 vmap
[-btn
->yindex
] = 1;
2565 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2566 hmap
[btn
->xindex
] = 1;
2568 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2570 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2571 vmap
[-btn
->yindex
] = 1;
2572 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2573 hmap
[btn
->xindex
] = 1;
2578 for (i
= 0; i
< dock
->max_icons
; i
++) {
2579 btn
= dock
->icon_array
[i
];
2583 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2584 vmap
[-btn
->yindex
] = 1;
2585 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2586 hmap
[-btn
->xindex
] = 1;
2588 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2590 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2591 vmap
[-btn
->yindex
] = 1;
2592 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2593 hmap
[-btn
->xindex
] = 1;
2599 /* search a vacant slot */
2600 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2601 if (i
< vcount
&& vmap
[i
] == 0) {
2607 } else if (i
< hcount
&& hmap
[i
] == 0) {
2617 /* If found a slot, translate and return */
2619 if (corner
== C_NW
|| corner
== C_NE
) {
2624 if (corner
== C_NE
|| corner
== C_SE
) {
2631 /* else, try to find a slot somewhere else */
2634 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2635 * placed outside of screen */
2636 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2638 /* In the worst case (the clip is in the corner of the screen),
2639 * the amount of icons that fit in the clip is smaller.
2640 * Double the map to get a safe value.
2644 r
= (mwidth
- 1) / 2;
2646 slot_map
= wmalloc(mwidth
* mwidth
);
2647 memset(slot_map
, 0, mwidth
* mwidth
);
2649 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2651 /* mark used slots in the map. If the slot falls outside the map
2652 * (for example, when all icons are placed in line), ignore them. */
2653 for (i
= 0; i
< dock
->max_icons
; i
++) {
2654 btn
= dock
->icon_array
[i
];
2656 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2658 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2659 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2661 /* Find closest slot from the center that is free by scanning the
2662 * map from the center to outward in circular passes.
2663 * This will not result in a neat layout, but will be optimal
2664 * in the sense that there will not be holes left.
2667 for (i
= 1; i
<= r
&& !done
; i
++) {
2670 /* top and bottom parts of the ring */
2671 for (x
= -i
; x
<= i
&& !done
; x
++) {
2672 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2674 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2675 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2682 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2683 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2690 /* left and right parts of the ring */
2691 for (y
= -i
+ 1; y
<= i
- 1; y
++) {
2692 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2694 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2695 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2702 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2703 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2716 static void moveDock(WDock
* dock
, int new_x
, int new_y
)
2721 dock
->x_pos
= new_x
;
2722 dock
->y_pos
= new_y
;
2723 for (i
= 0; i
< dock
->max_icons
; i
++) {
2724 btn
= dock
->icon_array
[i
];
2726 btn
->x_pos
= new_x
+ btn
->xindex
* ICON_SIZE
;
2727 btn
->y_pos
= new_y
+ btn
->yindex
* ICON_SIZE
;
2728 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2733 static void swapDock(WDock
* dock
)
2735 WScreen
*scr
= dock
->screen_ptr
;
2739 if (dock
->on_right_side
) {
2740 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2742 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2745 for (i
= 0; i
< dock
->max_icons
; i
++) {
2746 btn
= dock
->icon_array
[i
];
2749 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2753 wScreenUpdateUsableArea(scr
);
2756 static pid_t
execCommand(WAppIcon
* btn
, char *command
, WSavedState
* state
)
2758 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2764 cmdline
= ExpandOptions(scr
, command
);
2766 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2774 wtokensplit(cmdline
, &argv
, &argc
);
2784 if ((pid
= fork()) == 0) {
2788 SetupEnvironment(scr
);
2794 args
= malloc(sizeof(char *) * (argc
+ 1));
2797 for (i
= 0; i
< argc
; i
++) {
2801 execvp(argv
[0], args
);
2804 wtokenfree(argv
, argc
);
2808 state
= wmalloc(sizeof(WSavedState
));
2809 memset(state
, 0, sizeof(WSavedState
));
2811 state
->miniaturized
= -1;
2813 if (btn
->dock
== scr
->dock
|| btn
->omnipresent
)
2814 state
->workspace
= -1;
2816 state
->workspace
= scr
->current_workspace
;
2818 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
2819 wAddDeathHandler(pid
, (WDeathHandler
*) trackDeadProcess
, btn
->dock
);
2827 void wDockHideIcons(WDock
* dock
)
2834 for (i
= 1; i
< dock
->max_icons
; i
++) {
2835 if (dock
->icon_array
[i
])
2836 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2840 dockIconPaint(dock
->icon_array
[0]);
2843 void wDockShowIcons(WDock
* dock
)
2851 btn
= dock
->icon_array
[0];
2852 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2854 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2855 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2857 for (i
= 1; i
< dock
->max_icons
; i
++) {
2858 if (dock
->icon_array
[i
]) {
2859 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
, btn
->icon
->core
);
2864 if (!dock
->collapsed
) {
2865 for (i
= 1; i
< dock
->max_icons
; i
++) {
2866 if (dock
->icon_array
[i
]) {
2867 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2876 void wDockLower(WDock
* dock
)
2880 for (i
= 0; i
< dock
->max_icons
; i
++) {
2881 if (dock
->icon_array
[i
])
2882 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2886 void wDockRaise(WDock
* dock
)
2890 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
2891 if (dock
->icon_array
[i
])
2892 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2896 void wDockRaiseLower(WDock
* dock
)
2898 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2899 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2900 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2906 void wDockFinishLaunch(WDock
* dock
, WAppIcon
* icon
)
2908 icon
->launching
= 0;
2909 icon
->relaunching
= 0;
2910 dockIconPaint(icon
);
2913 WAppIcon
*wDockFindIconForWindow(WDock
* dock
, Window window
)
2918 for (i
= 0; i
< dock
->max_icons
; i
++) {
2919 icon
= dock
->icon_array
[i
];
2920 if (icon
&& icon
->main_window
== window
)
2926 void wDockTrackWindowLaunch(WDock
* dock
, Window window
)
2929 char *wm_class
, *wm_instance
;
2931 Bool firstPass
= True
;
2933 char *command
= NULL
;
2935 command
= GetCommandForWindow(window
);
2937 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) || (!wm_class
&& !wm_instance
)) {
2945 for (i
= 0; i
< dock
->max_icons
; i
++) {
2946 icon
= dock
->icon_array
[i
];
2950 /* app is already attached to icon */
2951 if (icon
->main_window
== window
) {
2956 if ((icon
->wm_instance
|| icon
->wm_class
)
2957 && (icon
->launching
|| !icon
->running
)) {
2959 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0) {
2962 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0) {
2965 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0) {
2969 if (!icon
->relaunching
) {
2972 /* Possibly an application that was docked with dockit,
2973 * but the user did not update WMState to indicate that
2974 * it was docked by force */
2975 wapp
= wApplicationOf(window
);
2977 icon
->forced_dock
= 1;
2980 if (!icon
->forced_dock
) {
2981 icon
->main_window
= window
;
2985 if (!wPreferences
.no_animations
&& !icon
->launching
&&
2986 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
2990 icon
->launching
= 1;
2991 dockIconPaint(icon
);
2993 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
2994 wm_instance
, wm_class
, TILE_NORMAL
);
2995 /* XXX: can: aicon->icon == NULL ? */
2996 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
2997 wAppIconMove(aicon
, x0
, y0
);
2998 /* Should this always be lowered? -Dan */
3000 wLowerFrame(aicon
->icon
->core
);
3001 XMapWindow(dpy
, aicon
->icon
->core
->window
);
3002 aicon
->launching
= 1;
3003 wAppIconPaint(aicon
);
3004 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
3005 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
3006 wAppIconDestroy(aicon
);
3008 wDockFinishLaunch(dock
, icon
);
3013 if (firstPass
&& !found
) {
3027 void wClipUpdateForWorkspaceChange(WScreen
* scr
, int workspace
)
3029 if (!wPreferences
.flags
.noclip
) {
3030 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3031 if (scr
->current_workspace
!= workspace
) {
3032 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3033 WAppIconChain
*chain
= scr
->global_icons
;
3036 moveIconBetweenDocks(chain
->aicon
->dock
,
3037 scr
->workspaces
[workspace
]->clip
,
3038 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
3039 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
3040 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3041 chain
= chain
->next
;
3044 wDockHideIcons(old_clip
);
3045 if (old_clip
->auto_raise_lower
) {
3046 if (old_clip
->auto_raise_magic
) {
3047 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3048 old_clip
->auto_raise_magic
= NULL
;
3050 wDockLower(old_clip
);
3052 if (old_clip
->auto_collapse
) {
3053 if (old_clip
->auto_expand_magic
) {
3054 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3055 old_clip
->auto_expand_magic
= NULL
;
3057 old_clip
->collapsed
= 1;
3059 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3061 if (scr
->flags
.clip_balloon_mapped
)
3062 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3066 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
* dock
)
3071 for (i
= 0; i
< dock
->max_icons
; i
++) {
3072 icon
= dock
->icon_array
[i
];
3076 if (icon
->launching
&& icon
->pid
== pid
) {
3077 if (!icon
->relaunching
) {
3079 icon
->main_window
= None
;
3081 wDockFinishLaunch(dock
, icon
);
3083 if (status
== 111) {
3088 if (icon
->drop_launch
)
3089 cmd
= icon
->dnd_command
;
3092 if (icon
->paste_launch
)
3093 cmd
= icon
->paste_command
;
3095 cmd
= icon
->command
;
3097 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3099 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3106 static void toggleLowered(WDock
* dock
)
3111 /* lower/raise Dock */
3112 if (!dock
->lowered
) {
3113 newlevel
= WMNormalLevel
;
3116 newlevel
= WMDockLevel
;
3120 for (i
= 0; i
< dock
->max_icons
; i
++) {
3121 tmp
= dock
->icon_array
[i
];
3125 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3127 wLowerFrame(tmp
->icon
->core
);
3130 if (dock
->type
== WM_DOCK
)
3131 wScreenUpdateUsableArea(dock
->screen_ptr
);
3134 static void toggleCollapsed(WDock
* dock
)
3136 if (dock
->collapsed
) {
3137 dock
->collapsed
= 0;
3138 wDockShowIcons(dock
);
3140 dock
->collapsed
= 1;
3141 wDockHideIcons(dock
);
3145 static void openDockMenu(WDock
* dock
, WAppIcon
* aicon
, XEvent
* event
)
3147 WScreen
*scr
= dock
->screen_ptr
;
3148 WObjDescriptor
*desc
;
3150 WApplication
*wapp
= NULL
;
3154 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3156 if (dock
->type
== WM_DOCK
) {
3158 entry
= dock
->menu
->entries
[index
];
3159 entry
->flags
.indicator_on
= !dock
->lowered
;
3160 entry
->clientdata
= dock
;
3161 dock
->menu
->flags
.realized
= 0;
3164 if (scr
->clip_options
)
3165 updateClipOptionsMenu(scr
->clip_options
, dock
);
3167 n_selected
= numberOfSelectedIcons(dock
);
3169 /* Rename Workspace */
3170 entry
= dock
->menu
->entries
[++index
];
3171 if (aicon
== scr
->clip_icon
) {
3172 entry
->callback
= renameCallback
;
3173 entry
->clientdata
= dock
;
3174 entry
->flags
.indicator
= 0;
3175 entry
->text
= _("Rename Workspace");
3177 entry
->callback
= omnipresentCallback
;
3178 entry
->clientdata
= aicon
;
3179 if (n_selected
> 0) {
3180 entry
->flags
.indicator
= 0;
3181 entry
->text
= _("Toggle Omnipresent");
3183 entry
->flags
.indicator
= 1;
3184 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3185 entry
->flags
.indicator_type
= MI_CHECK
;
3186 entry
->text
= _("Omnipresent");
3190 /* select/unselect icon */
3191 entry
= dock
->menu
->entries
[++index
];
3192 entry
->clientdata
= aicon
;
3193 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3194 wMenuSetEnabled(dock
->menu
, index
, aicon
!= scr
->clip_icon
);
3196 /* select/unselect all icons */
3197 entry
= dock
->menu
->entries
[++index
];
3198 entry
->clientdata
= aicon
;
3200 entry
->text
= _("Unselect All Icons");
3202 entry
->text
= _("Select All Icons");
3203 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3206 entry
= dock
->menu
->entries
[++index
];
3207 entry
->clientdata
= aicon
;
3209 entry
->text
= _("Keep Icons");
3211 entry
->text
= _("Keep Icon");
3212 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3214 /* this is the workspace submenu part */
3215 entry
= dock
->menu
->entries
[++index
];
3217 entry
->text
= _("Move Icons To");
3219 entry
->text
= _("Move Icon To");
3220 if (scr
->clip_submenu
)
3221 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3222 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3224 /* remove icon(s) */
3225 entry
= dock
->menu
->entries
[++index
];
3226 entry
->clientdata
= aicon
;
3228 entry
->text
= _("Remove Icons");
3230 entry
->text
= _("Remove Icon");
3231 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3233 /* attract icon(s) */
3234 entry
= dock
->menu
->entries
[++index
];
3235 entry
->clientdata
= aicon
;
3237 dock
->menu
->flags
.realized
= 0;
3238 wMenuRealize(dock
->menu
);
3241 if (aicon
->icon
->owner
) {
3242 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3248 entry
= dock
->menu
->entries
[++index
];
3249 entry
->clientdata
= aicon
;
3250 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3253 entry
= dock
->menu
->entries
[++index
];
3254 entry
->clientdata
= aicon
;
3255 if (wapp
&& wapp
->flags
.hidden
) {
3256 entry
->text
= _("Unhide Here");
3258 entry
->text
= _("Bring Here");
3260 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3263 entry
= dock
->menu
->entries
[++index
];
3264 entry
->clientdata
= aicon
;
3265 if (wapp
&& wapp
->flags
.hidden
) {
3266 entry
->text
= _("Unhide");
3268 entry
->text
= _("Hide");
3270 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3273 entry
= dock
->menu
->entries
[++index
];
3274 entry
->clientdata
= aicon
;
3275 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3278 entry
= dock
->menu
->entries
[++index
];
3279 entry
->clientdata
= aicon
;
3280 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3282 if (!dock
->menu
->flags
.realized
)
3283 wMenuRealize(dock
->menu
);
3285 if (dock
->type
== WM_CLIP
) {
3286 /*x_pos = event->xbutton.x_root+2; */
3287 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3290 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3291 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3294 x_pos
= dock
->on_right_side
? scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3297 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3299 /* allow drag select */
3300 event
->xany
.send_event
= True
;
3301 desc
= &dock
->menu
->menu
->descriptor
;
3302 (*desc
->handle_mousedown
) (desc
, event
);
3305 /******************************************************************/
3306 static void iconDblClick(WObjDescriptor
* desc
, XEvent
* event
)
3308 WAppIcon
*btn
= desc
->parent
;
3309 WDock
*dock
= btn
->dock
;
3310 WApplication
*wapp
= NULL
;
3313 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3314 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3316 assert(wapp
!= NULL
);
3318 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3320 /* go to the last workspace that the user worked on the app */
3321 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
&& !unhideHere
) {
3322 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3325 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3327 if (event
->xbutton
.state
& MOD_MASK
) {
3328 wHideOtherApplications(btn
->icon
->owner
);
3331 if (event
->xbutton
.button
== Button1
) {
3333 if (event
->xbutton
.state
& MOD_MASK
) {
3334 /* raise/lower dock */
3335 toggleLowered(dock
);
3336 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3337 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
)
3338 toggleCollapsed(dock
);
3340 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3341 } else if (btn
->command
) {
3342 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3343 launchDockedApplication(btn
, False
);
3345 } else if (btn
->xindex
== 0 && btn
->yindex
== 0 && btn
->dock
->type
== WM_DOCK
) {
3346 wShowGNUstepPanel(dock
->screen_ptr
);
3352 static void handleDockMove(WDock
* dock
, WAppIcon
* aicon
, XEvent
* event
)
3354 WScreen
*scr
= dock
->screen_ptr
;
3355 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3358 int grabbed
= 0, swapped
= 0, done
;
3359 Pixmap ghost
= None
;
3360 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3363 puts("moving dock");
3365 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3366 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3367 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3368 wwarning("pointer grab failed for dock move");
3371 for (x
= 0; x
< dock
->max_icons
; x
++) {
3372 if (dock
->icon_array
[x
] != NULL
&& dock
->icon_array
[x
]->yindex
> y
)
3373 y
= dock
->icon_array
[x
]->yindex
;
3376 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
* y
);
3380 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3381 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3388 /* It means the cursor moved so fast that it entered
3389 * something else (if moving slowly, it would have
3390 * stayed in the dock that is being moved. Ignore such
3391 * "spurious" EnterNotifiy's */
3396 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3397 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3398 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3399 | ButtonReleaseMask
| ButtonPressMask
,
3400 wCursor
[WCUR_MOVE
], CurrentTime
);
3405 if (dock
->type
== WM_CLIP
) {
3406 x
= ev
.xmotion
.x_root
- ofs_x
;
3407 y
= ev
.xmotion
.y_root
- ofs_y
;
3408 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3410 moveDock(dock
, x
, y
);
3412 /* move vertically if pointer is inside the dock */
3413 if ((dock
->on_right_side
&& ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3414 || (!dock
->on_right_side
&& ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
* 2)) {
3416 x
= ev
.xmotion
.x_root
- ofs_x
;
3417 y
= ev
.xmotion
.y_root
- ofs_y
;
3418 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3419 moveDock(dock
, dock
->x_pos
, y
);
3421 /* move horizontally to change sides */
3422 x
= ev
.xmotion
.x_root
- ofs_x
;
3423 if (!dock
->on_right_side
) {
3427 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
* 2) {
3428 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
- ICON_SIZE
3429 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3430 if (superfluous
&& ghost
== None
) {
3431 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3432 scr
->scr_width
- ICON_SIZE
3433 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3434 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3435 XClearWindow(dpy
, scr
->dock_shadow
);
3437 XMapRaised(dpy
, scr
->dock_shadow
);
3440 if (superfluous
&& ghost
!= None
) {
3441 XFreePixmap(dpy
, ghost
);
3444 XUnmapWindow(dpy
, scr
->dock_shadow
);
3449 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3450 XMoveWindow(dpy
, scr
->dock_shadow
, DOCK_EXTRA_SPACE
, dock
->y_pos
);
3451 if (superfluous
&& ghost
== None
) {
3452 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3453 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3454 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3455 XClearWindow(dpy
, scr
->dock_shadow
);
3457 XMapRaised(dpy
, scr
->dock_shadow
);
3460 XUnmapWindow(dpy
, scr
->dock_shadow
);
3462 if (superfluous
&& ghost
!= None
) {
3463 XFreePixmap(dpy
, ghost
);
3475 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3477 XUngrabPointer(dpy
, CurrentTime
);
3478 XUnmapWindow(dpy
, scr
->dock_shadow
);
3479 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3480 if (dock
->type
== WM_DOCK
) {
3483 dock
->on_right_side
= 1;
3485 dock
->on_right_side
= 0;
3487 wArrangeIcons(scr
, False
);
3496 XFreePixmap(dpy
, ghost
);
3497 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3500 puts("End dock move");
3504 static Bool
handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3506 WScreen
*scr
= dock
->screen_ptr
;
3508 WIcon
*icon
= aicon
->icon
;
3509 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3510 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3512 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3513 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3514 int shad_x
= x
, shad_y
= y
;
3515 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3517 Pixmap ghost
= None
;
3519 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3520 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3521 Bool hasMoved
= False
;
3523 if (wPreferences
.flags
.noupdates
)
3526 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3527 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3528 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3530 wwarning("pointer grab failed for icon move");
3534 if (!(event
->xbutton
.state
& MOD_MASK
))
3535 wRaiseFrame(icon
->core
);
3537 if (!wPreferences
.flags
.noclip
)
3538 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3540 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3542 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3545 wins
[0] = icon
->core
->window
;
3546 wins
[1] = scr
->dock_shadow
;
3547 XRestackWindows(dpy
, wins
, 2);
3548 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
3550 if (icon
->pixmap
!= None
)
3551 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3553 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3555 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3556 XClearWindow(dpy
, scr
->dock_shadow
);
3558 XMapWindow(dpy
, scr
->dock_shadow
);
3563 XMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3564 | ButtonMotionMask
| ExposureMask
, &ev
);
3573 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3574 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3575 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3576 | ButtonReleaseMask
| ButtonPressMask
,
3577 wCursor
[WCUR_MOVE
], CurrentTime
);
3586 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3587 if (i
== scr
->current_workspace
)
3589 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3593 x
= ev
.xmotion
.x_root
- ofs_x
;
3594 y
= ev
.xmotion
.y_root
- ofs_y
;
3595 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3598 if (last_dock
!= dock
&& collapsed
) {
3599 last_dock
->collapsed
= 1;
3600 wDockHideIcons(last_dock
);
3603 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3604 dock
->collapsed
= 0;
3605 wDockShowIcons(dock
);
3607 if (dock
->auto_raise_lower
)
3611 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3614 if (last_dock
!= dock2
&& collapsed
) {
3615 last_dock
->collapsed
= 1;
3616 wDockHideIcons(last_dock
);
3619 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3620 dock2
->collapsed
= 0;
3621 wDockShowIcons(dock2
);
3623 if (dock2
->auto_raise_lower
)
3628 if (aicon
->launching
|| aicon
->lock
|| (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3629 || (!aicon
->running
&& tmp
)) {
3630 shad_x
= last_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3631 shad_y
= last_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3633 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3636 XMapWindow(dpy
, scr
->dock_shadow
);
3641 XUnmapWindow(dpy
, scr
->dock_shadow
);
3645 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3652 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3654 XUngrabPointer(dpy
, CurrentTime
);
3656 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3657 XUnmapWindow(dpy
, scr
->dock_shadow
);
3659 reattachIcon(dock
, aicon
, ix
, iy
);
3660 if (clip
&& dock
!= clip
&& clip
->auto_raise_lower
)
3663 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3665 /* Slide it back if dock rejected it */
3666 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
, aicon
->y_pos
);
3667 reattachIcon(dock
, aicon
, aicon
->xindex
, aicon
->yindex
);
3669 if (last_dock
->type
== WM_CLIP
&& last_dock
->auto_collapse
) {
3677 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3678 /* We need to deselect it, even if is deselected in
3679 * wDockDetach(), because else DoKaboom() will fail.
3681 if (aicon
->icon
->selected
)
3682 wIconSelect(aicon
->icon
);
3684 wSoundPlay(WSOUND_KABOOM
);
3685 DoKaboom(scr
, aicon
->icon
->core
->window
, x
, y
);
3687 wSoundPlay(WSOUND_UNDOCK
);
3690 wSoundPlay(WSOUND_UNDOCK
);
3692 if (clip
&& clip
->auto_raise_lower
)
3694 wDockDetach(dock
, aicon
);
3697 last_dock
->collapsed
= 1;
3698 wDockHideIcons(last_dock
);
3703 XFreePixmap(dpy
, ghost
);
3704 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3708 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3709 if (i
== scr
->current_workspace
)
3711 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3715 puts("End icon move");
3720 return False
; /* never reached */
3723 static int getClipButton(int px
, int py
)
3725 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3727 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3730 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3731 return CLIP_FORWARD
;
3732 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3738 static void handleClipChangeWorkspace(WScreen
* scr
, XEvent
* event
)
3741 int done
, direction
, new_ws
;
3743 WDock
*clip
= scr
->clip_icon
->dock
;
3745 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3747 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3748 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3750 wClipIconPaint(scr
->clip_icon
);
3753 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3760 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3761 if (new_dir
!= direction
) {
3762 direction
= new_dir
;
3763 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3764 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3765 wClipIconPaint(scr
->clip_icon
);
3773 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3778 clip
->lclip_button_pushed
= 0;
3779 clip
->rclip_button_pushed
= 0;
3781 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3783 if (direction
== CLIP_FORWARD
) {
3784 if (scr
->current_workspace
< scr
->workspace_count
- 1)
3785 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3786 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
- 1)
3787 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3788 else if (wPreferences
.ws_cycle
)
3789 wWorkspaceChange(scr
, 0);
3790 } else if (direction
== CLIP_REWIND
) {
3791 if (scr
->current_workspace
> 0)
3792 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
3793 else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
)
3794 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
3797 wClipIconPaint(scr
->clip_icon
);
3800 static void iconMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
3802 WAppIcon
*aicon
= desc
->parent
;
3803 WDock
*dock
= aicon
->dock
;
3804 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3806 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3809 scr
->last_dock
= dock
;
3811 if (dock
->menu
->flags
.mapped
)
3812 wMenuUnmap(dock
->menu
);
3814 if (IsDoubleClick(scr
, event
)) {
3815 /* double-click was not in the main clip icon */
3816 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3817 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3818 iconDblClick(desc
, event
);
3823 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
3824 XUnmapWindow(dpy
, scr
->clip_balloon
);
3825 scr
->flags
.clip_balloon_mapped
= 0;
3828 puts("handling dock");
3830 if (event
->xbutton
.button
== Button1
) {
3831 if (event
->xbutton
.state
& MOD_MASK
)
3836 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
&& dock
->type
!= WM_DOCK
) {
3837 wIconSelect(aicon
->icon
);
3841 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3842 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
3843 && dock
->type
== WM_CLIP
)
3844 handleClipChangeWorkspace(scr
, event
);
3846 handleDockMove(dock
, aicon
, event
);
3848 Bool hasMoved
= handleIconMove(dock
, aicon
, event
);
3849 if (wPreferences
.single_click
&& !hasMoved
)
3850 iconDblClick(desc
, event
);
3852 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&& aicon
== scr
->clip_icon
) {
3853 if (!scr
->clip_ws_menu
) {
3854 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3856 if (scr
->clip_ws_menu
) {
3857 WMenu
*wsMenu
= scr
->clip_ws_menu
;
3860 wWorkspaceMenuUpdate(scr
, wsMenu
);
3862 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
3865 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
3866 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
3868 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
3870 desc
= &wsMenu
->menu
->descriptor
;
3871 event
->xany
.send_event
= True
;
3872 (*desc
->handle_mousedown
) (desc
, event
);
3874 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
3875 (event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
) {
3876 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3877 } else if (event
->xbutton
.button
== Button3
) {
3878 if (event
->xbutton
.send_event
&&
3879 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3880 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3881 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3882 wwarning("pointer grab failed for dockicon menu");
3886 openDockMenu(dock
, aicon
, event
);
3887 } else if (event
->xbutton
.button
== Button2
) {
3888 WAppIcon
*btn
= desc
->parent
;
3890 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3891 launchDockedApplication(btn
, True
);
3896 static void showClipBalloon(WDock
* dock
, int workspace
)
3900 WScreen
*scr
= dock
->screen_ptr
;
3904 scr
->flags
.clip_balloon_mapped
= 1;
3905 XMapWindow(dpy
, scr
->clip_balloon
);
3907 text
= scr
->workspaces
[workspace
]->name
;
3909 w
= WMWidthOfString(scr
->clip_title_font
, text
, strlen(text
));
3911 h
= WMFontHeight(scr
->clip_title_font
);
3912 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
3914 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
3915 y
= dock
->y_pos
+ ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
3917 if (x
+ w
> scr
->scr_width
) {
3918 x
= scr
->scr_width
- w
;
3919 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
3920 y
= dock
->y_pos
- h
- 1;
3922 y
= dock
->y_pos
+ ICON_SIZE
;
3923 XRaiseWindow(dpy
, scr
->clip_balloon
);
3925 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
3926 stack
[1] = scr
->clip_balloon
;
3927 XRestackWindows(dpy
, stack
, 2);
3929 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
3930 XClearWindow(dpy
, scr
->clip_balloon
);
3931 WMDrawString(scr
->wmscreen
, scr
->clip_balloon
,
3932 scr
->clip_title_color
[CLIP_NORMAL
], scr
->clip_title_font
, 0, 0, text
, strlen(text
));
3935 static void clipEnterNotify(WObjDescriptor
* desc
, XEvent
* event
)
3937 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3941 assert(event
->type
== EnterNotify
);
3943 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3946 scr
= btn
->icon
->core
->screen_ptr
;
3947 if (!btn
->omnipresent
)
3950 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3952 if (!dock
|| dock
->type
!= WM_CLIP
)
3955 /* The auto raise/lower code */
3956 if (dock
->auto_lower_magic
) {
3957 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3958 dock
->auto_lower_magic
= NULL
;
3960 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
3961 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
, clipAutoRaise
, (void *)dock
);
3964 /* The auto expand/collapse code */
3965 if (dock
->auto_collapse_magic
) {
3966 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3967 dock
->auto_collapse_magic
= NULL
;
3969 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
3970 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
, clipAutoExpand
, (void *)dock
);
3973 if (btn
->xindex
== 0 && btn
->yindex
== 0)
3974 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
3976 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
3977 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
3978 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
3983 static void clipLeave(WDock
* dock
)
3986 WObjDescriptor
*desc
= NULL
;
3988 if (!dock
|| dock
->type
!= WM_CLIP
)
3991 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
3992 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3993 (XPointer
*) & desc
) != XCNOENT
3994 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
3995 && ((WAppIcon
*) desc
->parent
)->dock
&& ((WAppIcon
*) desc
->parent
)->dock
->type
== WM_CLIP
) {
3996 /* We didn't left the Clip yet */
3997 XPutBackEvent(dpy
, &event
);
4001 XPutBackEvent(dpy
, &event
);
4003 /* We entered a withdrawn window, so we're still in Clip */
4007 if (dock
->auto_raise_magic
) {
4008 WMDeleteTimerHandler(dock
->auto_raise_magic
);
4009 dock
->auto_raise_magic
= NULL
;
4011 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
4012 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
, clipAutoLower
, (void *)dock
);
4015 if (dock
->auto_expand_magic
) {
4016 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4017 dock
->auto_expand_magic
= NULL
;
4019 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
4020 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
, clipAutoCollapse
, (void *)dock
);
4024 static void clipLeaveNotify(WObjDescriptor
* desc
, XEvent
* event
)
4026 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
4028 assert(event
->type
== LeaveNotify
);
4030 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
4033 clipLeave(btn
->dock
);
4036 static void clipAutoCollapse(void *cdata
)
4038 WDock
*dock
= (WDock
*) cdata
;
4040 if (dock
->type
!= WM_CLIP
)
4043 if (dock
->auto_collapse
) {
4044 dock
->collapsed
= 1;
4045 wDockHideIcons(dock
);
4047 dock
->auto_collapse_magic
= NULL
;
4050 static void clipAutoExpand(void *cdata
)
4052 WDock
*dock
= (WDock
*) cdata
;
4054 if (dock
->type
!= WM_CLIP
)
4057 if (dock
->auto_collapse
) {
4058 dock
->collapsed
= 0;
4059 wDockShowIcons(dock
);
4061 dock
->auto_expand_magic
= NULL
;
4064 static void clipAutoLower(void *cdata
)
4066 WDock
*dock
= (WDock
*) cdata
;
4068 if (dock
->type
!= WM_CLIP
)
4071 if (dock
->auto_raise_lower
)
4074 dock
->auto_lower_magic
= NULL
;
4077 static void clipAutoRaise(void *cdata
)
4079 WDock
*dock
= (WDock
*) cdata
;
4081 if (dock
->type
!= WM_CLIP
)
4084 if (dock
->auto_raise_lower
)
4087 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4088 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4091 dock
->auto_raise_magic
= NULL
;
4094 static Bool
iconCanBeOmnipresent(WAppIcon
* aicon
)
4096 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4101 for (i
= 0; i
< scr
->workspace_count
; i
++) {
4102 clip
= scr
->workspaces
[i
]->clip
;
4104 if (clip
== aicon
->dock
)
4107 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4108 return False
; /* Clip is full in some workspace */
4110 for (j
= 0; j
< clip
->max_icons
; j
++) {
4111 btn
= clip
->icon_array
[j
];
4112 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
4120 int wClipMakeIconOmnipresent(WAppIcon
* aicon
, int omnipresent
)
4122 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4123 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4124 int status
= WO_SUCCESS
;
4126 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== scr
->clip_icon
) {
4127 return WO_NOT_APPLICABLE
;
4130 if (aicon
->omnipresent
== omnipresent
)
4134 if (iconCanBeOmnipresent(aicon
)) {
4135 aicon
->omnipresent
= 1;
4136 new_entry
= wmalloc(sizeof(WAppIconChain
));
4137 new_entry
->aicon
= aicon
;
4138 new_entry
->next
= scr
->global_icons
;
4139 scr
->global_icons
= new_entry
;
4140 scr
->global_icon_count
++;
4142 aicon
->omnipresent
= 0;
4146 aicon
->omnipresent
= 0;
4147 if (aicon
== scr
->global_icons
->aicon
) {
4148 tmp
= scr
->global_icons
->next
;
4149 wfree(scr
->global_icons
);
4150 scr
->global_icons
= tmp
;
4151 scr
->global_icon_count
--;
4153 tmp
= scr
->global_icons
;
4155 if (tmp
->next
->aicon
== aicon
) {
4156 tmp1
= tmp
->next
->next
;
4159 scr
->global_icon_count
--;
4167 wAppIconPaint(aicon
);