2002-08-02 19:57:46 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
* Copyright (C) 2002 Chris Schoeneman
|
|
|
|
*
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2002-06-22 19:20:21 +00:00
|
|
|
#include "CXWindowsScreenSaver.h"
|
2002-06-23 15:43:40 +00:00
|
|
|
#include "CXWindowsScreen.h"
|
2002-06-22 19:20:21 +00:00
|
|
|
#include "CXWindowsUtil.h"
|
2002-06-22 20:29:59 +00:00
|
|
|
#include "CLog.h"
|
2002-06-23 15:43:40 +00:00
|
|
|
#include "TMethodJob.h"
|
2002-06-22 19:20:21 +00:00
|
|
|
#include <X11/Xatom.h>
|
2002-06-23 15:43:40 +00:00
|
|
|
#if defined(HAVE_X11_EXTENSIONS_XTEST_H)
|
|
|
|
# include <X11/extensions/XTest.h>
|
|
|
|
#else
|
|
|
|
# error The XTest extension is required to build synergy
|
|
|
|
#endif
|
2002-06-22 19:20:21 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// CXWindowsScreenSaver
|
|
|
|
//
|
|
|
|
|
2002-06-23 15:43:40 +00:00
|
|
|
CXWindowsScreenSaver::CXWindowsScreenSaver(
|
|
|
|
CXWindowsScreen* screen, Display* display) :
|
|
|
|
m_screen(screen),
|
2002-06-22 19:20:21 +00:00
|
|
|
m_display(display),
|
|
|
|
m_notify(None),
|
2002-06-23 15:43:40 +00:00
|
|
|
m_xscreensaver(None),
|
2002-06-23 21:48:33 +00:00
|
|
|
m_xscreensaverActive(false),
|
2003-01-11 15:16:41 +00:00
|
|
|
m_disabled(false),
|
|
|
|
m_suppressDisable(false),
|
|
|
|
m_disableJobInstalled(false)
|
2002-06-22 19:20:21 +00:00
|
|
|
{
|
2002-06-23 15:43:40 +00:00
|
|
|
// screen saver disable callback
|
|
|
|
m_disableJob = new TMethodJob<CXWindowsScreenSaver>(this,
|
|
|
|
&CXWindowsScreenSaver::disableCallback);
|
|
|
|
|
2002-06-22 19:20:21 +00:00
|
|
|
// get atoms
|
|
|
|
m_atomScreenSaver = XInternAtom(m_display,
|
|
|
|
"SCREENSAVER", False);
|
|
|
|
m_atomScreenSaverVersion = XInternAtom(m_display,
|
|
|
|
"_SCREENSAVER_VERSION", False);
|
|
|
|
m_atomScreenSaverActivate = XInternAtom(m_display,
|
|
|
|
"ACTIVATE", False);
|
|
|
|
m_atomScreenSaverDeactivate = XInternAtom(m_display,
|
|
|
|
"DEACTIVATE", False);
|
2002-11-05 19:23:05 +00:00
|
|
|
m_atomSynergyScreenSaver = XInternAtom(m_display,
|
|
|
|
"SYNERGY_SCREENSAVER", False);
|
2002-06-22 19:20:21 +00:00
|
|
|
|
2002-06-23 15:43:40 +00:00
|
|
|
// create dummy window to receive xscreensaver responses. this
|
|
|
|
// shouldn't be necessary (we should be able to send responses
|
|
|
|
// to None) but it doesn't hurt.
|
2002-06-22 20:29:59 +00:00
|
|
|
XSetWindowAttributes attr;
|
|
|
|
attr.event_mask = 0;//PropertyChangeMask;
|
|
|
|
attr.do_not_propagate_mask = 0;
|
|
|
|
attr.override_redirect = True;
|
|
|
|
m_xscreensaverSink = XCreateWindow(m_display,
|
|
|
|
DefaultRootWindow(m_display),
|
|
|
|
0, 0, 1, 1, 0, 0,
|
|
|
|
InputOnly, CopyFromParent,
|
|
|
|
CWDontPropagate | CWEventMask |
|
|
|
|
CWOverrideRedirect,
|
|
|
|
&attr);
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG "xscreensaver sink window is 0x%08x", m_xscreensaverSink));
|
2002-06-22 20:29:59 +00:00
|
|
|
|
2002-06-22 19:20:21 +00:00
|
|
|
// watch top-level windows for changes
|
|
|
|
{
|
|
|
|
bool error = false;
|
2002-06-22 19:47:27 +00:00
|
|
|
CXWindowsUtil::CErrorLock lock(m_display, &error);
|
2002-06-22 19:20:21 +00:00
|
|
|
Window root = DefaultRootWindow(m_display);
|
|
|
|
XWindowAttributes attr;
|
|
|
|
XGetWindowAttributes(m_display, root, &attr);
|
|
|
|
m_rootEventMask = attr.your_event_mask;
|
|
|
|
XSelectInput(m_display, root, m_rootEventMask | SubstructureNotifyMask);
|
|
|
|
if (error) {
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG "didn't set root event mask"));
|
2002-06-22 19:20:21 +00:00
|
|
|
m_rootEventMask = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the xscreensaver window, if any
|
2002-06-23 15:43:40 +00:00
|
|
|
if (!findXScreenSaver()) {
|
|
|
|
setXScreenSaver(None);
|
|
|
|
}
|
2002-06-22 19:20:21 +00:00
|
|
|
|
|
|
|
// get the built-in settings
|
|
|
|
XGetScreenSaver(m_display, &m_timeout, &m_interval,
|
|
|
|
&m_preferBlanking, &m_allowExposures);
|
|
|
|
}
|
|
|
|
|
|
|
|
CXWindowsScreenSaver::~CXWindowsScreenSaver()
|
|
|
|
{
|
2002-06-23 15:43:40 +00:00
|
|
|
// clear watch list
|
|
|
|
clearWatchForXScreenSaver();
|
|
|
|
|
2002-06-22 19:20:21 +00:00
|
|
|
// stop watching root for events
|
2002-06-22 19:47:27 +00:00
|
|
|
CXWindowsUtil::CErrorLock lock(m_display);
|
2002-06-22 19:20:21 +00:00
|
|
|
Window root = DefaultRootWindow(m_display);
|
|
|
|
XSelectInput(m_display, root, m_rootEventMask);
|
2002-06-23 15:43:40 +00:00
|
|
|
|
|
|
|
// destroy dummy sink window
|
|
|
|
XDestroyWindow(m_display, m_xscreensaverSink);
|
|
|
|
|
|
|
|
// done with disable job
|
|
|
|
m_screen->removeTimer(m_disableJob);
|
|
|
|
delete m_disableJob;
|
2002-06-22 19:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2002-07-12 20:41:23 +00:00
|
|
|
CXWindowsScreenSaver::onPreDispatch(const XEvent* xevent)
|
2002-06-22 19:20:21 +00:00
|
|
|
{
|
|
|
|
switch (xevent->type) {
|
2002-06-23 15:43:40 +00:00
|
|
|
case CreateNotify:
|
|
|
|
if (m_xscreensaver == None) {
|
|
|
|
if (isXScreenSaver(xevent->xcreatewindow.window)) {
|
|
|
|
// found the xscreensaver
|
|
|
|
setXScreenSaver(xevent->xcreatewindow.window);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// another window to watch. to detect the xscreensaver
|
|
|
|
// window we look for a property but that property may
|
|
|
|
// not yet exist by the time we get this event so we
|
|
|
|
// have to watch the window for property changes.
|
|
|
|
// this would be so much easier if xscreensaver did the
|
|
|
|
// smart thing and stored its window in a property on
|
|
|
|
// the root window.
|
|
|
|
addWatchXScreenSaver(xevent->xcreatewindow.window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-06-22 19:20:21 +00:00
|
|
|
case DestroyNotify:
|
|
|
|
if (xevent->xdestroywindow.window == m_xscreensaver) {
|
|
|
|
// xscreensaver is gone
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG "xscreensaver died"));
|
2002-06-23 15:43:40 +00:00
|
|
|
setXScreenSaver(None);
|
2002-06-22 19:20:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-06-23 15:43:40 +00:00
|
|
|
case PropertyNotify:
|
|
|
|
if (xevent->xproperty.state == PropertyNewValue) {
|
|
|
|
if (isXScreenSaver(xevent->xproperty.window)) {
|
|
|
|
// found the xscreensaver
|
|
|
|
setXScreenSaver(xevent->xcreatewindow.window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-06-22 19:20:21 +00:00
|
|
|
case MapNotify:
|
|
|
|
if (xevent->xmap.window == m_xscreensaver) {
|
|
|
|
// xscreensaver has activated
|
2002-06-23 15:43:40 +00:00
|
|
|
setXScreenSaverActive(true);
|
2002-06-22 19:20:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UnmapNotify:
|
|
|
|
if (xevent->xunmap.window == m_xscreensaver) {
|
|
|
|
// xscreensaver has deactivated
|
2002-06-23 15:43:40 +00:00
|
|
|
setXScreenSaverActive(false);
|
2002-06-22 19:20:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CXWindowsScreenSaver::setNotify(Window notify)
|
|
|
|
{
|
|
|
|
m_notify = notify;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CXWindowsScreenSaver::enable()
|
|
|
|
{
|
2002-06-23 15:43:40 +00:00
|
|
|
// for xscreensaver
|
2002-06-23 21:48:33 +00:00
|
|
|
m_disabled = false;
|
2003-01-11 15:16:41 +00:00
|
|
|
updateDisableJob();
|
2002-06-22 19:20:21 +00:00
|
|
|
|
2002-06-23 15:43:40 +00:00
|
|
|
// for built-in X screen saver
|
2002-06-22 19:20:21 +00:00
|
|
|
XSetScreenSaver(m_display, m_timeout, m_interval,
|
|
|
|
m_preferBlanking, m_allowExposures);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CXWindowsScreenSaver::disable()
|
|
|
|
{
|
2003-03-13 20:24:45 +00:00
|
|
|
// for xscreensaver
|
2002-06-23 21:48:33 +00:00
|
|
|
m_disabled = true;
|
2003-01-11 15:16:41 +00:00
|
|
|
updateDisableJob();
|
2002-06-22 19:20:21 +00:00
|
|
|
|
|
|
|
// use built-in X screen saver
|
|
|
|
XGetScreenSaver(m_display, &m_timeout, &m_interval,
|
|
|
|
&m_preferBlanking, &m_allowExposures);
|
|
|
|
XSetScreenSaver(m_display, 0, m_interval,
|
|
|
|
m_preferBlanking, m_allowExposures);
|
|
|
|
// FIXME -- now deactivate?
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CXWindowsScreenSaver::activate()
|
|
|
|
{
|
2002-06-23 21:48:33 +00:00
|
|
|
// remove disable job timer
|
2003-01-11 15:16:41 +00:00
|
|
|
m_suppressDisable = true;
|
|
|
|
updateDisableJob();
|
2002-06-23 21:48:33 +00:00
|
|
|
|
2002-06-22 19:20:21 +00:00
|
|
|
// try xscreensaver
|
2002-06-23 15:43:40 +00:00
|
|
|
findXScreenSaver();
|
|
|
|
if (m_xscreensaver != None) {
|
2002-06-22 19:20:21 +00:00
|
|
|
sendXScreenSaverCommand(m_atomScreenSaverActivate);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// use built-in X screen saver
|
|
|
|
XForceScreenSaver(m_display, ScreenSaverActive);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CXWindowsScreenSaver::deactivate()
|
|
|
|
{
|
2002-06-23 21:48:33 +00:00
|
|
|
// reinstall disable job timer
|
2003-01-11 15:16:41 +00:00
|
|
|
m_suppressDisable = false;
|
|
|
|
updateDisableJob();
|
2002-06-23 21:48:33 +00:00
|
|
|
|
2002-06-22 19:20:21 +00:00
|
|
|
// try xscreensaver
|
2002-06-23 15:43:40 +00:00
|
|
|
findXScreenSaver();
|
|
|
|
if (m_xscreensaver != None) {
|
2002-06-22 19:20:21 +00:00
|
|
|
sendXScreenSaverCommand(m_atomScreenSaverDeactivate);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// use built-in X screen saver
|
|
|
|
XForceScreenSaver(m_display, ScreenSaverReset);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CXWindowsScreenSaver::isActive() const
|
|
|
|
{
|
|
|
|
// check xscreensaver
|
|
|
|
if (m_xscreensaver != None) {
|
|
|
|
return m_xscreensaverActive;
|
|
|
|
}
|
|
|
|
|
|
|
|
// can't check built-in X screen saver activity
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CXWindowsScreenSaver::sendNotify(bool activated)
|
|
|
|
{
|
|
|
|
if (m_notify != None) {
|
|
|
|
XEvent event;
|
|
|
|
event.xclient.type = ClientMessage;
|
|
|
|
event.xclient.display = m_display;
|
|
|
|
event.xclient.window = m_notify;
|
2002-11-05 19:23:05 +00:00
|
|
|
event.xclient.message_type = m_atomSynergyScreenSaver;
|
2002-06-22 19:20:21 +00:00
|
|
|
event.xclient.format = 32;
|
|
|
|
event.xclient.data.l[0] = activated ? 1 : 0;
|
|
|
|
event.xclient.data.l[1] = 0;
|
|
|
|
event.xclient.data.l[2] = 0;
|
|
|
|
event.xclient.data.l[3] = 0;
|
|
|
|
event.xclient.data.l[4] = 0;
|
|
|
|
|
2002-06-22 19:47:27 +00:00
|
|
|
CXWindowsUtil::CErrorLock lock(m_display);
|
2002-06-22 19:20:21 +00:00
|
|
|
XSendEvent(m_display, m_notify, False, 0, &event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-23 15:43:40 +00:00
|
|
|
bool
|
|
|
|
CXWindowsScreenSaver::findXScreenSaver()
|
2002-06-22 19:20:21 +00:00
|
|
|
{
|
2002-06-23 15:43:40 +00:00
|
|
|
// do nothing if we've already got the xscreensaver window
|
|
|
|
if (m_xscreensaver == None) {
|
|
|
|
// find top-level window xscreensaver window
|
|
|
|
Window root = DefaultRootWindow(m_display);
|
|
|
|
Window rw, pw, *cw;
|
|
|
|
unsigned int nc;
|
|
|
|
if (XQueryTree(m_display, root, &rw, &pw, &cw, &nc)) {
|
|
|
|
for (unsigned int i = 0; i < nc; ++i) {
|
|
|
|
if (isXScreenSaver(cw[i])) {
|
|
|
|
setXScreenSaver(cw[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XFree(cw);
|
|
|
|
}
|
2002-06-22 19:20:21 +00:00
|
|
|
}
|
2002-06-23 15:43:40 +00:00
|
|
|
|
|
|
|
return (m_xscreensaver != None);
|
2002-06-22 19:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-06-23 15:43:40 +00:00
|
|
|
CXWindowsScreenSaver::setXScreenSaver(Window window)
|
2002-06-22 19:20:21 +00:00
|
|
|
{
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG "xscreensaver window: 0x%08x", window));
|
2002-06-22 19:20:21 +00:00
|
|
|
|
2002-06-23 15:43:40 +00:00
|
|
|
// save window
|
|
|
|
m_xscreensaver = window;
|
2002-06-22 19:20:21 +00:00
|
|
|
|
|
|
|
if (m_xscreensaver != None) {
|
2002-06-23 15:43:40 +00:00
|
|
|
// clear old watch list
|
|
|
|
clearWatchForXScreenSaver();
|
|
|
|
|
|
|
|
// see if xscreensaver is active
|
2002-06-22 19:20:21 +00:00
|
|
|
bool error = false;
|
2002-06-22 19:47:27 +00:00
|
|
|
CXWindowsUtil::CErrorLock lock(m_display, &error);
|
2002-06-22 19:20:21 +00:00
|
|
|
XWindowAttributes attr;
|
|
|
|
XGetWindowAttributes(m_display, m_xscreensaver, &attr);
|
2002-06-23 15:43:40 +00:00
|
|
|
setXScreenSaverActive(!error && attr.map_state != IsUnmapped);
|
2002-06-22 19:20:21 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-06-23 15:43:40 +00:00
|
|
|
// screen saver can't be active if it doesn't exist
|
|
|
|
setXScreenSaverActive(false);
|
|
|
|
|
|
|
|
// start watching for xscreensaver
|
|
|
|
watchForXScreenSaver();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CXWindowsScreenSaver::isXScreenSaver(Window w) const
|
|
|
|
{
|
|
|
|
// check for m_atomScreenSaverVersion string property
|
|
|
|
Atom type;
|
|
|
|
return (CXWindowsUtil::getWindowProperty(m_display, w,
|
|
|
|
m_atomScreenSaverVersion,
|
|
|
|
NULL, &type, NULL, False) &&
|
|
|
|
type == XA_STRING);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CXWindowsScreenSaver::setXScreenSaverActive(bool activated)
|
|
|
|
{
|
|
|
|
if (m_xscreensaverActive != activated) {
|
2002-11-05 19:23:05 +00:00
|
|
|
LOG((CLOG_DEBUG "xscreensaver %s on window 0x%08x", activated ? "activated" : "deactivated", m_xscreensaver));
|
2002-06-23 15:43:40 +00:00
|
|
|
m_xscreensaverActive = activated;
|
2003-01-11 15:16:41 +00:00
|
|
|
|
|
|
|
// if screen saver was activated forcefully (i.e. against
|
|
|
|
// our will) then just accept it. don't try to keep it
|
|
|
|
// from activating since that'll just pop up the password
|
|
|
|
// dialog if locking is enabled.
|
|
|
|
m_suppressDisable = activated;
|
|
|
|
updateDisableJob();
|
|
|
|
|
2002-06-23 15:43:40 +00:00
|
|
|
sendNotify(activated);
|
2002-06-22 19:20:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-06-22 20:29:59 +00:00
|
|
|
CXWindowsScreenSaver::sendXScreenSaverCommand(Atom cmd, long arg1, long arg2)
|
2002-06-22 19:20:21 +00:00
|
|
|
{
|
|
|
|
XEvent event;
|
|
|
|
event.xclient.type = ClientMessage;
|
|
|
|
event.xclient.display = m_display;
|
2002-06-22 20:29:59 +00:00
|
|
|
event.xclient.window = m_xscreensaverSink;
|
2002-06-22 19:20:21 +00:00
|
|
|
event.xclient.message_type = m_atomScreenSaver;
|
|
|
|
event.xclient.format = 32;
|
|
|
|
event.xclient.data.l[0] = static_cast<long>(cmd);
|
|
|
|
event.xclient.data.l[1] = arg1;
|
|
|
|
event.xclient.data.l[2] = arg2;
|
|
|
|
event.xclient.data.l[3] = 0;
|
|
|
|
event.xclient.data.l[4] = 0;
|
|
|
|
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG "send xscreensaver command: %d %d %d", (long)cmd, arg1, arg2));
|
2002-06-22 20:29:59 +00:00
|
|
|
bool error = false;
|
|
|
|
CXWindowsUtil::CErrorLock lock(m_display, &error);
|
2002-06-22 19:20:21 +00:00
|
|
|
XSendEvent(m_display, m_xscreensaver, False, 0, &event);
|
2002-06-22 20:29:59 +00:00
|
|
|
if (error) {
|
2002-06-23 15:43:40 +00:00
|
|
|
findXScreenSaver();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CXWindowsScreenSaver::watchForXScreenSaver()
|
|
|
|
{
|
|
|
|
// clear old watch list
|
|
|
|
clearWatchForXScreenSaver();
|
|
|
|
|
|
|
|
// add every child of the root to the list of windows to watch
|
|
|
|
Window root = DefaultRootWindow(m_display);
|
|
|
|
Window rw, pw, *cw;
|
|
|
|
unsigned int nc;
|
|
|
|
if (XQueryTree(m_display, root, &rw, &pw, &cw, &nc)) {
|
|
|
|
for (unsigned int i = 0; i < nc; ++i) {
|
|
|
|
addWatchXScreenSaver(cw[i]);
|
|
|
|
}
|
|
|
|
XFree(cw);
|
|
|
|
}
|
|
|
|
|
|
|
|
// now check for xscreensaver window in case it set the property
|
|
|
|
// before we could request property change events.
|
|
|
|
if (findXScreenSaver()) {
|
|
|
|
// found it so clear out our watch list
|
|
|
|
clearWatchForXScreenSaver();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CXWindowsScreenSaver::clearWatchForXScreenSaver()
|
|
|
|
{
|
|
|
|
// stop watching all windows
|
|
|
|
CXWindowsUtil::CErrorLock lock(m_display);
|
|
|
|
for (CWatchList::iterator index = m_watchWindows.begin();
|
|
|
|
index != m_watchWindows.end(); ++index) {
|
|
|
|
XSelectInput(m_display, index->first, index->second);
|
|
|
|
}
|
|
|
|
m_watchWindows.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CXWindowsScreenSaver::addWatchXScreenSaver(Window window)
|
|
|
|
{
|
|
|
|
bool error = false;
|
|
|
|
CXWindowsUtil::CErrorLock lock(m_display, &error);
|
|
|
|
|
|
|
|
// get window attributes
|
|
|
|
XWindowAttributes attr;
|
|
|
|
XGetWindowAttributes(m_display, window, &attr);
|
|
|
|
|
|
|
|
// if successful and window uses override_redirect (like xscreensaver
|
|
|
|
// does) then watch it for property changes.
|
|
|
|
if (!error && attr.override_redirect == True) {
|
|
|
|
XSelectInput(m_display, window,
|
|
|
|
attr.your_event_mask | PropertyChangeMask);
|
|
|
|
if (!error) {
|
|
|
|
// if successful then add the window to our list
|
|
|
|
m_watchWindows.insert(std::make_pair(window, attr.your_event_mask));
|
|
|
|
}
|
2002-06-22 20:29:59 +00:00
|
|
|
}
|
2002-06-22 19:20:21 +00:00
|
|
|
}
|
2002-06-23 15:43:40 +00:00
|
|
|
|
2003-01-11 15:16:41 +00:00
|
|
|
void
|
|
|
|
CXWindowsScreenSaver::updateDisableJob()
|
|
|
|
{
|
|
|
|
assert(m_disableJob != NULL);
|
|
|
|
|
|
|
|
if (m_disabled && !m_suppressDisable && !m_disableJobInstalled) {
|
2003-03-13 20:24:45 +00:00
|
|
|
// 5 seconds should be plenty often to suppress the screen saver
|
2003-01-11 15:16:41 +00:00
|
|
|
m_disableJobInstalled = true;
|
|
|
|
m_screen->addTimer(m_disableJob, 5.0);
|
|
|
|
}
|
|
|
|
else if ((!m_disabled || m_suppressDisable) && m_disableJobInstalled) {
|
|
|
|
m_disableJobInstalled = false;
|
|
|
|
m_screen->removeTimer(m_disableJob);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-23 15:43:40 +00:00
|
|
|
void
|
|
|
|
CXWindowsScreenSaver::disableCallback(void*)
|
|
|
|
{
|
|
|
|
// send fake mouse motion directly to xscreensaver
|
|
|
|
if (m_xscreensaver != None) {
|
|
|
|
XEvent event;
|
|
|
|
event.xmotion.type = MotionNotify;
|
|
|
|
event.xmotion.display = m_display;
|
|
|
|
event.xmotion.window = m_xscreensaver;
|
|
|
|
event.xmotion.root = DefaultRootWindow(m_display);
|
|
|
|
event.xmotion.subwindow = None;
|
|
|
|
event.xmotion.time = CurrentTime;
|
|
|
|
event.xmotion.x = 0;
|
|
|
|
event.xmotion.y = 0;
|
|
|
|
event.xmotion.x_root = 0;
|
|
|
|
event.xmotion.y_root = 0;
|
|
|
|
event.xmotion.state = 0;
|
|
|
|
event.xmotion.is_hint = NotifyNormal;
|
|
|
|
event.xmotion.same_screen = True;
|
|
|
|
|
|
|
|
CXWindowsUtil::CErrorLock lock(m_display);
|
|
|
|
XSendEvent(m_display, m_xscreensaver, False, 0, &event);
|
|
|
|
}
|
|
|
|
}
|