mirror of
https://github.com/labwc/labwc.git
synced 2025-10-31 22:25:34 -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);
|
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
|
* @view: view to be checked
|
||||||
*
|
*
|
||||||
* The purpose of this test is to filter out views (generally Xwayland) which
|
* 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
|
* The only views that are allowed to be focusd are those that have a surface
|
||||||
* and have been mapped at some point since creation.
|
* 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_toggle_keybinds(struct view *view);
|
||||||
|
|
||||||
void view_set_activated(struct view *view, bool activated);
|
void view_set_activated(struct view *view, bool activated);
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ first_view(struct server *server)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
struct view *view = node_view_from_node(node);
|
struct view *view = node_view_from_node(node);
|
||||||
if (view_isfocusable(view)) {
|
if (view_is_focusable(view)) {
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -186,7 +186,7 @@ desktop_cycle_view(struct server *server, struct view *start_view,
|
||||||
view = node_view_from_node(node);
|
view = node_view_from_node(node);
|
||||||
|
|
||||||
enum property skip = window_rules_get_property(view, "skipWindowSwitcher");
|
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;
|
return view;
|
||||||
}
|
}
|
||||||
} while (view != start_view);
|
} while (view != start_view);
|
||||||
|
|
@ -208,7 +208,7 @@ desktop_topmost_focusable_view(struct server *server)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
view = node_view_from_node(node);
|
view = node_view_from_node(node);
|
||||||
if (view->mapped && view_isfocusable(view)) {
|
if (view->mapped && view_is_focusable(view)) {
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -247,7 +247,7 @@ desktop_focus_output(struct output *output)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
view = node_view_from_node(node);
|
view = node_view_from_node(node);
|
||||||
if (!view_isfocusable(view)) {
|
if (!view_is_focusable(view)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (wlr_output_layout_intersects(layout,
|
if (wlr_output_layout_intersects(layout,
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,8 @@ handle_keybinding(struct server *server, uint32_t modifiers, xkb_keysym_t sym, x
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (server->seat.nr_inhibited_keybind_views
|
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)) {
|
&& !actions_contain_toggle_keybinds(&keybind->actions)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -479,7 +479,7 @@ osd_update(struct server *server)
|
||||||
|
|
||||||
/* Outline current window */
|
/* Outline current window */
|
||||||
if (rc.window_switcher.outlines) {
|
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);
|
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
|
static bool
|
||||||
matches_criteria(struct view *view, enum lab_view_criteria criteria)
|
matches_criteria(struct view *view, enum lab_view_criteria criteria)
|
||||||
{
|
{
|
||||||
if (!view_isfocusable(view)) {
|
if (!view_is_focusable(view)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (criteria & LAB_VIEW_CRITERIA_CURRENT_WORKSPACE) {
|
if (criteria & LAB_VIEW_CRITERIA_CURRENT_WORKSPACE) {
|
||||||
|
|
@ -144,8 +144,9 @@ view_array_append(struct server *server, struct wl_array *views,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
view_isfocusable(struct view *view)
|
view_is_focusable(struct view *view)
|
||||||
{
|
{
|
||||||
|
assert(view);
|
||||||
if (!view->surface) {
|
if (!view->surface) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -322,6 +323,7 @@ view_move_resize(struct view *view, struct wlr_box geo)
|
||||||
void
|
void
|
||||||
view_resize_relative(struct view *view, int left, int right, int top, int bottom)
|
view_resize_relative(struct view *view, int left, int right, int top, int bottom)
|
||||||
{
|
{
|
||||||
|
assert(view);
|
||||||
if (view->fullscreen || view->maximized) {
|
if (view->fullscreen || view->maximized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -337,6 +339,7 @@ view_resize_relative(struct view *view, int left, int right, int top, int bottom
|
||||||
void
|
void
|
||||||
view_move_relative(struct view *view, int x, int y)
|
view_move_relative(struct view *view, int x, int y)
|
||||||
{
|
{
|
||||||
|
assert(view);
|
||||||
if (view->fullscreen) {
|
if (view->fullscreen) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -351,6 +354,7 @@ view_move_relative(struct view *view, int x, int y)
|
||||||
struct view_size_hints
|
struct view_size_hints
|
||||||
view_get_size_hints(struct view *view)
|
view_get_size_hints(struct view *view)
|
||||||
{
|
{
|
||||||
|
assert(view);
|
||||||
if (view->impl->get_size_hints) {
|
if (view->impl->get_size_hints) {
|
||||||
return view->impl->get_size_hints(view);
|
return view->impl->get_size_hints(view);
|
||||||
}
|
}
|
||||||
|
|
@ -458,6 +462,7 @@ minimize_sub_views(struct view *view, bool minimized)
|
||||||
void
|
void
|
||||||
view_minimize(struct view *view, bool minimized)
|
view_minimize(struct view *view, bool minimized)
|
||||||
{
|
{
|
||||||
|
assert(view);
|
||||||
/*
|
/*
|
||||||
* Minimize the root window first because some xwayland clients send a
|
* Minimize the root window first because some xwayland clients send a
|
||||||
* request-unmap to sub-windows at this point (for example gimp and its
|
* 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
|
bool
|
||||||
view_is_tiled(struct view *view)
|
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);
|
|| view->tiled_region_evacuate);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
view_is_floating(struct view *view)
|
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);
|
|| view->tiled_region || view->tiled_region_evacuate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1323,36 +1330,23 @@ view_reload_ssd(struct view *view)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
inhibit_keybinds(struct view *view, bool inhibit)
|
view_toggle_keybinds(struct view *view)
|
||||||
{
|
{
|
||||||
assert(view->inhibits_keybinds != inhibit);
|
assert(view);
|
||||||
|
view->inhibits_keybinds = !view->inhibits_keybinds;
|
||||||
view->inhibits_keybinds = inhibit;
|
if (view->inhibits_keybinds) {
|
||||||
if (inhibit) {
|
|
||||||
view->server->seat.nr_inhibited_keybind_views++;
|
view->server->seat.nr_inhibited_keybind_views++;
|
||||||
} else {
|
} else {
|
||||||
view->server->seat.nr_inhibited_keybind_views--;
|
view->server->seat.nr_inhibited_keybind_views--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (view->ssd_enabled) {
|
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
|
void
|
||||||
view_destroy(struct view *view)
|
view_destroy(struct view *view)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue