Skip to content

Commit 8e5b3f8

Browse files
committed
apps: daemon: Only create devices that are required
We don't need a stylus device for touchpads. And disabling a device through the config now hides it instead of making it do nothing.
1 parent 2729d18 commit 8e5b3f8

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

src/apps/daemon/daemon.hpp

+29-23
Original file line numberDiff line numberDiff line change
@@ -21,57 +21,63 @@ namespace iptsd::apps::daemon {
2121
class Daemon : public core::Application {
2222
private:
2323
// The touch device.
24-
TouchDevice m_touch;
24+
std::optional<TouchDevice> m_touch = std::nullopt;
2525

2626
// The stylus device.
27-
StylusDevice m_stylus;
27+
std::optional<StylusDevice> m_stylus = std::nullopt;
2828

2929
public:
3030
Daemon(const core::Config &config, const core::DeviceInfo &info)
31-
: core::Application(config, info),
32-
m_touch {config, info},
33-
m_stylus {config, info} {};
31+
: core::Application(config, info)
32+
{
33+
const bool create_touch =
34+
(m_info.is_touchscreen() && !m_config.touchscreen_disable) ||
35+
(m_info.is_touchpad() && !m_config.touchpad_disable);
36+
37+
if (create_touch)
38+
m_touch.emplace(config, info);
39+
40+
if (m_info.is_touchscreen() && !m_config.touchscreen_disable)
41+
m_stylus.emplace(config, info);
42+
}
3443

3544
void on_start() override
3645
{
37-
if (m_config.touchpad_disable && m_info.is_touchpad())
38-
spdlog::warn("Touchpad is disabled!");
39-
40-
if (m_config.touchscreen_disable && m_info.is_touchscreen())
46+
if (!m_touch.has_value() && m_info.is_touchscreen())
4147
spdlog::warn("Touchscreen is disabled!");
4248

43-
if (m_config.stylus_disable && m_info.is_touchpad())
49+
if (!m_touch.has_value() && m_info.is_touchpad())
50+
spdlog::warn("Touchpad is disabled!");
51+
52+
if (!m_stylus.has_value())
4453
spdlog::warn("Stylus is disabled!");
4554
}
4655

4756
void on_touch(const std::vector<contacts::Contact<f64>> &contacts) override
4857
{
49-
if (m_config.touchpad_disable && m_info.is_touchpad())
50-
return;
51-
52-
if (m_config.touchscreen_disable && m_info.is_touchscreen())
58+
if (!m_touch.has_value())
5359
return;
5460

5561
// Enable the touchscreen if it was disabled by a stylus that is no longer active.
56-
if (m_config.touchscreen_disable_on_stylus && m_info.is_touchscreen()) {
57-
if (!m_stylus.active() && !m_touch.enabled())
58-
m_touch.enable();
62+
if (m_config.touchscreen_disable_on_stylus && m_stylus.has_value()) {
63+
if (!m_stylus->active() && !m_touch->enabled())
64+
m_touch->enable();
5965
}
6066

61-
m_touch.update(contacts);
67+
m_touch->update(contacts);
6268
}
6369

6470
void on_stylus(const ipts::samples::Stylus &stylus) override
6571
{
66-
if (m_config.stylus_disable)
72+
if (!m_stylus.has_value())
6773
return;
6874

69-
if (m_config.touchscreen_disable_on_stylus && m_info.is_touchscreen()) {
70-
if (m_touch.enabled())
71-
m_touch.disable();
75+
if (m_config.touchscreen_disable_on_stylus && m_touch.has_value()) {
76+
if (m_touch->enabled())
77+
m_touch->disable();
7278
}
7379

74-
m_stylus.update(stylus);
80+
m_stylus->update(stylus);
7581
}
7682
};
7783

0 commit comments

Comments
 (0)