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>
36 #define PATH_MAX DEFAULT_PATH_MAX
39 #include "WindowMaker.h"
47 #include "dockedapp.h"
50 #include "properties.h"
54 #include "workspace.h"
56 #include "superfluous.h"
58 #include "placement.h"
62 /**** Local variables ****/
65 #define CLIP_FORWARD 2
67 /**** Global variables ****/
68 extern Cursor wCursor
[WCUR_LAST
];
69 extern WPreferences wPreferences
;
70 extern XContext wWinContext
;
71 extern void appIconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
73 #define MOD_MASK wPreferences.modifier_mask
74 #define ICON_SIZE wPreferences.icon_size
76 /***** Local variables ****/
78 static WMPropList
*dCommand
= NULL
;
79 static WMPropList
*dPasteCommand
= NULL
;
80 #ifdef XDND /* XXX was OFFIX */
81 static WMPropList
*dDropCommand
= NULL
;
83 static WMPropList
*dAutoLaunch
, *dLock
;
84 static WMPropList
*dName
, *dForced
, *dBuggyApplication
, *dYes
, *dNo
;
85 static WMPropList
*dHost
, *dDock
, *dClip
;
86 static WMPropList
*dAutoAttractIcons
;
88 static WMPropList
*dPosition
, *dApplications
, *dLowered
, *dCollapsed
;
90 static WMPropList
*dAutoCollapse
, *dAutoRaiseLower
, *dOmnipresent
;
92 static WMPropList
*dDrawers
= NULL
;
94 static void dockIconPaint(WAppIcon
*btn
);
96 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
98 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
);
100 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
102 static int getClipButton(int px
, int py
);
104 static void toggleLowered(WDock
*dock
);
106 static void toggleCollapsed(WDock
*dock
);
108 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
110 static void clipLeave(WDock
*dock
);
112 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
114 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
115 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
116 static void clipAutoCollapse(void *cdata
);
117 static void clipAutoExpand(void *cdata
);
118 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
);
120 static void clipAutoLower(void *cdata
);
121 static void clipAutoRaise(void *cdata
);
122 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
, char *name
);
124 static void drawerIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
125 static void removeDrawerCallback(WMenu
*menu
, WMenuEntry
*entry
);
126 static void drawerAppendToChain(WScreen
*scr
, WDock
*drawer
);
127 static char *findUniqueName(WScreen
*scr
, const char *instance_basename
);
128 static void addADrawerCallback(WMenu
*menu
, WMenuEntry
*entry
);
129 static void swapDrawers(WScreen
*scr
, int on_right_side
, int new_x
);
130 static WDock
* getDrawer(WScreen
*scr
, int y_index
);
131 static int indexOfHole(WDock
*drawer
, WAppIcon
*moving_aicon
, int redocking
);
132 static void drawerConsolidateIcons(WDock
*drawer
);
134 static int onScreen(WScreen
*scr
, int x
, int y
);
136 static void make_keys(void)
138 if (dCommand
!= NULL
)
141 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
142 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
144 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
146 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
147 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
148 dName
= WMRetainPropList(WMCreatePLString("Name"));
149 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
150 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
151 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
152 dNo
= WMRetainPropList(WMCreatePLString("No"));
153 dHost
= WMRetainPropList(WMCreatePLString("Host"));
155 dPosition
= WMCreatePLString("Position");
156 dApplications
= WMCreatePLString("Applications");
157 dLowered
= WMCreatePLString("Lowered");
158 dCollapsed
= WMCreatePLString("Collapsed");
159 dAutoCollapse
= WMCreatePLString("AutoCollapse");
160 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
161 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
163 dOmnipresent
= WMCreatePLString("Omnipresent");
165 dDock
= WMCreatePLString("Dock");
166 dClip
= WMCreatePLString("Clip");
167 dDrawers
= WMCreatePLString("Drawers");
170 static void renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
172 WDock
*dock
= entry
->clientdata
;
177 assert(entry
->clientdata
!= NULL
);
179 wspace
= dock
->screen_ptr
->current_workspace
;
181 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
183 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+ 1);
184 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
, &name
))
185 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
190 static void toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
192 assert(entry
->clientdata
!= NULL
);
194 toggleLowered(entry
->clientdata
);
196 entry
->flags
.indicator_on
= !(((WDock
*) entry
->clientdata
)->lowered
);
201 static int matchWindow(const void *item
, const void *cdata
)
203 return (((WFakeGroupLeader
*) item
)->leader
== (Window
) cdata
);
206 static void killCallback(WMenu
*menu
, WMenuEntry
*entry
)
208 WScreen
*scr
= menu
->menu
->screen_ptr
;
210 WFakeGroupLeader
*fPtr
;
211 char *buffer
, *shortname
, **argv
;
212 char *basename(const char *shortname
);
215 if (!WCHECK_STATE(WSTATE_NORMAL
))
218 assert(entry
->clientdata
!= NULL
);
220 icon
= (WAppIcon
*) entry
->clientdata
;
224 WCHANGE_STATE(WSTATE_MODAL
);
226 /* strip away dir names */
227 shortname
= basename(icon
->command
);
228 /* separate out command options */
229 wtokensplit(shortname
, &argv
, &argc
);
231 buffer
= wstrconcat(argv
[0],
232 _(" will be forcibly closed.\n"
233 "Any unsaved changes will be lost.\n" "Please confirm."));
235 if (icon
->icon
&& icon
->icon
->owner
) {
236 fPtr
= icon
->icon
->owner
->fake_group
;
238 /* is this really necessary? can we kill a non-running dock icon? */
239 Window win
= icon
->main_window
;
242 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)win
);
243 if (index
!= WANotFound
)
244 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
249 if (wPreferences
.dont_confirm_kill
250 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
251 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
253 WWindow
*wwin
, *twin
;
255 wwin
= scr
->focused_window
;
258 if (wwin
->fake_group
== fPtr
)
263 } else if (icon
->icon
&& icon
->icon
->owner
) {
264 wClientKill(icon
->icon
->owner
);
269 wtokenfree(argv
, argc
);
273 WCHANGE_STATE(WSTATE_NORMAL
);
276 /* TODO: replace this function with a member of the dock struct */
277 static int numberOfSelectedIcons(WDock
*dock
)
283 for (i
= 1; i
< dock
->max_icons
; i
++) {
284 aicon
= dock
->icon_array
[i
];
285 if (aicon
&& aicon
->icon
->selected
)
292 static WMArray
*getSelected(WDock
*dock
)
294 WMArray
*ret
= WMCreateArray(8);
298 for (i
= 1; i
< dock
->max_icons
; i
++) {
299 btn
= dock
->icon_array
[i
];
300 if (btn
&& btn
->icon
->selected
)
301 WMAddToArray(ret
, btn
);
307 static void paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
309 Window win
= clipIcon
->icon
->core
->window
;
310 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
312 int pt
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
313 int tp
= ICON_SIZE
- pt
;
314 int as
= pt
- 15; /* 15 = 5+5+5 */
315 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
318 color
= scr
->clip_title_color
[CLIP_NORMAL
];
320 XSetForeground(dpy
, gc
, WMColorPixel(color
));
325 p
[1].x
= ICON_SIZE
- 2;
327 p
[2].x
= ICON_SIZE
- 2;
329 } else if (lpushed
) {
333 p
[1].y
= ICON_SIZE
- 2;
335 p
[2].y
= ICON_SIZE
- 2;
337 if (lpushed
|| rpushed
) {
338 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
339 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
340 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
343 /* top right arrow */
344 p
[0].x
= p
[3].x
= ICON_SIZE
- 5 - as
;
346 p
[1].x
= ICON_SIZE
- 6;
348 p
[2].x
= ICON_SIZE
- 6;
351 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
352 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
354 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
355 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
358 /* bottom left arrow */
360 p
[0].y
= p
[3].y
= ICON_SIZE
- 5 - as
;
362 p
[1].y
= ICON_SIZE
- 6;
364 p
[2].y
= ICON_SIZE
- 6;
366 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
367 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
369 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
370 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
374 RImage
*wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
376 RImage
*tile
= RCloneImage(normalTile
);
383 pt
= CLIP_BUTTON_SIZE
* wPreferences
.icon_size
/ 64;
384 tp
= wPreferences
.icon_size
- 1 - pt
;
388 black
.red
= black
.green
= black
.blue
= 0;
391 dark
.red
= dark
.green
= dark
.blue
= 60;
394 light
.red
= light
.green
= light
.blue
= 80;
397 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
- 2, pt
- 1, &dark
);
398 RDrawLine(tile
, tp
- 1, 0, wPreferences
.icon_size
- 1, pt
+ 1, &black
);
399 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
- 3, pt
, &light
);
402 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, 4, &dark
);
403 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 5, 6 + as
, &dark
);
404 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
, &light
);
407 ROperateLine(tile
, RAddOperation
, 2, tp
+ 2, pt
- 2, wPreferences
.icon_size
- 3, &dark
);
408 RDrawLine(tile
, 0, tp
- 1, pt
+ 1, wPreferences
.icon_size
- 1, &black
);
409 ROperateLine(tile
, RSubtractOperation
, 0, tp
- 2, pt
+ 1, wPreferences
.icon_size
- 2, &light
);
412 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, &dark
);
413 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
, 6 + as
, ICON_SIZE
- 5, &dark
);
414 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5, &light
);
419 static void omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
421 WAppIcon
*clickedIcon
= entry
->clientdata
;
424 WMArray
*selectedIcons
;
425 WMArrayIterator iter
;
428 assert(entry
->clientdata
!= NULL
);
430 dock
= clickedIcon
->dock
;
432 selectedIcons
= getSelected(dock
);
434 if (!WMGetArrayItemCount(selectedIcons
))
435 WMAddToArray(selectedIcons
, clickedIcon
);
438 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
439 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
441 else if (aicon
->icon
->selected
)
442 wIconSelect(aicon
->icon
);
444 WMFreeArray(selectedIcons
);
447 wMessageDialog(dock
->screen_ptr
, _("Warning"),
448 _("Some icons cannot be made omnipresent. "
449 "Please make sure that no other icon is "
450 "docked in the same positions on the other "
451 "workspaces and the Clip is not full in "
452 "some workspace."), _("OK"), NULL
, NULL
);
453 } else if (failed
== 1) {
454 wMessageDialog(dock
->screen_ptr
, _("Warning"),
455 _("Icon cannot be made omnipresent. "
456 "Please make sure that no other icon is "
457 "docked in the same position on the other "
458 "workspaces and the Clip is not full in "
459 "some workspace."), _("OK"), NULL
, NULL
);
463 static void removeIcons(WMArray
*icons
, WDock
*dock
)
469 WM_ITERATE_ARRAY(icons
, aicon
, it
) {
470 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
471 wDockDetach(dock
, aicon
);
473 /* XXX: can: aicon->icon == NULL ? */
474 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
475 wGetHeadForWindow(aicon
->icon
->owner
));
476 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
477 if (!dock
->mapped
|| dock
->collapsed
)
478 XMapWindow(dpy
, aicon
->icon
->core
->window
);
483 if (wPreferences
.auto_arrange_icons
)
484 wArrangeIcons(dock
->screen_ptr
, True
);
487 static void removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
489 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
491 WMArray
*selectedIcons
;
493 assert(clickedIcon
!= NULL
);
495 dock
= clickedIcon
->dock
;
497 selectedIcons
= getSelected(dock
);
499 if (WMGetArrayItemCount(selectedIcons
)) {
500 if (wMessageDialog(dock
->screen_ptr
,
501 dock
->type
== WM_CLIP
? _("Workspace Clip") : _("Drawer"),
502 _("All selected icons will be removed!"),
503 _("OK"), _("Cancel"), NULL
) != WAPRDefault
) {
504 WMFreeArray(selectedIcons
);
508 if (clickedIcon
->xindex
== 0 && clickedIcon
->yindex
== 0) {
509 WMFreeArray(selectedIcons
);
512 WMAddToArray(selectedIcons
, clickedIcon
);
515 removeIcons(selectedIcons
, dock
);
517 if (dock
->type
== WM_DRAWER
) {
518 drawerConsolidateIcons(dock
);
522 static void keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
524 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
527 WMArray
*selectedIcons
;
530 assert(clickedIcon
!= NULL
);
531 dock
= clickedIcon
->dock
;
533 selectedIcons
= getSelected(dock
);
535 if (!WMGetArrayItemCount(selectedIcons
)
536 && clickedIcon
!= dock
->screen_ptr
->clip_icon
) {
537 char *command
= NULL
;
539 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
540 clickedIcon
->editing
= 1;
541 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
542 _("Type the command used to launch the application"), &command
)) {
543 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
547 clickedIcon
->command
= command
;
548 clickedIcon
->editing
= 0;
550 clickedIcon
->editing
= 0;
553 WMFreeArray(selectedIcons
);
558 WMAddToArray(selectedIcons
, clickedIcon
);
561 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
562 if (aicon
->icon
->selected
)
563 wIconSelect(aicon
->icon
);
565 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
566 aicon
->attracted
= 0;
567 if (aicon
->icon
->shadowed
) {
568 aicon
->icon
->shadowed
= 0;
571 * Update icon pixmap, RImage doesn't change,
572 * so call wIconUpdate is not needed
574 update_icon_pixmap(aicon
->icon
);
577 wAppIconPaint(aicon
);
580 save_appicon(aicon
, True
);
582 WMFreeArray(selectedIcons
);
585 static void toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
587 WDock
*dock
= (WDock
*) entry
->clientdata
;
588 WScreen
*scr
= dock
->screen_ptr
;
590 assert(entry
->clientdata
!= NULL
);
592 /* Setting a clip as autoattracting will disable an autoattracting drawer,
593 * and reciprocally. Ask for confirmation? */
594 #ifdef CONFIRM_AUTOATTRACT_CHANGE
595 if (dock
->type
== WM_CLIP
&& scr
->attracting_drawer
) {
596 if (wMessageDialog(scr
, _("Workspace Clip"),
597 _("The drawer that auto-attracted icons so far won't do so anymore!"),
598 _("OK"), _("Cancel"), NULL
) != WAPRDefault
)
600 } else if (dock
->type
== WM_DRAWER
) {
601 /* check if at least one clip already auto attracts icons */
602 int i
, ask_for_confirmation
= False
;
603 for (i
= 0; i
< scr
->workspace_count
; i
++) {
604 if (scr
->workspaces
[ i
]->clip
->attract_icons
) {
605 ask_for_confirmation
= True
;
609 if (ask_for_confirmation
) {
610 if (wMessageDialog(scr
, _("Drawer"),
611 _("Any clips that auto-attracted icons so far won't do so anymore!"),
612 _("OK"), _("Cancel"), NULL
) != WAPRDefault
)
618 dock
->attract_icons
= !dock
->attract_icons
;
620 entry
->flags
.indicator_on
= dock
->attract_icons
;
624 if (dock
->attract_icons
) {
625 if (dock
->type
== WM_DRAWER
) {
626 /* The newly auto-attracting dock is a drawer: disable any clip and
627 * previously attracting drawer */
629 for (i
= 0; i
< scr
->workspace_count
; i
++) {
630 scr
->workspaces
[ i
]->clip
->attract_icons
= False
;
631 /* dock menu will be updated later, when opened */
633 if (scr
->attracting_drawer
!= NULL
)
634 scr
->attracting_drawer
->attract_icons
= False
;
635 scr
->attracting_drawer
= dock
;
637 /* The newly auto-attracting dock is a clip: disable
638 * previously attracting drawer, if applicable */
639 if (scr
->attracting_drawer
!= NULL
) {
640 scr
->attracting_drawer
->attract_icons
= False
;
641 /* again, its menu will be updated, later. */
642 scr
->attracting_drawer
= NULL
;
648 static void selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
650 WAppIcon
*icon
= (WAppIcon
*) entry
->clientdata
;
652 assert(icon
!= NULL
);
654 wIconSelect(icon
->icon
);
659 static void colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
661 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
662 WDock
*clip
; /* clip... is a WM_CLIP or a WM_DRAWER */
664 int x
, y
, x_pos
, y_pos
;
665 Bool update_icon
= False
;
667 assert(entry
->clientdata
!= NULL
);
668 clip
= clickedIcon
->dock
;
670 aicon
= clip
->screen_ptr
->app_icon_list
;
673 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
674 x_pos
= clip
->x_pos
+ x
* ICON_SIZE
;
675 y_pos
= clip
->y_pos
+ y
* ICON_SIZE
;
676 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
)
677 move_window(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
679 aicon
->attracted
= 1;
680 if (!aicon
->icon
->shadowed
) {
681 aicon
->icon
->shadowed
= 1;
684 wDockAttachIcon(clip
, aicon
, x
, y
, update_icon
);
685 if (clip
->collapsed
|| !clip
->mapped
)
686 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
692 static void selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
694 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
696 WMArray
*selectedIcons
;
697 WMArrayIterator iter
;
701 assert(clickedIcon
!= NULL
);
702 dock
= clickedIcon
->dock
;
704 selectedIcons
= getSelected(dock
);
706 if (!WMGetArrayItemCount(selectedIcons
)) {
707 for (i
= 1; i
< dock
->max_icons
; i
++) {
708 btn
= dock
->icon_array
[i
];
709 if (btn
&& !btn
->icon
->selected
)
710 wIconSelect(btn
->icon
);
713 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
714 wIconSelect(btn
->icon
);
717 WMFreeArray(selectedIcons
);
722 static void toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
724 assert(entry
->clientdata
!= NULL
);
726 toggleCollapsed(entry
->clientdata
);
728 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->collapsed
;
733 static void toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
736 assert(entry
->clientdata
!= NULL
);
738 dock
= (WDock
*) entry
->clientdata
;
740 dock
->auto_collapse
= !dock
->auto_collapse
;
742 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_collapse
;
747 static void toggleAutoRaiseLower(WDock
*dock
)
751 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
752 if (dock
->type
== WM_DOCK
)
754 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
755 toggleAutoRaiseLower(dc
->adrawer
);
760 static void toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
763 assert(entry
->clientdata
!= NULL
);
765 dock
= (WDock
*) entry
->clientdata
;
767 toggleAutoRaiseLower(dock
);
769 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_raise_lower
;
774 static void launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
776 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
778 launchDockedApplication(btn
, False
);
781 static void settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
783 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
787 ShowDockAppSettingsPanel(btn
);
790 static void hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
793 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
795 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
797 if (wapp
->flags
.hidden
) {
798 wWorkspaceChange(btn
->icon
->core
->screen_ptr
, wapp
->last_workspace
);
799 wUnhideApplication(wapp
, False
, False
);
801 wHideApplication(wapp
);
805 static void unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
808 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
810 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
812 wUnhideApplication(wapp
, False
, True
);
815 /* Name is only used when type == WM_DRAWER and when restoring a specific
816 * drawer, with a specific name. When creating a drawer, leave name to NULL
817 * and mainIconCreate will find the first unused unique name */
818 WAppIcon
*mainIconCreate(WScreen
*scr
, int type
, char *name
)
826 return scr
->clip_icon
;
827 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
828 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
832 default: /* to avoid a warning about btn and x_pos, basically */
833 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
834 if (wPreferences
.flags
.clip_merged_in_dock
)
835 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
836 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
840 name
= findUniqueName(scr
, "Drawer");
841 btn
= wAppIconCreateForDock(scr
, NULL
, name
, "WMDrawer", TILE_DRAWER
);
842 btn
->icon
->core
->descriptor
.handle_expose
= drawerIconExpose
;
849 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
850 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
851 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
852 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
853 btn
->icon
->core
->descriptor
.parent
= btn
;
854 XMapWindow(dpy
, btn
->icon
->core
->window
);
858 if (type
== WM_CLIP
||
859 (type
== WM_DOCK
&& wPreferences
.flags
.clip_merged_in_dock
))
860 scr
->clip_icon
= btn
;
865 static void switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
867 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
868 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
870 WMArray
*selectedIcons
;
873 if (entry
->order
== scr
->current_workspace
)
876 dest
= scr
->workspaces
[entry
->order
]->clip
;
878 selectedIcons
= getSelected(src
);
880 if (WMGetArrayItemCount(selectedIcons
)) {
881 WMArrayIterator iter
;
883 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
884 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
885 wDockMoveIconBetweenDocks(src
, dest
, btn
, x
, y
);
886 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
889 } else if (icon
!= scr
->clip_icon
) {
890 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
891 wDockMoveIconBetweenDocks(src
, dest
, icon
, x
, y
);
892 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
895 WMFreeArray(selectedIcons
);
898 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
)
900 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
902 if (!btn
->launching
&&
903 ((!withSelection
&& btn
->command
!= NULL
) || (withSelection
&& btn
->paste_command
!= NULL
))) {
904 if (!btn
->forced_dock
) {
905 btn
->relaunching
= btn
->running
;
908 if (btn
->wm_instance
|| btn
->wm_class
) {
909 WWindowAttributes attr
;
910 memset(&attr
, 0, sizeof(WWindowAttributes
));
911 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
913 if (!attr
.no_appicon
&& !btn
->buggy_app
)
918 btn
->drop_launch
= 0;
919 btn
->paste_launch
= withSelection
;
920 scr
->last_dock
= btn
->dock
;
921 btn
->pid
= execCommand(btn
, (withSelection
? btn
->paste_command
: btn
->command
), NULL
);
923 if (btn
->buggy_app
) {
924 /* give feedback that the app was launched */
928 WMAddTimerHandler(200, (WMCallback
*) dockIconPaint
, btn
);
933 wwarning(_("could not launch application %s"), btn
->command
);
935 if (!btn
->relaunching
)
941 static void updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
943 WScreen
*scr
= menu
->frame
->screen_ptr
;
944 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
950 for (i
= 0; i
< scr
->workspace_count
; i
++) {
951 if (i
< menu
->entry_no
) {
952 if (strcmp(menu
->entries
[i
]->text
, scr
->workspaces
[i
]->name
) != 0) {
953 wfree(menu
->entries
[i
]->text
);
954 strcpy(title
, scr
->workspaces
[i
]->name
);
955 menu
->entries
[i
]->text
= wstrdup(title
);
956 menu
->flags
.realized
= 0;
958 menu
->entries
[i
]->clientdata
= (void *)icon
;
960 strcpy(title
, scr
->workspaces
[i
]->name
);
962 wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)icon
);
964 menu
->flags
.realized
= 0;
967 if (i
== scr
->current_workspace
)
968 wMenuSetEnabled(menu
, i
, False
);
970 wMenuSetEnabled(menu
, i
, True
);
973 if (!menu
->flags
.realized
)
977 static WMenu
*makeWorkspaceMenu(WScreen
*scr
)
981 menu
= wMenuCreate(scr
, NULL
, False
);
983 wwarning(_("could not create workspace submenu for Clip menu"));
985 wMenuAddCallback(menu
, "", switchWSCommand
, (void *)scr
->clip_icon
);
987 menu
->flags
.realized
= 0;
993 static void updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
1002 entry
= menu
->entries
[index
];
1003 entry
->flags
.indicator_on
= !dock
->lowered
;
1004 entry
->clientdata
= dock
;
1005 wMenuSetEnabled(menu
, index
, dock
->type
== WM_CLIP
);
1008 entry
= menu
->entries
[++index
];
1009 entry
->flags
.indicator_on
= dock
->collapsed
;
1010 entry
->clientdata
= dock
;
1013 entry
= menu
->entries
[++index
];
1014 entry
->flags
.indicator_on
= dock
->auto_collapse
;
1015 entry
->clientdata
= dock
;
1017 /* auto-raise/lower */
1018 entry
= menu
->entries
[++index
];
1019 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1020 entry
->clientdata
= dock
;
1021 wMenuSetEnabled(menu
, index
, dock
->lowered
&& (dock
->type
== WM_CLIP
));
1024 entry
= menu
->entries
[++index
];
1025 entry
->flags
.indicator_on
= dock
->attract_icons
;
1026 entry
->clientdata
= dock
;
1028 menu
->flags
.realized
= 0;
1033 static WMenu
*makeClipOptionsMenu(WScreen
*scr
)
1038 menu
= wMenuCreate(scr
, NULL
, False
);
1040 wwarning(_("could not create options submenu for Clip menu"));
1044 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
1045 entry
->flags
.indicator
= 1;
1046 entry
->flags
.indicator_on
= 1;
1047 entry
->flags
.indicator_type
= MI_CHECK
;
1049 entry
= wMenuAddCallback(menu
, _("Collapsed"), toggleCollapsedCallback
, NULL
);
1050 entry
->flags
.indicator
= 1;
1051 entry
->flags
.indicator_on
= 1;
1052 entry
->flags
.indicator_type
= MI_CHECK
;
1054 entry
= wMenuAddCallback(menu
, _("Autocollapse"), toggleAutoCollapseCallback
, NULL
);
1055 entry
->flags
.indicator
= 1;
1056 entry
->flags
.indicator_on
= 1;
1057 entry
->flags
.indicator_type
= MI_CHECK
;
1059 entry
= wMenuAddCallback(menu
, _("Autoraise"), toggleAutoRaiseLowerCallback
, NULL
);
1060 entry
->flags
.indicator
= 1;
1061 entry
->flags
.indicator_on
= 1;
1062 entry
->flags
.indicator_type
= MI_CHECK
;
1064 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"), toggleAutoAttractCallback
, NULL
);
1065 entry
->flags
.indicator
= 1;
1066 entry
->flags
.indicator_on
= 1;
1067 entry
->flags
.indicator_type
= MI_CHECK
;
1069 menu
->flags
.realized
= 0;
1076 static void setDockPositionNormalCallback(WMenu
*menu
, WMenuEntry
*entry
)
1078 WDock
*dock
= (WDock
*) entry
->clientdata
;
1080 if (entry
->flags
.indicator_on
) // already set, nothing to do
1082 // Do we come from auto raise lower or keep on top?
1083 if (dock
->auto_raise_lower
)
1085 dock
->auto_raise_lower
= 0;
1086 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1087 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1088 dc
->adrawer
->auto_raise_lower
= 0;
1093 // Will take care of setting lowered = 0 in drawers
1094 toggleLowered(dock
);
1096 entry
->flags
.indicator_on
= 1;
1099 static void setDockPositionAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
1101 WDock
*dock
= (WDock
*) entry
->clientdata
;
1103 if (entry
->flags
.indicator_on
) // already set, nothing to do
1105 // Do we come from normal or keep on top?
1108 toggleLowered(dock
);
1110 dock
->auto_raise_lower
= 1;
1111 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1112 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1113 dc
->adrawer
->auto_raise_lower
= 1;
1115 entry
->flags
.indicator_on
= 1;
1118 static void setDockPositionKeepOnTopCallback(WMenu
*menu
, WMenuEntry
*entry
)
1120 WDock
*dock
= (WDock
*) entry
->clientdata
;
1122 if (entry
->flags
.indicator_on
) // already set, nothing to do
1124 dock
->auto_raise_lower
= 0;
1125 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1126 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1127 dc
->adrawer
->auto_raise_lower
= 0;
1129 toggleLowered(dock
);
1130 entry
->flags
.indicator_on
= 1;
1133 static void updateDockPositionMenu(WMenu
*menu
, WDock
*dock
)
1142 entry
= menu
->entries
[index
++];
1143 entry
->flags
.indicator_on
= (dock
->lowered
&& !dock
->auto_raise_lower
);
1144 entry
->clientdata
= dock
;
1146 /* Auto-raise/lower */
1147 entry
= menu
->entries
[index
++];
1148 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1149 entry
->clientdata
= dock
;
1152 entry
= menu
->entries
[index
++];
1153 entry
->flags
.indicator_on
= !dock
->lowered
;
1154 entry
->clientdata
= dock
;
1157 static WMenu
*makeDockPositionMenu(WScreen
*scr
)
1159 /* When calling this, the dock is being created, so scr->dock is still not set
1160 * Therefore the callbacks' clientdata and the indicators can't be set,
1161 * they will be updated when the dock menu is opened. */
1165 menu
= wMenuCreate(scr
, NULL
, False
);
1167 wwarning(_("could not create options submenu for dock position menu"));
1171 entry
= wMenuAddCallback(menu
, _("Normal"), setDockPositionNormalCallback
, NULL
);
1172 entry
->flags
.indicator
= 1;
1173 entry
->flags
.indicator_type
= MI_DIAMOND
;
1175 entry
= wMenuAddCallback(menu
, _("Auto raise & lower"), setDockPositionAutoRaiseLowerCallback
, NULL
);
1176 entry
->flags
.indicator
= 1;
1177 entry
->flags
.indicator_type
= MI_DIAMOND
;
1179 entry
= wMenuAddCallback(menu
, _("Keep on Top"), setDockPositionKeepOnTopCallback
, NULL
);
1180 entry
->flags
.indicator
= 1;
1181 entry
->flags
.indicator_type
= MI_DIAMOND
;
1183 menu
->flags
.realized
= 0;
1190 static WMenu
*dockMenuCreate(WScreen
*scr
, int type
)
1195 if (type
== WM_CLIP
&& scr
->clip_menu
)
1196 return scr
->clip_menu
;
1198 if (type
== WM_DRAWER
&& scr
->drawer_menu
)
1199 return scr
->drawer_menu
;
1201 menu
= wMenuCreate(scr
, NULL
, False
);
1202 if (type
== WM_DOCK
) {
1203 entry
= wMenuAddCallback(menu
, _("Dock position"), NULL
, NULL
);
1204 if (scr
->dock_pos_menu
== NULL
)
1205 scr
->dock_pos_menu
= makeDockPositionMenu(scr
);
1206 wMenuEntrySetCascade(menu
, entry
, scr
->dock_pos_menu
);
1208 if (!wPreferences
.flags
.nodrawer
) {
1209 entry
= wMenuAddCallback(menu
, _("Add a drawer"), addADrawerCallback
, NULL
);
1212 if (type
== WM_CLIP
)
1213 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1214 else /* if (type == WM_DRAWER) */
1215 entry
= wMenuAddCallback(menu
, _("Drawer options"), NULL
, NULL
);
1217 if (scr
->clip_options
== NULL
)
1218 scr
->clip_options
= makeClipOptionsMenu(scr
);
1219 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1221 /* The same menu is used for the dock and its appicons. If the menu
1222 * entry text is different between the two contexts, or if it can
1223 * change depending on some state, free the duplicated string (from
1224 * wMenuInsertCallback) and use gettext's string */
1225 if (type
== WM_CLIP
) {
1226 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1228 entry
->text
= _("Rename Workspace"); /* can be: (Toggle) Omnipresent */
1231 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1232 entry
->flags
.indicator
= 1;
1233 entry
->flags
.indicator_on
= 1;
1234 entry
->flags
.indicator_type
= MI_CHECK
;
1236 entry
= wMenuAddCallback(menu
, _("Select All Icons"), selectIconsCallback
, NULL
);
1238 entry
->text
= _("Select All Icons"); /* can be: Unselect all icons */
1240 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1242 entry
->text
= _("Keep Icon"); /* can be: Keep Icons */
1244 if (type
== WM_CLIP
) {
1245 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1247 entry
->text
= _("Move Icon To"); /* can be: Move Icons to */
1248 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1249 if (scr
->clip_submenu
)
1250 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1253 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
, NULL
);
1255 entry
->text
= _("Remove Icon"); /* can be: Remove Icons */
1257 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1260 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1262 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1264 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1266 entry
->text
= _("Hide"); /* can be: Unhide */
1268 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1270 entry
= wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1272 entry
->text
= _("Kill"); /* can be: Remove drawer */
1274 if (type
== WM_CLIP
)
1275 scr
->clip_menu
= menu
;
1277 if (type
== WM_DRAWER
)
1278 scr
->drawer_menu
= menu
;
1283 WDock
*wDockCreate(WScreen
*scr
, int type
, char *name
)
1290 dock
= wmalloc(sizeof(WDock
));
1294 dock
->max_icons
= DOCK_MAX_ICONS
;
1297 dock
->max_icons
= scr
->scr_width
/ wPreferences
.icon_size
;
1301 dock
->max_icons
= scr
->scr_height
/ wPreferences
.icon_size
;
1304 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * dock
->max_icons
);
1306 btn
= mainIconCreate(scr
, type
, name
);
1310 dock
->x_pos
= btn
->x_pos
;
1311 dock
->y_pos
= btn
->y_pos
;
1312 dock
->screen_ptr
= scr
;
1314 dock
->icon_count
= 1;
1315 if (type
== WM_DRAWER
)
1316 dock
->on_right_side
= scr
->dock
->on_right_side
;
1318 dock
->on_right_side
= 1;
1319 dock
->collapsed
= 0;
1320 dock
->auto_collapse
= 0;
1321 dock
->auto_collapse_magic
= NULL
;
1322 dock
->auto_raise_lower
= 0;
1323 dock
->auto_lower_magic
= NULL
;
1324 dock
->auto_raise_magic
= NULL
;
1325 dock
->attract_icons
= 0;
1327 dock
->icon_array
[0] = btn
;
1328 wRaiseFrame(btn
->icon
->core
);
1329 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1331 /* create dock menu */
1332 dock
->menu
= dockMenuCreate(scr
, type
);
1334 if (type
== WM_DRAWER
) {
1335 drawerAppendToChain(scr
, dock
);
1336 dock
->auto_collapse
= 1;
1342 void wDockDestroy(WDock
*dock
)
1347 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1348 aicon
= dock
->icon_array
[i
];
1350 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1351 wDockDetach(dock
, aicon
);
1353 /* XXX: can: aicon->icon == NULL ? */
1354 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1355 wGetHeadForWindow(aicon
->icon
->owner
));
1356 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1357 if (!dock
->mapped
|| dock
->collapsed
)
1358 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1362 if (wPreferences
.auto_arrange_icons
)
1363 wArrangeIcons(dock
->screen_ptr
, True
);
1364 wfree(dock
->icon_array
);
1365 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1366 wMenuDestroy(dock
->menu
, True
);
1367 if (dock
->screen_ptr
->last_dock
== dock
)
1368 dock
->screen_ptr
->last_dock
= NULL
;
1372 void wClipIconPaint(WAppIcon
*aicon
)
1374 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1375 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1377 Window win
= aicon
->icon
->core
->window
;
1378 int length
, nlength
;
1379 char *ws_name
, ws_number
[10];
1382 wIconPaint(aicon
->icon
);
1384 length
= strlen(workspace
->name
);
1385 ws_name
= wmalloc(length
+ 1);
1386 snprintf(ws_name
, length
+ 1, "%s", workspace
->name
);
1387 snprintf(ws_number
, sizeof(ws_number
), "%i", scr
->current_workspace
+ 1);
1388 nlength
= strlen(ws_number
);
1390 if (wPreferences
.flags
.noclip
|| !workspace
->clip
->collapsed
)
1391 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1393 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1395 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1397 tx
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
1399 if(wPreferences
.show_clip_title
)
1400 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, ty
, ws_name
, length
);
1402 tx
= (ICON_SIZE
/ 2 - WMWidthOfString(scr
->clip_title_font
, ws_number
, nlength
)) / 2;
1404 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, 2, ws_number
, nlength
);
1408 if (aicon
->launching
)
1409 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1410 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1412 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
, aicon
->dock
->rclip_button_pushed
);
1415 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1417 wClipIconPaint(desc
->parent
);
1420 static void dockIconPaint(WAppIcon
*btn
)
1422 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
) {
1423 wClipIconPaint(btn
);
1424 } else if (wIsADrawer(btn
->icon
->core
->screen_ptr
, btn
)) {
1425 wDrawerIconPaint(btn
);
1428 save_appicon(btn
, True
);
1432 static WMPropList
*make_icon_state(WAppIcon
*btn
)
1434 WMPropList
*node
= NULL
;
1435 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
;
1436 WMPropList
*position
, *buggy
, *omnipresent
;
1442 command
= WMCreatePLString("-");
1444 command
= WMCreatePLString(btn
->command
);
1446 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1448 lock
= btn
->lock
? dYes
: dNo
;
1450 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1452 name
= WMCreatePLString(tmp
);
1456 forced
= btn
->forced_dock
? dYes
: dNo
;
1458 buggy
= btn
->buggy_app
? dYes
: dNo
;
1460 if (!wPreferences
.flags
.clip_merged_in_dock
&& btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1461 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1463 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1464 position
= WMCreatePLString(buffer
);
1466 node
= WMCreatePLDictionary(dCommand
, command
,
1468 dAutoLaunch
, autolaunch
,
1470 dForced
, forced
, dBuggyApplication
, buggy
, dPosition
, position
, NULL
);
1471 WMReleasePropList(command
);
1472 WMReleasePropList(name
);
1473 WMReleasePropList(position
);
1475 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1476 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&& (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1477 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1479 #ifdef XDND /* was OFFIX */
1480 if (btn
->dnd_command
) {
1481 command
= WMCreatePLString(btn
->dnd_command
);
1482 WMPutInPLDictionary(node
, dDropCommand
, command
);
1483 WMReleasePropList(command
);
1487 if (btn
->paste_command
) {
1488 command
= WMCreatePLString(btn
->paste_command
);
1489 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1490 WMReleasePropList(command
);
1497 static WMPropList
*dockSaveState(WDock
*dock
)
1500 WMPropList
*icon_info
;
1501 WMPropList
*list
= NULL
, *dock_state
= NULL
;
1502 WMPropList
*value
, *key
;
1505 list
= WMCreatePLArray(NULL
);
1507 for (i
= (dock
->type
== WM_DOCK
? 0 : 1); i
< dock
->max_icons
; i
++) {
1508 WAppIcon
*btn
= dock
->icon_array
[i
];
1510 if (!btn
|| btn
->attracted
)
1513 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1514 WMAddToPLArray(list
, icon_info
);
1515 WMReleasePropList(icon_info
);
1519 dock_state
= WMCreatePLDictionary(dApplications
, list
, NULL
);
1521 if (dock
->type
== WM_DOCK
) {
1522 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1523 key
= WMCreatePLString(buffer
);
1524 WMPutInPLDictionary(dock_state
, key
, list
);
1525 WMReleasePropList(key
);
1527 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0), dock
->y_pos
);
1528 value
= WMCreatePLString(buffer
);
1529 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1530 WMReleasePropList(value
);
1532 WMReleasePropList(list
);
1534 if (dock
->type
== WM_CLIP
|| dock
->type
== WM_DRAWER
) {
1535 value
= (dock
->collapsed
? dYes
: dNo
);
1536 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1538 value
= (dock
->auto_collapse
? dYes
: dNo
);
1539 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1541 value
= (dock
->attract_icons
? dYes
: dNo
);
1542 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1545 if (dock
->type
== WM_DOCK
|| dock
->type
== WM_CLIP
) {
1546 value
= (dock
->lowered
? dYes
: dNo
);
1547 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1549 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1550 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1556 void wDockSaveState(WScreen
*scr
, WMPropList
*old_state
)
1558 WMPropList
*dock_state
;
1561 dock_state
= dockSaveState(scr
->dock
);
1564 * Copy saved states of docks with different sizes.
1570 keys
= WMGetPLDictionaryKeys(old_state
);
1571 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1572 tmp
= WMGetFromPLArray(keys
, i
);
1574 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1575 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1577 WMPutInPLDictionary(dock_state
, tmp
, WMGetFromPLDictionary(old_state
, tmp
));
1580 WMReleasePropList(keys
);
1583 WMPutInPLDictionary(scr
->session_state
, dDock
, dock_state
);
1585 WMReleasePropList(dock_state
);
1588 void wClipSaveState(WScreen
*scr
)
1590 WMPropList
*clip_state
;
1592 clip_state
= make_icon_state(scr
->clip_icon
);
1594 WMPutInPLDictionary(scr
->session_state
, dClip
, clip_state
);
1596 WMReleasePropList(clip_state
);
1599 WMPropList
*wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1601 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1604 static Bool
getBooleanDockValue(WMPropList
*value
, WMPropList
*key
)
1607 if (WMIsPLString(value
)) {
1608 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1611 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1617 static WAppIcon
*restore_icon_state(WScreen
*scr
, WMPropList
*info
, int type
, int index
)
1620 WMPropList
*cmd
, *value
;
1621 char *wclass
, *winstance
, *command
;
1623 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1624 if (!cmd
|| !WMIsPLString(cmd
))
1627 /* parse window name */
1628 value
= WMGetFromPLDictionary(info
, dName
);
1632 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1634 if (!winstance
&& !wclass
)
1639 command
= wstrdup(WMGetFromPLString(cmd
));
1643 if (!command
|| strcmp(command
, "-") == 0) {
1654 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1662 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1663 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1664 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1665 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1666 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1668 #ifdef XDND /* was OFFIX */
1669 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1671 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1674 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1676 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1678 /* check auto launch */
1679 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1681 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1684 value
= WMGetFromPLDictionary(info
, dLock
);
1686 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1688 /* check if it wasn't normally docked */
1689 value
= WMGetFromPLDictionary(info
, dForced
);
1691 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1693 /* check if we can rely on the stuff in the app */
1694 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1696 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1698 /* get position in the dock */
1699 value
= WMGetFromPLDictionary(info
, dPosition
);
1700 if (value
&& WMIsPLString(value
)) {
1701 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1702 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1704 /* check position sanity */
1705 /* *Very* incomplete section! */
1706 if (type
== WM_DOCK
) {
1710 aicon
->yindex
= index
;
1714 /* check if icon is omnipresent */
1715 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1717 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1725 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1727 WAppIcon
*wClipRestoreState(WScreen
*scr
, WMPropList
*clip_state
)
1732 icon
= mainIconCreate(scr
, WM_CLIP
, NULL
);
1737 WMRetainPropList(clip_state
);
1739 /* restore position */
1741 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1744 if (!WMIsPLString(value
)) {
1745 COMPLAIN("Position");
1747 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1748 COMPLAIN("Position");
1750 /* check position sanity */
1751 if (!onScreen(scr
, icon
->x_pos
, icon
->y_pos
))
1752 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1755 #ifdef XDND /* was OFFIX */
1756 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1757 if (value
&& WMIsPLString(value
))
1758 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1761 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1762 if (value
&& WMIsPLString(value
))
1763 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1765 WMReleasePropList(clip_state
);
1770 WDock
*wDockRestoreState(WScreen
*scr
, WMPropList
*dock_state
, int type
)
1775 WAppIcon
*aicon
, *old_top
;
1778 dock
= wDockCreate(scr
, type
, NULL
);
1783 WMRetainPropList(dock_state
);
1785 /* restore position */
1786 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1788 if (!WMIsPLString(value
)) {
1789 COMPLAIN("Position");
1791 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1792 COMPLAIN("Position");
1794 /* check position sanity */
1795 if (!onScreen(scr
, dock
->x_pos
, dock
->y_pos
)) {
1796 int x
= dock
->x_pos
;
1797 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1800 /* Is this needed any more? */
1801 if (type
== WM_CLIP
) {
1802 if (dock
->x_pos
< 0) {
1804 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1805 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1808 if (dock
->x_pos
>= 0) {
1809 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1810 dock
->on_right_side
= 0;
1812 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1813 dock
->on_right_side
= 1;
1819 /* restore lowered/raised state */
1822 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1824 if (!WMIsPLString(value
)) {
1825 COMPLAIN("Lowered");
1827 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1832 /* restore collapsed state */
1833 dock
->collapsed
= 0;
1835 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1837 if (!WMIsPLString(value
)) {
1838 COMPLAIN("Collapsed");
1840 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1841 dock
->collapsed
= 1;
1845 /* restore auto-collapsed state */
1846 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1848 if (!WMIsPLString(value
)) {
1849 COMPLAIN("AutoCollapse");
1851 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1852 dock
->auto_collapse
= 1;
1853 dock
->collapsed
= 1;
1858 /* restore auto-raise/lower state */
1859 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1861 if (!WMIsPLString(value
)) {
1862 COMPLAIN("AutoRaiseLower");
1864 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1865 dock
->auto_raise_lower
= 1;
1869 /* restore attract icons state */
1870 dock
->attract_icons
= 0;
1872 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1874 if (!WMIsPLString(value
)) {
1875 COMPLAIN("AutoAttractIcons");
1877 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1878 dock
->attract_icons
= 1;
1882 /* application list */
1889 * When saving, it saves the dock state in
1890 * Applications and Applicationsnnn
1892 * When loading, it will first try Applicationsnnn.
1893 * If it does not exist, use Applications as default.
1896 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1898 tmp
= WMCreatePLString(buffer
);
1899 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1900 WMReleasePropList(tmp
);
1903 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1909 count
= WMGetPropListItemCount(apps
);
1913 old_top
= dock
->icon_array
[0];
1915 /* dock->icon_count is set to 1 when dock is created.
1916 * Since Clip is already restored, we want to keep it so for clip,
1917 * but for dock we may change the default top tile, so we set it to 0.
1919 if (type
== WM_DOCK
)
1920 dock
->icon_count
= 0;
1922 for (i
= 0; i
< count
; i
++) {
1923 if (dock
->icon_count
>= dock
->max_icons
) {
1924 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1928 value
= WMGetFromPLArray(apps
, i
);
1929 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1931 dock
->icon_array
[dock
->icon_count
] = aicon
;
1935 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1936 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1939 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1941 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1943 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1944 if (!dock
->collapsed
)
1945 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1947 wRaiseFrame(aicon
->icon
->core
);
1950 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
) {
1955 /* if the first icon is not defined, use the default */
1956 if (dock
->icon_array
[0] == NULL
) {
1957 /* update default icon */
1958 old_top
->x_pos
= dock
->x_pos
;
1959 old_top
->y_pos
= dock
->y_pos
;
1961 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1963 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1965 dock
->icon_array
[0] = old_top
;
1966 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1967 /* we don't need to increment dock->icon_count here because it was
1968 * incremented in the loop above.
1970 } else if (old_top
!= dock
->icon_array
[0]) {
1971 if (old_top
== scr
->clip_icon
) // TODO dande: understand the logic
1972 scr
->clip_icon
= dock
->icon_array
[0];
1974 wAppIconDestroy(old_top
);
1978 WMReleasePropList(dock_state
);
1983 void wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1985 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1986 btn
->drop_launch
= 0;
1987 btn
->paste_launch
= 0;
1989 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1992 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
2002 void wDockDoAutoLaunch(WDock
*dock
, int workspace
)
2008 for (i
= 0; i
< dock
->max_icons
; i
++) {
2009 btn
= dock
->icon_array
[i
];
2010 if (!btn
|| !btn
->auto_launch
)
2013 state
= wmalloc(sizeof(WSavedState
));
2014 state
->workspace
= workspace
;
2015 /* TODO: this is klugy and is very difficult to understand
2016 * what's going on. Try to clean up */
2017 wDockLaunchWithState(dock
, btn
, state
);
2021 #ifdef XDND /* was OFFIX */
2022 static WDock
*findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
2028 if ((dock
= scr
->dock
) != NULL
) {
2029 for (i
= 0; i
< dock
->max_icons
; i
++) {
2030 if (dock
->icon_array
[i
]
2031 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
2037 if (*icon_pos
< 0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
) != NULL
) {
2038 for (i
= 0; i
< dock
->max_icons
; i
++) {
2039 if (dock
->icon_array
[i
]
2040 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
2051 int wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
2057 dock
= findDock(scr
, event
, &icon_pos
);
2062 * Return True if the drop was on an application icon window.
2063 * In this case, let the ClientMessage handler redirect the
2064 * message to the app.
2066 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
2069 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
2070 scr
->flags
.dnd_data_convertion_status
= 0;
2072 btn
= dock
->icon_array
[icon_pos
];
2074 if (!btn
->forced_dock
) {
2075 btn
->relaunching
= btn
->running
;
2078 if (btn
->wm_instance
|| btn
->wm_class
) {
2079 WWindowAttributes attr
;
2080 memset(&attr
, 0, sizeof(WWindowAttributes
));
2081 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
2083 if (!attr
.no_appicon
)
2089 btn
->paste_launch
= 0;
2090 btn
->drop_launch
= 1;
2091 scr
->last_dock
= dock
;
2092 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
2097 if (!btn
->relaunching
)
2105 Bool
wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
, Bool update_icon
)
2108 Bool lupdate_icon
= False
;
2109 char *command
= NULL
;
2115 lupdate_icon
= True
;
2117 if (icon
->command
== NULL
) {
2118 /* If icon->owner exists, it means the application is running */
2119 if (icon
->icon
->owner
) {
2120 wwin
= icon
->icon
->owner
;
2121 command
= GetCommandForWindow(wwin
->client_win
);
2125 icon
->command
= command
;
2127 /* icon->forced_dock = 1; */
2128 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
2130 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2131 _("Type the command used to launch the application"), &command
)) {
2132 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2136 icon
->command
= command
;
2142 /* If the target is the dock, reject the icon. If
2143 * the target is the clip, make it an attracted icon
2145 if (dock
->type
== WM_CLIP
) {
2146 icon
->attracted
= 1;
2147 if (!icon
->icon
->shadowed
) {
2148 icon
->icon
->shadowed
= 1;
2149 lupdate_icon
= True
;
2159 for (index
= 1; index
< dock
->max_icons
; index
++)
2160 if (dock
->icon_array
[index
] == NULL
)
2162 /* if (index == dock->max_icons)
2165 assert(index
< dock
->max_icons
);
2167 dock
->icon_array
[index
] = icon
;
2171 icon
->omnipresent
= 0;
2173 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2174 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2179 icon
->launching
= 0;
2182 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2183 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2184 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2185 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2186 icon
->icon
->core
->descriptor
.parent
= icon
;
2188 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2189 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2192 * Update icon pixmap, RImage doesn't change,
2193 * so call wIconUpdate is not needed
2196 update_icon_pixmap(icon
->icon
);
2199 wAppIconPaint(icon
);
2202 save_appicon(icon
, True
);
2204 if (wPreferences
.auto_arrange_icons
)
2205 wArrangeIcons(dock
->screen_ptr
, True
);
2207 #ifdef XDND /* was OFFIX */
2208 if (icon
->command
&& !icon
->dnd_command
) {
2209 int len
= strlen(icon
->command
) + 8;
2210 icon
->dnd_command
= wmalloc(len
);
2211 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
2215 if (icon
->command
&& !icon
->paste_command
) {
2216 int len
= strlen(icon
->command
) + 8;
2217 icon
->paste_command
= wmalloc(len
);
2218 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
2224 void wDockReattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2228 for (index
= 1; index
< dock
->max_icons
; index
++) {
2229 if (dock
->icon_array
[index
] == icon
)
2232 assert(index
< dock
->max_icons
);
2237 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2238 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2241 Bool
wDockMoveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2244 char *command
= NULL
;
2246 Bool update_icon
= False
;
2249 return True
; /* No move needed, we're already there */
2255 * For the moment we can't do this if we move icons in Clip from one
2256 * workspace to other, because if we move two or more icons without
2257 * command, the dialog box will not be able to tell us to which of the
2258 * moved icons it applies. -Dan
2260 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
2261 /* If icon->owner exists, it means the application is running */
2262 if (icon
->icon
->owner
) {
2263 wwin
= icon
->icon
->owner
;
2264 command
= GetCommandForWindow(wwin
->client_win
);
2268 icon
->command
= command
;
2271 /* icon->forced_dock = 1; */
2272 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2273 _("Type the command used to launch the application"), &command
)) {
2274 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2278 icon
->command
= command
;
2289 if (dest
->type
== WM_DOCK
|| dest
->type
== WM_DRAWER
)
2290 wClipMakeIconOmnipresent(icon
, False
);
2292 for (index
= 1; index
< src
->max_icons
; index
++) {
2293 if (src
->icon_array
[index
] == icon
)
2296 assert(index
< src
->max_icons
);
2298 src
->icon_array
[index
] = NULL
;
2301 for (index
= 1; index
< dest
->max_icons
; index
++) {
2302 if (dest
->icon_array
[index
] == NULL
)
2306 assert(index
< dest
->max_icons
);
2308 dest
->icon_array
[index
] = icon
;
2311 /* deselect the icon */
2312 if (icon
->icon
->selected
)
2313 wIconSelect(icon
->icon
);
2315 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2316 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2318 /* set it to be kept when moving to dock.
2319 * Unless the icon does not have a command set
2321 if (icon
->command
&& (dest
->type
== WM_DOCK
|| dest
->type
== WM_DRAWER
)) {
2322 icon
->attracted
= 0;
2323 if (icon
->icon
->shadowed
) {
2324 icon
->icon
->shadowed
= 0;
2327 save_appicon(icon
, True
);
2330 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2336 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2337 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2341 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2344 * Update icon pixmap, RImage doesn't change,
2345 * so call wIconUpdate is not needed
2348 update_icon_pixmap(icon
->icon
);
2351 wAppIconPaint(icon
);
2356 void wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2359 Bool update_icon
= False
;
2361 /* make the settings panel be closed */
2363 DestroyDockAppSettingsPanel(icon
->panel
);
2365 /* This must be called before icon->dock is set to NULL.
2366 * Don't move it. -Dan
2368 wClipMakeIconOmnipresent(icon
, False
);
2372 icon
->attracted
= 0;
2373 icon
->auto_launch
= 0;
2374 if (icon
->icon
->shadowed
) {
2375 icon
->icon
->shadowed
= 0;
2379 /* deselect the icon */
2380 if (icon
->icon
->selected
)
2381 wIconSelect(icon
->icon
);
2383 if (icon
->command
) {
2384 wfree(icon
->command
);
2385 icon
->command
= NULL
;
2387 #ifdef XDND /* was OFFIX */
2388 if (icon
->dnd_command
) {
2389 wfree(icon
->dnd_command
);
2390 icon
->dnd_command
= NULL
;
2393 if (icon
->paste_command
) {
2394 wfree(icon
->paste_command
);
2395 icon
->paste_command
= NULL
;
2398 for (index
= 1; index
< dock
->max_icons
; index
++)
2399 if (dock
->icon_array
[index
] == icon
)
2402 assert(index
< dock
->max_icons
);
2403 dock
->icon_array
[index
] = NULL
;
2409 /* if the dock is not attached to an application or
2410 * the application did not set the appropriate hints yet,
2411 * destroy the icon */
2412 if (!icon
->running
|| !wApplicationOf(icon
->main_window
)) {
2413 wAppIconDestroy(icon
);
2415 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2416 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2417 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2418 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2419 icon
->icon
->core
->descriptor
.parent
= icon
;
2421 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2424 * Update icon pixmap, RImage doesn't change,
2425 * so call wIconUpdate is not needed
2428 update_icon_pixmap(icon
->icon
);
2431 wAppIconPaint(icon
);
2433 if (wPreferences
.auto_arrange_icons
)
2434 wArrangeIcons(dock
->screen_ptr
, True
);
2436 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2441 * returns the closest Dock slot index for the passed
2444 * Returns False if icon can't be docked.
2446 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2449 /* Redocking == true means either icon->dock == dock (normal case)
2450 * or we are called from handleDockMove for a drawer */
2451 Bool
wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2453 WScreen
*scr
= dock
->screen_ptr
;
2456 int i
, offset
= ICON_SIZE
/ 2;
2457 WAppIcon
*aicon
= NULL
;
2458 WAppIcon
*nicon
= NULL
;
2460 if (wPreferences
.flags
.noupdates
)
2466 /* if the dock is full */
2467 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
))
2470 /* exact position */
2472 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2474 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2477 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2479 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2481 /* check if the icon is outside the screen boundaries */
2482 if (!onScreen(scr
, dx
+ ex_x
* ICON_SIZE
, dy
+ ex_y
* ICON_SIZE
))
2485 switch (dock
->type
) {
2487 /* We can return False right away if
2488 * - we do not come from this dock (which is a WM_DOCK),
2489 * - we are not right over it, and
2490 * - we are not the main tile of a drawer.
2491 * In the latter case, we are called from handleDockMove. */
2492 if (icon
->dock
!= dock
&& ex_x
!= 0 &&
2493 !(icon
->dock
&& icon
->dock
->type
== WM_DRAWER
&& icon
== icon
->dock
->icon_array
[0]))
2496 if (!redocking
&& ex_x
!= 0)
2499 if (getDrawer(scr
, ex_y
)) /* Return false so that the drawer gets it. */
2503 for (i
= 0; i
< dock
->max_icons
; i
++) {
2504 nicon
= dock
->icon_array
[i
];
2505 if (nicon
&& nicon
->yindex
== ex_y
) {
2512 int sig
, done
, closest
;
2514 /* Possible cases when redocking:
2516 * icon dragged out of range of any slot -> false
2517 * icon dragged on a drawer -> false (to open the drawer)
2518 * icon dragged to range of free slot
2519 * icon dragged to range of same slot
2520 * icon dragged to range of different icon
2522 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2525 if (aicon
== icon
|| !aicon
) {
2531 /* start looking at the upper slot or lower? */
2532 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2538 /* look for closest free slot */
2539 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2543 closest
= sig
* (i
/ 2) + ex_y
;
2544 /* check if this slot is fully on the screen and not used */
2545 if (onScreen(scr
, dx
, dy
+ closest
* ICON_SIZE
)) {
2546 for (j
= 0; j
< dock
->max_icons
; j
++) {
2547 if (dock
->icon_array
[j
]
2548 && dock
->icon_array
[j
]->yindex
== closest
) {
2549 /* slot is used by someone else */
2550 if (dock
->icon_array
[j
] != icon
)
2555 /* slot is used by a drawer */
2556 done
= done
&& !getDrawer(scr
, closest
);
2563 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2564 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2569 } else { /* !redocking */
2571 /* if slot is free and the icon is close enough, return it */
2572 if (!aicon
&& ex_x
== 0) {
2584 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2585 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+ 1;
2588 for (k
= start
; k
< stop
; k
++) {
2589 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2592 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2593 nicon
= tmp
->icon_array
[i
];
2594 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2602 for (k
= start
; k
< stop
; k
++) {
2603 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2606 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2607 nicon
= tmp
->icon_array
[i
];
2608 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2609 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2610 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2619 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2628 WAppIcon
*aicons_to_shift
[ dock
->icon_count
];
2629 int index_of_hole
, j
;
2632 abs(ex_x
) - dock
->icon_count
> DOCK_DETTACH_THRESHOLD
||
2633 (ex_x
< 0 && !dock
->on_right_side
) ||
2634 (ex_x
> 0 && dock
->on_right_side
)) {
2639 ex_x
= (dock
->on_right_side
? -1 : 1);
2641 /* "Reduce" ex_x but keep its sign */
2643 if (abs(ex_x
) > dock
->icon_count
- 1) /* minus 1: do not take icon_array[0] into account */
2644 ex_x
= ex_x
* (dock
->icon_count
- 1) / abs(ex_x
); /* don't use *= ! */
2646 if (abs(ex_x
) > dock
->icon_count
)
2647 ex_x
= ex_x
* dock
->icon_count
/ abs(ex_x
);
2649 index_of_hole
= indexOfHole(dock
, icon
, redocking
);
2651 /* Find the appicons between where icon was (index_of_hole) and where
2652 * it wants to be (ex_x) and slide them. */
2654 for (i
= 1; i
< dock
->max_icons
; i
++) {
2655 if ((aicon
= dock
->icon_array
[ i
]) && aicon
!= icon
&&
2656 ((ex_x
<= aicon
->xindex
&& aicon
->xindex
< index_of_hole
) ||
2657 (index_of_hole
< aicon
->xindex
&& aicon
->xindex
<= ex_x
)))
2658 aicons_to_shift
[ j
++ ] = aicon
;
2660 assert(j
== abs(ex_x
- index_of_hole
));
2662 wSlideAppicons(aicons_to_shift
, j
, (index_of_hole
< ex_x
));
2672 static int onScreen(WScreen
*scr
, int x
, int y
)
2679 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2681 wGetRectPlacementInfo(scr
, rect
, &flags
);
2683 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2687 * returns true if it can find a free slot in the dock,
2688 * in which case it changes x_pos and y_pos accordingly.
2689 * Else returns false.
2691 Bool
wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2693 WScreen
*scr
= dock
->screen_ptr
;
2695 WAppIconChain
*chain
;
2696 unsigned char *slot_map
;
2700 int i
, done
= False
;
2702 int sx
= 0, ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2703 int extra_count
= 0;
2705 if (dock
->type
== WM_DRAWER
) {
2706 if (dock
->icon_count
>= dock
->max_icons
) { /* drawer is full */
2709 *x_pos
= dock
->icon_count
* (dock
->on_right_side
? -1 : 1);
2714 if (dock
->type
== WM_CLIP
&& dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2715 extra_count
= scr
->global_icon_count
;
2717 /* if the dock is full */
2718 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
)
2721 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2722 if (scr
->dock
->on_right_side
)
2723 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2725 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2728 if (ex
< dock
->x_pos
)
2730 if (sx
> dock
->x_pos
+ ICON_SIZE
)
2731 sx
= dock
->x_pos
+ ICON_SIZE
;
2738 /* check if clip is in a corner */
2739 if (dock
->type
== WM_CLIP
) {
2740 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2742 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2744 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2746 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2754 /* If the clip is in the corner, use only slots that are in the border
2756 if (corner
!= C_NONE
) {
2760 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2761 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2762 hmap
= wmalloc(hcount
+ 1);
2763 vmap
= wmalloc(vcount
+ 1);
2765 /* mark used positions */
2768 for (i
= 0; i
< dock
->max_icons
; i
++) {
2769 btn
= dock
->icon_array
[i
];
2773 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2774 vmap
[btn
->yindex
] = 1;
2775 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2776 hmap
[btn
->xindex
] = 1;
2778 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2780 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2781 vmap
[btn
->yindex
] = 1;
2782 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2783 hmap
[btn
->xindex
] = 1;
2787 for (i
= 0; i
< dock
->max_icons
; i
++) {
2788 btn
= dock
->icon_array
[i
];
2792 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2793 vmap
[btn
->yindex
] = 1;
2794 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2795 hmap
[-btn
->xindex
] = 1;
2797 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2799 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2800 vmap
[btn
->yindex
] = 1;
2801 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2802 hmap
[-btn
->xindex
] = 1;
2806 for (i
= 0; i
< dock
->max_icons
; i
++) {
2807 btn
= dock
->icon_array
[i
];
2811 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2812 vmap
[-btn
->yindex
] = 1;
2813 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2814 hmap
[btn
->xindex
] = 1;
2816 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2818 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2819 vmap
[-btn
->yindex
] = 1;
2820 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2821 hmap
[btn
->xindex
] = 1;
2826 for (i
= 0; i
< dock
->max_icons
; i
++) {
2827 btn
= dock
->icon_array
[i
];
2831 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2832 vmap
[-btn
->yindex
] = 1;
2833 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2834 hmap
[-btn
->xindex
] = 1;
2836 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2838 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2839 vmap
[-btn
->yindex
] = 1;
2840 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2841 hmap
[-btn
->xindex
] = 1;
2847 /* search a vacant slot */
2848 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2849 if (i
< vcount
&& vmap
[i
] == 0) {
2855 } else if (i
< hcount
&& hmap
[i
] == 0) {
2865 /* If found a slot, translate and return */
2867 if (corner
== C_NW
|| corner
== C_NE
)
2872 if (corner
== C_NE
|| corner
== C_SE
)
2879 /* else, try to find a slot somewhere else */
2882 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2883 * placed outside of screen */
2884 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2886 /* In the worst case (the clip is in the corner of the screen),
2887 * the amount of icons that fit in the clip is smaller.
2888 * Double the map to get a safe value.
2892 r
= (mwidth
- 1) / 2;
2894 slot_map
= wmalloc(mwidth
* mwidth
);
2896 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2898 /* mark used slots in the map. If the slot falls outside the map
2899 * (for example, when all icons are placed in line), ignore them. */
2900 for (i
= 0; i
< dock
->max_icons
; i
++) {
2901 btn
= dock
->icon_array
[i
];
2903 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2906 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
)
2907 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2909 /* Find closest slot from the center that is free by scanning the
2910 * map from the center to outward in circular passes.
2911 * This will not result in a neat layout, but will be optimal
2912 * in the sense that there will not be holes left.
2915 for (i
= 1; i
<= r
&& !done
; i
++) {
2918 /* top and bottom parts of the ring */
2919 for (x
= -i
; x
<= i
&& !done
; x
++) {
2920 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2922 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2923 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2930 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2931 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2938 /* left and right parts of the ring */
2939 for (y
= -i
+ 1; y
<= i
- 1; y
++) {
2940 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2942 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2943 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2950 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2951 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2964 static void moveDock(WDock
*dock
, int new_x
, int new_y
)
2970 if (dock
->type
== WM_DOCK
) {
2971 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
2972 moveDock(dc
->adrawer
, new_x
, dc
->adrawer
->y_pos
- dock
->y_pos
+ new_y
);
2975 dock
->x_pos
= new_x
;
2976 dock
->y_pos
= new_y
;
2977 for (i
= 0; i
< dock
->max_icons
; i
++) {
2978 btn
= dock
->icon_array
[i
];
2980 btn
->x_pos
= new_x
+ btn
->xindex
* ICON_SIZE
;
2981 btn
->y_pos
= new_y
+ btn
->yindex
* ICON_SIZE
;
2982 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2987 static void swapDock(WDock
*dock
)
2989 WScreen
*scr
= dock
->screen_ptr
;
2993 if (dock
->on_right_side
)
2994 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2996 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2998 swapDrawers(scr
, dock
->on_right_side
, x
);
3000 for (i
= 0; i
< dock
->max_icons
; i
++) {
3001 btn
= dock
->icon_array
[i
];
3004 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
3008 wScreenUpdateUsableArea(scr
);
3011 static pid_t
execCommand(WAppIcon
*btn
, char *command
, WSavedState
*state
)
3013 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
3019 cmdline
= ExpandOptions(scr
, command
);
3021 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
3029 wtokensplit(cmdline
, &argv
, &argc
);
3039 if ((pid
= fork()) == 0) {
3043 SetupEnvironment(scr
);
3049 args
= malloc(sizeof(char *) * (argc
+ 1));
3053 for (i
= 0; i
< argc
; i
++)
3057 execvp(argv
[0], args
);
3060 wtokenfree(argv
, argc
);
3064 state
= wmalloc(sizeof(WSavedState
));
3066 state
->miniaturized
= -1;
3068 if (btn
->dock
== scr
->dock
|| btn
->dock
->type
== WM_DRAWER
|| btn
->omnipresent
)
3069 state
->workspace
= -1;
3071 state
->workspace
= scr
->current_workspace
;
3073 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
3074 wAddDeathHandler(pid
, (WDeathHandler
*) trackDeadProcess
, btn
->dock
);
3082 void wDockHideIcons(WDock
*dock
)
3089 for (i
= 1; i
< dock
->max_icons
; i
++) {
3090 if (dock
->icon_array
[i
])
3091 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3095 dockIconPaint(dock
->icon_array
[0]);
3098 void wDockShowIcons(WDock
*dock
)
3106 btn
= dock
->icon_array
[0];
3107 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
3109 /* Deleting any change in stacking level, this function is now only about
3112 if (!dock
->collapsed
) {
3113 for (i
= 1; i
< dock
->max_icons
; i
++) {
3114 if (dock
->icon_array
[i
])
3115 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3123 void wDockLower(WDock
*dock
)
3128 if (dock
->type
== WM_DOCK
) {
3129 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3130 wDockLower(dc
->adrawer
);
3132 for (i
= 0; i
< dock
->max_icons
; i
++) {
3133 if (dock
->icon_array
[i
])
3134 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
3138 void wDockRaise(WDock
*dock
)
3143 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
3144 if (dock
->icon_array
[i
])
3145 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
3147 if (dock
->type
== WM_DOCK
) {
3148 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3149 wDockRaise(dc
->adrawer
);
3153 void wDockRaiseLower(WDock
*dock
)
3155 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
3156 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
3157 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
3163 void wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
3165 icon
->launching
= 0;
3166 icon
->relaunching
= 0;
3167 dockIconPaint(icon
);
3170 WAppIcon
*wDockFindIconForWindow(WDock
*dock
, Window window
)
3175 for (i
= 0; i
< dock
->max_icons
; i
++) {
3176 icon
= dock
->icon_array
[i
];
3177 if (icon
&& icon
->main_window
== window
)
3183 void wDockTrackWindowLaunch(WDock
*dock
, Window window
)
3186 char *wm_class
, *wm_instance
;
3188 Bool firstPass
= True
;
3190 char *command
= NULL
;
3192 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) || (!wm_class
&& !wm_instance
))
3195 command
= GetCommandForWindow(window
);
3197 for (i
= 0; i
< dock
->max_icons
; i
++) {
3198 icon
= dock
->icon_array
[i
];
3202 /* app is already attached to icon */
3203 if (icon
->main_window
== window
) {
3208 if ((icon
->wm_instance
|| icon
->wm_class
)
3209 && (icon
->launching
|| !icon
->running
)) {
3211 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0)
3214 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0)
3217 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0)
3220 if (!icon
->relaunching
) {
3223 /* Possibly an application that was docked with dockit,
3224 * but the user did not update WMState to indicate that
3225 * it was docked by force */
3226 wapp
= wApplicationOf(window
);
3228 icon
->forced_dock
= 1;
3231 if (!icon
->forced_dock
)
3232 icon
->main_window
= window
;
3235 if (!wPreferences
.no_animations
&& !icon
->launching
&&
3236 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
3240 icon
->launching
= 1;
3241 dockIconPaint(icon
);
3243 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
3244 wm_instance
, wm_class
, TILE_NORMAL
);
3245 /* XXX: can: aicon->icon == NULL ? */
3246 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
3247 wAppIconMove(aicon
, x0
, y0
);
3248 /* Should this always be lowered? -Dan */
3250 wLowerFrame(aicon
->icon
->core
);
3251 XMapWindow(dpy
, aicon
->icon
->core
->window
);
3252 aicon
->launching
= 1;
3253 wAppIconPaint(aicon
);
3254 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
3255 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
3256 wAppIconDestroy(aicon
);
3258 wDockFinishLaunch(dock
, icon
);
3263 if (firstPass
&& !found
) {
3277 void wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3279 if (!wPreferences
.flags
.noclip
) {
3280 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3281 if (scr
->current_workspace
!= workspace
) {
3282 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3283 WAppIconChain
*chain
= scr
->global_icons
;
3286 wDockMoveIconBetweenDocks(chain
->aicon
->dock
,
3287 scr
->workspaces
[workspace
]->clip
,
3288 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
3289 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
3290 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3291 chain
= chain
->next
;
3294 wDockHideIcons(old_clip
);
3295 if (old_clip
->auto_raise_lower
) {
3296 if (old_clip
->auto_raise_magic
) {
3297 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3298 old_clip
->auto_raise_magic
= NULL
;
3300 wDockLower(old_clip
);
3302 if (old_clip
->auto_collapse
) {
3303 if (old_clip
->auto_expand_magic
) {
3304 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3305 old_clip
->auto_expand_magic
= NULL
;
3307 old_clip
->collapsed
= 1;
3309 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3314 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3319 for (i
= 0; i
< dock
->max_icons
; i
++) {
3320 icon
= dock
->icon_array
[i
];
3324 if (icon
->launching
&& icon
->pid
== pid
) {
3325 if (!icon
->relaunching
) {
3327 icon
->main_window
= None
;
3329 wDockFinishLaunch(dock
, icon
);
3331 if (status
== 111) {
3336 if (icon
->drop_launch
)
3337 cmd
= icon
->dnd_command
;
3340 if (icon
->paste_launch
)
3341 cmd
= icon
->paste_command
;
3343 cmd
= icon
->command
;
3345 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3347 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3354 /* This function is called when the dock switches state between
3355 * "normal" (including auto-raise/lower) and "keep on top". It is
3356 * therefore clearly distinct from wDockLower/Raise, which are called
3357 * each time a not-kept-on-top dock is lowered/raised. */
3358 static void toggleLowered(WDock
*dock
)
3364 if (!dock
->lowered
) {
3365 newlevel
= WMNormalLevel
;
3368 newlevel
= WMDockLevel
;
3372 for (i
= 0; i
< dock
->max_icons
; i
++) {
3373 tmp
= dock
->icon_array
[i
];
3377 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3379 /* When the dock is no longer "on top", explicitly lower it as well.
3380 * It saves some CPU cycles (probably) to do it ourselves here
3381 * rather than calling wDockLower at the end of toggleLowered */
3383 wLowerFrame(tmp
->icon
->core
);
3386 if (dock
->type
== WM_DOCK
) {
3387 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
3388 toggleLowered(dc
->adrawer
);
3390 wScreenUpdateUsableArea(dock
->screen_ptr
);
3394 static void toggleCollapsed(WDock
*dock
)
3396 if (dock
->collapsed
) {
3397 dock
->collapsed
= 0;
3398 wDockShowIcons(dock
);
3400 dock
->collapsed
= 1;
3401 wDockHideIcons(dock
);
3405 static void openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3407 WScreen
*scr
= dock
->screen_ptr
;
3408 WObjDescriptor
*desc
;
3410 WApplication
*wapp
= NULL
;
3414 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3416 if (dock
->type
== WM_DOCK
) {
3417 /* Dock position menu */
3418 updateDockPositionMenu(scr
->dock_pos_menu
, dock
);
3419 dock
->menu
->flags
.realized
= 0;
3420 if (!wPreferences
.flags
.nodrawer
) {
3422 entry
= dock
->menu
->entries
[++index
];
3423 entry
->clientdata
= aicon
;
3424 wMenuSetEnabled(dock
->menu
, index
, True
);
3427 /* clip/drawer options */
3428 if (scr
->clip_options
)
3429 updateClipOptionsMenu(scr
->clip_options
, dock
);
3431 n_selected
= numberOfSelectedIcons(dock
);
3433 if (dock
->type
== WM_CLIP
) {
3434 /* Rename Workspace */
3435 entry
= dock
->menu
->entries
[++index
];
3436 if (aicon
== scr
->clip_icon
) {
3437 entry
->callback
= renameCallback
;
3438 entry
->clientdata
= dock
;
3439 entry
->flags
.indicator
= 0;
3440 entry
->text
= _("Rename Workspace");
3442 entry
->callback
= omnipresentCallback
;
3443 entry
->clientdata
= aicon
;
3444 if (n_selected
> 0) {
3445 entry
->flags
.indicator
= 0;
3446 entry
->text
= _("Toggle Omnipresent");
3448 entry
->flags
.indicator
= 1;
3449 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3450 entry
->flags
.indicator_type
= MI_CHECK
;
3451 entry
->text
= _("Omnipresent");
3456 /* select/unselect icon */
3457 entry
= dock
->menu
->entries
[++index
];
3458 entry
->clientdata
= aicon
;
3459 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3460 wMenuSetEnabled(dock
->menu
, index
, aicon
!= scr
->clip_icon
&& !wIsADrawer(scr
, aicon
));
3462 /* select/unselect all icons */
3463 entry
= dock
->menu
->entries
[++index
];
3464 entry
->clientdata
= aicon
;
3466 entry
->text
= _("Unselect All Icons");
3468 entry
->text
= _("Select All Icons");
3470 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3473 entry
= dock
->menu
->entries
[++index
];
3474 entry
->clientdata
= aicon
;
3476 entry
->text
= _("Keep Icons");
3478 entry
->text
= _("Keep Icon");
3480 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3482 if (dock
->type
== WM_CLIP
) {
3483 /* this is the workspace submenu part */
3484 entry
= dock
->menu
->entries
[++index
];
3486 entry
->text
= _("Move Icons To");
3488 entry
->text
= _("Move Icon To");
3490 if (scr
->clip_submenu
)
3491 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3493 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3496 /* remove icon(s) */
3497 entry
= dock
->menu
->entries
[++index
];
3498 entry
->clientdata
= aicon
;
3500 entry
->text
= _("Remove Icons");
3502 entry
->text
= _("Remove Icon");
3504 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3506 /* attract icon(s) */
3507 entry
= dock
->menu
->entries
[++index
];
3508 entry
->clientdata
= aicon
;
3510 dock
->menu
->flags
.realized
= 0;
3511 wMenuRealize(dock
->menu
);
3514 if (aicon
->icon
->owner
)
3515 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3520 entry
= dock
->menu
->entries
[++index
];
3521 entry
->clientdata
= aicon
;
3522 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3525 entry
= dock
->menu
->entries
[++index
];
3526 entry
->clientdata
= aicon
;
3527 if (wapp
&& wapp
->flags
.hidden
)
3528 entry
->text
= _("Unhide Here");
3530 entry
->text
= _("Bring Here");
3532 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3535 entry
= dock
->menu
->entries
[++index
];
3536 entry
->clientdata
= aicon
;
3537 if (wapp
&& wapp
->flags
.hidden
)
3538 entry
->text
= _("Unhide");
3540 entry
->text
= _("Hide");
3542 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3545 entry
= dock
->menu
->entries
[++index
];
3546 entry
->clientdata
= aicon
;
3547 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3549 /* kill or remove drawer */
3550 entry
= dock
->menu
->entries
[++index
];
3551 entry
->clientdata
= aicon
;
3552 if (wIsADrawer(scr
, aicon
)) {
3553 entry
->callback
= removeDrawerCallback
;
3554 entry
->text
= _("Remove drawer");
3555 wMenuSetEnabled(dock
->menu
, index
, True
);
3557 entry
->callback
= killCallback
;
3558 entry
->text
= _("Kill");
3559 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3562 if (!dock
->menu
->flags
.realized
)
3563 wMenuRealize(dock
->menu
);
3565 if (dock
->type
== WM_CLIP
|| dock
->type
== WM_DRAWER
) {
3566 /*x_pos = event->xbutton.x_root+2; */
3567 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3570 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3571 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3574 x_pos
= dock
->on_right_side
? scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3577 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3579 /* allow drag select */
3580 event
->xany
.send_event
= True
;
3581 desc
= &dock
->menu
->menu
->descriptor
;
3582 (*desc
->handle_mousedown
) (desc
, event
);
3585 /******************************************************************/
3586 static void iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3588 WAppIcon
*btn
= desc
->parent
;
3589 WDock
*dock
= btn
->dock
;
3590 WApplication
*wapp
= NULL
;
3593 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3594 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3596 assert(wapp
!= NULL
);
3598 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3600 /* go to the last workspace that the user worked on the app */
3601 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
&& !unhideHere
)
3602 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3604 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3606 if (event
->xbutton
.state
& MOD_MASK
)
3607 wHideOtherApplications(btn
->icon
->owner
);
3609 if (event
->xbutton
.button
== Button1
) {
3610 if (event
->xbutton
.state
& MOD_MASK
) {
3611 /* raise/lower dock */
3612 toggleLowered(dock
);
3613 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3614 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
)
3615 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3616 else if (wPreferences
.flags
.clip_merged_in_dock
) {
3617 // Is actually the dock
3620 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3621 launchDockedApplication(btn
, False
);
3625 wShowInfoPanel(dock
->screen_ptr
);
3629 toggleCollapsed(dock
);
3630 } else if (wIsADrawer(dock
->screen_ptr
, btn
)) {
3631 toggleCollapsed(dock
);
3632 } else if (btn
->command
) {
3633 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3634 launchDockedApplication(btn
, False
);
3635 } else if (btn
->xindex
== 0 && btn
->yindex
== 0 && btn
->dock
->type
== WM_DOCK
) {
3636 wShowInfoPanel(dock
->screen_ptr
);
3642 static void handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3644 WScreen
*scr
= dock
->screen_ptr
;
3645 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3646 WIcon
*icon
= aicon
->icon
;
3649 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;;
3650 int shad_x
= x
, shad_y
= y
;
3652 int grabbed
= 0, done
, previously_on_right
, now_on_right
, previous_x_pos
, i
;
3653 Pixmap ghost
= None
;
3654 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3656 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3657 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3658 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
)
3659 wwarning("pointer grab failed for dock move");
3661 if (dock
->type
== WM_DRAWER
) {
3663 wins
[0] = icon
->core
->window
;
3664 wins
[1] = scr
->dock_shadow
;
3665 XRestackWindows(dpy
, wins
, 2);
3666 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3667 ICON_SIZE
, ICON_SIZE
);
3669 if (icon
->pixmap
!=None
)
3670 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3672 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3674 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3675 XClearWindow(dpy
, scr
->dock_shadow
);
3677 XMapWindow(dpy
, scr
->dock_shadow
);
3680 previously_on_right
= now_on_right
= dock
->on_right_side
;
3681 previous_x_pos
= dock
->x_pos
;
3684 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3685 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3692 /* It means the cursor moved so fast that it entered
3693 * something else (if moving slowly, it would have
3694 * stayed in the dock that is being moved. Ignore such
3695 * "spurious" EnterNotifiy's */
3700 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3701 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3702 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3703 | ButtonReleaseMask
| ButtonPressMask
,
3704 wCursor
[WCUR_MOVE
], CurrentTime
);
3709 switch (dock
->type
) {
3711 x
= ev
.xmotion
.x_root
- ofs_x
;
3712 y
= ev
.xmotion
.y_root
- ofs_y
;
3713 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3714 moveDock(dock
, x
, y
);
3717 x
= ev
.xmotion
.x_root
- ofs_x
;
3718 y
= ev
.xmotion
.y_root
- ofs_y
;
3719 if (previously_on_right
)
3721 now_on_right
= (ev
.xmotion
.x_root
>= previous_x_pos
- ICON_SIZE
);
3725 now_on_right
= (ev
.xmotion
.x_root
> previous_x_pos
+ ICON_SIZE
* 2);
3727 if (now_on_right
!= dock
->on_right_side
)
3729 dock
->on_right_side
= now_on_right
;
3731 wArrangeIcons(scr
, False
);
3733 // Also perform the vertical move
3734 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3735 moveDock(dock
, dock
->x_pos
, y
);
3736 if (wPreferences
.flags
.wrap_appicons_in_dock
)
3738 for (i
= 0; i
< dock
->max_icons
; i
++) {
3739 int new_y
, new_index
, j
, ok
;
3740 if ((tmpaicon
= dock
->icon_array
[i
]) == NULL
)
3742 if (onScreen(scr
, tmpaicon
->x_pos
, tmpaicon
->y_pos
))
3744 new_y
= (tmpaicon
->y_pos
+ ICON_SIZE
* dock
->max_icons
) % (ICON_SIZE
* dock
->max_icons
);
3745 new_index
= (new_y
- dock
->y_pos
) / ICON_SIZE
;
3746 if (!onScreen(scr
, tmpaicon
->x_pos
, new_y
))
3749 for (j
= 0; j
< dock
->max_icons
; j
++)
3751 if (dock
->icon_array
[j
] != NULL
&&
3752 dock
->icon_array
[j
]->yindex
== new_index
)
3758 if (!ok
|| getDrawer(scr
, new_index
) != NULL
)
3760 wDockReattachIcon(dock
, tmpaicon
, tmpaicon
->xindex
, new_index
);
3762 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3764 int new_y
, new_index
, j
, ok
;
3765 tmpaicon
= dc
->adrawer
->icon_array
[0];
3766 if (onScreen(scr
, tmpaicon
->x_pos
, tmpaicon
->y_pos
))
3768 new_y
= (tmpaicon
->y_pos
+ ICON_SIZE
* dock
->max_icons
) % (ICON_SIZE
* dock
->max_icons
);
3769 new_index
= (new_y
- dock
->y_pos
) / ICON_SIZE
;
3770 if (!onScreen(scr
, tmpaicon
->x_pos
, new_y
))
3773 for (j
= 0; j
< dock
->max_icons
; j
++)
3775 if (dock
->icon_array
[j
] != NULL
&&
3776 dock
->icon_array
[j
]->yindex
== new_index
)
3782 if (!ok
|| getDrawer(scr
, new_index
) != NULL
)
3784 moveDock(dc
->adrawer
, tmpaicon
->x_pos
, new_y
);
3790 WDock
*real_dock
= dock
->screen_ptr
->dock
;
3793 x
= ev
.xmotion
.x_root
- ofs_x
;
3794 y
= ev
.xmotion
.y_root
- ofs_y
;
3795 snapped
= wDockSnapIcon(real_dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3797 shad_x
= real_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3798 shad_y
= real_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3799 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3801 moveDock(dock
, x
, y
);
3811 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3813 XUngrabPointer(dpy
, CurrentTime
);
3814 if (dock
->type
== WM_DRAWER
) {
3815 Window
*wins
[dock
->icon_count
];
3817 for (i
= 0; i
< dock
->max_icons
; i
++) {
3818 if ((tmpaicon
= dock
->icon_array
[i
]) == NULL
)
3820 wins
[ tmpaicon
->xindex
+ (dock
->on_right_side
? dock
->icon_count
- 1 : 0) ] = &tmpaicon
->icon
->core
->window
;
3822 SlideWindows(wins
, dock
->icon_count
,
3823 (dock
->on_right_side
? x
- (dock
->icon_count
- 1) * ICON_SIZE
: x
),
3825 (dock
->on_right_side
? shad_x
- (dock
->icon_count
- 1) * ICON_SIZE
: shad_x
),
3827 XUnmapWindow(dpy
, scr
->dock_shadow
);
3828 moveDock(dock
, shad_x
, shad_y
);
3829 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3837 XFreePixmap(dpy
, ghost
);
3838 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3843 static int getClipButton(int px
, int py
)
3845 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3847 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3850 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3851 return CLIP_FORWARD
;
3852 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3858 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3861 int done
, direction
, new_ws
;
3863 WDock
*clip
= scr
->clip_icon
->dock
;
3865 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3867 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3868 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3870 wClipIconPaint(scr
->clip_icon
);
3873 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3880 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3881 if (new_dir
!= direction
) {
3882 direction
= new_dir
;
3883 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3884 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3885 wClipIconPaint(scr
->clip_icon
);
3893 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3898 clip
->lclip_button_pushed
= 0;
3899 clip
->rclip_button_pushed
= 0;
3901 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3903 if (direction
== CLIP_FORWARD
) {
3904 if (scr
->current_workspace
< scr
->workspace_count
- 1)
3905 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3906 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
- 1)
3907 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3908 else if (wPreferences
.ws_cycle
)
3909 wWorkspaceChange(scr
, 0);
3910 } else if (direction
== CLIP_REWIND
) {
3911 if (scr
->current_workspace
> 0)
3912 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
3913 else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
)
3914 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
3917 wClipIconPaint(scr
->clip_icon
);
3920 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3922 WAppIcon
*aicon
= desc
->parent
;
3923 WDock
*dock
= aicon
->dock
;
3924 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3926 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3929 scr
->last_dock
= dock
;
3931 if (dock
->menu
->flags
.mapped
)
3932 wMenuUnmap(dock
->menu
);
3934 if (IsDoubleClick(scr
, event
)) {
3935 /* double-click was not in the main clip icon */
3936 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3937 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3938 iconDblClick(desc
, event
);
3943 if (event
->xbutton
.button
== Button1
) {
3944 if (event
->xbutton
.state
& MOD_MASK
)
3949 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
&& dock
->type
!= WM_DOCK
) {
3950 wIconSelect(aicon
->icon
);
3954 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3955 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
&&
3956 (dock
->type
== WM_CLIP
|| (dock
->type
== WM_DOCK
&& wPreferences
.flags
.clip_merged_in_dock
)))
3957 handleClipChangeWorkspace(scr
, event
);
3959 handleDockMove(dock
, aicon
, event
);
3961 Bool hasMoved
= wHandleAppIconMove(aicon
, event
);
3962 if (wPreferences
.single_click
&& !hasMoved
)
3963 iconDblClick(desc
, event
);
3965 } else if (event
->xbutton
.button
== Button2
&& aicon
== scr
->clip_icon
) {
3966 if (!scr
->clip_ws_menu
) {
3967 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3969 if (scr
->clip_ws_menu
) {
3970 WMenu
*wsMenu
= scr
->clip_ws_menu
;
3973 wWorkspaceMenuUpdate(scr
, wsMenu
);
3975 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
3978 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
3979 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
3981 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
3983 desc
= &wsMenu
->menu
->descriptor
;
3984 event
->xany
.send_event
= True
;
3985 (*desc
->handle_mousedown
) (desc
, event
);
3987 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
3988 (event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
) {
3989 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3990 } else if (event
->xbutton
.button
== Button3
) {
3991 if (event
->xbutton
.send_event
&&
3992 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3993 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3994 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3995 wwarning("pointer grab failed for dockicon menu");
3999 openDockMenu(dock
, aicon
, event
);
4000 } else if (event
->xbutton
.button
== Button2
) {
4001 WAppIcon
*btn
= desc
->parent
;
4003 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
4004 launchDockedApplication(btn
, True
);
4008 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
4010 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
4014 assert(event
->type
== EnterNotify
);
4016 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
4019 scr
= btn
->icon
->core
->screen_ptr
;
4025 /* The auto raise/lower code */
4026 tmp
= (dock
->type
== WM_DRAWER
? scr
->dock
: dock
);
4027 if (tmp
->auto_lower_magic
) {
4028 WMDeleteTimerHandler(tmp
->auto_lower_magic
);
4029 tmp
->auto_lower_magic
= NULL
;
4031 if (tmp
->auto_raise_lower
&& !tmp
->auto_raise_magic
)
4032 tmp
->auto_raise_magic
= WMAddTimerHandler(wPreferences
.clip_auto_raise_delay
, clipAutoRaise
, (void *) tmp
);
4034 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4037 /* The auto expand/collapse code */
4038 if (dock
->auto_collapse_magic
) {
4039 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
4040 dock
->auto_collapse_magic
= NULL
;
4042 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
)
4043 dock
->auto_expand_magic
= WMAddTimerHandler(wPreferences
.clip_auto_expand_delay
, clipAutoExpand
, (void *)dock
);
4046 static void clipLeave(WDock
*dock
)
4049 WObjDescriptor
*desc
= NULL
;
4055 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
4056 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
4057 (XPointer
*) & desc
) != XCNOENT
4058 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
4059 && ((WAppIcon
*) desc
->parent
)->dock
== dock
) {
4060 /* We haven't left the dock/clip/drawer yet */
4061 XPutBackEvent(dpy
, &event
);
4065 XPutBackEvent(dpy
, &event
);
4067 /* We entered a withdrawn window, so we're still in Clip */
4071 tmp
= (dock
->type
== WM_DRAWER
? dock
->screen_ptr
->dock
: dock
);
4072 if (tmp
->auto_raise_magic
) {
4073 WMDeleteTimerHandler(tmp
->auto_raise_magic
);
4074 tmp
->auto_raise_magic
= NULL
;
4076 if (tmp
->auto_raise_lower
&& !tmp
->auto_lower_magic
)
4077 tmp
->auto_lower_magic
= WMAddTimerHandler(wPreferences
.clip_auto_lower_delay
, clipAutoLower
, (void *)tmp
);
4079 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4082 if (dock
->auto_expand_magic
) {
4083 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4084 dock
->auto_expand_magic
= NULL
;
4086 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
)
4087 dock
->auto_collapse_magic
= WMAddTimerHandler(wPreferences
.clip_auto_collapse_delay
, clipAutoCollapse
, (void *)dock
);
4090 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4092 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
4094 assert(event
->type
== LeaveNotify
);
4096 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
4099 clipLeave(btn
->dock
);
4102 static void clipAutoCollapse(void *cdata
)
4104 WDock
*dock
= (WDock
*) cdata
;
4106 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4109 if (dock
->auto_collapse
) {
4110 dock
->collapsed
= 1;
4111 wDockHideIcons(dock
);
4113 dock
->auto_collapse_magic
= NULL
;
4116 static void clipAutoExpand(void *cdata
)
4118 WDock
*dock
= (WDock
*) cdata
;
4120 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4123 if (dock
->auto_collapse
) {
4124 dock
->collapsed
= 0;
4125 wDockShowIcons(dock
);
4127 dock
->auto_expand_magic
= NULL
;
4130 static void clipAutoLower(void *cdata
)
4132 WDock
*dock
= (WDock
*) cdata
;
4134 if (dock
->auto_raise_lower
)
4137 dock
->auto_lower_magic
= NULL
;
4140 static void clipAutoRaise(void *cdata
)
4142 WDock
*dock
= (WDock
*) cdata
;
4144 if (dock
->auto_raise_lower
)
4147 dock
->auto_raise_magic
= NULL
;
4150 static Bool
iconCanBeOmnipresent(WAppIcon
*aicon
)
4152 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4157 for (i
= 0; i
< scr
->workspace_count
; i
++) {
4158 clip
= scr
->workspaces
[i
]->clip
;
4160 if (clip
== aicon
->dock
)
4163 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4164 return False
; /* Clip is full in some workspace */
4166 for (j
= 0; j
< clip
->max_icons
; j
++) {
4167 btn
= clip
->icon_array
[j
];
4168 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
4176 int wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
4178 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4179 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4180 int status
= WO_SUCCESS
;
4182 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== scr
->clip_icon
)
4183 return WO_NOT_APPLICABLE
;
4185 if (aicon
->omnipresent
== omnipresent
)
4189 if (iconCanBeOmnipresent(aicon
)) {
4190 aicon
->omnipresent
= 1;
4191 new_entry
= wmalloc(sizeof(WAppIconChain
));
4192 new_entry
->aicon
= aicon
;
4193 new_entry
->next
= scr
->global_icons
;
4194 scr
->global_icons
= new_entry
;
4195 scr
->global_icon_count
++;
4197 aicon
->omnipresent
= 0;
4201 aicon
->omnipresent
= 0;
4202 if (aicon
== scr
->global_icons
->aicon
) {
4203 tmp
= scr
->global_icons
->next
;
4204 wfree(scr
->global_icons
);
4205 scr
->global_icons
= tmp
;
4206 scr
->global_icon_count
--;
4208 tmp
= scr
->global_icons
;
4210 if (tmp
->next
->aicon
== aicon
) {
4211 tmp1
= tmp
->next
->next
;
4214 scr
->global_icon_count
--;
4222 wAppIconPaint(aicon
);
4227 static void drawerAppendToChain(WScreen
*scr
, WDock
*drawer
)
4229 WDrawerChain
**where_to_add
;
4231 where_to_add
= &scr
->drawers
;
4232 while ((*where_to_add
) != NULL
) {
4233 where_to_add
= &(*where_to_add
)->next
;
4236 *where_to_add
= wmalloc(sizeof(WDrawerChain
));
4237 (*where_to_add
)->adrawer
= drawer
;
4238 (*where_to_add
)->next
= NULL
;
4239 scr
->drawer_count
++;
4243 static void drawerRemoveFromChain(WScreen
*scr
, WDock
*drawer
)
4245 WDrawerChain
*next
, **to_remove
;
4247 to_remove
= &scr
->drawers
;
4249 if (*to_remove
== NULL
) {
4250 wwarning("The drawer to be removed can not be found.");
4253 if ((*to_remove
)->adrawer
== drawer
)
4256 to_remove
= &(*to_remove
)->next
;
4258 next
= (*to_remove
)->next
;
4261 scr
->drawer_count
--;
4265 /* Don't free the returned string. Duplicate it. */
4266 static char * findUniqueName(WScreen
*scr
, const char *instance_basename
)
4268 static char buffer
[128];
4271 Bool already_in_use
= True
;
4273 #define UNIQUE_NAME_WATCHDOG 128
4274 for (i
= 0; already_in_use
&& i
< UNIQUE_NAME_WATCHDOG
; i
++) {
4275 snprintf(buffer
, sizeof buffer
, "%s%d", instance_basename
, i
);
4277 already_in_use
= False
;
4279 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4280 if (!strncmp(dc
->adrawer
->icon_array
[0]->wm_instance
, buffer
,
4282 already_in_use
= True
;
4288 if (i
== UNIQUE_NAME_WATCHDOG
)
4289 wwarning("Couldn't find a unique name for drawer in %d attemps.", i
);
4290 #undef UNIQUE_NAME_WATCHDOG
4296 static void drawerIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
4298 wDrawerIconPaint((WAppIcon
*) desc
->parent
);
4302 static int addADrawer(WScreen
*scr
)
4304 int i
, y
, sig
, found_y
;
4305 WDock
*drawer
, *dock
= scr
->dock
;
4307 char can_be_here
[2 * dock
->max_icons
- 1];
4309 if (dock
->icon_count
+ scr
->drawer_count
>= dock
->max_icons
)
4312 for (y
= -dock
->max_icons
+ 1; y
< dock
->max_icons
; y
++) {
4313 can_be_here
[y
+ dock
->max_icons
- 1] = True
;
4315 for (i
= 0; i
< dock
->max_icons
; i
++) {
4316 if (dock
->icon_array
[i
] != NULL
)
4317 can_be_here
[dock
->icon_array
[i
]->yindex
+ dock
->max_icons
- 1] = False
;
4319 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4320 y
= (int) ((dc
->adrawer
->y_pos
- dock
->y_pos
) / ICON_SIZE
);
4321 can_be_here
[y
+ dock
->max_icons
- 1] = False
;
4325 for (sig
= 1; !found_y
&& sig
> -2; sig
-= 2) // 1, then -1
4327 for (y
= sig
; sig
* y
< dock
->max_icons
; y
+= sig
)
4329 if (can_be_here
[y
+ dock
->max_icons
- 1] &&
4330 onScreen(scr
, dock
->x_pos
, dock
->y_pos
+ y
* ICON_SIZE
))
4339 /* This can happen even when dock->icon_count + scr->drawer_count
4340 * < dock->max_icons when the dock is not aligned on an
4341 * ICON_SIZE multiple, as some space is lost above and under it */
4344 drawer
= wDockCreate(scr
, WM_DRAWER
, NULL
);
4345 drawer
->lowered
= scr
->dock
->lowered
;
4346 drawer
->auto_raise_lower
= scr
->dock
->auto_raise_lower
;
4347 drawer
->x_pos
= dock
->x_pos
;
4348 drawer
->y_pos
= dock
->y_pos
+ ICON_SIZE
* y
;
4349 drawer
->icon_array
[0]->xindex
= 0;
4350 drawer
->icon_array
[0]->yindex
= 0;
4351 drawer
->icon_array
[0]->x_pos
= drawer
->x_pos
;
4352 drawer
->icon_array
[0]->y_pos
= drawer
->y_pos
;
4353 XMoveWindow(dpy
, drawer
->icon_array
[0]->icon
->core
->window
,
4354 drawer
->icon_array
[0]->x_pos
, drawer
->icon_array
[0]->y_pos
);
4360 static void addADrawerCallback(WMenu
*menu
, WMenuEntry
*entry
)
4362 assert(entry
->clientdata
!=NULL
);
4363 addADrawer(((WAppIcon
*) entry
->clientdata
)->dock
->screen_ptr
);
4367 static void drawerDestroy(WDock
*drawer
)
4377 scr
= drawer
->screen_ptr
;
4379 /* Note regarding menus: we can't delete any dock/clip/drawer menu, because
4380 * that would (attempt to) wfree some memory in gettext library (see menu
4381 * entries that have several "versions", such like "Hide" and "Unhide"). */
4383 wDefaultPurgeInfo(scr
, drawer
->icon_array
[0]->wm_instance
,
4384 drawer
->icon_array
[0]->wm_class
);
4385 icons
= WMCreateArray(drawer
->icon_count
- 1);
4386 for (i
= 1; i
< drawer
->max_icons
; i
++) {
4387 if (!(aicon
= drawer
->icon_array
[i
]))
4389 WMAddToArray(icons
, aicon
);
4391 removeIcons(icons
, drawer
);
4393 if (drawer
->auto_collapse_magic
) {
4394 WMDeleteTimerHandler(drawer
->auto_collapse_magic
);
4395 drawer
->auto_collapse_magic
= NULL
;
4397 if (drawer
->auto_lower_magic
) {
4398 WMDeleteTimerHandler(drawer
->auto_lower_magic
);
4399 drawer
->auto_lower_magic
= NULL
;
4402 wAppIconDestroy(drawer
->icon_array
[0]);
4403 wfree(drawer
->icon_array
);
4406 drawerRemoveFromChain(scr
, drawer
);
4407 if (scr
->last_dock
== drawer
)
4408 scr
->last_dock
= NULL
;
4409 if (scr
->attracting_drawer
== drawer
)
4410 scr
->attracting_drawer
= NULL
;
4414 static void removeDrawerCallback(WMenu
*menu
, WMenuEntry
*entry
)
4416 WDock
*dock
= ((WAppIcon
*)entry
->clientdata
)->dock
;
4417 assert(dock
!= NULL
);
4419 if (dock
->icon_count
> 1) {
4420 if (wMessageDialog(dock
->screen_ptr
, _("Drawer"),
4421 _("All icons in this drawer will be detached!"),
4422 _("OK"), _("Cancel"), NULL
) != WAPRDefault
)
4425 drawerDestroy(dock
);
4429 void wDrawerIconPaint(WAppIcon
*dicon
)
4431 Window win
= dicon
->icon
->core
->window
;
4432 WScreen
*scr
= dicon
->icon
->core
->screen_ptr
;
4434 GC gc
= scr
->draw_gc
;
4437 wIconPaint(dicon
->icon
);
4439 if (!dicon
->dock
->collapsed
)
4440 color
= scr
->clip_title_color
[CLIP_NORMAL
];
4442 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
4443 XSetForeground(dpy
, gc
, WMColorPixel(color
));
4445 if (dicon
->dock
->on_right_side
) {
4446 p
[0].x
= p
[3].x
= 10;
4447 p
[0].y
= p
[3].y
= ICON_SIZE
/ 2 - 5;
4449 p
[1].y
= ICON_SIZE
/ 2 + 5;
4451 p
[2].y
= ICON_SIZE
/ 2;
4454 p
[0].x
= p
[3].x
= ICON_SIZE
-1 - 10;
4455 p
[0].y
= p
[3].y
= ICON_SIZE
/ 2 - 5;
4456 p
[1].x
= ICON_SIZE
-1 - 10;
4457 p
[1].y
= ICON_SIZE
/ 2 + 5;
4458 p
[2].x
= ICON_SIZE
-1 - 5;
4459 p
[2].y
= ICON_SIZE
/ 2;
4461 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
4462 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
4466 RImage
* wDrawerMakeTile(WScreen
*scr
, RImage
*normalTile
)
4468 RImage
*tile
= RCloneImage(normalTile
);
4473 dark
.red
= dark
.green
= dark
.blue
= 60;
4476 light
.red
= light
.green
= light
.blue
= 80;
4479 if (!scr
->dock
|| scr
->dock
->on_right_side
) {
4480 ROperateLine(tile
, RSubtractOperation
, 11, ICON_SIZE
/ 2 - 7,
4481 4, ICON_SIZE
/ 2, &dark
); /* / */
4482 ROperateLine(tile
, RSubtractOperation
, 11, ICON_SIZE
/ 2 + 7,
4483 4, ICON_SIZE
/ 2, &dark
); /* \ */
4484 ROperateLine(tile
, RAddOperation
, 11, ICON_SIZE
/ 2 - 7,
4485 11, ICON_SIZE
/ 2 + 7, &light
); /* | */
4488 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 - 7,
4489 ICON_SIZE
-1 - 4, ICON_SIZE
/ 2, &dark
); /* \ */
4490 ROperateLine(tile
, RAddOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 + 7,
4491 ICON_SIZE
-1 - 4, ICON_SIZE
/ 2, &light
); /* / */
4492 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 - 7,
4493 ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 + 7, &dark
); /* | */
4499 static void swapDrawer(WDock
*drawer
, int new_x
)
4503 drawer
->on_right_side
= !drawer
->on_right_side
;
4504 drawer
->x_pos
= new_x
;
4506 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4508 if ((ai
= drawer
->icon_array
[i
]) == NULL
)
4510 ai
->xindex
*= -1; /* so A B C becomes C B A */
4511 ai
->x_pos
= new_x
+ ai
->xindex
* ICON_SIZE
;
4513 /* Update drawer's tile */
4515 wIconUpdate(ai
->icon
);
4516 wDrawerIconPaint(ai
);
4518 XMoveWindow(dpy
, ai
->icon
->core
->window
, ai
->x_pos
, ai
->y_pos
);
4523 static void swapDrawers(WScreen
*scr
, int on_right_side
, int new_x
)
4527 if (scr
->drawer_tile
) {
4528 RReleaseImage(scr
->drawer_tile
);
4530 scr
->drawer_tile
= wDrawerMakeTile(scr
, scr
->icon_tile
);
4532 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4533 swapDrawer(dc
->adrawer
, new_x
);
4534 assert(dc
->adrawer
->on_right_side
== on_right_side
);
4539 int wIsADrawer(WScreen
*scr
, WAppIcon
*aicon
)
4541 return aicon
&& aicon
->dock
&&
4542 aicon
->dock
->type
== WM_DRAWER
&& aicon
->dock
->icon_array
[0] == aicon
;
4546 static WDock
* getDrawer(WScreen
*scr
, int y_index
)
4550 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4551 if (dc
->adrawer
->y_pos
- scr
->dock
->y_pos
== y_index
* ICON_SIZE
)
4559 /* Find the "hole" a moving appicon created when snapped into the
4560 * drawer. redocking is a boolean. If the moving appicon comes from the
4561 * drawer, drawer->icon_count is correct. If not, redocking is then false and
4562 * there are now drawer->icon_count plus one appicons in the drawer. */
4563 static int indexOfHole(WDock
*drawer
, WAppIcon
*moving_aicon
, int redocking
)
4565 int index_of_hole
, i
;
4567 /* Classic interview question...
4569 * We have n-1 (n = drawer->icon_count-1 or drawer->icon_count, see
4570 * redocking) appicons, whose xindex are unique in [1..n]. One is missing:
4571 * that's where the ghost of the moving appicon is, that's what the
4572 * function should return.
4574 * We compute 1+2+...+n (this sum is equal to n*(n+1)/2), we substract to
4575 * this sum the xindex of each of the n-1 appicons, and we get the correct
4579 index_of_hole
= (drawer
->icon_count
- 1) * drawer
->icon_count
/ 2;
4581 index_of_hole
= drawer
->icon_count
* (drawer
->icon_count
+ 1) / 2;
4583 index_of_hole
*= (drawer
->on_right_side
? -1 : 1);
4585 for (i
= 1; i
< drawer
->max_icons
; i
++) {
4586 if (drawer
->icon_array
[i
] && drawer
->icon_array
[i
] != moving_aicon
)
4587 index_of_hole
-= drawer
->icon_array
[i
]->xindex
;
4589 /* wmessage(" Index of the moving appicon is %d (%sredocking)", index_of_hole, (redocking ? "" : "not ")); */
4590 if (abs(index_of_hole
) > abs(drawer
->icon_count
) - (redocking
? 1 : 0))
4591 wwarning(" index_of_hole is too large ! (%d greater than %d)",
4592 index_of_hole
, abs(drawer
->icon_count
) - (redocking
? 1 : 0));
4593 if (index_of_hole
== 0)
4594 wwarning(" index_of_hole == 0 (%sredocking, icon_count == %d)", (redocking
? "" : "not "), drawer
->icon_count
);
4596 return index_of_hole
;
4600 void wSlideAppicons(WAppIcon
**appicons
, int n
, int to_the_left
)
4603 int leftmost
= -1, min_index
= 9999, from_x
= -1; // leftmost and from_x initialized to avoid warning
4610 for (i
= 0; i
< n
; i
++) {
4611 aicon
= appicons
[i
];
4612 aicon
->xindex
+= (to_the_left
? -1 : +1);
4613 if (aicon
->xindex
< min_index
) {
4614 min_index
= aicon
->xindex
;
4616 from_x
= aicon
->x_pos
;
4618 aicon
->x_pos
+= (to_the_left
? -ICON_SIZE
: +ICON_SIZE
);
4621 for (i
= 0; i
< n
; i
++) {
4622 aicon
= appicons
[i
];
4623 wins
[aicon
->xindex
- min_index
] = &aicon
->icon
->core
->window
;
4625 aicon
= appicons
[leftmost
];
4626 SlideWindows(wins
, n
, from_x
, aicon
->y_pos
, aicon
->x_pos
, aicon
->y_pos
);
4630 void wDrawerFillTheGap(WDock
*drawer
, WAppIcon
*aicon
, Bool redocking
)
4633 int index_of_hole
= indexOfHole(drawer
, aicon
, redocking
);
4634 WAppIcon
*aicons_to_shift
[drawer
->icon_count
];
4637 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4638 WAppIcon
*ai
= drawer
->icon_array
[i
];
4639 if (ai
&& ai
!= aicon
&&
4640 abs(ai
->xindex
) > abs(index_of_hole
))
4641 aicons_to_shift
[j
++] = ai
;
4643 if (j
!= drawer
->icon_count
- abs(index_of_hole
) - (redocking
? 1 : 0))
4644 wwarning("Removing aicon at index %d from %s: j=%d but should be %d",
4645 index_of_hole
, drawer
->icon_array
[0]->wm_instance
,
4646 j
, drawer
->icon_count
- abs(index_of_hole
) - (redocking
? 1 : 0));
4647 wSlideAppicons(aicons_to_shift
, j
, !drawer
->on_right_side
);
4651 static void drawerConsolidateIcons(WDock
*drawer
)
4653 WAppIcon
*aicons_to_shift
[drawer
->icon_count
];
4654 int maxRemaining
= 0;
4657 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4658 WAppIcon
*ai
= drawer
->icon_array
[i
];
4661 sum
+= abs(ai
->xindex
);
4662 if (abs(ai
->xindex
) > maxRemaining
)
4663 maxRemaining
= abs(ai
->xindex
);
4665 while (sum
!= maxRemaining
* (maxRemaining
+ 1) / 2) { // while there is a hole
4668 // Look up for the hole at max position
4670 for (maxDeleted
= maxRemaining
- 1; maxDeleted
> 0; maxDeleted
--) {
4671 Bool foundAppIconThere
= False
;
4672 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4673 WAppIcon
*ai
= drawer
->icon_array
[i
];
4676 if (abs(ai
->xindex
) == maxDeleted
) {
4677 foundAppIconThere
= True
;
4681 if (!foundAppIconThere
)
4684 assert(maxDeleted
> 0); // would mean while test is wrong
4686 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4687 ai
= drawer
->icon_array
[i
];
4688 if (ai
!= NULL
&& abs(ai
->xindex
) > maxDeleted
)
4689 aicons_to_shift
[n
++] = ai
;
4691 assert(n
== maxRemaining
- maxDeleted
); // for the code review ;-)
4692 wSlideAppicons(aicons_to_shift
, n
, !drawer
->on_right_side
);
4693 // Efficient beancounting
4701 /* similar to wDockRestoreState, but a lot a specific stuff too... */
4702 static WDock
* drawerRestoreState(WScreen
*scr
, WMPropList
*drawer_state
)
4705 WMPropList
*apps
, *value
, *dock_state
;
4714 WMRetainPropList(drawer_state
);
4716 /* Get the instance name, and create a drawer */
4717 value
= WMGetFromPLDictionary(drawer_state
, dName
);
4718 drawer
= wDockCreate(scr
, WM_DRAWER
, WMGetFromPLString(value
));
4720 /* restore DnD command and paste command */
4722 value
= WMGetFromPLDictionary(drawer_state
, dDropCommand
);
4723 if (value
&& WMIsPLString(value
))
4724 drawer
->icon_array
[0]->dnd_command
= wstrdup(WMGetFromPLString(value
));
4727 value
= WMGetFromPLDictionary(drawer_state
, dPasteCommand
);
4728 if (value
&& WMIsPLString(value
))
4729 drawer
->icon_array
[0]->paste_command
= wstrdup(WMGetFromPLString(value
));
4731 /* restore position */
4732 value
= WMGetFromPLDictionary(drawer_state
, dPosition
);
4733 if (!value
|| !WMIsPLString(value
))
4734 COMPLAIN("Position");
4737 if (sscanf(WMGetFromPLString(value
), "%i,%i", &x
, &y
) != 2)
4738 COMPLAIN("Position");
4740 /* check position sanity */
4741 if (x
!= scr
->dock
->x_pos
) {
4742 x
= scr
->dock
->x_pos
;
4744 y_index
= (y
- scr
->dock
->y_pos
) / ICON_SIZE
;
4745 if (y_index
>= scr
->dock
->max_icons
) {
4746 /* Here we should do something more intelligent, since it
4747 * can happen even if the user hasn't hand-edited his
4748 * G/D/State file (but uses a lower resolution). */
4749 y_index
= scr
->dock
->max_icons
- 1;
4751 y
= scr
->dock
->y_pos
+ y_index
* ICON_SIZE
;
4752 moveDock(drawer
, x
, y
);
4755 /* restore dock properties (applist and others) */
4756 dock_state
= WMGetFromPLDictionary(drawer_state
, dDock
);
4758 /* restore lowered/raised state: same as scr->dock, no matter what */
4759 drawer
->lowered
= scr
->dock
->lowered
;
4760 if (!drawer
->lowered
)
4761 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMDockLevel
);
4763 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMNormalLevel
);
4764 wRaiseFrame(drawer
->icon_array
[0]->icon
->core
);
4766 /* restore collapsed state */
4767 drawer
->collapsed
= 0;
4768 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
4769 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4770 drawer
->collapsed
= 1;
4772 /* restore auto-collapsed state */
4773 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
4774 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4775 drawer
->auto_collapse
= 1;
4776 drawer
->collapsed
= 1;
4778 drawer
->auto_collapse
= 0; // because wDockCreate sets it (drawers only)
4781 /* restore auto-raise/lower state: same as scr->dock, no matter what */
4782 drawer
->auto_raise_lower
= scr
->dock
->auto_raise_lower
;
4784 /* restore attract icons state */
4785 drawer
->attract_icons
= 0;
4786 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
4787 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4788 drawer
->attract_icons
= 1;
4789 scr
->attracting_drawer
= drawer
;
4792 /* application list */
4793 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
4799 count
= WMGetPropListItemCount(apps
);
4804 for (i
=0; i
<count
; i
++) {
4805 if (drawer
->icon_count
>= drawer
->max_icons
) {
4806 wwarning(_("there are too many icons stored in drawer. Ignoring what doesn't fit"));
4810 value
= WMGetFromPLArray(apps
, i
);
4811 aicon
= restore_icon_state(scr
, value
, WM_DRAWER
, drawer
->icon_count
);
4813 drawer
->icon_array
[drawer
->icon_count
] = aicon
;
4816 aicon
->dock
= drawer
;
4817 aicon
->x_pos
= drawer
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
4818 aicon
->y_pos
= drawer
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
4820 if (!drawer
->lowered
)
4821 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
4823 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
4825 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
4827 if (!drawer
->collapsed
)
4828 XMapWindow(dpy
, aicon
->icon
->core
->window
);
4829 wRaiseFrame(aicon
->icon
->core
);
4831 drawer
->icon_count
++;
4836 WMReleasePropList(drawer_state
);
4842 /* Same kind of comment than for previous function: this function is
4843 * very similar to make_icon_state, but has substential differences as
4845 static WMPropList
*drawerSaveState(WScreen
*scr
, WDock
*drawer
)
4847 WMPropList
*pstr
, *drawer_state
;
4851 ai
= drawer
->icon_array
[0];
4852 /* Store its name */
4853 pstr
= WMCreatePLString(ai
->wm_instance
);
4854 drawer_state
= WMCreatePLDictionary(dName
, pstr
, NULL
); /* we need this final NULL */
4855 WMReleasePropList(pstr
);
4857 /* Store its position */
4858 snprintf(buffer
, sizeof(buffer
), "%i,%i", ai
->x_pos
, ai
->y_pos
);
4859 pstr
= WMCreatePLString(buffer
);
4860 WMPutInPLDictionary(drawer_state
, dPosition
, pstr
);
4861 WMReleasePropList(pstr
);
4864 /* Store its DnD command */
4865 if (ai
->dnd_command
) {
4866 pstr
= WMCreatePLString(ai
->dnd_command
);
4867 WMPutInPLDictionary(drawer_state
, dDropCommand
, pstr
);
4868 WMReleasePropList(pstr
);
4872 /* Store its paste command */
4873 if (ai
->paste_command
) {
4874 pstr
= WMCreatePLString(ai
->paste_command
);
4875 WMPutInPLDictionary(drawer_state
, dPasteCommand
, pstr
);
4876 WMReleasePropList(pstr
);
4879 /* Store applications list and other properties */
4880 pstr
= dockSaveState(drawer
);
4881 WMPutInPLDictionary(drawer_state
, dDock
, pstr
);
4882 WMReleasePropList(pstr
);
4884 return drawer_state
;
4888 void wDrawersSaveState(WScreen
*scr
)
4890 WMPropList
*all_drawers
, *drawer_state
;
4896 all_drawers
= WMCreatePLArray(NULL
);
4897 for (i
=0, dc
= scr
->drawers
;
4898 i
< scr
->drawer_count
;
4899 i
++, dc
= dc
->next
) {
4900 drawer_state
= drawerSaveState(scr
, dc
->adrawer
);
4901 WMAddToPLArray(all_drawers
, drawer_state
);
4902 WMReleasePropList(drawer_state
);
4904 WMPutInPLDictionary(scr
->session_state
, dDrawers
, all_drawers
);
4905 WMReleasePropList(all_drawers
);
4909 void wDrawersRestoreState(WScreen
*scr
)
4911 WMPropList
*all_drawers
, *drawer_state
;
4916 if (scr
->session_state
== NULL
)
4919 all_drawers
= WMGetFromPLDictionary(scr
->session_state
, dDrawers
);
4923 for (i
= 0; i
< WMGetPropListItemCount(all_drawers
); i
++) {
4924 drawer_state
= WMGetFromPLArray(all_drawers
, i
);
4925 drawerRestoreState(scr
, drawer_state
);
4926 // Note: scr->drawers was updated when the the drawer was created