Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion etc/iptsd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
# DisableOnPalm = false

##
## Ignore all touchscreen inputs if a stylus is in proximity.
## Ignore all touchscreen inputs on a chosen stylus condition
## default - Do not disable stylus
## connected/true - Disable if stylus is sending packets
## active - Disable if stylus is hovering or being used
## contact - Disable if stylus is in contact with the screen
##
# DisableOnStylus = false

Expand Down
48 changes: 42 additions & 6 deletions src/apps/daemon/daemon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,25 @@
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 class DisableOnStylus : u8 {
Off = 0,
Connected,
Active,
Contact,
};

private:
// The touch device.
std::optional<TouchDevice> m_touch = std::nullopt;

// The stylus device.
std::optional<StylusDevice> m_stylus = std::nullopt;

// The state of the config setting Touchscreen.DisableOnStylus
DisableOnStylus m_disable_on_stylus = DisableOnStylus::Connected;

public:
Daemon(const core::Config &config, const core::DeviceInfo &info)
: core::Application(config, info)
Expand All @@ -40,6 +52,16 @@ 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 == "active")
m_disable_on_stylus = DisableOnStylus::Active;
else if (m_config.touchscreen_disable_on_stylus == "contact")
m_disable_on_stylus = DisableOnStylus::Contact;
else if (m_config.touchscreen_disable_on_stylus == "true" ||
m_config.touchscreen_disable_on_stylus == "connected")
m_disable_on_stylus = DisableOnStylus::Connected;
else
m_disable_on_stylus = DisableOnStylus::Off;
}

void on_start() override
Expand All @@ -60,9 +82,18 @@ class Daemon : public core::Application {
return;

// 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 != DisableOnStylus::Off && m_stylus.has_value()) {
if ((m_disable_on_stylus == DisableOnStylus::Active &&
!m_stylus->active()) ||
(m_disable_on_stylus == DisableOnStylus::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 == DisableOnStylus::Connected &&
!m_stylus->active()))
if (!m_touch->enabled())
m_touch->enable();
}

m_touch->update(contacts);
Expand All @@ -81,9 +112,14 @@ class Daemon : public core::Application {
if (!m_stylus.has_value())
return;

if (m_config.touchscreen_disable_on_stylus && m_touch.has_value()) {
if (m_touch->enabled())
m_touch->disable();
if (m_disable_on_stylus != DisableOnStylus::Off && m_touch.has_value()) {
if ((m_disable_on_stylus == DisableOnStylus::Active &&
m_stylus->active()) ||
(m_disable_on_stylus == DisableOnStylus::Contact &&
m_stylus->contact()) ||
(m_disable_on_stylus == DisableOnStylus::Connected))
if (m_touch->enabled())
m_touch->disable();
}

m_stylus->update(stylus);
Expand Down
18 changes: 17 additions & 1 deletion src/apps/daemon/stylus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -106,6 +109,8 @@ class StylusDevice {

m_uinput->emit(EV_ABS, ABS_TILT_X, tilt.x());
m_uinput->emit(EV_ABS, ABS_TILT_Y, tilt.y());

m_contact = data.contact;
} else {
this->lift();
}
Expand Down Expand Up @@ -156,6 +161,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.
Expand Down Expand Up @@ -187,8 +202,9 @@ class StylusDevice {
/*!
* Lifts the stylus input.
*/
void lift() const
void lift()
{
m_contact = false;
m_uinput->emit(EV_KEY, BTN_TOUCH, 0);
m_uinput->emit(EV_KEY, BTN_TOOL_PEN, 0);
m_uinput->emit(EV_KEY, BTN_TOOL_RUBBER, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/core/generic/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Config {
// [Touchscreen]
bool touchscreen_disable = false;
bool touchscreen_disable_on_palm = false;
bool touchscreen_disable_on_stylus = false;
std::string touchscreen_disable_on_stylus = "false";
f64 touchscreen_overshoot = 0.5;

// [Touchpad]
Expand Down