checkpoint. changed clipboard model. the clipboard can only

be accessed now between open()/close().  ownership of the
clipboard is asserted via the empty() method.  this parallels
the win32 model (but the win32 code hasn't been updated yet).

refactored X11 clipboard code.  moved the bulk of it into
CXWindowsClipboard and moved some comment event handling into
CXWindowsScreen.  changed how requests are processed into a
hopefully easier to understand model.  added support for getting
clipboard from and sending clipboard to motif (or at least
lesstif) clients.  sending to lesstif required a hack to work
around an apparent bug in lesstif.
This commit is contained in:
crs 2002-05-27 16:22:59 +00:00
parent 097882b71c
commit 854d2c7fbf
12 changed files with 1800 additions and 1182 deletions

View File

@ -1,4 +1,6 @@
#include "CXWindowsSecondaryScreen.h" #include "CXWindowsSecondaryScreen.h"
#include "CXWindowsClipboard.h"
#include "CXWindowsUtil.h"
#include "CClient.h" #include "CClient.h"
#include "CThread.h" #include "CThread.h"
#include "CLog.h" #include "CLog.h"
@ -57,71 +59,6 @@ void CXWindowsSecondaryScreen::run()
XUnmapWindow(display, m_window); XUnmapWindow(display, m_window);
break; break;
} }
case SelectionClear:
// we just lost the selection. that means someone else
// grabbed the selection so this screen is now the
// selection owner. report that to the server.
if (lostClipboard(xevent.xselectionclear.selection,
xevent.xselectionclear.time)) {
m_client->onClipboardChanged(getClipboardID(
xevent.xselectionclear.selection));
}
break;
case SelectionNotify:
// notification of selection transferred. we shouldn't
// get this here because we handle them in the selection
// retrieval methods. we'll just delete the property
// with the data (satisfying the usual ICCCM protocol).
if (xevent.xselection.property != None) {
CDisplayLock display(this);
XDeleteProperty(display, m_window, xevent.xselection.property);
}
break;
case SelectionRequest:
// somebody is asking for clipboard data
if (xevent.xselectionrequest.owner == m_window) {
addClipboardRequest(m_window,
xevent.xselectionrequest.requestor,
xevent.xselectionrequest.selection,
xevent.xselectionrequest.target,
xevent.xselectionrequest.property,
xevent.xselectionrequest.time);
}
else {
// unknown window. return failure.
CDisplayLock display(this);
XEvent event;
event.xselection.type = SelectionNotify;
event.xselection.display = display;
event.xselection.requestor = xevent.xselectionrequest.requestor;
event.xselection.selection = xevent.xselectionrequest.selection;
event.xselection.target = xevent.xselectionrequest.target;
event.xselection.property = None;
event.xselection.time = xevent.xselectionrequest.time;
XSendEvent(display, xevent.xselectionrequest.requestor,
False, 0, &event);
}
break;
case PropertyNotify:
// clipboard transfers involve property changes so forward
// the event to the superclass. we only care about the
// deletion of properties.
if (xevent.xproperty.state == PropertyDelete) {
processClipboardRequest(xevent.xproperty.window,
xevent.xproperty.atom,
xevent.xproperty.time);
}
break;
case DestroyNotify:
// looks like one of the windows that requested a clipboard
// transfer has gone bye-bye.
destroyClipboardRequest(xevent.xdestroywindow.window);
break;
} }
} }
} }
@ -315,12 +252,12 @@ void CXWindowsSecondaryScreen::mouseWheel(SInt32 delta)
void CXWindowsSecondaryScreen::setClipboard( void CXWindowsSecondaryScreen::setClipboard(
ClipboardID id, const IClipboard* clipboard) ClipboardID id, const IClipboard* clipboard)
{ {
setDisplayClipboard(id, clipboard, m_window, getCurrentTime(m_window)); setDisplayClipboard(id, clipboard);
} }
void CXWindowsSecondaryScreen::grabClipboard(ClipboardID id) void CXWindowsSecondaryScreen::grabClipboard(ClipboardID id)
{ {
setDisplayClipboard(id, NULL, m_window, getCurrentTime(m_window)); setDisplayClipboard(id, NULL);
} }
void CXWindowsSecondaryScreen::getMousePos( void CXWindowsSecondaryScreen::getMousePos(
@ -350,7 +287,7 @@ SInt32 CXWindowsSecondaryScreen::getJumpZoneSize() const
void CXWindowsSecondaryScreen::getClipboard( void CXWindowsSecondaryScreen::getClipboard(
ClipboardID id, IClipboard* clipboard) const ClipboardID id, IClipboard* clipboard) const
{ {
getDisplayClipboard(id, clipboard, m_window, getCurrentTime(m_window)); getDisplayClipboard(id, clipboard);
} }
void CXWindowsSecondaryScreen::onOpenDisplay() void CXWindowsSecondaryScreen::onOpenDisplay()
@ -381,6 +318,13 @@ void CXWindowsSecondaryScreen::onOpenDisplay()
leaveNoLock(display); leaveNoLock(display);
} }
CXWindowsClipboard* CXWindowsSecondaryScreen::createClipboard(
ClipboardID id)
{
CDisplayLock display(this);
return new CXWindowsClipboard(display, m_window, id);
}
void CXWindowsSecondaryScreen::onCloseDisplay() void CXWindowsSecondaryScreen::onCloseDisplay()
{ {
assert(m_window != None); assert(m_window != None);
@ -394,6 +338,13 @@ void CXWindowsSecondaryScreen::onCloseDisplay()
m_window = None; m_window = None;
} }
void CXWindowsSecondaryScreen::onLostClipboard(
ClipboardID id)
{
// tell client that the clipboard was grabbed locally
m_client->onClipboardChanged(id);
}
long CXWindowsSecondaryScreen::getEventMask(Window w) const long CXWindowsSecondaryScreen::getEventMask(Window w) const
{ {
if (w == m_window) if (w == m_window)

View File

@ -3,6 +3,7 @@
#include "CXWindowsScreen.h" #include "CXWindowsScreen.h"
#include "ISecondaryScreen.h" #include "ISecondaryScreen.h"
#include <map>
#include <vector> #include <vector>
class CXWindowsSecondaryScreen : public CXWindowsScreen, public ISecondaryScreen { class CXWindowsSecondaryScreen : public CXWindowsScreen, public ISecondaryScreen {
@ -35,7 +36,10 @@ public:
protected: protected:
// CXWindowsScreen overrides // CXWindowsScreen overrides
virtual void onOpenDisplay(); virtual void onOpenDisplay();
virtual CXWindowsClipboard*
createClipboard(ClipboardID);
virtual void onCloseDisplay(); virtual void onCloseDisplay();
virtual void onLostClipboard(ClipboardID);
virtual long getEventMask(Window) const; virtual long getEventMask(Window) const;
private: private:

View File

@ -1,4 +1,6 @@
#include "CXWindowsPrimaryScreen.h" #include "CXWindowsPrimaryScreen.h"
#include "CXWindowsClipboard.h"
#include "CXWindowsUtil.h"
#include "CServer.h" #include "CServer.h"
#include "CThread.h" #include "CThread.h"
#include "CLog.h" #include "CLog.h"
@ -171,71 +173,6 @@ void CXWindowsPrimaryScreen::run()
} }
break; break;
} }
case SelectionClear:
// we just lost the selection. that means someone else
// grabbed the selection so this screen is now the
// selection owner. report that to the server.
if (lostClipboard(xevent.xselectionclear.selection,
xevent.xselectionclear.time)) {
m_server->grabClipboard(getClipboardID(
xevent.xselectionclear.selection));
}
break;
case SelectionNotify:
// notification of selection transferred. we shouldn't
// get this here because we handle them in the selection
// retrieval methods. we'll just delete the property
// with the data (satisfying the usual ICCCM protocol).
if (xevent.xselection.property != None) {
CDisplayLock display(this);
XDeleteProperty(display, m_window, xevent.xselection.property);
}
break;
case SelectionRequest:
// somebody is asking for clipboard data
if (xevent.xselectionrequest.owner == m_window) {
addClipboardRequest(m_window,
xevent.xselectionrequest.requestor,
xevent.xselectionrequest.selection,
xevent.xselectionrequest.target,
xevent.xselectionrequest.property,
xevent.xselectionrequest.time);
}
else {
// unknown window. return failure.
CDisplayLock display(this);
XEvent event;
event.xselection.type = SelectionNotify;
event.xselection.display = display;
event.xselection.requestor = xevent.xselectionrequest.requestor;
event.xselection.selection = xevent.xselectionrequest.selection;
event.xselection.target = xevent.xselectionrequest.target;
event.xselection.property = None;
event.xselection.time = xevent.xselectionrequest.time;
XSendEvent(display, xevent.xselectionrequest.requestor,
False, 0, &event);
}
break;
case PropertyNotify:
// clipboard transfers involve property changes so forward
// the event to the superclass. we only care about the
// deletion of properties.
if (xevent.xproperty.state == PropertyDelete) {
processClipboardRequest(xevent.xproperty.window,
xevent.xproperty.atom,
xevent.xproperty.time);
}
break;
case DestroyNotify:
// looks like one of the windows that requested a clipboard
// transfer has gone bye-bye.
destroyClipboardRequest(xevent.xdestroywindow.window);
break;
} }
} }
} }
@ -394,12 +331,12 @@ void CXWindowsPrimaryScreen::warpCursorNoLock(
void CXWindowsPrimaryScreen::setClipboard( void CXWindowsPrimaryScreen::setClipboard(
ClipboardID id, const IClipboard* clipboard) ClipboardID id, const IClipboard* clipboard)
{ {
setDisplayClipboard(id, clipboard, m_window, getCurrentTime(m_window)); setDisplayClipboard(id, clipboard);
} }
void CXWindowsPrimaryScreen::grabClipboard(ClipboardID id) void CXWindowsPrimaryScreen::grabClipboard(ClipboardID id)
{ {
setDisplayClipboard(id, NULL, m_window, getCurrentTime(m_window)); setDisplayClipboard(id, NULL);
} }
void CXWindowsPrimaryScreen::getSize( void CXWindowsPrimaryScreen::getSize(
@ -416,7 +353,7 @@ SInt32 CXWindowsPrimaryScreen::getJumpZoneSize() const
void CXWindowsPrimaryScreen::getClipboard( void CXWindowsPrimaryScreen::getClipboard(
ClipboardID id, IClipboard* clipboard) const ClipboardID id, IClipboard* clipboard) const
{ {
getDisplayClipboard(id, clipboard, m_window, getCurrentTime(m_window)); getDisplayClipboard(id, clipboard);
} }
KeyModifierMask CXWindowsPrimaryScreen::getToggleMask() const KeyModifierMask CXWindowsPrimaryScreen::getToggleMask() const
@ -508,6 +445,13 @@ void CXWindowsPrimaryScreen::onOpenDisplay()
selectEvents(display, getRoot()); selectEvents(display, getRoot());
} }
CXWindowsClipboard* CXWindowsPrimaryScreen::createClipboard(
ClipboardID id)
{
CDisplayLock display(this);
return new CXWindowsClipboard(display, m_window, id);
}
void CXWindowsPrimaryScreen::onCloseDisplay() void CXWindowsPrimaryScreen::onCloseDisplay()
{ {
assert(m_window != None); assert(m_window != None);
@ -518,6 +462,13 @@ void CXWindowsPrimaryScreen::onCloseDisplay()
m_window = None; m_window = None;
} }
void CXWindowsPrimaryScreen::onLostClipboard(
ClipboardID id)
{
// tell server that the clipboard was grabbed locally
m_server->grabClipboard(id);
}
long CXWindowsPrimaryScreen::getEventMask(Window w) const long CXWindowsPrimaryScreen::getEventMask(Window w) const
{ {
if (w == m_window) if (w == m_window)

View File

@ -30,7 +30,10 @@ public:
protected: protected:
// CXWindowsScreen overrides // CXWindowsScreen overrides
virtual void onOpenDisplay(); virtual void onOpenDisplay();
virtual CXWindowsClipboard*
createClipboard(ClipboardID);
virtual void onCloseDisplay(); virtual void onCloseDisplay();
virtual void onLostClipboard(ClipboardID);
virtual long getEventMask(Window) const; virtual long getEventMask(Window) const;
private: private:

View File

@ -5,9 +5,10 @@
// CClipboard // CClipboard
// //
CClipboard::CClipboard() CClipboard::CClipboard() : m_open(false), m_owner(false)
{ {
open(0); open(0);
empty();
close(); close();
} }
@ -16,8 +17,10 @@ CClipboard::~CClipboard()
// do nothing // do nothing
} }
bool CClipboard::open(Time time) bool CClipboard::empty()
{ {
assert(m_open);
// clear all data // clear all data
for (SInt32 index = 0; index < kNumFormats; ++index) { for (SInt32 index = 0; index < kNumFormats; ++index) {
m_data[index] = ""; m_data[index] = "";
@ -25,60 +28,90 @@ bool CClipboard::open(Time time)
} }
// save time // save time
m_timeOwned = m_time;
// we're the owner now
m_owner = true;
return true;
}
void CClipboard::add(EFormat format, const CString& data)
{
assert(m_open);
assert(m_owner);
m_data[format] = data;
m_added[format] = true;
}
bool CClipboard::open(Time time) const
{
assert(!m_open);
m_open = true;
m_time = time; m_time = time;
return true; return true;
} }
void CClipboard::close() void CClipboard::close() const
{ {
// do nothing assert(m_open);
}
void CClipboard::add(EFormat format, const CString& data) m_open = false;
{
m_data[format] = data;
m_added[format] = true;
} }
CClipboard::Time CClipboard::getTime() const CClipboard::Time CClipboard::getTime() const
{ {
return m_time; return m_timeOwned;
} }
bool CClipboard::has(EFormat format) const bool CClipboard::has(EFormat format) const
{ {
assert(m_open);
return m_added[format]; return m_added[format];
} }
CString CClipboard::get(EFormat format) const CString CClipboard::get(EFormat format) const
{ {
assert(m_open);
return m_data[format]; return m_data[format];
} }
void CClipboard::copy(IClipboard* dst, const IClipboard* src) bool CClipboard::copy(IClipboard* dst, const IClipboard* src)
{ {
assert(dst != NULL); assert(dst != NULL);
assert(src != NULL); assert(src != NULL);
copy(dst, src, src->getTime()); return copy(dst, src, src->getTime());
} }
void CClipboard::copy(IClipboard* dst, bool CClipboard::copy(IClipboard* dst,
const IClipboard* src, Time time) const IClipboard* src, Time time)
{ {
assert(dst != NULL); assert(dst != NULL);
assert(src != NULL); assert(src != NULL);
if (dst->open(time)) { bool success = false;
for (SInt32 format = 0; format != IClipboard::kNumFormats; ++format) { if (src->open(time)) {
IClipboard::EFormat eFormat = (IClipboard::EFormat)format; if (dst->open(time)) {
if (src->has(eFormat)) { if (dst->empty()) {
dst->add(eFormat, src->get(eFormat)); for (SInt32 format = 0;
format != IClipboard::kNumFormats; ++format) {
IClipboard::EFormat eFormat = (IClipboard::EFormat)format;
if (src->has(eFormat)) {
dst->add(eFormat, src->get(eFormat));
}
}
success = true;
} }
dst->close();
} }
dst->close(); src->close();
} }
return success;
} }
void CClipboard::unmarshall(const CString& data, Time time) void CClipboard::unmarshall(const CString& data, Time time)
@ -87,6 +120,7 @@ void CClipboard::unmarshall(const CString& data, Time time)
// clear existing data // clear existing data
open(time); open(time);
empty();
// read the number of formats // read the number of formats
const UInt32 numFormats = readUInt32(index); const UInt32 numFormats = readUInt32(index);

View File

@ -24,9 +24,10 @@ public:
CString marshall() const; CString marshall() const;
// IClipboard overrides // IClipboard overrides
virtual bool open(Time); virtual bool empty();
virtual void close();
virtual void add(EFormat, const CString& data); virtual void add(EFormat, const CString& data);
virtual bool open(Time) const;
virtual void close() const;
virtual Time getTime() const; virtual Time getTime() const;
virtual bool has(EFormat) const; virtual bool has(EFormat) const;
virtual CString get(EFormat) const; virtual CString get(EFormat) const;
@ -37,15 +38,19 @@ public:
// clipboards can be of any concrete clipboard type (and // clipboards can be of any concrete clipboard type (and
// they don't have to be the same type). this also sets // they don't have to be the same type). this also sets
// the timestamp to time, if provided, or the time in src. // the timestamp to time, if provided, or the time in src.
static void copy(IClipboard* dst, const IClipboard* src); // returns true iff the copy succeeded.
static void copy(IClipboard* dst, const IClipboard* src, Time); static bool copy(IClipboard* dst, const IClipboard* src);
static bool copy(IClipboard* dst, const IClipboard* src, Time);
private: private:
UInt32 readUInt32(const char*) const; UInt32 readUInt32(const char*) const;
void writeUInt32(CString*, UInt32) const; void writeUInt32(CString*, UInt32) const;
private: private:
Time m_time; mutable bool m_open;
mutable Time m_time;
bool m_owner;
Time m_timeOwned;
bool m_added[kNumFormats]; bool m_added[kNumFormats];
CString m_data[kNumFormats]; CString m_data[kNumFormats];
}; };

File diff suppressed because it is too large Load Diff

View File

@ -2,18 +2,262 @@
#define CXWINDOWSCLIPBOARD_H #define CXWINDOWSCLIPBOARD_H
#include "IClipboard.h" #include "IClipboard.h"
#include "ClipboardTypes.h"
#include "CString.h"
#include <X11/Xlib.h>
#include <map>
#include <list>
class CXWindowsClipboard : public IClipboard { class CXWindowsClipboard : public IClipboard {
public: public:
CXWindowsClipboard(); CXWindowsClipboard(Display*, Window, ClipboardID);
virtual ~CXWindowsClipboard(); virtual ~CXWindowsClipboard();
// tell clipboard it lost ownership
void lost(Time);
// add a selection request to the request list. if the given
// owner window isn't this clipboard's window then this simply
// sends a failure event to the requestor.
void addRequest(Window owner,
Window requestor, Atom target,
::Time time, Atom property);
// continue processing a selection request. returns true if the
// request was handled, false if the request was unknown.
bool processRequest(Window requestor,
::Time time, Atom property);
// terminate a selection request. returns true iff the request
// was known and handled.
bool destroyRequest(Window requestor);
// get the clipboard's window
Window getWindow() const;
// get the clipboard selection atom
Atom getSelection() const;
// IClipboard overrides // IClipboard overrides
virtual bool open(); virtual bool empty();
virtual void close();
virtual void add(EFormat, const CString& data); virtual void add(EFormat, const CString& data);
virtual bool open(Time) const;
virtual void close() const;
virtual Time getTime() const;
virtual bool has(EFormat) const; virtual bool has(EFormat) const;
virtual CString get(EFormat) const; virtual CString get(EFormat) const;
private:
// convert target atom to clipboard format
EFormat getFormat(Atom target) const;
// add a non-MULTIPLE request. does not verify that the selection
// was owned at the given time. returns true if the conversion
// could be performed, false otherwise. in either case, the
// reply is inserted.
bool addSimpleRequest(
Window requestor, Atom target,
::Time time, Atom property);
// clear the cache, resetting the cached flag and the added flag for
// each format.
void clearCache() const;
void doClearCache();
// cache all formats of the selection
void fillCache() const;
void doFillCache();
// ICCCM interoperability methods
void icccmFillCache();
bool icccmGetSelection(Atom target,
Atom* actualTarget,
CString* data) const;
Time icccmGetTime() const;
// motif interoperability methods
bool motifLockClipboard() const;
void motifUnlockClipboard() const;
bool motifOwnsClipboard() const;
Time motifGetTime() const;
void motifFillCache();
// FIXME
//
// helper classes
//
// read an ICCCM conforming selection
class CICCCMGetClipboard {
public:
CICCCMGetClipboard(Window requestor, Time time, Atom property);
~CICCCMGetClipboard();
// convert the given selection to the given type. returns
// true iff the conversion was successful or the conversion
// cannot be performed (in which case *actualTarget == None).
bool readClipboard(Display* display,
Atom selection, Atom target,
Atom* actualTarget, CString* data);
private:
bool doEventPredicate(Display* display,
XEvent* event);
static Bool eventPredicate(Display* display,
XEvent* event,
XPointer arg);
private:
Window m_requestor;
Time m_time;
Atom m_property;
bool m_incr;
bool m_failed;
bool m_done;
// true iff we've received the selection notify
bool m_reading;
// the converted selection data
CString* m_data;
// the actual type of the data. if this is None then the
// selection owner cannot convert to the requested type.
Atom* m_actualTarget;
public:
// true iff the selection owner didn't follow ICCCM conventions
bool m_error;
};
// Motif structure IDs
enum { kMotifClipFormat = 1, kMotifClipItem, kMotifClipHeader };
// _MOTIF_CLIP_HEADER structure
class CMotifClipHeader {
public:
SInt32 m_id; // kMotifClipHeader
SInt32 m_pad1[3];
SInt32 m_item;
SInt32 m_pad2[4];
SInt32 m_numItems;
SInt32 m_pad3[3];
Window m_selectionOwner;
SInt32 m_pad4[2];
SInt32 m_items[1]; // m_numItems items
};
// Motif clip item structure
class CMotifClipItem {
public:
SInt32 m_id; // kMotifClipItem
SInt32 m_pad1[6];
SInt32 m_numFormats;
SInt32 m_pad2[7];
SInt32 m_formats[1]; // m_numFormats formats
};
// Motif clip format structure
class CMotifClipFormat {
public:
SInt32 m_id; // kMotifClipFormat
SInt32 m_pad1[6];
SInt32 m_length;
SInt32 m_data;
Atom m_type;
SInt32 m_pad2[6];
};
// stores data needed to respond to a selection request
class CReply {
public:
CReply(Window, Atom target, ::Time);
CReply(Window, Atom target, ::Time, Atom property,
const CString& data, Atom type, int format);
public:
// information about the request
Window m_requestor;
Atom m_target;
::Time m_time;
Atom m_property;
// true iff we've sent the notification for this reply
bool m_replied;
// true iff the reply has sent its last message
bool m_done;
// the data to send and its type and format
CString m_data;
Atom m_type;
int m_format;
// index of next byte in m_data to send
UInt32 m_ptr;
};
typedef std::list<CReply*> CReplyList;
typedef std::map<Window, CReplyList> CReplyMap;
typedef std::map<Window, long> CReplyEventMask;
// reply methods
bool insertMultipleReply(Window, ::Time, Atom);
void insertReply(CReply*);
void pushReplies();
void pushReplies(CReplyMap::iterator,
CReplyList&, CReplyList::iterator);
bool sendReply(CReply*);
void clearReplies();
void clearReplies(CReplyList&);
void sendNotify(Window requestor, Atom selection,
Atom target, Atom property, Time time);
bool wasOwnedAtTime(::Time) const;
// data conversion methods
Atom getTargetsData(CString&, int* format) const;
Atom getTimestampData(CString&, int* format) const;
Atom getStringData(CString&, int* format) const;
private:
Display* m_display;
Window m_window;
ClipboardID m_id;
Atom m_selection;
mutable bool m_open;
mutable Time m_time;
bool m_owner;
mutable Time m_timeOwned;
Time m_timeLost;
// true iff open and clipboard owned by a motif app
mutable bool m_motif;
// the added/cached clipboard data
bool m_cached;
Time m_cacheTime;
bool m_added[kNumFormats];
CString m_data[kNumFormats];
// conversion request replies
CReplyMap m_replies;
CReplyEventMask m_eventMasks;
// atoms we'll need
Atom m_atomTargets;
Atom m_atomMultiple;
Atom m_atomTimestamp;
Atom m_atomAtom;
Atom m_atomAtomPair;
Atom m_atomInteger;
Atom m_atomData;
Atom m_atomINCR;
Atom m_atomString;
Atom m_atomText;
Atom m_atomCompoundText;
Atom m_atomMotifClipLock;
Atom m_atomMotifClipHeader;
Atom m_atomMotifClipAccess;
Atom m_atomGDKSelection;
}; };
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -3,13 +3,11 @@
#include "BasicTypes.h" #include "BasicTypes.h"
#include "ClipboardTypes.h" #include "ClipboardTypes.h"
#include "CClipboard.h"
#include "CMutex.h" #include "CMutex.h"
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <map>
#include <list>
class CString; class IClipboard;
class CXWindowsClipboard;
class CXWindowsScreen { class CXWindowsScreen {
public: public:
@ -57,141 +55,54 @@ protected:
// cause getEvent() to return false immediately and forever after // cause getEvent() to return false immediately and forever after
void doStop(); void doStop();
// determine the clipboard from the X selection. returns
// kClipboardEnd if no such clipboard.
ClipboardID getClipboardID(Atom selection);
// 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) // set the contents of the clipboard (i.e. primary selection)
bool setDisplayClipboard(ClipboardID, bool setDisplayClipboard(ClipboardID,
const IClipboard* clipboard, const IClipboard* clipboard);
Window requestor, Time timestamp);
// copy the clipboard contents to clipboard. requestor must be a // copy the clipboard contents to clipboard
// valid window; it will be used to receive the transfer. timestamp bool getDisplayClipboard(ClipboardID,
// should be the timestamp of the provoking event and not CurrentTime. IClipboard* clipboard) const;
// if force is false then only update clipboard
void getDisplayClipboard(ClipboardID,
IClipboard* clipboard,
Window requestor, Time timestamp) const;
// 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);
// terminate a selection request
void destroyClipboardRequest(Window window);
// get the current server time
Time getCurrentTime(Window) const;
// called by openDisplay() to allow subclasses to prepare the display // called by openDisplay() to allow subclasses to prepare the display
virtual void onOpenDisplay() = 0; virtual void onOpenDisplay() = 0;
// called by openDisplay() after onOpenDisplay() to create each clipboard
virtual CXWindowsClipboard*
createClipboard(ClipboardID) = 0;
// called by closeDisplay() to // called by closeDisplay() to
virtual void onCloseDisplay() = 0; virtual void onCloseDisplay() = 0;
// called when a clipboard is lost
virtual void onLostClipboard(ClipboardID) = 0;
// get the X event mask required by the subclass for the given window // get the X event mask required by the subclass for the given window
virtual long getEventMask(Window) const = 0; virtual long getEventMask(Window) const = 0;
private: private:
class CPropertyNotifyInfo { // internal event processing
public: bool processEvent(XEvent*);
Window m_window;
Atom m_property;
};
class CClipboardRequest {
public:
CString m_data;
UInt32 m_sent;
Window m_requestor;
Atom m_property;
Atom m_type;
int m_size;
};
typedef std::list<CClipboardRequest*> CRequestList;
typedef std::map<Window, CRequestList*> CRequestMap;
bool getDisplayClipboard(Atom selection, Atom type, // determine the clipboard from the X selection. returns
Window requestor, Time timestamp, // kClipboardEnd if no such clipboard.
Atom* outputType, CString* data) const; ClipboardID getClipboardID(Atom selection) 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);
bool sendClipboardData(ClipboardID, Window requestor, // continue processing a selection request
Atom target, Atom property, Time time); void processClipboardRequest(Window window,
bool sendClipboardMultiple(ClipboardID, Window requestor, Time time, Atom property);
Atom property, Time time);
bool sendClipboardTargets(ClipboardID, Window requestor, // terminate a selection request
Atom property, Time time); void destroyClipboardRequest(Window window);
bool sendClipboardTimestamp(ClipboardID, Window requestor,
Atom property, Time time);
void sendNotify(Window requestor, Atom selection,
Atom target, Atom property, Time time);
bool wasOwnedAtTime(ClipboardID, Window, Time) const;
Time getCurrentTimeNoLock(Window) const;
private: private:
class CClipboardInfo {
public:
CClipboardInfo();
public:
// the contents of the clipboard and the time we got it
CClipboard m_clipboard;
// when we lost the clipboard
Time m_lostClipboard;
// the request queues
CRequestMap m_requests;
// owner of clipboard when we last asked for it
Window m_owner;
// true iff the previous request to m_owner got no reply
bool m_unresponsive;
};
Display* m_display; Display* m_display;
int m_screen; int m_screen;
Window m_root; Window m_root;
SInt32 m_w, m_h; SInt32 m_w, m_h;
bool m_stop; bool m_stop;
// atoms we'll need // clipboards
Atom m_atomTargets; CXWindowsClipboard* m_clipboard[kClipboardEnd];
Atom m_atomMultiple;
Atom m_atomTimestamp;
Atom m_atomAtom;
Atom m_atomAtomPair;
Atom m_atomInteger;
Atom m_atomData;
Atom m_atomINCR;
Atom m_atomString;
Atom m_atomText;
Atom m_atomCompoundText;
Atom m_atomClipboard[kClipboardEnd];
Atom m_atomSynergyTime;
// clipboard info
CClipboardInfo m_clipboards[kClipboardEnd];
// X is not thread safe // X is not thread safe
CMutex m_mutex; CMutex m_mutex;

View File

@ -19,38 +19,41 @@ public:
// manipulators // manipulators
// grab ownership of and clear the clipboard of all data. // take ownership of the clipboard and clear all data from it.
// only add() may be called between an open() and its // must be called between an open() and close(). if returns
// corresponding close(). if open() returns false then // false then the clipboard ownership could not be taken; the
// the clipboard could not be opened or grabbed; do not // clipboard should not be emptied in this case.
// call close() in that case. iff open() returns true it virtual bool empty() = 0;
// should have saved the timestamp. the timestamp should
// be zero before the first successful open. // add data in the given format to the clipboard. data is
virtual bool open(Time) = 0; // passed as a string but the contents are generally not
// interpreted. may only be called after a successful empty().
virtual void add(EFormat, const CString& data) = 0;
// accessors
// open the clipboard. return true iff the clipboard could
// be opened. if open() returns true then it must be followed
// by a close() at some later time; if it returns false then
// close() must not be called.
virtual bool open(Time) const = 0;
// close the clipboard. close() must match a preceding open(). // close the clipboard. close() must match a preceding open().
// this signals that the clipboard has been filled with all the // this signals that the clipboard has been filled with all the
// necessary data. it does not mean the clipboard ownership // necessary data. it does not mean the clipboard ownership
// should be released. // should be released.
virtual void close() = 0; virtual void close() const = 0;
// add data in the given format to the clipboard. data is
// passed as a string but the contents are generally not
// interpreted. may only be called between an open() and
// a close().
virtual void add(EFormat, const CString& data) = 0;
// accessors
// returns the timestamp passed to the last successful open(). // returns the timestamp passed to the last successful open().
virtual Time getTime() const = 0; virtual Time getTime() const = 0;
// returns true iff the clipboard contains data in the given // returns true iff the clipboard contains data in the given
// format. // format. must be called between an open() and close().
virtual bool has(EFormat) const = 0; virtual bool has(EFormat) const = 0;
// returns data in the given format. rturns the empty string // returns data in the given format. rturns the empty string
// if there is no data in that format. // if there is no data in that format. must be called between
// an open() and close().
virtual CString get(EFormat) const = 0; virtual CString get(EFormat) const = 0;
}; };

View File

@ -23,6 +23,7 @@ CXXFILES = \
CTCPSocketFactory.cpp \ CTCPSocketFactory.cpp \
CXWindowsClipboard.cpp \ CXWindowsClipboard.cpp \
CXWindowsScreen.cpp \ CXWindowsScreen.cpp \
CXWindowsUtil.cpp \
XSynergy.cpp \ XSynergy.cpp \
$(NULL) $(NULL)