2001-11-11 21:15:30 +00:00
|
|
|
#ifndef CXWINDOWSSCREEN_H
|
|
|
|
#define CXWINDOWSSCREEN_H
|
|
|
|
|
2001-11-25 18:32:41 +00:00
|
|
|
#include "CClipboard.h"
|
2001-11-11 21:15:30 +00:00
|
|
|
#include "CMutex.h"
|
|
|
|
#include "BasicTypes.h"
|
2002-04-27 14:19:53 +00:00
|
|
|
#include "ClipboardTypes.h"
|
2001-11-11 21:15:30 +00:00
|
|
|
#include <X11/Xlib.h>
|
2001-11-25 22:20:41 +00:00
|
|
|
#include <map>
|
|
|
|
#include <list>
|
2001-11-11 21:15:30 +00:00
|
|
|
|
2001-11-13 23:34:12 +00:00
|
|
|
class CString;
|
2001-11-11 21:15:30 +00:00
|
|
|
|
|
|
|
class CXWindowsScreen {
|
|
|
|
public:
|
|
|
|
CXWindowsScreen();
|
|
|
|
virtual ~CXWindowsScreen();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
class CDisplayLock {
|
|
|
|
public:
|
|
|
|
CDisplayLock(const CXWindowsScreen*);
|
|
|
|
~CDisplayLock();
|
|
|
|
|
|
|
|
operator Display*() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const CMutex* m_mutex;
|
|
|
|
Display* m_display;
|
|
|
|
};
|
|
|
|
friend class CDisplayLock;
|
|
|
|
|
|
|
|
// open the X display. calls onOpenDisplay() after opening the display,
|
|
|
|
// getting the screen, its size, and root window. then it starts the
|
|
|
|
// event thread.
|
|
|
|
void openDisplay();
|
|
|
|
|
|
|
|
// destroy the window and close the display. calls onCloseDisplay()
|
|
|
|
// after the event thread has been shut down but before the display
|
|
|
|
// is closed.
|
|
|
|
void closeDisplay();
|
|
|
|
|
|
|
|
// get the opened screen, its size, its root window. to get the
|
|
|
|
// display create a CDisplayLock object passing this. while the
|
|
|
|
// object exists no other threads may access the display. do not
|
|
|
|
// save the Display* beyond the lifetime of the CDisplayLock.
|
|
|
|
int getScreen() const;
|
|
|
|
void getScreenSize(SInt32* w, SInt32* h) const;
|
|
|
|
Window getRoot() const;
|
|
|
|
|
|
|
|
// create a cursor that is transparent everywhere
|
|
|
|
Cursor createBlankCursor() const;
|
|
|
|
|
|
|
|
// wait for and get the next X event. cancellable.
|
2001-11-19 00:33:36 +00:00
|
|
|
bool getEvent(XEvent*) const;
|
|
|
|
|
|
|
|
// cause getEvent() to return false immediately and forever after
|
|
|
|
void doStop();
|
2001-11-11 21:15:30 +00:00
|
|
|
|
2002-04-27 14:19:53 +00:00
|
|
|
// determine the clipboard from the X selection. returns
|
|
|
|
// kClipboardEnd if no such clipboard.
|
|
|
|
ClipboardID getClipboardID(Atom selection);
|
|
|
|
|
2001-11-25 22:20:41 +00:00
|
|
|
// call when we lose the clipboard ownership (i.e. when we receive
|
|
|
|
// a SelectionClear event). returns true iff we've actually lost
|
|
|
|
// a selection we care about.
|
|
|
|
bool lostClipboard(Atom selection, Time timestamp);
|
|
|
|
|
|
|
|
// set the contents of the clipboard (i.e. primary selection)
|
2002-04-27 14:19:53 +00:00
|
|
|
bool setDisplayClipboard(ClipboardID,
|
|
|
|
const IClipboard* clipboard,
|
2001-11-25 18:32:41 +00:00
|
|
|
Window requestor, Time timestamp);
|
|
|
|
|
2001-11-13 23:34:12 +00:00
|
|
|
// copy the clipboard contents to clipboard. requestor must be a
|
|
|
|
// valid window; it will be used to receive the transfer. timestamp
|
|
|
|
// should be the timestamp of the provoking event and not CurrentTime.
|
2002-04-27 14:19:53 +00:00
|
|
|
void getDisplayClipboard(ClipboardID,
|
|
|
|
IClipboard* clipboard,
|
2001-11-13 23:34:12 +00:00
|
|
|
Window requestor, Time timestamp) const;
|
|
|
|
|
2001-11-25 18:32:41 +00:00
|
|
|
// add a selection request to the request list
|
|
|
|
void addClipboardRequest(
|
|
|
|
Window owner, Window requestor,
|
|
|
|
Atom selection, Atom target,
|
|
|
|
Atom property, Time time);
|
|
|
|
|
|
|
|
// continue processing a selection request
|
|
|
|
void processClipboardRequest(Window window,
|
|
|
|
Atom property, Time time);
|
|
|
|
|
2002-04-25 10:43:53 +00:00
|
|
|
// terminate a selection request
|
|
|
|
void destroyClipboardRequest(Window window);
|
|
|
|
|
2002-04-28 00:46:15 +00:00
|
|
|
// get the current server time
|
|
|
|
Time getCurrentTime(Window) const;
|
|
|
|
|
2001-11-11 21:15:30 +00:00
|
|
|
// called by openDisplay() to allow subclasses to prepare the display
|
|
|
|
virtual void onOpenDisplay() = 0;
|
|
|
|
|
|
|
|
// called by closeDisplay() to
|
|
|
|
virtual void onCloseDisplay() = 0;
|
|
|
|
|
2001-11-13 23:34:12 +00:00
|
|
|
private:
|
2001-11-25 22:20:41 +00:00
|
|
|
struct CPropertyNotifyInfo {
|
2001-11-13 23:34:12 +00:00
|
|
|
public:
|
|
|
|
Window m_window;
|
|
|
|
Atom m_property;
|
|
|
|
};
|
2001-11-25 22:20:41 +00:00
|
|
|
struct CClipboardRequest {
|
|
|
|
public:
|
|
|
|
CString m_data;
|
|
|
|
UInt32 m_sent;
|
|
|
|
Window m_requestor;
|
|
|
|
Atom m_property;
|
|
|
|
Atom m_type;
|
2001-11-26 22:09:53 +00:00
|
|
|
int m_size;
|
2001-11-25 22:20:41 +00:00
|
|
|
};
|
|
|
|
typedef std::list<CClipboardRequest*> CRequestList;
|
|
|
|
typedef std::map<Window, CRequestList*> CRequestMap;
|
2001-11-13 23:34:12 +00:00
|
|
|
|
|
|
|
bool getDisplayClipboard(Atom selection, Atom type,
|
|
|
|
Window requestor, Time timestamp,
|
|
|
|
Atom* outputType, CString* data) const;
|
|
|
|
bool getData(Window, Atom property,
|
|
|
|
Atom* type, SInt32* datumSize,
|
|
|
|
CString* data) const;
|
|
|
|
IClipboard::EFormat getFormat(Atom) const;
|
|
|
|
static Bool findSelectionNotify(Display*,
|
|
|
|
XEvent* xevent, XPointer arg);
|
|
|
|
static Bool findPropertyNotify(Display*,
|
|
|
|
XEvent* xevent, XPointer arg);
|
|
|
|
|
2002-04-27 14:19:53 +00:00
|
|
|
bool sendClipboardData(ClipboardID, Window requestor,
|
|
|
|
Atom target, Atom property, Time time);
|
|
|
|
bool sendClipboardMultiple(ClipboardID, Window requestor,
|
2001-11-25 18:32:41 +00:00
|
|
|
Atom property, Time time);
|
2002-04-27 14:19:53 +00:00
|
|
|
bool sendClipboardTargets(ClipboardID, Window requestor,
|
2001-11-25 22:20:41 +00:00
|
|
|
Atom property, Time time);
|
2002-04-27 14:19:53 +00:00
|
|
|
bool sendClipboardTimestamp(ClipboardID, Window requestor,
|
2001-11-25 18:32:41 +00:00
|
|
|
Atom property, Time time);
|
2002-04-28 00:46:15 +00:00
|
|
|
void sendNotify(Window requestor, Atom selection,
|
2002-04-27 14:19:53 +00:00
|
|
|
Atom target, Atom property, Time time);
|
2002-04-28 00:46:15 +00:00
|
|
|
bool wasOwnedAtTime(ClipboardID, Window, Time) const;
|
|
|
|
Time getCurrentTimeNoLock(Window) const;
|
2001-11-25 18:32:41 +00:00
|
|
|
|
2001-11-11 21:15:30 +00:00
|
|
|
private:
|
2002-04-28 00:46:15 +00:00
|
|
|
class CClipboardInfo {
|
|
|
|
public:
|
|
|
|
CClipboardInfo();
|
|
|
|
|
2002-04-27 14:19:53 +00:00
|
|
|
public:
|
|
|
|
// the contents of the clipboard
|
|
|
|
CClipboard m_clipboard;
|
|
|
|
|
|
|
|
// when we got the clipboard and when we lost it
|
|
|
|
Time m_gotClipboard;
|
|
|
|
Time m_lostClipboard;
|
|
|
|
|
|
|
|
// the request queues
|
|
|
|
CRequestMap m_requests;
|
|
|
|
};
|
|
|
|
|
2001-11-11 21:15:30 +00:00
|
|
|
Display* m_display;
|
|
|
|
int m_screen;
|
|
|
|
Window m_root;
|
|
|
|
SInt32 m_w, m_h;
|
2001-11-19 00:33:36 +00:00
|
|
|
bool m_stop;
|
2001-11-11 21:15:30 +00:00
|
|
|
|
2001-11-13 23:34:12 +00:00
|
|
|
// atoms we'll need
|
|
|
|
Atom m_atomTargets;
|
2001-11-25 18:32:41 +00:00
|
|
|
Atom m_atomMultiple;
|
2001-11-25 22:20:41 +00:00
|
|
|
Atom m_atomTimestamp;
|
|
|
|
Atom m_atomAtom;
|
|
|
|
Atom m_atomAtomPair;
|
|
|
|
Atom m_atomInteger;
|
2001-11-13 23:34:12 +00:00
|
|
|
Atom m_atomData;
|
|
|
|
Atom m_atomINCR;
|
2001-11-26 22:09:53 +00:00
|
|
|
Atom m_atomString;
|
2001-11-13 23:34:12 +00:00
|
|
|
Atom m_atomText;
|
|
|
|
Atom m_atomCompoundText;
|
2002-04-27 14:19:53 +00:00
|
|
|
Atom m_atomClipboard[kClipboardEnd];
|
2002-04-28 00:46:15 +00:00
|
|
|
Atom m_atomSynergyTime;
|
2001-11-13 23:34:12 +00:00
|
|
|
|
2002-04-27 14:19:53 +00:00
|
|
|
// clipboard info
|
2002-04-28 00:46:15 +00:00
|
|
|
CClipboardInfo m_clipboards[kClipboardEnd];
|
2001-11-25 22:20:41 +00:00
|
|
|
|
2001-11-11 21:15:30 +00:00
|
|
|
// X is not thread safe
|
|
|
|
CMutex m_mutex;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|