2002-08-02 23:57:46 +04: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.
|
|
|
|
*/
|
|
|
|
|
2001-11-12 00:15:30 +03:00
|
|
|
#ifndef CXWINDOWSSCREEN_H
|
|
|
|
#define CXWINDOWSSCREEN_H
|
|
|
|
|
2002-07-14 02:00:38 +04:00
|
|
|
#include "IScreen.h"
|
2002-04-29 17:31:44 +04:00
|
|
|
#include "CMutex.h"
|
2002-06-23 19:43:40 +04:00
|
|
|
#include "CStopwatch.h"
|
|
|
|
#include "stdvector.h"
|
2002-06-19 15:23:49 +04:00
|
|
|
#if defined(X_DISPLAY_MISSING)
|
|
|
|
# error X11 is required to build synergy
|
|
|
|
#else
|
|
|
|
# include <X11/Xlib.h>
|
|
|
|
#endif
|
2002-06-23 19:43:40 +04:00
|
|
|
#include <algorithm>
|
|
|
|
#include <functional>
|
2001-11-12 00:15:30 +03:00
|
|
|
|
2002-06-23 19:43:40 +04:00
|
|
|
class IJob;
|
2002-07-14 02:00:38 +04:00
|
|
|
class IScreenEventHandler;
|
|
|
|
class IScreenReceiver;
|
2002-05-27 20:22:59 +04:00
|
|
|
class CXWindowsClipboard;
|
2002-06-22 23:20:21 +04:00
|
|
|
class CXWindowsScreenSaver;
|
2001-11-12 00:15:30 +03:00
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
// X11 event
|
2002-07-13 00:41:23 +04:00
|
|
|
class CEvent {
|
|
|
|
public:
|
|
|
|
XEvent m_event;
|
|
|
|
SInt32 m_result;
|
|
|
|
};
|
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
// X11 screen implementation
|
2002-07-14 02:00:38 +04:00
|
|
|
class CXWindowsScreen : public IScreen {
|
2002-04-29 18:40:01 +04:00
|
|
|
public:
|
2002-07-14 02:00:38 +04:00
|
|
|
CXWindowsScreen(IScreenReceiver*, IScreenEventHandler*);
|
2001-11-12 00:15:30 +03:00
|
|
|
virtual ~CXWindowsScreen();
|
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! @name manipulators
|
|
|
|
//@{
|
2002-06-23 19:43:40 +04:00
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Add timer
|
|
|
|
/*!
|
|
|
|
Add a job to invoke every timeout seconds. The job is
|
|
|
|
called with the display locked. If a job timeout expires twice
|
|
|
|
or more before the job can be called then the job is called
|
|
|
|
just once. The caller retains ownership of the job.
|
|
|
|
*/
|
2002-06-23 19:43:40 +04:00
|
|
|
void addTimer(IJob*, double timeout);
|
2002-07-29 21:03:55 +04:00
|
|
|
|
|
|
|
//! Remove timer
|
|
|
|
/*!
|
|
|
|
Remove a job. The caller retains ownership of the job.
|
|
|
|
*/
|
2002-06-23 19:43:40 +04:00
|
|
|
void removeTimer(IJob*);
|
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Set window
|
|
|
|
/*!
|
|
|
|
Set the window (created by the subclass). This performs some
|
|
|
|
initialization and saves the window in case it's needed later.
|
|
|
|
*/
|
2002-07-14 02:00:38 +04:00
|
|
|
void setWindow(Window);
|
2001-11-12 00:15:30 +03:00
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//@}
|
|
|
|
//! @name accessors
|
|
|
|
//@{
|
2002-07-13 00:41:23 +04:00
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Get window
|
|
|
|
/*!
|
|
|
|
Returns the root window of the screen.
|
|
|
|
*/
|
2001-11-12 00:15:30 +03:00
|
|
|
Window getRoot() const;
|
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Get transparent cursor
|
|
|
|
/*!
|
|
|
|
Returns a cursor that is transparent everywhere.
|
|
|
|
*/
|
2002-07-11 22:58:49 +04:00
|
|
|
Cursor getBlankCursor() const;
|
2001-11-12 00:15:30 +03:00
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//@}
|
|
|
|
|
2002-07-14 02:00:38 +04:00
|
|
|
// IScreen overrides
|
|
|
|
void open();
|
|
|
|
void mainLoop();
|
|
|
|
void exitMainLoop();
|
|
|
|
void close();
|
|
|
|
bool setClipboard(ClipboardID, const IClipboard*);
|
|
|
|
void checkClipboards();
|
2002-07-15 19:01:36 +04:00
|
|
|
void openScreensaver(bool notify);
|
|
|
|
void closeScreensaver();
|
2002-07-14 02:00:38 +04:00
|
|
|
void screensaver(bool activate);
|
|
|
|
void syncDesktop();
|
|
|
|
bool getClipboard(ClipboardID, IClipboard*) const;
|
|
|
|
void getShape(SInt32&, SInt32&, SInt32&, SInt32&) const;
|
|
|
|
void getCursorPos(SInt32&, SInt32&) const;
|
|
|
|
void getCursorCenter(SInt32&, SInt32&) const;
|
2002-07-13 00:41:23 +04:00
|
|
|
|
2002-07-14 02:00:38 +04:00
|
|
|
private:
|
|
|
|
// update screen size cache
|
|
|
|
void updateScreenShape();
|
2001-11-12 00:15:30 +03:00
|
|
|
|
2002-07-14 02:00:38 +04:00
|
|
|
// process events before dispatching to receiver
|
|
|
|
bool onPreDispatch(CEvent* event);
|
2002-05-27 20:22:59 +04:00
|
|
|
|
2002-07-11 22:58:49 +04:00
|
|
|
// create the transparent cursor
|
|
|
|
void createBlankCursor();
|
|
|
|
|
2002-06-23 19:43:40 +04:00
|
|
|
// remove a timer without locking
|
|
|
|
void removeTimerNoLock(IJob*);
|
|
|
|
|
|
|
|
// process timers
|
|
|
|
bool processTimers();
|
|
|
|
|
2002-05-27 20:22:59 +04:00
|
|
|
// determine the clipboard from the X selection. returns
|
|
|
|
// kClipboardEnd if no such clipboard.
|
|
|
|
ClipboardID getClipboardID(Atom selection) const;
|
2002-05-01 19:31:47 +04:00
|
|
|
|
2002-05-27 20:22:59 +04:00
|
|
|
// continue processing a selection request
|
|
|
|
void processClipboardRequest(Window window,
|
2002-06-11 02:06:45 +04:00
|
|
|
Time time, Atom property);
|
2002-05-01 19:31:47 +04:00
|
|
|
|
2002-05-27 20:22:59 +04:00
|
|
|
// terminate a selection request
|
|
|
|
void destroyClipboardRequest(Window window);
|
2002-04-27 18:19:53 +04:00
|
|
|
|
2002-06-03 17:45:30 +04:00
|
|
|
// X I/O error handler
|
|
|
|
static int ioErrorHandler(Display*);
|
|
|
|
|
2002-05-27 20:22:59 +04:00
|
|
|
private:
|
2002-06-23 19:43:40 +04:00
|
|
|
// a priority queue will direct access to the elements
|
|
|
|
template <class T, class Container = std::vector<T>,
|
|
|
|
class Compare = std::greater<typename Container::value_type> >
|
|
|
|
class CPriorityQueue {
|
|
|
|
public:
|
|
|
|
typedef typename Container::value_type value_type;
|
|
|
|
typedef typename Container::size_type size_type;
|
|
|
|
typedef typename Container::iterator iterator;
|
|
|
|
typedef Container container_type;
|
|
|
|
|
|
|
|
CPriorityQueue() { }
|
|
|
|
CPriorityQueue(Container& swappedIn);
|
|
|
|
~CPriorityQueue() { }
|
|
|
|
|
|
|
|
// manipulators
|
|
|
|
|
|
|
|
void push(const value_type& v)
|
|
|
|
{
|
|
|
|
c.push_back(v);
|
|
|
|
std::push_heap(c.begin(), c.end(), comp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pop()
|
|
|
|
{
|
|
|
|
std::pop_heap(c.begin(), c.end(), comp);
|
|
|
|
c.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
iterator begin()
|
|
|
|
{
|
|
|
|
return c.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
iterator end()
|
|
|
|
{
|
|
|
|
return c.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
void swap(CPriorityQueue<T, Container, Compare>& q)
|
|
|
|
{
|
|
|
|
c.swap(q.c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void swap(Container& c2)
|
|
|
|
{
|
|
|
|
c.swap(c2);
|
|
|
|
std::make_heap(c.begin(), c.end(), comp);
|
|
|
|
}
|
|
|
|
|
|
|
|
// accessors
|
|
|
|
|
|
|
|
bool empty() const
|
|
|
|
{
|
|
|
|
return c.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_type size() const
|
|
|
|
{
|
|
|
|
return c.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
const value_type&
|
|
|
|
top() const
|
|
|
|
{
|
|
|
|
return c.front();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Container c;
|
|
|
|
Compare comp;
|
|
|
|
};
|
|
|
|
|
|
|
|
// a timer priority queue element
|
|
|
|
class CTimer {
|
|
|
|
public:
|
|
|
|
CTimer(IJob* job, double timeout);
|
|
|
|
~CTimer();
|
|
|
|
|
|
|
|
// manipulators
|
|
|
|
|
|
|
|
void run();
|
|
|
|
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
CTimer& operator-=(double);
|
|
|
|
|
|
|
|
// accessors
|
|
|
|
|
|
|
|
IJob* getJob() const
|
|
|
|
{
|
|
|
|
return m_job;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator double() const;
|
|
|
|
|
|
|
|
bool operator<(const CTimer&) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
IJob* m_job;
|
|
|
|
double m_timeout;
|
|
|
|
double m_time;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2002-07-14 02:00:38 +04:00
|
|
|
friend class CDisplayLock;
|
|
|
|
|
2002-06-23 19:43:40 +04:00
|
|
|
typedef CPriorityQueue<CTimer> CTimerPriorityQueue;
|
|
|
|
|
2002-07-14 02:00:38 +04:00
|
|
|
// X is not thread safe
|
|
|
|
CMutex m_mutex;
|
|
|
|
|
2001-11-12 00:15:30 +03:00
|
|
|
Display* m_display;
|
|
|
|
Window m_root;
|
2002-07-14 02:00:38 +04:00
|
|
|
bool m_stop;
|
|
|
|
|
|
|
|
IScreenReceiver* m_receiver;
|
|
|
|
IScreenEventHandler* m_eventHandler;
|
|
|
|
Window m_window;
|
|
|
|
|
2002-06-19 21:03:29 +04:00
|
|
|
SInt32 m_x, m_y;
|
2001-11-12 00:15:30 +03:00
|
|
|
SInt32 m_w, m_h;
|
|
|
|
|
2002-05-27 20:22:59 +04:00
|
|
|
// clipboards
|
|
|
|
CXWindowsClipboard* m_clipboard[kClipboardEnd];
|
2001-11-26 01:20:41 +03:00
|
|
|
|
2002-07-11 22:58:49 +04:00
|
|
|
// the transparent cursor
|
|
|
|
Cursor m_cursor;
|
|
|
|
|
2002-07-14 02:00:38 +04:00
|
|
|
// screen saver stuff
|
|
|
|
CXWindowsScreenSaver* m_screensaver;
|
|
|
|
bool m_screensaverNotify;
|
|
|
|
Atom m_atomScreensaver;
|
2002-06-22 23:20:21 +04:00
|
|
|
|
2002-06-23 19:43:40 +04:00
|
|
|
// timers, the stopwatch used to time, and a mutex for the timers
|
|
|
|
CTimerPriorityQueue m_timers;
|
|
|
|
CStopwatch m_time;
|
|
|
|
CMutex m_timersMutex;
|
|
|
|
|
2002-06-03 17:45:30 +04:00
|
|
|
// pointer to (singleton) screen. this is only needed by
|
|
|
|
// ioErrorHandler().
|
|
|
|
static CXWindowsScreen* s_screen;
|
2001-11-12 00:15:30 +03:00
|
|
|
};
|
|
|
|
|
2002-07-14 02:00:38 +04:00
|
|
|
class CDisplayLock {
|
|
|
|
public:
|
|
|
|
CDisplayLock(const CXWindowsScreen*);
|
|
|
|
~CDisplayLock();
|
|
|
|
|
|
|
|
operator Display*() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const CMutex* m_mutex;
|
|
|
|
Display* m_display;
|
|
|
|
};
|
|
|
|
|
2001-11-12 00:15:30 +03:00
|
|
|
#endif
|