]> Dogcows Code - chaz/openbox/blob - openbox/geom.h
make keeping windows on screen much more clever
[chaz/openbox] / openbox / geom.h
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3 geom.h for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #ifndef __geom_h
21 #define __geom_h
22
23 typedef struct _Point {
24 int x;
25 int y;
26 } Point;
27
28 #define POINT_SET(pt, nx, ny) (pt).x = (nx), (pt).y = (ny)
29 #define POINT_EQUAL(p1, p2) ((p1).x == (p2).x && (p1).y == (p2).y)
30
31 typedef struct _Size {
32 int width;
33 int height;
34 } Size;
35
36 #define SIZE_SET(sz, w, h) (sz).width = (w), (sz).height = (h)
37
38 typedef struct _Rect {
39 int x;
40 int y;
41 int width;
42 int height;
43 } Rect;
44
45 #define RECT_LEFT(r) ((r).x)
46 #define RECT_TOP(r) ((r).y)
47 #define RECT_RIGHT(r) ((r).x + (r).width - 1)
48 #define RECT_BOTTOM(r) ((r).y + (r).height - 1)
49
50 #define RECT_SET_POINT(r, nx, ny) \
51 (r).x = (nx), (r).y = (ny)
52 #define RECT_SET_SIZE(r, w, h) \
53 (r).width = (w), (r).height = (h)
54 #define RECT_SET(r, nx, ny, w, h) \
55 (r).x = (nx), (r).y = (ny), (r).width = (w), (r).height = (h)
56
57 #define RECT_EQUAL(r1, r2) ((r1).x == (r2).x && (r1).y == (r2).y && \
58 (r1).width == (r2).width && \
59 (r1).height == (r2).height)
60
61 #define RECT_CONTAINS(r, px, py) \
62 ((px) >= (r).x && (px) < (r).x + (r).width && \
63 (py) >= (r).y && (py) < (r).y + (r).height)
64 #define RECT_CONTAINS_RECT(r, o) \
65 ((o).x >= (r).x && (o).x + (o).width <= (r).x + (r).width && \
66 (o).y >= (r).y && (o).y + (o).height <= (r).y + (r).height)
67
68 /* Returns true if Rect r and o intersect */
69 #define RECT_INTERSECTS_RECT(r, o) \
70 ((o).x < (r).x + (r).width && (o).x + (o).width > (r).x && \
71 (o).y < (r).y + (r).height && (o).y + (o).height > (r).y)
72
73 /* Sets Rect r to be the intersection of Rect a and b. */
74 #define RECT_SET_INTERSECTION(r, a, b) \
75 ((r).x = MAX((a).x, (b).x), \
76 (r).y = MAX((a).y, (b).y), \
77 (r).width = MIN((a).x + (a).width - 1, \
78 (b).x + (b).width - 1) - (r).x + 1, \
79 (r).height = MIN((a).y + (a).height - 1, \
80 (b).y + (b).height - 1) - (r).y + 1)
81
82 typedef struct _Strut {
83 int left;
84 int top;
85 int right;
86 int bottom;
87 } Strut;
88
89 typedef struct _StrutPartial {
90 int left;
91 int top;
92 int right;
93 int bottom;
94
95 int left_start, left_end;
96 int top_start, top_end;
97 int right_start, right_end;
98 int bottom_start, bottom_end;
99 } StrutPartial;
100
101 #define STRUT_SET(s, l, t, r, b) \
102 (s).left = (l), (s).top = (t), (s).right = (r), (s).bottom = (b)
103
104 #define STRUT_PARTIAL_SET(s, l, t, r, b, ls, le, ts, te, rs, re, bs, be) \
105 (s).left = (l), (s).top = (t), (s).right = (r), (s).bottom = (b), \
106 (s).left_start = (ls), (s).left_end = (le), \
107 (s).top_start = (ts), (s).top_end = (te), \
108 (s).right_start = (rs), (s).right_end = (re), \
109 (s).bottom_start = (bs), (s).bottom_end = (be)
110
111 #define STRUT_ADD(s1, s2) \
112 (s1).left = MAX((s1).left, (s2).left), \
113 (s1).right = MAX((s1).right, (s2).right), \
114 (s1).top = MAX((s1).top, (s2).top), \
115 (s1).bottom = MAX((s1).bottom, (s2).bottom)
116
117 #define STRUT_EXISTS(s1) \
118 ((s1).left || (s1).top || (s1).right || (s1).bottom)
119
120 #define STRUT_EQUAL(s1, s2) \
121 ((s1).left == (s2).left && \
122 (s1).top == (s2).top && \
123 (s1).right == (s2).right && \
124 (s1).bottom == (s2).bottom)
125
126 #define PARTIAL_STRUT_EQUAL(s1, s2) \
127 ((s1).left == (s2).left && \
128 (s1).top == (s2).top && \
129 (s1).right == (s2).right && \
130 (s1).bottom == (s2).bottom && \
131 (s1).left_start == (s2).left_start && \
132 (s1).left_end == (s2).left_end && \
133 (s1).top_start == (s2).top_start && \
134 (s1).top_end == (s2).top_end && \
135 (s1).right_start == (s2).right_start && \
136 (s1).right_end == (s2).right_end && \
137 (s1).bottom_start == (s2).bottom_start && \
138 (s1).bottom_end == (s2).bottom_end)
139
140 #endif
This page took 0.04271 seconds and 5 git commands to generate.