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 (#896)

* Always focus on click

* More flexible option on which buttons should focus a view on click

* Adjust names of settings
  • Loading branch information
dkondor authored Nov 25, 2020
1 parent af2065b commit c180c29
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
10 changes: 10 additions & 0 deletions metadata/core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,15 @@
<_long>Sets the compositor render delay in milliseconds, which allows applications to render with low latency.</_long>
<default>-1</default>
</option>
<option name="focus_button_with_modifiers" type="bool">
<_short>Focus on click if keyboard modifiers are pressed</_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>
<option name="focus_buttons" type="activator">
<_short>Mouse buttons to focus views</_short>
<_long>Clicking on a view with any of the mouse buttons of these will focus it.</_long>
<default>BTN_LEFT | BTN_MIDDLE | BTN_RIGHT</default>
</option>
</plugin>
</wayfire>
27 changes: 21 additions & 6 deletions src/core/wm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "../output/output-impl.hpp"
#include "wayfire/signal-definitions.hpp"

#include <linux/input-event-codes.h>

static void idle_shutdown(void *data)
{
wf::get_core().shutdown();
Expand Down Expand Up @@ -109,14 +111,27 @@ void wayfire_focus::init()
};
output->connect_signal("wm-focus-request", &on_wm_focus_request);

on_button = [=] (const wf::buttonbinding_t&)
on_button.set_callback([=] (wf::signal_data_t *data)
{
this->check_focus_surface(wf::get_core().get_cursor_focus());
auto ev = static_cast<
wf::input_event_signal<wlr_event_pointer_button>*>(data);

return false;
};
output->add_button(
wf::create_option_string<wf::buttonbinding_t>("BTN_LEFT"), &on_button);
if (ev->event->state != WLR_BUTTON_PRESSED)
{
return;
}

/* focuse_btns->get_value() does not compile */
wf::option_sptr_t<wf::activatorbinding_t> tmp = focus_btns;
if ((!focus_modifiers && wf::get_core().get_keyboard_modifiers()) ||
!tmp->get_value().has_match(wf::buttonbinding_t(0, ev->event->button)))
{
return;
}

this->check_focus_surface(wf::get_core().get_cursor_focus());
});
wf::get_core().connect_signal("pointer_button", &on_button);

// build touch gesture
auto on_tap = std::make_unique<wf::touch::touch_action_t>(1, true);
Expand Down
6 changes: 5 additions & 1 deletion src/core/wm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "wayfire/bindings.hpp"
#include "wayfire/view.hpp"
#include "wayfire/touch/touch.hpp"
#include "wayfire/option-wrapper.hpp"

struct wm_focus_request : public wf::signal_data_t
{
Expand All @@ -22,12 +23,15 @@ class wayfire_close : public wf::plugin_interface_t

class wayfire_focus : public wf::plugin_interface_t
{
wf::button_callback on_button;
wf::signal_connection_t on_button;
wf::signal_callback_t on_wm_focus_request;

std::unique_ptr<wf::touch::gesture_t> tap_gesture;
void check_focus_surface(wf::surface_interface_t *surface);

wf::option_wrapper_t<bool> focus_modifiers{"core/focus_button_with_modifiers"};
wf::option_wrapper_t<wf::activatorbinding_t> focus_btns{"core/focus_buttons"};

public:
void init() override;
void fini() override;
Expand Down

0 comments on commit c180c29

Please sign in to comment.