mirror of
https://github.com/swaywm/sway.git
synced 2024-11-26 01:41:30 +00:00
Consider view's min/max sizes when resizing
This commit is contained in:
parent
9df660ee31
commit
011d1ebfa4
|
@ -26,6 +26,8 @@ enum sway_view_prop {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sway_view_impl {
|
struct sway_view_impl {
|
||||||
|
void (*get_constraints)(struct sway_view *view, double *min_width,
|
||||||
|
double *max_width, double *min_height, double *max_height);
|
||||||
const char *(*get_string_prop)(struct sway_view *view,
|
const char *(*get_string_prop)(struct sway_view *view,
|
||||||
enum sway_view_prop prop);
|
enum sway_view_prop prop);
|
||||||
uint32_t (*get_int_prop)(struct sway_view *view, enum sway_view_prop prop);
|
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);
|
||||||
|
|
||||||
const char *view_get_shell(struct sway_view *view);
|
const char *view_get_shell(struct sway_view *view);
|
||||||
|
|
||||||
|
void view_get_constraints(struct sway_view *view, double *min_width,
|
||||||
|
double *max_width, double *min_height, double *max_height);
|
||||||
|
|
||||||
uint32_t view_configure(struct sway_view *view, double lx, double ly, int width,
|
uint32_t view_configure(struct sway_view *view, double lx, double ly, int width,
|
||||||
int height);
|
int height);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#define _POSIX_C_SOURCE 199309L
|
#define _POSIX_C_SOURCE 199309L
|
||||||
|
#include <float.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <wayland-server.h>
|
#include <wayland-server.h>
|
||||||
|
@ -95,6 +96,16 @@ static struct sway_xdg_shell_view *xdg_shell_view_from_view(
|
||||||
return (struct sway_xdg_shell_view *)view;
|
return (struct sway_xdg_shell_view *)view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void get_constraints(struct sway_view *view, double *min_width,
|
||||||
|
double *max_width, double *min_height, double *max_height) {
|
||||||
|
struct wlr_xdg_toplevel_state *state =
|
||||||
|
&view->wlr_xdg_surface->toplevel->current;
|
||||||
|
*min_width = state->min_width > 0 ? state->min_width : DBL_MIN;
|
||||||
|
*max_width = state->max_width > 0 ? state->max_width : DBL_MAX;
|
||||||
|
*min_height = state->min_height > 0 ? state->min_height : DBL_MIN;
|
||||||
|
*max_height = state->max_height > 0 ? state->max_height : DBL_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
static const char *get_string_prop(struct sway_view *view, enum sway_view_prop prop) {
|
static const char *get_string_prop(struct sway_view *view, enum sway_view_prop prop) {
|
||||||
if (xdg_shell_view_from_view(view) == NULL) {
|
if (xdg_shell_view_from_view(view) == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -188,6 +199,7 @@ static void destroy(struct sway_view *view) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct sway_view_impl view_impl = {
|
static const struct sway_view_impl view_impl = {
|
||||||
|
.get_constraints = get_constraints,
|
||||||
.get_string_prop = get_string_prop,
|
.get_string_prop = get_string_prop,
|
||||||
.configure = configure,
|
.configure = configure,
|
||||||
.set_activated = set_activated,
|
.set_activated = set_activated,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#define _POSIX_C_SOURCE 199309L
|
#define _POSIX_C_SOURCE 199309L
|
||||||
|
#include <float.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <wayland-server.h>
|
#include <wayland-server.h>
|
||||||
|
@ -94,6 +95,16 @@ static struct sway_xdg_shell_v6_view *xdg_shell_v6_view_from_view(
|
||||||
return (struct sway_xdg_shell_v6_view *)view;
|
return (struct sway_xdg_shell_v6_view *)view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void get_constraints(struct sway_view *view, double *min_width,
|
||||||
|
double *max_width, double *min_height, double *max_height) {
|
||||||
|
struct wlr_xdg_toplevel_v6_state *state =
|
||||||
|
&view->wlr_xdg_surface_v6->toplevel->current;
|
||||||
|
*min_width = state->min_width > 0 ? state->min_width : DBL_MIN;
|
||||||
|
*max_width = state->max_width > 0 ? state->max_width : DBL_MAX;
|
||||||
|
*min_height = state->min_height > 0 ? state->min_height : DBL_MIN;
|
||||||
|
*max_height = state->max_height > 0 ? state->max_height : DBL_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
static const char *get_string_prop(struct sway_view *view, enum sway_view_prop prop) {
|
static const char *get_string_prop(struct sway_view *view, enum sway_view_prop prop) {
|
||||||
if (xdg_shell_v6_view_from_view(view) == NULL) {
|
if (xdg_shell_v6_view_from_view(view) == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -184,6 +195,7 @@ static void destroy(struct sway_view *view) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct sway_view_impl view_impl = {
|
static const struct sway_view_impl view_impl = {
|
||||||
|
.get_constraints = get_constraints,
|
||||||
.get_string_prop = get_string_prop,
|
.get_string_prop = get_string_prop,
|
||||||
.configure = configure,
|
.configure = configure,
|
||||||
.set_activated = set_activated,
|
.set_activated = set_activated,
|
||||||
|
|
|
@ -243,7 +243,7 @@ static void handle_resize_motion(struct sway_seat *seat,
|
||||||
grow_height = seat->op_ref_height * max_multiplier;
|
grow_height = seat->op_ref_height * max_multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine new width/height, and accommodate for min/max values
|
// Determine new width/height, and accommodate for floating min/max values
|
||||||
double width = seat->op_ref_width + grow_width;
|
double width = seat->op_ref_width + grow_width;
|
||||||
double height = seat->op_ref_height + grow_height;
|
double height = seat->op_ref_height + grow_height;
|
||||||
int min_width, max_width, min_height, max_height;
|
int min_width, max_width, min_height, max_height;
|
||||||
|
@ -252,6 +252,15 @@ static void handle_resize_motion(struct sway_seat *seat,
|
||||||
width = fmax(min_width, fmin(width, max_width));
|
width = fmax(min_width, fmin(width, max_width));
|
||||||
height = fmax(min_height, fmin(height, max_height));
|
height = fmax(min_height, fmin(height, max_height));
|
||||||
|
|
||||||
|
// Apply the view's min/max size
|
||||||
|
if (con->type == C_VIEW) {
|
||||||
|
double view_min_width, view_max_width, view_min_height, view_max_height;
|
||||||
|
view_get_constraints(con->sway_view, &view_min_width, &view_max_width,
|
||||||
|
&view_min_height, &view_max_height);
|
||||||
|
width = fmax(view_min_width, fmin(width, view_max_width));
|
||||||
|
height = fmax(view_min_height, fmin(height, view_max_height));
|
||||||
|
}
|
||||||
|
|
||||||
// Recalculate these, in case we hit a min/max limit
|
// Recalculate these, in case we hit a min/max limit
|
||||||
grow_width = width - seat->op_ref_width;
|
grow_width = width - seat->op_ref_width;
|
||||||
grow_height = height - seat->op_ref_height;
|
grow_height = height - seat->op_ref_height;
|
||||||
|
|
|
@ -141,6 +141,19 @@ const char *view_get_shell(struct sway_view *view) {
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void view_get_constraints(struct sway_view *view, double *min_width,
|
||||||
|
double *max_width, double *min_height, double *max_height) {
|
||||||
|
if (view->impl->get_constraints) {
|
||||||
|
view->impl->get_constraints(view,
|
||||||
|
min_width, max_width, min_height, max_height);
|
||||||
|
} else {
|
||||||
|
*min_width = DBL_MIN;
|
||||||
|
*max_width = DBL_MAX;
|
||||||
|
*min_height = DBL_MIN;
|
||||||
|
*max_height = DBL_MAX;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t view_configure(struct sway_view *view, double lx, double ly, int width,
|
uint32_t view_configure(struct sway_view *view, double lx, double ly, int width,
|
||||||
int height) {
|
int height) {
|
||||||
if (view->impl->configure) {
|
if (view->impl->configure) {
|
||||||
|
|
Loading…
Reference in a new issue