1 | /*
|
---|
2 | * synergy -- mouse and keyboard sharing utility
|
---|
3 | * Copyright (C) 2002 Chris Schoeneman
|
---|
4 | *
|
---|
5 | * This package is free software; you can redistribute it and/or
|
---|
6 | * modify it under the terms of the GNU General Public License
|
---|
7 | * found in the file COPYING that should have accompanied this file.
|
---|
8 | *
|
---|
9 | * This package is distributed in the hope that it will be useful,
|
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | * GNU General Public License for more details.
|
---|
13 | */
|
---|
14 |
|
---|
15 | #ifndef CXWINDOWSSCREENSAVER_H
|
---|
16 | #define CXWINDOWSSCREENSAVER_H
|
---|
17 |
|
---|
18 | #include "IScreenSaver.h"
|
---|
19 | #include "stdmap.h"
|
---|
20 | #if X_DISPLAY_MISSING
|
---|
21 | # error X11 is required to build synergy
|
---|
22 | #else
|
---|
23 | # include <X11/Xlib.h>
|
---|
24 | #endif
|
---|
25 |
|
---|
26 | class CEvent;
|
---|
27 | class CEventQueueTimer;
|
---|
28 |
|
---|
29 | //! X11 screen saver implementation
|
---|
30 | class CXWindowsScreenSaver : public IScreenSaver {
|
---|
31 | public:
|
---|
32 | CXWindowsScreenSaver(Display*, Window, void* eventTarget);
|
---|
33 | virtual ~CXWindowsScreenSaver();
|
---|
34 |
|
---|
35 | //! @name manipulators
|
---|
36 | //@{
|
---|
37 |
|
---|
38 | //! Event filtering
|
---|
39 | /*!
|
---|
40 | Should be called for each system event before event translation and
|
---|
41 | dispatch. Returns true to skip translation and dispatch.
|
---|
42 | */
|
---|
43 | bool handleXEvent(const XEvent*);
|
---|
44 |
|
---|
45 | //! Destroy without the display
|
---|
46 | /*!
|
---|
47 | Tells this object to delete itself without using the X11 display.
|
---|
48 | It may leak some resources as a result.
|
---|
49 | */
|
---|
50 | void destroy();
|
---|
51 |
|
---|
52 | //@}
|
---|
53 |
|
---|
54 | // IScreenSaver overrides
|
---|
55 | virtual void enable();
|
---|
56 | virtual void disable();
|
---|
57 | virtual void activate();
|
---|
58 | virtual void deactivate();
|
---|
59 | virtual bool isActive() const;
|
---|
60 |
|
---|
61 | private:
|
---|
62 | // find and set the running xscreensaver's window. returns true iff
|
---|
63 | // found.
|
---|
64 | bool findXScreenSaver();
|
---|
65 |
|
---|
66 | // set the xscreensaver's window, updating the activation state flag
|
---|
67 | void setXScreenSaver(Window);
|
---|
68 |
|
---|
69 | // returns true if the window appears to be the xscreensaver window
|
---|
70 | bool isXScreenSaver(Window) const;
|
---|
71 |
|
---|
72 | // set xscreensaver's activation state flag. sends notification
|
---|
73 | // if the state has changed.
|
---|
74 | void setXScreenSaverActive(bool activated);
|
---|
75 |
|
---|
76 | // send a command to xscreensaver
|
---|
77 | void sendXScreenSaverCommand(Atom, long = 0, long = 0);
|
---|
78 |
|
---|
79 | // watch all windows that could potentially be the xscreensaver for
|
---|
80 | // the events that will confirm it.
|
---|
81 | void watchForXScreenSaver();
|
---|
82 |
|
---|
83 | // stop watching all watched windows
|
---|
84 | void clearWatchForXScreenSaver();
|
---|
85 |
|
---|
86 | // add window to the watch list
|
---|
87 | void addWatchXScreenSaver(Window window);
|
---|
88 |
|
---|
89 | // install/uninstall the job used to suppress the screensaver
|
---|
90 | void updateDisableTimer();
|
---|
91 |
|
---|
92 | // called periodically to prevent the screen saver from starting
|
---|
93 | void handleDisableTimer(const CEvent&, void*);
|
---|
94 |
|
---|
95 | // force DPMS to activate or deactivate
|
---|
96 | void activateDPMS(bool activate);
|
---|
97 |
|
---|
98 | // enable/disable DPMS screen saver
|
---|
99 | void enableDPMS(bool);
|
---|
100 |
|
---|
101 | // check if DPMS is enabled
|
---|
102 | bool isDPMSEnabled() const;
|
---|
103 |
|
---|
104 | // check if DPMS is activate
|
---|
105 | bool isDPMSActivated() const;
|
---|
106 |
|
---|
107 | private:
|
---|
108 | typedef std::map<Window, long> CWatchList;
|
---|
109 |
|
---|
110 | // the X display
|
---|
111 | Display* m_display;
|
---|
112 |
|
---|
113 | // window to receive xscreensaver repsonses
|
---|
114 | Window m_xscreensaverSink;
|
---|
115 |
|
---|
116 | // the target for the events we generate
|
---|
117 | void* m_eventTarget;
|
---|
118 |
|
---|
119 | // xscreensaver's window
|
---|
120 | Window m_xscreensaver;
|
---|
121 |
|
---|
122 | // xscreensaver activation state
|
---|
123 | bool m_xscreensaverActive;
|
---|
124 |
|
---|
125 | // old event mask on root window
|
---|
126 | long m_rootEventMask;
|
---|
127 |
|
---|
128 | // potential xscreensaver windows being watched
|
---|
129 | CWatchList m_watchWindows;
|
---|
130 |
|
---|
131 | // atoms used to communicate with xscreensaver's window
|
---|
132 | Atom m_atomScreenSaver;
|
---|
133 | Atom m_atomScreenSaverVersion;
|
---|
134 | Atom m_atomScreenSaverActivate;
|
---|
135 | Atom m_atomScreenSaverDeactivate;
|
---|
136 |
|
---|
137 | // built-in screen saver settings
|
---|
138 | int m_timeout;
|
---|
139 | int m_interval;
|
---|
140 | int m_preferBlanking;
|
---|
141 | int m_allowExposures;
|
---|
142 |
|
---|
143 | // DPMS screen saver settings
|
---|
144 | bool m_dpms;
|
---|
145 | bool m_dpmsEnabled;
|
---|
146 |
|
---|
147 | // true iff the client wants the screen saver suppressed
|
---|
148 | bool m_disabled;
|
---|
149 |
|
---|
150 | // true iff we're ignoring m_disabled. this is true, for example,
|
---|
151 | // when the client has called activate() and so presumably wants
|
---|
152 | // to activate the screen saver even if disabled.
|
---|
153 | bool m_suppressDisable;
|
---|
154 |
|
---|
155 | // the disable timer (NULL if not installed)
|
---|
156 | CEventQueueTimer* m_disableTimer;
|
---|
157 |
|
---|
158 | // fake mouse motion position for suppressing the screen saver.
|
---|
159 | // xscreensaver since 2.21 requires the mouse to move more than 10
|
---|
160 | // pixels to be considered significant.
|
---|
161 | SInt32 m_disablePos;
|
---|
162 | };
|
---|
163 |
|
---|
164 | #endif
|
---|