1 /* dock.c- built-in Dock module for WindowMaker
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <X11/Xutil.h>
37 #define PATH_MAX DEFAULT_PATH_MAX
40 #include "WindowMaker.h"
48 #include "dockedapp.h"
51 #include "properties.h"
55 #include "workspace.h"
57 #include "superfluous.h"
59 #include "placement.h"
63 /**** Local variables ****/
66 #define CLIP_FORWARD 2
68 /**** Global variables ****/
69 extern Cursor wCursor
[WCUR_LAST
];
70 extern XContext wWinContext
;
72 #define MOD_MASK wPreferences.modifier_mask
73 #define ICON_SIZE wPreferences.icon_size
75 /***** Local variables ****/
77 static WMPropList
*dCommand
= NULL
;
78 static WMPropList
*dPasteCommand
= NULL
;
79 #ifdef XDND /* XXX was OFFIX */
80 static WMPropList
*dDropCommand
= NULL
;
82 static WMPropList
*dAutoLaunch
, *dLock
;
83 static WMPropList
*dName
, *dForced
, *dBuggyApplication
, *dYes
, *dNo
;
84 static WMPropList
*dHost
, *dDock
, *dClip
;
85 static WMPropList
*dAutoAttractIcons
;
87 static WMPropList
*dPosition
, *dApplications
, *dLowered
, *dCollapsed
;
89 static WMPropList
*dAutoCollapse
, *dAutoRaiseLower
, *dOmnipresent
;
91 static WMPropList
*dDrawers
= NULL
;
93 static void dockIconPaint(WAppIcon
*btn
);
95 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
97 static pid_t
execCommand(WAppIcon
*btn
, const char *command
, WSavedState
*state
);
99 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
101 static int getClipButton(int px
, int py
);
103 static void toggleLowered(WDock
*dock
);
105 static void toggleCollapsed(WDock
*dock
);
107 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
109 static void clipLeave(WDock
*dock
);
111 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
113 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
114 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
115 static void clipAutoCollapse(void *cdata
);
116 static void clipAutoExpand(void *cdata
);
117 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
);
119 static void clipAutoLower(void *cdata
);
120 static void clipAutoRaise(void *cdata
);
121 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
, const char *name
);
123 static void drawerIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
124 static void removeDrawerCallback(WMenu
*menu
, WMenuEntry
*entry
);
125 static void drawerAppendToChain(WScreen
*scr
, WDock
*drawer
);
126 static char *findUniqueName(WScreen
*scr
, const char *instance_basename
);
127 static void addADrawerCallback(WMenu
*menu
, WMenuEntry
*entry
);
128 static void swapDrawers(WScreen
*scr
, int on_right_side
, int new_x
);
129 static WDock
* getDrawer(WScreen
*scr
, int y_index
);
130 static int indexOfHole(WDock
*drawer
, WAppIcon
*moving_aicon
, int redocking
);
131 static void drawerConsolidateIcons(WDock
*drawer
);
133 static int onScreen(WScreen
*scr
, int x
, int y
);
135 static void make_keys(void)
137 if (dCommand
!= NULL
)
140 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
141 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
143 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
145 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
146 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
147 dName
= WMRetainPropList(WMCreatePLString("Name"));
148 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
149 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
150 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
151 dNo
= WMRetainPropList(WMCreatePLString("No"));
152 dHost
= WMRetainPropList(WMCreatePLString("Host"));
154 dPosition
= WMCreatePLString("Position");
155 dApplications
= WMCreatePLString("Applications");
156 dLowered
= WMCreatePLString("Lowered");
157 dCollapsed
= WMCreatePLString("Collapsed");
158 dAutoCollapse
= WMCreatePLString("AutoCollapse");
159 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
160 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
162 dOmnipresent
= WMCreatePLString("Omnipresent");
164 dDock
= WMCreatePLString("Dock");
165 dClip
= WMCreatePLString("Clip");
166 dDrawers
= WMCreatePLString("Drawers");
169 static void renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
171 WDock
*dock
= entry
->clientdata
;
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(WScreen
*scr
, 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 assert(entry
->clientdata
!= NULL
);
428 dock
= clickedIcon
->dock
;
430 selectedIcons
= getSelected(dock
);
432 if (!WMGetArrayItemCount(selectedIcons
))
433 WMAddToArray(selectedIcons
, clickedIcon
);
436 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
437 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
439 else if (aicon
->icon
->selected
)
440 wIconSelect(aicon
->icon
);
442 WMFreeArray(selectedIcons
);
445 wMessageDialog(dock
->screen_ptr
, _("Warning"),
446 _("Some icons cannot be made omnipresent. "
447 "Please make sure that no other icon is "
448 "docked in the same positions on the other "
449 "workspaces and the Clip is not full in "
450 "some workspace."), _("OK"), NULL
, NULL
);
451 } else if (failed
== 1) {
452 wMessageDialog(dock
->screen_ptr
, _("Warning"),
453 _("Icon cannot be made omnipresent. "
454 "Please make sure that no other icon is "
455 "docked in the same position on the other "
456 "workspaces and the Clip is not full in "
457 "some workspace."), _("OK"), NULL
, NULL
);
461 static void removeIcons(WMArray
*icons
, WDock
*dock
)
467 WM_ITERATE_ARRAY(icons
, aicon
, it
) {
468 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
469 wDockDetach(dock
, aicon
);
471 /* XXX: can: aicon->icon == NULL ? */
472 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
473 wGetHeadForWindow(aicon
->icon
->owner
));
474 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
475 if (!dock
->mapped
|| dock
->collapsed
)
476 XMapWindow(dpy
, aicon
->icon
->core
->window
);
481 if (wPreferences
.auto_arrange_icons
)
482 wArrangeIcons(dock
->screen_ptr
, True
);
485 static void removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
487 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
489 WMArray
*selectedIcons
;
491 assert(clickedIcon
!= NULL
);
493 dock
= clickedIcon
->dock
;
495 selectedIcons
= getSelected(dock
);
497 if (WMGetArrayItemCount(selectedIcons
)) {
498 if (wMessageDialog(dock
->screen_ptr
,
499 dock
->type
== WM_CLIP
? _("Workspace Clip") : _("Drawer"),
500 _("All selected icons will be removed!"),
501 _("OK"), _("Cancel"), NULL
) != WAPRDefault
) {
502 WMFreeArray(selectedIcons
);
506 if (clickedIcon
->xindex
== 0 && clickedIcon
->yindex
== 0) {
507 WMFreeArray(selectedIcons
);
510 WMAddToArray(selectedIcons
, clickedIcon
);
513 removeIcons(selectedIcons
, dock
);
515 if (dock
->type
== WM_DRAWER
) {
516 drawerConsolidateIcons(dock
);
520 static void keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
522 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
525 WMArray
*selectedIcons
;
528 assert(clickedIcon
!= NULL
);
529 dock
= clickedIcon
->dock
;
531 selectedIcons
= getSelected(dock
);
533 if (!WMGetArrayItemCount(selectedIcons
)
534 && clickedIcon
!= dock
->screen_ptr
->clip_icon
) {
535 char *command
= NULL
;
537 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
538 clickedIcon
->editing
= 1;
539 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
540 _("Type the command used to launch the application"), &command
)) {
541 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
545 clickedIcon
->command
= command
;
546 clickedIcon
->editing
= 0;
548 clickedIcon
->editing
= 0;
551 WMFreeArray(selectedIcons
);
556 WMAddToArray(selectedIcons
, clickedIcon
);
559 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
560 if (aicon
->icon
->selected
)
561 wIconSelect(aicon
->icon
);
563 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
564 aicon
->attracted
= 0;
565 if (aicon
->icon
->shadowed
) {
566 aicon
->icon
->shadowed
= 0;
569 * Update icon pixmap, RImage doesn't change,
570 * so call wIconUpdate is not needed
572 update_icon_pixmap(aicon
->icon
);
575 wAppIconPaint(aicon
);
578 save_appicon(aicon
, True
);
580 WMFreeArray(selectedIcons
);
583 static void toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
585 WDock
*dock
= (WDock
*) entry
->clientdata
;
586 WScreen
*scr
= dock
->screen_ptr
;
588 assert(entry
->clientdata
!= NULL
);
590 /* Setting a clip as autoattracting will disable an autoattracting drawer,
591 * and reciprocally. Ask for confirmation? */
592 #ifdef CONFIRM_AUTOATTRACT_CHANGE
593 if (dock
->type
== WM_CLIP
&& scr
->attracting_drawer
) {
594 if (wMessageDialog(scr
, _("Workspace Clip"),
595 _("The drawer that auto-attracted icons so far won't do so anymore!"),
596 _("OK"), _("Cancel"), NULL
) != WAPRDefault
)
598 } else if (dock
->type
== WM_DRAWER
) {
599 /* check if at least one clip already auto attracts icons */
600 int i
, ask_for_confirmation
= False
;
601 for (i
= 0; i
< scr
->workspace_count
; i
++) {
602 if (scr
->workspaces
[ i
]->clip
->attract_icons
) {
603 ask_for_confirmation
= True
;
607 if (ask_for_confirmation
) {
608 if (wMessageDialog(scr
, _("Drawer"),
609 _("Any clips that auto-attracted icons so far won't do so anymore!"),
610 _("OK"), _("Cancel"), NULL
) != WAPRDefault
)
616 dock
->attract_icons
= !dock
->attract_icons
;
618 entry
->flags
.indicator_on
= dock
->attract_icons
;
622 if (dock
->attract_icons
) {
623 if (dock
->type
== WM_DRAWER
) {
624 /* The newly auto-attracting dock is a drawer: disable any clip and
625 * previously attracting drawer */
627 for (i
= 0; i
< scr
->workspace_count
; i
++) {
628 scr
->workspaces
[ i
]->clip
->attract_icons
= False
;
629 /* dock menu will be updated later, when opened */
631 if (scr
->attracting_drawer
!= NULL
)
632 scr
->attracting_drawer
->attract_icons
= False
;
633 scr
->attracting_drawer
= dock
;
635 /* The newly auto-attracting dock is a clip: disable
636 * previously attracting drawer, if applicable */
637 if (scr
->attracting_drawer
!= NULL
) {
638 scr
->attracting_drawer
->attract_icons
= False
;
639 /* again, its menu will be updated, later. */
640 scr
->attracting_drawer
= NULL
;
646 static void selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
648 WAppIcon
*icon
= (WAppIcon
*) entry
->clientdata
;
650 assert(icon
!= NULL
);
652 wIconSelect(icon
->icon
);
657 static void colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
659 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
660 WDock
*clip
; /* clip... is a WM_CLIP or a WM_DRAWER */
662 int x
, y
, x_pos
, y_pos
;
663 Bool update_icon
= False
;
665 assert(entry
->clientdata
!= NULL
);
666 clip
= clickedIcon
->dock
;
668 aicon
= clip
->screen_ptr
->app_icon_list
;
671 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
672 x_pos
= clip
->x_pos
+ x
* ICON_SIZE
;
673 y_pos
= clip
->y_pos
+ y
* ICON_SIZE
;
674 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
)
675 move_window(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
677 aicon
->attracted
= 1;
678 if (!aicon
->icon
->shadowed
) {
679 aicon
->icon
->shadowed
= 1;
682 wDockAttachIcon(clip
, aicon
, x
, y
, update_icon
);
683 if (clip
->collapsed
|| !clip
->mapped
)
684 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
690 static void selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
692 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
694 WMArray
*selectedIcons
;
695 WMArrayIterator iter
;
699 assert(clickedIcon
!= NULL
);
700 dock
= clickedIcon
->dock
;
702 selectedIcons
= getSelected(dock
);
704 if (!WMGetArrayItemCount(selectedIcons
)) {
705 for (i
= 1; i
< dock
->max_icons
; i
++) {
706 btn
= dock
->icon_array
[i
];
707 if (btn
&& !btn
->icon
->selected
)
708 wIconSelect(btn
->icon
);
711 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
712 wIconSelect(btn
->icon
);
715 WMFreeArray(selectedIcons
);
720 static void toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
722 assert(entry
->clientdata
!= NULL
);
724 toggleCollapsed(entry
->clientdata
);
726 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->collapsed
;
731 static void toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
734 assert(entry
->clientdata
!= NULL
);
736 dock
= (WDock
*) entry
->clientdata
;
738 dock
->auto_collapse
= !dock
->auto_collapse
;
740 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_collapse
;
745 static void toggleAutoRaiseLower(WDock
*dock
)
749 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
750 if (dock
->type
== WM_DOCK
)
752 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
753 toggleAutoRaiseLower(dc
->adrawer
);
758 static void toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
761 assert(entry
->clientdata
!= NULL
);
763 dock
= (WDock
*) entry
->clientdata
;
765 toggleAutoRaiseLower(dock
);
767 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_raise_lower
;
772 static void launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
774 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
776 launchDockedApplication(btn
, False
);
779 static void settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
781 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
785 ShowDockAppSettingsPanel(btn
);
788 static void hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
791 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
793 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
795 if (wapp
->flags
.hidden
) {
796 wWorkspaceChange(btn
->icon
->core
->screen_ptr
, wapp
->last_workspace
);
797 wUnhideApplication(wapp
, False
, False
);
799 wHideApplication(wapp
);
803 static void unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
806 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
808 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
810 wUnhideApplication(wapp
, False
, True
);
813 /* Name is only used when type == WM_DRAWER and when restoring a specific
814 * drawer, with a specific name. When creating a drawer, leave name to NULL
815 * and mainIconCreate will find the first unused unique name */
816 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
, const char *name
)
824 return scr
->clip_icon
;
825 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
826 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
830 default: /* to avoid a warning about btn and x_pos, basically */
831 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
832 if (wPreferences
.flags
.clip_merged_in_dock
)
833 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
834 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
838 name
= findUniqueName(scr
, "Drawer");
839 btn
= wAppIconCreateForDock(scr
, NULL
, name
, "WMDrawer", TILE_DRAWER
);
840 btn
->icon
->core
->descriptor
.handle_expose
= drawerIconExpose
;
847 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
848 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
849 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
850 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
851 btn
->icon
->core
->descriptor
.parent
= btn
;
852 XMapWindow(dpy
, btn
->icon
->core
->window
);
856 if (type
== WM_CLIP
||
857 (type
== WM_DOCK
&& wPreferences
.flags
.clip_merged_in_dock
))
858 scr
->clip_icon
= btn
;
863 static void switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
865 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
866 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
868 WMArray
*selectedIcons
;
871 if (entry
->order
== scr
->current_workspace
)
874 dest
= scr
->workspaces
[entry
->order
]->clip
;
876 selectedIcons
= getSelected(src
);
878 if (WMGetArrayItemCount(selectedIcons
)) {
879 WMArrayIterator iter
;
881 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
882 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
883 wDockMoveIconBetweenDocks(src
, dest
, btn
, x
, y
);
884 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
887 } else if (icon
!= scr
->clip_icon
) {
888 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
889 wDockMoveIconBetweenDocks(src
, dest
, icon
, x
, y
);
890 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
893 WMFreeArray(selectedIcons
);
896 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
)
898 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
900 if (!btn
->launching
&&
901 ((!withSelection
&& btn
->command
!= NULL
) || (withSelection
&& btn
->paste_command
!= NULL
))) {
902 if (!btn
->forced_dock
) {
903 btn
->relaunching
= btn
->running
;
906 if (btn
->wm_instance
|| btn
->wm_class
) {
907 WWindowAttributes attr
;
908 memset(&attr
, 0, sizeof(WWindowAttributes
));
909 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
911 if (!attr
.no_appicon
&& !btn
->buggy_app
)
916 btn
->drop_launch
= 0;
917 btn
->paste_launch
= withSelection
;
918 scr
->last_dock
= btn
->dock
;
919 btn
->pid
= execCommand(btn
, (withSelection
? btn
->paste_command
: btn
->command
), NULL
);
921 if (btn
->buggy_app
) {
922 /* give feedback that the app was launched */
926 WMAddTimerHandler(200, (WMCallback
*) dockIconPaint
, btn
);
931 wwarning(_("could not launch application %s"), btn
->command
);
933 if (!btn
->relaunching
)
939 static void updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
941 WScreen
*scr
= menu
->frame
->screen_ptr
;
942 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
948 for (i
= 0; i
< scr
->workspace_count
; i
++) {
949 if (i
< menu
->entry_no
) {
950 if (strcmp(menu
->entries
[i
]->text
, scr
->workspaces
[i
]->name
) != 0) {
951 wfree(menu
->entries
[i
]->text
);
952 strcpy(title
, scr
->workspaces
[i
]->name
);
953 menu
->entries
[i
]->text
= wstrdup(title
);
954 menu
->flags
.realized
= 0;
956 menu
->entries
[i
]->clientdata
= (void *)icon
;
958 strcpy(title
, scr
->workspaces
[i
]->name
);
960 wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)icon
);
962 menu
->flags
.realized
= 0;
965 if (i
== scr
->current_workspace
)
966 wMenuSetEnabled(menu
, i
, False
);
968 wMenuSetEnabled(menu
, i
, True
);
971 if (!menu
->flags
.realized
)
975 static WMenu
*makeWorkspaceMenu(WScreen
*scr
)
979 menu
= wMenuCreate(scr
, NULL
, False
);
981 wwarning(_("could not create workspace submenu for Clip menu"));
983 wMenuAddCallback(menu
, "", switchWSCommand
, (void *)scr
->clip_icon
);
985 menu
->flags
.realized
= 0;
991 static void updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
1000 entry
= menu
->entries
[index
];
1001 entry
->flags
.indicator_on
= !dock
->lowered
;
1002 entry
->clientdata
= dock
;
1003 wMenuSetEnabled(menu
, index
, dock
->type
== WM_CLIP
);
1006 entry
= menu
->entries
[++index
];
1007 entry
->flags
.indicator_on
= dock
->collapsed
;
1008 entry
->clientdata
= dock
;
1011 entry
= menu
->entries
[++index
];
1012 entry
->flags
.indicator_on
= dock
->auto_collapse
;
1013 entry
->clientdata
= dock
;
1015 /* auto-raise/lower */
1016 entry
= menu
->entries
[++index
];
1017 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1018 entry
->clientdata
= dock
;
1019 wMenuSetEnabled(menu
, index
, dock
->lowered
&& (dock
->type
== WM_CLIP
));
1022 entry
= menu
->entries
[++index
];
1023 entry
->flags
.indicator_on
= dock
->attract_icons
;
1024 entry
->clientdata
= dock
;
1026 menu
->flags
.realized
= 0;
1031 static WMenu
*makeClipOptionsMenu(WScreen
*scr
)
1036 menu
= wMenuCreate(scr
, NULL
, False
);
1038 wwarning(_("could not create options submenu for Clip menu"));
1042 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
1043 entry
->flags
.indicator
= 1;
1044 entry
->flags
.indicator_on
= 1;
1045 entry
->flags
.indicator_type
= MI_CHECK
;
1047 entry
= wMenuAddCallback(menu
, _("Collapsed"), toggleCollapsedCallback
, NULL
);
1048 entry
->flags
.indicator
= 1;
1049 entry
->flags
.indicator_on
= 1;
1050 entry
->flags
.indicator_type
= MI_CHECK
;
1052 entry
= wMenuAddCallback(menu
, _("Autocollapse"), toggleAutoCollapseCallback
, NULL
);
1053 entry
->flags
.indicator
= 1;
1054 entry
->flags
.indicator_on
= 1;
1055 entry
->flags
.indicator_type
= MI_CHECK
;
1057 entry
= wMenuAddCallback(menu
, _("Autoraise"), toggleAutoRaiseLowerCallback
, NULL
);
1058 entry
->flags
.indicator
= 1;
1059 entry
->flags
.indicator_on
= 1;
1060 entry
->flags
.indicator_type
= MI_CHECK
;
1062 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"), toggleAutoAttractCallback
, NULL
);
1063 entry
->flags
.indicator
= 1;
1064 entry
->flags
.indicator_on
= 1;
1065 entry
->flags
.indicator_type
= MI_CHECK
;
1067 menu
->flags
.realized
= 0;
1074 static void setDockPositionNormalCallback(WMenu
*menu
, WMenuEntry
*entry
)
1076 WDock
*dock
= (WDock
*) entry
->clientdata
;
1078 if (entry
->flags
.indicator_on
) // already set, nothing to do
1080 // Do we come from auto raise lower or keep on top?
1081 if (dock
->auto_raise_lower
)
1083 dock
->auto_raise_lower
= 0;
1084 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1085 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1086 dc
->adrawer
->auto_raise_lower
= 0;
1091 // Will take care of setting lowered = 0 in drawers
1092 toggleLowered(dock
);
1094 entry
->flags
.indicator_on
= 1;
1097 static void setDockPositionAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
1099 WDock
*dock
= (WDock
*) entry
->clientdata
;
1101 if (entry
->flags
.indicator_on
) // already set, nothing to do
1103 // Do we come from normal or keep on top?
1106 toggleLowered(dock
);
1108 dock
->auto_raise_lower
= 1;
1109 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1110 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1111 dc
->adrawer
->auto_raise_lower
= 1;
1113 entry
->flags
.indicator_on
= 1;
1116 static void setDockPositionKeepOnTopCallback(WMenu
*menu
, WMenuEntry
*entry
)
1118 WDock
*dock
= (WDock
*) entry
->clientdata
;
1120 if (entry
->flags
.indicator_on
) // already set, nothing to do
1122 dock
->auto_raise_lower
= 0;
1123 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1124 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1125 dc
->adrawer
->auto_raise_lower
= 0;
1127 toggleLowered(dock
);
1128 entry
->flags
.indicator_on
= 1;
1131 static void updateDockPositionMenu(WMenu
*menu
, WDock
*dock
)
1140 entry
= menu
->entries
[index
++];
1141 entry
->flags
.indicator_on
= (dock
->lowered
&& !dock
->auto_raise_lower
);
1142 entry
->clientdata
= dock
;
1144 /* Auto-raise/lower */
1145 entry
= menu
->entries
[index
++];
1146 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1147 entry
->clientdata
= dock
;
1150 entry
= menu
->entries
[index
++];
1151 entry
->flags
.indicator_on
= !dock
->lowered
;
1152 entry
->clientdata
= dock
;
1155 static WMenu
*makeDockPositionMenu(WScreen
*scr
)
1157 /* When calling this, the dock is being created, so scr->dock is still not set
1158 * Therefore the callbacks' clientdata and the indicators can't be set,
1159 * they will be updated when the dock menu is opened. */
1163 menu
= wMenuCreate(scr
, NULL
, False
);
1165 wwarning(_("could not create options submenu for dock position menu"));
1169 entry
= wMenuAddCallback(menu
, _("Normal"), setDockPositionNormalCallback
, NULL
);
1170 entry
->flags
.indicator
= 1;
1171 entry
->flags
.indicator_type
= MI_DIAMOND
;
1173 entry
= wMenuAddCallback(menu
, _("Auto raise & lower"), setDockPositionAutoRaiseLowerCallback
, NULL
);
1174 entry
->flags
.indicator
= 1;
1175 entry
->flags
.indicator_type
= MI_DIAMOND
;
1177 entry
= wMenuAddCallback(menu
, _("Keep on Top"), setDockPositionKeepOnTopCallback
, NULL
);
1178 entry
->flags
.indicator
= 1;
1179 entry
->flags
.indicator_type
= MI_DIAMOND
;
1181 menu
->flags
.realized
= 0;
1188 static WMenu
*dockMenuCreate(WScreen
*scr
, int type
)
1193 if (type
== WM_CLIP
&& scr
->clip_menu
)
1194 return scr
->clip_menu
;
1196 if (type
== WM_DRAWER
&& scr
->drawer_menu
)
1197 return scr
->drawer_menu
;
1199 menu
= wMenuCreate(scr
, NULL
, False
);
1200 if (type
== WM_DOCK
) {
1201 entry
= wMenuAddCallback(menu
, _("Dock position"), NULL
, NULL
);
1202 if (scr
->dock_pos_menu
== NULL
)
1203 scr
->dock_pos_menu
= makeDockPositionMenu(scr
);
1204 wMenuEntrySetCascade(menu
, entry
, scr
->dock_pos_menu
);
1206 if (!wPreferences
.flags
.nodrawer
) {
1207 entry
= wMenuAddCallback(menu
, _("Add a drawer"), addADrawerCallback
, NULL
);
1210 if (type
== WM_CLIP
)
1211 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1212 else /* if (type == WM_DRAWER) */
1213 entry
= wMenuAddCallback(menu
, _("Drawer options"), NULL
, NULL
);
1215 if (scr
->clip_options
== NULL
)
1216 scr
->clip_options
= makeClipOptionsMenu(scr
);
1217 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1219 /* The same menu is used for the dock and its appicons. If the menu
1220 * entry text is different between the two contexts, or if it can
1221 * change depending on some state, free the duplicated string (from
1222 * wMenuInsertCallback) and use gettext's string */
1223 if (type
== WM_CLIP
) {
1224 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1226 entry
->text
= _("Rename Workspace"); /* can be: (Toggle) Omnipresent */
1229 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1230 entry
->flags
.indicator
= 1;
1231 entry
->flags
.indicator_on
= 1;
1232 entry
->flags
.indicator_type
= MI_CHECK
;
1234 entry
= wMenuAddCallback(menu
, _("Select All Icons"), selectIconsCallback
, NULL
);
1236 entry
->text
= _("Select All Icons"); /* can be: Unselect all icons */
1238 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1240 entry
->text
= _("Keep Icon"); /* can be: Keep Icons */
1242 if (type
== WM_CLIP
) {
1243 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1245 entry
->text
= _("Move Icon To"); /* can be: Move Icons to */
1246 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1247 if (scr
->clip_submenu
)
1248 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1251 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
, NULL
);
1253 entry
->text
= _("Remove Icon"); /* can be: Remove Icons */
1255 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1258 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1260 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1262 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1264 entry
->text
= _("Hide"); /* can be: Unhide */
1266 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1268 entry
= wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1270 entry
->text
= _("Kill"); /* can be: Remove drawer */
1272 if (type
== WM_CLIP
)
1273 scr
->clip_menu
= menu
;
1275 if (type
== WM_DRAWER
)
1276 scr
->drawer_menu
= menu
;
1281 WDock
*wDockCreate(WScreen
*scr
, int type
, const char *name
)
1288 dock
= wmalloc(sizeof(WDock
));
1292 dock
->max_icons
= DOCK_MAX_ICONS
;
1295 dock
->max_icons
= scr
->scr_width
/ wPreferences
.icon_size
;
1299 dock
->max_icons
= scr
->scr_height
/ wPreferences
.icon_size
;
1302 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * dock
->max_icons
);
1304 btn
= mainIconCreate(scr
, type
, name
);
1308 dock
->x_pos
= btn
->x_pos
;
1309 dock
->y_pos
= btn
->y_pos
;
1310 dock
->screen_ptr
= scr
;
1312 dock
->icon_count
= 1;
1313 if (type
== WM_DRAWER
)
1314 dock
->on_right_side
= scr
->dock
->on_right_side
;
1316 dock
->on_right_side
= 1;
1317 dock
->collapsed
= 0;
1318 dock
->auto_collapse
= 0;
1319 dock
->auto_collapse_magic
= NULL
;
1320 dock
->auto_raise_lower
= 0;
1321 dock
->auto_lower_magic
= NULL
;
1322 dock
->auto_raise_magic
= NULL
;
1323 dock
->attract_icons
= 0;
1325 dock
->icon_array
[0] = btn
;
1326 wRaiseFrame(btn
->icon
->core
);
1327 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1329 /* create dock menu */
1330 dock
->menu
= dockMenuCreate(scr
, type
);
1332 if (type
== WM_DRAWER
) {
1333 drawerAppendToChain(scr
, dock
);
1334 dock
->auto_collapse
= 1;
1340 void wDockDestroy(WDock
*dock
)
1345 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1346 aicon
= dock
->icon_array
[i
];
1348 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1349 wDockDetach(dock
, aicon
);
1351 /* XXX: can: aicon->icon == NULL ? */
1352 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1353 wGetHeadForWindow(aicon
->icon
->owner
));
1354 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1355 if (!dock
->mapped
|| dock
->collapsed
)
1356 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1360 if (wPreferences
.auto_arrange_icons
)
1361 wArrangeIcons(dock
->screen_ptr
, True
);
1362 wfree(dock
->icon_array
);
1363 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1364 wMenuDestroy(dock
->menu
, True
);
1365 if (dock
->screen_ptr
->last_dock
== dock
)
1366 dock
->screen_ptr
->last_dock
= NULL
;
1370 void wClipIconPaint(WAppIcon
*aicon
)
1372 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1373 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1375 Window win
= aicon
->icon
->core
->window
;
1376 int length
, nlength
;
1377 char *ws_name
, ws_number
[10];
1380 wIconPaint(aicon
->icon
);
1382 length
= strlen(workspace
->name
);
1383 ws_name
= wmalloc(length
+ 1);
1384 snprintf(ws_name
, length
+ 1, "%s", workspace
->name
);
1385 snprintf(ws_number
, sizeof(ws_number
), "%i", scr
->current_workspace
+ 1);
1386 nlength
= strlen(ws_number
);
1388 if (wPreferences
.flags
.noclip
|| !workspace
->clip
->collapsed
)
1389 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1391 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1393 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1395 tx
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
1397 if(wPreferences
.show_clip_title
)
1398 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, ty
, ws_name
, length
);
1400 tx
= (ICON_SIZE
/ 2 - WMWidthOfString(scr
->clip_title_font
, ws_number
, nlength
)) / 2;
1402 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, 2, ws_number
, nlength
);
1406 if (aicon
->launching
)
1407 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1408 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1410 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
, aicon
->dock
->rclip_button_pushed
);
1413 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1415 wClipIconPaint(desc
->parent
);
1418 static void dockIconPaint(WAppIcon
*btn
)
1420 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
) {
1421 wClipIconPaint(btn
);
1422 } else if (wIsADrawer(btn
->icon
->core
->screen_ptr
, btn
)) {
1423 wDrawerIconPaint(btn
);
1426 save_appicon(btn
, True
);
1430 static WMPropList
*make_icon_state(WAppIcon
*btn
)
1432 WMPropList
*node
= NULL
;
1433 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
;
1434 WMPropList
*position
, *buggy
, *omnipresent
;
1440 command
= WMCreatePLString("-");
1442 command
= WMCreatePLString(btn
->command
);
1444 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1446 lock
= btn
->lock
? dYes
: dNo
;
1448 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1450 name
= WMCreatePLString(tmp
);
1454 forced
= btn
->forced_dock
? dYes
: dNo
;
1456 buggy
= btn
->buggy_app
? dYes
: dNo
;
1458 if (!wPreferences
.flags
.clip_merged_in_dock
&& btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1459 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1461 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1462 position
= WMCreatePLString(buffer
);
1464 node
= WMCreatePLDictionary(dCommand
, command
,
1466 dAutoLaunch
, autolaunch
,
1468 dForced
, forced
, dBuggyApplication
, buggy
, dPosition
, position
, NULL
);
1469 WMReleasePropList(command
);
1470 WMReleasePropList(name
);
1471 WMReleasePropList(position
);
1473 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1474 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&& (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1475 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1477 #ifdef XDND /* was OFFIX */
1478 if (btn
->dnd_command
) {
1479 command
= WMCreatePLString(btn
->dnd_command
);
1480 WMPutInPLDictionary(node
, dDropCommand
, command
);
1481 WMReleasePropList(command
);
1485 if (btn
->paste_command
) {
1486 command
= WMCreatePLString(btn
->paste_command
);
1487 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1488 WMReleasePropList(command
);
1495 static WMPropList
*dockSaveState(WDock
*dock
)
1498 WMPropList
*icon_info
;
1499 WMPropList
*list
= NULL
, *dock_state
= NULL
;
1500 WMPropList
*value
, *key
;
1503 list
= WMCreatePLArray(NULL
);
1505 for (i
= (dock
->type
== WM_DOCK
? 0 : 1); i
< dock
->max_icons
; i
++) {
1506 WAppIcon
*btn
= dock
->icon_array
[i
];
1508 if (!btn
|| btn
->attracted
)
1511 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1512 WMAddToPLArray(list
, icon_info
);
1513 WMReleasePropList(icon_info
);
1517 dock_state
= WMCreatePLDictionary(dApplications
, list
, NULL
);
1519 if (dock
->type
== WM_DOCK
) {
1520 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1521 key
= WMCreatePLString(buffer
);
1522 WMPutInPLDictionary(dock_state
, key
, list
);
1523 WMReleasePropList(key
);
1525 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0), dock
->y_pos
);
1526 value
= WMCreatePLString(buffer
);
1527 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1528 WMReleasePropList(value
);
1530 WMReleasePropList(list
);
1532 if (dock
->type
== WM_CLIP
|| dock
->type
== WM_DRAWER
) {
1533 value
= (dock
->collapsed
? dYes
: dNo
);
1534 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1536 value
= (dock
->auto_collapse
? dYes
: dNo
);
1537 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1539 value
= (dock
->attract_icons
? dYes
: dNo
);
1540 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1543 if (dock
->type
== WM_DOCK
|| dock
->type
== WM_CLIP
) {
1544 value
= (dock
->lowered
? dYes
: dNo
);
1545 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1547 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1548 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1554 void wDockSaveState(WScreen
*scr
, WMPropList
*old_state
)
1556 WMPropList
*dock_state
;
1559 dock_state
= dockSaveState(scr
->dock
);
1562 * Copy saved states of docks with different sizes.
1568 keys
= WMGetPLDictionaryKeys(old_state
);
1569 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1570 tmp
= WMGetFromPLArray(keys
, i
);
1572 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1573 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1575 WMPutInPLDictionary(dock_state
, tmp
, WMGetFromPLDictionary(old_state
, tmp
));
1578 WMReleasePropList(keys
);
1581 WMPutInPLDictionary(scr
->session_state
, dDock
, dock_state
);
1583 WMReleasePropList(dock_state
);
1586 void wClipSaveState(WScreen
*scr
)
1588 WMPropList
*clip_state
;
1590 clip_state
= make_icon_state(scr
->clip_icon
);
1592 WMPutInPLDictionary(scr
->session_state
, dClip
, clip_state
);
1594 WMReleasePropList(clip_state
);
1597 WMPropList
*wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1599 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1602 static Bool
getBooleanDockValue(WMPropList
*value
, WMPropList
*key
)
1605 if (WMIsPLString(value
)) {
1606 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1609 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1615 static WAppIcon
*restore_icon_state(WScreen
*scr
, WMPropList
*info
, int type
, int index
)
1618 WMPropList
*cmd
, *value
;
1619 char *wclass
, *winstance
, *command
;
1621 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1622 if (!cmd
|| !WMIsPLString(cmd
))
1625 /* parse window name */
1626 value
= WMGetFromPLDictionary(info
, dName
);
1630 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1632 if (!winstance
&& !wclass
)
1637 command
= wstrdup(WMGetFromPLString(cmd
));
1641 if (!command
|| strcmp(command
, "-") == 0) {
1652 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1660 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1661 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1662 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1663 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1664 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1666 #ifdef XDND /* was OFFIX */
1667 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1669 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1672 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1674 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1676 /* check auto launch */
1677 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1679 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1682 value
= WMGetFromPLDictionary(info
, dLock
);
1684 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1686 /* check if it wasn't normally docked */
1687 value
= WMGetFromPLDictionary(info
, dForced
);
1689 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1691 /* check if we can rely on the stuff in the app */
1692 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1694 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1696 /* get position in the dock */
1697 value
= WMGetFromPLDictionary(info
, dPosition
);
1698 if (value
&& WMIsPLString(value
)) {
1699 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1700 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1702 /* check position sanity */
1703 /* *Very* incomplete section! */
1704 if (type
== WM_DOCK
) {
1708 aicon
->yindex
= index
;
1712 /* check if icon is omnipresent */
1713 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1715 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1723 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1725 WAppIcon
*wClipRestoreState(WScreen
*scr
, WMPropList
*clip_state
)
1730 icon
= mainIconCreate(scr
, WM_CLIP
, NULL
);
1735 WMRetainPropList(clip_state
);
1737 /* restore position */
1739 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1742 if (!WMIsPLString(value
)) {
1743 COMPLAIN("Position");
1745 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1746 COMPLAIN("Position");
1748 /* check position sanity */
1749 if (!onScreen(scr
, icon
->x_pos
, icon
->y_pos
))
1750 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1753 #ifdef XDND /* was OFFIX */
1754 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1755 if (value
&& WMIsPLString(value
))
1756 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1759 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1760 if (value
&& WMIsPLString(value
))
1761 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1763 WMReleasePropList(clip_state
);
1768 WDock
*wDockRestoreState(WScreen
*scr
, WMPropList
*dock_state
, int type
)
1773 WAppIcon
*aicon
, *old_top
;
1776 dock
= wDockCreate(scr
, type
, NULL
);
1781 WMRetainPropList(dock_state
);
1783 /* restore position */
1784 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1786 if (!WMIsPLString(value
)) {
1787 COMPLAIN("Position");
1789 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1790 COMPLAIN("Position");
1792 /* check position sanity */
1793 if (!onScreen(scr
, dock
->x_pos
, dock
->y_pos
)) {
1794 int x
= dock
->x_pos
;
1795 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1798 /* Is this needed any more? */
1799 if (type
== WM_CLIP
) {
1800 if (dock
->x_pos
< 0) {
1802 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1803 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1806 if (dock
->x_pos
>= 0) {
1807 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1808 dock
->on_right_side
= 0;
1810 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1811 dock
->on_right_side
= 1;
1817 /* restore lowered/raised state */
1820 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1822 if (!WMIsPLString(value
)) {
1823 COMPLAIN("Lowered");
1825 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1830 /* restore collapsed state */
1831 dock
->collapsed
= 0;
1833 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1835 if (!WMIsPLString(value
)) {
1836 COMPLAIN("Collapsed");
1838 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1839 dock
->collapsed
= 1;
1843 /* restore auto-collapsed state */
1844 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1846 if (!WMIsPLString(value
)) {
1847 COMPLAIN("AutoCollapse");
1849 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1850 dock
->auto_collapse
= 1;
1851 dock
->collapsed
= 1;
1856 /* restore auto-raise/lower state */
1857 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1859 if (!WMIsPLString(value
)) {
1860 COMPLAIN("AutoRaiseLower");
1862 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1863 dock
->auto_raise_lower
= 1;
1867 /* restore attract icons state */
1868 dock
->attract_icons
= 0;
1870 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1872 if (!WMIsPLString(value
)) {
1873 COMPLAIN("AutoAttractIcons");
1875 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1876 dock
->attract_icons
= 1;
1880 /* application list */
1887 * When saving, it saves the dock state in
1888 * Applications and Applicationsnnn
1890 * When loading, it will first try Applicationsnnn.
1891 * If it does not exist, use Applications as default.
1894 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1896 tmp
= WMCreatePLString(buffer
);
1897 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1898 WMReleasePropList(tmp
);
1901 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1907 count
= WMGetPropListItemCount(apps
);
1911 old_top
= dock
->icon_array
[0];
1913 /* dock->icon_count is set to 1 when dock is created.
1914 * Since Clip is already restored, we want to keep it so for clip,
1915 * but for dock we may change the default top tile, so we set it to 0.
1917 if (type
== WM_DOCK
)
1918 dock
->icon_count
= 0;
1920 for (i
= 0; i
< count
; i
++) {
1921 if (dock
->icon_count
>= dock
->max_icons
) {
1922 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1926 value
= WMGetFromPLArray(apps
, i
);
1927 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1929 dock
->icon_array
[dock
->icon_count
] = aicon
;
1933 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1934 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1937 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1939 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1941 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1942 if (!dock
->collapsed
)
1943 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1945 wRaiseFrame(aicon
->icon
->core
);
1948 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
) {
1953 /* if the first icon is not defined, use the default */
1954 if (dock
->icon_array
[0] == NULL
) {
1955 /* update default icon */
1956 old_top
->x_pos
= dock
->x_pos
;
1957 old_top
->y_pos
= dock
->y_pos
;
1959 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1961 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1963 dock
->icon_array
[0] = old_top
;
1964 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1965 /* we don't need to increment dock->icon_count here because it was
1966 * incremented in the loop above.
1968 } else if (old_top
!= dock
->icon_array
[0]) {
1969 if (old_top
== scr
->clip_icon
) // TODO dande: understand the logic
1970 scr
->clip_icon
= dock
->icon_array
[0];
1972 wAppIconDestroy(old_top
);
1976 WMReleasePropList(dock_state
);
1981 void wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1983 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1984 btn
->drop_launch
= 0;
1985 btn
->paste_launch
= 0;
1987 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1990 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
2000 void wDockDoAutoLaunch(WDock
*dock
, int workspace
)
2006 for (i
= 0; i
< dock
->max_icons
; i
++) {
2007 btn
= dock
->icon_array
[i
];
2008 if (!btn
|| !btn
->auto_launch
)
2011 state
= wmalloc(sizeof(WSavedState
));
2012 state
->workspace
= workspace
;
2013 /* TODO: this is klugy and is very difficult to understand
2014 * what's going on. Try to clean up */
2015 wDockLaunchWithState(dock
, btn
, state
);
2019 #ifdef XDND /* was OFFIX */
2020 static WDock
*findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
2026 if ((dock
= scr
->dock
) != NULL
) {
2027 for (i
= 0; i
< dock
->max_icons
; i
++) {
2028 if (dock
->icon_array
[i
]
2029 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
2035 if (*icon_pos
< 0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
) != NULL
) {
2036 for (i
= 0; i
< dock
->max_icons
; i
++) {
2037 if (dock
->icon_array
[i
]
2038 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
2049 int wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
2055 dock
= findDock(scr
, event
, &icon_pos
);
2060 * Return True if the drop was on an application icon window.
2061 * In this case, let the ClientMessage handler redirect the
2062 * message to the app.
2064 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
2067 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
2068 scr
->flags
.dnd_data_convertion_status
= 0;
2070 btn
= dock
->icon_array
[icon_pos
];
2072 if (!btn
->forced_dock
) {
2073 btn
->relaunching
= btn
->running
;
2076 if (btn
->wm_instance
|| btn
->wm_class
) {
2077 WWindowAttributes attr
;
2078 memset(&attr
, 0, sizeof(WWindowAttributes
));
2079 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
2081 if (!attr
.no_appicon
)
2087 btn
->paste_launch
= 0;
2088 btn
->drop_launch
= 1;
2089 scr
->last_dock
= dock
;
2090 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
2095 if (!btn
->relaunching
)
2103 Bool
wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
, Bool update_icon
)
2106 Bool lupdate_icon
= False
;
2107 char *command
= NULL
;
2113 lupdate_icon
= True
;
2115 if (icon
->command
== NULL
) {
2116 /* If icon->owner exists, it means the application is running */
2117 if (icon
->icon
->owner
) {
2118 wwin
= icon
->icon
->owner
;
2119 command
= GetCommandForWindow(wwin
->client_win
);
2123 icon
->command
= command
;
2125 /* icon->forced_dock = 1; */
2126 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
2128 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2129 _("Type the command used to launch the application"), &command
)) {
2130 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2134 icon
->command
= command
;
2140 /* If the target is the dock, reject the icon. If
2141 * the target is the clip, make it an attracted icon
2143 if (dock
->type
== WM_CLIP
) {
2144 icon
->attracted
= 1;
2145 if (!icon
->icon
->shadowed
) {
2146 icon
->icon
->shadowed
= 1;
2147 lupdate_icon
= True
;
2157 for (index
= 1; index
< dock
->max_icons
; index
++)
2158 if (dock
->icon_array
[index
] == NULL
)
2160 /* if (index == dock->max_icons)
2163 assert(index
< dock
->max_icons
);
2165 dock
->icon_array
[index
] = icon
;
2169 icon
->omnipresent
= 0;
2171 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2172 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2177 icon
->launching
= 0;
2180 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2181 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2182 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2183 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2184 icon
->icon
->core
->descriptor
.parent
= icon
;
2186 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2187 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2190 * Update icon pixmap, RImage doesn't change,
2191 * so call wIconUpdate is not needed
2194 update_icon_pixmap(icon
->icon
);
2197 wAppIconPaint(icon
);
2200 save_appicon(icon
, True
);
2202 if (wPreferences
.auto_arrange_icons
)
2203 wArrangeIcons(dock
->screen_ptr
, True
);
2205 #ifdef XDND /* was OFFIX */
2206 if (icon
->command
&& !icon
->dnd_command
) {
2207 int len
= strlen(icon
->command
) + 8;
2208 icon
->dnd_command
= wmalloc(len
);
2209 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
2213 if (icon
->command
&& !icon
->paste_command
) {
2214 int len
= strlen(icon
->command
) + 8;
2215 icon
->paste_command
= wmalloc(len
);
2216 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
2222 void wDockReattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2226 for (index
= 1; index
< dock
->max_icons
; index
++) {
2227 if (dock
->icon_array
[index
] == icon
)
2230 assert(index
< dock
->max_icons
);
2235 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2236 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2239 Bool
wDockMoveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2242 char *command
= NULL
;
2244 Bool update_icon
= False
;
2247 return True
; /* No move needed, we're already there */
2253 * For the moment we can't do this if we move icons in Clip from one
2254 * workspace to other, because if we move two or more icons without
2255 * command, the dialog box will not be able to tell us to which of the
2256 * moved icons it applies. -Dan
2258 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
2259 /* If icon->owner exists, it means the application is running */
2260 if (icon
->icon
->owner
) {
2261 wwin
= icon
->icon
->owner
;
2262 command
= GetCommandForWindow(wwin
->client_win
);
2266 icon
->command
= command
;
2269 /* icon->forced_dock = 1; */
2270 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2271 _("Type the command used to launch the application"), &command
)) {
2272 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2276 icon
->command
= command
;
2287 if (dest
->type
== WM_DOCK
|| dest
->type
== WM_DRAWER
)
2288 wClipMakeIconOmnipresent(icon
, False
);
2290 for (index
= 1; index
< src
->max_icons
; index
++) {
2291 if (src
->icon_array
[index
] == icon
)
2294 assert(index
< src
->max_icons
);
2296 src
->icon_array
[index
] = NULL
;
2299 for (index
= 1; index
< dest
->max_icons
; index
++) {
2300 if (dest
->icon_array
[index
] == NULL
)
2304 assert(index
< dest
->max_icons
);
2306 dest
->icon_array
[index
] = icon
;
2309 /* deselect the icon */
2310 if (icon
->icon
->selected
)
2311 wIconSelect(icon
->icon
);
2313 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2314 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2316 /* set it to be kept when moving to dock.
2317 * Unless the icon does not have a command set
2319 if (icon
->command
&& (dest
->type
== WM_DOCK
|| dest
->type
== WM_DRAWER
)) {
2320 icon
->attracted
= 0;
2321 if (icon
->icon
->shadowed
) {
2322 icon
->icon
->shadowed
= 0;
2325 save_appicon(icon
, True
);
2328 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2334 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2335 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2339 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2342 * Update icon pixmap, RImage doesn't change,
2343 * so call wIconUpdate is not needed
2346 update_icon_pixmap(icon
->icon
);
2349 wAppIconPaint(icon
);
2354 void wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2357 Bool update_icon
= False
;
2359 /* make the settings panel be closed */
2361 DestroyDockAppSettingsPanel(icon
->panel
);
2363 /* This must be called before icon->dock is set to NULL.
2364 * Don't move it. -Dan
2366 wClipMakeIconOmnipresent(icon
, False
);
2370 icon
->attracted
= 0;
2371 icon
->auto_launch
= 0;
2372 if (icon
->icon
->shadowed
) {
2373 icon
->icon
->shadowed
= 0;
2377 /* deselect the icon */
2378 if (icon
->icon
->selected
)
2379 wIconSelect(icon
->icon
);
2381 if (icon
->command
) {
2382 wfree(icon
->command
);
2383 icon
->command
= NULL
;
2385 #ifdef XDND /* was OFFIX */
2386 if (icon
->dnd_command
) {
2387 wfree(icon
->dnd_command
);
2388 icon
->dnd_command
= NULL
;
2391 if (icon
->paste_command
) {
2392 wfree(icon
->paste_command
);
2393 icon
->paste_command
= NULL
;
2396 for (index
= 1; index
< dock
->max_icons
; index
++)
2397 if (dock
->icon_array
[index
] == icon
)
2400 assert(index
< dock
->max_icons
);
2401 dock
->icon_array
[index
] = NULL
;
2407 /* if the dock is not attached to an application or
2408 * the application did not set the appropriate hints yet,
2409 * destroy the icon */
2410 if (!icon
->running
|| !wApplicationOf(icon
->main_window
)) {
2411 wAppIconDestroy(icon
);
2413 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2414 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2415 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2416 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2417 icon
->icon
->core
->descriptor
.parent
= icon
;
2419 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2422 * Update icon pixmap, RImage doesn't change,
2423 * so call wIconUpdate is not needed
2426 update_icon_pixmap(icon
->icon
);
2429 wAppIconPaint(icon
);
2431 if (wPreferences
.auto_arrange_icons
)
2432 wArrangeIcons(dock
->screen_ptr
, True
);
2434 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2439 * returns the closest Dock slot index for the passed
2442 * Returns False if icon can't be docked.
2444 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2447 /* Redocking == true means either icon->dock == dock (normal case)
2448 * or we are called from handleDockMove for a drawer */
2449 Bool
wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2451 WScreen
*scr
= dock
->screen_ptr
;
2454 int i
, offset
= ICON_SIZE
/ 2;
2455 WAppIcon
*aicon
= NULL
;
2456 WAppIcon
*nicon
= NULL
;
2458 if (wPreferences
.flags
.noupdates
)
2464 /* if the dock is full */
2465 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
))
2468 /* exact position */
2470 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2472 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2475 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2477 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2479 /* check if the icon is outside the screen boundaries */
2480 if (!onScreen(scr
, dx
+ ex_x
* ICON_SIZE
, dy
+ ex_y
* ICON_SIZE
))
2483 switch (dock
->type
) {
2485 /* We can return False right away if
2486 * - we do not come from this dock (which is a WM_DOCK),
2487 * - we are not right over it, and
2488 * - we are not the main tile of a drawer.
2489 * In the latter case, we are called from handleDockMove. */
2490 if (icon
->dock
!= dock
&& ex_x
!= 0 &&
2491 !(icon
->dock
&& icon
->dock
->type
== WM_DRAWER
&& icon
== icon
->dock
->icon_array
[0]))
2494 if (!redocking
&& ex_x
!= 0)
2497 if (getDrawer(scr
, ex_y
)) /* Return false so that the drawer gets it. */
2501 for (i
= 0; i
< dock
->max_icons
; i
++) {
2502 nicon
= dock
->icon_array
[i
];
2503 if (nicon
&& nicon
->yindex
== ex_y
) {
2510 int sig
, done
, closest
;
2512 /* Possible cases when redocking:
2514 * icon dragged out of range of any slot -> false
2515 * icon dragged on a drawer -> false (to open the drawer)
2516 * icon dragged to range of free slot
2517 * icon dragged to range of same slot
2518 * icon dragged to range of different icon
2520 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2523 if (aicon
== icon
|| !aicon
) {
2529 /* start looking at the upper slot or lower? */
2530 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2536 /* look for closest free slot */
2537 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2541 closest
= sig
* (i
/ 2) + ex_y
;
2542 /* check if this slot is fully on the screen and not used */
2543 if (onScreen(scr
, dx
, dy
+ closest
* ICON_SIZE
)) {
2544 for (j
= 0; j
< dock
->max_icons
; j
++) {
2545 if (dock
->icon_array
[j
]
2546 && dock
->icon_array
[j
]->yindex
== closest
) {
2547 /* slot is used by someone else */
2548 if (dock
->icon_array
[j
] != icon
)
2553 /* slot is used by a drawer */
2554 done
= done
&& !getDrawer(scr
, closest
);
2561 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2562 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2567 } else { /* !redocking */
2569 /* if slot is free and the icon is close enough, return it */
2570 if (!aicon
&& ex_x
== 0) {
2582 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2583 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+ 1;
2586 for (k
= start
; k
< stop
; k
++) {
2587 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2590 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2591 nicon
= tmp
->icon_array
[i
];
2592 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2600 for (k
= start
; k
< stop
; k
++) {
2601 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2604 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2605 nicon
= tmp
->icon_array
[i
];
2606 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2607 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2608 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2617 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2626 WAppIcon
*aicons_to_shift
[ dock
->icon_count
];
2627 int index_of_hole
, j
;
2630 abs(ex_x
) - dock
->icon_count
> DOCK_DETTACH_THRESHOLD
||
2631 (ex_x
< 0 && !dock
->on_right_side
) ||
2632 (ex_x
> 0 && dock
->on_right_side
)) {
2637 ex_x
= (dock
->on_right_side
? -1 : 1);
2639 /* "Reduce" ex_x but keep its sign */
2641 if (abs(ex_x
) > dock
->icon_count
- 1) /* minus 1: do not take icon_array[0] into account */
2642 ex_x
= ex_x
* (dock
->icon_count
- 1) / abs(ex_x
); /* don't use *= ! */
2644 if (abs(ex_x
) > dock
->icon_count
)
2645 ex_x
= ex_x
* dock
->icon_count
/ abs(ex_x
);
2647 index_of_hole
= indexOfHole(dock
, icon
, redocking
);
2649 /* Find the appicons between where icon was (index_of_hole) and where
2650 * it wants to be (ex_x) and slide them. */
2652 for (i
= 1; i
< dock
->max_icons
; i
++) {
2653 if ((aicon
= dock
->icon_array
[ i
]) && aicon
!= icon
&&
2654 ((ex_x
<= aicon
->xindex
&& aicon
->xindex
< index_of_hole
) ||
2655 (index_of_hole
< aicon
->xindex
&& aicon
->xindex
<= ex_x
)))
2656 aicons_to_shift
[ j
++ ] = aicon
;
2658 assert(j
== abs(ex_x
- index_of_hole
));
2660 wSlideAppicons(aicons_to_shift
, j
, (index_of_hole
< ex_x
));
2670 static int onScreen(WScreen
*scr
, int x
, int y
)
2677 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2679 wGetRectPlacementInfo(scr
, rect
, &flags
);
2681 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2685 * returns true if it can find a free slot in the dock,
2686 * in which case it changes x_pos and y_pos accordingly.
2687 * Else returns false.
2689 Bool
wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2691 WScreen
*scr
= dock
->screen_ptr
;
2693 WAppIconChain
*chain
;
2694 unsigned char *slot_map
;
2698 int i
, done
= False
;
2700 int sx
= 0, ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2701 int extra_count
= 0;
2703 if (dock
->type
== WM_DRAWER
) {
2704 if (dock
->icon_count
>= dock
->max_icons
) { /* drawer is full */
2707 *x_pos
= dock
->icon_count
* (dock
->on_right_side
? -1 : 1);
2712 if (dock
->type
== WM_CLIP
&& dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2713 extra_count
= scr
->global_icon_count
;
2715 /* if the dock is full */
2716 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
)
2719 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2720 if (scr
->dock
->on_right_side
)
2721 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2723 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2726 if (ex
< dock
->x_pos
)
2728 if (sx
> dock
->x_pos
+ ICON_SIZE
)
2729 sx
= dock
->x_pos
+ ICON_SIZE
;
2736 /* check if clip is in a corner */
2737 if (dock
->type
== WM_CLIP
) {
2738 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2740 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2742 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2744 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2752 /* If the clip is in the corner, use only slots that are in the border
2754 if (corner
!= C_NONE
) {
2758 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2759 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2760 hmap
= wmalloc(hcount
+ 1);
2761 vmap
= wmalloc(vcount
+ 1);
2763 /* mark used positions */
2766 for (i
= 0; i
< dock
->max_icons
; i
++) {
2767 btn
= dock
->icon_array
[i
];
2771 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2772 vmap
[btn
->yindex
] = 1;
2773 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2774 hmap
[btn
->xindex
] = 1;
2776 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2778 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2779 vmap
[btn
->yindex
] = 1;
2780 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2781 hmap
[btn
->xindex
] = 1;
2785 for (i
= 0; i
< dock
->max_icons
; i
++) {
2786 btn
= dock
->icon_array
[i
];
2790 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2791 vmap
[btn
->yindex
] = 1;
2792 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2793 hmap
[-btn
->xindex
] = 1;
2795 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2797 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2798 vmap
[btn
->yindex
] = 1;
2799 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2800 hmap
[-btn
->xindex
] = 1;
2804 for (i
= 0; i
< dock
->max_icons
; i
++) {
2805 btn
= dock
->icon_array
[i
];
2809 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2810 vmap
[-btn
->yindex
] = 1;
2811 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2812 hmap
[btn
->xindex
] = 1;
2814 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2816 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2817 vmap
[-btn
->yindex
] = 1;
2818 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2819 hmap
[btn
->xindex
] = 1;
2824 for (i
= 0; i
< dock
->max_icons
; i
++) {
2825 btn
= dock
->icon_array
[i
];
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;
2834 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2836 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2837 vmap
[-btn
->yindex
] = 1;
2838 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2839 hmap
[-btn
->xindex
] = 1;
2845 /* search a vacant slot */
2846 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2847 if (i
< vcount
&& vmap
[i
] == 0) {
2853 } else if (i
< hcount
&& hmap
[i
] == 0) {
2863 /* If found a slot, translate and return */
2865 if (corner
== C_NW
|| corner
== C_NE
)
2870 if (corner
== C_NE
|| corner
== C_SE
)
2877 /* else, try to find a slot somewhere else */
2880 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2881 * placed outside of screen */
2882 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2884 /* In the worst case (the clip is in the corner of the screen),
2885 * the amount of icons that fit in the clip is smaller.
2886 * Double the map to get a safe value.
2890 r
= (mwidth
- 1) / 2;
2892 slot_map
= wmalloc(mwidth
* mwidth
);
2894 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2896 /* mark used slots in the map. If the slot falls outside the map
2897 * (for example, when all icons are placed in line), ignore them. */
2898 for (i
= 0; i
< dock
->max_icons
; i
++) {
2899 btn
= dock
->icon_array
[i
];
2901 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2904 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
)
2905 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2907 /* Find closest slot from the center that is free by scanning the
2908 * map from the center to outward in circular passes.
2909 * This will not result in a neat layout, but will be optimal
2910 * in the sense that there will not be holes left.
2913 for (i
= 1; i
<= r
&& !done
; i
++) {
2916 /* top and bottom parts of the ring */
2917 for (x
= -i
; x
<= i
&& !done
; x
++) {
2918 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2920 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2921 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2928 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2929 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2936 /* left and right parts of the ring */
2937 for (y
= -i
+ 1; y
<= i
- 1; y
++) {
2938 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2940 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2941 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2948 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2949 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2962 static void moveDock(WDock
*dock
, int new_x
, int new_y
)
2968 if (dock
->type
== WM_DOCK
) {
2969 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
2970 moveDock(dc
->adrawer
, new_x
, dc
->adrawer
->y_pos
- dock
->y_pos
+ new_y
);
2973 dock
->x_pos
= new_x
;
2974 dock
->y_pos
= new_y
;
2975 for (i
= 0; i
< dock
->max_icons
; i
++) {
2976 btn
= dock
->icon_array
[i
];
2978 btn
->x_pos
= new_x
+ btn
->xindex
* ICON_SIZE
;
2979 btn
->y_pos
= new_y
+ btn
->yindex
* ICON_SIZE
;
2980 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2985 static void swapDock(WDock
*dock
)
2987 WScreen
*scr
= dock
->screen_ptr
;
2991 if (dock
->on_right_side
)
2992 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2994 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2996 swapDrawers(scr
, dock
->on_right_side
, x
);
2998 for (i
= 0; i
< dock
->max_icons
; i
++) {
2999 btn
= dock
->icon_array
[i
];
3002 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
3006 wScreenUpdateUsableArea(scr
);
3009 static pid_t
execCommand(WAppIcon
*btn
, const char *command
, WSavedState
*state
)
3011 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
3017 cmdline
= ExpandOptions(scr
, command
);
3019 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
3027 wtokensplit(cmdline
, &argv
, &argc
);
3037 if ((pid
= fork()) == 0) {
3041 SetupEnvironment(scr
);
3047 args
= malloc(sizeof(char *) * (argc
+ 1));
3051 for (i
= 0; i
< argc
; i
++)
3055 execvp(argv
[0], args
);
3058 wtokenfree(argv
, argc
);
3062 state
= wmalloc(sizeof(WSavedState
));
3064 state
->miniaturized
= -1;
3066 if (btn
->dock
== scr
->dock
|| btn
->dock
->type
== WM_DRAWER
|| btn
->omnipresent
)
3067 state
->workspace
= -1;
3069 state
->workspace
= scr
->current_workspace
;
3071 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
3072 wAddDeathHandler(pid
, (WDeathHandler
*) trackDeadProcess
, btn
->dock
);
3080 void wDockHideIcons(WDock
*dock
)
3087 for (i
= 1; i
< dock
->max_icons
; i
++) {
3088 if (dock
->icon_array
[i
])
3089 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3093 dockIconPaint(dock
->icon_array
[0]);
3096 void wDockShowIcons(WDock
*dock
)
3104 btn
= dock
->icon_array
[0];
3105 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
3107 /* Deleting any change in stacking level, this function is now only about
3110 if (!dock
->collapsed
) {
3111 for (i
= 1; i
< dock
->max_icons
; i
++) {
3112 if (dock
->icon_array
[i
])
3113 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3121 void wDockLower(WDock
*dock
)
3126 if (dock
->type
== WM_DOCK
) {
3127 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3128 wDockLower(dc
->adrawer
);
3130 for (i
= 0; i
< dock
->max_icons
; i
++) {
3131 if (dock
->icon_array
[i
])
3132 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
3136 void wDockRaise(WDock
*dock
)
3141 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
3142 if (dock
->icon_array
[i
])
3143 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
3145 if (dock
->type
== WM_DOCK
) {
3146 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3147 wDockRaise(dc
->adrawer
);
3151 void wDockRaiseLower(WDock
*dock
)
3153 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
3154 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
3155 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
3161 void wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
3163 icon
->launching
= 0;
3164 icon
->relaunching
= 0;
3165 dockIconPaint(icon
);
3168 WAppIcon
*wDockFindIconForWindow(WDock
*dock
, Window window
)
3173 for (i
= 0; i
< dock
->max_icons
; i
++) {
3174 icon
= dock
->icon_array
[i
];
3175 if (icon
&& icon
->main_window
== window
)
3181 void wDockTrackWindowLaunch(WDock
*dock
, Window window
)
3184 char *wm_class
, *wm_instance
;
3186 Bool firstPass
= True
;
3188 char *command
= NULL
;
3190 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) || (!wm_class
&& !wm_instance
))
3193 command
= GetCommandForWindow(window
);
3195 for (i
= 0; i
< dock
->max_icons
; i
++) {
3196 icon
= dock
->icon_array
[i
];
3200 /* app is already attached to icon */
3201 if (icon
->main_window
== window
) {
3206 if ((icon
->wm_instance
|| icon
->wm_class
)
3207 && (icon
->launching
|| !icon
->running
)) {
3209 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0)
3212 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0)
3215 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0)
3218 if (!icon
->relaunching
) {
3221 /* Possibly an application that was docked with dockit,
3222 * but the user did not update WMState to indicate that
3223 * it was docked by force */
3224 wapp
= wApplicationOf(window
);
3226 icon
->forced_dock
= 1;
3229 if (!icon
->forced_dock
)
3230 icon
->main_window
= window
;
3233 if (!wPreferences
.no_animations
&& !icon
->launching
&&
3234 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
3238 icon
->launching
= 1;
3239 dockIconPaint(icon
);
3241 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
3242 wm_instance
, wm_class
, TILE_NORMAL
);
3243 /* XXX: can: aicon->icon == NULL ? */
3244 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
3245 wAppIconMove(aicon
, x0
, y0
);
3246 /* Should this always be lowered? -Dan */
3248 wLowerFrame(aicon
->icon
->core
);
3249 XMapWindow(dpy
, aicon
->icon
->core
->window
);
3250 aicon
->launching
= 1;
3251 wAppIconPaint(aicon
);
3252 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
3253 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
3254 wAppIconDestroy(aicon
);
3256 wDockFinishLaunch(dock
, icon
);
3261 if (firstPass
&& !found
) {
3275 void wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3277 if (!wPreferences
.flags
.noclip
) {
3278 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3279 if (scr
->current_workspace
!= workspace
) {
3280 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3281 WAppIconChain
*chain
= scr
->global_icons
;
3284 wDockMoveIconBetweenDocks(chain
->aicon
->dock
,
3285 scr
->workspaces
[workspace
]->clip
,
3286 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
3287 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
3288 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3289 chain
= chain
->next
;
3292 wDockHideIcons(old_clip
);
3293 if (old_clip
->auto_raise_lower
) {
3294 if (old_clip
->auto_raise_magic
) {
3295 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3296 old_clip
->auto_raise_magic
= NULL
;
3298 wDockLower(old_clip
);
3300 if (old_clip
->auto_collapse
) {
3301 if (old_clip
->auto_expand_magic
) {
3302 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3303 old_clip
->auto_expand_magic
= NULL
;
3305 old_clip
->collapsed
= 1;
3307 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3312 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3317 for (i
= 0; i
< dock
->max_icons
; i
++) {
3318 icon
= dock
->icon_array
[i
];
3322 if (icon
->launching
&& icon
->pid
== pid
) {
3323 if (!icon
->relaunching
) {
3325 icon
->main_window
= None
;
3327 wDockFinishLaunch(dock
, icon
);
3329 if (status
== 111) {
3334 if (icon
->drop_launch
)
3335 cmd
= icon
->dnd_command
;
3338 if (icon
->paste_launch
)
3339 cmd
= icon
->paste_command
;
3341 cmd
= icon
->command
;
3343 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3345 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3352 /* This function is called when the dock switches state between
3353 * "normal" (including auto-raise/lower) and "keep on top". It is
3354 * therefore clearly distinct from wDockLower/Raise, which are called
3355 * each time a not-kept-on-top dock is lowered/raised. */
3356 static void toggleLowered(WDock
*dock
)
3362 if (!dock
->lowered
) {
3363 newlevel
= WMNormalLevel
;
3366 newlevel
= WMDockLevel
;
3370 for (i
= 0; i
< dock
->max_icons
; i
++) {
3371 tmp
= dock
->icon_array
[i
];
3375 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3377 /* When the dock is no longer "on top", explicitly lower it as well.
3378 * It saves some CPU cycles (probably) to do it ourselves here
3379 * rather than calling wDockLower at the end of toggleLowered */
3381 wLowerFrame(tmp
->icon
->core
);
3384 if (dock
->type
== WM_DOCK
) {
3385 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
3386 toggleLowered(dc
->adrawer
);
3388 wScreenUpdateUsableArea(dock
->screen_ptr
);
3392 static void toggleCollapsed(WDock
*dock
)
3394 if (dock
->collapsed
) {
3395 dock
->collapsed
= 0;
3396 wDockShowIcons(dock
);
3398 dock
->collapsed
= 1;
3399 wDockHideIcons(dock
);
3403 static void openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3405 WScreen
*scr
= dock
->screen_ptr
;
3406 WObjDescriptor
*desc
;
3408 WApplication
*wapp
= NULL
;
3412 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3414 if (dock
->type
== WM_DOCK
) {
3415 /* Dock position menu */
3416 updateDockPositionMenu(scr
->dock_pos_menu
, dock
);
3417 dock
->menu
->flags
.realized
= 0;
3418 if (!wPreferences
.flags
.nodrawer
) {
3420 entry
= dock
->menu
->entries
[++index
];
3421 entry
->clientdata
= aicon
;
3422 wMenuSetEnabled(dock
->menu
, index
, True
);
3425 /* clip/drawer options */
3426 if (scr
->clip_options
)
3427 updateClipOptionsMenu(scr
->clip_options
, dock
);
3429 n_selected
= numberOfSelectedIcons(dock
);
3431 if (dock
->type
== WM_CLIP
) {
3432 /* Rename Workspace */
3433 entry
= dock
->menu
->entries
[++index
];
3434 if (aicon
== scr
->clip_icon
) {
3435 entry
->callback
= renameCallback
;
3436 entry
->clientdata
= dock
;
3437 entry
->flags
.indicator
= 0;
3438 entry
->text
= _("Rename Workspace");
3440 entry
->callback
= omnipresentCallback
;
3441 entry
->clientdata
= aicon
;
3442 if (n_selected
> 0) {
3443 entry
->flags
.indicator
= 0;
3444 entry
->text
= _("Toggle Omnipresent");
3446 entry
->flags
.indicator
= 1;
3447 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3448 entry
->flags
.indicator_type
= MI_CHECK
;
3449 entry
->text
= _("Omnipresent");
3454 /* select/unselect icon */
3455 entry
= dock
->menu
->entries
[++index
];
3456 entry
->clientdata
= aicon
;
3457 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3458 wMenuSetEnabled(dock
->menu
, index
, aicon
!= scr
->clip_icon
&& !wIsADrawer(scr
, aicon
));
3460 /* select/unselect all icons */
3461 entry
= dock
->menu
->entries
[++index
];
3462 entry
->clientdata
= aicon
;
3464 entry
->text
= _("Unselect All Icons");
3466 entry
->text
= _("Select All Icons");
3468 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3471 entry
= dock
->menu
->entries
[++index
];
3472 entry
->clientdata
= aicon
;
3474 entry
->text
= _("Keep Icons");
3476 entry
->text
= _("Keep Icon");
3478 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3480 if (dock
->type
== WM_CLIP
) {
3481 /* this is the workspace submenu part */
3482 entry
= dock
->menu
->entries
[++index
];
3484 entry
->text
= _("Move Icons To");
3486 entry
->text
= _("Move Icon To");
3488 if (scr
->clip_submenu
)
3489 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3491 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3494 /* remove icon(s) */
3495 entry
= dock
->menu
->entries
[++index
];
3496 entry
->clientdata
= aicon
;
3498 entry
->text
= _("Remove Icons");
3500 entry
->text
= _("Remove Icon");
3502 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3504 /* attract icon(s) */
3505 entry
= dock
->menu
->entries
[++index
];
3506 entry
->clientdata
= aicon
;
3508 dock
->menu
->flags
.realized
= 0;
3509 wMenuRealize(dock
->menu
);
3512 if (aicon
->icon
->owner
)
3513 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3518 entry
= dock
->menu
->entries
[++index
];
3519 entry
->clientdata
= aicon
;
3520 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3523 entry
= dock
->menu
->entries
[++index
];
3524 entry
->clientdata
= aicon
;
3525 if (wapp
&& wapp
->flags
.hidden
)
3526 entry
->text
= _("Unhide Here");
3528 entry
->text
= _("Bring Here");
3530 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3533 entry
= dock
->menu
->entries
[++index
];
3534 entry
->clientdata
= aicon
;
3535 if (wapp
&& wapp
->flags
.hidden
)
3536 entry
->text
= _("Unhide");
3538 entry
->text
= _("Hide");
3540 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3543 entry
= dock
->menu
->entries
[++index
];
3544 entry
->clientdata
= aicon
;
3545 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3547 /* kill or remove drawer */
3548 entry
= dock
->menu
->entries
[++index
];
3549 entry
->clientdata
= aicon
;
3550 if (wIsADrawer(scr
, aicon
)) {
3551 entry
->callback
= removeDrawerCallback
;
3552 entry
->text
= _("Remove drawer");
3553 wMenuSetEnabled(dock
->menu
, index
, True
);
3555 entry
->callback
= killCallback
;
3556 entry
->text
= _("Kill");
3557 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3560 if (!dock
->menu
->flags
.realized
)
3561 wMenuRealize(dock
->menu
);
3563 if (dock
->type
== WM_CLIP
|| dock
->type
== WM_DRAWER
) {
3564 /*x_pos = event->xbutton.x_root+2; */
3565 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3568 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3569 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3572 x_pos
= dock
->on_right_side
? scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3575 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3577 /* allow drag select */
3578 event
->xany
.send_event
= True
;
3579 desc
= &dock
->menu
->menu
->descriptor
;
3580 (*desc
->handle_mousedown
) (desc
, event
);
3583 /******************************************************************/
3584 static void iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3586 WAppIcon
*btn
= desc
->parent
;
3587 WDock
*dock
= btn
->dock
;
3588 WApplication
*wapp
= NULL
;
3591 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3592 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3594 assert(wapp
!= NULL
);
3596 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3598 /* go to the last workspace that the user worked on the app */
3599 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
&& !unhideHere
)
3600 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3602 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3604 if (event
->xbutton
.state
& MOD_MASK
)
3605 wHideOtherApplications(btn
->icon
->owner
);
3607 if (event
->xbutton
.button
== Button1
) {
3608 if (event
->xbutton
.state
& MOD_MASK
) {
3609 /* raise/lower dock */
3610 toggleLowered(dock
);
3611 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3612 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
)
3613 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3614 else if (wPreferences
.flags
.clip_merged_in_dock
) {
3615 // Is actually the dock
3618 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3619 launchDockedApplication(btn
, False
);
3623 wShowInfoPanel(dock
->screen_ptr
);
3627 toggleCollapsed(dock
);
3628 } else if (wIsADrawer(dock
->screen_ptr
, btn
)) {
3629 toggleCollapsed(dock
);
3630 } else if (btn
->command
) {
3631 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3632 launchDockedApplication(btn
, False
);
3633 } else if (btn
->xindex
== 0 && btn
->yindex
== 0 && btn
->dock
->type
== WM_DOCK
) {
3634 wShowInfoPanel(dock
->screen_ptr
);
3640 static void handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3642 WScreen
*scr
= dock
->screen_ptr
;
3643 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3644 WIcon
*icon
= aicon
->icon
;
3647 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;;
3648 int shad_x
= x
, shad_y
= y
;
3650 int grabbed
= 0, done
, previously_on_right
, now_on_right
, previous_x_pos
, i
;
3651 Pixmap ghost
= None
;
3652 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3654 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3655 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3656 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
)
3657 wwarning("pointer grab failed for dock move");
3659 if (dock
->type
== WM_DRAWER
) {
3661 wins
[0] = icon
->core
->window
;
3662 wins
[1] = scr
->dock_shadow
;
3663 XRestackWindows(dpy
, wins
, 2);
3664 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3665 ICON_SIZE
, ICON_SIZE
);
3667 if (icon
->pixmap
!=None
)
3668 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3670 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3672 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3673 XClearWindow(dpy
, scr
->dock_shadow
);
3675 XMapWindow(dpy
, scr
->dock_shadow
);
3678 previously_on_right
= now_on_right
= dock
->on_right_side
;
3679 previous_x_pos
= dock
->x_pos
;
3682 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3683 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3690 /* It means the cursor moved so fast that it entered
3691 * something else (if moving slowly, it would have
3692 * stayed in the dock that is being moved. Ignore such
3693 * "spurious" EnterNotifiy's */
3698 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3699 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3700 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3701 | ButtonReleaseMask
| ButtonPressMask
,
3702 wCursor
[WCUR_MOVE
], CurrentTime
);
3707 switch (dock
->type
) {
3709 x
= ev
.xmotion
.x_root
- ofs_x
;
3710 y
= ev
.xmotion
.y_root
- ofs_y
;
3711 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3712 moveDock(dock
, x
, y
);
3715 x
= ev
.xmotion
.x_root
- ofs_x
;
3716 y
= ev
.xmotion
.y_root
- ofs_y
;
3717 if (previously_on_right
)
3719 now_on_right
= (ev
.xmotion
.x_root
>= previous_x_pos
- ICON_SIZE
);
3723 now_on_right
= (ev
.xmotion
.x_root
> previous_x_pos
+ ICON_SIZE
* 2);
3725 if (now_on_right
!= dock
->on_right_side
)
3727 dock
->on_right_side
= now_on_right
;
3729 wArrangeIcons(scr
, False
);
3731 // Also perform the vertical move
3732 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3733 moveDock(dock
, dock
->x_pos
, y
);
3734 if (wPreferences
.flags
.wrap_appicons_in_dock
)
3736 for (i
= 0; i
< dock
->max_icons
; i
++) {
3737 int new_y
, new_index
, j
, ok
;
3738 if ((tmpaicon
= dock
->icon_array
[i
]) == NULL
)
3740 if (onScreen(scr
, tmpaicon
->x_pos
, tmpaicon
->y_pos
))
3742 new_y
= (tmpaicon
->y_pos
+ ICON_SIZE
* dock
->max_icons
) % (ICON_SIZE
* dock
->max_icons
);
3743 new_index
= (new_y
- dock
->y_pos
) / ICON_SIZE
;
3744 if (!onScreen(scr
, tmpaicon
->x_pos
, new_y
))
3747 for (j
= 0; j
< dock
->max_icons
; j
++)
3749 if (dock
->icon_array
[j
] != NULL
&&
3750 dock
->icon_array
[j
]->yindex
== new_index
)
3756 if (!ok
|| getDrawer(scr
, new_index
) != NULL
)
3758 wDockReattachIcon(dock
, tmpaicon
, tmpaicon
->xindex
, new_index
);
3760 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3762 int new_y
, new_index
, j
, ok
;
3763 tmpaicon
= dc
->adrawer
->icon_array
[0];
3764 if (onScreen(scr
, tmpaicon
->x_pos
, tmpaicon
->y_pos
))
3766 new_y
= (tmpaicon
->y_pos
+ ICON_SIZE
* dock
->max_icons
) % (ICON_SIZE
* dock
->max_icons
);
3767 new_index
= (new_y
- dock
->y_pos
) / ICON_SIZE
;
3768 if (!onScreen(scr
, tmpaicon
->x_pos
, new_y
))
3771 for (j
= 0; j
< dock
->max_icons
; j
++)
3773 if (dock
->icon_array
[j
] != NULL
&&
3774 dock
->icon_array
[j
]->yindex
== new_index
)
3780 if (!ok
|| getDrawer(scr
, new_index
) != NULL
)
3782 moveDock(dc
->adrawer
, tmpaicon
->x_pos
, new_y
);
3788 WDock
*real_dock
= dock
->screen_ptr
->dock
;
3791 x
= ev
.xmotion
.x_root
- ofs_x
;
3792 y
= ev
.xmotion
.y_root
- ofs_y
;
3793 snapped
= wDockSnapIcon(real_dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3795 shad_x
= real_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3796 shad_y
= real_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3797 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3799 moveDock(dock
, x
, y
);
3809 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3811 XUngrabPointer(dpy
, CurrentTime
);
3812 if (dock
->type
== WM_DRAWER
) {
3813 Window
*wins
[dock
->icon_count
];
3815 for (i
= 0; i
< dock
->max_icons
; i
++) {
3816 if ((tmpaicon
= dock
->icon_array
[i
]) == NULL
)
3818 wins
[ tmpaicon
->xindex
+ (dock
->on_right_side
? dock
->icon_count
- 1 : 0) ] = &tmpaicon
->icon
->core
->window
;
3820 SlideWindows(wins
, dock
->icon_count
,
3821 (dock
->on_right_side
? x
- (dock
->icon_count
- 1) * ICON_SIZE
: x
),
3823 (dock
->on_right_side
? shad_x
- (dock
->icon_count
- 1) * ICON_SIZE
: shad_x
),
3825 XUnmapWindow(dpy
, scr
->dock_shadow
);
3826 moveDock(dock
, shad_x
, shad_y
);
3827 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3835 XFreePixmap(dpy
, ghost
);
3836 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3841 static int getClipButton(int px
, int py
)
3843 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3845 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3848 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3849 return CLIP_FORWARD
;
3850 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3856 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3859 int done
, direction
, new_ws
;
3861 WDock
*clip
= scr
->clip_icon
->dock
;
3863 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3865 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3866 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3868 wClipIconPaint(scr
->clip_icon
);
3871 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3878 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3879 if (new_dir
!= direction
) {
3880 direction
= new_dir
;
3881 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3882 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3883 wClipIconPaint(scr
->clip_icon
);
3891 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3896 clip
->lclip_button_pushed
= 0;
3897 clip
->rclip_button_pushed
= 0;
3899 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3901 if (direction
== CLIP_FORWARD
) {
3902 if (scr
->current_workspace
< scr
->workspace_count
- 1)
3903 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3904 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
- 1)
3905 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3906 else if (wPreferences
.ws_cycle
)
3907 wWorkspaceChange(scr
, 0);
3908 } else if (direction
== CLIP_REWIND
) {
3909 if (scr
->current_workspace
> 0)
3910 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
3911 else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
)
3912 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
3915 wClipIconPaint(scr
->clip_icon
);
3918 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3920 WAppIcon
*aicon
= desc
->parent
;
3921 WDock
*dock
= aicon
->dock
;
3922 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3924 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3927 scr
->last_dock
= dock
;
3929 if (dock
->menu
->flags
.mapped
)
3930 wMenuUnmap(dock
->menu
);
3932 if (IsDoubleClick(scr
, event
)) {
3933 /* double-click was not in the main clip icon */
3934 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3935 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3936 iconDblClick(desc
, event
);
3941 if (event
->xbutton
.button
== Button1
) {
3942 if (event
->xbutton
.state
& MOD_MASK
)
3947 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
&& dock
->type
!= WM_DOCK
) {
3948 wIconSelect(aicon
->icon
);
3952 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3953 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
&&
3954 (dock
->type
== WM_CLIP
|| (dock
->type
== WM_DOCK
&& wPreferences
.flags
.clip_merged_in_dock
)))
3955 handleClipChangeWorkspace(scr
, event
);
3957 handleDockMove(dock
, aicon
, event
);
3959 Bool hasMoved
= wHandleAppIconMove(aicon
, event
);
3960 if (wPreferences
.single_click
&& !hasMoved
)
3961 iconDblClick(desc
, event
);
3963 } else if (event
->xbutton
.button
== Button2
&& aicon
== scr
->clip_icon
) {
3964 if (!scr
->clip_ws_menu
) {
3965 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3967 if (scr
->clip_ws_menu
) {
3968 WMenu
*wsMenu
= scr
->clip_ws_menu
;
3971 wWorkspaceMenuUpdate(scr
, wsMenu
);
3973 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
3976 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
3977 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
3979 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
3981 desc
= &wsMenu
->menu
->descriptor
;
3982 event
->xany
.send_event
= True
;
3983 (*desc
->handle_mousedown
) (desc
, event
);
3985 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
3986 (event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
) {
3987 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3988 } else if (event
->xbutton
.button
== Button3
) {
3989 if (event
->xbutton
.send_event
&&
3990 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3991 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3992 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3993 wwarning("pointer grab failed for dockicon menu");
3997 openDockMenu(dock
, aicon
, event
);
3998 } else if (event
->xbutton
.button
== Button2
) {
3999 WAppIcon
*btn
= desc
->parent
;
4001 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
4002 launchDockedApplication(btn
, True
);
4006 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
4008 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
4012 assert(event
->type
== EnterNotify
);
4014 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
4017 scr
= btn
->icon
->core
->screen_ptr
;
4023 /* The auto raise/lower code */
4024 tmp
= (dock
->type
== WM_DRAWER
? scr
->dock
: dock
);
4025 if (tmp
->auto_lower_magic
) {
4026 WMDeleteTimerHandler(tmp
->auto_lower_magic
);
4027 tmp
->auto_lower_magic
= NULL
;
4029 if (tmp
->auto_raise_lower
&& !tmp
->auto_raise_magic
)
4030 tmp
->auto_raise_magic
= WMAddTimerHandler(wPreferences
.clip_auto_raise_delay
, clipAutoRaise
, (void *) tmp
);
4032 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4035 /* The auto expand/collapse code */
4036 if (dock
->auto_collapse_magic
) {
4037 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
4038 dock
->auto_collapse_magic
= NULL
;
4040 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
)
4041 dock
->auto_expand_magic
= WMAddTimerHandler(wPreferences
.clip_auto_expand_delay
, clipAutoExpand
, (void *)dock
);
4044 static void clipLeave(WDock
*dock
)
4047 WObjDescriptor
*desc
= NULL
;
4053 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
4054 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
4055 (XPointer
*) & desc
) != XCNOENT
4056 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
4057 && ((WAppIcon
*) desc
->parent
)->dock
== dock
) {
4058 /* We haven't left the dock/clip/drawer yet */
4059 XPutBackEvent(dpy
, &event
);
4063 XPutBackEvent(dpy
, &event
);
4065 /* We entered a withdrawn window, so we're still in Clip */
4069 tmp
= (dock
->type
== WM_DRAWER
? dock
->screen_ptr
->dock
: dock
);
4070 if (tmp
->auto_raise_magic
) {
4071 WMDeleteTimerHandler(tmp
->auto_raise_magic
);
4072 tmp
->auto_raise_magic
= NULL
;
4074 if (tmp
->auto_raise_lower
&& !tmp
->auto_lower_magic
)
4075 tmp
->auto_lower_magic
= WMAddTimerHandler(wPreferences
.clip_auto_lower_delay
, clipAutoLower
, (void *)tmp
);
4077 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4080 if (dock
->auto_expand_magic
) {
4081 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4082 dock
->auto_expand_magic
= NULL
;
4084 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
)
4085 dock
->auto_collapse_magic
= WMAddTimerHandler(wPreferences
.clip_auto_collapse_delay
, clipAutoCollapse
, (void *)dock
);
4088 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4090 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
4092 assert(event
->type
== LeaveNotify
);
4094 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
4097 clipLeave(btn
->dock
);
4100 static void clipAutoCollapse(void *cdata
)
4102 WDock
*dock
= (WDock
*) cdata
;
4104 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4107 if (dock
->auto_collapse
) {
4108 dock
->collapsed
= 1;
4109 wDockHideIcons(dock
);
4111 dock
->auto_collapse_magic
= NULL
;
4114 static void clipAutoExpand(void *cdata
)
4116 WDock
*dock
= (WDock
*) cdata
;
4118 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4121 if (dock
->auto_collapse
) {
4122 dock
->collapsed
= 0;
4123 wDockShowIcons(dock
);
4125 dock
->auto_expand_magic
= NULL
;
4128 static void clipAutoLower(void *cdata
)
4130 WDock
*dock
= (WDock
*) cdata
;
4132 if (dock
->auto_raise_lower
)
4135 dock
->auto_lower_magic
= NULL
;
4138 static void clipAutoRaise(void *cdata
)
4140 WDock
*dock
= (WDock
*) cdata
;
4142 if (dock
->auto_raise_lower
)
4145 dock
->auto_raise_magic
= NULL
;
4148 static Bool
iconCanBeOmnipresent(WAppIcon
*aicon
)
4150 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4155 for (i
= 0; i
< scr
->workspace_count
; i
++) {
4156 clip
= scr
->workspaces
[i
]->clip
;
4158 if (clip
== aicon
->dock
)
4161 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4162 return False
; /* Clip is full in some workspace */
4164 for (j
= 0; j
< clip
->max_icons
; j
++) {
4165 btn
= clip
->icon_array
[j
];
4166 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
4174 int wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
4176 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4177 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4178 int status
= WO_SUCCESS
;
4180 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== scr
->clip_icon
)
4181 return WO_NOT_APPLICABLE
;
4183 if (aicon
->omnipresent
== omnipresent
)
4187 if (iconCanBeOmnipresent(aicon
)) {
4188 aicon
->omnipresent
= 1;
4189 new_entry
= wmalloc(sizeof(WAppIconChain
));
4190 new_entry
->aicon
= aicon
;
4191 new_entry
->next
= scr
->global_icons
;
4192 scr
->global_icons
= new_entry
;
4193 scr
->global_icon_count
++;
4195 aicon
->omnipresent
= 0;
4199 aicon
->omnipresent
= 0;
4200 if (aicon
== scr
->global_icons
->aicon
) {
4201 tmp
= scr
->global_icons
->next
;
4202 wfree(scr
->global_icons
);
4203 scr
->global_icons
= tmp
;
4204 scr
->global_icon_count
--;
4206 tmp
= scr
->global_icons
;
4208 if (tmp
->next
->aicon
== aicon
) {
4209 tmp1
= tmp
->next
->next
;
4212 scr
->global_icon_count
--;
4220 wAppIconPaint(aicon
);
4225 static void drawerAppendToChain(WScreen
*scr
, WDock
*drawer
)
4227 WDrawerChain
**where_to_add
;
4229 where_to_add
= &scr
->drawers
;
4230 while ((*where_to_add
) != NULL
) {
4231 where_to_add
= &(*where_to_add
)->next
;
4234 *where_to_add
= wmalloc(sizeof(WDrawerChain
));
4235 (*where_to_add
)->adrawer
= drawer
;
4236 (*where_to_add
)->next
= NULL
;
4237 scr
->drawer_count
++;
4241 static void drawerRemoveFromChain(WScreen
*scr
, WDock
*drawer
)
4243 WDrawerChain
*next
, **to_remove
;
4245 to_remove
= &scr
->drawers
;
4247 if (*to_remove
== NULL
) {
4248 wwarning("The drawer to be removed can not be found.");
4251 if ((*to_remove
)->adrawer
== drawer
)
4254 to_remove
= &(*to_remove
)->next
;
4256 next
= (*to_remove
)->next
;
4259 scr
->drawer_count
--;
4263 /* Don't free the returned string. Duplicate it. */
4264 static char * findUniqueName(WScreen
*scr
, const char *instance_basename
)
4266 static char buffer
[128];
4269 Bool already_in_use
= True
;
4271 #define UNIQUE_NAME_WATCHDOG 128
4272 for (i
= 0; already_in_use
&& i
< UNIQUE_NAME_WATCHDOG
; i
++) {
4273 snprintf(buffer
, sizeof buffer
, "%s%d", instance_basename
, i
);
4275 already_in_use
= False
;
4277 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4278 if (!strncmp(dc
->adrawer
->icon_array
[0]->wm_instance
, buffer
,
4280 already_in_use
= True
;
4286 if (i
== UNIQUE_NAME_WATCHDOG
)
4287 wwarning("Couldn't find a unique name for drawer in %d attemps.", i
);
4288 #undef UNIQUE_NAME_WATCHDOG
4294 static void drawerIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
4296 wDrawerIconPaint((WAppIcon
*) desc
->parent
);
4300 static int addADrawer(WScreen
*scr
)
4302 int i
, y
, sig
, found_y
;
4303 WDock
*drawer
, *dock
= scr
->dock
;
4305 char can_be_here
[2 * dock
->max_icons
- 1];
4307 if (dock
->icon_count
+ scr
->drawer_count
>= dock
->max_icons
)
4310 for (y
= -dock
->max_icons
+ 1; y
< dock
->max_icons
; y
++) {
4311 can_be_here
[y
+ dock
->max_icons
- 1] = True
;
4313 for (i
= 0; i
< dock
->max_icons
; i
++) {
4314 if (dock
->icon_array
[i
] != NULL
)
4315 can_be_here
[dock
->icon_array
[i
]->yindex
+ dock
->max_icons
- 1] = False
;
4317 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4318 y
= (int) ((dc
->adrawer
->y_pos
- dock
->y_pos
) / ICON_SIZE
);
4319 can_be_here
[y
+ dock
->max_icons
- 1] = False
;
4323 for (sig
= 1; !found_y
&& sig
> -2; sig
-= 2) // 1, then -1
4325 for (y
= sig
; sig
* y
< dock
->max_icons
; y
+= sig
)
4327 if (can_be_here
[y
+ dock
->max_icons
- 1] &&
4328 onScreen(scr
, dock
->x_pos
, dock
->y_pos
+ y
* ICON_SIZE
))
4337 /* This can happen even when dock->icon_count + scr->drawer_count
4338 * < dock->max_icons when the dock is not aligned on an
4339 * ICON_SIZE multiple, as some space is lost above and under it */
4342 drawer
= wDockCreate(scr
, WM_DRAWER
, NULL
);
4343 drawer
->lowered
= scr
->dock
->lowered
;
4344 drawer
->auto_raise_lower
= scr
->dock
->auto_raise_lower
;
4345 drawer
->x_pos
= dock
->x_pos
;
4346 drawer
->y_pos
= dock
->y_pos
+ ICON_SIZE
* y
;
4347 drawer
->icon_array
[0]->xindex
= 0;
4348 drawer
->icon_array
[0]->yindex
= 0;
4349 drawer
->icon_array
[0]->x_pos
= drawer
->x_pos
;
4350 drawer
->icon_array
[0]->y_pos
= drawer
->y_pos
;
4351 XMoveWindow(dpy
, drawer
->icon_array
[0]->icon
->core
->window
,
4352 drawer
->icon_array
[0]->x_pos
, drawer
->icon_array
[0]->y_pos
);
4358 static void addADrawerCallback(WMenu
*menu
, WMenuEntry
*entry
)
4360 assert(entry
->clientdata
!=NULL
);
4361 addADrawer(((WAppIcon
*) entry
->clientdata
)->dock
->screen_ptr
);
4365 static void drawerDestroy(WDock
*drawer
)
4375 scr
= drawer
->screen_ptr
;
4377 /* Note regarding menus: we can't delete any dock/clip/drawer menu, because
4378 * that would (attempt to) wfree some memory in gettext library (see menu
4379 * entries that have several "versions", such like "Hide" and "Unhide"). */
4381 wDefaultPurgeInfo(scr
, drawer
->icon_array
[0]->wm_instance
,
4382 drawer
->icon_array
[0]->wm_class
);
4383 icons
= WMCreateArray(drawer
->icon_count
- 1);
4384 for (i
= 1; i
< drawer
->max_icons
; i
++) {
4385 if (!(aicon
= drawer
->icon_array
[i
]))
4387 WMAddToArray(icons
, aicon
);
4389 removeIcons(icons
, drawer
);
4391 if (drawer
->auto_collapse_magic
) {
4392 WMDeleteTimerHandler(drawer
->auto_collapse_magic
);
4393 drawer
->auto_collapse_magic
= NULL
;
4395 if (drawer
->auto_lower_magic
) {
4396 WMDeleteTimerHandler(drawer
->auto_lower_magic
);
4397 drawer
->auto_lower_magic
= NULL
;
4400 wAppIconDestroy(drawer
->icon_array
[0]);
4401 wfree(drawer
->icon_array
);
4404 drawerRemoveFromChain(scr
, drawer
);
4405 if (scr
->last_dock
== drawer
)
4406 scr
->last_dock
= NULL
;
4407 if (scr
->attracting_drawer
== drawer
)
4408 scr
->attracting_drawer
= NULL
;
4412 static void removeDrawerCallback(WMenu
*menu
, WMenuEntry
*entry
)
4414 WDock
*dock
= ((WAppIcon
*)entry
->clientdata
)->dock
;
4415 assert(dock
!= NULL
);
4417 if (dock
->icon_count
> 1) {
4418 if (wMessageDialog(dock
->screen_ptr
, _("Drawer"),
4419 _("All icons in this drawer will be detached!"),
4420 _("OK"), _("Cancel"), NULL
) != WAPRDefault
)
4423 drawerDestroy(dock
);
4427 void wDrawerIconPaint(WAppIcon
*dicon
)
4429 Window win
= dicon
->icon
->core
->window
;
4430 WScreen
*scr
= dicon
->icon
->core
->screen_ptr
;
4432 GC gc
= scr
->draw_gc
;
4435 wIconPaint(dicon
->icon
);
4437 if (!dicon
->dock
->collapsed
)
4438 color
= scr
->clip_title_color
[CLIP_NORMAL
];
4440 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
4441 XSetForeground(dpy
, gc
, WMColorPixel(color
));
4443 if (dicon
->dock
->on_right_side
) {
4444 p
[0].x
= p
[3].x
= 10;
4445 p
[0].y
= p
[3].y
= ICON_SIZE
/ 2 - 5;
4447 p
[1].y
= ICON_SIZE
/ 2 + 5;
4449 p
[2].y
= ICON_SIZE
/ 2;
4452 p
[0].x
= p
[3].x
= ICON_SIZE
-1 - 10;
4453 p
[0].y
= p
[3].y
= ICON_SIZE
/ 2 - 5;
4454 p
[1].x
= ICON_SIZE
-1 - 10;
4455 p
[1].y
= ICON_SIZE
/ 2 + 5;
4456 p
[2].x
= ICON_SIZE
-1 - 5;
4457 p
[2].y
= ICON_SIZE
/ 2;
4459 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
4460 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
4464 RImage
* wDrawerMakeTile(WScreen
*scr
, RImage
*normalTile
)
4466 RImage
*tile
= RCloneImage(normalTile
);
4471 dark
.red
= dark
.green
= dark
.blue
= 60;
4474 light
.red
= light
.green
= light
.blue
= 80;
4477 if (!scr
->dock
|| scr
->dock
->on_right_side
) {
4478 ROperateLine(tile
, RSubtractOperation
, 11, ICON_SIZE
/ 2 - 7,
4479 4, ICON_SIZE
/ 2, &dark
); /* / */
4480 ROperateLine(tile
, RSubtractOperation
, 11, ICON_SIZE
/ 2 + 7,
4481 4, ICON_SIZE
/ 2, &dark
); /* \ */
4482 ROperateLine(tile
, RAddOperation
, 11, ICON_SIZE
/ 2 - 7,
4483 11, ICON_SIZE
/ 2 + 7, &light
); /* | */
4486 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 - 7,
4487 ICON_SIZE
-1 - 4, ICON_SIZE
/ 2, &dark
); /* \ */
4488 ROperateLine(tile
, RAddOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 + 7,
4489 ICON_SIZE
-1 - 4, ICON_SIZE
/ 2, &light
); /* / */
4490 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 - 7,
4491 ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 + 7, &dark
); /* | */
4497 static void swapDrawer(WDock
*drawer
, int new_x
)
4501 drawer
->on_right_side
= !drawer
->on_right_side
;
4502 drawer
->x_pos
= new_x
;
4504 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4506 if ((ai
= drawer
->icon_array
[i
]) == NULL
)
4508 ai
->xindex
*= -1; /* so A B C becomes C B A */
4509 ai
->x_pos
= new_x
+ ai
->xindex
* ICON_SIZE
;
4511 /* Update drawer's tile */
4513 wIconUpdate(ai
->icon
);
4514 wDrawerIconPaint(ai
);
4516 XMoveWindow(dpy
, ai
->icon
->core
->window
, ai
->x_pos
, ai
->y_pos
);
4521 static void swapDrawers(WScreen
*scr
, int on_right_side
, int new_x
)
4525 if (scr
->drawer_tile
) {
4526 RReleaseImage(scr
->drawer_tile
);
4528 scr
->drawer_tile
= wDrawerMakeTile(scr
, scr
->icon_tile
);
4530 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4531 swapDrawer(dc
->adrawer
, new_x
);
4532 assert(dc
->adrawer
->on_right_side
== on_right_side
);
4537 int wIsADrawer(WScreen
*scr
, WAppIcon
*aicon
)
4539 return aicon
&& aicon
->dock
&&
4540 aicon
->dock
->type
== WM_DRAWER
&& aicon
->dock
->icon_array
[0] == aicon
;
4544 static WDock
* getDrawer(WScreen
*scr
, int y_index
)
4548 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4549 if (dc
->adrawer
->y_pos
- scr
->dock
->y_pos
== y_index
* ICON_SIZE
)
4557 /* Find the "hole" a moving appicon created when snapped into the
4558 * drawer. redocking is a boolean. If the moving appicon comes from the
4559 * drawer, drawer->icon_count is correct. If not, redocking is then false and
4560 * there are now drawer->icon_count plus one appicons in the drawer. */
4561 static int indexOfHole(WDock
*drawer
, WAppIcon
*moving_aicon
, int redocking
)
4563 int index_of_hole
, i
;
4565 /* Classic interview question...
4567 * We have n-1 (n = drawer->icon_count-1 or drawer->icon_count, see
4568 * redocking) appicons, whose xindex are unique in [1..n]. One is missing:
4569 * that's where the ghost of the moving appicon is, that's what the
4570 * function should return.
4572 * We compute 1+2+...+n (this sum is equal to n*(n+1)/2), we substract to
4573 * this sum the xindex of each of the n-1 appicons, and we get the correct
4577 index_of_hole
= (drawer
->icon_count
- 1) * drawer
->icon_count
/ 2;
4579 index_of_hole
= drawer
->icon_count
* (drawer
->icon_count
+ 1) / 2;
4581 index_of_hole
*= (drawer
->on_right_side
? -1 : 1);
4583 for (i
= 1; i
< drawer
->max_icons
; i
++) {
4584 if (drawer
->icon_array
[i
] && drawer
->icon_array
[i
] != moving_aicon
)
4585 index_of_hole
-= drawer
->icon_array
[i
]->xindex
;
4587 /* wmessage(" Index of the moving appicon is %d (%sredocking)", index_of_hole, (redocking ? "" : "not ")); */
4588 if (abs(index_of_hole
) > abs(drawer
->icon_count
) - (redocking
? 1 : 0))
4589 wwarning(" index_of_hole is too large ! (%d greater than %d)",
4590 index_of_hole
, abs(drawer
->icon_count
) - (redocking
? 1 : 0));
4591 if (index_of_hole
== 0)
4592 wwarning(" index_of_hole == 0 (%sredocking, icon_count == %d)", (redocking
? "" : "not "), drawer
->icon_count
);
4594 return index_of_hole
;
4598 void wSlideAppicons(WAppIcon
**appicons
, int n
, int to_the_left
)
4601 int leftmost
= -1, min_index
= 9999, from_x
= -1; // leftmost and from_x initialized to avoid warning
4608 for (i
= 0; i
< n
; i
++) {
4609 aicon
= appicons
[i
];
4610 aicon
->xindex
+= (to_the_left
? -1 : +1);
4611 if (aicon
->xindex
< min_index
) {
4612 min_index
= aicon
->xindex
;
4614 from_x
= aicon
->x_pos
;
4616 aicon
->x_pos
+= (to_the_left
? -ICON_SIZE
: +ICON_SIZE
);
4619 for (i
= 0; i
< n
; i
++) {
4620 aicon
= appicons
[i
];
4621 wins
[aicon
->xindex
- min_index
] = &aicon
->icon
->core
->window
;
4623 aicon
= appicons
[leftmost
];
4624 SlideWindows(wins
, n
, from_x
, aicon
->y_pos
, aicon
->x_pos
, aicon
->y_pos
);
4628 void wDrawerFillTheGap(WDock
*drawer
, WAppIcon
*aicon
, Bool redocking
)
4631 int index_of_hole
= indexOfHole(drawer
, aicon
, redocking
);
4632 WAppIcon
*aicons_to_shift
[drawer
->icon_count
];
4635 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4636 WAppIcon
*ai
= drawer
->icon_array
[i
];
4637 if (ai
&& ai
!= aicon
&&
4638 abs(ai
->xindex
) > abs(index_of_hole
))
4639 aicons_to_shift
[j
++] = ai
;
4641 if (j
!= drawer
->icon_count
- abs(index_of_hole
) - (redocking
? 1 : 0))
4642 wwarning("Removing aicon at index %d from %s: j=%d but should be %d",
4643 index_of_hole
, drawer
->icon_array
[0]->wm_instance
,
4644 j
, drawer
->icon_count
- abs(index_of_hole
) - (redocking
? 1 : 0));
4645 wSlideAppicons(aicons_to_shift
, j
, !drawer
->on_right_side
);
4649 static void drawerConsolidateIcons(WDock
*drawer
)
4651 WAppIcon
*aicons_to_shift
[drawer
->icon_count
];
4652 int maxRemaining
= 0;
4655 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4656 WAppIcon
*ai
= drawer
->icon_array
[i
];
4659 sum
+= abs(ai
->xindex
);
4660 if (abs(ai
->xindex
) > maxRemaining
)
4661 maxRemaining
= abs(ai
->xindex
);
4663 while (sum
!= maxRemaining
* (maxRemaining
+ 1) / 2) { // while there is a hole
4666 // Look up for the hole at max position
4668 for (maxDeleted
= maxRemaining
- 1; maxDeleted
> 0; maxDeleted
--) {
4669 Bool foundAppIconThere
= False
;
4670 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4671 WAppIcon
*ai
= drawer
->icon_array
[i
];
4674 if (abs(ai
->xindex
) == maxDeleted
) {
4675 foundAppIconThere
= True
;
4679 if (!foundAppIconThere
)
4682 assert(maxDeleted
> 0); // would mean while test is wrong
4684 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4685 ai
= drawer
->icon_array
[i
];
4686 if (ai
!= NULL
&& abs(ai
->xindex
) > maxDeleted
)
4687 aicons_to_shift
[n
++] = ai
;
4689 assert(n
== maxRemaining
- maxDeleted
); // for the code review ;-)
4690 wSlideAppicons(aicons_to_shift
, n
, !drawer
->on_right_side
);
4691 // Efficient beancounting
4699 /* similar to wDockRestoreState, but a lot a specific stuff too... */
4700 static WDock
* drawerRestoreState(WScreen
*scr
, WMPropList
*drawer_state
)
4703 WMPropList
*apps
, *value
, *dock_state
;
4712 WMRetainPropList(drawer_state
);
4714 /* Get the instance name, and create a drawer */
4715 value
= WMGetFromPLDictionary(drawer_state
, dName
);
4716 drawer
= wDockCreate(scr
, WM_DRAWER
, WMGetFromPLString(value
));
4718 /* restore DnD command and paste command */
4720 value
= WMGetFromPLDictionary(drawer_state
, dDropCommand
);
4721 if (value
&& WMIsPLString(value
))
4722 drawer
->icon_array
[0]->dnd_command
= wstrdup(WMGetFromPLString(value
));
4725 value
= WMGetFromPLDictionary(drawer_state
, dPasteCommand
);
4726 if (value
&& WMIsPLString(value
))
4727 drawer
->icon_array
[0]->paste_command
= wstrdup(WMGetFromPLString(value
));
4729 /* restore position */
4730 value
= WMGetFromPLDictionary(drawer_state
, dPosition
);
4731 if (!value
|| !WMIsPLString(value
))
4732 COMPLAIN("Position");
4735 if (sscanf(WMGetFromPLString(value
), "%i,%i", &x
, &y
) != 2)
4736 COMPLAIN("Position");
4738 /* check position sanity */
4739 if (x
!= scr
->dock
->x_pos
) {
4740 x
= scr
->dock
->x_pos
;
4742 y_index
= (y
- scr
->dock
->y_pos
) / ICON_SIZE
;
4743 if (y_index
>= scr
->dock
->max_icons
) {
4744 /* Here we should do something more intelligent, since it
4745 * can happen even if the user hasn't hand-edited his
4746 * G/D/State file (but uses a lower resolution). */
4747 y_index
= scr
->dock
->max_icons
- 1;
4749 y
= scr
->dock
->y_pos
+ y_index
* ICON_SIZE
;
4750 moveDock(drawer
, x
, y
);
4753 /* restore dock properties (applist and others) */
4754 dock_state
= WMGetFromPLDictionary(drawer_state
, dDock
);
4756 /* restore lowered/raised state: same as scr->dock, no matter what */
4757 drawer
->lowered
= scr
->dock
->lowered
;
4758 if (!drawer
->lowered
)
4759 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMDockLevel
);
4761 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMNormalLevel
);
4762 wRaiseFrame(drawer
->icon_array
[0]->icon
->core
);
4764 /* restore collapsed state */
4765 drawer
->collapsed
= 0;
4766 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
4767 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4768 drawer
->collapsed
= 1;
4770 /* restore auto-collapsed state */
4771 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
4772 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4773 drawer
->auto_collapse
= 1;
4774 drawer
->collapsed
= 1;
4776 drawer
->auto_collapse
= 0; // because wDockCreate sets it (drawers only)
4779 /* restore auto-raise/lower state: same as scr->dock, no matter what */
4780 drawer
->auto_raise_lower
= scr
->dock
->auto_raise_lower
;
4782 /* restore attract icons state */
4783 drawer
->attract_icons
= 0;
4784 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
4785 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4786 drawer
->attract_icons
= 1;
4787 scr
->attracting_drawer
= drawer
;
4790 /* application list */
4791 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
4797 count
= WMGetPropListItemCount(apps
);
4802 for (i
=0; i
<count
; i
++) {
4803 if (drawer
->icon_count
>= drawer
->max_icons
) {
4804 wwarning(_("there are too many icons stored in drawer. Ignoring what doesn't fit"));
4808 value
= WMGetFromPLArray(apps
, i
);
4809 aicon
= restore_icon_state(scr
, value
, WM_DRAWER
, drawer
->icon_count
);
4811 drawer
->icon_array
[drawer
->icon_count
] = aicon
;
4814 aicon
->dock
= drawer
;
4815 aicon
->x_pos
= drawer
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
4816 aicon
->y_pos
= drawer
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
4818 if (!drawer
->lowered
)
4819 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
4821 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
4823 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
4825 if (!drawer
->collapsed
)
4826 XMapWindow(dpy
, aicon
->icon
->core
->window
);
4827 wRaiseFrame(aicon
->icon
->core
);
4829 drawer
->icon_count
++;
4834 WMReleasePropList(drawer_state
);
4840 /* Same kind of comment than for previous function: this function is
4841 * very similar to make_icon_state, but has substential differences as
4843 static WMPropList
*drawerSaveState(WScreen
*scr
, WDock
*drawer
)
4845 WMPropList
*pstr
, *drawer_state
;
4849 ai
= drawer
->icon_array
[0];
4850 /* Store its name */
4851 pstr
= WMCreatePLString(ai
->wm_instance
);
4852 drawer_state
= WMCreatePLDictionary(dName
, pstr
, NULL
); /* we need this final NULL */
4853 WMReleasePropList(pstr
);
4855 /* Store its position */
4856 snprintf(buffer
, sizeof(buffer
), "%i,%i", ai
->x_pos
, ai
->y_pos
);
4857 pstr
= WMCreatePLString(buffer
);
4858 WMPutInPLDictionary(drawer_state
, dPosition
, pstr
);
4859 WMReleasePropList(pstr
);
4862 /* Store its DnD command */
4863 if (ai
->dnd_command
) {
4864 pstr
= WMCreatePLString(ai
->dnd_command
);
4865 WMPutInPLDictionary(drawer_state
, dDropCommand
, pstr
);
4866 WMReleasePropList(pstr
);
4870 /* Store its paste command */
4871 if (ai
->paste_command
) {
4872 pstr
= WMCreatePLString(ai
->paste_command
);
4873 WMPutInPLDictionary(drawer_state
, dPasteCommand
, pstr
);
4874 WMReleasePropList(pstr
);
4877 /* Store applications list and other properties */
4878 pstr
= dockSaveState(drawer
);
4879 WMPutInPLDictionary(drawer_state
, dDock
, pstr
);
4880 WMReleasePropList(pstr
);
4882 return drawer_state
;
4886 void wDrawersSaveState(WScreen
*scr
)
4888 WMPropList
*all_drawers
, *drawer_state
;
4894 all_drawers
= WMCreatePLArray(NULL
);
4895 for (i
=0, dc
= scr
->drawers
;
4896 i
< scr
->drawer_count
;
4897 i
++, dc
= dc
->next
) {
4898 drawer_state
= drawerSaveState(scr
, dc
->adrawer
);
4899 WMAddToPLArray(all_drawers
, drawer_state
);
4900 WMReleasePropList(drawer_state
);
4902 WMPutInPLDictionary(scr
->session_state
, dDrawers
, all_drawers
);
4903 WMReleasePropList(all_drawers
);
4907 void wDrawersRestoreState(WScreen
*scr
)
4909 WMPropList
*all_drawers
, *drawer_state
;
4914 if (scr
->session_state
== NULL
)
4917 all_drawers
= WMGetFromPLDictionary(scr
->session_state
, dDrawers
);
4921 for (i
= 0; i
< WMGetPropListItemCount(all_drawers
); i
++) {
4922 drawer_state
= WMGetFromPLArray(all_drawers
, i
);
4923 drawerRestoreState(scr
, drawer_state
);
4924 // Note: scr->drawers was updated when the the drawer was created