Skip to content

Commit

Permalink
core: Add option to focus a view on mouse click even if modifiers are…
Browse files Browse the repository at this point in the history
… pressed

Also, make click-to-focus to work with all mouse buttons (note: this part cannot be changed with an option).

Handling of click-to-focus moved from core/wm.cpp to core/seat/pointer.cpp
  • Loading branch information
dkondor committed Nov 23, 2020
1 parent 87d9e5b commit 95483cc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
5 changes: 5 additions & 0 deletions metadata/core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,10 @@
<_long>Sets the compositor render delay in milliseconds, which allows applications to render with low latency.</_long>
<default>-1</default>
</option>
<option name="focus_btn_mod" type="bool">
<_short>Click to focus with with modifiers</_short>
<_long>Allow focusing the clicked view even if keyboard modifiers are pressed. Without this option, click-to-focus only works if no modifiers are pressed.</_long>
<default>false</default>
</option>
</plugin>
</wayfire>
16 changes: 16 additions & 0 deletions src/core/seat/pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,22 @@ void wf::pointer_t::send_button(wlr_event_pointer_button *ev, bool has_binding)
return;
}

/* Change focus if needed */
if (cursor_focus && (ev->state == WLR_BUTTON_PRESSED))
{
if (btn_focus_modifiers || !seat->get_modifiers())
{
auto main_surface = cursor_focus->get_main_surface();
auto view = dynamic_cast<wf::view_interface_t*>(main_surface);
/* condition takes from wm.cpp -- not sure if view->is_mapped() can be
* false here */
if (view && view->is_mapped() && view->get_keyboard_focus_surface())
{
view->get_output()->focus_view(view->self(), true);
}
}
}

auto custom = compositor_surface_from_surface(cursor_focus);
if (custom)
{
Expand Down
3 changes: 3 additions & 0 deletions src/core/seat/pointer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class pointer_t
int focus_enabled_count = 1;
bool focus_enabled() const;

/** Whether click-to-focus works if modifiers are pressed */
wf::option_wrapper_t<bool> btn_focus_modifiers{"core/focus_btn_mod"};

/**
* Set the pointer focus.
*
Expand Down
9 changes: 0 additions & 9 deletions src/core/wm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,6 @@ void wayfire_focus::init()
};
output->connect_signal("wm-focus-request", &on_wm_focus_request);

on_button = [=] (const wf::buttonbinding_t&)
{
this->check_focus_surface(wf::get_core().get_cursor_focus());

return false;
};
output->add_button(
wf::create_option_string<wf::buttonbinding_t>("BTN_LEFT"), &on_button);

// build touch gesture
auto on_tap = std::make_unique<wf::touch::touch_action_t>(1, true);
std::vector<std::unique_ptr<wf::touch::gesture_action_t>> actions;
Expand Down

0 comments on commit 95483cc

Please sign in to comment.