From 52f42194fd3cabe575efbab2b5d57b06d975544a Mon Sep 17 00:00:00 2001 From: Vaughan Milliman Date: Thu, 14 May 2026 17:20:18 -0500 Subject: [PATCH 1/4] lets see if ts works --- etc/iptsd.conf | 9 ++++++++ src/apps/daemon/daemon.hpp | 36 ++++++++++++++++++++++++++++---- src/apps/daemon/stylus.hpp | 14 +++++++++++++ src/core/generic/config.hpp | 1 + src/core/linux/config-loader.hpp | 1 + 5 files changed, 57 insertions(+), 4 deletions(-) diff --git a/etc/iptsd.conf b/etc/iptsd.conf index 140fb2b..4017441 100644 --- a/etc/iptsd.conf +++ b/etc/iptsd.conf @@ -24,6 +24,15 @@ ## # DisableOnStylus = false + +## +## What condition the stylus must be in to disable the touchscreen if DisableOnStylus = true +## connected - Disable if stylus is sending packets (old behavior and default) +## active - Disable if stylus is hovering or being used +## contact - Disable if stylus is in contact with the screen +## +# DisableOnStylusLevel = connected + ## ## How many centimeters a contact can be outside of the screen and still get registered. ## diff --git a/src/apps/daemon/daemon.hpp b/src/apps/daemon/daemon.hpp index 5a633fd..7cd6aca 100644 --- a/src/apps/daemon/daemon.hpp +++ b/src/apps/daemon/daemon.hpp @@ -20,6 +20,14 @@ namespace iptsd::apps::daemon { class Daemon : public core::Application { +private: + // Put this enum here as this class is the only one that needs to quickly reference it + enum DisableOnStylusLevel : u8 { + Connected = 0, + Active, + Contact, + }; + private: // The touch device. std::optional m_touch = std::nullopt; @@ -27,6 +35,9 @@ class Daemon : public core::Application { // The stylus device. std::optional m_stylus = std::nullopt; + // The state of the config setting Touchscreen.DisableOnStylusLevel + DisableOnStylusLevel m_disable_on_stylus_level = DisableOnStylusLevel::Connected; + public: Daemon(const core::Config &config, const core::DeviceInfo &info) : core::Application(config, info) @@ -40,6 +51,14 @@ class Daemon : public core::Application { if (m_info.is_touchscreen() && !m_config.stylus_disable) m_stylus.emplace(config, info); + + if (m_config.touchscreen_disable_on_stylus_level == "active") + m_disable_on_stylus_level = DisableOnStylusLevel::Active; + else if (m_config.touchscreen_disable_on_stylus_level == "contact") + m_disable_on_stylus_level = DisableOnStylusLevel::Contact; + else // catch nonexistent/invalid level as connected, which is the old behavior + m_disable_on_stylus_level = DisableOnStylusLevel::Connected; + } void on_start() override @@ -61,8 +80,14 @@ class Daemon : public core::Application { // Enable the touchscreen if it was disabled by a stylus that is no longer active. if (m_config.touchscreen_disable_on_stylus && m_stylus.has_value()) { - if (!m_stylus->active() && !m_touch->enabled()) - m_touch->enable(); + if ((m_disable_on_stylus_level == DisableOnStylusLevel::Active && !m_stylus->active()) || + (m_disable_on_stylus_level == DisableOnStylusLevel::Contact && !m_stylus->contact()) || + // stylus cant report a state after its disconnected (obviously), so just check if its active for reenabling after connection + // (this was the old behavior) + (m_disable_on_stylus_level == DisableOnStylusLevel::Connected && !m_stylus->active()) + ) + if (!m_touch->enabled()) + m_touch->enable(); } m_touch->update(contacts); @@ -82,8 +107,11 @@ class Daemon : public core::Application { return; if (m_config.touchscreen_disable_on_stylus && m_touch.has_value()) { - if (m_touch->enabled()) - m_touch->disable(); + if ((m_disable_on_stylus_level == DisableOnStylusLevel::Active && m_stylus->active()) || + (m_disable_on_stylus_level == DisableOnStylusLevel::Contact && m_stylus->contact()) + ) + if (m_touch->enabled()) + m_touch->disable(); } m_stylus->update(stylus); diff --git a/src/apps/daemon/stylus.hpp b/src/apps/daemon/stylus.hpp index 70ae415..1123034 100644 --- a/src/apps/daemon/stylus.hpp +++ b/src/apps/daemon/stylus.hpp @@ -36,6 +36,9 @@ class StylusDevice { // Whether the stylus is currently in proximity and sending data. bool m_active = false; + // Whether the stylus is making contact with the screen + bool m_contact = false; + // The last known state of the stylus. ipts::samples::Stylus m_last; @@ -82,6 +85,7 @@ class StylusDevice { void update(const ipts::samples::Stylus &data) { m_active = data.proximity; + m_contact = data.contact; // Switching tools within one frame causes issues, lift the stylus for one frame. if (m_last.rubber != data.rubber) @@ -156,6 +160,16 @@ class StylusDevice { return m_active; } + /*! + * Whether the stylus is currently making contact with the screen. + * + * @return true if, well, it speaks for itself. + */ + [[nodiscard]] bool contact() const + { + return m_contact; + } + private: /*! * Calculates the tilt of the stylus on X and Y axis. diff --git a/src/core/generic/config.hpp b/src/core/generic/config.hpp index f16553d..3fc2aa9 100644 --- a/src/core/generic/config.hpp +++ b/src/core/generic/config.hpp @@ -28,6 +28,7 @@ class Config { bool touchscreen_disable = false; bool touchscreen_disable_on_palm = false; bool touchscreen_disable_on_stylus = false; + std::string touchscreen_disable_on_stylus_level = "connected"; f64 touchscreen_overshoot = 0.5; // [Touchpad] diff --git a/src/core/linux/config-loader.hpp b/src/core/linux/config-loader.hpp index 8ffd944..abf8afc 100644 --- a/src/core/linux/config-loader.hpp +++ b/src/core/linux/config-loader.hpp @@ -155,6 +155,7 @@ class ConfigLoader { this->get(ini, "Touchscreen", "Disable", m_config.touchscreen_disable); this->get(ini, "Touchscreen", "DisableOnPalm", m_config.touchscreen_disable_on_palm); this->get(ini, "Touchscreen", "DisableOnStylus", m_config.touchscreen_disable_on_stylus); + this->get(ini, "Touchscreen", "DisableOnStylusLevel", m_config.touchscreen_disable_on_stylus_level); this->get(ini, "Touchscreen", "Overshoot", m_config.touchscreen_overshoot); this->get(ini, "Touchpad", "Disable", m_config.touchpad_disable); From 3a99adda365c25a3fc142f3dc9283f35495ee7ae Mon Sep 17 00:00:00 2001 From: Vaughan Milliman Date: Thu, 14 May 2026 17:41:22 -0500 Subject: [PATCH 2/4] forgot to disable screen when connected on default --- src/apps/daemon/daemon.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/apps/daemon/daemon.hpp b/src/apps/daemon/daemon.hpp index 7cd6aca..8e409a2 100644 --- a/src/apps/daemon/daemon.hpp +++ b/src/apps/daemon/daemon.hpp @@ -108,7 +108,8 @@ class Daemon : public core::Application { if (m_config.touchscreen_disable_on_stylus && m_touch.has_value()) { if ((m_disable_on_stylus_level == DisableOnStylusLevel::Active && m_stylus->active()) || - (m_disable_on_stylus_level == DisableOnStylusLevel::Contact && m_stylus->contact()) + (m_disable_on_stylus_level == DisableOnStylusLevel::Contact && m_stylus->contact()) || + (m_disable_on_stylus_level == DisableOnStylusLevel::Connected) ) if (m_touch->enabled()) m_touch->disable(); From 37851fc6b8192e4f11883798cc065d3e7e68070e Mon Sep 17 00:00:00 2001 From: Vaughan Milliman Date: Thu, 14 May 2026 17:45:06 -0500 Subject: [PATCH 3/4] clang format --- src/apps/daemon/daemon.hpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/apps/daemon/daemon.hpp b/src/apps/daemon/daemon.hpp index 8e409a2..778f53f 100644 --- a/src/apps/daemon/daemon.hpp +++ b/src/apps/daemon/daemon.hpp @@ -58,7 +58,6 @@ class Daemon : public core::Application { m_disable_on_stylus_level = DisableOnStylusLevel::Contact; else // catch nonexistent/invalid level as connected, which is the old behavior m_disable_on_stylus_level = DisableOnStylusLevel::Connected; - } void on_start() override @@ -80,12 +79,15 @@ class Daemon : public core::Application { // Enable the touchscreen if it was disabled by a stylus that is no longer active. if (m_config.touchscreen_disable_on_stylus && m_stylus.has_value()) { - if ((m_disable_on_stylus_level == DisableOnStylusLevel::Active && !m_stylus->active()) || - (m_disable_on_stylus_level == DisableOnStylusLevel::Contact && !m_stylus->contact()) || - // stylus cant report a state after its disconnected (obviously), so just check if its active for reenabling after connection - // (this was the old behavior) - (m_disable_on_stylus_level == DisableOnStylusLevel::Connected && !m_stylus->active()) - ) + if ((m_disable_on_stylus_level == DisableOnStylusLevel::Active && + !m_stylus->active()) || + (m_disable_on_stylus_level == DisableOnStylusLevel::Contact && + !m_stylus->contact()) || + // stylus cant report a state after its disconnected (obviously), so + // just check if its active for reenabling after connection (this was + // the old behavior) + (m_disable_on_stylus_level == DisableOnStylusLevel::Connected && + !m_stylus->active())) if (!m_touch->enabled()) m_touch->enable(); } @@ -107,10 +109,11 @@ class Daemon : public core::Application { return; if (m_config.touchscreen_disable_on_stylus && m_touch.has_value()) { - if ((m_disable_on_stylus_level == DisableOnStylusLevel::Active && m_stylus->active()) || - (m_disable_on_stylus_level == DisableOnStylusLevel::Contact && m_stylus->contact()) || - (m_disable_on_stylus_level == DisableOnStylusLevel::Connected) - ) + if ((m_disable_on_stylus_level == DisableOnStylusLevel::Active && + m_stylus->active()) || + (m_disable_on_stylus_level == DisableOnStylusLevel::Contact && + m_stylus->contact()) || + (m_disable_on_stylus_level == DisableOnStylusLevel::Connected)) if (m_touch->enabled()) m_touch->disable(); } From 6fea5bac6bdac248ab15a58aa5ff09da574ce148 Mon Sep 17 00:00:00 2001 From: Vaughan Milliman Date: Thu, 14 May 2026 19:19:25 -0500 Subject: [PATCH 4/4] fuck you clang tidy --- src/apps/daemon/daemon.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/daemon/daemon.hpp b/src/apps/daemon/daemon.hpp index 778f53f..a166c7a 100644 --- a/src/apps/daemon/daemon.hpp +++ b/src/apps/daemon/daemon.hpp @@ -22,7 +22,7 @@ namespace iptsd::apps::daemon { class Daemon : public core::Application { private: // Put this enum here as this class is the only one that needs to quickly reference it - enum DisableOnStylusLevel : u8 { + enum class DisableOnStylusLevel : u8 { Connected = 0, Active, Contact,