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-14 02:34:12 +03:00
|
|
|
#ifndef CXWINDOWSCLIPBOARD_H
|
|
|
|
#define CXWINDOWSCLIPBOARD_H
|
|
|
|
|
|
|
|
#include "IClipboard.h"
|
2002-05-27 20:22:59 +04:00
|
|
|
#include "ClipboardTypes.h"
|
2002-06-01 23:26:11 +04:00
|
|
|
#include "stdmap.h"
|
|
|
|
#include "stdlist.h"
|
2002-07-22 21:32:51 +04:00
|
|
|
#include "stdvector.h"
|
2004-10-29 01:40:56 +04:00
|
|
|
#if X_DISPLAY_MISSING
|
2002-06-19 15:23:49 +04:00
|
|
|
# error X11 is required to build synergy
|
|
|
|
#else
|
|
|
|
# include <X11/Xlib.h>
|
|
|
|
#endif
|
2001-11-14 02:34:12 +03:00
|
|
|
|
2002-07-22 21:32:51 +04:00
|
|
|
class IXWindowsClipboardConverter;
|
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! X11 clipboard implementation
|
2001-11-14 02:34:12 +03:00
|
|
|
class CXWindowsClipboard : public IClipboard {
|
2002-04-29 18:40:01 +04:00
|
|
|
public:
|
2002-07-29 21:03:55 +04:00
|
|
|
/*!
|
|
|
|
Use \c window as the window that owns or interacts with the
|
|
|
|
clipboard identified by \c id.
|
|
|
|
*/
|
|
|
|
CXWindowsClipboard(Display*, Window window, ClipboardID id);
|
2001-11-14 02:34:12 +03:00
|
|
|
virtual ~CXWindowsClipboard();
|
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Notify clipboard was lost
|
|
|
|
/*!
|
|
|
|
Tells clipboard it lost ownership at the given time.
|
|
|
|
*/
|
2002-05-27 20:22:59 +04:00
|
|
|
void lost(Time);
|
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Add clipboard request
|
|
|
|
/*!
|
|
|
|
Adds 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.
|
|
|
|
*/
|
2002-05-27 20:22:59 +04:00
|
|
|
void addRequest(Window owner,
|
2002-06-11 02:06:45 +04:00
|
|
|
Window requestor, Atom target,
|
|
|
|
::Time time, Atom property);
|
2002-05-27 20:22:59 +04:00
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Process clipboard request
|
|
|
|
/*!
|
|
|
|
Continues processing a selection request. Returns true if the
|
|
|
|
request was handled, false if the request was unknown.
|
|
|
|
*/
|
2002-05-27 20:22:59 +04:00
|
|
|
bool processRequest(Window requestor,
|
2002-06-11 02:06:45 +04:00
|
|
|
::Time time, Atom property);
|
2002-05-27 20:22:59 +04:00
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Cancel clipboard request
|
|
|
|
/*!
|
|
|
|
Terminate a selection request. Returns true iff the request
|
|
|
|
was known and handled.
|
|
|
|
*/
|
2002-05-27 20:22:59 +04:00
|
|
|
bool destroyRequest(Window requestor);
|
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Get window
|
|
|
|
/*!
|
|
|
|
Returns the clipboard's window (passed the c'tor).
|
|
|
|
*/
|
2002-05-27 20:22:59 +04:00
|
|
|
Window getWindow() const;
|
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Get selection atom
|
|
|
|
/*!
|
|
|
|
Returns the selection atom that identifies the clipboard to X11
|
|
|
|
(e.g. XA_PRIMARY).
|
|
|
|
*/
|
2002-05-27 20:22:59 +04:00
|
|
|
Atom getSelection() const;
|
|
|
|
|
2001-11-14 02:34:12 +03:00
|
|
|
// IClipboard overrides
|
2002-05-27 20:22:59 +04:00
|
|
|
virtual bool empty();
|
2001-11-14 02:34:12 +03:00
|
|
|
virtual void add(EFormat, const CString& data);
|
2002-05-27 20:22:59 +04:00
|
|
|
virtual bool open(Time) const;
|
|
|
|
virtual void close() const;
|
|
|
|
virtual Time getTime() const;
|
2001-11-14 02:34:12 +03:00
|
|
|
virtual bool has(EFormat) const;
|
|
|
|
virtual CString get(EFormat) const;
|
2002-05-27 20:22:59 +04:00
|
|
|
|
|
|
|
private:
|
2002-07-22 21:32:51 +04:00
|
|
|
// remove all converters from our list
|
|
|
|
void clearConverters();
|
|
|
|
|
|
|
|
// get the converter for a clipboard format. returns NULL if no
|
|
|
|
// suitable converter. iff onlyIfNotAdded is true then also
|
|
|
|
// return NULL if a suitable converter was found but we already
|
|
|
|
// have data of the converter's clipboard format.
|
|
|
|
IXWindowsClipboardConverter*
|
|
|
|
getConverter(Atom target,
|
|
|
|
bool onlyIfNotAdded = false) const;
|
|
|
|
|
2002-05-27 20:22:59 +04:00
|
|
|
// 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(
|
2002-06-11 02:06:45 +04:00
|
|
|
Window requestor, Atom target,
|
|
|
|
::Time time, Atom property);
|
2002-05-27 20:22:59 +04:00
|
|
|
|
2002-06-20 17:35:28 +04:00
|
|
|
// if not already checked then see if the cache is stale and, if so,
|
|
|
|
// clear it. this has the side effect of updating m_timeOwned.
|
|
|
|
void checkCache() const;
|
|
|
|
|
2002-05-27 20:22:59 +04:00
|
|
|
// 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();
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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,
|
2002-06-11 02:06:45 +04:00
|
|
|
Atom selection, Atom target,
|
|
|
|
Atom* actualTarget, CString* data);
|
2002-05-27 20:22:59 +04:00
|
|
|
|
|
|
|
private:
|
2002-06-20 20:27:49 +04:00
|
|
|
bool processEvent(Display* display, XEvent* event);
|
2002-05-27 20:22:59 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
Window m_requestor;
|
|
|
|
Time m_time;
|
|
|
|
Atom m_property;
|
|
|
|
bool m_incr;
|
|
|
|
bool m_failed;
|
|
|
|
bool m_done;
|
|
|
|
|
2007-06-17 15:19:18 +04:00
|
|
|
// atoms needed for the protocol
|
|
|
|
Atom m_atomNone; // NONE, not None
|
|
|
|
Atom m_atomIncr;
|
|
|
|
|
2002-05-27 20:22:59 +04:00
|
|
|
// 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];
|
2007-06-17 15:19:18 +04:00
|
|
|
SInt32 m_selectionOwner; // a Window
|
2002-05-27 20:22:59 +04:00
|
|
|
SInt32 m_pad4[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
// Motif clip item structure
|
|
|
|
class CMotifClipItem {
|
|
|
|
public:
|
|
|
|
SInt32 m_id; // kMotifClipItem
|
2002-07-24 21:07:52 +04:00
|
|
|
SInt32 m_pad1[5];
|
|
|
|
SInt32 m_size;
|
2002-05-27 20:22:59 +04:00
|
|
|
SInt32 m_numFormats;
|
2002-07-24 21:07:52 +04:00
|
|
|
SInt32 m_numDeletedFormats;
|
|
|
|
SInt32 m_pad2[6];
|
2002-05-27 20:22:59 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Motif clip format structure
|
|
|
|
class CMotifClipFormat {
|
|
|
|
public:
|
|
|
|
SInt32 m_id; // kMotifClipFormat
|
|
|
|
SInt32 m_pad1[6];
|
|
|
|
SInt32 m_length;
|
|
|
|
SInt32 m_data;
|
2007-06-17 15:19:18 +04:00
|
|
|
SInt32 m_type; // an Atom
|
2002-07-24 21:07:52 +04:00
|
|
|
SInt32 m_pad2[1];
|
2007-06-17 15:19:18 +04:00
|
|
|
SInt32 m_deleted;
|
2002-07-24 21:07:52 +04:00
|
|
|
SInt32 m_pad3[4];
|
2002-05-27 20:22:59 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// stores data needed to respond to a selection request
|
|
|
|
class CReply {
|
|
|
|
public:
|
|
|
|
CReply(Window, Atom target, ::Time);
|
|
|
|
CReply(Window, Atom target, ::Time, Atom property,
|
2002-06-11 02:06:45 +04:00
|
|
|
const CString& data, Atom type, int format);
|
2002-05-27 20:22:59 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2002-07-24 21:07:52 +04:00
|
|
|
// 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;
|
|
|
|
void motifFillCache();
|
|
|
|
bool motifGetSelection(const CMotifClipFormat*,
|
|
|
|
Atom* actualTarget, CString* data) const;
|
|
|
|
Time motifGetTime() const;
|
|
|
|
|
2002-05-27 20:22:59 +04:00
|
|
|
// reply methods
|
|
|
|
bool insertMultipleReply(Window, ::Time, Atom);
|
|
|
|
void insertReply(CReply*);
|
|
|
|
void pushReplies();
|
|
|
|
void pushReplies(CReplyMap::iterator,
|
2002-06-11 02:06:45 +04:00
|
|
|
CReplyList&, CReplyList::iterator);
|
2002-05-27 20:22:59 +04:00
|
|
|
bool sendReply(CReply*);
|
|
|
|
void clearReplies();
|
|
|
|
void clearReplies(CReplyList&);
|
|
|
|
void sendNotify(Window requestor, Atom selection,
|
2002-06-11 02:06:45 +04:00
|
|
|
Atom target, Atom property, Time time);
|
2002-05-27 20:22:59 +04:00
|
|
|
bool wasOwnedAtTime(::Time) const;
|
|
|
|
|
|
|
|
// data conversion methods
|
|
|
|
Atom getTargetsData(CString&, int* format) const;
|
|
|
|
Atom getTimestampData(CString&, int* format) const;
|
|
|
|
|
|
|
|
private:
|
2002-07-22 21:32:51 +04:00
|
|
|
typedef std::vector<IXWindowsClipboardConverter*> ConverterList;
|
|
|
|
|
2002-05-27 20:22:59 +04:00
|
|
|
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
|
2002-06-20 17:35:28 +04:00
|
|
|
mutable bool m_checkCache;
|
2002-05-27 20:22:59 +04:00
|
|
|
bool m_cached;
|
|
|
|
Time m_cacheTime;
|
|
|
|
bool m_added[kNumFormats];
|
|
|
|
CString m_data[kNumFormats];
|
|
|
|
|
|
|
|
// conversion request replies
|
|
|
|
CReplyMap m_replies;
|
|
|
|
CReplyEventMask m_eventMasks;
|
|
|
|
|
2002-07-22 21:32:51 +04:00
|
|
|
// clipboard format converters
|
|
|
|
ConverterList m_converters;
|
|
|
|
|
2002-05-27 20:22:59 +04:00
|
|
|
// atoms we'll need
|
|
|
|
Atom m_atomTargets;
|
|
|
|
Atom m_atomMultiple;
|
|
|
|
Atom m_atomTimestamp;
|
2002-07-24 21:07:52 +04:00
|
|
|
Atom m_atomInteger;
|
2002-07-24 21:30:32 +04:00
|
|
|
Atom m_atomAtom;
|
2002-05-27 20:22:59 +04:00
|
|
|
Atom m_atomAtomPair;
|
|
|
|
Atom m_atomData;
|
|
|
|
Atom m_atomINCR;
|
|
|
|
Atom m_atomMotifClipLock;
|
|
|
|
Atom m_atomMotifClipHeader;
|
|
|
|
Atom m_atomMotifClipAccess;
|
|
|
|
Atom m_atomGDKSelection;
|
2001-11-14 02:34:12 +03:00
|
|
|
};
|
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Clipboard format converter interface
|
|
|
|
/*!
|
|
|
|
This interface defines the methods common to all X11 clipboard format
|
|
|
|
converters.
|
|
|
|
*/
|
2002-07-22 21:32:51 +04:00
|
|
|
class IXWindowsClipboardConverter : public IInterface {
|
|
|
|
public:
|
2002-07-29 21:03:55 +04:00
|
|
|
//! @name accessors
|
|
|
|
//@{
|
2002-07-22 21:32:51 +04:00
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Get clipboard format
|
|
|
|
/*!
|
|
|
|
Return the clipboard format this object converts from/to.
|
|
|
|
*/
|
2002-07-22 21:32:51 +04:00
|
|
|
virtual IClipboard::EFormat
|
|
|
|
getFormat() const = 0;
|
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Get X11 format atom
|
|
|
|
/*!
|
|
|
|
Return the atom representing the X selection format that
|
|
|
|
this object converts from/to.
|
|
|
|
*/
|
2002-07-22 21:32:51 +04:00
|
|
|
virtual Atom getAtom() const = 0;
|
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Get X11 property datum size
|
|
|
|
/*!
|
|
|
|
Return the size (in bits) of data elements returned by
|
|
|
|
toIClipboard().
|
|
|
|
*/
|
2002-07-22 21:32:51 +04:00
|
|
|
virtual int getDataSize() const = 0;
|
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Convert from IClipboard format
|
|
|
|
/*!
|
|
|
|
Convert from the IClipboard format to the X selection format.
|
|
|
|
The input data must be in the IClipboard format returned by
|
|
|
|
getFormat(). The return data will be in the X selection
|
|
|
|
format returned by getAtom().
|
|
|
|
*/
|
2002-07-22 21:32:51 +04:00
|
|
|
virtual CString fromIClipboard(const CString&) const = 0;
|
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Convert to IClipboard format
|
|
|
|
/*!
|
|
|
|
Convert from the X selection format to the IClipboard format
|
|
|
|
(i.e., the reverse of fromIClipboard()).
|
|
|
|
*/
|
2002-07-22 21:32:51 +04:00
|
|
|
virtual CString toIClipboard(const CString&) const = 0;
|
2002-07-29 21:03:55 +04:00
|
|
|
|
|
|
|
//@}
|
2002-07-22 21:32:51 +04:00
|
|
|
};
|
|
|
|
|
2001-11-14 02:34:12 +03:00
|
|
|
#endif
|