1 | /* GDK - The GIMP Drawing Kit |
2 | * Copyright (C) 2020 Red Hat |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Lesser General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Lesser General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Lesser General Public |
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
16 | * |
17 | */ |
18 | |
19 | #include "config.h" |
20 | |
21 | #include "gdktoplevelsizeprivate.h" |
22 | |
23 | /** |
24 | * GdkToplevelSize: |
25 | * |
26 | * The `GdkToplevelSize` struct contains information that is useful |
27 | * to compute the size of a toplevel. |
28 | */ |
29 | |
30 | G_DEFINE_POINTER_TYPE (GdkToplevelSize, gdk_toplevel_size) |
31 | |
32 | #define UNCONFIGURED_WIDTH 400 |
33 | #define UNCONFIGURED_HEIGHT 300 |
34 | |
35 | #define DEFAULT_BOUNDS_WIDTH INT_MAX |
36 | #define DEFAULT_BOUNDS_HEIGHT INT_MAX |
37 | |
38 | void |
39 | gdk_toplevel_size_init (GdkToplevelSize *size, |
40 | int bounds_width, |
41 | int bounds_height) |
42 | { |
43 | *size = (GdkToplevelSize) { 0 }; |
44 | |
45 | size->bounds_width = bounds_width; |
46 | size->bounds_height = bounds_height; |
47 | |
48 | size->width = UNCONFIGURED_WIDTH; |
49 | size->height = UNCONFIGURED_HEIGHT; |
50 | } |
51 | |
52 | /** |
53 | * gdk_toplevel_size_get_bounds: |
54 | * @size: a `GdkToplevelSize` |
55 | * @bounds_width: (out): return location for width |
56 | * @bounds_height: (out): return location for height |
57 | * |
58 | * Retrieves the bounds the toplevel is placed within. |
59 | * |
60 | * The bounds represent the largest size a toplevel may have while still being |
61 | * able to fit within some type of boundary. Depending on the backend, this may |
62 | * be equivalent to the dimensions of the work area or the monitor on which the |
63 | * window is being presented on, or something else that limits the way a |
64 | * toplevel can be presented. |
65 | */ |
66 | void |
67 | gdk_toplevel_size_get_bounds (GdkToplevelSize *size, |
68 | int *bounds_width, |
69 | int *bounds_height) |
70 | { |
71 | g_return_if_fail (bounds_width); |
72 | g_return_if_fail (bounds_height); |
73 | |
74 | if (size->bounds_width > 0) |
75 | *bounds_width = size->bounds_width; |
76 | else |
77 | *bounds_width = DEFAULT_BOUNDS_WIDTH; |
78 | |
79 | if (size->bounds_height > 0) |
80 | *bounds_height = size->bounds_height; |
81 | else |
82 | *bounds_height = DEFAULT_BOUNDS_HEIGHT; |
83 | } |
84 | |
85 | /** |
86 | * gdk_toplevel_size_set_size: |
87 | * @size: a `GdkToplevelSize` |
88 | * @width: the width |
89 | * @height: the height |
90 | * |
91 | * Sets the size the toplevel prefers to be resized to. |
92 | * |
93 | * The size should be within the bounds (see |
94 | * [method@Gdk.ToplevelSize.get_bounds]). The set size should |
95 | * be considered as a hint, and should not be assumed to be |
96 | * respected by the windowing system, or backend. |
97 | */ |
98 | void |
99 | gdk_toplevel_size_set_size (GdkToplevelSize *size, |
100 | int width, |
101 | int height) |
102 | { |
103 | size->width = width; |
104 | size->height = height; |
105 | } |
106 | |
107 | /** |
108 | * gdk_toplevel_size_set_min_size: |
109 | * @size: a `GdkToplevelSize` |
110 | * @min_width: the minimum width |
111 | * @min_height: the minimum height |
112 | * |
113 | * Sets the minimum size of the toplevel. |
114 | * |
115 | * The minimum size corresponds to the limitations the toplevel can be shrunk |
116 | * to, without resulting in incorrect painting. A user of a `GdkToplevel` should |
117 | * calculate these given both the existing size, and the bounds retrieved from |
118 | * the `GdkToplevelSize` object. |
119 | * |
120 | * The minimum size should be within the bounds (see |
121 | * [method@Gdk.ToplevelSize.get_bounds]). |
122 | */ |
123 | void |
124 | gdk_toplevel_size_set_min_size (GdkToplevelSize *size, |
125 | int min_width, |
126 | int min_height) |
127 | { |
128 | size->min_width = min_width; |
129 | size->min_height = min_height; |
130 | } |
131 | |
132 | /** |
133 | * gdk_toplevel_size_set_shadow_width: |
134 | * @size: a `GdkToplevelSize` |
135 | * @left: width of the left part of the shadow |
136 | * @right: width of the right part of the shadow |
137 | * @top: height of the top part of the shadow |
138 | * @bottom: height of the bottom part of the shadow |
139 | * |
140 | * Sets the shadows size of the toplevel. |
141 | * |
142 | * The shadow width corresponds to the part of the computed surface size |
143 | * that would consist of the shadow margin surrounding the window, would |
144 | * there be any. |
145 | */ |
146 | void |
147 | gdk_toplevel_size_set_shadow_width (GdkToplevelSize *size, |
148 | int left, |
149 | int right, |
150 | int top, |
151 | int bottom) |
152 | { |
153 | size->shadow.is_valid = TRUE; |
154 | size->shadow.left = left; |
155 | size->shadow.right = right; |
156 | size->shadow.top = top; |
157 | size->shadow.bottom = bottom; |
158 | } |
159 | |
160 | void |
161 | gdk_toplevel_size_validate (GdkToplevelSize *size) |
162 | { |
163 | #if 0 |
164 | int geometry_width, geometry_height; |
165 | |
166 | geometry_width = size->width; |
167 | geometry_height = size->height; |
168 | if (size->shadow.is_valid) |
169 | { |
170 | geometry_width -= size->shadow.left + size->shadow.right; |
171 | geometry_height -= size->shadow.top + size->shadow.bottom; |
172 | } |
173 | #endif |
174 | } |
175 | |