diff options
-rw-r--r-- | include/sway/tree/view.h | 5 | ||||
-rw-r--r-- | sway/desktop/xdg_shell.c | 12 | ||||
-rw-r--r-- | sway/desktop/xdg_shell_v6.c | 12 | ||||
-rw-r--r-- | sway/input/cursor.c | 11 | ||||
-rw-r--r-- | sway/tree/view.c | 13 |
5 files changed, 52 insertions, 1 deletions
diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 068d92c6..1dfb218b 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h | |||
@@ -26,6 +26,8 @@ enum sway_view_prop { | |||
26 | }; | 26 | }; |
27 | 27 | ||
28 | struct sway_view_impl { | 28 | struct sway_view_impl { |
29 | void (*get_constraints)(struct sway_view *view, double *min_width, | ||
30 | double *max_width, double *min_height, double *max_height); | ||
29 | const char *(*get_string_prop)(struct sway_view *view, | 31 | const char *(*get_string_prop)(struct sway_view *view, |
30 | enum sway_view_prop prop); | 32 | enum sway_view_prop prop); |
31 | uint32_t (*get_int_prop)(struct sway_view *view, enum sway_view_prop prop); | 33 | uint32_t (*get_int_prop)(struct sway_view *view, enum sway_view_prop prop); |
@@ -215,6 +217,9 @@ uint32_t view_get_window_type(struct sway_view *view); | |||
215 | 217 | ||
216 | const char *view_get_shell(struct sway_view *view); | 218 | const char *view_get_shell(struct sway_view *view); |
217 | 219 | ||
220 | void view_get_constraints(struct sway_view *view, double *min_width, | ||
221 | double *max_width, double *min_height, double *max_height); | ||
222 | |||
218 | uint32_t view_configure(struct sway_view *view, double lx, double ly, int width, | 223 | uint32_t view_configure(struct sway_view *view, double lx, double ly, int width, |
219 | int height); | 224 | int height); |
220 | 225 | ||
diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index c5d53d1d..76fe72ea 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c | |||
@@ -1,4 +1,5 @@ | |||
1 | #define _POSIX_C_SOURCE 199309L | 1 | #define _POSIX_C_SOURCE 199309L |
2 | #include <float.h> | ||
2 | #include <stdbool.h> | 3 | #include <stdbool.h> |
3 | #include <stdlib.h> | 4 | #include <stdlib.h> |
4 | #include <wayland-server.h> | 5 | #include <wayland-server.h> |
@@ -95,6 +96,16 @@ static struct sway_xdg_shell_view *xdg_shell_view_from_view( | |||
95 | return (struct sway_xdg_shell_view *)view; | 96 | return (struct sway_xdg_shell_view *)view; |
96 | } | 97 | } |
97 | 98 | ||
99 | static void get_constraints(struct sway_view *view, double *min_width, | ||
100 | double *max_width, double *min_height, double *max_height) { | ||
101 | struct wlr_xdg_toplevel_state *state = | ||
102 | &view->wlr_xdg_surface->toplevel->current; | ||
103 | *min_width = state->min_width > 0 ? state->min_width : DBL_MIN; | ||
104 | *max_width = state->max_width > 0 ? state->max_width : DBL_MAX; | ||
105 | *min_height = state->min_height > 0 ? state->min_height : DBL_MIN; | ||
106 | *max_height = state->max_height > 0 ? state->max_height : DBL_MAX; | ||
107 | } | ||
108 | |||
98 | static const char *get_string_prop(struct sway_view *view, enum sway_view_prop prop) { | 109 | static const char *get_string_prop(struct sway_view *view, enum sway_view_prop prop) { |
99 | if (xdg_shell_view_from_view(view) == NULL) { | 110 | if (xdg_shell_view_from_view(view) == NULL) { |
100 | return NULL; | 111 | return NULL; |
@@ -188,6 +199,7 @@ static void destroy(struct sway_view *view) { | |||
188 | } | 199 | } |
189 | 200 | ||
190 | static const struct sway_view_impl view_impl = { | 201 | static const struct sway_view_impl view_impl = { |
202 | .get_constraints = get_constraints, | ||
191 | .get_string_prop = get_string_prop, | 203 | .get_string_prop = get_string_prop, |
192 | .configure = configure, | 204 | .configure = configure, |
193 | .set_activated = set_activated, | 205 | .set_activated = set_activated, |
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index 4bd6af5e..57b51908 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c | |||
@@ -1,4 +1,5 @@ | |||
1 | #define _POSIX_C_SOURCE 199309L | 1 | #define _POSIX_C_SOURCE 199309L |
2 | #include <float.h> | ||
2 | #include <stdbool.h> | 3 | #include <stdbool.h> |
3 | #include <stdlib.h> | 4 | #include <stdlib.h> |
4 | #include <wayland-server.h> | 5 | #include <wayland-server.h> |
@@ -94,6 +95,16 @@ static struct sway_xdg_shell_v6_view *xdg_shell_v6_view_from_view( | |||
94 | return (struct sway_xdg_shell_v6_view *)view; | 95 | return (struct sway_xdg_shell_v6_view *)view; |
95 | } | 96 | } |
96 | 97 | ||
98 | static void get_constraints(struct sway_view *view, double *min_width, | ||
99 | double *max_width, double *min_height, double *max_height) { | ||
100 | struct wlr_xdg_toplevel_v6_state *state = | ||
101 | &view->wlr_xdg_surface_v6->toplevel->current; | ||
102 | *min_width = state->min_width > 0 ? state->min_width : DBL_MIN; | ||
103 | *max_width = state->max_width > 0 ? state->max_width : DBL_MAX; | ||
104 | *min_height = state->min_height > 0 ? state->min_height : DBL_MIN; | ||
105 | *max_height = state->max_height > 0 ? state->max_height : DBL_MAX; | ||
106 | } | ||
107 | |||
97 | static const char *get_string_prop(struct sway_view *view, enum sway_view_prop prop) { | 108 | static const char *get_string_prop(struct sway_view *view, enum sway_view_prop prop) { |
98 | if (xdg_shell_v6_view_from_view(view) == NULL) { | 109 | if (xdg_shell_v6_view_from_view(view) == NULL) { |
99 | return NULL; | 110 | return NULL; |
@@ -184,6 +195,7 @@ static void destroy(struct sway_view *view) { | |||
184 | } | 195 | } |
185 | 196 | ||
186 | static const struct sway_view_impl view_impl = { | 197 | static const struct sway_view_impl view_impl = { |
198 | .get_constraints = get_constraints, | ||
187 | .get_string_prop = get_string_prop, | 199 | .get_string_prop = get_string_prop, |
188 | .configure = configure, | 200 | .configure = configure, |
189 | .set_activated = set_activated, | 201 | .set_activated = set_activated, |
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index ad0ceb94..7deb2b19 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c | |||
@@ -243,7 +243,7 @@ static void handle_resize_motion(struct sway_seat *seat, | |||
243 | grow_height = seat->op_ref_height * max_multiplier; | 243 | grow_height = seat->op_ref_height * max_multiplier; |
244 | } | 244 | } |
245 | 245 | ||
246 | // Determine new width/height, and accommodate for min/max values | 246 | // Determine new width/height, and accommodate for floating min/max values |
247 | double width = seat->op_ref_width + grow_width; | 247 | double width = seat->op_ref_width + grow_width; |
248 | double height = seat->op_ref_height + grow_height; | 248 | double height = seat->op_ref_height + grow_height; |
249 | int min_width, max_width, min_height, max_height; | 249 | int min_width, max_width, min_height, max_height; |
@@ -252,6 +252,15 @@ static void handle_resize_motion(struct sway_seat *seat, | |||
252 | width = fmax(min_width, fmin(width, max_width)); | 252 | width = fmax(min_width, fmin(width, max_width)); |
253 | height = fmax(min_height, fmin(height, max_height)); | 253 | height = fmax(min_height, fmin(height, max_height)); |
254 | 254 | ||
255 | // Apply the view's min/max size | ||
256 | if (con->type == C_VIEW) { | ||
257 | double view_min_width, view_max_width, view_min_height, view_max_height; | ||
258 | view_get_constraints(con->sway_view, &view_min_width, &view_max_width, | ||
259 | &view_min_height, &view_max_height); | ||
260 | width = fmax(view_min_width, fmin(width, view_max_width)); | ||
261 | height = fmax(view_min_height, fmin(height, view_max_height)); | ||
262 | } | ||
263 | |||
255 | // Recalculate these, in case we hit a min/max limit | 264 | // Recalculate these, in case we hit a min/max limit |
256 | grow_width = width - seat->op_ref_width; | 265 | grow_width = width - seat->op_ref_width; |
257 | grow_height = height - seat->op_ref_height; | 266 | grow_height = height - seat->op_ref_height; |
diff --git a/sway/tree/view.c b/sway/tree/view.c index 24594950..89150a69 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -141,6 +141,19 @@ const char *view_get_shell(struct sway_view *view) { | |||
141 | return "unknown"; | 141 | return "unknown"; |
142 | } | 142 | } |
143 | 143 | ||
144 | void view_get_constraints(struct sway_view *view, double *min_width, | ||
145 | double *max_width, double *min_height, double *max_height) { | ||
146 | if (view->impl->get_constraints) { | ||
147 | view->impl->get_constraints(view, | ||
148 | min_width, max_width, min_height, max_height); | ||
149 | } else { | ||
150 | *min_width = DBL_MIN; | ||
151 | *max_width = DBL_MAX; | ||
152 | *min_height = DBL_MIN; | ||
153 | *max_height = DBL_MAX; | ||
154 | } | ||
155 | } | ||
156 | |||
144 | uint32_t view_configure(struct sway_view *view, double lx, double ly, int width, | 157 | uint32_t view_configure(struct sway_view *view, double lx, double ly, int width, |
145 | int height) { | 158 | int height) { |
146 | if (view->impl->configure) { | 159 | if (view->impl->configure) { |