2001-11-12 00:15:30 +03:00
|
|
|
#ifndef CXWINDOWSSCREEN_H
|
|
|
|
#define CXWINDOWSSCREEN_H
|
|
|
|
|
2002-04-27 18:19:53 +04:00
|
|
|
#include "ClipboardTypes.h"
|
2002-04-29 17:31:44 +04:00
|
|
|
#include "CMutex.h"
|
2001-11-12 00:15:30 +03:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
|
2002-05-27 20:22:59 +04:00
|
|
|
class IClipboard;
|
|
|
|
class CXWindowsClipboard;
|
2001-11-12 00:15:30 +03:00
|
|
|
|
|
|
|
class CXWindowsScreen {
|
2002-04-29 18:40:01 +04:00
|
|
|
public:
|
2001-11-12 00:15:30 +03:00
|
|
|
CXWindowsScreen();
|
|
|
|
virtual ~CXWindowsScreen();
|
|
|
|
|
2002-04-29 18:40:01 +04:00
|
|
|
protected:
|
2001-11-12 00:15:30 +03:00
|
|
|
class CDisplayLock {
|
2002-04-29 18:40:01 +04:00
|
|
|
public:
|
2001-11-12 00:15:30 +03:00
|
|
|
CDisplayLock(const CXWindowsScreen*);
|
|
|
|
~CDisplayLock();
|
|
|
|
|
|
|
|
operator Display*() const;
|
|
|
|
|
2002-04-29 18:40:01 +04:00
|
|
|
private:
|
2001-11-12 00:15:30 +03:00
|
|
|
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 03:33:36 +03:00
|
|
|
bool getEvent(XEvent*) const;
|
|
|
|
|
2002-06-03 17:45:30 +04:00
|
|
|
// cause getEvent() to return false immediately and forever after.
|
|
|
|
// the caller must have locked the display.
|
2001-11-19 03:33:36 +03:00
|
|
|
void doStop();
|
2001-11-12 00:15:30 +03:00
|
|
|
|
2001-11-26 01:20:41 +03:00
|
|
|
// set the contents of the clipboard (i.e. primary selection)
|
2002-04-27 18:19:53 +04:00
|
|
|
bool setDisplayClipboard(ClipboardID,
|
2002-06-11 02:06:45 +04:00
|
|
|
const IClipboard* clipboard);
|
2001-11-25 21:32:41 +03:00
|
|
|
|
2002-05-27 20:22:59 +04:00
|
|
|
// copy the clipboard contents to clipboard
|
|
|
|
bool getDisplayClipboard(ClipboardID,
|
2002-06-11 02:06:45 +04:00
|
|
|
IClipboard* clipboard) const;
|
2002-04-28 04:46:15 +04:00
|
|
|
|
2002-06-03 17:45:30 +04:00
|
|
|
// called by openDisplay() to allow subclasses to prepare the display.
|
|
|
|
// the display is locked and passed to the subclass.
|
|
|
|
virtual void onOpenDisplay(Display*) = 0;
|
2001-11-12 00:15:30 +03:00
|
|
|
|
2002-05-27 20:22:59 +04:00
|
|
|
// called by openDisplay() after onOpenDisplay() to create each clipboard
|
|
|
|
virtual CXWindowsClipboard*
|
|
|
|
createClipboard(ClipboardID) = 0;
|
|
|
|
|
2002-06-03 17:45:30 +04:00
|
|
|
// called by closeDisplay() to allow subclasses to clean up the display.
|
|
|
|
// the display is locked and passed to the subclass. note that the
|
|
|
|
// display may be NULL if the display has unexpectedly disconnected.
|
|
|
|
virtual void onCloseDisplay(Display*) = 0;
|
|
|
|
|
|
|
|
// called if the display is unexpectedly closing. default does nothing.
|
|
|
|
virtual void onUnexpectedClose();
|
2001-11-12 00:15:30 +03:00
|
|
|
|
2002-05-27 20:22:59 +04:00
|
|
|
// called when a clipboard is lost
|
|
|
|
virtual void onLostClipboard(ClipboardID) = 0;
|
|
|
|
|
2002-04-29 18:40:01 +04:00
|
|
|
private:
|
2002-05-27 20:22:59 +04:00
|
|
|
// internal event processing
|
|
|
|
bool processEvent(XEvent*);
|
2002-04-28 04:46:15 +04:00
|
|
|
|
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:
|
2001-11-12 00:15:30 +03:00
|
|
|
Display* m_display;
|
|
|
|
int m_screen;
|
|
|
|
Window m_root;
|
|
|
|
SInt32 m_w, m_h;
|
2001-11-19 03:33:36 +03:00
|
|
|
bool m_stop;
|
2001-11-12 00:15:30 +03:00
|
|
|
|
2002-05-27 20:22:59 +04:00
|
|
|
// clipboards
|
|
|
|
CXWindowsClipboard* m_clipboard[kClipboardEnd];
|
2001-11-26 01:20:41 +03:00
|
|
|
|
2001-11-12 00:15:30 +03:00
|
|
|
// X is not thread safe
|
|
|
|
CMutex m_mutex;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|