1 /* dock.c- built-in Dock module for WindowMaker
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <X11/Xutil.h>
37 #define PATH_MAX DEFAULT_PATH_MAX
40 #include "WindowMaker.h"
48 #include "dockedapp.h"
51 #include "properties.h"
55 #include "workspace.h"
57 #include "superfluous.h"
59 #include "placement.h"
63 /**** Local variables ****/
66 #define CLIP_FORWARD 2
68 #define MOD_MASK wPreferences.modifier_mask
69 #define ICON_SIZE wPreferences.icon_size
71 /***** Local variables ****/
73 static WMPropList
*dCommand
= NULL
;
74 static WMPropList
*dPasteCommand
= NULL
;
75 #ifdef XDND /* XXX was OFFIX */
76 static WMPropList
*dDropCommand
= NULL
;
78 static WMPropList
*dAutoLaunch
, *dLock
;
79 static WMPropList
*dName
, *dForced
, *dBuggyApplication
, *dYes
, *dNo
;
80 static WMPropList
*dHost
, *dDock
, *dClip
;
81 static WMPropList
*dAutoAttractIcons
;
83 static WMPropList
*dPosition
, *dApplications
, *dLowered
, *dCollapsed
;
85 static WMPropList
*dAutoCollapse
, *dAutoRaiseLower
, *dOmnipresent
;
87 static WMPropList
*dDrawers
= NULL
;
89 static void dockIconPaint(WAppIcon
*btn
);
91 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
93 static pid_t
execCommand(WAppIcon
*btn
, const char *command
, WSavedState
*state
);
95 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
97 static int getClipButton(int px
, int py
);
99 static void toggleLowered(WDock
*dock
);
101 static void toggleCollapsed(WDock
*dock
);
103 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
105 static void clipLeave(WDock
*dock
);
107 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
109 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
110 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
111 static void clipAutoCollapse(void *cdata
);
112 static void clipAutoExpand(void *cdata
);
113 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
);
115 static void clipAutoLower(void *cdata
);
116 static void clipAutoRaise(void *cdata
);
117 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
, const char *name
);
119 static void drawerIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
120 static void removeDrawerCallback(WMenu
*menu
, WMenuEntry
*entry
);
121 static void drawerAppendToChain(WScreen
*scr
, WDock
*drawer
);
122 static char *findUniqueName(WScreen
*scr
, const char *instance_basename
);
123 static void addADrawerCallback(WMenu
*menu
, WMenuEntry
*entry
);
124 static void swapDrawers(WScreen
*scr
, int on_right_side
, int new_x
);
125 static WDock
* getDrawer(WScreen
*scr
, int y_index
);
126 static int indexOfHole(WDock
*drawer
, WAppIcon
*moving_aicon
, int redocking
);
127 static void drawerConsolidateIcons(WDock
*drawer
);
129 static int onScreen(WScreen
*scr
, int x
, int y
);
131 static void make_keys(void)
133 if (dCommand
!= NULL
)
136 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
137 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
139 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
141 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
142 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
143 dName
= WMRetainPropList(WMCreatePLString("Name"));
144 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
145 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
146 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
147 dNo
= WMRetainPropList(WMCreatePLString("No"));
148 dHost
= WMRetainPropList(WMCreatePLString("Host"));
150 dPosition
= WMCreatePLString("Position");
151 dApplications
= WMCreatePLString("Applications");
152 dLowered
= WMCreatePLString("Lowered");
153 dCollapsed
= WMCreatePLString("Collapsed");
154 dAutoCollapse
= WMCreatePLString("AutoCollapse");
155 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
156 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
158 dOmnipresent
= WMCreatePLString("Omnipresent");
160 dDock
= WMCreatePLString("Dock");
161 dClip
= WMCreatePLString("Clip");
162 dDrawers
= WMCreatePLString("Drawers");
165 static void renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
167 WDock
*dock
= entry
->clientdata
;
172 assert(entry
->clientdata
!= NULL
);
174 wspace
= w_global
.workspace
.current
;
176 name
= wstrdup(w_global
.workspace
.array
[wspace
]->name
);
178 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+ 1);
179 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
, &name
))
180 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
185 static void toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
187 assert(entry
->clientdata
!= NULL
);
189 toggleLowered(entry
->clientdata
);
191 entry
->flags
.indicator_on
= !(((WDock
*) entry
->clientdata
)->lowered
);
196 static int matchWindow(const void *item
, const void *cdata
)
198 return (((WFakeGroupLeader
*) item
)->leader
== (Window
) cdata
);
201 static void killCallback(WMenu
*menu
, WMenuEntry
*entry
)
203 WScreen
*scr
= menu
->menu
->screen_ptr
;
205 WFakeGroupLeader
*fPtr
;
206 char *buffer
, *shortname
, **argv
;
209 if (!WCHECK_STATE(WSTATE_NORMAL
))
212 assert(entry
->clientdata
!= NULL
);
214 icon
= (WAppIcon
*) entry
->clientdata
;
218 WCHANGE_STATE(WSTATE_MODAL
);
220 /* strip away dir names */
221 shortname
= basename(icon
->command
);
222 /* separate out command options */
223 wtokensplit(shortname
, &argv
, &argc
);
225 buffer
= wstrconcat(argv
[0],
226 _(" will be forcibly closed.\n"
227 "Any unsaved changes will be lost.\n" "Please confirm."));
229 if (icon
->icon
&& icon
->icon
->owner
) {
230 fPtr
= icon
->icon
->owner
->fake_group
;
232 /* is this really necessary? can we kill a non-running dock icon? */
233 Window win
= icon
->main_window
;
236 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)win
);
237 if (index
!= WANotFound
)
238 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
243 if (wPreferences
.dont_confirm_kill
244 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
245 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
247 WWindow
*wwin
, *twin
;
249 wwin
= scr
->focused_window
;
252 if (wwin
->fake_group
== fPtr
)
257 } else if (icon
->icon
&& icon
->icon
->owner
) {
258 wClientKill(icon
->icon
->owner
);
263 wtokenfree(argv
, argc
);
267 WCHANGE_STATE(WSTATE_NORMAL
);
270 /* TODO: replace this function with a member of the dock struct */
271 static int numberOfSelectedIcons(WDock
*dock
)
277 for (i
= 1; i
< dock
->max_icons
; i
++) {
278 aicon
= dock
->icon_array
[i
];
279 if (aicon
&& aicon
->icon
->selected
)
286 static WMArray
*getSelected(WDock
*dock
)
288 WMArray
*ret
= WMCreateArray(8);
292 for (i
= 1; i
< dock
->max_icons
; i
++) {
293 btn
= dock
->icon_array
[i
];
294 if (btn
&& btn
->icon
->selected
)
295 WMAddToArray(ret
, btn
);
301 static void paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
303 Window win
= clipIcon
->icon
->core
->window
;
304 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
306 int pt
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
307 int tp
= ICON_SIZE
- pt
;
308 int as
= pt
- 15; /* 15 = 5+5+5 */
309 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
312 color
= scr
->clip_title_color
[CLIP_NORMAL
];
314 XSetForeground(dpy
, gc
, WMColorPixel(color
));
319 p
[1].x
= ICON_SIZE
- 2;
321 p
[2].x
= ICON_SIZE
- 2;
323 } else if (lpushed
) {
327 p
[1].y
= ICON_SIZE
- 2;
329 p
[2].y
= ICON_SIZE
- 2;
331 if (lpushed
|| rpushed
) {
332 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
333 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
334 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
337 /* top right arrow */
338 p
[0].x
= p
[3].x
= ICON_SIZE
- 5 - as
;
340 p
[1].x
= ICON_SIZE
- 6;
342 p
[2].x
= ICON_SIZE
- 6;
345 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
346 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
348 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
349 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
352 /* bottom left arrow */
354 p
[0].y
= p
[3].y
= ICON_SIZE
- 5 - as
;
356 p
[1].y
= ICON_SIZE
- 6;
358 p
[2].y
= ICON_SIZE
- 6;
360 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
361 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
363 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
364 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
368 RImage
*wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
370 RImage
*tile
= RCloneImage(normalTile
);
377 pt
= CLIP_BUTTON_SIZE
* wPreferences
.icon_size
/ 64;
378 tp
= wPreferences
.icon_size
- 1 - pt
;
382 black
.red
= black
.green
= black
.blue
= 0;
385 dark
.red
= dark
.green
= dark
.blue
= 60;
388 light
.red
= light
.green
= light
.blue
= 80;
391 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
- 2, pt
- 1, &dark
);
392 RDrawLine(tile
, tp
- 1, 0, wPreferences
.icon_size
- 1, pt
+ 1, &black
);
393 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
- 3, pt
, &light
);
396 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, 4, &dark
);
397 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 5, 6 + as
, &dark
);
398 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
, &light
);
401 ROperateLine(tile
, RAddOperation
, 2, tp
+ 2, pt
- 2, wPreferences
.icon_size
- 3, &dark
);
402 RDrawLine(tile
, 0, tp
- 1, pt
+ 1, wPreferences
.icon_size
- 1, &black
);
403 ROperateLine(tile
, RSubtractOperation
, 0, tp
- 2, pt
+ 1, wPreferences
.icon_size
- 2, &light
);
406 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, &dark
);
407 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
, 6 + as
, ICON_SIZE
- 5, &dark
);
408 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5, &light
);
413 static void omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
415 WAppIcon
*clickedIcon
= entry
->clientdata
;
418 WMArray
*selectedIcons
;
419 WMArrayIterator iter
;
422 assert(entry
->clientdata
!= NULL
);
424 dock
= clickedIcon
->dock
;
426 selectedIcons
= getSelected(dock
);
428 if (!WMGetArrayItemCount(selectedIcons
))
429 WMAddToArray(selectedIcons
, clickedIcon
);
432 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
433 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
435 else if (aicon
->icon
->selected
)
436 wIconSelect(aicon
->icon
);
438 WMFreeArray(selectedIcons
);
441 wMessageDialog(dock
->screen_ptr
, _("Warning"),
442 _("Some icons cannot be made omnipresent. "
443 "Please make sure that no other icon is "
444 "docked in the same positions on the other "
445 "workspaces and the Clip is not full in "
446 "some workspace."), _("OK"), NULL
, NULL
);
447 } else if (failed
== 1) {
448 wMessageDialog(dock
->screen_ptr
, _("Warning"),
449 _("Icon cannot be made omnipresent. "
450 "Please make sure that no other icon is "
451 "docked in the same position on the other "
452 "workspaces and the Clip is not full in "
453 "some workspace."), _("OK"), NULL
, NULL
);
457 static void removeIcons(WMArray
*icons
, WDock
*dock
)
463 WM_ITERATE_ARRAY(icons
, aicon
, it
) {
464 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
465 wDockDetach(dock
, aicon
);
467 /* XXX: can: aicon->icon == NULL ? */
468 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
469 wGetHeadForWindow(aicon
->icon
->owner
));
470 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
471 if (!dock
->mapped
|| dock
->collapsed
)
472 XMapWindow(dpy
, aicon
->icon
->core
->window
);
477 if (wPreferences
.auto_arrange_icons
)
478 wArrangeIcons(dock
->screen_ptr
, True
);
481 static void removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
483 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
485 WMArray
*selectedIcons
;
487 assert(clickedIcon
!= NULL
);
489 dock
= clickedIcon
->dock
;
491 selectedIcons
= getSelected(dock
);
493 if (WMGetArrayItemCount(selectedIcons
)) {
494 if (wMessageDialog(dock
->screen_ptr
,
495 dock
->type
== WM_CLIP
? _("Workspace Clip") : _("Drawer"),
496 _("All selected icons will be removed!"),
497 _("OK"), _("Cancel"), NULL
) != WAPRDefault
) {
498 WMFreeArray(selectedIcons
);
502 if (clickedIcon
->xindex
== 0 && clickedIcon
->yindex
== 0) {
503 WMFreeArray(selectedIcons
);
506 WMAddToArray(selectedIcons
, clickedIcon
);
509 removeIcons(selectedIcons
, dock
);
511 if (dock
->type
== WM_DRAWER
) {
512 drawerConsolidateIcons(dock
);
516 static void keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
518 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
521 WMArray
*selectedIcons
;
524 assert(clickedIcon
!= NULL
);
525 dock
= clickedIcon
->dock
;
527 selectedIcons
= getSelected(dock
);
529 if (!WMGetArrayItemCount(selectedIcons
)
530 && clickedIcon
!= dock
->screen_ptr
->clip_icon
) {
531 char *command
= NULL
;
533 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
534 clickedIcon
->editing
= 1;
535 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
536 _("Type the command used to launch the application"), &command
)) {
537 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
541 clickedIcon
->command
= command
;
542 clickedIcon
->editing
= 0;
544 clickedIcon
->editing
= 0;
547 WMFreeArray(selectedIcons
);
552 WMAddToArray(selectedIcons
, clickedIcon
);
555 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
556 if (aicon
->icon
->selected
)
557 wIconSelect(aicon
->icon
);
559 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
560 aicon
->attracted
= 0;
561 if (aicon
->icon
->shadowed
) {
562 aicon
->icon
->shadowed
= 0;
565 * Update icon pixmap, RImage doesn't change,
566 * so call wIconUpdate is not needed
568 update_icon_pixmap(aicon
->icon
);
571 wAppIconPaint(aicon
);
574 save_appicon(aicon
, True
);
576 WMFreeArray(selectedIcons
);
579 static void toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
581 WDock
*dock
= (WDock
*) entry
->clientdata
;
582 WScreen
*scr
= dock
->screen_ptr
;
584 assert(entry
->clientdata
!= NULL
);
586 /* Setting a clip as autoattracting will disable an autoattracting drawer,
587 * and reciprocally. Ask for confirmation? */
588 #ifdef CONFIRM_AUTOATTRACT_CHANGE
589 if (dock
->type
== WM_CLIP
&& scr
->attracting_drawer
) {
590 if (wMessageDialog(scr
, _("Workspace Clip"),
591 _("The drawer that auto-attracted icons so far won't do so anymore!"),
592 _("OK"), _("Cancel"), NULL
) != WAPRDefault
)
594 } else if (dock
->type
== WM_DRAWER
) {
595 /* check if at least one clip already auto attracts icons */
596 int i
, ask_for_confirmation
= False
;
597 for (i
= 0; i
< w_global
.workspace
.count
; i
++) {
598 if (w_global
.workspace
.array
[i
]->clip
->attract_icons
) {
599 ask_for_confirmation
= True
;
603 if (ask_for_confirmation
) {
604 if (wMessageDialog(scr
, _("Drawer"),
605 _("Any clips that auto-attracted icons so far won't do so anymore!"),
606 _("OK"), _("Cancel"), NULL
) != WAPRDefault
)
612 dock
->attract_icons
= !dock
->attract_icons
;
614 entry
->flags
.indicator_on
= dock
->attract_icons
;
618 if (dock
->attract_icons
) {
619 if (dock
->type
== WM_DRAWER
) {
620 /* The newly auto-attracting dock is a drawer: disable any clip and
621 * previously attracting drawer */
623 for (i
= 0; i
< w_global
.workspace
.count
; i
++)
624 w_global
.workspace
.array
[i
]->clip
->attract_icons
= False
;
625 /* dock menu will be updated later, when opened */
627 if (scr
->attracting_drawer
!= NULL
)
628 scr
->attracting_drawer
->attract_icons
= False
;
629 scr
->attracting_drawer
= dock
;
631 /* The newly auto-attracting dock is a clip: disable
632 * previously attracting drawer, if applicable */
633 if (scr
->attracting_drawer
!= NULL
) {
634 scr
->attracting_drawer
->attract_icons
= False
;
635 /* again, its menu will be updated, later. */
636 scr
->attracting_drawer
= NULL
;
642 static void selectCallback(WMenu
*menu
, WMenuEntry
*entry
)
644 WAppIcon
*icon
= (WAppIcon
*) entry
->clientdata
;
646 assert(icon
!= NULL
);
648 wIconSelect(icon
->icon
);
653 static void colectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
655 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
656 WDock
*clip
; /* clip... is a WM_CLIP or a WM_DRAWER */
658 int x
, y
, x_pos
, y_pos
;
659 Bool update_icon
= False
;
661 assert(entry
->clientdata
!= NULL
);
662 clip
= clickedIcon
->dock
;
664 aicon
= w_global
.app_icon_list
;
667 if (!aicon
->docked
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
668 x_pos
= clip
->x_pos
+ x
* ICON_SIZE
;
669 y_pos
= clip
->y_pos
+ y
* ICON_SIZE
;
670 if (aicon
->x_pos
!= x_pos
|| aicon
->y_pos
!= y_pos
)
671 move_window(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, x_pos
, y_pos
);
673 aicon
->attracted
= 1;
674 if (!aicon
->icon
->shadowed
) {
675 aicon
->icon
->shadowed
= 1;
678 wDockAttachIcon(clip
, aicon
, x
, y
, update_icon
);
679 if (clip
->collapsed
|| !clip
->mapped
)
680 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
686 static void selectIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
688 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
690 WMArray
*selectedIcons
;
691 WMArrayIterator iter
;
695 assert(clickedIcon
!= NULL
);
696 dock
= clickedIcon
->dock
;
698 selectedIcons
= getSelected(dock
);
700 if (!WMGetArrayItemCount(selectedIcons
)) {
701 for (i
= 1; i
< dock
->max_icons
; i
++) {
702 btn
= dock
->icon_array
[i
];
703 if (btn
&& !btn
->icon
->selected
)
704 wIconSelect(btn
->icon
);
707 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
708 wIconSelect(btn
->icon
);
711 WMFreeArray(selectedIcons
);
716 static void toggleCollapsedCallback(WMenu
*menu
, WMenuEntry
*entry
)
718 assert(entry
->clientdata
!= NULL
);
720 toggleCollapsed(entry
->clientdata
);
722 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->collapsed
;
727 static void toggleAutoCollapseCallback(WMenu
*menu
, WMenuEntry
*entry
)
730 assert(entry
->clientdata
!= NULL
);
732 dock
= (WDock
*) entry
->clientdata
;
734 dock
->auto_collapse
= !dock
->auto_collapse
;
736 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_collapse
;
741 static void toggleAutoRaiseLower(WDock
*dock
)
745 dock
->auto_raise_lower
= !dock
->auto_raise_lower
;
746 if (dock
->type
== WM_DOCK
)
748 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
749 toggleAutoRaiseLower(dc
->adrawer
);
754 static void toggleAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
757 assert(entry
->clientdata
!= NULL
);
759 dock
= (WDock
*) entry
->clientdata
;
761 toggleAutoRaiseLower(dock
);
763 entry
->flags
.indicator_on
= ((WDock
*) entry
->clientdata
)->auto_raise_lower
;
768 static void launchCallback(WMenu
*menu
, WMenuEntry
*entry
)
770 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
772 launchDockedApplication(btn
, False
);
775 static void settingsCallback(WMenu
*menu
, WMenuEntry
*entry
)
777 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
781 ShowDockAppSettingsPanel(btn
);
784 static void hideCallback(WMenu
*menu
, WMenuEntry
*entry
)
787 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
789 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
791 if (wapp
->flags
.hidden
) {
792 wWorkspaceChange(btn
->icon
->core
->screen_ptr
, wapp
->last_workspace
);
793 wUnhideApplication(wapp
, False
, False
);
795 wHideApplication(wapp
);
799 static void unhideHereCallback(WMenu
*menu
, WMenuEntry
*entry
)
802 WAppIcon
*btn
= (WAppIcon
*) entry
->clientdata
;
804 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
806 wUnhideApplication(wapp
, False
, True
);
809 /* Name is only used when type == WM_DRAWER and when restoring a specific
810 * drawer, with a specific name. When creating a drawer, leave name to NULL
811 * and mainIconCreate will find the first unused unique name */
812 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
, const char *name
)
820 return scr
->clip_icon
;
822 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMClip", TILE_CLIP
);
823 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
827 default: /* to avoid a warning about btn and x_pos, basically */
828 btn
= wAppIconCreateForDock(scr
, NULL
, "Logo", "WMDock", TILE_NORMAL
);
829 if (wPreferences
.flags
.clip_merged_in_dock
)
830 btn
->icon
->core
->descriptor
.handle_expose
= clipIconExpose
;
831 x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
835 name
= findUniqueName(scr
, "Drawer");
836 btn
= wAppIconCreateForDock(scr
, NULL
, name
, "WMDrawer", TILE_DRAWER
);
837 btn
->icon
->core
->descriptor
.handle_expose
= drawerIconExpose
;
844 btn
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
845 btn
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
846 btn
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
847 btn
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
848 btn
->icon
->core
->descriptor
.parent
= btn
;
849 XMapWindow(dpy
, btn
->icon
->core
->window
);
853 if (type
== WM_CLIP
||
854 (type
== WM_DOCK
&& wPreferences
.flags
.clip_merged_in_dock
))
855 scr
->clip_icon
= btn
;
860 static void switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
862 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
863 WScreen
*scr
= icon
->icon
->core
->screen_ptr
;
865 WMArray
*selectedIcons
;
868 if (entry
->order
== w_global
.workspace
.current
)
871 dest
= w_global
.workspace
.array
[entry
->order
]->clip
;
873 selectedIcons
= getSelected(src
);
875 if (WMGetArrayItemCount(selectedIcons
)) {
876 WMArrayIterator iter
;
878 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
879 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
880 wDockMoveIconBetweenDocks(src
, dest
, btn
, x
, y
);
881 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
884 } else if (icon
!= scr
->clip_icon
) {
885 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
886 wDockMoveIconBetweenDocks(src
, dest
, icon
, x
, y
);
887 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
890 WMFreeArray(selectedIcons
);
893 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
)
895 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
897 if (!btn
->launching
&&
898 ((!withSelection
&& btn
->command
!= NULL
) || (withSelection
&& btn
->paste_command
!= NULL
))) {
899 if (!btn
->forced_dock
) {
900 btn
->relaunching
= btn
->running
;
903 if (btn
->wm_instance
|| btn
->wm_class
) {
904 WWindowAttributes attr
;
905 memset(&attr
, 0, sizeof(WWindowAttributes
));
906 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
908 if (!attr
.no_appicon
&& !btn
->buggy_app
)
913 btn
->drop_launch
= 0;
914 btn
->paste_launch
= withSelection
;
915 scr
->last_dock
= btn
->dock
;
916 btn
->pid
= execCommand(btn
, (withSelection
? btn
->paste_command
: btn
->command
), NULL
);
918 if (btn
->buggy_app
) {
919 /* give feedback that the app was launched */
923 WMAddTimerHandler(200, (WMCallback
*) dockIconPaint
, btn
);
928 wwarning(_("could not launch application %s"), btn
->command
);
930 if (!btn
->relaunching
)
936 static void updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
938 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
944 for (i
= 0; i
< w_global
.workspace
.count
; i
++) {
945 if (i
< menu
->entry_no
) {
946 if (strcmp(menu
->entries
[i
]->text
, w_global
.workspace
.array
[i
]->name
) != 0) {
947 wfree(menu
->entries
[i
]->text
);
948 strcpy(title
, w_global
.workspace
.array
[i
]->name
);
949 menu
->entries
[i
]->text
= wstrdup(title
);
950 menu
->flags
.realized
= 0;
952 menu
->entries
[i
]->clientdata
= (void *)icon
;
954 strcpy(title
, w_global
.workspace
.array
[i
]->name
);
956 wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)icon
);
958 menu
->flags
.realized
= 0;
961 if (i
== w_global
.workspace
.current
)
962 wMenuSetEnabled(menu
, i
, False
);
964 wMenuSetEnabled(menu
, i
, True
);
967 if (!menu
->flags
.realized
)
971 static WMenu
*makeWorkspaceMenu(WScreen
*scr
)
975 menu
= wMenuCreate(scr
, NULL
, False
);
977 wwarning(_("could not create workspace submenu for Clip menu"));
979 wMenuAddCallback(menu
, "", switchWSCommand
, (void *)scr
->clip_icon
);
981 menu
->flags
.realized
= 0;
987 static void updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
996 entry
= menu
->entries
[index
];
997 entry
->flags
.indicator_on
= !dock
->lowered
;
998 entry
->clientdata
= dock
;
999 wMenuSetEnabled(menu
, index
, dock
->type
== WM_CLIP
);
1002 entry
= menu
->entries
[++index
];
1003 entry
->flags
.indicator_on
= dock
->collapsed
;
1004 entry
->clientdata
= dock
;
1007 entry
= menu
->entries
[++index
];
1008 entry
->flags
.indicator_on
= dock
->auto_collapse
;
1009 entry
->clientdata
= dock
;
1011 /* auto-raise/lower */
1012 entry
= menu
->entries
[++index
];
1013 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1014 entry
->clientdata
= dock
;
1015 wMenuSetEnabled(menu
, index
, dock
->lowered
&& (dock
->type
== WM_CLIP
));
1018 entry
= menu
->entries
[++index
];
1019 entry
->flags
.indicator_on
= dock
->attract_icons
;
1020 entry
->clientdata
= dock
;
1022 menu
->flags
.realized
= 0;
1027 static WMenu
*makeClipOptionsMenu(WScreen
*scr
)
1032 menu
= wMenuCreate(scr
, NULL
, False
);
1034 wwarning(_("could not create options submenu for Clip menu"));
1038 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
1039 entry
->flags
.indicator
= 1;
1040 entry
->flags
.indicator_on
= 1;
1041 entry
->flags
.indicator_type
= MI_CHECK
;
1043 entry
= wMenuAddCallback(menu
, _("Collapsed"), toggleCollapsedCallback
, NULL
);
1044 entry
->flags
.indicator
= 1;
1045 entry
->flags
.indicator_on
= 1;
1046 entry
->flags
.indicator_type
= MI_CHECK
;
1048 entry
= wMenuAddCallback(menu
, _("Autocollapse"), toggleAutoCollapseCallback
, NULL
);
1049 entry
->flags
.indicator
= 1;
1050 entry
->flags
.indicator_on
= 1;
1051 entry
->flags
.indicator_type
= MI_CHECK
;
1053 entry
= wMenuAddCallback(menu
, _("Autoraise"), toggleAutoRaiseLowerCallback
, NULL
);
1054 entry
->flags
.indicator
= 1;
1055 entry
->flags
.indicator_on
= 1;
1056 entry
->flags
.indicator_type
= MI_CHECK
;
1058 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"), toggleAutoAttractCallback
, NULL
);
1059 entry
->flags
.indicator
= 1;
1060 entry
->flags
.indicator_on
= 1;
1061 entry
->flags
.indicator_type
= MI_CHECK
;
1063 menu
->flags
.realized
= 0;
1070 static void setDockPositionNormalCallback(WMenu
*menu
, WMenuEntry
*entry
)
1072 WDock
*dock
= (WDock
*) entry
->clientdata
;
1074 if (entry
->flags
.indicator_on
) // already set, nothing to do
1076 // Do we come from auto raise lower or keep on top?
1077 if (dock
->auto_raise_lower
)
1079 dock
->auto_raise_lower
= 0;
1080 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1081 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1082 dc
->adrawer
->auto_raise_lower
= 0;
1087 // Will take care of setting lowered = 0 in drawers
1088 toggleLowered(dock
);
1090 entry
->flags
.indicator_on
= 1;
1093 static void setDockPositionAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
1095 WDock
*dock
= (WDock
*) entry
->clientdata
;
1097 if (entry
->flags
.indicator_on
) // already set, nothing to do
1099 // Do we come from normal or keep on top?
1102 toggleLowered(dock
);
1104 dock
->auto_raise_lower
= 1;
1105 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1106 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1107 dc
->adrawer
->auto_raise_lower
= 1;
1109 entry
->flags
.indicator_on
= 1;
1112 static void setDockPositionKeepOnTopCallback(WMenu
*menu
, WMenuEntry
*entry
)
1114 WDock
*dock
= (WDock
*) entry
->clientdata
;
1116 if (entry
->flags
.indicator_on
) // already set, nothing to do
1118 dock
->auto_raise_lower
= 0;
1119 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1120 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1121 dc
->adrawer
->auto_raise_lower
= 0;
1123 toggleLowered(dock
);
1124 entry
->flags
.indicator_on
= 1;
1127 static void updateDockPositionMenu(WMenu
*menu
, WDock
*dock
)
1136 entry
= menu
->entries
[index
++];
1137 entry
->flags
.indicator_on
= (dock
->lowered
&& !dock
->auto_raise_lower
);
1138 entry
->clientdata
= dock
;
1140 /* Auto-raise/lower */
1141 entry
= menu
->entries
[index
++];
1142 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1143 entry
->clientdata
= dock
;
1146 entry
= menu
->entries
[index
++];
1147 entry
->flags
.indicator_on
= !dock
->lowered
;
1148 entry
->clientdata
= dock
;
1151 static WMenu
*makeDockPositionMenu(WScreen
*scr
)
1153 /* When calling this, the dock is being created, so scr->dock is still not set
1154 * Therefore the callbacks' clientdata and the indicators can't be set,
1155 * they will be updated when the dock menu is opened. */
1159 menu
= wMenuCreate(scr
, NULL
, False
);
1161 wwarning(_("could not create options submenu for dock position menu"));
1165 entry
= wMenuAddCallback(menu
, _("Normal"), setDockPositionNormalCallback
, NULL
);
1166 entry
->flags
.indicator
= 1;
1167 entry
->flags
.indicator_type
= MI_DIAMOND
;
1169 entry
= wMenuAddCallback(menu
, _("Auto raise & lower"), setDockPositionAutoRaiseLowerCallback
, NULL
);
1170 entry
->flags
.indicator
= 1;
1171 entry
->flags
.indicator_type
= MI_DIAMOND
;
1173 entry
= wMenuAddCallback(menu
, _("Keep on Top"), setDockPositionKeepOnTopCallback
, NULL
);
1174 entry
->flags
.indicator
= 1;
1175 entry
->flags
.indicator_type
= MI_DIAMOND
;
1177 menu
->flags
.realized
= 0;
1184 static WMenu
*dockMenuCreate(WScreen
*scr
, int type
)
1189 if (type
== WM_CLIP
&& w_global
.clip
.menu
)
1190 return w_global
.clip
.menu
;
1192 if (type
== WM_DRAWER
&& w_global
.dock
.drawer_menu
)
1193 return w_global
.dock
.drawer_menu
;
1195 menu
= wMenuCreate(scr
, NULL
, False
);
1196 if (type
== WM_DOCK
) {
1197 entry
= wMenuAddCallback(menu
, _("Dock position"), NULL
, NULL
);
1198 if (w_global
.dock
.pos_menu
== NULL
)
1199 w_global
.dock
.pos_menu
= makeDockPositionMenu(scr
);
1200 wMenuEntrySetCascade(menu
, entry
, w_global
.dock
.pos_menu
);
1202 if (!wPreferences
.flags
.nodrawer
) {
1203 entry
= wMenuAddCallback(menu
, _("Add a drawer"), addADrawerCallback
, NULL
);
1206 if (type
== WM_CLIP
)
1207 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1208 else /* if (type == WM_DRAWER) */
1209 entry
= wMenuAddCallback(menu
, _("Drawer options"), NULL
, NULL
);
1211 if (w_global
.clip
.opt_menu
== NULL
)
1212 w_global
.clip
.opt_menu
= makeClipOptionsMenu(scr
);
1214 wMenuEntrySetCascade(menu
, entry
, w_global
.clip
.opt_menu
);
1216 /* The same menu is used for the dock and its appicons. If the menu
1217 * entry text is different between the two contexts, or if it can
1218 * change depending on some state, free the duplicated string (from
1219 * wMenuInsertCallback) and use gettext's string */
1220 if (type
== WM_CLIP
) {
1221 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1223 entry
->text
= _("Rename Workspace"); /* can be: (Toggle) Omnipresent */
1226 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1227 entry
->flags
.indicator
= 1;
1228 entry
->flags
.indicator_on
= 1;
1229 entry
->flags
.indicator_type
= MI_CHECK
;
1231 entry
= wMenuAddCallback(menu
, _("Select All Icons"), selectIconsCallback
, NULL
);
1233 entry
->text
= _("Select All Icons"); /* can be: Unselect all icons */
1235 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1237 entry
->text
= _("Keep Icon"); /* can be: Keep Icons */
1239 if (type
== WM_CLIP
) {
1240 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1242 entry
->text
= _("Move Icon To"); /* can be: Move Icons to */
1243 w_global
.clip
.submenu
= makeWorkspaceMenu(scr
);
1244 if (w_global
.clip
.submenu
)
1245 wMenuEntrySetCascade(menu
, entry
, w_global
.clip
.submenu
);
1248 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
, NULL
);
1250 entry
->text
= _("Remove Icon"); /* can be: Remove Icons */
1252 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1255 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1257 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1259 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1261 entry
->text
= _("Hide"); /* can be: Unhide */
1263 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1265 entry
= wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1267 entry
->text
= _("Kill"); /* can be: Remove drawer */
1269 if (type
== WM_CLIP
)
1270 w_global
.clip
.menu
= menu
;
1272 if (type
== WM_DRAWER
)
1273 w_global
.dock
.drawer_menu
= menu
;
1278 WDock
*wDockCreate(WScreen
*scr
, int type
, const char *name
)
1285 dock
= wmalloc(sizeof(WDock
));
1289 dock
->max_icons
= DOCK_MAX_ICONS
;
1292 dock
->max_icons
= scr
->scr_width
/ wPreferences
.icon_size
;
1296 dock
->max_icons
= scr
->scr_height
/ wPreferences
.icon_size
;
1299 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * dock
->max_icons
);
1301 btn
= mainIconCreate(scr
, type
, name
);
1305 dock
->x_pos
= btn
->x_pos
;
1306 dock
->y_pos
= btn
->y_pos
;
1307 dock
->screen_ptr
= scr
;
1309 dock
->icon_count
= 1;
1310 if (type
== WM_DRAWER
)
1311 dock
->on_right_side
= scr
->dock
->on_right_side
;
1313 dock
->on_right_side
= 1;
1314 dock
->collapsed
= 0;
1315 dock
->auto_collapse
= 0;
1316 dock
->auto_collapse_magic
= NULL
;
1317 dock
->auto_raise_lower
= 0;
1318 dock
->auto_lower_magic
= NULL
;
1319 dock
->auto_raise_magic
= NULL
;
1320 dock
->attract_icons
= 0;
1322 dock
->icon_array
[0] = btn
;
1323 wRaiseFrame(btn
->icon
->core
);
1324 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1326 /* create dock menu */
1327 dock
->menu
= dockMenuCreate(scr
, type
);
1329 if (type
== WM_DRAWER
) {
1330 drawerAppendToChain(scr
, dock
);
1331 dock
->auto_collapse
= 1;
1337 void wDockDestroy(WDock
*dock
)
1342 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1343 aicon
= dock
->icon_array
[i
];
1345 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1346 wDockDetach(dock
, aicon
);
1348 /* XXX: can: aicon->icon == NULL ? */
1349 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1350 wGetHeadForWindow(aicon
->icon
->owner
));
1351 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1352 if (!dock
->mapped
|| dock
->collapsed
)
1353 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1357 if (wPreferences
.auto_arrange_icons
)
1358 wArrangeIcons(dock
->screen_ptr
, True
);
1359 wfree(dock
->icon_array
);
1360 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1361 wMenuDestroy(dock
->menu
, True
);
1362 if (dock
->screen_ptr
->last_dock
== dock
)
1363 dock
->screen_ptr
->last_dock
= NULL
;
1367 void wClipIconPaint(WAppIcon
*aicon
)
1369 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
1370 WWorkspace
*workspace
= w_global
.workspace
.array
[w_global
.workspace
.current
];
1372 Window win
= aicon
->icon
->core
->window
;
1373 int length
, nlength
;
1374 char *ws_name
, ws_number
[10];
1377 wIconPaint(aicon
->icon
);
1379 length
= strlen(workspace
->name
);
1380 ws_name
= wmalloc(length
+ 1);
1381 snprintf(ws_name
, length
+ 1, "%s", workspace
->name
);
1382 snprintf(ws_number
, sizeof(ws_number
), "%i", w_global
.workspace
.current
+ 1);
1383 nlength
= strlen(ws_number
);
1385 if (wPreferences
.flags
.noclip
|| !workspace
->clip
->collapsed
)
1386 color
= scr
->clip_title_color
[CLIP_NORMAL
];
1388 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
1390 ty
= ICON_SIZE
- WMFontHeight(scr
->clip_title_font
) - 3;
1392 tx
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
1394 if(wPreferences
.show_clip_title
)
1395 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, ty
, ws_name
, length
);
1397 tx
= (ICON_SIZE
/ 2 - WMWidthOfString(scr
->clip_title_font
, ws_number
, nlength
)) / 2;
1399 WMDrawString(scr
->wmscreen
, win
, color
, scr
->clip_title_font
, tx
, 2, ws_number
, nlength
);
1403 if (aicon
->launching
)
1404 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
1405 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
1407 paintClipButtons(aicon
, aicon
->dock
->lclip_button_pushed
, aicon
->dock
->rclip_button_pushed
);
1410 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
1412 wClipIconPaint(desc
->parent
);
1415 static void dockIconPaint(WAppIcon
*btn
)
1417 if (btn
== btn
->icon
->core
->screen_ptr
->clip_icon
) {
1418 wClipIconPaint(btn
);
1419 } else if (wIsADrawer(btn
)) {
1420 wDrawerIconPaint(btn
);
1423 save_appicon(btn
, True
);
1427 static WMPropList
*make_icon_state(WAppIcon
*btn
)
1429 WMPropList
*node
= NULL
;
1430 WMPropList
*command
, *autolaunch
, *lock
, *name
, *forced
;
1431 WMPropList
*position
, *buggy
, *omnipresent
;
1437 command
= WMCreatePLString("-");
1439 command
= WMCreatePLString(btn
->command
);
1441 autolaunch
= btn
->auto_launch
? dYes
: dNo
;
1443 lock
= btn
->lock
? dYes
: dNo
;
1445 tmp
= EscapeWM_CLASS(btn
->wm_instance
, btn
->wm_class
);
1447 name
= WMCreatePLString(tmp
);
1451 forced
= btn
->forced_dock
? dYes
: dNo
;
1453 buggy
= btn
->buggy_app
? dYes
: dNo
;
1455 if (!wPreferences
.flags
.clip_merged_in_dock
&& btn
== btn
->icon
->core
->screen_ptr
->clip_icon
)
1456 snprintf(buffer
, sizeof(buffer
), "%i,%i", btn
->x_pos
, btn
->y_pos
);
1458 snprintf(buffer
, sizeof(buffer
), "%hi,%hi", btn
->xindex
, btn
->yindex
);
1459 position
= WMCreatePLString(buffer
);
1461 node
= WMCreatePLDictionary(dCommand
, command
,
1463 dAutoLaunch
, autolaunch
,
1465 dForced
, forced
, dBuggyApplication
, buggy
, dPosition
, position
, NULL
);
1466 WMReleasePropList(command
);
1467 WMReleasePropList(name
);
1468 WMReleasePropList(position
);
1470 omnipresent
= btn
->omnipresent
? dYes
: dNo
;
1471 if (btn
->dock
!= btn
->icon
->core
->screen_ptr
->dock
&& (btn
->xindex
!= 0 || btn
->yindex
!= 0))
1472 WMPutInPLDictionary(node
, dOmnipresent
, omnipresent
);
1474 #ifdef XDND /* was OFFIX */
1475 if (btn
->dnd_command
) {
1476 command
= WMCreatePLString(btn
->dnd_command
);
1477 WMPutInPLDictionary(node
, dDropCommand
, command
);
1478 WMReleasePropList(command
);
1482 if (btn
->paste_command
) {
1483 command
= WMCreatePLString(btn
->paste_command
);
1484 WMPutInPLDictionary(node
, dPasteCommand
, command
);
1485 WMReleasePropList(command
);
1492 static WMPropList
*dockSaveState(WDock
*dock
)
1495 WMPropList
*icon_info
;
1496 WMPropList
*list
= NULL
, *dock_state
= NULL
;
1497 WMPropList
*value
, *key
;
1500 list
= WMCreatePLArray(NULL
);
1502 for (i
= (dock
->type
== WM_DOCK
? 0 : 1); i
< dock
->max_icons
; i
++) {
1503 WAppIcon
*btn
= dock
->icon_array
[i
];
1505 if (!btn
|| btn
->attracted
)
1508 if ((icon_info
= make_icon_state(dock
->icon_array
[i
]))) {
1509 WMAddToPLArray(list
, icon_info
);
1510 WMReleasePropList(icon_info
);
1514 dock_state
= WMCreatePLDictionary(dApplications
, list
, NULL
);
1516 if (dock
->type
== WM_DOCK
) {
1517 snprintf(buffer
, sizeof(buffer
), "Applications%i", dock
->screen_ptr
->scr_height
);
1518 key
= WMCreatePLString(buffer
);
1519 WMPutInPLDictionary(dock_state
, key
, list
);
1520 WMReleasePropList(key
);
1522 snprintf(buffer
, sizeof(buffer
), "%i,%i", (dock
->on_right_side
? -ICON_SIZE
: 0), dock
->y_pos
);
1523 value
= WMCreatePLString(buffer
);
1524 WMPutInPLDictionary(dock_state
, dPosition
, value
);
1525 WMReleasePropList(value
);
1527 WMReleasePropList(list
);
1529 if (dock
->type
== WM_CLIP
|| dock
->type
== WM_DRAWER
) {
1530 value
= (dock
->collapsed
? dYes
: dNo
);
1531 WMPutInPLDictionary(dock_state
, dCollapsed
, value
);
1533 value
= (dock
->auto_collapse
? dYes
: dNo
);
1534 WMPutInPLDictionary(dock_state
, dAutoCollapse
, value
);
1536 value
= (dock
->attract_icons
? dYes
: dNo
);
1537 WMPutInPLDictionary(dock_state
, dAutoAttractIcons
, value
);
1540 if (dock
->type
== WM_DOCK
|| dock
->type
== WM_CLIP
) {
1541 value
= (dock
->lowered
? dYes
: dNo
);
1542 WMPutInPLDictionary(dock_state
, dLowered
, value
);
1544 value
= (dock
->auto_raise_lower
? dYes
: dNo
);
1545 WMPutInPLDictionary(dock_state
, dAutoRaiseLower
, value
);
1551 void wDockSaveState(WScreen
*scr
, WMPropList
*old_state
)
1553 WMPropList
*dock_state
;
1556 dock_state
= dockSaveState(scr
->dock
);
1559 * Copy saved states of docks with different sizes.
1565 keys
= WMGetPLDictionaryKeys(old_state
);
1566 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
1567 tmp
= WMGetFromPLArray(keys
, i
);
1569 if (strncasecmp(WMGetFromPLString(tmp
), "applications", 12) == 0
1570 && !WMGetFromPLDictionary(dock_state
, tmp
)) {
1572 WMPutInPLDictionary(dock_state
, tmp
, WMGetFromPLDictionary(old_state
, tmp
));
1575 WMReleasePropList(keys
);
1578 WMPutInPLDictionary(scr
->session_state
, dDock
, dock_state
);
1580 WMReleasePropList(dock_state
);
1583 void wClipSaveState(WScreen
*scr
)
1585 WMPropList
*clip_state
;
1587 clip_state
= make_icon_state(scr
->clip_icon
);
1589 WMPutInPLDictionary(scr
->session_state
, dClip
, clip_state
);
1591 WMReleasePropList(clip_state
);
1594 WMPropList
*wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1596 return dockSaveState(w_global
.workspace
.array
[workspace
]->clip
);
1599 static Bool
getBooleanDockValue(WMPropList
*value
, WMPropList
*key
)
1602 if (WMIsPLString(value
)) {
1603 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1606 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1612 static WAppIcon
*restore_icon_state(WScreen
*scr
, WMPropList
*info
, int type
, int index
)
1615 WMPropList
*cmd
, *value
;
1616 char *wclass
, *winstance
, *command
;
1618 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1619 if (!cmd
|| !WMIsPLString(cmd
))
1622 /* parse window name */
1623 value
= WMGetFromPLDictionary(info
, dName
);
1627 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1629 if (!winstance
&& !wclass
)
1634 command
= wstrdup(WMGetFromPLString(cmd
));
1638 if (!command
|| strcmp(command
, "-") == 0) {
1649 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1657 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1658 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1659 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1660 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1661 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1663 #ifdef XDND /* was OFFIX */
1664 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1666 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1669 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1671 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1673 /* check auto launch */
1674 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1676 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1679 value
= WMGetFromPLDictionary(info
, dLock
);
1681 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1683 /* check if it wasn't normally docked */
1684 value
= WMGetFromPLDictionary(info
, dForced
);
1686 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1688 /* check if we can rely on the stuff in the app */
1689 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1691 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1693 /* get position in the dock */
1694 value
= WMGetFromPLDictionary(info
, dPosition
);
1695 if (value
&& WMIsPLString(value
)) {
1696 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1697 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1699 /* check position sanity */
1700 /* *Very* incomplete section! */
1701 if (type
== WM_DOCK
) {
1705 aicon
->yindex
= index
;
1709 /* check if icon is omnipresent */
1710 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1712 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1720 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1722 WAppIcon
*wClipRestoreState(WScreen
*scr
, WMPropList
*clip_state
)
1727 icon
= mainIconCreate(scr
, WM_CLIP
, NULL
);
1732 WMRetainPropList(clip_state
);
1734 /* restore position */
1736 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1739 if (!WMIsPLString(value
)) {
1740 COMPLAIN("Position");
1742 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1743 COMPLAIN("Position");
1745 /* check position sanity */
1746 if (!onScreen(scr
, icon
->x_pos
, icon
->y_pos
))
1747 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1750 #ifdef XDND /* was OFFIX */
1751 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1752 if (value
&& WMIsPLString(value
))
1753 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1756 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1757 if (value
&& WMIsPLString(value
))
1758 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1760 WMReleasePropList(clip_state
);
1765 WDock
*wDockRestoreState(WScreen
*scr
, WMPropList
*dock_state
, int type
)
1770 WAppIcon
*aicon
, *old_top
;
1773 dock
= wDockCreate(scr
, type
, NULL
);
1778 WMRetainPropList(dock_state
);
1780 /* restore position */
1781 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1783 if (!WMIsPLString(value
)) {
1784 COMPLAIN("Position");
1786 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1787 COMPLAIN("Position");
1789 /* check position sanity */
1790 if (!onScreen(scr
, dock
->x_pos
, dock
->y_pos
)) {
1791 int x
= dock
->x_pos
;
1792 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1795 /* Is this needed any more? */
1796 if (type
== WM_CLIP
) {
1797 if (dock
->x_pos
< 0) {
1799 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1800 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1803 if (dock
->x_pos
>= 0) {
1804 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1805 dock
->on_right_side
= 0;
1807 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1808 dock
->on_right_side
= 1;
1814 /* restore lowered/raised state */
1817 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1819 if (!WMIsPLString(value
)) {
1820 COMPLAIN("Lowered");
1822 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1827 /* restore collapsed state */
1828 dock
->collapsed
= 0;
1830 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1832 if (!WMIsPLString(value
)) {
1833 COMPLAIN("Collapsed");
1835 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1836 dock
->collapsed
= 1;
1840 /* restore auto-collapsed state */
1841 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1843 if (!WMIsPLString(value
)) {
1844 COMPLAIN("AutoCollapse");
1846 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1847 dock
->auto_collapse
= 1;
1848 dock
->collapsed
= 1;
1853 /* restore auto-raise/lower state */
1854 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1856 if (!WMIsPLString(value
)) {
1857 COMPLAIN("AutoRaiseLower");
1859 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1860 dock
->auto_raise_lower
= 1;
1864 /* restore attract icons state */
1865 dock
->attract_icons
= 0;
1867 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1869 if (!WMIsPLString(value
)) {
1870 COMPLAIN("AutoAttractIcons");
1872 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1873 dock
->attract_icons
= 1;
1877 /* application list */
1884 * When saving, it saves the dock state in
1885 * Applications and Applicationsnnn
1887 * When loading, it will first try Applicationsnnn.
1888 * If it does not exist, use Applications as default.
1891 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1893 tmp
= WMCreatePLString(buffer
);
1894 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1895 WMReleasePropList(tmp
);
1898 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1904 count
= WMGetPropListItemCount(apps
);
1908 old_top
= dock
->icon_array
[0];
1910 /* dock->icon_count is set to 1 when dock is created.
1911 * Since Clip is already restored, we want to keep it so for clip,
1912 * but for dock we may change the default top tile, so we set it to 0.
1914 if (type
== WM_DOCK
)
1915 dock
->icon_count
= 0;
1917 for (i
= 0; i
< count
; i
++) {
1918 if (dock
->icon_count
>= dock
->max_icons
) {
1919 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1923 value
= WMGetFromPLArray(apps
, i
);
1924 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1926 dock
->icon_array
[dock
->icon_count
] = aicon
;
1930 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1931 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1934 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1936 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1938 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1939 if (!dock
->collapsed
)
1940 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1942 wRaiseFrame(aicon
->icon
->core
);
1945 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
) {
1950 /* if the first icon is not defined, use the default */
1951 if (dock
->icon_array
[0] == NULL
) {
1952 /* update default icon */
1953 old_top
->x_pos
= dock
->x_pos
;
1954 old_top
->y_pos
= dock
->y_pos
;
1956 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1958 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1960 dock
->icon_array
[0] = old_top
;
1961 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1962 /* we don't need to increment dock->icon_count here because it was
1963 * incremented in the loop above.
1965 } else if (old_top
!= dock
->icon_array
[0]) {
1966 if (old_top
== scr
->clip_icon
) // TODO dande: understand the logic
1967 scr
->clip_icon
= dock
->icon_array
[0];
1969 wAppIconDestroy(old_top
);
1973 WMReleasePropList(dock_state
);
1978 void wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1980 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1981 btn
->drop_launch
= 0;
1982 btn
->paste_launch
= 0;
1984 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1987 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1997 void wDockDoAutoLaunch(WDock
*dock
, int workspace
)
2003 for (i
= 0; i
< dock
->max_icons
; i
++) {
2004 btn
= dock
->icon_array
[i
];
2005 if (!btn
|| !btn
->auto_launch
)
2008 state
= wmalloc(sizeof(WSavedState
));
2009 state
->workspace
= workspace
;
2010 /* TODO: this is klugy and is very difficult to understand
2011 * what's going on. Try to clean up */
2012 wDockLaunchWithState(dock
, btn
, state
);
2016 #ifdef XDND /* was OFFIX */
2017 static WDock
*findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
2023 if ((dock
= scr
->dock
) != NULL
) {
2024 for (i
= 0; i
< dock
->max_icons
; i
++) {
2025 if (dock
->icon_array
[i
]
2026 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
2032 if (*icon_pos
< 0 && (dock
= w_global
.workspace
.array
[w_global
.workspace
.current
]->clip
) != NULL
) {
2033 for (i
= 0; i
< dock
->max_icons
; i
++) {
2034 if (dock
->icon_array
[i
]
2035 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
2046 int wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
2052 dock
= findDock(scr
, event
, &icon_pos
);
2057 * Return True if the drop was on an application icon window.
2058 * In this case, let the ClientMessage handler redirect the
2059 * message to the app.
2061 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
2064 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
2065 scr
->flags
.dnd_data_convertion_status
= 0;
2067 btn
= dock
->icon_array
[icon_pos
];
2069 if (!btn
->forced_dock
) {
2070 btn
->relaunching
= btn
->running
;
2073 if (btn
->wm_instance
|| btn
->wm_class
) {
2074 WWindowAttributes attr
;
2075 memset(&attr
, 0, sizeof(WWindowAttributes
));
2076 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
2078 if (!attr
.no_appicon
)
2084 btn
->paste_launch
= 0;
2085 btn
->drop_launch
= 1;
2086 scr
->last_dock
= dock
;
2087 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
2092 if (!btn
->relaunching
)
2100 Bool
wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
, Bool update_icon
)
2103 Bool lupdate_icon
= False
;
2104 char *command
= NULL
;
2110 lupdate_icon
= True
;
2112 if (icon
->command
== NULL
) {
2113 /* If icon->owner exists, it means the application is running */
2114 if (icon
->icon
->owner
) {
2115 wwin
= icon
->icon
->owner
;
2116 command
= GetCommandForWindow(wwin
->client_win
);
2120 icon
->command
= command
;
2122 /* icon->forced_dock = 1; */
2123 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
2125 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2126 _("Type the command used to launch the application"), &command
)) {
2127 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2131 icon
->command
= command
;
2137 /* If the target is the dock, reject the icon. If
2138 * the target is the clip, make it an attracted icon
2140 if (dock
->type
== WM_CLIP
) {
2141 icon
->attracted
= 1;
2142 if (!icon
->icon
->shadowed
) {
2143 icon
->icon
->shadowed
= 1;
2144 lupdate_icon
= True
;
2154 for (index
= 1; index
< dock
->max_icons
; index
++)
2155 if (dock
->icon_array
[index
] == NULL
)
2157 /* if (index == dock->max_icons)
2160 assert(index
< dock
->max_icons
);
2162 dock
->icon_array
[index
] = icon
;
2166 icon
->omnipresent
= 0;
2168 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2169 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2174 icon
->launching
= 0;
2177 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2178 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2179 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2180 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2181 icon
->icon
->core
->descriptor
.parent
= icon
;
2183 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2184 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2187 * Update icon pixmap, RImage doesn't change,
2188 * so call wIconUpdate is not needed
2191 update_icon_pixmap(icon
->icon
);
2194 wAppIconPaint(icon
);
2197 save_appicon(icon
, True
);
2199 if (wPreferences
.auto_arrange_icons
)
2200 wArrangeIcons(dock
->screen_ptr
, True
);
2202 #ifdef XDND /* was OFFIX */
2203 if (icon
->command
&& !icon
->dnd_command
) {
2204 int len
= strlen(icon
->command
) + 8;
2205 icon
->dnd_command
= wmalloc(len
);
2206 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
2210 if (icon
->command
&& !icon
->paste_command
) {
2211 int len
= strlen(icon
->command
) + 8;
2212 icon
->paste_command
= wmalloc(len
);
2213 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
2219 void wDockReattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2223 for (index
= 1; index
< dock
->max_icons
; index
++) {
2224 if (dock
->icon_array
[index
] == icon
)
2227 assert(index
< dock
->max_icons
);
2232 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2233 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2236 Bool
wDockMoveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2239 char *command
= NULL
;
2241 Bool update_icon
= False
;
2244 return True
; /* No move needed, we're already there */
2250 * For the moment we can't do this if we move icons in Clip from one
2251 * workspace to other, because if we move two or more icons without
2252 * command, the dialog box will not be able to tell us to which of the
2253 * moved icons it applies. -Dan
2255 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
2256 /* If icon->owner exists, it means the application is running */
2257 if (icon
->icon
->owner
) {
2258 wwin
= icon
->icon
->owner
;
2259 command
= GetCommandForWindow(wwin
->client_win
);
2263 icon
->command
= command
;
2266 /* icon->forced_dock = 1; */
2267 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2268 _("Type the command used to launch the application"), &command
)) {
2269 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2273 icon
->command
= command
;
2284 if (dest
->type
== WM_DOCK
|| dest
->type
== WM_DRAWER
)
2285 wClipMakeIconOmnipresent(icon
, False
);
2287 for (index
= 1; index
< src
->max_icons
; index
++) {
2288 if (src
->icon_array
[index
] == icon
)
2291 assert(index
< src
->max_icons
);
2293 src
->icon_array
[index
] = NULL
;
2296 for (index
= 1; index
< dest
->max_icons
; index
++) {
2297 if (dest
->icon_array
[index
] == NULL
)
2301 assert(index
< dest
->max_icons
);
2303 dest
->icon_array
[index
] = icon
;
2306 /* deselect the icon */
2307 if (icon
->icon
->selected
)
2308 wIconSelect(icon
->icon
);
2310 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2311 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2313 /* set it to be kept when moving to dock.
2314 * Unless the icon does not have a command set
2316 if (icon
->command
&& (dest
->type
== WM_DOCK
|| dest
->type
== WM_DRAWER
)) {
2317 icon
->attracted
= 0;
2318 if (icon
->icon
->shadowed
) {
2319 icon
->icon
->shadowed
= 0;
2322 save_appicon(icon
, True
);
2325 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2331 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2332 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2336 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2339 * Update icon pixmap, RImage doesn't change,
2340 * so call wIconUpdate is not needed
2343 update_icon_pixmap(icon
->icon
);
2346 wAppIconPaint(icon
);
2351 void wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2354 Bool update_icon
= False
;
2356 /* make the settings panel be closed */
2358 DestroyDockAppSettingsPanel(icon
->panel
);
2360 /* This must be called before icon->dock is set to NULL.
2361 * Don't move it. -Dan
2363 wClipMakeIconOmnipresent(icon
, False
);
2367 icon
->attracted
= 0;
2368 icon
->auto_launch
= 0;
2369 if (icon
->icon
->shadowed
) {
2370 icon
->icon
->shadowed
= 0;
2374 /* deselect the icon */
2375 if (icon
->icon
->selected
)
2376 wIconSelect(icon
->icon
);
2378 if (icon
->command
) {
2379 wfree(icon
->command
);
2380 icon
->command
= NULL
;
2382 #ifdef XDND /* was OFFIX */
2383 if (icon
->dnd_command
) {
2384 wfree(icon
->dnd_command
);
2385 icon
->dnd_command
= NULL
;
2388 if (icon
->paste_command
) {
2389 wfree(icon
->paste_command
);
2390 icon
->paste_command
= NULL
;
2393 for (index
= 1; index
< dock
->max_icons
; index
++)
2394 if (dock
->icon_array
[index
] == icon
)
2397 assert(index
< dock
->max_icons
);
2398 dock
->icon_array
[index
] = NULL
;
2404 /* if the dock is not attached to an application or
2405 * the application did not set the appropriate hints yet,
2406 * destroy the icon */
2407 if (!icon
->running
|| !wApplicationOf(icon
->main_window
)) {
2408 wAppIconDestroy(icon
);
2410 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2411 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2412 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2413 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2414 icon
->icon
->core
->descriptor
.parent
= icon
;
2416 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2419 * Update icon pixmap, RImage doesn't change,
2420 * so call wIconUpdate is not needed
2423 update_icon_pixmap(icon
->icon
);
2426 wAppIconPaint(icon
);
2428 if (wPreferences
.auto_arrange_icons
)
2429 wArrangeIcons(dock
->screen_ptr
, True
);
2431 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2436 * returns the closest Dock slot index for the passed
2439 * Returns False if icon can't be docked.
2441 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2444 /* Redocking == true means either icon->dock == dock (normal case)
2445 * or we are called from handleDockMove for a drawer */
2446 Bool
wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2448 WScreen
*scr
= dock
->screen_ptr
;
2451 int i
, offset
= ICON_SIZE
/ 2;
2452 WAppIcon
*aicon
= NULL
;
2453 WAppIcon
*nicon
= NULL
;
2455 if (wPreferences
.flags
.noupdates
)
2461 /* if the dock is full */
2462 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
))
2465 /* exact position */
2467 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2469 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2472 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2474 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2476 /* check if the icon is outside the screen boundaries */
2477 if (!onScreen(scr
, dx
+ ex_x
* ICON_SIZE
, dy
+ ex_y
* ICON_SIZE
))
2480 switch (dock
->type
) {
2482 /* We can return False right away if
2483 * - we do not come from this dock (which is a WM_DOCK),
2484 * - we are not right over it, and
2485 * - we are not the main tile of a drawer.
2486 * In the latter case, we are called from handleDockMove. */
2487 if (icon
->dock
!= dock
&& ex_x
!= 0 &&
2488 !(icon
->dock
&& icon
->dock
->type
== WM_DRAWER
&& icon
== icon
->dock
->icon_array
[0]))
2491 if (!redocking
&& ex_x
!= 0)
2494 if (getDrawer(scr
, ex_y
)) /* Return false so that the drawer gets it. */
2498 for (i
= 0; i
< dock
->max_icons
; i
++) {
2499 nicon
= dock
->icon_array
[i
];
2500 if (nicon
&& nicon
->yindex
== ex_y
) {
2507 int sig
, done
, closest
;
2509 /* Possible cases when redocking:
2511 * icon dragged out of range of any slot -> false
2512 * icon dragged on a drawer -> false (to open the drawer)
2513 * icon dragged to range of free slot
2514 * icon dragged to range of same slot
2515 * icon dragged to range of different icon
2517 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2520 if (aicon
== icon
|| !aicon
) {
2526 /* start looking at the upper slot or lower? */
2527 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2533 /* look for closest free slot */
2534 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2538 closest
= sig
* (i
/ 2) + ex_y
;
2539 /* check if this slot is fully on the screen and not used */
2540 if (onScreen(scr
, dx
, dy
+ closest
* ICON_SIZE
)) {
2541 for (j
= 0; j
< dock
->max_icons
; j
++) {
2542 if (dock
->icon_array
[j
]
2543 && dock
->icon_array
[j
]->yindex
== closest
) {
2544 /* slot is used by someone else */
2545 if (dock
->icon_array
[j
] != icon
)
2550 /* slot is used by a drawer */
2551 done
= done
&& !getDrawer(scr
, closest
);
2558 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2559 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2564 } else { /* !redocking */
2566 /* if slot is free and the icon is close enough, return it */
2567 if (!aicon
&& ex_x
== 0) {
2579 start
= icon
->omnipresent
? 0 : w_global
.workspace
.current
;
2580 stop
= icon
->omnipresent
? w_global
.workspace
.count
: start
+ 1;
2583 for (k
= start
; k
< stop
; k
++) {
2584 WDock
*tmp
= w_global
.workspace
.array
[k
]->clip
;
2587 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2588 nicon
= tmp
->icon_array
[i
];
2589 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2597 for (k
= start
; k
< stop
; k
++) {
2598 WDock
*tmp
= w_global
.workspace
.array
[k
]->clip
;
2601 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2602 nicon
= tmp
->icon_array
[i
];
2603 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2604 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2605 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2614 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2623 WAppIcon
*aicons_to_shift
[ dock
->icon_count
];
2624 int index_of_hole
, j
;
2627 abs(ex_x
) - dock
->icon_count
> DOCK_DETTACH_THRESHOLD
||
2628 (ex_x
< 0 && !dock
->on_right_side
) ||
2629 (ex_x
> 0 && dock
->on_right_side
)) {
2634 ex_x
= (dock
->on_right_side
? -1 : 1);
2636 /* "Reduce" ex_x but keep its sign */
2638 if (abs(ex_x
) > dock
->icon_count
- 1) /* minus 1: do not take icon_array[0] into account */
2639 ex_x
= ex_x
* (dock
->icon_count
- 1) / abs(ex_x
); /* don't use *= ! */
2641 if (abs(ex_x
) > dock
->icon_count
)
2642 ex_x
= ex_x
* dock
->icon_count
/ abs(ex_x
);
2644 index_of_hole
= indexOfHole(dock
, icon
, redocking
);
2646 /* Find the appicons between where icon was (index_of_hole) and where
2647 * it wants to be (ex_x) and slide them. */
2649 for (i
= 1; i
< dock
->max_icons
; i
++) {
2650 if ((aicon
= dock
->icon_array
[ i
]) && aicon
!= icon
&&
2651 ((ex_x
<= aicon
->xindex
&& aicon
->xindex
< index_of_hole
) ||
2652 (index_of_hole
< aicon
->xindex
&& aicon
->xindex
<= ex_x
)))
2653 aicons_to_shift
[ j
++ ] = aicon
;
2655 assert(j
== abs(ex_x
- index_of_hole
));
2657 wSlideAppicons(aicons_to_shift
, j
, (index_of_hole
< ex_x
));
2667 static int onScreen(WScreen
*scr
, int x
, int y
)
2674 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2676 wGetRectPlacementInfo(scr
, rect
, &flags
);
2678 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2682 * returns true if it can find a free slot in the dock,
2683 * in which case it changes x_pos and y_pos accordingly.
2684 * Else returns false.
2686 Bool
wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2688 WScreen
*scr
= dock
->screen_ptr
;
2690 WAppIconChain
*chain
;
2691 unsigned char *slot_map
;
2695 int i
, done
= False
;
2697 int sx
= 0, ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2698 int extra_count
= 0;
2700 if (dock
->type
== WM_DRAWER
) {
2701 if (dock
->icon_count
>= dock
->max_icons
) { /* drawer is full */
2704 *x_pos
= dock
->icon_count
* (dock
->on_right_side
? -1 : 1);
2709 if (dock
->type
== WM_CLIP
&& dock
!= w_global
.workspace
.array
[w_global
.workspace
.current
]->clip
)
2710 extra_count
= scr
->global_icon_count
;
2712 /* if the dock is full */
2713 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
)
2716 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2717 if (scr
->dock
->on_right_side
)
2718 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2720 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2723 if (ex
< dock
->x_pos
)
2725 if (sx
> dock
->x_pos
+ ICON_SIZE
)
2726 sx
= dock
->x_pos
+ ICON_SIZE
;
2733 /* check if clip is in a corner */
2734 if (dock
->type
== WM_CLIP
) {
2735 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2737 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2739 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2741 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2749 /* If the clip is in the corner, use only slots that are in the border
2751 if (corner
!= C_NONE
) {
2755 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2756 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2757 hmap
= wmalloc(hcount
+ 1);
2758 vmap
= wmalloc(vcount
+ 1);
2760 /* mark used positions */
2763 for (i
= 0; i
< dock
->max_icons
; i
++) {
2764 btn
= dock
->icon_array
[i
];
2768 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2769 vmap
[btn
->yindex
] = 1;
2770 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2771 hmap
[btn
->xindex
] = 1;
2773 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2775 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2776 vmap
[btn
->yindex
] = 1;
2777 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2778 hmap
[btn
->xindex
] = 1;
2782 for (i
= 0; i
< dock
->max_icons
; i
++) {
2783 btn
= dock
->icon_array
[i
];
2787 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2788 vmap
[btn
->yindex
] = 1;
2789 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2790 hmap
[-btn
->xindex
] = 1;
2792 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2794 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2795 vmap
[btn
->yindex
] = 1;
2796 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2797 hmap
[-btn
->xindex
] = 1;
2801 for (i
= 0; i
< dock
->max_icons
; i
++) {
2802 btn
= dock
->icon_array
[i
];
2806 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2807 vmap
[-btn
->yindex
] = 1;
2808 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2809 hmap
[btn
->xindex
] = 1;
2811 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2813 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2814 vmap
[-btn
->yindex
] = 1;
2815 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2816 hmap
[btn
->xindex
] = 1;
2821 for (i
= 0; i
< dock
->max_icons
; i
++) {
2822 btn
= dock
->icon_array
[i
];
2826 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2827 vmap
[-btn
->yindex
] = 1;
2828 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2829 hmap
[-btn
->xindex
] = 1;
2831 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2833 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2834 vmap
[-btn
->yindex
] = 1;
2835 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2836 hmap
[-btn
->xindex
] = 1;
2842 /* search a vacant slot */
2843 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2844 if (i
< vcount
&& vmap
[i
] == 0) {
2850 } else if (i
< hcount
&& hmap
[i
] == 0) {
2860 /* If found a slot, translate and return */
2862 if (corner
== C_NW
|| corner
== C_NE
)
2867 if (corner
== C_NE
|| corner
== C_SE
)
2874 /* else, try to find a slot somewhere else */
2877 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2878 * placed outside of screen */
2879 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2881 /* In the worst case (the clip is in the corner of the screen),
2882 * the amount of icons that fit in the clip is smaller.
2883 * Double the map to get a safe value.
2887 r
= (mwidth
- 1) / 2;
2889 slot_map
= wmalloc(mwidth
* mwidth
);
2891 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2893 /* mark used slots in the map. If the slot falls outside the map
2894 * (for example, when all icons are placed in line), ignore them. */
2895 for (i
= 0; i
< dock
->max_icons
; i
++) {
2896 btn
= dock
->icon_array
[i
];
2898 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2901 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
)
2902 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2904 /* Find closest slot from the center that is free by scanning the
2905 * map from the center to outward in circular passes.
2906 * This will not result in a neat layout, but will be optimal
2907 * in the sense that there will not be holes left.
2910 for (i
= 1; i
<= r
&& !done
; i
++) {
2913 /* top and bottom parts of the ring */
2914 for (x
= -i
; x
<= i
&& !done
; x
++) {
2915 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2917 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2918 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2925 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2926 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2933 /* left and right parts of the ring */
2934 for (y
= -i
+ 1; y
<= i
- 1; y
++) {
2935 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2937 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2938 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2945 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2946 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2959 static void moveDock(WDock
*dock
, int new_x
, int new_y
)
2965 if (dock
->type
== WM_DOCK
) {
2966 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
2967 moveDock(dc
->adrawer
, new_x
, dc
->adrawer
->y_pos
- dock
->y_pos
+ new_y
);
2970 dock
->x_pos
= new_x
;
2971 dock
->y_pos
= new_y
;
2972 for (i
= 0; i
< dock
->max_icons
; i
++) {
2973 btn
= dock
->icon_array
[i
];
2975 btn
->x_pos
= new_x
+ btn
->xindex
* ICON_SIZE
;
2976 btn
->y_pos
= new_y
+ btn
->yindex
* ICON_SIZE
;
2977 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2982 static void swapDock(WDock
*dock
)
2984 WScreen
*scr
= dock
->screen_ptr
;
2988 if (dock
->on_right_side
)
2989 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2991 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2993 swapDrawers(scr
, dock
->on_right_side
, x
);
2995 for (i
= 0; i
< dock
->max_icons
; i
++) {
2996 btn
= dock
->icon_array
[i
];
2999 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
3003 wScreenUpdateUsableArea(scr
);
3006 static pid_t
execCommand(WAppIcon
*btn
, const char *command
, WSavedState
*state
)
3008 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
3014 cmdline
= ExpandOptions(scr
, command
);
3016 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
3024 wtokensplit(cmdline
, &argv
, &argc
);
3034 if ((pid
= fork()) == 0) {
3038 SetupEnvironment(scr
);
3044 args
= malloc(sizeof(char *) * (argc
+ 1));
3048 for (i
= 0; i
< argc
; i
++)
3052 execvp(argv
[0], args
);
3055 wtokenfree(argv
, argc
);
3059 state
= wmalloc(sizeof(WSavedState
));
3061 state
->miniaturized
= -1;
3063 if (btn
->dock
== scr
->dock
|| btn
->dock
->type
== WM_DRAWER
|| btn
->omnipresent
)
3064 state
->workspace
= -1;
3066 state
->workspace
= w_global
.workspace
.current
;
3068 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
3069 wAddDeathHandler(pid
, (WDeathHandler
*) trackDeadProcess
, btn
->dock
);
3077 void wDockHideIcons(WDock
*dock
)
3084 for (i
= 1; i
< dock
->max_icons
; i
++) {
3085 if (dock
->icon_array
[i
])
3086 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3090 dockIconPaint(dock
->icon_array
[0]);
3093 void wDockShowIcons(WDock
*dock
)
3101 btn
= dock
->icon_array
[0];
3102 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
3104 /* Deleting any change in stacking level, this function is now only about
3107 if (!dock
->collapsed
) {
3108 for (i
= 1; i
< dock
->max_icons
; i
++) {
3109 if (dock
->icon_array
[i
])
3110 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3118 void wDockLower(WDock
*dock
)
3123 if (dock
->type
== WM_DOCK
) {
3124 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3125 wDockLower(dc
->adrawer
);
3127 for (i
= 0; i
< dock
->max_icons
; i
++) {
3128 if (dock
->icon_array
[i
])
3129 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
3133 void wDockRaise(WDock
*dock
)
3138 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
3139 if (dock
->icon_array
[i
])
3140 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
3142 if (dock
->type
== WM_DOCK
) {
3143 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3144 wDockRaise(dc
->adrawer
);
3148 void wDockRaiseLower(WDock
*dock
)
3150 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
3151 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
3152 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
3158 void wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
3160 icon
->launching
= 0;
3161 icon
->relaunching
= 0;
3162 dockIconPaint(icon
);
3165 WAppIcon
*wDockFindIconForWindow(WDock
*dock
, Window window
)
3170 for (i
= 0; i
< dock
->max_icons
; i
++) {
3171 icon
= dock
->icon_array
[i
];
3172 if (icon
&& icon
->main_window
== window
)
3178 void wDockTrackWindowLaunch(WDock
*dock
, Window window
)
3181 char *wm_class
, *wm_instance
;
3183 Bool firstPass
= True
;
3185 char *command
= NULL
;
3187 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) || (!wm_class
&& !wm_instance
))
3190 command
= GetCommandForWindow(window
);
3192 for (i
= 0; i
< dock
->max_icons
; i
++) {
3193 icon
= dock
->icon_array
[i
];
3197 /* app is already attached to icon */
3198 if (icon
->main_window
== window
) {
3203 if ((icon
->wm_instance
|| icon
->wm_class
)
3204 && (icon
->launching
|| !icon
->running
)) {
3206 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0)
3209 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0)
3212 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0)
3215 if (!icon
->relaunching
) {
3218 /* Possibly an application that was docked with dockit,
3219 * but the user did not update WMState to indicate that
3220 * it was docked by force */
3221 wapp
= wApplicationOf(window
);
3223 icon
->forced_dock
= 1;
3226 if (!icon
->forced_dock
)
3227 icon
->main_window
= window
;
3230 if (!wPreferences
.no_animations
&& !icon
->launching
&&
3231 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
3235 icon
->launching
= 1;
3236 dockIconPaint(icon
);
3238 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
3239 wm_instance
, wm_class
, TILE_NORMAL
);
3240 /* XXX: can: aicon->icon == NULL ? */
3241 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
3242 wAppIconMove(aicon
, x0
, y0
);
3243 /* Should this always be lowered? -Dan */
3245 wLowerFrame(aicon
->icon
->core
);
3246 XMapWindow(dpy
, aicon
->icon
->core
->window
);
3247 aicon
->launching
= 1;
3248 wAppIconPaint(aicon
);
3249 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
3250 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
3251 wAppIconDestroy(aicon
);
3253 wDockFinishLaunch(dock
, icon
);
3258 if (firstPass
&& !found
) {
3272 void wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3274 if (!wPreferences
.flags
.noclip
) {
3275 scr
->clip_icon
->dock
= w_global
.workspace
.array
[workspace
]->clip
;
3276 if (w_global
.workspace
.current
!= workspace
) {
3277 WDock
*old_clip
= w_global
.workspace
.array
[w_global
.workspace
.current
]->clip
;
3278 WAppIconChain
*chain
= scr
->global_icons
;
3281 wDockMoveIconBetweenDocks(chain
->aicon
->dock
,
3282 w_global
.workspace
.array
[workspace
]->clip
,
3283 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
3284 if (w_global
.workspace
.array
[workspace
]->clip
->collapsed
)
3285 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3286 chain
= chain
->next
;
3289 wDockHideIcons(old_clip
);
3290 if (old_clip
->auto_raise_lower
) {
3291 if (old_clip
->auto_raise_magic
) {
3292 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3293 old_clip
->auto_raise_magic
= NULL
;
3295 wDockLower(old_clip
);
3297 if (old_clip
->auto_collapse
) {
3298 if (old_clip
->auto_expand_magic
) {
3299 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3300 old_clip
->auto_expand_magic
= NULL
;
3302 old_clip
->collapsed
= 1;
3304 wDockShowIcons(w_global
.workspace
.array
[workspace
]->clip
);
3309 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3314 for (i
= 0; i
< dock
->max_icons
; i
++) {
3315 icon
= dock
->icon_array
[i
];
3319 if (icon
->launching
&& icon
->pid
== pid
) {
3320 if (!icon
->relaunching
) {
3322 icon
->main_window
= None
;
3324 wDockFinishLaunch(dock
, icon
);
3326 if (status
== 111) {
3331 if (icon
->drop_launch
)
3332 cmd
= icon
->dnd_command
;
3335 if (icon
->paste_launch
)
3336 cmd
= icon
->paste_command
;
3338 cmd
= icon
->command
;
3340 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3342 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3349 /* This function is called when the dock switches state between
3350 * "normal" (including auto-raise/lower) and "keep on top". It is
3351 * therefore clearly distinct from wDockLower/Raise, which are called
3352 * each time a not-kept-on-top dock is lowered/raised. */
3353 static void toggleLowered(WDock
*dock
)
3359 if (!dock
->lowered
) {
3360 newlevel
= WMNormalLevel
;
3363 newlevel
= WMDockLevel
;
3367 for (i
= 0; i
< dock
->max_icons
; i
++) {
3368 tmp
= dock
->icon_array
[i
];
3372 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3374 /* When the dock is no longer "on top", explicitly lower it as well.
3375 * It saves some CPU cycles (probably) to do it ourselves here
3376 * rather than calling wDockLower at the end of toggleLowered */
3378 wLowerFrame(tmp
->icon
->core
);
3381 if (dock
->type
== WM_DOCK
) {
3382 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
3383 toggleLowered(dc
->adrawer
);
3385 wScreenUpdateUsableArea(dock
->screen_ptr
);
3389 static void toggleCollapsed(WDock
*dock
)
3391 if (dock
->collapsed
) {
3392 dock
->collapsed
= 0;
3393 wDockShowIcons(dock
);
3395 dock
->collapsed
= 1;
3396 wDockHideIcons(dock
);
3400 static void openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3402 WScreen
*scr
= dock
->screen_ptr
;
3403 WObjDescriptor
*desc
;
3405 WApplication
*wapp
= NULL
;
3409 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3411 if (dock
->type
== WM_DOCK
) {
3412 /* Dock position menu */
3413 updateDockPositionMenu(w_global
.dock
.pos_menu
, dock
);
3414 dock
->menu
->flags
.realized
= 0;
3415 if (!wPreferences
.flags
.nodrawer
) {
3417 entry
= dock
->menu
->entries
[++index
];
3418 entry
->clientdata
= aicon
;
3419 wMenuSetEnabled(dock
->menu
, index
, True
);
3422 /* clip/drawer options */
3423 if (w_global
.clip
.opt_menu
)
3424 updateClipOptionsMenu(w_global
.clip
.opt_menu
, dock
);
3426 n_selected
= numberOfSelectedIcons(dock
);
3428 if (dock
->type
== WM_CLIP
) {
3429 /* Rename Workspace */
3430 entry
= dock
->menu
->entries
[++index
];
3431 if (aicon
== scr
->clip_icon
) {
3432 entry
->callback
= renameCallback
;
3433 entry
->clientdata
= dock
;
3434 entry
->flags
.indicator
= 0;
3435 entry
->text
= _("Rename Workspace");
3437 entry
->callback
= omnipresentCallback
;
3438 entry
->clientdata
= aicon
;
3439 if (n_selected
> 0) {
3440 entry
->flags
.indicator
= 0;
3441 entry
->text
= _("Toggle Omnipresent");
3443 entry
->flags
.indicator
= 1;
3444 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3445 entry
->flags
.indicator_type
= MI_CHECK
;
3446 entry
->text
= _("Omnipresent");
3451 /* select/unselect icon */
3452 entry
= dock
->menu
->entries
[++index
];
3453 entry
->clientdata
= aicon
;
3454 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3455 wMenuSetEnabled(dock
->menu
, index
, aicon
!= scr
->clip_icon
&& !wIsADrawer(aicon
));
3457 /* select/unselect all icons */
3458 entry
= dock
->menu
->entries
[++index
];
3459 entry
->clientdata
= aicon
;
3461 entry
->text
= _("Unselect All Icons");
3463 entry
->text
= _("Select All Icons");
3465 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3468 entry
= dock
->menu
->entries
[++index
];
3469 entry
->clientdata
= aicon
;
3471 entry
->text
= _("Keep Icons");
3473 entry
->text
= _("Keep Icon");
3475 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3477 if (dock
->type
== WM_CLIP
) {
3478 /* this is the workspace submenu part */
3479 entry
= dock
->menu
->entries
[++index
];
3481 entry
->text
= _("Move Icons To");
3483 entry
->text
= _("Move Icon To");
3485 if (w_global
.clip
.submenu
)
3486 updateWorkspaceMenu(w_global
.clip
.submenu
, aicon
);
3488 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3491 /* remove icon(s) */
3492 entry
= dock
->menu
->entries
[++index
];
3493 entry
->clientdata
= aicon
;
3495 entry
->text
= _("Remove Icons");
3497 entry
->text
= _("Remove Icon");
3499 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3501 /* attract icon(s) */
3502 entry
= dock
->menu
->entries
[++index
];
3503 entry
->clientdata
= aicon
;
3505 dock
->menu
->flags
.realized
= 0;
3506 wMenuRealize(dock
->menu
);
3509 if (aicon
->icon
->owner
)
3510 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3515 entry
= dock
->menu
->entries
[++index
];
3516 entry
->clientdata
= aicon
;
3517 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3520 entry
= dock
->menu
->entries
[++index
];
3521 entry
->clientdata
= aicon
;
3522 if (wapp
&& wapp
->flags
.hidden
)
3523 entry
->text
= _("Unhide Here");
3525 entry
->text
= _("Bring Here");
3527 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3530 entry
= dock
->menu
->entries
[++index
];
3531 entry
->clientdata
= aicon
;
3532 if (wapp
&& wapp
->flags
.hidden
)
3533 entry
->text
= _("Unhide");
3535 entry
->text
= _("Hide");
3537 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3540 entry
= dock
->menu
->entries
[++index
];
3541 entry
->clientdata
= aicon
;
3542 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3544 /* kill or remove drawer */
3545 entry
= dock
->menu
->entries
[++index
];
3546 entry
->clientdata
= aicon
;
3547 if (wIsADrawer(aicon
)) {
3548 entry
->callback
= removeDrawerCallback
;
3549 entry
->text
= _("Remove drawer");
3550 wMenuSetEnabled(dock
->menu
, index
, True
);
3552 entry
->callback
= killCallback
;
3553 entry
->text
= _("Kill");
3554 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3557 if (!dock
->menu
->flags
.realized
)
3558 wMenuRealize(dock
->menu
);
3560 if (dock
->type
== WM_CLIP
|| dock
->type
== WM_DRAWER
) {
3561 /*x_pos = event->xbutton.x_root+2; */
3562 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3565 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3566 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3569 x_pos
= dock
->on_right_side
? scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3572 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3574 /* allow drag select */
3575 event
->xany
.send_event
= True
;
3576 desc
= &dock
->menu
->menu
->descriptor
;
3577 (*desc
->handle_mousedown
) (desc
, event
);
3580 /******************************************************************/
3581 static void iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3583 WAppIcon
*btn
= desc
->parent
;
3584 WDock
*dock
= btn
->dock
;
3585 WApplication
*wapp
= NULL
;
3588 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3589 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3591 assert(wapp
!= NULL
);
3593 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3595 /* go to the last workspace that the user worked on the app */
3596 if (wapp
->last_workspace
!= w_global
.workspace
.current
&& !unhideHere
)
3597 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3599 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3601 if (event
->xbutton
.state
& MOD_MASK
)
3602 wHideOtherApplications(btn
->icon
->owner
);
3604 if (event
->xbutton
.button
== Button1
) {
3605 if (event
->xbutton
.state
& MOD_MASK
) {
3606 /* raise/lower dock */
3607 toggleLowered(dock
);
3608 } else if (btn
== dock
->screen_ptr
->clip_icon
) {
3609 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
)
3610 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3611 else if (wPreferences
.flags
.clip_merged_in_dock
) {
3612 // Is actually the dock
3615 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3616 launchDockedApplication(btn
, False
);
3620 wShowInfoPanel(dock
->screen_ptr
);
3624 toggleCollapsed(dock
);
3625 } else if (wIsADrawer(btn
)) {
3626 toggleCollapsed(dock
);
3627 } else if (btn
->command
) {
3628 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3629 launchDockedApplication(btn
, False
);
3630 } else if (btn
->xindex
== 0 && btn
->yindex
== 0 && btn
->dock
->type
== WM_DOCK
) {
3631 wShowInfoPanel(dock
->screen_ptr
);
3637 static void handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3639 WScreen
*scr
= dock
->screen_ptr
;
3640 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3641 WIcon
*icon
= aicon
->icon
;
3644 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;;
3645 int shad_x
= x
, shad_y
= y
;
3647 int grabbed
= 0, done
, previously_on_right
, now_on_right
, previous_x_pos
, i
;
3648 Pixmap ghost
= None
;
3649 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3651 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3652 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3653 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
)
3654 wwarning("pointer grab failed for dock move");
3656 if (dock
->type
== WM_DRAWER
) {
3658 wins
[0] = icon
->core
->window
;
3659 wins
[1] = scr
->dock_shadow
;
3660 XRestackWindows(dpy
, wins
, 2);
3661 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3662 ICON_SIZE
, ICON_SIZE
);
3664 if (icon
->pixmap
!=None
)
3665 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3667 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3669 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3670 XClearWindow(dpy
, scr
->dock_shadow
);
3672 XMapWindow(dpy
, scr
->dock_shadow
);
3675 previously_on_right
= now_on_right
= dock
->on_right_side
;
3676 previous_x_pos
= dock
->x_pos
;
3679 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3680 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3687 /* It means the cursor moved so fast that it entered
3688 * something else (if moving slowly, it would have
3689 * stayed in the dock that is being moved. Ignore such
3690 * "spurious" EnterNotifiy's */
3695 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3696 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3697 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3698 | ButtonReleaseMask
| ButtonPressMask
,
3699 wPreferences
.cursor
[WCUR_MOVE
], CurrentTime
);
3704 switch (dock
->type
) {
3706 x
= ev
.xmotion
.x_root
- ofs_x
;
3707 y
= ev
.xmotion
.y_root
- ofs_y
;
3708 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3709 moveDock(dock
, x
, y
);
3712 x
= ev
.xmotion
.x_root
- ofs_x
;
3713 y
= ev
.xmotion
.y_root
- ofs_y
;
3714 if (previously_on_right
)
3716 now_on_right
= (ev
.xmotion
.x_root
>= previous_x_pos
- ICON_SIZE
);
3720 now_on_right
= (ev
.xmotion
.x_root
> previous_x_pos
+ ICON_SIZE
* 2);
3722 if (now_on_right
!= dock
->on_right_side
)
3724 dock
->on_right_side
= now_on_right
;
3726 wArrangeIcons(scr
, False
);
3728 // Also perform the vertical move
3729 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3730 moveDock(dock
, dock
->x_pos
, y
);
3731 if (wPreferences
.flags
.wrap_appicons_in_dock
)
3733 for (i
= 0; i
< dock
->max_icons
; i
++) {
3734 int new_y
, new_index
, j
, ok
;
3735 if ((tmpaicon
= dock
->icon_array
[i
]) == NULL
)
3737 if (onScreen(scr
, tmpaicon
->x_pos
, tmpaicon
->y_pos
))
3739 new_y
= (tmpaicon
->y_pos
+ ICON_SIZE
* dock
->max_icons
) % (ICON_SIZE
* dock
->max_icons
);
3740 new_index
= (new_y
- dock
->y_pos
) / ICON_SIZE
;
3741 if (!onScreen(scr
, tmpaicon
->x_pos
, new_y
))
3744 for (j
= 0; j
< dock
->max_icons
; j
++)
3746 if (dock
->icon_array
[j
] != NULL
&&
3747 dock
->icon_array
[j
]->yindex
== new_index
)
3753 if (!ok
|| getDrawer(scr
, new_index
) != NULL
)
3755 wDockReattachIcon(dock
, tmpaicon
, tmpaicon
->xindex
, new_index
);
3757 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3759 int new_y
, new_index
, j
, ok
;
3760 tmpaicon
= dc
->adrawer
->icon_array
[0];
3761 if (onScreen(scr
, tmpaicon
->x_pos
, tmpaicon
->y_pos
))
3763 new_y
= (tmpaicon
->y_pos
+ ICON_SIZE
* dock
->max_icons
) % (ICON_SIZE
* dock
->max_icons
);
3764 new_index
= (new_y
- dock
->y_pos
) / ICON_SIZE
;
3765 if (!onScreen(scr
, tmpaicon
->x_pos
, new_y
))
3768 for (j
= 0; j
< dock
->max_icons
; j
++)
3770 if (dock
->icon_array
[j
] != NULL
&&
3771 dock
->icon_array
[j
]->yindex
== new_index
)
3777 if (!ok
|| getDrawer(scr
, new_index
) != NULL
)
3779 moveDock(dc
->adrawer
, tmpaicon
->x_pos
, new_y
);
3785 WDock
*real_dock
= dock
->screen_ptr
->dock
;
3788 x
= ev
.xmotion
.x_root
- ofs_x
;
3789 y
= ev
.xmotion
.y_root
- ofs_y
;
3790 snapped
= wDockSnapIcon(real_dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3792 shad_x
= real_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3793 shad_y
= real_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3794 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3796 moveDock(dock
, x
, y
);
3806 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3808 XUngrabPointer(dpy
, CurrentTime
);
3809 if (dock
->type
== WM_DRAWER
) {
3810 Window
*wins
[dock
->icon_count
];
3812 for (i
= 0; i
< dock
->max_icons
; i
++) {
3813 if ((tmpaicon
= dock
->icon_array
[i
]) == NULL
)
3815 wins
[ tmpaicon
->xindex
+ (dock
->on_right_side
? dock
->icon_count
- 1 : 0) ] = &tmpaicon
->icon
->core
->window
;
3817 SlideWindows(wins
, dock
->icon_count
,
3818 (dock
->on_right_side
? x
- (dock
->icon_count
- 1) * ICON_SIZE
: x
),
3820 (dock
->on_right_side
? shad_x
- (dock
->icon_count
- 1) * ICON_SIZE
: shad_x
),
3822 XUnmapWindow(dpy
, scr
->dock_shadow
);
3823 moveDock(dock
, shad_x
, shad_y
);
3824 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3832 XFreePixmap(dpy
, ghost
);
3833 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3838 static int getClipButton(int px
, int py
)
3840 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3842 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3845 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3846 return CLIP_FORWARD
;
3847 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3853 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3856 int done
, direction
, new_ws
;
3858 WDock
*clip
= scr
->clip_icon
->dock
;
3860 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3862 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3863 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3865 wClipIconPaint(scr
->clip_icon
);
3868 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3875 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3876 if (new_dir
!= direction
) {
3877 direction
= new_dir
;
3878 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3879 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3880 wClipIconPaint(scr
->clip_icon
);
3888 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3893 clip
->lclip_button_pushed
= 0;
3894 clip
->rclip_button_pushed
= 0;
3896 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3898 if (direction
== CLIP_FORWARD
) {
3899 if (w_global
.workspace
.current
< w_global
.workspace
.count
- 1)
3900 wWorkspaceChange(scr
, w_global
.workspace
.current
+ 1);
3901 else if (new_ws
&& w_global
.workspace
.current
< MAX_WORKSPACES
- 1)
3902 wWorkspaceChange(scr
, w_global
.workspace
.current
+ 1);
3903 else if (wPreferences
.ws_cycle
)
3904 wWorkspaceChange(scr
, 0);
3905 } else if (direction
== CLIP_REWIND
) {
3906 if (w_global
.workspace
.current
> 0)
3907 wWorkspaceChange(scr
, w_global
.workspace
.current
- 1);
3908 else if (w_global
.workspace
.current
== 0 && wPreferences
.ws_cycle
)
3909 wWorkspaceChange(scr
, w_global
.workspace
.count
- 1);
3912 wClipIconPaint(scr
->clip_icon
);
3915 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3917 WAppIcon
*aicon
= desc
->parent
;
3918 WDock
*dock
= aicon
->dock
;
3919 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3921 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3924 scr
->last_dock
= dock
;
3926 if (dock
->menu
->flags
.mapped
)
3927 wMenuUnmap(dock
->menu
);
3929 if (IsDoubleClick(scr
, event
)) {
3930 /* double-click was not in the main clip icon */
3931 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3932 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3933 iconDblClick(desc
, event
);
3938 if (event
->xbutton
.button
== Button1
) {
3939 if (event
->xbutton
.state
& MOD_MASK
)
3944 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
&& dock
->type
!= WM_DOCK
) {
3945 wIconSelect(aicon
->icon
);
3949 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3950 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
&&
3951 (dock
->type
== WM_CLIP
|| (dock
->type
== WM_DOCK
&& wPreferences
.flags
.clip_merged_in_dock
)))
3952 handleClipChangeWorkspace(scr
, event
);
3954 handleDockMove(dock
, aicon
, event
);
3956 Bool hasMoved
= wHandleAppIconMove(aicon
, event
);
3957 if (wPreferences
.single_click
&& !hasMoved
)
3958 iconDblClick(desc
, event
);
3960 } else if (event
->xbutton
.button
== Button2
&& aicon
== scr
->clip_icon
) {
3961 if (!w_global
.clip
.ws_menu
)
3962 w_global
.clip
.ws_menu
= wWorkspaceMenuMake(scr
, False
);
3964 if (w_global
.clip
.ws_menu
) {
3965 WMenu
*wsMenu
= w_global
.clip
.ws_menu
;
3968 wWorkspaceMenuUpdate(wsMenu
);
3970 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
3973 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
3974 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
3976 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
3978 desc
= &wsMenu
->menu
->descriptor
;
3979 event
->xany
.send_event
= True
;
3980 (*desc
->handle_mousedown
) (desc
, event
);
3982 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
3983 (event
->xbutton
.state
& ShiftMask
) && aicon
!= scr
->clip_icon
) {
3984 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3985 } else if (event
->xbutton
.button
== Button3
) {
3986 if (event
->xbutton
.send_event
&&
3987 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3988 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3989 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3990 wwarning("pointer grab failed for dockicon menu");
3994 openDockMenu(dock
, aicon
, event
);
3995 } else if (event
->xbutton
.button
== Button2
) {
3996 WAppIcon
*btn
= desc
->parent
;
3998 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3999 launchDockedApplication(btn
, True
);
4003 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
4005 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
4009 assert(event
->type
== EnterNotify
);
4011 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
4014 scr
= btn
->icon
->core
->screen_ptr
;
4020 /* The auto raise/lower code */
4021 tmp
= (dock
->type
== WM_DRAWER
? scr
->dock
: dock
);
4022 if (tmp
->auto_lower_magic
) {
4023 WMDeleteTimerHandler(tmp
->auto_lower_magic
);
4024 tmp
->auto_lower_magic
= NULL
;
4026 if (tmp
->auto_raise_lower
&& !tmp
->auto_raise_magic
)
4027 tmp
->auto_raise_magic
= WMAddTimerHandler(wPreferences
.clip_auto_raise_delay
, clipAutoRaise
, (void *) tmp
);
4029 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4032 /* The auto expand/collapse code */
4033 if (dock
->auto_collapse_magic
) {
4034 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
4035 dock
->auto_collapse_magic
= NULL
;
4037 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
)
4038 dock
->auto_expand_magic
= WMAddTimerHandler(wPreferences
.clip_auto_expand_delay
, clipAutoExpand
, (void *)dock
);
4041 static void clipLeave(WDock
*dock
)
4044 WObjDescriptor
*desc
= NULL
;
4050 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
4051 if (XFindContext(dpy
, event
.xcrossing
.window
, w_global
.context
.client_win
,
4052 (XPointer
*) & desc
) != XCNOENT
4053 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
4054 && ((WAppIcon
*) desc
->parent
)->dock
== dock
) {
4055 /* We haven't left the dock/clip/drawer yet */
4056 XPutBackEvent(dpy
, &event
);
4060 XPutBackEvent(dpy
, &event
);
4062 /* We entered a withdrawn window, so we're still in Clip */
4066 tmp
= (dock
->type
== WM_DRAWER
? dock
->screen_ptr
->dock
: dock
);
4067 if (tmp
->auto_raise_magic
) {
4068 WMDeleteTimerHandler(tmp
->auto_raise_magic
);
4069 tmp
->auto_raise_magic
= NULL
;
4071 if (tmp
->auto_raise_lower
&& !tmp
->auto_lower_magic
)
4072 tmp
->auto_lower_magic
= WMAddTimerHandler(wPreferences
.clip_auto_lower_delay
, clipAutoLower
, (void *)tmp
);
4074 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4077 if (dock
->auto_expand_magic
) {
4078 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4079 dock
->auto_expand_magic
= NULL
;
4081 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
)
4082 dock
->auto_collapse_magic
= WMAddTimerHandler(wPreferences
.clip_auto_collapse_delay
, clipAutoCollapse
, (void *)dock
);
4085 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4087 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
4089 assert(event
->type
== LeaveNotify
);
4091 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
4094 clipLeave(btn
->dock
);
4097 static void clipAutoCollapse(void *cdata
)
4099 WDock
*dock
= (WDock
*) cdata
;
4101 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4104 if (dock
->auto_collapse
) {
4105 dock
->collapsed
= 1;
4106 wDockHideIcons(dock
);
4108 dock
->auto_collapse_magic
= NULL
;
4111 static void clipAutoExpand(void *cdata
)
4113 WDock
*dock
= (WDock
*) cdata
;
4115 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4118 if (dock
->auto_collapse
) {
4119 dock
->collapsed
= 0;
4120 wDockShowIcons(dock
);
4122 dock
->auto_expand_magic
= NULL
;
4125 static void clipAutoLower(void *cdata
)
4127 WDock
*dock
= (WDock
*) cdata
;
4129 if (dock
->auto_raise_lower
)
4132 dock
->auto_lower_magic
= NULL
;
4135 static void clipAutoRaise(void *cdata
)
4137 WDock
*dock
= (WDock
*) cdata
;
4139 if (dock
->auto_raise_lower
)
4142 dock
->auto_raise_magic
= NULL
;
4145 static Bool
iconCanBeOmnipresent(WAppIcon
*aicon
)
4147 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4152 for (i
= 0; i
< w_global
.workspace
.count
; i
++) {
4153 clip
= w_global
.workspace
.array
[i
]->clip
;
4155 if (clip
== aicon
->dock
)
4158 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4159 return False
; /* Clip is full in some workspace */
4161 for (j
= 0; j
< clip
->max_icons
; j
++) {
4162 btn
= clip
->icon_array
[j
];
4163 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
4171 int wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
4173 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4174 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4175 int status
= WO_SUCCESS
;
4177 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== scr
->clip_icon
)
4178 return WO_NOT_APPLICABLE
;
4180 if (aicon
->omnipresent
== omnipresent
)
4184 if (iconCanBeOmnipresent(aicon
)) {
4185 aicon
->omnipresent
= 1;
4186 new_entry
= wmalloc(sizeof(WAppIconChain
));
4187 new_entry
->aicon
= aicon
;
4188 new_entry
->next
= scr
->global_icons
;
4189 scr
->global_icons
= new_entry
;
4190 scr
->global_icon_count
++;
4192 aicon
->omnipresent
= 0;
4196 aicon
->omnipresent
= 0;
4197 if (aicon
== scr
->global_icons
->aicon
) {
4198 tmp
= scr
->global_icons
->next
;
4199 wfree(scr
->global_icons
);
4200 scr
->global_icons
= tmp
;
4201 scr
->global_icon_count
--;
4203 tmp
= scr
->global_icons
;
4205 if (tmp
->next
->aicon
== aicon
) {
4206 tmp1
= tmp
->next
->next
;
4209 scr
->global_icon_count
--;
4217 wAppIconPaint(aicon
);
4222 static void drawerAppendToChain(WScreen
*scr
, WDock
*drawer
)
4224 WDrawerChain
**where_to_add
;
4226 where_to_add
= &scr
->drawers
;
4227 while ((*where_to_add
) != NULL
) {
4228 where_to_add
= &(*where_to_add
)->next
;
4231 *where_to_add
= wmalloc(sizeof(WDrawerChain
));
4232 (*where_to_add
)->adrawer
= drawer
;
4233 (*where_to_add
)->next
= NULL
;
4234 scr
->drawer_count
++;
4238 static void drawerRemoveFromChain(WScreen
*scr
, WDock
*drawer
)
4240 WDrawerChain
*next
, **to_remove
;
4242 to_remove
= &scr
->drawers
;
4244 if (*to_remove
== NULL
) {
4245 wwarning("The drawer to be removed can not be found.");
4248 if ((*to_remove
)->adrawer
== drawer
)
4251 to_remove
= &(*to_remove
)->next
;
4253 next
= (*to_remove
)->next
;
4256 scr
->drawer_count
--;
4260 /* Don't free the returned string. Duplicate it. */
4261 static char * findUniqueName(WScreen
*scr
, const char *instance_basename
)
4263 static char buffer
[128];
4266 Bool already_in_use
= True
;
4268 #define UNIQUE_NAME_WATCHDOG 128
4269 for (i
= 0; already_in_use
&& i
< UNIQUE_NAME_WATCHDOG
; i
++) {
4270 snprintf(buffer
, sizeof buffer
, "%s%d", instance_basename
, i
);
4272 already_in_use
= False
;
4274 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4275 if (!strncmp(dc
->adrawer
->icon_array
[0]->wm_instance
, buffer
,
4277 already_in_use
= True
;
4283 if (i
== UNIQUE_NAME_WATCHDOG
)
4284 wwarning("Couldn't find a unique name for drawer in %d attempts.", i
);
4285 #undef UNIQUE_NAME_WATCHDOG
4291 static void drawerIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
4293 wDrawerIconPaint((WAppIcon
*) desc
->parent
);
4297 static int addADrawer(WScreen
*scr
)
4299 int i
, y
, sig
, found_y
;
4300 WDock
*drawer
, *dock
= scr
->dock
;
4302 char can_be_here
[2 * dock
->max_icons
- 1];
4304 if (dock
->icon_count
+ scr
->drawer_count
>= dock
->max_icons
)
4307 for (y
= -dock
->max_icons
+ 1; y
< dock
->max_icons
; y
++) {
4308 can_be_here
[y
+ dock
->max_icons
- 1] = True
;
4310 for (i
= 0; i
< dock
->max_icons
; i
++) {
4311 if (dock
->icon_array
[i
] != NULL
)
4312 can_be_here
[dock
->icon_array
[i
]->yindex
+ dock
->max_icons
- 1] = False
;
4314 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4315 y
= (int) ((dc
->adrawer
->y_pos
- dock
->y_pos
) / ICON_SIZE
);
4316 can_be_here
[y
+ dock
->max_icons
- 1] = False
;
4320 for (sig
= 1; !found_y
&& sig
> -2; sig
-= 2) // 1, then -1
4322 for (y
= sig
; sig
* y
< dock
->max_icons
; y
+= sig
)
4324 if (can_be_here
[y
+ dock
->max_icons
- 1] &&
4325 onScreen(scr
, dock
->x_pos
, dock
->y_pos
+ y
* ICON_SIZE
))
4334 /* This can happen even when dock->icon_count + scr->drawer_count
4335 * < dock->max_icons when the dock is not aligned on an
4336 * ICON_SIZE multiple, as some space is lost above and under it */
4339 drawer
= wDockCreate(scr
, WM_DRAWER
, NULL
);
4340 drawer
->lowered
= scr
->dock
->lowered
;
4341 drawer
->auto_raise_lower
= scr
->dock
->auto_raise_lower
;
4342 drawer
->x_pos
= dock
->x_pos
;
4343 drawer
->y_pos
= dock
->y_pos
+ ICON_SIZE
* y
;
4344 drawer
->icon_array
[0]->xindex
= 0;
4345 drawer
->icon_array
[0]->yindex
= 0;
4346 drawer
->icon_array
[0]->x_pos
= drawer
->x_pos
;
4347 drawer
->icon_array
[0]->y_pos
= drawer
->y_pos
;
4348 XMoveWindow(dpy
, drawer
->icon_array
[0]->icon
->core
->window
,
4349 drawer
->icon_array
[0]->x_pos
, drawer
->icon_array
[0]->y_pos
);
4355 static void addADrawerCallback(WMenu
*menu
, WMenuEntry
*entry
)
4357 assert(entry
->clientdata
!=NULL
);
4358 addADrawer(((WAppIcon
*) entry
->clientdata
)->dock
->screen_ptr
);
4362 static void drawerDestroy(WDock
*drawer
)
4372 scr
= drawer
->screen_ptr
;
4374 /* Note regarding menus: we can't delete any dock/clip/drawer menu, because
4375 * that would (attempt to) wfree some memory in gettext library (see menu
4376 * entries that have several "versions", such like "Hide" and "Unhide"). */
4378 wDefaultPurgeInfo(scr
, drawer
->icon_array
[0]->wm_instance
,
4379 drawer
->icon_array
[0]->wm_class
);
4380 icons
= WMCreateArray(drawer
->icon_count
- 1);
4381 for (i
= 1; i
< drawer
->max_icons
; i
++) {
4382 if (!(aicon
= drawer
->icon_array
[i
]))
4384 WMAddToArray(icons
, aicon
);
4386 removeIcons(icons
, drawer
);
4388 if (drawer
->auto_collapse_magic
) {
4389 WMDeleteTimerHandler(drawer
->auto_collapse_magic
);
4390 drawer
->auto_collapse_magic
= NULL
;
4392 if (drawer
->auto_lower_magic
) {
4393 WMDeleteTimerHandler(drawer
->auto_lower_magic
);
4394 drawer
->auto_lower_magic
= NULL
;
4397 wAppIconDestroy(drawer
->icon_array
[0]);
4398 wfree(drawer
->icon_array
);
4401 drawerRemoveFromChain(scr
, drawer
);
4402 if (scr
->last_dock
== drawer
)
4403 scr
->last_dock
= NULL
;
4404 if (scr
->attracting_drawer
== drawer
)
4405 scr
->attracting_drawer
= NULL
;
4409 static void removeDrawerCallback(WMenu
*menu
, WMenuEntry
*entry
)
4411 WDock
*dock
= ((WAppIcon
*)entry
->clientdata
)->dock
;
4412 assert(dock
!= NULL
);
4414 if (dock
->icon_count
> 1) {
4415 if (wMessageDialog(dock
->screen_ptr
, _("Drawer"),
4416 _("All icons in this drawer will be detached!"),
4417 _("OK"), _("Cancel"), NULL
) != WAPRDefault
)
4420 drawerDestroy(dock
);
4424 void wDrawerIconPaint(WAppIcon
*dicon
)
4426 Window win
= dicon
->icon
->core
->window
;
4427 WScreen
*scr
= dicon
->icon
->core
->screen_ptr
;
4429 GC gc
= scr
->draw_gc
;
4432 wIconPaint(dicon
->icon
);
4434 if (!dicon
->dock
->collapsed
)
4435 color
= scr
->clip_title_color
[CLIP_NORMAL
];
4437 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
4438 XSetForeground(dpy
, gc
, WMColorPixel(color
));
4440 if (dicon
->dock
->on_right_side
) {
4441 p
[0].x
= p
[3].x
= 10;
4442 p
[0].y
= p
[3].y
= ICON_SIZE
/ 2 - 5;
4444 p
[1].y
= ICON_SIZE
/ 2 + 5;
4446 p
[2].y
= ICON_SIZE
/ 2;
4449 p
[0].x
= p
[3].x
= ICON_SIZE
-1 - 10;
4450 p
[0].y
= p
[3].y
= ICON_SIZE
/ 2 - 5;
4451 p
[1].x
= ICON_SIZE
-1 - 10;
4452 p
[1].y
= ICON_SIZE
/ 2 + 5;
4453 p
[2].x
= ICON_SIZE
-1 - 5;
4454 p
[2].y
= ICON_SIZE
/ 2;
4456 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
4457 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
4461 RImage
* wDrawerMakeTile(WScreen
*scr
, RImage
*normalTile
)
4463 RImage
*tile
= RCloneImage(normalTile
);
4468 dark
.red
= dark
.green
= dark
.blue
= 60;
4471 light
.red
= light
.green
= light
.blue
= 80;
4474 if (!scr
->dock
|| scr
->dock
->on_right_side
) {
4475 ROperateLine(tile
, RSubtractOperation
, 11, ICON_SIZE
/ 2 - 7,
4476 4, ICON_SIZE
/ 2, &dark
); /* / */
4477 ROperateLine(tile
, RSubtractOperation
, 11, ICON_SIZE
/ 2 + 7,
4478 4, ICON_SIZE
/ 2, &dark
); /* \ */
4479 ROperateLine(tile
, RAddOperation
, 11, ICON_SIZE
/ 2 - 7,
4480 11, ICON_SIZE
/ 2 + 7, &light
); /* | */
4483 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 - 7,
4484 ICON_SIZE
-1 - 4, ICON_SIZE
/ 2, &dark
); /* \ */
4485 ROperateLine(tile
, RAddOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 + 7,
4486 ICON_SIZE
-1 - 4, ICON_SIZE
/ 2, &light
); /* / */
4487 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 - 7,
4488 ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 + 7, &dark
); /* | */
4494 static void swapDrawer(WDock
*drawer
, int new_x
)
4498 drawer
->on_right_side
= !drawer
->on_right_side
;
4499 drawer
->x_pos
= new_x
;
4501 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4503 if ((ai
= drawer
->icon_array
[i
]) == NULL
)
4505 ai
->xindex
*= -1; /* so A B C becomes C B A */
4506 ai
->x_pos
= new_x
+ ai
->xindex
* ICON_SIZE
;
4508 /* Update drawer's tile */
4510 wIconUpdate(ai
->icon
);
4511 wDrawerIconPaint(ai
);
4513 XMoveWindow(dpy
, ai
->icon
->core
->window
, ai
->x_pos
, ai
->y_pos
);
4518 static void swapDrawers(WScreen
*scr
, int on_right_side
, int new_x
)
4522 if (scr
->drawer_tile
) {
4523 RReleaseImage(scr
->drawer_tile
);
4525 scr
->drawer_tile
= wDrawerMakeTile(scr
, scr
->icon_tile
);
4527 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4528 swapDrawer(dc
->adrawer
, new_x
);
4529 assert(dc
->adrawer
->on_right_side
== on_right_side
);
4534 int wIsADrawer(WAppIcon
*aicon
)
4536 return aicon
&& aicon
->dock
&&
4537 aicon
->dock
->type
== WM_DRAWER
&& aicon
->dock
->icon_array
[0] == aicon
;
4541 static WDock
* getDrawer(WScreen
*scr
, int y_index
)
4545 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4546 if (dc
->adrawer
->y_pos
- scr
->dock
->y_pos
== y_index
* ICON_SIZE
)
4554 /* Find the "hole" a moving appicon created when snapped into the
4555 * drawer. redocking is a boolean. If the moving appicon comes from the
4556 * drawer, drawer->icon_count is correct. If not, redocking is then false and
4557 * there are now drawer->icon_count plus one appicons in the drawer. */
4558 static int indexOfHole(WDock
*drawer
, WAppIcon
*moving_aicon
, int redocking
)
4560 int index_of_hole
, i
;
4562 /* Classic interview question...
4564 * We have n-1 (n = drawer->icon_count-1 or drawer->icon_count, see
4565 * redocking) appicons, whose xindex are unique in [1..n]. One is missing:
4566 * that's where the ghost of the moving appicon is, that's what the
4567 * function should return.
4569 * We compute 1+2+...+n (this sum is equal to n*(n+1)/2), we substract to
4570 * this sum the xindex of each of the n-1 appicons, and we get the correct
4574 index_of_hole
= (drawer
->icon_count
- 1) * drawer
->icon_count
/ 2;
4576 index_of_hole
= drawer
->icon_count
* (drawer
->icon_count
+ 1) / 2;
4578 index_of_hole
*= (drawer
->on_right_side
? -1 : 1);
4580 for (i
= 1; i
< drawer
->max_icons
; i
++) {
4581 if (drawer
->icon_array
[i
] && drawer
->icon_array
[i
] != moving_aicon
)
4582 index_of_hole
-= drawer
->icon_array
[i
]->xindex
;
4584 /* wmessage(" Index of the moving appicon is %d (%sredocking)", index_of_hole, (redocking ? "" : "not ")); */
4585 if (abs(index_of_hole
) > abs(drawer
->icon_count
) - (redocking
? 1 : 0))
4586 wwarning(" index_of_hole is too large ! (%d greater than %d)",
4587 index_of_hole
, abs(drawer
->icon_count
) - (redocking
? 1 : 0));
4588 if (index_of_hole
== 0)
4589 wwarning(" index_of_hole == 0 (%sredocking, icon_count == %d)", (redocking
? "" : "not "), drawer
->icon_count
);
4591 return index_of_hole
;
4595 void wSlideAppicons(WAppIcon
**appicons
, int n
, int to_the_left
)
4598 int leftmost
= -1, min_index
= 9999, from_x
= -1; // leftmost and from_x initialized to avoid warning
4605 for (i
= 0; i
< n
; i
++) {
4606 aicon
= appicons
[i
];
4607 aicon
->xindex
+= (to_the_left
? -1 : +1);
4608 if (aicon
->xindex
< min_index
) {
4609 min_index
= aicon
->xindex
;
4611 from_x
= aicon
->x_pos
;
4613 aicon
->x_pos
+= (to_the_left
? -ICON_SIZE
: +ICON_SIZE
);
4616 for (i
= 0; i
< n
; i
++) {
4617 aicon
= appicons
[i
];
4618 wins
[aicon
->xindex
- min_index
] = &aicon
->icon
->core
->window
;
4620 aicon
= appicons
[leftmost
];
4621 SlideWindows(wins
, n
, from_x
, aicon
->y_pos
, aicon
->x_pos
, aicon
->y_pos
);
4625 void wDrawerFillTheGap(WDock
*drawer
, WAppIcon
*aicon
, Bool redocking
)
4628 int index_of_hole
= indexOfHole(drawer
, aicon
, redocking
);
4629 WAppIcon
*aicons_to_shift
[drawer
->icon_count
];
4632 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4633 WAppIcon
*ai
= drawer
->icon_array
[i
];
4634 if (ai
&& ai
!= aicon
&&
4635 abs(ai
->xindex
) > abs(index_of_hole
))
4636 aicons_to_shift
[j
++] = ai
;
4638 if (j
!= drawer
->icon_count
- abs(index_of_hole
) - (redocking
? 1 : 0))
4639 wwarning("Removing aicon at index %d from %s: j=%d but should be %d",
4640 index_of_hole
, drawer
->icon_array
[0]->wm_instance
,
4641 j
, drawer
->icon_count
- abs(index_of_hole
) - (redocking
? 1 : 0));
4642 wSlideAppicons(aicons_to_shift
, j
, !drawer
->on_right_side
);
4646 static void drawerConsolidateIcons(WDock
*drawer
)
4648 WAppIcon
*aicons_to_shift
[drawer
->icon_count
];
4649 int maxRemaining
= 0;
4652 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4653 WAppIcon
*ai
= drawer
->icon_array
[i
];
4656 sum
+= abs(ai
->xindex
);
4657 if (abs(ai
->xindex
) > maxRemaining
)
4658 maxRemaining
= abs(ai
->xindex
);
4660 while (sum
!= maxRemaining
* (maxRemaining
+ 1) / 2) { // while there is a hole
4663 // Look up for the hole at max position
4665 for (maxDeleted
= maxRemaining
- 1; maxDeleted
> 0; maxDeleted
--) {
4666 Bool foundAppIconThere
= False
;
4667 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4668 WAppIcon
*ai
= drawer
->icon_array
[i
];
4671 if (abs(ai
->xindex
) == maxDeleted
) {
4672 foundAppIconThere
= True
;
4676 if (!foundAppIconThere
)
4679 assert(maxDeleted
> 0); // would mean while test is wrong
4681 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4682 ai
= drawer
->icon_array
[i
];
4683 if (ai
!= NULL
&& abs(ai
->xindex
) > maxDeleted
)
4684 aicons_to_shift
[n
++] = ai
;
4686 assert(n
== maxRemaining
- maxDeleted
); // for the code review ;-)
4687 wSlideAppicons(aicons_to_shift
, n
, !drawer
->on_right_side
);
4688 // Efficient beancounting
4696 /* similar to wDockRestoreState, but a lot a specific stuff too... */
4697 static WDock
* drawerRestoreState(WScreen
*scr
, WMPropList
*drawer_state
)
4700 WMPropList
*apps
, *value
, *dock_state
;
4709 WMRetainPropList(drawer_state
);
4711 /* Get the instance name, and create a drawer */
4712 value
= WMGetFromPLDictionary(drawer_state
, dName
);
4713 drawer
= wDockCreate(scr
, WM_DRAWER
, WMGetFromPLString(value
));
4715 /* restore DnD command and paste command */
4717 value
= WMGetFromPLDictionary(drawer_state
, dDropCommand
);
4718 if (value
&& WMIsPLString(value
))
4719 drawer
->icon_array
[0]->dnd_command
= wstrdup(WMGetFromPLString(value
));
4722 value
= WMGetFromPLDictionary(drawer_state
, dPasteCommand
);
4723 if (value
&& WMIsPLString(value
))
4724 drawer
->icon_array
[0]->paste_command
= wstrdup(WMGetFromPLString(value
));
4726 /* restore position */
4727 value
= WMGetFromPLDictionary(drawer_state
, dPosition
);
4728 if (!value
|| !WMIsPLString(value
))
4729 COMPLAIN("Position");
4732 if (sscanf(WMGetFromPLString(value
), "%i,%i", &x
, &y
) != 2)
4733 COMPLAIN("Position");
4735 /* check position sanity */
4736 if (x
!= scr
->dock
->x_pos
) {
4737 x
= scr
->dock
->x_pos
;
4739 y_index
= (y
- scr
->dock
->y_pos
) / ICON_SIZE
;
4740 if (y_index
>= scr
->dock
->max_icons
) {
4741 /* Here we should do something more intelligent, since it
4742 * can happen even if the user hasn't hand-edited his
4743 * G/D/State file (but uses a lower resolution). */
4744 y_index
= scr
->dock
->max_icons
- 1;
4746 y
= scr
->dock
->y_pos
+ y_index
* ICON_SIZE
;
4747 moveDock(drawer
, x
, y
);
4750 /* restore dock properties (applist and others) */
4751 dock_state
= WMGetFromPLDictionary(drawer_state
, dDock
);
4753 /* restore lowered/raised state: same as scr->dock, no matter what */
4754 drawer
->lowered
= scr
->dock
->lowered
;
4755 if (!drawer
->lowered
)
4756 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMDockLevel
);
4758 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMNormalLevel
);
4759 wRaiseFrame(drawer
->icon_array
[0]->icon
->core
);
4761 /* restore collapsed state */
4762 drawer
->collapsed
= 0;
4763 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
4764 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4765 drawer
->collapsed
= 1;
4767 /* restore auto-collapsed state */
4768 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
4769 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4770 drawer
->auto_collapse
= 1;
4771 drawer
->collapsed
= 1;
4773 drawer
->auto_collapse
= 0; // because wDockCreate sets it (drawers only)
4776 /* restore auto-raise/lower state: same as scr->dock, no matter what */
4777 drawer
->auto_raise_lower
= scr
->dock
->auto_raise_lower
;
4779 /* restore attract icons state */
4780 drawer
->attract_icons
= 0;
4781 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
4782 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4783 drawer
->attract_icons
= 1;
4784 scr
->attracting_drawer
= drawer
;
4787 /* application list */
4788 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
4794 count
= WMGetPropListItemCount(apps
);
4799 for (i
=0; i
<count
; i
++) {
4800 if (drawer
->icon_count
>= drawer
->max_icons
) {
4801 wwarning(_("there are too many icons stored in drawer. Ignoring what doesn't fit"));
4805 value
= WMGetFromPLArray(apps
, i
);
4806 aicon
= restore_icon_state(scr
, value
, WM_DRAWER
, drawer
->icon_count
);
4808 drawer
->icon_array
[drawer
->icon_count
] = aicon
;
4811 aicon
->dock
= drawer
;
4812 aicon
->x_pos
= drawer
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
4813 aicon
->y_pos
= drawer
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
4815 if (!drawer
->lowered
)
4816 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
4818 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
4820 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
4822 if (!drawer
->collapsed
)
4823 XMapWindow(dpy
, aicon
->icon
->core
->window
);
4824 wRaiseFrame(aicon
->icon
->core
);
4826 drawer
->icon_count
++;
4831 WMReleasePropList(drawer_state
);
4837 /* Same kind of comment than for previous function: this function is
4838 * very similar to make_icon_state, but has substential differences as
4840 static WMPropList
*drawerSaveState(WScreen
*scr
, WDock
*drawer
)
4842 WMPropList
*pstr
, *drawer_state
;
4846 ai
= drawer
->icon_array
[0];
4847 /* Store its name */
4848 pstr
= WMCreatePLString(ai
->wm_instance
);
4849 drawer_state
= WMCreatePLDictionary(dName
, pstr
, NULL
); /* we need this final NULL */
4850 WMReleasePropList(pstr
);
4852 /* Store its position */
4853 snprintf(buffer
, sizeof(buffer
), "%i,%i", ai
->x_pos
, ai
->y_pos
);
4854 pstr
= WMCreatePLString(buffer
);
4855 WMPutInPLDictionary(drawer_state
, dPosition
, pstr
);
4856 WMReleasePropList(pstr
);
4859 /* Store its DnD command */
4860 if (ai
->dnd_command
) {
4861 pstr
= WMCreatePLString(ai
->dnd_command
);
4862 WMPutInPLDictionary(drawer_state
, dDropCommand
, pstr
);
4863 WMReleasePropList(pstr
);
4867 /* Store its paste command */
4868 if (ai
->paste_command
) {
4869 pstr
= WMCreatePLString(ai
->paste_command
);
4870 WMPutInPLDictionary(drawer_state
, dPasteCommand
, pstr
);
4871 WMReleasePropList(pstr
);
4874 /* Store applications list and other properties */
4875 pstr
= dockSaveState(drawer
);
4876 WMPutInPLDictionary(drawer_state
, dDock
, pstr
);
4877 WMReleasePropList(pstr
);
4879 return drawer_state
;
4883 void wDrawersSaveState(WScreen
*scr
)
4885 WMPropList
*all_drawers
, *drawer_state
;
4891 all_drawers
= WMCreatePLArray(NULL
);
4892 for (i
=0, dc
= scr
->drawers
;
4893 i
< scr
->drawer_count
;
4894 i
++, dc
= dc
->next
) {
4895 drawer_state
= drawerSaveState(scr
, dc
->adrawer
);
4896 WMAddToPLArray(all_drawers
, drawer_state
);
4897 WMReleasePropList(drawer_state
);
4899 WMPutInPLDictionary(scr
->session_state
, dDrawers
, all_drawers
);
4900 WMReleasePropList(all_drawers
);
4904 void wDrawersRestoreState(WScreen
*scr
)
4906 WMPropList
*all_drawers
, *drawer_state
;
4911 if (scr
->session_state
== NULL
)
4914 all_drawers
= WMGetFromPLDictionary(scr
->session_state
, dDrawers
);
4918 for (i
= 0; i
< WMGetPropListItemCount(all_drawers
); i
++) {
4919 drawer_state
= WMGetFromPLArray(all_drawers
, i
);
4920 drawerRestoreState(scr
, drawer_state
);
4921 // Note: scr->drawers was updated when the the drawer was created