Deskflow 1.22.0.197
Keyboard and mouse sharing utility
Loading...
Searching...
No Matches
XWindowsScreenSaver.h
Go to the documentation of this file.
1/*
2 * Deskflow -- mouse and keyboard sharing utility
3 * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
4 * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
5 * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
6 * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
7 */
8
9#pragma once
10
11#include "base/IEventQueue.h"
13
14#include <map>
15
16#include <X11/Xlib.h>
17
18class Event;
19class EventQueueTimer;
20
23{
24public:
25 XWindowsScreenSaver(Display *, Window, void *eventTarget, IEventQueue *events);
28 ~XWindowsScreenSaver() override;
29
32
34
35
37
41 bool handleXEvent(const XEvent *);
42
44
48 void destroy();
49
51
52 // IScreenSaver overrides
53 void enable() override;
54 void disable() override;
55 void activate() override;
56 void deactivate() override;
57 bool isActive() const override;
58
59private:
60 // find and set the running xscreensaver's window. returns true iff
61 // found.
62 bool findXScreenSaver();
63
64 // set the xscreensaver's window, updating the activation state flag
65 void setXScreenSaver(Window);
66
67 // returns true if the window appears to be the xscreensaver window
68 bool isXScreenSaver(Window) const;
69
70 // set xscreensaver's activation state flag. sends notification
71 // if the state has changed.
72 void setXScreenSaverActive(bool activated);
73
74 // send a command to xscreensaver
75 void sendXScreenSaverCommand(Atom, long = 0, long = 0);
76
77 // watch all windows that could potentially be the xscreensaver for
78 // the events that will confirm it.
79 void watchForXScreenSaver();
80
81 // stop watching all watched windows
82 void clearWatchForXScreenSaver();
83
84 // add window to the watch list
85 void addWatchXScreenSaver(Window window);
86
87 // install/uninstall the job used to suppress the screensaver
88 void updateDisableTimer();
89
90 // called periodically to prevent the screen saver from starting
91 void handleDisableTimer();
92
93 // force DPMS to activate or deactivate
94 void activateDPMS(bool activate);
95
96 // enable/disable DPMS screen saver
97 void enableDPMS(bool);
98
99 // check if DPMS is enabled
100 bool isDPMSEnabled() const;
101
102 // check if DPMS is activate
103 bool isDPMSActivated() const;
104
105private:
106 using WatchList = std::map<Window, long>;
107
108 // the X display
109 Display *m_display;
110
111 // window to receive xscreensaver responses
112 Window m_xscreensaverSink;
113
114 // the target for the events we generate
115 void *m_eventTarget;
116
117 // xscreensaver's window
118 Window m_xscreensaver = None;
119
120 // xscreensaver activation state
121 bool m_xscreensaverActive = false;
122
123 // old event mask on root window
124 long m_rootEventMask;
125
126 // potential xscreensaver windows being watched
127 WatchList m_watchWindows;
128
129 // atoms used to communicate with xscreensaver's window
130 Atom m_atomScreenSaver;
131 Atom m_atomScreenSaverVersion;
132 Atom m_atomScreenSaverActivate;
133 Atom m_atomScreenSaverDeactivate;
134
135 // built-in screen saver settings
136 int m_timeout;
137 int m_interval;
138 int m_preferBlanking;
139 int m_allowExposures;
140
141 // DPMS screen saver settings
142 bool m_dpms = false;
143 bool m_dpmsEnabled;
144
145 // true iff the client wants the screen saver suppressed
146 bool m_disabled = false;
147
148 // true iff we're ignoring m_disabled. this is true, for example,
149 // when the client has called activate() and so presumably wants
150 // to activate the screen saver even if disabled.
151 bool m_suppressDisable = false;
152
153 // the disable timer (nullptr if not installed)
154 EventQueueTimer *m_disableTimer = nullptr;
155
156 // fake mouse motion position for suppressing the screen saver.
157 // xscreensaver since 2.21 requires the mouse to move more than 10
158 // pixels to be considered significant.
159 int32_t m_disablePos = 0;
160
161 IEventQueue *m_events = nullptr;
162};
Definition SimpleEventQueueBuffer.cpp:13
Event.
Definition Event.h:27
Event queue interface.
Definition IEventQueue.h:32
Screen saver interface.
Definition IScreenSaver.h:18
XWindowsScreenSaver & operator=(XWindowsScreenSaver const &)=delete
void destroy()
Destroy without the display.
Definition XWindowsScreenSaver.cpp:105
XWindowsScreenSaver(Display *, Window, void *eventTarget, IEventQueue *events)
Definition XWindowsScreenSaver.cpp:35
void activate() override
Activate screen saver.
Definition XWindowsScreenSaver.cpp:200
~XWindowsScreenSaver() override
Definition XWindowsScreenSaver.cpp:88
void deactivate() override
Deactivate screen saver.
Definition XWindowsScreenSaver.cpp:225
bool handleXEvent(const XEvent *)
Event filtering.
Definition XWindowsScreenSaver.cpp:111
XWindowsScreenSaver & operator=(XWindowsScreenSaver &&)=delete
void enable() override
Enable screen saver.
Definition XWindowsScreenSaver.cpp:170
bool isActive() const override
Test if screen saver on.
Definition XWindowsScreenSaver.cpp:250
void disable() override
Disable screen saver.
Definition XWindowsScreenSaver.cpp:183
XWindowsScreenSaver(XWindowsScreenSaver &&)=delete
XWindowsScreenSaver(XWindowsScreenSaver const &)=delete