labwc/src/view.c

132 lines
2.9 KiB
C
Raw Normal View History

#include <stdio.h>
2021-03-20 14:36:40 +00:00
#include "labwc.h"
2021-03-21 20:54:55 +00:00
#include "ssd.h"
void
2020-12-22 20:35:06 +00:00
view_move_resize(struct view *view, struct wlr_box geo)
{
2020-12-22 20:35:06 +00:00
view->impl->configure(view, geo);
}
2020-12-23 18:52:46 +00:00
void
view_move(struct view *view, double x, double y)
{
view->impl->move(view, x, y);
}
void
view_minimize(struct view *view)
2020-09-08 20:51:33 +01:00
{
if (view->minimized == true) {
2020-09-08 20:51:33 +01:00
return;
}
2020-09-08 20:51:33 +01:00
view->minimized = true;
view->impl->unmap(view);
}
void
view_unminimize(struct view *view)
2020-09-08 20:51:33 +01:00
{
if (view->minimized == false) {
2020-09-08 20:51:33 +01:00
return;
}
2020-09-08 20:51:33 +01:00
view->minimized = false;
view->impl->map(view);
}
2020-09-29 20:48:50 +01:00
2021-03-20 14:36:40 +00:00
/*
* view_output - return the output that a view is mostly on
*/
static struct wlr_output *
view_output(struct view *view)
{
struct wlr_output_layout *layout = view->server->output_layout;
struct wlr_output *output;
/* TODO: make this a bit more sophisticated */
output = wlr_output_layout_output_at(layout, view->x + view->w / 2,
view->y + view->h / 2);
return output;
}
2021-07-09 21:39:20 +01:00
void
view_center(struct view *view)
{
struct wlr_output *output = view_output(view);
if (!output) {
return;
}
struct wlr_output_layout *layout = view->server->output_layout;
struct wlr_output_layout_output* ol_output =
wlr_output_layout_get(layout, output);
int center_x = ol_output->x + output->width / 2;
int center_y = ol_output->y + output->height / 2;
view_move(view, center_x - view->w / 2, center_y - view->h / 2);
}
void
view_maximize(struct view *view, bool maximize)
{
2021-03-12 21:27:17 +00:00
if (view->maximized == maximize) {
return;
}
view->impl->maximize(view, maximize);
if (maximize) {
2021-03-20 14:36:40 +00:00
struct wlr_output *output = view_output(view);
if (!output) {
return;
}
2021-03-20 14:36:40 +00:00
struct wlr_output_layout *layout = view->server->output_layout;
struct wlr_output_layout_output* ol_output =
wlr_output_layout_get(layout, output);
2021-02-28 18:12:10 +00:00
view->unmaximized_geometry.x = view->x;
view->unmaximized_geometry.y = view->y;
view->unmaximized_geometry.width = view->w;
view->unmaximized_geometry.height = view->h;
struct wlr_box box = {
2021-03-01 18:15:02 +00:00
.x = ol_output->x,
.y = ol_output->y,
.width = output->width,
.height = output->height,
};
if (view->ssd.enabled) {
2021-03-20 14:41:39 +00:00
struct border border = ssd_thickness(view);
2021-03-01 18:15:02 +00:00
box.x += border.left;
box.y += border.top;
box.width -= border.right + border.left;
box.height -= border.top + border.bottom;
}
box.width /= output->scale;
box.height /= output->scale;
view_move_resize(view, box);
2021-03-01 18:15:02 +00:00
view_move(view, box.x, box.y);
view->maximized = true;
2021-02-28 18:12:10 +00:00
} else {
/* unmaximize */
view_move_resize(view, view->unmaximized_geometry);
view->maximized = false;
}
}
2020-09-29 20:48:50 +01:00
void
view_for_each_surface(struct view *view, wlr_surface_iterator_func_t iterator,
void *user_data)
{
view->impl->for_each_surface(view, iterator, user_data);
}
2021-01-09 22:51:20 +00:00
void
view_for_each_popup_surface(struct view *view, wlr_surface_iterator_func_t iterator,
2021-01-09 22:51:20 +00:00
void *data)
{
if (!view->impl->for_each_popup_surface) {
2021-01-09 22:51:20 +00:00
return;
}
view->impl->for_each_popup_surface(view, iterator, data);
2021-01-09 22:51:20 +00:00
}