mirror of
https://github.com/swaywm/sway.git
synced 2024-11-25 09:21:28 +00:00
floating_maximum_size: change default behavior
This changes the way zero (which is the default) is interpreted for both the width and height of `floating_maximum_size`. It now refers to the width and height of the entire output layout, which matches i3's behavior. This also removes duplicated code to calculate the floating constraints in three files. Before this, `container_init_floating` used two-thirds of the workspace width/height as the max and the entire workspace width/height was used everywhere else. Now, all callers use a single function `floating_calculate_constraints`.
This commit is contained in:
parent
37f0e1f1a2
commit
430359519c
|
@ -212,6 +212,9 @@ void container_update_representation(struct sway_container *container);
|
||||||
*/
|
*/
|
||||||
size_t container_titlebar_height(void);
|
size_t container_titlebar_height(void);
|
||||||
|
|
||||||
|
void floating_calculate_constraints(int *min_width, int *max_width,
|
||||||
|
int *min_height, int *max_height);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resize and center the container in its workspace.
|
* Resize and center the container in its workspace.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -66,45 +66,6 @@ static int parse_resize_amount(int argc, char **argv,
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void calculate_constraints(int *min_width, int *max_width,
|
|
||||||
int *min_height, int *max_height) {
|
|
||||||
struct sway_container *con = config->handler_context.container;
|
|
||||||
|
|
||||||
if (config->floating_minimum_width == -1) { // no minimum
|
|
||||||
*min_width = 0;
|
|
||||||
} else if (config->floating_minimum_width == 0) { // automatic
|
|
||||||
*min_width = 75;
|
|
||||||
} else {
|
|
||||||
*min_width = config->floating_minimum_width;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config->floating_minimum_height == -1) { // no minimum
|
|
||||||
*min_height = 0;
|
|
||||||
} else if (config->floating_minimum_height == 0) { // automatic
|
|
||||||
*min_height = 50;
|
|
||||||
} else {
|
|
||||||
*min_height = config->floating_minimum_height;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config->floating_maximum_width == -1 ||
|
|
||||||
container_is_scratchpad_hidden(con)) { // no max
|
|
||||||
*max_width = INT_MAX;
|
|
||||||
} else if (config->floating_maximum_width == 0) { // automatic
|
|
||||||
*max_width = con->workspace->width;
|
|
||||||
} else {
|
|
||||||
*max_width = config->floating_maximum_width;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config->floating_maximum_height == -1 ||
|
|
||||||
container_is_scratchpad_hidden(con)) { // no max
|
|
||||||
*max_height = INT_MAX;
|
|
||||||
} else if (config->floating_maximum_height == 0) { // automatic
|
|
||||||
*max_height = con->workspace->height;
|
|
||||||
} else {
|
|
||||||
*max_height = config->floating_maximum_height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint32_t parse_resize_axis(const char *axis) {
|
static uint32_t parse_resize_axis(const char *axis) {
|
||||||
if (strcasecmp(axis, "width") == 0 || strcasecmp(axis, "horizontal") == 0) {
|
if (strcasecmp(axis, "width") == 0 || strcasecmp(axis, "horizontal") == 0) {
|
||||||
return AXIS_HORIZONTAL;
|
return AXIS_HORIZONTAL;
|
||||||
|
@ -258,7 +219,8 @@ static struct cmd_results *resize_adjust_floating(uint32_t axis,
|
||||||
|
|
||||||
// Make sure we're not adjusting beyond floating min/max size
|
// Make sure we're not adjusting beyond floating min/max size
|
||||||
int min_width, max_width, min_height, max_height;
|
int min_width, max_width, min_height, max_height;
|
||||||
calculate_constraints(&min_width, &max_width, &min_height, &max_height);
|
floating_calculate_constraints(&min_width, &max_width,
|
||||||
|
&min_height, &max_height);
|
||||||
if (con->width + grow_width < min_width) {
|
if (con->width + grow_width < min_width) {
|
||||||
grow_width = min_width - con->width;
|
grow_width = min_width - con->width;
|
||||||
} else if (con->width + grow_width > max_width) {
|
} else if (con->width + grow_width > max_width) {
|
||||||
|
@ -383,7 +345,8 @@ static struct cmd_results *resize_set_tiled(struct sway_container *con,
|
||||||
static struct cmd_results *resize_set_floating(struct sway_container *con,
|
static struct cmd_results *resize_set_floating(struct sway_container *con,
|
||||||
struct resize_amount *width, struct resize_amount *height) {
|
struct resize_amount *width, struct resize_amount *height) {
|
||||||
int min_width, max_width, min_height, max_height, grow_width = 0, grow_height = 0;
|
int min_width, max_width, min_height, max_height, grow_width = 0, grow_height = 0;
|
||||||
calculate_constraints(&min_width, &max_width, &min_height, &max_height);
|
floating_calculate_constraints(&min_width, &max_width,
|
||||||
|
&min_height, &max_height);
|
||||||
|
|
||||||
if (width->amount) {
|
if (width->amount) {
|
||||||
switch (width->unit) {
|
switch (width->unit) {
|
||||||
|
|
|
@ -17,41 +17,6 @@ struct seatop_resize_floating_event {
|
||||||
double ref_con_lx, ref_con_ly; // container's x/y at start of op
|
double ref_con_lx, ref_con_ly; // container's x/y at start of op
|
||||||
};
|
};
|
||||||
|
|
||||||
static void calculate_floating_constraints(struct sway_container *con,
|
|
||||||
int *min_width, int *max_width, int *min_height, int *max_height) {
|
|
||||||
if (config->floating_minimum_width == -1) { // no minimum
|
|
||||||
*min_width = 0;
|
|
||||||
} else if (config->floating_minimum_width == 0) { // automatic
|
|
||||||
*min_width = 75;
|
|
||||||
} else {
|
|
||||||
*min_width = config->floating_minimum_width;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config->floating_minimum_height == -1) { // no minimum
|
|
||||||
*min_height = 0;
|
|
||||||
} else if (config->floating_minimum_height == 0) { // automatic
|
|
||||||
*min_height = 50;
|
|
||||||
} else {
|
|
||||||
*min_height = config->floating_minimum_height;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config->floating_maximum_width == -1) { // no maximum
|
|
||||||
*max_width = INT_MAX;
|
|
||||||
} else if (config->floating_maximum_width == 0) { // automatic
|
|
||||||
*max_width = con->workspace->width;
|
|
||||||
} else {
|
|
||||||
*max_width = config->floating_maximum_width;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config->floating_maximum_height == -1) { // no maximum
|
|
||||||
*max_height = INT_MAX;
|
|
||||||
} else if (config->floating_maximum_height == 0) { // automatic
|
|
||||||
*max_height = con->workspace->height;
|
|
||||||
} else {
|
|
||||||
*max_height = config->floating_maximum_height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void handle_motion(struct sway_seat *seat, uint32_t time_msec) {
|
static void handle_motion(struct sway_seat *seat, uint32_t time_msec) {
|
||||||
struct seatop_resize_floating_event *e = seat->seatop_data;
|
struct seatop_resize_floating_event *e = seat->seatop_data;
|
||||||
struct sway_container *con = e->con;
|
struct sway_container *con = e->con;
|
||||||
|
@ -85,7 +50,7 @@ static void handle_motion(struct sway_seat *seat, uint32_t time_msec) {
|
||||||
double width = e->ref_width + grow_width;
|
double width = e->ref_width + grow_width;
|
||||||
double height = e->ref_height + grow_height;
|
double height = e->ref_height + grow_height;
|
||||||
int min_width, max_width, min_height, max_height;
|
int min_width, max_width, min_height, max_height;
|
||||||
calculate_floating_constraints(con, &min_width, &max_width,
|
floating_calculate_constraints(&min_width, &max_width,
|
||||||
&min_height, &max_height);
|
&min_height, &max_height);
|
||||||
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));
|
||||||
|
|
|
@ -430,7 +430,8 @@ The default colors are:
|
||||||
|
|
||||||
*floating_maximum_size* <width> x <height>
|
*floating_maximum_size* <width> x <height>
|
||||||
Specifies the maximum size of floating windows. -1 x -1 removes the upper
|
Specifies the maximum size of floating windows. -1 x -1 removes the upper
|
||||||
limit.
|
limit. The default is 0 x 0, which will use the width and height of the
|
||||||
|
entire output layout as the maximums
|
||||||
|
|
||||||
*floating_minimum_size* <width> x <height>
|
*floating_minimum_size* <width> x <height>
|
||||||
Specifies the minimum size of floating windows. The default is 75 x 50.
|
Specifies the minimum size of floating windows. The default is 75 x 50.
|
||||||
|
|
|
@ -611,56 +611,78 @@ size_t container_titlebar_height(void) {
|
||||||
return config->font_height + config->titlebar_v_padding * 2;
|
return config->font_height + config->titlebar_v_padding * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void container_init_floating(struct sway_container *con) {
|
void floating_calculate_constraints(int *min_width, int *max_width,
|
||||||
struct sway_workspace *ws = con->workspace;
|
int *min_height, int *max_height) {
|
||||||
int min_width, min_height;
|
|
||||||
int max_width, max_height;
|
|
||||||
|
|
||||||
if (config->floating_minimum_width == -1) { // no minimum
|
if (config->floating_minimum_width == -1) { // no minimum
|
||||||
min_width = 0;
|
*min_width = 0;
|
||||||
} else if (config->floating_minimum_width == 0) { // automatic
|
} else if (config->floating_minimum_width == 0) { // automatic
|
||||||
min_width = 75;
|
*min_width = 75;
|
||||||
} else {
|
} else {
|
||||||
min_width = config->floating_minimum_width;
|
*min_width = config->floating_minimum_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config->floating_minimum_height == -1) { // no minimum
|
if (config->floating_minimum_height == -1) { // no minimum
|
||||||
min_height = 0;
|
*min_height = 0;
|
||||||
} else if (config->floating_minimum_height == 0) { // automatic
|
} else if (config->floating_minimum_height == 0) { // automatic
|
||||||
min_height = 50;
|
*min_height = 50;
|
||||||
} else {
|
} else {
|
||||||
min_height = config->floating_minimum_height;
|
*min_height = config->floating_minimum_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct wlr_box *box = wlr_output_layout_get_box(root->output_layout, NULL);
|
||||||
|
|
||||||
if (config->floating_maximum_width == -1) { // no maximum
|
if (config->floating_maximum_width == -1) { // no maximum
|
||||||
max_width = INT_MAX;
|
*max_width = INT_MAX;
|
||||||
} else if (config->floating_maximum_width == 0) { // automatic
|
} else if (config->floating_maximum_width == 0) { // automatic
|
||||||
max_width = ws->width * 0.6666;
|
*max_width = box->width;
|
||||||
} else {
|
} else {
|
||||||
max_width = config->floating_maximum_width;
|
*max_width = config->floating_maximum_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config->floating_maximum_height == -1) { // no maximum
|
if (config->floating_maximum_height == -1) { // no maximum
|
||||||
max_height = INT_MAX;
|
*max_height = INT_MAX;
|
||||||
} else if (config->floating_maximum_height == 0) { // automatic
|
} else if (config->floating_maximum_height == 0) { // automatic
|
||||||
max_height = ws->height * 0.6666;
|
*max_height = box->height;
|
||||||
} else {
|
} else {
|
||||||
max_height = config->floating_maximum_height;
|
*max_height = config->floating_maximum_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void container_init_floating(struct sway_container *con) {
|
||||||
|
struct sway_workspace *ws = con->workspace;
|
||||||
|
int min_width, max_width, min_height, max_height;
|
||||||
|
floating_calculate_constraints(&min_width, &max_width,
|
||||||
|
&min_height, &max_height);
|
||||||
|
|
||||||
if (!con->view) {
|
if (!con->view) {
|
||||||
con->width = max_width;
|
con->width = max_width;
|
||||||
con->height = max_height;
|
con->height = max_height;
|
||||||
|
if (con->width > ws->width || con->height > ws->height) {
|
||||||
|
struct wlr_box *ob = wlr_output_layout_get_box(root->output_layout,
|
||||||
|
ws->output->wlr_output);
|
||||||
|
con->x = ob->x + (ob->width - con->width) / 2;
|
||||||
|
con->y = ob->y + (ob->height - con->height) / 2;
|
||||||
|
} else {
|
||||||
con->x = ws->x + (ws->width - con->width) / 2;
|
con->x = ws->x + (ws->width - con->width) / 2;
|
||||||
con->y = ws->y + (ws->height - con->height) / 2;
|
con->y = ws->y + (ws->height - con->height) / 2;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
struct sway_view *view = con->view;
|
struct sway_view *view = con->view;
|
||||||
con->content_width =
|
con->content_width =
|
||||||
fmax(min_width, fmin(view->natural_width, max_width));
|
fmax(min_width, fmin(view->natural_width, max_width));
|
||||||
con->content_height =
|
con->content_height =
|
||||||
fmax(min_height, fmin(view->natural_height, max_height));
|
fmax(min_height, fmin(view->natural_height, max_height));
|
||||||
|
if (con->content_width > ws->width
|
||||||
|
|| con->content_height > ws->height) {
|
||||||
|
struct wlr_box *ob = wlr_output_layout_get_box(root->output_layout,
|
||||||
|
ws->output->wlr_output);
|
||||||
|
con->content_x = ob->x + (ob->width - con->content_width) / 2;
|
||||||
|
con->content_y = ob->y + (ob->height - con->content_height) / 2;
|
||||||
|
} else {
|
||||||
con->content_x = ws->x + (ws->width - con->content_width) / 2;
|
con->content_x = ws->x + (ws->width - con->content_width) / 2;
|
||||||
con->content_y = ws->y + (ws->height - con->content_height) / 2;
|
con->content_y = ws->y + (ws->height - con->content_height) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
// If the view's border is B_NONE then these properties are ignored.
|
// If the view's border is B_NONE then these properties are ignored.
|
||||||
con->border_top = con->border_bottom = true;
|
con->border_top = con->border_bottom = true;
|
||||||
|
|
Loading…
Reference in a new issue