scratchpad: set initial size
This matches i3's behavior of setting scratchpad containers to 50% of the workspace's width and 75% of the workspace's height, bound by the minimum and maximum floating width/height.
This commit is contained in:
parent
0676ace97f
commit
679c058fac
|
@ -217,6 +217,8 @@ void floating_calculate_constraints(int *min_width, int *max_width,
|
||||||
|
|
||||||
void container_floating_resize_and_center(struct sway_container *con);
|
void container_floating_resize_and_center(struct sway_container *con);
|
||||||
|
|
||||||
|
void container_floating_set_default_size(struct sway_container *con);
|
||||||
|
|
||||||
void container_set_floating(struct sway_container *container, bool enable);
|
void container_set_floating(struct sway_container *container, bool enable);
|
||||||
|
|
||||||
void container_set_geometry_from_content(struct sway_container *con);
|
void container_set_geometry_from_content(struct sway_container *con);
|
||||||
|
|
|
@ -712,19 +712,28 @@ void container_floating_resize_and_center(struct sway_container *con) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void container_floating_set_default_size(struct sway_container *con) {
|
void container_floating_set_default_size(struct sway_container *con) {
|
||||||
if (!sway_assert(con->workspace, "Expected a container on a workspace")) {
|
if (!sway_assert(con->workspace, "Expected a container on a workspace")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int min_width, max_width, min_height, max_height;
|
int min_width, max_width, min_height, max_height;
|
||||||
floating_calculate_constraints(&min_width, &max_width,
|
floating_calculate_constraints(&min_width, &max_width,
|
||||||
&min_height, &max_height);
|
&min_height, &max_height);
|
||||||
struct wlr_box *box = calloc(1, sizeof(struct wlr_box));
|
struct wlr_box *box = calloc(1, sizeof(struct wlr_box));
|
||||||
workspace_get_box(con->workspace, box);
|
workspace_get_box(con->workspace, box);
|
||||||
|
|
||||||
|
double width = fmax(min_width, fmin(box->width * 0.5, max_width));
|
||||||
|
double height = fmax(min_height, fmin(box->height * 0.75, max_height));
|
||||||
if (!con->view) {
|
if (!con->view) {
|
||||||
con->width = fmax(min_width, fmin(box->width * 0.5, max_width));
|
con->width = width;
|
||||||
con->height = fmax(min_height, fmin(box->height * 0.75, max_height));
|
con->height = height;
|
||||||
|
} else {
|
||||||
|
con->content_width = width;
|
||||||
|
con->content_height = height;
|
||||||
|
container_set_geometry_from_content(con);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(box);
|
free(box);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,8 @@ void root_scratchpad_add_container(struct sway_container *con) {
|
||||||
struct sway_container *parent = con->parent;
|
struct sway_container *parent = con->parent;
|
||||||
struct sway_workspace *workspace = con->workspace;
|
struct sway_workspace *workspace = con->workspace;
|
||||||
container_set_floating(con, true);
|
container_set_floating(con, true);
|
||||||
|
container_floating_set_default_size(con);
|
||||||
|
container_floating_move_to_center(con);
|
||||||
container_detach(con);
|
container_detach(con);
|
||||||
con->scratchpad = true;
|
con->scratchpad = true;
|
||||||
list_add(root->scratchpad, con);
|
list_add(root->scratchpad, con);
|
||||||
|
|
Loading…
Reference in a new issue