chiark / gitweb /
Imported Upstream version 1.0.0
[e16] / src / size.c
1 /*
2  * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
3  * Copyright (C) 2003-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 "hints.h"
27 #include "screen.h"
28
29 #define MAX_ABSOLUTE     0      /* Fill screen */
30 #define MAX_AVAILABLE    1      /* Expand until don't cover */
31 #define MAX_CONSERVATIVE 2      /* Expand until something */
32 #define MAX_XINERAMA     3      /* Fill Xinerama screen */
33
34 void
35 MaxSizeHV(EWin * ewin, const char *resize_type, int hor, int ver)
36 {
37    int                 x, y, w, h, x1, x2, y1, y2, type, bl, br, bt, bb;
38    EWin               *const *lst, *pe;
39    int                 i, num;
40
41    if (!ewin)
42       return;
43
44    if (ewin->state.inhibit_max_hor && hor)
45       return;
46    if (ewin->state.inhibit_max_ver && ver)
47       return;
48
49    if (ewin->state.maximized_horz || ewin->state.maximized_vert)
50      {
51         EwinMoveResize(ewin, ewin->save_max.x, ewin->save_max.y,
52                        ewin->save_max.w, ewin->save_max.h);
53         ewin->save_max.x = EoGetX(ewin);
54         ewin->save_max.y = EoGetY(ewin);
55         ewin->save_max.w = ewin->client.w;
56         ewin->save_max.h = ewin->client.h;
57         ewin->state.maximized_horz = 0;
58         ewin->state.maximized_vert = 0;
59         goto done;
60      }
61
62    type = MAX_ABSOLUTE;         /* Select default */
63    if (!resize_type || !resize_type[0])
64       type = Conf.movres.mode_maximize_default;
65    else if (!strcmp(resize_type, "absolute"))
66       type = MAX_ABSOLUTE;
67    else if (!strcmp(resize_type, "available"))
68       type = MAX_AVAILABLE;
69    else if (!strcmp(resize_type, "conservative"))
70       type = MAX_CONSERVATIVE;
71    else if (!strcmp(resize_type, "xinerama"))
72       type = MAX_XINERAMA;
73
74    /* Default is no change */
75    x = EoGetX(ewin);
76    y = EoGetY(ewin);
77    h = EoGetH(ewin);
78    w = EoGetW(ewin);
79
80    switch (type)
81      {
82      case MAX_XINERAMA:
83         if (hor)
84           {
85              x = 0;
86              w = WinGetW(VROOT);
87              ewin->state.maximized_horz = 1;
88           }
89         if (ver)
90           {
91              y = 0;
92              h = WinGetH(VROOT);
93              ewin->state.maximized_vert = 1;
94           }
95         break;
96
97      default:
98      case MAX_ABSOLUTE:
99      case MAX_AVAILABLE:
100      case MAX_CONSERVATIVE:
101         ScreenGetAvailableArea(x + w / 2, y + h / 2, &x1, &y1, &x2, &y2);
102         x2 += x1;
103         y2 += y1;
104
105         if (Conf.movres.dragbar_nocover && type != MAX_ABSOLUTE)
106           {
107              /* Leave room for the dragbar */
108              switch (Conf.desks.dragdir)
109                {
110                case 0:          /* left */
111                   if (x1 < Conf.desks.dragbar_width)
112                      x1 = Conf.desks.dragbar_width;
113                   break;
114
115                case 1:          /* right */
116                   if (x2 > WinGetW(VROOT) - Conf.desks.dragbar_width)
117                      x2 = WinGetW(VROOT) - Conf.desks.dragbar_width;
118                   break;
119
120                case 2:          /* top */
121                   if (y1 < Conf.desks.dragbar_width)
122                      y1 = Conf.desks.dragbar_width;
123                   break;
124
125                case 3:          /* bottom */
126                   if (y2 > WinGetH(VROOT) - Conf.desks.dragbar_width)
127                      y2 = WinGetH(VROOT) - Conf.desks.dragbar_width;
128                   break;
129
130                default:
131                   break;
132                }
133           }
134
135         if (type == MAX_ABSOLUTE)
136           {
137              /* Simply ignore all windows */
138              lst = NULL;
139              num = 0;
140           }
141         else
142           {
143              lst = EwinListGetAll(&num);
144           }
145
146         if (ver)
147           {
148              for (i = 0; i < num; i++)
149                {
150                   pe = lst[i];
151                   if (pe == ewin ||
152                       pe->state.iconified || EoIsFloating(pe) ||
153                       pe->props.ignorearrange ||
154                       (EoGetDesk(ewin) != EoGetDesk(pe) && !EoIsSticky(pe)) ||
155                       (pe->type & (EWIN_TYPE_DIALOG | EWIN_TYPE_MENU)) ||
156                       (type == MAX_AVAILABLE && !pe->props.never_use_area) ||
157                       !SPANS_COMMON(x, w, EoGetX(pe), EoGetW(pe)))
158                      continue;
159
160                   if (((EoGetY(pe) + EoGetH(pe)) <= y)
161                       && ((EoGetY(pe) + EoGetH(pe)) >= y1))
162                      y1 = EoGetY(pe) + EoGetH(pe);
163                   else if (((y + h) <= EoGetY(pe)) && (y2 >= EoGetY(pe)))
164                      y2 = EoGetY(pe);
165                }
166              y = y1;
167              h = y2 - y1;
168
169              ewin->state.maximized_vert = 1;
170           }
171
172         if (hor)
173           {
174              for (i = 0; i < num; i++)
175                {
176                   pe = lst[i];
177                   if (pe == ewin ||
178                       pe->state.iconified || EoIsFloating(pe) ||
179                       pe->props.ignorearrange ||
180                       (EoGetDesk(ewin) != EoGetDesk(pe) && !EoIsSticky(pe)) ||
181                       (pe->type & (EWIN_TYPE_DIALOG | EWIN_TYPE_MENU)) ||
182                       (type == MAX_AVAILABLE && !pe->props.never_use_area) ||
183                       !SPANS_COMMON(y, h, EoGetY(pe), EoGetH(pe)))
184                      continue;
185
186                   if (((EoGetX(pe) + EoGetW(pe)) <= x)
187                       && ((EoGetX(pe) + EoGetW(pe)) >= x1))
188                      x1 = EoGetX(pe) + EoGetW(pe);
189                   else if (((x + w) <= EoGetX(pe)) && (x2 >= EoGetX(pe)))
190                      x2 = EoGetX(pe);
191                }
192              x = x1;
193              w = x2 - x1;
194
195              ewin->state.maximized_horz = 1;
196           }
197
198         break;
199      }
200
201    EwinBorderGetSize(ewin, &bl, &br, &bt, &bb);
202    w -= (bl + br);
203    if (w < 10)
204       w = 10;
205    h -= (bt + bb);
206    if (h < 10)
207       h = 10;
208
209    ewin->save_max.x = EoGetX(ewin);
210    ewin->save_max.y = EoGetY(ewin);
211    ewin->save_max.w = ewin->client.w;
212    ewin->save_max.h = ewin->client.h;
213
214    ewin->state.maximizing = 1;
215    EwinMoveResize(ewin, x, y, w, h);
216    ewin->state.maximizing = 0;
217  done:
218    HintsSetWindowState(ewin);
219 }