1 /* dock.c- built-in Dock module for WindowMaker
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <X11/Xutil.h>
36 #define PATH_MAX DEFAULT_PATH_MAX
39 #include "WindowMaker.h"
47 #include "dockedapp.h"
50 #include "properties.h"
54 #include "workspace.h"
56 #include "superfluous.h"
58 #include "placement.h"
62 /**** Local variables ****/
65 #define CLIP_FORWARD 2
67 /**** Global variables ****/
68 extern Cursor wCursor
[WCUR_LAST
];
69 extern XContext wWinContext
;
70 extern void appIconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
72 #define MOD_MASK wPreferences.modifier_mask
73 #define ICON_SIZE wPreferences.icon_size
75 /***** Local variables ****/
77 static WMPropList
*dCommand
= NULL
;
78 static WMPropList
*dPasteCommand
= NULL
;
79 #ifdef XDND /* XXX was OFFIX */
80 static WMPropList
*dDropCommand
= NULL
;
82 static WMPropList
*dAutoLaunch
, *dLock
;
83 static WMPropList
*dName
, *dForced
, *dBuggyApplication
, *dYes
, *dNo
;
84 static WMPropList
*dHost
, *dDock
, *dClip
;
85 static WMPropList
*dAutoAttractIcons
;
87 static WMPropList
*dPosition
, *dApplications
, *dLowered
, *dCollapsed
;
89 static WMPropList
*dAutoCollapse
, *dAutoRaiseLower
, *dOmnipresent
;
91 static WMPropList
*dDrawers
= NULL
;
93 static void dockIconPaint(WAppIcon
*btn
);
95 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
97 static pid_t
execCommand(WAppIcon
*btn
, const char *command
, WSavedState
*state
);
99 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
101 static int getClipButton(int px
, int py
);
103 static void toggleLowered(WDock
*dock
);
105 static void toggleCollapsed(WDock
*dock
);
107 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
109 static void clipLeave(WDock
*dock
);
111 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
113 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
114 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
115 static void clipAutoCollapse(void *cdata
);
116 static void clipAutoExpand(void *cdata
);
117 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
);
119 static void clipAutoLower(void *cdata
);
120 static void clipAutoRaise(void *cdata
);
121 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
, const char *name
);
123 static void drawerIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
124 static void removeDrawerCallback(WMenu
*menu
, WMenuEntry
*entry
);
125 static void drawerAppendToChain(WScreen
*scr
, WDock
*drawer
);
126 static char *findUniqueName(WScreen
*scr
, const char *instance_basename
);
127 static void addADrawerCallback(WMenu
*menu
, WMenuEntry
*entry
);
128 static void swapDrawers(WScreen
*scr
, int on_right_side
, int new_x
);
129 static WDock
* getDrawer(WScreen
*scr
, int y_index
);
130 static int indexOfHole(WDock
*drawer
, WAppIcon
*moving_aicon
, int redocking
);
131 static void drawerConsolidateIcons(WDock
*drawer
);
133 static int onScreen(WScreen
*scr
, int x
, int y
);
135 static void make_keys(void)
137 if (dCommand
!= NULL
)
140 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
141 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
143 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
145 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
146 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
147 dName
= WMRetainPropList(WMCreatePLString("Name"));
148 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
149 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
150 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
151 dNo
= WMRetainPropList(WMCreatePLString("No"));
152 dHost
= WMRetainPropList(WMCreatePLString("Host"));
154 dPosition
= WMCreatePLString("Position");
155 dApplications
= WMCreatePLString("Applications");
156 dLowered
= WMCreatePLString("Lowered");
157 dCollapsed
= WMCreatePLString("Collapsed");
158 dAutoCollapse
= WMCreatePLString("AutoCollapse");
159 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
160 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
162 dOmnipresent
= WMCreatePLString("Omnipresent");
164 dDock
= WMCreatePLString("Dock");
165 dClip
= WMCreatePLString("Clip");
166 dDrawers
= WMCreatePLString("Drawers");
169 static void renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
171 WDock
*dock
= entry
->clientdata
;
176 assert(entry
->clientdata
!= NULL
);
178 wspace
= dock
->screen_ptr
->current_workspace
;
180 name
= wstrdup(dock
->screen_ptr
->workspaces
[wspace
]->name
);
182 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+ 1);
183 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
, &name
))
184 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
189 static void toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
191 assert(entry
->clientdata
!= NULL
);
193 toggleLowered(entry
->clientdata
);
195 entry
->flags
.indicator_on
= !(((WDock
*) entry
->clientdata
)->lowered
);
200 static int matchWindow(const void *item
, const void *cdata
)
202 return (((WFakeGroupLeader
*) item
)->leader
== (Window
) cdata
);
205 static void killCallback(WMenu
*menu
, WMenuEntry
*entry
)
207 WScreen
*scr
= menu
->menu
->screen_ptr
;
209 WFakeGroupLeader
*fPtr
;
210 char *buffer
, *shortname
, **argv
;
211 char *basename(const char *shortname
);
214 if (!WCHECK_STATE(WSTATE_NORMAL
))
217 assert(entry
->clientdata
!= NULL
);
219 icon
= (WAppIcon
*) entry
->clientdata
;
223 WCHANGE_STATE(WSTATE_MODAL
);
225 /* strip away dir names */
226 shortname
= basename(icon
->command
);
227 /* separate out command options */
228 wtokensplit(shortname
, &argv
, &argc
);
230 buffer
= wstrconcat(argv
[0],
231 _(" will be forcibly closed.\n"
232 "Any unsaved changes will be lost.\n" "Please confirm."));
234 if (icon
->icon
&& icon
->icon
->owner
) {
235 fPtr
= icon
->icon
->owner
->fake_group
;
237 /* is this really necessary? can we kill a non-running dock icon? */
238 Window win
= icon
->main_window
;
241 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)win
);
242 if (index
!= WANotFound
)
243 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
248 if (wPreferences
.dont_confirm_kill
249 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
250 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
252 WWindow
*wwin
, *twin
;
254 wwin
= scr
->focused_window
;
257 if (wwin
->fake_group
== fPtr
)
262 } else if (icon
->icon
&& icon
->icon
->owner
) {
263 wClientKill(icon
->icon
->owner
);
268 wtokenfree(argv
, argc
);
272 WCHANGE_STATE(WSTATE_NORMAL
);
275 /* TODO: replace this function with a member of the dock struct */
276 static int numberOfSelectedIcons(WDock
*dock
)
282 for (i
= 1; i
< dock
->max_icons
; i
++) {
283 aicon
= dock
->icon_array
[i
];
284 if (aicon
&& aicon
->icon
->selected
)
291 static WMArray
*getSelected(WDock
*dock
)
293 WMArray
*ret
= WMCreateArray(8);
297 for (i
= 1; i
< dock
->max_icons
; i
++) {
298 btn
= dock
->icon_array
[i
];
299 if (btn
&& btn
->icon
->selected
)
300 WMAddToArray(ret
, btn
);
306 static void paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
308 Window win
= clipIcon
->icon
->core
->window
;
309 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
311 int pt
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
312 int tp
= ICON_SIZE
- pt
;
313 int as
= pt
- 15; /* 15 = 5+5+5 */
314 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
317 color
= scr
->clip_title_color
[CLIP_NORMAL
];
319 XSetForeground(dpy
, gc
, WMColorPixel(color
));
324 p
[1].x
= ICON_SIZE
- 2;
326 p
[2].x
= ICON_SIZE
- 2;
328 } else if (lpushed
) {
332 p
[1].y
= ICON_SIZE
- 2;
334 p
[2].y
= ICON_SIZE
- 2;
336 if (lpushed
|| rpushed
) {
337 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
338 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
339 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
342 /* top right arrow */
343 p
[0].x
= p
[3].x
= ICON_SIZE
- 5 - as
;
345 p
[1].x
= ICON_SIZE
- 6;
347 p
[2].x
= ICON_SIZE
- 6;
350 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
351 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
353 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
354 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
357 /* bottom left arrow */
359 p
[0].y
= p
[3].y
= ICON_SIZE
- 5 - as
;
361 p
[1].y
= ICON_SIZE
- 6;
363 p
[2].y
= ICON_SIZE
- 6;
365 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
366 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
368 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
369 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
373 RImage
*wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
375 RImage
*tile
= RCloneImage(normalTile
);
382 pt
= CLIP_BUTTON_SIZE
* wPreferences
.icon_size
/ 64;
383 tp
= wPreferences
.icon_size
- 1 - pt
;
387 black
.red
= black
.green
= black
.blue
= 0;
390 dark
.red
= dark
.green
= dark
.blue
= 60;
393 light
.red
= light
.green
= light
.blue
= 80;
396 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
- 2, pt
- 1, &dark
);
397 RDrawLine(tile
, tp
- 1, 0, wPreferences
.icon_size
- 1, pt
+ 1, &black
);
398 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
- 3, pt
, &light
);
401 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, 4, &dark
);
402 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 5, 6 + as
, &dark
);
403 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
, &light
);
406 ROperateLine(tile
, RAddOperation
, 2, tp
+ 2, pt
- 2, wPreferences
.icon_size
- 3, &dark
);
407 RDrawLine(tile
, 0, tp
- 1, pt
+ 1, wPreferences
.icon_size
- 1, &black
);
408 ROperateLine(tile
, RSubtractOperation
, 0, tp
- 2, pt
+ 1, wPreferences
.icon_size
- 2, &light
);
411 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, &dark
);
412 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
, 6 + as
, ICON_SIZE
- 5, &dark
);
413 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5, &light
);
418 static void omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
420 WAppIcon
*clickedIcon
= entry
->clientdata
;
423 WMArray
*selectedIcons
;
424 WMArrayIterator iter
;
427 assert(entry
->clientdata
!= NULL
);
429 dock
= clickedIcon
->dock
;
431 selectedIcons
= getSelected(dock
);
433 if (!WMGetArrayItemCount(selectedIcons
))
434 WMAddToArray(selectedIcons
, clickedIcon
);
437 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
438 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
440 else if (aicon
->icon
->selected
)
441 wIconSelect(aicon
->icon
);
443 WMFreeArray(selectedIcons
);
446 wMessageDialog(dock
->screen_ptr
, _("Warning"),
447 _("Some icons cannot be made omnipresent. "
448 "Please make sure that no other icon is "
449 "docked in the same positions on the other "
450 "workspaces and the Clip is not full in "
451 "some workspace."), _("OK"), NULL
, NULL
);
452 } else if (failed
== 1) {
453 wMessageDialog(dock
->screen_ptr
, _("Warning"),
454 _("Icon cannot be made omnipresent. "
455 "Please make sure that no other icon is "
456 "docked in the same position on the other "
457 "workspaces and the Clip is not full in "
458 "some workspace."), _("OK"), NULL
, NULL
);
462 static void removeIcons(WMArray
*icons
, WDock
*dock
)
468 WM_ITERATE_ARRAY(icons
, aicon
, it
) {
469 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
470 wDockDetach(dock
, aicon
);
472 /* XXX: can: aicon->icon == NULL ? */
473 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
474 wGetHeadForWindow(aicon
->icon
->owner
));
475 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
476 if (!dock
->mapped
|| dock
->collapsed
)
477 XMapWindow(dpy
, aicon
->icon
->core
->window
);
482 if (wPreferences
.auto_arrange_icons
)
483 wArrangeIcons(dock
->screen_ptr
, True
);
486 static void removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
488 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
490 WMArray
*selectedIcons
;
492 assert(clickedIcon
!= NULL
);
494 dock
= clickedIcon
->dock
;
496 selectedIcons
= getSelected(dock
);
498 if (WMGetArrayItemCount(selectedIcons
)) {
499 if (wMessageDialog(dock
->screen_ptr
,
500 dock
->type
== WM_CLIP
? _("Workspace Clip") : _("Drawer"),
501 _("All selected icons will be removed!"),
502 _("OK"), _("Cancel"), NULL
) != WAPRDefault
) {
503 WMFreeArray(selectedIcons
);
507 if (clickedIcon
->xindex
== 0 && clickedIcon
->yindex
== 0) {
508 WMFreeArray(selectedIcons
);
511 WMAddToArray(selectedIcons
, clickedIcon
);
514 removeIcons(selectedIcons
, dock
);
516 if (dock
->type
== WM_DRAWER
) {
517 drawerConsolidateIcons(dock
);
521 static void keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
523 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
526 WMArray
*selectedIcons
;
529 assert(clickedIcon
!= NULL
);
530 dock
= clickedIcon
->dock
;
532 selectedIcons
= getSelected(dock
);
534 if (!WMGetArrayItemCount(selectedIcons
)
535 && clickedIcon
!= dock
->screen_ptr
->clip_icon
) {
536 char *command
= NULL
;
538 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
539 clickedIcon
->editing
= 1;
540 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
541 _("Type the command used to launch the application"), &command
)) {
542 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
546 clickedIcon
->command
= command
;
547 clickedIcon
->editing
= 0;
549 clickedIcon
->editing
= 0;
552 WMFreeArray(selectedIcons
);
557 WMAddToArray(selectedIcons
, clickedIcon
);
560 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
561 if (aicon
->icon
->selected
)
562 wIconSelect(aicon
->icon
);
564 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
565 aicon
->attracted
= 0;
566 if (aicon
->icon
->shadowed
) {
567 aicon
->icon
->shadowed
= 0;
570 * Update icon pixmap, RImage doesn't change,
571 * so call wIconUpdate is not needed
573 update_icon_pixmap(aicon
->icon
);
576 wAppIconPaint(aicon
);
579 save_appicon(aicon
, True
);
581 WMFreeArray(selectedIcons
);
584 static void toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
586 WDock
*dock
= (WDock
*) entry
->clientdata
;
587 WScreen
*scr
= dock
->screen_ptr
;
589 assert(entry
->clientdata
!= NULL
);
591 /* Setting a clip as autoattracting will disable an autoattracting drawer,
592 * and reciprocally. Ask for confirmation? */
593 #ifdef CONFIRM_AUTOATTRACT_CHANGE
594 if (dock
->type
== WM_CLIP
&& scr
->attracting_drawer
) {
595 if (wMessageDialog(scr
, _("Workspace Clip"),
596 _("The drawer that auto-attracted icons so far won't do so anymore!"),
597 _("OK"), _("Cancel"), NULL
) != WAPRDefault
)
599 } else if (dock
->type
== WM_DRAWER
) {
600 /* check if at least one clip already auto attracts icons */
601 int i
, ask_for_confirmation
= False
;
602 for (i
= 0; i
< scr
->workspace_count
; i
++) {
603 if (scr
->workspaces
[ i
]->clip
->attract_icons
) {
604 ask_for_confirmation
= True
;
608 if (ask_for_confirmation
) {
609 if (wMessageDialog(scr
, _("Drawer"),
610 _("Any clips that auto-attracted icons so far won't do so anymore!"),
611 _("OK"), _("Cancel"), NULL
) != WAPRDefault
)
617 dock
->attract_icons
= !dock
->attract_icons
;
619 entry
->flags
.indicator_on
= dock
->attract_icons
;
623 if (dock
->attract_icons
) {
624 if (dock
->type
== WM_DRAWER
) {
625 /* The newly auto-attracting dock is a drawer: disable any clip and
626 * previously attracting drawer */
628 for (i
= 0; i
< scr
->workspace_count
; i
++) {
629 scr
->workspaces
[ i
]->clip
->attract_icons
= False
;
630 /* dock menu will be updated later, when opened */
632 if (scr
->attracting_drawer
!= NULL
)
633 scr
->attracting_drawer
->attract_icons
= False
;
634 scr
->attracting_drawer
= dock
;
636 /* The newly auto-attracting dock is a clip: disable
637 * previously attracting drawer, if applicable */
638 if (scr
->attracting_drawer
!= NULL
) {
639 scr
->attracting_drawer
->attract_icons
= False
;
640 /* again, its menu will be updated, later. */
641 scr
->attracting_drawer
= NULL
;
647 static void selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
649 WAppIcon
*icon
= (WAppIcon
*) entry
->clientdata
;
651 assert(icon
!= NULL
);
653 wIconSelect(icon
->icon
);
658 static void colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
660 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
661 WDock
*clip
; /* clip... is a WM_CLIP or a WM_DRAWER */
663 int x
, y
, x_pos
, y_pos
;
664 Bool update_icon
= False
;
666 assert(entry
->clientdata
!= NULL
);
667 clip
= clickedIcon
->dock
;
669 aicon
= clip
->screen_ptr
->app_icon_list
;
672 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
673 x_pos
= clip
->x_pos
+ x
* ICON_SIZE
;
674 y_pos
= clip
->y_pos
+ y
* ICON_SIZE
;
675 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
)
676 move_window(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
678 aicon
->attracted
= 1;
679 if (!aicon
->icon
->shadowed
) {
680 aicon
->icon
->shadowed
= 1;
683 wDockAttachIcon(clip
, aicon
, x
, y
, update_icon
);
684 if (clip
->collapsed
|| !clip
->mapped
)
685 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
691 static void selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
693 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
695 WMArray
*selectedIcons
;
696 WMArrayIterator iter
;
700 assert(clickedIcon
!= NULL
);
701 dock
= clickedIcon
->dock
;
703 selectedIcons
= getSelected(dock
);
705 if (!WMGetArrayItemCount(selectedIcons
)) {
706 for (i
= 1; i
< dock
->max_icons
; i
++) {
707 btn
= dock
->icon_array
[i
];
708 if (btn
&& !btn
->icon
->selected
)
709 wIconSelect(btn
->icon
);
712 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
713 wIconSelect(btn
->icon
);
716 WMFreeArray(selectedIcons
);
721 static void toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
723 assert(entry
->clientdata
!= NULL
);
725 toggleCollapsed(entry
->clientdata
);
727 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->collapsed
;
732 static void toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
735 assert(entry
->clientdata
!= NULL
);
737 dock
= (WDock
*) entry
->clientdata
;
739 dock
->auto_collapse
= !dock
->auto_collapse
;
741 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_collapse
;
746 static void toggleAutoRaiseLower(WDock
*dock
)
750 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
751 if (dock
->type
== WM_DOCK
)
753 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
754 toggleAutoRaiseLower(dc
->adrawer
);
759 static void toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
762 assert(entry
->clientdata
!= NULL
);
764 dock
= (WDock
*) entry
->clientdata
;
766 toggleAutoRaiseLower(dock
);
768 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_raise_lower
;
773 static void launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
775 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
777 launchDockedApplication(btn
, False
);
780 static void settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
782 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
786 ShowDockAppSettingsPanel(btn
);
789 static void hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
792 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
794 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
796 if (wapp
->flags
.hidden
) {
797 wWorkspaceChange(btn
->icon
->core
->screen_ptr
, wapp
->last_workspace
);
798 wUnhideApplication(wapp
, False
, False
);
800 wHideApplication(wapp
);
804 static void unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
807 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
809 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
811 wUnhideApplication(wapp
, False
, True
);
814 /* Name is only used when type == WM_DRAWER and when restoring a specific
815 * drawer, with a specific name. When creating a drawer, leave name to NULL
816 * and mainIconCreate will find the first unused unique name */
817 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
, const char *name
)
825 return scr
->clip_icon
;
826 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
827 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
831 default: /* to avoid a warning about btn and x_pos, basically */
832 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
833 if (wPreferences
.flags
.clip_merged_in_dock
)
834 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
835 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
839 name
= findUniqueName(scr
, "Drawer");
840 btn
= wAppIconCreateForDock(scr
, NULL
, name
, "WMDrawer", TILE_DRAWER
);
841 btn
->icon
->core
->descriptor
.handle_expose
= drawerIconExpose
;
848 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
849 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
850 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
851 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
852 btn
->icon
->core
->descriptor
.parent
= btn
;
853 XMapWindow(dpy
, btn
->icon
->core
->window
);
857 if (type
== WM_CLIP
||
858 (type
== WM_DOCK
&& wPreferences
.flags
.clip_merged_in_dock
))
859 scr
->clip_icon
= btn
;
864 static void switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
866 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
867 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
869 WMArray
*selectedIcons
;
872 if (entry
->order
== scr
->current_workspace
)
875 dest
= scr
->workspaces
[entry
->order
]->clip
;
877 selectedIcons
= getSelected(src
);
879 if (WMGetArrayItemCount(selectedIcons
)) {
880 WMArrayIterator iter
;
882 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
883 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
884 wDockMoveIconBetweenDocks(src
, dest
, btn
, x
, y
);
885 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
888 } else if (icon
!= scr
->clip_icon
) {
889 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
890 wDockMoveIconBetweenDocks(src
, dest
, icon
, x
, y
);
891 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
894 WMFreeArray(selectedIcons
);
897 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
)
899 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
901 if (!btn
->launching
&&
902 ((!withSelection
&& btn
->command
!= NULL
) || (withSelection
&& btn
->paste_command
!= NULL
))) {
903 if (!btn
->forced_dock
) {
904 btn
->relaunching
= btn
->running
;
907 if (btn
->wm_instance
|| btn
->wm_class
) {
908 WWindowAttributes attr
;
909 memset(&attr
, 0, sizeof(WWindowAttributes
));
910 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
912 if (!attr
.no_appicon
&& !btn
->buggy_app
)
917 btn
->drop_launch
= 0;
918 btn
->paste_launch
= withSelection
;
919 scr
->last_dock
= btn
->dock
;
920 btn
->pid
= execCommand(btn
, (withSelection
? btn
->paste_command
: btn
->command
), NULL
);
922 if (btn
->buggy_app
) {
923 /* give feedback that the app was launched */
927 WMAddTimerHandler(200, (WMCallback
*) dockIconPaint
, btn
);
932 wwarning(_("could not launch application %s"), btn
->command
);
934 if (!btn
->relaunching
)
940 static void updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
942 WScreen
*scr
= menu
->frame
->screen_ptr
;
943 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
949 for (i
= 0; i
< scr
->workspace_count
; i
++) {
950 if (i
< menu
->entry_no
) {
951 if (strcmp(menu
->entries
[i
]->text
, scr
->workspaces
[i
]->name
) != 0) {
952 wfree(menu
->entries
[i
]->text
);
953 strcpy(title
, scr
->workspaces
[i
]->name
);
954 menu
->entries
[i
]->text
= wstrdup(title
);
955 menu
->flags
.realized
= 0;
957 menu
->entries
[i
]->clientdata
= (void *)icon
;
959 strcpy(title
, scr
->workspaces
[i
]->name
);
961 wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)icon
);
963 menu
->flags
.realized
= 0;
966 if (i
== scr
->current_workspace
)
967 wMenuSetEnabled(menu
, i
, False
);
969 wMenuSetEnabled(menu
, i
, True
);
972 if (!menu
->flags
.realized
)
976 static WMenu
*makeWorkspaceMenu(WScreen
*scr
)
980 menu
= wMenuCreate(scr
, NULL
, False
);
982 wwarning(_("could not create workspace submenu for Clip menu"));
984 wMenuAddCallback(menu
, "", switchWSCommand
, (void *)scr
->clip_icon
);
986 menu
->flags
.realized
= 0;
992 static void updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
1001 entry
= menu
->entries
[index
];
1002 entry
->flags
.indicator_on
= !dock
->lowered
;
1003 entry
->clientdata
= dock
;
1004 wMenuSetEnabled(menu
, index
, dock
->type
== WM_CLIP
);
1007 entry
= menu
->entries
[++index
];
1008 entry
->flags
.indicator_on
= dock
->collapsed
;
1009 entry
->clientdata
= dock
;
1012 entry
= menu
->entries
[++index
];
1013 entry
->flags
.indicator_on
= dock
->auto_collapse
;
1014 entry
->clientdata
= dock
;
1016 /* auto-raise/lower */
1017 entry
= menu
->entries
[++index
];
1018 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1019 entry
->clientdata
= dock
;
1020 wMenuSetEnabled(menu
, index
, dock
->lowered
&& (dock
->type
== WM_CLIP
));
1023 entry
= menu
->entries
[++index
];
1024 entry
->flags
.indicator_on
= dock
->attract_icons
;
1025 entry
->clientdata
= dock
;
1027 menu
->flags
.realized
= 0;
1032 static WMenu
*makeClipOptionsMenu(WScreen
*scr
)
1037 menu
= wMenuCreate(scr
, NULL
, False
);
1039 wwarning(_("could not create options submenu for Clip menu"));
1043 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
1044 entry
->flags
.indicator
= 1;
1045 entry
->flags
.indicator_on
= 1;
1046 entry
->flags
.indicator_type
= MI_CHECK
;
1048 entry
= wMenuAddCallback(menu
, _("Collapsed"), toggleCollapsedCallback
, NULL
);
1049 entry
->flags
.indicator
= 1;
1050 entry
->flags
.indicator_on
= 1;
1051 entry
->flags
.indicator_type
= MI_CHECK
;
1053 entry
= wMenuAddCallback(menu
, _("Autocollapse"), toggleAutoCollapseCallback
, NULL
);
1054 entry
->flags
.indicator
= 1;
1055 entry
->flags
.indicator_on
= 1;
1056 entry
->flags
.indicator_type
= MI_CHECK
;
1058 entry
= wMenuAddCallback(menu
, _("Autoraise"), toggleAutoRaiseLowerCallback
, NULL
);
1059 entry
->flags
.indicator
= 1;
1060 entry
->flags
.indicator_on
= 1;
1061 entry
->flags
.indicator_type
= MI_CHECK
;
1063 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"), toggleAutoAttractCallback
, NULL
);
1064 entry
->flags
.indicator
= 1;
1065 entry
->flags
.indicator_on
= 1;
1066 entry
->flags
.indicator_type
= MI_CHECK
;
1068 menu
->flags
.realized
= 0;
1075 static void setDockPositionNormalCallback(WMenu
*menu
, WMenuEntry
*entry
)
1077 WDock
*dock
= (WDock
*) entry
->clientdata
;
1079 if (entry
->flags
.indicator_on
) // already set, nothing to do
1081 // Do we come from auto raise lower or keep on top?
1082 if (dock
->auto_raise_lower
)
1084 dock
->auto_raise_lower
= 0;
1085 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1086 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1087 dc
->adrawer
->auto_raise_lower
= 0;
1092 // Will take care of setting lowered = 0 in drawers
1093 toggleLowered(dock
);
1095 entry
->flags
.indicator_on
= 1;
1098 static void setDockPositionAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
1100 WDock
*dock
= (WDock
*) entry
->clientdata
;
1102 if (entry
->flags
.indicator_on
) // already set, nothing to do
1104 // Do we come from normal or keep on top?
1107 toggleLowered(dock
);
1109 dock
->auto_raise_lower
= 1;
1110 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1111 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1112 dc
->adrawer
->auto_raise_lower
= 1;
1114 entry
->flags
.indicator_on
= 1;
1117 static void setDockPositionKeepOnTopCallback(WMenu
*menu
, WMenuEntry
*entry
)
1119 WDock
*dock
= (WDock
*) entry
->clientdata
;
1121 if (entry
->flags
.indicator_on
) // already set, nothing to do
1123 dock
->auto_raise_lower
= 0;
1124 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1125 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1126 dc
->adrawer
->auto_raise_lower
= 0;
1128 toggleLowered(dock
);
1129 entry
->flags
.indicator_on
= 1;
1132 static void updateDockPositionMenu(WMenu
*menu
, WDock
*dock
)
1141 entry
= menu
->entries
[index
++];
1142 entry
->flags
.indicator_on
= (dock
->lowered
&& !dock
->auto_raise_lower
);
1143 entry
->clientdata
= dock
;
1145 /* Auto-raise/lower */
1146 entry
= menu
->entries
[index
++];
1147 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1148 entry
->clientdata
= dock
;
1151 entry
= menu
->entries
[index
++];
1152 entry
->flags
.indicator_on
= !dock
->lowered
;
1153 entry
->clientdata
= dock
;
1156 static WMenu
*makeDockPositionMenu(WScreen
*scr
)
1158 /* When calling this, the dock is being created, so scr->dock is still not set
1159 * Therefore the callbacks' clientdata and the indicators can't be set,
1160 * they will be updated when the dock menu is opened. */
1164 menu
= wMenuCreate(scr
, NULL
, False
);
1166 wwarning(_("could not create options submenu for dock position menu"));
1170 entry
= wMenuAddCallback(menu
, _("Normal"), setDockPositionNormalCallback
, NULL
);
1171 entry
->flags
.indicator
= 1;
1172 entry
->flags
.indicator_type
= MI_DIAMOND
;
1174 entry
= wMenuAddCallback(menu
, _("Auto raise & lower"), setDockPositionAutoRaiseLowerCallback
, NULL
);
1175 entry
->flags
.indicator
= 1;
1176 entry
->flags
.indicator_type
= MI_DIAMOND
;
1178 entry
= wMenuAddCallback(menu
, _("Keep on Top"), setDockPositionKeepOnTopCallback
, NULL
);
1179 entry
->flags
.indicator
= 1;
1180 entry
->flags
.indicator_type
= MI_DIAMOND
;
1182 menu
->flags
.realized
= 0;
1189 static WMenu
*dockMenuCreate(WScreen
*scr
, int type
)
1194 if (type
== WM_CLIP
&& scr
->clip_menu
)
1195 return scr
->clip_menu
;
1197 if (type
== WM_DRAWER
&& scr
->drawer_menu
)
1198 return scr
->drawer_menu
;
1200 menu
= wMenuCreate(scr
, NULL
, False
);
1201 if (type
== WM_DOCK
) {
1202 entry
= wMenuAddCallback(menu
, _("Dock position"), NULL
, NULL
);
1203 if (scr
->dock_pos_menu
== NULL
)
1204 scr
->dock_pos_menu
= makeDockPositionMenu(scr
);
1205 wMenuEntrySetCascade(menu
, entry
, scr
->dock_pos_menu
);
1207 if (!wPreferences
.flags
.nodrawer
) {
1208 entry
= wMenuAddCallback(menu
, _("Add a drawer"), addADrawerCallback
, NULL
);
1211 if (type
== WM_CLIP
)
1212 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1213 else /* if (type == WM_DRAWER) */
1214 entry
= wMenuAddCallback(menu
, _("Drawer options"), NULL
, NULL
);
1216 if (scr
->clip_options
== NULL
)
1217 scr
->clip_options
= makeClipOptionsMenu(scr
);
1218 wMenuEntrySetCascade(menu
, entry
, scr
->clip_options
);
1220 /* The same menu is used for the dock and its appicons. If the menu
1221 * entry text is different between the two contexts, or if it can
1222 * change depending on some state, free the duplicated string (from
1223 * wMenuInsertCallback) and use gettext's string */
1224 if (type
== WM_CLIP
) {
1225 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1227 entry
->text
= _("Rename Workspace"); /* can be: (Toggle) Omnipresent */
1230 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1231 entry
->flags
.indicator
= 1;
1232 entry
->flags
.indicator_on
= 1;
1233 entry
->flags
.indicator_type
= MI_CHECK
;
1235 entry
= wMenuAddCallback(menu
, _("Select All Icons"), selectIconsCallback
, NULL
);
1237 entry
->text
= _("Select All Icons"); /* can be: Unselect all icons */
1239 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1241 entry
->text
= _("Keep Icon"); /* can be: Keep Icons */
1243 if (type
== WM_CLIP
) {
1244 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1246 entry
->text
= _("Move Icon To"); /* can be: Move Icons to */
1247 scr
->clip_submenu
= makeWorkspaceMenu(scr
);
1248 if (scr
->clip_submenu
)
1249 wMenuEntrySetCascade(menu
, entry
, scr
->clip_submenu
);
1252 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
, NULL
);
1254 entry
->text
= _("Remove Icon"); /* can be: Remove Icons */
1256 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1259 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1261 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1263 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1265 entry
->text
= _("Hide"); /* can be: Unhide */
1267 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1269 entry
= wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1271 entry
->text
= _("Kill"); /* can be: Remove drawer */
1273 if (type
== WM_CLIP
)
1274 scr
->clip_menu
= menu
;
1276 if (type
== WM_DRAWER
)
1277 scr
->drawer_menu
= menu
;
1282 WDock
*wDockCreate(WScreen
*scr
, int type
, const char *name
)
1289 dock
= wmalloc(sizeof(WDock
));
1293 dock
->max_icons
= DOCK_MAX_ICONS
;
1296 dock
->max_icons
= scr
->scr_width
/ wPreferences
.icon_size
;
1300 dock
->max_icons
= scr
->scr_height
/ wPreferences
.icon_size
;
1303 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * dock
->max_icons
);
1305 btn
= mainIconCreate(scr
, type
, name
);
1309 dock
->x_pos
= btn
->x_pos
;
1310 dock
->y_pos
= btn
->y_pos
;
1311 dock
->screen_ptr
= scr
;
1313 dock
->icon_count
= 1;
1314 if (type
== WM_DRAWER
)
1315 dock
->on_right_side
= scr
->dock
->on_right_side
;
1317 dock
->on_right_side
= 1;
1318 dock
->collapsed
= 0;
1319 dock
->auto_collapse
= 0;
1320 dock
->auto_collapse_magic
= NULL
;
1321 dock
->auto_raise_lower
= 0;
1322 dock
->auto_lower_magic
= NULL
;
1323 dock
->auto_raise_magic
= NULL
;
1324 dock
->attract_icons
= 0;
1326 dock
->icon_array
[0] = btn
;
1327 wRaiseFrame(btn
->icon
->core
);
1328 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1330 /* create dock menu */
1331 dock
->menu
= dockMenuCreate(scr
, type
);
1333 if (type
== WM_DRAWER
) {
1334 drawerAppendToChain(scr
, dock
);
1335 dock
->auto_collapse
= 1;
1341 void wDockDestroy(WDock
*dock
)
1346 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1347 aicon
= dock
->icon_array
[i
];
1349 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1350 wDockDetach(dock
, aicon
);
1352 /* XXX: can: aicon->icon == NULL ? */
1353 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1354 wGetHeadForWindow(aicon
->icon
->owner
));
1355 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1356 if (!dock
->mapped
|| dock
->collapsed
)
1357 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1361 if (wPreferences
.auto_arrange_icons
)
1362 wArrangeIcons(dock
->screen_ptr
, True
);
1363 wfree(dock
->icon_array
);
1364 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1365 wMenuDestroy(dock
->menu
, True
);
1366 if (dock
->screen_ptr
->last_dock
== dock
)
1367 dock
->screen_ptr
->last_dock
= NULL
;
1371 void wClipIconPaint(WAppIcon
*aicon
)
1373 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1374 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
1376 Window win
= aicon
->icon
->core
->window
;
1377 int length
, nlength
;
1378 char *ws_name
, ws_number
[10];
1381 wIconPaint(aicon
->icon
);
1383 length
= strlen(workspace
->name
);
1384 ws_name
= wmalloc(length
+ 1);
1385 snprintf(ws_name
, length
+ 1, "%s", workspace
->name
);
1386 snprintf(ws_number
, sizeof(ws_number
), "%i", scr
->current_workspace
+ 1);
1387 nlength
= strlen(ws_number
);
1389 if (wPreferences
.flags
.noclip
|| !workspace
->clip
->collapsed
)
1390 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1392 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1394 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1396 tx
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
1398 if(wPreferences
.show_clip_title
)
1399 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, ty
, ws_name
, length
);
1401 tx
= (ICON_SIZE
/ 2 - WMWidthOfString(scr
->clip_title_font
, ws_number
, nlength
)) / 2;
1403 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, 2, ws_number
, nlength
);
1407 if (aicon
->launching
)
1408 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1409 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1411 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
, aicon
->dock
->rclip_button_pushed
);
1414 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1416 wClipIconPaint(desc
->parent
);
1419 static void dockIconPaint(WAppIcon
*btn
)
1421 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
) {
1422 wClipIconPaint(btn
);
1423 } else if (wIsADrawer(btn
->icon
->core
->screen_ptr
, btn
)) {
1424 wDrawerIconPaint(btn
);
1427 save_appicon(btn
, True
);
1431 static WMPropList
*make_icon_state(WAppIcon
*btn
)
1433 WMPropList
*node
= NULL
;
1434 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
;
1435 WMPropList
*position
, *buggy
, *omnipresent
;
1441 command
= WMCreatePLString("-");
1443 command
= WMCreatePLString(btn
->command
);
1445 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1447 lock
= btn
->lock
? dYes
: dNo
;
1449 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1451 name
= WMCreatePLString(tmp
);
1455 forced
= btn
->forced_dock
? dYes
: dNo
;
1457 buggy
= btn
->buggy_app
? dYes
: dNo
;
1459 if (!wPreferences
.flags
.clip_merged_in_dock
&& btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1460 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1462 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1463 position
= WMCreatePLString(buffer
);
1465 node
= WMCreatePLDictionary(dCommand
, command
,
1467 dAutoLaunch
, autolaunch
,
1469 dForced
, forced
, dBuggyApplication
, buggy
, dPosition
, position
, NULL
);
1470 WMReleasePropList(command
);
1471 WMReleasePropList(name
);
1472 WMReleasePropList(position
);
1474 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1475 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&& (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1476 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1478 #ifdef XDND /* was OFFIX */
1479 if (btn
->dnd_command
) {
1480 command
= WMCreatePLString(btn
->dnd_command
);
1481 WMPutInPLDictionary(node
, dDropCommand
, command
);
1482 WMReleasePropList(command
);
1486 if (btn
->paste_command
) {
1487 command
= WMCreatePLString(btn
->paste_command
);
1488 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1489 WMReleasePropList(command
);
1496 static WMPropList
*dockSaveState(WDock
*dock
)
1499 WMPropList
*icon_info
;
1500 WMPropList
*list
= NULL
, *dock_state
= NULL
;
1501 WMPropList
*value
, *key
;
1504 list
= WMCreatePLArray(NULL
);
1506 for (i
= (dock
->type
== WM_DOCK
? 0 : 1); i
< dock
->max_icons
; i
++) {
1507 WAppIcon
*btn
= dock
->icon_array
[i
];
1509 if (!btn
|| btn
->attracted
)
1512 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1513 WMAddToPLArray(list
, icon_info
);
1514 WMReleasePropList(icon_info
);
1518 dock_state
= WMCreatePLDictionary(dApplications
, list
, NULL
);
1520 if (dock
->type
== WM_DOCK
) {
1521 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1522 key
= WMCreatePLString(buffer
);
1523 WMPutInPLDictionary(dock_state
, key
, list
);
1524 WMReleasePropList(key
);
1526 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0), dock
->y_pos
);
1527 value
= WMCreatePLString(buffer
);
1528 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1529 WMReleasePropList(value
);
1531 WMReleasePropList(list
);
1533 if (dock
->type
== WM_CLIP
|| dock
->type
== WM_DRAWER
) {
1534 value
= (dock
->collapsed
? dYes
: dNo
);
1535 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1537 value
= (dock
->auto_collapse
? dYes
: dNo
);
1538 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1540 value
= (dock
->attract_icons
? dYes
: dNo
);
1541 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1544 if (dock
->type
== WM_DOCK
|| dock
->type
== WM_CLIP
) {
1545 value
= (dock
->lowered
? dYes
: dNo
);
1546 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1548 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1549 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1555 void wDockSaveState(WScreen
*scr
, WMPropList
*old_state
)
1557 WMPropList
*dock_state
;
1560 dock_state
= dockSaveState(scr
->dock
);
1563 * Copy saved states of docks with different sizes.
1569 keys
= WMGetPLDictionaryKeys(old_state
);
1570 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1571 tmp
= WMGetFromPLArray(keys
, i
);
1573 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1574 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1576 WMPutInPLDictionary(dock_state
, tmp
, WMGetFromPLDictionary(old_state
, tmp
));
1579 WMReleasePropList(keys
);
1582 WMPutInPLDictionary(scr
->session_state
, dDock
, dock_state
);
1584 WMReleasePropList(dock_state
);
1587 void wClipSaveState(WScreen
*scr
)
1589 WMPropList
*clip_state
;
1591 clip_state
= make_icon_state(scr
->clip_icon
);
1593 WMPutInPLDictionary(scr
->session_state
, dClip
, clip_state
);
1595 WMReleasePropList(clip_state
);
1598 WMPropList
*wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1600 return dockSaveState(scr
->workspaces
[workspace
]->clip
);
1603 static Bool
getBooleanDockValue(WMPropList
*value
, WMPropList
*key
)
1606 if (WMIsPLString(value
)) {
1607 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1610 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1616 static WAppIcon
*restore_icon_state(WScreen
*scr
, WMPropList
*info
, int type
, int index
)
1619 WMPropList
*cmd
, *value
;
1620 char *wclass
, *winstance
, *command
;
1622 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1623 if (!cmd
|| !WMIsPLString(cmd
))
1626 /* parse window name */
1627 value
= WMGetFromPLDictionary(info
, dName
);
1631 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1633 if (!winstance
&& !wclass
)
1638 command
= wstrdup(WMGetFromPLString(cmd
));
1642 if (!command
|| strcmp(command
, "-") == 0) {
1653 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1661 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1662 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1663 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1664 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1665 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1667 #ifdef XDND /* was OFFIX */
1668 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1670 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1673 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1675 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1677 /* check auto launch */
1678 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1680 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1683 value
= WMGetFromPLDictionary(info
, dLock
);
1685 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1687 /* check if it wasn't normally docked */
1688 value
= WMGetFromPLDictionary(info
, dForced
);
1690 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1692 /* check if we can rely on the stuff in the app */
1693 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1695 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1697 /* get position in the dock */
1698 value
= WMGetFromPLDictionary(info
, dPosition
);
1699 if (value
&& WMIsPLString(value
)) {
1700 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1701 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1703 /* check position sanity */
1704 /* *Very* incomplete section! */
1705 if (type
== WM_DOCK
) {
1709 aicon
->yindex
= index
;
1713 /* check if icon is omnipresent */
1714 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1716 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1724 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1726 WAppIcon
*wClipRestoreState(WScreen
*scr
, WMPropList
*clip_state
)
1731 icon
= mainIconCreate(scr
, WM_CLIP
, NULL
);
1736 WMRetainPropList(clip_state
);
1738 /* restore position */
1740 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1743 if (!WMIsPLString(value
)) {
1744 COMPLAIN("Position");
1746 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1747 COMPLAIN("Position");
1749 /* check position sanity */
1750 if (!onScreen(scr
, icon
->x_pos
, icon
->y_pos
))
1751 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1754 #ifdef XDND /* was OFFIX */
1755 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1756 if (value
&& WMIsPLString(value
))
1757 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1760 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1761 if (value
&& WMIsPLString(value
))
1762 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1764 WMReleasePropList(clip_state
);
1769 WDock
*wDockRestoreState(WScreen
*scr
, WMPropList
*dock_state
, int type
)
1774 WAppIcon
*aicon
, *old_top
;
1777 dock
= wDockCreate(scr
, type
, NULL
);
1782 WMRetainPropList(dock_state
);
1784 /* restore position */
1785 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1787 if (!WMIsPLString(value
)) {
1788 COMPLAIN("Position");
1790 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1791 COMPLAIN("Position");
1793 /* check position sanity */
1794 if (!onScreen(scr
, dock
->x_pos
, dock
->y_pos
)) {
1795 int x
= dock
->x_pos
;
1796 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1799 /* Is this needed any more? */
1800 if (type
== WM_CLIP
) {
1801 if (dock
->x_pos
< 0) {
1803 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1804 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1807 if (dock
->x_pos
>= 0) {
1808 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1809 dock
->on_right_side
= 0;
1811 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1812 dock
->on_right_side
= 1;
1818 /* restore lowered/raised state */
1821 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1823 if (!WMIsPLString(value
)) {
1824 COMPLAIN("Lowered");
1826 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1831 /* restore collapsed state */
1832 dock
->collapsed
= 0;
1834 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1836 if (!WMIsPLString(value
)) {
1837 COMPLAIN("Collapsed");
1839 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1840 dock
->collapsed
= 1;
1844 /* restore auto-collapsed state */
1845 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1847 if (!WMIsPLString(value
)) {
1848 COMPLAIN("AutoCollapse");
1850 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1851 dock
->auto_collapse
= 1;
1852 dock
->collapsed
= 1;
1857 /* restore auto-raise/lower state */
1858 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1860 if (!WMIsPLString(value
)) {
1861 COMPLAIN("AutoRaiseLower");
1863 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1864 dock
->auto_raise_lower
= 1;
1868 /* restore attract icons state */
1869 dock
->attract_icons
= 0;
1871 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1873 if (!WMIsPLString(value
)) {
1874 COMPLAIN("AutoAttractIcons");
1876 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1877 dock
->attract_icons
= 1;
1881 /* application list */
1888 * When saving, it saves the dock state in
1889 * Applications and Applicationsnnn
1891 * When loading, it will first try Applicationsnnn.
1892 * If it does not exist, use Applications as default.
1895 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1897 tmp
= WMCreatePLString(buffer
);
1898 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1899 WMReleasePropList(tmp
);
1902 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1908 count
= WMGetPropListItemCount(apps
);
1912 old_top
= dock
->icon_array
[0];
1914 /* dock->icon_count is set to 1 when dock is created.
1915 * Since Clip is already restored, we want to keep it so for clip,
1916 * but for dock we may change the default top tile, so we set it to 0.
1918 if (type
== WM_DOCK
)
1919 dock
->icon_count
= 0;
1921 for (i
= 0; i
< count
; i
++) {
1922 if (dock
->icon_count
>= dock
->max_icons
) {
1923 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1927 value
= WMGetFromPLArray(apps
, i
);
1928 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1930 dock
->icon_array
[dock
->icon_count
] = aicon
;
1934 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1935 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1938 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1940 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1942 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1943 if (!dock
->collapsed
)
1944 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1946 wRaiseFrame(aicon
->icon
->core
);
1949 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
) {
1954 /* if the first icon is not defined, use the default */
1955 if (dock
->icon_array
[0] == NULL
) {
1956 /* update default icon */
1957 old_top
->x_pos
= dock
->x_pos
;
1958 old_top
->y_pos
= dock
->y_pos
;
1960 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1962 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1964 dock
->icon_array
[0] = old_top
;
1965 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1966 /* we don't need to increment dock->icon_count here because it was
1967 * incremented in the loop above.
1969 } else if (old_top
!= dock
->icon_array
[0]) {
1970 if (old_top
== scr
->clip_icon
) // TODO dande: understand the logic
1971 scr
->clip_icon
= dock
->icon_array
[0];
1973 wAppIconDestroy(old_top
);
1977 WMReleasePropList(dock_state
);
1982 void wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1984 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1985 btn
->drop_launch
= 0;
1986 btn
->paste_launch
= 0;
1988 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1991 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
2001 void wDockDoAutoLaunch(WDock
*dock
, int workspace
)
2007 for (i
= 0; i
< dock
->max_icons
; i
++) {
2008 btn
= dock
->icon_array
[i
];
2009 if (!btn
|| !btn
->auto_launch
)
2012 state
= wmalloc(sizeof(WSavedState
));
2013 state
->workspace
= workspace
;
2014 /* TODO: this is klugy and is very difficult to understand
2015 * what's going on. Try to clean up */
2016 wDockLaunchWithState(dock
, btn
, state
);
2020 #ifdef XDND /* was OFFIX */
2021 static WDock
*findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
2027 if ((dock
= scr
->dock
) != NULL
) {
2028 for (i
= 0; i
< dock
->max_icons
; i
++) {
2029 if (dock
->icon_array
[i
]
2030 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
2036 if (*icon_pos
< 0 && (dock
= scr
->workspaces
[scr
->current_workspace
]->clip
) != NULL
) {
2037 for (i
= 0; i
< dock
->max_icons
; i
++) {
2038 if (dock
->icon_array
[i
]
2039 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
2050 int wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
2056 dock
= findDock(scr
, event
, &icon_pos
);
2061 * Return True if the drop was on an application icon window.
2062 * In this case, let the ClientMessage handler redirect the
2063 * message to the app.
2065 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
2068 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
2069 scr
->flags
.dnd_data_convertion_status
= 0;
2071 btn
= dock
->icon_array
[icon_pos
];
2073 if (!btn
->forced_dock
) {
2074 btn
->relaunching
= btn
->running
;
2077 if (btn
->wm_instance
|| btn
->wm_class
) {
2078 WWindowAttributes attr
;
2079 memset(&attr
, 0, sizeof(WWindowAttributes
));
2080 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
2082 if (!attr
.no_appicon
)
2088 btn
->paste_launch
= 0;
2089 btn
->drop_launch
= 1;
2090 scr
->last_dock
= dock
;
2091 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
2096 if (!btn
->relaunching
)
2104 Bool
wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
, Bool update_icon
)
2107 Bool lupdate_icon
= False
;
2108 char *command
= NULL
;
2114 lupdate_icon
= True
;
2116 if (icon
->command
== NULL
) {
2117 /* If icon->owner exists, it means the application is running */
2118 if (icon
->icon
->owner
) {
2119 wwin
= icon
->icon
->owner
;
2120 command
= GetCommandForWindow(wwin
->client_win
);
2124 icon
->command
= command
;
2126 /* icon->forced_dock = 1; */
2127 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
2129 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2130 _("Type the command used to launch the application"), &command
)) {
2131 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2135 icon
->command
= command
;
2141 /* If the target is the dock, reject the icon. If
2142 * the target is the clip, make it an attracted icon
2144 if (dock
->type
== WM_CLIP
) {
2145 icon
->attracted
= 1;
2146 if (!icon
->icon
->shadowed
) {
2147 icon
->icon
->shadowed
= 1;
2148 lupdate_icon
= True
;
2158 for (index
= 1; index
< dock
->max_icons
; index
++)
2159 if (dock
->icon_array
[index
] == NULL
)
2161 /* if (index == dock->max_icons)
2164 assert(index
< dock
->max_icons
);
2166 dock
->icon_array
[index
] = icon
;
2170 icon
->omnipresent
= 0;
2172 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2173 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2178 icon
->launching
= 0;
2181 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2182 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2183 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2184 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2185 icon
->icon
->core
->descriptor
.parent
= icon
;
2187 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2188 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2191 * Update icon pixmap, RImage doesn't change,
2192 * so call wIconUpdate is not needed
2195 update_icon_pixmap(icon
->icon
);
2198 wAppIconPaint(icon
);
2201 save_appicon(icon
, True
);
2203 if (wPreferences
.auto_arrange_icons
)
2204 wArrangeIcons(dock
->screen_ptr
, True
);
2206 #ifdef XDND /* was OFFIX */
2207 if (icon
->command
&& !icon
->dnd_command
) {
2208 int len
= strlen(icon
->command
) + 8;
2209 icon
->dnd_command
= wmalloc(len
);
2210 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
2214 if (icon
->command
&& !icon
->paste_command
) {
2215 int len
= strlen(icon
->command
) + 8;
2216 icon
->paste_command
= wmalloc(len
);
2217 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
2223 void wDockReattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2227 for (index
= 1; index
< dock
->max_icons
; index
++) {
2228 if (dock
->icon_array
[index
] == icon
)
2231 assert(index
< dock
->max_icons
);
2236 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2237 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2240 Bool
wDockMoveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2243 char *command
= NULL
;
2245 Bool update_icon
= False
;
2248 return True
; /* No move needed, we're already there */
2254 * For the moment we can't do this if we move icons in Clip from one
2255 * workspace to other, because if we move two or more icons without
2256 * command, the dialog box will not be able to tell us to which of the
2257 * moved icons it applies. -Dan
2259 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
2260 /* If icon->owner exists, it means the application is running */
2261 if (icon
->icon
->owner
) {
2262 wwin
= icon
->icon
->owner
;
2263 command
= GetCommandForWindow(wwin
->client_win
);
2267 icon
->command
= command
;
2270 /* icon->forced_dock = 1; */
2271 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2272 _("Type the command used to launch the application"), &command
)) {
2273 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2277 icon
->command
= command
;
2288 if (dest
->type
== WM_DOCK
|| dest
->type
== WM_DRAWER
)
2289 wClipMakeIconOmnipresent(icon
, False
);
2291 for (index
= 1; index
< src
->max_icons
; index
++) {
2292 if (src
->icon_array
[index
] == icon
)
2295 assert(index
< src
->max_icons
);
2297 src
->icon_array
[index
] = NULL
;
2300 for (index
= 1; index
< dest
->max_icons
; index
++) {
2301 if (dest
->icon_array
[index
] == NULL
)
2305 assert(index
< dest
->max_icons
);
2307 dest
->icon_array
[index
] = icon
;
2310 /* deselect the icon */
2311 if (icon
->icon
->selected
)
2312 wIconSelect(icon
->icon
);
2314 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2315 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2317 /* set it to be kept when moving to dock.
2318 * Unless the icon does not have a command set
2320 if (icon
->command
&& (dest
->type
== WM_DOCK
|| dest
->type
== WM_DRAWER
)) {
2321 icon
->attracted
= 0;
2322 if (icon
->icon
->shadowed
) {
2323 icon
->icon
->shadowed
= 0;
2326 save_appicon(icon
, True
);
2329 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2335 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2336 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2340 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2343 * Update icon pixmap, RImage doesn't change,
2344 * so call wIconUpdate is not needed
2347 update_icon_pixmap(icon
->icon
);
2350 wAppIconPaint(icon
);
2355 void wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2358 Bool update_icon
= False
;
2360 /* make the settings panel be closed */
2362 DestroyDockAppSettingsPanel(icon
->panel
);
2364 /* This must be called before icon->dock is set to NULL.
2365 * Don't move it. -Dan
2367 wClipMakeIconOmnipresent(icon
, False
);
2371 icon
->attracted
= 0;
2372 icon
->auto_launch
= 0;
2373 if (icon
->icon
->shadowed
) {
2374 icon
->icon
->shadowed
= 0;
2378 /* deselect the icon */
2379 if (icon
->icon
->selected
)
2380 wIconSelect(icon
->icon
);
2382 if (icon
->command
) {
2383 wfree(icon
->command
);
2384 icon
->command
= NULL
;
2386 #ifdef XDND /* was OFFIX */
2387 if (icon
->dnd_command
) {
2388 wfree(icon
->dnd_command
);
2389 icon
->dnd_command
= NULL
;
2392 if (icon
->paste_command
) {
2393 wfree(icon
->paste_command
);
2394 icon
->paste_command
= NULL
;
2397 for (index
= 1; index
< dock
->max_icons
; index
++)
2398 if (dock
->icon_array
[index
] == icon
)
2401 assert(index
< dock
->max_icons
);
2402 dock
->icon_array
[index
] = NULL
;
2408 /* if the dock is not attached to an application or
2409 * the application did not set the appropriate hints yet,
2410 * destroy the icon */
2411 if (!icon
->running
|| !wApplicationOf(icon
->main_window
)) {
2412 wAppIconDestroy(icon
);
2414 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2415 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2416 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2417 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2418 icon
->icon
->core
->descriptor
.parent
= icon
;
2420 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2423 * Update icon pixmap, RImage doesn't change,
2424 * so call wIconUpdate is not needed
2427 update_icon_pixmap(icon
->icon
);
2430 wAppIconPaint(icon
);
2432 if (wPreferences
.auto_arrange_icons
)
2433 wArrangeIcons(dock
->screen_ptr
, True
);
2435 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2440 * returns the closest Dock slot index for the passed
2443 * Returns False if icon can't be docked.
2445 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2448 /* Redocking == true means either icon->dock == dock (normal case)
2449 * or we are called from handleDockMove for a drawer */
2450 Bool
wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2452 WScreen
*scr
= dock
->screen_ptr
;
2455 int i
, offset
= ICON_SIZE
/ 2;
2456 WAppIcon
*aicon
= NULL
;
2457 WAppIcon
*nicon
= NULL
;
2459 if (wPreferences
.flags
.noupdates
)
2465 /* if the dock is full */
2466 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
))
2469 /* exact position */
2471 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2473 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2476 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2478 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2480 /* check if the icon is outside the screen boundaries */
2481 if (!onScreen(scr
, dx
+ ex_x
* ICON_SIZE
, dy
+ ex_y
* ICON_SIZE
))
2484 switch (dock
->type
) {
2486 /* We can return False right away if
2487 * - we do not come from this dock (which is a WM_DOCK),
2488 * - we are not right over it, and
2489 * - we are not the main tile of a drawer.
2490 * In the latter case, we are called from handleDockMove. */
2491 if (icon
->dock
!= dock
&& ex_x
!= 0 &&
2492 !(icon
->dock
&& icon
->dock
->type
== WM_DRAWER
&& icon
== icon
->dock
->icon_array
[0]))
2495 if (!redocking
&& ex_x
!= 0)
2498 if (getDrawer(scr
, ex_y
)) /* Return false so that the drawer gets it. */
2502 for (i
= 0; i
< dock
->max_icons
; i
++) {
2503 nicon
= dock
->icon_array
[i
];
2504 if (nicon
&& nicon
->yindex
== ex_y
) {
2511 int sig
, done
, closest
;
2513 /* Possible cases when redocking:
2515 * icon dragged out of range of any slot -> false
2516 * icon dragged on a drawer -> false (to open the drawer)
2517 * icon dragged to range of free slot
2518 * icon dragged to range of same slot
2519 * icon dragged to range of different icon
2521 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2524 if (aicon
== icon
|| !aicon
) {
2530 /* start looking at the upper slot or lower? */
2531 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2537 /* look for closest free slot */
2538 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2542 closest
= sig
* (i
/ 2) + ex_y
;
2543 /* check if this slot is fully on the screen and not used */
2544 if (onScreen(scr
, dx
, dy
+ closest
* ICON_SIZE
)) {
2545 for (j
= 0; j
< dock
->max_icons
; j
++) {
2546 if (dock
->icon_array
[j
]
2547 && dock
->icon_array
[j
]->yindex
== closest
) {
2548 /* slot is used by someone else */
2549 if (dock
->icon_array
[j
] != icon
)
2554 /* slot is used by a drawer */
2555 done
= done
&& !getDrawer(scr
, closest
);
2562 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2563 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2568 } else { /* !redocking */
2570 /* if slot is free and the icon is close enough, return it */
2571 if (!aicon
&& ex_x
== 0) {
2583 start
= icon
->omnipresent
? 0 : scr
->current_workspace
;
2584 stop
= icon
->omnipresent
? scr
->workspace_count
: start
+ 1;
2587 for (k
= start
; k
< stop
; k
++) {
2588 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2591 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2592 nicon
= tmp
->icon_array
[i
];
2593 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2601 for (k
= start
; k
< stop
; k
++) {
2602 WDock
*tmp
= scr
->workspaces
[k
]->clip
;
2605 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2606 nicon
= tmp
->icon_array
[i
];
2607 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2608 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2609 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2618 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2627 WAppIcon
*aicons_to_shift
[ dock
->icon_count
];
2628 int index_of_hole
, j
;
2631 abs(ex_x
) - dock
->icon_count
> DOCK_DETTACH_THRESHOLD
||
2632 (ex_x
< 0 && !dock
->on_right_side
) ||
2633 (ex_x
> 0 && dock
->on_right_side
)) {
2638 ex_x
= (dock
->on_right_side
? -1 : 1);
2640 /* "Reduce" ex_x but keep its sign */
2642 if (abs(ex_x
) > dock
->icon_count
- 1) /* minus 1: do not take icon_array[0] into account */
2643 ex_x
= ex_x
* (dock
->icon_count
- 1) / abs(ex_x
); /* don't use *= ! */
2645 if (abs(ex_x
) > dock
->icon_count
)
2646 ex_x
= ex_x
* dock
->icon_count
/ abs(ex_x
);
2648 index_of_hole
= indexOfHole(dock
, icon
, redocking
);
2650 /* Find the appicons between where icon was (index_of_hole) and where
2651 * it wants to be (ex_x) and slide them. */
2653 for (i
= 1; i
< dock
->max_icons
; i
++) {
2654 if ((aicon
= dock
->icon_array
[ i
]) && aicon
!= icon
&&
2655 ((ex_x
<= aicon
->xindex
&& aicon
->xindex
< index_of_hole
) ||
2656 (index_of_hole
< aicon
->xindex
&& aicon
->xindex
<= ex_x
)))
2657 aicons_to_shift
[ j
++ ] = aicon
;
2659 assert(j
== abs(ex_x
- index_of_hole
));
2661 wSlideAppicons(aicons_to_shift
, j
, (index_of_hole
< ex_x
));
2671 static int onScreen(WScreen
*scr
, int x
, int y
)
2678 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2680 wGetRectPlacementInfo(scr
, rect
, &flags
);
2682 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2686 * returns true if it can find a free slot in the dock,
2687 * in which case it changes x_pos and y_pos accordingly.
2688 * Else returns false.
2690 Bool
wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2692 WScreen
*scr
= dock
->screen_ptr
;
2694 WAppIconChain
*chain
;
2695 unsigned char *slot_map
;
2699 int i
, done
= False
;
2701 int sx
= 0, ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2702 int extra_count
= 0;
2704 if (dock
->type
== WM_DRAWER
) {
2705 if (dock
->icon_count
>= dock
->max_icons
) { /* drawer is full */
2708 *x_pos
= dock
->icon_count
* (dock
->on_right_side
? -1 : 1);
2713 if (dock
->type
== WM_CLIP
&& dock
!= scr
->workspaces
[scr
->current_workspace
]->clip
)
2714 extra_count
= scr
->global_icon_count
;
2716 /* if the dock is full */
2717 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
)
2720 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2721 if (scr
->dock
->on_right_side
)
2722 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2724 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2727 if (ex
< dock
->x_pos
)
2729 if (sx
> dock
->x_pos
+ ICON_SIZE
)
2730 sx
= dock
->x_pos
+ ICON_SIZE
;
2737 /* check if clip is in a corner */
2738 if (dock
->type
== WM_CLIP
) {
2739 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2741 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2743 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2745 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2753 /* If the clip is in the corner, use only slots that are in the border
2755 if (corner
!= C_NONE
) {
2759 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2760 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2761 hmap
= wmalloc(hcount
+ 1);
2762 vmap
= wmalloc(vcount
+ 1);
2764 /* mark used positions */
2767 for (i
= 0; i
< dock
->max_icons
; i
++) {
2768 btn
= dock
->icon_array
[i
];
2772 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2773 vmap
[btn
->yindex
] = 1;
2774 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2775 hmap
[btn
->xindex
] = 1;
2777 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2779 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2780 vmap
[btn
->yindex
] = 1;
2781 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2782 hmap
[btn
->xindex
] = 1;
2786 for (i
= 0; i
< dock
->max_icons
; i
++) {
2787 btn
= dock
->icon_array
[i
];
2791 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2792 vmap
[btn
->yindex
] = 1;
2793 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2794 hmap
[-btn
->xindex
] = 1;
2796 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2798 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2799 vmap
[btn
->yindex
] = 1;
2800 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2801 hmap
[-btn
->xindex
] = 1;
2805 for (i
= 0; i
< dock
->max_icons
; i
++) {
2806 btn
= dock
->icon_array
[i
];
2810 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2811 vmap
[-btn
->yindex
] = 1;
2812 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2813 hmap
[btn
->xindex
] = 1;
2815 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2817 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2818 vmap
[-btn
->yindex
] = 1;
2819 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2820 hmap
[btn
->xindex
] = 1;
2825 for (i
= 0; i
< dock
->max_icons
; i
++) {
2826 btn
= dock
->icon_array
[i
];
2830 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2831 vmap
[-btn
->yindex
] = 1;
2832 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2833 hmap
[-btn
->xindex
] = 1;
2835 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2837 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2838 vmap
[-btn
->yindex
] = 1;
2839 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2840 hmap
[-btn
->xindex
] = 1;
2846 /* search a vacant slot */
2847 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2848 if (i
< vcount
&& vmap
[i
] == 0) {
2854 } else if (i
< hcount
&& hmap
[i
] == 0) {
2864 /* If found a slot, translate and return */
2866 if (corner
== C_NW
|| corner
== C_NE
)
2871 if (corner
== C_NE
|| corner
== C_SE
)
2878 /* else, try to find a slot somewhere else */
2881 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2882 * placed outside of screen */
2883 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2885 /* In the worst case (the clip is in the corner of the screen),
2886 * the amount of icons that fit in the clip is smaller.
2887 * Double the map to get a safe value.
2891 r
= (mwidth
- 1) / 2;
2893 slot_map
= wmalloc(mwidth
* mwidth
);
2895 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2897 /* mark used slots in the map. If the slot falls outside the map
2898 * (for example, when all icons are placed in line), ignore them. */
2899 for (i
= 0; i
< dock
->max_icons
; i
++) {
2900 btn
= dock
->icon_array
[i
];
2902 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2905 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
)
2906 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2908 /* Find closest slot from the center that is free by scanning the
2909 * map from the center to outward in circular passes.
2910 * This will not result in a neat layout, but will be optimal
2911 * in the sense that there will not be holes left.
2914 for (i
= 1; i
<= r
&& !done
; i
++) {
2917 /* top and bottom parts of the ring */
2918 for (x
= -i
; x
<= i
&& !done
; x
++) {
2919 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2921 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2922 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2929 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2930 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2937 /* left and right parts of the ring */
2938 for (y
= -i
+ 1; y
<= i
- 1; y
++) {
2939 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2941 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2942 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2949 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2950 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2963 static void moveDock(WDock
*dock
, int new_x
, int new_y
)
2969 if (dock
->type
== WM_DOCK
) {
2970 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
2971 moveDock(dc
->adrawer
, new_x
, dc
->adrawer
->y_pos
- dock
->y_pos
+ new_y
);
2974 dock
->x_pos
= new_x
;
2975 dock
->y_pos
= new_y
;
2976 for (i
= 0; i
< dock
->max_icons
; i
++) {
2977 btn
= dock
->icon_array
[i
];
2979 btn
->x_pos
= new_x
+ btn
->xindex
* ICON_SIZE
;
2980 btn
->y_pos
= new_y
+ btn
->yindex
* ICON_SIZE
;
2981 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2986 static void swapDock(WDock
*dock
)
2988 WScreen
*scr
= dock
->screen_ptr
;
2992 if (dock
->on_right_side
)
2993 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2995 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2997 swapDrawers(scr
, dock
->on_right_side
, x
);
2999 for (i
= 0; i
< dock
->max_icons
; i
++) {
3000 btn
= dock
->icon_array
[i
];
3003 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
3007 wScreenUpdateUsableArea(scr
);
3010 static pid_t
execCommand(WAppIcon
*btn
, const char *command
, WSavedState
*state
)
3012 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
3018 cmdline
= ExpandOptions(scr
, command
);
3020 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
3028 wtokensplit(cmdline
, &argv
, &argc
);
3038 if ((pid
= fork()) == 0) {
3042 SetupEnvironment(scr
);
3048 args
= malloc(sizeof(char *) * (argc
+ 1));
3052 for (i
= 0; i
< argc
; i
++)
3056 execvp(argv
[0], args
);
3059 wtokenfree(argv
, argc
);
3063 state
= wmalloc(sizeof(WSavedState
));
3065 state
->miniaturized
= -1;
3067 if (btn
->dock
== scr
->dock
|| btn
->dock
->type
== WM_DRAWER
|| btn
->omnipresent
)
3068 state
->workspace
= -1;
3070 state
->workspace
= scr
->current_workspace
;
3072 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
3073 wAddDeathHandler(pid
, (WDeathHandler
*) trackDeadProcess
, btn
->dock
);
3081 void wDockHideIcons(WDock
*dock
)
3088 for (i
= 1; i
< dock
->max_icons
; i
++) {
3089 if (dock
->icon_array
[i
])
3090 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3094 dockIconPaint(dock
->icon_array
[0]);
3097 void wDockShowIcons(WDock
*dock
)
3105 btn
= dock
->icon_array
[0];
3106 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
3108 /* Deleting any change in stacking level, this function is now only about
3111 if (!dock
->collapsed
) {
3112 for (i
= 1; i
< dock
->max_icons
; i
++) {
3113 if (dock
->icon_array
[i
])
3114 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3122 void wDockLower(WDock
*dock
)
3127 if (dock
->type
== WM_DOCK
) {
3128 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3129 wDockLower(dc
->adrawer
);
3131 for (i
= 0; i
< dock
->max_icons
; i
++) {
3132 if (dock
->icon_array
[i
])
3133 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
3137 void wDockRaise(WDock
*dock
)
3142 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
3143 if (dock
->icon_array
[i
])
3144 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
3146 if (dock
->type
== WM_DOCK
) {
3147 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3148 wDockRaise(dc
->adrawer
);
3152 void wDockRaiseLower(WDock
*dock
)
3154 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
3155 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
3156 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
3162 void wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
3164 icon
->launching
= 0;
3165 icon
->relaunching
= 0;
3166 dockIconPaint(icon
);
3169 WAppIcon
*wDockFindIconForWindow(WDock
*dock
, Window window
)
3174 for (i
= 0; i
< dock
->max_icons
; i
++) {
3175 icon
= dock
->icon_array
[i
];
3176 if (icon
&& icon
->main_window
== window
)
3182 void wDockTrackWindowLaunch(WDock
*dock
, Window window
)
3185 char *wm_class
, *wm_instance
;
3187 Bool firstPass
= True
;
3189 char *command
= NULL
;
3191 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) || (!wm_class
&& !wm_instance
))
3194 command
= GetCommandForWindow(window
);
3196 for (i
= 0; i
< dock
->max_icons
; i
++) {
3197 icon
= dock
->icon_array
[i
];
3201 /* app is already attached to icon */
3202 if (icon
->main_window
== window
) {
3207 if ((icon
->wm_instance
|| icon
->wm_class
)
3208 && (icon
->launching
|| !icon
->running
)) {
3210 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0)
3213 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0)
3216 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0)
3219 if (!icon
->relaunching
) {
3222 /* Possibly an application that was docked with dockit,
3223 * but the user did not update WMState to indicate that
3224 * it was docked by force */
3225 wapp
= wApplicationOf(window
);
3227 icon
->forced_dock
= 1;
3230 if (!icon
->forced_dock
)
3231 icon
->main_window
= window
;
3234 if (!wPreferences
.no_animations
&& !icon
->launching
&&
3235 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
3239 icon
->launching
= 1;
3240 dockIconPaint(icon
);
3242 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
3243 wm_instance
, wm_class
, TILE_NORMAL
);
3244 /* XXX: can: aicon->icon == NULL ? */
3245 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
3246 wAppIconMove(aicon
, x0
, y0
);
3247 /* Should this always be lowered? -Dan */
3249 wLowerFrame(aicon
->icon
->core
);
3250 XMapWindow(dpy
, aicon
->icon
->core
->window
);
3251 aicon
->launching
= 1;
3252 wAppIconPaint(aicon
);
3253 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
3254 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
3255 wAppIconDestroy(aicon
);
3257 wDockFinishLaunch(dock
, icon
);
3262 if (firstPass
&& !found
) {
3276 void wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3278 if (!wPreferences
.flags
.noclip
) {
3279 scr
->clip_icon
->dock
= scr
->workspaces
[workspace
]->clip
;
3280 if (scr
->current_workspace
!= workspace
) {
3281 WDock
*old_clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
3282 WAppIconChain
*chain
= scr
->global_icons
;
3285 wDockMoveIconBetweenDocks(chain
->aicon
->dock
,
3286 scr
->workspaces
[workspace
]->clip
,
3287 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
3288 if (scr
->workspaces
[workspace
]->clip
->collapsed
)
3289 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3290 chain
= chain
->next
;
3293 wDockHideIcons(old_clip
);
3294 if (old_clip
->auto_raise_lower
) {
3295 if (old_clip
->auto_raise_magic
) {
3296 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3297 old_clip
->auto_raise_magic
= NULL
;
3299 wDockLower(old_clip
);
3301 if (old_clip
->auto_collapse
) {
3302 if (old_clip
->auto_expand_magic
) {
3303 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3304 old_clip
->auto_expand_magic
= NULL
;
3306 old_clip
->collapsed
= 1;
3308 wDockShowIcons(scr
->workspaces
[workspace
]->clip
);
3313 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3318 for (i
= 0; i
< dock
->max_icons
; i
++) {
3319 icon
= dock
->icon_array
[i
];
3323 if (icon
->launching
&& icon
->pid
== pid
) {
3324 if (!icon
->relaunching
) {
3326 icon
->main_window
= None
;
3328 wDockFinishLaunch(dock
, icon
);
3330 if (status
== 111) {
3335 if (icon
->drop_launch
)
3336 cmd
= icon
->dnd_command
;
3339 if (icon
->paste_launch
)
3340 cmd
= icon
->paste_command
;
3342 cmd
= icon
->command
;
3344 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3346 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3353 /* This function is called when the dock switches state between
3354 * "normal" (including auto-raise/lower) and "keep on top". It is
3355 * therefore clearly distinct from wDockLower/Raise, which are called
3356 * each time a not-kept-on-top dock is lowered/raised. */
3357 static void toggleLowered(WDock
*dock
)
3363 if (!dock
->lowered
) {
3364 newlevel
= WMNormalLevel
;
3367 newlevel
= WMDockLevel
;
3371 for (i
= 0; i
< dock
->max_icons
; i
++) {
3372 tmp
= dock
->icon_array
[i
];
3376 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3378 /* When the dock is no longer "on top", explicitly lower it as well.
3379 * It saves some CPU cycles (probably) to do it ourselves here
3380 * rather than calling wDockLower at the end of toggleLowered */
3382 wLowerFrame(tmp
->icon
->core
);
3385 if (dock
->type
== WM_DOCK
) {
3386 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
3387 toggleLowered(dc
->adrawer
);
3389 wScreenUpdateUsableArea(dock
->screen_ptr
);
3393 static void toggleCollapsed(WDock
*dock
)
3395 if (dock
->collapsed
) {
3396 dock
->collapsed
= 0;
3397 wDockShowIcons(dock
);
3399 dock
->collapsed
= 1;
3400 wDockHideIcons(dock
);
3404 static void openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3406 WScreen
*scr
= dock
->screen_ptr
;
3407 WObjDescriptor
*desc
;
3409 WApplication
*wapp
= NULL
;
3413 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3415 if (dock
->type
== WM_DOCK
) {
3416 /* Dock position menu */
3417 updateDockPositionMenu(scr
->dock_pos_menu
, dock
);
3418 dock
->menu
->flags
.realized
= 0;
3419 if (!wPreferences
.flags
.nodrawer
) {
3421 entry
= dock
->menu
->entries
[++index
];
3422 entry
->clientdata
= aicon
;
3423 wMenuSetEnabled(dock
->menu
, index
, True
);
3426 /* clip/drawer options */
3427 if (scr
->clip_options
)
3428 updateClipOptionsMenu(scr
->clip_options
, dock
);
3430 n_selected
= numberOfSelectedIcons(dock
);
3432 if (dock
->type
== WM_CLIP
) {
3433 /* Rename Workspace */
3434 entry
= dock
->menu
->entries
[++index
];
3435 if (aicon
== scr
->clip_icon
) {
3436 entry
->callback
= renameCallback
;
3437 entry
->clientdata
= dock
;
3438 entry
->flags
.indicator
= 0;
3439 entry
->text
= _("Rename Workspace");
3441 entry
->callback
= omnipresentCallback
;
3442 entry
->clientdata
= aicon
;
3443 if (n_selected
> 0) {
3444 entry
->flags
.indicator
= 0;
3445 entry
->text
= _("Toggle Omnipresent");
3447 entry
->flags
.indicator
= 1;
3448 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3449 entry
->flags
.indicator_type
= MI_CHECK
;
3450 entry
->text
= _("Omnipresent");
3455 /* select/unselect icon */
3456 entry
= dock
->menu
->entries
[++index
];
3457 entry
->clientdata
= aicon
;
3458 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3459 wMenuSetEnabled(dock
->menu
, index
, aicon
!= scr
->clip_icon
&& !wIsADrawer(scr
, aicon
));
3461 /* select/unselect all icons */
3462 entry
= dock
->menu
->entries
[++index
];
3463 entry
->clientdata
= aicon
;
3465 entry
->text
= _("Unselect All Icons");
3467 entry
->text
= _("Select All Icons");
3469 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3472 entry
= dock
->menu
->entries
[++index
];
3473 entry
->clientdata
= aicon
;
3475 entry
->text
= _("Keep Icons");
3477 entry
->text
= _("Keep Icon");
3479 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3481 if (dock
->type
== WM_CLIP
) {
3482 /* this is the workspace submenu part */
3483 entry
= dock
->menu
->entries
[++index
];
3485 entry
->text
= _("Move Icons To");
3487 entry
->text
= _("Move Icon To");
3489 if (scr
->clip_submenu
)
3490 updateWorkspaceMenu(scr
->clip_submenu
, aicon
);
3492 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3495 /* remove icon(s) */
3496 entry
= dock
->menu
->entries
[++index
];
3497 entry
->clientdata
= aicon
;
3499 entry
->text
= _("Remove Icons");
3501 entry
->text
= _("Remove Icon");
3503 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3505 /* attract icon(s) */
3506 entry
= dock
->menu
->entries
[++index
];
3507 entry
->clientdata
= aicon
;
3509 dock
->menu
->flags
.realized
= 0;
3510 wMenuRealize(dock
->menu
);
3513 if (aicon
->icon
->owner
)
3514 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3519 entry
= dock
->menu
->entries
[++index
];
3520 entry
->clientdata
= aicon
;
3521 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3524 entry
= dock
->menu
->entries
[++index
];
3525 entry
->clientdata
= aicon
;
3526 if (wapp
&& wapp
->flags
.hidden
)
3527 entry
->text
= _("Unhide Here");
3529 entry
->text
= _("Bring Here");
3531 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3534 entry
= dock
->menu
->entries
[++index
];
3535 entry
->clientdata
= aicon
;
3536 if (wapp
&& wapp
->flags
.hidden
)
3537 entry
->text
= _("Unhide");
3539 entry
->text
= _("Hide");
3541 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3544 entry
= dock
->menu
->entries
[++index
];
3545 entry
->clientdata
= aicon
;
3546 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3548 /* kill or remove drawer */
3549 entry
= dock
->menu
->entries
[++index
];
3550 entry
->clientdata
= aicon
;
3551 if (wIsADrawer(scr
, aicon
)) {
3552 entry
->callback
= removeDrawerCallback
;
3553 entry
->text
= _("Remove drawer");
3554 wMenuSetEnabled(dock
->menu
, index
, True
);
3556 entry
->callback
= killCallback
;
3557 entry
->text
= _("Kill");
3558 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3561 if (!dock
->menu
->flags
.realized
)
3562 wMenuRealize(dock
->menu
);
3564 if (dock
->type
== WM_CLIP
|| dock
->type
== WM_DRAWER
) {
3565 /*x_pos = event->xbutton.x_root+2; */
3566 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3569 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3570 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3573 x_pos
= dock
->on_right_side
? scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3576 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3578 /* allow drag select */
3579 event
->xany
.send_event
= True
;
3580 desc
= &dock
->menu
->menu
->descriptor
;
3581 (*desc
->handle_mousedown
) (desc
, event
);
3584 /******************************************************************/
3585 static void iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3587 WAppIcon
*btn
= desc
->parent
;
3588 WDock
*dock
= btn
->dock
;
3589 WApplication
*wapp
= NULL
;
3592 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3593 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3595 assert(wapp
!= NULL
);
3597 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3599 /* go to the last workspace that the user worked on the app */
3600 if (wapp
->last_workspace
!= dock
->screen_ptr
->current_workspace
&& !unhideHere
)
3601 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3603 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3605 if (event
->xbutton
.state
& MOD_MASK
)
3606 wHideOtherApplications(btn
->icon
->owner
);
3608 if (event
->xbutton
.button
== Button1
) {
3609 if (event
->xbutton
.state
& MOD_MASK
) {
3610 /* raise/lower dock */
3611 toggleLowered(dock
);
3612 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3613 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
)
3614 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3615 else if (wPreferences
.flags
.clip_merged_in_dock
) {
3616 // Is actually the dock
3619 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3620 launchDockedApplication(btn
, False
);
3624 wShowInfoPanel(dock
->screen_ptr
);
3628 toggleCollapsed(dock
);
3629 } else if (wIsADrawer(dock
->screen_ptr
, btn
)) {
3630 toggleCollapsed(dock
);
3631 } else if (btn
->command
) {
3632 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3633 launchDockedApplication(btn
, False
);
3634 } else if (btn
->xindex
== 0 && btn
->yindex
== 0 && btn
->dock
->type
== WM_DOCK
) {
3635 wShowInfoPanel(dock
->screen_ptr
);
3641 static void handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3643 WScreen
*scr
= dock
->screen_ptr
;
3644 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3645 WIcon
*icon
= aicon
->icon
;
3648 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;;
3649 int shad_x
= x
, shad_y
= y
;
3651 int grabbed
= 0, done
, previously_on_right
, now_on_right
, previous_x_pos
, i
;
3652 Pixmap ghost
= None
;
3653 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3655 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3656 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3657 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
)
3658 wwarning("pointer grab failed for dock move");
3660 if (dock
->type
== WM_DRAWER
) {
3662 wins
[0] = icon
->core
->window
;
3663 wins
[1] = scr
->dock_shadow
;
3664 XRestackWindows(dpy
, wins
, 2);
3665 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3666 ICON_SIZE
, ICON_SIZE
);
3668 if (icon
->pixmap
!=None
)
3669 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3671 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3673 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3674 XClearWindow(dpy
, scr
->dock_shadow
);
3676 XMapWindow(dpy
, scr
->dock_shadow
);
3679 previously_on_right
= now_on_right
= dock
->on_right_side
;
3680 previous_x_pos
= dock
->x_pos
;
3683 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3684 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3691 /* It means the cursor moved so fast that it entered
3692 * something else (if moving slowly, it would have
3693 * stayed in the dock that is being moved. Ignore such
3694 * "spurious" EnterNotifiy's */
3699 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3700 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3701 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3702 | ButtonReleaseMask
| ButtonPressMask
,
3703 wCursor
[WCUR_MOVE
], CurrentTime
);
3708 switch (dock
->type
) {
3710 x
= ev
.xmotion
.x_root
- ofs_x
;
3711 y
= ev
.xmotion
.y_root
- ofs_y
;
3712 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3713 moveDock(dock
, x
, y
);
3716 x
= ev
.xmotion
.x_root
- ofs_x
;
3717 y
= ev
.xmotion
.y_root
- ofs_y
;
3718 if (previously_on_right
)
3720 now_on_right
= (ev
.xmotion
.x_root
>= previous_x_pos
- ICON_SIZE
);
3724 now_on_right
= (ev
.xmotion
.x_root
> previous_x_pos
+ ICON_SIZE
* 2);
3726 if (now_on_right
!= dock
->on_right_side
)
3728 dock
->on_right_side
= now_on_right
;
3730 wArrangeIcons(scr
, False
);
3732 // Also perform the vertical move
3733 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3734 moveDock(dock
, dock
->x_pos
, y
);
3735 if (wPreferences
.flags
.wrap_appicons_in_dock
)
3737 for (i
= 0; i
< dock
->max_icons
; i
++) {
3738 int new_y
, new_index
, j
, ok
;
3739 if ((tmpaicon
= dock
->icon_array
[i
]) == NULL
)
3741 if (onScreen(scr
, tmpaicon
->x_pos
, tmpaicon
->y_pos
))
3743 new_y
= (tmpaicon
->y_pos
+ ICON_SIZE
* dock
->max_icons
) % (ICON_SIZE
* dock
->max_icons
);
3744 new_index
= (new_y
- dock
->y_pos
) / ICON_SIZE
;
3745 if (!onScreen(scr
, tmpaicon
->x_pos
, new_y
))
3748 for (j
= 0; j
< dock
->max_icons
; j
++)
3750 if (dock
->icon_array
[j
] != NULL
&&
3751 dock
->icon_array
[j
]->yindex
== new_index
)
3757 if (!ok
|| getDrawer(scr
, new_index
) != NULL
)
3759 wDockReattachIcon(dock
, tmpaicon
, tmpaicon
->xindex
, new_index
);
3761 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3763 int new_y
, new_index
, j
, ok
;
3764 tmpaicon
= dc
->adrawer
->icon_array
[0];
3765 if (onScreen(scr
, tmpaicon
->x_pos
, tmpaicon
->y_pos
))
3767 new_y
= (tmpaicon
->y_pos
+ ICON_SIZE
* dock
->max_icons
) % (ICON_SIZE
* dock
->max_icons
);
3768 new_index
= (new_y
- dock
->y_pos
) / ICON_SIZE
;
3769 if (!onScreen(scr
, tmpaicon
->x_pos
, new_y
))
3772 for (j
= 0; j
< dock
->max_icons
; j
++)
3774 if (dock
->icon_array
[j
] != NULL
&&
3775 dock
->icon_array
[j
]->yindex
== new_index
)
3781 if (!ok
|| getDrawer(scr
, new_index
) != NULL
)
3783 moveDock(dc
->adrawer
, tmpaicon
->x_pos
, new_y
);
3789 WDock
*real_dock
= dock
->screen_ptr
->dock
;
3792 x
= ev
.xmotion
.x_root
- ofs_x
;
3793 y
= ev
.xmotion
.y_root
- ofs_y
;
3794 snapped
= wDockSnapIcon(real_dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3796 shad_x
= real_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3797 shad_y
= real_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3798 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3800 moveDock(dock
, x
, y
);
3810 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3812 XUngrabPointer(dpy
, CurrentTime
);
3813 if (dock
->type
== WM_DRAWER
) {
3814 Window
*wins
[dock
->icon_count
];
3816 for (i
= 0; i
< dock
->max_icons
; i
++) {
3817 if ((tmpaicon
= dock
->icon_array
[i
]) == NULL
)
3819 wins
[ tmpaicon
->xindex
+ (dock
->on_right_side
? dock
->icon_count
- 1 : 0) ] = &tmpaicon
->icon
->core
->window
;
3821 SlideWindows(wins
, dock
->icon_count
,
3822 (dock
->on_right_side
? x
- (dock
->icon_count
- 1) * ICON_SIZE
: x
),
3824 (dock
->on_right_side
? shad_x
- (dock
->icon_count
- 1) * ICON_SIZE
: shad_x
),
3826 XUnmapWindow(dpy
, scr
->dock_shadow
);
3827 moveDock(dock
, shad_x
, shad_y
);
3828 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3836 XFreePixmap(dpy
, ghost
);
3837 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3842 static int getClipButton(int px
, int py
)
3844 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3846 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3849 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3850 return CLIP_FORWARD
;
3851 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3857 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3860 int done
, direction
, new_ws
;
3862 WDock
*clip
= scr
->clip_icon
->dock
;
3864 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3866 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3867 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3869 wClipIconPaint(scr
->clip_icon
);
3872 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3879 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3880 if (new_dir
!= direction
) {
3881 direction
= new_dir
;
3882 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3883 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3884 wClipIconPaint(scr
->clip_icon
);
3892 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3897 clip
->lclip_button_pushed
= 0;
3898 clip
->rclip_button_pushed
= 0;
3900 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3902 if (direction
== CLIP_FORWARD
) {
3903 if (scr
->current_workspace
< scr
->workspace_count
- 1)
3904 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3905 else if (new_ws
&& scr
->current_workspace
< MAX_WORKSPACES
- 1)
3906 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
3907 else if (wPreferences
.ws_cycle
)
3908 wWorkspaceChange(scr
, 0);
3909 } else if (direction
== CLIP_REWIND
) {
3910 if (scr
->current_workspace
> 0)
3911 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
3912 else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
)
3913 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
3916 wClipIconPaint(scr
->clip_icon
);
3919 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3921 WAppIcon
*aicon
= desc
->parent
;
3922 WDock
*dock
= aicon
->dock
;
3923 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3925 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3928 scr
->last_dock
= dock
;
3930 if (dock
->menu
->flags
.mapped
)
3931 wMenuUnmap(dock
->menu
);
3933 if (IsDoubleClick(scr
, event
)) {
3934 /* double-click was not in the main clip icon */
3935 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3936 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3937 iconDblClick(desc
, event
);
3942 if (event
->xbutton
.button
== Button1
) {
3943 if (event
->xbutton
.state
& MOD_MASK
)
3948 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
&& dock
->type
!= WM_DOCK
) {
3949 wIconSelect(aicon
->icon
);
3953 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3954 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
&&
3955 (dock
->type
== WM_CLIP
|| (dock
->type
== WM_DOCK
&& wPreferences
.flags
.clip_merged_in_dock
)))
3956 handleClipChangeWorkspace(scr
, event
);
3958 handleDockMove(dock
, aicon
, event
);
3960 Bool hasMoved
= wHandleAppIconMove(aicon
, event
);
3961 if (wPreferences
.single_click
&& !hasMoved
)
3962 iconDblClick(desc
, event
);
3964 } else if (event
->xbutton
.button
== Button2
&& aicon
== scr
->clip_icon
) {
3965 if (!scr
->clip_ws_menu
) {
3966 scr
->clip_ws_menu
= wWorkspaceMenuMake(scr
, False
);
3968 if (scr
->clip_ws_menu
) {
3969 WMenu
*wsMenu
= scr
->clip_ws_menu
;
3972 wWorkspaceMenuUpdate(scr
, wsMenu
);
3974 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
3977 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
3978 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
3980 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
3982 desc
= &wsMenu
->menu
->descriptor
;
3983 event
->xany
.send_event
= True
;
3984 (*desc
->handle_mousedown
) (desc
, event
);
3986 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
3987 (event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
) {
3988 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3989 } else if (event
->xbutton
.button
== Button3
) {
3990 if (event
->xbutton
.send_event
&&
3991 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3992 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3993 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3994 wwarning("pointer grab failed for dockicon menu");
3998 openDockMenu(dock
, aicon
, event
);
3999 } else if (event
->xbutton
.button
== Button2
) {
4000 WAppIcon
*btn
= desc
->parent
;
4002 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
4003 launchDockedApplication(btn
, True
);
4007 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
4009 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
4013 assert(event
->type
== EnterNotify
);
4015 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
4018 scr
= btn
->icon
->core
->screen_ptr
;
4024 /* The auto raise/lower code */
4025 tmp
= (dock
->type
== WM_DRAWER
? scr
->dock
: dock
);
4026 if (tmp
->auto_lower_magic
) {
4027 WMDeleteTimerHandler(tmp
->auto_lower_magic
);
4028 tmp
->auto_lower_magic
= NULL
;
4030 if (tmp
->auto_raise_lower
&& !tmp
->auto_raise_magic
)
4031 tmp
->auto_raise_magic
= WMAddTimerHandler(wPreferences
.clip_auto_raise_delay
, clipAutoRaise
, (void *) tmp
);
4033 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4036 /* The auto expand/collapse code */
4037 if (dock
->auto_collapse_magic
) {
4038 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
4039 dock
->auto_collapse_magic
= NULL
;
4041 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
)
4042 dock
->auto_expand_magic
= WMAddTimerHandler(wPreferences
.clip_auto_expand_delay
, clipAutoExpand
, (void *)dock
);
4045 static void clipLeave(WDock
*dock
)
4048 WObjDescriptor
*desc
= NULL
;
4054 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
4055 if (XFindContext(dpy
, event
.xcrossing
.window
, wWinContext
,
4056 (XPointer
*) & desc
) != XCNOENT
4057 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
4058 && ((WAppIcon
*) desc
->parent
)->dock
== dock
) {
4059 /* We haven't left the dock/clip/drawer yet */
4060 XPutBackEvent(dpy
, &event
);
4064 XPutBackEvent(dpy
, &event
);
4066 /* We entered a withdrawn window, so we're still in Clip */
4070 tmp
= (dock
->type
== WM_DRAWER
? dock
->screen_ptr
->dock
: dock
);
4071 if (tmp
->auto_raise_magic
) {
4072 WMDeleteTimerHandler(tmp
->auto_raise_magic
);
4073 tmp
->auto_raise_magic
= NULL
;
4075 if (tmp
->auto_raise_lower
&& !tmp
->auto_lower_magic
)
4076 tmp
->auto_lower_magic
= WMAddTimerHandler(wPreferences
.clip_auto_lower_delay
, clipAutoLower
, (void *)tmp
);
4078 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4081 if (dock
->auto_expand_magic
) {
4082 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4083 dock
->auto_expand_magic
= NULL
;
4085 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
)
4086 dock
->auto_collapse_magic
= WMAddTimerHandler(wPreferences
.clip_auto_collapse_delay
, clipAutoCollapse
, (void *)dock
);
4089 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4091 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
4093 assert(event
->type
== LeaveNotify
);
4095 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
4098 clipLeave(btn
->dock
);
4101 static void clipAutoCollapse(void *cdata
)
4103 WDock
*dock
= (WDock
*) cdata
;
4105 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4108 if (dock
->auto_collapse
) {
4109 dock
->collapsed
= 1;
4110 wDockHideIcons(dock
);
4112 dock
->auto_collapse_magic
= NULL
;
4115 static void clipAutoExpand(void *cdata
)
4117 WDock
*dock
= (WDock
*) cdata
;
4119 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4122 if (dock
->auto_collapse
) {
4123 dock
->collapsed
= 0;
4124 wDockShowIcons(dock
);
4126 dock
->auto_expand_magic
= NULL
;
4129 static void clipAutoLower(void *cdata
)
4131 WDock
*dock
= (WDock
*) cdata
;
4133 if (dock
->auto_raise_lower
)
4136 dock
->auto_lower_magic
= NULL
;
4139 static void clipAutoRaise(void *cdata
)
4141 WDock
*dock
= (WDock
*) cdata
;
4143 if (dock
->auto_raise_lower
)
4146 dock
->auto_raise_magic
= NULL
;
4149 static Bool
iconCanBeOmnipresent(WAppIcon
*aicon
)
4151 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4156 for (i
= 0; i
< scr
->workspace_count
; i
++) {
4157 clip
= scr
->workspaces
[i
]->clip
;
4159 if (clip
== aicon
->dock
)
4162 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4163 return False
; /* Clip is full in some workspace */
4165 for (j
= 0; j
< clip
->max_icons
; j
++) {
4166 btn
= clip
->icon_array
[j
];
4167 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
4175 int wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
4177 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4178 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4179 int status
= WO_SUCCESS
;
4181 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== scr
->clip_icon
)
4182 return WO_NOT_APPLICABLE
;
4184 if (aicon
->omnipresent
== omnipresent
)
4188 if (iconCanBeOmnipresent(aicon
)) {
4189 aicon
->omnipresent
= 1;
4190 new_entry
= wmalloc(sizeof(WAppIconChain
));
4191 new_entry
->aicon
= aicon
;
4192 new_entry
->next
= scr
->global_icons
;
4193 scr
->global_icons
= new_entry
;
4194 scr
->global_icon_count
++;
4196 aicon
->omnipresent
= 0;
4200 aicon
->omnipresent
= 0;
4201 if (aicon
== scr
->global_icons
->aicon
) {
4202 tmp
= scr
->global_icons
->next
;
4203 wfree(scr
->global_icons
);
4204 scr
->global_icons
= tmp
;
4205 scr
->global_icon_count
--;
4207 tmp
= scr
->global_icons
;
4209 if (tmp
->next
->aicon
== aicon
) {
4210 tmp1
= tmp
->next
->next
;
4213 scr
->global_icon_count
--;
4221 wAppIconPaint(aicon
);
4226 static void drawerAppendToChain(WScreen
*scr
, WDock
*drawer
)
4228 WDrawerChain
**where_to_add
;
4230 where_to_add
= &scr
->drawers
;
4231 while ((*where_to_add
) != NULL
) {
4232 where_to_add
= &(*where_to_add
)->next
;
4235 *where_to_add
= wmalloc(sizeof(WDrawerChain
));
4236 (*where_to_add
)->adrawer
= drawer
;
4237 (*where_to_add
)->next
= NULL
;
4238 scr
->drawer_count
++;
4242 static void drawerRemoveFromChain(WScreen
*scr
, WDock
*drawer
)
4244 WDrawerChain
*next
, **to_remove
;
4246 to_remove
= &scr
->drawers
;
4248 if (*to_remove
== NULL
) {
4249 wwarning("The drawer to be removed can not be found.");
4252 if ((*to_remove
)->adrawer
== drawer
)
4255 to_remove
= &(*to_remove
)->next
;
4257 next
= (*to_remove
)->next
;
4260 scr
->drawer_count
--;
4264 /* Don't free the returned string. Duplicate it. */
4265 static char * findUniqueName(WScreen
*scr
, const char *instance_basename
)
4267 static char buffer
[128];
4270 Bool already_in_use
= True
;
4272 #define UNIQUE_NAME_WATCHDOG 128
4273 for (i
= 0; already_in_use
&& i
< UNIQUE_NAME_WATCHDOG
; i
++) {
4274 snprintf(buffer
, sizeof buffer
, "%s%d", instance_basename
, i
);
4276 already_in_use
= False
;
4278 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4279 if (!strncmp(dc
->adrawer
->icon_array
[0]->wm_instance
, buffer
,
4281 already_in_use
= True
;
4287 if (i
== UNIQUE_NAME_WATCHDOG
)
4288 wwarning("Couldn't find a unique name for drawer in %d attemps.", i
);
4289 #undef UNIQUE_NAME_WATCHDOG
4295 static void drawerIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
4297 wDrawerIconPaint((WAppIcon
*) desc
->parent
);
4301 static int addADrawer(WScreen
*scr
)
4303 int i
, y
, sig
, found_y
;
4304 WDock
*drawer
, *dock
= scr
->dock
;
4306 char can_be_here
[2 * dock
->max_icons
- 1];
4308 if (dock
->icon_count
+ scr
->drawer_count
>= dock
->max_icons
)
4311 for (y
= -dock
->max_icons
+ 1; y
< dock
->max_icons
; y
++) {
4312 can_be_here
[y
+ dock
->max_icons
- 1] = True
;
4314 for (i
= 0; i
< dock
->max_icons
; i
++) {
4315 if (dock
->icon_array
[i
] != NULL
)
4316 can_be_here
[dock
->icon_array
[i
]->yindex
+ dock
->max_icons
- 1] = False
;
4318 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4319 y
= (int) ((dc
->adrawer
->y_pos
- dock
->y_pos
) / ICON_SIZE
);
4320 can_be_here
[y
+ dock
->max_icons
- 1] = False
;
4324 for (sig
= 1; !found_y
&& sig
> -2; sig
-= 2) // 1, then -1
4326 for (y
= sig
; sig
* y
< dock
->max_icons
; y
+= sig
)
4328 if (can_be_here
[y
+ dock
->max_icons
- 1] &&
4329 onScreen(scr
, dock
->x_pos
, dock
->y_pos
+ y
* ICON_SIZE
))
4338 /* This can happen even when dock->icon_count + scr->drawer_count
4339 * < dock->max_icons when the dock is not aligned on an
4340 * ICON_SIZE multiple, as some space is lost above and under it */
4343 drawer
= wDockCreate(scr
, WM_DRAWER
, NULL
);
4344 drawer
->lowered
= scr
->dock
->lowered
;
4345 drawer
->auto_raise_lower
= scr
->dock
->auto_raise_lower
;
4346 drawer
->x_pos
= dock
->x_pos
;
4347 drawer
->y_pos
= dock
->y_pos
+ ICON_SIZE
* y
;
4348 drawer
->icon_array
[0]->xindex
= 0;
4349 drawer
->icon_array
[0]->yindex
= 0;
4350 drawer
->icon_array
[0]->x_pos
= drawer
->x_pos
;
4351 drawer
->icon_array
[0]->y_pos
= drawer
->y_pos
;
4352 XMoveWindow(dpy
, drawer
->icon_array
[0]->icon
->core
->window
,
4353 drawer
->icon_array
[0]->x_pos
, drawer
->icon_array
[0]->y_pos
);
4359 static void addADrawerCallback(WMenu
*menu
, WMenuEntry
*entry
)
4361 assert(entry
->clientdata
!=NULL
);
4362 addADrawer(((WAppIcon
*) entry
->clientdata
)->dock
->screen_ptr
);
4366 static void drawerDestroy(WDock
*drawer
)
4376 scr
= drawer
->screen_ptr
;
4378 /* Note regarding menus: we can't delete any dock/clip/drawer menu, because
4379 * that would (attempt to) wfree some memory in gettext library (see menu
4380 * entries that have several "versions", such like "Hide" and "Unhide"). */
4382 wDefaultPurgeInfo(scr
, drawer
->icon_array
[0]->wm_instance
,
4383 drawer
->icon_array
[0]->wm_class
);
4384 icons
= WMCreateArray(drawer
->icon_count
- 1);
4385 for (i
= 1; i
< drawer
->max_icons
; i
++) {
4386 if (!(aicon
= drawer
->icon_array
[i
]))
4388 WMAddToArray(icons
, aicon
);
4390 removeIcons(icons
, drawer
);
4392 if (drawer
->auto_collapse_magic
) {
4393 WMDeleteTimerHandler(drawer
->auto_collapse_magic
);
4394 drawer
->auto_collapse_magic
= NULL
;
4396 if (drawer
->auto_lower_magic
) {
4397 WMDeleteTimerHandler(drawer
->auto_lower_magic
);
4398 drawer
->auto_lower_magic
= NULL
;
4401 wAppIconDestroy(drawer
->icon_array
[0]);
4402 wfree(drawer
->icon_array
);
4405 drawerRemoveFromChain(scr
, drawer
);
4406 if (scr
->last_dock
== drawer
)
4407 scr
->last_dock
= NULL
;
4408 if (scr
->attracting_drawer
== drawer
)
4409 scr
->attracting_drawer
= NULL
;
4413 static void removeDrawerCallback(WMenu
*menu
, WMenuEntry
*entry
)
4415 WDock
*dock
= ((WAppIcon
*)entry
->clientdata
)->dock
;
4416 assert(dock
!= NULL
);
4418 if (dock
->icon_count
> 1) {
4419 if (wMessageDialog(dock
->screen_ptr
, _("Drawer"),
4420 _("All icons in this drawer will be detached!"),
4421 _("OK"), _("Cancel"), NULL
) != WAPRDefault
)
4424 drawerDestroy(dock
);
4428 void wDrawerIconPaint(WAppIcon
*dicon
)
4430 Window win
= dicon
->icon
->core
->window
;
4431 WScreen
*scr
= dicon
->icon
->core
->screen_ptr
;
4433 GC gc
= scr
->draw_gc
;
4436 wIconPaint(dicon
->icon
);
4438 if (!dicon
->dock
->collapsed
)
4439 color
= scr
->clip_title_color
[CLIP_NORMAL
];
4441 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
4442 XSetForeground(dpy
, gc
, WMColorPixel(color
));
4444 if (dicon
->dock
->on_right_side
) {
4445 p
[0].x
= p
[3].x
= 10;
4446 p
[0].y
= p
[3].y
= ICON_SIZE
/ 2 - 5;
4448 p
[1].y
= ICON_SIZE
/ 2 + 5;
4450 p
[2].y
= ICON_SIZE
/ 2;
4453 p
[0].x
= p
[3].x
= ICON_SIZE
-1 - 10;
4454 p
[0].y
= p
[3].y
= ICON_SIZE
/ 2 - 5;
4455 p
[1].x
= ICON_SIZE
-1 - 10;
4456 p
[1].y
= ICON_SIZE
/ 2 + 5;
4457 p
[2].x
= ICON_SIZE
-1 - 5;
4458 p
[2].y
= ICON_SIZE
/ 2;
4460 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
4461 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
4465 RImage
* wDrawerMakeTile(WScreen
*scr
, RImage
*normalTile
)
4467 RImage
*tile
= RCloneImage(normalTile
);
4472 dark
.red
= dark
.green
= dark
.blue
= 60;
4475 light
.red
= light
.green
= light
.blue
= 80;
4478 if (!scr
->dock
|| scr
->dock
->on_right_side
) {
4479 ROperateLine(tile
, RSubtractOperation
, 11, ICON_SIZE
/ 2 - 7,
4480 4, ICON_SIZE
/ 2, &dark
); /* / */
4481 ROperateLine(tile
, RSubtractOperation
, 11, ICON_SIZE
/ 2 + 7,
4482 4, ICON_SIZE
/ 2, &dark
); /* \ */
4483 ROperateLine(tile
, RAddOperation
, 11, ICON_SIZE
/ 2 - 7,
4484 11, ICON_SIZE
/ 2 + 7, &light
); /* | */
4487 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 - 7,
4488 ICON_SIZE
-1 - 4, ICON_SIZE
/ 2, &dark
); /* \ */
4489 ROperateLine(tile
, RAddOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 + 7,
4490 ICON_SIZE
-1 - 4, ICON_SIZE
/ 2, &light
); /* / */
4491 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 - 7,
4492 ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 + 7, &dark
); /* | */
4498 static void swapDrawer(WDock
*drawer
, int new_x
)
4502 drawer
->on_right_side
= !drawer
->on_right_side
;
4503 drawer
->x_pos
= new_x
;
4505 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4507 if ((ai
= drawer
->icon_array
[i
]) == NULL
)
4509 ai
->xindex
*= -1; /* so A B C becomes C B A */
4510 ai
->x_pos
= new_x
+ ai
->xindex
* ICON_SIZE
;
4512 /* Update drawer's tile */
4514 wIconUpdate(ai
->icon
);
4515 wDrawerIconPaint(ai
);
4517 XMoveWindow(dpy
, ai
->icon
->core
->window
, ai
->x_pos
, ai
->y_pos
);
4522 static void swapDrawers(WScreen
*scr
, int on_right_side
, int new_x
)
4526 if (scr
->drawer_tile
) {
4527 RReleaseImage(scr
->drawer_tile
);
4529 scr
->drawer_tile
= wDrawerMakeTile(scr
, scr
->icon_tile
);
4531 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4532 swapDrawer(dc
->adrawer
, new_x
);
4533 assert(dc
->adrawer
->on_right_side
== on_right_side
);
4538 int wIsADrawer(WScreen
*scr
, WAppIcon
*aicon
)
4540 return aicon
&& aicon
->dock
&&
4541 aicon
->dock
->type
== WM_DRAWER
&& aicon
->dock
->icon_array
[0] == aicon
;
4545 static WDock
* getDrawer(WScreen
*scr
, int y_index
)
4549 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4550 if (dc
->adrawer
->y_pos
- scr
->dock
->y_pos
== y_index
* ICON_SIZE
)
4558 /* Find the "hole" a moving appicon created when snapped into the
4559 * drawer. redocking is a boolean. If the moving appicon comes from the
4560 * drawer, drawer->icon_count is correct. If not, redocking is then false and
4561 * there are now drawer->icon_count plus one appicons in the drawer. */
4562 static int indexOfHole(WDock
*drawer
, WAppIcon
*moving_aicon
, int redocking
)
4564 int index_of_hole
, i
;
4566 /* Classic interview question...
4568 * We have n-1 (n = drawer->icon_count-1 or drawer->icon_count, see
4569 * redocking) appicons, whose xindex are unique in [1..n]. One is missing:
4570 * that's where the ghost of the moving appicon is, that's what the
4571 * function should return.
4573 * We compute 1+2+...+n (this sum is equal to n*(n+1)/2), we substract to
4574 * this sum the xindex of each of the n-1 appicons, and we get the correct
4578 index_of_hole
= (drawer
->icon_count
- 1) * drawer
->icon_count
/ 2;
4580 index_of_hole
= drawer
->icon_count
* (drawer
->icon_count
+ 1) / 2;
4582 index_of_hole
*= (drawer
->on_right_side
? -1 : 1);
4584 for (i
= 1; i
< drawer
->max_icons
; i
++) {
4585 if (drawer
->icon_array
[i
] && drawer
->icon_array
[i
] != moving_aicon
)
4586 index_of_hole
-= drawer
->icon_array
[i
]->xindex
;
4588 /* wmessage(" Index of the moving appicon is %d (%sredocking)", index_of_hole, (redocking ? "" : "not ")); */
4589 if (abs(index_of_hole
) > abs(drawer
->icon_count
) - (redocking
? 1 : 0))
4590 wwarning(" index_of_hole is too large ! (%d greater than %d)",
4591 index_of_hole
, abs(drawer
->icon_count
) - (redocking
? 1 : 0));
4592 if (index_of_hole
== 0)
4593 wwarning(" index_of_hole == 0 (%sredocking, icon_count == %d)", (redocking
? "" : "not "), drawer
->icon_count
);
4595 return index_of_hole
;
4599 void wSlideAppicons(WAppIcon
**appicons
, int n
, int to_the_left
)
4602 int leftmost
= -1, min_index
= 9999, from_x
= -1; // leftmost and from_x initialized to avoid warning
4609 for (i
= 0; i
< n
; i
++) {
4610 aicon
= appicons
[i
];
4611 aicon
->xindex
+= (to_the_left
? -1 : +1);
4612 if (aicon
->xindex
< min_index
) {
4613 min_index
= aicon
->xindex
;
4615 from_x
= aicon
->x_pos
;
4617 aicon
->x_pos
+= (to_the_left
? -ICON_SIZE
: +ICON_SIZE
);
4620 for (i
= 0; i
< n
; i
++) {
4621 aicon
= appicons
[i
];
4622 wins
[aicon
->xindex
- min_index
] = &aicon
->icon
->core
->window
;
4624 aicon
= appicons
[leftmost
];
4625 SlideWindows(wins
, n
, from_x
, aicon
->y_pos
, aicon
->x_pos
, aicon
->y_pos
);
4629 void wDrawerFillTheGap(WDock
*drawer
, WAppIcon
*aicon
, Bool redocking
)
4632 int index_of_hole
= indexOfHole(drawer
, aicon
, redocking
);
4633 WAppIcon
*aicons_to_shift
[drawer
->icon_count
];
4636 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4637 WAppIcon
*ai
= drawer
->icon_array
[i
];
4638 if (ai
&& ai
!= aicon
&&
4639 abs(ai
->xindex
) > abs(index_of_hole
))
4640 aicons_to_shift
[j
++] = ai
;
4642 if (j
!= drawer
->icon_count
- abs(index_of_hole
) - (redocking
? 1 : 0))
4643 wwarning("Removing aicon at index %d from %s: j=%d but should be %d",
4644 index_of_hole
, drawer
->icon_array
[0]->wm_instance
,
4645 j
, drawer
->icon_count
- abs(index_of_hole
) - (redocking
? 1 : 0));
4646 wSlideAppicons(aicons_to_shift
, j
, !drawer
->on_right_side
);
4650 static void drawerConsolidateIcons(WDock
*drawer
)
4652 WAppIcon
*aicons_to_shift
[drawer
->icon_count
];
4653 int maxRemaining
= 0;
4656 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4657 WAppIcon
*ai
= drawer
->icon_array
[i
];
4660 sum
+= abs(ai
->xindex
);
4661 if (abs(ai
->xindex
) > maxRemaining
)
4662 maxRemaining
= abs(ai
->xindex
);
4664 while (sum
!= maxRemaining
* (maxRemaining
+ 1) / 2) { // while there is a hole
4667 // Look up for the hole at max position
4669 for (maxDeleted
= maxRemaining
- 1; maxDeleted
> 0; maxDeleted
--) {
4670 Bool foundAppIconThere
= False
;
4671 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4672 WAppIcon
*ai
= drawer
->icon_array
[i
];
4675 if (abs(ai
->xindex
) == maxDeleted
) {
4676 foundAppIconThere
= True
;
4680 if (!foundAppIconThere
)
4683 assert(maxDeleted
> 0); // would mean while test is wrong
4685 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4686 ai
= drawer
->icon_array
[i
];
4687 if (ai
!= NULL
&& abs(ai
->xindex
) > maxDeleted
)
4688 aicons_to_shift
[n
++] = ai
;
4690 assert(n
== maxRemaining
- maxDeleted
); // for the code review ;-)
4691 wSlideAppicons(aicons_to_shift
, n
, !drawer
->on_right_side
);
4692 // Efficient beancounting
4700 /* similar to wDockRestoreState, but a lot a specific stuff too... */
4701 static WDock
* drawerRestoreState(WScreen
*scr
, WMPropList
*drawer_state
)
4704 WMPropList
*apps
, *value
, *dock_state
;
4713 WMRetainPropList(drawer_state
);
4715 /* Get the instance name, and create a drawer */
4716 value
= WMGetFromPLDictionary(drawer_state
, dName
);
4717 drawer
= wDockCreate(scr
, WM_DRAWER
, WMGetFromPLString(value
));
4719 /* restore DnD command and paste command */
4721 value
= WMGetFromPLDictionary(drawer_state
, dDropCommand
);
4722 if (value
&& WMIsPLString(value
))
4723 drawer
->icon_array
[0]->dnd_command
= wstrdup(WMGetFromPLString(value
));
4726 value
= WMGetFromPLDictionary(drawer_state
, dPasteCommand
);
4727 if (value
&& WMIsPLString(value
))
4728 drawer
->icon_array
[0]->paste_command
= wstrdup(WMGetFromPLString(value
));
4730 /* restore position */
4731 value
= WMGetFromPLDictionary(drawer_state
, dPosition
);
4732 if (!value
|| !WMIsPLString(value
))
4733 COMPLAIN("Position");
4736 if (sscanf(WMGetFromPLString(value
), "%i,%i", &x
, &y
) != 2)
4737 COMPLAIN("Position");
4739 /* check position sanity */
4740 if (x
!= scr
->dock
->x_pos
) {
4741 x
= scr
->dock
->x_pos
;
4743 y_index
= (y
- scr
->dock
->y_pos
) / ICON_SIZE
;
4744 if (y_index
>= scr
->dock
->max_icons
) {
4745 /* Here we should do something more intelligent, since it
4746 * can happen even if the user hasn't hand-edited his
4747 * G/D/State file (but uses a lower resolution). */
4748 y_index
= scr
->dock
->max_icons
- 1;
4750 y
= scr
->dock
->y_pos
+ y_index
* ICON_SIZE
;
4751 moveDock(drawer
, x
, y
);
4754 /* restore dock properties (applist and others) */
4755 dock_state
= WMGetFromPLDictionary(drawer_state
, dDock
);
4757 /* restore lowered/raised state: same as scr->dock, no matter what */
4758 drawer
->lowered
= scr
->dock
->lowered
;
4759 if (!drawer
->lowered
)
4760 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMDockLevel
);
4762 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMNormalLevel
);
4763 wRaiseFrame(drawer
->icon_array
[0]->icon
->core
);
4765 /* restore collapsed state */
4766 drawer
->collapsed
= 0;
4767 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
4768 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4769 drawer
->collapsed
= 1;
4771 /* restore auto-collapsed state */
4772 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
4773 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4774 drawer
->auto_collapse
= 1;
4775 drawer
->collapsed
= 1;
4777 drawer
->auto_collapse
= 0; // because wDockCreate sets it (drawers only)
4780 /* restore auto-raise/lower state: same as scr->dock, no matter what */
4781 drawer
->auto_raise_lower
= scr
->dock
->auto_raise_lower
;
4783 /* restore attract icons state */
4784 drawer
->attract_icons
= 0;
4785 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
4786 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4787 drawer
->attract_icons
= 1;
4788 scr
->attracting_drawer
= drawer
;
4791 /* application list */
4792 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
4798 count
= WMGetPropListItemCount(apps
);
4803 for (i
=0; i
<count
; i
++) {
4804 if (drawer
->icon_count
>= drawer
->max_icons
) {
4805 wwarning(_("there are too many icons stored in drawer. Ignoring what doesn't fit"));
4809 value
= WMGetFromPLArray(apps
, i
);
4810 aicon
= restore_icon_state(scr
, value
, WM_DRAWER
, drawer
->icon_count
);
4812 drawer
->icon_array
[drawer
->icon_count
] = aicon
;
4815 aicon
->dock
= drawer
;
4816 aicon
->x_pos
= drawer
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
4817 aicon
->y_pos
= drawer
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
4819 if (!drawer
->lowered
)
4820 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
4822 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
4824 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
4826 if (!drawer
->collapsed
)
4827 XMapWindow(dpy
, aicon
->icon
->core
->window
);
4828 wRaiseFrame(aicon
->icon
->core
);
4830 drawer
->icon_count
++;
4835 WMReleasePropList(drawer_state
);
4841 /* Same kind of comment than for previous function: this function is
4842 * very similar to make_icon_state, but has substential differences as
4844 static WMPropList
*drawerSaveState(WScreen
*scr
, WDock
*drawer
)
4846 WMPropList
*pstr
, *drawer_state
;
4850 ai
= drawer
->icon_array
[0];
4851 /* Store its name */
4852 pstr
= WMCreatePLString(ai
->wm_instance
);
4853 drawer_state
= WMCreatePLDictionary(dName
, pstr
, NULL
); /* we need this final NULL */
4854 WMReleasePropList(pstr
);
4856 /* Store its position */
4857 snprintf(buffer
, sizeof(buffer
), "%i,%i", ai
->x_pos
, ai
->y_pos
);
4858 pstr
= WMCreatePLString(buffer
);
4859 WMPutInPLDictionary(drawer_state
, dPosition
, pstr
);
4860 WMReleasePropList(pstr
);
4863 /* Store its DnD command */
4864 if (ai
->dnd_command
) {
4865 pstr
= WMCreatePLString(ai
->dnd_command
);
4866 WMPutInPLDictionary(drawer_state
, dDropCommand
, pstr
);
4867 WMReleasePropList(pstr
);
4871 /* Store its paste command */
4872 if (ai
->paste_command
) {
4873 pstr
= WMCreatePLString(ai
->paste_command
);
4874 WMPutInPLDictionary(drawer_state
, dPasteCommand
, pstr
);
4875 WMReleasePropList(pstr
);
4878 /* Store applications list and other properties */
4879 pstr
= dockSaveState(drawer
);
4880 WMPutInPLDictionary(drawer_state
, dDock
, pstr
);
4881 WMReleasePropList(pstr
);
4883 return drawer_state
;
4887 void wDrawersSaveState(WScreen
*scr
)
4889 WMPropList
*all_drawers
, *drawer_state
;
4895 all_drawers
= WMCreatePLArray(NULL
);
4896 for (i
=0, dc
= scr
->drawers
;
4897 i
< scr
->drawer_count
;
4898 i
++, dc
= dc
->next
) {
4899 drawer_state
= drawerSaveState(scr
, dc
->adrawer
);
4900 WMAddToPLArray(all_drawers
, drawer_state
);
4901 WMReleasePropList(drawer_state
);
4903 WMPutInPLDictionary(scr
->session_state
, dDrawers
, all_drawers
);
4904 WMReleasePropList(all_drawers
);
4908 void wDrawersRestoreState(WScreen
*scr
)
4910 WMPropList
*all_drawers
, *drawer_state
;
4915 if (scr
->session_state
== NULL
)
4918 all_drawers
= WMGetFromPLDictionary(scr
->session_state
, dDrawers
);
4922 for (i
= 0; i
< WMGetPropListItemCount(all_drawers
); i
++) {
4923 drawer_state
= WMGetFromPLArray(all_drawers
, i
);
4924 drawerRestoreState(scr
, drawer_state
);
4925 // Note: scr->drawers was updated when the the drawer was created