1 /* dock.c- built-in Dock module for WindowMaker
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <X11/Xutil.h>
37 #define PATH_MAX DEFAULT_PATH_MAX
40 #include "WindowMaker.h"
48 #include "dockedapp.h"
51 #include "properties.h"
55 #include "workspace.h"
57 #include "superfluous.h"
59 #include "placement.h"
63 /**** Local variables ****/
66 #define CLIP_FORWARD 2
68 #define MOD_MASK wPreferences.modifier_mask
69 #define ICON_SIZE wPreferences.icon_size
71 /***** Local variables ****/
73 static WMPropList
*dCommand
= NULL
;
74 static WMPropList
*dPasteCommand
= NULL
;
75 #ifdef XDND /* XXX was OFFIX */
76 static WMPropList
*dDropCommand
= NULL
;
78 static WMPropList
*dAutoLaunch
, *dLock
;
79 static WMPropList
*dName
, *dForced
, *dBuggyApplication
, *dYes
, *dNo
;
80 static WMPropList
*dHost
, *dDock
, *dClip
;
81 static WMPropList
*dAutoAttractIcons
;
83 static WMPropList
*dPosition
, *dApplications
, *dLowered
, *dCollapsed
;
85 static WMPropList
*dAutoCollapse
, *dAutoRaiseLower
, *dOmnipresent
;
87 static WMPropList
*dDrawers
= NULL
;
89 static void dockIconPaint(WAppIcon
*btn
);
91 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
93 static pid_t
execCommand(WAppIcon
*btn
, const char *command
, WSavedState
*state
);
95 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
97 static int getClipButton(int px
, int py
);
99 static void toggleLowered(WDock
*dock
);
101 static void toggleCollapsed(WDock
*dock
);
103 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
105 static void clipLeave(WDock
*dock
);
107 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
109 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
110 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
111 static void clipAutoCollapse(void *cdata
);
112 static void clipAutoExpand(void *cdata
);
113 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
);
115 static void clipAutoLower(void *cdata
);
116 static void clipAutoRaise(void *cdata
);
117 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
, const char *name
);
119 static void drawerIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
120 static void removeDrawerCallback(WMenu
*menu
, WMenuEntry
*entry
);
121 static void drawerAppendToChain(WScreen
*scr
, WDock
*drawer
);
122 static char *findUniqueName(WScreen
*scr
, const char *instance_basename
);
123 static void addADrawerCallback(WMenu
*menu
, WMenuEntry
*entry
);
124 static void swapDrawers(WScreen
*scr
, int on_right_side
, int new_x
);
125 static WDock
* getDrawer(WScreen
*scr
, int y_index
);
126 static int indexOfHole(WDock
*drawer
, WAppIcon
*moving_aicon
, int redocking
);
127 static void drawerConsolidateIcons(WDock
*drawer
);
129 static int onScreen(WScreen
*scr
, int x
, int y
);
131 static void make_keys(void)
133 if (dCommand
!= NULL
)
136 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
137 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
139 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
141 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
142 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
143 dName
= WMRetainPropList(WMCreatePLString("Name"));
144 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
145 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
146 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
147 dNo
= WMRetainPropList(WMCreatePLString("No"));
148 dHost
= WMRetainPropList(WMCreatePLString("Host"));
150 dPosition
= WMCreatePLString("Position");
151 dApplications
= WMCreatePLString("Applications");
152 dLowered
= WMCreatePLString("Lowered");
153 dCollapsed
= WMCreatePLString("Collapsed");
154 dAutoCollapse
= WMCreatePLString("AutoCollapse");
155 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
156 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
158 dOmnipresent
= WMCreatePLString("Omnipresent");
160 dDock
= WMCreatePLString("Dock");
161 dClip
= WMCreatePLString("Clip");
162 dDrawers
= WMCreatePLString("Drawers");
165 static void renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
167 WDock
*dock
= entry
->clientdata
;
172 assert(entry
->clientdata
!= NULL
);
174 wspace
= w_global
.workspace
.current
;
176 name
= wstrdup(w_global
.workspace
.array
[wspace
]->name
);
178 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+ 1);
179 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
, &name
))
180 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
185 static void toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
187 assert(entry
->clientdata
!= NULL
);
189 toggleLowered(entry
->clientdata
);
191 entry
->flags
.indicator_on
= !(((WDock
*) entry
->clientdata
)->lowered
);
196 static int matchWindow(const void *item
, const void *cdata
)
198 return (((WFakeGroupLeader
*) item
)->leader
== (Window
) cdata
);
201 static void killCallback(WMenu
*menu
, WMenuEntry
*entry
)
203 WScreen
*scr
= menu
->menu
->screen_ptr
;
205 WFakeGroupLeader
*fPtr
;
206 char *buffer
, *shortname
, **argv
;
209 if (!WCHECK_STATE(WSTATE_NORMAL
))
212 assert(entry
->clientdata
!= NULL
);
214 icon
= (WAppIcon
*) entry
->clientdata
;
218 WCHANGE_STATE(WSTATE_MODAL
);
220 /* strip away dir names */
221 shortname
= basename(icon
->command
);
222 /* separate out command options */
223 wtokensplit(shortname
, &argv
, &argc
);
225 buffer
= wstrconcat(argv
[0],
226 _(" will be forcibly closed.\n"
227 "Any unsaved changes will be lost.\n" "Please confirm."));
229 if (icon
->icon
&& icon
->icon
->owner
) {
230 fPtr
= icon
->icon
->owner
->fake_group
;
232 /* is this really necessary? can we kill a non-running dock icon? */
233 Window win
= icon
->main_window
;
236 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)win
);
237 if (index
!= WANotFound
)
238 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
243 if (wPreferences
.dont_confirm_kill
244 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
245 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
247 WWindow
*wwin
, *twin
;
249 wwin
= scr
->focused_window
;
252 if (wwin
->fake_group
== fPtr
)
257 } else if (icon
->icon
&& icon
->icon
->owner
) {
258 wClientKill(icon
->icon
->owner
);
263 wtokenfree(argv
, argc
);
267 WCHANGE_STATE(WSTATE_NORMAL
);
270 /* TODO: replace this function with a member of the dock struct */
271 static int numberOfSelectedIcons(WDock
*dock
)
277 for (i
= 1; i
< dock
->max_icons
; i
++) {
278 aicon
= dock
->icon_array
[i
];
279 if (aicon
&& aicon
->icon
->selected
)
286 static WMArray
*getSelected(WDock
*dock
)
288 WMArray
*ret
= WMCreateArray(8);
292 for (i
= 1; i
< dock
->max_icons
; i
++) {
293 btn
= dock
->icon_array
[i
];
294 if (btn
&& btn
->icon
->selected
)
295 WMAddToArray(ret
, btn
);
301 static void paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
303 Window win
= clipIcon
->icon
->core
->window
;
304 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
306 int pt
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
307 int tp
= ICON_SIZE
- pt
;
308 int as
= pt
- 15; /* 15 = 5+5+5 */
309 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
312 color
= scr
->clip_title_color
[CLIP_NORMAL
];
314 XSetForeground(dpy
, gc
, WMColorPixel(color
));
319 p
[1].x
= ICON_SIZE
- 2;
321 p
[2].x
= ICON_SIZE
- 2;
323 } else if (lpushed
) {
327 p
[1].y
= ICON_SIZE
- 2;
329 p
[2].y
= ICON_SIZE
- 2;
331 if (lpushed
|| rpushed
) {
332 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
333 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
334 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
337 /* top right arrow */
338 p
[0].x
= p
[3].x
= ICON_SIZE
- 5 - as
;
340 p
[1].x
= ICON_SIZE
- 6;
342 p
[2].x
= ICON_SIZE
- 6;
345 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
346 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
348 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
349 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
352 /* bottom left arrow */
354 p
[0].y
= p
[3].y
= ICON_SIZE
- 5 - as
;
356 p
[1].y
= ICON_SIZE
- 6;
358 p
[2].y
= ICON_SIZE
- 6;
360 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
361 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
363 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
364 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
368 RImage
*wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
370 RImage
*tile
= RCloneImage(normalTile
);
377 pt
= CLIP_BUTTON_SIZE
* wPreferences
.icon_size
/ 64;
378 tp
= wPreferences
.icon_size
- 1 - pt
;
382 black
.red
= black
.green
= black
.blue
= 0;
385 dark
.red
= dark
.green
= dark
.blue
= 60;
388 light
.red
= light
.green
= light
.blue
= 80;
391 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
- 2, pt
- 1, &dark
);
392 RDrawLine(tile
, tp
- 1, 0, wPreferences
.icon_size
- 1, pt
+ 1, &black
);
393 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
- 3, pt
, &light
);
396 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, 4, &dark
);
397 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 5, 6 + as
, &dark
);
398 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
, &light
);
401 ROperateLine(tile
, RAddOperation
, 2, tp
+ 2, pt
- 2, wPreferences
.icon_size
- 3, &dark
);
402 RDrawLine(tile
, 0, tp
- 1, pt
+ 1, wPreferences
.icon_size
- 1, &black
);
403 ROperateLine(tile
, RSubtractOperation
, 0, tp
- 2, pt
+ 1, wPreferences
.icon_size
- 2, &light
);
406 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, &dark
);
407 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
, 6 + as
, ICON_SIZE
- 5, &dark
);
408 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5, &light
);
413 static void omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
415 WAppIcon
*clickedIcon
= entry
->clientdata
;
418 WMArray
*selectedIcons
;
419 WMArrayIterator iter
;
422 assert(entry
->clientdata
!= NULL
);
424 dock
= clickedIcon
->dock
;
426 selectedIcons
= getSelected(dock
);
428 if (!WMGetArrayItemCount(selectedIcons
))
429 WMAddToArray(selectedIcons
, clickedIcon
);
432 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
433 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
435 else if (aicon
->icon
->selected
)
436 wIconSelect(aicon
->icon
);
438 WMFreeArray(selectedIcons
);
441 wMessageDialog(dock
->screen_ptr
, _("Warning"),
442 _("Some icons cannot be made omnipresent. "
443 "Please make sure that no other icon is "
444 "docked in the same positions on the other "
445 "workspaces and the Clip is not full in "
446 "some workspace."), _("OK"), NULL
, NULL
);
447 } else if (failed
== 1) {
448 wMessageDialog(dock
->screen_ptr
, _("Warning"),
449 _("Icon cannot be made omnipresent. "
450 "Please make sure that no other icon is "
451 "docked in the same position on the other "
452 "workspaces and the Clip is not full in "
453 "some workspace."), _("OK"), NULL
, NULL
);
457 static void removeIcons(WMArray
*icons
, WDock
*dock
)
463 WM_ITERATE_ARRAY(icons
, aicon
, it
) {
464 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
465 wDockDetach(dock
, aicon
);
467 /* XXX: can: aicon->icon == NULL ? */
468 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
469 wGetHeadForWindow(aicon
->icon
->owner
));
470 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
471 if (!dock
->mapped
|| dock
->collapsed
)
472 XMapWindow(dpy
, aicon
->icon
->core
->window
);
477 if (wPreferences
.auto_arrange_icons
)
478 wArrangeIcons(dock
->screen_ptr
, True
);
481 static void removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
483 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
485 WMArray
*selectedIcons
;
487 assert(clickedIcon
!= NULL
);
489 dock
= clickedIcon
->dock
;
491 selectedIcons
= getSelected(dock
);
493 if (WMGetArrayItemCount(selectedIcons
)) {
494 if (wMessageDialog(dock
->screen_ptr
,
495 dock
->type
== WM_CLIP
? _("Workspace Clip") : _("Drawer"),
496 _("All selected icons will be removed!"),
497 _("OK"), _("Cancel"), NULL
) != WAPRDefault
) {
498 WMFreeArray(selectedIcons
);
502 if (clickedIcon
->xindex
== 0 && clickedIcon
->yindex
== 0) {
503 WMFreeArray(selectedIcons
);
506 WMAddToArray(selectedIcons
, clickedIcon
);
509 removeIcons(selectedIcons
, dock
);
511 if (dock
->type
== WM_DRAWER
) {
512 drawerConsolidateIcons(dock
);
516 static void keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
518 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
521 WMArray
*selectedIcons
;
524 assert(clickedIcon
!= NULL
);
525 dock
= clickedIcon
->dock
;
527 selectedIcons
= getSelected(dock
);
529 if (!WMGetArrayItemCount(selectedIcons
)
530 && clickedIcon
!= w_global
.clip
.icon
) {
531 char *command
= NULL
;
533 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
534 clickedIcon
->editing
= 1;
535 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
536 _("Type the command used to launch the application"), &command
)) {
537 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
541 clickedIcon
->command
= command
;
542 clickedIcon
->editing
= 0;
544 clickedIcon
->editing
= 0;
547 WMFreeArray(selectedIcons
);
552 WMAddToArray(selectedIcons
, clickedIcon
);
555 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
556 if (aicon
->icon
->selected
)
557 wIconSelect(aicon
->icon
);
559 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
560 aicon
->attracted
= 0;
561 if (aicon
->icon
->shadowed
) {
562 aicon
->icon
->shadowed
= 0;
565 * Update icon pixmap, RImage doesn't change,
566 * so call wIconUpdate is not needed
568 update_icon_pixmap(aicon
->icon
);
571 wAppIconPaint(aicon
);
574 save_appicon(aicon
, True
);
576 WMFreeArray(selectedIcons
);
579 static void toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
581 WDock
*dock
= (WDock
*) entry
->clientdata
;
582 WScreen
*scr
= dock
->screen_ptr
;
584 assert(entry
->clientdata
!= NULL
);
586 /* Setting a clip as autoattracting will disable an autoattracting drawer,
587 * and reciprocally. Ask for confirmation? */
588 #ifdef CONFIRM_AUTOATTRACT_CHANGE
589 if (dock
->type
== WM_CLIP
&& scr
->attracting_drawer
) {
590 if (wMessageDialog(scr
, _("Workspace Clip"),
591 _("The drawer that auto-attracted icons so far won't do so anymore!"),
592 _("OK"), _("Cancel"), NULL
) != WAPRDefault
)
594 } else if (dock
->type
== WM_DRAWER
) {
595 /* check if at least one clip already auto attracts icons */
596 int i
, ask_for_confirmation
= False
;
597 for (i
= 0; i
< w_global
.workspace
.count
; i
++) {
598 if (w_global
.workspace
.array
[i
]->clip
->attract_icons
) {
599 ask_for_confirmation
= True
;
603 if (ask_for_confirmation
) {
604 if (wMessageDialog(scr
, _("Drawer"),
605 _("Any clips that auto-attracted icons so far won't do so anymore!"),
606 _("OK"), _("Cancel"), NULL
) != WAPRDefault
)
612 dock
->attract_icons
= !dock
->attract_icons
;
614 entry
->flags
.indicator_on
= dock
->attract_icons
;
618 if (dock
->attract_icons
) {
619 if (dock
->type
== WM_DRAWER
) {
620 /* The newly auto-attracting dock is a drawer: disable any clip and
621 * previously attracting drawer */
623 if (!wPreferences
.flags
.noclip
) {
625 for (i
= 0; i
< w_global
.workspace
.count
; i
++)
626 w_global
.workspace
.array
[i
]->clip
->attract_icons
= False
;
627 /* dock menu will be updated later, when opened */
630 if (scr
->attracting_drawer
!= NULL
)
631 scr
->attracting_drawer
->attract_icons
= False
;
632 scr
->attracting_drawer
= dock
;
634 /* The newly auto-attracting dock is a clip: disable
635 * previously attracting drawer, if applicable */
636 if (scr
->attracting_drawer
!= NULL
) {
637 scr
->attracting_drawer
->attract_icons
= False
;
638 /* again, its menu will be updated, later. */
639 scr
->attracting_drawer
= NULL
;
645 static void selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
647 WAppIcon
*icon
= (WAppIcon
*) entry
->clientdata
;
649 assert(icon
!= NULL
);
651 wIconSelect(icon
->icon
);
656 static void colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
658 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
659 WDock
*clip
; /* clip... is a WM_CLIP or a WM_DRAWER */
661 int x
, y
, x_pos
, y_pos
;
662 Bool update_icon
= False
;
664 assert(entry
->clientdata
!= NULL
);
665 clip
= clickedIcon
->dock
;
667 aicon
= w_global
.app_icon_list
;
670 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
671 x_pos
= clip
->x_pos
+ x
* ICON_SIZE
;
672 y_pos
= clip
->y_pos
+ y
* ICON_SIZE
;
673 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
)
674 move_window(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
676 aicon
->attracted
= 1;
677 if (!aicon
->icon
->shadowed
) {
678 aicon
->icon
->shadowed
= 1;
681 wDockAttachIcon(clip
, aicon
, x
, y
, update_icon
);
682 if (clip
->collapsed
|| !clip
->mapped
)
683 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
689 static void selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
691 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
693 WMArray
*selectedIcons
;
694 WMArrayIterator iter
;
698 assert(clickedIcon
!= NULL
);
699 dock
= clickedIcon
->dock
;
701 selectedIcons
= getSelected(dock
);
703 if (!WMGetArrayItemCount(selectedIcons
)) {
704 for (i
= 1; i
< dock
->max_icons
; i
++) {
705 btn
= dock
->icon_array
[i
];
706 if (btn
&& !btn
->icon
->selected
)
707 wIconSelect(btn
->icon
);
710 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
711 wIconSelect(btn
->icon
);
714 WMFreeArray(selectedIcons
);
719 static void toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
721 assert(entry
->clientdata
!= NULL
);
723 toggleCollapsed(entry
->clientdata
);
725 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->collapsed
;
730 static void toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
733 assert(entry
->clientdata
!= NULL
);
735 dock
= (WDock
*) entry
->clientdata
;
737 dock
->auto_collapse
= !dock
->auto_collapse
;
739 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_collapse
;
744 static void toggleAutoRaiseLower(WDock
*dock
)
748 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
749 if (dock
->type
== WM_DOCK
)
751 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
752 toggleAutoRaiseLower(dc
->adrawer
);
757 static void toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
760 assert(entry
->clientdata
!= NULL
);
762 dock
= (WDock
*) entry
->clientdata
;
764 toggleAutoRaiseLower(dock
);
766 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_raise_lower
;
771 static void launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
773 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
775 launchDockedApplication(btn
, False
);
778 static void settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
780 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
784 ShowDockAppSettingsPanel(btn
);
787 static void hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
790 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
792 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
794 if (wapp
->flags
.hidden
) {
795 wWorkspaceChange(btn
->icon
->core
->screen_ptr
, wapp
->last_workspace
);
796 wUnhideApplication(wapp
, False
, False
);
798 wHideApplication(wapp
);
802 static void unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
805 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
807 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
809 wUnhideApplication(wapp
, False
, True
);
812 /* Name is only used when type == WM_DRAWER and when restoring a specific
813 * drawer, with a specific name. When creating a drawer, leave name to NULL
814 * and mainIconCreate will find the first unused unique name */
815 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
, const char *name
)
822 if (w_global
.clip
.icon
)
823 return w_global
.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 w_global
.clip
.icon
= btn
;
863 static void switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
865 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
867 WMArray
*selectedIcons
;
870 if (entry
->order
== w_global
.workspace
.current
)
873 dest
= w_global
.workspace
.array
[entry
->order
]->clip
;
875 selectedIcons
= getSelected(src
);
877 if (WMGetArrayItemCount(selectedIcons
)) {
878 WMArrayIterator iter
;
880 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
881 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
882 wDockMoveIconBetweenDocks(src
, dest
, btn
, x
, y
);
883 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
886 } else if (icon
!= w_global
.clip
.icon
) {
887 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
888 wDockMoveIconBetweenDocks(src
, dest
, icon
, x
, y
);
889 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
892 WMFreeArray(selectedIcons
);
895 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
)
897 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
899 if (!btn
->launching
&&
900 ((!withSelection
&& btn
->command
!= NULL
) || (withSelection
&& btn
->paste_command
!= NULL
))) {
901 if (!btn
->forced_dock
) {
902 btn
->relaunching
= btn
->running
;
905 if (btn
->wm_instance
|| btn
->wm_class
) {
906 WWindowAttributes attr
;
907 memset(&attr
, 0, sizeof(WWindowAttributes
));
908 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
910 if (!attr
.no_appicon
&& !btn
->buggy_app
)
915 btn
->drop_launch
= 0;
916 btn
->paste_launch
= withSelection
;
917 scr
->last_dock
= btn
->dock
;
918 btn
->pid
= execCommand(btn
, (withSelection
? btn
->paste_command
: btn
->command
), NULL
);
920 if (btn
->buggy_app
) {
921 /* give feedback that the app was launched */
925 WMAddTimerHandler(200, (WMCallback
*) dockIconPaint
, btn
);
930 wwarning(_("could not launch application %s"), btn
->command
);
932 if (!btn
->relaunching
)
938 static void updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
940 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
946 for (i
= 0; i
< w_global
.workspace
.count
; i
++) {
947 if (i
< menu
->entry_no
) {
948 if (strcmp(menu
->entries
[i
]->text
, w_global
.workspace
.array
[i
]->name
) != 0) {
949 wfree(menu
->entries
[i
]->text
);
950 strcpy(title
, w_global
.workspace
.array
[i
]->name
);
951 menu
->entries
[i
]->text
= wstrdup(title
);
952 menu
->flags
.realized
= 0;
954 menu
->entries
[i
]->clientdata
= (void *)icon
;
956 strcpy(title
, w_global
.workspace
.array
[i
]->name
);
958 wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)icon
);
960 menu
->flags
.realized
= 0;
963 if (i
== w_global
.workspace
.current
)
964 wMenuSetEnabled(menu
, i
, False
);
966 wMenuSetEnabled(menu
, i
, True
);
969 if (!menu
->flags
.realized
)
973 static WMenu
*makeWorkspaceMenu(WScreen
*scr
)
977 menu
= wMenuCreate(scr
, NULL
, False
);
979 wwarning(_("could not create workspace submenu for Clip menu"));
981 wMenuAddCallback(menu
, "", switchWSCommand
, (void *)w_global
.clip
.icon
);
983 menu
->flags
.realized
= 0;
989 static void updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
998 entry
= menu
->entries
[index
];
999 entry
->flags
.indicator_on
= !dock
->lowered
;
1000 entry
->clientdata
= dock
;
1001 wMenuSetEnabled(menu
, index
, dock
->type
== WM_CLIP
);
1004 entry
= menu
->entries
[++index
];
1005 entry
->flags
.indicator_on
= dock
->collapsed
;
1006 entry
->clientdata
= dock
;
1009 entry
= menu
->entries
[++index
];
1010 entry
->flags
.indicator_on
= dock
->auto_collapse
;
1011 entry
->clientdata
= dock
;
1013 /* auto-raise/lower */
1014 entry
= menu
->entries
[++index
];
1015 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1016 entry
->clientdata
= dock
;
1017 wMenuSetEnabled(menu
, index
, dock
->lowered
&& (dock
->type
== WM_CLIP
));
1020 entry
= menu
->entries
[++index
];
1021 entry
->flags
.indicator_on
= dock
->attract_icons
;
1022 entry
->clientdata
= dock
;
1024 menu
->flags
.realized
= 0;
1029 static WMenu
*makeClipOptionsMenu(WScreen
*scr
)
1034 menu
= wMenuCreate(scr
, NULL
, False
);
1036 wwarning(_("could not create options submenu for Clip menu"));
1040 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
1041 entry
->flags
.indicator
= 1;
1042 entry
->flags
.indicator_on
= 1;
1043 entry
->flags
.indicator_type
= MI_CHECK
;
1045 entry
= wMenuAddCallback(menu
, _("Collapsed"), toggleCollapsedCallback
, NULL
);
1046 entry
->flags
.indicator
= 1;
1047 entry
->flags
.indicator_on
= 1;
1048 entry
->flags
.indicator_type
= MI_CHECK
;
1050 entry
= wMenuAddCallback(menu
, _("Autocollapse"), toggleAutoCollapseCallback
, NULL
);
1051 entry
->flags
.indicator
= 1;
1052 entry
->flags
.indicator_on
= 1;
1053 entry
->flags
.indicator_type
= MI_CHECK
;
1055 entry
= wMenuAddCallback(menu
, _("Autoraise"), toggleAutoRaiseLowerCallback
, NULL
);
1056 entry
->flags
.indicator
= 1;
1057 entry
->flags
.indicator_on
= 1;
1058 entry
->flags
.indicator_type
= MI_CHECK
;
1060 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"), toggleAutoAttractCallback
, NULL
);
1061 entry
->flags
.indicator
= 1;
1062 entry
->flags
.indicator_on
= 1;
1063 entry
->flags
.indicator_type
= MI_CHECK
;
1065 menu
->flags
.realized
= 0;
1072 static void setDockPositionNormalCallback(WMenu
*menu
, WMenuEntry
*entry
)
1074 WDock
*dock
= (WDock
*) entry
->clientdata
;
1076 if (entry
->flags
.indicator_on
) // already set, nothing to do
1078 // Do we come from auto raise lower or keep on top?
1079 if (dock
->auto_raise_lower
)
1081 dock
->auto_raise_lower
= 0;
1082 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1083 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1084 dc
->adrawer
->auto_raise_lower
= 0;
1089 // Will take care of setting lowered = 0 in drawers
1090 toggleLowered(dock
);
1092 entry
->flags
.indicator_on
= 1;
1095 static void setDockPositionAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
1097 WDock
*dock
= (WDock
*) entry
->clientdata
;
1099 if (entry
->flags
.indicator_on
) // already set, nothing to do
1101 // Do we come from normal or keep on top?
1104 toggleLowered(dock
);
1106 dock
->auto_raise_lower
= 1;
1107 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1108 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1109 dc
->adrawer
->auto_raise_lower
= 1;
1111 entry
->flags
.indicator_on
= 1;
1114 static void setDockPositionKeepOnTopCallback(WMenu
*menu
, WMenuEntry
*entry
)
1116 WDock
*dock
= (WDock
*) entry
->clientdata
;
1118 if (entry
->flags
.indicator_on
) // already set, nothing to do
1120 dock
->auto_raise_lower
= 0;
1121 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1122 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1123 dc
->adrawer
->auto_raise_lower
= 0;
1125 toggleLowered(dock
);
1126 entry
->flags
.indicator_on
= 1;
1129 static void updateDockPositionMenu(WMenu
*menu
, WDock
*dock
)
1138 entry
= menu
->entries
[index
++];
1139 entry
->flags
.indicator_on
= (dock
->lowered
&& !dock
->auto_raise_lower
);
1140 entry
->clientdata
= dock
;
1142 /* Auto-raise/lower */
1143 entry
= menu
->entries
[index
++];
1144 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1145 entry
->clientdata
= dock
;
1148 entry
= menu
->entries
[index
++];
1149 entry
->flags
.indicator_on
= !dock
->lowered
;
1150 entry
->clientdata
= dock
;
1153 static WMenu
*makeDockPositionMenu(WScreen
*scr
)
1155 /* When calling this, the dock is being created, so scr->dock is still not set
1156 * Therefore the callbacks' clientdata and the indicators can't be set,
1157 * they will be updated when the dock menu is opened. */
1161 menu
= wMenuCreate(scr
, NULL
, False
);
1163 wwarning(_("could not create options submenu for dock position menu"));
1167 entry
= wMenuAddCallback(menu
, _("Normal"), setDockPositionNormalCallback
, NULL
);
1168 entry
->flags
.indicator
= 1;
1169 entry
->flags
.indicator_type
= MI_DIAMOND
;
1171 entry
= wMenuAddCallback(menu
, _("Auto raise & lower"), setDockPositionAutoRaiseLowerCallback
, NULL
);
1172 entry
->flags
.indicator
= 1;
1173 entry
->flags
.indicator_type
= MI_DIAMOND
;
1175 entry
= wMenuAddCallback(menu
, _("Keep on Top"), setDockPositionKeepOnTopCallback
, NULL
);
1176 entry
->flags
.indicator
= 1;
1177 entry
->flags
.indicator_type
= MI_DIAMOND
;
1179 menu
->flags
.realized
= 0;
1186 static WMenu
*dockMenuCreate(WScreen
*scr
, int type
)
1191 if (type
== WM_CLIP
&& w_global
.clip
.menu
)
1192 return w_global
.clip
.menu
;
1194 if (type
== WM_DRAWER
&& w_global
.dock
.drawer_menu
)
1195 return w_global
.dock
.drawer_menu
;
1197 menu
= wMenuCreate(scr
, NULL
, False
);
1198 if (type
== WM_DOCK
) {
1199 entry
= wMenuAddCallback(menu
, _("Dock position"), NULL
, NULL
);
1200 if (w_global
.dock
.pos_menu
== NULL
)
1201 w_global
.dock
.pos_menu
= makeDockPositionMenu(scr
);
1202 wMenuEntrySetCascade(menu
, entry
, w_global
.dock
.pos_menu
);
1204 if (!wPreferences
.flags
.nodrawer
) {
1205 entry
= wMenuAddCallback(menu
, _("Add a drawer"), addADrawerCallback
, NULL
);
1208 if (type
== WM_CLIP
)
1209 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1210 else /* if (type == WM_DRAWER) */
1211 entry
= wMenuAddCallback(menu
, _("Drawer options"), NULL
, NULL
);
1213 if (w_global
.clip
.opt_menu
== NULL
)
1214 w_global
.clip
.opt_menu
= makeClipOptionsMenu(scr
);
1216 wMenuEntrySetCascade(menu
, entry
, w_global
.clip
.opt_menu
);
1218 /* The same menu is used for the dock and its appicons. If the menu
1219 * entry text is different between the two contexts, or if it can
1220 * change depending on some state, free the duplicated string (from
1221 * wMenuInsertCallback) and use gettext's string */
1222 if (type
== WM_CLIP
) {
1223 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1225 entry
->text
= _("Rename Workspace"); /* can be: (Toggle) Omnipresent */
1228 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1229 entry
->flags
.indicator
= 1;
1230 entry
->flags
.indicator_on
= 1;
1231 entry
->flags
.indicator_type
= MI_CHECK
;
1233 entry
= wMenuAddCallback(menu
, _("Select All Icons"), selectIconsCallback
, NULL
);
1235 entry
->text
= _("Select All Icons"); /* can be: Unselect all icons */
1237 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1239 entry
->text
= _("Keep Icon"); /* can be: Keep Icons */
1241 if (type
== WM_CLIP
) {
1242 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1244 entry
->text
= _("Move Icon To"); /* can be: Move Icons to */
1245 w_global
.clip
.submenu
= makeWorkspaceMenu(scr
);
1246 if (w_global
.clip
.submenu
)
1247 wMenuEntrySetCascade(menu
, entry
, w_global
.clip
.submenu
);
1250 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
, NULL
);
1252 entry
->text
= _("Remove Icon"); /* can be: Remove Icons */
1254 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1257 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1259 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1261 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1263 entry
->text
= _("Hide"); /* can be: Unhide */
1265 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1267 entry
= wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1269 entry
->text
= _("Kill"); /* can be: Remove drawer */
1271 if (type
== WM_CLIP
)
1272 w_global
.clip
.menu
= menu
;
1274 if (type
== WM_DRAWER
)
1275 w_global
.dock
.drawer_menu
= menu
;
1280 WDock
*wDockCreate(WScreen
*scr
, int type
, const char *name
)
1287 dock
= wmalloc(sizeof(WDock
));
1291 dock
->max_icons
= DOCK_MAX_ICONS
;
1294 dock
->max_icons
= scr
->scr_width
/ wPreferences
.icon_size
;
1298 dock
->max_icons
= scr
->scr_height
/ wPreferences
.icon_size
;
1301 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * dock
->max_icons
);
1303 btn
= mainIconCreate(scr
, type
, name
);
1307 dock
->x_pos
= btn
->x_pos
;
1308 dock
->y_pos
= btn
->y_pos
;
1309 dock
->screen_ptr
= scr
;
1311 dock
->icon_count
= 1;
1312 if (type
== WM_DRAWER
)
1313 dock
->on_right_side
= scr
->dock
->on_right_side
;
1315 dock
->on_right_side
= 1;
1316 dock
->collapsed
= 0;
1317 dock
->auto_collapse
= 0;
1318 dock
->auto_collapse_magic
= NULL
;
1319 dock
->auto_raise_lower
= 0;
1320 dock
->auto_lower_magic
= NULL
;
1321 dock
->auto_raise_magic
= NULL
;
1322 dock
->attract_icons
= 0;
1324 dock
->icon_array
[0] = btn
;
1325 wRaiseFrame(btn
->icon
->core
);
1326 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1328 /* create dock menu */
1329 dock
->menu
= dockMenuCreate(scr
, type
);
1331 if (type
== WM_DRAWER
) {
1332 drawerAppendToChain(scr
, dock
);
1333 dock
->auto_collapse
= 1;
1339 void wDockDestroy(WDock
*dock
)
1344 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1345 aicon
= dock
->icon_array
[i
];
1347 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1348 wDockDetach(dock
, aicon
);
1350 /* XXX: can: aicon->icon == NULL ? */
1351 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1352 wGetHeadForWindow(aicon
->icon
->owner
));
1353 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1354 if (!dock
->mapped
|| dock
->collapsed
)
1355 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1359 if (wPreferences
.auto_arrange_icons
)
1360 wArrangeIcons(dock
->screen_ptr
, True
);
1361 wfree(dock
->icon_array
);
1362 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1363 wMenuDestroy(dock
->menu
, True
);
1364 if (dock
->screen_ptr
->last_dock
== dock
)
1365 dock
->screen_ptr
->last_dock
= NULL
;
1369 void wClipIconPaint(void)
1371 WAppIcon
*aicon
= w_global
.clip
.icon
;
1372 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1373 WWorkspace
*workspace
= w_global
.workspace
.array
[w_global
.workspace
.current
];
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", w_global
.workspace
.current
+ 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
)
1418 static void dockIconPaint(WAppIcon
*btn
)
1420 if (btn
== w_global
.clip
.icon
) {
1422 } else if (wIsADrawer(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
== w_global
.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(w_global
.session_state
, dDock
, dock_state
);
1582 WMReleasePropList(dock_state
);
1585 void wClipSaveState(WScreen
*scr
)
1587 WMPropList
*clip_state
;
1589 clip_state
= make_icon_state(w_global
.clip
.icon
);
1591 WMPutInPLDictionary(w_global
.session_state
, dClip
, clip_state
);
1592 WMReleasePropList(clip_state
);
1595 WMPropList
*wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1597 return dockSaveState(w_global
.workspace
.array
[workspace
]->clip
);
1600 static Bool
getBooleanDockValue(WMPropList
*value
, WMPropList
*key
)
1603 if (WMIsPLString(value
)) {
1604 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1607 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1613 static WAppIcon
*restore_icon_state(WScreen
*scr
, WMPropList
*info
, int type
, int index
)
1616 WMPropList
*cmd
, *value
;
1617 char *wclass
, *winstance
, *command
;
1619 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1620 if (!cmd
|| !WMIsPLString(cmd
))
1623 /* parse window name */
1624 value
= WMGetFromPLDictionary(info
, dName
);
1628 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1630 if (!winstance
&& !wclass
)
1635 command
= wstrdup(WMGetFromPLString(cmd
));
1639 if (!command
|| strcmp(command
, "-") == 0) {
1650 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1658 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1659 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1660 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1661 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1662 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1664 #ifdef XDND /* was OFFIX */
1665 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1667 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1670 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1672 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1674 /* check auto launch */
1675 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1677 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1680 value
= WMGetFromPLDictionary(info
, dLock
);
1682 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1684 /* check if it wasn't normally docked */
1685 value
= WMGetFromPLDictionary(info
, dForced
);
1687 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1689 /* check if we can rely on the stuff in the app */
1690 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1692 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1694 /* get position in the dock */
1695 value
= WMGetFromPLDictionary(info
, dPosition
);
1696 if (value
&& WMIsPLString(value
)) {
1697 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1698 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1700 /* check position sanity */
1701 /* *Very* incomplete section! */
1702 if (type
== WM_DOCK
) {
1706 aicon
->yindex
= index
;
1710 /* check if icon is omnipresent */
1711 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1713 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1721 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1723 WAppIcon
*wClipRestoreState(WScreen
*scr
, WMPropList
*clip_state
)
1728 icon
= mainIconCreate(scr
, WM_CLIP
, NULL
);
1733 WMRetainPropList(clip_state
);
1735 /* restore position */
1737 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1740 if (!WMIsPLString(value
)) {
1741 COMPLAIN("Position");
1743 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1744 COMPLAIN("Position");
1746 /* check position sanity */
1747 if (!onScreen(scr
, icon
->x_pos
, icon
->y_pos
))
1748 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1751 #ifdef XDND /* was OFFIX */
1752 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1753 if (value
&& WMIsPLString(value
))
1754 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1757 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1758 if (value
&& WMIsPLString(value
))
1759 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1761 WMReleasePropList(clip_state
);
1766 WDock
*wDockRestoreState(WScreen
*scr
, WMPropList
*dock_state
, int type
)
1771 WAppIcon
*aicon
, *old_top
;
1774 dock
= wDockCreate(scr
, type
, NULL
);
1779 WMRetainPropList(dock_state
);
1781 /* restore position */
1782 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1784 if (!WMIsPLString(value
)) {
1785 COMPLAIN("Position");
1787 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1788 COMPLAIN("Position");
1790 /* check position sanity */
1791 if (!onScreen(scr
, dock
->x_pos
, dock
->y_pos
)) {
1792 int x
= dock
->x_pos
;
1793 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1796 /* Is this needed any more? */
1797 if (type
== WM_CLIP
) {
1798 if (dock
->x_pos
< 0) {
1800 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1801 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1804 if (dock
->x_pos
>= 0) {
1805 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1806 dock
->on_right_side
= 0;
1808 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1809 dock
->on_right_side
= 1;
1815 /* restore lowered/raised state */
1818 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1820 if (!WMIsPLString(value
)) {
1821 COMPLAIN("Lowered");
1823 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1828 /* restore collapsed state */
1829 dock
->collapsed
= 0;
1831 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1833 if (!WMIsPLString(value
)) {
1834 COMPLAIN("Collapsed");
1836 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1837 dock
->collapsed
= 1;
1841 /* restore auto-collapsed state */
1842 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1844 if (!WMIsPLString(value
)) {
1845 COMPLAIN("AutoCollapse");
1847 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1848 dock
->auto_collapse
= 1;
1849 dock
->collapsed
= 1;
1854 /* restore auto-raise/lower state */
1855 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1857 if (!WMIsPLString(value
)) {
1858 COMPLAIN("AutoRaiseLower");
1860 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1861 dock
->auto_raise_lower
= 1;
1865 /* restore attract icons state */
1866 dock
->attract_icons
= 0;
1868 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1870 if (!WMIsPLString(value
)) {
1871 COMPLAIN("AutoAttractIcons");
1873 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1874 dock
->attract_icons
= 1;
1878 /* application list */
1885 * When saving, it saves the dock state in
1886 * Applications and Applicationsnnn
1888 * When loading, it will first try Applicationsnnn.
1889 * If it does not exist, use Applications as default.
1892 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1894 tmp
= WMCreatePLString(buffer
);
1895 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1896 WMReleasePropList(tmp
);
1899 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1905 count
= WMGetPropListItemCount(apps
);
1909 old_top
= dock
->icon_array
[0];
1911 /* dock->icon_count is set to 1 when dock is created.
1912 * Since Clip is already restored, we want to keep it so for clip,
1913 * but for dock we may change the default top tile, so we set it to 0.
1915 if (type
== WM_DOCK
)
1916 dock
->icon_count
= 0;
1918 for (i
= 0; i
< count
; i
++) {
1919 if (dock
->icon_count
>= dock
->max_icons
) {
1920 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1924 value
= WMGetFromPLArray(apps
, i
);
1925 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1927 dock
->icon_array
[dock
->icon_count
] = aicon
;
1931 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1932 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1935 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1937 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1939 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1940 if (!dock
->collapsed
)
1941 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1943 wRaiseFrame(aicon
->icon
->core
);
1946 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
) {
1951 /* if the first icon is not defined, use the default */
1952 if (dock
->icon_array
[0] == NULL
) {
1953 /* update default icon */
1954 old_top
->x_pos
= dock
->x_pos
;
1955 old_top
->y_pos
= dock
->y_pos
;
1957 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1959 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1961 dock
->icon_array
[0] = old_top
;
1962 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1963 /* we don't need to increment dock->icon_count here because it was
1964 * incremented in the loop above.
1966 } else if (old_top
!= dock
->icon_array
[0]) {
1967 if (old_top
== w_global
.clip
.icon
) /* TODO dande: understand the logic */
1968 w_global
.clip
.icon
= dock
->icon_array
[0];
1970 wAppIconDestroy(old_top
);
1974 WMReleasePropList(dock_state
);
1979 void wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1981 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1982 btn
->drop_launch
= 0;
1983 btn
->paste_launch
= 0;
1985 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1988 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1998 void wDockDoAutoLaunch(WDock
*dock
, int workspace
)
2004 for (i
= 0; i
< dock
->max_icons
; i
++) {
2005 btn
= dock
->icon_array
[i
];
2006 if (!btn
|| !btn
->auto_launch
)
2009 state
= wmalloc(sizeof(WSavedState
));
2010 state
->workspace
= workspace
;
2011 /* TODO: this is klugy and is very difficult to understand
2012 * what's going on. Try to clean up */
2013 wDockLaunchWithState(dock
, btn
, state
);
2017 #ifdef XDND /* was OFFIX */
2018 static WDock
*findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
2024 if ((dock
= scr
->dock
) != NULL
) {
2025 for (i
= 0; i
< dock
->max_icons
; i
++) {
2026 if (dock
->icon_array
[i
]
2027 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
2033 if (*icon_pos
< 0 && (dock
= w_global
.workspace
.array
[w_global
.workspace
.current
]->clip
) != NULL
) {
2034 for (i
= 0; i
< dock
->max_icons
; i
++) {
2035 if (dock
->icon_array
[i
]
2036 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
2047 int wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
2053 dock
= findDock(scr
, event
, &icon_pos
);
2058 * Return True if the drop was on an application icon window.
2059 * In this case, let the ClientMessage handler redirect the
2060 * message to the app.
2062 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
2065 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
2066 scr
->flags
.dnd_data_convertion_status
= 0;
2068 btn
= dock
->icon_array
[icon_pos
];
2070 if (!btn
->forced_dock
) {
2071 btn
->relaunching
= btn
->running
;
2074 if (btn
->wm_instance
|| btn
->wm_class
) {
2075 WWindowAttributes attr
;
2076 memset(&attr
, 0, sizeof(WWindowAttributes
));
2077 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
2079 if (!attr
.no_appicon
)
2085 btn
->paste_launch
= 0;
2086 btn
->drop_launch
= 1;
2087 scr
->last_dock
= dock
;
2088 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
2093 if (!btn
->relaunching
)
2101 Bool
wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
, Bool update_icon
)
2104 Bool lupdate_icon
= False
;
2105 char *command
= NULL
;
2111 lupdate_icon
= True
;
2113 if (icon
->command
== NULL
) {
2114 /* If icon->owner exists, it means the application is running */
2115 if (icon
->icon
->owner
) {
2116 wwin
= icon
->icon
->owner
;
2117 command
= GetCommandForWindow(wwin
->client_win
);
2121 icon
->command
= command
;
2123 /* icon->forced_dock = 1; */
2124 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
2126 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2127 _("Type the command used to launch the application"), &command
)) {
2128 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2132 icon
->command
= command
;
2138 /* If the target is the dock, reject the icon. If
2139 * the target is the clip, make it an attracted icon
2141 if (dock
->type
== WM_CLIP
) {
2142 icon
->attracted
= 1;
2143 if (!icon
->icon
->shadowed
) {
2144 icon
->icon
->shadowed
= 1;
2145 lupdate_icon
= True
;
2155 for (index
= 1; index
< dock
->max_icons
; index
++)
2156 if (dock
->icon_array
[index
] == NULL
)
2158 /* if (index == dock->max_icons)
2161 assert(index
< dock
->max_icons
);
2163 dock
->icon_array
[index
] = icon
;
2167 icon
->omnipresent
= 0;
2169 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2170 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2175 icon
->launching
= 0;
2178 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2179 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2180 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2181 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2182 icon
->icon
->core
->descriptor
.parent
= icon
;
2184 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2185 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2188 * Update icon pixmap, RImage doesn't change,
2189 * so call wIconUpdate is not needed
2192 update_icon_pixmap(icon
->icon
);
2195 wAppIconPaint(icon
);
2198 save_appicon(icon
, True
);
2200 if (wPreferences
.auto_arrange_icons
)
2201 wArrangeIcons(dock
->screen_ptr
, True
);
2203 #ifdef XDND /* was OFFIX */
2204 if (icon
->command
&& !icon
->dnd_command
) {
2205 int len
= strlen(icon
->command
) + 8;
2206 icon
->dnd_command
= wmalloc(len
);
2207 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
2211 if (icon
->command
&& !icon
->paste_command
) {
2212 int len
= strlen(icon
->command
) + 8;
2213 icon
->paste_command
= wmalloc(len
);
2214 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
2220 void wDockReattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2224 for (index
= 1; index
< dock
->max_icons
; index
++) {
2225 if (dock
->icon_array
[index
] == icon
)
2228 assert(index
< dock
->max_icons
);
2233 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2234 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2237 Bool
wDockMoveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2240 char *command
= NULL
;
2242 Bool update_icon
= False
;
2245 return True
; /* No move needed, we're already there */
2251 * For the moment we can't do this if we move icons in Clip from one
2252 * workspace to other, because if we move two or more icons without
2253 * command, the dialog box will not be able to tell us to which of the
2254 * moved icons it applies. -Dan
2256 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
2257 /* If icon->owner exists, it means the application is running */
2258 if (icon
->icon
->owner
) {
2259 wwin
= icon
->icon
->owner
;
2260 command
= GetCommandForWindow(wwin
->client_win
);
2264 icon
->command
= command
;
2267 /* icon->forced_dock = 1; */
2268 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2269 _("Type the command used to launch the application"), &command
)) {
2270 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2274 icon
->command
= command
;
2285 if (dest
->type
== WM_DOCK
|| dest
->type
== WM_DRAWER
)
2286 wClipMakeIconOmnipresent(icon
, False
);
2288 for (index
= 1; index
< src
->max_icons
; index
++) {
2289 if (src
->icon_array
[index
] == icon
)
2292 assert(index
< src
->max_icons
);
2294 src
->icon_array
[index
] = NULL
;
2297 for (index
= 1; index
< dest
->max_icons
; index
++) {
2298 if (dest
->icon_array
[index
] == NULL
)
2302 assert(index
< dest
->max_icons
);
2304 dest
->icon_array
[index
] = icon
;
2307 /* deselect the icon */
2308 if (icon
->icon
->selected
)
2309 wIconSelect(icon
->icon
);
2311 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2312 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2314 /* set it to be kept when moving to dock.
2315 * Unless the icon does not have a command set
2317 if (icon
->command
&& (dest
->type
== WM_DOCK
|| dest
->type
== WM_DRAWER
)) {
2318 icon
->attracted
= 0;
2319 if (icon
->icon
->shadowed
) {
2320 icon
->icon
->shadowed
= 0;
2323 save_appicon(icon
, True
);
2326 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2332 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2333 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2337 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2340 * Update icon pixmap, RImage doesn't change,
2341 * so call wIconUpdate is not needed
2344 update_icon_pixmap(icon
->icon
);
2347 wAppIconPaint(icon
);
2352 void wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2355 Bool update_icon
= False
;
2357 /* make the settings panel be closed */
2359 DestroyDockAppSettingsPanel(icon
->panel
);
2361 /* This must be called before icon->dock is set to NULL.
2362 * Don't move it. -Dan
2364 wClipMakeIconOmnipresent(icon
, False
);
2368 icon
->attracted
= 0;
2369 icon
->auto_launch
= 0;
2370 if (icon
->icon
->shadowed
) {
2371 icon
->icon
->shadowed
= 0;
2375 /* deselect the icon */
2376 if (icon
->icon
->selected
)
2377 wIconSelect(icon
->icon
);
2379 if (icon
->command
) {
2380 wfree(icon
->command
);
2381 icon
->command
= NULL
;
2383 #ifdef XDND /* was OFFIX */
2384 if (icon
->dnd_command
) {
2385 wfree(icon
->dnd_command
);
2386 icon
->dnd_command
= NULL
;
2389 if (icon
->paste_command
) {
2390 wfree(icon
->paste_command
);
2391 icon
->paste_command
= NULL
;
2394 for (index
= 1; index
< dock
->max_icons
; index
++)
2395 if (dock
->icon_array
[index
] == icon
)
2398 assert(index
< dock
->max_icons
);
2399 dock
->icon_array
[index
] = NULL
;
2405 /* if the dock is not attached to an application or
2406 * the application did not set the appropriate hints yet,
2407 * destroy the icon */
2408 if (!icon
->running
|| !wApplicationOf(icon
->main_window
)) {
2409 wAppIconDestroy(icon
);
2411 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2412 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2413 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2414 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2415 icon
->icon
->core
->descriptor
.parent
= icon
;
2417 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2420 * Update icon pixmap, RImage doesn't change,
2421 * so call wIconUpdate is not needed
2424 update_icon_pixmap(icon
->icon
);
2427 wAppIconPaint(icon
);
2429 if (wPreferences
.auto_arrange_icons
)
2430 wArrangeIcons(dock
->screen_ptr
, True
);
2432 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2437 * returns the closest Dock slot index for the passed
2440 * Returns False if icon can't be docked.
2442 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2445 /* Redocking == true means either icon->dock == dock (normal case)
2446 * or we are called from handleDockMove for a drawer */
2447 Bool
wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2449 WScreen
*scr
= dock
->screen_ptr
;
2452 int i
, offset
= ICON_SIZE
/ 2;
2453 WAppIcon
*aicon
= NULL
;
2454 WAppIcon
*nicon
= NULL
;
2456 if (wPreferences
.flags
.noupdates
)
2462 /* if the dock is full */
2463 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
))
2466 /* exact position */
2468 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2470 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2473 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2475 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2477 /* check if the icon is outside the screen boundaries */
2478 if (!onScreen(scr
, dx
+ ex_x
* ICON_SIZE
, dy
+ ex_y
* ICON_SIZE
))
2481 switch (dock
->type
) {
2483 /* We can return False right away if
2484 * - we do not come from this dock (which is a WM_DOCK),
2485 * - we are not right over it, and
2486 * - we are not the main tile of a drawer.
2487 * In the latter case, we are called from handleDockMove. */
2488 if (icon
->dock
!= dock
&& ex_x
!= 0 &&
2489 !(icon
->dock
&& icon
->dock
->type
== WM_DRAWER
&& icon
== icon
->dock
->icon_array
[0]))
2492 if (!redocking
&& ex_x
!= 0)
2495 if (getDrawer(scr
, ex_y
)) /* Return false so that the drawer gets it. */
2499 for (i
= 0; i
< dock
->max_icons
; i
++) {
2500 nicon
= dock
->icon_array
[i
];
2501 if (nicon
&& nicon
->yindex
== ex_y
) {
2508 int sig
, done
, closest
;
2510 /* Possible cases when redocking:
2512 * icon dragged out of range of any slot -> false
2513 * icon dragged on a drawer -> false (to open the drawer)
2514 * icon dragged to range of free slot
2515 * icon dragged to range of same slot
2516 * icon dragged to range of different icon
2518 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2521 if (aicon
== icon
|| !aicon
) {
2527 /* start looking at the upper slot or lower? */
2528 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2534 /* look for closest free slot */
2535 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2539 closest
= sig
* (i
/ 2) + ex_y
;
2540 /* check if this slot is fully on the screen and not used */
2541 if (onScreen(scr
, dx
, dy
+ closest
* ICON_SIZE
)) {
2542 for (j
= 0; j
< dock
->max_icons
; j
++) {
2543 if (dock
->icon_array
[j
]
2544 && dock
->icon_array
[j
]->yindex
== closest
) {
2545 /* slot is used by someone else */
2546 if (dock
->icon_array
[j
] != icon
)
2551 /* slot is used by a drawer */
2552 done
= done
&& !getDrawer(scr
, closest
);
2559 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2560 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2565 } else { /* !redocking */
2567 /* if slot is free and the icon is close enough, return it */
2568 if (!aicon
&& ex_x
== 0) {
2580 start
= icon
->omnipresent
? 0 : w_global
.workspace
.current
;
2581 stop
= icon
->omnipresent
? w_global
.workspace
.count
: start
+ 1;
2584 for (k
= start
; k
< stop
; k
++) {
2585 WDock
*tmp
= w_global
.workspace
.array
[k
]->clip
;
2588 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2589 nicon
= tmp
->icon_array
[i
];
2590 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2598 for (k
= start
; k
< stop
; k
++) {
2599 WDock
*tmp
= w_global
.workspace
.array
[k
]->clip
;
2602 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2603 nicon
= tmp
->icon_array
[i
];
2604 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2605 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2606 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2615 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2624 WAppIcon
*aicons_to_shift
[ dock
->icon_count
];
2625 int index_of_hole
, j
;
2628 abs(ex_x
) - dock
->icon_count
> DOCK_DETTACH_THRESHOLD
||
2629 (ex_x
< 0 && !dock
->on_right_side
) ||
2630 (ex_x
> 0 && dock
->on_right_side
)) {
2635 ex_x
= (dock
->on_right_side
? -1 : 1);
2637 /* "Reduce" ex_x but keep its sign */
2639 if (abs(ex_x
) > dock
->icon_count
- 1) /* minus 1: do not take icon_array[0] into account */
2640 ex_x
= ex_x
* (dock
->icon_count
- 1) / abs(ex_x
); /* don't use *= ! */
2642 if (abs(ex_x
) > dock
->icon_count
)
2643 ex_x
= ex_x
* dock
->icon_count
/ abs(ex_x
);
2645 index_of_hole
= indexOfHole(dock
, icon
, redocking
);
2647 /* Find the appicons between where icon was (index_of_hole) and where
2648 * it wants to be (ex_x) and slide them. */
2650 for (i
= 1; i
< dock
->max_icons
; i
++) {
2651 if ((aicon
= dock
->icon_array
[ i
]) && aicon
!= icon
&&
2652 ((ex_x
<= aicon
->xindex
&& aicon
->xindex
< index_of_hole
) ||
2653 (index_of_hole
< aicon
->xindex
&& aicon
->xindex
<= ex_x
)))
2654 aicons_to_shift
[ j
++ ] = aicon
;
2656 assert(j
== abs(ex_x
- index_of_hole
));
2658 wSlideAppicons(aicons_to_shift
, j
, (index_of_hole
< ex_x
));
2668 static int onScreen(WScreen
*scr
, int x
, int y
)
2675 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2677 wGetRectPlacementInfo(scr
, rect
, &flags
);
2679 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2683 * returns true if it can find a free slot in the dock,
2684 * in which case it changes x_pos and y_pos accordingly.
2685 * Else returns false.
2687 Bool
wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2689 WScreen
*scr
= dock
->screen_ptr
;
2691 WAppIconChain
*chain
;
2692 unsigned char *slot_map
;
2696 int i
, done
= False
;
2698 int sx
= 0, ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2699 int extra_count
= 0;
2701 if (dock
->type
== WM_DRAWER
) {
2702 if (dock
->icon_count
>= dock
->max_icons
) { /* drawer is full */
2705 *x_pos
= dock
->icon_count
* (dock
->on_right_side
? -1 : 1);
2710 if (dock
->type
== WM_CLIP
&& dock
!= w_global
.workspace
.array
[w_global
.workspace
.current
]->clip
)
2711 extra_count
= scr
->global_icon_count
;
2713 /* if the dock is full */
2714 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
)
2717 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2718 if (scr
->dock
->on_right_side
)
2719 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2721 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2724 if (ex
< dock
->x_pos
)
2726 if (sx
> dock
->x_pos
+ ICON_SIZE
)
2727 sx
= dock
->x_pos
+ ICON_SIZE
;
2734 /* check if clip is in a corner */
2735 if (dock
->type
== WM_CLIP
) {
2736 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2738 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2740 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2742 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2750 /* If the clip is in the corner, use only slots that are in the border
2752 if (corner
!= C_NONE
) {
2756 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2757 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2758 hmap
= wmalloc(hcount
+ 1);
2759 vmap
= wmalloc(vcount
+ 1);
2761 /* mark used positions */
2764 for (i
= 0; i
< dock
->max_icons
; i
++) {
2765 btn
= dock
->icon_array
[i
];
2769 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2770 vmap
[btn
->yindex
] = 1;
2771 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2772 hmap
[btn
->xindex
] = 1;
2774 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2776 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2777 vmap
[btn
->yindex
] = 1;
2778 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2779 hmap
[btn
->xindex
] = 1;
2783 for (i
= 0; i
< dock
->max_icons
; i
++) {
2784 btn
= dock
->icon_array
[i
];
2788 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2789 vmap
[btn
->yindex
] = 1;
2790 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2791 hmap
[-btn
->xindex
] = 1;
2793 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2795 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2796 vmap
[btn
->yindex
] = 1;
2797 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2798 hmap
[-btn
->xindex
] = 1;
2802 for (i
= 0; i
< dock
->max_icons
; i
++) {
2803 btn
= dock
->icon_array
[i
];
2807 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2808 vmap
[-btn
->yindex
] = 1;
2809 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2810 hmap
[btn
->xindex
] = 1;
2812 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2814 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2815 vmap
[-btn
->yindex
] = 1;
2816 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2817 hmap
[btn
->xindex
] = 1;
2822 for (i
= 0; i
< dock
->max_icons
; i
++) {
2823 btn
= dock
->icon_array
[i
];
2827 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2828 vmap
[-btn
->yindex
] = 1;
2829 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2830 hmap
[-btn
->xindex
] = 1;
2832 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2834 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2835 vmap
[-btn
->yindex
] = 1;
2836 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2837 hmap
[-btn
->xindex
] = 1;
2843 /* search a vacant slot */
2844 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2845 if (i
< vcount
&& vmap
[i
] == 0) {
2851 } else if (i
< hcount
&& hmap
[i
] == 0) {
2861 /* If found a slot, translate and return */
2863 if (corner
== C_NW
|| corner
== C_NE
)
2868 if (corner
== C_NE
|| corner
== C_SE
)
2875 /* else, try to find a slot somewhere else */
2878 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2879 * placed outside of screen */
2880 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2882 /* In the worst case (the clip is in the corner of the screen),
2883 * the amount of icons that fit in the clip is smaller.
2884 * Double the map to get a safe value.
2888 r
= (mwidth
- 1) / 2;
2890 slot_map
= wmalloc(mwidth
* mwidth
);
2892 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2894 /* mark used slots in the map. If the slot falls outside the map
2895 * (for example, when all icons are placed in line), ignore them. */
2896 for (i
= 0; i
< dock
->max_icons
; i
++) {
2897 btn
= dock
->icon_array
[i
];
2899 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2902 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
)
2903 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2905 /* Find closest slot from the center that is free by scanning the
2906 * map from the center to outward in circular passes.
2907 * This will not result in a neat layout, but will be optimal
2908 * in the sense that there will not be holes left.
2911 for (i
= 1; i
<= r
&& !done
; i
++) {
2914 /* top and bottom parts of the ring */
2915 for (x
= -i
; x
<= i
&& !done
; x
++) {
2916 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2918 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2919 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2926 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2927 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2934 /* left and right parts of the ring */
2935 for (y
= -i
+ 1; y
<= i
- 1; y
++) {
2936 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2938 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2939 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2946 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2947 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2960 static void moveDock(WDock
*dock
, int new_x
, int new_y
)
2966 if (dock
->type
== WM_DOCK
) {
2967 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
2968 moveDock(dc
->adrawer
, new_x
, dc
->adrawer
->y_pos
- dock
->y_pos
+ new_y
);
2971 dock
->x_pos
= new_x
;
2972 dock
->y_pos
= new_y
;
2973 for (i
= 0; i
< dock
->max_icons
; i
++) {
2974 btn
= dock
->icon_array
[i
];
2976 btn
->x_pos
= new_x
+ btn
->xindex
* ICON_SIZE
;
2977 btn
->y_pos
= new_y
+ btn
->yindex
* ICON_SIZE
;
2978 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2983 static void swapDock(WDock
*dock
)
2985 WScreen
*scr
= dock
->screen_ptr
;
2989 if (dock
->on_right_side
)
2990 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2992 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2994 swapDrawers(scr
, dock
->on_right_side
, x
);
2996 for (i
= 0; i
< dock
->max_icons
; i
++) {
2997 btn
= dock
->icon_array
[i
];
3000 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
3004 wScreenUpdateUsableArea(scr
);
3007 static pid_t
execCommand(WAppIcon
*btn
, const char *command
, WSavedState
*state
)
3009 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
3015 cmdline
= ExpandOptions(scr
, command
);
3017 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
3025 wtokensplit(cmdline
, &argv
, &argc
);
3035 if ((pid
= fork()) == 0) {
3039 SetupEnvironment(scr
);
3045 args
= malloc(sizeof(char *) * (argc
+ 1));
3049 for (i
= 0; i
< argc
; i
++)
3053 execvp(argv
[0], args
);
3056 wtokenfree(argv
, argc
);
3060 state
= wmalloc(sizeof(WSavedState
));
3062 state
->miniaturized
= -1;
3064 if (btn
->dock
== scr
->dock
|| btn
->dock
->type
== WM_DRAWER
|| btn
->omnipresent
)
3065 state
->workspace
= -1;
3067 state
->workspace
= w_global
.workspace
.current
;
3069 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
3070 wAddDeathHandler(pid
, (WDeathHandler
*) trackDeadProcess
, btn
->dock
);
3078 void wDockHideIcons(WDock
*dock
)
3085 for (i
= 1; i
< dock
->max_icons
; i
++) {
3086 if (dock
->icon_array
[i
])
3087 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3091 dockIconPaint(dock
->icon_array
[0]);
3094 void wDockShowIcons(WDock
*dock
)
3102 btn
= dock
->icon_array
[0];
3103 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
3105 /* Deleting any change in stacking level, this function is now only about
3108 if (!dock
->collapsed
) {
3109 for (i
= 1; i
< dock
->max_icons
; i
++) {
3110 if (dock
->icon_array
[i
])
3111 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3119 void wDockLower(WDock
*dock
)
3124 if (dock
->type
== WM_DOCK
) {
3125 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3126 wDockLower(dc
->adrawer
);
3128 for (i
= 0; i
< dock
->max_icons
; i
++) {
3129 if (dock
->icon_array
[i
])
3130 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
3134 void wDockRaise(WDock
*dock
)
3139 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
3140 if (dock
->icon_array
[i
])
3141 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
3143 if (dock
->type
== WM_DOCK
) {
3144 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3145 wDockRaise(dc
->adrawer
);
3149 void wDockRaiseLower(WDock
*dock
)
3151 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
3152 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
3153 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
3159 void wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
3161 icon
->launching
= 0;
3162 icon
->relaunching
= 0;
3163 dockIconPaint(icon
);
3166 WAppIcon
*wDockFindIconForWindow(WDock
*dock
, Window window
)
3171 for (i
= 0; i
< dock
->max_icons
; i
++) {
3172 icon
= dock
->icon_array
[i
];
3173 if (icon
&& icon
->main_window
== window
)
3179 void wDockTrackWindowLaunch(WDock
*dock
, Window window
)
3182 char *wm_class
, *wm_instance
;
3184 Bool firstPass
= True
;
3186 char *command
= NULL
;
3188 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) || (!wm_class
&& !wm_instance
))
3191 command
= GetCommandForWindow(window
);
3193 for (i
= 0; i
< dock
->max_icons
; i
++) {
3194 icon
= dock
->icon_array
[i
];
3198 /* app is already attached to icon */
3199 if (icon
->main_window
== window
) {
3204 if ((icon
->wm_instance
|| icon
->wm_class
)
3205 && (icon
->launching
|| !icon
->running
)) {
3207 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0)
3210 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0)
3213 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0)
3216 if (!icon
->relaunching
) {
3219 /* Possibly an application that was docked with dockit,
3220 * but the user did not update WMState to indicate that
3221 * it was docked by force */
3222 wapp
= wApplicationOf(window
);
3224 icon
->forced_dock
= 1;
3227 if (!icon
->forced_dock
)
3228 icon
->main_window
= window
;
3231 if (!wPreferences
.no_animations
&& !icon
->launching
&&
3232 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
3236 icon
->launching
= 1;
3237 dockIconPaint(icon
);
3239 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
3240 wm_instance
, wm_class
, TILE_NORMAL
);
3241 /* XXX: can: aicon->icon == NULL ? */
3242 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
3243 wAppIconMove(aicon
, x0
, y0
);
3244 /* Should this always be lowered? -Dan */
3246 wLowerFrame(aicon
->icon
->core
);
3247 XMapWindow(dpy
, aicon
->icon
->core
->window
);
3248 aicon
->launching
= 1;
3249 wAppIconPaint(aicon
);
3250 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
3251 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
3252 wAppIconDestroy(aicon
);
3254 wDockFinishLaunch(dock
, icon
);
3259 if (firstPass
&& !found
) {
3273 void wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3275 if (!wPreferences
.flags
.noclip
) {
3276 w_global
.clip
.icon
->dock
= w_global
.workspace
.array
[workspace
]->clip
;
3277 if (w_global
.workspace
.current
!= workspace
) {
3278 WDock
*old_clip
= w_global
.workspace
.array
[w_global
.workspace
.current
]->clip
;
3279 WAppIconChain
*chain
= scr
->global_icons
;
3282 wDockMoveIconBetweenDocks(chain
->aicon
->dock
,
3283 w_global
.workspace
.array
[workspace
]->clip
,
3284 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
3285 if (w_global
.workspace
.array
[workspace
]->clip
->collapsed
)
3286 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3287 chain
= chain
->next
;
3290 wDockHideIcons(old_clip
);
3291 if (old_clip
->auto_raise_lower
) {
3292 if (old_clip
->auto_raise_magic
) {
3293 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3294 old_clip
->auto_raise_magic
= NULL
;
3296 wDockLower(old_clip
);
3298 if (old_clip
->auto_collapse
) {
3299 if (old_clip
->auto_expand_magic
) {
3300 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3301 old_clip
->auto_expand_magic
= NULL
;
3303 old_clip
->collapsed
= 1;
3305 wDockShowIcons(w_global
.workspace
.array
[workspace
]->clip
);
3310 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3315 for (i
= 0; i
< dock
->max_icons
; i
++) {
3316 icon
= dock
->icon_array
[i
];
3320 if (icon
->launching
&& icon
->pid
== pid
) {
3321 if (!icon
->relaunching
) {
3323 icon
->main_window
= None
;
3325 wDockFinishLaunch(dock
, icon
);
3327 if (status
== 111) {
3332 if (icon
->drop_launch
)
3333 cmd
= icon
->dnd_command
;
3336 if (icon
->paste_launch
)
3337 cmd
= icon
->paste_command
;
3339 cmd
= icon
->command
;
3341 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3343 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3350 /* This function is called when the dock switches state between
3351 * "normal" (including auto-raise/lower) and "keep on top". It is
3352 * therefore clearly distinct from wDockLower/Raise, which are called
3353 * each time a not-kept-on-top dock is lowered/raised. */
3354 static void toggleLowered(WDock
*dock
)
3360 if (!dock
->lowered
) {
3361 newlevel
= WMNormalLevel
;
3364 newlevel
= WMDockLevel
;
3368 for (i
= 0; i
< dock
->max_icons
; i
++) {
3369 tmp
= dock
->icon_array
[i
];
3373 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3375 /* When the dock is no longer "on top", explicitly lower it as well.
3376 * It saves some CPU cycles (probably) to do it ourselves here
3377 * rather than calling wDockLower at the end of toggleLowered */
3379 wLowerFrame(tmp
->icon
->core
);
3382 if (dock
->type
== WM_DOCK
) {
3383 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
3384 toggleLowered(dc
->adrawer
);
3386 wScreenUpdateUsableArea(dock
->screen_ptr
);
3390 static void toggleCollapsed(WDock
*dock
)
3392 if (dock
->collapsed
) {
3393 dock
->collapsed
= 0;
3394 wDockShowIcons(dock
);
3396 dock
->collapsed
= 1;
3397 wDockHideIcons(dock
);
3401 static void openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3403 WScreen
*scr
= dock
->screen_ptr
;
3404 WObjDescriptor
*desc
;
3406 WApplication
*wapp
= NULL
;
3410 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3412 if (dock
->type
== WM_DOCK
) {
3413 /* Dock position menu */
3414 updateDockPositionMenu(w_global
.dock
.pos_menu
, dock
);
3415 dock
->menu
->flags
.realized
= 0;
3416 if (!wPreferences
.flags
.nodrawer
) {
3418 entry
= dock
->menu
->entries
[++index
];
3419 entry
->clientdata
= aicon
;
3420 wMenuSetEnabled(dock
->menu
, index
, True
);
3423 /* clip/drawer options */
3424 if (w_global
.clip
.opt_menu
)
3425 updateClipOptionsMenu(w_global
.clip
.opt_menu
, dock
);
3427 n_selected
= numberOfSelectedIcons(dock
);
3429 if (dock
->type
== WM_CLIP
) {
3430 /* Rename Workspace */
3431 entry
= dock
->menu
->entries
[++index
];
3432 if (aicon
== w_global
.clip
.icon
) {
3433 entry
->callback
= renameCallback
;
3434 entry
->clientdata
= dock
;
3435 entry
->flags
.indicator
= 0;
3436 entry
->text
= _("Rename Workspace");
3438 entry
->callback
= omnipresentCallback
;
3439 entry
->clientdata
= aicon
;
3440 if (n_selected
> 0) {
3441 entry
->flags
.indicator
= 0;
3442 entry
->text
= _("Toggle Omnipresent");
3444 entry
->flags
.indicator
= 1;
3445 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3446 entry
->flags
.indicator_type
= MI_CHECK
;
3447 entry
->text
= _("Omnipresent");
3452 /* select/unselect icon */
3453 entry
= dock
->menu
->entries
[++index
];
3454 entry
->clientdata
= aicon
;
3455 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3456 wMenuSetEnabled(dock
->menu
, index
, aicon
!= w_global
.clip
.icon
&& !wIsADrawer(aicon
));
3458 /* select/unselect all icons */
3459 entry
= dock
->menu
->entries
[++index
];
3460 entry
->clientdata
= aicon
;
3462 entry
->text
= _("Unselect All Icons");
3464 entry
->text
= _("Select All Icons");
3466 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3469 entry
= dock
->menu
->entries
[++index
];
3470 entry
->clientdata
= aicon
;
3472 entry
->text
= _("Keep Icons");
3474 entry
->text
= _("Keep Icon");
3476 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3478 if (dock
->type
== WM_CLIP
) {
3479 /* this is the workspace submenu part */
3480 entry
= dock
->menu
->entries
[++index
];
3482 entry
->text
= _("Move Icons To");
3484 entry
->text
= _("Move Icon To");
3486 if (w_global
.clip
.submenu
)
3487 updateWorkspaceMenu(w_global
.clip
.submenu
, aicon
);
3489 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3492 /* remove icon(s) */
3493 entry
= dock
->menu
->entries
[++index
];
3494 entry
->clientdata
= aicon
;
3496 entry
->text
= _("Remove Icons");
3498 entry
->text
= _("Remove Icon");
3500 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3502 /* attract icon(s) */
3503 entry
= dock
->menu
->entries
[++index
];
3504 entry
->clientdata
= aicon
;
3506 dock
->menu
->flags
.realized
= 0;
3507 wMenuRealize(dock
->menu
);
3510 if (aicon
->icon
->owner
)
3511 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3516 entry
= dock
->menu
->entries
[++index
];
3517 entry
->clientdata
= aicon
;
3518 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3521 entry
= dock
->menu
->entries
[++index
];
3522 entry
->clientdata
= aicon
;
3523 if (wapp
&& wapp
->flags
.hidden
)
3524 entry
->text
= _("Unhide Here");
3526 entry
->text
= _("Bring Here");
3528 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3531 entry
= dock
->menu
->entries
[++index
];
3532 entry
->clientdata
= aicon
;
3533 if (wapp
&& wapp
->flags
.hidden
)
3534 entry
->text
= _("Unhide");
3536 entry
->text
= _("Hide");
3538 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3541 entry
= dock
->menu
->entries
[++index
];
3542 entry
->clientdata
= aicon
;
3543 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3545 /* kill or remove drawer */
3546 entry
= dock
->menu
->entries
[++index
];
3547 entry
->clientdata
= aicon
;
3548 if (wIsADrawer(aicon
)) {
3549 entry
->callback
= removeDrawerCallback
;
3550 entry
->text
= _("Remove drawer");
3551 wMenuSetEnabled(dock
->menu
, index
, True
);
3553 entry
->callback
= killCallback
;
3554 entry
->text
= _("Kill");
3555 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3558 if (!dock
->menu
->flags
.realized
)
3559 wMenuRealize(dock
->menu
);
3561 if (dock
->type
== WM_CLIP
|| dock
->type
== WM_DRAWER
) {
3562 /*x_pos = event->xbutton.x_root+2; */
3563 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3566 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3567 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3570 x_pos
= dock
->on_right_side
? scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3573 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3575 /* allow drag select */
3576 event
->xany
.send_event
= True
;
3577 desc
= &dock
->menu
->menu
->descriptor
;
3578 (*desc
->handle_mousedown
) (desc
, event
);
3581 /******************************************************************/
3582 static void iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3584 WAppIcon
*btn
= desc
->parent
;
3585 WDock
*dock
= btn
->dock
;
3586 WApplication
*wapp
= NULL
;
3589 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3590 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3592 assert(wapp
!= NULL
);
3594 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3596 /* go to the last workspace that the user worked on the app */
3597 if (wapp
->last_workspace
!= w_global
.workspace
.current
&& !unhideHere
)
3598 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3600 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3602 if (event
->xbutton
.state
& MOD_MASK
)
3603 wHideOtherApplications(btn
->icon
->owner
);
3605 if (event
->xbutton
.button
== Button1
) {
3606 if (event
->xbutton
.state
& MOD_MASK
) {
3607 /* raise/lower dock */
3608 toggleLowered(dock
);
3609 } else if (btn
== w_global
.clip
.icon
) {
3610 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
)
3611 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3612 else if (wPreferences
.flags
.clip_merged_in_dock
) {
3613 // Is actually the dock
3616 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3617 launchDockedApplication(btn
, False
);
3621 wShowInfoPanel(dock
->screen_ptr
);
3625 toggleCollapsed(dock
);
3626 } else if (wIsADrawer(btn
)) {
3627 toggleCollapsed(dock
);
3628 } else if (btn
->command
) {
3629 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3630 launchDockedApplication(btn
, False
);
3631 } else if (btn
->xindex
== 0 && btn
->yindex
== 0 && btn
->dock
->type
== WM_DOCK
) {
3632 wShowInfoPanel(dock
->screen_ptr
);
3638 static void handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3640 WScreen
*scr
= dock
->screen_ptr
;
3641 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3642 WIcon
*icon
= aicon
->icon
;
3645 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;;
3646 int shad_x
= x
, shad_y
= y
;
3648 int grabbed
= 0, done
, previously_on_right
, now_on_right
, previous_x_pos
, i
;
3649 Pixmap ghost
= None
;
3650 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3652 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3653 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3654 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
)
3655 wwarning("pointer grab failed for dock move");
3657 if (dock
->type
== WM_DRAWER
) {
3659 wins
[0] = icon
->core
->window
;
3660 wins
[1] = scr
->dock_shadow
;
3661 XRestackWindows(dpy
, wins
, 2);
3662 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3663 ICON_SIZE
, ICON_SIZE
);
3665 if (icon
->pixmap
!=None
)
3666 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3668 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3670 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3671 XClearWindow(dpy
, scr
->dock_shadow
);
3673 XMapWindow(dpy
, scr
->dock_shadow
);
3676 previously_on_right
= now_on_right
= dock
->on_right_side
;
3677 previous_x_pos
= dock
->x_pos
;
3680 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3681 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3688 /* It means the cursor moved so fast that it entered
3689 * something else (if moving slowly, it would have
3690 * stayed in the dock that is being moved. Ignore such
3691 * "spurious" EnterNotifiy's */
3696 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3697 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3698 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3699 | ButtonReleaseMask
| ButtonPressMask
,
3700 wPreferences
.cursor
[WCUR_MOVE
], CurrentTime
);
3705 switch (dock
->type
) {
3707 x
= ev
.xmotion
.x_root
- ofs_x
;
3708 y
= ev
.xmotion
.y_root
- ofs_y
;
3709 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3710 moveDock(dock
, x
, y
);
3713 x
= ev
.xmotion
.x_root
- ofs_x
;
3714 y
= ev
.xmotion
.y_root
- ofs_y
;
3715 if (previously_on_right
)
3717 now_on_right
= (ev
.xmotion
.x_root
>= previous_x_pos
- ICON_SIZE
);
3721 now_on_right
= (ev
.xmotion
.x_root
> previous_x_pos
+ ICON_SIZE
* 2);
3723 if (now_on_right
!= dock
->on_right_side
)
3725 dock
->on_right_side
= now_on_right
;
3727 wArrangeIcons(scr
, False
);
3729 // Also perform the vertical move
3730 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3731 moveDock(dock
, dock
->x_pos
, y
);
3732 if (wPreferences
.flags
.wrap_appicons_in_dock
)
3734 for (i
= 0; i
< dock
->max_icons
; i
++) {
3735 int new_y
, new_index
, j
, ok
;
3736 if ((tmpaicon
= dock
->icon_array
[i
]) == NULL
)
3738 if (onScreen(scr
, tmpaicon
->x_pos
, tmpaicon
->y_pos
))
3740 new_y
= (tmpaicon
->y_pos
+ ICON_SIZE
* dock
->max_icons
) % (ICON_SIZE
* dock
->max_icons
);
3741 new_index
= (new_y
- dock
->y_pos
) / ICON_SIZE
;
3742 if (!onScreen(scr
, tmpaicon
->x_pos
, new_y
))
3745 for (j
= 0; j
< dock
->max_icons
; j
++)
3747 if (dock
->icon_array
[j
] != NULL
&&
3748 dock
->icon_array
[j
]->yindex
== new_index
)
3754 if (!ok
|| getDrawer(scr
, new_index
) != NULL
)
3756 wDockReattachIcon(dock
, tmpaicon
, tmpaicon
->xindex
, new_index
);
3758 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3760 int new_y
, new_index
, j
, ok
;
3761 tmpaicon
= dc
->adrawer
->icon_array
[0];
3762 if (onScreen(scr
, tmpaicon
->x_pos
, tmpaicon
->y_pos
))
3764 new_y
= (tmpaicon
->y_pos
+ ICON_SIZE
* dock
->max_icons
) % (ICON_SIZE
* dock
->max_icons
);
3765 new_index
= (new_y
- dock
->y_pos
) / ICON_SIZE
;
3766 if (!onScreen(scr
, tmpaicon
->x_pos
, new_y
))
3769 for (j
= 0; j
< dock
->max_icons
; j
++)
3771 if (dock
->icon_array
[j
] != NULL
&&
3772 dock
->icon_array
[j
]->yindex
== new_index
)
3778 if (!ok
|| getDrawer(scr
, new_index
) != NULL
)
3780 moveDock(dc
->adrawer
, tmpaicon
->x_pos
, new_y
);
3786 WDock
*real_dock
= dock
->screen_ptr
->dock
;
3789 x
= ev
.xmotion
.x_root
- ofs_x
;
3790 y
= ev
.xmotion
.y_root
- ofs_y
;
3791 snapped
= wDockSnapIcon(real_dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3793 shad_x
= real_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3794 shad_y
= real_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3795 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3797 moveDock(dock
, x
, y
);
3807 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3809 XUngrabPointer(dpy
, CurrentTime
);
3810 if (dock
->type
== WM_DRAWER
) {
3811 Window
*wins
[dock
->icon_count
];
3813 for (i
= 0; i
< dock
->max_icons
; i
++) {
3814 if ((tmpaicon
= dock
->icon_array
[i
]) == NULL
)
3816 wins
[ tmpaicon
->xindex
+ (dock
->on_right_side
? dock
->icon_count
- 1 : 0) ] = &tmpaicon
->icon
->core
->window
;
3818 SlideWindows(wins
, dock
->icon_count
,
3819 (dock
->on_right_side
? x
- (dock
->icon_count
- 1) * ICON_SIZE
: x
),
3821 (dock
->on_right_side
? shad_x
- (dock
->icon_count
- 1) * ICON_SIZE
: shad_x
),
3823 XUnmapWindow(dpy
, scr
->dock_shadow
);
3824 moveDock(dock
, shad_x
, shad_y
);
3825 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3833 XFreePixmap(dpy
, ghost
);
3834 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3839 static int getClipButton(int px
, int py
)
3841 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3843 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3846 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3847 return CLIP_FORWARD
;
3848 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3854 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3857 int done
, direction
, new_ws
;
3859 WDock
*clip
= w_global
.clip
.icon
->dock
;
3861 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3863 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3864 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3869 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3876 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3877 if (new_dir
!= direction
) {
3878 direction
= new_dir
;
3879 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3880 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3889 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3894 clip
->lclip_button_pushed
= 0;
3895 clip
->rclip_button_pushed
= 0;
3897 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3899 if (direction
== CLIP_FORWARD
) {
3900 if (w_global
.workspace
.current
< w_global
.workspace
.count
- 1)
3901 wWorkspaceChange(scr
, w_global
.workspace
.current
+ 1);
3902 else if (new_ws
&& w_global
.workspace
.current
< MAX_WORKSPACES
- 1)
3903 wWorkspaceChange(scr
, w_global
.workspace
.current
+ 1);
3904 else if (wPreferences
.ws_cycle
)
3905 wWorkspaceChange(scr
, 0);
3906 } else if (direction
== CLIP_REWIND
) {
3907 if (w_global
.workspace
.current
> 0)
3908 wWorkspaceChange(scr
, w_global
.workspace
.current
- 1);
3909 else if (w_global
.workspace
.current
== 0 && wPreferences
.ws_cycle
)
3910 wWorkspaceChange(scr
, w_global
.workspace
.count
- 1);
3916 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3918 WAppIcon
*aicon
= desc
->parent
;
3919 WDock
*dock
= aicon
->dock
;
3920 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3922 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3925 scr
->last_dock
= dock
;
3927 if (dock
->menu
->flags
.mapped
)
3928 wMenuUnmap(dock
->menu
);
3930 if (IsDoubleClick(scr
, event
)) {
3931 /* double-click was not in the main clip icon */
3932 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3933 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3934 iconDblClick(desc
, event
);
3939 if (event
->xbutton
.button
== Button1
) {
3940 if (event
->xbutton
.state
& MOD_MASK
)
3945 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= w_global
.clip
.icon
&& dock
->type
!= WM_DOCK
) {
3946 wIconSelect(aicon
->icon
);
3950 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3951 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
&&
3952 (dock
->type
== WM_CLIP
|| (dock
->type
== WM_DOCK
&& wPreferences
.flags
.clip_merged_in_dock
)))
3953 handleClipChangeWorkspace(scr
, event
);
3955 handleDockMove(dock
, aicon
, event
);
3957 Bool hasMoved
= wHandleAppIconMove(aicon
, event
);
3958 if (wPreferences
.single_click
&& !hasMoved
)
3959 iconDblClick(desc
, event
);
3961 } else if (event
->xbutton
.button
== Button2
&& aicon
== w_global
.clip
.icon
) {
3962 if (!w_global
.clip
.ws_menu
)
3963 w_global
.clip
.ws_menu
= wWorkspaceMenuMake(scr
, False
);
3965 if (w_global
.clip
.ws_menu
) {
3966 WMenu
*wsMenu
= w_global
.clip
.ws_menu
;
3969 wWorkspaceMenuUpdate(wsMenu
);
3971 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
3974 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
3975 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
3977 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
3979 desc
= &wsMenu
->menu
->descriptor
;
3980 event
->xany
.send_event
= True
;
3981 (*desc
->handle_mousedown
) (desc
, event
);
3983 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
3984 (event
->xbutton
.state
& ShiftMask
) && aicon
!= w_global
.clip
.icon
) {
3985 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3986 } else if (event
->xbutton
.button
== Button3
) {
3987 if (event
->xbutton
.send_event
&&
3988 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3989 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3990 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3991 wwarning("pointer grab failed for dockicon menu");
3995 openDockMenu(dock
, aicon
, event
);
3996 } else if (event
->xbutton
.button
== Button2
) {
3997 WAppIcon
*btn
= desc
->parent
;
3999 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
4000 launchDockedApplication(btn
, True
);
4004 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
4006 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
4010 assert(event
->type
== EnterNotify
);
4012 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
4015 scr
= btn
->icon
->core
->screen_ptr
;
4021 /* The auto raise/lower code */
4022 tmp
= (dock
->type
== WM_DRAWER
? scr
->dock
: dock
);
4023 if (tmp
->auto_lower_magic
) {
4024 WMDeleteTimerHandler(tmp
->auto_lower_magic
);
4025 tmp
->auto_lower_magic
= NULL
;
4027 if (tmp
->auto_raise_lower
&& !tmp
->auto_raise_magic
)
4028 tmp
->auto_raise_magic
= WMAddTimerHandler(wPreferences
.clip_auto_raise_delay
, clipAutoRaise
, (void *) tmp
);
4030 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4033 /* The auto expand/collapse code */
4034 if (dock
->auto_collapse_magic
) {
4035 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
4036 dock
->auto_collapse_magic
= NULL
;
4038 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
)
4039 dock
->auto_expand_magic
= WMAddTimerHandler(wPreferences
.clip_auto_expand_delay
, clipAutoExpand
, (void *)dock
);
4042 static void clipLeave(WDock
*dock
)
4045 WObjDescriptor
*desc
= NULL
;
4051 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
4052 if (XFindContext(dpy
, event
.xcrossing
.window
, w_global
.context
.client_win
,
4053 (XPointer
*) & desc
) != XCNOENT
4054 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
4055 && ((WAppIcon
*) desc
->parent
)->dock
== dock
) {
4056 /* We haven't left the dock/clip/drawer yet */
4057 XPutBackEvent(dpy
, &event
);
4061 XPutBackEvent(dpy
, &event
);
4063 /* We entered a withdrawn window, so we're still in Clip */
4067 tmp
= (dock
->type
== WM_DRAWER
? dock
->screen_ptr
->dock
: dock
);
4068 if (tmp
->auto_raise_magic
) {
4069 WMDeleteTimerHandler(tmp
->auto_raise_magic
);
4070 tmp
->auto_raise_magic
= NULL
;
4072 if (tmp
->auto_raise_lower
&& !tmp
->auto_lower_magic
)
4073 tmp
->auto_lower_magic
= WMAddTimerHandler(wPreferences
.clip_auto_lower_delay
, clipAutoLower
, (void *)tmp
);
4075 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4078 if (dock
->auto_expand_magic
) {
4079 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4080 dock
->auto_expand_magic
= NULL
;
4082 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
)
4083 dock
->auto_collapse_magic
= WMAddTimerHandler(wPreferences
.clip_auto_collapse_delay
, clipAutoCollapse
, (void *)dock
);
4086 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4088 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
4090 assert(event
->type
== LeaveNotify
);
4092 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
4095 clipLeave(btn
->dock
);
4098 static void clipAutoCollapse(void *cdata
)
4100 WDock
*dock
= (WDock
*) cdata
;
4102 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4105 if (dock
->auto_collapse
) {
4106 dock
->collapsed
= 1;
4107 wDockHideIcons(dock
);
4109 dock
->auto_collapse_magic
= NULL
;
4112 static void clipAutoExpand(void *cdata
)
4114 WDock
*dock
= (WDock
*) cdata
;
4116 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4119 if (dock
->auto_collapse
) {
4120 dock
->collapsed
= 0;
4121 wDockShowIcons(dock
);
4123 dock
->auto_expand_magic
= NULL
;
4126 static void clipAutoLower(void *cdata
)
4128 WDock
*dock
= (WDock
*) cdata
;
4130 if (dock
->auto_raise_lower
)
4133 dock
->auto_lower_magic
= NULL
;
4136 static void clipAutoRaise(void *cdata
)
4138 WDock
*dock
= (WDock
*) cdata
;
4140 if (dock
->auto_raise_lower
)
4143 dock
->auto_raise_magic
= NULL
;
4146 static Bool
iconCanBeOmnipresent(WAppIcon
*aicon
)
4148 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4153 for (i
= 0; i
< w_global
.workspace
.count
; i
++) {
4154 clip
= w_global
.workspace
.array
[i
]->clip
;
4156 if (clip
== aicon
->dock
)
4159 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4160 return False
; /* Clip is full in some workspace */
4162 for (j
= 0; j
< clip
->max_icons
; j
++) {
4163 btn
= clip
->icon_array
[j
];
4164 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
4172 int wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
4174 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4175 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4176 int status
= WO_SUCCESS
;
4178 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== w_global
.clip
.icon
)
4179 return WO_NOT_APPLICABLE
;
4181 if (aicon
->omnipresent
== omnipresent
)
4185 if (iconCanBeOmnipresent(aicon
)) {
4186 aicon
->omnipresent
= 1;
4187 new_entry
= wmalloc(sizeof(WAppIconChain
));
4188 new_entry
->aicon
= aicon
;
4189 new_entry
->next
= scr
->global_icons
;
4190 scr
->global_icons
= new_entry
;
4191 scr
->global_icon_count
++;
4193 aicon
->omnipresent
= 0;
4197 aicon
->omnipresent
= 0;
4198 if (aicon
== scr
->global_icons
->aicon
) {
4199 tmp
= scr
->global_icons
->next
;
4200 wfree(scr
->global_icons
);
4201 scr
->global_icons
= tmp
;
4202 scr
->global_icon_count
--;
4204 tmp
= scr
->global_icons
;
4206 if (tmp
->next
->aicon
== aicon
) {
4207 tmp1
= tmp
->next
->next
;
4210 scr
->global_icon_count
--;
4218 wAppIconPaint(aicon
);
4223 static void drawerAppendToChain(WScreen
*scr
, WDock
*drawer
)
4225 WDrawerChain
**where_to_add
;
4227 where_to_add
= &scr
->drawers
;
4228 while ((*where_to_add
) != NULL
) {
4229 where_to_add
= &(*where_to_add
)->next
;
4232 *where_to_add
= wmalloc(sizeof(WDrawerChain
));
4233 (*where_to_add
)->adrawer
= drawer
;
4234 (*where_to_add
)->next
= NULL
;
4235 scr
->drawer_count
++;
4239 static void drawerRemoveFromChain(WScreen
*scr
, WDock
*drawer
)
4241 WDrawerChain
*next
, **to_remove
;
4243 to_remove
= &scr
->drawers
;
4245 if (*to_remove
== NULL
) {
4246 wwarning("The drawer to be removed can not be found.");
4249 if ((*to_remove
)->adrawer
== drawer
)
4252 to_remove
= &(*to_remove
)->next
;
4254 next
= (*to_remove
)->next
;
4257 scr
->drawer_count
--;
4261 /* Don't free the returned string. Duplicate it. */
4262 static char * findUniqueName(WScreen
*scr
, const char *instance_basename
)
4264 static char buffer
[128];
4267 Bool already_in_use
= True
;
4269 #define UNIQUE_NAME_WATCHDOG 128
4270 for (i
= 0; already_in_use
&& i
< UNIQUE_NAME_WATCHDOG
; i
++) {
4271 snprintf(buffer
, sizeof buffer
, "%s%d", instance_basename
, i
);
4273 already_in_use
= False
;
4275 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4276 if (!strncmp(dc
->adrawer
->icon_array
[0]->wm_instance
, buffer
,
4278 already_in_use
= True
;
4284 if (i
== UNIQUE_NAME_WATCHDOG
)
4285 wwarning("Couldn't find a unique name for drawer in %d attempts.", i
);
4286 #undef UNIQUE_NAME_WATCHDOG
4292 static void drawerIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
4294 wDrawerIconPaint((WAppIcon
*) desc
->parent
);
4298 static int addADrawer(WScreen
*scr
)
4300 int i
, y
, sig
, found_y
;
4301 WDock
*drawer
, *dock
= scr
->dock
;
4303 char can_be_here
[2 * dock
->max_icons
- 1];
4305 if (dock
->icon_count
+ scr
->drawer_count
>= dock
->max_icons
)
4308 for (y
= -dock
->max_icons
+ 1; y
< dock
->max_icons
; y
++) {
4309 can_be_here
[y
+ dock
->max_icons
- 1] = True
;
4311 for (i
= 0; i
< dock
->max_icons
; i
++) {
4312 if (dock
->icon_array
[i
] != NULL
)
4313 can_be_here
[dock
->icon_array
[i
]->yindex
+ dock
->max_icons
- 1] = False
;
4315 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4316 y
= (int) ((dc
->adrawer
->y_pos
- dock
->y_pos
) / ICON_SIZE
);
4317 can_be_here
[y
+ dock
->max_icons
- 1] = False
;
4321 for (sig
= 1; !found_y
&& sig
> -2; sig
-= 2) // 1, then -1
4323 for (y
= sig
; sig
* y
< dock
->max_icons
; y
+= sig
)
4325 if (can_be_here
[y
+ dock
->max_icons
- 1] &&
4326 onScreen(scr
, dock
->x_pos
, dock
->y_pos
+ y
* ICON_SIZE
))
4335 /* This can happen even when dock->icon_count + scr->drawer_count
4336 * < dock->max_icons when the dock is not aligned on an
4337 * ICON_SIZE multiple, as some space is lost above and under it */
4340 drawer
= wDockCreate(scr
, WM_DRAWER
, NULL
);
4341 drawer
->lowered
= scr
->dock
->lowered
;
4342 if (!drawer
->lowered
)
4343 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMDockLevel
);
4345 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMNormalLevel
);
4346 drawer
->auto_raise_lower
= scr
->dock
->auto_raise_lower
;
4347 drawer
->x_pos
= dock
->x_pos
;
4348 drawer
->y_pos
= dock
->y_pos
+ ICON_SIZE
* y
;
4349 drawer
->icon_array
[0]->xindex
= 0;
4350 drawer
->icon_array
[0]->yindex
= 0;
4351 drawer
->icon_array
[0]->x_pos
= drawer
->x_pos
;
4352 drawer
->icon_array
[0]->y_pos
= drawer
->y_pos
;
4353 XMoveWindow(dpy
, drawer
->icon_array
[0]->icon
->core
->window
,
4354 drawer
->icon_array
[0]->x_pos
, drawer
->icon_array
[0]->y_pos
);
4360 static void addADrawerCallback(WMenu
*menu
, WMenuEntry
*entry
)
4362 assert(entry
->clientdata
!=NULL
);
4363 addADrawer(((WAppIcon
*) entry
->clientdata
)->dock
->screen_ptr
);
4367 static void drawerDestroy(WDock
*drawer
)
4377 scr
= drawer
->screen_ptr
;
4379 /* Note regarding menus: we can't delete any dock/clip/drawer menu, because
4380 * that would (attempt to) wfree some memory in gettext library (see menu
4381 * entries that have several "versions", such like "Hide" and "Unhide"). */
4383 wDefaultPurgeInfo(scr
, drawer
->icon_array
[0]->wm_instance
,
4384 drawer
->icon_array
[0]->wm_class
);
4385 if (drawer
->icon_count
== 2) {
4386 // Drawer contains a single appicon: dock it where the drawer was
4387 for (i
= 1; i
< drawer
->max_icons
; i
++) {
4388 if ((aicon
= drawer
->icon_array
[i
]))
4391 wDockMoveIconBetweenDocks(drawer
, scr
->dock
, aicon
,
4392 0, (drawer
->y_pos
- scr
->dock
->y_pos
) / ICON_SIZE
);
4393 XMoveWindow(dpy
, aicon
->icon
->core
->window
, drawer
->x_pos
, drawer
->y_pos
);
4394 XMapWindow(dpy
, aicon
->icon
->core
->window
);
4396 else if (drawer
->icon_count
> 2) {
4397 icons
= WMCreateArray(drawer
->icon_count
- 1);
4398 for (i
= 1; i
< drawer
->max_icons
; i
++) {
4399 if (!(aicon
= drawer
->icon_array
[i
]))
4401 WMAddToArray(icons
, aicon
);
4403 removeIcons(icons
, drawer
);
4406 if (drawer
->auto_collapse_magic
) {
4407 WMDeleteTimerHandler(drawer
->auto_collapse_magic
);
4408 drawer
->auto_collapse_magic
= NULL
;
4410 if (drawer
->auto_lower_magic
) {
4411 WMDeleteTimerHandler(drawer
->auto_lower_magic
);
4412 drawer
->auto_lower_magic
= NULL
;
4415 wAppIconDestroy(drawer
->icon_array
[0]);
4416 wfree(drawer
->icon_array
);
4419 drawerRemoveFromChain(scr
, drawer
);
4420 if (scr
->last_dock
== drawer
)
4421 scr
->last_dock
= NULL
;
4422 if (scr
->attracting_drawer
== drawer
)
4423 scr
->attracting_drawer
= NULL
;
4427 static void removeDrawerCallback(WMenu
*menu
, WMenuEntry
*entry
)
4429 WDock
*dock
= ((WAppIcon
*)entry
->clientdata
)->dock
;
4430 assert(dock
!= NULL
);
4432 if (dock
->icon_count
> 2) {
4433 if (wMessageDialog(dock
->screen_ptr
, _("Drawer"),
4434 _("All icons in this drawer will be detached!"),
4435 _("OK"), _("Cancel"), NULL
) != WAPRDefault
)
4438 drawerDestroy(dock
);
4442 void wDrawerIconPaint(WAppIcon
*dicon
)
4444 Window win
= dicon
->icon
->core
->window
;
4445 WScreen
*scr
= dicon
->icon
->core
->screen_ptr
;
4447 GC gc
= scr
->draw_gc
;
4450 wIconPaint(dicon
->icon
);
4452 if (!dicon
->dock
->collapsed
)
4453 color
= scr
->clip_title_color
[CLIP_NORMAL
];
4455 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
4456 XSetForeground(dpy
, gc
, WMColorPixel(color
));
4458 if (dicon
->dock
->on_right_side
) {
4459 p
[0].x
= p
[3].x
= 10;
4460 p
[0].y
= p
[3].y
= ICON_SIZE
/ 2 - 5;
4462 p
[1].y
= ICON_SIZE
/ 2 + 5;
4464 p
[2].y
= ICON_SIZE
/ 2;
4467 p
[0].x
= p
[3].x
= ICON_SIZE
-1 - 10;
4468 p
[0].y
= p
[3].y
= ICON_SIZE
/ 2 - 5;
4469 p
[1].x
= ICON_SIZE
-1 - 10;
4470 p
[1].y
= ICON_SIZE
/ 2 + 5;
4471 p
[2].x
= ICON_SIZE
-1 - 5;
4472 p
[2].y
= ICON_SIZE
/ 2;
4474 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
4475 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
4479 RImage
* wDrawerMakeTile(WScreen
*scr
, RImage
*normalTile
)
4481 RImage
*tile
= RCloneImage(normalTile
);
4486 dark
.red
= dark
.green
= dark
.blue
= 60;
4489 light
.red
= light
.green
= light
.blue
= 80;
4492 if (!scr
->dock
|| scr
->dock
->on_right_side
) {
4493 ROperateLine(tile
, RSubtractOperation
, 11, ICON_SIZE
/ 2 - 7,
4494 4, ICON_SIZE
/ 2, &dark
); /* / */
4495 ROperateLine(tile
, RSubtractOperation
, 11, ICON_SIZE
/ 2 + 7,
4496 4, ICON_SIZE
/ 2, &dark
); /* \ */
4497 ROperateLine(tile
, RAddOperation
, 11, ICON_SIZE
/ 2 - 7,
4498 11, ICON_SIZE
/ 2 + 7, &light
); /* | */
4501 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 - 7,
4502 ICON_SIZE
-1 - 4, ICON_SIZE
/ 2, &dark
); /* \ */
4503 ROperateLine(tile
, RAddOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 + 7,
4504 ICON_SIZE
-1 - 4, ICON_SIZE
/ 2, &light
); /* / */
4505 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 - 7,
4506 ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 + 7, &dark
); /* | */
4512 static void swapDrawer(WDock
*drawer
, int new_x
)
4516 drawer
->on_right_side
= !drawer
->on_right_side
;
4517 drawer
->x_pos
= new_x
;
4519 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4521 if ((ai
= drawer
->icon_array
[i
]) == NULL
)
4523 ai
->xindex
*= -1; /* so A B C becomes C B A */
4524 ai
->x_pos
= new_x
+ ai
->xindex
* ICON_SIZE
;
4526 /* Update drawer's tile */
4528 wIconUpdate(ai
->icon
);
4529 wDrawerIconPaint(ai
);
4531 XMoveWindow(dpy
, ai
->icon
->core
->window
, ai
->x_pos
, ai
->y_pos
);
4536 static void swapDrawers(WScreen
*scr
, int on_right_side
, int new_x
)
4540 if (scr
->drawer_tile
) {
4541 RReleaseImage(scr
->drawer_tile
);
4543 scr
->drawer_tile
= wDrawerMakeTile(scr
, scr
->icon_tile
);
4545 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4546 swapDrawer(dc
->adrawer
, new_x
);
4547 assert(dc
->adrawer
->on_right_side
== on_right_side
);
4552 int wIsADrawer(WAppIcon
*aicon
)
4554 return aicon
&& aicon
->dock
&&
4555 aicon
->dock
->type
== WM_DRAWER
&& aicon
->dock
->icon_array
[0] == aicon
;
4559 static WDock
* getDrawer(WScreen
*scr
, int y_index
)
4563 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4564 if (dc
->adrawer
->y_pos
- scr
->dock
->y_pos
== y_index
* ICON_SIZE
)
4572 /* Find the "hole" a moving appicon created when snapped into the
4573 * drawer. redocking is a boolean. If the moving appicon comes from the
4574 * drawer, drawer->icon_count is correct. If not, redocking is then false and
4575 * there are now drawer->icon_count plus one appicons in the drawer. */
4576 static int indexOfHole(WDock
*drawer
, WAppIcon
*moving_aicon
, int redocking
)
4578 int index_of_hole
, i
;
4580 /* Classic interview question...
4582 * We have n-1 (n = drawer->icon_count-1 or drawer->icon_count, see
4583 * redocking) appicons, whose xindex are unique in [1..n]. One is missing:
4584 * that's where the ghost of the moving appicon is, that's what the
4585 * function should return.
4587 * We compute 1+2+...+n (this sum is equal to n*(n+1)/2), we substract to
4588 * this sum the xindex of each of the n-1 appicons, and we get the correct
4592 index_of_hole
= (drawer
->icon_count
- 1) * drawer
->icon_count
/ 2;
4594 index_of_hole
= drawer
->icon_count
* (drawer
->icon_count
+ 1) / 2;
4596 index_of_hole
*= (drawer
->on_right_side
? -1 : 1);
4598 for (i
= 1; i
< drawer
->max_icons
; i
++) {
4599 if (drawer
->icon_array
[i
] && drawer
->icon_array
[i
] != moving_aicon
)
4600 index_of_hole
-= drawer
->icon_array
[i
]->xindex
;
4602 /* wmessage(" Index of the moving appicon is %d (%sredocking)", index_of_hole, (redocking ? "" : "not ")); */
4603 if (abs(index_of_hole
) > abs(drawer
->icon_count
) - (redocking
? 1 : 0))
4604 wwarning(" index_of_hole is too large ! (%d greater than %d)",
4605 index_of_hole
, abs(drawer
->icon_count
) - (redocking
? 1 : 0));
4606 if (index_of_hole
== 0)
4607 wwarning(" index_of_hole == 0 (%sredocking, icon_count == %d)", (redocking
? "" : "not "), drawer
->icon_count
);
4609 return index_of_hole
;
4613 void wSlideAppicons(WAppIcon
**appicons
, int n
, int to_the_left
)
4616 int leftmost
= -1, min_index
= 9999, from_x
= -1; // leftmost and from_x initialized to avoid warning
4623 for (i
= 0; i
< n
; i
++) {
4624 aicon
= appicons
[i
];
4625 aicon
->xindex
+= (to_the_left
? -1 : +1);
4626 if (aicon
->xindex
< min_index
) {
4627 min_index
= aicon
->xindex
;
4629 from_x
= aicon
->x_pos
;
4631 aicon
->x_pos
+= (to_the_left
? -ICON_SIZE
: +ICON_SIZE
);
4634 for (i
= 0; i
< n
; i
++) {
4635 aicon
= appicons
[i
];
4636 wins
[aicon
->xindex
- min_index
] = &aicon
->icon
->core
->window
;
4638 aicon
= appicons
[leftmost
];
4639 SlideWindows(wins
, n
, from_x
, aicon
->y_pos
, aicon
->x_pos
, aicon
->y_pos
);
4643 void wDrawerFillTheGap(WDock
*drawer
, WAppIcon
*aicon
, Bool redocking
)
4646 int index_of_hole
= indexOfHole(drawer
, aicon
, redocking
);
4647 WAppIcon
*aicons_to_shift
[drawer
->icon_count
];
4650 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4651 WAppIcon
*ai
= drawer
->icon_array
[i
];
4652 if (ai
&& ai
!= aicon
&&
4653 abs(ai
->xindex
) > abs(index_of_hole
))
4654 aicons_to_shift
[j
++] = ai
;
4656 if (j
!= drawer
->icon_count
- abs(index_of_hole
) - (redocking
? 1 : 0))
4657 wwarning("Removing aicon at index %d from %s: j=%d but should be %d",
4658 index_of_hole
, drawer
->icon_array
[0]->wm_instance
,
4659 j
, drawer
->icon_count
- abs(index_of_hole
) - (redocking
? 1 : 0));
4660 wSlideAppicons(aicons_to_shift
, j
, !drawer
->on_right_side
);
4664 static void drawerConsolidateIcons(WDock
*drawer
)
4666 WAppIcon
*aicons_to_shift
[drawer
->icon_count
];
4667 int maxRemaining
= 0;
4670 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4671 WAppIcon
*ai
= drawer
->icon_array
[i
];
4674 sum
+= abs(ai
->xindex
);
4675 if (abs(ai
->xindex
) > maxRemaining
)
4676 maxRemaining
= abs(ai
->xindex
);
4678 while (sum
!= maxRemaining
* (maxRemaining
+ 1) / 2) { // while there is a hole
4681 // Look up for the hole at max position
4683 for (maxDeleted
= maxRemaining
- 1; maxDeleted
> 0; maxDeleted
--) {
4684 Bool foundAppIconThere
= False
;
4685 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4686 WAppIcon
*ai
= drawer
->icon_array
[i
];
4689 if (abs(ai
->xindex
) == maxDeleted
) {
4690 foundAppIconThere
= True
;
4694 if (!foundAppIconThere
)
4697 assert(maxDeleted
> 0); // would mean while test is wrong
4699 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4700 ai
= drawer
->icon_array
[i
];
4701 if (ai
!= NULL
&& abs(ai
->xindex
) > maxDeleted
)
4702 aicons_to_shift
[n
++] = ai
;
4704 assert(n
== maxRemaining
- maxDeleted
); // for the code review ;-)
4705 wSlideAppicons(aicons_to_shift
, n
, !drawer
->on_right_side
);
4706 // Efficient beancounting
4714 /* similar to wDockRestoreState, but a lot a specific stuff too... */
4715 static WDock
* drawerRestoreState(WScreen
*scr
, WMPropList
*drawer_state
)
4718 WMPropList
*apps
, *value
, *dock_state
;
4727 WMRetainPropList(drawer_state
);
4729 /* Get the instance name, and create a drawer */
4730 value
= WMGetFromPLDictionary(drawer_state
, dName
);
4731 drawer
= wDockCreate(scr
, WM_DRAWER
, WMGetFromPLString(value
));
4733 /* restore DnD command and paste command */
4735 value
= WMGetFromPLDictionary(drawer_state
, dDropCommand
);
4736 if (value
&& WMIsPLString(value
))
4737 drawer
->icon_array
[0]->dnd_command
= wstrdup(WMGetFromPLString(value
));
4740 value
= WMGetFromPLDictionary(drawer_state
, dPasteCommand
);
4741 if (value
&& WMIsPLString(value
))
4742 drawer
->icon_array
[0]->paste_command
= wstrdup(WMGetFromPLString(value
));
4744 /* restore position */
4745 value
= WMGetFromPLDictionary(drawer_state
, dPosition
);
4746 if (!value
|| !WMIsPLString(value
))
4747 COMPLAIN("Position");
4750 if (sscanf(WMGetFromPLString(value
), "%i,%i", &x
, &y
) != 2)
4751 COMPLAIN("Position");
4753 /* check position sanity */
4754 if (x
!= scr
->dock
->x_pos
) {
4755 x
= scr
->dock
->x_pos
;
4757 y_index
= (y
- scr
->dock
->y_pos
) / ICON_SIZE
;
4758 if (y_index
>= scr
->dock
->max_icons
) {
4759 /* Here we should do something more intelligent, since it
4760 * can happen even if the user hasn't hand-edited his
4761 * G/D/State file (but uses a lower resolution). */
4762 y_index
= scr
->dock
->max_icons
- 1;
4764 y
= scr
->dock
->y_pos
+ y_index
* ICON_SIZE
;
4765 moveDock(drawer
, x
, y
);
4768 /* restore dock properties (applist and others) */
4769 dock_state
= WMGetFromPLDictionary(drawer_state
, dDock
);
4771 /* restore lowered/raised state: same as scr->dock, no matter what */
4772 drawer
->lowered
= scr
->dock
->lowered
;
4773 if (!drawer
->lowered
)
4774 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMDockLevel
);
4776 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMNormalLevel
);
4777 wRaiseFrame(drawer
->icon_array
[0]->icon
->core
);
4779 /* restore collapsed state */
4780 drawer
->collapsed
= 0;
4781 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
4782 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4783 drawer
->collapsed
= 1;
4785 /* restore auto-collapsed state */
4786 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
4787 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4788 drawer
->auto_collapse
= 1;
4789 drawer
->collapsed
= 1;
4791 drawer
->auto_collapse
= 0; // because wDockCreate sets it (drawers only)
4794 /* restore auto-raise/lower state: same as scr->dock, no matter what */
4795 drawer
->auto_raise_lower
= scr
->dock
->auto_raise_lower
;
4797 /* restore attract icons state */
4798 drawer
->attract_icons
= 0;
4799 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
4800 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4801 drawer
->attract_icons
= 1;
4802 scr
->attracting_drawer
= drawer
;
4805 /* application list */
4806 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
4812 count
= WMGetPropListItemCount(apps
);
4817 for (i
=0; i
<count
; i
++) {
4818 if (drawer
->icon_count
>= drawer
->max_icons
) {
4819 wwarning(_("there are too many icons stored in drawer. Ignoring what doesn't fit"));
4823 value
= WMGetFromPLArray(apps
, i
);
4824 aicon
= restore_icon_state(scr
, value
, WM_DRAWER
, drawer
->icon_count
);
4826 drawer
->icon_array
[drawer
->icon_count
] = aicon
;
4829 aicon
->dock
= drawer
;
4830 aicon
->x_pos
= drawer
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
4831 aicon
->y_pos
= drawer
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
4833 if (!drawer
->lowered
)
4834 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
4836 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
4838 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
4840 if (!drawer
->collapsed
)
4841 XMapWindow(dpy
, aicon
->icon
->core
->window
);
4842 wRaiseFrame(aicon
->icon
->core
);
4844 drawer
->icon_count
++;
4849 WMReleasePropList(drawer_state
);
4855 /* Same kind of comment than for previous function: this function is
4856 * very similar to make_icon_state, but has substential differences as
4858 static WMPropList
*drawerSaveState(WScreen
*scr
, WDock
*drawer
)
4860 WMPropList
*pstr
, *drawer_state
;
4864 ai
= drawer
->icon_array
[0];
4865 /* Store its name */
4866 pstr
= WMCreatePLString(ai
->wm_instance
);
4867 drawer_state
= WMCreatePLDictionary(dName
, pstr
, NULL
); /* we need this final NULL */
4868 WMReleasePropList(pstr
);
4870 /* Store its position */
4871 snprintf(buffer
, sizeof(buffer
), "%i,%i", ai
->x_pos
, ai
->y_pos
);
4872 pstr
= WMCreatePLString(buffer
);
4873 WMPutInPLDictionary(drawer_state
, dPosition
, pstr
);
4874 WMReleasePropList(pstr
);
4877 /* Store its DnD command */
4878 if (ai
->dnd_command
) {
4879 pstr
= WMCreatePLString(ai
->dnd_command
);
4880 WMPutInPLDictionary(drawer_state
, dDropCommand
, pstr
);
4881 WMReleasePropList(pstr
);
4885 /* Store its paste command */
4886 if (ai
->paste_command
) {
4887 pstr
= WMCreatePLString(ai
->paste_command
);
4888 WMPutInPLDictionary(drawer_state
, dPasteCommand
, pstr
);
4889 WMReleasePropList(pstr
);
4892 /* Store applications list and other properties */
4893 pstr
= dockSaveState(drawer
);
4894 WMPutInPLDictionary(drawer_state
, dDock
, pstr
);
4895 WMReleasePropList(pstr
);
4897 return drawer_state
;
4901 void wDrawersSaveState(WScreen
*scr
)
4903 WMPropList
*all_drawers
, *drawer_state
;
4909 all_drawers
= WMCreatePLArray(NULL
);
4910 for (i
=0, dc
= scr
->drawers
;
4911 i
< scr
->drawer_count
;
4912 i
++, dc
= dc
->next
) {
4913 drawer_state
= drawerSaveState(scr
, dc
->adrawer
);
4914 WMAddToPLArray(all_drawers
, drawer_state
);
4915 WMReleasePropList(drawer_state
);
4917 WMPutInPLDictionary(w_global
.session_state
, dDrawers
, all_drawers
);
4918 WMReleasePropList(all_drawers
);
4922 void wDrawersRestoreState(WScreen
*scr
)
4924 WMPropList
*all_drawers
, *drawer_state
;
4929 if (w_global
.session_state
== NULL
)
4932 all_drawers
= WMGetFromPLDictionary(w_global
.session_state
, dDrawers
);
4936 for (i
= 0; i
< WMGetPropListItemCount(all_drawers
); i
++) {
4937 drawer_state
= WMGetFromPLArray(all_drawers
, i
);
4938 drawerRestoreState(scr
, drawer_state
);
4939 // Note: scr->drawers was updated when the the drawer was created