2 * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
3 * Copyright (C) 2004-2008 Kim Woelders
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to
7 * deal in the Software without restriction, including without limitation the
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 * sell copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies of the Software, its documentation and marketing & publicity
14 * materials, and acknowledgment shall be given in the documentation, materials
15 * and software packages that this Software was used.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 DockappFindEmptySpotFor(EWin * eapp)
31 EWin *const *lst, *ewin;
32 int num, i, j, x, y, w, h, done;
33 int step_right, step_down;
39 if (!eapp->state.placed)
44 else if (x > WinGetW(VROOT) - EoGetW(eapp))
45 x = WinGetW(VROOT) - EoGetW(eapp);
50 else if (y > WinGetH(VROOT) - EoGetH(eapp))
51 y = WinGetH(VROOT) - EoGetH(eapp);
54 step_right = Conf.dock.startx < WinGetW(VROOT);
55 step_down = Conf.dock.starty < WinGetH(VROOT);
57 lst = EwinListGetAll(&num);
58 for (j = 0; j < num; j++)
59 for (i = 0; i < num; i++)
63 /* Skip self and non-dockapps */
64 if (ewin == eapp || !ewin->state.docked)
67 if ((x + w) <= EoGetX(ewin) || x >= (EoGetX(ewin) + EoGetW(ewin)))
69 else if ((y + h) <= EoGetY(ewin)
70 || y > (EoGetY(ewin) + EoGetH(ewin)))
77 switch (Conf.dock.dirmode)
80 x = EoGetX(ewin) + EoGetW(ewin);
81 if (x + w >= WinGetW(VROOT))
84 y += (step_down) ? h : -h;
91 x = Conf.dock.startx - w;
92 y += (step_down) ? h : -h;
96 y = EoGetY(ewin) + EoGetH(ewin);
97 if (y + h >= WinGetH(VROOT))
100 x += (step_right) ? w : -w;
104 y = EoGetY(ewin) - h;
107 y = WinGetH(VROOT) - h;
108 x += (step_right) ? w : -w;
115 if (x < 0 || y < 0 || x + w > WinGetW(VROOT) || y + h > WinGetH(VROOT))
117 x = WinGetW(VROOT) - w / 2;
118 y = WinGetH(VROOT) - h / 2;
129 ic = ImageclassFind("DEFAULT_DOCK_BUTTON", 1);
131 if (Conf.dock.sticky)
132 EoSetSticky(ewin, 1);
134 ewin->props.donthide = 1;
135 ewin->props.focusclick = 1;
137 DockappFindEmptySpotFor(ewin);
138 ewin->state.placed = 1;
140 if (ewin->icccm.icon_win)
142 XSetWindowBorderWidth(disp, ewin->icccm.icon_win, 0);
143 XMoveWindow(disp, ewin->icccm.icon_win, 0, 0);
144 XMapWindow(disp, ewin->icccm.icon_win);
147 ImageclassApply(ic, EoGetWin(ewin), 0, 0, STATE_NORMAL, ST_BUTTON);