Skip to content

Commit

Permalink
Always focus on click
Browse files Browse the repository at this point in the history
  • Loading branch information
dkondor committed Nov 24, 2020
1 parent 87d9e5b commit 8f6cc10
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
15 changes: 15 additions & 0 deletions metadata/core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,20 @@
<_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>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_btn_middle" type="bool">
<_short>Focus on click with middle mouse button</_short>
<_long>Allow focusing the clicked view with the middle mouse button.</_long>
<default>false</default>
</option>
<option name="focus_btn_right" type="bool">
<_short>Focus on click with right mouse button</_short>
<_long>Allow focusing the clicked view with the right mouse button.</_long>
<default>false</default>
</option>
</plugin>
</wayfire>
26 changes: 20 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,26 @@ 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;
}

if ((!focus_modifiers && wf::get_core().get_keyboard_modifiers()) ||
((ev->event->button == BTN_MIDDLE) && !focus_btn_middle) ||
((ev->event->button == BTN_RIGHT) && !focus_btn_right))
{
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
7 changes: 6 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,16 @@ 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_btn_mod"};
wf::option_wrapper_t<bool> focus_btn_middle{"core/focus_btn_middle"};
wf::option_wrapper_t<bool> focus_btn_right{"core/focus_btn_right"};

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

0 comments on commit 8f6cc10

Please sign in to comment.