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"
57 /**** Local variables ****/
60 #define CLIP_FORWARD 2
62 /**** Global variables ****/
65 extern void DestroyDockAppSettingsPanel();
67 extern void ShowDockAppSettingsPanel(WAppIcon
* aicon
);
69 extern XContext wWinContext
;
71 extern Cursor wCursor
[WCUR_LAST
];
73 extern WPreferences wPreferences
;
75 extern XContext wWinContext
;
77 #define MOD_MASK wPreferences.modifier_mask
79 extern void appIconMouseDown(WObjDescriptor
* desc
, XEvent
* event
);
81 #define ICON_SIZE wPreferences.icon_size
83 /***** Local variables ****/
85 static WMPropList
*dCommand
= NULL
;
86 static WMPropList
*dPasteCommand
= NULL
;
87 #ifdef XDND /* XXX was OFFIX */
88 static WMPropList
*dDropCommand
= NULL
;
90 static WMPropList
*dAutoLaunch
, *dLock
;
91 static WMPropList
*dName
, *dForced
, *dBuggyApplication
, *dYes
, *dNo
;
92 static WMPropList
*dHost
, *dDock
, *dClip
;
93 static WMPropList
*dAutoAttractIcons
;
95 static WMPropList
*dPosition
, *dApplications
, *dLowered
, *dCollapsed
;
97 static WMPropList
*dAutoCollapse
, *dAutoRaiseLower
, *dOmnipresent
;
99 static void dockIconPaint(WAppIcon
* btn
);
101 static void iconMouseDown(WObjDescriptor
* desc
, XEvent
* event
);
103 static pid_t
execCommand(WAppIcon
* btn
, char *command
, WSavedState
* state
);
105 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
* dock
);
107 static int getClipButton(int px
, int py
);
109 static void toggleLowered(WDock
* dock
);
111 static void toggleCollapsed(WDock
* dock
);
113 static void clipIconExpose(WObjDescriptor
* desc
, XEvent
* event
);
115 static void clipLeave(WDock
* dock
);
117 static void handleClipChangeWorkspace(WScreen
* scr
, XEvent
* event
);
119 Bool
moveIconBetweenDocks(WDock
* src
, WDock
* dest
, WAppIcon
* icon
, int x
, int y
);
121 static void clipEnterNotify(WObjDescriptor
* desc
, XEvent
* event
);
122 static void clipLeaveNotify(WObjDescriptor
* desc
, XEvent
* event
);
123 static void clipAutoCollapse(void *cdata
);
124 static void clipAutoExpand(void *cdata
);
125 static void launchDockedApplication(WAppIcon
* btn
, Bool withSelection
);
127 static void clipAutoLower(void *cdata
);
128 static void clipAutoRaise(void *cdata
);
130 static void showClipBalloon(WDock
* dock
, int workspace
);
132 static void make_keys()
134 if (dCommand
!= NULL
)
137 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
138 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
140 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
142 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
143 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
144 dName
= WMRetainPropList(WMCreatePLString("Name"));
145 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
146 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
147 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
148 dNo
= WMRetainPropList(WMCreatePLString("No"));
149 dHost
= WMRetainPropList(WMCreatePLString("Host"));
151 dPosition
= WMCreatePLString("Position");
152 dApplications
= WMCreatePLString("Applications");
153 dLowered
= WMCreatePLString("Lowered");
154 dCollapsed
= WMCreatePLString("Collapsed");
155 dAutoCollapse
= WMCreatePLString("AutoCollapse");
156 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
157 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
159 dOmnipresent
= WMCreatePLString("Omnipresent");
161 dDock
= WMCreatePLString("Dock");
162 dClip
= WMCreatePLString("Clip");
165 static void renameCallback(WMenu
* menu
, WMenuEntry
* entry
)
167 WDock
*dock
= entry
->clientdata
;
172 assert(entry
->clientdata
!= NULL
);
174 wspace
= dock
->screen_ptr
->current_workspace
;
176 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
178 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+ 1);
179 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
, &name
)) {
180 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
187 static void toggleLoweredCallback(WMenu
* menu
, WMenuEntry
* entry
)
189 assert(entry
->clientdata
!= NULL
);
191 toggleLowered(entry
->clientdata
);
193 entry
->flags
.indicator_on
= !(((WDock
*) entry
->clientdata
)->lowered
);
198 static int matchWindow(void *item
, void *cdata
)
200 return (((WFakeGroupLeader
*) item
)->leader
== (Window
) cdata
);
203 static void killCallback(WMenu
* menu
, WMenuEntry
* entry
)
205 WScreen
*scr
= menu
->menu
->screen_ptr
;
207 WFakeGroupLeader
*fPtr
;
208 char *buffer
, *shortname
, **argv
;
209 char *basename(const char *shortname
);
212 if (!WCHECK_STATE(WSTATE_NORMAL
))
215 assert(entry
->clientdata
!= NULL
);
217 icon
= (WAppIcon
*) entry
->clientdata
;
221 WCHANGE_STATE(WSTATE_MODAL
);
223 /* strip away dir names */
224 shortname
= basename(icon
->command
);
225 /* separate out command options */
226 wtokensplit(shortname
, &argv
, &argc
);
228 buffer
= wstrconcat(argv
[0],
229 _(" will be forcibly closed.\n"
230 "Any unsaved changes will be lost.\n" "Please confirm."));
232 if (icon
->icon
&& icon
->icon
->owner
) {
233 fPtr
= icon
->icon
->owner
->fake_group
;
235 /* is this really necessary? can we kill a non-running dock icon? */
236 Window win
= icon
->main_window
;
239 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)win
);
240 if (index
!= WANotFound
)
241 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
246 if (wPreferences
.dont_confirm_kill
247 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
248 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
250 WWindow
*wwin
, *twin
;
252 wwin
= scr
->focused_window
;
255 if (wwin
->fake_group
== fPtr
) {
260 } else if (icon
->icon
&& icon
->icon
->owner
) {
261 wClientKill(icon
->icon
->owner
);
266 wtokenfree(argv
, argc
);
270 WCHANGE_STATE(WSTATE_NORMAL
);
273 /* TODO: replace this function with a member of the dock struct */
274 static int numberOfSelectedIcons(WDock
* dock
)
280 for (i
= 1; i
< dock
->max_icons
; i
++) {
281 aicon
= dock
->icon_array
[i
];
282 if (aicon
&& aicon
->icon
->selected
) {
290 static WMArray
*getSelected(WDock
* dock
)
292 WMArray
*ret
= WMCreateArray(8);
296 for (i
= 1; i
< dock
->max_icons
; i
++) {
297 btn
= dock
->icon_array
[i
];
298 if (btn
&& btn
->icon
->selected
) {
299 WMAddToArray(ret
, btn
);
306 static void paintClipButtons(WAppIcon
* clipIcon
, Bool lpushed
, Bool rpushed
)
308 Window win
= clipIcon
->icon
->core
->window
;
309 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
311 int pt
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
312 int tp
= ICON_SIZE
- pt
;
313 int as
= pt
- 15; /* 15 = 5+5+5 */
314 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
316 #ifdef GRADIENT_CLIP_ARROW
317 Bool collapsed
= clipIcon
->dock
->collapsed
;
320 /*if (!clipIcon->dock->collapsed)
321 color = scr->clip_title_color[CLIP_NORMAL];
323 color = scr->clip_title_color[CLIP_COLLAPSED]; */
324 color
= scr
->clip_title_color
[CLIP_NORMAL
];
326 XSetForeground(dpy
, gc
, WMColorPixel(color
));
331 p
[1].x
= ICON_SIZE
- 2;
333 p
[2].x
= ICON_SIZE
- 2;
335 } else if (lpushed
) {
339 p
[1].y
= ICON_SIZE
- 2;
341 p
[2].y
= ICON_SIZE
- 2;
343 if (lpushed
|| rpushed
) {
344 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
345 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
346 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
348 #ifdef GRADIENT_CLIP_ARROW
350 XSetFillStyle(dpy
, scr
->copy_gc
, FillTiled
);
351 XSetTile(dpy
, scr
->copy_gc
, scr
->clip_arrow_gradient
);
352 XSetClipMask(dpy
, scr
->copy_gc
, None
);
355 #endif /* GRADIENT_CLIP_ARROW */
357 /* top right arrow */
358 p
[0].x
= p
[3].x
= ICON_SIZE
- 5 - as
;
360 p
[1].x
= ICON_SIZE
- 6;
362 p
[2].x
= ICON_SIZE
- 6;
365 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
366 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
368 #ifdef GRADIENT_CLIP_ARROW
370 XSetTSOrigin(dpy
, gc
, ICON_SIZE
- 6 - as
, 5);
372 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
373 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
376 /* bottom left arrow */
378 p
[0].y
= p
[3].y
= ICON_SIZE
- 5 - as
;
380 p
[1].y
= ICON_SIZE
- 6;
382 p
[2].y
= ICON_SIZE
- 6;
384 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
385 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
387 #ifdef GRADIENT_CLIP_ARROW
389 XSetTSOrigin(dpy
, gc
, 5, ICON_SIZE
- 6 - as
);
391 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
392 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
394 #ifdef GRADIENT_CLIP_ARROW
396 XSetFillStyle(dpy
, scr
->copy_gc
, FillSolid
);
400 RImage
*wClipMakeTile(WScreen
* scr
, RImage
* normalTile
)
402 RImage
*tile
= RCloneImage(normalTile
);
409 pt
= CLIP_BUTTON_SIZE
* wPreferences
.icon_size
/ 64;
410 tp
= wPreferences
.icon_size
- 1 - pt
;
414 black
.red
= black
.green
= black
.blue
= 0;
417 dark
.red
= dark
.green
= dark
.blue
= 60;
420 light
.red
= light
.green
= light
.blue
= 80;
423 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
- 2, pt
- 1, &dark
);
424 RDrawLine(tile
, tp
- 1, 0, wPreferences
.icon_size
- 1, pt
+ 1, &black
);
425 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
- 3, pt
, &light
);
428 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, 4, &dark
);
429 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 5, 6 + as
, &dark
);
430 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
, &light
);
433 ROperateLine(tile
, RAddOperation
, 2, tp
+ 2, pt
- 2, wPreferences
.icon_size
- 3, &dark
);
434 RDrawLine(tile
, 0, tp
- 1, pt
+ 1, wPreferences
.icon_size
- 1, &black
);
435 ROperateLine(tile
, RSubtractOperation
, 0, tp
- 2, pt
+ 1, wPreferences
.icon_size
- 2, &light
);
438 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, &dark
);
439 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
, 6 + as
, ICON_SIZE
- 5, &dark
);
440 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5, &light
);
445 static void omnipresentCallback(WMenu
* menu
, WMenuEntry
* entry
)
447 WAppIcon
*clickedIcon
= entry
->clientdata
;
450 WMArray
*selectedIcons
;
451 WMArrayIterator iter
;
454 assert(entry
->clientdata
!= NULL
);
456 dock
= clickedIcon
->dock
;
458 selectedIcons
= getSelected(dock
);
460 if (!WMGetArrayItemCount(selectedIcons
))
461 WMAddToArray(selectedIcons
, clickedIcon
);
464 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
465 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
467 else if (aicon
->icon
->selected
)
468 wIconSelect(aicon
->icon
);
470 WMFreeArray(selectedIcons
);
473 wMessageDialog(dock
->screen_ptr
, _("Warning"),
474 _("Some icons cannot be made omnipresent. "
475 "Please make sure that no other icon is "
476 "docked in the same positions on the other "
477 "workspaces and the Clip is not full in "
478 "some workspace."), _("OK"), NULL
, NULL
);
479 } else if (failed
== 1) {
480 wMessageDialog(dock
->screen_ptr
, _("Warning"),
481 _("Icon cannot be made omnipresent. "
482 "Please make sure that no other icon is "
483 "docked in the same position on the other "
484 "workspaces and the Clip is not full in "
485 "some workspace."), _("OK"), NULL
, NULL
);
489 static void removeIconsCallback(WMenu
* menu
, WMenuEntry
* entry
)
491 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
494 WMArray
*selectedIcons
;
498 assert(clickedIcon
!= NULL
);
500 dock
= clickedIcon
->dock
;
502 selectedIcons
= getSelected(dock
);
504 if (WMGetArrayItemCount(selectedIcons
)) {
505 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
506 _("All selected icons will be removed!"),
507 _("OK"), _("Cancel"), NULL
) != WAPRDefault
) {
508 WMFreeArray(selectedIcons
);
512 if (clickedIcon
->xindex
== 0 && clickedIcon
->yindex
== 0) {
513 WMFreeArray(selectedIcons
);
516 WMAddToArray(selectedIcons
, clickedIcon
);
519 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
520 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
521 wDockDetach(dock
, aicon
);
523 /* XXX: can: aicon->icon == NULL ? */
524 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
525 wGetHeadForWindow(aicon
->icon
->owner
));
526 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
527 if (!dock
->mapped
|| dock
->collapsed
)
528 XMapWindow(dpy
, aicon
->icon
->core
->window
);
531 WMFreeArray(selectedIcons
);
533 if (wPreferences
.auto_arrange_icons
)
534 wArrangeIcons(dock
->screen_ptr
, True
);
537 static void keepIconsCallback(WMenu
* menu
, WMenuEntry
* entry
)
539 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
542 WMArray
*selectedIcons
;
545 assert(clickedIcon
!= NULL
);
546 dock
= clickedIcon
->dock
;
548 selectedIcons
= getSelected(dock
);
550 if (!WMGetArrayItemCount(selectedIcons
)
551 && clickedIcon
!= dock
->screen_ptr
->clip_icon
) {
552 char *command
= NULL
;
554 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
555 clickedIcon
->editing
= 1;
556 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
557 _("Type the command used to launch the application"), &command
)) {
558 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
562 clickedIcon
->command
= command
;
563 clickedIcon
->editing
= 0;
565 clickedIcon
->editing
= 0;
568 WMFreeArray(selectedIcons
);
573 WMAddToArray(selectedIcons
, clickedIcon
);
576 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
577 if (aicon
->icon
->selected
)
578 wIconSelect(aicon
->icon
);
579 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
580 aicon
->attracted
= 0;
581 if (aicon
->icon
->shadowed
) {
582 aicon
->icon
->shadowed
= 0;
583 aicon
->icon
->force_paint
= 1;
584 wAppIconPaint(aicon
);
588 WMFreeArray(selectedIcons
);
591 static void toggleAutoAttractCallback(WMenu
* menu
, WMenuEntry
* entry
)
593 WDock
*dock
= (WDock
*) entry
->clientdata
;
595 assert(entry
->clientdata
!= NULL
);
597 dock
->attract_icons
= !dock
->attract_icons
;
598 /*if (!dock->attract_icons)
599 dock->keep_attracted = 0; */
601 entry
->flags
.indicator_on
= dock
->attract_icons
;
606 static void selectCallback(WMenu
* menu
, WMenuEntry
* entry
)
608 WAppIcon
*icon
= (WAppIcon
*) entry
->clientdata
;
610 assert(icon
!= NULL
);
612 wIconSelect(icon
->icon
);
617 static void colectIconsCallback(WMenu
* menu
, WMenuEntry
* entry
)
619 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
622 int x
, y
, x_pos
, y_pos
;
624 assert(entry
->clientdata
!= NULL
);
625 clip
= clickedIcon
->dock
;
627 aicon
= clip
->screen_ptr
->app_icon_list
;
630 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
631 x_pos
= clip
->x_pos
+ x
* ICON_SIZE
;
632 y_pos
= clip
->y_pos
+ y
* ICON_SIZE
;
633 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
635 if (wPreferences
.no_animations
) {
636 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
638 SlideWindow(aicon
->icon
->core
->window
,
639 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
642 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
643 #endif /* ANIMATIONS */
645 aicon
->attracted
= 1;
646 if (!aicon
->icon
->shadowed
) {
647 aicon
->icon
->shadowed
= 1;
648 aicon
->icon
->force_paint
= 1;
649 /* We don't do an wAppIconPaint() here because it's in
650 * wDockAttachIcon(). -Dan
653 wDockAttachIcon(clip
, aicon
, x
, y
);
654 if (clip
->collapsed
|| !clip
->mapped
)
655 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
661 static void selectIconsCallback(WMenu
* menu
, WMenuEntry
* entry
)
663 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
665 WMArray
*selectedIcons
;
666 WMArrayIterator iter
;
670 assert(clickedIcon
!= NULL
);
671 dock
= clickedIcon
->dock
;
673 selectedIcons
= getSelected(dock
);
675 if (!WMGetArrayItemCount(selectedIcons
)) {
676 for (i
= 1; i
< dock
->max_icons
; i
++) {
677 btn
= dock
->icon_array
[i
];
678 if (btn
&& !btn
->icon
->selected
) {
679 wIconSelect(btn
->icon
);
683 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
684 wIconSelect(btn
->icon
);
687 WMFreeArray(selectedIcons
);
692 static void toggleCollapsedCallback(WMenu
* menu
, WMenuEntry
* entry
)
694 assert(entry
->clientdata
!= NULL
);
696 toggleCollapsed(entry
->clientdata
);
698 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->collapsed
;
703 static void toggleAutoCollapseCallback(WMenu
* menu
, WMenuEntry
* entry
)
706 assert(entry
->clientdata
!= NULL
);
708 dock
= (WDock
*) entry
->clientdata
;
710 dock
->auto_collapse
= !dock
->auto_collapse
;
712 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_collapse
;
717 static void toggleAutoRaiseLowerCallback(WMenu
* menu
, WMenuEntry
* entry
)
720 assert(entry
->clientdata
!= NULL
);
722 dock
= (WDock
*) entry
->clientdata
;
724 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
726 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_raise_lower
;
731 static void launchCallback(WMenu
* menu
, WMenuEntry
* entry
)
733 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
735 launchDockedApplication(btn
, False
);
738 static void settingsCallback(WMenu
* menu
, WMenuEntry
* entry
)
740 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
744 ShowDockAppSettingsPanel(btn
);
747 static void hideCallback(WMenu
* menu
, WMenuEntry
* entry
)
750 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
752 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
754 if (wapp
->flags
.hidden
) {
755 wWorkspaceChange(btn
->icon
->core
->screen_ptr
, wapp
->last_workspace
);
756 wUnhideApplication(wapp
, False
, False
);
758 wHideApplication(wapp
);
762 static void unhideHereCallback(WMenu
* menu
, WMenuEntry
* entry
)
765 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
767 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
769 wUnhideApplication(wapp
, False
, True
);
772 WAppIcon
*mainIconCreate(WScreen
* scr
, int type
)
777 if (type
== WM_CLIP
) {
779 return scr
->clip_icon
;
780 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
781 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
782 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
783 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
784 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE; */
787 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
788 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
794 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
795 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
796 btn
->icon
->core
->descriptor
.parent
= btn
;
797 /*ChangeStackingLevel(btn->icon->core, WMDockLevel); */
798 XMapWindow(dpy
, btn
->icon
->core
->window
);
803 scr
->clip_icon
= btn
;
808 static void switchWSCommand(WMenu
* menu
, WMenuEntry
* entry
)
810 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
811 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
813 WMArray
*selectedIcons
;
816 if (entry
->order
== scr
->current_workspace
)
819 dest
= scr
->workspaces
[entry
->order
]->clip
;
821 selectedIcons
= getSelected(src
);
823 if (WMGetArrayItemCount(selectedIcons
)) {
824 WMArrayIterator iter
;
826 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
827 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
828 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
829 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
832 } else if (icon
!= scr
->clip_icon
) {
833 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
834 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
835 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
838 WMFreeArray(selectedIcons
);
841 static void launchDockedApplication(WAppIcon
* btn
, Bool withSelection
)
843 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
845 if (!btn
->launching
&&
846 ((!withSelection
&& btn
->command
!= NULL
) || (withSelection
&& btn
->paste_command
!= NULL
))) {
847 if (!btn
->forced_dock
) {
848 btn
->relaunching
= btn
->running
;
851 if (btn
->wm_instance
|| btn
->wm_class
) {
852 WWindowAttributes attr
;
853 memset(&attr
, 0, sizeof(WWindowAttributes
));
854 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
856 if (!attr
.no_appicon
&& !btn
->buggy_app
)
861 btn
->drop_launch
= 0;
862 btn
->paste_launch
= withSelection
;
863 scr
->last_dock
= btn
->dock
;
864 btn
->pid
= execCommand(btn
, (withSelection
? btn
->paste_command
: btn
->command
), NULL
);
866 if (btn
->buggy_app
) {
867 /* give feedback that the app was launched */
871 WMAddTimerHandler(200, (WMCallback
*) dockIconPaint
, btn
);
876 wwarning(_("could not launch application %s\n"), btn
->command
);
878 if (!btn
->relaunching
) {
885 static void updateWorkspaceMenu(WMenu
* menu
, WAppIcon
* icon
)
887 WScreen
*scr
= menu
->frame
->screen_ptr
;
888 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
894 for (i
= 0; i
< scr
->workspace_count
; i
++) {
895 if (i
< menu
->entry_no
) {
896 if (strcmp(menu
->entries
[i
]->text
, scr
->workspaces
[i
]->name
) != 0) {
897 wfree(menu
->entries
[i
]->text
);
898 strcpy(title
, scr
->workspaces
[i
]->name
);
899 menu
->entries
[i
]->text
= wstrdup(title
);
900 menu
->flags
.realized
= 0;
902 menu
->entries
[i
]->clientdata
= (void *)icon
;
904 strcpy(title
, scr
->workspaces
[i
]->name
);
906 wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)icon
);
908 menu
->flags
.realized
= 0;
910 if (i
== scr
->current_workspace
) {
911 wMenuSetEnabled(menu
, i
, False
);
913 wMenuSetEnabled(menu
, i
, True
);
917 if (!menu
->flags
.realized
)
921 static WMenu
*makeWorkspaceMenu(WScreen
* scr
)
925 menu
= wMenuCreate(scr
, NULL
, False
);
927 wwarning(_("could not create workspace submenu for Clip menu"));
929 wMenuAddCallback(menu
, "", switchWSCommand
, (void *)scr
->clip_icon
);
931 menu
->flags
.realized
= 0;
937 static void updateClipOptionsMenu(WMenu
* menu
, WDock
* dock
)
946 entry
= menu
->entries
[index
];
947 entry
->flags
.indicator_on
= !dock
->lowered
;
948 entry
->clientdata
= dock
;
951 entry
= menu
->entries
[++index
];
952 entry
->flags
.indicator_on
= dock
->collapsed
;
953 entry
->clientdata
= dock
;
956 entry
= menu
->entries
[++index
];
957 entry
->flags
.indicator_on
= dock
->auto_collapse
;
958 entry
->clientdata
= dock
;
960 /* auto-raise/lower */
961 entry
= menu
->entries
[++index
];
962 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
963 entry
->clientdata
= dock
;
964 wMenuSetEnabled(menu
, index
, dock
->lowered
);
967 entry
= menu
->entries
[++index
];
968 entry
->flags
.indicator_on
= dock
->attract_icons
;
969 entry
->clientdata
= dock
;
971 menu
->flags
.realized
= 0;
975 static WMenu
*makeClipOptionsMenu(WScreen
* scr
)
980 menu
= wMenuCreate(scr
, NULL
, False
);
982 wwarning(_("could not create options submenu for Clip menu"));
986 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
987 entry
->flags
.indicator
= 1;
988 entry
->flags
.indicator_on
= 1;
989 entry
->flags
.indicator_type
= MI_CHECK
;
991 entry
= wMenuAddCallback(menu
, _("Collapsed"), toggleCollapsedCallback
, NULL
);
992 entry
->flags
.indicator
= 1;
993 entry
->flags
.indicator_on
= 1;
994 entry
->flags
.indicator_type
= MI_CHECK
;
996 entry
= wMenuAddCallback(menu
, _("Autocollapse"), toggleAutoCollapseCallback
, NULL
);
997 entry
->flags
.indicator
= 1;
998 entry
->flags
.indicator_on
= 1;
999 entry
->flags
.indicator_type
= MI_CHECK
;
1001 entry
= wMenuAddCallback(menu
, _("Autoraise"), toggleAutoRaiseLowerCallback
, NULL
);
1002 entry
->flags
.indicator
= 1;
1003 entry
->flags
.indicator_on
= 1;
1004 entry
->flags
.indicator_type
= MI_CHECK
;
1006 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"), toggleAutoAttractCallback
, NULL
);
1007 entry
->flags
.indicator
= 1;
1008 entry
->flags
.indicator_on
= 1;
1009 entry
->flags
.indicator_type
= MI_CHECK
;
1011 menu
->flags
.realized
= 0;
1017 static WMenu
*dockMenuCreate(WScreen
* scr
, int type
)
1022 if (type
== WM_CLIP
&& scr
->clip_menu
)
1023 return scr
->clip_menu
;
1025 menu
= wMenuCreate(scr
, NULL
, False
);
1026 if (type
!= WM_CLIP
) {
1027 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
1028 entry
->flags
.indicator
= 1;
1029 entry
->flags
.indicator_on
= 1;
1030 entry
->flags
.indicator_type
= MI_CHECK
;
1032 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1033 scr
->clip_options
= makeClipOptionsMenu(scr
);
1034 if (scr
->clip_options
)
1035 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1037 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1039 entry
->text
= _("Rename Workspace");
1041 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1042 entry
->flags
.indicator
= 1;
1043 entry
->flags
.indicator_on
= 1;
1044 entry
->flags
.indicator_type
= MI_CHECK
;
1046 entry
= wMenuAddCallback(menu
, _("Select All Icons"), selectIconsCallback
, NULL
);
1048 entry
->text
= _("Select All Icons");
1050 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1052 entry
->text
= _("Keep Icon");
1054 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1056 entry
->text
= _("Move Icon To");
1057 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1058 if (scr
->clip_submenu
)
1059 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1061 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
, NULL
);
1063 entry
->text
= _("Remove Icon");
1065 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1068 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1070 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1072 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1074 entry
->text
= _("Hide");
1076 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1078 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1080 if (type
== WM_CLIP
)
1081 scr
->clip_menu
= menu
;
1086 WDock
*wDockCreate(WScreen
* scr
, int type
)
1094 dock
= wmalloc(sizeof(WDock
));
1095 memset(dock
, 0, sizeof(WDock
));
1097 if (type
== WM_CLIP
)
1098 icon_count
= CLIP_MAX_ICONS
;
1100 icon_count
= scr
->scr_height
/ wPreferences
.icon_size
;
1102 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * icon_count
);
1103 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*) * icon_count
);
1105 dock
->max_icons
= icon_count
;
1107 btn
= mainIconCreate(scr
, type
);
1111 dock
->x_pos
= btn
->x_pos
;
1112 dock
->y_pos
= btn
->y_pos
;
1113 dock
->screen_ptr
= scr
;
1115 dock
->icon_count
= 1;
1116 dock
->on_right_side
= 1;
1117 dock
->collapsed
= 0;
1118 dock
->auto_collapse
= 0;
1119 dock
->auto_collapse_magic
= NULL
;
1120 dock
->auto_raise_lower
= 0;
1121 dock
->auto_lower_magic
= NULL
;
1122 dock
->auto_raise_magic
= NULL
;
1123 dock
->attract_icons
= 0;
1125 dock
->icon_array
[0] = btn
;
1126 wRaiseFrame(btn
->icon
->core
);
1127 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1129 /* create dock menu */
1130 dock
->menu
= dockMenuCreate(scr
, type
);
1135 void wDockDestroy(WDock
* dock
)
1140 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1141 aicon
= dock
->icon_array
[i
];
1143 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1144 wDockDetach(dock
, aicon
);
1146 /* XXX: can: aicon->icon == NULL ? */
1147 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1148 wGetHeadForWindow(aicon
->icon
->owner
));
1149 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1150 if (!dock
->mapped
|| dock
->collapsed
)
1151 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1155 if (wPreferences
.auto_arrange_icons
)
1156 wArrangeIcons(dock
->screen_ptr
, True
);
1157 wfree(dock
->icon_array
);
1158 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1159 wMenuDestroy(dock
->menu
, True
);
1160 if (dock
->screen_ptr
->last_dock
== dock
)
1161 dock
->screen_ptr
->last_dock
= NULL
;
1165 void wClipIconPaint(WAppIcon
* aicon
)
1167 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1168 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1170 Window win
= aicon
->icon
->core
->window
;
1171 int length
, nlength
;
1172 char *ws_name
, ws_number
[10];
1175 wIconPaint(aicon
->icon
);
1177 length
= strlen(workspace
->name
);
1178 ws_name
= wmalloc(length
+ 1);
1179 snprintf(ws_name
, length
+ 1, "%s", workspace
->name
);
1180 snprintf(ws_number
, sizeof(ws_number
), "%i", scr
->current_workspace
+ 1);
1181 nlength
= strlen(ws_number
);
1183 if (!workspace
->clip
->collapsed
)
1184 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1186 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1188 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1190 tx
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
1192 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, ty
, ws_name
, length
);
1193 /*WMDrawString(scr->wmscreen, win, color, scr->clip_title_font, 4,
1194 2, ws_name, length); */
1196 tx
= (ICON_SIZE
/ 2 - WMWidthOfString(scr
->clip_title_font
, ws_number
, nlength
)) / 2;
1198 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, 2, ws_number
, nlength
);
1202 if (aicon
->launching
) {
1203 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1204 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1206 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
, aicon
->dock
->rclip_button_pushed
);
1209 static void clipIconExpose(WObjDescriptor
* desc
, XEvent
* event
)
1211 wClipIconPaint(desc
->parent
);
1214 static void dockIconPaint(WAppIcon
* btn
)
1216 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1217 wClipIconPaint(btn
);
1222 static WMPropList
*make_icon_state(WAppIcon
* btn
)
1224 WMPropList
*node
= NULL
;
1225 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
, *host
;
1226 WMPropList
*position
, *buggy
, *omnipresent
;
1232 command
= WMCreatePLString("-");
1234 command
= WMCreatePLString(btn
->command
);
1236 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1238 lock
= btn
->lock
? dYes
: dNo
;
1240 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1242 name
= WMCreatePLString(tmp
);
1246 forced
= btn
->forced_dock
? dYes
: dNo
;
1248 buggy
= btn
->buggy_app
? dYes
: dNo
;
1250 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1251 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1253 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1254 position
= WMCreatePLString(buffer
);
1256 node
= WMCreatePLDictionary(dCommand
, command
,
1258 dAutoLaunch
, autolaunch
,
1260 dForced
, forced
, dBuggyApplication
, buggy
, dPosition
, position
, NULL
);
1261 WMReleasePropList(command
);
1262 WMReleasePropList(name
);
1263 WMReleasePropList(position
);
1265 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1266 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&& (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1267 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1269 #ifdef XDND /* was OFFIX */
1270 if (btn
->dnd_command
) {
1271 command
= WMCreatePLString(btn
->dnd_command
);
1272 WMPutInPLDictionary(node
, dDropCommand
, command
);
1273 WMReleasePropList(command
);
1277 if (btn
->paste_command
) {
1278 command
= WMCreatePLString(btn
->paste_command
);
1279 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1280 WMReleasePropList(command
);
1283 if (btn
->client_machine
&& btn
->remote_start
) {
1284 host
= WMCreatePLString(btn
->client_machine
);
1285 WMPutInPLDictionary(node
, dHost
, host
);
1286 WMReleasePropList(host
);
1293 static WMPropList
*dockSaveState(WDock
* dock
)
1296 WMPropList
*icon_info
;
1297 WMPropList
*list
= NULL
, *dock_state
= NULL
;
1298 WMPropList
*value
, *key
;
1301 list
= WMCreatePLArray(NULL
);
1303 for (i
= (dock
->type
== WM_DOCK
? 0 : 1); i
< dock
->max_icons
; i
++) {
1304 WAppIcon
*btn
= dock
->icon_array
[i
];
1306 if (!btn
|| btn
->attracted
)
1309 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1310 WMAddToPLArray(list
, icon_info
);
1311 WMReleasePropList(icon_info
);
1315 dock_state
= WMCreatePLDictionary(dApplications
, list
, NULL
);
1317 if (dock
->type
== WM_DOCK
) {
1318 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1319 key
= WMCreatePLString(buffer
);
1320 WMPutInPLDictionary(dock_state
, key
, list
);
1321 WMReleasePropList(key
);
1323 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0), dock
->y_pos
);
1324 value
= WMCreatePLString(buffer
);
1325 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1326 WMReleasePropList(value
);
1328 WMReleasePropList(list
);
1330 value
= (dock
->lowered
? dYes
: dNo
);
1331 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1333 if (dock
->type
== WM_CLIP
) {
1334 value
= (dock
->collapsed
? dYes
: dNo
);
1335 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1337 value
= (dock
->auto_collapse
? dYes
: dNo
);
1338 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1340 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1341 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1343 value
= (dock
->attract_icons
? dYes
: dNo
);
1344 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1350 void wDockSaveState(WScreen
* scr
, WMPropList
* old_state
)
1352 WMPropList
*dock_state
;
1355 dock_state
= dockSaveState(scr
->dock
);
1358 * Copy saved states of docks with different sizes.
1364 keys
= WMGetPLDictionaryKeys(old_state
);
1365 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1366 tmp
= WMGetFromPLArray(keys
, i
);
1368 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1369 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1371 WMPutInPLDictionary(dock_state
, tmp
, WMGetFromPLDictionary(old_state
, tmp
));
1374 WMReleasePropList(keys
);
1377 WMPutInPLDictionary(scr
->session_state
, dDock
, dock_state
);
1379 WMReleasePropList(dock_state
);
1382 void wClipSaveState(WScreen
* scr
)
1384 WMPropList
*clip_state
;
1386 clip_state
= make_icon_state(scr
->clip_icon
);
1388 WMPutInPLDictionary(scr
->session_state
, dClip
, clip_state
);
1390 WMReleasePropList(clip_state
);
1393 WMPropList
*wClipSaveWorkspaceState(WScreen
* scr
, int workspace
)
1395 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1398 static Bool
getBooleanDockValue(WMPropList
* value
, WMPropList
* key
)
1401 if (WMIsPLString(value
)) {
1402 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1405 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1411 static WAppIcon
*restore_icon_state(WScreen
* scr
, WMPropList
* info
, int type
, int index
)
1414 WMPropList
*cmd
, *value
;
1416 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1417 if (!cmd
|| !WMIsPLString(cmd
)) {
1421 /* parse window name */
1422 value
= WMGetFromPLDictionary(info
, dName
);
1427 char *wclass
, *winstance
;
1430 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1432 if (!winstance
&& !wclass
) {
1439 command
= wstrdup(WMGetFromPLString(cmd
));
1443 if (!command
|| strcmp(command
, "-") == 0) {
1454 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1463 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1464 if (type
== WM_CLIP
) {
1465 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1466 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1468 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1469 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1471 #ifdef XDND /* was OFFIX */
1472 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1474 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1477 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1479 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1481 /* check auto launch */
1482 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1484 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1487 value
= WMGetFromPLDictionary(info
, dLock
);
1489 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1491 /* check if it wasn't normally docked */
1492 value
= WMGetFromPLDictionary(info
, dForced
);
1494 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1496 /* check if we can rely on the stuff in the app */
1497 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1499 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1501 /* get position in the dock */
1502 value
= WMGetFromPLDictionary(info
, dPosition
);
1503 if (value
&& WMIsPLString(value
)) {
1504 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1505 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1507 /* check position sanity */
1508 /* incomplete section! */
1509 if (type
== WM_DOCK
) {
1511 if (aicon
->yindex
< 0)
1512 wwarning(_("bad value in docked icon position %i,%i"),
1513 aicon
->xindex
, aicon
->yindex
);
1516 aicon
->yindex
= index
;
1520 /* check if icon is omnipresent */
1521 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1523 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1531 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1533 WAppIcon
*wClipRestoreState(WScreen
* scr
, WMPropList
* clip_state
)
1538 icon
= mainIconCreate(scr
, WM_CLIP
);
1543 WMRetainPropList(clip_state
);
1545 /* restore position */
1547 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1550 if (!WMIsPLString(value
))
1551 COMPLAIN("Position");
1556 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1557 COMPLAIN("Position");
1559 /* check position sanity */
1560 rect
.pos
.x
= icon
->x_pos
;
1561 rect
.pos
.y
= icon
->y_pos
;
1562 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1564 wGetRectPlacementInfo(scr
, rect
, &flags
);
1565 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
1566 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1569 #ifdef XDND /* was OFFIX */
1570 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1571 if (value
&& WMIsPLString(value
))
1572 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1575 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1576 if (value
&& WMIsPLString(value
))
1577 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1579 WMReleasePropList(clip_state
);
1584 WDock
*wDockRestoreState(WScreen
* scr
, WMPropList
* dock_state
, int type
)
1589 WAppIcon
*aicon
, *old_top
;
1592 dock
= wDockCreate(scr
, type
);
1597 WMRetainPropList(dock_state
);
1599 /* restore position */
1601 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1604 if (!WMIsPLString(value
)) {
1605 COMPLAIN("Position");
1610 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1611 COMPLAIN("Position");
1613 /* check position sanity */
1614 rect
.pos
.x
= dock
->x_pos
;
1615 rect
.pos
.y
= dock
->y_pos
;
1616 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1618 wGetRectPlacementInfo(scr
, rect
, &flags
);
1619 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
)) {
1620 int x
= dock
->x_pos
;
1621 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1624 /* Is this needed any more? */
1625 if (type
== WM_CLIP
) {
1626 if (dock
->x_pos
< 0) {
1628 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1629 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1632 if (dock
->x_pos
>= 0) {
1633 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1634 dock
->on_right_side
= 0;
1636 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1637 dock
->on_right_side
= 1;
1643 /* restore lowered/raised state */
1647 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1650 if (!WMIsPLString(value
)) {
1651 COMPLAIN("Lowered");
1653 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1659 /* restore collapsed state */
1661 dock
->collapsed
= 0;
1663 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1666 if (!WMIsPLString(value
)) {
1667 COMPLAIN("Collapsed");
1669 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1670 dock
->collapsed
= 1;
1675 /* restore auto-collapsed state */
1677 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1680 if (!WMIsPLString(value
)) {
1681 COMPLAIN("AutoCollapse");
1683 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1684 dock
->auto_collapse
= 1;
1685 dock
->collapsed
= 1;
1690 /* restore auto-raise/lower state */
1692 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1695 if (!WMIsPLString(value
)) {
1696 COMPLAIN("AutoRaiseLower");
1698 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1699 dock
->auto_raise_lower
= 1;
1704 /* restore attract icons state */
1706 dock
->attract_icons
= 0;
1708 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1711 if (!WMIsPLString(value
)) {
1712 COMPLAIN("AutoAttractIcons");
1714 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1715 dock
->attract_icons
= 1;
1720 /* application list */
1727 * When saving, it saves the dock state in
1728 * Applications and Applicationsnnn
1730 * When loading, it will first try Applicationsnnn.
1731 * If it does not exist, use Applications as default.
1734 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1736 tmp
= WMCreatePLString(buffer
);
1737 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1738 WMReleasePropList(tmp
);
1741 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1749 count
= WMGetPropListItemCount(apps
);
1754 old_top
= dock
->icon_array
[0];
1756 /* dock->icon_count is set to 1 when dock is created.
1757 * Since Clip is already restored, we want to keep it so for clip,
1758 * but for dock we may change the default top tile, so we set it to 0.
1760 if (type
== WM_DOCK
)
1761 dock
->icon_count
= 0;
1763 for (i
= 0; i
< count
; i
++) {
1764 if (dock
->icon_count
>= dock
->max_icons
) {
1765 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1769 value
= WMGetFromPLArray(apps
, i
);
1770 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1772 dock
->icon_array
[dock
->icon_count
] = aicon
;
1776 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1777 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1780 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1782 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1784 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1786 if (!dock
->collapsed
)
1787 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1788 wRaiseFrame(aicon
->icon
->core
);
1791 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
)
1795 /* if the first icon is not defined, use the default */
1796 if (dock
->icon_array
[0] == NULL
) {
1797 /* update default icon */
1798 old_top
->x_pos
= dock
->x_pos
;
1799 old_top
->y_pos
= dock
->y_pos
;
1801 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1803 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1804 dock
->icon_array
[0] = old_top
;
1805 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1806 /* we don't need to increment dock->icon_count here because it was
1807 * incremented in the loop above.
1809 } else if (old_top
!= dock
->icon_array
[0]) {
1810 if (old_top
== scr
->clip_icon
)
1811 scr
->clip_icon
= dock
->icon_array
[0];
1812 wAppIconDestroy(old_top
);
1816 WMReleasePropList(dock_state
);
1821 void wDockLaunchWithState(WDock
* dock
, WAppIcon
* btn
, WSavedState
* state
)
1823 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1825 btn
->drop_launch
= 0;
1826 btn
->paste_launch
= 0;
1828 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1831 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1841 void wDockDoAutoLaunch(WDock
* dock
, int workspace
)
1847 for (i
= 0; i
< dock
->max_icons
; i
++) {
1848 btn
= dock
->icon_array
[i
];
1849 if (!btn
|| !btn
->auto_launch
)
1852 state
= wmalloc(sizeof(WSavedState
));
1853 memset(state
, 0, sizeof(WSavedState
));
1854 state
->workspace
= workspace
;
1855 /* TODO: this is klugy and is very difficult to understand
1856 * what's going on. Try to clean up */
1857 wDockLaunchWithState(dock
, btn
, state
);
1861 #ifdef XDND /* was OFFIX */
1862 static WDock
*findDock(WScreen
* scr
, XEvent
* event
, int *icon_pos
)
1868 if ((dock
= scr
->dock
) != NULL
) {
1869 for (i
= 0; i
< dock
->max_icons
; i
++) {
1870 if (dock
->icon_array
[i
]
1871 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1877 if (*icon_pos
< 0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
) != NULL
) {
1878 for (i
= 0; i
< dock
->max_icons
; i
++) {
1879 if (dock
->icon_array
[i
]
1880 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1891 int wDockReceiveDNDDrop(WScreen
* scr
, XEvent
* event
)
1897 dock
= findDock(scr
, event
, &icon_pos
);
1902 * Return True if the drop was on an application icon window.
1903 * In this case, let the ClientMessage handler redirect the
1904 * message to the app.
1906 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
1909 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
1910 scr
->flags
.dnd_data_convertion_status
= 0;
1912 btn
= dock
->icon_array
[icon_pos
];
1914 if (!btn
->forced_dock
) {
1915 btn
->relaunching
= btn
->running
;
1918 if (btn
->wm_instance
|| btn
->wm_class
) {
1919 WWindowAttributes attr
;
1920 memset(&attr
, 0, sizeof(WWindowAttributes
));
1921 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
1922 btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
1924 if (!attr
.no_appicon
)
1930 btn
->paste_launch
= 0;
1931 btn
->drop_launch
= 1;
1932 scr
->last_dock
= dock
;
1933 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1938 if (!btn
->relaunching
) {
1947 Bool
wDockAttachIcon(WDock
* dock
, WAppIcon
* icon
, int x
, int y
)
1952 wwin
= icon
->icon
->owner
;
1953 if (icon
->command
== NULL
) {
1958 command
= GetCommandForWindow(wwin
->client_win
);
1960 icon
->command
= command
;
1962 /* icon->forced_dock = 1; */
1963 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
1965 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
1966 _("Type the command used to launch the application"), &command
)) {
1967 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
1971 icon
->command
= command
;
1977 /* If the target is the dock, reject the icon. If
1978 * the target is the clip, make it an attracted icon
1980 if (dock
->type
== WM_CLIP
) {
1981 icon
->attracted
= 1;
1982 if (!icon
->icon
->shadowed
) {
1983 icon
->icon
->shadowed
= 1;
1984 icon
->icon
->force_paint
= 1;
1996 for (index
= 1; index
< dock
->max_icons
; index
++)
1997 if (dock
->icon_array
[index
] == NULL
)
1999 /* if (index == dock->max_icons)
2002 assert(index
< dock
->max_icons
);
2004 dock
->icon_array
[index
] = icon
;
2008 icon
->omnipresent
= 0;
2010 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2011 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2016 icon
->launching
= 0;
2019 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2020 if (dock
->type
== WM_CLIP
) {
2021 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2022 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2024 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2025 icon
->icon
->core
->descriptor
.parent
= icon
;
2027 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2028 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2029 wAppIconPaint(icon
);
2031 if (wPreferences
.auto_arrange_icons
)
2032 wArrangeIcons(dock
->screen_ptr
, True
);
2034 #ifdef XDND /* was OFFIX */
2035 if (icon
->command
&& !icon
->dnd_command
) {
2036 int len
= strlen(icon
->command
) + 8;
2037 icon
->dnd_command
= wmalloc(len
);
2038 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
2042 if (icon
->command
&& !icon
->paste_command
) {
2043 int len
= strlen(icon
->command
) + 8;
2044 icon
->paste_command
= wmalloc(len
);
2045 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
2051 void reattachIcon(WDock
* dock
, WAppIcon
* icon
, int x
, int y
)
2055 for (index
= 1; index
< dock
->max_icons
; index
++) {
2056 if (dock
->icon_array
[index
] == icon
)
2059 assert(index
< dock
->max_icons
);
2064 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2065 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2068 Bool
moveIconBetweenDocks(WDock
* src
, WDock
* dest
, WAppIcon
* icon
, int x
, int y
)
2075 return True
; /* No move needed, we're already there */
2080 wwin
= icon
->icon
->owner
;
2083 * For the moment we can't do this if we move icons in Clip from one
2084 * workspace to other, because if we move two or more icons without
2085 * command, the dialog box will not be able to tell us to which of the
2086 * moved icons it applies. -Dan
2088 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
2089 command
= GetCommandForWindow(wwin
->client_win
);
2091 icon
->command
= command
;
2094 /* icon->forced_dock = 1; */
2095 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2096 _("Type the command used to launch the application"), &command
)) {
2097 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2101 icon
->command
= command
;
2112 if (dest
->type
== WM_DOCK
)
2113 wClipMakeIconOmnipresent(icon
, False
);
2115 for (index
= 1; index
< src
->max_icons
; index
++) {
2116 if (src
->icon_array
[index
] == icon
)
2119 assert(index
< src
->max_icons
);
2121 src
->icon_array
[index
] = NULL
;
2124 for (index
= 1; index
< dest
->max_icons
; index
++) {
2125 if (dest
->icon_array
[index
] == NULL
)
2128 /* if (index == dest->max_icons)
2131 assert(index
< dest
->max_icons
);
2133 dest
->icon_array
[index
] = icon
;
2136 /* deselect the icon */
2137 if (icon
->icon
->selected
)
2138 wIconSelect(icon
->icon
);
2140 if (dest
->type
== WM_DOCK
) {
2141 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2142 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2144 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2145 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2148 /* set it to be kept when moving to dock.
2149 * Unless the icon does not have a command set
2151 if (icon
->command
&& dest
->type
== WM_DOCK
) {
2152 icon
->attracted
= 0;
2153 if (icon
->icon
->shadowed
) {
2154 icon
->icon
->shadowed
= 0;
2155 icon
->icon
->force_paint
= 1;
2159 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2165 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2166 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2170 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2171 wAppIconPaint(icon
);
2176 void wDockDetach(WDock
* dock
, WAppIcon
* icon
)
2180 /* make the settings panel be closed */
2182 DestroyDockAppSettingsPanel(icon
->panel
);
2185 /* This must be called before icon->dock is set to NULL.
2186 * Don't move it. -Dan
2188 wClipMakeIconOmnipresent(icon
, False
);
2192 icon
->attracted
= 0;
2193 icon
->auto_launch
= 0;
2194 if (icon
->icon
->shadowed
) {
2195 icon
->icon
->shadowed
= 0;
2196 icon
->icon
->force_paint
= 1;
2199 /* deselect the icon */
2200 if (icon
->icon
->selected
)
2201 wIconSelect(icon
->icon
);
2203 if (icon
->command
) {
2204 wfree(icon
->command
);
2205 icon
->command
= NULL
;
2207 #ifdef XDND /* was OFFIX */
2208 if (icon
->dnd_command
) {
2209 wfree(icon
->dnd_command
);
2210 icon
->dnd_command
= NULL
;
2213 if (icon
->paste_command
) {
2214 wfree(icon
->paste_command
);
2215 icon
->paste_command
= NULL
;
2218 for (index
= 1; index
< dock
->max_icons
; index
++)
2219 if (dock
->icon_array
[index
] == icon
)
2221 assert(index
< dock
->max_icons
);
2222 dock
->icon_array
[index
] = NULL
;
2228 /* if the dock is not attached to an application or
2229 * the the application did not set the approriate hints yet,
2230 * destroy the icon */
2231 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2232 wAppIconDestroy(icon
);
2234 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2235 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2236 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2237 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2238 icon
->icon
->core
->descriptor
.parent
= icon
;
2240 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2242 wAppIconPaint(icon
);
2243 if (wPreferences
.auto_arrange_icons
) {
2244 wArrangeIcons(dock
->screen_ptr
, True
);
2247 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2252 * returns the closest Dock slot index for the passed
2255 * Returns False if icon can't be docked.
2257 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2260 Bool
wDockSnapIcon(WDock
* dock
, WAppIcon
* icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2262 WScreen
*scr
= dock
->screen_ptr
;
2265 int i
, offset
= ICON_SIZE
/ 2;
2266 WAppIcon
*aicon
= NULL
;
2267 WAppIcon
*nicon
= NULL
;
2268 int max_y_icons
, max_x_icons
;
2270 /* TODO: XINERAMA, for these */
2271 max_x_icons
= scr
->scr_width
/ ICON_SIZE
;
2272 max_y_icons
= scr
->scr_height
/ ICON_SIZE
- 1;
2274 if (wPreferences
.flags
.noupdates
)
2280 /* if the dock is full */
2281 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
)) {
2285 /* exact position */
2287 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2289 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2292 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2294 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2296 /* check if the icon is outside the screen boundaries */
2301 rect
.pos
.x
= dx
+ ex_x
* ICON_SIZE
;
2302 rect
.pos
.y
= dy
+ ex_y
* ICON_SIZE
;
2303 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2305 wGetRectPlacementInfo(scr
, rect
, &flags
);
2306 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
2310 if (dock
->type
== WM_DOCK
) {
2311 if (icon
->dock
!= dock
&& ex_x
!= 0)
2315 for (i
= 0; i
< dock
->max_icons
; i
++) {
2316 nicon
= dock
->icon_array
[i
];
2317 if (nicon
&& nicon
->yindex
== ex_y
) {
2324 int sig
, done
, closest
;
2326 /* Possible cases when redocking:
2328 * icon dragged out of range of any slot -> false
2329 * icon dragged to range of free slot
2330 * icon dragged to range of same slot
2331 * icon dragged to range of different icon
2333 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2336 if (ex_y
>= 0 && ex_y
<= max_y_icons
&& (aicon
== icon
|| !aicon
)) {
2342 /* start looking at the upper slot or lower? */
2343 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2350 /* look for closest free slot */
2351 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2355 closest
= sig
* (i
/ 2) + ex_y
;
2356 /* check if this slot is used */
2358 for (j
= 0; j
< dock
->max_icons
; j
++) {
2359 if (dock
->icon_array
[j
]
2360 && dock
->icon_array
[j
]->yindex
== closest
) {
2361 /* slot is used by someone else */
2362 if (dock
->icon_array
[j
] != icon
)
2370 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2371 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2372 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2377 } else { /* !redocking */
2379 /* if slot is free and the icon is close enough, return it */
2380 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2390 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2391 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+ 1;
2394 for (k
= start
; k
< stop
; k
++) {
2395 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2398 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2399 nicon
= tmp
->icon_array
[i
];
2400 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2408 for (k
= start
; k
< stop
; k
++) {
2409 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2412 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2413 nicon
= tmp
->icon_array
[i
];
2414 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2415 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2416 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2425 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2434 static int onScreen(WScreen
* scr
, int x
, int y
, int sx
, int ex
, int sy
, int ey
)
2436 WMRect rect
= wmkrect(x
, y
, ICON_SIZE
, ICON_SIZE
);
2439 wGetRectPlacementInfo(scr
, rect
, &flags
);
2441 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2445 * returns true if it can find a free slot in the dock,
2446 * in which case it changes x_pos and y_pos accordingly.
2447 * Else returns false.
2449 Bool
wDockFindFreeSlot(WDock
* dock
, int *x_pos
, int *y_pos
)
2451 WScreen
*scr
= dock
->screen_ptr
;
2453 WAppIconChain
*chain
;
2454 unsigned char *slot_map
;
2458 int i
, done
= False
;
2460 int sx
= 0, sy
= 0, ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2461 int extra_count
= 0;
2463 if (dock
->type
== WM_CLIP
&& dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2464 extra_count
= scr
->global_icon_count
;
2466 /* if the dock is full */
2467 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
) {
2471 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2472 if (scr
->dock
->on_right_side
)
2473 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2475 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2478 if (ex
< dock
->x_pos
)
2480 if (sx
> dock
->x_pos
+ ICON_SIZE
)
2481 sx
= dock
->x_pos
+ ICON_SIZE
;
2488 /* check if clip is in a corner */
2489 if (dock
->type
== WM_CLIP
) {
2490 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2492 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2494 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2496 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2503 /* If the clip is in the corner, use only slots that are in the border
2505 if (corner
!= C_NONE
) {
2509 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2510 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2511 hmap
= wmalloc(hcount
+ 1);
2512 memset(hmap
, 0, hcount
+ 1);
2513 vmap
= wmalloc(vcount
+ 1);
2514 memset(vmap
, 0, vcount
+ 1);
2516 /* mark used positions */
2519 for (i
= 0; i
< dock
->max_icons
; i
++) {
2520 btn
= dock
->icon_array
[i
];
2524 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2525 vmap
[btn
->yindex
] = 1;
2526 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2527 hmap
[btn
->xindex
] = 1;
2529 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2531 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2532 vmap
[btn
->yindex
] = 1;
2533 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2534 hmap
[btn
->xindex
] = 1;
2538 for (i
= 0; i
< dock
->max_icons
; i
++) {
2539 btn
= dock
->icon_array
[i
];
2543 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2544 vmap
[btn
->yindex
] = 1;
2545 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2546 hmap
[-btn
->xindex
] = 1;
2548 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2550 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2551 vmap
[btn
->yindex
] = 1;
2552 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2553 hmap
[-btn
->xindex
] = 1;
2557 for (i
= 0; i
< dock
->max_icons
; i
++) {
2558 btn
= dock
->icon_array
[i
];
2562 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2563 vmap
[-btn
->yindex
] = 1;
2564 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2565 hmap
[btn
->xindex
] = 1;
2567 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2569 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2570 vmap
[-btn
->yindex
] = 1;
2571 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2572 hmap
[btn
->xindex
] = 1;
2577 for (i
= 0; i
< dock
->max_icons
; i
++) {
2578 btn
= dock
->icon_array
[i
];
2582 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2583 vmap
[-btn
->yindex
] = 1;
2584 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2585 hmap
[-btn
->xindex
] = 1;
2587 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2589 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2590 vmap
[-btn
->yindex
] = 1;
2591 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2592 hmap
[-btn
->xindex
] = 1;
2598 /* search a vacant slot */
2599 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2600 if (i
< vcount
&& vmap
[i
] == 0) {
2606 } else if (i
< hcount
&& hmap
[i
] == 0) {
2616 /* If found a slot, translate and return */
2618 if (corner
== C_NW
|| corner
== C_NE
) {
2623 if (corner
== C_NE
|| corner
== C_SE
) {
2630 /* else, try to find a slot somewhere else */
2633 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2634 * placed outside of screen */
2635 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2637 /* In the worst case (the clip is in the corner of the screen),
2638 * the amount of icons that fit in the clip is smaller.
2639 * Double the map to get a safe value.
2643 r
= (mwidth
- 1) / 2;
2645 slot_map
= wmalloc(mwidth
* mwidth
);
2646 memset(slot_map
, 0, mwidth
* mwidth
);
2648 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2650 /* mark used slots in the map. If the slot falls outside the map
2651 * (for example, when all icons are placed in line), ignore them. */
2652 for (i
= 0; i
< dock
->max_icons
; i
++) {
2653 btn
= dock
->icon_array
[i
];
2655 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2657 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2658 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2660 /* Find closest slot from the center that is free by scanning the
2661 * map from the center to outward in circular passes.
2662 * This will not result in a neat layout, but will be optimal
2663 * in the sense that there will not be holes left.
2666 for (i
= 1; i
<= r
&& !done
; i
++) {
2669 /* top and bottom parts of the ring */
2670 for (x
= -i
; x
<= i
&& !done
; x
++) {
2671 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2673 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2674 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2681 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2682 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2689 /* left and right parts of the ring */
2690 for (y
= -i
+ 1; y
<= i
- 1; y
++) {
2691 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2693 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2694 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2701 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2702 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2715 static void moveDock(WDock
* dock
, int new_x
, int new_y
)
2720 dock
->x_pos
= new_x
;
2721 dock
->y_pos
= new_y
;
2722 for (i
= 0; i
< dock
->max_icons
; i
++) {
2723 btn
= dock
->icon_array
[i
];
2725 btn
->x_pos
= new_x
+ btn
->xindex
* ICON_SIZE
;
2726 btn
->y_pos
= new_y
+ btn
->yindex
* ICON_SIZE
;
2727 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2732 static void swapDock(WDock
* dock
)
2734 WScreen
*scr
= dock
->screen_ptr
;
2738 if (dock
->on_right_side
) {
2739 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2741 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2744 for (i
= 0; i
< dock
->max_icons
; i
++) {
2745 btn
= dock
->icon_array
[i
];
2748 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2752 wScreenUpdateUsableArea(scr
);
2755 static pid_t
execCommand(WAppIcon
* btn
, char *command
, WSavedState
* state
)
2757 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2763 cmdline
= ExpandOptions(scr
, command
);
2765 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2773 wtokensplit(cmdline
, &argv
, &argc
);
2783 if ((pid
= fork()) == 0) {
2787 SetupEnvironment(scr
);
2793 args
= malloc(sizeof(char *) * (argc
+ 1));
2796 for (i
= 0; i
< argc
; i
++) {
2800 execvp(argv
[0], args
);
2803 wtokenfree(argv
, argc
);
2807 state
= wmalloc(sizeof(WSavedState
));
2808 memset(state
, 0, sizeof(WSavedState
));
2810 state
->miniaturized
= -1;
2812 if (btn
->dock
== scr
->dock
|| btn
->omnipresent
)
2813 state
->workspace
= -1;
2815 state
->workspace
= scr
->current_workspace
;
2817 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
2818 wAddDeathHandler(pid
, (WDeathHandler
*) trackDeadProcess
, btn
->dock
);
2826 void wDockHideIcons(WDock
* dock
)
2833 for (i
= 1; i
< dock
->max_icons
; i
++) {
2834 if (dock
->icon_array
[i
])
2835 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2839 dockIconPaint(dock
->icon_array
[0]);
2842 void wDockShowIcons(WDock
* dock
)
2850 btn
= dock
->icon_array
[0];
2851 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2853 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2854 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2856 for (i
= 1; i
< dock
->max_icons
; i
++) {
2857 if (dock
->icon_array
[i
]) {
2858 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
, btn
->icon
->core
);
2863 if (!dock
->collapsed
) {
2864 for (i
= 1; i
< dock
->max_icons
; i
++) {
2865 if (dock
->icon_array
[i
]) {
2866 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2875 void wDockLower(WDock
* dock
)
2879 for (i
= 0; i
< dock
->max_icons
; i
++) {
2880 if (dock
->icon_array
[i
])
2881 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2885 void wDockRaise(WDock
* dock
)
2889 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
2890 if (dock
->icon_array
[i
])
2891 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2895 void wDockRaiseLower(WDock
* dock
)
2897 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2898 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2899 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2905 void wDockFinishLaunch(WDock
* dock
, WAppIcon
* icon
)
2907 icon
->launching
= 0;
2908 icon
->relaunching
= 0;
2909 dockIconPaint(icon
);
2912 WAppIcon
*wDockFindIconForWindow(WDock
* dock
, Window window
)
2917 for (i
= 0; i
< dock
->max_icons
; i
++) {
2918 icon
= dock
->icon_array
[i
];
2919 if (icon
&& icon
->main_window
== window
)
2925 void wDockTrackWindowLaunch(WDock
* dock
, Window window
)
2928 char *wm_class
, *wm_instance
;
2930 Bool firstPass
= True
;
2932 char *command
= NULL
;
2934 command
= GetCommandForWindow(window
);
2936 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) || (!wm_class
&& !wm_instance
)) {
2944 for (i
= 0; i
< dock
->max_icons
; i
++) {
2945 icon
= dock
->icon_array
[i
];
2949 /* app is already attached to icon */
2950 if (icon
->main_window
== window
) {
2955 if ((icon
->wm_instance
|| icon
->wm_class
)
2956 && (icon
->launching
|| !icon
->running
)) {
2958 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0) {
2961 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0) {
2964 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0) {
2968 if (!icon
->relaunching
) {
2971 /* Possibly an application that was docked with dockit,
2972 * but the user did not update WMState to indicate that
2973 * it was docked by force */
2974 wapp
= wApplicationOf(window
);
2976 icon
->forced_dock
= 1;
2979 if (!icon
->forced_dock
) {
2980 icon
->main_window
= window
;
2984 if (!wPreferences
.no_animations
&& !icon
->launching
&&
2985 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
2989 icon
->launching
= 1;
2990 dockIconPaint(icon
);
2992 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
2993 wm_instance
, wm_class
, TILE_NORMAL
);
2994 /* XXX: can: aicon->icon == NULL ? */
2995 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
2996 wAppIconMove(aicon
, x0
, y0
);
2997 /* Should this always be lowered? -Dan */
2999 wLowerFrame(aicon
->icon
->core
);
3000 XMapWindow(dpy
, aicon
->icon
->core
->window
);
3001 aicon
->launching
= 1;
3002 wAppIconPaint(aicon
);
3003 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
3004 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
3005 wAppIconDestroy(aicon
);
3007 wDockFinishLaunch(dock
, icon
);
3012 if (firstPass
&& !found
) {
3026 void wClipUpdateForWorkspaceChange(WScreen
* scr
, int workspace
)
3028 if (!wPreferences
.flags
.noclip
) {
3029 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3030 if (scr
->current_workspace
!= workspace
) {
3031 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3032 WAppIconChain
*chain
= scr
->global_icons
;
3035 moveIconBetweenDocks(chain
->aicon
->dock
,
3036 scr
->workspaces
[workspace
]->clip
,
3037 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
3038 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
3039 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3040 chain
= chain
->next
;
3043 wDockHideIcons(old_clip
);
3044 if (old_clip
->auto_raise_lower
) {
3045 if (old_clip
->auto_raise_magic
) {
3046 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3047 old_clip
->auto_raise_magic
= NULL
;
3049 wDockLower(old_clip
);
3051 if (old_clip
->auto_collapse
) {
3052 if (old_clip
->auto_expand_magic
) {
3053 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3054 old_clip
->auto_expand_magic
= NULL
;
3056 old_clip
->collapsed
= 1;
3058 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3060 if (scr
->flags
.clip_balloon_mapped
)
3061 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3065 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
* dock
)
3070 for (i
= 0; i
< dock
->max_icons
; i
++) {
3071 icon
= dock
->icon_array
[i
];
3075 if (icon
->launching
&& icon
->pid
== pid
) {
3076 if (!icon
->relaunching
) {
3078 icon
->main_window
= None
;
3080 wDockFinishLaunch(dock
, icon
);
3082 if (status
== 111) {
3087 if (icon
->drop_launch
)
3088 cmd
= icon
->dnd_command
;
3091 if (icon
->paste_launch
)
3092 cmd
= icon
->paste_command
;
3094 cmd
= icon
->command
;
3096 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3098 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3105 static void toggleLowered(WDock
* dock
)
3110 /* lower/raise Dock */
3111 if (!dock
->lowered
) {
3112 newlevel
= WMNormalLevel
;
3115 newlevel
= WMDockLevel
;
3119 for (i
= 0; i
< dock
->max_icons
; i
++) {
3120 tmp
= dock
->icon_array
[i
];
3124 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3126 wLowerFrame(tmp
->icon
->core
);
3129 if (dock
->type
== WM_DOCK
)
3130 wScreenUpdateUsableArea(dock
->screen_ptr
);
3133 static void toggleCollapsed(WDock
* dock
)
3135 if (dock
->collapsed
) {
3136 dock
->collapsed
= 0;
3137 wDockShowIcons(dock
);
3139 dock
->collapsed
= 1;
3140 wDockHideIcons(dock
);
3144 static void openDockMenu(WDock
* dock
, WAppIcon
* aicon
, XEvent
* event
)
3146 WScreen
*scr
= dock
->screen_ptr
;
3147 WObjDescriptor
*desc
;
3149 WApplication
*wapp
= NULL
;
3153 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3155 if (dock
->type
== WM_DOCK
) {
3157 entry
= dock
->menu
->entries
[index
];
3158 entry
->flags
.indicator_on
= !dock
->lowered
;
3159 entry
->clientdata
= dock
;
3160 dock
->menu
->flags
.realized
= 0;
3163 if (scr
->clip_options
)
3164 updateClipOptionsMenu(scr
->clip_options
, dock
);
3166 n_selected
= numberOfSelectedIcons(dock
);
3168 /* Rename Workspace */
3169 entry
= dock
->menu
->entries
[++index
];
3170 if (aicon
== scr
->clip_icon
) {
3171 entry
->callback
= renameCallback
;
3172 entry
->clientdata
= dock
;
3173 entry
->flags
.indicator
= 0;
3174 entry
->text
= _("Rename Workspace");
3176 entry
->callback
= omnipresentCallback
;
3177 entry
->clientdata
= aicon
;
3178 if (n_selected
> 0) {
3179 entry
->flags
.indicator
= 0;
3180 entry
->text
= _("Toggle Omnipresent");
3182 entry
->flags
.indicator
= 1;
3183 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3184 entry
->flags
.indicator_type
= MI_CHECK
;
3185 entry
->text
= _("Omnipresent");
3189 /* select/unselect icon */
3190 entry
= dock
->menu
->entries
[++index
];
3191 entry
->clientdata
= aicon
;
3192 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3193 wMenuSetEnabled(dock
->menu
, index
, aicon
!= scr
->clip_icon
);
3195 /* select/unselect all icons */
3196 entry
= dock
->menu
->entries
[++index
];
3197 entry
->clientdata
= aicon
;
3199 entry
->text
= _("Unselect All Icons");
3201 entry
->text
= _("Select All Icons");
3202 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3205 entry
= dock
->menu
->entries
[++index
];
3206 entry
->clientdata
= aicon
;
3208 entry
->text
= _("Keep Icons");
3210 entry
->text
= _("Keep Icon");
3211 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3213 /* this is the workspace submenu part */
3214 entry
= dock
->menu
->entries
[++index
];
3216 entry
->text
= _("Move Icons To");
3218 entry
->text
= _("Move Icon To");
3219 if (scr
->clip_submenu
)
3220 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3221 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3223 /* remove icon(s) */
3224 entry
= dock
->menu
->entries
[++index
];
3225 entry
->clientdata
= aicon
;
3227 entry
->text
= _("Remove Icons");
3229 entry
->text
= _("Remove Icon");
3230 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3232 /* attract icon(s) */
3233 entry
= dock
->menu
->entries
[++index
];
3234 entry
->clientdata
= aicon
;
3236 dock
->menu
->flags
.realized
= 0;
3237 wMenuRealize(dock
->menu
);
3240 if (aicon
->icon
->owner
) {
3241 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3247 entry
= dock
->menu
->entries
[++index
];
3248 entry
->clientdata
= aicon
;
3249 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3252 entry
= dock
->menu
->entries
[++index
];
3253 entry
->clientdata
= aicon
;
3254 if (wapp
&& wapp
->flags
.hidden
) {
3255 entry
->text
= _("Unhide Here");
3257 entry
->text
= _("Bring Here");
3259 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3262 entry
= dock
->menu
->entries
[++index
];
3263 entry
->clientdata
= aicon
;
3264 if (wapp
&& wapp
->flags
.hidden
) {
3265 entry
->text
= _("Unhide");
3267 entry
->text
= _("Hide");
3269 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3272 entry
= dock
->menu
->entries
[++index
];
3273 entry
->clientdata
= aicon
;
3274 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3277 entry
= dock
->menu
->entries
[++index
];
3278 entry
->clientdata
= aicon
;
3279 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3281 if (!dock
->menu
->flags
.realized
)
3282 wMenuRealize(dock
->menu
);
3284 if (dock
->type
== WM_CLIP
) {
3285 /*x_pos = event->xbutton.x_root+2; */
3286 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3289 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3290 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3293 x_pos
= dock
->on_right_side
? scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3296 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3298 /* allow drag select */
3299 event
->xany
.send_event
= True
;
3300 desc
= &dock
->menu
->menu
->descriptor
;
3301 (*desc
->handle_mousedown
) (desc
, event
);
3304 /******************************************************************/
3305 static void iconDblClick(WObjDescriptor
* desc
, XEvent
* event
)
3307 WAppIcon
*btn
= desc
->parent
;
3308 WDock
*dock
= btn
->dock
;
3309 WApplication
*wapp
= NULL
;
3312 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3313 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3315 assert(wapp
!= NULL
);
3317 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3319 /* go to the last workspace that the user worked on the app */
3320 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
&& !unhideHere
) {
3321 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3324 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3326 if (event
->xbutton
.state
& MOD_MASK
) {
3327 wHideOtherApplications(btn
->icon
->owner
);
3330 if (event
->xbutton
.button
== Button1
) {
3332 if (event
->xbutton
.state
& MOD_MASK
) {
3333 /* raise/lower dock */
3334 toggleLowered(dock
);
3335 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3336 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
)
3337 toggleCollapsed(dock
);
3339 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3340 } else if (btn
->command
) {
3341 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3342 launchDockedApplication(btn
, False
);
3344 } else if (btn
->xindex
== 0 && btn
->yindex
== 0 && btn
->dock
->type
== WM_DOCK
) {
3345 wShowGNUstepPanel(dock
->screen_ptr
);
3351 static void handleDockMove(WDock
* dock
, WAppIcon
* aicon
, XEvent
* event
)
3353 WScreen
*scr
= dock
->screen_ptr
;
3354 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3357 int grabbed
= 0, swapped
= 0, done
;
3358 Pixmap ghost
= None
;
3359 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3362 puts("moving dock");
3364 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3365 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3366 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3367 wwarning("pointer grab failed for dock move");
3370 for (x
= 0; x
< dock
->max_icons
; x
++) {
3371 if (dock
->icon_array
[x
] != NULL
&& dock
->icon_array
[x
]->yindex
> y
)
3372 y
= dock
->icon_array
[x
]->yindex
;
3375 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
* y
);
3379 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3380 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3387 /* It means the cursor moved so fast that it entered
3388 * something else (if moving slowly, it would have
3389 * stayed in the dock that is being moved. Ignore such
3390 * "spurious" EnterNotifiy's */
3395 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3396 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3397 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3398 | ButtonReleaseMask
| ButtonPressMask
,
3399 wCursor
[WCUR_MOVE
], CurrentTime
);
3404 if (dock
->type
== WM_CLIP
) {
3405 x
= ev
.xmotion
.x_root
- ofs_x
;
3406 y
= ev
.xmotion
.y_root
- ofs_y
;
3407 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3409 moveDock(dock
, x
, y
);
3411 /* move vertically if pointer is inside the dock */
3412 if ((dock
->on_right_side
&& ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3413 || (!dock
->on_right_side
&& ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
* 2)) {
3415 x
= ev
.xmotion
.x_root
- ofs_x
;
3416 y
= ev
.xmotion
.y_root
- ofs_y
;
3417 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3418 moveDock(dock
, dock
->x_pos
, y
);
3420 /* move horizontally to change sides */
3421 x
= ev
.xmotion
.x_root
- ofs_x
;
3422 if (!dock
->on_right_side
) {
3426 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
* 2) {
3427 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
- ICON_SIZE
3428 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3429 if (superfluous
&& ghost
== None
) {
3430 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3431 scr
->scr_width
- ICON_SIZE
3432 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3433 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3434 XClearWindow(dpy
, scr
->dock_shadow
);
3436 XMapRaised(dpy
, scr
->dock_shadow
);
3439 if (superfluous
&& ghost
!= None
) {
3440 XFreePixmap(dpy
, ghost
);
3443 XUnmapWindow(dpy
, scr
->dock_shadow
);
3448 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3449 XMoveWindow(dpy
, scr
->dock_shadow
, DOCK_EXTRA_SPACE
, dock
->y_pos
);
3450 if (superfluous
&& ghost
== None
) {
3451 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3452 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3453 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3454 XClearWindow(dpy
, scr
->dock_shadow
);
3456 XMapRaised(dpy
, scr
->dock_shadow
);
3459 XUnmapWindow(dpy
, scr
->dock_shadow
);
3461 if (superfluous
&& ghost
!= None
) {
3462 XFreePixmap(dpy
, ghost
);
3474 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3476 XUngrabPointer(dpy
, CurrentTime
);
3477 XUnmapWindow(dpy
, scr
->dock_shadow
);
3478 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3479 if (dock
->type
== WM_DOCK
) {
3482 dock
->on_right_side
= 1;
3484 dock
->on_right_side
= 0;
3486 wArrangeIcons(scr
, False
);
3495 XFreePixmap(dpy
, ghost
);
3496 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3499 puts("End dock move");
3503 static Bool
handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3505 WScreen
*scr
= dock
->screen_ptr
;
3507 WIcon
*icon
= aicon
->icon
;
3508 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3509 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3511 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3512 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3513 int shad_x
= x
, shad_y
= y
;
3514 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3516 Pixmap ghost
= None
;
3518 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3519 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3520 Bool hasMoved
= False
;
3522 if (wPreferences
.flags
.noupdates
)
3525 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3526 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3527 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3529 wwarning("pointer grab failed for icon move");
3533 if (!(event
->xbutton
.state
& MOD_MASK
))
3534 wRaiseFrame(icon
->core
);
3536 if (!wPreferences
.flags
.noclip
)
3537 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3539 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3541 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3544 wins
[0] = icon
->core
->window
;
3545 wins
[1] = scr
->dock_shadow
;
3546 XRestackWindows(dpy
, wins
, 2);
3547 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
3549 if (icon
->pixmap
!= None
)
3550 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3552 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3554 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3555 XClearWindow(dpy
, scr
->dock_shadow
);
3557 XMapWindow(dpy
, scr
->dock_shadow
);
3562 XMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3563 | ButtonMotionMask
| ExposureMask
, &ev
);
3572 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3573 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3574 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3575 | ButtonReleaseMask
| ButtonPressMask
,
3576 wCursor
[WCUR_MOVE
], CurrentTime
);
3585 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3586 if (i
== scr
->current_workspace
)
3588 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3592 x
= ev
.xmotion
.x_root
- ofs_x
;
3593 y
= ev
.xmotion
.y_root
- ofs_y
;
3594 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3597 if (last_dock
!= dock
&& collapsed
) {
3598 last_dock
->collapsed
= 1;
3599 wDockHideIcons(last_dock
);
3602 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3603 dock
->collapsed
= 0;
3604 wDockShowIcons(dock
);
3606 if (dock
->auto_raise_lower
)
3610 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3613 if (last_dock
!= dock2
&& collapsed
) {
3614 last_dock
->collapsed
= 1;
3615 wDockHideIcons(last_dock
);
3618 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3619 dock2
->collapsed
= 0;
3620 wDockShowIcons(dock2
);
3622 if (dock2
->auto_raise_lower
)
3627 if (aicon
->launching
|| aicon
->lock
|| (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3628 || (!aicon
->running
&& tmp
)) {
3629 shad_x
= last_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3630 shad_y
= last_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3632 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3635 XMapWindow(dpy
, scr
->dock_shadow
);
3640 XUnmapWindow(dpy
, scr
->dock_shadow
);
3644 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3651 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3653 XUngrabPointer(dpy
, CurrentTime
);
3655 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3656 XUnmapWindow(dpy
, scr
->dock_shadow
);
3658 reattachIcon(dock
, aicon
, ix
, iy
);
3659 if (clip
&& dock
!= clip
&& clip
->auto_raise_lower
)
3662 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3664 /* Slide it back if dock rejected it */
3665 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
, aicon
->y_pos
);
3666 reattachIcon(dock
, aicon
, aicon
->xindex
, aicon
->yindex
);
3668 if (last_dock
->type
== WM_CLIP
&& last_dock
->auto_collapse
) {
3676 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3677 /* We need to deselect it, even if is deselected in
3678 * wDockDetach(), because else DoKaboom() will fail.
3680 if (aicon
->icon
->selected
)
3681 wIconSelect(aicon
->icon
);
3683 DoKaboom(scr
, aicon
->icon
->core
->window
, x
, y
);
3686 if (clip
&& clip
->auto_raise_lower
)
3688 wDockDetach(dock
, aicon
);
3691 last_dock
->collapsed
= 1;
3692 wDockHideIcons(last_dock
);
3697 XFreePixmap(dpy
, ghost
);
3698 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3702 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3703 if (i
== scr
->current_workspace
)
3705 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3709 puts("End icon move");
3714 return False
; /* never reached */
3717 static int getClipButton(int px
, int py
)
3719 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3721 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3724 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3725 return CLIP_FORWARD
;
3726 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3732 static void handleClipChangeWorkspace(WScreen
* scr
, XEvent
* event
)
3735 int done
, direction
, new_ws
;
3737 WDock
*clip
= scr
->clip_icon
->dock
;
3739 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3741 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3742 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3744 wClipIconPaint(scr
->clip_icon
);
3747 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3754 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3755 if (new_dir
!= direction
) {
3756 direction
= new_dir
;
3757 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3758 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3759 wClipIconPaint(scr
->clip_icon
);
3767 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3772 clip
->lclip_button_pushed
= 0;
3773 clip
->rclip_button_pushed
= 0;
3775 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3777 if (direction
== CLIP_FORWARD
) {
3778 if (scr
->current_workspace
< scr
->workspace_count
- 1)
3779 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3780 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
- 1)
3781 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3782 else if (wPreferences
.ws_cycle
)
3783 wWorkspaceChange(scr
, 0);
3784 } else if (direction
== CLIP_REWIND
) {
3785 if (scr
->current_workspace
> 0)
3786 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
3787 else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
)
3788 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
3791 wClipIconPaint(scr
->clip_icon
);
3794 static void iconMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
3796 WAppIcon
*aicon
= desc
->parent
;
3797 WDock
*dock
= aicon
->dock
;
3798 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3800 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3803 scr
->last_dock
= dock
;
3805 if (dock
->menu
->flags
.mapped
)
3806 wMenuUnmap(dock
->menu
);
3808 if (IsDoubleClick(scr
, event
)) {
3809 /* double-click was not in the main clip icon */
3810 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3811 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3812 iconDblClick(desc
, event
);
3817 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
3818 XUnmapWindow(dpy
, scr
->clip_balloon
);
3819 scr
->flags
.clip_balloon_mapped
= 0;
3822 puts("handling dock");
3824 if (event
->xbutton
.button
== Button1
) {
3825 if (event
->xbutton
.state
& MOD_MASK
)
3830 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
&& dock
->type
!= WM_DOCK
) {
3831 wIconSelect(aicon
->icon
);
3835 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3836 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
3837 && dock
->type
== WM_CLIP
)
3838 handleClipChangeWorkspace(scr
, event
);
3840 handleDockMove(dock
, aicon
, event
);
3842 Bool hasMoved
= handleIconMove(dock
, aicon
, event
);
3843 if (wPreferences
.single_click
&& !hasMoved
)
3844 iconDblClick(desc
, event
);
3846 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&& aicon
== scr
->clip_icon
) {
3847 if (!scr
->clip_ws_menu
) {
3848 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3850 if (scr
->clip_ws_menu
) {
3851 WMenu
*wsMenu
= scr
->clip_ws_menu
;
3854 wWorkspaceMenuUpdate(scr
, wsMenu
);
3856 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
3859 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
3860 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
3862 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
3864 desc
= &wsMenu
->menu
->descriptor
;
3865 event
->xany
.send_event
= True
;
3866 (*desc
->handle_mousedown
) (desc
, event
);
3868 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
3869 (event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
) {
3870 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3871 } else if (event
->xbutton
.button
== Button3
) {
3872 if (event
->xbutton
.send_event
&&
3873 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3874 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3875 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3876 wwarning("pointer grab failed for dockicon menu");
3880 openDockMenu(dock
, aicon
, event
);
3881 } else if (event
->xbutton
.button
== Button2
) {
3882 WAppIcon
*btn
= desc
->parent
;
3884 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3885 launchDockedApplication(btn
, True
);
3890 static void showClipBalloon(WDock
* dock
, int workspace
)
3894 WScreen
*scr
= dock
->screen_ptr
;
3898 scr
->flags
.clip_balloon_mapped
= 1;
3899 XMapWindow(dpy
, scr
->clip_balloon
);
3901 text
= scr
->workspaces
[workspace
]->name
;
3903 w
= WMWidthOfString(scr
->clip_title_font
, text
, strlen(text
));
3905 h
= WMFontHeight(scr
->clip_title_font
);
3906 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
3908 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
3909 y
= dock
->y_pos
+ ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
3911 if (x
+ w
> scr
->scr_width
) {
3912 x
= scr
->scr_width
- w
;
3913 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
3914 y
= dock
->y_pos
- h
- 1;
3916 y
= dock
->y_pos
+ ICON_SIZE
;
3917 XRaiseWindow(dpy
, scr
->clip_balloon
);
3919 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
3920 stack
[1] = scr
->clip_balloon
;
3921 XRestackWindows(dpy
, stack
, 2);
3923 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
3924 XClearWindow(dpy
, scr
->clip_balloon
);
3925 WMDrawString(scr
->wmscreen
, scr
->clip_balloon
,
3926 scr
->clip_title_color
[CLIP_NORMAL
], scr
->clip_title_font
, 0, 0, text
, strlen(text
));
3929 static void clipEnterNotify(WObjDescriptor
* desc
, XEvent
* event
)
3931 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3935 assert(event
->type
== EnterNotify
);
3937 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3940 scr
= btn
->icon
->core
->screen_ptr
;
3941 if (!btn
->omnipresent
)
3944 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3946 if (!dock
|| dock
->type
!= WM_CLIP
)
3949 /* The auto raise/lower code */
3950 if (dock
->auto_lower_magic
) {
3951 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3952 dock
->auto_lower_magic
= NULL
;
3954 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
3955 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
, clipAutoRaise
, (void *)dock
);
3958 /* The auto expand/collapse code */
3959 if (dock
->auto_collapse_magic
) {
3960 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3961 dock
->auto_collapse_magic
= NULL
;
3963 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
3964 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
, clipAutoExpand
, (void *)dock
);
3967 if (btn
->xindex
== 0 && btn
->yindex
== 0)
3968 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
3970 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
3971 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
3972 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
3977 static void clipLeave(WDock
* dock
)
3980 WObjDescriptor
*desc
= NULL
;
3982 if (!dock
|| dock
->type
!= WM_CLIP
)
3985 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
3986 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3987 (XPointer
*) & desc
) != XCNOENT
3988 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
3989 && ((WAppIcon
*) desc
->parent
)->dock
&& ((WAppIcon
*) desc
->parent
)->dock
->type
== WM_CLIP
) {
3990 /* We didn't left the Clip yet */
3991 XPutBackEvent(dpy
, &event
);
3995 XPutBackEvent(dpy
, &event
);
3997 /* We entered a withdrawn window, so we're still in Clip */
4001 if (dock
->auto_raise_magic
) {
4002 WMDeleteTimerHandler(dock
->auto_raise_magic
);
4003 dock
->auto_raise_magic
= NULL
;
4005 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
4006 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
, clipAutoLower
, (void *)dock
);
4009 if (dock
->auto_expand_magic
) {
4010 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4011 dock
->auto_expand_magic
= NULL
;
4013 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
4014 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
, clipAutoCollapse
, (void *)dock
);
4018 static void clipLeaveNotify(WObjDescriptor
* desc
, XEvent
* event
)
4020 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
4022 assert(event
->type
== LeaveNotify
);
4024 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
4027 clipLeave(btn
->dock
);
4030 static void clipAutoCollapse(void *cdata
)
4032 WDock
*dock
= (WDock
*) cdata
;
4034 if (dock
->type
!= WM_CLIP
)
4037 if (dock
->auto_collapse
) {
4038 dock
->collapsed
= 1;
4039 wDockHideIcons(dock
);
4041 dock
->auto_collapse_magic
= NULL
;
4044 static void clipAutoExpand(void *cdata
)
4046 WDock
*dock
= (WDock
*) cdata
;
4048 if (dock
->type
!= WM_CLIP
)
4051 if (dock
->auto_collapse
) {
4052 dock
->collapsed
= 0;
4053 wDockShowIcons(dock
);
4055 dock
->auto_expand_magic
= NULL
;
4058 static void clipAutoLower(void *cdata
)
4060 WDock
*dock
= (WDock
*) cdata
;
4062 if (dock
->type
!= WM_CLIP
)
4065 if (dock
->auto_raise_lower
)
4068 dock
->auto_lower_magic
= NULL
;
4071 static void clipAutoRaise(void *cdata
)
4073 WDock
*dock
= (WDock
*) cdata
;
4075 if (dock
->type
!= WM_CLIP
)
4078 if (dock
->auto_raise_lower
)
4081 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4082 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4085 dock
->auto_raise_magic
= NULL
;
4088 static Bool
iconCanBeOmnipresent(WAppIcon
* aicon
)
4090 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4095 for (i
= 0; i
< scr
->workspace_count
; i
++) {
4096 clip
= scr
->workspaces
[i
]->clip
;
4098 if (clip
== aicon
->dock
)
4101 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4102 return False
; /* Clip is full in some workspace */
4104 for (j
= 0; j
< clip
->max_icons
; j
++) {
4105 btn
= clip
->icon_array
[j
];
4106 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
4114 int wClipMakeIconOmnipresent(WAppIcon
* aicon
, int omnipresent
)
4116 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4117 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4118 int status
= WO_SUCCESS
;
4120 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== scr
->clip_icon
) {
4121 return WO_NOT_APPLICABLE
;
4124 if (aicon
->omnipresent
== omnipresent
)
4128 if (iconCanBeOmnipresent(aicon
)) {
4129 aicon
->omnipresent
= 1;
4130 new_entry
= wmalloc(sizeof(WAppIconChain
));
4131 new_entry
->aicon
= aicon
;
4132 new_entry
->next
= scr
->global_icons
;
4133 scr
->global_icons
= new_entry
;
4134 scr
->global_icon_count
++;
4136 aicon
->omnipresent
= 0;
4140 aicon
->omnipresent
= 0;
4141 if (aicon
== scr
->global_icons
->aicon
) {
4142 tmp
= scr
->global_icons
->next
;
4143 wfree(scr
->global_icons
);
4144 scr
->global_icons
= tmp
;
4145 scr
->global_icon_count
--;
4147 tmp
= scr
->global_icons
;
4149 if (tmp
->next
->aicon
== aicon
) {
4150 tmp1
= tmp
->next
->next
;
4153 scr
->global_icon_count
--;
4161 wAppIconPaint(aicon
);