]> git.mdlowis.com Git - proto/labwc.git/commitdiff
view: constrain window size to that of usable area
authorJohan Malm <jgm323@gmail.com>
Sat, 6 Jan 2024 21:36:12 +0000 (21:36 +0000)
committerJohan Malm <johanmalm@users.noreply.github.com>
Mon, 8 Jan 2024 22:08:27 +0000 (22:08 +0000)
...on first map (when application is started).

Fixes #1399

include/view.h
src/view.c
src/xdg.c
src/xwayland.c

index 8c1c54912c63231c908d62017fdad0111df1bd9f..c446df8bd1d206171d9a232ee4824567045bc153 100644 (file)
@@ -407,6 +407,7 @@ void view_center(struct view *view, const struct wlr_box *ref);
  * @view: view to be placed
  */
 void view_place_initial(struct view *view);
+void view_constrain_size_to_that_of_usable_area(struct view *view);
 
 void view_restore_to(struct view *view, struct wlr_box geometry);
 void view_set_untiled(struct view *view);
index 72f23812febc9ffc641a292e703c60ed11243e44..b39bde1734c92479804ae0ae0c0f8a45e12d4eaf 100644 (file)
@@ -731,6 +731,25 @@ view_place_initial(struct view *view)
        view_center(view, NULL);
 }
 
+void
+view_constrain_size_to_that_of_usable_area(struct view *view)
+{
+       if (!view || !view->output) {
+               return;
+       }
+       struct wlr_box *usable_area = &view->output->usable_area;
+       struct border margin = ssd_get_margin(view->ssd);
+       struct wlr_box box = {
+               .x = view->pending.x,
+               .y = view->pending.y,
+               .width = MIN(usable_area->width - margin.left - margin.right,
+                       view->pending.width),
+               .height = MIN(usable_area->height - margin.top - margin.bottom,
+                       view->pending.height),
+       };
+       view_move_resize(view, box);
+}
+
 static void
 view_apply_natural_geometry(struct view *view)
 {
index 544a067614aa2aa315d20708498b24cc4e5e7606..de106f8ae64e0eadada5984fa01a8d2f18359e27 100644 (file)
--- a/src/xdg.c
+++ b/src/xdg.c
@@ -420,6 +420,8 @@ position_xdg_toplevel_view(struct view *view)
        struct wlr_xdg_toplevel *parent_xdg_toplevel =
                xdg_toplevel_from_view(view)->parent;
 
+       view_constrain_size_to_that_of_usable_area(view);
+
        if (parent_xdg_toplevel) {
                /* Child views are center-aligned relative to their parents */
                struct view *parent = lookup_view_by_xdg_toplevel(
index 86f7a1ae87ac1cb4848cd93cb0ab336b222d4c98..b88daa8709fd15993eeb4a08bf0112d827e1a1f7 100644 (file)
@@ -505,6 +505,8 @@ set_initial_position(struct view *view,
                        XCB_ICCCM_SIZE_HINT_US_POSITION |
                        XCB_ICCCM_SIZE_HINT_P_POSITION));
 
+       view_constrain_size_to_that_of_usable_area(view);
+
        if (has_position) {
                /*
                 * Make sure a floating view is onscreen. For a