]> git.mdlowis.com Git - proto/labwc.git/commitdiff
view: add view_center()
authorJohan Malm <jgm323@gmail.com>
Fri, 9 Jul 2021 20:39:20 +0000 (21:39 +0100)
committerJohan Malm <jgm323@gmail.com>
Fri, 9 Jul 2021 20:39:20 +0000 (21:39 +0100)
include/labwc.h
src/view.c

index 6f55bce7061936997c6e964860595d21b26c9b1b..f12870df97d46520a293b010c6fd3aed3e5a2467 100644 (file)
@@ -290,6 +290,7 @@ void view_move_resize(struct view *view, struct wlr_box geo);
 void view_move(struct view *view, double x, double y);
 void view_minimize(struct view *view);
 void view_unminimize(struct view *view);
+void view_center(struct view *view);
 void view_maximize(struct view *view, bool maximize);
 void view_for_each_surface(struct view *view,
        wlr_surface_iterator_func_t iterator, void *user_data);
index 2a463232d8bdc94aafededb4c3d93af262ea5652..0f59e97918d44587150d49a84878a1bf631ec8fd 100644 (file)
@@ -49,6 +49,22 @@ view_output(struct view *view)
        return output;
 }
 
+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)
 {