Skip to content

Commit

Permalink
view-impl: fix handling of the focusable flag
Browse files Browse the repository at this point in the history
Fixes #2007
  • Loading branch information
ammen99 committed Nov 23, 2023
1 parent 503fc7d commit 42c73bd
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/view/layer-shell/layer-shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class wayfire_layer_shell_view : public wf::view_interface_t
std::string app_id;
friend class wf::tracking_allocator_t<view_interface_t>;
wayfire_layer_shell_view(wlr_layer_surface_v1 *lsurf);
bool keyboard_focus_enabled = true;

public:
wlr_layer_surface_v1 *lsurface;
Expand Down Expand Up @@ -110,7 +111,7 @@ class wayfire_layer_shell_view : public wf::view_interface_t

wlr_surface *get_keyboard_focus_surface() override
{
if (is_mapped() && priv->keyboard_focus_enabled)
if (is_mapped() && keyboard_focus_enabled)
{
return priv->wsurface;
}
Expand Down Expand Up @@ -502,7 +503,7 @@ void wayfire_layer_shell_view::map()
on_surface_commit.connect(&lsurface->surface->events.commit);

/* Read initial data */
priv->keyboard_focus_enabled = lsurface->current.keyboard_interactive;
keyboard_focus_enabled = lsurface->current.keyboard_interactive;

wf::scene::add_front(get_output()->node_for_layer(get_layer()), get_root_node());
wf_layer_shell_manager::get_instance().handle_map(this);
Expand Down Expand Up @@ -544,7 +545,7 @@ void wayfire_layer_shell_view::commit()
auto state = &lsurface->current;
/* Update the keyboard focus enabled state. If a refocusing is needed, i.e
* the view state changed, then this will happen when arranging layers */
priv->keyboard_focus_enabled = state->keyboard_interactive;
keyboard_focus_enabled = state->keyboard_interactive;

if (state->committed)
{
Expand Down
8 changes: 3 additions & 5 deletions src/view/view-impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ namespace wf
class view_interface_t::view_priv_impl
{
public:
wlr_surface *wsurface = nullptr;
size_t last_view_cnt = 0;

bool keyboard_focus_enabled = true;
uint32_t allowed_actions = VIEW_ALLOW_ALL;
wlr_surface *wsurface = nullptr;
size_t last_view_cnt = 0;
uint32_t allowed_actions = VIEW_ALLOW_ALL;

uint32_t edges = 0;
wlr_box minimize_hint = {0, 0, 0, 0};
Expand Down
2 changes: 1 addition & 1 deletion src/view/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ wlr_box wf::view_interface_t::get_bounding_box()

bool wf::view_interface_t::is_focusable() const
{
return priv->keyboard_focus_enabled;
return true;
}

void wf::view_interface_t::damage()
Expand Down
6 changes: 5 additions & 1 deletion src/view/xdg-shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ wayfire_xdg_popup::wayfire_xdg_popup(wlr_xdg_popup *popup) : wf::view_interface_
this->popup_parent = wf::wl_surface_to_wayfire_view(popup->parent->resource).get();
this->popup = popup;
this->role = wf::VIEW_ROLE_UNMANAGED;
this->priv->keyboard_focus_enabled = false;

if (!dynamic_cast<wayfire_xdg_popup*>(popup_parent.get()))
{
Expand Down Expand Up @@ -374,3 +373,8 @@ void wf::init_xdg_shell()
on_xdg_created.connect(&xdg_handle->events.new_surface);
}
}

bool wayfire_xdg_popup::is_focusable() const
{
return false;
}
2 changes: 2 additions & 0 deletions src/view/xdg-shell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class wayfire_xdg_popup : public wf::view_interface_t
std::string get_app_id() override final;
std::string get_title() override final;

bool is_focusable() const override final;

void move(int x, int y);
wf::geometry_t get_geometry();
virtual wlr_surface *get_keyboard_focus_surface() override;
Expand Down
4 changes: 2 additions & 2 deletions src/view/xwayland/xwayland-unmanaged-view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ class wayfire_unmanaged_xwayland_view : public wayfire_xwayland_view_internal_ba
* plugins can detect that this view can have keyboard focus.
*
* Note: only actual override-redirect views should get their focus disabled */
priv->keyboard_focus_enabled = (!xw->override_redirect ||
kb_focus_enabled = (!xw->override_redirect ||
wlr_xwayland_or_surface_wants_focus(xw));

wf::scene::readd_front(get_output()->node_for_layer(wf::scene::layer::UNMANAGED), get_root_node());

if (priv->keyboard_focus_enabled)
if (kb_focus_enabled)
{
wf::get_core().default_wm->focus_request(self());
}
Expand Down

0 comments on commit 42c73bd

Please sign in to comment.