Handle usable area for maximized windows
Also fixes some bugs
This commit is contained in:
parent
ab6c2bf584
commit
097e87ca9f
|
@ -86,6 +86,7 @@ void view_update_size(struct roots_view *view, uint32_t width, uint32_t height);
|
|||
void view_initial_focus(struct roots_view *view);
|
||||
void view_map(struct roots_view *view, struct wlr_surface *surface);
|
||||
void view_unmap(struct roots_view *view);
|
||||
void view_arrange_maximized(struct roots_view *view);
|
||||
|
||||
void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data);
|
||||
void handle_xdg_shell_surface(struct wl_listener *listener, void *data);
|
||||
|
|
|
@ -188,6 +188,38 @@ static struct wlr_output *view_get_output(struct roots_view *view) {
|
|||
output_y);
|
||||
}
|
||||
|
||||
void view_arrange_maximized(struct roots_view *view) {
|
||||
struct wlr_box view_box;
|
||||
view_get_box(view, &view_box);
|
||||
|
||||
view->maximized = true;
|
||||
view->saved.x = view->x;
|
||||
view->saved.y = view->y;
|
||||
view->saved.rotation = view->rotation;
|
||||
view->saved.width = view_box.width;
|
||||
view->saved.height = view_box.height;
|
||||
|
||||
struct wlr_output *output = view_get_output(view);
|
||||
struct roots_output *roots_output = output->data;
|
||||
struct wlr_box *output_box =
|
||||
wlr_output_layout_get_box(view->desktop->layout, output);
|
||||
struct wlr_box usable_area;
|
||||
memcpy(&usable_area, &roots_output->usable_area,
|
||||
sizeof(struct wlr_box));
|
||||
usable_area.x += output_box->x;
|
||||
usable_area.y += output_box->y;
|
||||
|
||||
wlr_log(L_DEBUG, "output area: %dx%d@%d,%d",
|
||||
output_box->width, output_box->height,
|
||||
output_box->x, output_box->y);
|
||||
wlr_log(L_DEBUG, "usable area: %dx%d@%d,%d",
|
||||
usable_area.width, usable_area.height,
|
||||
usable_area.x, usable_area.y);
|
||||
view_move_resize(view, usable_area.x, usable_area.y,
|
||||
usable_area.width, usable_area.height);
|
||||
view_rotate(view, 0);
|
||||
}
|
||||
|
||||
void view_maximize(struct roots_view *view, bool maximized) {
|
||||
if (view->maximized == maximized) {
|
||||
return;
|
||||
|
@ -198,23 +230,7 @@ void view_maximize(struct roots_view *view, bool maximized) {
|
|||
}
|
||||
|
||||
if (!view->maximized && maximized) {
|
||||
struct wlr_box view_box;
|
||||
view_get_box(view, &view_box);
|
||||
|
||||
view->maximized = true;
|
||||
view->saved.x = view->x;
|
||||
view->saved.y = view->y;
|
||||
view->saved.rotation = view->rotation;
|
||||
view->saved.width = view_box.width;
|
||||
view->saved.height = view_box.height;
|
||||
|
||||
struct wlr_output *output = view_get_output(view);
|
||||
struct wlr_box *output_box =
|
||||
wlr_output_layout_get_box(view->desktop->layout, output);
|
||||
|
||||
view_move_resize(view, output_box->x, output_box->y, output_box->width,
|
||||
output_box->height);
|
||||
view_rotate(view, 0);
|
||||
view_arrange_maximized(view);
|
||||
}
|
||||
|
||||
if (view->maximized && !maximized) {
|
||||
|
|
|
@ -15,45 +15,50 @@ static void apply_exclusive(struct wlr_box *usable_area,
|
|||
uint32_t anchor, uint32_t exclusive) {
|
||||
struct {
|
||||
uint32_t anchors;
|
||||
int *value;
|
||||
int multiplier;
|
||||
int *positive_axis;
|
||||
int *negative_axis;
|
||||
} edges[] = {
|
||||
{
|
||||
.anchors =
|
||||
ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
|
||||
ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT |
|
||||
ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP,
|
||||
.value = &usable_area->y,
|
||||
.multiplier = 1,
|
||||
.positive_axis = &usable_area->y,
|
||||
.negative_axis = &usable_area->height,
|
||||
},
|
||||
{
|
||||
.anchors =
|
||||
ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
|
||||
ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT |
|
||||
ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM,
|
||||
.value = &usable_area->height,
|
||||
.multiplier = -1,
|
||||
.positive_axis = NULL,
|
||||
.negative_axis = &usable_area->height,
|
||||
},
|
||||
{
|
||||
.anchors =
|
||||
ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
|
||||
ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |
|
||||
ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM,
|
||||
.value = &usable_area->x,
|
||||
.multiplier = 1,
|
||||
.positive_axis = &usable_area->x,
|
||||
.negative_axis = &usable_area->width,
|
||||
},
|
||||
{
|
||||
.anchors =
|
||||
ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT |
|
||||
ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |
|
||||
ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM,
|
||||
.value = &usable_area->width,
|
||||
.multiplier = -1,
|
||||
.positive_axis = NULL,
|
||||
.negative_axis = &usable_area->width,
|
||||
},
|
||||
};
|
||||
for (size_t i = 0; i < sizeof(edges) / sizeof(edges[0]); ++i) {
|
||||
if ((anchor & edges[i].anchors) == edges[i].anchors) {
|
||||
*edges[i].value += exclusive * edges[i].multiplier;
|
||||
if (edges[i].positive_axis) {
|
||||
*edges[i].positive_axis += exclusive;
|
||||
}
|
||||
if (edges[i].negative_axis) {
|
||||
*edges[i].negative_axis -= exclusive;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -74,9 +79,9 @@ static void arrange_layer(struct wlr_output *output, struct wl_list *list,
|
|||
} else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT)) {
|
||||
box.x = usable_area->x;
|
||||
} else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT)) {
|
||||
box.x = usable_area->width - box.width;
|
||||
box.x = usable_area->x + (usable_area->width - box.width);
|
||||
} else {
|
||||
box.x = (usable_area->width / 2) - (box.width / 2);
|
||||
box.x = usable_area->x + ((usable_area->width / 2) - (box.width / 2));
|
||||
}
|
||||
// Vertical axis
|
||||
const uint32_t both_vert = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
|
||||
|
@ -87,9 +92,9 @@ static void arrange_layer(struct wlr_output *output, struct wl_list *list,
|
|||
} else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP)) {
|
||||
box.y = usable_area->y;
|
||||
} else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM)) {
|
||||
box.y = usable_area->height - box.height;
|
||||
box.y = usable_area->y + (usable_area->height - box.height);
|
||||
} else {
|
||||
box.y = (usable_area->height / 2) - (box.height / 2);
|
||||
box.y = usable_area->y + ((usable_area->height / 2) - (box.height / 2));
|
||||
}
|
||||
wlr_log(L_DEBUG, "arranged layer at %dx%d@%d,%d",
|
||||
box.width, box.height, box.x, box.y);
|
||||
|
@ -119,16 +124,24 @@ static void arrange_layers(struct wlr_output *_output) {
|
|||
&usable_area);
|
||||
memcpy(&output->usable_area, &usable_area, sizeof(struct wlr_box));
|
||||
|
||||
arrange_layer(output->wlr_output,
|
||||
&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP],
|
||||
&usable_area);
|
||||
|
||||
memset(&usable_area, 0, sizeof(struct wlr_box));
|
||||
wlr_output_effective_resolution(output->wlr_output,
|
||||
&usable_area.width, &usable_area.height);
|
||||
|
||||
arrange_layer(output->wlr_output,
|
||||
&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP],
|
||||
&usable_area);
|
||||
arrange_layer(output->wlr_output,
|
||||
&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY],
|
||||
&usable_area);
|
||||
|
||||
struct roots_view *view;
|
||||
wl_list_for_each(view, &output->desktop->views, link) {
|
||||
if (view->maximized) {
|
||||
view_arrange_maximized(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_output_destroy(struct wl_listener *listener, void *data) {
|
||||
|
|
Loading…
Reference in New Issue