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
7 * Copyright (c) 2009-2023 Window Maker Team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <X11/Xutil.h>
38 #define PATH_MAX DEFAULT_PATH_MAX
41 #include "WindowMaker.h"
49 #include "dockedapp.h"
52 #include "properties.h"
56 #include "workspace.h"
58 #include "superfluous.h"
60 #include "placement.h"
64 /**** Local variables ****/
67 #define CLIP_FORWARD 2
69 #define MOD_MASK wPreferences.modifier_mask
70 #define ICON_SIZE wPreferences.icon_size
72 /***** Local variables ****/
74 static WMPropList
*dCommand
= NULL
;
75 static WMPropList
*dPasteCommand
= NULL
;
77 static WMPropList
*dDropCommand
= NULL
;
79 static WMPropList
*dAutoLaunch
, *dLock
;
80 static WMPropList
*dName
, *dForced
, *dBuggyApplication
, *dYes
, *dNo
;
81 static WMPropList
*dHost
, *dDock
, *dClip
;
82 static WMPropList
*dAutoAttractIcons
;
84 static WMPropList
*dPosition
, *dApplications
, *dLowered
, *dCollapsed
;
86 static WMPropList
*dAutoCollapse
, *dAutoRaiseLower
, *dOmnipresent
;
88 static WMPropList
*dDrawers
= NULL
;
90 static void dockIconPaint(WAppIcon
*btn
);
92 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
94 static pid_t
execCommand(WAppIcon
*btn
, const char *command
, WSavedState
*state
);
96 static void trackDeadProcess(pid_t pid
, unsigned int status
, void *cdata
);
98 static int getClipButton(int px
, int py
);
100 static void toggleLowered(WDock
*dock
);
102 static void toggleCollapsed(WDock
*dock
);
104 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
106 static void clipLeave(WDock
*dock
);
108 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
110 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
111 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
112 static void clipAutoCollapse(void *cdata
);
113 static void clipAutoExpand(void *cdata
);
114 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
);
116 static void clipAutoLower(void *cdata
);
117 static void clipAutoRaise(void *cdata
);
118 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
, const char *name
);
120 static void drawerIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
121 static void removeDrawerCallback(WMenu
*menu
, WMenuEntry
*entry
);
122 static void drawerAppendToChain(WScreen
*scr
, WDock
*drawer
);
123 static char *findUniqueName(WScreen
*scr
, const char *instance_basename
);
124 static void addADrawerCallback(WMenu
*menu
, WMenuEntry
*entry
);
125 static void swapDrawers(WScreen
*scr
, int new_x
);
126 static WDock
* getDrawer(WScreen
*scr
, int y_index
);
127 static int indexOfHole(WDock
*drawer
, WAppIcon
*moving_aicon
, int redocking
);
128 static void drawerConsolidateIcons(WDock
*drawer
);
130 static int onScreen(WScreen
*scr
, int x
, int y
);
132 static void make_keys(void)
134 if (dCommand
!= NULL
)
137 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
138 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
140 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
142 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
143 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
144 dName
= WMRetainPropList(WMCreatePLString("Name"));
145 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
146 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
147 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
148 dNo
= WMRetainPropList(WMCreatePLString("No"));
149 dHost
= WMRetainPropList(WMCreatePLString("Host"));
151 dPosition
= WMCreatePLString("Position");
152 dApplications
= WMCreatePLString("Applications");
153 dLowered
= WMCreatePLString("Lowered");
154 dCollapsed
= WMCreatePLString("Collapsed");
155 dAutoCollapse
= WMCreatePLString("AutoCollapse");
156 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
157 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
159 dOmnipresent
= WMCreatePLString("Omnipresent");
161 dDock
= WMCreatePLString("Dock");
162 dClip
= WMCreatePLString("Clip");
163 dDrawers
= WMCreatePLString("Drawers");
166 static void renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
168 WDock
*dock
= entry
->clientdata
;
173 /* Parameter not used, but tell the compiler that it is ok */
176 assert(entry
->clientdata
!= NULL
);
178 wspace
= dock
->screen_ptr
->current_workspace
;
180 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
182 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+ 1);
183 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
, &name
))
184 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
189 static void toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
191 assert(entry
->clientdata
!= NULL
);
193 toggleLowered(entry
->clientdata
);
195 entry
->flags
.indicator_on
= !(((WDock
*) entry
->clientdata
)->lowered
);
200 static int matchWindow(const void *item
, const void *cdata
)
202 return (((WFakeGroupLeader
*) item
)->leader
== (Window
) cdata
);
205 static void killCallback(WMenu
*menu
, WMenuEntry
*entry
)
207 WScreen
*scr
= menu
->menu
->screen_ptr
;
209 WFakeGroupLeader
*fPtr
;
210 char *buffer
, *shortname
, **argv
;
213 if (!WCHECK_STATE(WSTATE_NORMAL
))
216 assert(entry
->clientdata
!= NULL
);
218 icon
= (WAppIcon
*) entry
->clientdata
;
222 WCHANGE_STATE(WSTATE_MODAL
);
224 /* strip away dir names */
225 shortname
= basename(icon
->command
);
226 /* separate out command options */
227 wtokensplit(shortname
, &argv
, &argc
);
229 buffer
= wstrconcat(argv
[0],
230 _(" will be forcibly closed.\n"
231 "Any unsaved changes will be lost.\n" "Please confirm."));
233 if (icon
->icon
&& icon
->icon
->owner
) {
234 fPtr
= icon
->icon
->owner
->fake_group
;
236 /* is this really necessary? can we kill a non-running dock icon? */
237 Window win
= icon
->main_window
;
240 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)win
);
241 if (index
!= WANotFound
)
242 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
247 if (wPreferences
.dont_confirm_kill
248 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
249 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
251 WWindow
*wwin
, *twin
;
253 wwin
= scr
->focused_window
;
256 if (wwin
->fake_group
== fPtr
)
261 } else if (icon
->icon
&& icon
->icon
->owner
) {
262 wClientKill(icon
->icon
->owner
);
267 wtokenfree(argv
, argc
);
271 WCHANGE_STATE(WSTATE_NORMAL
);
274 /* TODO: replace this function with a member of the dock struct */
275 static int numberOfSelectedIcons(WDock
*dock
)
281 for (i
= 1; i
< dock
->max_icons
; i
++) {
282 aicon
= dock
->icon_array
[i
];
283 if (aicon
&& aicon
->icon
->selected
)
290 static WMArray
*getSelected(WDock
*dock
)
292 WMArray
*ret
= WMCreateArray(8);
296 for (i
= 1; i
< dock
->max_icons
; i
++) {
297 btn
= dock
->icon_array
[i
];
298 if (btn
&& btn
->icon
->selected
)
299 WMAddToArray(ret
, btn
);
305 static void paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
307 Window win
= clipIcon
->icon
->core
->window
;
308 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
310 int pt
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
311 int tp
= ICON_SIZE
- pt
;
312 int as
= pt
- 15; /* 15 = 5+5+5 */
313 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
316 color
= scr
->clip_title_color
[CLIP_NORMAL
];
318 XSetForeground(dpy
, gc
, WMColorPixel(color
));
323 p
[1].x
= ICON_SIZE
- 2;
325 p
[2].x
= ICON_SIZE
- 2;
327 } else if (lpushed
) {
331 p
[1].y
= ICON_SIZE
- 2;
333 p
[2].y
= ICON_SIZE
- 2;
335 if (lpushed
|| rpushed
) {
336 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
337 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
338 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
341 /* top right arrow */
342 p
[0].x
= p
[3].x
= ICON_SIZE
- 5 - as
;
344 p
[1].x
= ICON_SIZE
- 6;
346 p
[2].x
= ICON_SIZE
- 6;
349 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
350 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
352 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
353 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
356 /* bottom left arrow */
358 p
[0].y
= p
[3].y
= ICON_SIZE
- 5 - as
;
360 p
[1].y
= ICON_SIZE
- 6;
362 p
[2].y
= ICON_SIZE
- 6;
364 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
365 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
367 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
368 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
372 RImage
*wClipMakeTile(RImage
*normalTile
)
374 RImage
*tile
= RCloneImage(normalTile
);
381 pt
= CLIP_BUTTON_SIZE
* wPreferences
.icon_size
/ 64;
382 tp
= wPreferences
.icon_size
- 1 - pt
;
386 black
.red
= black
.green
= black
.blue
= 0;
389 dark
.red
= dark
.green
= dark
.blue
= 60;
392 light
.red
= light
.green
= light
.blue
= 80;
395 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
- 2, pt
- 1, &dark
);
396 RDrawLine(tile
, tp
- 1, 0, wPreferences
.icon_size
- 1, pt
+ 1, &black
);
397 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
- 3, pt
, &light
);
400 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, 4, &dark
);
401 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 5, 6 + as
, &dark
);
402 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
, &light
);
405 ROperateLine(tile
, RAddOperation
, 2, tp
+ 2, pt
- 2, wPreferences
.icon_size
- 3, &dark
);
406 RDrawLine(tile
, 0, tp
- 1, pt
+ 1, wPreferences
.icon_size
- 1, &black
);
407 ROperateLine(tile
, RSubtractOperation
, 0, tp
- 2, pt
+ 1, wPreferences
.icon_size
- 2, &light
);
410 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, &dark
);
411 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
, 6 + as
, ICON_SIZE
- 5, &dark
);
412 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5, &light
);
417 static void omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
419 WAppIcon
*clickedIcon
= entry
->clientdata
;
422 WMArray
*selectedIcons
;
423 WMArrayIterator iter
;
426 /* Parameter not used, but tell the compiler that it is ok */
429 assert(entry
->clientdata
!= NULL
);
431 dock
= clickedIcon
->dock
;
433 selectedIcons
= getSelected(dock
);
435 if (!WMGetArrayItemCount(selectedIcons
))
436 WMAddToArray(selectedIcons
, clickedIcon
);
439 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
440 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
442 else if (aicon
->icon
->selected
)
443 wIconSelect(aicon
->icon
);
445 WMFreeArray(selectedIcons
);
448 wMessageDialog(dock
->screen_ptr
, _("Warning"),
449 _("Some icons cannot be made omnipresent. "
450 "Please make sure that no other icon is "
451 "docked in the same positions on the other "
452 "workspaces and the Clip is not full in "
453 "some workspace."), _("OK"), NULL
, NULL
);
454 } else if (failed
== 1) {
455 wMessageDialog(dock
->screen_ptr
, _("Warning"),
456 _("Icon cannot be made omnipresent. "
457 "Please make sure that no other icon is "
458 "docked in the same position on the other "
459 "workspaces and the Clip is not full in "
460 "some workspace."), _("OK"), NULL
, NULL
);
464 static void removeIcons(WMArray
*icons
, WDock
*dock
)
470 WM_ITERATE_ARRAY(icons
, aicon
, it
) {
471 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
472 wDockDetach(dock
, aicon
);
474 /* XXX: can: aicon->icon == NULL ? */
475 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
476 wGetHeadForWindow(aicon
->icon
->owner
));
477 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
478 if (!dock
->mapped
|| dock
->collapsed
)
479 XMapWindow(dpy
, aicon
->icon
->core
->window
);
484 if (wPreferences
.auto_arrange_icons
)
485 wArrangeIcons(dock
->screen_ptr
, True
);
488 static void removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
490 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
492 WMArray
*selectedIcons
;
494 /* Parameter not used, but tell the compiler that it is ok */
497 assert(clickedIcon
!= NULL
);
499 dock
= clickedIcon
->dock
;
501 selectedIcons
= getSelected(dock
);
503 if (WMGetArrayItemCount(selectedIcons
)) {
504 if (wMessageDialog(dock
->screen_ptr
,
505 dock
->type
== WM_CLIP
? _("Workspace Clip") : _("Drawer"),
506 _("All selected icons will be removed!"),
507 _("OK"), _("Cancel"), NULL
) != WAPRDefault
) {
508 WMFreeArray(selectedIcons
);
512 if (clickedIcon
->xindex
== 0 && clickedIcon
->yindex
== 0) {
513 WMFreeArray(selectedIcons
);
516 WMAddToArray(selectedIcons
, clickedIcon
);
519 removeIcons(selectedIcons
, dock
);
521 if (dock
->type
== WM_DRAWER
) {
522 drawerConsolidateIcons(dock
);
526 static void keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
528 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
531 WMArray
*selectedIcons
;
534 /* Parameter not used, but tell the compiler that it is ok */
537 assert(clickedIcon
!= NULL
);
538 dock
= clickedIcon
->dock
;
540 selectedIcons
= getSelected(dock
);
542 if (!WMGetArrayItemCount(selectedIcons
)
543 && clickedIcon
!= dock
->screen_ptr
->clip_icon
) {
544 char *command
= NULL
;
546 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
547 clickedIcon
->editing
= 1;
548 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
549 _("Type the command used to launch the application"), &command
)) {
550 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
554 clickedIcon
->command
= command
;
555 clickedIcon
->editing
= 0;
557 clickedIcon
->editing
= 0;
560 WMFreeArray(selectedIcons
);
565 WMAddToArray(selectedIcons
, clickedIcon
);
568 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
569 if (aicon
->icon
->selected
)
570 wIconSelect(aicon
->icon
);
572 if (aicon
->attracted
&& aicon
->command
) {
573 aicon
->attracted
= 0;
574 if (aicon
->icon
->shadowed
) {
575 aicon
->icon
->shadowed
= 0;
578 * Update icon pixmap, RImage doesn't change,
579 * so call wIconUpdate is not needed
581 update_icon_pixmap(aicon
->icon
);
584 wAppIconPaint(aicon
);
589 WMFreeArray(selectedIcons
);
592 static void toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
594 WDock
*dock
= (WDock
*) entry
->clientdata
;
595 WScreen
*scr
= dock
->screen_ptr
;
597 assert(entry
->clientdata
!= NULL
);
599 dock
->attract_icons
= !dock
->attract_icons
;
601 entry
->flags
.indicator_on
= dock
->attract_icons
;
605 if (dock
->attract_icons
) {
606 if (dock
->type
== WM_DRAWER
) {
607 /* The newly auto-attracting dock is a drawer: disable any clip and
608 * previously attracting drawer */
610 if (!wPreferences
.flags
.noclip
) {
612 for (i
= 0; i
< scr
->workspace_count
; i
++)
613 scr
->workspaces
[ i
]->clip
->attract_icons
= False
;
614 /* dock menu will be updated later, when opened */
617 if (scr
->attracting_drawer
!= NULL
)
618 scr
->attracting_drawer
->attract_icons
= False
;
619 scr
->attracting_drawer
= dock
;
621 /* The newly auto-attracting dock is a clip: disable
622 * previously attracting drawer, if applicable */
623 if (scr
->attracting_drawer
!= NULL
) {
624 scr
->attracting_drawer
->attract_icons
= False
;
625 /* again, its menu will be updated, later. */
626 scr
->attracting_drawer
= NULL
;
632 static void selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
634 WAppIcon
*icon
= (WAppIcon
*) entry
->clientdata
;
636 assert(icon
!= NULL
);
638 wIconSelect(icon
->icon
);
643 static void attractIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
645 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
646 WDock
*clip
; /* clip... is a WM_CLIP or a WM_DRAWER */
648 int x
, y
, x_pos
, y_pos
;
649 Bool update_icon
= False
;
651 /* Parameter not used, but tell the compiler that it is ok */
654 assert(entry
->clientdata
!= NULL
);
655 clip
= clickedIcon
->dock
;
657 aicon
= clip
->screen_ptr
->app_icon_list
;
660 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
661 x_pos
= clip
->x_pos
+ x
* ICON_SIZE
;
662 y_pos
= clip
->y_pos
+ y
* ICON_SIZE
;
663 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
)
664 move_window(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
666 aicon
->attracted
= 1;
667 if (!aicon
->icon
->shadowed
) {
668 aicon
->icon
->shadowed
= 1;
671 wDockAttachIcon(clip
, aicon
, x
, y
, update_icon
);
672 if (clip
->collapsed
|| !clip
->mapped
)
673 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
679 static void selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
681 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
683 WMArray
*selectedIcons
;
684 WMArrayIterator iter
;
688 assert(clickedIcon
!= NULL
);
689 dock
= clickedIcon
->dock
;
691 selectedIcons
= getSelected(dock
);
693 if (!WMGetArrayItemCount(selectedIcons
)) {
694 for (i
= 1; i
< dock
->max_icons
; i
++) {
695 btn
= dock
->icon_array
[i
];
696 if (btn
&& !btn
->icon
->selected
)
697 wIconSelect(btn
->icon
);
700 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
701 wIconSelect(btn
->icon
);
704 WMFreeArray(selectedIcons
);
709 static void toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
711 assert(entry
->clientdata
!= NULL
);
713 toggleCollapsed(entry
->clientdata
);
715 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->collapsed
;
720 static void toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
723 assert(entry
->clientdata
!= NULL
);
725 dock
= (WDock
*) entry
->clientdata
;
727 dock
->auto_collapse
= !dock
->auto_collapse
;
729 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_collapse
;
734 static void toggleAutoRaiseLower(WDock
*dock
)
738 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
739 if (dock
->type
== WM_DOCK
)
741 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
742 toggleAutoRaiseLower(dc
->adrawer
);
747 static void toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
751 /* Parameter not used, but tell the compiler that it is ok */
754 assert(entry
->clientdata
!= NULL
);
756 dock
= (WDock
*) entry
->clientdata
;
758 toggleAutoRaiseLower(dock
);
760 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_raise_lower
;
765 static void launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
767 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
769 /* Parameter not used, but tell the compiler that it is ok */
772 launchDockedApplication(btn
, False
);
775 static void settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
777 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
779 /* Parameter not used, but tell the compiler that it is ok */
784 ShowDockAppSettingsPanel(btn
);
787 static void hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
790 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
792 /* Parameter not used, but tell the compiler that it is ok */
795 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
797 if (wapp
->flags
.hidden
) {
798 wWorkspaceChange(btn
->icon
->core
->screen_ptr
, wapp
->last_workspace
);
799 wUnhideApplication(wapp
, False
, False
);
801 wHideApplication(wapp
);
805 static void unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
808 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
810 /* Parameter not used, but tell the compiler that it is ok */
813 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
815 wUnhideApplication(wapp
, False
, True
);
818 static int getDockXPosition(WScreen
*scr
, Bool on_right_side
)
822 if (wPreferences
.keep_dock_on_primary_head
) {
825 rect
= wGetRectForHead(scr
, scr
->xine_info
.primary_head
);
828 x
+= rect
.size
.width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
830 x
+= DOCK_EXTRA_SPACE
;
833 x
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
835 x
= DOCK_EXTRA_SPACE
;
841 /* Name is only used when type == WM_DRAWER and when restoring a specific
842 * drawer, with a specific name. When creating a drawer, leave name to NULL
843 * and mainIconCreate will find the first unused unique name */
844 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
, const char *name
)
852 return scr
->clip_icon
;
854 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
855 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
859 default: /* to avoid a warning about btn and x_pos, basically */
860 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
861 if (wPreferences
.flags
.clip_merged_in_dock
)
862 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
863 x_pos
= getDockXPosition(scr
, True
);
867 name
= findUniqueName(scr
, "Drawer");
868 btn
= wAppIconCreateForDock(scr
, NULL
, name
, "WMDrawer", TILE_DRAWER
);
869 btn
->icon
->core
->descriptor
.handle_expose
= drawerIconExpose
;
876 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
877 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
878 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
879 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
880 btn
->icon
->core
->descriptor
.parent
= btn
;
881 XMapWindow(dpy
, btn
->icon
->core
->window
);
885 if (type
== WM_CLIP
||
886 (type
== WM_DOCK
&& wPreferences
.flags
.clip_merged_in_dock
))
887 scr
->clip_icon
= btn
;
892 static void switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
894 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
895 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
897 WMArray
*selectedIcons
;
900 /* Parameter not used, but tell the compiler that it is ok */
903 if (entry
->order
== scr
->current_workspace
)
907 dest
= scr
->workspaces
[entry
->order
]->clip
;
909 selectedIcons
= getSelected(src
);
911 if (WMGetArrayItemCount(selectedIcons
)) {
912 WMArrayIterator iter
;
914 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
915 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
916 wDockMoveIconBetweenDocks(src
, dest
, btn
, x
, y
);
917 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
920 } else if (icon
!= scr
->clip_icon
) {
921 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
922 wDockMoveIconBetweenDocks(src
, dest
, icon
, x
, y
);
923 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
926 WMFreeArray(selectedIcons
);
929 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
)
931 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
933 if (!btn
->launching
&&
934 ((!withSelection
&& btn
->command
!= NULL
) || (withSelection
&& btn
->paste_command
!= NULL
))) {
935 if (!btn
->forced_dock
) {
936 btn
->relaunching
= btn
->running
;
939 if (btn
->wm_instance
|| btn
->wm_class
) {
940 WWindowAttributes attr
;
941 memset(&attr
, 0, sizeof(WWindowAttributes
));
942 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
944 if (!attr
.no_appicon
&& !btn
->buggy_app
)
949 btn
->drop_launch
= 0;
950 btn
->paste_launch
= withSelection
;
951 scr
->last_dock
= btn
->dock
;
952 btn
->pid
= execCommand(btn
, (withSelection
? btn
->paste_command
: btn
->command
), NULL
);
954 if (btn
->buggy_app
) {
955 /* give feedback that the app was launched */
959 WMAddTimerHandler(200, (WMCallback
*) dockIconPaint
, btn
);
964 wwarning(_("could not launch application %s"), btn
->command
);
966 if (!btn
->relaunching
)
972 static void updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
974 WScreen
*scr
= menu
->frame
->screen_ptr
;
980 for (i
= 0; i
< scr
->workspace_count
; i
++) {
981 if (i
< menu
->entry_no
) {
982 if (strcmp(menu
->entries
[i
]->text
, scr
->workspaces
[i
]->name
) != 0) {
983 wfree(menu
->entries
[i
]->text
);
984 menu
->entries
[i
]->text
= wstrdup(scr
->workspaces
[i
]->name
);
985 menu
->flags
.realized
= 0;
987 menu
->entries
[i
]->clientdata
= (void *)icon
;
989 wMenuAddCallback(menu
, scr
->workspaces
[i
]->name
, switchWSCommand
, (void *)icon
);
991 menu
->flags
.realized
= 0;
994 if (i
== scr
->current_workspace
)
995 wMenuSetEnabled(menu
, i
, False
);
997 wMenuSetEnabled(menu
, i
, True
);
1000 if (!menu
->flags
.realized
)
1004 static WMenu
*makeWorkspaceMenu(WScreen
*scr
)
1008 menu
= wMenuCreate(scr
, NULL
, False
);
1010 wwarning(_("could not create workspace submenu for Clip menu"));
1012 wMenuAddCallback(menu
, "", switchWSCommand
, (void *)scr
->clip_icon
);
1014 menu
->flags
.realized
= 0;
1020 static void updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
1029 entry
= menu
->entries
[index
];
1030 entry
->flags
.indicator_on
= !dock
->lowered
;
1031 entry
->clientdata
= dock
;
1032 wMenuSetEnabled(menu
, index
, dock
->type
== WM_CLIP
);
1035 entry
= menu
->entries
[++index
];
1036 entry
->flags
.indicator_on
= dock
->collapsed
;
1037 entry
->clientdata
= dock
;
1040 entry
= menu
->entries
[++index
];
1041 entry
->flags
.indicator_on
= dock
->auto_collapse
;
1042 entry
->clientdata
= dock
;
1044 /* auto-raise/lower */
1045 entry
= menu
->entries
[++index
];
1046 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1047 entry
->clientdata
= dock
;
1048 wMenuSetEnabled(menu
, index
, dock
->lowered
&& (dock
->type
== WM_CLIP
));
1051 entry
= menu
->entries
[++index
];
1052 entry
->flags
.indicator_on
= dock
->attract_icons
;
1053 entry
->clientdata
= dock
;
1055 menu
->flags
.realized
= 0;
1060 static WMenu
*makeClipOptionsMenu(WScreen
*scr
)
1065 menu
= wMenuCreate(scr
, NULL
, False
);
1067 wwarning(_("could not create options submenu for Clip menu"));
1071 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
1072 entry
->flags
.indicator
= 1;
1073 entry
->flags
.indicator_on
= 1;
1074 entry
->flags
.indicator_type
= MI_CHECK
;
1076 entry
= wMenuAddCallback(menu
, _("Collapsed"), toggleCollapsedCallback
, NULL
);
1077 entry
->flags
.indicator
= 1;
1078 entry
->flags
.indicator_on
= 1;
1079 entry
->flags
.indicator_type
= MI_CHECK
;
1081 entry
= wMenuAddCallback(menu
, _("Autocollapse"), toggleAutoCollapseCallback
, NULL
);
1082 entry
->flags
.indicator
= 1;
1083 entry
->flags
.indicator_on
= 1;
1084 entry
->flags
.indicator_type
= MI_CHECK
;
1086 entry
= wMenuAddCallback(menu
, _("Autoraise"), toggleAutoRaiseLowerCallback
, NULL
);
1087 entry
->flags
.indicator
= 1;
1088 entry
->flags
.indicator_on
= 1;
1089 entry
->flags
.indicator_type
= MI_CHECK
;
1091 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"), toggleAutoAttractCallback
, NULL
);
1092 entry
->flags
.indicator
= 1;
1093 entry
->flags
.indicator_on
= 1;
1094 entry
->flags
.indicator_type
= MI_CHECK
;
1096 menu
->flags
.realized
= 0;
1103 static void setDockPositionNormalCallback(WMenu
*menu
, WMenuEntry
*entry
)
1105 WDock
*dock
= (WDock
*) entry
->clientdata
;
1108 /* Parameter not used, but tell the compiler that it is ok */
1111 if (entry
->flags
.indicator_on
) // already set, nothing to do
1113 // Do we come from auto raise lower or keep on top?
1114 if (dock
->auto_raise_lower
)
1116 dock
->auto_raise_lower
= 0;
1117 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1118 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1119 dc
->adrawer
->auto_raise_lower
= 0;
1124 // Will take care of setting lowered = 0 in drawers
1125 toggleLowered(dock
);
1127 entry
->flags
.indicator_on
= 1;
1130 static void setDockPositionAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
1132 WDock
*dock
= (WDock
*) entry
->clientdata
;
1135 /* Parameter not used, but tell the compiler that it is ok */
1138 if (entry
->flags
.indicator_on
) // already set, nothing to do
1140 // Do we come from normal or keep on top?
1143 toggleLowered(dock
);
1145 dock
->auto_raise_lower
= 1;
1146 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1147 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1148 dc
->adrawer
->auto_raise_lower
= 1;
1150 entry
->flags
.indicator_on
= 1;
1153 static void setDockPositionKeepOnTopCallback(WMenu
*menu
, WMenuEntry
*entry
)
1155 WDock
*dock
= (WDock
*) entry
->clientdata
;
1158 /* Parameter not used, but tell the compiler that it is ok */
1161 if (entry
->flags
.indicator_on
) // already set, nothing to do
1163 dock
->auto_raise_lower
= 0;
1164 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1165 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1166 dc
->adrawer
->auto_raise_lower
= 0;
1168 toggleLowered(dock
);
1169 entry
->flags
.indicator_on
= 1;
1172 static void updateDockPositionMenu(WMenu
*menu
, WDock
*dock
)
1181 entry
= menu
->entries
[index
++];
1182 entry
->flags
.indicator_on
= (dock
->lowered
&& !dock
->auto_raise_lower
);
1183 entry
->clientdata
= dock
;
1185 /* Auto-raise/lower */
1186 entry
= menu
->entries
[index
++];
1187 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1188 entry
->clientdata
= dock
;
1191 entry
= menu
->entries
[index
++];
1192 entry
->flags
.indicator_on
= !dock
->lowered
;
1193 entry
->clientdata
= dock
;
1196 static WMenu
*makeDockPositionMenu(WScreen
*scr
)
1198 /* When calling this, the dock is being created, so scr->dock is still not set
1199 * Therefore the callbacks' clientdata and the indicators can't be set,
1200 * they will be updated when the dock menu is opened. */
1204 menu
= wMenuCreate(scr
, NULL
, False
);
1206 wwarning(_("could not create options submenu for dock position menu"));
1210 entry
= wMenuAddCallback(menu
, _("Normal"), setDockPositionNormalCallback
, NULL
);
1211 entry
->flags
.indicator
= 1;
1212 entry
->flags
.indicator_type
= MI_DIAMOND
;
1214 entry
= wMenuAddCallback(menu
, _("Auto raise & lower"), setDockPositionAutoRaiseLowerCallback
, NULL
);
1215 entry
->flags
.indicator
= 1;
1216 entry
->flags
.indicator_type
= MI_DIAMOND
;
1218 entry
= wMenuAddCallback(menu
, _("Keep on Top"), setDockPositionKeepOnTopCallback
, NULL
);
1219 entry
->flags
.indicator
= 1;
1220 entry
->flags
.indicator_type
= MI_DIAMOND
;
1222 menu
->flags
.realized
= 0;
1229 static WMenu
*dockMenuCreate(WScreen
*scr
, int type
)
1234 if (type
== WM_CLIP
&& scr
->clip_menu
)
1235 return scr
->clip_menu
;
1237 if (type
== WM_DRAWER
&& scr
->drawer_menu
)
1238 return scr
->drawer_menu
;
1240 menu
= wMenuCreate(scr
, NULL
, False
);
1241 if (type
== WM_DOCK
) {
1242 entry
= wMenuAddCallback(menu
, _("Dock position"), NULL
, NULL
);
1243 if (scr
->dock_pos_menu
== NULL
)
1244 scr
->dock_pos_menu
= makeDockPositionMenu(scr
);
1245 wMenuEntrySetCascade(menu
, entry
, scr
->dock_pos_menu
);
1247 if (!wPreferences
.flags
.nodrawer
)
1248 wMenuAddCallback(menu
, _("Add a drawer"), addADrawerCallback
, NULL
);
1251 if (type
== WM_CLIP
)
1252 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1253 else /* if (type == WM_DRAWER) */
1254 entry
= wMenuAddCallback(menu
, _("Drawer options"), NULL
, NULL
);
1256 if (scr
->clip_options
== NULL
)
1257 scr
->clip_options
= makeClipOptionsMenu(scr
);
1259 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1261 /* The same menu is used for the dock and its appicons. If the menu
1262 * entry text is different between the two contexts, or if it can
1263 * change depending on some state, free the duplicated string (from
1264 * wMenuInsertCallback) and use gettext's string */
1265 if (type
== WM_CLIP
) {
1266 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1268 entry
->text
= _("Rename Workspace"); /* can be: (Toggle) Omnipresent */
1271 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1272 entry
->flags
.indicator
= 1;
1273 entry
->flags
.indicator_on
= 1;
1274 entry
->flags
.indicator_type
= MI_CHECK
;
1276 entry
= wMenuAddCallback(menu
, _("Select All Icons"), selectIconsCallback
, NULL
);
1278 entry
->text
= _("Select All Icons"); /* can be: Unselect all icons */
1280 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1282 entry
->text
= _("Keep Icon"); /* can be: Keep Icons */
1284 if (type
== WM_CLIP
) {
1285 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1287 entry
->text
= _("Move Icon To"); /* can be: Move Icons to */
1288 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1289 if (scr
->clip_submenu
)
1290 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1293 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
, NULL
);
1295 entry
->text
= _("Remove Icon"); /* can be: Remove Icons */
1297 wMenuAddCallback(menu
, _("Attract Icons"), attractIconsCallback
, NULL
);
1300 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1302 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1304 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1306 entry
->text
= _("Hide"); /* can be: Unhide */
1308 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1310 entry
= wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1312 entry
->text
= _("Kill"); /* can be: Remove drawer */
1314 if (type
== WM_CLIP
)
1315 scr
->clip_menu
= menu
;
1317 if (type
== WM_DRAWER
)
1318 scr
->drawer_menu
= menu
;
1323 WDock
*wDockCreate(WScreen
*scr
, int type
, const char *name
)
1330 dock
= wmalloc(sizeof(WDock
));
1334 dock
->max_icons
= DOCK_MAX_ICONS
;
1337 dock
->max_icons
= scr
->scr_width
/ wPreferences
.icon_size
;
1341 dock
->max_icons
= scr
->scr_height
/ wPreferences
.icon_size
;
1344 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * dock
->max_icons
);
1346 btn
= mainIconCreate(scr
, type
, name
);
1350 dock
->x_pos
= btn
->x_pos
;
1351 dock
->y_pos
= btn
->y_pos
;
1352 dock
->screen_ptr
= scr
;
1354 dock
->icon_count
= 1;
1355 if (type
== WM_DRAWER
)
1356 dock
->on_right_side
= scr
->dock
->on_right_side
;
1358 dock
->on_right_side
= 1;
1359 dock
->collapsed
= 0;
1360 dock
->auto_collapse
= 0;
1361 dock
->auto_collapse_magic
= NULL
;
1362 dock
->auto_raise_lower
= 0;
1363 dock
->auto_lower_magic
= NULL
;
1364 dock
->auto_raise_magic
= NULL
;
1365 dock
->attract_icons
= 0;
1367 dock
->icon_array
[0] = btn
;
1368 wRaiseFrame(btn
->icon
->core
);
1369 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1371 /* create dock menu */
1372 dock
->menu
= dockMenuCreate(scr
, type
);
1374 if (type
== WM_DRAWER
) {
1375 drawerAppendToChain(scr
, dock
);
1376 dock
->auto_collapse
= 1;
1382 void wDockDestroy(WDock
*dock
)
1387 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1388 aicon
= dock
->icon_array
[i
];
1390 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1391 wDockDetach(dock
, aicon
);
1393 /* XXX: can: aicon->icon == NULL ? */
1394 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1395 wGetHeadForWindow(aicon
->icon
->owner
));
1396 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1397 if (!dock
->mapped
|| dock
->collapsed
)
1398 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1402 if (wPreferences
.auto_arrange_icons
)
1403 wArrangeIcons(dock
->screen_ptr
, True
);
1404 wfree(dock
->icon_array
);
1405 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1406 wMenuDestroy(dock
->menu
, True
);
1407 if (dock
->screen_ptr
->last_dock
== dock
)
1408 dock
->screen_ptr
->last_dock
= NULL
;
1412 void wClipIconPaint(WAppIcon
*aicon
)
1414 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1415 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1417 Window win
= aicon
->icon
->core
->window
;
1418 int length
, nlength
;
1419 char *ws_name
, ws_number
[sizeof scr
->current_workspace
* CHAR_BIT
/ 3 + 1];
1422 wIconPaint(aicon
->icon
);
1424 length
= strlen(workspace
->name
);
1425 ws_name
= wmalloc(length
+ 1);
1426 snprintf(ws_name
, length
+ 1, "%s", workspace
->name
);
1427 snprintf(ws_number
, sizeof ws_number
, "%u", scr
->current_workspace
+ 1);
1428 nlength
= strlen(ws_number
);
1430 if (wPreferences
.flags
.noclip
|| !workspace
->clip
->collapsed
)
1431 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1433 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1435 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1437 tx
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
1439 if(wPreferences
.show_clip_title
)
1440 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, ty
, ws_name
, length
);
1442 tx
= (ICON_SIZE
/ 2 - WMWidthOfString(scr
->clip_title_font
, ws_number
, nlength
)) / 2;
1444 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, 2, ws_number
, nlength
);
1448 if (aicon
->launching
)
1449 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1450 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1452 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
, aicon
->dock
->rclip_button_pushed
);
1455 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1457 /* Parameter not used, but tell the compiler that it is ok */
1461 wClipIconPaint(desc
->parent
);
1464 static void dockIconPaint(WAppIcon
*btn
)
1466 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
) {
1467 wClipIconPaint(btn
);
1468 } else if (wIsADrawer(btn
)) {
1469 wDrawerIconPaint(btn
);
1476 static WMPropList
*make_icon_state(WAppIcon
*btn
)
1478 WMPropList
*node
= NULL
;
1479 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
;
1480 WMPropList
*position
, *buggy
, *omnipresent
;
1486 command
= WMCreatePLString("-");
1488 command
= WMCreatePLString(btn
->command
);
1490 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1492 lock
= btn
->lock
? dYes
: dNo
;
1494 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1496 name
= WMCreatePLString(tmp
);
1500 forced
= btn
->forced_dock
? dYes
: dNo
;
1502 buggy
= btn
->buggy_app
? dYes
: dNo
;
1504 if (!wPreferences
.flags
.clip_merged_in_dock
&& btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1505 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1507 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1508 position
= WMCreatePLString(buffer
);
1510 node
= WMCreatePLDictionary(dCommand
, command
,
1512 dAutoLaunch
, autolaunch
,
1514 dForced
, forced
, dBuggyApplication
, buggy
, dPosition
, position
, NULL
);
1515 WMReleasePropList(command
);
1516 WMReleasePropList(name
);
1517 WMReleasePropList(position
);
1519 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1520 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&& (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1521 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1523 #ifdef USE_DOCK_XDND
1524 if (btn
->dnd_command
) {
1525 command
= WMCreatePLString(btn
->dnd_command
);
1526 WMPutInPLDictionary(node
, dDropCommand
, command
);
1527 WMReleasePropList(command
);
1529 #endif /* USE_DOCK_XDND */
1531 if (btn
->paste_command
) {
1532 command
= WMCreatePLString(btn
->paste_command
);
1533 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1534 WMReleasePropList(command
);
1541 static WMPropList
*dockSaveState(WDock
*dock
)
1544 WMPropList
*icon_info
;
1545 WMPropList
*list
= NULL
, *dock_state
= NULL
;
1546 WMPropList
*value
, *key
;
1549 list
= WMCreatePLArray(NULL
);
1551 for (i
= (dock
->type
== WM_DOCK
? 0 : 1); i
< dock
->max_icons
; i
++) {
1552 WAppIcon
*btn
= dock
->icon_array
[i
];
1554 if (!btn
|| btn
->attracted
)
1557 icon_info
= make_icon_state(dock
->icon_array
[i
]);
1558 if (icon_info
!= NULL
) {
1559 WMAddToPLArray(list
, icon_info
);
1560 WMReleasePropList(icon_info
);
1564 dock_state
= WMCreatePLDictionary(dApplications
, list
, NULL
);
1566 if (dock
->type
== WM_DOCK
) {
1567 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1568 key
= WMCreatePLString(buffer
);
1569 WMPutInPLDictionary(dock_state
, key
, list
);
1570 WMReleasePropList(key
);
1572 snprintf(buffer
, sizeof(buffer
), "%i,%i", dock
->x_pos
, dock
->y_pos
);
1573 value
= WMCreatePLString(buffer
);
1574 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1575 WMReleasePropList(value
);
1577 WMReleasePropList(list
);
1579 if (dock
->type
== WM_CLIP
|| dock
->type
== WM_DRAWER
) {
1580 value
= (dock
->collapsed
? dYes
: dNo
);
1581 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1583 value
= (dock
->auto_collapse
? dYes
: dNo
);
1584 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1586 value
= (dock
->attract_icons
? dYes
: dNo
);
1587 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1590 if (dock
->type
== WM_DOCK
|| dock
->type
== WM_CLIP
) {
1591 value
= (dock
->lowered
? dYes
: dNo
);
1592 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1594 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1595 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1601 void wDockSaveState(WScreen
*scr
, WMPropList
*old_state
)
1603 WMPropList
*dock_state
;
1606 dock_state
= dockSaveState(scr
->dock
);
1609 * Copy saved states of docks with different sizes.
1615 keys
= WMGetPLDictionaryKeys(old_state
);
1616 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1617 tmp
= WMGetFromPLArray(keys
, i
);
1619 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1620 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1622 WMPutInPLDictionary(dock_state
, tmp
, WMGetFromPLDictionary(old_state
, tmp
));
1625 WMReleasePropList(keys
);
1628 WMPutInPLDictionary(scr
->session_state
, dDock
, dock_state
);
1630 WMReleasePropList(dock_state
);
1633 void wClipSaveState(WScreen
*scr
)
1635 WMPropList
*clip_state
;
1637 clip_state
= make_icon_state(scr
->clip_icon
);
1639 WMPutInPLDictionary(scr
->session_state
, dClip
, clip_state
);
1641 WMReleasePropList(clip_state
);
1644 WMPropList
*wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1646 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1649 static Bool
getBooleanDockValue(WMPropList
*value
, WMPropList
*key
)
1652 if (WMIsPLString(value
)) {
1653 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1656 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1662 static WAppIcon
*restore_icon_state(WScreen
*scr
, WMPropList
*info
, int type
, int index
)
1665 WMPropList
*cmd
, *value
;
1666 char *wclass
, *winstance
, *command
;
1668 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1669 if (!cmd
|| !WMIsPLString(cmd
))
1672 /* parse window name */
1673 value
= WMGetFromPLDictionary(info
, dName
);
1677 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1679 if (!winstance
&& !wclass
)
1683 command
= wstrdup(WMGetFromPLString(cmd
));
1685 if (strcmp(command
, "-") == 0) {
1696 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1704 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1705 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1706 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1707 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1708 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1710 #ifdef USE_DOCK_XDND
1711 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1713 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1716 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1718 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1720 /* check auto launch */
1721 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1723 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1726 value
= WMGetFromPLDictionary(info
, dLock
);
1728 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1730 /* check if it wasn't normally docked */
1731 value
= WMGetFromPLDictionary(info
, dForced
);
1733 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1735 /* check if we can rely on the stuff in the app */
1736 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1738 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1740 /* get position in the dock */
1741 value
= WMGetFromPLDictionary(info
, dPosition
);
1742 if (value
&& WMIsPLString(value
)) {
1743 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1744 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1746 /* check position sanity */
1747 /* *Very* incomplete section! */
1748 if (type
== WM_DOCK
) {
1752 aicon
->yindex
= index
;
1756 /* check if icon is omnipresent */
1757 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1759 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1767 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1769 WAppIcon
*wClipRestoreState(WScreen
*scr
, WMPropList
*clip_state
)
1774 icon
= mainIconCreate(scr
, WM_CLIP
, NULL
);
1779 WMRetainPropList(clip_state
);
1781 /* restore position */
1783 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1786 if (!WMIsPLString(value
)) {
1787 COMPLAIN("Position");
1789 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1790 COMPLAIN("Position");
1792 /* check position sanity */
1793 if (!onScreen(scr
, icon
->x_pos
, icon
->y_pos
))
1794 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1797 #ifdef USE_DOCK_XDND
1798 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1799 if (value
&& WMIsPLString(value
))
1800 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1803 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1804 if (value
&& WMIsPLString(value
))
1805 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1807 WMReleasePropList(clip_state
);
1812 WDock
*wDockRestoreState(WScreen
*scr
, WMPropList
*dock_state
, int type
)
1817 WAppIcon
*aicon
, *old_top
;
1820 dock
= wDockCreate(scr
, type
, NULL
);
1825 WMRetainPropList(dock_state
);
1827 /* restore position */
1828 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1830 if (!WMIsPLString(value
)) {
1831 COMPLAIN("Position");
1833 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1834 COMPLAIN("Position");
1836 /* check position sanity */
1837 if (!onScreen(scr
, dock
->x_pos
, dock
->y_pos
)) {
1838 int x
= dock
->x_pos
;
1839 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1842 /* Is this needed any more? */
1843 if (type
== WM_CLIP
) {
1844 if (dock
->x_pos
< 0) {
1846 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1847 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1850 int left
, right
, midpoint
;
1852 left
= getDockXPosition(scr
, False
);
1853 right
= getDockXPosition(scr
, True
);
1854 midpoint
= (left
+ right
) / 2;
1856 if (dock
->x_pos
< midpoint
) {
1858 dock
->on_right_side
= 0;
1860 dock
->x_pos
= right
;
1861 dock
->on_right_side
= 1;
1867 /* restore lowered/raised state */
1870 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1872 if (!WMIsPLString(value
)) {
1873 COMPLAIN("Lowered");
1875 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1880 /* restore collapsed state */
1881 dock
->collapsed
= 0;
1883 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1885 if (!WMIsPLString(value
)) {
1886 COMPLAIN("Collapsed");
1888 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1889 dock
->collapsed
= 1;
1893 /* restore auto-collapsed state */
1894 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1896 if (!WMIsPLString(value
)) {
1897 COMPLAIN("AutoCollapse");
1899 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1900 dock
->auto_collapse
= 1;
1901 dock
->collapsed
= 1;
1906 /* restore auto-raise/lower state */
1907 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1909 if (!WMIsPLString(value
)) {
1910 COMPLAIN("AutoRaiseLower");
1912 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1913 dock
->auto_raise_lower
= 1;
1917 /* restore attract icons state */
1918 dock
->attract_icons
= 0;
1920 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1922 if (!WMIsPLString(value
)) {
1923 COMPLAIN("AutoAttractIcons");
1925 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1926 dock
->attract_icons
= 1;
1930 /* application list */
1937 * When saving, it saves the dock state in
1938 * Applications and Applicationsnnn
1940 * When loading, it will first try Applicationsnnn.
1941 * If it does not exist, use Applications as default.
1944 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1946 tmp
= WMCreatePLString(buffer
);
1947 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1948 WMReleasePropList(tmp
);
1951 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1957 count
= WMGetPropListItemCount(apps
);
1961 old_top
= dock
->icon_array
[0];
1963 /* dock->icon_count is set to 1 when dock is created.
1964 * Since Clip is already restored, we want to keep it so for clip,
1965 * but for dock we may change the default top tile, so we set it to 0.
1967 if (type
== WM_DOCK
)
1968 dock
->icon_count
= 0;
1970 for (i
= 0; i
< count
; i
++) {
1971 if (dock
->icon_count
>= dock
->max_icons
) {
1972 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1976 value
= WMGetFromPLArray(apps
, i
);
1977 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1979 dock
->icon_array
[dock
->icon_count
] = aicon
;
1983 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1984 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1987 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1989 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1991 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1992 if (!dock
->collapsed
)
1993 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1995 wRaiseFrame(aicon
->icon
->core
);
1998 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
) {
2003 /* if the first icon is not defined, use the default */
2004 if (dock
->icon_array
[0] == NULL
) {
2005 /* update default icon */
2006 old_top
->x_pos
= dock
->x_pos
;
2007 old_top
->y_pos
= dock
->y_pos
;
2009 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
2011 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
2013 dock
->icon_array
[0] = old_top
;
2014 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
2015 /* we don't need to increment dock->icon_count here because it was
2016 * incremented in the loop above.
2018 } else if (old_top
!= dock
->icon_array
[0]) {
2019 if (old_top
== scr
->clip_icon
) // TODO dande: understand the logic
2020 scr
->clip_icon
= dock
->icon_array
[0];
2022 wAppIconDestroy(old_top
);
2026 WMReleasePropList(dock_state
);
2031 void wDockLaunchWithState(WAppIcon
*btn
, WSavedState
*state
)
2033 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
2034 btn
->drop_launch
= 0;
2035 btn
->paste_launch
= 0;
2037 btn
->pid
= execCommand(btn
, btn
->command
, state
);
2040 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
2050 void wDockDoAutoLaunch(WDock
*dock
, int workspace
)
2056 for (i
= 0; i
< dock
->max_icons
; i
++) {
2057 btn
= dock
->icon_array
[i
];
2058 if (!btn
|| !btn
->auto_launch
)
2061 state
= wmalloc(sizeof(WSavedState
));
2062 state
->workspace
= workspace
;
2063 /* TODO: this is klugy and is very difficult to understand
2064 * what's going on. Try to clean up */
2065 wDockLaunchWithState(btn
, state
);
2069 #ifdef USE_DOCK_XDND
2070 static WDock
*findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
2077 for (i
= 0; i
< dock
->max_icons
; i
++) {
2078 if (dock
->icon_array
[i
] &&
2079 dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
2086 dock
= scr
->workspaces
[scr
->current_workspace
]->clip
;
2088 for (i
= 0; i
< dock
->max_icons
; i
++) {
2089 if (dock
->icon_array
[i
] &&
2090 dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
2101 int wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
2107 dock
= findDock(scr
, event
, &icon_pos
);
2112 * Return True if the drop was on an application icon window.
2113 * In this case, let the ClientMessage handler redirect the
2114 * message to the app.
2116 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
2119 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
2120 scr
->flags
.dnd_data_convertion_status
= 0;
2122 btn
= dock
->icon_array
[icon_pos
];
2124 if (!btn
->forced_dock
) {
2125 btn
->relaunching
= btn
->running
;
2128 if (btn
->wm_instance
|| btn
->wm_class
) {
2129 WWindowAttributes attr
;
2130 memset(&attr
, 0, sizeof(WWindowAttributes
));
2131 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
2133 if (!attr
.no_appicon
)
2139 btn
->paste_launch
= 0;
2140 btn
->drop_launch
= 1;
2141 scr
->last_dock
= dock
;
2142 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
2147 if (!btn
->relaunching
)
2153 #endif /* USE_DOCK_XDND */
2155 Bool
wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
, Bool update_icon
)
2158 Bool lupdate_icon
= False
;
2159 char *command
= NULL
;
2165 lupdate_icon
= True
;
2167 if (icon
->command
== NULL
) {
2168 /* If icon->owner exists, it means the application is running */
2169 if (icon
->icon
->owner
) {
2170 wwin
= icon
->icon
->owner
;
2171 command
= GetCommandForWindow(wwin
->client_win
);
2175 icon
->command
= command
;
2177 /* icon->forced_dock = 1; */
2178 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
2180 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2181 _("Type the command used to launch the application"), &command
)) {
2182 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2186 icon
->command
= command
;
2192 /* If the target is the dock, reject the icon. If
2193 * the target is the clip, make it an attracted icon
2195 if (dock
->type
== WM_CLIP
) {
2196 icon
->attracted
= 1;
2197 if (!icon
->icon
->shadowed
) {
2198 icon
->icon
->shadowed
= 1;
2199 lupdate_icon
= True
;
2209 for (index
= 1; index
< dock
->max_icons
; index
++)
2210 if (dock
->icon_array
[index
] == NULL
)
2212 /* if (index == dock->max_icons)
2215 assert(index
< dock
->max_icons
);
2217 dock
->icon_array
[index
] = icon
;
2221 icon
->omnipresent
= 0;
2223 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2224 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2229 icon
->launching
= 0;
2232 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2233 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2234 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2235 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2236 icon
->icon
->core
->descriptor
.parent
= icon
;
2238 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2239 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2242 * Update icon pixmap, RImage doesn't change,
2243 * so call wIconUpdate is not needed
2246 update_icon_pixmap(icon
->icon
);
2249 wAppIconPaint(icon
);
2254 if (wPreferences
.auto_arrange_icons
)
2255 wArrangeIcons(dock
->screen_ptr
, True
);
2257 #ifdef USE_DOCK_XDND
2258 if (icon
->command
&& !icon
->dnd_command
) {
2259 int len
= strlen(icon
->command
) + 8;
2260 icon
->dnd_command
= wmalloc(len
);
2261 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
2265 if (icon
->command
&& !icon
->paste_command
) {
2266 int len
= strlen(icon
->command
) + 8;
2267 icon
->paste_command
= wmalloc(len
);
2268 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
2274 void wDockReattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2278 for (index
= 1; index
< dock
->max_icons
; index
++) {
2279 if (dock
->icon_array
[index
] == icon
)
2282 assert(index
< dock
->max_icons
);
2287 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2288 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2291 Bool
wDockMoveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2294 char *command
= NULL
;
2296 Bool update_icon
= False
;
2299 return True
; /* No move needed, we're already there */
2305 * For the moment we can't do this if we move icons in Clip from one
2306 * workspace to other, because if we move two or more icons without
2307 * command, the dialog box will not be able to tell us to which of the
2308 * moved icons it applies. -Dan
2310 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
2311 /* If icon->owner exists, it means the application is running */
2312 if (icon
->icon
->owner
) {
2313 wwin
= icon
->icon
->owner
;
2314 command
= GetCommandForWindow(wwin
->client_win
);
2318 icon
->command
= command
;
2321 /* icon->forced_dock = 1; */
2322 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2323 _("Type the command used to launch the application"), &command
)) {
2324 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2328 icon
->command
= command
;
2339 if (dest
->type
== WM_DOCK
|| dest
->type
== WM_DRAWER
)
2340 wClipMakeIconOmnipresent(icon
, False
);
2342 for (index
= 1; index
< src
->max_icons
; index
++) {
2343 if (src
->icon_array
[index
] == icon
)
2346 assert(index
< src
->max_icons
);
2348 src
->icon_array
[index
] = NULL
;
2351 for (index
= 1; index
< dest
->max_icons
; index
++) {
2352 if (dest
->icon_array
[index
] == NULL
)
2356 assert(index
< dest
->max_icons
);
2358 dest
->icon_array
[index
] = icon
;
2361 /* deselect the icon */
2362 if (icon
->icon
->selected
)
2363 wIconSelect(icon
->icon
);
2365 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2366 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2368 /* set it to be kept when moving to dock.
2369 * Unless the icon does not have a command set
2371 if (icon
->command
&& (dest
->type
== WM_DOCK
|| dest
->type
== WM_DRAWER
)) {
2372 icon
->attracted
= 0;
2373 if (icon
->icon
->shadowed
) {
2374 icon
->icon
->shadowed
= 0;
2379 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2385 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2386 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2390 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2393 * Update icon pixmap, RImage doesn't change,
2394 * so call wIconUpdate is not needed
2397 update_icon_pixmap(icon
->icon
);
2400 wAppIconPaint(icon
);
2405 void wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2408 Bool update_icon
= False
;
2410 /* make the settings panel be closed */
2412 DestroyDockAppSettingsPanel(icon
->panel
);
2414 /* This must be called before icon->dock is set to NULL.
2415 * Don't move it. -Dan
2417 wClipMakeIconOmnipresent(icon
, False
);
2421 icon
->attracted
= 0;
2422 icon
->auto_launch
= 0;
2423 if (icon
->icon
->shadowed
) {
2424 icon
->icon
->shadowed
= 0;
2428 /* deselect the icon */
2429 if (icon
->icon
->selected
)
2430 wIconSelect(icon
->icon
);
2432 if (icon
->command
) {
2433 wfree(icon
->command
);
2434 icon
->command
= NULL
;
2436 #ifdef USE_DOCK_XDND
2437 if (icon
->dnd_command
) {
2438 wfree(icon
->dnd_command
);
2439 icon
->dnd_command
= NULL
;
2442 if (icon
->paste_command
) {
2443 wfree(icon
->paste_command
);
2444 icon
->paste_command
= NULL
;
2447 for (index
= 1; index
< dock
->max_icons
; index
++)
2448 if (dock
->icon_array
[index
] == icon
)
2451 assert(index
< dock
->max_icons
);
2452 dock
->icon_array
[index
] = NULL
;
2458 /* Remove the Cached Icon */
2459 remove_cache_icon(icon
->icon
->file
);
2461 /* if the dock is not attached to an application or
2462 * the application did not set the appropriate hints yet,
2463 * destroy the icon */
2464 if (!icon
->running
|| !wApplicationOf(icon
->main_window
)) {
2465 wAppIconDestroy(icon
);
2467 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2468 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2469 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2470 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2471 icon
->icon
->core
->descriptor
.parent
= icon
;
2473 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2476 * Update icon pixmap, RImage doesn't change,
2477 * so call wIconUpdate is not needed
2480 update_icon_pixmap(icon
->icon
);
2483 wAppIconPaint(icon
);
2485 if (wPreferences
.auto_arrange_icons
)
2486 wArrangeIcons(dock
->screen_ptr
, True
);
2489 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2494 * returns the closest Dock slot index for the passed
2497 * Returns False if icon can't be docked.
2499 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2502 /* Redocking == true means either icon->dock == dock (normal case)
2503 * or we are called from handleDockMove for a drawer */
2504 Bool
wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2506 WScreen
*scr
= dock
->screen_ptr
;
2509 int i
, offset
= ICON_SIZE
/ 2;
2510 WAppIcon
*aicon
= NULL
;
2511 WAppIcon
*nicon
= NULL
;
2513 if (wPreferences
.flags
.noupdates
)
2519 /* if the dock is full */
2520 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
))
2523 /* exact position */
2525 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2527 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2530 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2532 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2534 /* check if the icon is outside the screen boundaries */
2535 if (!onScreen(scr
, dx
+ ex_x
* ICON_SIZE
, dy
+ ex_y
* ICON_SIZE
))
2538 switch (dock
->type
) {
2540 /* We can return False right away if
2541 * - we do not come from this dock (which is a WM_DOCK),
2542 * - we are not right over it, and
2543 * - we are not the main tile of a drawer.
2544 * In the latter case, we are called from handleDockMove. */
2545 if (icon
->dock
!= dock
&& ex_x
!= 0 &&
2546 !(icon
->dock
&& icon
->dock
->type
== WM_DRAWER
&& icon
== icon
->dock
->icon_array
[0]))
2549 if (!redocking
&& ex_x
!= 0)
2552 if (getDrawer(scr
, ex_y
)) /* Return false so that the drawer gets it. */
2556 for (i
= 0; i
< dock
->max_icons
; i
++) {
2557 nicon
= dock
->icon_array
[i
];
2558 if (nicon
&& nicon
->yindex
== ex_y
) {
2565 int sig
, done
, closest
;
2567 /* Possible cases when redocking:
2569 * icon dragged out of range of any slot -> false
2570 * icon dragged on a drawer -> false (to open the drawer)
2571 * icon dragged to range of free slot
2572 * icon dragged to range of same slot
2573 * icon dragged to range of different icon
2575 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2578 if (aicon
== icon
|| !aicon
) {
2584 /* start looking at the upper slot or lower? */
2585 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2591 /* look for closest free slot */
2592 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2596 closest
= sig
* (i
/ 2) + ex_y
;
2597 /* check if this slot is fully on the screen and not used */
2598 if (onScreen(scr
, dx
, dy
+ closest
* ICON_SIZE
)) {
2599 for (j
= 0; j
< dock
->max_icons
; j
++) {
2600 if (dock
->icon_array
[j
]
2601 && dock
->icon_array
[j
]->yindex
== closest
) {
2602 /* slot is used by someone else */
2603 if (dock
->icon_array
[j
] != icon
)
2608 /* slot is used by a drawer */
2609 done
= done
&& !getDrawer(scr
, closest
);
2616 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2617 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2622 } else { /* !redocking */
2624 /* if slot is free and the icon is close enough, return it */
2625 if (!aicon
&& ex_x
== 0) {
2637 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2638 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+ 1;
2641 for (k
= start
; k
< stop
; k
++) {
2642 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2645 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2646 nicon
= tmp
->icon_array
[i
];
2647 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2655 for (k
= start
; k
< stop
; k
++) {
2656 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2659 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2660 nicon
= tmp
->icon_array
[i
];
2661 if (nicon
&& nicon
!= icon
&& /* Icon can't be its own neighbour */
2662 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2663 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2672 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2681 WAppIcon
*aicons_to_shift
[ dock
->icon_count
];
2682 int index_of_hole
, j
;
2685 abs(ex_x
) - dock
->icon_count
> DOCK_DETTACH_THRESHOLD
||
2686 (ex_x
< 0 && !dock
->on_right_side
) ||
2687 (ex_x
> 0 && dock
->on_right_side
)) {
2692 ex_x
= (dock
->on_right_side
? -1 : 1);
2694 /* "Reduce" ex_x but keep its sign */
2696 if (abs(ex_x
) > dock
->icon_count
- 1) /* minus 1: do not take icon_array[0] into account */
2697 ex_x
= ex_x
* (dock
->icon_count
- 1) / abs(ex_x
); /* don't use *= ! */
2699 if (abs(ex_x
) > dock
->icon_count
)
2700 ex_x
= ex_x
* dock
->icon_count
/ abs(ex_x
);
2702 index_of_hole
= indexOfHole(dock
, icon
, redocking
);
2704 /* Find the appicons between where icon was (index_of_hole) and where
2705 * it wants to be (ex_x) and slide them. */
2707 for (i
= 1; i
< dock
->max_icons
; i
++) {
2708 aicon
= dock
->icon_array
[i
];
2709 if ((aicon
!= NULL
) && (aicon
!= icon
) &&
2710 ((ex_x
<= aicon
->xindex
&& aicon
->xindex
< index_of_hole
) ||
2711 (index_of_hole
< aicon
->xindex
&& aicon
->xindex
<= ex_x
)))
2712 aicons_to_shift
[ j
++ ] = aicon
;
2714 assert(j
== abs(ex_x
- index_of_hole
));
2716 wSlideAppicons(aicons_to_shift
, j
, (index_of_hole
< ex_x
));
2726 static int onScreen(WScreen
*scr
, int x
, int y
)
2733 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2735 wGetRectPlacementInfo(scr
, rect
, &flags
);
2737 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2741 * returns true if it can find a free slot in the dock,
2742 * in which case it changes x_pos and y_pos accordingly.
2743 * Else returns false.
2745 Bool
wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2747 WScreen
*scr
= dock
->screen_ptr
;
2749 WAppIconChain
*chain
;
2750 unsigned char *slot_map
;
2754 int i
, done
= False
;
2756 int ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2757 int extra_count
= 0;
2759 if (dock
->type
== WM_DRAWER
) {
2760 if (dock
->icon_count
>= dock
->max_icons
) { /* drawer is full */
2763 *x_pos
= dock
->icon_count
* (dock
->on_right_side
? -1 : 1);
2768 if (dock
->type
== WM_CLIP
&& dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2769 extra_count
= scr
->global_icon_count
;
2771 /* if the dock is full */
2772 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
)
2775 if (!wPreferences
.flags
.nodock
&& scr
->dock
&& scr
->dock
->on_right_side
) {
2776 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2779 if (ex
< dock
->x_pos
)
2787 /* check if clip is in a corner */
2788 if (dock
->type
== WM_CLIP
) {
2789 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2791 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2793 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2795 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2803 /* If the clip is in the corner, use only slots that are in the border
2805 if (corner
!= C_NONE
) {
2809 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2810 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2811 hmap
= wmalloc(hcount
+ 1);
2812 vmap
= wmalloc(vcount
+ 1);
2814 /* mark used positions */
2817 for (i
= 0; i
< dock
->max_icons
; i
++) {
2818 btn
= dock
->icon_array
[i
];
2822 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2823 vmap
[btn
->yindex
] = 1;
2824 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2825 hmap
[btn
->xindex
] = 1;
2827 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2829 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2830 vmap
[btn
->yindex
] = 1;
2831 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2832 hmap
[btn
->xindex
] = 1;
2836 for (i
= 0; i
< dock
->max_icons
; i
++) {
2837 btn
= dock
->icon_array
[i
];
2841 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2842 vmap
[btn
->yindex
] = 1;
2843 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2844 hmap
[-btn
->xindex
] = 1;
2846 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2848 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2849 vmap
[btn
->yindex
] = 1;
2850 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2851 hmap
[-btn
->xindex
] = 1;
2855 for (i
= 0; i
< dock
->max_icons
; i
++) {
2856 btn
= dock
->icon_array
[i
];
2860 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2861 vmap
[-btn
->yindex
] = 1;
2862 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2863 hmap
[btn
->xindex
] = 1;
2865 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2867 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2868 vmap
[-btn
->yindex
] = 1;
2869 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2870 hmap
[btn
->xindex
] = 1;
2875 for (i
= 0; i
< dock
->max_icons
; i
++) {
2876 btn
= dock
->icon_array
[i
];
2880 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2881 vmap
[-btn
->yindex
] = 1;
2882 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2883 hmap
[-btn
->xindex
] = 1;
2885 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2887 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2888 vmap
[-btn
->yindex
] = 1;
2889 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2890 hmap
[-btn
->xindex
] = 1;
2896 /* search a vacant slot */
2897 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2898 if (i
< vcount
&& vmap
[i
] == 0) {
2904 } else if (i
< hcount
&& hmap
[i
] == 0) {
2914 /* If found a slot, translate and return */
2916 if (corner
== C_NW
|| corner
== C_NE
)
2921 if (corner
== C_NE
|| corner
== C_SE
)
2928 /* else, try to find a slot somewhere else */
2931 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2932 * placed outside of screen */
2933 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2935 /* In the worst case (the clip is in the corner of the screen),
2936 * the amount of icons that fit in the clip is smaller.
2937 * Double the map to get a safe value.
2941 r
= (mwidth
- 1) / 2;
2943 slot_map
= wmalloc(mwidth
* mwidth
);
2945 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2947 /* mark used slots in the map. If the slot falls outside the map
2948 * (for example, when all icons are placed in line), ignore them. */
2949 for (i
= 0; i
< dock
->max_icons
; i
++) {
2950 btn
= dock
->icon_array
[i
];
2952 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2955 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
)
2956 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2958 /* Find closest slot from the center that is free by scanning the
2959 * map from the center to outward in circular passes.
2960 * This will not result in a neat layout, but will be optimal
2961 * in the sense that there will not be holes left.
2964 for (i
= 1; i
<= r
&& !done
; i
++) {
2967 /* top and bottom parts of the ring */
2968 for (x
= -i
; x
<= i
&& !done
; x
++) {
2969 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2971 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2972 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2979 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2980 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2987 /* left and right parts of the ring */
2988 for (y
= -i
+ 1; y
<= i
- 1; y
++) {
2989 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2991 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2992 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2999 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
3000 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
3013 static void moveDock(WDock
*dock
, int new_x
, int new_y
)
3019 if (dock
->type
== WM_DOCK
) {
3020 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3021 moveDock(dc
->adrawer
, new_x
, dc
->adrawer
->y_pos
- dock
->y_pos
+ new_y
);
3024 dock
->x_pos
= new_x
;
3025 dock
->y_pos
= new_y
;
3026 for (i
= 0; i
< dock
->max_icons
; i
++) {
3027 btn
= dock
->icon_array
[i
];
3029 btn
->x_pos
= new_x
+ btn
->xindex
* ICON_SIZE
;
3030 btn
->y_pos
= new_y
+ btn
->yindex
* ICON_SIZE
;
3031 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
3036 void wDockSwap(WDock
*dock
)
3038 WScreen
*scr
= dock
->screen_ptr
;
3042 x
= getDockXPosition(scr
, dock
->on_right_side
);
3043 swapDrawers(scr
, x
);
3046 for (i
= 0; i
< dock
->max_icons
; i
++) {
3047 btn
= dock
->icon_array
[i
];
3050 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
3054 wScreenUpdateUsableArea(scr
);
3057 static pid_t
execCommand(WAppIcon
*btn
, const char *command
, WSavedState
*state
)
3059 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
3065 cmdline
= ExpandOptions(scr
, command
);
3067 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
3075 wtokensplit(cmdline
, &argv
, &argc
);
3090 SetupEnvironment(scr
);
3096 args
= malloc(sizeof(char *) * (argc
+ 1));
3100 for (i
= 0; i
< argc
; i
++)
3104 execvp(argv
[0], args
);
3107 wtokenfree(argv
, argc
);
3111 state
= wmalloc(sizeof(WSavedState
));
3113 state
->miniaturized
= -1;
3115 if (btn
->dock
== scr
->dock
|| btn
->dock
->type
== WM_DRAWER
|| btn
->omnipresent
)
3116 state
->workspace
= -1;
3118 state
->workspace
= scr
->current_workspace
;
3120 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
3121 wAddDeathHandler(pid
, trackDeadProcess
, btn
->dock
);
3129 void wDockHideIcons(WDock
*dock
)
3136 for (i
= 1; i
< dock
->max_icons
; i
++) {
3137 if (dock
->icon_array
[i
])
3138 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3142 dockIconPaint(dock
->icon_array
[0]);
3145 void wDockShowIcons(WDock
*dock
)
3153 btn
= dock
->icon_array
[0];
3154 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
3156 /* Deleting any change in stacking level, this function is now only about
3159 if (!dock
->collapsed
) {
3160 for (i
= 1; i
< dock
->max_icons
; i
++) {
3161 if (dock
->icon_array
[i
])
3162 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3170 void wDockLower(WDock
*dock
)
3175 if (dock
->type
== WM_DOCK
) {
3176 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3177 wDockLower(dc
->adrawer
);
3179 for (i
= 0; i
< dock
->max_icons
; i
++) {
3180 if (dock
->icon_array
[i
])
3181 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
3185 void wDockRaise(WDock
*dock
)
3190 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
3191 if (dock
->icon_array
[i
])
3192 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
3194 if (dock
->type
== WM_DOCK
) {
3195 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3196 wDockRaise(dc
->adrawer
);
3200 void wDockRaiseLower(WDock
*dock
)
3202 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
3203 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
3204 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
3210 void wDockFinishLaunch(WAppIcon
*icon
)
3212 icon
->launching
= 0;
3213 icon
->relaunching
= 0;
3214 dockIconPaint(icon
);
3217 WAppIcon
*wDockFindIconForWindow(WDock
*dock
, Window window
)
3222 for (i
= 0; i
< dock
->max_icons
; i
++) {
3223 icon
= dock
->icon_array
[i
];
3224 if (icon
&& icon
->main_window
== window
)
3230 void wDockTrackWindowLaunch(WDock
*dock
, Window window
)
3233 char *wm_class
, *wm_instance
;
3235 Bool firstPass
= True
;
3237 char *command
= NULL
;
3239 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
)) {
3245 command
= GetCommandForWindow(window
);
3247 for (i
= 0; i
< dock
->max_icons
; i
++) {
3248 icon
= dock
->icon_array
[i
];
3252 /* app is already attached to icon */
3253 if (icon
->main_window
== window
) {
3258 if ((icon
->wm_instance
|| icon
->wm_class
)
3259 && (icon
->launching
|| !icon
->running
)) {
3261 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0)
3264 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0)
3267 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0)
3270 if (!icon
->relaunching
) {
3273 /* Possibly an application that was docked with dockit,
3274 * but the user did not update WMState to indicate that
3275 * it was docked by force */
3276 wapp
= wApplicationOf(window
);
3278 icon
->forced_dock
= 1;
3281 if (!icon
->forced_dock
)
3282 icon
->main_window
= window
;
3285 if (!wPreferences
.no_animations
&& !icon
->launching
&&
3286 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
3290 icon
->launching
= 1;
3291 dockIconPaint(icon
);
3293 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
3294 wm_instance
, wm_class
, TILE_NORMAL
);
3295 /* XXX: can: aicon->icon == NULL ? */
3296 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
3297 wAppIconMove(aicon
, x0
, y0
);
3298 /* Should this always be lowered? -Dan */
3300 wLowerFrame(aicon
->icon
->core
);
3301 XMapWindow(dpy
, aicon
->icon
->core
->window
);
3302 aicon
->launching
= 1;
3303 wAppIconPaint(aicon
);
3304 slide_window(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
3305 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
3306 wAppIconDestroy(aicon
);
3308 wDockFinishLaunch(icon
);
3313 if (firstPass
&& !found
) {
3327 void wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3329 if (!wPreferences
.flags
.noclip
) {
3330 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3331 if (scr
->current_workspace
!= workspace
) {
3332 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3333 WAppIconChain
*chain
= scr
->global_icons
;
3336 wDockMoveIconBetweenDocks(chain
->aicon
->dock
,
3337 scr
->workspaces
[workspace
]->clip
,
3338 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
3339 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
3340 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3341 chain
= chain
->next
;
3344 wDockHideIcons(old_clip
);
3345 if (old_clip
->auto_raise_lower
) {
3346 if (old_clip
->auto_raise_magic
) {
3347 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3348 old_clip
->auto_raise_magic
= NULL
;
3350 wDockLower(old_clip
);
3352 if (old_clip
->auto_collapse
) {
3353 if (old_clip
->auto_expand_magic
) {
3354 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3355 old_clip
->auto_expand_magic
= NULL
;
3357 old_clip
->collapsed
= 1;
3359 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3364 static void trackDeadProcess(pid_t pid
, unsigned int status
, void *cdata
)
3366 WDock
*dock
= cdata
;
3370 for (i
= 0; i
< dock
->max_icons
; i
++) {
3371 icon
= dock
->icon_array
[i
];
3375 if (icon
->launching
&& icon
->pid
== pid
) {
3376 if (!icon
->relaunching
) {
3378 icon
->main_window
= None
;
3380 wDockFinishLaunch(icon
);
3382 if (status
== 111) {
3386 #ifdef USE_DOCK_XDND
3387 if (icon
->drop_launch
)
3388 cmd
= icon
->dnd_command
;
3391 if (icon
->paste_launch
)
3392 cmd
= icon
->paste_command
;
3394 cmd
= icon
->command
;
3396 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3398 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3405 /* This function is called when the dock switches state between
3406 * "normal" (including auto-raise/lower) and "keep on top". It is
3407 * therefore clearly distinct from wDockLower/Raise, which are called
3408 * each time a not-kept-on-top dock is lowered/raised. */
3409 static void toggleLowered(WDock
*dock
)
3415 if (!dock
->lowered
) {
3416 newlevel
= WMNormalLevel
;
3419 newlevel
= WMDockLevel
;
3423 for (i
= 0; i
< dock
->max_icons
; i
++) {
3424 tmp
= dock
->icon_array
[i
];
3428 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3430 /* When the dock is no longer "on top", explicitly lower it as well.
3431 * It saves some CPU cycles (probably) to do it ourselves here
3432 * rather than calling wDockLower at the end of toggleLowered */
3434 wLowerFrame(tmp
->icon
->core
);
3437 if (dock
->type
== WM_DOCK
) {
3438 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
3439 toggleLowered(dc
->adrawer
);
3441 wScreenUpdateUsableArea(dock
->screen_ptr
);
3445 static void toggleCollapsed(WDock
*dock
)
3447 if (dock
->collapsed
) {
3448 dock
->collapsed
= 0;
3449 wDockShowIcons(dock
);
3451 dock
->collapsed
= 1;
3452 wDockHideIcons(dock
);
3456 static void openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3458 WScreen
*scr
= dock
->screen_ptr
;
3459 WObjDescriptor
*desc
;
3461 WApplication
*wapp
= NULL
;
3465 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3467 if (dock
->type
== WM_DOCK
) {
3468 /* Dock position menu */
3469 updateDockPositionMenu(scr
->dock_pos_menu
, dock
);
3470 dock
->menu
->flags
.realized
= 0;
3471 if (!wPreferences
.flags
.nodrawer
) {
3473 entry
= dock
->menu
->entries
[++index
];
3474 entry
->clientdata
= aicon
;
3475 wMenuSetEnabled(dock
->menu
, index
, True
);
3478 /* clip/drawer options */
3479 if (scr
->clip_options
)
3480 updateClipOptionsMenu(scr
->clip_options
, dock
);
3482 n_selected
= numberOfSelectedIcons(dock
);
3484 if (dock
->type
== WM_CLIP
) {
3485 /* Rename Workspace */
3486 entry
= dock
->menu
->entries
[++index
];
3487 if (aicon
== scr
->clip_icon
) {
3488 entry
->callback
= renameCallback
;
3489 entry
->clientdata
= dock
;
3490 entry
->flags
.indicator
= 0;
3491 entry
->text
= _("Rename Workspace");
3493 entry
->callback
= omnipresentCallback
;
3494 entry
->clientdata
= aicon
;
3495 if (n_selected
> 0) {
3496 entry
->flags
.indicator
= 0;
3497 entry
->text
= _("Toggle Omnipresent");
3499 entry
->flags
.indicator
= 1;
3500 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3501 entry
->flags
.indicator_type
= MI_CHECK
;
3502 entry
->text
= _("Omnipresent");
3507 /* select/unselect icon */
3508 entry
= dock
->menu
->entries
[++index
];
3509 entry
->clientdata
= aicon
;
3510 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3511 wMenuSetEnabled(dock
->menu
, index
, aicon
!= scr
->clip_icon
&& !wIsADrawer(aicon
));
3513 /* select/unselect all icons */
3514 entry
= dock
->menu
->entries
[++index
];
3515 entry
->clientdata
= aicon
;
3517 entry
->text
= _("Unselect All Icons");
3519 entry
->text
= _("Select All Icons");
3521 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3524 entry
= dock
->menu
->entries
[++index
];
3525 entry
->clientdata
= aicon
;
3527 entry
->text
= _("Keep Icons");
3529 entry
->text
= _("Keep Icon");
3531 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3533 if (dock
->type
== WM_CLIP
) {
3534 /* this is the workspace submenu part */
3535 entry
= dock
->menu
->entries
[++index
];
3537 entry
->text
= _("Move Icons To");
3539 entry
->text
= _("Move Icon To");
3541 if (scr
->clip_submenu
)
3542 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3544 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3547 /* remove icon(s) */
3548 entry
= dock
->menu
->entries
[++index
];
3549 entry
->clientdata
= aicon
;
3551 entry
->text
= _("Remove Icons");
3553 entry
->text
= _("Remove Icon");
3555 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3557 /* attract icon(s) */
3558 entry
= dock
->menu
->entries
[++index
];
3559 entry
->clientdata
= aicon
;
3561 dock
->menu
->flags
.realized
= 0;
3562 wMenuRealize(dock
->menu
);
3565 if (aicon
->icon
->owner
)
3566 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3571 entry
= dock
->menu
->entries
[++index
];
3572 entry
->clientdata
= aicon
;
3573 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3576 entry
= dock
->menu
->entries
[++index
];
3577 entry
->clientdata
= aicon
;
3578 if (wapp
&& wapp
->flags
.hidden
)
3579 entry
->text
= _("Unhide Here");
3581 entry
->text
= _("Bring Here");
3583 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3586 entry
= dock
->menu
->entries
[++index
];
3587 entry
->clientdata
= aicon
;
3588 if (wapp
&& wapp
->flags
.hidden
)
3589 entry
->text
= _("Unhide");
3591 entry
->text
= _("Hide");
3593 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3596 entry
= dock
->menu
->entries
[++index
];
3597 entry
->clientdata
= aicon
;
3598 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3600 /* kill or remove drawer */
3601 entry
= dock
->menu
->entries
[++index
];
3602 entry
->clientdata
= aicon
;
3603 if (wIsADrawer(aicon
)) {
3604 entry
->callback
= removeDrawerCallback
;
3605 entry
->text
= _("Remove drawer");
3606 wMenuSetEnabled(dock
->menu
, index
, True
);
3608 entry
->callback
= killCallback
;
3609 entry
->text
= _("Kill");
3610 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3613 if (!dock
->menu
->flags
.realized
)
3614 wMenuRealize(dock
->menu
);
3616 if (dock
->type
== WM_CLIP
|| dock
->type
== WM_DRAWER
) {
3617 /*x_pos = event->xbutton.x_root+2; */
3618 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3621 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3622 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3625 x_pos
= dock
->x_pos
;
3626 if (dock
->on_right_side
)
3627 x_pos
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
3628 - dock
->menu
->frame
->core
->width
- 3;
3631 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3633 /* allow drag select */
3634 event
->xany
.send_event
= True
;
3635 desc
= &dock
->menu
->menu
->descriptor
;
3636 (*desc
->handle_mousedown
) (desc
, event
);
3639 /******************************************************************/
3640 static void iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3642 WAppIcon
*btn
= desc
->parent
;
3643 WDock
*dock
= btn
->dock
;
3644 WApplication
*wapp
= NULL
;
3647 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3648 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3650 assert(wapp
!= NULL
);
3652 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3654 /* go to the last workspace that the user worked on the app */
3655 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
&& !unhideHere
)
3656 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3658 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3660 if (event
->xbutton
.state
& MOD_MASK
)
3661 wHideOtherApplications(btn
->icon
->owner
);
3663 if (event
->xbutton
.button
== Button1
) {
3664 if (event
->xbutton
.state
& MOD_MASK
) {
3665 /* raise/lower dock */
3666 toggleLowered(dock
);
3667 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3668 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
)
3669 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3670 else if (wPreferences
.flags
.clip_merged_in_dock
) {
3671 // Is actually the dock
3674 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3675 launchDockedApplication(btn
, False
);
3679 wShowInfoPanel(dock
->screen_ptr
);
3683 toggleCollapsed(dock
);
3684 } else if (wIsADrawer(btn
)) {
3685 toggleCollapsed(dock
);
3686 } else if (btn
->command
) {
3687 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3688 launchDockedApplication(btn
, False
);
3689 } else if (btn
->xindex
== 0 && btn
->yindex
== 0 && btn
->dock
->type
== WM_DOCK
) {
3690 wShowInfoPanel(dock
->screen_ptr
);
3696 static void handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3698 WScreen
*scr
= dock
->screen_ptr
;
3699 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3700 WIcon
*icon
= aicon
->icon
;
3703 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;;
3704 int shad_x
= x
, shad_y
= y
;
3706 int grabbed
= 0, done
, previously_on_right
, now_on_right
, previous_x_pos
, i
;
3707 Pixmap ghost
= None
;
3708 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3710 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3711 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3712 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
)
3713 wwarning("pointer grab failed for dock move");
3715 if (dock
->type
== WM_DRAWER
) {
3717 wins
[0] = icon
->core
->window
;
3718 wins
[1] = scr
->dock_shadow
;
3719 XRestackWindows(dpy
, wins
, 2);
3720 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3721 ICON_SIZE
, ICON_SIZE
);
3723 if (icon
->pixmap
!=None
)
3724 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3726 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3728 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3729 XClearWindow(dpy
, scr
->dock_shadow
);
3731 XMapWindow(dpy
, scr
->dock_shadow
);
3734 previously_on_right
= now_on_right
= dock
->on_right_side
;
3735 previous_x_pos
= dock
->x_pos
;
3738 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3739 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3746 /* It means the cursor moved so fast that it entered
3747 * something else (if moving slowly, it would have
3748 * stayed in the dock that is being moved. Ignore such
3749 * "spurious" EnterNotifiy's */
3754 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3755 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3756 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3757 | ButtonReleaseMask
| ButtonPressMask
,
3758 wPreferences
.cursor
[WCUR_MOVE
], CurrentTime
);
3763 switch (dock
->type
) {
3765 x
= ev
.xmotion
.x_root
- ofs_x
;
3766 y
= ev
.xmotion
.y_root
- ofs_y
;
3767 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3768 moveDock(dock
, x
, y
);
3771 x
= ev
.xmotion
.x_root
- ofs_x
;
3772 y
= ev
.xmotion
.y_root
- ofs_y
;
3773 if (previously_on_right
)
3775 now_on_right
= (ev
.xmotion
.x_root
>= previous_x_pos
- ICON_SIZE
);
3779 now_on_right
= (ev
.xmotion
.x_root
> previous_x_pos
+ ICON_SIZE
* 2);
3781 if (now_on_right
!= dock
->on_right_side
)
3783 dock
->on_right_side
= now_on_right
;
3785 wArrangeIcons(scr
, False
);
3787 // Also perform the vertical move
3788 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3789 moveDock(dock
, dock
->x_pos
, y
);
3790 if (wPreferences
.flags
.wrap_appicons_in_dock
)
3792 for (i
= 0; i
< dock
->max_icons
; i
++) {
3793 int new_y
, new_index
, j
, ok
;
3795 tmpaicon
= dock
->icon_array
[i
];
3796 if (tmpaicon
== NULL
)
3798 if (onScreen(scr
, tmpaicon
->x_pos
, tmpaicon
->y_pos
))
3800 new_y
= (tmpaicon
->y_pos
+ ICON_SIZE
* dock
->max_icons
) % (ICON_SIZE
* dock
->max_icons
);
3801 new_index
= (new_y
- dock
->y_pos
) / ICON_SIZE
;
3802 if (!onScreen(scr
, tmpaicon
->x_pos
, new_y
))
3805 for (j
= 0; j
< dock
->max_icons
; j
++)
3807 if (dock
->icon_array
[j
] != NULL
&&
3808 dock
->icon_array
[j
]->yindex
== new_index
)
3814 if (!ok
|| getDrawer(scr
, new_index
) != NULL
)
3816 wDockReattachIcon(dock
, tmpaicon
, tmpaicon
->xindex
, new_index
);
3818 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3820 int new_y
, new_index
, j
, ok
;
3821 tmpaicon
= dc
->adrawer
->icon_array
[0];
3822 if (onScreen(scr
, tmpaicon
->x_pos
, tmpaicon
->y_pos
))
3824 new_y
= (tmpaicon
->y_pos
+ ICON_SIZE
* dock
->max_icons
) % (ICON_SIZE
* dock
->max_icons
);
3825 new_index
= (new_y
- dock
->y_pos
) / ICON_SIZE
;
3826 if (!onScreen(scr
, tmpaicon
->x_pos
, new_y
))
3829 for (j
= 0; j
< dock
->max_icons
; j
++)
3831 if (dock
->icon_array
[j
] != NULL
&&
3832 dock
->icon_array
[j
]->yindex
== new_index
)
3838 if (!ok
|| getDrawer(scr
, new_index
) != NULL
)
3840 moveDock(dc
->adrawer
, tmpaicon
->x_pos
, new_y
);
3846 WDock
*real_dock
= dock
->screen_ptr
->dock
;
3849 x
= ev
.xmotion
.x_root
- ofs_x
;
3850 y
= ev
.xmotion
.y_root
- ofs_y
;
3851 snapped
= wDockSnapIcon(real_dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3853 shad_x
= real_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3854 shad_y
= real_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3855 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3857 moveDock(dock
, x
, y
);
3867 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3869 XUngrabPointer(dpy
, CurrentTime
);
3870 if (dock
->type
== WM_DRAWER
) {
3871 Window wins
[dock
->icon_count
];
3875 * When the dock is on the Right side, the index of the icons are negative to
3876 * reflect the fact that they are placed on the other side of the dock; we use
3877 * an offset here so we can have an always positive index for the storage in
3880 if (dock
->on_right_side
)
3881 offset_index
= dock
->icon_count
- 1;
3885 for (i
= 0; i
< dock
->max_icons
; i
++) {
3886 tmpaicon
= dock
->icon_array
[i
];
3887 if (tmpaicon
== NULL
)
3889 wins
[tmpaicon
->xindex
+ offset_index
] = tmpaicon
->icon
->core
->window
;
3891 slide_windows(wins
, dock
->icon_count
,
3892 (dock
->on_right_side
? x
- (dock
->icon_count
- 1) * ICON_SIZE
: x
),
3894 (dock
->on_right_side
? shad_x
- (dock
->icon_count
- 1) * ICON_SIZE
: shad_x
),
3896 XUnmapWindow(dpy
, scr
->dock_shadow
);
3897 moveDock(dock
, shad_x
, shad_y
);
3898 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3906 XFreePixmap(dpy
, ghost
);
3907 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3912 static int getClipButton(int px
, int py
)
3914 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3916 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3919 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3920 return CLIP_FORWARD
;
3921 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3927 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3930 int done
, direction
, new_ws
;
3932 WDock
*clip
= scr
->clip_icon
->dock
;
3934 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3936 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3937 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3939 wClipIconPaint(scr
->clip_icon
);
3942 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3949 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3950 if (new_dir
!= direction
) {
3951 direction
= new_dir
;
3952 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3953 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3954 wClipIconPaint(scr
->clip_icon
);
3962 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3967 clip
->lclip_button_pushed
= 0;
3968 clip
->rclip_button_pushed
= 0;
3970 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3972 if (direction
== CLIP_FORWARD
) {
3973 if (scr
->current_workspace
< scr
->workspace_count
- 1)
3974 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3975 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
- 1)
3976 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3977 else if (wPreferences
.ws_cycle
)
3978 wWorkspaceChange(scr
, 0);
3979 } else if (direction
== CLIP_REWIND
) {
3980 if (scr
->current_workspace
> 0)
3981 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
3982 else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
)
3983 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
3986 wClipIconPaint(scr
->clip_icon
);
3989 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3991 WAppIcon
*aicon
= desc
->parent
;
3992 WDock
*dock
= aicon
->dock
;
3993 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3995 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3998 scr
->last_dock
= dock
;
4000 if (dock
->menu
->flags
.mapped
)
4001 wMenuUnmap(dock
->menu
);
4003 if (IsDoubleClick(scr
, event
)) {
4004 /* double-click was not in the main clip icon */
4005 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
4006 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
4007 iconDblClick(desc
, event
);
4012 if (event
->xbutton
.button
== Button1
) {
4013 if (event
->xbutton
.state
& MOD_MASK
)
4018 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
&& dock
->type
!= WM_DOCK
) {
4019 wIconSelect(aicon
->icon
);
4023 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
4024 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
&&
4025 (dock
->type
== WM_CLIP
|| (dock
->type
== WM_DOCK
&& wPreferences
.flags
.clip_merged_in_dock
)))
4026 handleClipChangeWorkspace(scr
, event
);
4028 handleDockMove(dock
, aicon
, event
);
4030 Bool hasMoved
= wHandleAppIconMove(aicon
, event
);
4031 if (wPreferences
.single_click
&& !hasMoved
)
4032 iconDblClick(desc
, event
);
4034 } else if (event
->xbutton
.button
== Button2
&& aicon
== scr
->clip_icon
) {
4035 if (!scr
->clip_ws_menu
)
4036 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
4038 if (scr
->clip_ws_menu
) {
4039 WMenu
*wsMenu
= scr
->clip_ws_menu
;
4042 wWorkspaceMenuUpdate(scr
, wsMenu
);
4044 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
4047 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
4048 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
4050 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
4052 desc
= &wsMenu
->menu
->descriptor
;
4053 event
->xany
.send_event
= True
;
4054 (*desc
->handle_mousedown
) (desc
, event
);
4056 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
4057 (event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
) {
4058 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
4059 } else if (event
->xbutton
.button
== Button3
) {
4060 if (event
->xbutton
.send_event
&&
4061 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
4062 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
4063 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
4064 wwarning("pointer grab failed for dockicon menu");
4068 openDockMenu(dock
, aicon
, event
);
4069 } else if (event
->xbutton
.button
== Button2
) {
4070 WAppIcon
*btn
= desc
->parent
;
4072 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
4073 launchDockedApplication(btn
, True
);
4074 } else if (event
->xbutton
.button
== Button4
&& dock
->type
== WM_CLIP
) {
4075 wWorkspaceRelativeChange(scr
, 1);
4076 } else if (event
->xbutton
.button
== Button5
&& dock
->type
== WM_CLIP
) {
4077 wWorkspaceRelativeChange(scr
, -1);
4081 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
4083 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
4087 /* Parameter not used, but tell the compiler that it is ok */
4090 assert(event
->type
== EnterNotify
);
4092 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
4095 scr
= btn
->icon
->core
->screen_ptr
;
4101 /* The auto raise/lower code */
4102 tmp
= (dock
->type
== WM_DRAWER
? scr
->dock
: dock
);
4103 if (tmp
->auto_lower_magic
) {
4104 WMDeleteTimerHandler(tmp
->auto_lower_magic
);
4105 tmp
->auto_lower_magic
= NULL
;
4107 if (tmp
->auto_raise_lower
&& !tmp
->auto_raise_magic
)
4108 tmp
->auto_raise_magic
= WMAddTimerHandler(wPreferences
.clip_auto_raise_delay
, clipAutoRaise
, (void *) tmp
);
4110 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4113 /* The auto expand/collapse code */
4114 if (dock
->auto_collapse_magic
) {
4115 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
4116 dock
->auto_collapse_magic
= NULL
;
4118 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
)
4119 dock
->auto_expand_magic
= WMAddTimerHandler(wPreferences
.clip_auto_expand_delay
, clipAutoExpand
, (void *)dock
);
4122 static void clipLeave(WDock
*dock
)
4125 WObjDescriptor
*desc
= NULL
;
4131 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
4132 if (XFindContext(dpy
, event
.xcrossing
.window
, w_global
.context
.client_win
,
4133 (XPointer
*) & desc
) != XCNOENT
4134 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
4135 && ((WAppIcon
*) desc
->parent
)->dock
== dock
) {
4136 /* We haven't left the dock/clip/drawer yet */
4137 XPutBackEvent(dpy
, &event
);
4141 XPutBackEvent(dpy
, &event
);
4143 /* We entered a withdrawn window, so we're still in Clip */
4147 tmp
= (dock
->type
== WM_DRAWER
? dock
->screen_ptr
->dock
: dock
);
4148 if (tmp
->auto_raise_magic
) {
4149 WMDeleteTimerHandler(tmp
->auto_raise_magic
);
4150 tmp
->auto_raise_magic
= NULL
;
4152 if (tmp
->auto_raise_lower
&& !tmp
->auto_lower_magic
)
4153 tmp
->auto_lower_magic
= WMAddTimerHandler(wPreferences
.clip_auto_lower_delay
, clipAutoLower
, (void *)tmp
);
4155 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4158 if (dock
->auto_expand_magic
) {
4159 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4160 dock
->auto_expand_magic
= NULL
;
4162 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
)
4163 dock
->auto_collapse_magic
= WMAddTimerHandler(wPreferences
.clip_auto_collapse_delay
, clipAutoCollapse
, (void *)dock
);
4166 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4168 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
4170 /* Parameter not used, but tell the compiler that it is ok */
4173 assert(event
->type
== LeaveNotify
);
4175 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
4178 clipLeave(btn
->dock
);
4181 static void clipAutoCollapse(void *cdata
)
4183 WDock
*dock
= (WDock
*) cdata
;
4185 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4188 if (dock
->auto_collapse
) {
4189 dock
->collapsed
= 1;
4190 wDockHideIcons(dock
);
4192 dock
->auto_collapse_magic
= NULL
;
4195 static void clipAutoExpand(void *cdata
)
4197 WDock
*dock
= (WDock
*) cdata
;
4199 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4202 if (dock
->auto_collapse
) {
4203 dock
->collapsed
= 0;
4204 wDockShowIcons(dock
);
4206 dock
->auto_expand_magic
= NULL
;
4209 static void clipAutoLower(void *cdata
)
4211 WDock
*dock
= (WDock
*) cdata
;
4213 if (dock
->auto_raise_lower
)
4216 dock
->auto_lower_magic
= NULL
;
4219 static void clipAutoRaise(void *cdata
)
4221 WDock
*dock
= (WDock
*) cdata
;
4223 if (dock
->auto_raise_lower
)
4226 dock
->auto_raise_magic
= NULL
;
4229 static Bool
iconCanBeOmnipresent(WAppIcon
*aicon
)
4231 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4236 for (i
= 0; i
< scr
->workspace_count
; i
++) {
4237 clip
= scr
->workspaces
[i
]->clip
;
4239 if (clip
== aicon
->dock
)
4242 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4243 return False
; /* Clip is full in some workspace */
4245 for (j
= 0; j
< clip
->max_icons
; j
++) {
4246 btn
= clip
->icon_array
[j
];
4247 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
4255 int wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
4257 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4258 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4259 int status
= WO_SUCCESS
;
4261 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== scr
->clip_icon
)
4262 return WO_NOT_APPLICABLE
;
4264 if (aicon
->omnipresent
== omnipresent
)
4268 if (iconCanBeOmnipresent(aicon
)) {
4269 aicon
->omnipresent
= 1;
4270 new_entry
= wmalloc(sizeof(WAppIconChain
));
4271 new_entry
->aicon
= aicon
;
4272 new_entry
->next
= scr
->global_icons
;
4273 scr
->global_icons
= new_entry
;
4274 scr
->global_icon_count
++;
4276 aicon
->omnipresent
= 0;
4280 aicon
->omnipresent
= 0;
4281 if (aicon
== scr
->global_icons
->aicon
) {
4282 tmp
= scr
->global_icons
->next
;
4283 wfree(scr
->global_icons
);
4284 scr
->global_icons
= tmp
;
4285 scr
->global_icon_count
--;
4287 tmp
= scr
->global_icons
;
4289 if (tmp
->next
->aicon
== aicon
) {
4290 tmp1
= tmp
->next
->next
;
4293 scr
->global_icon_count
--;
4301 wAppIconPaint(aicon
);
4306 static void drawerAppendToChain(WScreen
*scr
, WDock
*drawer
)
4308 WDrawerChain
**where_to_add
;
4310 where_to_add
= &scr
->drawers
;
4311 while ((*where_to_add
) != NULL
) {
4312 where_to_add
= &(*where_to_add
)->next
;
4315 *where_to_add
= wmalloc(sizeof(WDrawerChain
));
4316 (*where_to_add
)->adrawer
= drawer
;
4317 (*where_to_add
)->next
= NULL
;
4318 scr
->drawer_count
++;
4322 static void drawerRemoveFromChain(WScreen
*scr
, WDock
*drawer
)
4324 WDrawerChain
*next
, **to_remove
;
4326 to_remove
= &scr
->drawers
;
4328 if (*to_remove
== NULL
) {
4329 wwarning("The drawer to be removed can not be found.");
4332 if ((*to_remove
)->adrawer
== drawer
)
4335 to_remove
= &(*to_remove
)->next
;
4337 next
= (*to_remove
)->next
;
4340 scr
->drawer_count
--;
4344 /* Don't free the returned string. Duplicate it. */
4345 static char * findUniqueName(WScreen
*scr
, const char *instance_basename
)
4347 static char buffer
[128];
4350 Bool already_in_use
= True
;
4352 #define UNIQUE_NAME_WATCHDOG 128
4353 for (i
= 0; already_in_use
&& i
< UNIQUE_NAME_WATCHDOG
; i
++) {
4354 snprintf(buffer
, sizeof buffer
, "%s%d", instance_basename
, i
);
4356 already_in_use
= False
;
4358 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4359 if (!strncmp(dc
->adrawer
->icon_array
[0]->wm_instance
, buffer
,
4361 already_in_use
= True
;
4367 if (i
== UNIQUE_NAME_WATCHDOG
)
4368 wwarning("Couldn't find a unique name for drawer in %d attempts.", i
);
4369 #undef UNIQUE_NAME_WATCHDOG
4375 static void drawerIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
4377 /* Parameter not used, but tell the compiler that it is ok */
4380 wDrawerIconPaint((WAppIcon
*) desc
->parent
);
4384 static int addADrawer(WScreen
*scr
)
4386 int i
, y
, sig
, found_y
;
4387 WDock
*drawer
, *dock
= scr
->dock
;
4389 char can_be_here
[2 * dock
->max_icons
- 1];
4391 if (dock
->icon_count
+ scr
->drawer_count
>= dock
->max_icons
)
4394 for (y
= -dock
->max_icons
+ 1; y
< dock
->max_icons
; y
++) {
4395 can_be_here
[y
+ dock
->max_icons
- 1] = True
;
4397 for (i
= 0; i
< dock
->max_icons
; i
++) {
4398 if (dock
->icon_array
[i
] != NULL
)
4399 can_be_here
[dock
->icon_array
[i
]->yindex
+ dock
->max_icons
- 1] = False
;
4401 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4402 y
= (int) ((dc
->adrawer
->y_pos
- dock
->y_pos
) / ICON_SIZE
);
4403 can_be_here
[y
+ dock
->max_icons
- 1] = False
;
4407 for (sig
= 1; !found_y
&& sig
> -2; sig
-= 2) // 1, then -1
4409 for (y
= sig
; sig
* y
< dock
->max_icons
; y
+= sig
)
4411 if (can_be_here
[y
+ dock
->max_icons
- 1] &&
4412 onScreen(scr
, dock
->x_pos
, dock
->y_pos
+ y
* ICON_SIZE
))
4421 /* This can happen even when dock->icon_count + scr->drawer_count
4422 * < dock->max_icons when the dock is not aligned on an
4423 * ICON_SIZE multiple, as some space is lost above and under it */
4426 drawer
= wDockCreate(scr
, WM_DRAWER
, NULL
);
4427 drawer
->lowered
= scr
->dock
->lowered
;
4428 if (!drawer
->lowered
)
4429 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMDockLevel
);
4431 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMNormalLevel
);
4432 drawer
->auto_raise_lower
= scr
->dock
->auto_raise_lower
;
4433 drawer
->x_pos
= dock
->x_pos
;
4434 drawer
->y_pos
= dock
->y_pos
+ ICON_SIZE
* y
;
4435 drawer
->icon_array
[0]->xindex
= 0;
4436 drawer
->icon_array
[0]->yindex
= 0;
4437 drawer
->icon_array
[0]->x_pos
= drawer
->x_pos
;
4438 drawer
->icon_array
[0]->y_pos
= drawer
->y_pos
;
4439 XMoveWindow(dpy
, drawer
->icon_array
[0]->icon
->core
->window
,
4440 drawer
->icon_array
[0]->x_pos
, drawer
->icon_array
[0]->y_pos
);
4446 static void addADrawerCallback(WMenu
*menu
, WMenuEntry
*entry
)
4448 /* Parameter not used, but tell the compiler that it is ok */
4451 assert(entry
->clientdata
!=NULL
);
4452 addADrawer(((WAppIcon
*) entry
->clientdata
)->dock
->screen_ptr
);
4456 static void drawerDestroy(WDock
*drawer
)
4460 WAppIcon
*aicon
= NULL
;
4466 scr
= drawer
->screen_ptr
;
4468 /* Note regarding menus: we can't delete any dock/clip/drawer menu, because
4469 * that would (attempt to) wfree some memory in gettext library (see menu
4470 * entries that have several "versions", such like "Hide" and "Unhide"). */
4471 wDefaultPurgeInfo(drawer
->icon_array
[0]->wm_instance
,
4472 drawer
->icon_array
[0]->wm_class
);
4474 if (drawer
->icon_count
== 2) {
4475 /* Drawer contains a single appicon: dock it where the drawer was */
4476 for (i
= 1; i
< drawer
->max_icons
; i
++) {
4477 aicon
= drawer
->icon_array
[i
];
4482 wDockMoveIconBetweenDocks(drawer
, scr
->dock
, aicon
,
4483 0, (drawer
->y_pos
- scr
->dock
->y_pos
) / ICON_SIZE
);
4484 XMoveWindow(dpy
, aicon
->icon
->core
->window
, drawer
->x_pos
, drawer
->y_pos
);
4485 XMapWindow(dpy
, aicon
->icon
->core
->window
);
4486 } else if (drawer
->icon_count
> 2) {
4487 icons
= WMCreateArray(drawer
->icon_count
- 1);
4488 for (i
= 1; i
< drawer
->max_icons
; i
++) {
4489 aicon
= drawer
->icon_array
[i
];
4492 WMAddToArray(icons
, aicon
);
4494 removeIcons(icons
, drawer
);
4497 if (drawer
->auto_collapse_magic
) {
4498 WMDeleteTimerHandler(drawer
->auto_collapse_magic
);
4499 drawer
->auto_collapse_magic
= NULL
;
4501 if (drawer
->auto_lower_magic
) {
4502 WMDeleteTimerHandler(drawer
->auto_lower_magic
);
4503 drawer
->auto_lower_magic
= NULL
;
4506 wAppIconDestroy(drawer
->icon_array
[0]);
4507 wfree(drawer
->icon_array
);
4508 drawer
->icon_array
= NULL
;
4510 drawerRemoveFromChain(scr
, drawer
);
4511 if (scr
->last_dock
== drawer
)
4512 scr
->last_dock
= NULL
;
4513 if (scr
->attracting_drawer
== drawer
)
4514 scr
->attracting_drawer
= NULL
;
4520 static void removeDrawerCallback(WMenu
*menu
, WMenuEntry
*entry
)
4522 WDock
*dock
= ((WAppIcon
*)entry
->clientdata
)->dock
;
4524 /* Parameter not used, but tell the compiler that it is ok */
4527 assert(dock
!= NULL
);
4529 if (dock
->icon_count
> 2) {
4530 if (wMessageDialog(dock
->screen_ptr
, _("Drawer"),
4531 _("All icons in this drawer will be detached!"),
4532 _("OK"), _("Cancel"), NULL
) != WAPRDefault
)
4535 drawerDestroy(dock
);
4539 void wDrawerIconPaint(WAppIcon
*dicon
)
4541 Window win
= dicon
->icon
->core
->window
;
4542 WScreen
*scr
= dicon
->icon
->core
->screen_ptr
;
4544 GC gc
= scr
->draw_gc
;
4547 wIconPaint(dicon
->icon
);
4549 if (!dicon
->dock
->collapsed
)
4550 color
= scr
->clip_title_color
[CLIP_NORMAL
];
4552 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
4553 XSetForeground(dpy
, gc
, WMColorPixel(color
));
4555 if (dicon
->dock
->on_right_side
) {
4556 p
[0].x
= p
[3].x
= 10;
4557 p
[0].y
= p
[3].y
= ICON_SIZE
/ 2 - 5;
4559 p
[1].y
= ICON_SIZE
/ 2 + 5;
4561 p
[2].y
= ICON_SIZE
/ 2;
4564 p
[0].x
= p
[3].x
= ICON_SIZE
-1 - 10;
4565 p
[0].y
= p
[3].y
= ICON_SIZE
/ 2 - 5;
4566 p
[1].x
= ICON_SIZE
-1 - 10;
4567 p
[1].y
= ICON_SIZE
/ 2 + 5;
4568 p
[2].x
= ICON_SIZE
-1 - 5;
4569 p
[2].y
= ICON_SIZE
/ 2;
4571 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
4572 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
4576 RImage
* wDrawerMakeTile(WScreen
*scr
, RImage
*normalTile
)
4578 RImage
*tile
= RCloneImage(normalTile
);
4583 dark
.red
= dark
.green
= dark
.blue
= 60;
4586 light
.red
= light
.green
= light
.blue
= 80;
4589 if (!scr
->dock
|| scr
->dock
->on_right_side
) {
4590 ROperateLine(tile
, RSubtractOperation
, 11, ICON_SIZE
/ 2 - 7,
4591 4, ICON_SIZE
/ 2, &dark
); /* / */
4592 ROperateLine(tile
, RSubtractOperation
, 11, ICON_SIZE
/ 2 + 7,
4593 4, ICON_SIZE
/ 2, &dark
); /* \ */
4594 ROperateLine(tile
, RAddOperation
, 11, ICON_SIZE
/ 2 - 7,
4595 11, ICON_SIZE
/ 2 + 7, &light
); /* | */
4598 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 - 7,
4599 ICON_SIZE
-1 - 4, ICON_SIZE
/ 2, &dark
); /* \ */
4600 ROperateLine(tile
, RAddOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 + 7,
4601 ICON_SIZE
-1 - 4, ICON_SIZE
/ 2, &light
); /* / */
4602 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 - 7,
4603 ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 + 7, &dark
); /* | */
4609 static void swapDrawer(WDock
*drawer
, int new_x
)
4613 drawer
->on_right_side
= drawer
->screen_ptr
->dock
->on_right_side
;
4614 drawer
->x_pos
= new_x
;
4616 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4619 ai
= drawer
->icon_array
[i
];
4622 if (drawer
->on_right_side
)
4623 ai
->xindex
= -abs(ai
->xindex
);
4625 ai
->xindex
= abs(ai
->xindex
);
4626 ai
->x_pos
= new_x
+ ai
->xindex
* ICON_SIZE
;
4628 /* Update drawer's tile */
4630 wIconUpdate(ai
->icon
);
4631 wDrawerIconPaint(ai
);
4633 XMoveWindow(dpy
, ai
->icon
->core
->window
, ai
->x_pos
, ai
->y_pos
);
4638 static void swapDrawers(WScreen
*scr
, int new_x
)
4642 if (scr
->drawer_tile
)
4643 RReleaseImage(scr
->drawer_tile
);
4645 scr
->drawer_tile
= wDrawerMakeTile(scr
, scr
->icon_tile
);
4647 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
4648 swapDrawer(dc
->adrawer
, new_x
);
4652 int wIsADrawer(WAppIcon
*aicon
)
4654 return aicon
&& aicon
->dock
&&
4655 aicon
->dock
->type
== WM_DRAWER
&& aicon
->dock
->icon_array
[0] == aicon
;
4659 static WDock
* getDrawer(WScreen
*scr
, int y_index
)
4663 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4664 if (dc
->adrawer
->y_pos
- scr
->dock
->y_pos
== y_index
* ICON_SIZE
)
4672 /* Find the "hole" a moving appicon created when snapped into the
4673 * drawer. redocking is a boolean. If the moving appicon comes from the
4674 * drawer, drawer->icon_count is correct. If not, redocking is then false and
4675 * there are now drawer->icon_count plus one appicons in the drawer. */
4676 static int indexOfHole(WDock
*drawer
, WAppIcon
*moving_aicon
, int redocking
)
4678 int index_of_hole
, i
;
4680 /* Classic interview question...
4682 * We have n-1 (n = drawer->icon_count-1 or drawer->icon_count, see
4683 * redocking) appicons, whose xindex are unique in [1..n]. One is missing:
4684 * that's where the ghost of the moving appicon is, that's what the
4685 * function should return.
4687 * We compute 1+2+...+n (this sum is equal to n*(n+1)/2), we subtract to
4688 * this sum the xindex of each of the n-1 appicons, and we get the correct
4692 index_of_hole
= (drawer
->icon_count
- 1) * drawer
->icon_count
/ 2;
4694 index_of_hole
= drawer
->icon_count
* (drawer
->icon_count
+ 1) / 2;
4696 index_of_hole
*= (drawer
->on_right_side
? -1 : 1);
4698 for (i
= 1; i
< drawer
->max_icons
; i
++) {
4699 if (drawer
->icon_array
[i
] && drawer
->icon_array
[i
] != moving_aicon
)
4700 index_of_hole
-= drawer
->icon_array
[i
]->xindex
;
4702 /* wmessage(" Index of the moving appicon is %d (%sredocking)", index_of_hole, (redocking ? "" : "not ")); */
4703 if (abs(index_of_hole
) > abs(drawer
->icon_count
) - (redocking
? 1 : 0))
4704 wwarning(" index_of_hole is too large ! (%d greater than %d)",
4705 index_of_hole
, abs(drawer
->icon_count
) - (redocking
? 1 : 0));
4706 if (index_of_hole
== 0)
4707 wwarning(" index_of_hole == 0 (%sredocking, icon_count == %d)", (redocking
? "" : "not "), drawer
->icon_count
);
4709 return index_of_hole
;
4713 void wSlideAppicons(WAppIcon
**appicons
, int n
, int to_the_left
)
4716 int leftmost
= -1, min_index
= 9999, from_x
= -1; // leftmost and from_x initialized to avoid warning
4723 for (i
= 0; i
< n
; i
++) {
4724 aicon
= appicons
[i
];
4725 aicon
->xindex
+= (to_the_left
? -1 : +1);
4726 if (aicon
->xindex
< min_index
) {
4727 min_index
= aicon
->xindex
;
4729 from_x
= aicon
->x_pos
;
4731 aicon
->x_pos
+= (to_the_left
? -ICON_SIZE
: +ICON_SIZE
);
4734 for (i
= 0; i
< n
; i
++) {
4735 aicon
= appicons
[i
];
4736 wins
[aicon
->xindex
- min_index
] = aicon
->icon
->core
->window
;
4738 aicon
= appicons
[leftmost
];
4739 slide_windows(wins
, n
, from_x
, aicon
->y_pos
, aicon
->x_pos
, aicon
->y_pos
);
4743 void wDrawerFillTheGap(WDock
*drawer
, WAppIcon
*aicon
, Bool redocking
)
4746 int index_of_hole
= indexOfHole(drawer
, aicon
, redocking
);
4747 WAppIcon
*aicons_to_shift
[drawer
->icon_count
];
4750 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4751 WAppIcon
*ai
= drawer
->icon_array
[i
];
4752 if (ai
&& ai
!= aicon
&&
4753 abs(ai
->xindex
) > abs(index_of_hole
))
4754 aicons_to_shift
[j
++] = ai
;
4756 if (j
!= drawer
->icon_count
- abs(index_of_hole
) - (redocking
? 1 : 0))
4757 wwarning("Removing aicon at index %d from %s: j=%d but should be %d",
4758 index_of_hole
, drawer
->icon_array
[0]->wm_instance
,
4759 j
, drawer
->icon_count
- abs(index_of_hole
) - (redocking
? 1 : 0));
4760 wSlideAppicons(aicons_to_shift
, j
, !drawer
->on_right_side
);
4764 static void drawerConsolidateIcons(WDock
*drawer
)
4766 WAppIcon
*aicons_to_shift
[drawer
->icon_count
];
4767 int maxRemaining
= 0;
4770 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4771 WAppIcon
*ai
= drawer
->icon_array
[i
];
4774 sum
+= abs(ai
->xindex
);
4775 if (abs(ai
->xindex
) > maxRemaining
)
4776 maxRemaining
= abs(ai
->xindex
);
4778 while (sum
!= maxRemaining
* (maxRemaining
+ 1) / 2) { // while there is a hole
4781 // Look up for the hole at max position
4783 for (maxDeleted
= maxRemaining
- 1; maxDeleted
> 0; maxDeleted
--) {
4784 Bool foundAppIconThere
= False
;
4785 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4786 WAppIcon
*ai
= drawer
->icon_array
[i
];
4789 if (abs(ai
->xindex
) == maxDeleted
) {
4790 foundAppIconThere
= True
;
4794 if (!foundAppIconThere
)
4797 assert(maxDeleted
> 0); // would mean while test is wrong
4799 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4800 ai
= drawer
->icon_array
[i
];
4801 if (ai
!= NULL
&& abs(ai
->xindex
) > maxDeleted
)
4802 aicons_to_shift
[n
++] = ai
;
4804 assert(n
== maxRemaining
- maxDeleted
); // for the code review ;-)
4805 wSlideAppicons(aicons_to_shift
, n
, !drawer
->on_right_side
);
4806 // Efficient beancounting
4814 /* similar to wDockRestoreState, but a lot a specific stuff too... */
4815 static WDock
* drawerRestoreState(WScreen
*scr
, WMPropList
*drawer_state
)
4818 WMPropList
*apps
, *value
, *dock_state
;
4827 WMRetainPropList(drawer_state
);
4829 /* Get the instance name, and create a drawer */
4830 value
= WMGetFromPLDictionary(drawer_state
, dName
);
4831 drawer
= wDockCreate(scr
, WM_DRAWER
, WMGetFromPLString(value
));
4833 /* restore DnD command and paste command */
4834 #ifdef USE_DOCK_XDND
4835 value
= WMGetFromPLDictionary(drawer_state
, dDropCommand
);
4836 if (value
&& WMIsPLString(value
))
4837 drawer
->icon_array
[0]->dnd_command
= wstrdup(WMGetFromPLString(value
));
4838 #endif /* USE_DOCK_XDND */
4840 value
= WMGetFromPLDictionary(drawer_state
, dPasteCommand
);
4841 if (value
&& WMIsPLString(value
))
4842 drawer
->icon_array
[0]->paste_command
= wstrdup(WMGetFromPLString(value
));
4844 /* restore position */
4845 value
= WMGetFromPLDictionary(drawer_state
, dPosition
);
4846 if (!value
|| !WMIsPLString(value
))
4847 COMPLAIN("Position");
4850 if (sscanf(WMGetFromPLString(value
), "%i,%i", &x
, &y
) != 2)
4851 COMPLAIN("Position");
4853 /* check position sanity */
4854 if (x
!= scr
->dock
->x_pos
) {
4855 x
= scr
->dock
->x_pos
;
4857 y_index
= (y
- scr
->dock
->y_pos
) / ICON_SIZE
;
4858 if (y_index
>= scr
->dock
->max_icons
) {
4859 /* Here we should do something more intelligent, since it
4860 * can happen even if the user hasn't hand-edited his
4861 * G/D/State file (but uses a lower resolution). */
4862 y_index
= scr
->dock
->max_icons
- 1;
4864 y
= scr
->dock
->y_pos
+ y_index
* ICON_SIZE
;
4865 moveDock(drawer
, x
, y
);
4868 /* restore dock properties (applist and others) */
4869 dock_state
= WMGetFromPLDictionary(drawer_state
, dDock
);
4871 /* restore lowered/raised state: same as scr->dock, no matter what */
4872 drawer
->lowered
= scr
->dock
->lowered
;
4873 if (!drawer
->lowered
)
4874 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMDockLevel
);
4876 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMNormalLevel
);
4877 wRaiseFrame(drawer
->icon_array
[0]->icon
->core
);
4879 /* restore collapsed state */
4880 drawer
->collapsed
= 0;
4881 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
4882 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4883 drawer
->collapsed
= 1;
4885 /* restore auto-collapsed state */
4886 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
4887 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4888 drawer
->auto_collapse
= 1;
4889 drawer
->collapsed
= 1;
4891 drawer
->auto_collapse
= 0; // because wDockCreate sets it (drawers only)
4894 /* restore auto-raise/lower state: same as scr->dock, no matter what */
4895 drawer
->auto_raise_lower
= scr
->dock
->auto_raise_lower
;
4897 /* restore attract icons state */
4898 drawer
->attract_icons
= 0;
4899 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
4900 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4901 drawer
->attract_icons
= 1;
4902 scr
->attracting_drawer
= drawer
;
4905 /* application list */
4906 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
4912 count
= WMGetPropListItemCount(apps
);
4917 for (i
=0; i
<count
; i
++) {
4918 if (drawer
->icon_count
>= drawer
->max_icons
) {
4919 wwarning(_("there are too many icons stored in drawer. Ignoring what doesn't fit"));
4923 value
= WMGetFromPLArray(apps
, i
);
4924 aicon
= restore_icon_state(scr
, value
, WM_DRAWER
, drawer
->icon_count
);
4926 drawer
->icon_array
[drawer
->icon_count
] = aicon
;
4929 /* don't trust the stored direction sign as the dock is
4930 * dynamically positioned depending on the screen size
4932 if (drawer
->screen_ptr
->dock
->on_right_side
)
4933 aicon
->xindex
= -abs(aicon
->xindex
);
4935 aicon
->xindex
= abs(aicon
->xindex
);
4936 aicon
->dock
= drawer
;
4937 aicon
->x_pos
= drawer
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
4938 aicon
->y_pos
= drawer
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
4940 if (!drawer
->lowered
)
4941 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
4943 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
4945 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
4947 if (!drawer
->collapsed
)
4948 XMapWindow(dpy
, aicon
->icon
->core
->window
);
4949 wRaiseFrame(aicon
->icon
->core
);
4951 drawer
->icon_count
++;
4956 WMReleasePropList(drawer_state
);
4962 /* Same kind of comment than for previous function: this function is
4963 * very similar to make_icon_state, but has substential differences as
4965 static WMPropList
*drawerSaveState(WDock
*drawer
)
4967 WMPropList
*pstr
, *drawer_state
;
4971 ai
= drawer
->icon_array
[0];
4972 /* Store its name */
4973 pstr
= WMCreatePLString(ai
->wm_instance
);
4974 drawer_state
= WMCreatePLDictionary(dName
, pstr
, NULL
); /* we need this final NULL */
4975 WMReleasePropList(pstr
);
4977 /* Store its position */
4978 snprintf(buffer
, sizeof(buffer
), "%i,%i", ai
->x_pos
, ai
->y_pos
);
4979 pstr
= WMCreatePLString(buffer
);
4980 WMPutInPLDictionary(drawer_state
, dPosition
, pstr
);
4981 WMReleasePropList(pstr
);
4983 #ifdef USE_DOCK_XDND
4984 /* Store its DnD command */
4985 if (ai
->dnd_command
) {
4986 pstr
= WMCreatePLString(ai
->dnd_command
);
4987 WMPutInPLDictionary(drawer_state
, dDropCommand
, pstr
);
4988 WMReleasePropList(pstr
);
4990 #endif /* USE_DOCK_XDND */
4992 /* Store its paste command */
4993 if (ai
->paste_command
) {
4994 pstr
= WMCreatePLString(ai
->paste_command
);
4995 WMPutInPLDictionary(drawer_state
, dPasteCommand
, pstr
);
4996 WMReleasePropList(pstr
);
4999 /* Store applications list and other properties */
5000 pstr
= dockSaveState(drawer
);
5001 WMPutInPLDictionary(drawer_state
, dDock
, pstr
);
5002 WMReleasePropList(pstr
);
5004 return drawer_state
;
5008 void wDrawersSaveState(WScreen
*scr
)
5010 WMPropList
*all_drawers
, *drawer_state
;
5016 all_drawers
= WMCreatePLArray(NULL
);
5017 for (i
=0, dc
= scr
->drawers
;
5018 i
< scr
->drawer_count
;
5019 i
++, dc
= dc
->next
) {
5020 drawer_state
= drawerSaveState(dc
->adrawer
);
5021 WMAddToPLArray(all_drawers
, drawer_state
);
5022 WMReleasePropList(drawer_state
);
5024 WMPutInPLDictionary(scr
->session_state
, dDrawers
, all_drawers
);
5025 WMReleasePropList(all_drawers
);
5029 void wDrawersRestoreState(WScreen
*scr
)
5031 WMPropList
*all_drawers
, *drawer_state
;
5036 if (scr
->session_state
== NULL
)
5039 all_drawers
= WMGetFromPLDictionary(scr
->session_state
, dDrawers
);
5043 for (i
= 0; i
< WMGetPropListItemCount(all_drawers
); i
++) {
5044 drawer_state
= WMGetFromPLArray(all_drawers
, i
);
5045 drawerRestoreState(scr
, drawer_state
);
5046 // Note: scr->drawers was updated when the the drawer was created