deskflow/src/lib/platform/XWindowsScreenSaver.h

166 lines
4.3 KiB
C
Raw Normal View History

2012-06-10 16:50:54 +00:00
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
2012-06-10 16:50:54 +00:00
*/
#pragma once
#include "base/IEventQueue.h"
#include "deskflow/IScreenSaver.h"
2012-06-10 16:50:54 +00:00
#include <map>
2012-06-10 16:50:54 +00:00
#if X_DISPLAY_MISSING
#error X11 is required to build deskflow
2012-06-10 16:50:54 +00:00
#else
#include <X11/Xlib.h>
2012-06-10 16:50:54 +00:00
#endif
2014-11-11 13:51:47 +00:00
class Event;
class EventQueueTimer;
2012-06-10 16:50:54 +00:00
//! X11 screen saver implementation
class XWindowsScreenSaver : public IScreenSaver
{
2012-06-10 16:50:54 +00:00
public:
XWindowsScreenSaver(Display *, Window, void *eventTarget, IEventQueue *events);
XWindowsScreenSaver(XWindowsScreenSaver const &) = delete;
XWindowsScreenSaver(XWindowsScreenSaver &&) = delete;
~XWindowsScreenSaver() override;
XWindowsScreenSaver &operator=(XWindowsScreenSaver const &) = delete;
XWindowsScreenSaver &operator=(XWindowsScreenSaver &&) = delete;
//! @name manipulators
//@{
//! Event filtering
/*!
Should be called for each system event before event translation and
dispatch. Returns true to skip translation and dispatch.
*/
bool handleXEvent(const XEvent *);
//! Destroy without the display
/*!
Tells this object to delete itself without using the X11 display.
It may leak some resources as a result.
*/
void destroy();
//@}
// IScreenSaver overrides
void enable() override;
void disable() override;
void activate() override;
void deactivate() override;
bool isActive() const override;
2012-06-10 16:50:54 +00:00
private:
// find and set the running xscreensaver's window. returns true iff
// found.
bool findXScreenSaver();
2012-06-10 16:50:54 +00:00
// set the xscreensaver's window, updating the activation state flag
void setXScreenSaver(Window);
2012-06-10 16:50:54 +00:00
// returns true if the window appears to be the xscreensaver window
bool isXScreenSaver(Window) const;
2012-06-10 16:50:54 +00:00
// set xscreensaver's activation state flag. sends notification
// if the state has changed.
void setXScreenSaverActive(bool activated);
2012-06-10 16:50:54 +00:00
// send a command to xscreensaver
void sendXScreenSaverCommand(Atom, long = 0, long = 0);
2012-06-10 16:50:54 +00:00
// watch all windows that could potentially be the xscreensaver for
// the events that will confirm it.
void watchForXScreenSaver();
2012-06-10 16:50:54 +00:00
// stop watching all watched windows
void clearWatchForXScreenSaver();
2012-06-10 16:50:54 +00:00
// add window to the watch list
void addWatchXScreenSaver(Window window);
2012-06-10 16:50:54 +00:00
// install/uninstall the job used to suppress the screensaver
void updateDisableTimer();
2012-06-10 16:50:54 +00:00
// called periodically to prevent the screen saver from starting
void handleDisableTimer(const Event &, void *);
2012-06-10 16:50:54 +00:00
// force DPMS to activate or deactivate
void activateDPMS(bool activate);
2012-06-10 16:50:54 +00:00
// enable/disable DPMS screen saver
void enableDPMS(bool);
2012-06-10 16:50:54 +00:00
// check if DPMS is enabled
bool isDPMSEnabled() const;
2012-06-10 16:50:54 +00:00
// check if DPMS is activate
bool isDPMSActivated() const;
2012-06-10 16:50:54 +00:00
private:
using WatchList = std::map<Window, long>;
2012-06-10 16:50:54 +00:00
// the X display
Display *m_display;
2012-06-10 16:50:54 +00:00
// window to receive xscreensaver responses
Window m_xscreensaverSink;
2012-06-10 16:50:54 +00:00
// the target for the events we generate
void *m_eventTarget;
2012-06-10 16:50:54 +00:00
// xscreensaver's window
Window m_xscreensaver;
2012-06-10 16:50:54 +00:00
// xscreensaver activation state
bool m_xscreensaverActive;
2012-06-10 16:50:54 +00:00
// old event mask on root window
long m_rootEventMask;
2012-06-10 16:50:54 +00:00
// potential xscreensaver windows being watched
WatchList m_watchWindows;
2012-06-10 16:50:54 +00:00
// atoms used to communicate with xscreensaver's window
Atom m_atomScreenSaver;
Atom m_atomScreenSaverVersion;
Atom m_atomScreenSaverActivate;
Atom m_atomScreenSaverDeactivate;
2012-06-10 16:50:54 +00:00
// built-in screen saver settings
int m_timeout;
int m_interval;
int m_preferBlanking;
int m_allowExposures;
2012-06-10 16:50:54 +00:00
// DPMS screen saver settings
bool m_dpms;
bool m_dpmsEnabled;
2012-06-10 16:50:54 +00:00
// true iff the client wants the screen saver suppressed
bool m_disabled;
2012-06-10 16:50:54 +00:00
// true iff we're ignoring m_disabled. this is true, for example,
// when the client has called activate() and so presumably wants
// to activate the screen saver even if disabled.
bool m_suppressDisable;
2012-06-10 16:50:54 +00:00
// the disable timer (NULL if not installed)
EventQueueTimer *m_disableTimer;
2012-06-10 16:50:54 +00:00
// fake mouse motion position for suppressing the screen saver.
// xscreensaver since 2.21 requires the mouse to move more than 10
// pixels to be considered significant.
2025-01-11 01:11:56 +00:00
int32_t m_disablePos;
2012-06-10 16:50:54 +00:00
IEventQueue *m_events;
2012-06-10 16:50:54 +00:00
};