Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Add option to focus a view on mouse click even if modifiers are pressed #896

Merged
merged 3 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_btn_mod" type="bool">
dkondor marked this conversation as resolved.
Show resolved Hide resolved
<_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_btns" type="activator">
dkondor marked this conversation as resolved.
Show resolved Hide resolved
<_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;
}

dkondor marked this conversation as resolved.
Show resolved Hide resolved
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_btn_mod"};
wf::option_wrapper_t<wf::activatorbinding_t> focus_btns{"core/focus_btns"};

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