From 8f6cc108942979bcabaac21435bfaa8004d955e4 Mon Sep 17 00:00:00 2001 From: Daniel Kondor Date: Tue, 24 Nov 2020 10:05:57 +0800 Subject: [PATCH 1/3] Always focus on click --- metadata/core.xml | 15 +++++++++++++++ src/core/wm.cpp | 26 ++++++++++++++++++++------ src/core/wm.hpp | 7 ++++++- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/metadata/core.xml b/metadata/core.xml index 5e409c5e2..a99c25d2b 100644 --- a/metadata/core.xml +++ b/metadata/core.xml @@ -53,5 +53,20 @@ <_long>Sets the compositor render delay in milliseconds, which allows applications to render with low latency. -1 + + + diff --git a/src/core/wm.cpp b/src/core/wm.cpp index 2e56d42fe..cdb9b4c5e 100644 --- a/src/core/wm.cpp +++ b/src/core/wm.cpp @@ -11,6 +11,8 @@ #include "../output/output-impl.hpp" #include "wayfire/signal-definitions.hpp" +#include + static void idle_shutdown(void *data) { wf::get_core().shutdown(); @@ -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*>(data); - return false; - }; - output->add_button( - wf::create_option_string("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(1, true); diff --git a/src/core/wm.hpp b/src/core/wm.hpp index bd7a840f6..780f58d69 100644 --- a/src/core/wm.hpp +++ b/src/core/wm.hpp @@ -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 { @@ -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 tap_gesture; void check_focus_surface(wf::surface_interface_t *surface); + wf::option_wrapper_t focus_modifiers{"core/focus_btn_mod"}; + wf::option_wrapper_t focus_btn_middle{"core/focus_btn_middle"}; + wf::option_wrapper_t focus_btn_right{"core/focus_btn_right"}; + public: void init() override; void fini() override; From f5b39fff62c0d1a06977c013e5de553ae5852c96 Mon Sep 17 00:00:00 2001 From: Daniel Kondor Date: Tue, 24 Nov 2020 17:56:15 +0800 Subject: [PATCH 2/3] More flexible option on which buttons should focus a view on click --- metadata/core.xml | 13 ++++--------- src/core/wm.cpp | 5 +++-- src/core/wm.hpp | 3 +-- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/metadata/core.xml b/metadata/core.xml index a99c25d2b..c995728f0 100644 --- a/metadata/core.xml +++ b/metadata/core.xml @@ -58,15 +58,10 @@ <_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. false - - diff --git a/src/core/wm.cpp b/src/core/wm.cpp index cdb9b4c5e..caa56961b 100644 --- a/src/core/wm.cpp +++ b/src/core/wm.cpp @@ -121,9 +121,10 @@ void wayfire_focus::init() return; } + /* focuse_btns->get_value() does not compile */ + wf::option_sptr_t tmp = focus_btns; 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)) + !tmp->get_value().has_match(wf::buttonbinding_t(0, ev->event->button))) { return; } diff --git a/src/core/wm.hpp b/src/core/wm.hpp index 780f58d69..2ce4c99a4 100644 --- a/src/core/wm.hpp +++ b/src/core/wm.hpp @@ -30,8 +30,7 @@ class wayfire_focus : public wf::plugin_interface_t void check_focus_surface(wf::surface_interface_t *surface); wf::option_wrapper_t focus_modifiers{"core/focus_btn_mod"}; - wf::option_wrapper_t focus_btn_middle{"core/focus_btn_middle"}; - wf::option_wrapper_t focus_btn_right{"core/focus_btn_right"}; + wf::option_wrapper_t focus_btns{"core/focus_btns"}; public: void init() override; From 5189c0bdc721313292a7df765c45cfdbc8484b20 Mon Sep 17 00:00:00 2001 From: Daniel Kondor Date: Wed, 25 Nov 2020 23:35:26 +0800 Subject: [PATCH 3/3] Adjust names of settings --- metadata/core.xml | 4 ++-- src/core/wm.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/metadata/core.xml b/metadata/core.xml index c995728f0..0cf1fbc0e 100644 --- a/metadata/core.xml +++ b/metadata/core.xml @@ -53,12 +53,12 @@ <_long>Sets the compositor render delay in milliseconds, which allows applications to render with low latency. -1 - -