chiark / gitweb /
Imported Upstream version 1.0.0
[e16] / src / dock.c
1 /*
2  * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
3  * Copyright (C) 2004-2008 Kim Woelders
4  *
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:
11  *
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.
16  *
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.
23  */
24 #include "E.h"
25 #include "ewins.h"
26 #include "iclass.h"
27
28 static void
29 DockappFindEmptySpotFor(EWin * eapp)
30 {
31    EWin               *const *lst, *ewin;
32    int                 num, i, j, x, y, w, h, done;
33    int                 step_right, step_down;
34
35    x = EoGetX(eapp);
36    y = EoGetY(eapp);
37    w = eapp->client.w;
38    h = eapp->client.h;
39    if (!eapp->state.placed)
40      {
41         x = Conf.dock.startx;
42         if (x < 0)
43            x = 0;
44         else if (x > WinGetW(VROOT) - EoGetW(eapp))
45            x = WinGetW(VROOT) - EoGetW(eapp);
46
47         y = Conf.dock.starty;
48         if (y < 0)
49            y = 0;
50         else if (y > WinGetH(VROOT) - EoGetH(eapp))
51            y = WinGetH(VROOT) - EoGetH(eapp);
52      }
53
54    step_right = Conf.dock.startx < WinGetW(VROOT);
55    step_down = Conf.dock.starty < WinGetH(VROOT);
56
57    lst = EwinListGetAll(&num);
58    for (j = 0; j < num; j++)
59       for (i = 0; i < num; i++)
60         {
61            ewin = lst[i];
62
63            /* Skip self and non-dockapps */
64            if (ewin == eapp || !ewin->state.docked)
65               continue;
66
67            if ((x + w) <= EoGetX(ewin) || x >= (EoGetX(ewin) + EoGetW(ewin)))
68               done = 1;
69            else if ((y + h) <= EoGetY(ewin)
70                     || y > (EoGetY(ewin) + EoGetH(ewin)))
71               done = 1;
72            else
73               done = 0;
74
75            if (!done)
76              {
77                 switch (Conf.dock.dirmode)
78                   {
79                   case DOCK_RIGHT:
80                      x = EoGetX(ewin) + EoGetW(ewin);
81                      if (x + w >= WinGetW(VROOT))
82                        {
83                           x = Conf.dock.startx;
84                           y += (step_down) ? h : -h;
85                        }
86                      break;
87                   case DOCK_LEFT:
88                      x = EoGetX(ewin) - w;
89                      if (x < 0)
90                        {
91                           x = Conf.dock.startx - w;
92                           y += (step_down) ? h : -h;
93                        }
94                      break;
95                   case DOCK_DOWN:
96                      y = EoGetY(ewin) + EoGetH(ewin);
97                      if (y + h >= WinGetH(VROOT))
98                        {
99                           y = Conf.dock.starty;
100                           x += (step_right) ? w : -w;
101                        }
102                      break;
103                   case DOCK_UP:
104                      y = EoGetY(ewin) - h;
105                      if (y < 0)
106                        {
107                           y = WinGetH(VROOT) - h;
108                           x += (step_right) ? w : -w;
109                        }
110                      break;
111                   }
112              }
113         }
114
115    if (x < 0 || y < 0 || x + w > WinGetW(VROOT) || y + h > WinGetH(VROOT))
116      {
117         x = WinGetW(VROOT) - w / 2;
118         y = WinGetH(VROOT) - h / 2;
119      }
120
121    EoMove(eapp, x, y);
122 }
123
124 void
125 DockIt(EWin * ewin)
126 {
127    ImageClass         *ic;
128
129    ic = ImageclassFind("DEFAULT_DOCK_BUTTON", 1);
130
131    if (Conf.dock.sticky)
132       EoSetSticky(ewin, 1);
133
134    ewin->props.donthide = 1;
135    ewin->props.focusclick = 1;
136
137    DockappFindEmptySpotFor(ewin);
138    ewin->state.placed = 1;
139
140    if (ewin->icccm.icon_win)
141      {
142         XSetWindowBorderWidth(disp, ewin->icccm.icon_win, 0);
143         XMoveWindow(disp, ewin->icccm.icon_win, 0, 0);
144         XMapWindow(disp, ewin->icccm.icon_win);
145      }
146
147    ImageclassApply(ic, EoGetWin(ewin), 0, 0, STATE_NORMAL, ST_BUTTON);
148 }