1 /* dock.c- built-in Dock module for WindowMaker
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <X11/Xutil.h>
35 #define PATH_MAX DEFAULT_PATH_MAX
38 #include "WindowMaker.h"
46 #include "dockedapp.h"
49 #include "properties.h"
53 #include "workspace.h"
55 #include "superfluous.h"
58 /**** Local variables ****/
61 #define CLIP_FORWARD 2
63 /**** Global variables ****/
64 extern Cursor wCursor
[WCUR_LAST
];
65 extern WPreferences wPreferences
;
66 extern XContext wWinContext
;
67 extern void appIconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
69 #define MOD_MASK wPreferences.modifier_mask
70 #define ICON_SIZE wPreferences.icon_size
72 /***** Local variables ****/
74 static WMPropList
*dCommand
= NULL
;
75 static WMPropList
*dPasteCommand
= NULL
;
76 #ifdef XDND /* XXX was OFFIX */
77 static WMPropList
*dDropCommand
= NULL
;
79 static WMPropList
*dAutoLaunch
, *dLock
;
80 static WMPropList
*dName
, *dForced
, *dBuggyApplication
, *dYes
, *dNo
;
81 static WMPropList
*dHost
, *dDock
, *dClip
;
82 static WMPropList
*dAutoAttractIcons
;
84 static WMPropList
*dPosition
, *dApplications
, *dLowered
, *dCollapsed
;
86 static WMPropList
*dAutoCollapse
, *dAutoRaiseLower
, *dOmnipresent
;
88 static void dockIconPaint(WAppIcon
*btn
);
90 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
92 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
);
94 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
96 static int getClipButton(int px
, int py
);
98 static void toggleLowered(WDock
*dock
);
100 static void toggleCollapsed(WDock
*dock
);
102 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
104 static void clipLeave(WDock
*dock
);
106 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
108 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
109 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
110 static void clipAutoCollapse(void *cdata
);
111 static void clipAutoExpand(void *cdata
);
112 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
);
114 static void clipAutoLower(void *cdata
);
115 static void clipAutoRaise(void *cdata
);
116 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
);
118 static int onScreen(WScreen
*scr
, int x
, int y
);
120 static void make_keys(void)
122 if (dCommand
!= NULL
)
125 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
126 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
128 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
130 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
131 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
132 dName
= WMRetainPropList(WMCreatePLString("Name"));
133 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
134 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
135 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
136 dNo
= WMRetainPropList(WMCreatePLString("No"));
137 dHost
= WMRetainPropList(WMCreatePLString("Host"));
139 dPosition
= WMCreatePLString("Position");
140 dApplications
= WMCreatePLString("Applications");
141 dLowered
= WMCreatePLString("Lowered");
142 dCollapsed
= WMCreatePLString("Collapsed");
143 dAutoCollapse
= WMCreatePLString("AutoCollapse");
144 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
145 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
147 dOmnipresent
= WMCreatePLString("Omnipresent");
149 dDock
= WMCreatePLString("Dock");
150 dClip
= WMCreatePLString("Clip");
153 static void renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
155 WDock
*dock
= entry
->clientdata
;
160 assert(entry
->clientdata
!= NULL
);
162 wspace
= dock
->screen_ptr
->current_workspace
;
164 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
166 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+ 1);
167 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
, &name
))
168 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
173 static void toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
175 assert(entry
->clientdata
!= NULL
);
177 toggleLowered(entry
->clientdata
);
179 entry
->flags
.indicator_on
= !(((WDock
*) entry
->clientdata
)->lowered
);
184 static int matchWindow(const void *item
, const void *cdata
)
186 return (((WFakeGroupLeader
*) item
)->leader
== (Window
) cdata
);
189 static void killCallback(WMenu
*menu
, WMenuEntry
*entry
)
191 WScreen
*scr
= menu
->menu
->screen_ptr
;
193 WFakeGroupLeader
*fPtr
;
194 char *buffer
, *shortname
, **argv
;
195 char *basename(const char *shortname
);
198 if (!WCHECK_STATE(WSTATE_NORMAL
))
201 assert(entry
->clientdata
!= NULL
);
203 icon
= (WAppIcon
*) entry
->clientdata
;
207 WCHANGE_STATE(WSTATE_MODAL
);
209 /* strip away dir names */
210 shortname
= basename(icon
->command
);
211 /* separate out command options */
212 wtokensplit(shortname
, &argv
, &argc
);
214 buffer
= wstrconcat(argv
[0],
215 _(" will be forcibly closed.\n"
216 "Any unsaved changes will be lost.\n" "Please confirm."));
218 if (icon
->icon
&& icon
->icon
->owner
) {
219 fPtr
= icon
->icon
->owner
->fake_group
;
221 /* is this really necessary? can we kill a non-running dock icon? */
222 Window win
= icon
->main_window
;
225 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)win
);
226 if (index
!= WANotFound
)
227 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
232 if (wPreferences
.dont_confirm_kill
233 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
234 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
236 WWindow
*wwin
, *twin
;
238 wwin
= scr
->focused_window
;
241 if (wwin
->fake_group
== fPtr
)
246 } else if (icon
->icon
&& icon
->icon
->owner
) {
247 wClientKill(icon
->icon
->owner
);
252 wtokenfree(argv
, argc
);
256 WCHANGE_STATE(WSTATE_NORMAL
);
259 /* TODO: replace this function with a member of the dock struct */
260 static int numberOfSelectedIcons(WDock
*dock
)
266 for (i
= 1; i
< dock
->max_icons
; i
++) {
267 aicon
= dock
->icon_array
[i
];
268 if (aicon
&& aicon
->icon
->selected
)
275 static WMArray
*getSelected(WDock
*dock
)
277 WMArray
*ret
= WMCreateArray(8);
281 for (i
= 1; i
< dock
->max_icons
; i
++) {
282 btn
= dock
->icon_array
[i
];
283 if (btn
&& btn
->icon
->selected
)
284 WMAddToArray(ret
, btn
);
290 static void paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
292 Window win
= clipIcon
->icon
->core
->window
;
293 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
295 int pt
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
296 int tp
= ICON_SIZE
- pt
;
297 int as
= pt
- 15; /* 15 = 5+5+5 */
298 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
301 color
= scr
->clip_title_color
[CLIP_NORMAL
];
303 XSetForeground(dpy
, gc
, WMColorPixel(color
));
308 p
[1].x
= ICON_SIZE
- 2;
310 p
[2].x
= ICON_SIZE
- 2;
312 } else if (lpushed
) {
316 p
[1].y
= ICON_SIZE
- 2;
318 p
[2].y
= ICON_SIZE
- 2;
320 if (lpushed
|| rpushed
) {
321 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
322 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
323 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
326 /* top right arrow */
327 p
[0].x
= p
[3].x
= ICON_SIZE
- 5 - as
;
329 p
[1].x
= ICON_SIZE
- 6;
331 p
[2].x
= ICON_SIZE
- 6;
334 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
335 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
337 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
338 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
341 /* bottom left arrow */
343 p
[0].y
= p
[3].y
= ICON_SIZE
- 5 - as
;
345 p
[1].y
= ICON_SIZE
- 6;
347 p
[2].y
= ICON_SIZE
- 6;
349 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
350 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
352 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
353 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
357 RImage
*wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
359 RImage
*tile
= RCloneImage(normalTile
);
366 pt
= CLIP_BUTTON_SIZE
* wPreferences
.icon_size
/ 64;
367 tp
= wPreferences
.icon_size
- 1 - pt
;
371 black
.red
= black
.green
= black
.blue
= 0;
374 dark
.red
= dark
.green
= dark
.blue
= 60;
377 light
.red
= light
.green
= light
.blue
= 80;
380 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
- 2, pt
- 1, &dark
);
381 RDrawLine(tile
, tp
- 1, 0, wPreferences
.icon_size
- 1, pt
+ 1, &black
);
382 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
- 3, pt
, &light
);
385 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, 4, &dark
);
386 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 5, 6 + as
, &dark
);
387 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
, &light
);
390 ROperateLine(tile
, RAddOperation
, 2, tp
+ 2, pt
- 2, wPreferences
.icon_size
- 3, &dark
);
391 RDrawLine(tile
, 0, tp
- 1, pt
+ 1, wPreferences
.icon_size
- 1, &black
);
392 ROperateLine(tile
, RSubtractOperation
, 0, tp
- 2, pt
+ 1, wPreferences
.icon_size
- 2, &light
);
395 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, &dark
);
396 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
, 6 + as
, ICON_SIZE
- 5, &dark
);
397 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5, &light
);
402 static void omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
404 WAppIcon
*clickedIcon
= entry
->clientdata
;
407 WMArray
*selectedIcons
;
408 WMArrayIterator iter
;
411 assert(entry
->clientdata
!= NULL
);
413 dock
= clickedIcon
->dock
;
415 selectedIcons
= getSelected(dock
);
417 if (!WMGetArrayItemCount(selectedIcons
))
418 WMAddToArray(selectedIcons
, clickedIcon
);
421 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
422 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
424 else if (aicon
->icon
->selected
)
425 wIconSelect(aicon
->icon
);
427 WMFreeArray(selectedIcons
);
430 wMessageDialog(dock
->screen_ptr
, _("Warning"),
431 _("Some icons cannot be made omnipresent. "
432 "Please make sure that no other icon is "
433 "docked in the same positions on the other "
434 "workspaces and the Clip is not full in "
435 "some workspace."), _("OK"), NULL
, NULL
);
436 } else if (failed
== 1) {
437 wMessageDialog(dock
->screen_ptr
, _("Warning"),
438 _("Icon cannot be made omnipresent. "
439 "Please make sure that no other icon is "
440 "docked in the same position on the other "
441 "workspaces and the Clip is not full in "
442 "some workspace."), _("OK"), NULL
, NULL
);
446 static void removeIcons(WMArray
*icons
, WDock
*dock
)
452 WM_ITERATE_ARRAY(icons
, aicon
, it
) {
453 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
454 wDockDetach(dock
, aicon
);
456 /* XXX: can: aicon->icon == NULL ? */
457 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
458 wGetHeadForWindow(aicon
->icon
->owner
));
459 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
460 if (!dock
->mapped
|| dock
->collapsed
)
461 XMapWindow(dpy
, aicon
->icon
->core
->window
);
466 if (wPreferences
.auto_arrange_icons
)
467 wArrangeIcons(dock
->screen_ptr
, True
);
470 static void removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
472 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
474 WMArray
*selectedIcons
;
476 assert(clickedIcon
!= NULL
);
478 dock
= clickedIcon
->dock
;
480 selectedIcons
= getSelected(dock
);
482 if (WMGetArrayItemCount(selectedIcons
)) {
483 if (wMessageDialog(dock
->screen_ptr
, _("Workspace Clip"),
484 _("All selected icons will be removed!"),
485 _("OK"), _("Cancel"), NULL
) != WAPRDefault
) {
486 WMFreeArray(selectedIcons
);
490 if (clickedIcon
->xindex
== 0 && clickedIcon
->yindex
== 0) {
491 WMFreeArray(selectedIcons
);
494 WMAddToArray(selectedIcons
, clickedIcon
);
497 removeIcons(selectedIcons
, dock
);
500 static void keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
502 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
505 WMArray
*selectedIcons
;
508 assert(clickedIcon
!= NULL
);
509 dock
= clickedIcon
->dock
;
511 selectedIcons
= getSelected(dock
);
513 if (!WMGetArrayItemCount(selectedIcons
)
514 && clickedIcon
!= dock
->screen_ptr
->clip_icon
) {
515 char *command
= NULL
;
517 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
518 clickedIcon
->editing
= 1;
519 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
520 _("Type the command used to launch the application"), &command
)) {
521 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
525 clickedIcon
->command
= command
;
526 clickedIcon
->editing
= 0;
528 clickedIcon
->editing
= 0;
531 WMFreeArray(selectedIcons
);
536 WMAddToArray(selectedIcons
, clickedIcon
);
539 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
540 if (aicon
->icon
->selected
)
541 wIconSelect(aicon
->icon
);
543 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
544 aicon
->attracted
= 0;
545 if (aicon
->icon
->shadowed
) {
546 aicon
->icon
->shadowed
= 0;
548 /* Update the icon images */
549 wIconUpdate(aicon
->icon
, NULL
);
552 wAppIconPaint(aicon
);
555 save_appicon(aicon
, True
);
557 WMFreeArray(selectedIcons
);
560 static void toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
562 WDock
*dock
= (WDock
*) entry
->clientdata
;
564 assert(entry
->clientdata
!= NULL
);
566 dock
->attract_icons
= !dock
->attract_icons
;
568 entry
->flags
.indicator_on
= dock
->attract_icons
;
573 static void selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
575 WAppIcon
*icon
= (WAppIcon
*) entry
->clientdata
;
577 assert(icon
!= NULL
);
579 wIconSelect(icon
->icon
);
584 static void colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
586 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
589 int x
, y
, x_pos
, y_pos
;
590 Bool update_icon
= False
;
592 assert(entry
->clientdata
!= NULL
);
593 clip
= clickedIcon
->dock
;
595 aicon
= clip
->screen_ptr
->app_icon_list
;
598 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
599 x_pos
= clip
->x_pos
+ x
* ICON_SIZE
;
600 y_pos
= clip
->y_pos
+ y
* ICON_SIZE
;
601 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
)
602 move_window(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
604 aicon
->attracted
= 1;
605 if (!aicon
->icon
->shadowed
) {
606 aicon
->icon
->shadowed
= 1;
609 wDockAttachIcon(clip
, aicon
, x
, y
, update_icon
);
610 if (clip
->collapsed
|| !clip
->mapped
)
611 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
617 static void selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
619 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
621 WMArray
*selectedIcons
;
622 WMArrayIterator iter
;
626 assert(clickedIcon
!= NULL
);
627 dock
= clickedIcon
->dock
;
629 selectedIcons
= getSelected(dock
);
631 if (!WMGetArrayItemCount(selectedIcons
)) {
632 for (i
= 1; i
< dock
->max_icons
; i
++) {
633 btn
= dock
->icon_array
[i
];
634 if (btn
&& !btn
->icon
->selected
)
635 wIconSelect(btn
->icon
);
638 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
639 wIconSelect(btn
->icon
);
642 WMFreeArray(selectedIcons
);
647 static void toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
649 assert(entry
->clientdata
!= NULL
);
651 toggleCollapsed(entry
->clientdata
);
653 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->collapsed
;
658 static void toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
661 assert(entry
->clientdata
!= NULL
);
663 dock
= (WDock
*) entry
->clientdata
;
665 dock
->auto_collapse
= !dock
->auto_collapse
;
667 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_collapse
;
672 static void toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
675 assert(entry
->clientdata
!= NULL
);
677 dock
= (WDock
*) entry
->clientdata
;
679 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
681 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_raise_lower
;
686 static void launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
688 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
690 launchDockedApplication(btn
, False
);
693 static void settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
695 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
699 ShowDockAppSettingsPanel(btn
);
702 static void hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
705 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
707 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
709 if (wapp
->flags
.hidden
) {
710 wWorkspaceChange(btn
->icon
->core
->screen_ptr
, wapp
->last_workspace
);
711 wUnhideApplication(wapp
, False
, False
);
713 wHideApplication(wapp
);
717 static void unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
720 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
722 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
724 wUnhideApplication(wapp
, False
, True
);
727 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
)
732 if (type
== WM_CLIP
) {
734 return scr
->clip_icon
;
735 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
736 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
737 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
738 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
741 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
742 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
748 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
749 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
750 btn
->icon
->core
->descriptor
.parent
= btn
;
751 XMapWindow(dpy
, btn
->icon
->core
->window
);
756 scr
->clip_icon
= btn
;
761 static void switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
763 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
764 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
766 WMArray
*selectedIcons
;
769 if (entry
->order
== scr
->current_workspace
)
772 dest
= scr
->workspaces
[entry
->order
]->clip
;
774 selectedIcons
= getSelected(src
);
776 if (WMGetArrayItemCount(selectedIcons
)) {
777 WMArrayIterator iter
;
779 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
780 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
781 wDockMoveIconBetweenDocks(src
, dest
, btn
, x
, y
);
782 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
785 } else if (icon
!= scr
->clip_icon
) {
786 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
787 wDockMoveIconBetweenDocks(src
, dest
, icon
, x
, y
);
788 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
791 WMFreeArray(selectedIcons
);
794 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
)
796 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
798 if (!btn
->launching
&&
799 ((!withSelection
&& btn
->command
!= NULL
) || (withSelection
&& btn
->paste_command
!= NULL
))) {
800 if (!btn
->forced_dock
) {
801 btn
->relaunching
= btn
->running
;
804 if (btn
->wm_instance
|| btn
->wm_class
) {
805 WWindowAttributes attr
;
806 memset(&attr
, 0, sizeof(WWindowAttributes
));
807 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
809 if (!attr
.no_appicon
&& !btn
->buggy_app
)
814 btn
->drop_launch
= 0;
815 btn
->paste_launch
= withSelection
;
816 scr
->last_dock
= btn
->dock
;
817 btn
->pid
= execCommand(btn
, (withSelection
? btn
->paste_command
: btn
->command
), NULL
);
819 if (btn
->buggy_app
) {
820 /* give feedback that the app was launched */
824 WMAddTimerHandler(200, (WMCallback
*) dockIconPaint
, btn
);
829 wwarning(_("could not launch application %s"), btn
->command
);
831 if (!btn
->relaunching
)
837 static void updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
839 WScreen
*scr
= menu
->frame
->screen_ptr
;
840 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
846 for (i
= 0; i
< scr
->workspace_count
; i
++) {
847 if (i
< menu
->entry_no
) {
848 if (strcmp(menu
->entries
[i
]->text
, scr
->workspaces
[i
]->name
) != 0) {
849 wfree(menu
->entries
[i
]->text
);
850 strcpy(title
, scr
->workspaces
[i
]->name
);
851 menu
->entries
[i
]->text
= wstrdup(title
);
852 menu
->flags
.realized
= 0;
854 menu
->entries
[i
]->clientdata
= (void *)icon
;
856 strcpy(title
, scr
->workspaces
[i
]->name
);
858 wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)icon
);
860 menu
->flags
.realized
= 0;
863 if (i
== scr
->current_workspace
)
864 wMenuSetEnabled(menu
, i
, False
);
866 wMenuSetEnabled(menu
, i
, True
);
869 if (!menu
->flags
.realized
)
873 static WMenu
*makeWorkspaceMenu(WScreen
*scr
)
877 menu
= wMenuCreate(scr
, NULL
, False
);
879 wwarning(_("could not create workspace submenu for Clip menu"));
881 wMenuAddCallback(menu
, "", switchWSCommand
, (void *)scr
->clip_icon
);
883 menu
->flags
.realized
= 0;
889 static void updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
898 entry
= menu
->entries
[index
];
899 entry
->flags
.indicator_on
= !dock
->lowered
;
900 entry
->clientdata
= dock
;
903 entry
= menu
->entries
[++index
];
904 entry
->flags
.indicator_on
= dock
->collapsed
;
905 entry
->clientdata
= dock
;
908 entry
= menu
->entries
[++index
];
909 entry
->flags
.indicator_on
= dock
->auto_collapse
;
910 entry
->clientdata
= dock
;
912 /* auto-raise/lower */
913 entry
= menu
->entries
[++index
];
914 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
915 entry
->clientdata
= dock
;
916 wMenuSetEnabled(menu
, index
, dock
->lowered
);
919 entry
= menu
->entries
[++index
];
920 entry
->flags
.indicator_on
= dock
->attract_icons
;
921 entry
->clientdata
= dock
;
923 menu
->flags
.realized
= 0;
927 static WMenu
*makeClipOptionsMenu(WScreen
*scr
)
932 menu
= wMenuCreate(scr
, NULL
, False
);
934 wwarning(_("could not create options submenu for Clip menu"));
938 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
939 entry
->flags
.indicator
= 1;
940 entry
->flags
.indicator_on
= 1;
941 entry
->flags
.indicator_type
= MI_CHECK
;
943 entry
= wMenuAddCallback(menu
, _("Collapsed"), toggleCollapsedCallback
, NULL
);
944 entry
->flags
.indicator
= 1;
945 entry
->flags
.indicator_on
= 1;
946 entry
->flags
.indicator_type
= MI_CHECK
;
948 entry
= wMenuAddCallback(menu
, _("Autocollapse"), toggleAutoCollapseCallback
, NULL
);
949 entry
->flags
.indicator
= 1;
950 entry
->flags
.indicator_on
= 1;
951 entry
->flags
.indicator_type
= MI_CHECK
;
953 entry
= wMenuAddCallback(menu
, _("Autoraise"), toggleAutoRaiseLowerCallback
, NULL
);
954 entry
->flags
.indicator
= 1;
955 entry
->flags
.indicator_on
= 1;
956 entry
->flags
.indicator_type
= MI_CHECK
;
958 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"), toggleAutoAttractCallback
, NULL
);
959 entry
->flags
.indicator
= 1;
960 entry
->flags
.indicator_on
= 1;
961 entry
->flags
.indicator_type
= MI_CHECK
;
963 menu
->flags
.realized
= 0;
969 static WMenu
*dockMenuCreate(WScreen
*scr
, int type
)
974 if (type
== WM_CLIP
&& scr
->clip_menu
)
975 return scr
->clip_menu
;
977 menu
= wMenuCreate(scr
, NULL
, False
);
978 if (type
!= WM_CLIP
) {
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
, _("Clip Options"), NULL
, NULL
);
985 scr
->clip_options
= makeClipOptionsMenu(scr
);
986 if (scr
->clip_options
)
987 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
989 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
991 entry
->text
= _("Rename Workspace");
993 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
994 entry
->flags
.indicator
= 1;
995 entry
->flags
.indicator_on
= 1;
996 entry
->flags
.indicator_type
= MI_CHECK
;
998 entry
= wMenuAddCallback(menu
, _("Select All Icons"), selectIconsCallback
, NULL
);
1000 entry
->text
= _("Select All Icons");
1002 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1004 entry
->text
= _("Keep Icon");
1006 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1008 entry
->text
= _("Move Icon To");
1009 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1010 if (scr
->clip_submenu
)
1011 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1013 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
, NULL
);
1015 entry
->text
= _("Remove Icon");
1017 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1020 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1022 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1024 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1026 entry
->text
= _("Hide");
1028 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1030 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1032 if (type
== WM_CLIP
)
1033 scr
->clip_menu
= menu
;
1038 WDock
*wDockCreate(WScreen
*scr
, int type
)
1045 dock
= wmalloc(sizeof(WDock
));
1047 dock
->max_icons
= DOCK_MAX_ICONS
;
1049 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * dock
->max_icons
);
1051 btn
= mainIconCreate(scr
, type
);
1055 dock
->x_pos
= btn
->x_pos
;
1056 dock
->y_pos
= btn
->y_pos
;
1057 dock
->screen_ptr
= scr
;
1059 dock
->icon_count
= 1;
1060 dock
->on_right_side
= 1;
1061 dock
->collapsed
= 0;
1062 dock
->auto_collapse
= 0;
1063 dock
->auto_collapse_magic
= NULL
;
1064 dock
->auto_raise_lower
= 0;
1065 dock
->auto_lower_magic
= NULL
;
1066 dock
->auto_raise_magic
= NULL
;
1067 dock
->attract_icons
= 0;
1069 dock
->icon_array
[0] = btn
;
1070 wRaiseFrame(btn
->icon
->core
);
1071 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1073 /* create dock menu */
1074 dock
->menu
= dockMenuCreate(scr
, type
);
1079 void wDockDestroy(WDock
*dock
)
1084 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1085 aicon
= dock
->icon_array
[i
];
1087 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1088 wDockDetach(dock
, aicon
);
1090 /* XXX: can: aicon->icon == NULL ? */
1091 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1092 wGetHeadForWindow(aicon
->icon
->owner
));
1093 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1094 if (!dock
->mapped
|| dock
->collapsed
)
1095 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1099 if (wPreferences
.auto_arrange_icons
)
1100 wArrangeIcons(dock
->screen_ptr
, True
);
1101 wfree(dock
->icon_array
);
1102 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1103 wMenuDestroy(dock
->menu
, True
);
1104 if (dock
->screen_ptr
->last_dock
== dock
)
1105 dock
->screen_ptr
->last_dock
= NULL
;
1109 void wClipIconPaint(WAppIcon
*aicon
)
1111 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1112 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1114 Window win
= aicon
->icon
->core
->window
;
1115 int length
, nlength
;
1116 char *ws_name
, ws_number
[10];
1119 wIconPaint(aicon
->icon
);
1121 length
= strlen(workspace
->name
);
1122 ws_name
= wmalloc(length
+ 1);
1123 snprintf(ws_name
, length
+ 1, "%s", workspace
->name
);
1124 snprintf(ws_number
, sizeof(ws_number
), "%i", scr
->current_workspace
+ 1);
1125 nlength
= strlen(ws_number
);
1127 if (!workspace
->clip
->collapsed
)
1128 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1130 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1132 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1134 tx
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
1136 if(wPreferences
.show_clip_title
)
1137 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, ty
, ws_name
, length
);
1139 tx
= (ICON_SIZE
/ 2 - WMWidthOfString(scr
->clip_title_font
, ws_number
, nlength
)) / 2;
1141 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, 2, ws_number
, nlength
);
1145 if (aicon
->launching
)
1146 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1147 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1149 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
, aicon
->dock
->rclip_button_pushed
);
1152 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1154 wClipIconPaint(desc
->parent
);
1157 static void dockIconPaint(WAppIcon
*btn
)
1159 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
) {
1160 wClipIconPaint(btn
);
1163 save_appicon(btn
, True
);
1167 static WMPropList
*make_icon_state(WAppIcon
*btn
)
1169 WMPropList
*node
= NULL
;
1170 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
;
1171 WMPropList
*position
, *buggy
, *omnipresent
;
1177 command
= WMCreatePLString("-");
1179 command
= WMCreatePLString(btn
->command
);
1181 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1183 lock
= btn
->lock
? dYes
: dNo
;
1185 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1187 name
= WMCreatePLString(tmp
);
1191 forced
= btn
->forced_dock
? dYes
: dNo
;
1193 buggy
= btn
->buggy_app
? dYes
: dNo
;
1195 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1196 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1198 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1199 position
= WMCreatePLString(buffer
);
1201 node
= WMCreatePLDictionary(dCommand
, command
,
1203 dAutoLaunch
, autolaunch
,
1205 dForced
, forced
, dBuggyApplication
, buggy
, dPosition
, position
, NULL
);
1206 WMReleasePropList(command
);
1207 WMReleasePropList(name
);
1208 WMReleasePropList(position
);
1210 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1211 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&& (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1212 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1214 #ifdef XDND /* was OFFIX */
1215 if (btn
->dnd_command
) {
1216 command
= WMCreatePLString(btn
->dnd_command
);
1217 WMPutInPLDictionary(node
, dDropCommand
, command
);
1218 WMReleasePropList(command
);
1222 if (btn
->paste_command
) {
1223 command
= WMCreatePLString(btn
->paste_command
);
1224 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1225 WMReleasePropList(command
);
1232 static WMPropList
*dockSaveState(WDock
*dock
)
1235 WMPropList
*icon_info
;
1236 WMPropList
*list
= NULL
, *dock_state
= NULL
;
1237 WMPropList
*value
, *key
;
1240 list
= WMCreatePLArray(NULL
);
1242 for (i
= (dock
->type
== WM_DOCK
? 0 : 1); i
< dock
->max_icons
; i
++) {
1243 WAppIcon
*btn
= dock
->icon_array
[i
];
1245 if (!btn
|| btn
->attracted
)
1248 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1249 WMAddToPLArray(list
, icon_info
);
1250 WMReleasePropList(icon_info
);
1254 dock_state
= WMCreatePLDictionary(dApplications
, list
, NULL
);
1256 if (dock
->type
== WM_DOCK
) {
1257 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1258 key
= WMCreatePLString(buffer
);
1259 WMPutInPLDictionary(dock_state
, key
, list
);
1260 WMReleasePropList(key
);
1262 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0), dock
->y_pos
);
1263 value
= WMCreatePLString(buffer
);
1264 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1265 WMReleasePropList(value
);
1267 WMReleasePropList(list
);
1269 value
= (dock
->lowered
? dYes
: dNo
);
1270 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1272 if (dock
->type
== WM_CLIP
) {
1273 value
= (dock
->collapsed
? dYes
: dNo
);
1274 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1276 value
= (dock
->auto_collapse
? dYes
: dNo
);
1277 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1279 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1280 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1282 value
= (dock
->attract_icons
? dYes
: dNo
);
1283 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1289 void wDockSaveState(WScreen
*scr
, WMPropList
*old_state
)
1291 WMPropList
*dock_state
;
1294 dock_state
= dockSaveState(scr
->dock
);
1297 * Copy saved states of docks with different sizes.
1303 keys
= WMGetPLDictionaryKeys(old_state
);
1304 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1305 tmp
= WMGetFromPLArray(keys
, i
);
1307 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1308 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1310 WMPutInPLDictionary(dock_state
, tmp
, WMGetFromPLDictionary(old_state
, tmp
));
1313 WMReleasePropList(keys
);
1316 WMPutInPLDictionary(scr
->session_state
, dDock
, dock_state
);
1318 WMReleasePropList(dock_state
);
1321 void wClipSaveState(WScreen
*scr
)
1323 WMPropList
*clip_state
;
1325 clip_state
= make_icon_state(scr
->clip_icon
);
1327 WMPutInPLDictionary(scr
->session_state
, dClip
, clip_state
);
1329 WMReleasePropList(clip_state
);
1332 WMPropList
*wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1334 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1337 static Bool
getBooleanDockValue(WMPropList
*value
, WMPropList
*key
)
1340 if (WMIsPLString(value
)) {
1341 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1344 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1350 static WAppIcon
*restore_icon_state(WScreen
*scr
, WMPropList
*info
, int type
, int index
)
1353 WMPropList
*cmd
, *value
;
1354 char *wclass
, *winstance
, *command
;
1356 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1357 if (!cmd
|| !WMIsPLString(cmd
))
1360 /* parse window name */
1361 value
= WMGetFromPLDictionary(info
, dName
);
1365 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1367 if (!winstance
&& !wclass
)
1372 command
= wstrdup(WMGetFromPLString(cmd
));
1376 if (!command
|| strcmp(command
, "-") == 0) {
1387 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1395 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1396 if (type
== WM_CLIP
) {
1397 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1398 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1400 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1401 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1403 #ifdef XDND /* was OFFIX */
1404 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1406 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1409 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1411 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1413 /* check auto launch */
1414 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1416 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1419 value
= WMGetFromPLDictionary(info
, dLock
);
1421 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1423 /* check if it wasn't normally docked */
1424 value
= WMGetFromPLDictionary(info
, dForced
);
1426 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1428 /* check if we can rely on the stuff in the app */
1429 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1431 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1433 /* get position in the dock */
1434 value
= WMGetFromPLDictionary(info
, dPosition
);
1435 if (value
&& WMIsPLString(value
)) {
1436 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1437 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1439 /* check position sanity */
1440 /* incomplete section! */
1441 if (type
== WM_DOCK
) {
1443 if (aicon
->yindex
< 0)
1444 wwarning(_("bad value in docked icon position %i,%i"),
1445 aicon
->xindex
, aicon
->yindex
);
1448 aicon
->yindex
= index
;
1452 /* check if icon is omnipresent */
1453 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1455 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1463 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1465 WAppIcon
*wClipRestoreState(WScreen
*scr
, WMPropList
*clip_state
)
1470 icon
= mainIconCreate(scr
, WM_CLIP
);
1475 WMRetainPropList(clip_state
);
1477 /* restore position */
1479 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1482 if (!WMIsPLString(value
)) {
1483 COMPLAIN("Position");
1485 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1486 COMPLAIN("Position");
1488 /* check position sanity */
1489 if (!onScreen(scr
, icon
->x_pos
, icon
->y_pos
))
1490 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1493 #ifdef XDND /* was OFFIX */
1494 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1495 if (value
&& WMIsPLString(value
))
1496 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1499 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1500 if (value
&& WMIsPLString(value
))
1501 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1503 WMReleasePropList(clip_state
);
1508 WDock
*wDockRestoreState(WScreen
*scr
, WMPropList
*dock_state
, int type
)
1513 WAppIcon
*aicon
, *old_top
;
1516 dock
= wDockCreate(scr
, type
);
1521 WMRetainPropList(dock_state
);
1523 /* restore position */
1524 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1526 if (!WMIsPLString(value
)) {
1527 COMPLAIN("Position");
1529 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1530 COMPLAIN("Position");
1532 /* check position sanity */
1533 if (!onScreen(scr
, dock
->x_pos
, dock
->y_pos
)) {
1534 int x
= dock
->x_pos
;
1535 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1538 /* Is this needed any more? */
1539 if (type
== WM_CLIP
) {
1540 if (dock
->x_pos
< 0) {
1542 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1543 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1546 if (dock
->x_pos
>= 0) {
1547 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1548 dock
->on_right_side
= 0;
1550 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1551 dock
->on_right_side
= 1;
1557 /* restore lowered/raised state */
1560 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1562 if (!WMIsPLString(value
)) {
1563 COMPLAIN("Lowered");
1565 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1570 /* restore collapsed state */
1571 dock
->collapsed
= 0;
1573 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1575 if (!WMIsPLString(value
)) {
1576 COMPLAIN("Collapsed");
1578 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1579 dock
->collapsed
= 1;
1583 /* restore auto-collapsed state */
1584 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1586 if (!WMIsPLString(value
)) {
1587 COMPLAIN("AutoCollapse");
1589 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1590 dock
->auto_collapse
= 1;
1591 dock
->collapsed
= 1;
1596 /* restore auto-raise/lower state */
1597 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1599 if (!WMIsPLString(value
)) {
1600 COMPLAIN("AutoRaiseLower");
1602 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1603 dock
->auto_raise_lower
= 1;
1607 /* restore attract icons state */
1608 dock
->attract_icons
= 0;
1610 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1612 if (!WMIsPLString(value
)) {
1613 COMPLAIN("AutoAttractIcons");
1615 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1616 dock
->attract_icons
= 1;
1620 /* application list */
1627 * When saving, it saves the dock state in
1628 * Applications and Applicationsnnn
1630 * When loading, it will first try Applicationsnnn.
1631 * If it does not exist, use Applications as default.
1634 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1636 tmp
= WMCreatePLString(buffer
);
1637 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1638 WMReleasePropList(tmp
);
1641 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1647 count
= WMGetPropListItemCount(apps
);
1651 old_top
= dock
->icon_array
[0];
1653 /* dock->icon_count is set to 1 when dock is created.
1654 * Since Clip is already restored, we want to keep it so for clip,
1655 * but for dock we may change the default top tile, so we set it to 0.
1657 if (type
== WM_DOCK
)
1658 dock
->icon_count
= 0;
1660 for (i
= 0; i
< count
; i
++) {
1661 if (dock
->icon_count
>= dock
->max_icons
) {
1662 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1666 value
= WMGetFromPLArray(apps
, i
);
1667 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1669 dock
->icon_array
[dock
->icon_count
] = aicon
;
1673 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1674 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1677 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1679 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1681 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1682 if (!dock
->collapsed
)
1683 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1685 wRaiseFrame(aicon
->icon
->core
);
1688 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
) {
1693 /* if the first icon is not defined, use the default */
1694 if (dock
->icon_array
[0] == NULL
) {
1695 /* update default icon */
1696 old_top
->x_pos
= dock
->x_pos
;
1697 old_top
->y_pos
= dock
->y_pos
;
1699 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1701 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1703 dock
->icon_array
[0] = old_top
;
1704 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1705 /* we don't need to increment dock->icon_count here because it was
1706 * incremented in the loop above.
1708 } else if (old_top
!= dock
->icon_array
[0]) {
1709 if (old_top
== scr
->clip_icon
)
1710 scr
->clip_icon
= dock
->icon_array
[0];
1712 wAppIconDestroy(old_top
);
1716 WMReleasePropList(dock_state
);
1721 void wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1723 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1724 btn
->drop_launch
= 0;
1725 btn
->paste_launch
= 0;
1727 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1730 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1740 void wDockDoAutoLaunch(WDock
*dock
, int workspace
)
1746 for (i
= 0; i
< dock
->max_icons
; i
++) {
1747 btn
= dock
->icon_array
[i
];
1748 if (!btn
|| !btn
->auto_launch
)
1751 state
= wmalloc(sizeof(WSavedState
));
1752 state
->workspace
= workspace
;
1753 /* TODO: this is klugy and is very difficult to understand
1754 * what's going on. Try to clean up */
1755 wDockLaunchWithState(dock
, btn
, state
);
1759 #ifdef XDND /* was OFFIX */
1760 static WDock
*findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
1766 if ((dock
= scr
->dock
) != NULL
) {
1767 for (i
= 0; i
< dock
->max_icons
; i
++) {
1768 if (dock
->icon_array
[i
]
1769 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1775 if (*icon_pos
< 0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
) != NULL
) {
1776 for (i
= 0; i
< dock
->max_icons
; i
++) {
1777 if (dock
->icon_array
[i
]
1778 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
1789 int wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
1795 dock
= findDock(scr
, event
, &icon_pos
);
1800 * Return True if the drop was on an application icon window.
1801 * In this case, let the ClientMessage handler redirect the
1802 * message to the app.
1804 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
1807 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
1808 scr
->flags
.dnd_data_convertion_status
= 0;
1810 btn
= dock
->icon_array
[icon_pos
];
1812 if (!btn
->forced_dock
) {
1813 btn
->relaunching
= btn
->running
;
1816 if (btn
->wm_instance
|| btn
->wm_class
) {
1817 WWindowAttributes attr
;
1818 memset(&attr
, 0, sizeof(WWindowAttributes
));
1819 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
1821 if (!attr
.no_appicon
)
1827 btn
->paste_launch
= 0;
1828 btn
->drop_launch
= 1;
1829 scr
->last_dock
= dock
;
1830 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
1835 if (!btn
->relaunching
)
1843 Bool
wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
, Bool update_icon
)
1846 Bool lupdate_icon
= False
;
1847 char *command
= NULL
;
1853 lupdate_icon
= True
;
1855 if (icon
->command
== NULL
) {
1856 /* If icon->owner exists, it means the application is running */
1857 if (icon
->icon
->owner
) {
1858 wwin
= icon
->icon
->owner
;
1859 command
= GetCommandForWindow(wwin
->client_win
);
1863 icon
->command
= command
;
1865 /* icon->forced_dock = 1; */
1866 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
1868 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
1869 _("Type the command used to launch the application"), &command
)) {
1870 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
1874 icon
->command
= command
;
1880 /* If the target is the dock, reject the icon. If
1881 * the target is the clip, make it an attracted icon
1883 if (dock
->type
== WM_CLIP
) {
1884 icon
->attracted
= 1;
1885 if (!icon
->icon
->shadowed
) {
1886 icon
->icon
->shadowed
= 1;
1887 lupdate_icon
= True
;
1897 for (index
= 1; index
< dock
->max_icons
; index
++)
1898 if (dock
->icon_array
[index
] == NULL
)
1900 /* if (index == dock->max_icons)
1903 assert(index
< dock
->max_icons
);
1905 dock
->icon_array
[index
] = icon
;
1909 icon
->omnipresent
= 0;
1911 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
1912 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
1917 icon
->launching
= 0;
1920 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1921 if (dock
->type
== WM_CLIP
) {
1922 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1923 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1925 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1926 icon
->icon
->core
->descriptor
.parent
= icon
;
1928 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
1929 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
1931 /* Update the icon images */
1933 wIconUpdate(icon
->icon
, NULL
);
1936 wAppIconPaint(icon
);
1939 save_appicon(icon
, True
);
1941 if (wPreferences
.auto_arrange_icons
)
1942 wArrangeIcons(dock
->screen_ptr
, True
);
1944 #ifdef XDND /* was OFFIX */
1945 if (icon
->command
&& !icon
->dnd_command
) {
1946 int len
= strlen(icon
->command
) + 8;
1947 icon
->dnd_command
= wmalloc(len
);
1948 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
1952 if (icon
->command
&& !icon
->paste_command
) {
1953 int len
= strlen(icon
->command
) + 8;
1954 icon
->paste_command
= wmalloc(len
);
1955 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
1961 void wDockReattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
1965 for (index
= 1; index
< dock
->max_icons
; index
++) {
1966 if (dock
->icon_array
[index
] == icon
)
1969 assert(index
< dock
->max_icons
);
1974 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
1975 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
1978 Bool
wDockMoveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
1981 char *command
= NULL
;
1983 Bool update_icon
= False
;
1986 return True
; /* No move needed, we're already there */
1992 * For the moment we can't do this if we move icons in Clip from one
1993 * workspace to other, because if we move two or more icons without
1994 * command, the dialog box will not be able to tell us to which of the
1995 * moved icons it applies. -Dan
1997 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
1998 /* If icon->owner exists, it means the application is running */
1999 if (icon
->icon
->owner
) {
2000 wwin
= icon
->icon
->owner
;
2001 command
= GetCommandForWindow(wwin
->client_win
);
2005 icon
->command
= command
;
2008 /* icon->forced_dock = 1; */
2009 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2010 _("Type the command used to launch the application"), &command
)) {
2011 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2015 icon
->command
= command
;
2026 if (dest
->type
== WM_DOCK
)
2027 wClipMakeIconOmnipresent(icon
, False
);
2029 for (index
= 1; index
< src
->max_icons
; index
++) {
2030 if (src
->icon_array
[index
] == icon
)
2033 assert(index
< src
->max_icons
);
2035 src
->icon_array
[index
] = NULL
;
2038 for (index
= 1; index
< dest
->max_icons
; index
++) {
2039 if (dest
->icon_array
[index
] == NULL
)
2043 assert(index
< dest
->max_icons
);
2045 dest
->icon_array
[index
] = icon
;
2048 /* deselect the icon */
2049 if (icon
->icon
->selected
)
2050 wIconSelect(icon
->icon
);
2052 if (dest
->type
== WM_DOCK
) {
2053 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2054 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2056 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2057 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2060 /* set it to be kept when moving to dock.
2061 * Unless the icon does not have a command set
2063 if (icon
->command
&& dest
->type
== WM_DOCK
) {
2064 icon
->attracted
= 0;
2065 if (icon
->icon
->shadowed
) {
2066 icon
->icon
->shadowed
= 0;
2069 save_appicon(icon
, True
);
2072 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2078 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2079 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2083 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2085 /* Update the icon images */
2087 wIconUpdate(icon
->icon
, NULL
);
2090 wAppIconPaint(icon
);
2095 void wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2098 Bool update_icon
= False
;
2100 /* make the settings panel be closed */
2102 DestroyDockAppSettingsPanel(icon
->panel
);
2104 /* This must be called before icon->dock is set to NULL.
2105 * Don't move it. -Dan
2107 wClipMakeIconOmnipresent(icon
, False
);
2111 icon
->attracted
= 0;
2112 icon
->auto_launch
= 0;
2113 if (icon
->icon
->shadowed
) {
2114 icon
->icon
->shadowed
= 0;
2118 /* deselect the icon */
2119 if (icon
->icon
->selected
)
2120 wIconSelect(icon
->icon
);
2122 if (icon
->command
) {
2123 wfree(icon
->command
);
2124 icon
->command
= NULL
;
2126 #ifdef XDND /* was OFFIX */
2127 if (icon
->dnd_command
) {
2128 wfree(icon
->dnd_command
);
2129 icon
->dnd_command
= NULL
;
2132 if (icon
->paste_command
) {
2133 wfree(icon
->paste_command
);
2134 icon
->paste_command
= NULL
;
2137 for (index
= 1; index
< dock
->max_icons
; index
++)
2138 if (dock
->icon_array
[index
] == icon
)
2141 assert(index
< dock
->max_icons
);
2142 dock
->icon_array
[index
] = NULL
;
2148 /* if the dock is not attached to an application or
2149 * the application did not set the appropriate hints yet,
2150 * destroy the icon */
2151 if (!icon
->running
|| !wApplicationOf(icon
->main_window
)) {
2152 wAppIconDestroy(icon
);
2154 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2155 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2156 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2157 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2158 icon
->icon
->core
->descriptor
.parent
= icon
;
2160 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2162 /* Update the icon images */
2164 wIconUpdate(icon
->icon
, NULL
);
2167 wAppIconPaint(icon
);
2169 if (wPreferences
.auto_arrange_icons
)
2170 wArrangeIcons(dock
->screen_ptr
, True
);
2172 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2177 * returns the closest Dock slot index for the passed
2180 * Returns False if icon can't be docked.
2182 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2185 Bool
wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2187 WScreen
*scr
= dock
->screen_ptr
;
2190 int i
, offset
= ICON_SIZE
/ 2;
2191 WAppIcon
*aicon
= NULL
;
2192 WAppIcon
*nicon
= NULL
;
2195 /* TODO: XINERAMA, for these */
2196 max_y_icons
= scr
->scr_height
/ ICON_SIZE
- 1;
2198 if (wPreferences
.flags
.noupdates
)
2204 /* if the dock is full */
2205 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
))
2208 /* exact position */
2210 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2212 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2215 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2217 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2219 /* check if the icon is outside the screen boundaries */
2220 if (!onScreen(scr
, dx
+ ex_x
* ICON_SIZE
, dy
+ ex_y
* ICON_SIZE
))
2223 if (dock
->type
== WM_DOCK
) {
2224 if (icon
->dock
!= dock
&& ex_x
!= 0)
2228 for (i
= 0; i
< dock
->max_icons
; i
++) {
2229 nicon
= dock
->icon_array
[i
];
2230 if (nicon
&& nicon
->yindex
== ex_y
) {
2237 int sig
, done
, closest
;
2239 /* Possible cases when redocking:
2241 * icon dragged out of range of any slot -> false
2242 * icon dragged to range of free slot
2243 * icon dragged to range of same slot
2244 * icon dragged to range of different icon
2246 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2249 if (ex_y
>= 0 && ex_y
<= max_y_icons
&& (aicon
== icon
|| !aicon
)) {
2255 /* start looking at the upper slot or lower? */
2256 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2263 /* look for closest free slot */
2264 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2268 closest
= sig
* (i
/ 2) + ex_y
;
2269 /* check if this slot is used */
2271 for (j
= 0; j
< dock
->max_icons
; j
++) {
2272 if (dock
->icon_array
[j
]
2273 && dock
->icon_array
[j
]->yindex
== closest
) {
2274 /* slot is used by someone else */
2275 if (dock
->icon_array
[j
] != icon
)
2283 if (done
&& closest
>= 0 && closest
<= max_y_icons
&&
2284 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2285 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2290 } else { /* !redocking */
2292 /* if slot is free and the icon is close enough, return it */
2293 if (!aicon
&& ex_x
== 0 && ex_y
>= 0 && ex_y
<= max_y_icons
) {
2303 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2304 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+ 1;
2307 for (k
= start
; k
< stop
; k
++) {
2308 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2311 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2312 nicon
= tmp
->icon_array
[i
];
2313 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2321 for (k
= start
; k
< stop
; k
++) {
2322 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2325 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2326 nicon
= tmp
->icon_array
[i
];
2327 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2328 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2329 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2338 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2347 static int onScreen(WScreen
*scr
, int x
, int y
)
2354 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2356 wGetRectPlacementInfo(scr
, rect
, &flags
);
2358 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2362 * returns true if it can find a free slot in the dock,
2363 * in which case it changes x_pos and y_pos accordingly.
2364 * Else returns false.
2366 Bool
wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2368 WScreen
*scr
= dock
->screen_ptr
;
2370 WAppIconChain
*chain
;
2371 unsigned char *slot_map
;
2375 int i
, done
= False
;
2377 int sx
= 0, ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2378 int extra_count
= 0;
2380 if (dock
->type
== WM_CLIP
&& dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2381 extra_count
= scr
->global_icon_count
;
2383 /* if the dock is full */
2384 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
)
2387 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2388 if (scr
->dock
->on_right_side
)
2389 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2391 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2394 if (ex
< dock
->x_pos
)
2396 if (sx
> dock
->x_pos
+ ICON_SIZE
)
2397 sx
= dock
->x_pos
+ ICON_SIZE
;
2404 /* check if clip is in a corner */
2405 if (dock
->type
== WM_CLIP
) {
2406 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2408 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2410 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2412 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2420 /* If the clip is in the corner, use only slots that are in the border
2422 if (corner
!= C_NONE
) {
2426 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2427 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2428 hmap
= wmalloc(hcount
+ 1);
2429 vmap
= wmalloc(vcount
+ 1);
2431 /* mark used positions */
2434 for (i
= 0; i
< dock
->max_icons
; i
++) {
2435 btn
= dock
->icon_array
[i
];
2439 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2440 vmap
[btn
->yindex
] = 1;
2441 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2442 hmap
[btn
->xindex
] = 1;
2444 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2446 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2447 vmap
[btn
->yindex
] = 1;
2448 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2449 hmap
[btn
->xindex
] = 1;
2453 for (i
= 0; i
< dock
->max_icons
; i
++) {
2454 btn
= dock
->icon_array
[i
];
2458 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2459 vmap
[btn
->yindex
] = 1;
2460 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2461 hmap
[-btn
->xindex
] = 1;
2463 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2465 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2466 vmap
[btn
->yindex
] = 1;
2467 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2468 hmap
[-btn
->xindex
] = 1;
2472 for (i
= 0; i
< dock
->max_icons
; i
++) {
2473 btn
= dock
->icon_array
[i
];
2477 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2478 vmap
[-btn
->yindex
] = 1;
2479 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2480 hmap
[btn
->xindex
] = 1;
2482 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2484 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2485 vmap
[-btn
->yindex
] = 1;
2486 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2487 hmap
[btn
->xindex
] = 1;
2492 for (i
= 0; i
< dock
->max_icons
; i
++) {
2493 btn
= dock
->icon_array
[i
];
2497 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2498 vmap
[-btn
->yindex
] = 1;
2499 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2500 hmap
[-btn
->xindex
] = 1;
2502 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2504 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2505 vmap
[-btn
->yindex
] = 1;
2506 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2507 hmap
[-btn
->xindex
] = 1;
2513 /* search a vacant slot */
2514 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2515 if (i
< vcount
&& vmap
[i
] == 0) {
2521 } else if (i
< hcount
&& hmap
[i
] == 0) {
2531 /* If found a slot, translate and return */
2533 if (corner
== C_NW
|| corner
== C_NE
)
2538 if (corner
== C_NE
|| corner
== C_SE
)
2545 /* else, try to find a slot somewhere else */
2548 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2549 * placed outside of screen */
2550 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2552 /* In the worst case (the clip is in the corner of the screen),
2553 * the amount of icons that fit in the clip is smaller.
2554 * Double the map to get a safe value.
2558 r
= (mwidth
- 1) / 2;
2560 slot_map
= wmalloc(mwidth
* mwidth
);
2562 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2564 /* mark used slots in the map. If the slot falls outside the map
2565 * (for example, when all icons are placed in line), ignore them. */
2566 for (i
= 0; i
< dock
->max_icons
; i
++) {
2567 btn
= dock
->icon_array
[i
];
2569 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2572 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
)
2573 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2575 /* Find closest slot from the center that is free by scanning the
2576 * map from the center to outward in circular passes.
2577 * This will not result in a neat layout, but will be optimal
2578 * in the sense that there will not be holes left.
2581 for (i
= 1; i
<= r
&& !done
; i
++) {
2584 /* top and bottom parts of the ring */
2585 for (x
= -i
; x
<= i
&& !done
; x
++) {
2586 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2588 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2589 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2596 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2597 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2604 /* left and right parts of the ring */
2605 for (y
= -i
+ 1; y
<= i
- 1; y
++) {
2606 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2608 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2609 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2616 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2617 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2630 static void moveDock(WDock
*dock
, int new_x
, int new_y
)
2635 dock
->x_pos
= new_x
;
2636 dock
->y_pos
= new_y
;
2637 for (i
= 0; i
< dock
->max_icons
; i
++) {
2638 btn
= dock
->icon_array
[i
];
2640 btn
->x_pos
= new_x
+ btn
->xindex
* ICON_SIZE
;
2641 btn
->y_pos
= new_y
+ btn
->yindex
* ICON_SIZE
;
2642 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2647 static void swapDock(WDock
*dock
)
2649 WScreen
*scr
= dock
->screen_ptr
;
2653 if (dock
->on_right_side
)
2654 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2656 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2658 for (i
= 0; i
< dock
->max_icons
; i
++) {
2659 btn
= dock
->icon_array
[i
];
2662 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2666 wScreenUpdateUsableArea(scr
);
2669 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
2671 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
2677 cmdline
= ExpandOptions(scr
, command
);
2679 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
2687 wtokensplit(cmdline
, &argv
, &argc
);
2697 if ((pid
= fork()) == 0) {
2701 SetupEnvironment(scr
);
2707 args
= malloc(sizeof(char *) * (argc
+ 1));
2711 for (i
= 0; i
< argc
; i
++)
2715 execvp(argv
[0], args
);
2718 wtokenfree(argv
, argc
);
2722 state
= wmalloc(sizeof(WSavedState
));
2724 state
->miniaturized
= -1;
2726 if (btn
->dock
== scr
->dock
|| btn
->omnipresent
)
2727 state
->workspace
= -1;
2729 state
->workspace
= scr
->current_workspace
;
2731 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
2732 wAddDeathHandler(pid
, (WDeathHandler
*) trackDeadProcess
, btn
->dock
);
2740 void wDockHideIcons(WDock
*dock
)
2747 for (i
= 1; i
< dock
->max_icons
; i
++) {
2748 if (dock
->icon_array
[i
])
2749 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2753 dockIconPaint(dock
->icon_array
[0]);
2756 void wDockShowIcons(WDock
*dock
)
2764 btn
= dock
->icon_array
[0];
2765 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
2767 newlevel
= dock
->lowered
? WMNormalLevel
: WMDockLevel
;
2768 ChangeStackingLevel(btn
->icon
->core
, newlevel
);
2770 for (i
= 1; i
< dock
->max_icons
; i
++) {
2771 if (dock
->icon_array
[i
]) {
2772 MoveInStackListAbove(dock
->icon_array
[i
]->icon
->core
, btn
->icon
->core
);
2777 if (!dock
->collapsed
) {
2778 for (i
= 1; i
< dock
->max_icons
; i
++) {
2779 if (dock
->icon_array
[i
])
2780 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
2788 void wDockLower(WDock
*dock
)
2792 for (i
= 0; i
< dock
->max_icons
; i
++) {
2793 if (dock
->icon_array
[i
])
2794 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
2798 void wDockRaise(WDock
*dock
)
2802 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
2803 if (dock
->icon_array
[i
])
2804 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
2808 void wDockRaiseLower(WDock
*dock
)
2810 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
2811 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
2812 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
2818 void wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
2820 icon
->launching
= 0;
2821 icon
->relaunching
= 0;
2822 dockIconPaint(icon
);
2825 WAppIcon
*wDockFindIconForWindow(WDock
*dock
, Window window
)
2830 for (i
= 0; i
< dock
->max_icons
; i
++) {
2831 icon
= dock
->icon_array
[i
];
2832 if (icon
&& icon
->main_window
== window
)
2838 void wDockTrackWindowLaunch(WDock
*dock
, Window window
)
2841 char *wm_class
, *wm_instance
;
2843 Bool firstPass
= True
;
2845 char *command
= NULL
;
2847 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) || (!wm_class
&& !wm_instance
))
2850 command
= GetCommandForWindow(window
);
2852 for (i
= 0; i
< dock
->max_icons
; i
++) {
2853 icon
= dock
->icon_array
[i
];
2857 /* app is already attached to icon */
2858 if (icon
->main_window
== window
) {
2863 if ((icon
->wm_instance
|| icon
->wm_class
)
2864 && (icon
->launching
|| !icon
->running
)) {
2866 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0)
2869 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0)
2872 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0)
2875 if (!icon
->relaunching
) {
2878 /* Possibly an application that was docked with dockit,
2879 * but the user did not update WMState to indicate that
2880 * it was docked by force */
2881 wapp
= wApplicationOf(window
);
2883 icon
->forced_dock
= 1;
2886 if (!icon
->forced_dock
)
2887 icon
->main_window
= window
;
2890 if (!wPreferences
.no_animations
&& !icon
->launching
&&
2891 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
2895 icon
->launching
= 1;
2896 dockIconPaint(icon
);
2898 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
2899 wm_instance
, wm_class
, TILE_NORMAL
);
2900 /* XXX: can: aicon->icon == NULL ? */
2901 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
2902 wAppIconMove(aicon
, x0
, y0
);
2903 /* Should this always be lowered? -Dan */
2905 wLowerFrame(aicon
->icon
->core
);
2906 XMapWindow(dpy
, aicon
->icon
->core
->window
);
2907 aicon
->launching
= 1;
2908 wAppIconPaint(aicon
);
2909 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
2910 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
2911 wAppIconDestroy(aicon
);
2913 wDockFinishLaunch(dock
, icon
);
2918 if (firstPass
&& !found
) {
2932 void wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
2934 if (!wPreferences
.flags
.noclip
) {
2935 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
2936 if (scr
->current_workspace
!= workspace
) {
2937 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
2938 WAppIconChain
*chain
= scr
->global_icons
;
2941 wDockMoveIconBetweenDocks(chain
->aicon
->dock
,
2942 scr
->workspaces
[workspace
]->clip
,
2943 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
2944 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
2945 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
2946 chain
= chain
->next
;
2949 wDockHideIcons(old_clip
);
2950 if (old_clip
->auto_raise_lower
) {
2951 if (old_clip
->auto_raise_magic
) {
2952 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
2953 old_clip
->auto_raise_magic
= NULL
;
2955 wDockLower(old_clip
);
2957 if (old_clip
->auto_collapse
) {
2958 if (old_clip
->auto_expand_magic
) {
2959 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
2960 old_clip
->auto_expand_magic
= NULL
;
2962 old_clip
->collapsed
= 1;
2964 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
2969 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
2974 for (i
= 0; i
< dock
->max_icons
; i
++) {
2975 icon
= dock
->icon_array
[i
];
2979 if (icon
->launching
&& icon
->pid
== pid
) {
2980 if (!icon
->relaunching
) {
2982 icon
->main_window
= None
;
2984 wDockFinishLaunch(dock
, icon
);
2986 if (status
== 111) {
2991 if (icon
->drop_launch
)
2992 cmd
= icon
->dnd_command
;
2995 if (icon
->paste_launch
)
2996 cmd
= icon
->paste_command
;
2998 cmd
= icon
->command
;
3000 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3002 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3009 static void toggleLowered(WDock
*dock
)
3014 /* lower/raise Dock */
3015 if (!dock
->lowered
) {
3016 newlevel
= WMNormalLevel
;
3019 newlevel
= WMDockLevel
;
3023 for (i
= 0; i
< dock
->max_icons
; i
++) {
3024 tmp
= dock
->icon_array
[i
];
3028 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3030 wLowerFrame(tmp
->icon
->core
);
3033 if (dock
->type
== WM_DOCK
)
3034 wScreenUpdateUsableArea(dock
->screen_ptr
);
3037 static void toggleCollapsed(WDock
*dock
)
3039 if (dock
->collapsed
) {
3040 dock
->collapsed
= 0;
3041 wDockShowIcons(dock
);
3043 dock
->collapsed
= 1;
3044 wDockHideIcons(dock
);
3048 static void openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3050 WScreen
*scr
= dock
->screen_ptr
;
3051 WObjDescriptor
*desc
;
3053 WApplication
*wapp
= NULL
;
3057 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3059 if (dock
->type
== WM_DOCK
) {
3061 entry
= dock
->menu
->entries
[index
];
3062 entry
->flags
.indicator_on
= !dock
->lowered
;
3063 entry
->clientdata
= dock
;
3064 dock
->menu
->flags
.realized
= 0;
3067 if (scr
->clip_options
)
3068 updateClipOptionsMenu(scr
->clip_options
, dock
);
3070 n_selected
= numberOfSelectedIcons(dock
);
3072 /* Rename Workspace */
3073 entry
= dock
->menu
->entries
[++index
];
3074 if (aicon
== scr
->clip_icon
) {
3075 entry
->callback
= renameCallback
;
3076 entry
->clientdata
= dock
;
3077 entry
->flags
.indicator
= 0;
3078 entry
->text
= _("Rename Workspace");
3080 entry
->callback
= omnipresentCallback
;
3081 entry
->clientdata
= aicon
;
3082 if (n_selected
> 0) {
3083 entry
->flags
.indicator
= 0;
3084 entry
->text
= _("Toggle Omnipresent");
3086 entry
->flags
.indicator
= 1;
3087 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3088 entry
->flags
.indicator_type
= MI_CHECK
;
3089 entry
->text
= _("Omnipresent");
3093 /* select/unselect icon */
3094 entry
= dock
->menu
->entries
[++index
];
3095 entry
->clientdata
= aicon
;
3096 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3097 wMenuSetEnabled(dock
->menu
, index
, aicon
!= scr
->clip_icon
);
3099 /* select/unselect all icons */
3100 entry
= dock
->menu
->entries
[++index
];
3101 entry
->clientdata
= aicon
;
3103 entry
->text
= _("Unselect All Icons");
3105 entry
->text
= _("Select All Icons");
3107 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3110 entry
= dock
->menu
->entries
[++index
];
3111 entry
->clientdata
= aicon
;
3113 entry
->text
= _("Keep Icons");
3115 entry
->text
= _("Keep Icon");
3117 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3119 /* this is the workspace submenu part */
3120 entry
= dock
->menu
->entries
[++index
];
3122 entry
->text
= _("Move Icons To");
3124 entry
->text
= _("Move Icon To");
3126 if (scr
->clip_submenu
)
3127 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3129 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3131 /* remove icon(s) */
3132 entry
= dock
->menu
->entries
[++index
];
3133 entry
->clientdata
= aicon
;
3135 entry
->text
= _("Remove Icons");
3137 entry
->text
= _("Remove Icon");
3139 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3141 /* attract icon(s) */
3142 entry
= dock
->menu
->entries
[++index
];
3143 entry
->clientdata
= aicon
;
3145 dock
->menu
->flags
.realized
= 0;
3146 wMenuRealize(dock
->menu
);
3149 if (aicon
->icon
->owner
)
3150 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3155 entry
= dock
->menu
->entries
[++index
];
3156 entry
->clientdata
= aicon
;
3157 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3160 entry
= dock
->menu
->entries
[++index
];
3161 entry
->clientdata
= aicon
;
3162 if (wapp
&& wapp
->flags
.hidden
)
3163 entry
->text
= _("Unhide Here");
3165 entry
->text
= _("Bring Here");
3167 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3170 entry
= dock
->menu
->entries
[++index
];
3171 entry
->clientdata
= aicon
;
3172 if (wapp
&& wapp
->flags
.hidden
)
3173 entry
->text
= _("Unhide");
3175 entry
->text
= _("Hide");
3177 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3180 entry
= dock
->menu
->entries
[++index
];
3181 entry
->clientdata
= aicon
;
3182 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3185 entry
= dock
->menu
->entries
[++index
];
3186 entry
->clientdata
= aicon
;
3187 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3189 if (!dock
->menu
->flags
.realized
)
3190 wMenuRealize(dock
->menu
);
3192 if (dock
->type
== WM_CLIP
) {
3193 /*x_pos = event->xbutton.x_root+2; */
3194 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3197 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3198 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3201 x_pos
= dock
->on_right_side
? scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3204 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3206 /* allow drag select */
3207 event
->xany
.send_event
= True
;
3208 desc
= &dock
->menu
->menu
->descriptor
;
3209 (*desc
->handle_mousedown
) (desc
, event
);
3212 /******************************************************************/
3213 static void iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3215 WAppIcon
*btn
= desc
->parent
;
3216 WDock
*dock
= btn
->dock
;
3217 WApplication
*wapp
= NULL
;
3220 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3221 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3223 assert(wapp
!= NULL
);
3225 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3227 /* go to the last workspace that the user worked on the app */
3228 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
&& !unhideHere
)
3229 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3231 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3233 if (event
->xbutton
.state
& MOD_MASK
)
3234 wHideOtherApplications(btn
->icon
->owner
);
3236 if (event
->xbutton
.button
== Button1
) {
3237 if (event
->xbutton
.state
& MOD_MASK
) {
3238 /* raise/lower dock */
3239 toggleLowered(dock
);
3240 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3241 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
)
3242 toggleCollapsed(dock
);
3244 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3245 } else if (btn
->command
) {
3246 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3247 launchDockedApplication(btn
, False
);
3248 } else if (btn
->xindex
== 0 && btn
->yindex
== 0 && btn
->dock
->type
== WM_DOCK
) {
3249 wShowInfoPanel(dock
->screen_ptr
);
3255 static void handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3257 WScreen
*scr
= dock
->screen_ptr
;
3258 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3261 int grabbed
= 0, swapped
= 0, done
;
3262 Pixmap ghost
= None
;
3263 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3265 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3266 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3267 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
)
3268 wwarning("pointer grab failed for dock move");
3271 for (x
= 0; x
< dock
->max_icons
; x
++) {
3272 if (dock
->icon_array
[x
] != NULL
&& dock
->icon_array
[x
]->yindex
> y
)
3273 y
= dock
->icon_array
[x
]->yindex
;
3276 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
* y
);
3280 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3281 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3288 /* It means the cursor moved so fast that it entered
3289 * something else (if moving slowly, it would have
3290 * stayed in the dock that is being moved. Ignore such
3291 * "spurious" EnterNotifiy's */
3296 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3297 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3298 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3299 | ButtonReleaseMask
| ButtonPressMask
,
3300 wCursor
[WCUR_MOVE
], CurrentTime
);
3305 if (dock
->type
== WM_CLIP
) {
3306 x
= ev
.xmotion
.x_root
- ofs_x
;
3307 y
= ev
.xmotion
.y_root
- ofs_y
;
3308 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3310 moveDock(dock
, x
, y
);
3312 /* move vertically if pointer is inside the dock */
3313 if ((dock
->on_right_side
&& ev
.xmotion
.x_root
>= dock
->x_pos
- ICON_SIZE
)
3314 || (!dock
->on_right_side
&& ev
.xmotion
.x_root
<= dock
->x_pos
+ ICON_SIZE
* 2)) {
3316 x
= ev
.xmotion
.x_root
- ofs_x
;
3317 y
= ev
.xmotion
.y_root
- ofs_y
;
3318 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3319 moveDock(dock
, dock
->x_pos
, y
);
3321 /* move horizontally to change sides */
3322 x
= ev
.xmotion
.x_root
- ofs_x
;
3323 if (!dock
->on_right_side
) {
3326 if (ev
.xmotion
.x_root
> dock
->x_pos
+ ICON_SIZE
* 2) {
3327 XMoveWindow(dpy
, scr
->dock_shadow
, scr
->scr_width
- ICON_SIZE
3328 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3329 if (superfluous
&& ghost
== None
) {
3330 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3331 scr
->scr_width
- ICON_SIZE
3332 - DOCK_EXTRA_SPACE
- 1, dock
->y_pos
);
3333 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3334 XClearWindow(dpy
, scr
->dock_shadow
);
3336 XMapRaised(dpy
, scr
->dock_shadow
);
3339 if (superfluous
&& ghost
!= None
) {
3340 XFreePixmap(dpy
, ghost
);
3343 XUnmapWindow(dpy
, scr
->dock_shadow
);
3348 if (ev
.xmotion
.x_root
< dock
->x_pos
- ICON_SIZE
) {
3349 XMoveWindow(dpy
, scr
->dock_shadow
, DOCK_EXTRA_SPACE
, dock
->y_pos
);
3350 if (superfluous
&& ghost
== None
) {
3351 ghost
= MakeGhostDock(dock
, dock
->x_pos
,
3352 DOCK_EXTRA_SPACE
, dock
->y_pos
);
3353 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3354 XClearWindow(dpy
, scr
->dock_shadow
);
3356 XMapRaised(dpy
, scr
->dock_shadow
);
3359 XUnmapWindow(dpy
, scr
->dock_shadow
);
3361 if (superfluous
&& ghost
!= None
) {
3362 XFreePixmap(dpy
, ghost
);
3374 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3376 XUngrabPointer(dpy
, CurrentTime
);
3377 XUnmapWindow(dpy
, scr
->dock_shadow
);
3378 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3379 if (dock
->type
== WM_DOCK
) {
3382 dock
->on_right_side
= 1;
3384 dock
->on_right_side
= 0;
3386 wArrangeIcons(scr
, False
);
3395 XFreePixmap(dpy
, ghost
);
3396 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3401 static int getClipButton(int px
, int py
)
3403 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3405 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3408 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3409 return CLIP_FORWARD
;
3410 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3416 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3419 int done
, direction
, new_ws
;
3421 WDock
*clip
= scr
->clip_icon
->dock
;
3423 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3425 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3426 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3428 wClipIconPaint(scr
->clip_icon
);
3431 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3438 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3439 if (new_dir
!= direction
) {
3440 direction
= new_dir
;
3441 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3442 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3443 wClipIconPaint(scr
->clip_icon
);
3451 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3456 clip
->lclip_button_pushed
= 0;
3457 clip
->rclip_button_pushed
= 0;
3459 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3461 if (direction
== CLIP_FORWARD
) {
3462 if (scr
->current_workspace
< scr
->workspace_count
- 1)
3463 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3464 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
- 1)
3465 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3466 else if (wPreferences
.ws_cycle
)
3467 wWorkspaceChange(scr
, 0);
3468 } else if (direction
== CLIP_REWIND
) {
3469 if (scr
->current_workspace
> 0)
3470 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
3471 else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
)
3472 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
3475 wClipIconPaint(scr
->clip_icon
);
3478 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3480 WAppIcon
*aicon
= desc
->parent
;
3481 WDock
*dock
= aicon
->dock
;
3482 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3484 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3487 scr
->last_dock
= dock
;
3489 if (dock
->menu
->flags
.mapped
)
3490 wMenuUnmap(dock
->menu
);
3492 if (IsDoubleClick(scr
, event
)) {
3493 /* double-click was not in the main clip icon */
3494 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3495 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3496 iconDblClick(desc
, event
);
3501 if (event
->xbutton
.button
== Button1
) {
3502 if (event
->xbutton
.state
& MOD_MASK
)
3507 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
&& dock
->type
!= WM_DOCK
) {
3508 wIconSelect(aicon
->icon
);
3512 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3513 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
3514 && dock
->type
== WM_CLIP
)
3515 handleClipChangeWorkspace(scr
, event
);
3517 handleDockMove(dock
, aicon
, event
);
3519 Bool hasMoved
= wHandleAppIconMove(aicon
, event
);
3520 if (wPreferences
.single_click
&& !hasMoved
)
3521 iconDblClick(desc
, event
);
3523 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&& aicon
== scr
->clip_icon
) {
3524 if (!scr
->clip_ws_menu
) {
3525 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3527 if (scr
->clip_ws_menu
) {
3528 WMenu
*wsMenu
= scr
->clip_ws_menu
;
3531 wWorkspaceMenuUpdate(scr
, wsMenu
);
3533 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
3536 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
3537 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
3539 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
3541 desc
= &wsMenu
->menu
->descriptor
;
3542 event
->xany
.send_event
= True
;
3543 (*desc
->handle_mousedown
) (desc
, event
);
3545 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
3546 (event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
) {
3547 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3548 } else if (event
->xbutton
.button
== Button3
) {
3549 if (event
->xbutton
.send_event
&&
3550 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3551 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3552 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3553 wwarning("pointer grab failed for dockicon menu");
3557 openDockMenu(dock
, aicon
, event
);
3558 } else if (event
->xbutton
.button
== Button2
) {
3559 WAppIcon
*btn
= desc
->parent
;
3561 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3562 launchDockedApplication(btn
, True
);
3566 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
3568 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3572 assert(event
->type
== EnterNotify
);
3574 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3577 scr
= btn
->icon
->core
->screen_ptr
;
3580 if (!dock
|| dock
->type
!= WM_CLIP
)
3583 /* The auto raise/lower code */
3584 if (dock
->auto_lower_magic
) {
3585 WMDeleteTimerHandler(dock
->auto_lower_magic
);
3586 dock
->auto_lower_magic
= NULL
;
3588 if (dock
->auto_raise_lower
&& !dock
->auto_raise_magic
)
3589 dock
->auto_raise_magic
= WMAddTimerHandler(wPreferences
.clip_auto_raise_delay
, clipAutoRaise
, (void *)dock
);
3591 /* The auto expand/collapse code */
3592 if (dock
->auto_collapse_magic
) {
3593 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
3594 dock
->auto_collapse_magic
= NULL
;
3596 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
)
3597 dock
->auto_expand_magic
= WMAddTimerHandler(wPreferences
.clip_auto_expand_delay
, clipAutoExpand
, (void *)dock
);
3600 static void clipLeave(WDock
*dock
)
3603 WObjDescriptor
*desc
= NULL
;
3605 if (!dock
|| dock
->type
!= WM_CLIP
)
3608 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
3609 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
3610 (XPointer
*) & desc
) != XCNOENT
3611 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
3612 && ((WAppIcon
*) desc
->parent
)->dock
&& ((WAppIcon
*) desc
->parent
)->dock
->type
== WM_CLIP
) {
3613 /* We didn't left the Clip yet */
3614 XPutBackEvent(dpy
, &event
);
3618 XPutBackEvent(dpy
, &event
);
3620 /* We entered a withdrawn window, so we're still in Clip */
3624 if (dock
->auto_raise_magic
) {
3625 WMDeleteTimerHandler(dock
->auto_raise_magic
);
3626 dock
->auto_raise_magic
= NULL
;
3628 if (dock
->auto_raise_lower
&& !dock
->auto_lower_magic
)
3629 dock
->auto_lower_magic
= WMAddTimerHandler(wPreferences
.clip_auto_lower_delay
, clipAutoLower
, (void *)dock
);
3631 if (dock
->auto_expand_magic
) {
3632 WMDeleteTimerHandler(dock
->auto_expand_magic
);
3633 dock
->auto_expand_magic
= NULL
;
3635 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
)
3636 dock
->auto_collapse_magic
= WMAddTimerHandler(wPreferences
.clip_auto_collapse_delay
, clipAutoCollapse
, (void *)dock
);
3639 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
3641 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
3643 assert(event
->type
== LeaveNotify
);
3645 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
3648 clipLeave(btn
->dock
);
3651 static void clipAutoCollapse(void *cdata
)
3653 WDock
*dock
= (WDock
*) cdata
;
3655 if (dock
->type
!= WM_CLIP
)
3658 if (dock
->auto_collapse
) {
3659 dock
->collapsed
= 1;
3660 wDockHideIcons(dock
);
3662 dock
->auto_collapse_magic
= NULL
;
3665 static void clipAutoExpand(void *cdata
)
3667 WDock
*dock
= (WDock
*) cdata
;
3669 if (dock
->type
!= WM_CLIP
)
3672 if (dock
->auto_collapse
) {
3673 dock
->collapsed
= 0;
3674 wDockShowIcons(dock
);
3676 dock
->auto_expand_magic
= NULL
;
3679 static void clipAutoLower(void *cdata
)
3681 WDock
*dock
= (WDock
*) cdata
;
3683 if (dock
->type
!= WM_CLIP
)
3686 if (dock
->auto_raise_lower
)
3689 dock
->auto_lower_magic
= NULL
;
3692 static void clipAutoRaise(void *cdata
)
3694 WDock
*dock
= (WDock
*) cdata
;
3696 if (dock
->type
!= WM_CLIP
)
3699 if (dock
->auto_raise_lower
)
3702 dock
->auto_raise_magic
= NULL
;
3705 static Bool
iconCanBeOmnipresent(WAppIcon
*aicon
)
3707 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3712 for (i
= 0; i
< scr
->workspace_count
; i
++) {
3713 clip
= scr
->workspaces
[i
]->clip
;
3715 if (clip
== aicon
->dock
)
3718 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
3719 return False
; /* Clip is full in some workspace */
3721 for (j
= 0; j
< clip
->max_icons
; j
++) {
3722 btn
= clip
->icon_array
[j
];
3723 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
3731 int wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
3733 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3734 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
3735 int status
= WO_SUCCESS
;
3737 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== scr
->clip_icon
)
3738 return WO_NOT_APPLICABLE
;
3740 if (aicon
->omnipresent
== omnipresent
)
3744 if (iconCanBeOmnipresent(aicon
)) {
3745 aicon
->omnipresent
= 1;
3746 new_entry
= wmalloc(sizeof(WAppIconChain
));
3747 new_entry
->aicon
= aicon
;
3748 new_entry
->next
= scr
->global_icons
;
3749 scr
->global_icons
= new_entry
;
3750 scr
->global_icon_count
++;
3752 aicon
->omnipresent
= 0;
3756 aicon
->omnipresent
= 0;
3757 if (aicon
== scr
->global_icons
->aicon
) {
3758 tmp
= scr
->global_icons
->next
;
3759 wfree(scr
->global_icons
);
3760 scr
->global_icons
= tmp
;
3761 scr
->global_icon_count
--;
3763 tmp
= scr
->global_icons
;
3765 if (tmp
->next
->aicon
== aicon
) {
3766 tmp1
= tmp
->next
->next
;
3769 scr
->global_icon_count
--;
3777 wAppIconPaint(aicon
);