mirror of
https://github.com/labwc/labwc.git
synced 2025-10-29 05:40:24 -04:00
view: fix some inconsistencies in view_ functions
... 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.
This commit is contained in:
parent
d00f76e562
commit
1f541be481
5 changed files with 27 additions and 33 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
42
src/view.c
42
src/view.c
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue