summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2022-04-02 19:09:27 +0200
committervaxerski <43317083+vaxerski@users.noreply.github.com>2022-04-02 19:09:27 +0200
commit7add082217b1e86f36bb152aec658eb5977622fa (patch)
treebf80981de454993f4b052588df2e7ec5cac7a77d /src
parent223beb8a826773e2e3ea4c6d7e7d40fde9247d9a (diff)
send focus change
Diffstat (limited to 'src')
-rw-r--r--src/Compositor.cpp7
-rw-r--r--src/helpers/MiscFunctions.cpp35
-rw-r--r--src/helpers/MiscFunctions.hpp3
3 files changed, 43 insertions, 2 deletions
diff --git a/src/Compositor.cpp b/src/Compositor.cpp
index 5fc00142..5f444fe8 100644
--- a/src/Compositor.cpp
+++ b/src/Compositor.cpp
@@ -388,6 +388,13 @@ void CCompositor::focusSurface(wlr_surface* pSurface, CWindow* pWindowOwner) {
wlr_seat_keyboard_notify_enter(m_sSeat.seat, pSurface, KEYBOARD->keycodes, KEYBOARD->num_keycodes, &KEYBOARD->modifiers);
+ wlr_seat_keyboard_focus_change_event event = {
+ .seat = m_sSeat.seat,
+ .old_surface = m_pLastFocus,
+ .new_surface = pSurface,
+ };
+ wlr_signal_emit_safe(&m_sSeat.seat->keyboard_state.events.focus_change, &event);
+
if (const auto PWINDOW = getWindowFromSurface(pSurface); PWINDOW)
Debug::log(LOG, "Set keyboard focus to surface %x, with window name: %s", pSurface, PWINDOW->m_szTitle.c_str());
else
diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp
index 484bbbfc..9974ab46 100644
--- a/src/helpers/MiscFunctions.cpp
+++ b/src/helpers/MiscFunctions.cpp
@@ -8,4 +8,37 @@ void addWLSignal(wl_signal* pSignal, wl_listener* pListener, void* pOwner, std::
wl_signal_add(pSignal, pListener);
Debug::log(LOG, "Registered signal for owner %x: %x -> %x (owner: %s)", pOwner, pSignal, pListener, ownerString.c_str());
-} \ No newline at end of file
+}
+
+void handleNoop(struct wl_listener *listener, void *data) {
+ // Do nothing
+}
+
+void wlr_signal_emit_safe(struct wl_signal *signal, void *data) {
+ struct wl_listener cursor;
+ struct wl_listener end;
+
+ /* Add two special markers: one cursor and one end marker. This way, we know
+ * that we've already called listeners on the left of the cursor and that we
+ * don't want to call listeners on the right of the end marker. The 'it'
+ * function can remove any element it wants from the list without troubles.
+ * wl_list_for_each_safe tries to be safe but it fails: it works fine
+ * if the current item is removed, but not if the next one is. */
+ wl_list_insert(&signal->listener_list, &cursor.link);
+ cursor.notify = handleNoop;
+ wl_list_insert(signal->listener_list.prev, &end.link);
+ end.notify = handleNoop;
+
+ while (cursor.link.next != &end.link) {
+ struct wl_list *pos = cursor.link.next;
+ struct wl_listener *l = wl_container_of(pos, l, link);
+
+ wl_list_remove(&cursor.link);
+ wl_list_insert(pos, &cursor.link);
+
+ l->notify(l, data);
+ }
+
+ wl_list_remove(&cursor.link);
+ wl_list_remove(&end.link);
+}
diff --git a/src/helpers/MiscFunctions.hpp b/src/helpers/MiscFunctions.hpp
index 0995aea7..acbd6d25 100644
--- a/src/helpers/MiscFunctions.hpp
+++ b/src/helpers/MiscFunctions.hpp
@@ -2,4 +2,5 @@
#include "../includes.hpp"
-void addWLSignal(wl_signal*, wl_listener*, void* pOwner, std::string ownerString); \ No newline at end of file
+void addWLSignal(wl_signal*, wl_listener*, void* pOwner, std::string ownerString);
+void wlr_signal_emit_safe(struct wl_signal *signal, void *data); \ No newline at end of file