1 /* dock.c- built-in Dock module for WindowMaker
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <X11/Xutil.h>
37 #define PATH_MAX DEFAULT_PATH_MAX
40 #include "WindowMaker.h"
48 #include "dockedapp.h"
51 #include "properties.h"
55 #include "workspace.h"
57 #include "superfluous.h"
59 #include "placement.h"
63 /**** Local variables ****/
66 #define CLIP_FORWARD 2
68 #define MOD_MASK wPreferences.modifier_mask
69 #define ICON_SIZE wPreferences.icon_size
71 /***** Local variables ****/
73 static WMPropList
*dCommand
= NULL
;
74 static WMPropList
*dPasteCommand
= NULL
;
75 #ifdef XDND /* XXX was OFFIX */
76 static WMPropList
*dDropCommand
= NULL
;
78 static WMPropList
*dAutoLaunch
, *dLock
;
79 static WMPropList
*dName
, *dForced
, *dBuggyApplication
, *dYes
, *dNo
;
80 static WMPropList
*dHost
, *dDock
, *dClip
;
81 static WMPropList
*dAutoAttractIcons
;
83 static WMPropList
*dPosition
, *dApplications
, *dLowered
, *dCollapsed
;
85 static WMPropList
*dAutoCollapse
, *dAutoRaiseLower
, *dOmnipresent
;
87 static WMPropList
*dDrawers
= NULL
;
89 static void dockIconPaint(WAppIcon
*btn
);
91 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
93 static pid_t
execCommand(WAppIcon
*btn
, const char *command
, WSavedState
*state
);
95 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
);
97 static int getClipButton(int px
, int py
);
99 static void toggleLowered(WDock
*dock
);
101 static void toggleCollapsed(WDock
*dock
);
103 static void clipIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
105 static void clipLeave(WDock
*dock
);
107 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
);
109 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
);
110 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
);
111 static void clipAutoCollapse(void *cdata
);
112 static void clipAutoExpand(void *cdata
);
113 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
);
115 static void clipAutoLower(void *cdata
);
116 static void clipAutoRaise(void *cdata
);
117 static WAppIcon
*mainIconCreate(WScreen
*scr
, int type
, const char *name
);
119 static void drawerIconExpose(WObjDescriptor
*desc
, XEvent
*event
);
120 static void removeDrawerCallback(WMenu
*menu
, WMenuEntry
*entry
);
121 static void drawerAppendToChain(WScreen
*scr
, WDock
*drawer
);
122 static char *findUniqueName(WScreen
*scr
, const char *instance_basename
);
123 static void addADrawerCallback(WMenu
*menu
, WMenuEntry
*entry
);
124 static void swapDrawers(WScreen
*scr
, int on_right_side
, int new_x
);
125 static WDock
* getDrawer(WScreen
*scr
, int y_index
);
126 static int indexOfHole(WDock
*drawer
, WAppIcon
*moving_aicon
, int redocking
);
127 static void drawerConsolidateIcons(WDock
*drawer
);
129 static int onScreen(WScreen
*scr
, int x
, int y
);
131 static void make_keys(void)
133 if (dCommand
!= NULL
)
136 dCommand
= WMRetainPropList(WMCreatePLString("Command"));
137 dPasteCommand
= WMRetainPropList(WMCreatePLString("PasteCommand"));
139 dDropCommand
= WMRetainPropList(WMCreatePLString("DropCommand"));
141 dLock
= WMRetainPropList(WMCreatePLString("Lock"));
142 dAutoLaunch
= WMRetainPropList(WMCreatePLString("AutoLaunch"));
143 dName
= WMRetainPropList(WMCreatePLString("Name"));
144 dForced
= WMRetainPropList(WMCreatePLString("Forced"));
145 dBuggyApplication
= WMRetainPropList(WMCreatePLString("BuggyApplication"));
146 dYes
= WMRetainPropList(WMCreatePLString("Yes"));
147 dNo
= WMRetainPropList(WMCreatePLString("No"));
148 dHost
= WMRetainPropList(WMCreatePLString("Host"));
150 dPosition
= WMCreatePLString("Position");
151 dApplications
= WMCreatePLString("Applications");
152 dLowered
= WMCreatePLString("Lowered");
153 dCollapsed
= WMCreatePLString("Collapsed");
154 dAutoCollapse
= WMCreatePLString("AutoCollapse");
155 dAutoRaiseLower
= WMCreatePLString("AutoRaiseLower");
156 dAutoAttractIcons
= WMCreatePLString("AutoAttractIcons");
158 dOmnipresent
= WMCreatePLString("Omnipresent");
160 dDock
= WMCreatePLString("Dock");
161 dClip
= WMCreatePLString("Clip");
162 dDrawers
= WMCreatePLString("Drawers");
165 static void renameCallback(WMenu
*menu
, WMenuEntry
*entry
)
167 WDock
*dock
= entry
->clientdata
;
172 assert(entry
->clientdata
!= NULL
);
174 wspace
= w_global
.workspace
.current
;
176 name
= wstrdup(w_global
.workspace
.array
[wspace
]->name
);
178 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), wspace
+ 1);
179 if (wInputDialog(dock
->screen_ptr
, _("Rename Workspace"), buffer
, &name
))
180 wWorkspaceRename(dock
->screen_ptr
, wspace
, name
);
185 static void toggleLoweredCallback(WMenu
*menu
, WMenuEntry
*entry
)
187 assert(entry
->clientdata
!= NULL
);
189 toggleLowered(entry
->clientdata
);
191 entry
->flags
.indicator_on
= !(((WDock
*) entry
->clientdata
)->lowered
);
196 static int matchWindow(const void *item
, const void *cdata
)
198 return (((WFakeGroupLeader
*) item
)->leader
== (Window
) cdata
);
201 static void killCallback(WMenu
*menu
, WMenuEntry
*entry
)
203 WScreen
*scr
= menu
->menu
->screen_ptr
;
205 WFakeGroupLeader
*fPtr
;
206 char *buffer
, *shortname
, **argv
;
209 if (!WCHECK_STATE(WSTATE_NORMAL
))
212 assert(entry
->clientdata
!= NULL
);
214 icon
= (WAppIcon
*) entry
->clientdata
;
218 WCHANGE_STATE(WSTATE_MODAL
);
220 /* strip away dir names */
221 shortname
= basename(icon
->command
);
222 /* separate out command options */
223 wtokensplit(shortname
, &argv
, &argc
);
225 buffer
= wstrconcat(argv
[0],
226 _(" will be forcibly closed.\n"
227 "Any unsaved changes will be lost.\n" "Please confirm."));
229 if (icon
->icon
&& icon
->icon
->owner
) {
230 fPtr
= icon
->icon
->owner
->fake_group
;
232 /* is this really necessary? can we kill a non-running dock icon? */
233 Window win
= icon
->main_window
;
236 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)win
);
237 if (index
!= WANotFound
)
238 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
243 if (wPreferences
.dont_confirm_kill
244 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
245 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
247 WWindow
*wwin
, *twin
;
249 wwin
= scr
->focused_window
;
252 if (wwin
->fake_group
== fPtr
)
257 } else if (icon
->icon
&& icon
->icon
->owner
) {
258 wClientKill(icon
->icon
->owner
);
263 wtokenfree(argv
, argc
);
267 WCHANGE_STATE(WSTATE_NORMAL
);
270 /* TODO: replace this function with a member of the dock struct */
271 static int numberOfSelectedIcons(WDock
*dock
)
277 for (i
= 1; i
< dock
->max_icons
; i
++) {
278 aicon
= dock
->icon_array
[i
];
279 if (aicon
&& aicon
->icon
->selected
)
286 static WMArray
*getSelected(WDock
*dock
)
288 WMArray
*ret
= WMCreateArray(8);
292 for (i
= 1; i
< dock
->max_icons
; i
++) {
293 btn
= dock
->icon_array
[i
];
294 if (btn
&& btn
->icon
->selected
)
295 WMAddToArray(ret
, btn
);
301 static void paintClipButtons(WAppIcon
*clipIcon
, Bool lpushed
, Bool rpushed
)
303 Window win
= clipIcon
->icon
->core
->window
;
304 WScreen
*scr
= clipIcon
->icon
->core
->screen_ptr
;
306 int pt
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
307 int tp
= ICON_SIZE
- pt
;
308 int as
= pt
- 15; /* 15 = 5+5+5 */
309 GC gc
= scr
->draw_gc
; /* maybe use WMColorGC() instead here? */
312 color
= scr
->clip_title_color
[CLIP_NORMAL
];
314 XSetForeground(dpy
, gc
, WMColorPixel(color
));
319 p
[1].x
= ICON_SIZE
- 2;
321 p
[2].x
= ICON_SIZE
- 2;
323 } else if (lpushed
) {
327 p
[1].y
= ICON_SIZE
- 2;
329 p
[2].y
= ICON_SIZE
- 2;
331 if (lpushed
|| rpushed
) {
332 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
333 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
334 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
337 /* top right arrow */
338 p
[0].x
= p
[3].x
= ICON_SIZE
- 5 - as
;
340 p
[1].x
= ICON_SIZE
- 6;
342 p
[2].x
= ICON_SIZE
- 6;
345 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
346 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
348 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
349 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
352 /* bottom left arrow */
354 p
[0].y
= p
[3].y
= ICON_SIZE
- 5 - as
;
356 p
[1].y
= ICON_SIZE
- 6;
358 p
[2].y
= ICON_SIZE
- 6;
360 XFillPolygon(dpy
, win
, scr
->draw_gc
, p
, 3, Convex
, CoordModeOrigin
);
361 XDrawLines(dpy
, win
, scr
->draw_gc
, p
, 4, CoordModeOrigin
);
363 XFillPolygon(dpy
, win
, gc
, p
, 3, Convex
, CoordModeOrigin
);
364 XDrawLines(dpy
, win
, gc
, p
, 4, CoordModeOrigin
);
368 RImage
*wClipMakeTile(WScreen
*scr
, RImage
*normalTile
)
370 RImage
*tile
= RCloneImage(normalTile
);
377 pt
= CLIP_BUTTON_SIZE
* wPreferences
.icon_size
/ 64;
378 tp
= wPreferences
.icon_size
- 1 - pt
;
382 black
.red
= black
.green
= black
.blue
= 0;
385 dark
.red
= dark
.green
= dark
.blue
= 60;
388 light
.red
= light
.green
= light
.blue
= 80;
391 ROperateLine(tile
, RSubtractOperation
, tp
, 0, wPreferences
.icon_size
- 2, pt
- 1, &dark
);
392 RDrawLine(tile
, tp
- 1, 0, wPreferences
.icon_size
- 1, pt
+ 1, &black
);
393 ROperateLine(tile
, RAddOperation
, tp
, 2, wPreferences
.icon_size
- 3, pt
, &light
);
396 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, 4, &dark
);
397 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 5, 6 + as
, &dark
);
398 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
, &light
);
401 ROperateLine(tile
, RAddOperation
, 2, tp
+ 2, pt
- 2, wPreferences
.icon_size
- 3, &dark
);
402 RDrawLine(tile
, 0, tp
- 1, pt
+ 1, wPreferences
.icon_size
- 1, &black
);
403 ROperateLine(tile
, RSubtractOperation
, 0, tp
- 2, pt
+ 1, wPreferences
.icon_size
- 2, &light
);
406 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, &dark
);
407 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
, 6 + as
, ICON_SIZE
- 5, &dark
);
408 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5, &light
);
413 static void omnipresentCallback(WMenu
*menu
, WMenuEntry
*entry
)
415 WAppIcon
*clickedIcon
= entry
->clientdata
;
418 WMArray
*selectedIcons
;
419 WMArrayIterator iter
;
422 assert(entry
->clientdata
!= NULL
);
424 dock
= clickedIcon
->dock
;
426 selectedIcons
= getSelected(dock
);
428 if (!WMGetArrayItemCount(selectedIcons
))
429 WMAddToArray(selectedIcons
, clickedIcon
);
432 WM_ITERATE_ARRAY(selectedIcons
, aicon
, iter
) {
433 if (wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
) == WO_FAILED
)
435 else if (aicon
->icon
->selected
)
436 wIconSelect(aicon
->icon
);
438 WMFreeArray(selectedIcons
);
441 wMessageDialog(dock
->screen_ptr
, _("Warning"),
442 _("Some icons cannot be made omnipresent. "
443 "Please make sure that no other icon is "
444 "docked in the same positions on the other "
445 "workspaces and the Clip is not full in "
446 "some workspace."), _("OK"), NULL
, NULL
);
447 } else if (failed
== 1) {
448 wMessageDialog(dock
->screen_ptr
, _("Warning"),
449 _("Icon cannot be made omnipresent. "
450 "Please make sure that no other icon is "
451 "docked in the same position on the other "
452 "workspaces and the Clip is not full in "
453 "some workspace."), _("OK"), NULL
, NULL
);
457 static void removeIcons(WMArray
*icons
, WDock
*dock
)
463 WM_ITERATE_ARRAY(icons
, aicon
, it
) {
464 keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
465 wDockDetach(dock
, aicon
);
467 /* XXX: can: aicon->icon == NULL ? */
468 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
469 wGetHeadForWindow(aicon
->icon
->owner
));
470 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
471 if (!dock
->mapped
|| dock
->collapsed
)
472 XMapWindow(dpy
, aicon
->icon
->core
->window
);
477 if (wPreferences
.auto_arrange_icons
)
478 wArrangeIcons(dock
->screen_ptr
, True
);
481 static void removeIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
483 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
485 WMArray
*selectedIcons
;
487 assert(clickedIcon
!= NULL
);
489 dock
= clickedIcon
->dock
;
491 selectedIcons
= getSelected(dock
);
493 if (WMGetArrayItemCount(selectedIcons
)) {
494 if (wMessageDialog(dock
->screen_ptr
,
495 dock
->type
== WM_CLIP
? _("Workspace Clip") : _("Drawer"),
496 _("All selected icons will be removed!"),
497 _("OK"), _("Cancel"), NULL
) != WAPRDefault
) {
498 WMFreeArray(selectedIcons
);
502 if (clickedIcon
->xindex
== 0 && clickedIcon
->yindex
== 0) {
503 WMFreeArray(selectedIcons
);
506 WMAddToArray(selectedIcons
, clickedIcon
);
509 removeIcons(selectedIcons
, dock
);
511 if (dock
->type
== WM_DRAWER
) {
512 drawerConsolidateIcons(dock
);
516 static void keepIconsCallback(WMenu
*menu
, WMenuEntry
*entry
)
518 WAppIcon
*clickedIcon
= (WAppIcon
*) entry
->clientdata
;
521 WMArray
*selectedIcons
;
524 assert(clickedIcon
!= NULL
);
525 dock
= clickedIcon
->dock
;
527 selectedIcons
= getSelected(dock
);
529 if (!WMGetArrayItemCount(selectedIcons
)
530 && clickedIcon
!= w_global
.clip
.icon
) {
531 char *command
= NULL
;
533 if (!clickedIcon
->command
&& !clickedIcon
->editing
) {
534 clickedIcon
->editing
= 1;
535 if (wInputDialog(dock
->screen_ptr
, _("Keep Icon"),
536 _("Type the command used to launch the application"), &command
)) {
537 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
541 clickedIcon
->command
= command
;
542 clickedIcon
->editing
= 0;
544 clickedIcon
->editing
= 0;
547 WMFreeArray(selectedIcons
);
552 WMAddToArray(selectedIcons
, clickedIcon
);
555 WM_ITERATE_ARRAY(selectedIcons
, aicon
, it
) {
556 if (aicon
->icon
->selected
)
557 wIconSelect(aicon
->icon
);
559 if (aicon
&& aicon
->attracted
&& aicon
->command
) {
560 aicon
->attracted
= 0;
561 if (aicon
->icon
->shadowed
) {
562 aicon
->icon
->shadowed
= 0;
565 * Update icon pixmap, RImage doesn't change,
566 * so call wIconUpdate is not needed
568 update_icon_pixmap(aicon
->icon
);
571 wAppIconPaint(aicon
);
574 save_appicon(aicon
, True
);
576 WMFreeArray(selectedIcons
);
579 static void toggleAutoAttractCallback(WMenu
*menu
, WMenuEntry
*entry
)
581 WDock
*dock
= (WDock
*) entry
->clientdata
;
582 WScreen
*scr
= dock
->screen_ptr
;
584 assert(entry
->clientdata
!= NULL
);
586 /* Setting a clip as autoattracting will disable an autoattracting drawer,
587 * and reciprocally. Ask for confirmation? */
588 #ifdef CONFIRM_AUTOATTRACT_CHANGE
589 if (dock
->type
== WM_CLIP
&& scr
->attracting_drawer
) {
590 if (wMessageDialog(scr
, _("Workspace Clip"),
591 _("The drawer that auto-attracted icons so far won't do so anymore!"),
592 _("OK"), _("Cancel"), NULL
) != WAPRDefault
)
594 } else if (dock
->type
== WM_DRAWER
) {
595 /* check if at least one clip already auto attracts icons */
596 int i
, ask_for_confirmation
= False
;
597 for (i
= 0; i
< w_global
.workspace
.count
; i
++) {
598 if (w_global
.workspace
.array
[i
]->clip
->attract_icons
) {
599 ask_for_confirmation
= True
;
603 if (ask_for_confirmation
) {
604 if (wMessageDialog(scr
, _("Drawer"),
605 _("Any clips that auto-attracted icons so far won't do so anymore!"),
606 _("OK"), _("Cancel"), NULL
) != WAPRDefault
)
612 dock
->attract_icons
= !dock
->attract_icons
;
614 entry
->flags
.indicator_on
= dock
->attract_icons
;
618 if (dock
->attract_icons
) {
619 if (dock
->type
== WM_DRAWER
) {
620 /* The newly auto-attracting dock is a drawer: disable any clip and
621 * previously attracting drawer */
623 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
)
819 if (w_global
.clip
.icon
)
820 return w_global
.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 w_global
.clip
.icon
= btn
;
860 static void switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
862 WAppIcon
*btn
, *icon
= (WAppIcon
*) entry
->clientdata
;
864 WMArray
*selectedIcons
;
867 if (entry
->order
== w_global
.workspace
.current
)
870 dest
= w_global
.workspace
.array
[entry
->order
]->clip
;
872 selectedIcons
= getSelected(src
);
874 if (WMGetArrayItemCount(selectedIcons
)) {
875 WMArrayIterator iter
;
877 WM_ITERATE_ARRAY(selectedIcons
, btn
, iter
) {
878 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
879 wDockMoveIconBetweenDocks(src
, dest
, btn
, x
, y
);
880 XUnmapWindow(dpy
, btn
->icon
->core
->window
);
883 } else if (icon
!= w_global
.clip
.icon
) {
884 if (wDockFindFreeSlot(dest
, &x
, &y
)) {
885 wDockMoveIconBetweenDocks(src
, dest
, icon
, x
, y
);
886 XUnmapWindow(dpy
, icon
->icon
->core
->window
);
889 WMFreeArray(selectedIcons
);
892 static void launchDockedApplication(WAppIcon
*btn
, Bool withSelection
)
894 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
896 if (!btn
->launching
&&
897 ((!withSelection
&& btn
->command
!= NULL
) || (withSelection
&& btn
->paste_command
!= NULL
))) {
898 if (!btn
->forced_dock
) {
899 btn
->relaunching
= btn
->running
;
902 if (btn
->wm_instance
|| btn
->wm_class
) {
903 WWindowAttributes attr
;
904 memset(&attr
, 0, sizeof(WWindowAttributes
));
905 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
907 if (!attr
.no_appicon
&& !btn
->buggy_app
)
912 btn
->drop_launch
= 0;
913 btn
->paste_launch
= withSelection
;
914 scr
->last_dock
= btn
->dock
;
915 btn
->pid
= execCommand(btn
, (withSelection
? btn
->paste_command
: btn
->command
), NULL
);
917 if (btn
->buggy_app
) {
918 /* give feedback that the app was launched */
922 WMAddTimerHandler(200, (WMCallback
*) dockIconPaint
, btn
);
927 wwarning(_("could not launch application %s"), btn
->command
);
929 if (!btn
->relaunching
)
935 static void updateWorkspaceMenu(WMenu
*menu
, WAppIcon
*icon
)
937 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
943 for (i
= 0; i
< w_global
.workspace
.count
; i
++) {
944 if (i
< menu
->entry_no
) {
945 if (strcmp(menu
->entries
[i
]->text
, w_global
.workspace
.array
[i
]->name
) != 0) {
946 wfree(menu
->entries
[i
]->text
);
947 strcpy(title
, w_global
.workspace
.array
[i
]->name
);
948 menu
->entries
[i
]->text
= wstrdup(title
);
949 menu
->flags
.realized
= 0;
951 menu
->entries
[i
]->clientdata
= (void *)icon
;
953 strcpy(title
, w_global
.workspace
.array
[i
]->name
);
955 wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)icon
);
957 menu
->flags
.realized
= 0;
960 if (i
== w_global
.workspace
.current
)
961 wMenuSetEnabled(menu
, i
, False
);
963 wMenuSetEnabled(menu
, i
, True
);
966 if (!menu
->flags
.realized
)
970 static WMenu
*makeWorkspaceMenu(WScreen
*scr
)
974 menu
= wMenuCreate(scr
, NULL
, False
);
976 wwarning(_("could not create workspace submenu for Clip menu"));
978 wMenuAddCallback(menu
, "", switchWSCommand
, (void *)w_global
.clip
.icon
);
980 menu
->flags
.realized
= 0;
986 static void updateClipOptionsMenu(WMenu
*menu
, WDock
*dock
)
995 entry
= menu
->entries
[index
];
996 entry
->flags
.indicator_on
= !dock
->lowered
;
997 entry
->clientdata
= dock
;
998 wMenuSetEnabled(menu
, index
, dock
->type
== WM_CLIP
);
1001 entry
= menu
->entries
[++index
];
1002 entry
->flags
.indicator_on
= dock
->collapsed
;
1003 entry
->clientdata
= dock
;
1006 entry
= menu
->entries
[++index
];
1007 entry
->flags
.indicator_on
= dock
->auto_collapse
;
1008 entry
->clientdata
= dock
;
1010 /* auto-raise/lower */
1011 entry
= menu
->entries
[++index
];
1012 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1013 entry
->clientdata
= dock
;
1014 wMenuSetEnabled(menu
, index
, dock
->lowered
&& (dock
->type
== WM_CLIP
));
1017 entry
= menu
->entries
[++index
];
1018 entry
->flags
.indicator_on
= dock
->attract_icons
;
1019 entry
->clientdata
= dock
;
1021 menu
->flags
.realized
= 0;
1026 static WMenu
*makeClipOptionsMenu(WScreen
*scr
)
1031 menu
= wMenuCreate(scr
, NULL
, False
);
1033 wwarning(_("could not create options submenu for Clip menu"));
1037 entry
= wMenuAddCallback(menu
, _("Keep on Top"), toggleLoweredCallback
, NULL
);
1038 entry
->flags
.indicator
= 1;
1039 entry
->flags
.indicator_on
= 1;
1040 entry
->flags
.indicator_type
= MI_CHECK
;
1042 entry
= wMenuAddCallback(menu
, _("Collapsed"), toggleCollapsedCallback
, NULL
);
1043 entry
->flags
.indicator
= 1;
1044 entry
->flags
.indicator_on
= 1;
1045 entry
->flags
.indicator_type
= MI_CHECK
;
1047 entry
= wMenuAddCallback(menu
, _("Autocollapse"), toggleAutoCollapseCallback
, NULL
);
1048 entry
->flags
.indicator
= 1;
1049 entry
->flags
.indicator_on
= 1;
1050 entry
->flags
.indicator_type
= MI_CHECK
;
1052 entry
= wMenuAddCallback(menu
, _("Autoraise"), toggleAutoRaiseLowerCallback
, NULL
);
1053 entry
->flags
.indicator
= 1;
1054 entry
->flags
.indicator_on
= 1;
1055 entry
->flags
.indicator_type
= MI_CHECK
;
1057 entry
= wMenuAddCallback(menu
, _("Autoattract Icons"), toggleAutoAttractCallback
, NULL
);
1058 entry
->flags
.indicator
= 1;
1059 entry
->flags
.indicator_on
= 1;
1060 entry
->flags
.indicator_type
= MI_CHECK
;
1062 menu
->flags
.realized
= 0;
1069 static void setDockPositionNormalCallback(WMenu
*menu
, WMenuEntry
*entry
)
1071 WDock
*dock
= (WDock
*) entry
->clientdata
;
1073 if (entry
->flags
.indicator_on
) // already set, nothing to do
1075 // Do we come from auto raise lower or keep on top?
1076 if (dock
->auto_raise_lower
)
1078 dock
->auto_raise_lower
= 0;
1079 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1080 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1081 dc
->adrawer
->auto_raise_lower
= 0;
1086 // Will take care of setting lowered = 0 in drawers
1087 toggleLowered(dock
);
1089 entry
->flags
.indicator_on
= 1;
1092 static void setDockPositionAutoRaiseLowerCallback(WMenu
*menu
, WMenuEntry
*entry
)
1094 WDock
*dock
= (WDock
*) entry
->clientdata
;
1096 if (entry
->flags
.indicator_on
) // already set, nothing to do
1098 // Do we come from normal or keep on top?
1101 toggleLowered(dock
);
1103 dock
->auto_raise_lower
= 1;
1104 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1105 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1106 dc
->adrawer
->auto_raise_lower
= 1;
1108 entry
->flags
.indicator_on
= 1;
1111 static void setDockPositionKeepOnTopCallback(WMenu
*menu
, WMenuEntry
*entry
)
1113 WDock
*dock
= (WDock
*) entry
->clientdata
;
1115 if (entry
->flags
.indicator_on
) // already set, nothing to do
1117 dock
->auto_raise_lower
= 0;
1118 // Only for aesthetic purposes, can be removed when Autoraise status is no longer exposed in drawer option menu
1119 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
1120 dc
->adrawer
->auto_raise_lower
= 0;
1122 toggleLowered(dock
);
1123 entry
->flags
.indicator_on
= 1;
1126 static void updateDockPositionMenu(WMenu
*menu
, WDock
*dock
)
1135 entry
= menu
->entries
[index
++];
1136 entry
->flags
.indicator_on
= (dock
->lowered
&& !dock
->auto_raise_lower
);
1137 entry
->clientdata
= dock
;
1139 /* Auto-raise/lower */
1140 entry
= menu
->entries
[index
++];
1141 entry
->flags
.indicator_on
= dock
->auto_raise_lower
;
1142 entry
->clientdata
= dock
;
1145 entry
= menu
->entries
[index
++];
1146 entry
->flags
.indicator_on
= !dock
->lowered
;
1147 entry
->clientdata
= dock
;
1150 static WMenu
*makeDockPositionMenu(WScreen
*scr
)
1152 /* When calling this, the dock is being created, so scr->dock is still not set
1153 * Therefore the callbacks' clientdata and the indicators can't be set,
1154 * they will be updated when the dock menu is opened. */
1158 menu
= wMenuCreate(scr
, NULL
, False
);
1160 wwarning(_("could not create options submenu for dock position menu"));
1164 entry
= wMenuAddCallback(menu
, _("Normal"), setDockPositionNormalCallback
, NULL
);
1165 entry
->flags
.indicator
= 1;
1166 entry
->flags
.indicator_type
= MI_DIAMOND
;
1168 entry
= wMenuAddCallback(menu
, _("Auto raise & lower"), setDockPositionAutoRaiseLowerCallback
, NULL
);
1169 entry
->flags
.indicator
= 1;
1170 entry
->flags
.indicator_type
= MI_DIAMOND
;
1172 entry
= wMenuAddCallback(menu
, _("Keep on Top"), setDockPositionKeepOnTopCallback
, NULL
);
1173 entry
->flags
.indicator
= 1;
1174 entry
->flags
.indicator_type
= MI_DIAMOND
;
1176 menu
->flags
.realized
= 0;
1183 static WMenu
*dockMenuCreate(WScreen
*scr
, int type
)
1188 if (type
== WM_CLIP
&& w_global
.clip
.menu
)
1189 return w_global
.clip
.menu
;
1191 if (type
== WM_DRAWER
&& w_global
.dock
.drawer_menu
)
1192 return w_global
.dock
.drawer_menu
;
1194 menu
= wMenuCreate(scr
, NULL
, False
);
1195 if (type
== WM_DOCK
) {
1196 entry
= wMenuAddCallback(menu
, _("Dock position"), NULL
, NULL
);
1197 if (w_global
.dock
.pos_menu
== NULL
)
1198 w_global
.dock
.pos_menu
= makeDockPositionMenu(scr
);
1199 wMenuEntrySetCascade(menu
, entry
, w_global
.dock
.pos_menu
);
1201 if (!wPreferences
.flags
.nodrawer
) {
1202 entry
= wMenuAddCallback(menu
, _("Add a drawer"), addADrawerCallback
, NULL
);
1205 if (type
== WM_CLIP
)
1206 entry
= wMenuAddCallback(menu
, _("Clip Options"), NULL
, NULL
);
1207 else /* if (type == WM_DRAWER) */
1208 entry
= wMenuAddCallback(menu
, _("Drawer options"), NULL
, NULL
);
1210 if (w_global
.clip
.opt_menu
== NULL
)
1211 w_global
.clip
.opt_menu
= makeClipOptionsMenu(scr
);
1213 wMenuEntrySetCascade(menu
, entry
, w_global
.clip
.opt_menu
);
1215 /* The same menu is used for the dock and its appicons. If the menu
1216 * entry text is different between the two contexts, or if it can
1217 * change depending on some state, free the duplicated string (from
1218 * wMenuInsertCallback) and use gettext's string */
1219 if (type
== WM_CLIP
) {
1220 entry
= wMenuAddCallback(menu
, _("Rename Workspace"), renameCallback
, NULL
);
1222 entry
->text
= _("Rename Workspace"); /* can be: (Toggle) Omnipresent */
1225 entry
= wMenuAddCallback(menu
, _("Selected"), selectCallback
, NULL
);
1226 entry
->flags
.indicator
= 1;
1227 entry
->flags
.indicator_on
= 1;
1228 entry
->flags
.indicator_type
= MI_CHECK
;
1230 entry
= wMenuAddCallback(menu
, _("Select All Icons"), selectIconsCallback
, NULL
);
1232 entry
->text
= _("Select All Icons"); /* can be: Unselect all icons */
1234 entry
= wMenuAddCallback(menu
, _("Keep Icon"), keepIconsCallback
, NULL
);
1236 entry
->text
= _("Keep Icon"); /* can be: Keep Icons */
1238 if (type
== WM_CLIP
) {
1239 entry
= wMenuAddCallback(menu
, _("Move Icon To"), NULL
, NULL
);
1241 entry
->text
= _("Move Icon To"); /* can be: Move Icons to */
1242 w_global
.clip
.submenu
= makeWorkspaceMenu(scr
);
1243 if (w_global
.clip
.submenu
)
1244 wMenuEntrySetCascade(menu
, entry
, w_global
.clip
.submenu
);
1247 entry
= wMenuAddCallback(menu
, _("Remove Icon"), removeIconsCallback
, NULL
);
1249 entry
->text
= _("Remove Icon"); /* can be: Remove Icons */
1251 wMenuAddCallback(menu
, _("Attract Icons"), colectIconsCallback
, NULL
);
1254 wMenuAddCallback(menu
, _("Launch"), launchCallback
, NULL
);
1256 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
1258 entry
= wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
1260 entry
->text
= _("Hide"); /* can be: Unhide */
1262 wMenuAddCallback(menu
, _("Settings..."), settingsCallback
, NULL
);
1264 entry
= wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
1266 entry
->text
= _("Kill"); /* can be: Remove drawer */
1268 if (type
== WM_CLIP
)
1269 w_global
.clip
.menu
= menu
;
1271 if (type
== WM_DRAWER
)
1272 w_global
.dock
.drawer_menu
= menu
;
1277 WDock
*wDockCreate(WScreen
*scr
, int type
, const char *name
)
1284 dock
= wmalloc(sizeof(WDock
));
1288 dock
->max_icons
= DOCK_MAX_ICONS
;
1291 dock
->max_icons
= scr
->scr_width
/ wPreferences
.icon_size
;
1295 dock
->max_icons
= scr
->scr_height
/ wPreferences
.icon_size
;
1298 dock
->icon_array
= wmalloc(sizeof(WAppIcon
*) * dock
->max_icons
);
1300 btn
= mainIconCreate(scr
, type
, name
);
1304 dock
->x_pos
= btn
->x_pos
;
1305 dock
->y_pos
= btn
->y_pos
;
1306 dock
->screen_ptr
= scr
;
1308 dock
->icon_count
= 1;
1309 if (type
== WM_DRAWER
)
1310 dock
->on_right_side
= scr
->dock
->on_right_side
;
1312 dock
->on_right_side
= 1;
1313 dock
->collapsed
= 0;
1314 dock
->auto_collapse
= 0;
1315 dock
->auto_collapse_magic
= NULL
;
1316 dock
->auto_raise_lower
= 0;
1317 dock
->auto_lower_magic
= NULL
;
1318 dock
->auto_raise_magic
= NULL
;
1319 dock
->attract_icons
= 0;
1321 dock
->icon_array
[0] = btn
;
1322 wRaiseFrame(btn
->icon
->core
);
1323 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
1325 /* create dock menu */
1326 dock
->menu
= dockMenuCreate(scr
, type
);
1328 if (type
== WM_DRAWER
) {
1329 drawerAppendToChain(scr
, dock
);
1330 dock
->auto_collapse
= 1;
1336 void wDockDestroy(WDock
*dock
)
1341 for (i
= (dock
->type
== WM_CLIP
) ? 1 : 0; i
< dock
->max_icons
; i
++) {
1342 aicon
= dock
->icon_array
[i
];
1344 int keepit
= aicon
->running
&& wApplicationOf(aicon
->main_window
);
1345 wDockDetach(dock
, aicon
);
1347 /* XXX: can: aicon->icon == NULL ? */
1348 PlaceIcon(dock
->screen_ptr
, &aicon
->x_pos
, &aicon
->y_pos
,
1349 wGetHeadForWindow(aicon
->icon
->owner
));
1350 XMoveWindow(dpy
, aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
);
1351 if (!dock
->mapped
|| dock
->collapsed
)
1352 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1356 if (wPreferences
.auto_arrange_icons
)
1357 wArrangeIcons(dock
->screen_ptr
, True
);
1358 wfree(dock
->icon_array
);
1359 if (dock
->menu
&& dock
->type
!= WM_CLIP
)
1360 wMenuDestroy(dock
->menu
, True
);
1361 if (dock
->screen_ptr
->last_dock
== dock
)
1362 dock
->screen_ptr
->last_dock
= NULL
;
1366 void wClipIconPaint(void)
1368 WAppIcon
*aicon
= w_global
.clip
.icon
;
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
)
1415 static void dockIconPaint(WAppIcon
*btn
)
1417 if (btn
== w_global
.clip
.icon
) {
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
== w_global
.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(w_global
.session_state
, dDock
, dock_state
);
1579 WMReleasePropList(dock_state
);
1582 void wClipSaveState(WScreen
*scr
)
1584 WMPropList
*clip_state
;
1586 clip_state
= make_icon_state(w_global
.clip
.icon
);
1588 WMPutInPLDictionary(w_global
.session_state
, dClip
, clip_state
);
1589 WMReleasePropList(clip_state
);
1592 WMPropList
*wClipSaveWorkspaceState(WScreen
*scr
, int workspace
)
1594 return dockSaveState(w_global
.workspace
.array
[workspace
]->clip
);
1597 static Bool
getBooleanDockValue(WMPropList
*value
, WMPropList
*key
)
1600 if (WMIsPLString(value
)) {
1601 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1604 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(key
));
1610 static WAppIcon
*restore_icon_state(WScreen
*scr
, WMPropList
*info
, int type
, int index
)
1613 WMPropList
*cmd
, *value
;
1614 char *wclass
, *winstance
, *command
;
1616 cmd
= WMGetFromPLDictionary(info
, dCommand
);
1617 if (!cmd
|| !WMIsPLString(cmd
))
1620 /* parse window name */
1621 value
= WMGetFromPLDictionary(info
, dName
);
1625 ParseWindowName(value
, &winstance
, &wclass
, "dock");
1627 if (!winstance
&& !wclass
)
1632 command
= wstrdup(WMGetFromPLString(cmd
));
1636 if (!command
|| strcmp(command
, "-") == 0) {
1647 aicon
= wAppIconCreateForDock(scr
, command
, winstance
, wclass
, TILE_NORMAL
);
1655 aicon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
1656 aicon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
1657 aicon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
1658 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
1659 aicon
->icon
->core
->descriptor
.parent
= aicon
;
1661 #ifdef XDND /* was OFFIX */
1662 cmd
= WMGetFromPLDictionary(info
, dDropCommand
);
1664 aicon
->dnd_command
= wstrdup(WMGetFromPLString(cmd
));
1667 cmd
= WMGetFromPLDictionary(info
, dPasteCommand
);
1669 aicon
->paste_command
= wstrdup(WMGetFromPLString(cmd
));
1671 /* check auto launch */
1672 value
= WMGetFromPLDictionary(info
, dAutoLaunch
);
1674 aicon
->auto_launch
= getBooleanDockValue(value
, dAutoLaunch
);
1677 value
= WMGetFromPLDictionary(info
, dLock
);
1679 aicon
->lock
= getBooleanDockValue(value
, dLock
);
1681 /* check if it wasn't normally docked */
1682 value
= WMGetFromPLDictionary(info
, dForced
);
1684 aicon
->forced_dock
= getBooleanDockValue(value
, dForced
);
1686 /* check if we can rely on the stuff in the app */
1687 value
= WMGetFromPLDictionary(info
, dBuggyApplication
);
1689 aicon
->buggy_app
= getBooleanDockValue(value
, dBuggyApplication
);
1691 /* get position in the dock */
1692 value
= WMGetFromPLDictionary(info
, dPosition
);
1693 if (value
&& WMIsPLString(value
)) {
1694 if (sscanf(WMGetFromPLString(value
), "%hi,%hi", &aicon
->xindex
, &aicon
->yindex
) != 2)
1695 wwarning(_("bad value in docked icon state info %s"), WMGetFromPLString(dPosition
));
1697 /* check position sanity */
1698 /* *Very* incomplete section! */
1699 if (type
== WM_DOCK
) {
1703 aicon
->yindex
= index
;
1707 /* check if icon is omnipresent */
1708 value
= WMGetFromPLDictionary(info
, dOmnipresent
);
1710 aicon
->omnipresent
= getBooleanDockValue(value
, dOmnipresent
);
1718 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1720 WAppIcon
*wClipRestoreState(WScreen
*scr
, WMPropList
*clip_state
)
1725 icon
= mainIconCreate(scr
, WM_CLIP
, NULL
);
1730 WMRetainPropList(clip_state
);
1732 /* restore position */
1734 value
= WMGetFromPLDictionary(clip_state
, dPosition
);
1737 if (!WMIsPLString(value
)) {
1738 COMPLAIN("Position");
1740 if (sscanf(WMGetFromPLString(value
), "%i,%i", &icon
->x_pos
, &icon
->y_pos
) != 2)
1741 COMPLAIN("Position");
1743 /* check position sanity */
1744 if (!onScreen(scr
, icon
->x_pos
, icon
->y_pos
))
1745 wScreenKeepInside(scr
, &icon
->x_pos
, &icon
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1748 #ifdef XDND /* was OFFIX */
1749 value
= WMGetFromPLDictionary(clip_state
, dDropCommand
);
1750 if (value
&& WMIsPLString(value
))
1751 icon
->dnd_command
= wstrdup(WMGetFromPLString(value
));
1754 value
= WMGetFromPLDictionary(clip_state
, dPasteCommand
);
1755 if (value
&& WMIsPLString(value
))
1756 icon
->paste_command
= wstrdup(WMGetFromPLString(value
));
1758 WMReleasePropList(clip_state
);
1763 WDock
*wDockRestoreState(WScreen
*scr
, WMPropList
*dock_state
, int type
)
1768 WAppIcon
*aicon
, *old_top
;
1771 dock
= wDockCreate(scr
, type
, NULL
);
1776 WMRetainPropList(dock_state
);
1778 /* restore position */
1779 value
= WMGetFromPLDictionary(dock_state
, dPosition
);
1781 if (!WMIsPLString(value
)) {
1782 COMPLAIN("Position");
1784 if (sscanf(WMGetFromPLString(value
), "%i,%i", &dock
->x_pos
, &dock
->y_pos
) != 2)
1785 COMPLAIN("Position");
1787 /* check position sanity */
1788 if (!onScreen(scr
, dock
->x_pos
, dock
->y_pos
)) {
1789 int x
= dock
->x_pos
;
1790 wScreenKeepInside(scr
, &x
, &dock
->y_pos
, ICON_SIZE
, ICON_SIZE
);
1793 /* Is this needed any more? */
1794 if (type
== WM_CLIP
) {
1795 if (dock
->x_pos
< 0) {
1797 } else if (dock
->x_pos
> scr
->scr_width
- ICON_SIZE
) {
1798 dock
->x_pos
= scr
->scr_width
- ICON_SIZE
;
1801 if (dock
->x_pos
>= 0) {
1802 dock
->x_pos
= DOCK_EXTRA_SPACE
;
1803 dock
->on_right_side
= 0;
1805 dock
->x_pos
= scr
->scr_width
- DOCK_EXTRA_SPACE
- ICON_SIZE
;
1806 dock
->on_right_side
= 1;
1812 /* restore lowered/raised state */
1815 value
= WMGetFromPLDictionary(dock_state
, dLowered
);
1817 if (!WMIsPLString(value
)) {
1818 COMPLAIN("Lowered");
1820 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1825 /* restore collapsed state */
1826 dock
->collapsed
= 0;
1828 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
1830 if (!WMIsPLString(value
)) {
1831 COMPLAIN("Collapsed");
1833 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1834 dock
->collapsed
= 1;
1838 /* restore auto-collapsed state */
1839 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
1841 if (!WMIsPLString(value
)) {
1842 COMPLAIN("AutoCollapse");
1844 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
1845 dock
->auto_collapse
= 1;
1846 dock
->collapsed
= 1;
1851 /* restore auto-raise/lower state */
1852 value
= WMGetFromPLDictionary(dock_state
, dAutoRaiseLower
);
1854 if (!WMIsPLString(value
)) {
1855 COMPLAIN("AutoRaiseLower");
1857 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1858 dock
->auto_raise_lower
= 1;
1862 /* restore attract icons state */
1863 dock
->attract_icons
= 0;
1865 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
1867 if (!WMIsPLString(value
)) {
1868 COMPLAIN("AutoAttractIcons");
1870 if (strcasecmp(WMGetFromPLString(value
), "YES") == 0)
1871 dock
->attract_icons
= 1;
1875 /* application list */
1882 * When saving, it saves the dock state in
1883 * Applications and Applicationsnnn
1885 * When loading, it will first try Applicationsnnn.
1886 * If it does not exist, use Applications as default.
1889 snprintf(buffer
, sizeof(buffer
), "Applications%i", scr
->scr_height
);
1891 tmp
= WMCreatePLString(buffer
);
1892 apps
= WMGetFromPLDictionary(dock_state
, tmp
);
1893 WMReleasePropList(tmp
);
1896 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
1902 count
= WMGetPropListItemCount(apps
);
1906 old_top
= dock
->icon_array
[0];
1908 /* dock->icon_count is set to 1 when dock is created.
1909 * Since Clip is already restored, we want to keep it so for clip,
1910 * but for dock we may change the default top tile, so we set it to 0.
1912 if (type
== WM_DOCK
)
1913 dock
->icon_count
= 0;
1915 for (i
= 0; i
< count
; i
++) {
1916 if (dock
->icon_count
>= dock
->max_icons
) {
1917 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1921 value
= WMGetFromPLArray(apps
, i
);
1922 aicon
= restore_icon_state(scr
, value
, type
, dock
->icon_count
);
1924 dock
->icon_array
[dock
->icon_count
] = aicon
;
1928 aicon
->x_pos
= dock
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
1929 aicon
->y_pos
= dock
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
1932 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
1934 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
1936 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
1937 if (!dock
->collapsed
)
1938 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1940 wRaiseFrame(aicon
->icon
->core
);
1943 } else if (dock
->icon_count
== 0 && type
== WM_DOCK
) {
1948 /* if the first icon is not defined, use the default */
1949 if (dock
->icon_array
[0] == NULL
) {
1950 /* update default icon */
1951 old_top
->x_pos
= dock
->x_pos
;
1952 old_top
->y_pos
= dock
->y_pos
;
1954 ChangeStackingLevel(old_top
->icon
->core
, WMNormalLevel
);
1956 ChangeStackingLevel(old_top
->icon
->core
, WMDockLevel
);
1958 dock
->icon_array
[0] = old_top
;
1959 XMoveWindow(dpy
, old_top
->icon
->core
->window
, dock
->x_pos
, dock
->y_pos
);
1960 /* we don't need to increment dock->icon_count here because it was
1961 * incremented in the loop above.
1963 } else if (old_top
!= dock
->icon_array
[0]) {
1964 if (old_top
== w_global
.clip
.icon
) /* TODO dande: understand the logic */
1965 w_global
.clip
.icon
= dock
->icon_array
[0];
1967 wAppIconDestroy(old_top
);
1971 WMReleasePropList(dock_state
);
1976 void wDockLaunchWithState(WDock
*dock
, WAppIcon
*btn
, WSavedState
*state
)
1978 if (btn
&& btn
->command
&& !btn
->running
&& !btn
->launching
) {
1979 btn
->drop_launch
= 0;
1980 btn
->paste_launch
= 0;
1982 btn
->pid
= execCommand(btn
, btn
->command
, state
);
1985 if (!btn
->forced_dock
&& !btn
->buggy_app
) {
1995 void wDockDoAutoLaunch(WDock
*dock
, int workspace
)
2001 for (i
= 0; i
< dock
->max_icons
; i
++) {
2002 btn
= dock
->icon_array
[i
];
2003 if (!btn
|| !btn
->auto_launch
)
2006 state
= wmalloc(sizeof(WSavedState
));
2007 state
->workspace
= workspace
;
2008 /* TODO: this is klugy and is very difficult to understand
2009 * what's going on. Try to clean up */
2010 wDockLaunchWithState(dock
, btn
, state
);
2014 #ifdef XDND /* was OFFIX */
2015 static WDock
*findDock(WScreen
*scr
, XEvent
*event
, int *icon_pos
)
2021 if ((dock
= scr
->dock
) != NULL
) {
2022 for (i
= 0; i
< dock
->max_icons
; i
++) {
2023 if (dock
->icon_array
[i
]
2024 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
2030 if (*icon_pos
< 0 && (dock
= w_global
.workspace
.array
[w_global
.workspace
.current
]->clip
) != NULL
) {
2031 for (i
= 0; i
< dock
->max_icons
; i
++) {
2032 if (dock
->icon_array
[i
]
2033 && dock
->icon_array
[i
]->icon
->core
->window
== event
->xclient
.window
) {
2044 int wDockReceiveDNDDrop(WScreen
*scr
, XEvent
*event
)
2050 dock
= findDock(scr
, event
, &icon_pos
);
2055 * Return True if the drop was on an application icon window.
2056 * In this case, let the ClientMessage handler redirect the
2057 * message to the app.
2059 if (dock
->icon_array
[icon_pos
]->icon
->icon_win
!= None
)
2062 if (dock
->icon_array
[icon_pos
]->dnd_command
!= NULL
) {
2063 scr
->flags
.dnd_data_convertion_status
= 0;
2065 btn
= dock
->icon_array
[icon_pos
];
2067 if (!btn
->forced_dock
) {
2068 btn
->relaunching
= btn
->running
;
2071 if (btn
->wm_instance
|| btn
->wm_class
) {
2072 WWindowAttributes attr
;
2073 memset(&attr
, 0, sizeof(WWindowAttributes
));
2074 wDefaultFillAttributes(btn
->wm_instance
, btn
->wm_class
, &attr
, NULL
, True
);
2076 if (!attr
.no_appicon
)
2082 btn
->paste_launch
= 0;
2083 btn
->drop_launch
= 1;
2084 scr
->last_dock
= dock
;
2085 btn
->pid
= execCommand(btn
, btn
->dnd_command
, NULL
);
2090 if (!btn
->relaunching
)
2098 Bool
wDockAttachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
, Bool update_icon
)
2101 Bool lupdate_icon
= False
;
2102 char *command
= NULL
;
2108 lupdate_icon
= True
;
2110 if (icon
->command
== NULL
) {
2111 /* If icon->owner exists, it means the application is running */
2112 if (icon
->icon
->owner
) {
2113 wwin
= icon
->icon
->owner
;
2114 command
= GetCommandForWindow(wwin
->client_win
);
2118 icon
->command
= command
;
2120 /* icon->forced_dock = 1; */
2121 if (dock
->type
!= WM_CLIP
|| !icon
->attracted
) {
2123 if (wInputDialog(dock
->screen_ptr
, _("Dock Icon"),
2124 _("Type the command used to launch the application"), &command
)) {
2125 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2129 icon
->command
= command
;
2135 /* If the target is the dock, reject the icon. If
2136 * the target is the clip, make it an attracted icon
2138 if (dock
->type
== WM_CLIP
) {
2139 icon
->attracted
= 1;
2140 if (!icon
->icon
->shadowed
) {
2141 icon
->icon
->shadowed
= 1;
2142 lupdate_icon
= True
;
2152 for (index
= 1; index
< dock
->max_icons
; index
++)
2153 if (dock
->icon_array
[index
] == NULL
)
2155 /* if (index == dock->max_icons)
2158 assert(index
< dock
->max_icons
);
2160 dock
->icon_array
[index
] = icon
;
2164 icon
->omnipresent
= 0;
2166 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2167 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2172 icon
->launching
= 0;
2175 icon
->icon
->core
->descriptor
.handle_mousedown
= iconMouseDown
;
2176 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2177 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2178 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_DOCK_ICON
;
2179 icon
->icon
->core
->descriptor
.parent
= icon
;
2181 MoveInStackListUnder(dock
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2182 wAppIconMove(icon
, icon
->x_pos
, icon
->y_pos
);
2185 * Update icon pixmap, RImage doesn't change,
2186 * so call wIconUpdate is not needed
2189 update_icon_pixmap(icon
->icon
);
2192 wAppIconPaint(icon
);
2195 save_appicon(icon
, True
);
2197 if (wPreferences
.auto_arrange_icons
)
2198 wArrangeIcons(dock
->screen_ptr
, True
);
2200 #ifdef XDND /* was OFFIX */
2201 if (icon
->command
&& !icon
->dnd_command
) {
2202 int len
= strlen(icon
->command
) + 8;
2203 icon
->dnd_command
= wmalloc(len
);
2204 snprintf(icon
->dnd_command
, len
, "%s %%d", icon
->command
);
2208 if (icon
->command
&& !icon
->paste_command
) {
2209 int len
= strlen(icon
->command
) + 8;
2210 icon
->paste_command
= wmalloc(len
);
2211 snprintf(icon
->paste_command
, len
, "%s %%s", icon
->command
);
2217 void wDockReattachIcon(WDock
*dock
, WAppIcon
*icon
, int x
, int y
)
2221 for (index
= 1; index
< dock
->max_icons
; index
++) {
2222 if (dock
->icon_array
[index
] == icon
)
2225 assert(index
< dock
->max_icons
);
2230 icon
->x_pos
= dock
->x_pos
+ x
* ICON_SIZE
;
2231 icon
->y_pos
= dock
->y_pos
+ y
* ICON_SIZE
;
2234 Bool
wDockMoveIconBetweenDocks(WDock
*src
, WDock
*dest
, WAppIcon
*icon
, int x
, int y
)
2237 char *command
= NULL
;
2239 Bool update_icon
= False
;
2242 return True
; /* No move needed, we're already there */
2248 * For the moment we can't do this if we move icons in Clip from one
2249 * workspace to other, because if we move two or more icons without
2250 * command, the dialog box will not be able to tell us to which of the
2251 * moved icons it applies. -Dan
2253 if ((dest
->type
== WM_DOCK
/*|| dest->keep_attracted */ ) && icon
->command
== NULL
) {
2254 /* If icon->owner exists, it means the application is running */
2255 if (icon
->icon
->owner
) {
2256 wwin
= icon
->icon
->owner
;
2257 command
= GetCommandForWindow(wwin
->client_win
);
2261 icon
->command
= command
;
2264 /* icon->forced_dock = 1; */
2265 if (wInputDialog(src
->screen_ptr
, _("Dock Icon"),
2266 _("Type the command used to launch the application"), &command
)) {
2267 if (command
&& (command
[0] == 0 || (command
[0] == '-' && command
[1] == 0))) {
2271 icon
->command
= command
;
2282 if (dest
->type
== WM_DOCK
|| dest
->type
== WM_DRAWER
)
2283 wClipMakeIconOmnipresent(icon
, False
);
2285 for (index
= 1; index
< src
->max_icons
; index
++) {
2286 if (src
->icon_array
[index
] == icon
)
2289 assert(index
< src
->max_icons
);
2291 src
->icon_array
[index
] = NULL
;
2294 for (index
= 1; index
< dest
->max_icons
; index
++) {
2295 if (dest
->icon_array
[index
] == NULL
)
2299 assert(index
< dest
->max_icons
);
2301 dest
->icon_array
[index
] = icon
;
2304 /* deselect the icon */
2305 if (icon
->icon
->selected
)
2306 wIconSelect(icon
->icon
);
2308 icon
->icon
->core
->descriptor
.handle_enternotify
= clipEnterNotify
;
2309 icon
->icon
->core
->descriptor
.handle_leavenotify
= clipLeaveNotify
;
2311 /* set it to be kept when moving to dock.
2312 * Unless the icon does not have a command set
2314 if (icon
->command
&& (dest
->type
== WM_DOCK
|| dest
->type
== WM_DRAWER
)) {
2315 icon
->attracted
= 0;
2316 if (icon
->icon
->shadowed
) {
2317 icon
->icon
->shadowed
= 0;
2320 save_appicon(icon
, True
);
2323 if (src
->auto_collapse
|| src
->auto_raise_lower
)
2329 icon
->x_pos
= dest
->x_pos
+ x
* ICON_SIZE
;
2330 icon
->y_pos
= dest
->y_pos
+ y
* ICON_SIZE
;
2334 MoveInStackListUnder(dest
->icon_array
[index
- 1]->icon
->core
, icon
->icon
->core
);
2337 * Update icon pixmap, RImage doesn't change,
2338 * so call wIconUpdate is not needed
2341 update_icon_pixmap(icon
->icon
);
2344 wAppIconPaint(icon
);
2349 void wDockDetach(WDock
*dock
, WAppIcon
*icon
)
2352 Bool update_icon
= False
;
2354 /* make the settings panel be closed */
2356 DestroyDockAppSettingsPanel(icon
->panel
);
2358 /* This must be called before icon->dock is set to NULL.
2359 * Don't move it. -Dan
2361 wClipMakeIconOmnipresent(icon
, False
);
2365 icon
->attracted
= 0;
2366 icon
->auto_launch
= 0;
2367 if (icon
->icon
->shadowed
) {
2368 icon
->icon
->shadowed
= 0;
2372 /* deselect the icon */
2373 if (icon
->icon
->selected
)
2374 wIconSelect(icon
->icon
);
2376 if (icon
->command
) {
2377 wfree(icon
->command
);
2378 icon
->command
= NULL
;
2380 #ifdef XDND /* was OFFIX */
2381 if (icon
->dnd_command
) {
2382 wfree(icon
->dnd_command
);
2383 icon
->dnd_command
= NULL
;
2386 if (icon
->paste_command
) {
2387 wfree(icon
->paste_command
);
2388 icon
->paste_command
= NULL
;
2391 for (index
= 1; index
< dock
->max_icons
; index
++)
2392 if (dock
->icon_array
[index
] == icon
)
2395 assert(index
< dock
->max_icons
);
2396 dock
->icon_array
[index
] = NULL
;
2402 /* if the dock is not attached to an application or
2403 * the application did not set the appropriate hints yet,
2404 * destroy the icon */
2405 if (!icon
->running
|| !wApplicationOf(icon
->main_window
)) {
2406 wAppIconDestroy(icon
);
2408 icon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
2409 icon
->icon
->core
->descriptor
.handle_enternotify
= NULL
;
2410 icon
->icon
->core
->descriptor
.handle_leavenotify
= NULL
;
2411 icon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
2412 icon
->icon
->core
->descriptor
.parent
= icon
;
2414 ChangeStackingLevel(icon
->icon
->core
, NORMAL_ICON_LEVEL
);
2417 * Update icon pixmap, RImage doesn't change,
2418 * so call wIconUpdate is not needed
2421 update_icon_pixmap(icon
->icon
);
2424 wAppIconPaint(icon
);
2426 if (wPreferences
.auto_arrange_icons
)
2427 wArrangeIcons(dock
->screen_ptr
, True
);
2429 if (dock
->auto_collapse
|| dock
->auto_raise_lower
)
2434 * returns the closest Dock slot index for the passed
2437 * Returns False if icon can't be docked.
2439 * Note: this function should NEVER alter ret_x or ret_y, unless it will
2442 /* Redocking == true means either icon->dock == dock (normal case)
2443 * or we are called from handleDockMove for a drawer */
2444 Bool
wDockSnapIcon(WDock
*dock
, WAppIcon
*icon
, int req_x
, int req_y
, int *ret_x
, int *ret_y
, int redocking
)
2446 WScreen
*scr
= dock
->screen_ptr
;
2449 int i
, offset
= ICON_SIZE
/ 2;
2450 WAppIcon
*aicon
= NULL
;
2451 WAppIcon
*nicon
= NULL
;
2453 if (wPreferences
.flags
.noupdates
)
2459 /* if the dock is full */
2460 if (!redocking
&& (dock
->icon_count
>= dock
->max_icons
))
2463 /* exact position */
2465 ex_y
= (req_y
- offset
- dy
) / ICON_SIZE
;
2467 ex_y
= (req_y
+ offset
- dy
) / ICON_SIZE
;
2470 ex_x
= (req_x
- offset
- dx
) / ICON_SIZE
;
2472 ex_x
= (req_x
+ offset
- dx
) / ICON_SIZE
;
2474 /* check if the icon is outside the screen boundaries */
2475 if (!onScreen(scr
, dx
+ ex_x
* ICON_SIZE
, dy
+ ex_y
* ICON_SIZE
))
2478 switch (dock
->type
) {
2480 /* We can return False right away if
2481 * - we do not come from this dock (which is a WM_DOCK),
2482 * - we are not right over it, and
2483 * - we are not the main tile of a drawer.
2484 * In the latter case, we are called from handleDockMove. */
2485 if (icon
->dock
!= dock
&& ex_x
!= 0 &&
2486 !(icon
->dock
&& icon
->dock
->type
== WM_DRAWER
&& icon
== icon
->dock
->icon_array
[0]))
2489 if (!redocking
&& ex_x
!= 0)
2492 if (getDrawer(scr
, ex_y
)) /* Return false so that the drawer gets it. */
2496 for (i
= 0; i
< dock
->max_icons
; i
++) {
2497 nicon
= dock
->icon_array
[i
];
2498 if (nicon
&& nicon
->yindex
== ex_y
) {
2505 int sig
, done
, closest
;
2507 /* Possible cases when redocking:
2509 * icon dragged out of range of any slot -> false
2510 * icon dragged on a drawer -> false (to open the drawer)
2511 * icon dragged to range of free slot
2512 * icon dragged to range of same slot
2513 * icon dragged to range of different icon
2515 if (abs(ex_x
) > DOCK_DETTACH_THRESHOLD
)
2518 if (aicon
== icon
|| !aicon
) {
2524 /* start looking at the upper slot or lower? */
2525 if (ex_y
* ICON_SIZE
< (req_y
+ offset
- dy
))
2531 /* look for closest free slot */
2532 for (i
= 0; i
< (DOCK_DETTACH_THRESHOLD
+ 1) * 2 && !done
; i
++) {
2536 closest
= sig
* (i
/ 2) + ex_y
;
2537 /* check if this slot is fully on the screen and not used */
2538 if (onScreen(scr
, dx
, dy
+ closest
* ICON_SIZE
)) {
2539 for (j
= 0; j
< dock
->max_icons
; j
++) {
2540 if (dock
->icon_array
[j
]
2541 && dock
->icon_array
[j
]->yindex
== closest
) {
2542 /* slot is used by someone else */
2543 if (dock
->icon_array
[j
] != icon
)
2548 /* slot is used by a drawer */
2549 done
= done
&& !getDrawer(scr
, closest
);
2556 ((ex_y
>= closest
&& ex_y
- closest
< DOCK_DETTACH_THRESHOLD
+ 1)
2557 || (ex_y
< closest
&& closest
- ex_y
<= DOCK_DETTACH_THRESHOLD
+ 1))) {
2562 } else { /* !redocking */
2564 /* if slot is free and the icon is close enough, return it */
2565 if (!aicon
&& ex_x
== 0) {
2577 start
= icon
->omnipresent
? 0 : w_global
.workspace
.current
;
2578 stop
= icon
->omnipresent
? w_global
.workspace
.count
: start
+ 1;
2581 for (k
= start
; k
< stop
; k
++) {
2582 WDock
*tmp
= w_global
.workspace
.array
[k
]->clip
;
2585 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2586 nicon
= tmp
->icon_array
[i
];
2587 if (nicon
&& nicon
->xindex
== ex_x
&& nicon
->yindex
== ex_y
) {
2595 for (k
= start
; k
< stop
; k
++) {
2596 WDock
*tmp
= w_global
.workspace
.array
[k
]->clip
;
2599 for (i
= 0; i
< tmp
->max_icons
; i
++) {
2600 nicon
= tmp
->icon_array
[i
];
2601 if (nicon
&& nicon
!= icon
&& /* Icon can't be it's own neighbour */
2602 (abs(nicon
->xindex
- ex_x
) <= CLIP_ATTACH_VICINITY
&&
2603 abs(nicon
->yindex
- ex_y
) <= CLIP_ATTACH_VICINITY
)) {
2612 if (neighbours
&& (aicon
== NULL
|| (redocking
&& aicon
== icon
))) {
2621 WAppIcon
*aicons_to_shift
[ dock
->icon_count
];
2622 int index_of_hole
, j
;
2625 abs(ex_x
) - dock
->icon_count
> DOCK_DETTACH_THRESHOLD
||
2626 (ex_x
< 0 && !dock
->on_right_side
) ||
2627 (ex_x
> 0 && dock
->on_right_side
)) {
2632 ex_x
= (dock
->on_right_side
? -1 : 1);
2634 /* "Reduce" ex_x but keep its sign */
2636 if (abs(ex_x
) > dock
->icon_count
- 1) /* minus 1: do not take icon_array[0] into account */
2637 ex_x
= ex_x
* (dock
->icon_count
- 1) / abs(ex_x
); /* don't use *= ! */
2639 if (abs(ex_x
) > dock
->icon_count
)
2640 ex_x
= ex_x
* dock
->icon_count
/ abs(ex_x
);
2642 index_of_hole
= indexOfHole(dock
, icon
, redocking
);
2644 /* Find the appicons between where icon was (index_of_hole) and where
2645 * it wants to be (ex_x) and slide them. */
2647 for (i
= 1; i
< dock
->max_icons
; i
++) {
2648 if ((aicon
= dock
->icon_array
[ i
]) && aicon
!= icon
&&
2649 ((ex_x
<= aicon
->xindex
&& aicon
->xindex
< index_of_hole
) ||
2650 (index_of_hole
< aicon
->xindex
&& aicon
->xindex
<= ex_x
)))
2651 aicons_to_shift
[ j
++ ] = aicon
;
2653 assert(j
== abs(ex_x
- index_of_hole
));
2655 wSlideAppicons(aicons_to_shift
, j
, (index_of_hole
< ex_x
));
2665 static int onScreen(WScreen
*scr
, int x
, int y
)
2672 rect
.size
.width
= rect
.size
.height
= ICON_SIZE
;
2674 wGetRectPlacementInfo(scr
, rect
, &flags
);
2676 return !(flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
));
2680 * returns true if it can find a free slot in the dock,
2681 * in which case it changes x_pos and y_pos accordingly.
2682 * Else returns false.
2684 Bool
wDockFindFreeSlot(WDock
*dock
, int *x_pos
, int *y_pos
)
2686 WScreen
*scr
= dock
->screen_ptr
;
2688 WAppIconChain
*chain
;
2689 unsigned char *slot_map
;
2693 int i
, done
= False
;
2695 int sx
= 0, ex
= scr
->scr_width
, ey
= scr
->scr_height
;
2696 int extra_count
= 0;
2698 if (dock
->type
== WM_DRAWER
) {
2699 if (dock
->icon_count
>= dock
->max_icons
) { /* drawer is full */
2702 *x_pos
= dock
->icon_count
* (dock
->on_right_side
? -1 : 1);
2707 if (dock
->type
== WM_CLIP
&& dock
!= w_global
.workspace
.array
[w_global
.workspace
.current
]->clip
)
2708 extra_count
= scr
->global_icon_count
;
2710 /* if the dock is full */
2711 if (dock
->icon_count
+ extra_count
>= dock
->max_icons
)
2714 if (!wPreferences
.flags
.nodock
&& scr
->dock
) {
2715 if (scr
->dock
->on_right_side
)
2716 ex
-= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2718 sx
+= ICON_SIZE
+ DOCK_EXTRA_SPACE
;
2721 if (ex
< dock
->x_pos
)
2723 if (sx
> dock
->x_pos
+ ICON_SIZE
)
2724 sx
= dock
->x_pos
+ ICON_SIZE
;
2731 /* check if clip is in a corner */
2732 if (dock
->type
== WM_CLIP
) {
2733 if (dock
->x_pos
< 1 && dock
->y_pos
< 1)
2735 else if (dock
->x_pos
< 1 && dock
->y_pos
>= (ey
- ICON_SIZE
))
2737 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
>= (ey
- ICON_SIZE
))
2739 else if (dock
->x_pos
>= (ex
- ICON_SIZE
) && dock
->y_pos
< 1)
2747 /* If the clip is in the corner, use only slots that are in the border
2749 if (corner
!= C_NONE
) {
2753 hcount
= WMIN(dock
->max_icons
, scr
->scr_width
/ ICON_SIZE
);
2754 vcount
= WMIN(dock
->max_icons
, scr
->scr_height
/ ICON_SIZE
);
2755 hmap
= wmalloc(hcount
+ 1);
2756 vmap
= wmalloc(vcount
+ 1);
2758 /* mark used positions */
2761 for (i
= 0; i
< dock
->max_icons
; i
++) {
2762 btn
= dock
->icon_array
[i
];
2766 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2767 vmap
[btn
->yindex
] = 1;
2768 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2769 hmap
[btn
->xindex
] = 1;
2771 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2773 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2774 vmap
[btn
->yindex
] = 1;
2775 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2776 hmap
[btn
->xindex
] = 1;
2780 for (i
= 0; i
< dock
->max_icons
; i
++) {
2781 btn
= dock
->icon_array
[i
];
2785 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2786 vmap
[btn
->yindex
] = 1;
2787 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2788 hmap
[-btn
->xindex
] = 1;
2790 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2792 if (btn
->xindex
== 0 && btn
->yindex
> 0 && btn
->yindex
< vcount
)
2793 vmap
[btn
->yindex
] = 1;
2794 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2795 hmap
[-btn
->xindex
] = 1;
2799 for (i
= 0; i
< dock
->max_icons
; i
++) {
2800 btn
= dock
->icon_array
[i
];
2804 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2805 vmap
[-btn
->yindex
] = 1;
2806 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2807 hmap
[btn
->xindex
] = 1;
2809 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2811 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2812 vmap
[-btn
->yindex
] = 1;
2813 else if (btn
->yindex
== 0 && btn
->xindex
> 0 && btn
->xindex
< hcount
)
2814 hmap
[btn
->xindex
] = 1;
2819 for (i
= 0; i
< dock
->max_icons
; i
++) {
2820 btn
= dock
->icon_array
[i
];
2824 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2825 vmap
[-btn
->yindex
] = 1;
2826 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2827 hmap
[-btn
->xindex
] = 1;
2829 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
) {
2831 if (btn
->xindex
== 0 && btn
->yindex
< 0 && btn
->yindex
> -vcount
)
2832 vmap
[-btn
->yindex
] = 1;
2833 else if (btn
->yindex
== 0 && btn
->xindex
< 0 && btn
->xindex
> -hcount
)
2834 hmap
[-btn
->xindex
] = 1;
2840 /* search a vacant slot */
2841 for (i
= 1; i
< WMAX(vcount
, hcount
); i
++) {
2842 if (i
< vcount
&& vmap
[i
] == 0) {
2848 } else if (i
< hcount
&& hmap
[i
] == 0) {
2858 /* If found a slot, translate and return */
2860 if (corner
== C_NW
|| corner
== C_NE
)
2865 if (corner
== C_NE
|| corner
== C_SE
)
2872 /* else, try to find a slot somewhere else */
2875 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2876 * placed outside of screen */
2877 mwidth
= (int)ceil(sqrt(dock
->max_icons
));
2879 /* In the worst case (the clip is in the corner of the screen),
2880 * the amount of icons that fit in the clip is smaller.
2881 * Double the map to get a safe value.
2885 r
= (mwidth
- 1) / 2;
2887 slot_map
= wmalloc(mwidth
* mwidth
);
2889 #define XY2OFS(x,y) (WMAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2891 /* mark used slots in the map. If the slot falls outside the map
2892 * (for example, when all icons are placed in line), ignore them. */
2893 for (i
= 0; i
< dock
->max_icons
; i
++) {
2894 btn
= dock
->icon_array
[i
];
2896 slot_map
[XY2OFS(btn
->xindex
, btn
->yindex
)] = 1;
2899 for (chain
= scr
->global_icons
; chain
!= NULL
; chain
= chain
->next
)
2900 slot_map
[XY2OFS(chain
->aicon
->xindex
, chain
->aicon
->yindex
)] = 1;
2902 /* Find closest slot from the center that is free by scanning the
2903 * map from the center to outward in circular passes.
2904 * This will not result in a neat layout, but will be optimal
2905 * in the sense that there will not be holes left.
2908 for (i
= 1; i
<= r
&& !done
; i
++) {
2911 /* top and bottom parts of the ring */
2912 for (x
= -i
; x
<= i
&& !done
; x
++) {
2913 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2915 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2916 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2923 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2924 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2931 /* left and right parts of the ring */
2932 for (y
= -i
+ 1; y
<= i
- 1; y
++) {
2933 ty
= dock
->y_pos
+ y
* ICON_SIZE
;
2935 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2936 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2943 tx
= dock
->x_pos
+ x
* ICON_SIZE
;
2944 if (slot_map
[XY2OFS(x
, y
)] == 0 && onScreen(scr
, tx
, ty
)) {
2957 static void moveDock(WDock
*dock
, int new_x
, int new_y
)
2963 if (dock
->type
== WM_DOCK
) {
2964 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
2965 moveDock(dc
->adrawer
, new_x
, dc
->adrawer
->y_pos
- dock
->y_pos
+ new_y
);
2968 dock
->x_pos
= new_x
;
2969 dock
->y_pos
= new_y
;
2970 for (i
= 0; i
< dock
->max_icons
; i
++) {
2971 btn
= dock
->icon_array
[i
];
2973 btn
->x_pos
= new_x
+ btn
->xindex
* ICON_SIZE
;
2974 btn
->y_pos
= new_y
+ btn
->yindex
* ICON_SIZE
;
2975 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
2980 static void swapDock(WDock
*dock
)
2982 WScreen
*scr
= dock
->screen_ptr
;
2986 if (dock
->on_right_side
)
2987 x
= dock
->x_pos
= scr
->scr_width
- ICON_SIZE
- DOCK_EXTRA_SPACE
;
2989 x
= dock
->x_pos
= DOCK_EXTRA_SPACE
;
2991 swapDrawers(scr
, dock
->on_right_side
, x
);
2993 for (i
= 0; i
< dock
->max_icons
; i
++) {
2994 btn
= dock
->icon_array
[i
];
2997 XMoveWindow(dpy
, btn
->icon
->core
->window
, btn
->x_pos
, btn
->y_pos
);
3001 wScreenUpdateUsableArea(scr
);
3004 static pid_t
execCommand(WAppIcon
*btn
, const char *command
, WSavedState
*state
)
3006 WScreen
*scr
= btn
->icon
->core
->screen_ptr
;
3012 cmdline
= ExpandOptions(scr
, command
);
3014 if (scr
->flags
.dnd_data_convertion_status
|| !cmdline
) {
3022 wtokensplit(cmdline
, &argv
, &argc
);
3032 if ((pid
= fork()) == 0) {
3036 SetupEnvironment(scr
);
3042 args
= malloc(sizeof(char *) * (argc
+ 1));
3046 for (i
= 0; i
< argc
; i
++)
3050 execvp(argv
[0], args
);
3053 wtokenfree(argv
, argc
);
3057 state
= wmalloc(sizeof(WSavedState
));
3059 state
->miniaturized
= -1;
3061 if (btn
->dock
== scr
->dock
|| btn
->dock
->type
== WM_DRAWER
|| btn
->omnipresent
)
3062 state
->workspace
= -1;
3064 state
->workspace
= w_global
.workspace
.current
;
3066 wWindowAddSavedState(btn
->wm_instance
, btn
->wm_class
, cmdline
, pid
, state
);
3067 wAddDeathHandler(pid
, (WDeathHandler
*) trackDeadProcess
, btn
->dock
);
3075 void wDockHideIcons(WDock
*dock
)
3082 for (i
= 1; i
< dock
->max_icons
; i
++) {
3083 if (dock
->icon_array
[i
])
3084 XUnmapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3088 dockIconPaint(dock
->icon_array
[0]);
3091 void wDockShowIcons(WDock
*dock
)
3099 btn
= dock
->icon_array
[0];
3100 moveDock(dock
, btn
->x_pos
, btn
->y_pos
);
3102 /* Deleting any change in stacking level, this function is now only about
3105 if (!dock
->collapsed
) {
3106 for (i
= 1; i
< dock
->max_icons
; i
++) {
3107 if (dock
->icon_array
[i
])
3108 XMapWindow(dpy
, dock
->icon_array
[i
]->icon
->core
->window
);
3116 void wDockLower(WDock
*dock
)
3121 if (dock
->type
== WM_DOCK
) {
3122 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3123 wDockLower(dc
->adrawer
);
3125 for (i
= 0; i
< dock
->max_icons
; i
++) {
3126 if (dock
->icon_array
[i
])
3127 wLowerFrame(dock
->icon_array
[i
]->icon
->core
);
3131 void wDockRaise(WDock
*dock
)
3136 for (i
= dock
->max_icons
- 1; i
>= 0; i
--) {
3137 if (dock
->icon_array
[i
])
3138 wRaiseFrame(dock
->icon_array
[i
]->icon
->core
);
3140 if (dock
->type
== WM_DOCK
) {
3141 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3142 wDockRaise(dc
->adrawer
);
3146 void wDockRaiseLower(WDock
*dock
)
3148 if (!dock
->icon_array
[0]->icon
->core
->stacking
->above
3149 || (dock
->icon_array
[0]->icon
->core
->stacking
->window_level
3150 != dock
->icon_array
[0]->icon
->core
->stacking
->above
->stacking
->window_level
))
3156 void wDockFinishLaunch(WDock
*dock
, WAppIcon
*icon
)
3158 icon
->launching
= 0;
3159 icon
->relaunching
= 0;
3160 dockIconPaint(icon
);
3163 WAppIcon
*wDockFindIconForWindow(WDock
*dock
, Window window
)
3168 for (i
= 0; i
< dock
->max_icons
; i
++) {
3169 icon
= dock
->icon_array
[i
];
3170 if (icon
&& icon
->main_window
== window
)
3176 void wDockTrackWindowLaunch(WDock
*dock
, Window window
)
3179 char *wm_class
, *wm_instance
;
3181 Bool firstPass
= True
;
3183 char *command
= NULL
;
3185 if (!PropGetWMClass(window
, &wm_class
, &wm_instance
) || (!wm_class
&& !wm_instance
))
3188 command
= GetCommandForWindow(window
);
3190 for (i
= 0; i
< dock
->max_icons
; i
++) {
3191 icon
= dock
->icon_array
[i
];
3195 /* app is already attached to icon */
3196 if (icon
->main_window
== window
) {
3201 if ((icon
->wm_instance
|| icon
->wm_class
)
3202 && (icon
->launching
|| !icon
->running
)) {
3204 if (icon
->wm_instance
&& wm_instance
&& strcmp(icon
->wm_instance
, wm_instance
) != 0)
3207 if (icon
->wm_class
&& wm_class
&& strcmp(icon
->wm_class
, wm_class
) != 0)
3210 if (firstPass
&& command
&& strcmp(icon
->command
, command
) != 0)
3213 if (!icon
->relaunching
) {
3216 /* Possibly an application that was docked with dockit,
3217 * but the user did not update WMState to indicate that
3218 * it was docked by force */
3219 wapp
= wApplicationOf(window
);
3221 icon
->forced_dock
= 1;
3224 if (!icon
->forced_dock
)
3225 icon
->main_window
= window
;
3228 if (!wPreferences
.no_animations
&& !icon
->launching
&&
3229 !dock
->screen_ptr
->flags
.startup
&& !dock
->collapsed
) {
3233 icon
->launching
= 1;
3234 dockIconPaint(icon
);
3236 aicon
= wAppIconCreateForDock(dock
->screen_ptr
, NULL
,
3237 wm_instance
, wm_class
, TILE_NORMAL
);
3238 /* XXX: can: aicon->icon == NULL ? */
3239 PlaceIcon(dock
->screen_ptr
, &x0
, &y0
, wGetHeadForWindow(aicon
->icon
->owner
));
3240 wAppIconMove(aicon
, x0
, y0
);
3241 /* Should this always be lowered? -Dan */
3243 wLowerFrame(aicon
->icon
->core
);
3244 XMapWindow(dpy
, aicon
->icon
->core
->window
);
3245 aicon
->launching
= 1;
3246 wAppIconPaint(aicon
);
3247 SlideWindow(aicon
->icon
->core
->window
, x0
, y0
, icon
->x_pos
, icon
->y_pos
);
3248 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
3249 wAppIconDestroy(aicon
);
3251 wDockFinishLaunch(dock
, icon
);
3256 if (firstPass
&& !found
) {
3270 void wClipUpdateForWorkspaceChange(WScreen
*scr
, int workspace
)
3272 if (!wPreferences
.flags
.noclip
) {
3273 w_global
.clip
.icon
->dock
= w_global
.workspace
.array
[workspace
]->clip
;
3274 if (w_global
.workspace
.current
!= workspace
) {
3275 WDock
*old_clip
= w_global
.workspace
.array
[w_global
.workspace
.current
]->clip
;
3276 WAppIconChain
*chain
= scr
->global_icons
;
3279 wDockMoveIconBetweenDocks(chain
->aicon
->dock
,
3280 w_global
.workspace
.array
[workspace
]->clip
,
3281 chain
->aicon
, chain
->aicon
->xindex
, chain
->aicon
->yindex
);
3282 if (w_global
.workspace
.array
[workspace
]->clip
->collapsed
)
3283 XUnmapWindow(dpy
, chain
->aicon
->icon
->core
->window
);
3284 chain
= chain
->next
;
3287 wDockHideIcons(old_clip
);
3288 if (old_clip
->auto_raise_lower
) {
3289 if (old_clip
->auto_raise_magic
) {
3290 WMDeleteTimerHandler(old_clip
->auto_raise_magic
);
3291 old_clip
->auto_raise_magic
= NULL
;
3293 wDockLower(old_clip
);
3295 if (old_clip
->auto_collapse
) {
3296 if (old_clip
->auto_expand_magic
) {
3297 WMDeleteTimerHandler(old_clip
->auto_expand_magic
);
3298 old_clip
->auto_expand_magic
= NULL
;
3300 old_clip
->collapsed
= 1;
3302 wDockShowIcons(w_global
.workspace
.array
[workspace
]->clip
);
3307 static void trackDeadProcess(pid_t pid
, unsigned char status
, WDock
*dock
)
3312 for (i
= 0; i
< dock
->max_icons
; i
++) {
3313 icon
= dock
->icon_array
[i
];
3317 if (icon
->launching
&& icon
->pid
== pid
) {
3318 if (!icon
->relaunching
) {
3320 icon
->main_window
= None
;
3322 wDockFinishLaunch(dock
, icon
);
3324 if (status
== 111) {
3329 if (icon
->drop_launch
)
3330 cmd
= icon
->dnd_command
;
3333 if (icon
->paste_launch
)
3334 cmd
= icon
->paste_command
;
3336 cmd
= icon
->command
;
3338 snprintf(msg
, sizeof(msg
), _("Could not execute command \"%s\""), cmd
);
3340 wMessageDialog(dock
->screen_ptr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
3347 /* This function is called when the dock switches state between
3348 * "normal" (including auto-raise/lower) and "keep on top". It is
3349 * therefore clearly distinct from wDockLower/Raise, which are called
3350 * each time a not-kept-on-top dock is lowered/raised. */
3351 static void toggleLowered(WDock
*dock
)
3357 if (!dock
->lowered
) {
3358 newlevel
= WMNormalLevel
;
3361 newlevel
= WMDockLevel
;
3365 for (i
= 0; i
< dock
->max_icons
; i
++) {
3366 tmp
= dock
->icon_array
[i
];
3370 ChangeStackingLevel(tmp
->icon
->core
, newlevel
);
3372 /* When the dock is no longer "on top", explicitly lower it as well.
3373 * It saves some CPU cycles (probably) to do it ourselves here
3374 * rather than calling wDockLower at the end of toggleLowered */
3376 wLowerFrame(tmp
->icon
->core
);
3379 if (dock
->type
== WM_DOCK
) {
3380 for (dc
= dock
->screen_ptr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
3381 toggleLowered(dc
->adrawer
);
3383 wScreenUpdateUsableArea(dock
->screen_ptr
);
3387 static void toggleCollapsed(WDock
*dock
)
3389 if (dock
->collapsed
) {
3390 dock
->collapsed
= 0;
3391 wDockShowIcons(dock
);
3393 dock
->collapsed
= 1;
3394 wDockHideIcons(dock
);
3398 static void openDockMenu(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3400 WScreen
*scr
= dock
->screen_ptr
;
3401 WObjDescriptor
*desc
;
3403 WApplication
*wapp
= NULL
;
3407 int appIsRunning
= aicon
->running
&& aicon
->icon
&& aicon
->icon
->owner
;
3409 if (dock
->type
== WM_DOCK
) {
3410 /* Dock position menu */
3411 updateDockPositionMenu(w_global
.dock
.pos_menu
, dock
);
3412 dock
->menu
->flags
.realized
= 0;
3413 if (!wPreferences
.flags
.nodrawer
) {
3415 entry
= dock
->menu
->entries
[++index
];
3416 entry
->clientdata
= aicon
;
3417 wMenuSetEnabled(dock
->menu
, index
, True
);
3420 /* clip/drawer options */
3421 if (w_global
.clip
.opt_menu
)
3422 updateClipOptionsMenu(w_global
.clip
.opt_menu
, dock
);
3424 n_selected
= numberOfSelectedIcons(dock
);
3426 if (dock
->type
== WM_CLIP
) {
3427 /* Rename Workspace */
3428 entry
= dock
->menu
->entries
[++index
];
3429 if (aicon
== w_global
.clip
.icon
) {
3430 entry
->callback
= renameCallback
;
3431 entry
->clientdata
= dock
;
3432 entry
->flags
.indicator
= 0;
3433 entry
->text
= _("Rename Workspace");
3435 entry
->callback
= omnipresentCallback
;
3436 entry
->clientdata
= aicon
;
3437 if (n_selected
> 0) {
3438 entry
->flags
.indicator
= 0;
3439 entry
->text
= _("Toggle Omnipresent");
3441 entry
->flags
.indicator
= 1;
3442 entry
->flags
.indicator_on
= aicon
->omnipresent
;
3443 entry
->flags
.indicator_type
= MI_CHECK
;
3444 entry
->text
= _("Omnipresent");
3449 /* select/unselect icon */
3450 entry
= dock
->menu
->entries
[++index
];
3451 entry
->clientdata
= aicon
;
3452 entry
->flags
.indicator_on
= aicon
->icon
->selected
;
3453 wMenuSetEnabled(dock
->menu
, index
, aicon
!= w_global
.clip
.icon
&& !wIsADrawer(aicon
));
3455 /* select/unselect all icons */
3456 entry
= dock
->menu
->entries
[++index
];
3457 entry
->clientdata
= aicon
;
3459 entry
->text
= _("Unselect All Icons");
3461 entry
->text
= _("Select All Icons");
3463 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3466 entry
= dock
->menu
->entries
[++index
];
3467 entry
->clientdata
= aicon
;
3469 entry
->text
= _("Keep Icons");
3471 entry
->text
= _("Keep Icon");
3473 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3475 if (dock
->type
== WM_CLIP
) {
3476 /* this is the workspace submenu part */
3477 entry
= dock
->menu
->entries
[++index
];
3479 entry
->text
= _("Move Icons To");
3481 entry
->text
= _("Move Icon To");
3483 if (w_global
.clip
.submenu
)
3484 updateWorkspaceMenu(w_global
.clip
.submenu
, aicon
);
3486 wMenuSetEnabled(dock
->menu
, index
, !aicon
->omnipresent
);
3489 /* remove icon(s) */
3490 entry
= dock
->menu
->entries
[++index
];
3491 entry
->clientdata
= aicon
;
3493 entry
->text
= _("Remove Icons");
3495 entry
->text
= _("Remove Icon");
3497 wMenuSetEnabled(dock
->menu
, index
, dock
->icon_count
> 1);
3499 /* attract icon(s) */
3500 entry
= dock
->menu
->entries
[++index
];
3501 entry
->clientdata
= aicon
;
3503 dock
->menu
->flags
.realized
= 0;
3504 wMenuRealize(dock
->menu
);
3507 if (aicon
->icon
->owner
)
3508 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
3513 entry
= dock
->menu
->entries
[++index
];
3514 entry
->clientdata
= aicon
;
3515 wMenuSetEnabled(dock
->menu
, index
, aicon
->command
!= NULL
);
3518 entry
= dock
->menu
->entries
[++index
];
3519 entry
->clientdata
= aicon
;
3520 if (wapp
&& wapp
->flags
.hidden
)
3521 entry
->text
= _("Unhide Here");
3523 entry
->text
= _("Bring Here");
3525 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3528 entry
= dock
->menu
->entries
[++index
];
3529 entry
->clientdata
= aicon
;
3530 if (wapp
&& wapp
->flags
.hidden
)
3531 entry
->text
= _("Unhide");
3533 entry
->text
= _("Hide");
3535 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3538 entry
= dock
->menu
->entries
[++index
];
3539 entry
->clientdata
= aicon
;
3540 wMenuSetEnabled(dock
->menu
, index
, !aicon
->editing
&& !wPreferences
.flags
.noupdates
);
3542 /* kill or remove drawer */
3543 entry
= dock
->menu
->entries
[++index
];
3544 entry
->clientdata
= aicon
;
3545 if (wIsADrawer(aicon
)) {
3546 entry
->callback
= removeDrawerCallback
;
3547 entry
->text
= _("Remove drawer");
3548 wMenuSetEnabled(dock
->menu
, index
, True
);
3550 entry
->callback
= killCallback
;
3551 entry
->text
= _("Kill");
3552 wMenuSetEnabled(dock
->menu
, index
, appIsRunning
);
3555 if (!dock
->menu
->flags
.realized
)
3556 wMenuRealize(dock
->menu
);
3558 if (dock
->type
== WM_CLIP
|| dock
->type
== WM_DRAWER
) {
3559 /*x_pos = event->xbutton.x_root+2; */
3560 x_pos
= event
->xbutton
.x_root
- dock
->menu
->frame
->core
->width
/ 2 - 1;
3563 } else if (x_pos
+ dock
->menu
->frame
->core
->width
> scr
->scr_width
- 2) {
3564 x_pos
= scr
->scr_width
- dock
->menu
->frame
->core
->width
- 4;
3567 x_pos
= dock
->on_right_side
? scr
->scr_width
- dock
->menu
->frame
->core
->width
- 3 : 0;
3570 wMenuMapAt(dock
->menu
, x_pos
, event
->xbutton
.y_root
+ 2, False
);
3572 /* allow drag select */
3573 event
->xany
.send_event
= True
;
3574 desc
= &dock
->menu
->menu
->descriptor
;
3575 (*desc
->handle_mousedown
) (desc
, event
);
3578 /******************************************************************/
3579 static void iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
3581 WAppIcon
*btn
= desc
->parent
;
3582 WDock
*dock
= btn
->dock
;
3583 WApplication
*wapp
= NULL
;
3586 if (btn
->icon
->owner
&& !(event
->xbutton
.state
& ControlMask
)) {
3587 wapp
= wApplicationOf(btn
->icon
->owner
->main_window
);
3589 assert(wapp
!= NULL
);
3591 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
3593 /* go to the last workspace that the user worked on the app */
3594 if (wapp
->last_workspace
!= w_global
.workspace
.current
&& !unhideHere
)
3595 wWorkspaceChange(dock
->screen_ptr
, wapp
->last_workspace
);
3597 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
3599 if (event
->xbutton
.state
& MOD_MASK
)
3600 wHideOtherApplications(btn
->icon
->owner
);
3602 if (event
->xbutton
.button
== Button1
) {
3603 if (event
->xbutton
.state
& MOD_MASK
) {
3604 /* raise/lower dock */
3605 toggleLowered(dock
);
3606 } else if (btn
== w_global
.clip
.icon
) {
3607 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
)
3608 handleClipChangeWorkspace(dock
->screen_ptr
, event
);
3609 else if (wPreferences
.flags
.clip_merged_in_dock
) {
3610 // Is actually the dock
3613 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3614 launchDockedApplication(btn
, False
);
3618 wShowInfoPanel(dock
->screen_ptr
);
3622 toggleCollapsed(dock
);
3623 } else if (wIsADrawer(btn
)) {
3624 toggleCollapsed(dock
);
3625 } else if (btn
->command
) {
3626 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3627 launchDockedApplication(btn
, False
);
3628 } else if (btn
->xindex
== 0 && btn
->yindex
== 0 && btn
->dock
->type
== WM_DOCK
) {
3629 wShowInfoPanel(dock
->screen_ptr
);
3635 static void handleDockMove(WDock
*dock
, WAppIcon
*aicon
, XEvent
*event
)
3637 WScreen
*scr
= dock
->screen_ptr
;
3638 int ofs_x
= event
->xbutton
.x
, ofs_y
= event
->xbutton
.y
;
3639 WIcon
*icon
= aicon
->icon
;
3642 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;;
3643 int shad_x
= x
, shad_y
= y
;
3645 int grabbed
= 0, done
, previously_on_right
, now_on_right
, previous_x_pos
, i
;
3646 Pixmap ghost
= None
;
3647 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
3649 if (XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3650 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3651 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
)
3652 wwarning("pointer grab failed for dock move");
3654 if (dock
->type
== WM_DRAWER
) {
3656 wins
[0] = icon
->core
->window
;
3657 wins
[1] = scr
->dock_shadow
;
3658 XRestackWindows(dpy
, wins
, 2);
3659 XMoveResizeWindow(dpy
, scr
->dock_shadow
, aicon
->x_pos
, aicon
->y_pos
,
3660 ICON_SIZE
, ICON_SIZE
);
3662 if (icon
->pixmap
!=None
)
3663 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
3665 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
3667 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
3668 XClearWindow(dpy
, scr
->dock_shadow
);
3670 XMapWindow(dpy
, scr
->dock_shadow
);
3673 previously_on_right
= now_on_right
= dock
->on_right_side
;
3674 previous_x_pos
= dock
->x_pos
;
3677 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
3678 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
3685 /* It means the cursor moved so fast that it entered
3686 * something else (if moving slowly, it would have
3687 * stayed in the dock that is being moved. Ignore such
3688 * "spurious" EnterNotifiy's */
3693 if (abs(ofs_x
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
3694 || abs(ofs_y
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
3695 XChangeActivePointerGrab(dpy
, ButtonMotionMask
3696 | ButtonReleaseMask
| ButtonPressMask
,
3697 wPreferences
.cursor
[WCUR_MOVE
], CurrentTime
);
3702 switch (dock
->type
) {
3704 x
= ev
.xmotion
.x_root
- ofs_x
;
3705 y
= ev
.xmotion
.y_root
- ofs_y
;
3706 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3707 moveDock(dock
, x
, y
);
3710 x
= ev
.xmotion
.x_root
- ofs_x
;
3711 y
= ev
.xmotion
.y_root
- ofs_y
;
3712 if (previously_on_right
)
3714 now_on_right
= (ev
.xmotion
.x_root
>= previous_x_pos
- ICON_SIZE
);
3718 now_on_right
= (ev
.xmotion
.x_root
> previous_x_pos
+ ICON_SIZE
* 2);
3720 if (now_on_right
!= dock
->on_right_side
)
3722 dock
->on_right_side
= now_on_right
;
3724 wArrangeIcons(scr
, False
);
3726 // Also perform the vertical move
3727 wScreenKeepInside(scr
, &x
, &y
, ICON_SIZE
, ICON_SIZE
);
3728 moveDock(dock
, dock
->x_pos
, y
);
3729 if (wPreferences
.flags
.wrap_appicons_in_dock
)
3731 for (i
= 0; i
< dock
->max_icons
; i
++) {
3732 int new_y
, new_index
, j
, ok
;
3733 if ((tmpaicon
= dock
->icon_array
[i
]) == NULL
)
3735 if (onScreen(scr
, tmpaicon
->x_pos
, tmpaicon
->y_pos
))
3737 new_y
= (tmpaicon
->y_pos
+ ICON_SIZE
* dock
->max_icons
) % (ICON_SIZE
* dock
->max_icons
);
3738 new_index
= (new_y
- dock
->y_pos
) / ICON_SIZE
;
3739 if (!onScreen(scr
, tmpaicon
->x_pos
, new_y
))
3742 for (j
= 0; j
< dock
->max_icons
; j
++)
3744 if (dock
->icon_array
[j
] != NULL
&&
3745 dock
->icon_array
[j
]->yindex
== new_index
)
3751 if (!ok
|| getDrawer(scr
, new_index
) != NULL
)
3753 wDockReattachIcon(dock
, tmpaicon
, tmpaicon
->xindex
, new_index
);
3755 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
)
3757 int new_y
, new_index
, j
, ok
;
3758 tmpaicon
= dc
->adrawer
->icon_array
[0];
3759 if (onScreen(scr
, tmpaicon
->x_pos
, tmpaicon
->y_pos
))
3761 new_y
= (tmpaicon
->y_pos
+ ICON_SIZE
* dock
->max_icons
) % (ICON_SIZE
* dock
->max_icons
);
3762 new_index
= (new_y
- dock
->y_pos
) / ICON_SIZE
;
3763 if (!onScreen(scr
, tmpaicon
->x_pos
, new_y
))
3766 for (j
= 0; j
< dock
->max_icons
; j
++)
3768 if (dock
->icon_array
[j
] != NULL
&&
3769 dock
->icon_array
[j
]->yindex
== new_index
)
3775 if (!ok
|| getDrawer(scr
, new_index
) != NULL
)
3777 moveDock(dc
->adrawer
, tmpaicon
->x_pos
, new_y
);
3783 WDock
*real_dock
= dock
->screen_ptr
->dock
;
3786 x
= ev
.xmotion
.x_root
- ofs_x
;
3787 y
= ev
.xmotion
.y_root
- ofs_y
;
3788 snapped
= wDockSnapIcon(real_dock
, aicon
, x
, y
, &ix
, &iy
, True
);
3790 shad_x
= real_dock
->x_pos
+ ix
* wPreferences
.icon_size
;
3791 shad_y
= real_dock
->y_pos
+ iy
* wPreferences
.icon_size
;
3792 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
3794 moveDock(dock
, x
, y
);
3804 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
3806 XUngrabPointer(dpy
, CurrentTime
);
3807 if (dock
->type
== WM_DRAWER
) {
3808 Window
*wins
[dock
->icon_count
];
3810 for (i
= 0; i
< dock
->max_icons
; i
++) {
3811 if ((tmpaicon
= dock
->icon_array
[i
]) == NULL
)
3813 wins
[ tmpaicon
->xindex
+ (dock
->on_right_side
? dock
->icon_count
- 1 : 0) ] = &tmpaicon
->icon
->core
->window
;
3815 SlideWindows(wins
, dock
->icon_count
,
3816 (dock
->on_right_side
? x
- (dock
->icon_count
- 1) * ICON_SIZE
: x
),
3818 (dock
->on_right_side
? shad_x
- (dock
->icon_count
- 1) * ICON_SIZE
: shad_x
),
3820 XUnmapWindow(dpy
, scr
->dock_shadow
);
3821 moveDock(dock
, shad_x
, shad_y
);
3822 XResizeWindow(dpy
, scr
->dock_shadow
, ICON_SIZE
, ICON_SIZE
);
3830 XFreePixmap(dpy
, ghost
);
3831 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
3836 static int getClipButton(int px
, int py
)
3838 int pt
= (CLIP_BUTTON_SIZE
+ 2) * ICON_SIZE
/ 64;
3840 if (px
< 0 || py
< 0 || px
>= ICON_SIZE
|| py
>= ICON_SIZE
)
3843 if (py
<= pt
- ((int)ICON_SIZE
- 1 - px
))
3844 return CLIP_FORWARD
;
3845 else if (px
<= pt
- ((int)ICON_SIZE
- 1 - py
))
3851 static void handleClipChangeWorkspace(WScreen
*scr
, XEvent
*event
)
3854 int done
, direction
, new_ws
;
3856 WDock
*clip
= w_global
.clip
.icon
->dock
;
3858 direction
= getClipButton(event
->xbutton
.x
, event
->xbutton
.y
);
3860 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3861 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3866 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
3873 new_dir
= getClipButton(ev
.xmotion
.x
, ev
.xmotion
.y
);
3874 if (new_dir
!= direction
) {
3875 direction
= new_dir
;
3876 clip
->lclip_button_pushed
= direction
== CLIP_REWIND
;
3877 clip
->rclip_button_pushed
= direction
== CLIP_FORWARD
;
3886 if (ev
.xbutton
.button
== event
->xbutton
.button
)
3891 clip
->lclip_button_pushed
= 0;
3892 clip
->rclip_button_pushed
= 0;
3894 new_ws
= wPreferences
.ws_advance
|| (event
->xbutton
.state
& ControlMask
);
3896 if (direction
== CLIP_FORWARD
) {
3897 if (w_global
.workspace
.current
< w_global
.workspace
.count
- 1)
3898 wWorkspaceChange(scr
, w_global
.workspace
.current
+ 1);
3899 else if (new_ws
&& w_global
.workspace
.current
< MAX_WORKSPACES
- 1)
3900 wWorkspaceChange(scr
, w_global
.workspace
.current
+ 1);
3901 else if (wPreferences
.ws_cycle
)
3902 wWorkspaceChange(scr
, 0);
3903 } else if (direction
== CLIP_REWIND
) {
3904 if (w_global
.workspace
.current
> 0)
3905 wWorkspaceChange(scr
, w_global
.workspace
.current
- 1);
3906 else if (w_global
.workspace
.current
== 0 && wPreferences
.ws_cycle
)
3907 wWorkspaceChange(scr
, w_global
.workspace
.count
- 1);
3913 static void iconMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3915 WAppIcon
*aicon
= desc
->parent
;
3916 WDock
*dock
= aicon
->dock
;
3917 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
3919 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
3922 scr
->last_dock
= dock
;
3924 if (dock
->menu
->flags
.mapped
)
3925 wMenuUnmap(dock
->menu
);
3927 if (IsDoubleClick(scr
, event
)) {
3928 /* double-click was not in the main clip icon */
3929 if (dock
->type
!= WM_CLIP
|| aicon
->xindex
!= 0 || aicon
->yindex
!= 0
3930 || getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) == CLIP_IDLE
) {
3931 iconDblClick(desc
, event
);
3936 if (event
->xbutton
.button
== Button1
) {
3937 if (event
->xbutton
.state
& MOD_MASK
)
3942 if ((event
->xbutton
.state
& ShiftMask
) && aicon
!= w_global
.clip
.icon
&& dock
->type
!= WM_DOCK
) {
3943 wIconSelect(aicon
->icon
);
3947 if (aicon
->yindex
== 0 && aicon
->xindex
== 0) {
3948 if (getClipButton(event
->xbutton
.x
, event
->xbutton
.y
) != CLIP_IDLE
&&
3949 (dock
->type
== WM_CLIP
|| (dock
->type
== WM_DOCK
&& wPreferences
.flags
.clip_merged_in_dock
)))
3950 handleClipChangeWorkspace(scr
, event
);
3952 handleDockMove(dock
, aicon
, event
);
3954 Bool hasMoved
= wHandleAppIconMove(aicon
, event
);
3955 if (wPreferences
.single_click
&& !hasMoved
)
3956 iconDblClick(desc
, event
);
3958 } else if (event
->xbutton
.button
== Button2
&& aicon
== w_global
.clip
.icon
) {
3959 if (!w_global
.clip
.ws_menu
)
3960 w_global
.clip
.ws_menu
= wWorkspaceMenuMake(scr
, False
);
3962 if (w_global
.clip
.ws_menu
) {
3963 WMenu
*wsMenu
= w_global
.clip
.ws_menu
;
3966 wWorkspaceMenuUpdate(wsMenu
);
3968 xpos
= event
->xbutton
.x_root
- wsMenu
->frame
->core
->width
/ 2 - 1;
3971 } else if (xpos
+ wsMenu
->frame
->core
->width
> scr
->scr_width
- 2) {
3972 xpos
= scr
->scr_width
- wsMenu
->frame
->core
->width
- 4;
3974 wMenuMapAt(wsMenu
, xpos
, event
->xbutton
.y_root
+ 2, False
);
3976 desc
= &wsMenu
->menu
->descriptor
;
3977 event
->xany
.send_event
= True
;
3978 (*desc
->handle_mousedown
) (desc
, event
);
3980 } else if (event
->xbutton
.button
== Button2
&& dock
->type
== WM_CLIP
&&
3981 (event
->xbutton
.state
& ShiftMask
) && aicon
!= w_global
.clip
.icon
) {
3982 wClipMakeIconOmnipresent(aicon
, !aicon
->omnipresent
);
3983 } else if (event
->xbutton
.button
== Button3
) {
3984 if (event
->xbutton
.send_event
&&
3985 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
3986 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
3987 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3988 wwarning("pointer grab failed for dockicon menu");
3992 openDockMenu(dock
, aicon
, event
);
3993 } else if (event
->xbutton
.button
== Button2
) {
3994 WAppIcon
*btn
= desc
->parent
;
3996 if (!btn
->launching
&& (!btn
->running
|| (event
->xbutton
.state
& ControlMask
)))
3997 launchDockedApplication(btn
, True
);
4001 static void clipEnterNotify(WObjDescriptor
*desc
, XEvent
*event
)
4003 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
4007 assert(event
->type
== EnterNotify
);
4009 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
4012 scr
= btn
->icon
->core
->screen_ptr
;
4018 /* The auto raise/lower code */
4019 tmp
= (dock
->type
== WM_DRAWER
? scr
->dock
: dock
);
4020 if (tmp
->auto_lower_magic
) {
4021 WMDeleteTimerHandler(tmp
->auto_lower_magic
);
4022 tmp
->auto_lower_magic
= NULL
;
4024 if (tmp
->auto_raise_lower
&& !tmp
->auto_raise_magic
)
4025 tmp
->auto_raise_magic
= WMAddTimerHandler(wPreferences
.clip_auto_raise_delay
, clipAutoRaise
, (void *) tmp
);
4027 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4030 /* The auto expand/collapse code */
4031 if (dock
->auto_collapse_magic
) {
4032 WMDeleteTimerHandler(dock
->auto_collapse_magic
);
4033 dock
->auto_collapse_magic
= NULL
;
4035 if (dock
->auto_collapse
&& !dock
->auto_expand_magic
)
4036 dock
->auto_expand_magic
= WMAddTimerHandler(wPreferences
.clip_auto_expand_delay
, clipAutoExpand
, (void *)dock
);
4039 static void clipLeave(WDock
*dock
)
4042 WObjDescriptor
*desc
= NULL
;
4048 if (XCheckTypedEvent(dpy
, EnterNotify
, &event
) != False
) {
4049 if (XFindContext(dpy
, event
.xcrossing
.window
, w_global
.context
.client_win
,
4050 (XPointer
*) & desc
) != XCNOENT
4051 && desc
&& desc
->parent_type
== WCLASS_DOCK_ICON
4052 && ((WAppIcon
*) desc
->parent
)->dock
== dock
) {
4053 /* We haven't left the dock/clip/drawer yet */
4054 XPutBackEvent(dpy
, &event
);
4058 XPutBackEvent(dpy
, &event
);
4060 /* We entered a withdrawn window, so we're still in Clip */
4064 tmp
= (dock
->type
== WM_DRAWER
? dock
->screen_ptr
->dock
: dock
);
4065 if (tmp
->auto_raise_magic
) {
4066 WMDeleteTimerHandler(tmp
->auto_raise_magic
);
4067 tmp
->auto_raise_magic
= NULL
;
4069 if (tmp
->auto_raise_lower
&& !tmp
->auto_lower_magic
)
4070 tmp
->auto_lower_magic
= WMAddTimerHandler(wPreferences
.clip_auto_lower_delay
, clipAutoLower
, (void *)tmp
);
4072 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4075 if (dock
->auto_expand_magic
) {
4076 WMDeleteTimerHandler(dock
->auto_expand_magic
);
4077 dock
->auto_expand_magic
= NULL
;
4079 if (dock
->auto_collapse
&& !dock
->auto_collapse_magic
)
4080 dock
->auto_collapse_magic
= WMAddTimerHandler(wPreferences
.clip_auto_collapse_delay
, clipAutoCollapse
, (void *)dock
);
4083 static void clipLeaveNotify(WObjDescriptor
*desc
, XEvent
*event
)
4085 WAppIcon
*btn
= (WAppIcon
*) desc
->parent
;
4087 assert(event
->type
== LeaveNotify
);
4089 if (desc
->parent_type
!= WCLASS_DOCK_ICON
)
4092 clipLeave(btn
->dock
);
4095 static void clipAutoCollapse(void *cdata
)
4097 WDock
*dock
= (WDock
*) cdata
;
4099 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4102 if (dock
->auto_collapse
) {
4103 dock
->collapsed
= 1;
4104 wDockHideIcons(dock
);
4106 dock
->auto_collapse_magic
= NULL
;
4109 static void clipAutoExpand(void *cdata
)
4111 WDock
*dock
= (WDock
*) cdata
;
4113 if (dock
->type
!= WM_CLIP
&& dock
->type
!= WM_DRAWER
)
4116 if (dock
->auto_collapse
) {
4117 dock
->collapsed
= 0;
4118 wDockShowIcons(dock
);
4120 dock
->auto_expand_magic
= NULL
;
4123 static void clipAutoLower(void *cdata
)
4125 WDock
*dock
= (WDock
*) cdata
;
4127 if (dock
->auto_raise_lower
)
4130 dock
->auto_lower_magic
= NULL
;
4133 static void clipAutoRaise(void *cdata
)
4135 WDock
*dock
= (WDock
*) cdata
;
4137 if (dock
->auto_raise_lower
)
4140 dock
->auto_raise_magic
= NULL
;
4143 static Bool
iconCanBeOmnipresent(WAppIcon
*aicon
)
4145 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4150 for (i
= 0; i
< w_global
.workspace
.count
; i
++) {
4151 clip
= w_global
.workspace
.array
[i
]->clip
;
4153 if (clip
== aicon
->dock
)
4156 if (clip
->icon_count
+ scr
->global_icon_count
>= clip
->max_icons
)
4157 return False
; /* Clip is full in some workspace */
4159 for (j
= 0; j
< clip
->max_icons
; j
++) {
4160 btn
= clip
->icon_array
[j
];
4161 if (btn
&& btn
->xindex
== aicon
->xindex
&& btn
->yindex
== aicon
->yindex
)
4169 int wClipMakeIconOmnipresent(WAppIcon
*aicon
, int omnipresent
)
4171 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
4172 WAppIconChain
*new_entry
, *tmp
, *tmp1
;
4173 int status
= WO_SUCCESS
;
4175 if ((scr
->dock
&& aicon
->dock
== scr
->dock
) || aicon
== w_global
.clip
.icon
)
4176 return WO_NOT_APPLICABLE
;
4178 if (aicon
->omnipresent
== omnipresent
)
4182 if (iconCanBeOmnipresent(aicon
)) {
4183 aicon
->omnipresent
= 1;
4184 new_entry
= wmalloc(sizeof(WAppIconChain
));
4185 new_entry
->aicon
= aicon
;
4186 new_entry
->next
= scr
->global_icons
;
4187 scr
->global_icons
= new_entry
;
4188 scr
->global_icon_count
++;
4190 aicon
->omnipresent
= 0;
4194 aicon
->omnipresent
= 0;
4195 if (aicon
== scr
->global_icons
->aicon
) {
4196 tmp
= scr
->global_icons
->next
;
4197 wfree(scr
->global_icons
);
4198 scr
->global_icons
= tmp
;
4199 scr
->global_icon_count
--;
4201 tmp
= scr
->global_icons
;
4203 if (tmp
->next
->aicon
== aicon
) {
4204 tmp1
= tmp
->next
->next
;
4207 scr
->global_icon_count
--;
4215 wAppIconPaint(aicon
);
4220 static void drawerAppendToChain(WScreen
*scr
, WDock
*drawer
)
4222 WDrawerChain
**where_to_add
;
4224 where_to_add
= &scr
->drawers
;
4225 while ((*where_to_add
) != NULL
) {
4226 where_to_add
= &(*where_to_add
)->next
;
4229 *where_to_add
= wmalloc(sizeof(WDrawerChain
));
4230 (*where_to_add
)->adrawer
= drawer
;
4231 (*where_to_add
)->next
= NULL
;
4232 scr
->drawer_count
++;
4236 static void drawerRemoveFromChain(WScreen
*scr
, WDock
*drawer
)
4238 WDrawerChain
*next
, **to_remove
;
4240 to_remove
= &scr
->drawers
;
4242 if (*to_remove
== NULL
) {
4243 wwarning("The drawer to be removed can not be found.");
4246 if ((*to_remove
)->adrawer
== drawer
)
4249 to_remove
= &(*to_remove
)->next
;
4251 next
= (*to_remove
)->next
;
4254 scr
->drawer_count
--;
4258 /* Don't free the returned string. Duplicate it. */
4259 static char * findUniqueName(WScreen
*scr
, const char *instance_basename
)
4261 static char buffer
[128];
4264 Bool already_in_use
= True
;
4266 #define UNIQUE_NAME_WATCHDOG 128
4267 for (i
= 0; already_in_use
&& i
< UNIQUE_NAME_WATCHDOG
; i
++) {
4268 snprintf(buffer
, sizeof buffer
, "%s%d", instance_basename
, i
);
4270 already_in_use
= False
;
4272 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4273 if (!strncmp(dc
->adrawer
->icon_array
[0]->wm_instance
, buffer
,
4275 already_in_use
= True
;
4281 if (i
== UNIQUE_NAME_WATCHDOG
)
4282 wwarning("Couldn't find a unique name for drawer in %d attempts.", i
);
4283 #undef UNIQUE_NAME_WATCHDOG
4289 static void drawerIconExpose(WObjDescriptor
*desc
, XEvent
*event
)
4291 wDrawerIconPaint((WAppIcon
*) desc
->parent
);
4295 static int addADrawer(WScreen
*scr
)
4297 int i
, y
, sig
, found_y
;
4298 WDock
*drawer
, *dock
= scr
->dock
;
4300 char can_be_here
[2 * dock
->max_icons
- 1];
4302 if (dock
->icon_count
+ scr
->drawer_count
>= dock
->max_icons
)
4305 for (y
= -dock
->max_icons
+ 1; y
< dock
->max_icons
; y
++) {
4306 can_be_here
[y
+ dock
->max_icons
- 1] = True
;
4308 for (i
= 0; i
< dock
->max_icons
; i
++) {
4309 if (dock
->icon_array
[i
] != NULL
)
4310 can_be_here
[dock
->icon_array
[i
]->yindex
+ dock
->max_icons
- 1] = False
;
4312 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4313 y
= (int) ((dc
->adrawer
->y_pos
- dock
->y_pos
) / ICON_SIZE
);
4314 can_be_here
[y
+ dock
->max_icons
- 1] = False
;
4318 for (sig
= 1; !found_y
&& sig
> -2; sig
-= 2) // 1, then -1
4320 for (y
= sig
; sig
* y
< dock
->max_icons
; y
+= sig
)
4322 if (can_be_here
[y
+ dock
->max_icons
- 1] &&
4323 onScreen(scr
, dock
->x_pos
, dock
->y_pos
+ y
* ICON_SIZE
))
4332 /* This can happen even when dock->icon_count + scr->drawer_count
4333 * < dock->max_icons when the dock is not aligned on an
4334 * ICON_SIZE multiple, as some space is lost above and under it */
4337 drawer
= wDockCreate(scr
, WM_DRAWER
, NULL
);
4338 drawer
->lowered
= scr
->dock
->lowered
;
4339 drawer
->auto_raise_lower
= scr
->dock
->auto_raise_lower
;
4340 drawer
->x_pos
= dock
->x_pos
;
4341 drawer
->y_pos
= dock
->y_pos
+ ICON_SIZE
* y
;
4342 drawer
->icon_array
[0]->xindex
= 0;
4343 drawer
->icon_array
[0]->yindex
= 0;
4344 drawer
->icon_array
[0]->x_pos
= drawer
->x_pos
;
4345 drawer
->icon_array
[0]->y_pos
= drawer
->y_pos
;
4346 XMoveWindow(dpy
, drawer
->icon_array
[0]->icon
->core
->window
,
4347 drawer
->icon_array
[0]->x_pos
, drawer
->icon_array
[0]->y_pos
);
4353 static void addADrawerCallback(WMenu
*menu
, WMenuEntry
*entry
)
4355 assert(entry
->clientdata
!=NULL
);
4356 addADrawer(((WAppIcon
*) entry
->clientdata
)->dock
->screen_ptr
);
4360 static void drawerDestroy(WDock
*drawer
)
4370 scr
= drawer
->screen_ptr
;
4372 /* Note regarding menus: we can't delete any dock/clip/drawer menu, because
4373 * that would (attempt to) wfree some memory in gettext library (see menu
4374 * entries that have several "versions", such like "Hide" and "Unhide"). */
4376 wDefaultPurgeInfo(scr
, drawer
->icon_array
[0]->wm_instance
,
4377 drawer
->icon_array
[0]->wm_class
);
4378 icons
= WMCreateArray(drawer
->icon_count
- 1);
4379 for (i
= 1; i
< drawer
->max_icons
; i
++) {
4380 if (!(aicon
= drawer
->icon_array
[i
]))
4382 WMAddToArray(icons
, aicon
);
4384 removeIcons(icons
, drawer
);
4386 if (drawer
->auto_collapse_magic
) {
4387 WMDeleteTimerHandler(drawer
->auto_collapse_magic
);
4388 drawer
->auto_collapse_magic
= NULL
;
4390 if (drawer
->auto_lower_magic
) {
4391 WMDeleteTimerHandler(drawer
->auto_lower_magic
);
4392 drawer
->auto_lower_magic
= NULL
;
4395 wAppIconDestroy(drawer
->icon_array
[0]);
4396 wfree(drawer
->icon_array
);
4399 drawerRemoveFromChain(scr
, drawer
);
4400 if (scr
->last_dock
== drawer
)
4401 scr
->last_dock
= NULL
;
4402 if (scr
->attracting_drawer
== drawer
)
4403 scr
->attracting_drawer
= NULL
;
4407 static void removeDrawerCallback(WMenu
*menu
, WMenuEntry
*entry
)
4409 WDock
*dock
= ((WAppIcon
*)entry
->clientdata
)->dock
;
4410 assert(dock
!= NULL
);
4412 if (dock
->icon_count
> 1) {
4413 if (wMessageDialog(dock
->screen_ptr
, _("Drawer"),
4414 _("All icons in this drawer will be detached!"),
4415 _("OK"), _("Cancel"), NULL
) != WAPRDefault
)
4418 drawerDestroy(dock
);
4422 void wDrawerIconPaint(WAppIcon
*dicon
)
4424 Window win
= dicon
->icon
->core
->window
;
4425 WScreen
*scr
= dicon
->icon
->core
->screen_ptr
;
4427 GC gc
= scr
->draw_gc
;
4430 wIconPaint(dicon
->icon
);
4432 if (!dicon
->dock
->collapsed
)
4433 color
= scr
->clip_title_color
[CLIP_NORMAL
];
4435 color
= scr
->clip_title_color
[CLIP_COLLAPSED
];
4436 XSetForeground(dpy
, gc
, WMColorPixel(color
));
4438 if (dicon
->dock
->on_right_side
) {
4439 p
[0].x
= p
[3].x
= 10;
4440 p
[0].y
= p
[3].y
= ICON_SIZE
/ 2 - 5;
4442 p
[1].y
= ICON_SIZE
/ 2 + 5;
4444 p
[2].y
= ICON_SIZE
/ 2;
4447 p
[0].x
= p
[3].x
= ICON_SIZE
-1 - 10;
4448 p
[0].y
= p
[3].y
= ICON_SIZE
/ 2 - 5;
4449 p
[1].x
= ICON_SIZE
-1 - 10;
4450 p
[1].y
= ICON_SIZE
/ 2 + 5;
4451 p
[2].x
= ICON_SIZE
-1 - 5;
4452 p
[2].y
= ICON_SIZE
/ 2;
4454 XFillPolygon(dpy
, win
, gc
, p
,3,Convex
,CoordModeOrigin
);
4455 XDrawLines(dpy
, win
, gc
, p
,4,CoordModeOrigin
);
4459 RImage
* wDrawerMakeTile(WScreen
*scr
, RImage
*normalTile
)
4461 RImage
*tile
= RCloneImage(normalTile
);
4466 dark
.red
= dark
.green
= dark
.blue
= 60;
4469 light
.red
= light
.green
= light
.blue
= 80;
4472 if (!scr
->dock
|| scr
->dock
->on_right_side
) {
4473 ROperateLine(tile
, RSubtractOperation
, 11, ICON_SIZE
/ 2 - 7,
4474 4, ICON_SIZE
/ 2, &dark
); /* / */
4475 ROperateLine(tile
, RSubtractOperation
, 11, ICON_SIZE
/ 2 + 7,
4476 4, ICON_SIZE
/ 2, &dark
); /* \ */
4477 ROperateLine(tile
, RAddOperation
, 11, ICON_SIZE
/ 2 - 7,
4478 11, ICON_SIZE
/ 2 + 7, &light
); /* | */
4481 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 - 7,
4482 ICON_SIZE
-1 - 4, ICON_SIZE
/ 2, &dark
); /* \ */
4483 ROperateLine(tile
, RAddOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 + 7,
4484 ICON_SIZE
-1 - 4, ICON_SIZE
/ 2, &light
); /* / */
4485 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 - 7,
4486 ICON_SIZE
-1 - 11, ICON_SIZE
/ 2 + 7, &dark
); /* | */
4492 static void swapDrawer(WDock
*drawer
, int new_x
)
4496 drawer
->on_right_side
= !drawer
->on_right_side
;
4497 drawer
->x_pos
= new_x
;
4499 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4501 if ((ai
= drawer
->icon_array
[i
]) == NULL
)
4503 ai
->xindex
*= -1; /* so A B C becomes C B A */
4504 ai
->x_pos
= new_x
+ ai
->xindex
* ICON_SIZE
;
4506 /* Update drawer's tile */
4508 wIconUpdate(ai
->icon
);
4509 wDrawerIconPaint(ai
);
4511 XMoveWindow(dpy
, ai
->icon
->core
->window
, ai
->x_pos
, ai
->y_pos
);
4516 static void swapDrawers(WScreen
*scr
, int on_right_side
, int new_x
)
4520 if (scr
->drawer_tile
) {
4521 RReleaseImage(scr
->drawer_tile
);
4523 scr
->drawer_tile
= wDrawerMakeTile(scr
, scr
->icon_tile
);
4525 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4526 swapDrawer(dc
->adrawer
, new_x
);
4527 assert(dc
->adrawer
->on_right_side
== on_right_side
);
4532 int wIsADrawer(WAppIcon
*aicon
)
4534 return aicon
&& aicon
->dock
&&
4535 aicon
->dock
->type
== WM_DRAWER
&& aicon
->dock
->icon_array
[0] == aicon
;
4539 static WDock
* getDrawer(WScreen
*scr
, int y_index
)
4543 for (dc
= scr
->drawers
; dc
!= NULL
; dc
= dc
->next
) {
4544 if (dc
->adrawer
->y_pos
- scr
->dock
->y_pos
== y_index
* ICON_SIZE
)
4552 /* Find the "hole" a moving appicon created when snapped into the
4553 * drawer. redocking is a boolean. If the moving appicon comes from the
4554 * drawer, drawer->icon_count is correct. If not, redocking is then false and
4555 * there are now drawer->icon_count plus one appicons in the drawer. */
4556 static int indexOfHole(WDock
*drawer
, WAppIcon
*moving_aicon
, int redocking
)
4558 int index_of_hole
, i
;
4560 /* Classic interview question...
4562 * We have n-1 (n = drawer->icon_count-1 or drawer->icon_count, see
4563 * redocking) appicons, whose xindex are unique in [1..n]. One is missing:
4564 * that's where the ghost of the moving appicon is, that's what the
4565 * function should return.
4567 * We compute 1+2+...+n (this sum is equal to n*(n+1)/2), we substract to
4568 * this sum the xindex of each of the n-1 appicons, and we get the correct
4572 index_of_hole
= (drawer
->icon_count
- 1) * drawer
->icon_count
/ 2;
4574 index_of_hole
= drawer
->icon_count
* (drawer
->icon_count
+ 1) / 2;
4576 index_of_hole
*= (drawer
->on_right_side
? -1 : 1);
4578 for (i
= 1; i
< drawer
->max_icons
; i
++) {
4579 if (drawer
->icon_array
[i
] && drawer
->icon_array
[i
] != moving_aicon
)
4580 index_of_hole
-= drawer
->icon_array
[i
]->xindex
;
4582 /* wmessage(" Index of the moving appicon is %d (%sredocking)", index_of_hole, (redocking ? "" : "not ")); */
4583 if (abs(index_of_hole
) > abs(drawer
->icon_count
) - (redocking
? 1 : 0))
4584 wwarning(" index_of_hole is too large ! (%d greater than %d)",
4585 index_of_hole
, abs(drawer
->icon_count
) - (redocking
? 1 : 0));
4586 if (index_of_hole
== 0)
4587 wwarning(" index_of_hole == 0 (%sredocking, icon_count == %d)", (redocking
? "" : "not "), drawer
->icon_count
);
4589 return index_of_hole
;
4593 void wSlideAppicons(WAppIcon
**appicons
, int n
, int to_the_left
)
4596 int leftmost
= -1, min_index
= 9999, from_x
= -1; // leftmost and from_x initialized to avoid warning
4603 for (i
= 0; i
< n
; i
++) {
4604 aicon
= appicons
[i
];
4605 aicon
->xindex
+= (to_the_left
? -1 : +1);
4606 if (aicon
->xindex
< min_index
) {
4607 min_index
= aicon
->xindex
;
4609 from_x
= aicon
->x_pos
;
4611 aicon
->x_pos
+= (to_the_left
? -ICON_SIZE
: +ICON_SIZE
);
4614 for (i
= 0; i
< n
; i
++) {
4615 aicon
= appicons
[i
];
4616 wins
[aicon
->xindex
- min_index
] = &aicon
->icon
->core
->window
;
4618 aicon
= appicons
[leftmost
];
4619 SlideWindows(wins
, n
, from_x
, aicon
->y_pos
, aicon
->x_pos
, aicon
->y_pos
);
4623 void wDrawerFillTheGap(WDock
*drawer
, WAppIcon
*aicon
, Bool redocking
)
4626 int index_of_hole
= indexOfHole(drawer
, aicon
, redocking
);
4627 WAppIcon
*aicons_to_shift
[drawer
->icon_count
];
4630 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4631 WAppIcon
*ai
= drawer
->icon_array
[i
];
4632 if (ai
&& ai
!= aicon
&&
4633 abs(ai
->xindex
) > abs(index_of_hole
))
4634 aicons_to_shift
[j
++] = ai
;
4636 if (j
!= drawer
->icon_count
- abs(index_of_hole
) - (redocking
? 1 : 0))
4637 wwarning("Removing aicon at index %d from %s: j=%d but should be %d",
4638 index_of_hole
, drawer
->icon_array
[0]->wm_instance
,
4639 j
, drawer
->icon_count
- abs(index_of_hole
) - (redocking
? 1 : 0));
4640 wSlideAppicons(aicons_to_shift
, j
, !drawer
->on_right_side
);
4644 static void drawerConsolidateIcons(WDock
*drawer
)
4646 WAppIcon
*aicons_to_shift
[drawer
->icon_count
];
4647 int maxRemaining
= 0;
4650 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4651 WAppIcon
*ai
= drawer
->icon_array
[i
];
4654 sum
+= abs(ai
->xindex
);
4655 if (abs(ai
->xindex
) > maxRemaining
)
4656 maxRemaining
= abs(ai
->xindex
);
4658 while (sum
!= maxRemaining
* (maxRemaining
+ 1) / 2) { // while there is a hole
4661 // Look up for the hole at max position
4663 for (maxDeleted
= maxRemaining
- 1; maxDeleted
> 0; maxDeleted
--) {
4664 Bool foundAppIconThere
= False
;
4665 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4666 WAppIcon
*ai
= drawer
->icon_array
[i
];
4669 if (abs(ai
->xindex
) == maxDeleted
) {
4670 foundAppIconThere
= True
;
4674 if (!foundAppIconThere
)
4677 assert(maxDeleted
> 0); // would mean while test is wrong
4679 for (i
= 0; i
< drawer
->max_icons
; i
++) {
4680 ai
= drawer
->icon_array
[i
];
4681 if (ai
!= NULL
&& abs(ai
->xindex
) > maxDeleted
)
4682 aicons_to_shift
[n
++] = ai
;
4684 assert(n
== maxRemaining
- maxDeleted
); // for the code review ;-)
4685 wSlideAppicons(aicons_to_shift
, n
, !drawer
->on_right_side
);
4686 // Efficient beancounting
4694 /* similar to wDockRestoreState, but a lot a specific stuff too... */
4695 static WDock
* drawerRestoreState(WScreen
*scr
, WMPropList
*drawer_state
)
4698 WMPropList
*apps
, *value
, *dock_state
;
4707 WMRetainPropList(drawer_state
);
4709 /* Get the instance name, and create a drawer */
4710 value
= WMGetFromPLDictionary(drawer_state
, dName
);
4711 drawer
= wDockCreate(scr
, WM_DRAWER
, WMGetFromPLString(value
));
4713 /* restore DnD command and paste command */
4715 value
= WMGetFromPLDictionary(drawer_state
, dDropCommand
);
4716 if (value
&& WMIsPLString(value
))
4717 drawer
->icon_array
[0]->dnd_command
= wstrdup(WMGetFromPLString(value
));
4720 value
= WMGetFromPLDictionary(drawer_state
, dPasteCommand
);
4721 if (value
&& WMIsPLString(value
))
4722 drawer
->icon_array
[0]->paste_command
= wstrdup(WMGetFromPLString(value
));
4724 /* restore position */
4725 value
= WMGetFromPLDictionary(drawer_state
, dPosition
);
4726 if (!value
|| !WMIsPLString(value
))
4727 COMPLAIN("Position");
4730 if (sscanf(WMGetFromPLString(value
), "%i,%i", &x
, &y
) != 2)
4731 COMPLAIN("Position");
4733 /* check position sanity */
4734 if (x
!= scr
->dock
->x_pos
) {
4735 x
= scr
->dock
->x_pos
;
4737 y_index
= (y
- scr
->dock
->y_pos
) / ICON_SIZE
;
4738 if (y_index
>= scr
->dock
->max_icons
) {
4739 /* Here we should do something more intelligent, since it
4740 * can happen even if the user hasn't hand-edited his
4741 * G/D/State file (but uses a lower resolution). */
4742 y_index
= scr
->dock
->max_icons
- 1;
4744 y
= scr
->dock
->y_pos
+ y_index
* ICON_SIZE
;
4745 moveDock(drawer
, x
, y
);
4748 /* restore dock properties (applist and others) */
4749 dock_state
= WMGetFromPLDictionary(drawer_state
, dDock
);
4751 /* restore lowered/raised state: same as scr->dock, no matter what */
4752 drawer
->lowered
= scr
->dock
->lowered
;
4753 if (!drawer
->lowered
)
4754 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMDockLevel
);
4756 ChangeStackingLevel(drawer
->icon_array
[0]->icon
->core
, WMNormalLevel
);
4757 wRaiseFrame(drawer
->icon_array
[0]->icon
->core
);
4759 /* restore collapsed state */
4760 drawer
->collapsed
= 0;
4761 value
= WMGetFromPLDictionary(dock_state
, dCollapsed
);
4762 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4763 drawer
->collapsed
= 1;
4765 /* restore auto-collapsed state */
4766 value
= WMGetFromPLDictionary(dock_state
, dAutoCollapse
);
4767 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4768 drawer
->auto_collapse
= 1;
4769 drawer
->collapsed
= 1;
4771 drawer
->auto_collapse
= 0; // because wDockCreate sets it (drawers only)
4774 /* restore auto-raise/lower state: same as scr->dock, no matter what */
4775 drawer
->auto_raise_lower
= scr
->dock
->auto_raise_lower
;
4777 /* restore attract icons state */
4778 drawer
->attract_icons
= 0;
4779 value
= WMGetFromPLDictionary(dock_state
, dAutoAttractIcons
);
4780 if (value
&& strcasecmp(WMGetFromPLString(value
), "YES") == 0) {
4781 drawer
->attract_icons
= 1;
4782 scr
->attracting_drawer
= drawer
;
4785 /* application list */
4786 apps
= WMGetFromPLDictionary(dock_state
, dApplications
);
4792 count
= WMGetPropListItemCount(apps
);
4797 for (i
=0; i
<count
; i
++) {
4798 if (drawer
->icon_count
>= drawer
->max_icons
) {
4799 wwarning(_("there are too many icons stored in drawer. Ignoring what doesn't fit"));
4803 value
= WMGetFromPLArray(apps
, i
);
4804 aicon
= restore_icon_state(scr
, value
, WM_DRAWER
, drawer
->icon_count
);
4806 drawer
->icon_array
[drawer
->icon_count
] = aicon
;
4809 aicon
->dock
= drawer
;
4810 aicon
->x_pos
= drawer
->x_pos
+ (aicon
->xindex
* ICON_SIZE
);
4811 aicon
->y_pos
= drawer
->y_pos
+ (aicon
->yindex
* ICON_SIZE
);
4813 if (!drawer
->lowered
)
4814 ChangeStackingLevel(aicon
->icon
->core
, WMDockLevel
);
4816 ChangeStackingLevel(aicon
->icon
->core
, WMNormalLevel
);
4818 wCoreConfigure(aicon
->icon
->core
, aicon
->x_pos
, aicon
->y_pos
, 0, 0);
4820 if (!drawer
->collapsed
)
4821 XMapWindow(dpy
, aicon
->icon
->core
->window
);
4822 wRaiseFrame(aicon
->icon
->core
);
4824 drawer
->icon_count
++;
4829 WMReleasePropList(drawer_state
);
4835 /* Same kind of comment than for previous function: this function is
4836 * very similar to make_icon_state, but has substential differences as
4838 static WMPropList
*drawerSaveState(WScreen
*scr
, WDock
*drawer
)
4840 WMPropList
*pstr
, *drawer_state
;
4844 ai
= drawer
->icon_array
[0];
4845 /* Store its name */
4846 pstr
= WMCreatePLString(ai
->wm_instance
);
4847 drawer_state
= WMCreatePLDictionary(dName
, pstr
, NULL
); /* we need this final NULL */
4848 WMReleasePropList(pstr
);
4850 /* Store its position */
4851 snprintf(buffer
, sizeof(buffer
), "%i,%i", ai
->x_pos
, ai
->y_pos
);
4852 pstr
= WMCreatePLString(buffer
);
4853 WMPutInPLDictionary(drawer_state
, dPosition
, pstr
);
4854 WMReleasePropList(pstr
);
4857 /* Store its DnD command */
4858 if (ai
->dnd_command
) {
4859 pstr
= WMCreatePLString(ai
->dnd_command
);
4860 WMPutInPLDictionary(drawer_state
, dDropCommand
, pstr
);
4861 WMReleasePropList(pstr
);
4865 /* Store its paste command */
4866 if (ai
->paste_command
) {
4867 pstr
= WMCreatePLString(ai
->paste_command
);
4868 WMPutInPLDictionary(drawer_state
, dPasteCommand
, pstr
);
4869 WMReleasePropList(pstr
);
4872 /* Store applications list and other properties */
4873 pstr
= dockSaveState(drawer
);
4874 WMPutInPLDictionary(drawer_state
, dDock
, pstr
);
4875 WMReleasePropList(pstr
);
4877 return drawer_state
;
4881 void wDrawersSaveState(WScreen
*scr
)
4883 WMPropList
*all_drawers
, *drawer_state
;
4889 all_drawers
= WMCreatePLArray(NULL
);
4890 for (i
=0, dc
= scr
->drawers
;
4891 i
< scr
->drawer_count
;
4892 i
++, dc
= dc
->next
) {
4893 drawer_state
= drawerSaveState(scr
, dc
->adrawer
);
4894 WMAddToPLArray(all_drawers
, drawer_state
);
4895 WMReleasePropList(drawer_state
);
4897 WMPutInPLDictionary(w_global
.session_state
, dDrawers
, all_drawers
);
4898 WMReleasePropList(all_drawers
);
4902 void wDrawersRestoreState(WScreen
*scr
)
4904 WMPropList
*all_drawers
, *drawer_state
;
4909 if (w_global
.session_state
== NULL
)
4912 all_drawers
= WMGetFromPLDictionary(w_global
.session_state
, dDrawers
);
4916 for (i
= 0; i
< WMGetPropListItemCount(all_drawers
); i
++) {
4917 drawer_state
= WMGetFromPLArray(all_drawers
, i
);
4918 drawerRestoreState(scr
, drawer_state
);
4919 // Note: scr->drawers was updated when the the drawer was created