@@ -21,57 +21,63 @@ namespace iptsd::apps::daemon {
21
21
class Daemon : public core ::Application {
22
22
private:
23
23
// The touch device.
24
- TouchDevice m_touch;
24
+ std::optional< TouchDevice> m_touch = std::nullopt ;
25
25
26
26
// The stylus device.
27
- StylusDevice m_stylus;
27
+ std::optional< StylusDevice> m_stylus = std::nullopt ;
28
28
29
29
public:
30
30
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
+ }
34
43
35
44
void on_start () override
36
45
{
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 ())
41
47
spdlog::warn (" Touchscreen is disabled!" );
42
48
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 ())
44
53
spdlog::warn (" Stylus is disabled!" );
45
54
}
46
55
47
56
void on_touch (const std::vector<contacts::Contact<f64>> &contacts) override
48
57
{
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 ())
53
59
return ;
54
60
55
61
// 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 ();
59
65
}
60
66
61
- m_touch. update (contacts);
67
+ m_touch-> update (contacts);
62
68
}
63
69
64
70
void on_stylus (const ipts::samples::Stylus &stylus) override
65
71
{
66
- if (m_config. stylus_disable )
72
+ if (!m_stylus. has_value () )
67
73
return ;
68
74
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 ();
72
78
}
73
79
74
- m_stylus. update (stylus);
80
+ m_stylus-> update (stylus);
75
81
}
76
82
};
77
83
0 commit comments