]> git.mdlowis.com Git - proto/labwc.git/commitdiff
view: fix some inconsistencies in view_ functions
authorJohn Lindgren <john@jlindgren.net>
Tue, 26 Sep 2023 02:42:06 +0000 (22:42 -0400)
committerJohan Malm <johanmalm@users.noreply.github.com>
Mon, 9 Oct 2023 19:34:13 +0000 (20:34 +0100)
... especially regarding whether a (view *) parameter may be NULL. It's
confusing when some functions accept NULL and others don't, and could
trip someone up.

I'm partly to blame for the inconsistency, since (if memory serves) I
added view_is_tiled() and view_is_floating(), which do accept NULL.

In detail:

- Make view_is_tiled() and view_is_floating() no longer accept NULL.

- Rename view_isfocusable -> view_is_focusable for consistency with
  other view_is_ functions.

- Eliminate view_inhibits_keybinds() as it only existed to safely accept
  NULL and check a single flag, which can be checked directly.

- Add assert(view) to remaining public view_ functions to catch
  accidentally passing NULL.

- Inline inhibit_keybinds() into view_toggle_keybinds(). It is closely
  related and not called from anywhere else; inlining it allows
  eliminating an extra assert() which is now impossible.

include/view.h
src/desktop.c
src/keyboard.c
src/osd.c
src/view.c

index 7046c1153187d2f921cef99ac21a7cb9e64529d9..d9a213acd2bd80f5af6b0a779d8f74e64e9a3f2f 100644 (file)
@@ -271,7 +271,7 @@ void view_array_append(struct server *server, struct wl_array *views,
        enum lab_view_criteria criteria);
 
 /**
- * view_isfocusable() - Check whether or not a view can be focused
+ * view_is_focusable() - Check whether or not a view can be focused
  * @view: view to be checked
  *
  * The purpose of this test is to filter out views (generally Xwayland) which
@@ -282,9 +282,8 @@ void view_array_append(struct server *server, struct wl_array *views,
  * The only views that are allowed to be focusd are those that have a surface
  * and have been mapped at some point since creation.
  */
-bool view_isfocusable(struct view *view);
+bool view_is_focusable(struct view *view);
 
-bool view_inhibits_keybinds(struct view *view);
 void view_toggle_keybinds(struct view *view);
 
 void view_set_activated(struct view *view, bool activated);
index eac5645345a418b5390e82246258143d0685de08..f6c94dd89572246f92bdb6627428570fbc8b3d60 100644 (file)
@@ -114,7 +114,7 @@ first_view(struct server *server)
                        continue;
                }
                struct view *view = node_view_from_node(node);
-               if (view_isfocusable(view)) {
+               if (view_is_focusable(view)) {
                        return view;
                }
        }
@@ -186,7 +186,7 @@ desktop_cycle_view(struct server *server, struct view *start_view,
                view = node_view_from_node(node);
 
                enum property skip = window_rules_get_property(view, "skipWindowSwitcher");
-               if (view_isfocusable(view) && skip != LAB_PROP_TRUE) {
+               if (view_is_focusable(view) && skip != LAB_PROP_TRUE) {
                        return view;
                }
        } while (view != start_view);
@@ -208,7 +208,7 @@ desktop_topmost_focusable_view(struct server *server)
                        continue;
                }
                view = node_view_from_node(node);
-               if (view->mapped && view_isfocusable(view)) {
+               if (view->mapped && view_is_focusable(view)) {
                        return view;
                }
        }
@@ -247,7 +247,7 @@ desktop_focus_output(struct output *output)
                        continue;
                }
                view = node_view_from_node(node);
-               if (!view_isfocusable(view)) {
+               if (!view_is_focusable(view)) {
                        continue;
                }
                if (wlr_output_layout_intersects(layout,
index a589ee8fce4c51df8aaa96f5d8b3bee4560d2c71..aba3c6c95ba0aed71e2711fbdcd595643809d122 100644 (file)
@@ -94,7 +94,8 @@ handle_keybinding(struct server *server, uint32_t modifiers, xkb_keysym_t sym, x
                        continue;
                }
                if (server->seat.nr_inhibited_keybind_views
-                               && view_inhibits_keybinds(server->focused_view)
+                               && server->focused_view
+                               && server->focused_view->inhibits_keybinds
                                && !actions_contain_toggle_keybinds(&keybind->actions)) {
                        continue;
                }
index 5477cf27e842cff332666cc100b257e0a2b6b39c..230f87afc6bc35606a52525977f63638a1ddf3a0 100644 (file)
--- a/src/osd.c
+++ b/src/osd.c
@@ -479,7 +479,7 @@ osd_update(struct server *server)
 
        /* Outline current window */
        if (rc.window_switcher.outlines) {
-               if (view_isfocusable(server->osd_state.cycle_view)) {
+               if (view_is_focusable(server->osd_state.cycle_view)) {
                        osd_update_preview_outlines(server->osd_state.cycle_view);
                }
        }
index 6185d9177009f4963a21681b37434a980d52de53..3e27bc77ff07c712a79dc30905ad971baccf80cd 100644 (file)
@@ -85,7 +85,7 @@ view_matches_query(struct view *view, struct view_query *query)
 static bool
 matches_criteria(struct view *view, enum lab_view_criteria criteria)
 {
-       if (!view_isfocusable(view)) {
+       if (!view_is_focusable(view)) {
                return false;
        }
        if (criteria & LAB_VIEW_CRITERIA_CURRENT_WORKSPACE) {
@@ -144,8 +144,9 @@ view_array_append(struct server *server, struct wl_array *views,
 }
 
 bool
-view_isfocusable(struct view *view)
+view_is_focusable(struct view *view)
 {
+       assert(view);
        if (!view->surface) {
                return false;
        }
@@ -322,6 +323,7 @@ view_move_resize(struct view *view, struct wlr_box geo)
 void
 view_resize_relative(struct view *view, int left, int right, int top, int bottom)
 {
+       assert(view);
        if (view->fullscreen || view->maximized) {
                return;
        }
@@ -337,6 +339,7 @@ view_resize_relative(struct view *view, int left, int right, int top, int bottom
 void
 view_move_relative(struct view *view, int x, int y)
 {
+       assert(view);
        if (view->fullscreen) {
                return;
        }
@@ -351,6 +354,7 @@ view_move_relative(struct view *view, int x, int y)
 struct view_size_hints
 view_get_size_hints(struct view *view)
 {
+       assert(view);
        if (view->impl->get_size_hints) {
                return view->impl->get_size_hints(view);
        }
@@ -458,6 +462,7 @@ minimize_sub_views(struct view *view, bool minimized)
 void
 view_minimize(struct view *view, bool minimized)
 {
+       assert(view);
        /*
         * Minimize the root window first because some xwayland clients send a
         * request-unmap to sub-windows at this point (for example gimp and its
@@ -765,14 +770,16 @@ view_restore_to(struct view *view, struct wlr_box geometry)
 bool
 view_is_tiled(struct view *view)
 {
-       return view && (view->tiled || view->tiled_region
+       assert(view);
+       return (view->tiled || view->tiled_region
                || view->tiled_region_evacuate);
 }
 
 bool
 view_is_floating(struct view *view)
 {
-       return view && !(view->fullscreen || view->maximized || view->tiled
+       assert(view);
+       return !(view->fullscreen || view->maximized || view->tiled
                || view->tiled_region || view->tiled_region_evacuate);
 }
 
@@ -1323,36 +1330,23 @@ view_reload_ssd(struct view *view)
        }
 }
 
-static void
-inhibit_keybinds(struct view *view, bool inhibit)
+void
+view_toggle_keybinds(struct view *view)
 {
-       assert(view->inhibits_keybinds != inhibit);
-
-       view->inhibits_keybinds = inhibit;
-       if (inhibit) {
+       assert(view);
+       view->inhibits_keybinds = !view->inhibits_keybinds;
+       if (view->inhibits_keybinds) {
                view->server->seat.nr_inhibited_keybind_views++;
        } else {
                view->server->seat.nr_inhibited_keybind_views--;
        }
 
        if (view->ssd_enabled) {
-               ssd_enable_keybind_inhibit_indicator(view->ssd, inhibit);
+               ssd_enable_keybind_inhibit_indicator(view->ssd,
+                       view->inhibits_keybinds);
        }
 }
 
-bool
-view_inhibits_keybinds(struct view *view)
-{
-       return view && view->inhibits_keybinds;
-}
-
-void
-view_toggle_keybinds(struct view *view)
-{
-       assert(view);
-       inhibit_keybinds(view, !view->inhibits_keybinds);
-}
-
 void
 view_destroy(struct view *view)
 {