From 03a5047c495b9c029c59f5cdf9817d2e01f4e770 Mon Sep 17 00:00:00 2001
From: Dmitry Sapozhnikov <11535558+o-sdn-o@users.noreply.github.com>
Date: Thu, 7 Nov 2024 16:52:58 +0500
Subject: [PATCH] #86 WIP: Fix exclusive keyboard mode
---
src/netxs/desktopio/gui.hpp | 21 ++++++++++++++-------
src/netxs/desktopio/input.hpp | 6 +++++-
2 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/src/netxs/desktopio/gui.hpp b/src/netxs/desktopio/gui.hpp
index 7ccde04f9..168509e79 100644
--- a/src/netxs/desktopio/gui.hpp
+++ b/src/netxs/desktopio/gui.hpp
@@ -1807,14 +1807,21 @@ namespace netxs::gui
void handle(s11n::xs::focus_set lock)
{
auto& item = lock.thing;
- if (owner.mfocus.focused()) // We are the focus tree endpoint. Signal back the focus set up.
+ if (item.solo < 0) // Exclusive keyboard mode: -1: set, -2: reset.
{
- auto seed = owner.bell::signal(tier::release, hids::events::keybd::focus::bus::on, { .id = item.gear_id, .solo = item.solo, .item = owner.This() });
+ gears->set_exclusive(item.solo == -1 ? owner.This() : netxs::sptr{}); // Exclusive mode will be reset automatically when focus is changed.
}
- else owner.window_post_command(ipc::take_focus);
- if (item.solo == ui::pro::focus::solo::on) // Set solo focus.
+ else
{
- owner.window_post_command(ipc::solo_focus);
+ if (owner.mfocus.focused()) // We are the focus tree endpoint. Signal back the focus set up.
+ {
+ auto seed = owner.bell::signal(tier::release, hids::events::keybd::focus::bus::on, { .id = item.gear_id, .solo = item.solo, .item = owner.This() });
+ }
+ else owner.window_post_command(ipc::take_focus);
+ if (item.solo == ui::pro::focus::solo::on) // Set solo focus.
+ {
+ owner.window_post_command(ipc::solo_focus);
+ }
}
}
void handle(s11n::xs::syskeybd lock)
@@ -2838,7 +2845,7 @@ namespace netxs::gui
{
keybd_send_block(block); // Send multifocus events.
}
- return wkeybd.filter(gear);
+ return gear.is_exclusive() || wkeybd.filter(gear);
});
}
void keybd_send_state(si32 virtcod = {}, si32 keystat = {}, si32 scancod = {}, bool extflag = {}, view cluster = {}, bool synth = faux)
@@ -3060,7 +3067,7 @@ namespace netxs::gui
stream.m.ctlstat = keymod;
keybd.syncto(gear);
gear.gear_id = gear.bell::id; // Restore gear id.
- if (wkeybd.filter(gear))
+ if (gear.is_exclusive() || wkeybd.filter(gear))
{
stream.keybd(gear);
}
diff --git a/src/netxs/desktopio/input.hpp b/src/netxs/desktopio/input.hpp
index 79c278487..733a643ea 100644
--- a/src/netxs/desktopio/input.hpp
+++ b/src/netxs/desktopio/input.hpp
@@ -1965,10 +1965,14 @@ namespace netxs::input
if (m_sav.changed != m_sys.changed) m_sav = m_sys;
return !alive;
}
+ auto is_exclusive()
+ {
+ return !ptr::is_empty(exclusive_wptr);
+ }
void fire_keybd()
{
alive = true;
- if (!ptr::is_empty(exclusive_wptr))
+ if (is_exclusive())
if (auto target = exclusive_wptr.lock())
{
target->bell::signal(tier::preview, hids::events::keybd::key::post, *this);