1 /* dock.c- built-in Dock module for WindowMaker
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <X11/Xutil.h>
35 #define PATH_MAX DEFAULT_PATH_MAX
38 #include "WindowMaker.h"
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();
66 extern void ShowDockAppSettingsPanel(WAppIcon
* aicon
);
67 extern Cursor wCursor
[WCUR_LAST
];
68 extern WPreferences wPreferences
;
69 extern XContext wWinContext
;
70 extern void appIconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
72 #define MOD_MASK wPreferences.modifier_mask
73 #define ICON_SIZE wPreferences.icon_size
75 /***** Local variables ****/
77 static WMPropList
*dCommand
= NULL
;
78 static WMPropList
*dPasteCommand
= NULL
;
79 #ifdef XDND /* XXX was OFFIX */
80 static WMPropList
*dDropCommand
= NULL
;
82 static WMPropList
*dAutoLaunch
, *dLock
;
83 static WMPropList
*dName
, *dForced
, *dBuggyApplication
, *dYes
, *dNo
;
84 static WMPropList
*dHost
, *dDock
, *dClip
;
85 static WMPropList
*dAutoAttractIcons
;
87 static WMPropList
*dPosition
, *dApplications
, *dLowered
, *dCollapsed
;
89 static WMPropList
*dAutoCollapse
, *dAutoRaiseLower
, *dOmnipresent
;
91 static void dockIconPaint(WAppIcon
* btn
);
93 static void iconMouseDown(WObjDescriptor
* desc
, XEvent
* event
);
95 static pid_t
execCommand(WAppIcon
* btn
, char *command
, WSavedState
* state
);
97 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
* dock
);
99 static int getClipButton(int px
, int py
);
101 static void toggleLowered(WDock
* dock
);
103 static void toggleCollapsed(WDock
* dock
);
105 static void clipIconExpose(WObjDescriptor
* desc
, XEvent
* event
);
107 static void clipLeave(WDock
* dock
);
109 static void handleClipChangeWorkspace(WScreen
* scr
, XEvent
* event
);
111 Bool
moveIconBetweenDocks(WDock
* src
, WDock
* dest
, WAppIcon
* icon
, int x
, int y
);
113 static void clipEnterNotify(WObjDescriptor
* desc
, XEvent
* event
);
114 static void clipLeaveNotify(WObjDescriptor
* desc
, XEvent
* event
);
115 static void clipAutoCollapse(void *cdata
);
116 static void clipAutoExpand(void *cdata
);
117 static void launchDockedApplication(WAppIcon
* btn
, Bool withSelection
);
119 static void clipAutoLower(void *cdata
);
120 static void clipAutoRaise(void *cdata
);
122 static void showClipBalloon(WDock
* dock
, int workspace
);
124 static void make_keys(void)
126 if (dCommand
!= NULL
)
129 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
130 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
132 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
134 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
135 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
136 dName
= WMRetainPropList(WMCreatePLString("Name"));
137 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
138 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
139 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
140 dNo
= WMRetainPropList(WMCreatePLString("No"));
141 dHost
= WMRetainPropList(WMCreatePLString("Host"));
143 dPosition
= WMCreatePLString("Position");
144 dApplications
= WMCreatePLString("Applications");
145 dLowered
= WMCreatePLString("Lowered");
146 dCollapsed
= WMCreatePLString("Collapsed");
147 dAutoCollapse
= WMCreatePLString("AutoCollapse");
148 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
149 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
151 dOmnipresent
= WMCreatePLString("Omnipresent");
153 dDock
= WMCreatePLString("Dock");
154 dClip
= WMCreatePLString("Clip");
157 static void renameCallback(WMenu
* menu
, WMenuEntry
* entry
)
159 WDock
*dock
= entry
->clientdata
;
164 assert(entry
->clientdata
!= NULL
);
166 wspace
= dock
->screen_ptr
->current_workspace
;
168 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
170 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+ 1);
171 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
, &name
)) {
172 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
179 static void toggleLoweredCallback(WMenu
* menu
, WMenuEntry
* entry
)
181 assert(entry
->clientdata
!= NULL
);
183 toggleLowered(entry
->clientdata
);
185 entry
->flags
.indicator_on
= !(((WDock
*) entry
->clientdata
)->lowered
);
190 static int matchWindow(const void *item
, const void *cdata
)
192 return (((WFakeGroupLeader
*) item
)->leader
== (Window
) cdata
);
195 static void killCallback(WMenu
* menu
, WMenuEntry
* entry
)
197 WScreen
*scr
= menu
->menu
->screen_ptr
;
199 WFakeGroupLeader
*fPtr
;
200 char *buffer
, *shortname
, **argv
;
201 char *basename(const char *shortname
);
204 if (!WCHECK_STATE(WSTATE_NORMAL
))
207 assert(entry
->clientdata
!= NULL
);
209 icon
= (WAppIcon
*) entry
->clientdata
;
213 WCHANGE_STATE(WSTATE_MODAL
);
215 /* strip away dir names */
216 shortname
= basename(icon
->command
);
217 /* separate out command options */
218 wtokensplit(shortname
, &argv
, &argc
);
220 buffer
= wstrconcat(argv
[0],
221 _(" will be forcibly closed.\n"
222 "Any unsaved changes will be lost.\n" "Please confirm."));
224 if (icon
->icon
&& icon
->icon
->owner
) {
225 fPtr
= icon
->icon
->owner
->fake_group
;
227 /* is this really necessary? can we kill a non-running dock icon? */
228 Window win
= icon
->main_window
;
231 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)win
);
232 if (index
!= WANotFound
)
233 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
238 if (wPreferences
.dont_confirm_kill
239 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
240 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
242 WWindow
*wwin
, *twin
;
244 wwin
= scr
->focused_window
;
247 if (wwin
->fake_group
== fPtr
) {
252 } else if (icon
->icon
&& icon
->icon
->owner
) {
253 wClientKill(icon
->icon
->owner
);
258 wtokenfree(argv
, argc
);
262 WCHANGE_STATE(WSTATE_NORMAL
);
265 /* TODO: replace this function with a member of the dock struct */
266 static int numberOfSelectedIcons(WDock
* dock
)
272 for (i
= 1; i
< dock
->max_icons
; i
++) {
273 aicon
= dock
->icon_array
[i
];
274 if (aicon
&& aicon
->icon
->selected
) {
282 static WMArray
*getSelected(WDock
* dock
)
284 WMArray
*ret
= WMCreateArray(8);
288 for (i
= 1; i
< dock
->max_icons
; i
++) {
289 btn
= dock
->icon_array
[i
];
290 if (btn
&& btn
->icon
->selected
) {
291 WMAddToArray(ret
, btn
);
298 static void paintClipButtons(WAppIcon
* clipIcon
, Bool lpushed
, Bool rpushed
)
300 Window win
= clipIcon
->icon
->core
->window
;
301 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
303 int pt
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
304 int tp
= ICON_SIZE
- pt
;
305 int as
= pt
- 15; /* 15 = 5+5+5 */
306 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
308 #ifdef GRADIENT_CLIP_ARROW
309 Bool collapsed
= clipIcon
->dock
->collapsed
;
312 /*if (!clipIcon->dock->collapsed)
313 color = scr->clip_title_color[CLIP_NORMAL];
315 color = scr->clip_title_color[CLIP_COLLAPSED]; */
316 color
= scr
->clip_title_color
[CLIP_NORMAL
];
318 XSetForeground(dpy
, gc
, WMColorPixel(color
));
323 p
[1].x
= ICON_SIZE
- 2;
325 p
[2].x
= ICON_SIZE
- 2;
327 } else if (lpushed
) {
331 p
[1].y
= ICON_SIZE
- 2;
333 p
[2].y
= ICON_SIZE
- 2;
335 if (lpushed
|| rpushed
) {
336 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
337 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
338 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
340 #ifdef GRADIENT_CLIP_ARROW
342 XSetFillStyle(dpy
, scr
->copy_gc
, FillTiled
);
343 XSetTile(dpy
, scr
->copy_gc
, scr
->clip_arrow_gradient
);
344 XSetClipMask(dpy
, scr
->copy_gc
, None
);
347 #endif /* GRADIENT_CLIP_ARROW */
349 /* top right arrow */
350 p
[0].x
= p
[3].x
= ICON_SIZE
- 5 - as
;
352 p
[1].x
= ICON_SIZE
- 6;
354 p
[2].x
= ICON_SIZE
- 6;
357 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
358 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
360 #ifdef GRADIENT_CLIP_ARROW
362 XSetTSOrigin(dpy
, gc
, ICON_SIZE
- 6 - as
, 5);
364 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
365 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
368 /* bottom left arrow */
370 p
[0].y
= p
[3].y
= ICON_SIZE
- 5 - as
;
372 p
[1].y
= ICON_SIZE
- 6;
374 p
[2].y
= ICON_SIZE
- 6;
376 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
377 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
379 #ifdef GRADIENT_CLIP_ARROW
381 XSetTSOrigin(dpy
, gc
, 5, ICON_SIZE
- 6 - as
);
383 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
384 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
386 #ifdef GRADIENT_CLIP_ARROW
388 XSetFillStyle(dpy
, scr
->copy_gc
, FillSolid
);
392 RImage
*wClipMakeTile(WScreen
* scr
, RImage
* normalTile
)
394 RImage
*tile
= RCloneImage(normalTile
);
401 pt
= CLIP_BUTTON_SIZE
* wPreferences
.icon_size
/ 64;
402 tp
= wPreferences
.icon_size
- 1 - pt
;
406 black
.red
= black
.green
= black
.blue
= 0;
409 dark
.red
= dark
.green
= dark
.blue
= 60;
412 light
.red
= light
.green
= light
.blue
= 80;
415 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
- 2, pt
- 1, &dark
);
416 RDrawLine(tile
, tp
- 1, 0, wPreferences
.icon_size
- 1, pt
+ 1, &black
);
417 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
- 3, pt
, &light
);
420 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, 4, &dark
);
421 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 5, 6 + as
, &dark
);
422 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
, &light
);
425 ROperateLine(tile
, RAddOperation
, 2, tp
+ 2, pt
- 2, wPreferences
.icon_size
- 3, &dark
);
426 RDrawLine(tile
, 0, tp
- 1, pt
+ 1, wPreferences
.icon_size
- 1, &black
);
427 ROperateLine(tile
, RSubtractOperation
, 0, tp
- 2, pt
+ 1, wPreferences
.icon_size
- 2, &light
);
430 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, &dark
);
431 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
, 6 + as
, ICON_SIZE
- 5, &dark
);
432 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5, &light
);
437 static void omnipresentCallback(WMenu
* menu
, WMenuEntry
* entry
)
439 WAppIcon
*clickedIcon
= entry
->clientdata
;
442 WMArray
*selectedIcons
;
443 WMArrayIterator iter
;
446 assert(entry
->clientdata
!= NULL
);
448 dock
= clickedIcon
->dock
;
450 selectedIcons
= getSelected(dock
);
452 if (!WMGetArrayItemCount(selectedIcons
))
453 WMAddToArray(selectedIcons
, clickedIcon
);
456 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
457 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
459 else if (aicon
->icon
->selected
)
460 wIconSelect(aicon
->icon
);
462 WMFreeArray(selectedIcons
);
465 wMessageDialog(dock
->screen_ptr
, _("Warning"),
466 _("Some icons cannot be made omnipresent. "
467 "Please make sure that no other icon is "
468 "docked in the same positions on the other "
469 "workspaces and the Clip is not full in "
470 "some workspace."), _("OK"), NULL
, NULL
);
471 } else if (failed
== 1) {
472 wMessageDialog(dock
->screen_ptr
, _("Warning"),
473 _("Icon cannot be made omnipresent. "
474 "Please make sure that no other icon is "
475 "docked in the same position on the other "
476 "workspaces and the Clip is not full in "
477 "some workspace."), _("OK"), NULL
, NULL
);
481 static void removeIconsCallback(WMenu
* menu
, WMenuEntry
* entry
)
483 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
486 WMArray
*selectedIcons
;
490 assert(clickedIcon
!= NULL
);
492 dock
= clickedIcon
->dock
;
494 selectedIcons
= getSelected(dock
);
496 if (WMGetArrayItemCount(selectedIcons
)) {
497 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
498 _("All selected icons will be removed!"),
499 _("OK"), _("Cancel"), NULL
) != WAPRDefault
) {
500 WMFreeArray(selectedIcons
);
504 if (clickedIcon
->xindex
== 0 && clickedIcon
->yindex
== 0) {
505 WMFreeArray(selectedIcons
);
508 WMAddToArray(selectedIcons
, clickedIcon
);
511 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
512 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
513 wDockDetach(dock
, aicon
);
515 /* XXX: can: aicon->icon == NULL ? */
516 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
517 wGetHeadForWindow(aicon
->icon
->owner
));
518 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
519 if (!dock
->mapped
|| dock
->collapsed
)
520 XMapWindow(dpy
, aicon
->icon
->core
->window
);
523 WMFreeArray(selectedIcons
);
525 if (wPreferences
.auto_arrange_icons
)
526 wArrangeIcons(dock
->screen_ptr
, True
);
529 static void keepIconsCallback(WMenu
* menu
, WMenuEntry
* entry
)
531 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
534 WMArray
*selectedIcons
;
537 assert(clickedIcon
!= NULL
);
538 dock
= clickedIcon
->dock
;
540 selectedIcons
= getSelected(dock
);
542 if (!WMGetArrayItemCount(selectedIcons
)
543 && clickedIcon
!= dock
->screen_ptr
->clip_icon
) {
544 char *command
= NULL
;
546 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
547 clickedIcon
->editing
= 1;
548 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
549 _("Type the command used to launch the application"), &command
)) {
550 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
554 clickedIcon
->command
= command
;
555 clickedIcon
->editing
= 0;
557 clickedIcon
->editing
= 0;
560 WMFreeArray(selectedIcons
);
565 WMAddToArray(selectedIcons
, clickedIcon
);
568 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
569 if (aicon
->icon
->selected
)
570 wIconSelect(aicon
->icon
);
571 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
572 aicon
->attracted
= 0;
573 if (aicon
->icon
->shadowed
) {
574 aicon
->icon
->shadowed
= 0;
575 aicon
->icon
->force_paint
= 1;
576 wAppIconPaint(aicon
);
581 WMFreeArray(selectedIcons
);
584 static void toggleAutoAttractCallback(WMenu
* menu
, WMenuEntry
* entry
)
586 WDock
*dock
= (WDock
*) entry
->clientdata
;
588 assert(entry
->clientdata
!= NULL
);
590 dock
->attract_icons
= !dock
->attract_icons
;
591 /*if (!dock->attract_icons)
592 dock->keep_attracted = 0; */
594 entry
->flags
.indicator_on
= dock
->attract_icons
;
599 static void selectCallback(WMenu
* menu
, WMenuEntry
* entry
)
601 WAppIcon
*icon
= (WAppIcon
*) entry
->clientdata
;
603 assert(icon
!= NULL
);
605 wIconSelect(icon
->icon
);
610 static void colectIconsCallback(WMenu
* menu
, WMenuEntry
* entry
)
612 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
615 int x
, y
, x_pos
, y_pos
;
617 assert(entry
->clientdata
!= NULL
);
618 clip
= clickedIcon
->dock
;
620 aicon
= clip
->screen_ptr
->app_icon_list
;
623 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
624 x_pos
= clip
->x_pos
+ x
* ICON_SIZE
;
625 y_pos
= clip
->y_pos
+ y
* ICON_SIZE
;
626 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
) {
628 if (wPreferences
.no_animations
) {
629 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
631 SlideWindow(aicon
->icon
->core
->window
,
632 aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
635 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x_pos
, y_pos
);
636 #endif /* ANIMATIONS */
638 aicon
->attracted
= 1;
639 if (!aicon
->icon
->shadowed
) {
640 aicon
->icon
->shadowed
= 1;
641 aicon
->icon
->force_paint
= 1;
642 /* We don't do an wAppIconPaint() here because it's in
643 * wDockAttachIcon(). -Dan
646 wDockAttachIcon(clip
, aicon
, x
, y
);
647 if (clip
->collapsed
|| !clip
->mapped
)
648 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
654 static void selectIconsCallback(WMenu
* menu
, WMenuEntry
* entry
)
656 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
658 WMArray
*selectedIcons
;
659 WMArrayIterator iter
;
663 assert(clickedIcon
!= NULL
);
664 dock
= clickedIcon
->dock
;
666 selectedIcons
= getSelected(dock
);
668 if (!WMGetArrayItemCount(selectedIcons
)) {
669 for (i
= 1; i
< dock
->max_icons
; i
++) {
670 btn
= dock
->icon_array
[i
];
671 if (btn
&& !btn
->icon
->selected
) {
672 wIconSelect(btn
->icon
);
676 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
677 wIconSelect(btn
->icon
);
680 WMFreeArray(selectedIcons
);
685 static void toggleCollapsedCallback(WMenu
* menu
, WMenuEntry
* entry
)
687 assert(entry
->clientdata
!= NULL
);
689 toggleCollapsed(entry
->clientdata
);
691 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->collapsed
;
696 static void toggleAutoCollapseCallback(WMenu
* menu
, WMenuEntry
* entry
)
699 assert(entry
->clientdata
!= NULL
);
701 dock
= (WDock
*) entry
->clientdata
;
703 dock
->auto_collapse
= !dock
->auto_collapse
;
705 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_collapse
;
710 static void toggleAutoRaiseLowerCallback(WMenu
* menu
, WMenuEntry
* entry
)
713 assert(entry
->clientdata
!= NULL
);
715 dock
= (WDock
*) entry
->clientdata
;
717 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
719 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_raise_lower
;
724 static void launchCallback(WMenu
* menu
, WMenuEntry
* entry
)
726 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
728 launchDockedApplication(btn
, False
);
731 static void settingsCallback(WMenu
* menu
, WMenuEntry
* entry
)
733 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
737 ShowDockAppSettingsPanel(btn
);
740 static void hideCallback(WMenu
* menu
, WMenuEntry
* entry
)
743 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
745 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
747 if (wapp
->flags
.hidden
) {
748 wWorkspaceChange(btn
->icon
->core
->screen_ptr
, wapp
->last_workspace
);
749 wUnhideApplication(wapp
, False
, False
);
751 wHideApplication(wapp
);
755 static void unhideHereCallback(WMenu
* menu
, WMenuEntry
* entry
)
758 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
760 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
762 wUnhideApplication(wapp
, False
, True
);
765 WAppIcon
*mainIconCreate(WScreen
* scr
, int type
)
770 if (type
== WM_CLIP
) {
772 return scr
->clip_icon
;
773 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
774 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
775 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
776 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
777 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE; */
780 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
781 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
787 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
788 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
789 btn
->icon
->core
->descriptor
.parent
= btn
;
790 /*ChangeStackingLevel(btn->icon->core, WMDockLevel); */
791 XMapWindow(dpy
, btn
->icon
->core
->window
);
796 scr
->clip_icon
= btn
;
801 static void switchWSCommand(WMenu
* menu
, WMenuEntry
* entry
)
803 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
804 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
806 WMArray
*selectedIcons
;
809 if (entry
->order
== scr
->current_workspace
)
812 dest
= scr
->workspaces
[entry
->order
]->clip
;
814 selectedIcons
= getSelected(src
);
816 if (WMGetArrayItemCount(selectedIcons
)) {
817 WMArrayIterator iter
;
819 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
820 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
821 moveIconBetweenDocks(src
, dest
, btn
, x
, y
);
822 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
825 } else if (icon
!= scr
->clip_icon
) {
826 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
827 moveIconBetweenDocks(src
, dest
, icon
, x
, y
);
828 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
831 WMFreeArray(selectedIcons
);
834 static void launchDockedApplication(WAppIcon
* btn
, Bool withSelection
)
836 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
838 if (!btn
->launching
&&
839 ((!withSelection
&& btn
->command
!= NULL
) || (withSelection
&& btn
->paste_command
!= NULL
))) {
840 if (!btn
->forced_dock
) {
841 btn
->relaunching
= btn
->running
;
844 if (btn
->wm_instance
|| btn
->wm_class
) {
845 WWindowAttributes attr
;
846 memset(&attr
, 0, sizeof(WWindowAttributes
));
847 wDefaultFillAttributes(scr
, btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
849 if (!attr
.no_appicon
&& !btn
->buggy_app
)
854 btn
->drop_launch
= 0;
855 btn
->paste_launch
= withSelection
;
856 scr
->last_dock
= btn
->dock
;
857 btn
->pid
= execCommand(btn
, (withSelection
? btn
->paste_command
: btn
->command
), NULL
);
859 if (btn
->buggy_app
) {
860 /* give feedback that the app was launched */
864 WMAddTimerHandler(200, (WMCallback
*) dockIconPaint
, btn
);
869 wwarning(_("could not launch application %s"), btn
->command
);
871 if (!btn
->relaunching
) {
878 static void updateWorkspaceMenu(WMenu
* menu
, WAppIcon
* icon
)
880 WScreen
*scr
= menu
->frame
->screen_ptr
;
881 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
887 for (i
= 0; i
< scr
->workspace_count
; i
++) {
888 if (i
< menu
->entry_no
) {
889 if (strcmp(menu
->entries
[i
]->text
, scr
->workspaces
[i
]->name
) != 0) {
890 wfree(menu
->entries
[i
]->text
);
891 strcpy(title
, scr
->workspaces
[i
]->name
);
892 menu
->entries
[i
]->text
= wstrdup(title
);
893 menu
->flags
.realized
= 0;
895 menu
->entries
[i
]->clientdata
= (void *)icon
;
897 strcpy(title
, scr
->workspaces
[i
]->name
);
899 wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)icon
);
901 menu
->flags
.realized
= 0;
903 if (i
== scr
->current_workspace
) {
904 wMenuSetEnabled(menu
, i
, False
);
906 wMenuSetEnabled(menu
, i
, True
);
910 if (!menu
->flags
.realized
)
914 static WMenu
*makeWorkspaceMenu(WScreen
* scr
)
918 menu
= wMenuCreate(scr
, NULL
, False
);
920 wwarning(_("could not create workspace submenu for Clip menu"));
922 wMenuAddCallback(menu
, "", switchWSCommand
, (void *)scr
->clip_icon
);
924 menu
->flags
.realized
= 0;
930 static void updateClipOptionsMenu(WMenu
* menu
, WDock
* dock
)
939 entry
= menu
->entries
[index
];
940 entry
->flags
.indicator_on
= !dock
->lowered
;
941 entry
->clientdata
= dock
;
944 entry
= menu
->entries
[++index
];
945 entry
->flags
.indicator_on
= dock
->collapsed
;
946 entry
->clientdata
= dock
;
949 entry
= menu
->entries
[++index
];
950 entry
->flags
.indicator_on
= dock
->auto_collapse
;
951 entry
->clientdata
= dock
;
953 /* auto-raise/lower */
954 entry
= menu
->entries
[++index
];
955 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
956 entry
->clientdata
= dock
;
957 wMenuSetEnabled(menu
, index
, dock
->lowered
);
960 entry
= menu
->entries
[++index
];
961 entry
->flags
.indicator_on
= dock
->attract_icons
;
962 entry
->clientdata
= dock
;
964 menu
->flags
.realized
= 0;
968 static WMenu
*makeClipOptionsMenu(WScreen
* scr
)
973 menu
= wMenuCreate(scr
, NULL
, False
);
975 wwarning(_("could not create options submenu for Clip menu"));
979 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
980 entry
->flags
.indicator
= 1;
981 entry
->flags
.indicator_on
= 1;
982 entry
->flags
.indicator_type
= MI_CHECK
;
984 entry
= wMenuAddCallback(menu
, _("Collapsed"), toggleCollapsedCallback
, NULL
);
985 entry
->flags
.indicator
= 1;
986 entry
->flags
.indicator_on
= 1;
987 entry
->flags
.indicator_type
= MI_CHECK
;
989 entry
= wMenuAddCallback(menu
, _("Autocollapse"), toggleAutoCollapseCallback
, NULL
);
990 entry
->flags
.indicator
= 1;
991 entry
->flags
.indicator_on
= 1;
992 entry
->flags
.indicator_type
= MI_CHECK
;
994 entry
= wMenuAddCallback(menu
, _("Autoraise"), toggleAutoRaiseLowerCallback
, NULL
);
995 entry
->flags
.indicator
= 1;
996 entry
->flags
.indicator_on
= 1;
997 entry
->flags
.indicator_type
= MI_CHECK
;
999 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"), toggleAutoAttractCallback
, NULL
);
1000 entry
->flags
.indicator
= 1;
1001 entry
->flags
.indicator_on
= 1;
1002 entry
->flags
.indicator_type
= MI_CHECK
;
1004 menu
->flags
.realized
= 0;
1010 static WMenu
*dockMenuCreate(WScreen
* scr
, int type
)
1015 if (type
== WM_CLIP
&& scr
->clip_menu
)
1016 return scr
->clip_menu
;
1018 menu
= wMenuCreate(scr
, NULL
, False
);
1019 if (type
!= WM_CLIP
) {
1020 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
1021 entry
->flags
.indicator
= 1;
1022 entry
->flags
.indicator_on
= 1;
1023 entry
->flags
.indicator_type
= MI_CHECK
;
1025 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1026 scr
->clip_options
= makeClipOptionsMenu(scr
);
1027 if (scr
->clip_options
)
1028 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1030 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1032 entry
->text
= _("Rename Workspace");
1034 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1035 entry
->flags
.indicator
= 1;
1036 entry
->flags
.indicator_on
= 1;
1037 entry
->flags
.indicator_type
= MI_CHECK
;
1039 entry
= wMenuAddCallback(menu
, _("Select All Icons"), selectIconsCallback
, NULL
);
1041 entry
->text
= _("Select All Icons");
1043 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1045 entry
->text
= _("Keep Icon");
1047 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1049 entry
->text
= _("Move Icon To");
1050 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1051 if (scr
->clip_submenu
)
1052 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1054 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
, NULL
);
1056 entry
->text
= _("Remove Icon");
1058 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1061 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1063 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1065 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1067 entry
->text
= _("Hide");
1069 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1071 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1073 if (type
== WM_CLIP
)
1074 scr
->clip_menu
= menu
;
1079 WDock
*wDockCreate(WScreen
* scr
, int type
)
1087 dock
= wmalloc(sizeof(WDock
));
1088 memset(dock
, 0, sizeof(WDock
));
1090 if (type
== WM_CLIP
)
1091 icon_count
= CLIP_MAX_ICONS
;
1093 icon_count
= scr
->scr_height
/ wPreferences
.icon_size
;
1095 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * icon_count
);
1096 memset(dock
->icon_array
, 0, sizeof(WAppIcon
*) * icon_count
);
1098 dock
->max_icons
= icon_count
;
1100 btn
= mainIconCreate(scr
, type
);
1104 dock
->x_pos
= btn
->x_pos
;
1105 dock
->y_pos
= btn
->y_pos
;
1106 dock
->screen_ptr
= scr
;
1108 dock
->icon_count
= 1;
1109 dock
->on_right_side
= 1;
1110 dock
->collapsed
= 0;
1111 dock
->auto_collapse
= 0;
1112 dock
->auto_collapse_magic
= NULL
;
1113 dock
->auto_raise_lower
= 0;
1114 dock
->auto_lower_magic
= NULL
;
1115 dock
->auto_raise_magic
= NULL
;
1116 dock
->attract_icons
= 0;
1118 dock
->icon_array
[0] = btn
;
1119 wRaiseFrame(btn
->icon
->core
);
1120 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1122 /* create dock menu */
1123 dock
->menu
= dockMenuCreate(scr
, type
);
1128 void wDockDestroy(WDock
* dock
)
1133 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1134 aicon
= dock
->icon_array
[i
];
1136 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1137 wDockDetach(dock
, aicon
);
1139 /* XXX: can: aicon->icon == NULL ? */
1140 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1141 wGetHeadForWindow(aicon
->icon
->owner
));
1142 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1143 if (!dock
->mapped
|| dock
->collapsed
)
1144 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1148 if (wPreferences
.auto_arrange_icons
)
1149 wArrangeIcons(dock
->screen_ptr
, True
);
1150 wfree(dock
->icon_array
);
1151 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1152 wMenuDestroy(dock
->menu
, True
);
1153 if (dock
->screen_ptr
->last_dock
== dock
)
1154 dock
->screen_ptr
->last_dock
= NULL
;
1158 void wClipIconPaint(WAppIcon
* aicon
)
1160 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1161 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1163 Window win
= aicon
->icon
->core
->window
;
1164 int length
, nlength
;
1165 char *ws_name
, ws_number
[10];
1168 wIconPaint(aicon
->icon
);
1170 length
= strlen(workspace
->name
);
1171 ws_name
= wmalloc(length
+ 1);
1172 snprintf(ws_name
, length
+ 1, "%s", workspace
->name
);
1173 snprintf(ws_number
, sizeof(ws_number
), "%i", scr
->current_workspace
+ 1);
1174 nlength
= strlen(ws_number
);
1176 if (!workspace
->clip
->collapsed
)
1177 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1179 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1181 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1183 tx
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
1185 if(wPreferences
.show_clip_title
)
1186 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, ty
, ws_name
, length
);
1187 /*WMDrawString(scr->wmscreen, win, color, scr->clip_title_font, 4,
1188 2, ws_name, length); */
1190 tx
= (ICON_SIZE
/ 2 - WMWidthOfString(scr
->clip_title_font
, ws_number
, nlength
)) / 2;
1192 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, 2, ws_number
, nlength
);
1196 if (aicon
->launching
) {
1197 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1198 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1200 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
, aicon
->dock
->rclip_button_pushed
);
1203 static void clipIconExpose(WObjDescriptor
* desc
, XEvent
* event
)
1205 wClipIconPaint(desc
->parent
);
1208 static void dockIconPaint(WAppIcon
* btn
)
1210 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1211 wClipIconPaint(btn
);
1218 static WMPropList
*make_icon_state(WAppIcon
* btn
)
1220 WMPropList
*node
= NULL
;
1221 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
, *host
;
1222 WMPropList
*position
, *buggy
, *omnipresent
;
1228 command
= WMCreatePLString("-");
1230 command
= WMCreatePLString(btn
->command
);
1232 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1234 lock
= btn
->lock
? dYes
: dNo
;
1236 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1238 name
= WMCreatePLString(tmp
);
1242 forced
= btn
->forced_dock
? dYes
: dNo
;
1244 buggy
= btn
->buggy_app
? dYes
: dNo
;
1246 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1247 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1249 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1250 position
= WMCreatePLString(buffer
);
1252 node
= WMCreatePLDictionary(dCommand
, command
,
1254 dAutoLaunch
, autolaunch
,
1256 dForced
, forced
, dBuggyApplication
, buggy
, dPosition
, position
, NULL
);
1257 WMReleasePropList(command
);
1258 WMReleasePropList(name
);
1259 WMReleasePropList(position
);
1261 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1262 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&& (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1263 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1265 #ifdef XDND /* was OFFIX */
1266 if (btn
->dnd_command
) {
1267 command
= WMCreatePLString(btn
->dnd_command
);
1268 WMPutInPLDictionary(node
, dDropCommand
, command
);
1269 WMReleasePropList(command
);
1273 if (btn
->paste_command
) {
1274 command
= WMCreatePLString(btn
->paste_command
);
1275 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1276 WMReleasePropList(command
);
1279 if (btn
->client_machine
&& btn
->remote_start
) {
1280 host
= WMCreatePLString(btn
->client_machine
);
1281 WMPutInPLDictionary(node
, dHost
, host
);
1282 WMReleasePropList(host
);
1289 static WMPropList
*dockSaveState(WDock
* dock
)
1292 WMPropList
*icon_info
;
1293 WMPropList
*list
= NULL
, *dock_state
= NULL
;
1294 WMPropList
*value
, *key
;
1297 list
= WMCreatePLArray(NULL
);
1299 for (i
= (dock
->type
== WM_DOCK
? 0 : 1); i
< dock
->max_icons
; i
++) {
1300 WAppIcon
*btn
= dock
->icon_array
[i
];
1302 if (!btn
|| btn
->attracted
)
1305 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1306 WMAddToPLArray(list
, icon_info
);
1307 WMReleasePropList(icon_info
);
1311 dock_state
= WMCreatePLDictionary(dApplications
, list
, NULL
);
1313 if (dock
->type
== WM_DOCK
) {
1314 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1315 key
= WMCreatePLString(buffer
);
1316 WMPutInPLDictionary(dock_state
, key
, list
);
1317 WMReleasePropList(key
);
1319 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0), dock
->y_pos
);
1320 value
= WMCreatePLString(buffer
);
1321 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1322 WMReleasePropList(value
);
1324 WMReleasePropList(list
);
1326 value
= (dock
->lowered
? dYes
: dNo
);
1327 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1329 if (dock
->type
== WM_CLIP
) {
1330 value
= (dock
->collapsed
? dYes
: dNo
);
1331 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1333 value
= (dock
->auto_collapse
? dYes
: dNo
);
1334 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1336 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1337 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1339 value
= (dock
->attract_icons
? dYes
: dNo
);
1340 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1346 void wDockSaveState(WScreen
* scr
, WMPropList
* old_state
)
1348 WMPropList
*dock_state
;
1351 dock_state
= dockSaveState(scr
->dock
);
1354 * Copy saved states of docks with different sizes.
1360 keys
= WMGetPLDictionaryKeys(old_state
);
1361 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1362 tmp
= WMGetFromPLArray(keys
, i
);
1364 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1365 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1367 WMPutInPLDictionary(dock_state
, tmp
, WMGetFromPLDictionary(old_state
, tmp
));
1370 WMReleasePropList(keys
);
1373 WMPutInPLDictionary(scr
->session_state
, dDock
, dock_state
);
1375 WMReleasePropList(dock_state
);
1378 void wClipSaveState(WScreen
* scr
)
1380 WMPropList
*clip_state
;
1382 clip_state
= make_icon_state(scr
->clip_icon
);
1384 WMPutInPLDictionary(scr
->session_state
, dClip
, clip_state
);
1386 WMReleasePropList(clip_state
);
1389 WMPropList
*wClipSaveWorkspaceState(WScreen
* scr
, int workspace
)
1391 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1394 static Bool
getBooleanDockValue(WMPropList
* value
, WMPropList
* key
)
1397 if (WMIsPLString(value
)) {
1398 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1401 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1407 static WAppIcon
*restore_icon_state(WScreen
* scr
, WMPropList
* info
, int type
, int index
)
1410 WMPropList
*cmd
, *value
;
1412 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1413 if (!cmd
|| !WMIsPLString(cmd
)) {
1417 /* parse window name */
1418 value
= WMGetFromPLDictionary(info
, dName
);
1423 char *wclass
, *winstance
;
1426 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1428 if (!winstance
&& !wclass
) {
1435 command
= wstrdup(WMGetFromPLString(cmd
));
1439 if (!command
|| strcmp(command
, "-") == 0) {
1450 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1459 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1460 if (type
== WM_CLIP
) {
1461 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1462 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1464 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1465 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1467 #ifdef XDND /* was OFFIX */
1468 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1470 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1473 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1475 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1477 /* check auto launch */
1478 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1480 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1483 value
= WMGetFromPLDictionary(info
, dLock
);
1485 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1487 /* check if it wasn't normally docked */
1488 value
= WMGetFromPLDictionary(info
, dForced
);
1490 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1492 /* check if we can rely on the stuff in the app */
1493 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1495 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1497 /* get position in the dock */
1498 value
= WMGetFromPLDictionary(info
, dPosition
);
1499 if (value
&& WMIsPLString(value
)) {
1500 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1501 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1503 /* check position sanity */
1504 /* incomplete section! */
1505 if (type
== WM_DOCK
) {
1507 if (aicon
->yindex
< 0)
1508 wwarning(_("bad value in docked icon position %i,%i"),
1509 aicon
->xindex
, aicon
->yindex
);
1512 aicon
->yindex
= index
;
1516 /* check if icon is omnipresent */
1517 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1519 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1527 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1529 WAppIcon
*wClipRestoreState(WScreen
* scr
, WMPropList
* clip_state
)
1534 icon
= mainIconCreate(scr
, WM_CLIP
);
1539 WMRetainPropList(clip_state
);
1541 /* restore position */
1543 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1546 if (!WMIsPLString(value
))
1547 COMPLAIN("Position");
1552 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1553 COMPLAIN("Position");
1555 /* check position sanity */
1556 rect
.pos
.x
= icon
->x_pos
;
1557 rect
.pos
.y
= icon
->y_pos
;
1558 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1560 wGetRectPlacementInfo(scr
, rect
, &flags
);
1561 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
1562 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1565 #ifdef XDND /* was OFFIX */
1566 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1567 if (value
&& WMIsPLString(value
))
1568 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1571 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1572 if (value
&& WMIsPLString(value
))
1573 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1575 WMReleasePropList(clip_state
);
1580 WDock
*wDockRestoreState(WScreen
* scr
, WMPropList
* dock_state
, int type
)
1585 WAppIcon
*aicon
, *old_top
;
1588 dock
= wDockCreate(scr
, type
);
1593 WMRetainPropList(dock_state
);
1595 /* restore position */
1597 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1600 if (!WMIsPLString(value
)) {
1601 COMPLAIN("Position");
1606 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1607 COMPLAIN("Position");
1609 /* check position sanity */
1610 rect
.pos
.x
= dock
->x_pos
;
1611 rect
.pos
.y
= dock
->y_pos
;
1612 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
1614 wGetRectPlacementInfo(scr
, rect
, &flags
);
1615 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
)) {
1616 int x
= dock
->x_pos
;
1617 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1620 /* Is this needed any more? */
1621 if (type
== WM_CLIP
) {
1622 if (dock
->x_pos
< 0) {
1624 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1625 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1628 if (dock
->x_pos
>= 0) {
1629 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1630 dock
->on_right_side
= 0;
1632 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1633 dock
->on_right_side
= 1;
1639 /* restore lowered/raised state */
1643 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1646 if (!WMIsPLString(value
)) {
1647 COMPLAIN("Lowered");
1649 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1655 /* restore collapsed state */
1657 dock
->collapsed
= 0;
1659 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1662 if (!WMIsPLString(value
)) {
1663 COMPLAIN("Collapsed");
1665 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1666 dock
->collapsed
= 1;
1671 /* restore auto-collapsed state */
1673 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1676 if (!WMIsPLString(value
)) {
1677 COMPLAIN("AutoCollapse");
1679 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1680 dock
->auto_collapse
= 1;
1681 dock
->collapsed
= 1;
1686 /* restore auto-raise/lower state */
1688 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1691 if (!WMIsPLString(value
)) {
1692 COMPLAIN("AutoRaiseLower");
1694 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1695 dock
->auto_raise_lower
= 1;
1700 /* restore attract icons state */
1702 dock
->attract_icons
= 0;
1704 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1707 if (!WMIsPLString(value
)) {
1708 COMPLAIN("AutoAttractIcons");
1710 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1711 dock
->attract_icons
= 1;
1716 /* application list */
1723 * When saving, it saves the dock state in
1724 * Applications and Applicationsnnn
1726 * When loading, it will first try Applicationsnnn.
1727 * If it does not exist, use Applications as default.
1730 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1732 tmp
= WMCreatePLString(buffer
);
1733 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1734 WMReleasePropList(tmp
);
1737 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1745 count
= WMGetPropListItemCount(apps
);
1750 old_top
= dock
->icon_array
[0];
1752 /* dock->icon_count is set to 1 when dock is created.
1753 * Since Clip is already restored, we want to keep it so for clip,
1754 * but for dock we may change the default top tile, so we set it to 0.
1756 if (type
== WM_DOCK
)
1757 dock
->icon_count
= 0;
1759 for (i
= 0; i
< count
; i
++) {
1760 if (dock
->icon_count
>= dock
->max_icons
) {
1761 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1765 value
= WMGetFromPLArray(apps
, i
);
1766 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1768 dock
->icon_array
[dock
->icon_count
] = aicon
;
1772 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1773 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1776 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1778 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1780 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1782 if (!dock
->collapsed
)
1783 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1784 wRaiseFrame(aicon
->icon
->core
);
1787 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
)
1791 /* if the first icon is not defined, use the default */
1792 if (dock
->icon_array
[0] == NULL
) {
1793 /* update default icon */
1794 old_top
->x_pos
= dock
->x_pos
;
1795 old_top
->y_pos
= dock
->y_pos
;
1797 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1799 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1800 dock
->icon_array
[0] = old_top
;
1801 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1802 /* we don't need to increment dock->icon_count here because it was
1803 * incremented in the loop above.
1805 } else if (old_top
!= dock
->icon_array
[0]) {
1806 if (old_top
== scr
->clip_icon
)
1807 scr
->clip_icon
= dock
->icon_array
[0];
1808 wAppIconDestroy(old_top
);
1812 WMReleasePropList(dock_state
);
1817 void wDockLaunchWithState(WDock
* dock
, WAppIcon
* btn
, WSavedState
* state
)
1819 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1821 btn
->drop_launch
= 0;
1822 btn
->paste_launch
= 0;
1824 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1827 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1837 void wDockDoAutoLaunch(WDock
* dock
, int workspace
)
1843 for (i
= 0; i
< dock
->max_icons
; i
++) {
1844 btn
= dock
->icon_array
[i
];
1845 if (!btn
|| !btn
->auto_launch
)
1848 state
= wmalloc(sizeof(WSavedState
));
1849 memset(state
, 0, sizeof(WSavedState
));
1850 state
->workspace
= workspace
;
1851 /* TODO: this is klugy and is very difficult to understand
1852 * what's going on. Try to clean up */
1853 wDockLaunchWithState(dock
, btn
, state
);
1857 #ifdef XDND /* was OFFIX */
1858 static WDock
*findDock(WScreen
* scr
, XEvent
* event
, int *icon_pos
)
1864 if ((dock
= scr
->dock
) != NULL
) {
1865 for (i
= 0; i
< dock
->max_icons
; i
++) {
1866 if (dock
->icon_array
[i
]
1867 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1873 if (*icon_pos
< 0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
) != NULL
) {
1874 for (i
= 0; i
< dock
->max_icons
; i
++) {
1875 if (dock
->icon_array
[i
]
1876 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1887 int wDockReceiveDNDDrop(WScreen
* scr
, XEvent
* event
)
1893 dock
= findDock(scr
, event
, &icon_pos
);
1898 * Return True if the drop was on an application icon window.
1899 * In this case, let the ClientMessage handler redirect the
1900 * message to the app.
1902 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
1905 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
1906 scr
->flags
.dnd_data_convertion_status
= 0;
1908 btn
= dock
->icon_array
[icon_pos
];
1910 if (!btn
->forced_dock
) {
1911 btn
->relaunching
= btn
->running
;
1914 if (btn
->wm_instance
|| btn
->wm_class
) {
1915 WWindowAttributes attr
;
1916 memset(&attr
, 0, sizeof(WWindowAttributes
));
1917 wDefaultFillAttributes(btn
->icon
->core
->screen_ptr
,
1918 btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
1920 if (!attr
.no_appicon
)
1926 btn
->paste_launch
= 0;
1927 btn
->drop_launch
= 1;
1928 scr
->last_dock
= dock
;
1929 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1934 if (!btn
->relaunching
) {
1943 Bool
wDockAttachIcon(WDock
* dock
, WAppIcon
* icon
, int x
, int y
)
1948 wwin
= icon
->icon
->owner
;
1949 if (icon
->command
== NULL
) {
1954 command
= GetCommandForWindow(wwin
->client_win
);
1956 icon
->command
= command
;
1958 /* icon->forced_dock = 1; */
1959 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
1961 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
1962 _("Type the command used to launch the application"), &command
)) {
1963 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
1967 icon
->command
= command
;
1973 /* If the target is the dock, reject the icon. If
1974 * the target is the clip, make it an attracted icon
1976 if (dock
->type
== WM_CLIP
) {
1977 icon
->attracted
= 1;
1978 if (!icon
->icon
->shadowed
) {
1979 icon
->icon
->shadowed
= 1;
1980 icon
->icon
->force_paint
= 1;
1992 for (index
= 1; index
< dock
->max_icons
; index
++)
1993 if (dock
->icon_array
[index
] == NULL
)
1995 /* if (index == dock->max_icons)
1998 assert(index
< dock
->max_icons
);
2000 dock
->icon_array
[index
] = icon
;
2004 icon
->omnipresent
= 0;
2006 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2007 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2012 icon
->launching
= 0;
2015 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2016 if (dock
->type
== WM_CLIP
) {
2017 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2018 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2020 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2021 icon
->icon
->core
->descriptor
.parent
= icon
;
2023 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2024 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2025 wAppIconPaint(icon
);
2028 if (wPreferences
.auto_arrange_icons
)
2029 wArrangeIcons(dock
->screen_ptr
, True
);
2031 #ifdef XDND /* was OFFIX */
2032 if (icon
->command
&& !icon
->dnd_command
) {
2033 int len
= strlen(icon
->command
) + 8;
2034 icon
->dnd_command
= wmalloc(len
);
2035 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
2039 if (icon
->command
&& !icon
->paste_command
) {
2040 int len
= strlen(icon
->command
) + 8;
2041 icon
->paste_command
= wmalloc(len
);
2042 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
2048 void reattachIcon(WDock
* dock
, WAppIcon
* icon
, int x
, int y
)
2052 for (index
= 1; index
< dock
->max_icons
; index
++) {
2053 if (dock
->icon_array
[index
] == icon
)
2056 assert(index
< dock
->max_icons
);
2061 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2062 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2065 Bool
moveIconBetweenDocks(WDock
* src
, WDock
* dest
, WAppIcon
* icon
, int x
, int y
)
2072 return True
; /* No move needed, we're already there */
2077 wwin
= icon
->icon
->owner
;
2080 * For the moment we can't do this if we move icons in Clip from one
2081 * workspace to other, because if we move two or more icons without
2082 * command, the dialog box will not be able to tell us to which of the
2083 * moved icons it applies. -Dan
2085 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
2086 command
= GetCommandForWindow(wwin
->client_win
);
2088 icon
->command
= command
;
2091 /* icon->forced_dock = 1; */
2092 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2093 _("Type the command used to launch the application"), &command
)) {
2094 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2098 icon
->command
= command
;
2109 if (dest
->type
== WM_DOCK
)
2110 wClipMakeIconOmnipresent(icon
, False
);
2112 for (index
= 1; index
< src
->max_icons
; index
++) {
2113 if (src
->icon_array
[index
] == icon
)
2116 assert(index
< src
->max_icons
);
2118 src
->icon_array
[index
] = NULL
;
2121 for (index
= 1; index
< dest
->max_icons
; index
++) {
2122 if (dest
->icon_array
[index
] == NULL
)
2125 /* if (index == dest->max_icons)
2128 assert(index
< dest
->max_icons
);
2130 dest
->icon_array
[index
] = icon
;
2133 /* deselect the icon */
2134 if (icon
->icon
->selected
)
2135 wIconSelect(icon
->icon
);
2137 if (dest
->type
== WM_DOCK
) {
2138 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2139 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2141 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2142 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2145 /* set it to be kept when moving to dock.
2146 * Unless the icon does not have a command set
2148 if (icon
->command
&& dest
->type
== WM_DOCK
) {
2149 icon
->attracted
= 0;
2150 if (icon
->icon
->shadowed
) {
2151 icon
->icon
->shadowed
= 0;
2152 icon
->icon
->force_paint
= 1;
2157 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2163 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2164 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2168 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2169 wAppIconPaint(icon
);
2174 void wDockDetach(WDock
* dock
, WAppIcon
* icon
)
2178 /* make the settings panel be closed */
2180 DestroyDockAppSettingsPanel(icon
->panel
);
2183 /* This must be called before icon->dock is set to NULL.
2184 * Don't move it. -Dan
2186 wClipMakeIconOmnipresent(icon
, False
);
2190 icon
->attracted
= 0;
2191 icon
->auto_launch
= 0;
2192 if (icon
->icon
->shadowed
) {
2193 icon
->icon
->shadowed
= 0;
2194 icon
->icon
->force_paint
= 1;
2197 /* deselect the icon */
2198 if (icon
->icon
->selected
)
2199 wIconSelect(icon
->icon
);
2201 if (icon
->command
) {
2202 wfree(icon
->command
);
2203 icon
->command
= NULL
;
2205 #ifdef XDND /* was OFFIX */
2206 if (icon
->dnd_command
) {
2207 wfree(icon
->dnd_command
);
2208 icon
->dnd_command
= NULL
;
2211 if (icon
->paste_command
) {
2212 wfree(icon
->paste_command
);
2213 icon
->paste_command
= NULL
;
2216 for (index
= 1; index
< dock
->max_icons
; index
++)
2217 if (dock
->icon_array
[index
] == icon
)
2219 assert(index
< dock
->max_icons
);
2220 dock
->icon_array
[index
] = NULL
;
2226 /* if the dock is not attached to an application or
2227 * the the application did not set the approriate hints yet,
2228 * destroy the icon */
2229 if (!icon
->running
|| !wApplicationOf(icon
->main_window
))
2230 wAppIconDestroy(icon
);
2232 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2233 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2234 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2235 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2236 icon
->icon
->core
->descriptor
.parent
= icon
;
2238 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2240 wAppIconPaint(icon
);
2241 if (wPreferences
.auto_arrange_icons
) {
2242 wArrangeIcons(dock
->screen_ptr
, True
);
2245 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2250 * returns the closest Dock slot index for the passed
2253 * Returns False if icon can't be docked.
2255 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2258 Bool
wDockSnapIcon(WDock
* dock
, WAppIcon
* icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2260 WScreen
*scr
= dock
->screen_ptr
;
2263 int i
, offset
= ICON_SIZE
/ 2;
2264 WAppIcon
*aicon
= NULL
;
2265 WAppIcon
*nicon
= NULL
;
2268 /* TODO: XINERAMA, for these */
2269 max_y_icons
= scr
->scr_height
/ ICON_SIZE
- 1;
2271 if (wPreferences
.flags
.noupdates
)
2277 /* if the dock is full */
2278 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
)) {
2282 /* exact position */
2284 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2286 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2289 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2291 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2293 /* check if the icon is outside the screen boundaries */
2298 rect
.pos
.x
= dx
+ ex_x
* ICON_SIZE
;
2299 rect
.pos
.y
= dy
+ ex_y
* ICON_SIZE
;
2300 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2302 wGetRectPlacementInfo(scr
, rect
, &flags
);
2303 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
))
2307 if (dock
->type
== WM_DOCK
) {
2308 if (icon
->dock
!= dock
&& ex_x
!= 0)
2312 for (i
= 0; i
< dock
->max_icons
; i
++) {
2313 nicon
= dock
->icon_array
[i
];
2314 if (nicon
&& nicon
->yindex
== ex_y
) {
2321 int sig
, done
, closest
;
2323 /* Possible cases when redocking:
2325 * icon dragged out of range of any slot -> false
2326 * icon dragged to range of free slot
2327 * icon dragged to range of same slot
2328 * icon dragged to range of different icon
2330 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2333 if (ex_y
>= 0 && ex_y
<= max_y_icons
&& (aicon
== icon
|| !aicon
)) {
2339 /* start looking at the upper slot or lower? */
2340 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2347 /* look for closest free slot */
2348 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2352 closest
= sig
* (i
/ 2) + ex_y
;
2353 /* check if this slot is used */
2355 for (j
= 0; j
< dock
->max_icons
; j
++) {
2356 if (dock
->icon_array
[j
]
2357 && dock
->icon_array
[j
]->yindex
== closest
) {
2358 /* slot is used by someone else */
2359 if (dock
->icon_array
[j
] != icon
)
2367 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2368 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2369 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2374 } else { /* !redocking */
2376 /* if slot is free and the icon is close enough, return it */
2377 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2387 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2388 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+ 1;
2391 for (k
= start
; k
< stop
; k
++) {
2392 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2395 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2396 nicon
= tmp
->icon_array
[i
];
2397 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2405 for (k
= start
; k
< stop
; k
++) {
2406 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2409 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2410 nicon
= tmp
->icon_array
[i
];
2411 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2412 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2413 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2422 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2431 static int onScreen(WScreen
* scr
, int x
, int y
, int sx
, int ex
, int sy
, int ey
)
2433 WMRect rect
= wmkrect(x
, y
, ICON_SIZE
, ICON_SIZE
);
2436 wGetRectPlacementInfo(scr
, rect
, &flags
);
2438 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2442 * returns true if it can find a free slot in the dock,
2443 * in which case it changes x_pos and y_pos accordingly.
2444 * Else returns false.
2446 Bool
wDockFindFreeSlot(WDock
* dock
, int *x_pos
, int *y_pos
)
2448 WScreen
*scr
= dock
->screen_ptr
;
2450 WAppIconChain
*chain
;
2451 unsigned char *slot_map
;
2455 int i
, done
= False
;
2457 int sx
= 0, sy
= 0, ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2458 int extra_count
= 0;
2460 if (dock
->type
== WM_CLIP
&& dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2461 extra_count
= scr
->global_icon_count
;
2463 /* if the dock is full */
2464 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
) {
2468 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2469 if (scr
->dock
->on_right_side
)
2470 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2472 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2475 if (ex
< dock
->x_pos
)
2477 if (sx
> dock
->x_pos
+ ICON_SIZE
)
2478 sx
= dock
->x_pos
+ ICON_SIZE
;
2485 /* check if clip is in a corner */
2486 if (dock
->type
== WM_CLIP
) {
2487 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2489 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2491 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2493 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2500 /* If the clip is in the corner, use only slots that are in the border
2502 if (corner
!= C_NONE
) {
2506 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2507 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2508 hmap
= wmalloc(hcount
+ 1);
2509 memset(hmap
, 0, hcount
+ 1);
2510 vmap
= wmalloc(vcount
+ 1);
2511 memset(vmap
, 0, vcount
+ 1);
2513 /* mark used positions */
2516 for (i
= 0; i
< dock
->max_icons
; i
++) {
2517 btn
= dock
->icon_array
[i
];
2521 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2522 vmap
[btn
->yindex
] = 1;
2523 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2524 hmap
[btn
->xindex
] = 1;
2526 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2528 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2529 vmap
[btn
->yindex
] = 1;
2530 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2531 hmap
[btn
->xindex
] = 1;
2535 for (i
= 0; i
< dock
->max_icons
; i
++) {
2536 btn
= dock
->icon_array
[i
];
2540 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2541 vmap
[btn
->yindex
] = 1;
2542 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2543 hmap
[-btn
->xindex
] = 1;
2545 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2547 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2548 vmap
[btn
->yindex
] = 1;
2549 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2550 hmap
[-btn
->xindex
] = 1;
2554 for (i
= 0; i
< dock
->max_icons
; i
++) {
2555 btn
= dock
->icon_array
[i
];
2559 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2560 vmap
[-btn
->yindex
] = 1;
2561 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2562 hmap
[btn
->xindex
] = 1;
2564 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2566 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2567 vmap
[-btn
->yindex
] = 1;
2568 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2569 hmap
[btn
->xindex
] = 1;
2574 for (i
= 0; i
< dock
->max_icons
; i
++) {
2575 btn
= dock
->icon_array
[i
];
2579 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2580 vmap
[-btn
->yindex
] = 1;
2581 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2582 hmap
[-btn
->xindex
] = 1;
2584 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2586 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2587 vmap
[-btn
->yindex
] = 1;
2588 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2589 hmap
[-btn
->xindex
] = 1;
2595 /* search a vacant slot */
2596 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2597 if (i
< vcount
&& vmap
[i
] == 0) {
2603 } else if (i
< hcount
&& hmap
[i
] == 0) {
2613 /* If found a slot, translate and return */
2615 if (corner
== C_NW
|| corner
== C_NE
) {
2620 if (corner
== C_NE
|| corner
== C_SE
) {
2627 /* else, try to find a slot somewhere else */
2630 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2631 * placed outside of screen */
2632 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2634 /* In the worst case (the clip is in the corner of the screen),
2635 * the amount of icons that fit in the clip is smaller.
2636 * Double the map to get a safe value.
2640 r
= (mwidth
- 1) / 2;
2642 slot_map
= wmalloc(mwidth
* mwidth
);
2643 memset(slot_map
, 0, mwidth
* mwidth
);
2645 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2647 /* mark used slots in the map. If the slot falls outside the map
2648 * (for example, when all icons are placed in line), ignore them. */
2649 for (i
= 0; i
< dock
->max_icons
; i
++) {
2650 btn
= dock
->icon_array
[i
];
2652 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2654 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2655 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2657 /* Find closest slot from the center that is free by scanning the
2658 * map from the center to outward in circular passes.
2659 * This will not result in a neat layout, but will be optimal
2660 * in the sense that there will not be holes left.
2663 for (i
= 1; i
<= r
&& !done
; i
++) {
2666 /* top and bottom parts of the ring */
2667 for (x
= -i
; x
<= i
&& !done
; x
++) {
2668 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2670 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2671 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2678 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2679 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2686 /* left and right parts of the ring */
2687 for (y
= -i
+ 1; y
<= i
- 1; y
++) {
2688 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2690 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2691 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2698 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2699 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
, sx
, ex
, sy
, ey
)) {
2712 static void moveDock(WDock
* dock
, int new_x
, int new_y
)
2717 dock
->x_pos
= new_x
;
2718 dock
->y_pos
= new_y
;
2719 for (i
= 0; i
< dock
->max_icons
; i
++) {
2720 btn
= dock
->icon_array
[i
];
2722 btn
->x_pos
= new_x
+ btn
->xindex
* ICON_SIZE
;
2723 btn
->y_pos
= new_y
+ btn
->yindex
* ICON_SIZE
;
2724 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2729 static void swapDock(WDock
* dock
)
2731 WScreen
*scr
= dock
->screen_ptr
;
2735 if (dock
->on_right_side
) {
2736 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2738 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2741 for (i
= 0; i
< dock
->max_icons
; i
++) {
2742 btn
= dock
->icon_array
[i
];
2745 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2749 wScreenUpdateUsableArea(scr
);
2752 static pid_t
execCommand(WAppIcon
* btn
, char *command
, WSavedState
* state
)
2754 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2760 cmdline
= ExpandOptions(scr
, command
);
2762 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2770 wtokensplit(cmdline
, &argv
, &argc
);
2780 if ((pid
= fork()) == 0) {
2784 SetupEnvironment(scr
);
2790 args
= malloc(sizeof(char *) * (argc
+ 1));
2793 for (i
= 0; i
< argc
; i
++) {
2797 execvp(argv
[0], args
);
2800 wtokenfree(argv
, argc
);
2804 state
= wmalloc(sizeof(WSavedState
));
2805 memset(state
, 0, sizeof(WSavedState
));
2807 state
->miniaturized
= -1;
2809 if (btn
->dock
== scr
->dock
|| btn
->omnipresent
)
2810 state
->workspace
= -1;
2812 state
->workspace
= scr
->current_workspace
;
2814 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
2815 wAddDeathHandler(pid
, (WDeathHandler
*) trackDeadProcess
, btn
->dock
);
2823 void wDockHideIcons(WDock
* dock
)
2830 for (i
= 1; i
< dock
->max_icons
; i
++) {
2831 if (dock
->icon_array
[i
])
2832 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2836 dockIconPaint(dock
->icon_array
[0]);
2839 void wDockShowIcons(WDock
* dock
)
2847 btn
= dock
->icon_array
[0];
2848 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2850 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2851 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2853 for (i
= 1; i
< dock
->max_icons
; i
++) {
2854 if (dock
->icon_array
[i
]) {
2855 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
, btn
->icon
->core
);
2860 if (!dock
->collapsed
) {
2861 for (i
= 1; i
< dock
->max_icons
; i
++) {
2862 if (dock
->icon_array
[i
]) {
2863 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2872 void wDockLower(WDock
* dock
)
2876 for (i
= 0; i
< dock
->max_icons
; i
++) {
2877 if (dock
->icon_array
[i
])
2878 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2882 void wDockRaise(WDock
* dock
)
2886 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
2887 if (dock
->icon_array
[i
])
2888 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2892 void wDockRaiseLower(WDock
* dock
)
2894 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2895 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2896 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2902 void wDockFinishLaunch(WDock
* dock
, WAppIcon
* icon
)
2904 icon
->launching
= 0;
2905 icon
->relaunching
= 0;
2906 dockIconPaint(icon
);
2909 WAppIcon
*wDockFindIconForWindow(WDock
* dock
, Window window
)
2914 for (i
= 0; i
< dock
->max_icons
; i
++) {
2915 icon
= dock
->icon_array
[i
];
2916 if (icon
&& icon
->main_window
== window
)
2922 void wDockTrackWindowLaunch(WDock
* dock
, Window window
)
2925 char *wm_class
, *wm_instance
;
2927 Bool firstPass
= True
;
2929 char *command
= NULL
;
2931 command
= GetCommandForWindow(window
);
2933 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) || (!wm_class
&& !wm_instance
)) {
2941 for (i
= 0; i
< dock
->max_icons
; i
++) {
2942 icon
= dock
->icon_array
[i
];
2946 /* app is already attached to icon */
2947 if (icon
->main_window
== window
) {
2952 if ((icon
->wm_instance
|| icon
->wm_class
)
2953 && (icon
->launching
|| !icon
->running
)) {
2955 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0) {
2958 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0) {
2961 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0) {
2965 if (!icon
->relaunching
) {
2968 /* Possibly an application that was docked with dockit,
2969 * but the user did not update WMState to indicate that
2970 * it was docked by force */
2971 wapp
= wApplicationOf(window
);
2973 icon
->forced_dock
= 1;
2976 if (!icon
->forced_dock
) {
2977 icon
->main_window
= window
;
2981 if (!wPreferences
.no_animations
&& !icon
->launching
&&
2982 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
2986 icon
->launching
= 1;
2987 dockIconPaint(icon
);
2989 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
2990 wm_instance
, wm_class
, TILE_NORMAL
);
2991 /* XXX: can: aicon->icon == NULL ? */
2992 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
2993 wAppIconMove(aicon
, x0
, y0
);
2994 /* Should this always be lowered? -Dan */
2996 wLowerFrame(aicon
->icon
->core
);
2997 XMapWindow(dpy
, aicon
->icon
->core
->window
);
2998 aicon
->launching
= 1;
2999 wAppIconPaint(aicon
);
3000 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
3001 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
3002 wAppIconDestroy(aicon
);
3004 wDockFinishLaunch(dock
, icon
);
3009 if (firstPass
&& !found
) {
3023 void wClipUpdateForWorkspaceChange(WScreen
* scr
, int workspace
)
3025 if (!wPreferences
.flags
.noclip
) {
3026 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3027 if (scr
->current_workspace
!= workspace
) {
3028 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3029 WAppIconChain
*chain
= scr
->global_icons
;
3032 moveIconBetweenDocks(chain
->aicon
->dock
,
3033 scr
->workspaces
[workspace
]->clip
,
3034 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
3035 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
3036 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3037 chain
= chain
->next
;
3040 wDockHideIcons(old_clip
);
3041 if (old_clip
->auto_raise_lower
) {
3042 if (old_clip
->auto_raise_magic
) {
3043 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3044 old_clip
->auto_raise_magic
= NULL
;
3046 wDockLower(old_clip
);
3048 if (old_clip
->auto_collapse
) {
3049 if (old_clip
->auto_expand_magic
) {
3050 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3051 old_clip
->auto_expand_magic
= NULL
;
3053 old_clip
->collapsed
= 1;
3055 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3057 if (scr
->flags
.clip_balloon_mapped
)
3058 showClipBalloon(scr
->clip_icon
->dock
, workspace
);
3062 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
* dock
)
3067 for (i
= 0; i
< dock
->max_icons
; i
++) {
3068 icon
= dock
->icon_array
[i
];
3072 if (icon
->launching
&& icon
->pid
== pid
) {
3073 if (!icon
->relaunching
) {
3075 icon
->main_window
= None
;
3077 wDockFinishLaunch(dock
, icon
);
3079 if (status
== 111) {
3084 if (icon
->drop_launch
)
3085 cmd
= icon
->dnd_command
;
3088 if (icon
->paste_launch
)
3089 cmd
= icon
->paste_command
;
3091 cmd
= icon
->command
;
3093 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3095 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3102 static void toggleLowered(WDock
* dock
)
3107 /* lower/raise Dock */
3108 if (!dock
->lowered
) {
3109 newlevel
= WMNormalLevel
;
3112 newlevel
= WMDockLevel
;
3116 for (i
= 0; i
< dock
->max_icons
; i
++) {
3117 tmp
= dock
->icon_array
[i
];
3121 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3123 wLowerFrame(tmp
->icon
->core
);
3126 if (dock
->type
== WM_DOCK
)
3127 wScreenUpdateUsableArea(dock
->screen_ptr
);
3130 static void toggleCollapsed(WDock
* dock
)
3132 if (dock
->collapsed
) {
3133 dock
->collapsed
= 0;
3134 wDockShowIcons(dock
);
3136 dock
->collapsed
= 1;
3137 wDockHideIcons(dock
);
3141 static void openDockMenu(WDock
* dock
, WAppIcon
* aicon
, XEvent
* event
)
3143 WScreen
*scr
= dock
->screen_ptr
;
3144 WObjDescriptor
*desc
;
3146 WApplication
*wapp
= NULL
;
3150 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3152 if (dock
->type
== WM_DOCK
) {
3154 entry
= dock
->menu
->entries
[index
];
3155 entry
->flags
.indicator_on
= !dock
->lowered
;
3156 entry
->clientdata
= dock
;
3157 dock
->menu
->flags
.realized
= 0;
3160 if (scr
->clip_options
)
3161 updateClipOptionsMenu(scr
->clip_options
, dock
);
3163 n_selected
= numberOfSelectedIcons(dock
);
3165 /* Rename Workspace */
3166 entry
= dock
->menu
->entries
[++index
];
3167 if (aicon
== scr
->clip_icon
) {
3168 entry
->callback
= renameCallback
;
3169 entry
->clientdata
= dock
;
3170 entry
->flags
.indicator
= 0;
3171 entry
->text
= _("Rename Workspace");
3173 entry
->callback
= omnipresentCallback
;
3174 entry
->clientdata
= aicon
;
3175 if (n_selected
> 0) {
3176 entry
->flags
.indicator
= 0;
3177 entry
->text
= _("Toggle Omnipresent");
3179 entry
->flags
.indicator
= 1;
3180 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3181 entry
->flags
.indicator_type
= MI_CHECK
;
3182 entry
->text
= _("Omnipresent");
3186 /* select/unselect icon */
3187 entry
= dock
->menu
->entries
[++index
];
3188 entry
->clientdata
= aicon
;
3189 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3190 wMenuSetEnabled(dock
->menu
, index
, aicon
!= scr
->clip_icon
);
3192 /* select/unselect all icons */
3193 entry
= dock
->menu
->entries
[++index
];
3194 entry
->clientdata
= aicon
;
3196 entry
->text
= _("Unselect All Icons");
3198 entry
->text
= _("Select All Icons");
3199 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3202 entry
= dock
->menu
->entries
[++index
];
3203 entry
->clientdata
= aicon
;
3205 entry
->text
= _("Keep Icons");
3207 entry
->text
= _("Keep Icon");
3208 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3210 /* this is the workspace submenu part */
3211 entry
= dock
->menu
->entries
[++index
];
3213 entry
->text
= _("Move Icons To");
3215 entry
->text
= _("Move Icon To");
3216 if (scr
->clip_submenu
)
3217 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3218 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3220 /* remove icon(s) */
3221 entry
= dock
->menu
->entries
[++index
];
3222 entry
->clientdata
= aicon
;
3224 entry
->text
= _("Remove Icons");
3226 entry
->text
= _("Remove Icon");
3227 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3229 /* attract icon(s) */
3230 entry
= dock
->menu
->entries
[++index
];
3231 entry
->clientdata
= aicon
;
3233 dock
->menu
->flags
.realized
= 0;
3234 wMenuRealize(dock
->menu
);
3237 if (aicon
->icon
->owner
) {
3238 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3244 entry
= dock
->menu
->entries
[++index
];
3245 entry
->clientdata
= aicon
;
3246 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3249 entry
= dock
->menu
->entries
[++index
];
3250 entry
->clientdata
= aicon
;
3251 if (wapp
&& wapp
->flags
.hidden
) {
3252 entry
->text
= _("Unhide Here");
3254 entry
->text
= _("Bring Here");
3256 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3259 entry
= dock
->menu
->entries
[++index
];
3260 entry
->clientdata
= aicon
;
3261 if (wapp
&& wapp
->flags
.hidden
) {
3262 entry
->text
= _("Unhide");
3264 entry
->text
= _("Hide");
3266 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3269 entry
= dock
->menu
->entries
[++index
];
3270 entry
->clientdata
= aicon
;
3271 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3274 entry
= dock
->menu
->entries
[++index
];
3275 entry
->clientdata
= aicon
;
3276 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3278 if (!dock
->menu
->flags
.realized
)
3279 wMenuRealize(dock
->menu
);
3281 if (dock
->type
== WM_CLIP
) {
3282 /*x_pos = event->xbutton.x_root+2; */
3283 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3286 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3287 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3290 x_pos
= dock
->on_right_side
? scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3293 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3295 /* allow drag select */
3296 event
->xany
.send_event
= True
;
3297 desc
= &dock
->menu
->menu
->descriptor
;
3298 (*desc
->handle_mousedown
) (desc
, event
);
3301 /******************************************************************/
3302 static void iconDblClick(WObjDescriptor
* desc
, XEvent
* event
)
3304 WAppIcon
*btn
= desc
->parent
;
3305 WDock
*dock
= btn
->dock
;
3306 WApplication
*wapp
= NULL
;
3309 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3310 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3312 assert(wapp
!= NULL
);
3314 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3316 /* go to the last workspace that the user worked on the app */
3317 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
&& !unhideHere
) {
3318 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3321 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3323 if (event
->xbutton
.state
& MOD_MASK
) {
3324 wHideOtherApplications(btn
->icon
->owner
);
3327 if (event
->xbutton
.button
== Button1
) {
3329 if (event
->xbutton
.state
& MOD_MASK
) {
3330 /* raise/lower dock */
3331 toggleLowered(dock
);
3332 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3333 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
)
3334 toggleCollapsed(dock
);
3336 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3337 } else if (btn
->command
) {
3338 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3339 launchDockedApplication(btn
, False
);
3341 } else if (btn
->xindex
== 0 && btn
->yindex
== 0 && btn
->dock
->type
== WM_DOCK
) {
3342 wShowGNUstepPanel(dock
->screen_ptr
);
3348 static void handleDockMove(WDock
* dock
, WAppIcon
* aicon
, XEvent
* event
)
3350 WScreen
*scr
= dock
->screen_ptr
;
3351 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3354 int grabbed
= 0, swapped
= 0, done
;
3355 Pixmap ghost
= None
;
3356 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3358 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3359 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3360 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3361 wwarning("pointer grab failed for dock move");
3364 for (x
= 0; x
< dock
->max_icons
; x
++) {
3365 if (dock
->icon_array
[x
] != NULL
&& dock
->icon_array
[x
]->yindex
> y
)
3366 y
= dock
->icon_array
[x
]->yindex
;
3369 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
* y
);
3373 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3374 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3381 /* It means the cursor moved so fast that it entered
3382 * something else (if moving slowly, it would have
3383 * stayed in the dock that is being moved. Ignore such
3384 * "spurious" EnterNotifiy's */
3389 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3390 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3391 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3392 | ButtonReleaseMask
| ButtonPressMask
,
3393 wCursor
[WCUR_MOVE
], CurrentTime
);
3398 if (dock
->type
== WM_CLIP
) {
3399 x
= ev
.xmotion
.x_root
- ofs_x
;
3400 y
= ev
.xmotion
.y_root
- ofs_y
;
3401 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3403 moveDock(dock
, x
, y
);
3405 /* move vertically if pointer is inside the dock */
3406 if ((dock
->on_right_side
&& ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3407 || (!dock
->on_right_side
&& ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
* 2)) {
3409 x
= ev
.xmotion
.x_root
- ofs_x
;
3410 y
= ev
.xmotion
.y_root
- ofs_y
;
3411 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3412 moveDock(dock
, dock
->x_pos
, y
);
3414 /* move horizontally to change sides */
3415 x
= ev
.xmotion
.x_root
- ofs_x
;
3416 if (!dock
->on_right_side
) {
3420 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
* 2) {
3421 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
- ICON_SIZE
3422 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3423 if (superfluous
&& ghost
== None
) {
3424 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3425 scr
->scr_width
- ICON_SIZE
3426 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3427 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3428 XClearWindow(dpy
, scr
->dock_shadow
);
3430 XMapRaised(dpy
, scr
->dock_shadow
);
3433 if (superfluous
&& ghost
!= None
) {
3434 XFreePixmap(dpy
, ghost
);
3437 XUnmapWindow(dpy
, scr
->dock_shadow
);
3442 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3443 XMoveWindow(dpy
, scr
->dock_shadow
, DOCK_EXTRA_SPACE
, dock
->y_pos
);
3444 if (superfluous
&& ghost
== None
) {
3445 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3446 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3447 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3448 XClearWindow(dpy
, scr
->dock_shadow
);
3450 XMapRaised(dpy
, scr
->dock_shadow
);
3453 XUnmapWindow(dpy
, scr
->dock_shadow
);
3455 if (superfluous
&& ghost
!= None
) {
3456 XFreePixmap(dpy
, ghost
);
3468 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3470 XUngrabPointer(dpy
, CurrentTime
);
3471 XUnmapWindow(dpy
, scr
->dock_shadow
);
3472 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3473 if (dock
->type
== WM_DOCK
) {
3476 dock
->on_right_side
= 1;
3478 dock
->on_right_side
= 0;
3480 wArrangeIcons(scr
, False
);
3489 XFreePixmap(dpy
, ghost
);
3490 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3494 static Bool
handleIconMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3496 WScreen
*scr
= dock
->screen_ptr
;
3498 WIcon
*icon
= aicon
->icon
;
3499 WDock
*dock2
= NULL
, *last_dock
= dock
, *clip
= NULL
;
3500 int ondock
, grabbed
= 0, change_dock
= 0, collapsed
= 0;
3502 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
3503 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3504 int shad_x
= x
, shad_y
= y
;
3505 int ix
= aicon
->xindex
, iy
= aicon
->yindex
;
3507 Pixmap ghost
= None
;
3509 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3510 int omnipresent
= aicon
->omnipresent
; /* this must be cached!!! */
3511 Bool hasMoved
= False
;
3513 if (wPreferences
.flags
.noupdates
)
3516 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
3517 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3518 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3521 if (!(event
->xbutton
.state
& MOD_MASK
))
3522 wRaiseFrame(icon
->core
);
3524 if (!wPreferences
.flags
.noclip
)
3525 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3527 if (dock
== scr
->dock
&& !wPreferences
.flags
.noclip
)
3529 else if (dock
!= scr
->dock
&& !wPreferences
.flags
.nodock
)
3532 wins
[0] = icon
->core
->window
;
3533 wins
[1] = scr
->dock_shadow
;
3534 XRestackWindows(dpy
, wins
, 2);
3535 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
3537 if (icon
->pixmap
!= None
)
3538 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3540 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3542 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3543 XClearWindow(dpy
, scr
->dock_shadow
);
3545 XMapWindow(dpy
, scr
->dock_shadow
);
3550 XMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3551 | ButtonMotionMask
| ExposureMask
, &ev
);
3560 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3561 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3562 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3563 | ButtonReleaseMask
| ButtonPressMask
,
3564 wCursor
[WCUR_MOVE
], CurrentTime
);
3573 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3574 if (i
== scr
->current_workspace
)
3576 wDockShowIcons(scr
->workspaces
[i
]->clip
);
3580 x
= ev
.xmotion
.x_root
- ofs_x
;
3581 y
= ev
.xmotion
.y_root
- ofs_y
;
3582 tmp
= wDockSnapIcon(dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3585 if (last_dock
!= dock
&& collapsed
) {
3586 last_dock
->collapsed
= 1;
3587 wDockHideIcons(last_dock
);
3590 if (!collapsed
&& (collapsed
= dock
->collapsed
)) {
3591 dock
->collapsed
= 0;
3592 wDockShowIcons(dock
);
3594 if (dock
->auto_raise_lower
)
3598 tmp
= wDockSnapIcon(dock2
, aicon
, x
, y
, &ix
, &iy
, False
);
3601 if (last_dock
!= dock2
&& collapsed
) {
3602 last_dock
->collapsed
= 1;
3603 wDockHideIcons(last_dock
);
3606 if (!collapsed
&& (collapsed
= dock2
->collapsed
)) {
3607 dock2
->collapsed
= 0;
3608 wDockShowIcons(dock2
);
3610 if (dock2
->auto_raise_lower
)
3615 if (aicon
->launching
|| aicon
->lock
|| (aicon
->running
&& !(ev
.xmotion
.state
& MOD_MASK
))
3616 || (!aicon
->running
&& tmp
)) {
3617 shad_x
= last_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3618 shad_y
= last_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3620 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3623 XMapWindow(dpy
, scr
->dock_shadow
);
3628 XUnmapWindow(dpy
, scr
->dock_shadow
);
3632 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
3639 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3641 XUngrabPointer(dpy
, CurrentTime
);
3643 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
3644 XUnmapWindow(dpy
, scr
->dock_shadow
);
3646 reattachIcon(dock
, aicon
, ix
, iy
);
3647 if (clip
&& dock
!= clip
&& clip
->auto_raise_lower
)
3650 docked
= moveIconBetweenDocks(dock
, dock2
, aicon
, ix
, iy
);
3652 /* Slide it back if dock rejected it */
3653 SlideWindow(icon
->core
->window
, x
, y
, aicon
->x_pos
, aicon
->y_pos
);
3654 reattachIcon(dock
, aicon
, aicon
->xindex
, aicon
->yindex
);
3656 if (last_dock
->type
== WM_CLIP
&& last_dock
->auto_collapse
) {
3664 if (!aicon
->running
&& !wPreferences
.no_animations
) {
3665 /* We need to deselect it, even if is deselected in
3666 * wDockDetach(), because else DoKaboom() will fail.
3668 if (aicon
->icon
->selected
)
3669 wIconSelect(aicon
->icon
);
3671 DoKaboom(scr
, aicon
->icon
->core
->window
, x
, y
);
3674 if (clip
&& clip
->auto_raise_lower
)
3676 wDockDetach(dock
, aicon
);
3679 last_dock
->collapsed
= 1;
3680 wDockHideIcons(last_dock
);
3685 XFreePixmap(dpy
, ghost
);
3686 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3690 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3691 if (i
== scr
->current_workspace
)
3693 wDockHideIcons(scr
->workspaces
[i
]->clip
);
3699 return False
; /* never reached */
3702 static int getClipButton(int px
, int py
)
3704 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3706 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3709 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3710 return CLIP_FORWARD
;
3711 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3717 static void handleClipChangeWorkspace(WScreen
* scr
, XEvent
* event
)
3720 int done
, direction
, new_ws
;
3722 WDock
*clip
= scr
->clip_icon
->dock
;
3724 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3726 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3727 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3729 wClipIconPaint(scr
->clip_icon
);
3732 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3739 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3740 if (new_dir
!= direction
) {
3741 direction
= new_dir
;
3742 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3743 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3744 wClipIconPaint(scr
->clip_icon
);
3752 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3757 clip
->lclip_button_pushed
= 0;
3758 clip
->rclip_button_pushed
= 0;
3760 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3762 if (direction
== CLIP_FORWARD
) {
3763 if (scr
->current_workspace
< scr
->workspace_count
- 1)
3764 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3765 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
- 1)
3766 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3767 else if (wPreferences
.ws_cycle
)
3768 wWorkspaceChange(scr
, 0);
3769 } else if (direction
== CLIP_REWIND
) {
3770 if (scr
->current_workspace
> 0)
3771 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
3772 else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
)
3773 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
3776 wClipIconPaint(scr
->clip_icon
);
3779 static void iconMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
3781 WAppIcon
*aicon
= desc
->parent
;
3782 WDock
*dock
= aicon
->dock
;
3783 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3785 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3788 scr
->last_dock
= dock
;
3790 if (dock
->menu
->flags
.mapped
)
3791 wMenuUnmap(dock
->menu
);
3793 if (IsDoubleClick(scr
, event
)) {
3794 /* double-click was not in the main clip icon */
3795 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3796 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3797 iconDblClick(desc
, event
);
3802 if (dock
->type
== WM_CLIP
&& scr
->flags
.clip_balloon_mapped
) {
3803 XUnmapWindow(dpy
, scr
->clip_balloon
);
3804 scr
->flags
.clip_balloon_mapped
= 0;
3806 if (event
->xbutton
.button
== Button1
) {
3807 if (event
->xbutton
.state
& MOD_MASK
)
3812 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
&& dock
->type
!= WM_DOCK
) {
3813 wIconSelect(aicon
->icon
);
3817 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3818 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
3819 && dock
->type
== WM_CLIP
)
3820 handleClipChangeWorkspace(scr
, event
);
3822 handleDockMove(dock
, aicon
, event
);
3824 Bool hasMoved
= handleIconMove(dock
, aicon
, event
);
3825 if (wPreferences
.single_click
&& !hasMoved
)
3826 iconDblClick(desc
, event
);
3828 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&& aicon
== scr
->clip_icon
) {
3829 if (!scr
->clip_ws_menu
) {
3830 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3832 if (scr
->clip_ws_menu
) {
3833 WMenu
*wsMenu
= scr
->clip_ws_menu
;
3836 wWorkspaceMenuUpdate(scr
, wsMenu
);
3838 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
3841 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
3842 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
3844 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
3846 desc
= &wsMenu
->menu
->descriptor
;
3847 event
->xany
.send_event
= True
;
3848 (*desc
->handle_mousedown
) (desc
, event
);
3850 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
3851 (event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
) {
3852 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3853 } else if (event
->xbutton
.button
== Button3
) {
3854 if (event
->xbutton
.send_event
&&
3855 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3856 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3857 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3858 wwarning("pointer grab failed for dockicon menu");
3862 openDockMenu(dock
, aicon
, event
);
3863 } else if (event
->xbutton
.button
== Button2
) {
3864 WAppIcon
*btn
= desc
->parent
;
3866 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
))) {
3867 launchDockedApplication(btn
, True
);
3872 static void showClipBalloon(WDock
* dock
, int workspace
)
3876 WScreen
*scr
= dock
->screen_ptr
;
3880 scr
->flags
.clip_balloon_mapped
= 1;
3881 XMapWindow(dpy
, scr
->clip_balloon
);
3883 text
= scr
->workspaces
[workspace
]->name
;
3885 w
= WMWidthOfString(scr
->clip_title_font
, text
, strlen(text
));
3887 h
= WMFontHeight(scr
->clip_title_font
);
3888 XResizeWindow(dpy
, scr
->clip_balloon
, w
, h
);
3890 x
= dock
->x_pos
+ CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
3891 y
= dock
->y_pos
+ ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
3893 if (x
+ w
> scr
->scr_width
) {
3894 x
= scr
->scr_width
- w
;
3895 if (dock
->y_pos
+ ICON_SIZE
+ h
> scr
->scr_height
)
3896 y
= dock
->y_pos
- h
- 1;
3898 y
= dock
->y_pos
+ ICON_SIZE
;
3899 XRaiseWindow(dpy
, scr
->clip_balloon
);
3901 stack
[0] = scr
->clip_icon
->icon
->core
->window
;
3902 stack
[1] = scr
->clip_balloon
;
3903 XRestackWindows(dpy
, stack
, 2);
3905 XMoveWindow(dpy
, scr
->clip_balloon
, x
, y
);
3906 XClearWindow(dpy
, scr
->clip_balloon
);
3907 WMDrawString(scr
->wmscreen
, scr
->clip_balloon
,
3908 scr
->clip_title_color
[CLIP_NORMAL
], scr
->clip_title_font
, 0, 0, text
, strlen(text
));
3911 static void clipEnterNotify(WObjDescriptor
* desc
, XEvent
* event
)
3913 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3917 assert(event
->type
== EnterNotify
);
3919 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3922 scr
= btn
->icon
->core
->screen_ptr
;
3923 if (!btn
->omnipresent
)
3926 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3928 if (!dock
|| dock
->type
!= WM_CLIP
)
3931 /* The auto raise/lower code */
3932 if (dock
->auto_lower_magic
) {
3933 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3934 dock
->auto_lower_magic
= NULL
;
3936 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
) {
3937 dock
->auto_raise_magic
= WMAddTimerHandler(AUTO_RAISE_DELAY
, clipAutoRaise
, (void *)dock
);
3940 /* The auto expand/collapse code */
3941 if (dock
->auto_collapse_magic
) {
3942 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3943 dock
->auto_collapse_magic
= NULL
;
3945 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
) {
3946 dock
->auto_expand_magic
= WMAddTimerHandler(AUTO_EXPAND_DELAY
, clipAutoExpand
, (void *)dock
);
3949 if (btn
->xindex
== 0 && btn
->yindex
== 0)
3950 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
3952 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
3953 XUnmapWindow(dpy
, dock
->screen_ptr
->clip_balloon
);
3954 dock
->screen_ptr
->flags
.clip_balloon_mapped
= 0;
3959 static void clipLeave(WDock
* dock
)
3962 WObjDescriptor
*desc
= NULL
;
3964 if (!dock
|| dock
->type
!= WM_CLIP
)
3967 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
3968 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3969 (XPointer
*) & desc
) != XCNOENT
3970 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
3971 && ((WAppIcon
*) desc
->parent
)->dock
&& ((WAppIcon
*) desc
->parent
)->dock
->type
== WM_CLIP
) {
3972 /* We didn't left the Clip yet */
3973 XPutBackEvent(dpy
, &event
);
3977 XPutBackEvent(dpy
, &event
);
3979 /* We entered a withdrawn window, so we're still in Clip */
3983 if (dock
->auto_raise_magic
) {
3984 WMDeleteTimerHandler(dock
->auto_raise_magic
);
3985 dock
->auto_raise_magic
= NULL
;
3987 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
) {
3988 dock
->auto_lower_magic
= WMAddTimerHandler(AUTO_LOWER_DELAY
, clipAutoLower
, (void *)dock
);
3991 if (dock
->auto_expand_magic
) {
3992 WMDeleteTimerHandler(dock
->auto_expand_magic
);
3993 dock
->auto_expand_magic
= NULL
;
3995 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
) {
3996 dock
->auto_collapse_magic
= WMAddTimerHandler(AUTO_COLLAPSE_DELAY
, clipAutoCollapse
, (void *)dock
);
4000 static void clipLeaveNotify(WObjDescriptor
* desc
, XEvent
* event
)
4002 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
4004 assert(event
->type
== LeaveNotify
);
4006 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
4009 clipLeave(btn
->dock
);
4012 static void clipAutoCollapse(void *cdata
)
4014 WDock
*dock
= (WDock
*) cdata
;
4016 if (dock
->type
!= WM_CLIP
)
4019 if (dock
->auto_collapse
) {
4020 dock
->collapsed
= 1;
4021 wDockHideIcons(dock
);
4023 dock
->auto_collapse_magic
= NULL
;
4026 static void clipAutoExpand(void *cdata
)
4028 WDock
*dock
= (WDock
*) cdata
;
4030 if (dock
->type
!= WM_CLIP
)
4033 if (dock
->auto_collapse
) {
4034 dock
->collapsed
= 0;
4035 wDockShowIcons(dock
);
4037 dock
->auto_expand_magic
= NULL
;
4040 static void clipAutoLower(void *cdata
)
4042 WDock
*dock
= (WDock
*) cdata
;
4044 if (dock
->type
!= WM_CLIP
)
4047 if (dock
->auto_raise_lower
)
4050 dock
->auto_lower_magic
= NULL
;
4053 static void clipAutoRaise(void *cdata
)
4055 WDock
*dock
= (WDock
*) cdata
;
4057 if (dock
->type
!= WM_CLIP
)
4060 if (dock
->auto_raise_lower
)
4063 if (dock
->screen_ptr
->flags
.clip_balloon_mapped
) {
4064 showClipBalloon(dock
, dock
->screen_ptr
->current_workspace
);
4067 dock
->auto_raise_magic
= NULL
;
4070 static Bool
iconCanBeOmnipresent(WAppIcon
* aicon
)
4072 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4077 for (i
= 0; i
< scr
->workspace_count
; i
++) {
4078 clip
= scr
->workspaces
[i
]->clip
;
4080 if (clip
== aicon
->dock
)
4083 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4084 return False
; /* Clip is full in some workspace */
4086 for (j
= 0; j
< clip
->max_icons
; j
++) {
4087 btn
= clip
->icon_array
[j
];
4088 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
4096 int wClipMakeIconOmnipresent(WAppIcon
* aicon
, int omnipresent
)
4098 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4099 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4100 int status
= WO_SUCCESS
;
4102 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== scr
->clip_icon
) {
4103 return WO_NOT_APPLICABLE
;
4106 if (aicon
->omnipresent
== omnipresent
)
4110 if (iconCanBeOmnipresent(aicon
)) {
4111 aicon
->omnipresent
= 1;
4112 new_entry
= wmalloc(sizeof(WAppIconChain
));
4113 new_entry
->aicon
= aicon
;
4114 new_entry
->next
= scr
->global_icons
;
4115 scr
->global_icons
= new_entry
;
4116 scr
->global_icon_count
++;
4118 aicon
->omnipresent
= 0;
4122 aicon
->omnipresent
= 0;
4123 if (aicon
== scr
->global_icons
->aicon
) {
4124 tmp
= scr
->global_icons
->next
;
4125 wfree(scr
->global_icons
);
4126 scr
->global_icons
= tmp
;
4127 scr
->global_icon_count
--;
4129 tmp
= scr
->global_icons
;
4131 if (tmp
->next
->aicon
== aicon
) {
4132 tmp1
= tmp
->next
->next
;
4135 scr
->global_icon_count
--;
4143 wAppIconPaint(aicon
);