checkpoint. adding screen saver support. only on X so far

and untested.  also some known problems:  not detecting an
xscreensaver started after us and not detecting built-in
screen saver activation (not sure if we can without using
ugly extensions).
This commit is contained in:
crs
2002-06-22 19:20:21 +00:00
parent 4e37691a9c
commit 504bfa2def
16 changed files with 532 additions and 30 deletions

View File

@@ -709,6 +709,66 @@ CServer::onMouseWheel(SInt32 delta)
}
}
void
CServer::onScreenSaver(bool activated)
{
log((CLOG_DEBUG "onScreenSaver %s", activated ? "activated" : "deactivated"));
CLock lock(&m_mutex);
if (activated) {
// save current screen and position
m_activeSaver = m_active;
m_xSaver = m_x;
m_ySaver = m_y;
// jump to primary screen
if (m_active != m_primaryInfo) {
// FIXME -- should have separate "center" pixel reported by screen
m_x = m_primaryInfo->m_x + (m_primaryInfo->m_w >> 1);
m_y = m_primaryInfo->m_y + (m_primaryInfo->m_h >> 1);
m_active = m_primaryInfo;
m_primary->enter(m_x, m_y);
}
}
else {
// jump back to previous screen and position. we must check
// that the position is still valid since the screen may have
// changed resolutions while the screen saver was running.
if (m_activeSaver != NULL && m_activeSaver != m_primaryInfo) {
// check position
CScreenInfo* screen = m_activeSaver;
if (m_xSaver < screen->m_x + screen->m_zoneSize) {
m_xSaver = screen->m_x + screen->m_zoneSize;
}
else if (m_xSaver >= screen->m_x +
screen->m_w - screen->m_zoneSize) {
m_xSaver = screen->m_x + screen->m_w - screen->m_zoneSize - 1;
}
if (m_ySaver < screen->m_y + screen->m_zoneSize) {
m_ySaver = screen->m_y + screen->m_zoneSize;
}
else if (m_ySaver >= screen->m_y +
screen->m_h - screen->m_zoneSize) {
m_ySaver = screen->m_y + screen->m_h - screen->m_zoneSize - 1;
}
// now jump
switchScreen(screen, m_xSaver, m_ySaver);
}
// reset state
m_activeSaver = NULL;
}
// send message to all secondary screens
for (CScreenList::const_iterator index = m_screens.begin();
index != m_screens.end(); ++index) {
if (index->second->m_protocol != NULL) {
index->second->m_protocol->sendScreenSaver(activated);
}
}
}
bool
CServer::isLockedToScreen() const
{
@@ -1557,6 +1617,7 @@ CServer::removeConnection(const CString& name)
// if this is active screen then we have to jump off of it
if (m_active == index->second && m_active != m_primaryInfo) {
// record new position (center of primary screen)
// FIXME -- should have separate "center" pixel reported by screen
m_x = m_primaryInfo->m_x + (m_primaryInfo->m_w >> 1);
m_y = m_primaryInfo->m_y + (m_primaryInfo->m_h >> 1);
@@ -1570,6 +1631,13 @@ CServer::removeConnection(const CString& name)
m_primary->enter(m_x, m_y);
}
// if this screen had the cursor when the screen saver activated
// then we can't switch back to it when the screen saver
// deactivates.
if (m_activeSaver == index->second) {
m_activeSaver = NULL;
}
// done with screen info
delete index->second;
m_screens.erase(index);

View File

@@ -58,6 +58,7 @@ public:
void onMouseMoveSecondary(SInt32 dx, SInt32 dy);
void onMouseWheel(SInt32 delta);
void grabClipboard(ClipboardID);
void onScreenSaver(bool activated);
// handle updates from primary
void setInfo(SInt32 xScreen, SInt32 yScreen,
@@ -207,6 +208,7 @@ private:
CMutex m_mutex;
// the name of the primary screen
CString m_name;
double m_bindTimeout;
@@ -214,8 +216,10 @@ private:
ISocketFactory* m_socketFactory;
ISecurityFactory* m_securityFactory;
// running threads
CThreadList m_threads;
// the screens
IPrimaryScreen* m_primary;
CScreenList m_screens;
CScreenInfo* m_active;
@@ -227,10 +231,16 @@ private:
// current mouse position (in absolute secondary screen coordinates)
SInt32 m_x, m_y;
// current configuration
CConfig m_config;
// clipboard cache
CClipboardInfo m_clipboards[kClipboardEnd];
// state saved when screen saver activates
CScreenInfo* m_activeSaver;
SInt32 m_xSaver, m_ySaver;
// HTTP request processing stuff
CHTTPServer* m_httpServer;
CCondVar<SInt32> m_httpAvailable;

View File

@@ -1,6 +1,7 @@
#include "CXWindowsPrimaryScreen.h"
#include "CServer.h"
#include "CXWindowsClipboard.h"
#include "CXWindowsScreenSaver.h"
#include "CXWindowsUtil.h"
#include "CThread.h"
#include "CLog.h"
@@ -60,6 +61,14 @@ CXWindowsPrimaryScreen::run()
}
break;
case ClientMessage:
if (xevent.xclient.message_type == m_atomScreenSaver ||
xevent.xclient.format == 32) {
// screen saver activation/deactivation event
m_server->onScreenSaver(xevent.xclient.data.l[0] != 0);
}
break;
case KeyPress:
{
log((CLOG_DEBUG1 "event: KeyPress code=%d, state=0x%04x", xevent.xkey.keycode, xevent.xkey.state));
@@ -267,6 +276,10 @@ CXWindowsPrimaryScreen::open(CServer* server)
{
CDisplayLock display(this);
// get notified of screen saver activation/deactivation
m_atomScreenSaver = XInternAtom(display, "SCREENSAVER", False);
getScreenSaver()->setNotify(m_window);
// update key state
updateModifierMap(display);
@@ -298,6 +311,10 @@ CXWindowsPrimaryScreen::close()
{
assert(m_server != NULL);
// stop being notified of screen saver activation/deactivation
getScreenSaver()->setNotify(None);
m_atomScreenSaver = None;
// close the display
closeDisplay();

View File

@@ -62,6 +62,9 @@ private:
bool m_active;
Window m_window;
// atom for screen saver messages
Atom m_atomScreenSaver;
// note toggle keys that toggle on up/down (false) or on
// transition (true)
bool m_numLockHalfDuplex;