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>
37 #define PATH_MAX DEFAULT_PATH_MAX
40 #include "WindowMaker.h"
48 #include "dockedapp.h"
51 #include "properties.h"
55 #include "workspace.h"
57 #include "superfluous.h"
59 #include "placement.h"
63 /**** Local variables ****/
66 #define CLIP_FORWARD 2
68 #define MOD_MASK wPreferences.modifier_mask
69 #define ICON_SIZE wPreferences.icon_size
71 /***** Local variables ****/
73 static WMPropList
*dCommand
= NULL
;
74 static WMPropList
*dPasteCommand
= NULL
;
76 static WMPropList
*dDropCommand
= NULL
;
78 static WMPropList
*dAutoLaunch
, *dLock
;
79 static WMPropList
*dName
, *dForced
, *dBuggyApplication
, *dYes
, *dNo
;
80 static WMPropList
*dHost
, *dDock
, *dClip
;
81 static WMPropList
*dAutoAttractIcons
;
83 static WMPropList
*dPosition
, *dApplications
, *dLowered
, *dCollapsed
;
85 static WMPropList
*dAutoCollapse
, *dAutoRaiseLower
, *dOmnipresent
;
87 static WMPropList
*dDrawers
= NULL
;
89 static void dockIconPaint(WAppIcon
*btn
);
91 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
93 static pid_t
execCommand(WAppIcon
*btn
, const char *command
, WSavedState
*state
);
95 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
97 static int getClipButton(int px
, int py
);
99 static void toggleLowered(WDock
*dock
);
101 static void toggleCollapsed(WDock
*dock
);
103 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
105 static void clipLeave(WDock
*dock
);
107 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
109 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
110 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
111 static void clipAutoCollapse(void *cdata
);
112 static void clipAutoExpand(void *cdata
);
113 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
);
115 static void clipAutoLower(void *cdata
);
116 static void clipAutoRaise(void *cdata
);
117 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
, const char *name
);
119 static void drawerIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
120 static void removeDrawerCallback(WMenu
*menu
, WMenuEntry
*entry
);
121 static void drawerAppendToChain(WScreen
*scr
, WDock
*drawer
);
122 static char *findUniqueName(WScreen
*scr
, const char *instance_basename
);
123 static void addADrawerCallback(WMenu
*menu
, WMenuEntry
*entry
);
124 static void swapDrawers(WScreen
*scr
, int new_x
);
125 static WDock
* getDrawer(WScreen
*scr
, int y_index
);
126 static int indexOfHole(WDock
*drawer
, WAppIcon
*moving_aicon
, int redocking
);
127 static void drawerConsolidateIcons(WDock
*drawer
);
129 static int onScreen(WScreen
*scr
, int x
, int y
);
131 static void make_keys(void)
133 if (dCommand
!= NULL
)
136 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
137 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
139 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
141 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
142 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
143 dName
= WMRetainPropList(WMCreatePLString("Name"));
144 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
145 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
146 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
147 dNo
= WMRetainPropList(WMCreatePLString("No"));
148 dHost
= WMRetainPropList(WMCreatePLString("Host"));
150 dPosition
= WMCreatePLString("Position");
151 dApplications
= WMCreatePLString("Applications");
152 dLowered
= WMCreatePLString("Lowered");
153 dCollapsed
= WMCreatePLString("Collapsed");
154 dAutoCollapse
= WMCreatePLString("AutoCollapse");
155 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
156 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
158 dOmnipresent
= WMCreatePLString("Omnipresent");
160 dDock
= WMCreatePLString("Dock");
161 dClip
= WMCreatePLString("Clip");
162 dDrawers
= WMCreatePLString("Drawers");
165 static void renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
167 WDock
*dock
= entry
->clientdata
;
172 /* Parameter not used, but tell the compiler that it is ok */
175 assert(entry
->clientdata
!= NULL
);
177 wspace
= dock
->screen_ptr
->current_workspace
;
179 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
181 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+ 1);
182 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
, &name
))
183 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
188 static void toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
190 assert(entry
->clientdata
!= NULL
);
192 toggleLowered(entry
->clientdata
);
194 entry
->flags
.indicator_on
= !(((WDock
*) entry
->clientdata
)->lowered
);
199 static int matchWindow(const void *item
, const void *cdata
)
201 return (((WFakeGroupLeader
*) item
)->leader
== (Window
) cdata
);
204 static void killCallback(WMenu
*menu
, WMenuEntry
*entry
)
206 WScreen
*scr
= menu
->menu
->screen_ptr
;
208 WFakeGroupLeader
*fPtr
;
209 char *buffer
, *shortname
, **argv
;
212 if (!WCHECK_STATE(WSTATE_NORMAL
))
215 assert(entry
->clientdata
!= NULL
);
217 icon
= (WAppIcon
*) entry
->clientdata
;
221 WCHANGE_STATE(WSTATE_MODAL
);
223 /* strip away dir names */
224 shortname
= basename(icon
->command
);
225 /* separate out command options */
226 wtokensplit(shortname
, &argv
, &argc
);
228 buffer
= wstrconcat(argv
[0],
229 _(" will be forcibly closed.\n"
230 "Any unsaved changes will be lost.\n" "Please confirm."));
232 if (icon
->icon
&& icon
->icon
->owner
) {
233 fPtr
= icon
->icon
->owner
->fake_group
;
235 /* is this really necessary? can we kill a non-running dock icon? */
236 Window win
= icon
->main_window
;
239 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)win
);
240 if (index
!= WANotFound
)
241 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
246 if (wPreferences
.dont_confirm_kill
247 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
248 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
250 WWindow
*wwin
, *twin
;
252 wwin
= scr
->focused_window
;
255 if (wwin
->fake_group
== fPtr
)
260 } else if (icon
->icon
&& icon
->icon
->owner
) {
261 wClientKill(icon
->icon
->owner
);
266 wtokenfree(argv
, argc
);
270 WCHANGE_STATE(WSTATE_NORMAL
);
273 /* TODO: replace this function with a member of the dock struct */
274 static int numberOfSelectedIcons(WDock
*dock
)
280 for (i
= 1; i
< dock
->max_icons
; i
++) {
281 aicon
= dock
->icon_array
[i
];
282 if (aicon
&& aicon
->icon
->selected
)
289 static WMArray
*getSelected(WDock
*dock
)
291 WMArray
*ret
= WMCreateArray(8);
295 for (i
= 1; i
< dock
->max_icons
; i
++) {
296 btn
= dock
->icon_array
[i
];
297 if (btn
&& btn
->icon
->selected
)
298 WMAddToArray(ret
, btn
);
304 static void paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
306 Window win
= clipIcon
->icon
->core
->window
;
307 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
309 int pt
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
310 int tp
= ICON_SIZE
- pt
;
311 int as
= pt
- 15; /* 15 = 5+5+5 */
312 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
315 color
= scr
->clip_title_color
[CLIP_NORMAL
];
317 XSetForeground(dpy
, gc
, WMColorPixel(color
));
322 p
[1].x
= ICON_SIZE
- 2;
324 p
[2].x
= ICON_SIZE
- 2;
326 } else if (lpushed
) {
330 p
[1].y
= ICON_SIZE
- 2;
332 p
[2].y
= ICON_SIZE
- 2;
334 if (lpushed
|| rpushed
) {
335 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
336 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
337 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
340 /* top right arrow */
341 p
[0].x
= p
[3].x
= ICON_SIZE
- 5 - as
;
343 p
[1].x
= ICON_SIZE
- 6;
345 p
[2].x
= ICON_SIZE
- 6;
348 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
349 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
351 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
352 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
355 /* bottom left arrow */
357 p
[0].y
= p
[3].y
= ICON_SIZE
- 5 - as
;
359 p
[1].y
= ICON_SIZE
- 6;
361 p
[2].y
= ICON_SIZE
- 6;
363 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
364 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
366 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
367 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
371 RImage
*wClipMakeTile(RImage
*normalTile
)
373 RImage
*tile
= RCloneImage(normalTile
);
380 pt
= CLIP_BUTTON_SIZE
* wPreferences
.icon_size
/ 64;
381 tp
= wPreferences
.icon_size
- 1 - pt
;
385 black
.red
= black
.green
= black
.blue
= 0;
388 dark
.red
= dark
.green
= dark
.blue
= 60;
391 light
.red
= light
.green
= light
.blue
= 80;
394 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
- 2, pt
- 1, &dark
);
395 RDrawLine(tile
, tp
- 1, 0, wPreferences
.icon_size
- 1, pt
+ 1, &black
);
396 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
- 3, pt
, &light
);
399 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, 4, &dark
);
400 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 5, 6 + as
, &dark
);
401 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
, &light
);
404 ROperateLine(tile
, RAddOperation
, 2, tp
+ 2, pt
- 2, wPreferences
.icon_size
- 3, &dark
);
405 RDrawLine(tile
, 0, tp
- 1, pt
+ 1, wPreferences
.icon_size
- 1, &black
);
406 ROperateLine(tile
, RSubtractOperation
, 0, tp
- 2, pt
+ 1, wPreferences
.icon_size
- 2, &light
);
409 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, &dark
);
410 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
, 6 + as
, ICON_SIZE
- 5, &dark
);
411 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5, &light
);
416 static void omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
418 WAppIcon
*clickedIcon
= entry
->clientdata
;
421 WMArray
*selectedIcons
;
422 WMArrayIterator iter
;
425 /* Parameter not used, but tell the compiler that it is ok */
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 /* Parameter not used, but tell the compiler that it is ok */
496 assert(clickedIcon
!= NULL
);
498 dock
= clickedIcon
->dock
;
500 selectedIcons
= getSelected(dock
);
502 if (WMGetArrayItemCount(selectedIcons
)) {
503 if (wMessageDialog(dock
->screen_ptr
,
504 dock
->type
== WM_CLIP
? _("Workspace Clip") : _("Drawer"),
505 _("All selected icons will be removed!"),
506 _("OK"), _("Cancel"), NULL
) != WAPRDefault
) {
507 WMFreeArray(selectedIcons
);
511 if (clickedIcon
->xindex
== 0 && clickedIcon
->yindex
== 0) {
512 WMFreeArray(selectedIcons
);
515 WMAddToArray(selectedIcons
, clickedIcon
);
518 removeIcons(selectedIcons
, dock
);
520 if (dock
->type
== WM_DRAWER
) {
521 drawerConsolidateIcons(dock
);
525 static void keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
527 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
530 WMArray
*selectedIcons
;
533 /* Parameter not used, but tell the compiler that it is ok */
536 assert(clickedIcon
!= NULL
);
537 dock
= clickedIcon
->dock
;
539 selectedIcons
= getSelected(dock
);
541 if (!WMGetArrayItemCount(selectedIcons
)
542 && clickedIcon
!= dock
->screen_ptr
->clip_icon
) {
543 char *command
= NULL
;
545 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
546 clickedIcon
->editing
= 1;
547 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
548 _("Type the command used to launch the application"), &command
)) {
549 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
553 clickedIcon
->command
= command
;
554 clickedIcon
->editing
= 0;
556 clickedIcon
->editing
= 0;
559 WMFreeArray(selectedIcons
);
564 WMAddToArray(selectedIcons
, clickedIcon
);
567 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
568 if (aicon
->icon
->selected
)
569 wIconSelect(aicon
->icon
);
571 if (aicon
->attracted
&& aicon
->command
) {
572 aicon
->attracted
= 0;
573 if (aicon
->icon
->shadowed
) {
574 aicon
->icon
->shadowed
= 0;
577 * Update icon pixmap, RImage doesn't change,
578 * so call wIconUpdate is not needed
580 update_icon_pixmap(aicon
->icon
);
583 wAppIconPaint(aicon
);
588 WMFreeArray(selectedIcons
);
591 static void toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
593 WDock
*dock
= (WDock
*) entry
->clientdata
;
594 WScreen
*scr
= dock
->screen_ptr
;
596 assert(entry
->clientdata
!= NULL
);
598 dock
->attract_icons
= !dock
->attract_icons
;
600 entry
->flags
.indicator_on
= dock
->attract_icons
;
604 if (dock
->attract_icons
) {
605 if (dock
->type
== WM_DRAWER
) {
606 /* The newly auto-attracting dock is a drawer: disable any clip and
607 * previously attracting drawer */
609 if (!wPreferences
.flags
.noclip
) {
611 for (i
= 0; i
< scr
->workspace_count
; i
++)
612 scr
->workspaces
[ i
]->clip
->attract_icons
= False
;
613 /* dock menu will be updated later, when opened */
616 if (scr
->attracting_drawer
!= NULL
)
617 scr
->attracting_drawer
->attract_icons
= False
;
618 scr
->attracting_drawer
= dock
;
620 /* The newly auto-attracting dock is a clip: disable
621 * previously attracting drawer, if applicable */
622 if (scr
->attracting_drawer
!= NULL
) {
623 scr
->attracting_drawer
->attract_icons
= False
;
624 /* again, its menu will be updated, later. */
625 scr
->attracting_drawer
= NULL
;
631 static void selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
633 WAppIcon
*icon
= (WAppIcon
*) entry
->clientdata
;
635 assert(icon
!= NULL
);
637 wIconSelect(icon
->icon
);
642 static void attractIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
644 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
645 WDock
*clip
; /* clip... is a WM_CLIP or a WM_DRAWER */
647 int x
, y
, x_pos
, y_pos
;
648 Bool update_icon
= False
;
650 /* Parameter not used, but tell the compiler that it is ok */
653 assert(entry
->clientdata
!= NULL
);
654 clip
= clickedIcon
->dock
;
656 aicon
= clip
->screen_ptr
->app_icon_list
;
659 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
660 x_pos
= clip
->x_pos
+ x
* ICON_SIZE
;
661 y_pos
= clip
->y_pos
+ y
* ICON_SIZE
;
662 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
)
663 move_window(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
665 aicon
->attracted
= 1;
666 if (!aicon
->icon
->shadowed
) {
667 aicon
->icon
->shadowed
= 1;
670 wDockAttachIcon(clip
, aicon
, x
, y
, update_icon
);
671 if (clip
->collapsed
|| !clip
->mapped
)
672 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
678 static void selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
680 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
682 WMArray
*selectedIcons
;
683 WMArrayIterator iter
;
687 assert(clickedIcon
!= NULL
);
688 dock
= clickedIcon
->dock
;
690 selectedIcons
= getSelected(dock
);
692 if (!WMGetArrayItemCount(selectedIcons
)) {
693 for (i
= 1; i
< dock
->max_icons
; i
++) {
694 btn
= dock
->icon_array
[i
];
695 if (btn
&& !btn
->icon
->selected
)
696 wIconSelect(btn
->icon
);
699 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
700 wIconSelect(btn
->icon
);
703 WMFreeArray(selectedIcons
);
708 static void toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
710 assert(entry
->clientdata
!= NULL
);
712 toggleCollapsed(entry
->clientdata
);
714 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->collapsed
;
719 static void toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
722 assert(entry
->clientdata
!= NULL
);
724 dock
= (WDock
*) entry
->clientdata
;
726 dock
->auto_collapse
= !dock
->auto_collapse
;
728 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_collapse
;
733 static void toggleAutoRaiseLower(WDock
*dock
)
737 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
738 if (dock
->type
== WM_DOCK
)
740 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
741 toggleAutoRaiseLower(dc
->adrawer
);
746 static void toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
750 /* Parameter not used, but tell the compiler that it is ok */
753 assert(entry
->clientdata
!= NULL
);
755 dock
= (WDock
*) entry
->clientdata
;
757 toggleAutoRaiseLower(dock
);
759 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_raise_lower
;
764 static void launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
766 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
768 /* Parameter not used, but tell the compiler that it is ok */
771 launchDockedApplication(btn
, False
);
774 static void settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
776 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
778 /* Parameter not used, but tell the compiler that it is ok */
783 ShowDockAppSettingsPanel(btn
);
786 static void hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
789 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
791 /* Parameter not used, but tell the compiler that it is ok */
794 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
796 if (wapp
->flags
.hidden
) {
797 wWorkspaceChange(btn
->icon
->core
->screen_ptr
, wapp
->last_workspace
);
798 wUnhideApplication(wapp
, False
, False
);
800 wHideApplication(wapp
);
804 static void unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
807 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
809 /* Parameter not used, but tell the compiler that it is ok */
812 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
814 wUnhideApplication(wapp
, False
, True
);
817 /* Name is only used when type == WM_DRAWER and when restoring a specific
818 * drawer, with a specific name. When creating a drawer, leave name to NULL
819 * and mainIconCreate will find the first unused unique name */
820 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
, const char *name
)
828 return scr
->clip_icon
;
830 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
831 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
835 default: /* to avoid a warning about btn and x_pos, basically */
836 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
837 if (wPreferences
.flags
.clip_merged_in_dock
)
838 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
839 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
843 name
= findUniqueName(scr
, "Drawer");
844 btn
= wAppIconCreateForDock(scr
, NULL
, name
, "WMDrawer", TILE_DRAWER
);
845 btn
->icon
->core
->descriptor
.handle_expose
= drawerIconExpose
;
852 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
853 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
854 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
855 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
856 btn
->icon
->core
->descriptor
.parent
= btn
;
857 XMapWindow(dpy
, btn
->icon
->core
->window
);
861 if (type
== WM_CLIP
||
862 (type
== WM_DOCK
&& wPreferences
.flags
.clip_merged_in_dock
))
863 scr
->clip_icon
= btn
;
868 static void switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
870 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
871 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
873 WMArray
*selectedIcons
;
876 /* Parameter not used, but tell the compiler that it is ok */
879 if (entry
->order
== scr
->current_workspace
)
883 dest
= scr
->workspaces
[entry
->order
]->clip
;
885 selectedIcons
= getSelected(src
);
887 if (WMGetArrayItemCount(selectedIcons
)) {
888 WMArrayIterator iter
;
890 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
891 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
892 wDockMoveIconBetweenDocks(src
, dest
, btn
, x
, y
);
893 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
896 } else if (icon
!= scr
->clip_icon
) {
897 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
898 wDockMoveIconBetweenDocks(src
, dest
, icon
, x
, y
);
899 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
902 WMFreeArray(selectedIcons
);
905 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
)
907 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
909 if (!btn
->launching
&&
910 ((!withSelection
&& btn
->command
!= NULL
) || (withSelection
&& btn
->paste_command
!= NULL
))) {
911 if (!btn
->forced_dock
) {
912 btn
->relaunching
= btn
->running
;
915 if (btn
->wm_instance
|| btn
->wm_class
) {
916 WWindowAttributes attr
;
917 memset(&attr
, 0, sizeof(WWindowAttributes
));
918 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
920 if (!attr
.no_appicon
&& !btn
->buggy_app
)
925 btn
->drop_launch
= 0;
926 btn
->paste_launch
= withSelection
;
927 scr
->last_dock
= btn
->dock
;
928 btn
->pid
= execCommand(btn
, (withSelection
? btn
->paste_command
: btn
->command
), NULL
);
930 if (btn
->buggy_app
) {
931 /* give feedback that the app was launched */
935 WMAddTimerHandler(200, (WMCallback
*) dockIconPaint
, btn
);
940 wwarning(_("could not launch application %s"), btn
->command
);
942 if (!btn
->relaunching
)
948 static void updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
950 WScreen
*scr
= menu
->frame
->screen_ptr
;
956 for (i
= 0; i
< scr
->workspace_count
; i
++) {
957 if (i
< menu
->entry_no
) {
958 if (strcmp(menu
->entries
[i
]->text
, scr
->workspaces
[i
]->name
) != 0) {
959 wfree(menu
->entries
[i
]->text
);
960 menu
->entries
[i
]->text
= wstrdup(scr
->workspaces
[i
]->name
);
961 menu
->flags
.realized
= 0;
963 menu
->entries
[i
]->clientdata
= (void *)icon
;
965 wMenuAddCallback(menu
, scr
->workspaces
[i
]->name
, switchWSCommand
, (void *)icon
);
967 menu
->flags
.realized
= 0;
970 if (i
== scr
->current_workspace
)
971 wMenuSetEnabled(menu
, i
, False
);
973 wMenuSetEnabled(menu
, i
, True
);
976 if (!menu
->flags
.realized
)
980 static WMenu
*makeWorkspaceMenu(WScreen
*scr
)
984 menu
= wMenuCreate(scr
, NULL
, False
);
986 wwarning(_("could not create workspace submenu for Clip menu"));
988 wMenuAddCallback(menu
, "", switchWSCommand
, (void *)scr
->clip_icon
);
990 menu
->flags
.realized
= 0;
996 static void updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
1005 entry
= menu
->entries
[index
];
1006 entry
->flags
.indicator_on
= !dock
->lowered
;
1007 entry
->clientdata
= dock
;
1008 wMenuSetEnabled(menu
, index
, dock
->type
== WM_CLIP
);
1011 entry
= menu
->entries
[++index
];
1012 entry
->flags
.indicator_on
= dock
->collapsed
;
1013 entry
->clientdata
= dock
;
1016 entry
= menu
->entries
[++index
];
1017 entry
->flags
.indicator_on
= dock
->auto_collapse
;
1018 entry
->clientdata
= dock
;
1020 /* auto-raise/lower */
1021 entry
= menu
->entries
[++index
];
1022 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1023 entry
->clientdata
= dock
;
1024 wMenuSetEnabled(menu
, index
, dock
->lowered
&& (dock
->type
== WM_CLIP
));
1027 entry
= menu
->entries
[++index
];
1028 entry
->flags
.indicator_on
= dock
->attract_icons
;
1029 entry
->clientdata
= dock
;
1031 menu
->flags
.realized
= 0;
1036 static WMenu
*makeClipOptionsMenu(WScreen
*scr
)
1041 menu
= wMenuCreate(scr
, NULL
, False
);
1043 wwarning(_("could not create options submenu for Clip menu"));
1047 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
1048 entry
->flags
.indicator
= 1;
1049 entry
->flags
.indicator_on
= 1;
1050 entry
->flags
.indicator_type
= MI_CHECK
;
1052 entry
= wMenuAddCallback(menu
, _("Collapsed"), toggleCollapsedCallback
, NULL
);
1053 entry
->flags
.indicator
= 1;
1054 entry
->flags
.indicator_on
= 1;
1055 entry
->flags
.indicator_type
= MI_CHECK
;
1057 entry
= wMenuAddCallback(menu
, _("Autocollapse"), toggleAutoCollapseCallback
, NULL
);
1058 entry
->flags
.indicator
= 1;
1059 entry
->flags
.indicator_on
= 1;
1060 entry
->flags
.indicator_type
= MI_CHECK
;
1062 entry
= wMenuAddCallback(menu
, _("Autoraise"), toggleAutoRaiseLowerCallback
, NULL
);
1063 entry
->flags
.indicator
= 1;
1064 entry
->flags
.indicator_on
= 1;
1065 entry
->flags
.indicator_type
= MI_CHECK
;
1067 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"), toggleAutoAttractCallback
, NULL
);
1068 entry
->flags
.indicator
= 1;
1069 entry
->flags
.indicator_on
= 1;
1070 entry
->flags
.indicator_type
= MI_CHECK
;
1072 menu
->flags
.realized
= 0;
1079 static void setDockPositionNormalCallback(WMenu
*menu
, WMenuEntry
*entry
)
1081 WDock
*dock
= (WDock
*) entry
->clientdata
;
1084 /* Parameter not used, but tell the compiler that it is ok */
1087 if (entry
->flags
.indicator_on
) // already set, nothing to do
1089 // Do we come from auto raise lower or keep on top?
1090 if (dock
->auto_raise_lower
)
1092 dock
->auto_raise_lower
= 0;
1093 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1094 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1095 dc
->adrawer
->auto_raise_lower
= 0;
1100 // Will take care of setting lowered = 0 in drawers
1101 toggleLowered(dock
);
1103 entry
->flags
.indicator_on
= 1;
1106 static void setDockPositionAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
1108 WDock
*dock
= (WDock
*) entry
->clientdata
;
1111 /* Parameter not used, but tell the compiler that it is ok */
1114 if (entry
->flags
.indicator_on
) // already set, nothing to do
1116 // Do we come from normal or keep on top?
1119 toggleLowered(dock
);
1121 dock
->auto_raise_lower
= 1;
1122 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1123 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1124 dc
->adrawer
->auto_raise_lower
= 1;
1126 entry
->flags
.indicator_on
= 1;
1129 static void setDockPositionKeepOnTopCallback(WMenu
*menu
, WMenuEntry
*entry
)
1131 WDock
*dock
= (WDock
*) entry
->clientdata
;
1134 /* Parameter not used, but tell the compiler that it is ok */
1137 if (entry
->flags
.indicator_on
) // already set, nothing to do
1139 dock
->auto_raise_lower
= 0;
1140 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1141 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1142 dc
->adrawer
->auto_raise_lower
= 0;
1144 toggleLowered(dock
);
1145 entry
->flags
.indicator_on
= 1;
1148 static void updateDockPositionMenu(WMenu
*menu
, WDock
*dock
)
1157 entry
= menu
->entries
[index
++];
1158 entry
->flags
.indicator_on
= (dock
->lowered
&& !dock
->auto_raise_lower
);
1159 entry
->clientdata
= dock
;
1161 /* Auto-raise/lower */
1162 entry
= menu
->entries
[index
++];
1163 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1164 entry
->clientdata
= dock
;
1167 entry
= menu
->entries
[index
++];
1168 entry
->flags
.indicator_on
= !dock
->lowered
;
1169 entry
->clientdata
= dock
;
1172 static WMenu
*makeDockPositionMenu(WScreen
*scr
)
1174 /* When calling this, the dock is being created, so scr->dock is still not set
1175 * Therefore the callbacks' clientdata and the indicators can't be set,
1176 * they will be updated when the dock menu is opened. */
1180 menu
= wMenuCreate(scr
, NULL
, False
);
1182 wwarning(_("could not create options submenu for dock position menu"));
1186 entry
= wMenuAddCallback(menu
, _("Normal"), setDockPositionNormalCallback
, NULL
);
1187 entry
->flags
.indicator
= 1;
1188 entry
->flags
.indicator_type
= MI_DIAMOND
;
1190 entry
= wMenuAddCallback(menu
, _("Auto raise & lower"), setDockPositionAutoRaiseLowerCallback
, NULL
);
1191 entry
->flags
.indicator
= 1;
1192 entry
->flags
.indicator_type
= MI_DIAMOND
;
1194 entry
= wMenuAddCallback(menu
, _("Keep on Top"), setDockPositionKeepOnTopCallback
, NULL
);
1195 entry
->flags
.indicator
= 1;
1196 entry
->flags
.indicator_type
= MI_DIAMOND
;
1198 menu
->flags
.realized
= 0;
1205 static WMenu
*dockMenuCreate(WScreen
*scr
, int type
)
1210 if (type
== WM_CLIP
&& scr
->clip_menu
)
1211 return scr
->clip_menu
;
1213 if (type
== WM_DRAWER
&& scr
->drawer_menu
)
1214 return scr
->drawer_menu
;
1216 menu
= wMenuCreate(scr
, NULL
, False
);
1217 if (type
== WM_DOCK
) {
1218 entry
= wMenuAddCallback(menu
, _("Dock position"), NULL
, NULL
);
1219 if (scr
->dock_pos_menu
== NULL
)
1220 scr
->dock_pos_menu
= makeDockPositionMenu(scr
);
1221 wMenuEntrySetCascade(menu
, entry
, scr
->dock_pos_menu
);
1223 if (!wPreferences
.flags
.nodrawer
)
1224 wMenuAddCallback(menu
, _("Add a drawer"), addADrawerCallback
, NULL
);
1227 if (type
== WM_CLIP
)
1228 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1229 else /* if (type == WM_DRAWER) */
1230 entry
= wMenuAddCallback(menu
, _("Drawer options"), NULL
, NULL
);
1232 if (scr
->clip_options
== NULL
)
1233 scr
->clip_options
= makeClipOptionsMenu(scr
);
1235 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1237 /* The same menu is used for the dock and its appicons. If the menu
1238 * entry text is different between the two contexts, or if it can
1239 * change depending on some state, free the duplicated string (from
1240 * wMenuInsertCallback) and use gettext's string */
1241 if (type
== WM_CLIP
) {
1242 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1244 entry
->text
= _("Rename Workspace"); /* can be: (Toggle) Omnipresent */
1247 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1248 entry
->flags
.indicator
= 1;
1249 entry
->flags
.indicator_on
= 1;
1250 entry
->flags
.indicator_type
= MI_CHECK
;
1252 entry
= wMenuAddCallback(menu
, _("Select All Icons"), selectIconsCallback
, NULL
);
1254 entry
->text
= _("Select All Icons"); /* can be: Unselect all icons */
1256 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1258 entry
->text
= _("Keep Icon"); /* can be: Keep Icons */
1260 if (type
== WM_CLIP
) {
1261 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1263 entry
->text
= _("Move Icon To"); /* can be: Move Icons to */
1264 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1265 if (scr
->clip_submenu
)
1266 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1269 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
, NULL
);
1271 entry
->text
= _("Remove Icon"); /* can be: Remove Icons */
1273 wMenuAddCallback(menu
, _("Attract Icons"), attractIconsCallback
, NULL
);
1276 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1278 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1280 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1282 entry
->text
= _("Hide"); /* can be: Unhide */
1284 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1286 entry
= wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1288 entry
->text
= _("Kill"); /* can be: Remove drawer */
1290 if (type
== WM_CLIP
)
1291 scr
->clip_menu
= menu
;
1293 if (type
== WM_DRAWER
)
1294 scr
->drawer_menu
= menu
;
1299 WDock
*wDockCreate(WScreen
*scr
, int type
, const char *name
)
1306 dock
= wmalloc(sizeof(WDock
));
1310 dock
->max_icons
= DOCK_MAX_ICONS
;
1313 dock
->max_icons
= scr
->scr_width
/ wPreferences
.icon_size
;
1317 dock
->max_icons
= scr
->scr_height
/ wPreferences
.icon_size
;
1320 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * dock
->max_icons
);
1322 btn
= mainIconCreate(scr
, type
, name
);
1326 dock
->x_pos
= btn
->x_pos
;
1327 dock
->y_pos
= btn
->y_pos
;
1328 dock
->screen_ptr
= scr
;
1330 dock
->icon_count
= 1;
1331 if (type
== WM_DRAWER
)
1332 dock
->on_right_side
= scr
->dock
->on_right_side
;
1334 dock
->on_right_side
= 1;
1335 dock
->collapsed
= 0;
1336 dock
->auto_collapse
= 0;
1337 dock
->auto_collapse_magic
= NULL
;
1338 dock
->auto_raise_lower
= 0;
1339 dock
->auto_lower_magic
= NULL
;
1340 dock
->auto_raise_magic
= NULL
;
1341 dock
->attract_icons
= 0;
1343 dock
->icon_array
[0] = btn
;
1344 wRaiseFrame(btn
->icon
->core
);
1345 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1347 /* create dock menu */
1348 dock
->menu
= dockMenuCreate(scr
, type
);
1350 if (type
== WM_DRAWER
) {
1351 drawerAppendToChain(scr
, dock
);
1352 dock
->auto_collapse
= 1;
1358 void wDockDestroy(WDock
*dock
)
1363 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1364 aicon
= dock
->icon_array
[i
];
1366 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1367 wDockDetach(dock
, aicon
);
1369 /* XXX: can: aicon->icon == NULL ? */
1370 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1371 wGetHeadForWindow(aicon
->icon
->owner
));
1372 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1373 if (!dock
->mapped
|| dock
->collapsed
)
1374 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1378 if (wPreferences
.auto_arrange_icons
)
1379 wArrangeIcons(dock
->screen_ptr
, True
);
1380 wfree(dock
->icon_array
);
1381 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1382 wMenuDestroy(dock
->menu
, True
);
1383 if (dock
->screen_ptr
->last_dock
== dock
)
1384 dock
->screen_ptr
->last_dock
= NULL
;
1388 void wClipIconPaint(WAppIcon
*aicon
)
1390 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1391 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1393 Window win
= aicon
->icon
->core
->window
;
1394 int length
, nlength
;
1395 char *ws_name
, ws_number
[10];
1398 wIconPaint(aicon
->icon
);
1400 length
= strlen(workspace
->name
);
1401 ws_name
= wmalloc(length
+ 1);
1402 snprintf(ws_name
, length
+ 1, "%s", workspace
->name
);
1403 snprintf(ws_number
, sizeof(ws_number
), "%i", scr
->current_workspace
+ 1);
1404 nlength
= strlen(ws_number
);
1406 if (wPreferences
.flags
.noclip
|| !workspace
->clip
->collapsed
)
1407 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1409 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1411 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1413 tx
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
1415 if(wPreferences
.show_clip_title
)
1416 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, ty
, ws_name
, length
);
1418 tx
= (ICON_SIZE
/ 2 - WMWidthOfString(scr
->clip_title_font
, ws_number
, nlength
)) / 2;
1420 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, 2, ws_number
, nlength
);
1424 if (aicon
->launching
)
1425 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1426 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1428 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
, aicon
->dock
->rclip_button_pushed
);
1431 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1433 /* Parameter not used, but tell the compiler that it is ok */
1437 wClipIconPaint(desc
->parent
);
1440 static void dockIconPaint(WAppIcon
*btn
)
1442 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
) {
1443 wClipIconPaint(btn
);
1444 } else if (wIsADrawer(btn
)) {
1445 wDrawerIconPaint(btn
);
1452 static WMPropList
*make_icon_state(WAppIcon
*btn
)
1454 WMPropList
*node
= NULL
;
1455 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
;
1456 WMPropList
*position
, *buggy
, *omnipresent
;
1462 command
= WMCreatePLString("-");
1464 command
= WMCreatePLString(btn
->command
);
1466 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1468 lock
= btn
->lock
? dYes
: dNo
;
1470 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1472 name
= WMCreatePLString(tmp
);
1476 forced
= btn
->forced_dock
? dYes
: dNo
;
1478 buggy
= btn
->buggy_app
? dYes
: dNo
;
1480 if (!wPreferences
.flags
.clip_merged_in_dock
&& btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1481 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1483 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1484 position
= WMCreatePLString(buffer
);
1486 node
= WMCreatePLDictionary(dCommand
, command
,
1488 dAutoLaunch
, autolaunch
,
1490 dForced
, forced
, dBuggyApplication
, buggy
, dPosition
, position
, NULL
);
1491 WMReleasePropList(command
);
1492 WMReleasePropList(name
);
1493 WMReleasePropList(position
);
1495 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1496 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&& (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1497 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1499 #ifdef USE_DOCK_XDND
1500 if (btn
->dnd_command
) {
1501 command
= WMCreatePLString(btn
->dnd_command
);
1502 WMPutInPLDictionary(node
, dDropCommand
, command
);
1503 WMReleasePropList(command
);
1505 #endif /* USE_DOCK_XDND */
1507 if (btn
->paste_command
) {
1508 command
= WMCreatePLString(btn
->paste_command
);
1509 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1510 WMReleasePropList(command
);
1517 static WMPropList
*dockSaveState(WDock
*dock
)
1520 WMPropList
*icon_info
;
1521 WMPropList
*list
= NULL
, *dock_state
= NULL
;
1522 WMPropList
*value
, *key
;
1525 list
= WMCreatePLArray(NULL
);
1527 for (i
= (dock
->type
== WM_DOCK
? 0 : 1); i
< dock
->max_icons
; i
++) {
1528 WAppIcon
*btn
= dock
->icon_array
[i
];
1530 if (!btn
|| btn
->attracted
)
1533 icon_info
= make_icon_state(dock
->icon_array
[i
]);
1534 if (icon_info
!= NULL
) {
1535 WMAddToPLArray(list
, icon_info
);
1536 WMReleasePropList(icon_info
);
1540 dock_state
= WMCreatePLDictionary(dApplications
, list
, NULL
);
1542 if (dock
->type
== WM_DOCK
) {
1543 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1544 key
= WMCreatePLString(buffer
);
1545 WMPutInPLDictionary(dock_state
, key
, list
);
1546 WMReleasePropList(key
);
1548 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0), dock
->y_pos
);
1549 value
= WMCreatePLString(buffer
);
1550 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1551 WMReleasePropList(value
);
1553 WMReleasePropList(list
);
1555 if (dock
->type
== WM_CLIP
|| dock
->type
== WM_DRAWER
) {
1556 value
= (dock
->collapsed
? dYes
: dNo
);
1557 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1559 value
= (dock
->auto_collapse
? dYes
: dNo
);
1560 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1562 value
= (dock
->attract_icons
? dYes
: dNo
);
1563 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1566 if (dock
->type
== WM_DOCK
|| dock
->type
== WM_CLIP
) {
1567 value
= (dock
->lowered
? dYes
: dNo
);
1568 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1570 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1571 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1577 void wDockSaveState(WScreen
*scr
, WMPropList
*old_state
)
1579 WMPropList
*dock_state
;
1582 dock_state
= dockSaveState(scr
->dock
);
1585 * Copy saved states of docks with different sizes.
1591 keys
= WMGetPLDictionaryKeys(old_state
);
1592 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1593 tmp
= WMGetFromPLArray(keys
, i
);
1595 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1596 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1598 WMPutInPLDictionary(dock_state
, tmp
, WMGetFromPLDictionary(old_state
, tmp
));
1601 WMReleasePropList(keys
);
1604 WMPutInPLDictionary(scr
->session_state
, dDock
, dock_state
);
1606 WMReleasePropList(dock_state
);
1609 void wClipSaveState(WScreen
*scr
)
1611 WMPropList
*clip_state
;
1613 clip_state
= make_icon_state(scr
->clip_icon
);
1615 WMPutInPLDictionary(scr
->session_state
, dClip
, clip_state
);
1617 WMReleasePropList(clip_state
);
1620 WMPropList
*wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1622 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1625 static Bool
getBooleanDockValue(WMPropList
*value
, WMPropList
*key
)
1628 if (WMIsPLString(value
)) {
1629 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1632 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1638 static WAppIcon
*restore_icon_state(WScreen
*scr
, WMPropList
*info
, int type
, int index
)
1641 WMPropList
*cmd
, *value
;
1642 char *wclass
, *winstance
, *command
;
1644 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1645 if (!cmd
|| !WMIsPLString(cmd
))
1648 /* parse window name */
1649 value
= WMGetFromPLDictionary(info
, dName
);
1653 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1655 if (!winstance
&& !wclass
)
1659 command
= wstrdup(WMGetFromPLString(cmd
));
1661 if (strcmp(command
, "-") == 0) {
1672 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1680 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1681 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1682 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1683 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1684 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1686 #ifdef USE_DOCK_XDND
1687 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1689 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1692 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1694 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1696 /* check auto launch */
1697 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1699 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1702 value
= WMGetFromPLDictionary(info
, dLock
);
1704 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1706 /* check if it wasn't normally docked */
1707 value
= WMGetFromPLDictionary(info
, dForced
);
1709 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1711 /* check if we can rely on the stuff in the app */
1712 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1714 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1716 /* get position in the dock */
1717 value
= WMGetFromPLDictionary(info
, dPosition
);
1718 if (value
&& WMIsPLString(value
)) {
1719 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1720 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1722 /* check position sanity */
1723 /* *Very* incomplete section! */
1724 if (type
== WM_DOCK
) {
1728 aicon
->yindex
= index
;
1732 /* check if icon is omnipresent */
1733 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1735 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1743 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1745 WAppIcon
*wClipRestoreState(WScreen
*scr
, WMPropList
*clip_state
)
1750 icon
= mainIconCreate(scr
, WM_CLIP
, NULL
);
1755 WMRetainPropList(clip_state
);
1757 /* restore position */
1759 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1762 if (!WMIsPLString(value
)) {
1763 COMPLAIN("Position");
1765 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1766 COMPLAIN("Position");
1768 /* check position sanity */
1769 if (!onScreen(scr
, icon
->x_pos
, icon
->y_pos
))
1770 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1773 #ifdef USE_DOCK_XDND
1774 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1775 if (value
&& WMIsPLString(value
))
1776 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1779 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1780 if (value
&& WMIsPLString(value
))
1781 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1783 WMReleasePropList(clip_state
);
1788 WDock
*wDockRestoreState(WScreen
*scr
, WMPropList
*dock_state
, int type
)
1793 WAppIcon
*aicon
, *old_top
;
1796 dock
= wDockCreate(scr
, type
, NULL
);
1801 WMRetainPropList(dock_state
);
1803 /* restore position */
1804 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1806 if (!WMIsPLString(value
)) {
1807 COMPLAIN("Position");
1809 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1810 COMPLAIN("Position");
1812 /* check position sanity */
1813 if (!onScreen(scr
, dock
->x_pos
, dock
->y_pos
)) {
1814 int x
= dock
->x_pos
;
1815 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1818 /* Is this needed any more? */
1819 if (type
== WM_CLIP
) {
1820 if (dock
->x_pos
< 0) {
1822 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1823 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1826 if (dock
->x_pos
>= 0) {
1827 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1828 dock
->on_right_side
= 0;
1830 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1831 dock
->on_right_side
= 1;
1837 /* restore lowered/raised state */
1840 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1842 if (!WMIsPLString(value
)) {
1843 COMPLAIN("Lowered");
1845 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1850 /* restore collapsed state */
1851 dock
->collapsed
= 0;
1853 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1855 if (!WMIsPLString(value
)) {
1856 COMPLAIN("Collapsed");
1858 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1859 dock
->collapsed
= 1;
1863 /* restore auto-collapsed state */
1864 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1866 if (!WMIsPLString(value
)) {
1867 COMPLAIN("AutoCollapse");
1869 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1870 dock
->auto_collapse
= 1;
1871 dock
->collapsed
= 1;
1876 /* restore auto-raise/lower state */
1877 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1879 if (!WMIsPLString(value
)) {
1880 COMPLAIN("AutoRaiseLower");
1882 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1883 dock
->auto_raise_lower
= 1;
1887 /* restore attract icons state */
1888 dock
->attract_icons
= 0;
1890 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1892 if (!WMIsPLString(value
)) {
1893 COMPLAIN("AutoAttractIcons");
1895 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1896 dock
->attract_icons
= 1;
1900 /* application list */
1907 * When saving, it saves the dock state in
1908 * Applications and Applicationsnnn
1910 * When loading, it will first try Applicationsnnn.
1911 * If it does not exist, use Applications as default.
1914 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1916 tmp
= WMCreatePLString(buffer
);
1917 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1918 WMReleasePropList(tmp
);
1921 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1927 count
= WMGetPropListItemCount(apps
);
1931 old_top
= dock
->icon_array
[0];
1933 /* dock->icon_count is set to 1 when dock is created.
1934 * Since Clip is already restored, we want to keep it so for clip,
1935 * but for dock we may change the default top tile, so we set it to 0.
1937 if (type
== WM_DOCK
)
1938 dock
->icon_count
= 0;
1940 for (i
= 0; i
< count
; i
++) {
1941 if (dock
->icon_count
>= dock
->max_icons
) {
1942 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1946 value
= WMGetFromPLArray(apps
, i
);
1947 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1949 dock
->icon_array
[dock
->icon_count
] = aicon
;
1953 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1954 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1957 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1959 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1961 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1962 if (!dock
->collapsed
)
1963 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1965 wRaiseFrame(aicon
->icon
->core
);
1968 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
) {
1973 /* if the first icon is not defined, use the default */
1974 if (dock
->icon_array
[0] == NULL
) {
1975 /* update default icon */
1976 old_top
->x_pos
= dock
->x_pos
;
1977 old_top
->y_pos
= dock
->y_pos
;
1979 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1981 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1983 dock
->icon_array
[0] = old_top
;
1984 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1985 /* we don't need to increment dock->icon_count here because it was
1986 * incremented in the loop above.
1988 } else if (old_top
!= dock
->icon_array
[0]) {
1989 if (old_top
== scr
->clip_icon
) // TODO dande: understand the logic
1990 scr
->clip_icon
= dock
->icon_array
[0];
1992 wAppIconDestroy(old_top
);
1996 WMReleasePropList(dock_state
);
2001 void wDockLaunchWithState(WAppIcon
*btn
, WSavedState
*state
)
2003 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
2004 btn
->drop_launch
= 0;
2005 btn
->paste_launch
= 0;
2007 btn
->pid
= execCommand(btn
, btn
->command
, state
);
2010 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
2020 void wDockDoAutoLaunch(WDock
*dock
, int workspace
)
2026 for (i
= 0; i
< dock
->max_icons
; i
++) {
2027 btn
= dock
->icon_array
[i
];
2028 if (!btn
|| !btn
->auto_launch
)
2031 state
= wmalloc(sizeof(WSavedState
));
2032 state
->workspace
= workspace
;
2033 /* TODO: this is klugy and is very difficult to understand
2034 * what's going on. Try to clean up */
2035 wDockLaunchWithState(btn
, state
);
2039 #ifdef USE_DOCK_XDND
2040 static WDock
*findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
2047 for (i
= 0; i
< dock
->max_icons
; i
++) {
2048 if (dock
->icon_array
[i
] &&
2049 dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
2056 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
2058 for (i
= 0; i
< dock
->max_icons
; i
++) {
2059 if (dock
->icon_array
[i
] &&
2060 dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
2071 int wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
2077 dock
= findDock(scr
, event
, &icon_pos
);
2082 * Return True if the drop was on an application icon window.
2083 * In this case, let the ClientMessage handler redirect the
2084 * message to the app.
2086 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
2089 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
2090 scr
->flags
.dnd_data_convertion_status
= 0;
2092 btn
= dock
->icon_array
[icon_pos
];
2094 if (!btn
->forced_dock
) {
2095 btn
->relaunching
= btn
->running
;
2098 if (btn
->wm_instance
|| btn
->wm_class
) {
2099 WWindowAttributes attr
;
2100 memset(&attr
, 0, sizeof(WWindowAttributes
));
2101 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
2103 if (!attr
.no_appicon
)
2109 btn
->paste_launch
= 0;
2110 btn
->drop_launch
= 1;
2111 scr
->last_dock
= dock
;
2112 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
2117 if (!btn
->relaunching
)
2123 #endif /* USE_DOCK_XDND */
2125 Bool
wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
, Bool update_icon
)
2128 Bool lupdate_icon
= False
;
2129 char *command
= NULL
;
2135 lupdate_icon
= True
;
2137 if (icon
->command
== NULL
) {
2138 /* If icon->owner exists, it means the application is running */
2139 if (icon
->icon
->owner
) {
2140 wwin
= icon
->icon
->owner
;
2141 command
= GetCommandForWindow(wwin
->client_win
);
2145 icon
->command
= command
;
2147 /* icon->forced_dock = 1; */
2148 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
2150 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2151 _("Type the command used to launch the application"), &command
)) {
2152 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2156 icon
->command
= command
;
2162 /* If the target is the dock, reject the icon. If
2163 * the target is the clip, make it an attracted icon
2165 if (dock
->type
== WM_CLIP
) {
2166 icon
->attracted
= 1;
2167 if (!icon
->icon
->shadowed
) {
2168 icon
->icon
->shadowed
= 1;
2169 lupdate_icon
= True
;
2179 for (index
= 1; index
< dock
->max_icons
; index
++)
2180 if (dock
->icon_array
[index
] == NULL
)
2182 /* if (index == dock->max_icons)
2185 assert(index
< dock
->max_icons
);
2187 dock
->icon_array
[index
] = icon
;
2191 icon
->omnipresent
= 0;
2193 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2194 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2199 icon
->launching
= 0;
2202 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2203 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2204 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2205 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2206 icon
->icon
->core
->descriptor
.parent
= icon
;
2208 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2209 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2212 * Update icon pixmap, RImage doesn't change,
2213 * so call wIconUpdate is not needed
2216 update_icon_pixmap(icon
->icon
);
2219 wAppIconPaint(icon
);
2224 if (wPreferences
.auto_arrange_icons
)
2225 wArrangeIcons(dock
->screen_ptr
, True
);
2227 #ifdef USE_DOCK_XDND
2228 if (icon
->command
&& !icon
->dnd_command
) {
2229 int len
= strlen(icon
->command
) + 8;
2230 icon
->dnd_command
= wmalloc(len
);
2231 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
2235 if (icon
->command
&& !icon
->paste_command
) {
2236 int len
= strlen(icon
->command
) + 8;
2237 icon
->paste_command
= wmalloc(len
);
2238 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
2244 void wDockReattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2248 for (index
= 1; index
< dock
->max_icons
; index
++) {
2249 if (dock
->icon_array
[index
] == icon
)
2252 assert(index
< dock
->max_icons
);
2257 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2258 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2261 Bool
wDockMoveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2264 char *command
= NULL
;
2266 Bool update_icon
= False
;
2269 return True
; /* No move needed, we're already there */
2275 * For the moment we can't do this if we move icons in Clip from one
2276 * workspace to other, because if we move two or more icons without
2277 * command, the dialog box will not be able to tell us to which of the
2278 * moved icons it applies. -Dan
2280 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
2281 /* If icon->owner exists, it means the application is running */
2282 if (icon
->icon
->owner
) {
2283 wwin
= icon
->icon
->owner
;
2284 command
= GetCommandForWindow(wwin
->client_win
);
2288 icon
->command
= command
;
2291 /* icon->forced_dock = 1; */
2292 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2293 _("Type the command used to launch the application"), &command
)) {
2294 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2298 icon
->command
= command
;
2309 if (dest
->type
== WM_DOCK
|| dest
->type
== WM_DRAWER
)
2310 wClipMakeIconOmnipresent(icon
, False
);
2312 for (index
= 1; index
< src
->max_icons
; index
++) {
2313 if (src
->icon_array
[index
] == icon
)
2316 assert(index
< src
->max_icons
);
2318 src
->icon_array
[index
] = NULL
;
2321 for (index
= 1; index
< dest
->max_icons
; index
++) {
2322 if (dest
->icon_array
[index
] == NULL
)
2326 assert(index
< dest
->max_icons
);
2328 dest
->icon_array
[index
] = icon
;
2331 /* deselect the icon */
2332 if (icon
->icon
->selected
)
2333 wIconSelect(icon
->icon
);
2335 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2336 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2338 /* set it to be kept when moving to dock.
2339 * Unless the icon does not have a command set
2341 if (icon
->command
&& (dest
->type
== WM_DOCK
|| dest
->type
== WM_DRAWER
)) {
2342 icon
->attracted
= 0;
2343 if (icon
->icon
->shadowed
) {
2344 icon
->icon
->shadowed
= 0;
2349 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2355 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2356 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2360 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2363 * Update icon pixmap, RImage doesn't change,
2364 * so call wIconUpdate is not needed
2367 update_icon_pixmap(icon
->icon
);
2370 wAppIconPaint(icon
);
2375 void wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2378 Bool update_icon
= False
;
2380 /* make the settings panel be closed */
2382 DestroyDockAppSettingsPanel(icon
->panel
);
2384 /* This must be called before icon->dock is set to NULL.
2385 * Don't move it. -Dan
2387 wClipMakeIconOmnipresent(icon
, False
);
2391 icon
->attracted
= 0;
2392 icon
->auto_launch
= 0;
2393 if (icon
->icon
->shadowed
) {
2394 icon
->icon
->shadowed
= 0;
2398 /* deselect the icon */
2399 if (icon
->icon
->selected
)
2400 wIconSelect(icon
->icon
);
2402 if (icon
->command
) {
2403 wfree(icon
->command
);
2404 icon
->command
= NULL
;
2406 #ifdef USE_DOCK_XDND
2407 if (icon
->dnd_command
) {
2408 wfree(icon
->dnd_command
);
2409 icon
->dnd_command
= NULL
;
2412 if (icon
->paste_command
) {
2413 wfree(icon
->paste_command
);
2414 icon
->paste_command
= NULL
;
2417 for (index
= 1; index
< dock
->max_icons
; index
++)
2418 if (dock
->icon_array
[index
] == icon
)
2421 assert(index
< dock
->max_icons
);
2422 dock
->icon_array
[index
] = NULL
;
2428 /* Remove the Cached Icon */
2429 remove_cache_icon(icon
->icon
->file
);
2431 /* if the dock is not attached to an application or
2432 * the application did not set the appropriate hints yet,
2433 * destroy the icon */
2434 if (!icon
->running
|| !wApplicationOf(icon
->main_window
)) {
2435 wAppIconDestroy(icon
);
2437 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2438 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2439 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2440 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2441 icon
->icon
->core
->descriptor
.parent
= icon
;
2443 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2446 * Update icon pixmap, RImage doesn't change,
2447 * so call wIconUpdate is not needed
2450 update_icon_pixmap(icon
->icon
);
2453 wAppIconPaint(icon
);
2455 if (wPreferences
.auto_arrange_icons
)
2456 wArrangeIcons(dock
->screen_ptr
, True
);
2459 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2464 * returns the closest Dock slot index for the passed
2467 * Returns False if icon can't be docked.
2469 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2472 /* Redocking == true means either icon->dock == dock (normal case)
2473 * or we are called from handleDockMove for a drawer */
2474 Bool
wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2476 WScreen
*scr
= dock
->screen_ptr
;
2479 int i
, offset
= ICON_SIZE
/ 2;
2480 WAppIcon
*aicon
= NULL
;
2481 WAppIcon
*nicon
= NULL
;
2483 if (wPreferences
.flags
.noupdates
)
2489 /* if the dock is full */
2490 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
))
2493 /* exact position */
2495 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2497 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2500 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2502 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2504 /* check if the icon is outside the screen boundaries */
2505 if (!onScreen(scr
, dx
+ ex_x
* ICON_SIZE
, dy
+ ex_y
* ICON_SIZE
))
2508 switch (dock
->type
) {
2510 /* We can return False right away if
2511 * - we do not come from this dock (which is a WM_DOCK),
2512 * - we are not right over it, and
2513 * - we are not the main tile of a drawer.
2514 * In the latter case, we are called from handleDockMove. */
2515 if (icon
->dock
!= dock
&& ex_x
!= 0 &&
2516 !(icon
->dock
&& icon
->dock
->type
== WM_DRAWER
&& icon
== icon
->dock
->icon_array
[0]))
2519 if (!redocking
&& ex_x
!= 0)
2522 if (getDrawer(scr
, ex_y
)) /* Return false so that the drawer gets it. */
2526 for (i
= 0; i
< dock
->max_icons
; i
++) {
2527 nicon
= dock
->icon_array
[i
];
2528 if (nicon
&& nicon
->yindex
== ex_y
) {
2535 int sig
, done
, closest
;
2537 /* Possible cases when redocking:
2539 * icon dragged out of range of any slot -> false
2540 * icon dragged on a drawer -> false (to open the drawer)
2541 * icon dragged to range of free slot
2542 * icon dragged to range of same slot
2543 * icon dragged to range of different icon
2545 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2548 if (aicon
== icon
|| !aicon
) {
2554 /* start looking at the upper slot or lower? */
2555 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2561 /* look for closest free slot */
2562 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2566 closest
= sig
* (i
/ 2) + ex_y
;
2567 /* check if this slot is fully on the screen and not used */
2568 if (onScreen(scr
, dx
, dy
+ closest
* ICON_SIZE
)) {
2569 for (j
= 0; j
< dock
->max_icons
; j
++) {
2570 if (dock
->icon_array
[j
]
2571 && dock
->icon_array
[j
]->yindex
== closest
) {
2572 /* slot is used by someone else */
2573 if (dock
->icon_array
[j
] != icon
)
2578 /* slot is used by a drawer */
2579 done
= done
&& !getDrawer(scr
, closest
);
2586 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2587 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2592 } else { /* !redocking */
2594 /* if slot is free and the icon is close enough, return it */
2595 if (!aicon
&& ex_x
== 0) {
2607 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2608 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+ 1;
2611 for (k
= start
; k
< stop
; k
++) {
2612 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2615 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2616 nicon
= tmp
->icon_array
[i
];
2617 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2625 for (k
= start
; k
< stop
; k
++) {
2626 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2629 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2630 nicon
= tmp
->icon_array
[i
];
2631 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2632 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2633 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2642 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2651 WAppIcon
*aicons_to_shift
[ dock
->icon_count
];
2652 int index_of_hole
, j
;
2655 abs(ex_x
) - dock
->icon_count
> DOCK_DETTACH_THRESHOLD
||
2656 (ex_x
< 0 && !dock
->on_right_side
) ||
2657 (ex_x
> 0 && dock
->on_right_side
)) {
2662 ex_x
= (dock
->on_right_side
? -1 : 1);
2664 /* "Reduce" ex_x but keep its sign */
2666 if (abs(ex_x
) > dock
->icon_count
- 1) /* minus 1: do not take icon_array[0] into account */
2667 ex_x
= ex_x
* (dock
->icon_count
- 1) / abs(ex_x
); /* don't use *= ! */
2669 if (abs(ex_x
) > dock
->icon_count
)
2670 ex_x
= ex_x
* dock
->icon_count
/ abs(ex_x
);
2672 index_of_hole
= indexOfHole(dock
, icon
, redocking
);
2674 /* Find the appicons between where icon was (index_of_hole) and where
2675 * it wants to be (ex_x) and slide them. */
2677 for (i
= 1; i
< dock
->max_icons
; i
++) {
2678 aicon
= dock
->icon_array
[i
];
2679 if ((aicon
!= NULL
) && (aicon
!= icon
) &&
2680 ((ex_x
<= aicon
->xindex
&& aicon
->xindex
< index_of_hole
) ||
2681 (index_of_hole
< aicon
->xindex
&& aicon
->xindex
<= ex_x
)))
2682 aicons_to_shift
[ j
++ ] = aicon
;
2684 assert(j
== abs(ex_x
- index_of_hole
));
2686 wSlideAppicons(aicons_to_shift
, j
, (index_of_hole
< ex_x
));
2696 static int onScreen(WScreen
*scr
, int x
, int y
)
2703 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2705 wGetRectPlacementInfo(scr
, rect
, &flags
);
2707 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2711 * returns true if it can find a free slot in the dock,
2712 * in which case it changes x_pos and y_pos accordingly.
2713 * Else returns false.
2715 Bool
wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2717 WScreen
*scr
= dock
->screen_ptr
;
2719 WAppIconChain
*chain
;
2720 unsigned char *slot_map
;
2724 int i
, done
= False
;
2726 int ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2727 int extra_count
= 0;
2729 if (dock
->type
== WM_DRAWER
) {
2730 if (dock
->icon_count
>= dock
->max_icons
) { /* drawer is full */
2733 *x_pos
= dock
->icon_count
* (dock
->on_right_side
? -1 : 1);
2738 if (dock
->type
== WM_CLIP
&& dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2739 extra_count
= scr
->global_icon_count
;
2741 /* if the dock is full */
2742 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
)
2745 if (!wPreferences
.flags
.nodock
&& scr
->dock
&& scr
->dock
->on_right_side
) {
2746 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2749 if (ex
< dock
->x_pos
)
2757 /* check if clip is in a corner */
2758 if (dock
->type
== WM_CLIP
) {
2759 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2761 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2763 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2765 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2773 /* If the clip is in the corner, use only slots that are in the border
2775 if (corner
!= C_NONE
) {
2779 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2780 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2781 hmap
= wmalloc(hcount
+ 1);
2782 vmap
= wmalloc(vcount
+ 1);
2784 /* mark used positions */
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;
2825 for (i
= 0; i
< dock
->max_icons
; i
++) {
2826 btn
= dock
->icon_array
[i
];
2830 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2831 vmap
[-btn
->yindex
] = 1;
2832 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2833 hmap
[btn
->xindex
] = 1;
2835 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2837 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2838 vmap
[-btn
->yindex
] = 1;
2839 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2840 hmap
[btn
->xindex
] = 1;
2845 for (i
= 0; i
< dock
->max_icons
; i
++) {
2846 btn
= dock
->icon_array
[i
];
2850 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2851 vmap
[-btn
->yindex
] = 1;
2852 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2853 hmap
[-btn
->xindex
] = 1;
2855 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2857 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2858 vmap
[-btn
->yindex
] = 1;
2859 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2860 hmap
[-btn
->xindex
] = 1;
2866 /* search a vacant slot */
2867 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2868 if (i
< vcount
&& vmap
[i
] == 0) {
2874 } else if (i
< hcount
&& hmap
[i
] == 0) {
2884 /* If found a slot, translate and return */
2886 if (corner
== C_NW
|| corner
== C_NE
)
2891 if (corner
== C_NE
|| corner
== C_SE
)
2898 /* else, try to find a slot somewhere else */
2901 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2902 * placed outside of screen */
2903 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2905 /* In the worst case (the clip is in the corner of the screen),
2906 * the amount of icons that fit in the clip is smaller.
2907 * Double the map to get a safe value.
2911 r
= (mwidth
- 1) / 2;
2913 slot_map
= wmalloc(mwidth
* mwidth
);
2915 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2917 /* mark used slots in the map. If the slot falls outside the map
2918 * (for example, when all icons are placed in line), ignore them. */
2919 for (i
= 0; i
< dock
->max_icons
; i
++) {
2920 btn
= dock
->icon_array
[i
];
2922 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2925 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
)
2926 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2928 /* Find closest slot from the center that is free by scanning the
2929 * map from the center to outward in circular passes.
2930 * This will not result in a neat layout, but will be optimal
2931 * in the sense that there will not be holes left.
2934 for (i
= 1; i
<= r
&& !done
; i
++) {
2937 /* top and bottom parts of the ring */
2938 for (x
= -i
; x
<= i
&& !done
; x
++) {
2939 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2941 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2942 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2949 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2950 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2957 /* left and right parts of the ring */
2958 for (y
= -i
+ 1; y
<= i
- 1; y
++) {
2959 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2961 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2962 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2969 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2970 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2983 static void moveDock(WDock
*dock
, int new_x
, int new_y
)
2989 if (dock
->type
== WM_DOCK
) {
2990 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
2991 moveDock(dc
->adrawer
, new_x
, dc
->adrawer
->y_pos
- dock
->y_pos
+ new_y
);
2994 dock
->x_pos
= new_x
;
2995 dock
->y_pos
= new_y
;
2996 for (i
= 0; i
< dock
->max_icons
; i
++) {
2997 btn
= dock
->icon_array
[i
];
2999 btn
->x_pos
= new_x
+ btn
->xindex
* ICON_SIZE
;
3000 btn
->y_pos
= new_y
+ btn
->yindex
* ICON_SIZE
;
3001 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
3006 static void swapDock(WDock
*dock
)
3008 WScreen
*scr
= dock
->screen_ptr
;
3012 if (dock
->on_right_side
)
3013 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
3015 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
3017 swapDrawers(scr
, x
);
3019 for (i
= 0; i
< dock
->max_icons
; i
++) {
3020 btn
= dock
->icon_array
[i
];
3023 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
3027 wScreenUpdateUsableArea(scr
);
3030 static pid_t
execCommand(WAppIcon
*btn
, const char *command
, WSavedState
*state
)
3032 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
3038 cmdline
= ExpandOptions(scr
, command
);
3040 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
3048 wtokensplit(cmdline
, &argv
, &argc
);
3063 SetupEnvironment(scr
);
3069 args
= malloc(sizeof(char *) * (argc
+ 1));
3073 for (i
= 0; i
< argc
; i
++)
3077 execvp(argv
[0], args
);
3080 wtokenfree(argv
, argc
);
3084 state
= wmalloc(sizeof(WSavedState
));
3086 state
->miniaturized
= -1;
3088 if (btn
->dock
== scr
->dock
|| btn
->dock
->type
== WM_DRAWER
|| btn
->omnipresent
)
3089 state
->workspace
= -1;
3091 state
->workspace
= scr
->current_workspace
;
3093 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
3094 wAddDeathHandler(pid
, (WDeathHandler
*) trackDeadProcess
, btn
->dock
);
3102 void wDockHideIcons(WDock
*dock
)
3109 for (i
= 1; i
< dock
->max_icons
; i
++) {
3110 if (dock
->icon_array
[i
])
3111 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3115 dockIconPaint(dock
->icon_array
[0]);
3118 void wDockShowIcons(WDock
*dock
)
3126 btn
= dock
->icon_array
[0];
3127 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
3129 /* Deleting any change in stacking level, this function is now only about
3132 if (!dock
->collapsed
) {
3133 for (i
= 1; i
< dock
->max_icons
; i
++) {
3134 if (dock
->icon_array
[i
])
3135 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3143 void wDockLower(WDock
*dock
)
3148 if (dock
->type
== WM_DOCK
) {
3149 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3150 wDockLower(dc
->adrawer
);
3152 for (i
= 0; i
< dock
->max_icons
; i
++) {
3153 if (dock
->icon_array
[i
])
3154 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
3158 void wDockRaise(WDock
*dock
)
3163 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
3164 if (dock
->icon_array
[i
])
3165 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
3167 if (dock
->type
== WM_DOCK
) {
3168 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3169 wDockRaise(dc
->adrawer
);
3173 void wDockRaiseLower(WDock
*dock
)
3175 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
3176 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
3177 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
3183 void wDockFinishLaunch(WAppIcon
*icon
)
3185 icon
->launching
= 0;
3186 icon
->relaunching
= 0;
3187 dockIconPaint(icon
);
3190 WAppIcon
*wDockFindIconForWindow(WDock
*dock
, Window window
)
3195 for (i
= 0; i
< dock
->max_icons
; i
++) {
3196 icon
= dock
->icon_array
[i
];
3197 if (icon
&& icon
->main_window
== window
)
3203 void wDockTrackWindowLaunch(WDock
*dock
, Window window
)
3206 char *wm_class
, *wm_instance
;
3208 Bool firstPass
= True
;
3210 char *command
= NULL
;
3212 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
)) {
3218 command
= GetCommandForWindow(window
);
3220 for (i
= 0; i
< dock
->max_icons
; i
++) {
3221 icon
= dock
->icon_array
[i
];
3225 /* app is already attached to icon */
3226 if (icon
->main_window
== window
) {
3231 if ((icon
->wm_instance
|| icon
->wm_class
)
3232 && (icon
->launching
|| !icon
->running
)) {
3234 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0)
3237 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0)
3240 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0)
3243 if (!icon
->relaunching
) {
3246 /* Possibly an application that was docked with dockit,
3247 * but the user did not update WMState to indicate that
3248 * it was docked by force */
3249 wapp
= wApplicationOf(window
);
3251 icon
->forced_dock
= 1;
3254 if (!icon
->forced_dock
)
3255 icon
->main_window
= window
;
3258 if (!wPreferences
.no_animations
&& !icon
->launching
&&
3259 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
3263 icon
->launching
= 1;
3264 dockIconPaint(icon
);
3266 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
3267 wm_instance
, wm_class
, TILE_NORMAL
);
3268 /* XXX: can: aicon->icon == NULL ? */
3269 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
3270 wAppIconMove(aicon
, x0
, y0
);
3271 /* Should this always be lowered? -Dan */
3273 wLowerFrame(aicon
->icon
->core
);
3274 XMapWindow(dpy
, aicon
->icon
->core
->window
);
3275 aicon
->launching
= 1;
3276 wAppIconPaint(aicon
);
3277 slide_window(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
3278 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
3279 wAppIconDestroy(aicon
);
3281 wDockFinishLaunch(icon
);
3286 if (firstPass
&& !found
) {
3300 void wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3302 if (!wPreferences
.flags
.noclip
) {
3303 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3304 if (scr
->current_workspace
!= workspace
) {
3305 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3306 WAppIconChain
*chain
= scr
->global_icons
;
3309 wDockMoveIconBetweenDocks(chain
->aicon
->dock
,
3310 scr
->workspaces
[workspace
]->clip
,
3311 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
3312 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
3313 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3314 chain
= chain
->next
;
3317 wDockHideIcons(old_clip
);
3318 if (old_clip
->auto_raise_lower
) {
3319 if (old_clip
->auto_raise_magic
) {
3320 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3321 old_clip
->auto_raise_magic
= NULL
;
3323 wDockLower(old_clip
);
3325 if (old_clip
->auto_collapse
) {
3326 if (old_clip
->auto_expand_magic
) {
3327 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3328 old_clip
->auto_expand_magic
= NULL
;
3330 old_clip
->collapsed
= 1;
3332 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3337 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3342 for (i
= 0; i
< dock
->max_icons
; i
++) {
3343 icon
= dock
->icon_array
[i
];
3347 if (icon
->launching
&& icon
->pid
== pid
) {
3348 if (!icon
->relaunching
) {
3350 icon
->main_window
= None
;
3352 wDockFinishLaunch(icon
);
3354 if (status
== 111) {
3358 #ifdef USE_DOCK_XDND
3359 if (icon
->drop_launch
)
3360 cmd
= icon
->dnd_command
;
3363 if (icon
->paste_launch
)
3364 cmd
= icon
->paste_command
;
3366 cmd
= icon
->command
;
3368 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3370 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3377 /* This function is called when the dock switches state between
3378 * "normal" (including auto-raise/lower) and "keep on top". It is
3379 * therefore clearly distinct from wDockLower/Raise, which are called
3380 * each time a not-kept-on-top dock is lowered/raised. */
3381 static void toggleLowered(WDock
*dock
)
3387 if (!dock
->lowered
) {
3388 newlevel
= WMNormalLevel
;
3391 newlevel
= WMDockLevel
;
3395 for (i
= 0; i
< dock
->max_icons
; i
++) {
3396 tmp
= dock
->icon_array
[i
];
3400 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3402 /* When the dock is no longer "on top", explicitly lower it as well.
3403 * It saves some CPU cycles (probably) to do it ourselves here
3404 * rather than calling wDockLower at the end of toggleLowered */
3406 wLowerFrame(tmp
->icon
->core
);
3409 if (dock
->type
== WM_DOCK
) {
3410 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
3411 toggleLowered(dc
->adrawer
);
3413 wScreenUpdateUsableArea(dock
->screen_ptr
);
3417 static void toggleCollapsed(WDock
*dock
)
3419 if (dock
->collapsed
) {
3420 dock
->collapsed
= 0;
3421 wDockShowIcons(dock
);
3423 dock
->collapsed
= 1;
3424 wDockHideIcons(dock
);
3428 static void openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3430 WScreen
*scr
= dock
->screen_ptr
;
3431 WObjDescriptor
*desc
;
3433 WApplication
*wapp
= NULL
;
3437 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3439 if (dock
->type
== WM_DOCK
) {
3440 /* Dock position menu */
3441 updateDockPositionMenu(scr
->dock_pos_menu
, dock
);
3442 dock
->menu
->flags
.realized
= 0;
3443 if (!wPreferences
.flags
.nodrawer
) {
3445 entry
= dock
->menu
->entries
[++index
];
3446 entry
->clientdata
= aicon
;
3447 wMenuSetEnabled(dock
->menu
, index
, True
);
3450 /* clip/drawer options */
3451 if (scr
->clip_options
)
3452 updateClipOptionsMenu(scr
->clip_options
, dock
);
3454 n_selected
= numberOfSelectedIcons(dock
);
3456 if (dock
->type
== WM_CLIP
) {
3457 /* Rename Workspace */
3458 entry
= dock
->menu
->entries
[++index
];
3459 if (aicon
== scr
->clip_icon
) {
3460 entry
->callback
= renameCallback
;
3461 entry
->clientdata
= dock
;
3462 entry
->flags
.indicator
= 0;
3463 entry
->text
= _("Rename Workspace");
3465 entry
->callback
= omnipresentCallback
;
3466 entry
->clientdata
= aicon
;
3467 if (n_selected
> 0) {
3468 entry
->flags
.indicator
= 0;
3469 entry
->text
= _("Toggle Omnipresent");
3471 entry
->flags
.indicator
= 1;
3472 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3473 entry
->flags
.indicator_type
= MI_CHECK
;
3474 entry
->text
= _("Omnipresent");
3479 /* select/unselect icon */
3480 entry
= dock
->menu
->entries
[++index
];
3481 entry
->clientdata
= aicon
;
3482 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3483 wMenuSetEnabled(dock
->menu
, index
, aicon
!= scr
->clip_icon
&& !wIsADrawer(aicon
));
3485 /* select/unselect all icons */
3486 entry
= dock
->menu
->entries
[++index
];
3487 entry
->clientdata
= aicon
;
3489 entry
->text
= _("Unselect All Icons");
3491 entry
->text
= _("Select All Icons");
3493 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3496 entry
= dock
->menu
->entries
[++index
];
3497 entry
->clientdata
= aicon
;
3499 entry
->text
= _("Keep Icons");
3501 entry
->text
= _("Keep Icon");
3503 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3505 if (dock
->type
== WM_CLIP
) {
3506 /* this is the workspace submenu part */
3507 entry
= dock
->menu
->entries
[++index
];
3509 entry
->text
= _("Move Icons To");
3511 entry
->text
= _("Move Icon To");
3513 if (scr
->clip_submenu
)
3514 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3516 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3519 /* remove icon(s) */
3520 entry
= dock
->menu
->entries
[++index
];
3521 entry
->clientdata
= aicon
;
3523 entry
->text
= _("Remove Icons");
3525 entry
->text
= _("Remove Icon");
3527 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3529 /* attract icon(s) */
3530 entry
= dock
->menu
->entries
[++index
];
3531 entry
->clientdata
= aicon
;
3533 dock
->menu
->flags
.realized
= 0;
3534 wMenuRealize(dock
->menu
);
3537 if (aicon
->icon
->owner
)
3538 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3543 entry
= dock
->menu
->entries
[++index
];
3544 entry
->clientdata
= aicon
;
3545 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3548 entry
= dock
->menu
->entries
[++index
];
3549 entry
->clientdata
= aicon
;
3550 if (wapp
&& wapp
->flags
.hidden
)
3551 entry
->text
= _("Unhide Here");
3553 entry
->text
= _("Bring Here");
3555 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3558 entry
= dock
->menu
->entries
[++index
];
3559 entry
->clientdata
= aicon
;
3560 if (wapp
&& wapp
->flags
.hidden
)
3561 entry
->text
= _("Unhide");
3563 entry
->text
= _("Hide");
3565 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3568 entry
= dock
->menu
->entries
[++index
];
3569 entry
->clientdata
= aicon
;
3570 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3572 /* kill or remove drawer */
3573 entry
= dock
->menu
->entries
[++index
];
3574 entry
->clientdata
= aicon
;
3575 if (wIsADrawer(aicon
)) {
3576 entry
->callback
= removeDrawerCallback
;
3577 entry
->text
= _("Remove drawer");
3578 wMenuSetEnabled(dock
->menu
, index
, True
);
3580 entry
->callback
= killCallback
;
3581 entry
->text
= _("Kill");
3582 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3585 if (!dock
->menu
->flags
.realized
)
3586 wMenuRealize(dock
->menu
);
3588 if (dock
->type
== WM_CLIP
|| dock
->type
== WM_DRAWER
) {
3589 /*x_pos = event->xbutton.x_root+2; */
3590 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3593 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3594 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3597 x_pos
= dock
->on_right_side
? scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3600 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3602 /* allow drag select */
3603 event
->xany
.send_event
= True
;
3604 desc
= &dock
->menu
->menu
->descriptor
;
3605 (*desc
->handle_mousedown
) (desc
, event
);
3608 /******************************************************************/
3609 static void iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3611 WAppIcon
*btn
= desc
->parent
;
3612 WDock
*dock
= btn
->dock
;
3613 WApplication
*wapp
= NULL
;
3616 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3617 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3619 assert(wapp
!= NULL
);
3621 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3623 /* go to the last workspace that the user worked on the app */
3624 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
&& !unhideHere
)
3625 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3627 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3629 if (event
->xbutton
.state
& MOD_MASK
)
3630 wHideOtherApplications(btn
->icon
->owner
);
3632 if (event
->xbutton
.button
== Button1
) {
3633 if (event
->xbutton
.state
& MOD_MASK
) {
3634 /* raise/lower dock */
3635 toggleLowered(dock
);
3636 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3637 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
)
3638 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3639 else if (wPreferences
.flags
.clip_merged_in_dock
) {
3640 // Is actually the dock
3643 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3644 launchDockedApplication(btn
, False
);
3648 wShowInfoPanel(dock
->screen_ptr
);
3652 toggleCollapsed(dock
);
3653 } else if (wIsADrawer(btn
)) {
3654 toggleCollapsed(dock
);
3655 } else if (btn
->command
) {
3656 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3657 launchDockedApplication(btn
, False
);
3658 } else if (btn
->xindex
== 0 && btn
->yindex
== 0 && btn
->dock
->type
== WM_DOCK
) {
3659 wShowInfoPanel(dock
->screen_ptr
);
3665 static void handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3667 WScreen
*scr
= dock
->screen_ptr
;
3668 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3669 WIcon
*icon
= aicon
->icon
;
3672 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;;
3673 int shad_x
= x
, shad_y
= y
;
3675 int grabbed
= 0, done
, previously_on_right
, now_on_right
, previous_x_pos
, i
;
3676 Pixmap ghost
= None
;
3677 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3679 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3680 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3681 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
)
3682 wwarning("pointer grab failed for dock move");
3684 if (dock
->type
== WM_DRAWER
) {
3686 wins
[0] = icon
->core
->window
;
3687 wins
[1] = scr
->dock_shadow
;
3688 XRestackWindows(dpy
, wins
, 2);
3689 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3690 ICON_SIZE
, ICON_SIZE
);
3692 if (icon
->pixmap
!=None
)
3693 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3695 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3697 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3698 XClearWindow(dpy
, scr
->dock_shadow
);
3700 XMapWindow(dpy
, scr
->dock_shadow
);
3703 previously_on_right
= now_on_right
= dock
->on_right_side
;
3704 previous_x_pos
= dock
->x_pos
;
3707 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3708 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3715 /* It means the cursor moved so fast that it entered
3716 * something else (if moving slowly, it would have
3717 * stayed in the dock that is being moved. Ignore such
3718 * "spurious" EnterNotifiy's */
3723 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3724 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3725 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3726 | ButtonReleaseMask
| ButtonPressMask
,
3727 wPreferences
.cursor
[WCUR_MOVE
], CurrentTime
);
3732 switch (dock
->type
) {
3734 x
= ev
.xmotion
.x_root
- ofs_x
;
3735 y
= ev
.xmotion
.y_root
- ofs_y
;
3736 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3737 moveDock(dock
, x
, y
);
3740 x
= ev
.xmotion
.x_root
- ofs_x
;
3741 y
= ev
.xmotion
.y_root
- ofs_y
;
3742 if (previously_on_right
)
3744 now_on_right
= (ev
.xmotion
.x_root
>= previous_x_pos
- ICON_SIZE
);
3748 now_on_right
= (ev
.xmotion
.x_root
> previous_x_pos
+ ICON_SIZE
* 2);
3750 if (now_on_right
!= dock
->on_right_side
)
3752 dock
->on_right_side
= now_on_right
;
3754 wArrangeIcons(scr
, False
);
3756 // Also perform the vertical move
3757 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3758 moveDock(dock
, dock
->x_pos
, y
);
3759 if (wPreferences
.flags
.wrap_appicons_in_dock
)
3761 for (i
= 0; i
< dock
->max_icons
; i
++) {
3762 int new_y
, new_index
, j
, ok
;
3764 tmpaicon
= dock
->icon_array
[i
];
3765 if (tmpaicon
== NULL
)
3767 if (onScreen(scr
, tmpaicon
->x_pos
, tmpaicon
->y_pos
))
3769 new_y
= (tmpaicon
->y_pos
+ ICON_SIZE
* dock
->max_icons
) % (ICON_SIZE
* dock
->max_icons
);
3770 new_index
= (new_y
- dock
->y_pos
) / ICON_SIZE
;
3771 if (!onScreen(scr
, tmpaicon
->x_pos
, new_y
))
3774 for (j
= 0; j
< dock
->max_icons
; j
++)
3776 if (dock
->icon_array
[j
] != NULL
&&
3777 dock
->icon_array
[j
]->yindex
== new_index
)
3783 if (!ok
|| getDrawer(scr
, new_index
) != NULL
)
3785 wDockReattachIcon(dock
, tmpaicon
, tmpaicon
->xindex
, new_index
);
3787 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3789 int new_y
, new_index
, j
, ok
;
3790 tmpaicon
= dc
->adrawer
->icon_array
[0];
3791 if (onScreen(scr
, tmpaicon
->x_pos
, tmpaicon
->y_pos
))
3793 new_y
= (tmpaicon
->y_pos
+ ICON_SIZE
* dock
->max_icons
) % (ICON_SIZE
* dock
->max_icons
);
3794 new_index
= (new_y
- dock
->y_pos
) / ICON_SIZE
;
3795 if (!onScreen(scr
, tmpaicon
->x_pos
, new_y
))
3798 for (j
= 0; j
< dock
->max_icons
; j
++)
3800 if (dock
->icon_array
[j
] != NULL
&&
3801 dock
->icon_array
[j
]->yindex
== new_index
)
3807 if (!ok
|| getDrawer(scr
, new_index
) != NULL
)
3809 moveDock(dc
->adrawer
, tmpaicon
->x_pos
, new_y
);
3815 WDock
*real_dock
= dock
->screen_ptr
->dock
;
3818 x
= ev
.xmotion
.x_root
- ofs_x
;
3819 y
= ev
.xmotion
.y_root
- ofs_y
;
3820 snapped
= wDockSnapIcon(real_dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3822 shad_x
= real_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3823 shad_y
= real_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3824 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3826 moveDock(dock
, x
, y
);
3836 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3838 XUngrabPointer(dpy
, CurrentTime
);
3839 if (dock
->type
== WM_DRAWER
) {
3840 Window wins
[dock
->icon_count
];
3844 * When the dock is on the Right side, the index of the icons are negative to
3845 * reflect the fact that they are placed on the other side of the dock; we use
3846 * an offset here so we can have an always positive index for the storage in
3849 if (dock
->on_right_side
)
3850 offset_index
= dock
->icon_count
- 1;
3854 for (i
= 0; i
< dock
->max_icons
; i
++) {
3855 tmpaicon
= dock
->icon_array
[i
];
3856 if (tmpaicon
== NULL
)
3858 wins
[tmpaicon
->xindex
+ offset_index
] = tmpaicon
->icon
->core
->window
;
3860 slide_windows(wins
, dock
->icon_count
,
3861 (dock
->on_right_side
? x
- (dock
->icon_count
- 1) * ICON_SIZE
: x
),
3863 (dock
->on_right_side
? shad_x
- (dock
->icon_count
- 1) * ICON_SIZE
: shad_x
),
3865 XUnmapWindow(dpy
, scr
->dock_shadow
);
3866 moveDock(dock
, shad_x
, shad_y
);
3867 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3875 XFreePixmap(dpy
, ghost
);
3876 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3881 static int getClipButton(int px
, int py
)
3883 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3885 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3888 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3889 return CLIP_FORWARD
;
3890 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3896 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3899 int done
, direction
, new_ws
;
3901 WDock
*clip
= scr
->clip_icon
->dock
;
3903 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3905 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3906 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3908 wClipIconPaint(scr
->clip_icon
);
3911 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3918 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3919 if (new_dir
!= direction
) {
3920 direction
= new_dir
;
3921 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3922 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3923 wClipIconPaint(scr
->clip_icon
);
3931 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3936 clip
->lclip_button_pushed
= 0;
3937 clip
->rclip_button_pushed
= 0;
3939 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3941 if (direction
== CLIP_FORWARD
) {
3942 if (scr
->current_workspace
< scr
->workspace_count
- 1)
3943 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3944 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
- 1)
3945 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3946 else if (wPreferences
.ws_cycle
)
3947 wWorkspaceChange(scr
, 0);
3948 } else if (direction
== CLIP_REWIND
) {
3949 if (scr
->current_workspace
> 0)
3950 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
3951 else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
)
3952 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
3955 wClipIconPaint(scr
->clip_icon
);
3958 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3960 WAppIcon
*aicon
= desc
->parent
;
3961 WDock
*dock
= aicon
->dock
;
3962 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3964 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3967 scr
->last_dock
= dock
;
3969 if (dock
->menu
->flags
.mapped
)
3970 wMenuUnmap(dock
->menu
);
3972 if (IsDoubleClick(scr
, event
)) {
3973 /* double-click was not in the main clip icon */
3974 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3975 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3976 iconDblClick(desc
, event
);
3981 if (event
->xbutton
.button
== Button1
) {
3982 if (event
->xbutton
.state
& MOD_MASK
)
3987 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
&& dock
->type
!= WM_DOCK
) {
3988 wIconSelect(aicon
->icon
);
3992 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3993 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
&&
3994 (dock
->type
== WM_CLIP
|| (dock
->type
== WM_DOCK
&& wPreferences
.flags
.clip_merged_in_dock
)))
3995 handleClipChangeWorkspace(scr
, event
);
3997 handleDockMove(dock
, aicon
, event
);
3999 Bool hasMoved
= wHandleAppIconMove(aicon
, event
);
4000 if (wPreferences
.single_click
&& !hasMoved
)
4001 iconDblClick(desc
, event
);
4003 } else if (event
->xbutton
.button
== Button2
&& aicon
== scr
->clip_icon
) {
4004 if (!scr
->clip_ws_menu
)
4005 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
4007 if (scr
->clip_ws_menu
) {
4008 WMenu
*wsMenu
= scr
->clip_ws_menu
;
4011 wWorkspaceMenuUpdate(scr
, wsMenu
);
4013 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
4016 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
4017 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
4019 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
4021 desc
= &wsMenu
->menu
->descriptor
;
4022 event
->xany
.send_event
= True
;
4023 (*desc
->handle_mousedown
) (desc
, event
);
4025 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
4026 (event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
) {
4027 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
4028 } else if (event
->xbutton
.button
== Button3
) {
4029 if (event
->xbutton
.send_event
&&
4030 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
4031 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
4032 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
4033 wwarning("pointer grab failed for dockicon menu");
4037 openDockMenu(dock
, aicon
, event
);
4038 } else if (event
->xbutton
.button
== Button2
) {
4039 WAppIcon
*btn
= desc
->parent
;
4041 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
4042 launchDockedApplication(btn
, True
);
4043 } else if (event
->xbutton
.button
== Button4
&& dock
->type
== WM_CLIP
) {
4044 wWorkspaceRelativeChange(scr
, 1);
4045 } else if (event
->xbutton
.button
== Button5
&& dock
->type
== WM_CLIP
) {
4046 wWorkspaceRelativeChange(scr
, -1);
4050 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
4052 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
4056 /* Parameter not used, but tell the compiler that it is ok */
4059 assert(event
->type
== EnterNotify
);
4061 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
4064 scr
= btn
->icon
->core
->screen_ptr
;
4070 /* The auto raise/lower code */
4071 tmp
= (dock
->type
== WM_DRAWER
? scr
->dock
: dock
);
4072 if (tmp
->auto_lower_magic
) {
4073 WMDeleteTimerHandler(tmp
->auto_lower_magic
);
4074 tmp
->auto_lower_magic
= NULL
;
4076 if (tmp
->auto_raise_lower
&& !tmp
->auto_raise_magic
)
4077 tmp
->auto_raise_magic
= WMAddTimerHandler(wPreferences
.clip_auto_raise_delay
, clipAutoRaise
, (void *) tmp
);
4079 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4082 /* The auto expand/collapse code */
4083 if (dock
->auto_collapse_magic
) {
4084 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
4085 dock
->auto_collapse_magic
= NULL
;
4087 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
)
4088 dock
->auto_expand_magic
= WMAddTimerHandler(wPreferences
.clip_auto_expand_delay
, clipAutoExpand
, (void *)dock
);
4091 static void clipLeave(WDock
*dock
)
4094 WObjDescriptor
*desc
= NULL
;
4100 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
4101 if (XFindContext(dpy
, event
.xcrossing
.window
, w_global
.context
.client_win
,
4102 (XPointer
*) & desc
) != XCNOENT
4103 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
4104 && ((WAppIcon
*) desc
->parent
)->dock
== dock
) {
4105 /* We haven't left the dock/clip/drawer yet */
4106 XPutBackEvent(dpy
, &event
);
4110 XPutBackEvent(dpy
, &event
);
4112 /* We entered a withdrawn window, so we're still in Clip */
4116 tmp
= (dock
->type
== WM_DRAWER
? dock
->screen_ptr
->dock
: dock
);
4117 if (tmp
->auto_raise_magic
) {
4118 WMDeleteTimerHandler(tmp
->auto_raise_magic
);
4119 tmp
->auto_raise_magic
= NULL
;
4121 if (tmp
->auto_raise_lower
&& !tmp
->auto_lower_magic
)
4122 tmp
->auto_lower_magic
= WMAddTimerHandler(wPreferences
.clip_auto_lower_delay
, clipAutoLower
, (void *)tmp
);
4124 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4127 if (dock
->auto_expand_magic
) {
4128 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4129 dock
->auto_expand_magic
= NULL
;
4131 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
)
4132 dock
->auto_collapse_magic
= WMAddTimerHandler(wPreferences
.clip_auto_collapse_delay
, clipAutoCollapse
, (void *)dock
);
4135 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4137 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
4139 /* Parameter not used, but tell the compiler that it is ok */
4142 assert(event
->type
== LeaveNotify
);
4144 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
4147 clipLeave(btn
->dock
);
4150 static void clipAutoCollapse(void *cdata
)
4152 WDock
*dock
= (WDock
*) cdata
;
4154 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4157 if (dock
->auto_collapse
) {
4158 dock
->collapsed
= 1;
4159 wDockHideIcons(dock
);
4161 dock
->auto_collapse_magic
= NULL
;
4164 static void clipAutoExpand(void *cdata
)
4166 WDock
*dock
= (WDock
*) cdata
;
4168 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4171 if (dock
->auto_collapse
) {
4172 dock
->collapsed
= 0;
4173 wDockShowIcons(dock
);
4175 dock
->auto_expand_magic
= NULL
;
4178 static void clipAutoLower(void *cdata
)
4180 WDock
*dock
= (WDock
*) cdata
;
4182 if (dock
->auto_raise_lower
)
4185 dock
->auto_lower_magic
= NULL
;
4188 static void clipAutoRaise(void *cdata
)
4190 WDock
*dock
= (WDock
*) cdata
;
4192 if (dock
->auto_raise_lower
)
4195 dock
->auto_raise_magic
= NULL
;
4198 static Bool
iconCanBeOmnipresent(WAppIcon
*aicon
)
4200 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4205 for (i
= 0; i
< scr
->workspace_count
; i
++) {
4206 clip
= scr
->workspaces
[i
]->clip
;
4208 if (clip
== aicon
->dock
)
4211 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4212 return False
; /* Clip is full in some workspace */
4214 for (j
= 0; j
< clip
->max_icons
; j
++) {
4215 btn
= clip
->icon_array
[j
];
4216 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
4224 int wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
4226 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4227 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4228 int status
= WO_SUCCESS
;
4230 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== scr
->clip_icon
)
4231 return WO_NOT_APPLICABLE
;
4233 if (aicon
->omnipresent
== omnipresent
)
4237 if (iconCanBeOmnipresent(aicon
)) {
4238 aicon
->omnipresent
= 1;
4239 new_entry
= wmalloc(sizeof(WAppIconChain
));
4240 new_entry
->aicon
= aicon
;
4241 new_entry
->next
= scr
->global_icons
;
4242 scr
->global_icons
= new_entry
;
4243 scr
->global_icon_count
++;
4245 aicon
->omnipresent
= 0;
4249 aicon
->omnipresent
= 0;
4250 if (aicon
== scr
->global_icons
->aicon
) {
4251 tmp
= scr
->global_icons
->next
;
4252 wfree(scr
->global_icons
);
4253 scr
->global_icons
= tmp
;
4254 scr
->global_icon_count
--;
4256 tmp
= scr
->global_icons
;
4258 if (tmp
->next
->aicon
== aicon
) {
4259 tmp1
= tmp
->next
->next
;
4262 scr
->global_icon_count
--;
4270 wAppIconPaint(aicon
);
4275 static void drawerAppendToChain(WScreen
*scr
, WDock
*drawer
)
4277 WDrawerChain
**where_to_add
;
4279 where_to_add
= &scr
->drawers
;
4280 while ((*where_to_add
) != NULL
) {
4281 where_to_add
= &(*where_to_add
)->next
;
4284 *where_to_add
= wmalloc(sizeof(WDrawerChain
));
4285 (*where_to_add
)->adrawer
= drawer
;
4286 (*where_to_add
)->next
= NULL
;
4287 scr
->drawer_count
++;
4291 static void drawerRemoveFromChain(WScreen
*scr
, WDock
*drawer
)
4293 WDrawerChain
*next
, **to_remove
;
4295 to_remove
= &scr
->drawers
;
4297 if (*to_remove
== NULL
) {
4298 wwarning("The drawer to be removed can not be found.");
4301 if ((*to_remove
)->adrawer
== drawer
)
4304 to_remove
= &(*to_remove
)->next
;
4306 next
= (*to_remove
)->next
;
4309 scr
->drawer_count
--;
4313 /* Don't free the returned string. Duplicate it. */
4314 static char * findUniqueName(WScreen
*scr
, const char *instance_basename
)
4316 static char buffer
[128];
4319 Bool already_in_use
= True
;
4321 #define UNIQUE_NAME_WATCHDOG 128
4322 for (i
= 0; already_in_use
&& i
< UNIQUE_NAME_WATCHDOG
; i
++) {
4323 snprintf(buffer
, sizeof buffer
, "%s%d", instance_basename
, i
);
4325 already_in_use
= False
;
4327 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4328 if (!strncmp(dc
->adrawer
->icon_array
[0]->wm_instance
, buffer
,
4330 already_in_use
= True
;
4336 if (i
== UNIQUE_NAME_WATCHDOG
)
4337 wwarning("Couldn't find a unique name for drawer in %d attempts.", i
);
4338 #undef UNIQUE_NAME_WATCHDOG
4344 static void drawerIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
4346 /* Parameter not used, but tell the compiler that it is ok */
4349 wDrawerIconPaint((WAppIcon
*) desc
->parent
);
4353 static int addADrawer(WScreen
*scr
)
4355 int i
, y
, sig
, found_y
;
4356 WDock
*drawer
, *dock
= scr
->dock
;
4358 char can_be_here
[2 * dock
->max_icons
- 1];
4360 if (dock
->icon_count
+ scr
->drawer_count
>= dock
->max_icons
)
4363 for (y
= -dock
->max_icons
+ 1; y
< dock
->max_icons
; y
++) {
4364 can_be_here
[y
+ dock
->max_icons
- 1] = True
;
4366 for (i
= 0; i
< dock
->max_icons
; i
++) {
4367 if (dock
->icon_array
[i
] != NULL
)
4368 can_be_here
[dock
->icon_array
[i
]->yindex
+ dock
->max_icons
- 1] = False
;
4370 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4371 y
= (int) ((dc
->adrawer
->y_pos
- dock
->y_pos
) / ICON_SIZE
);
4372 can_be_here
[y
+ dock
->max_icons
- 1] = False
;
4376 for (sig
= 1; !found_y
&& sig
> -2; sig
-= 2) // 1, then -1
4378 for (y
= sig
; sig
* y
< dock
->max_icons
; y
+= sig
)
4380 if (can_be_here
[y
+ dock
->max_icons
- 1] &&
4381 onScreen(scr
, dock
->x_pos
, dock
->y_pos
+ y
* ICON_SIZE
))
4390 /* This can happen even when dock->icon_count + scr->drawer_count
4391 * < dock->max_icons when the dock is not aligned on an
4392 * ICON_SIZE multiple, as some space is lost above and under it */
4395 drawer
= wDockCreate(scr
, WM_DRAWER
, NULL
);
4396 drawer
->lowered
= scr
->dock
->lowered
;
4397 if (!drawer
->lowered
)
4398 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMDockLevel
);
4400 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMNormalLevel
);
4401 drawer
->auto_raise_lower
= scr
->dock
->auto_raise_lower
;
4402 drawer
->x_pos
= dock
->x_pos
;
4403 drawer
->y_pos
= dock
->y_pos
+ ICON_SIZE
* y
;
4404 drawer
->icon_array
[0]->xindex
= 0;
4405 drawer
->icon_array
[0]->yindex
= 0;
4406 drawer
->icon_array
[0]->x_pos
= drawer
->x_pos
;
4407 drawer
->icon_array
[0]->y_pos
= drawer
->y_pos
;
4408 XMoveWindow(dpy
, drawer
->icon_array
[0]->icon
->core
->window
,
4409 drawer
->icon_array
[0]->x_pos
, drawer
->icon_array
[0]->y_pos
);
4415 static void addADrawerCallback(WMenu
*menu
, WMenuEntry
*entry
)
4417 /* Parameter not used, but tell the compiler that it is ok */
4420 assert(entry
->clientdata
!=NULL
);
4421 addADrawer(((WAppIcon
*) entry
->clientdata
)->dock
->screen_ptr
);
4425 static void drawerDestroy(WDock
*drawer
)
4429 WAppIcon
*aicon
= NULL
;
4435 scr
= drawer
->screen_ptr
;
4437 /* Note regarding menus: we can't delete any dock/clip/drawer menu, because
4438 * that would (attempt to) wfree some memory in gettext library (see menu
4439 * entries that have several "versions", such like "Hide" and "Unhide"). */
4440 wDefaultPurgeInfo(drawer
->icon_array
[0]->wm_instance
,
4441 drawer
->icon_array
[0]->wm_class
);
4443 if (drawer
->icon_count
== 2) {
4444 /* Drawer contains a single appicon: dock it where the drawer was */
4445 for (i
= 1; i
< drawer
->max_icons
; i
++) {
4446 aicon
= drawer
->icon_array
[i
];
4451 wDockMoveIconBetweenDocks(drawer
, scr
->dock
, aicon
,
4452 0, (drawer
->y_pos
- scr
->dock
->y_pos
) / ICON_SIZE
);
4453 XMoveWindow(dpy
, aicon
->icon
->core
->window
, drawer
->x_pos
, drawer
->y_pos
);
4454 XMapWindow(dpy
, aicon
->icon
->core
->window
);
4455 } else if (drawer
->icon_count
> 2) {
4456 icons
= WMCreateArray(drawer
->icon_count
- 1);
4457 for (i
= 1; i
< drawer
->max_icons
; i
++) {
4458 aicon
= drawer
->icon_array
[i
];
4461 WMAddToArray(icons
, aicon
);
4463 removeIcons(icons
, drawer
);
4466 if (drawer
->auto_collapse_magic
) {
4467 WMDeleteTimerHandler(drawer
->auto_collapse_magic
);
4468 drawer
->auto_collapse_magic
= NULL
;
4470 if (drawer
->auto_lower_magic
) {
4471 WMDeleteTimerHandler(drawer
->auto_lower_magic
);
4472 drawer
->auto_lower_magic
= NULL
;
4475 wAppIconDestroy(drawer
->icon_array
[0]);
4476 wfree(drawer
->icon_array
);
4477 drawer
->icon_array
= NULL
;
4479 drawerRemoveFromChain(scr
, drawer
);
4480 if (scr
->last_dock
== drawer
)
4481 scr
->last_dock
= NULL
;
4482 if (scr
->attracting_drawer
== drawer
)
4483 scr
->attracting_drawer
= NULL
;
4489 static void removeDrawerCallback(WMenu
*menu
, WMenuEntry
*entry
)
4491 WDock
*dock
= ((WAppIcon
*)entry
->clientdata
)->dock
;
4493 /* Parameter not used, but tell the compiler that it is ok */
4496 assert(dock
!= NULL
);
4498 if (dock
->icon_count
> 2) {
4499 if (wMessageDialog(dock
->screen_ptr
, _("Drawer"),
4500 _("All icons in this drawer will be detached!"),
4501 _("OK"), _("Cancel"), NULL
) != WAPRDefault
)
4504 drawerDestroy(dock
);
4508 void wDrawerIconPaint(WAppIcon
*dicon
)
4510 Window win
= dicon
->icon
->core
->window
;
4511 WScreen
*scr
= dicon
->icon
->core
->screen_ptr
;
4513 GC gc
= scr
->draw_gc
;
4516 wIconPaint(dicon
->icon
);
4518 if (!dicon
->dock
->collapsed
)
4519 color
= scr
->clip_title_color
[CLIP_NORMAL
];
4521 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
4522 XSetForeground(dpy
, gc
, WMColorPixel(color
));
4524 if (dicon
->dock
->on_right_side
) {
4525 p
[0].x
= p
[3].x
= 10;
4526 p
[0].y
= p
[3].y
= ICON_SIZE
/ 2 - 5;
4528 p
[1].y
= ICON_SIZE
/ 2 + 5;
4530 p
[2].y
= ICON_SIZE
/ 2;
4533 p
[0].x
= p
[3].x
= ICON_SIZE
-1 - 10;
4534 p
[0].y
= p
[3].y
= ICON_SIZE
/ 2 - 5;
4535 p
[1].x
= ICON_SIZE
-1 - 10;
4536 p
[1].y
= ICON_SIZE
/ 2 + 5;
4537 p
[2].x
= ICON_SIZE
-1 - 5;
4538 p
[2].y
= ICON_SIZE
/ 2;
4540 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
4541 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
4545 RImage
* wDrawerMakeTile(WScreen
*scr
, RImage
*normalTile
)
4547 RImage
*tile
= RCloneImage(normalTile
);
4552 dark
.red
= dark
.green
= dark
.blue
= 60;
4555 light
.red
= light
.green
= light
.blue
= 80;
4558 if (!scr
->dock
|| scr
->dock
->on_right_side
) {
4559 ROperateLine(tile
, RSubtractOperation
, 11, ICON_SIZE
/ 2 - 7,
4560 4, ICON_SIZE
/ 2, &dark
); /* / */
4561 ROperateLine(tile
, RSubtractOperation
, 11, ICON_SIZE
/ 2 + 7,
4562 4, ICON_SIZE
/ 2, &dark
); /* \ */
4563 ROperateLine(tile
, RAddOperation
, 11, ICON_SIZE
/ 2 - 7,
4564 11, ICON_SIZE
/ 2 + 7, &light
); /* | */
4567 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 - 7,
4568 ICON_SIZE
-1 - 4, ICON_SIZE
/ 2, &dark
); /* \ */
4569 ROperateLine(tile
, RAddOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 + 7,
4570 ICON_SIZE
-1 - 4, ICON_SIZE
/ 2, &light
); /* / */
4571 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 - 7,
4572 ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 + 7, &dark
); /* | */
4578 static void swapDrawer(WDock
*drawer
, int new_x
)
4582 drawer
->on_right_side
= !drawer
->on_right_side
;
4583 drawer
->x_pos
= new_x
;
4585 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4588 ai
= drawer
->icon_array
[i
];
4591 ai
->xindex
*= -1; /* so A B C becomes C B A */
4592 ai
->x_pos
= new_x
+ ai
->xindex
* ICON_SIZE
;
4594 /* Update drawer's tile */
4596 wIconUpdate(ai
->icon
);
4597 wDrawerIconPaint(ai
);
4599 XMoveWindow(dpy
, ai
->icon
->core
->window
, ai
->x_pos
, ai
->y_pos
);
4604 static void swapDrawers(WScreen
*scr
, int new_x
)
4608 if (scr
->drawer_tile
)
4609 RReleaseImage(scr
->drawer_tile
);
4611 scr
->drawer_tile
= wDrawerMakeTile(scr
, scr
->icon_tile
);
4613 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
4614 swapDrawer(dc
->adrawer
, new_x
);
4618 int wIsADrawer(WAppIcon
*aicon
)
4620 return aicon
&& aicon
->dock
&&
4621 aicon
->dock
->type
== WM_DRAWER
&& aicon
->dock
->icon_array
[0] == aicon
;
4625 static WDock
* getDrawer(WScreen
*scr
, int y_index
)
4629 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4630 if (dc
->adrawer
->y_pos
- scr
->dock
->y_pos
== y_index
* ICON_SIZE
)
4638 /* Find the "hole" a moving appicon created when snapped into the
4639 * drawer. redocking is a boolean. If the moving appicon comes from the
4640 * drawer, drawer->icon_count is correct. If not, redocking is then false and
4641 * there are now drawer->icon_count plus one appicons in the drawer. */
4642 static int indexOfHole(WDock
*drawer
, WAppIcon
*moving_aicon
, int redocking
)
4644 int index_of_hole
, i
;
4646 /* Classic interview question...
4648 * We have n-1 (n = drawer->icon_count-1 or drawer->icon_count, see
4649 * redocking) appicons, whose xindex are unique in [1..n]. One is missing:
4650 * that's where the ghost of the moving appicon is, that's what the
4651 * function should return.
4653 * We compute 1+2+...+n (this sum is equal to n*(n+1)/2), we subtract to
4654 * this sum the xindex of each of the n-1 appicons, and we get the correct
4658 index_of_hole
= (drawer
->icon_count
- 1) * drawer
->icon_count
/ 2;
4660 index_of_hole
= drawer
->icon_count
* (drawer
->icon_count
+ 1) / 2;
4662 index_of_hole
*= (drawer
->on_right_side
? -1 : 1);
4664 for (i
= 1; i
< drawer
->max_icons
; i
++) {
4665 if (drawer
->icon_array
[i
] && drawer
->icon_array
[i
] != moving_aicon
)
4666 index_of_hole
-= drawer
->icon_array
[i
]->xindex
;
4668 /* wmessage(" Index of the moving appicon is %d (%sredocking)", index_of_hole, (redocking ? "" : "not ")); */
4669 if (abs(index_of_hole
) > abs(drawer
->icon_count
) - (redocking
? 1 : 0))
4670 wwarning(" index_of_hole is too large ! (%d greater than %d)",
4671 index_of_hole
, abs(drawer
->icon_count
) - (redocking
? 1 : 0));
4672 if (index_of_hole
== 0)
4673 wwarning(" index_of_hole == 0 (%sredocking, icon_count == %d)", (redocking
? "" : "not "), drawer
->icon_count
);
4675 return index_of_hole
;
4679 void wSlideAppicons(WAppIcon
**appicons
, int n
, int to_the_left
)
4682 int leftmost
= -1, min_index
= 9999, from_x
= -1; // leftmost and from_x initialized to avoid warning
4689 for (i
= 0; i
< n
; i
++) {
4690 aicon
= appicons
[i
];
4691 aicon
->xindex
+= (to_the_left
? -1 : +1);
4692 if (aicon
->xindex
< min_index
) {
4693 min_index
= aicon
->xindex
;
4695 from_x
= aicon
->x_pos
;
4697 aicon
->x_pos
+= (to_the_left
? -ICON_SIZE
: +ICON_SIZE
);
4700 for (i
= 0; i
< n
; i
++) {
4701 aicon
= appicons
[i
];
4702 wins
[aicon
->xindex
- min_index
] = aicon
->icon
->core
->window
;
4704 aicon
= appicons
[leftmost
];
4705 slide_windows(wins
, n
, from_x
, aicon
->y_pos
, aicon
->x_pos
, aicon
->y_pos
);
4709 void wDrawerFillTheGap(WDock
*drawer
, WAppIcon
*aicon
, Bool redocking
)
4712 int index_of_hole
= indexOfHole(drawer
, aicon
, redocking
);
4713 WAppIcon
*aicons_to_shift
[drawer
->icon_count
];
4716 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4717 WAppIcon
*ai
= drawer
->icon_array
[i
];
4718 if (ai
&& ai
!= aicon
&&
4719 abs(ai
->xindex
) > abs(index_of_hole
))
4720 aicons_to_shift
[j
++] = ai
;
4722 if (j
!= drawer
->icon_count
- abs(index_of_hole
) - (redocking
? 1 : 0))
4723 wwarning("Removing aicon at index %d from %s: j=%d but should be %d",
4724 index_of_hole
, drawer
->icon_array
[0]->wm_instance
,
4725 j
, drawer
->icon_count
- abs(index_of_hole
) - (redocking
? 1 : 0));
4726 wSlideAppicons(aicons_to_shift
, j
, !drawer
->on_right_side
);
4730 static void drawerConsolidateIcons(WDock
*drawer
)
4732 WAppIcon
*aicons_to_shift
[drawer
->icon_count
];
4733 int maxRemaining
= 0;
4736 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4737 WAppIcon
*ai
= drawer
->icon_array
[i
];
4740 sum
+= abs(ai
->xindex
);
4741 if (abs(ai
->xindex
) > maxRemaining
)
4742 maxRemaining
= abs(ai
->xindex
);
4744 while (sum
!= maxRemaining
* (maxRemaining
+ 1) / 2) { // while there is a hole
4747 // Look up for the hole at max position
4749 for (maxDeleted
= maxRemaining
- 1; maxDeleted
> 0; maxDeleted
--) {
4750 Bool foundAppIconThere
= False
;
4751 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4752 WAppIcon
*ai
= drawer
->icon_array
[i
];
4755 if (abs(ai
->xindex
) == maxDeleted
) {
4756 foundAppIconThere
= True
;
4760 if (!foundAppIconThere
)
4763 assert(maxDeleted
> 0); // would mean while test is wrong
4765 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4766 ai
= drawer
->icon_array
[i
];
4767 if (ai
!= NULL
&& abs(ai
->xindex
) > maxDeleted
)
4768 aicons_to_shift
[n
++] = ai
;
4770 assert(n
== maxRemaining
- maxDeleted
); // for the code review ;-)
4771 wSlideAppicons(aicons_to_shift
, n
, !drawer
->on_right_side
);
4772 // Efficient beancounting
4780 /* similar to wDockRestoreState, but a lot a specific stuff too... */
4781 static WDock
* drawerRestoreState(WScreen
*scr
, WMPropList
*drawer_state
)
4784 WMPropList
*apps
, *value
, *dock_state
;
4793 WMRetainPropList(drawer_state
);
4795 /* Get the instance name, and create a drawer */
4796 value
= WMGetFromPLDictionary(drawer_state
, dName
);
4797 drawer
= wDockCreate(scr
, WM_DRAWER
, WMGetFromPLString(value
));
4799 /* restore DnD command and paste command */
4800 #ifdef USE_DOCK_XDND
4801 value
= WMGetFromPLDictionary(drawer_state
, dDropCommand
);
4802 if (value
&& WMIsPLString(value
))
4803 drawer
->icon_array
[0]->dnd_command
= wstrdup(WMGetFromPLString(value
));
4804 #endif /* USE_DOCK_XDND */
4806 value
= WMGetFromPLDictionary(drawer_state
, dPasteCommand
);
4807 if (value
&& WMIsPLString(value
))
4808 drawer
->icon_array
[0]->paste_command
= wstrdup(WMGetFromPLString(value
));
4810 /* restore position */
4811 value
= WMGetFromPLDictionary(drawer_state
, dPosition
);
4812 if (!value
|| !WMIsPLString(value
))
4813 COMPLAIN("Position");
4816 if (sscanf(WMGetFromPLString(value
), "%i,%i", &x
, &y
) != 2)
4817 COMPLAIN("Position");
4819 /* check position sanity */
4820 if (x
!= scr
->dock
->x_pos
) {
4821 x
= scr
->dock
->x_pos
;
4823 y_index
= (y
- scr
->dock
->y_pos
) / ICON_SIZE
;
4824 if (y_index
>= scr
->dock
->max_icons
) {
4825 /* Here we should do something more intelligent, since it
4826 * can happen even if the user hasn't hand-edited his
4827 * G/D/State file (but uses a lower resolution). */
4828 y_index
= scr
->dock
->max_icons
- 1;
4830 y
= scr
->dock
->y_pos
+ y_index
* ICON_SIZE
;
4831 moveDock(drawer
, x
, y
);
4834 /* restore dock properties (applist and others) */
4835 dock_state
= WMGetFromPLDictionary(drawer_state
, dDock
);
4837 /* restore lowered/raised state: same as scr->dock, no matter what */
4838 drawer
->lowered
= scr
->dock
->lowered
;
4839 if (!drawer
->lowered
)
4840 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMDockLevel
);
4842 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMNormalLevel
);
4843 wRaiseFrame(drawer
->icon_array
[0]->icon
->core
);
4845 /* restore collapsed state */
4846 drawer
->collapsed
= 0;
4847 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
4848 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4849 drawer
->collapsed
= 1;
4851 /* restore auto-collapsed state */
4852 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
4853 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4854 drawer
->auto_collapse
= 1;
4855 drawer
->collapsed
= 1;
4857 drawer
->auto_collapse
= 0; // because wDockCreate sets it (drawers only)
4860 /* restore auto-raise/lower state: same as scr->dock, no matter what */
4861 drawer
->auto_raise_lower
= scr
->dock
->auto_raise_lower
;
4863 /* restore attract icons state */
4864 drawer
->attract_icons
= 0;
4865 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
4866 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4867 drawer
->attract_icons
= 1;
4868 scr
->attracting_drawer
= drawer
;
4871 /* application list */
4872 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
4878 count
= WMGetPropListItemCount(apps
);
4883 for (i
=0; i
<count
; i
++) {
4884 if (drawer
->icon_count
>= drawer
->max_icons
) {
4885 wwarning(_("there are too many icons stored in drawer. Ignoring what doesn't fit"));
4889 value
= WMGetFromPLArray(apps
, i
);
4890 aicon
= restore_icon_state(scr
, value
, WM_DRAWER
, drawer
->icon_count
);
4892 drawer
->icon_array
[drawer
->icon_count
] = aicon
;
4895 aicon
->dock
= drawer
;
4896 aicon
->x_pos
= drawer
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
4897 aicon
->y_pos
= drawer
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
4899 if (!drawer
->lowered
)
4900 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
4902 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
4904 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
4906 if (!drawer
->collapsed
)
4907 XMapWindow(dpy
, aicon
->icon
->core
->window
);
4908 wRaiseFrame(aicon
->icon
->core
);
4910 drawer
->icon_count
++;
4915 WMReleasePropList(drawer_state
);
4921 /* Same kind of comment than for previous function: this function is
4922 * very similar to make_icon_state, but has substential differences as
4924 static WMPropList
*drawerSaveState(WDock
*drawer
)
4926 WMPropList
*pstr
, *drawer_state
;
4930 ai
= drawer
->icon_array
[0];
4931 /* Store its name */
4932 pstr
= WMCreatePLString(ai
->wm_instance
);
4933 drawer_state
= WMCreatePLDictionary(dName
, pstr
, NULL
); /* we need this final NULL */
4934 WMReleasePropList(pstr
);
4936 /* Store its position */
4937 snprintf(buffer
, sizeof(buffer
), "%i,%i", ai
->x_pos
, ai
->y_pos
);
4938 pstr
= WMCreatePLString(buffer
);
4939 WMPutInPLDictionary(drawer_state
, dPosition
, pstr
);
4940 WMReleasePropList(pstr
);
4942 #ifdef USE_DOCK_XDND
4943 /* Store its DnD command */
4944 if (ai
->dnd_command
) {
4945 pstr
= WMCreatePLString(ai
->dnd_command
);
4946 WMPutInPLDictionary(drawer_state
, dDropCommand
, pstr
);
4947 WMReleasePropList(pstr
);
4949 #endif /* USE_DOCK_XDND */
4951 /* Store its paste command */
4952 if (ai
->paste_command
) {
4953 pstr
= WMCreatePLString(ai
->paste_command
);
4954 WMPutInPLDictionary(drawer_state
, dPasteCommand
, pstr
);
4955 WMReleasePropList(pstr
);
4958 /* Store applications list and other properties */
4959 pstr
= dockSaveState(drawer
);
4960 WMPutInPLDictionary(drawer_state
, dDock
, pstr
);
4961 WMReleasePropList(pstr
);
4963 return drawer_state
;
4967 void wDrawersSaveState(WScreen
*scr
)
4969 WMPropList
*all_drawers
, *drawer_state
;
4975 all_drawers
= WMCreatePLArray(NULL
);
4976 for (i
=0, dc
= scr
->drawers
;
4977 i
< scr
->drawer_count
;
4978 i
++, dc
= dc
->next
) {
4979 drawer_state
= drawerSaveState(dc
->adrawer
);
4980 WMAddToPLArray(all_drawers
, drawer_state
);
4981 WMReleasePropList(drawer_state
);
4983 WMPutInPLDictionary(scr
->session_state
, dDrawers
, all_drawers
);
4984 WMReleasePropList(all_drawers
);
4988 void wDrawersRestoreState(WScreen
*scr
)
4990 WMPropList
*all_drawers
, *drawer_state
;
4995 if (scr
->session_state
== NULL
)
4998 all_drawers
= WMGetFromPLDictionary(scr
->session_state
, dDrawers
);
5002 for (i
= 0; i
< WMGetPropListItemCount(all_drawers
); i
++) {
5003 drawer_state
= WMGetFromPLArray(all_drawers
, i
);
5004 drawerRestoreState(scr
, drawer_state
);
5005 // Note: scr->drawers was updated when the the drawer was created