Qt 4.8
Public Functions | Private Functions | Properties | Static Private Attributes | List of all members
QXlibClipboard Class Reference

#include <qxlibclipboard.h>

Inheritance diagram for QXlibClipboard:
QPlatformClipboard

Public Functions

QByteArray clipboardReadIncrementalProperty (Window win, Atom property, int nbytes, bool nullterm)
 
bool clipboardReadProperty (Window win, Atom property, bool deleteProperty, QByteArray *buffer, int *size, Atom *type, int *format) const
 
QByteArray getDataInFormat (Atom modeAtom, Atom fmtatom)
 
void handleSelectionRequest (XEvent *event)
 
QMimeDatamimeData (QClipboard::Mode mode)
 
Window owner () const
 
 QXlibClipboard (QXlibScreen *screen)
 
Window requestor () const
 
QXlibScreenscreen () const
 
void setMimeData (QMimeData *data, QClipboard::Mode mode)
 
void setRequestor (Window window)
 
bool supportsMode (QClipboard::Mode mode) const
 
- Public Functions inherited from QPlatformClipboard
void emitChanged (QClipboard::Mode mode)
 
virtual ~QPlatformClipboard ()
 

Private Functions

Atom sendSelection (QMimeData *d, Atom target, Window window, Atom property)
 
Atom sendTargetsSelection (QMimeData *d, Window window, Atom property)
 
void setOwner (Window window)
 

Properties

QMimeDatam_clientClipboard
 
QMimeDatam_clientSelection
 
Window m_owner
 
Window m_requestor
 
QXlibScreenm_screen
 
QMimeDatam_xClipboard
 
QMimeDatam_xSelection
 

Static Private Attributes

static const int clipboard_timeout = 5000
 

Detailed Description

Definition at line 49 of file qxlibclipboard.h.

Constructors and Destructors

◆ QXlibClipboard()

QXlibClipboard::QXlibClipboard ( QXlibScreen screen)

Definition at line 152 of file qxlibclipboard.cpp.

154  , m_screen(screen)
155  , m_xClipboard(0)
156  , m_clientClipboard(0)
157  , m_xSelection(0)
158  , m_clientSelection(0)
159  , m_requestor(XNone)
160  , m_owner(XNone)
161 {
162 }
QMimeData * m_clientClipboard
QMimeData * m_xClipboard
QMimeData * m_clientSelection
QXlibScreen * m_screen
QMimeData * m_xSelection

Functions

◆ clipboardReadIncrementalProperty()

QByteArray QXlibClipboard::clipboardReadIncrementalProperty ( Window  win,
Atom  property,
int  nbytes,
bool  nullterm 
)

Definition at line 583 of file qxlibclipboard.cpp.

Referenced by getDataInFormat().

584 {
585  XEvent event;
586 
587  QByteArray buf;
588  QByteArray tmp_buf;
589  bool alloc_error = false;
590  int length;
591  int offset = 0;
592 
593  if (nbytes > 0) {
594  // Reserve buffer + zero-terminator (for text data)
595  // We want to complete the INCR transfer even if we cannot
596  // allocate more memory
597  buf.resize(nbytes+1);
598  alloc_error = buf.size() != nbytes+1;
599  }
600 
601  for (;;) {
602  screen()->display()->flush();
603  if (!screen()->waitForClipboardEvent(win,PropertyNotify,&event,clipboard_timeout))
604  break;
605  if (event.xproperty.atom != property ||
606  event.xproperty.state != PropertyNewValue)
607  continue;
608  if (clipboardReadProperty(win, property, true, &tmp_buf, &length, 0, 0)) {
609  if (length == 0) { // no more data, we're done
610  if (nullterm) {
611  buf.resize(offset+1);
612  buf[offset] = '\0';
613  } else {
614  buf.resize(offset);
615  }
616  return buf;
617  } else if (!alloc_error) {
618  if (offset+length > (int)buf.size()) {
619  buf.resize(offset+length+65535);
620  if (buf.size() != offset+length+65535) {
621  alloc_error = true;
622  length = buf.size() - offset;
623  }
624  }
625  memcpy(buf.data()+offset, tmp_buf.constData(), length);
626  tmp_buf.resize(0);
627  offset += length;
628  }
629  } else {
630  break;
631  }
632  }
633 
634  // timed out ... create a new requestor window, otherwise the requestor
635  // could consider next request to be still part of this timed out request
636  setRequestor(0);
637 
638  return QByteArray();
639 }
EventRef event
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
bool clipboardReadProperty(Window win, Atom property, bool deleteProperty, QByteArray *buffer, int *size, Atom *type, int *format) const
static const int clipboard_timeout
union _XEvent XEvent
Definition: qwindowdefs.h:116
void setRequestor(Window window)
QXlibScreen * screen() const
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
void resize(int size)
Sets the size of the byte array to size bytes.
const char * property
Definition: qwizard.cpp:138
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QXlibDisplay * display() const
void flush() const

◆ clipboardReadProperty()

bool QXlibClipboard::clipboardReadProperty ( Window  win,
Atom  property,
bool  deleteProperty,
QByteArray buffer,
int *  size,
Atom *  type,
int *  format 
) const

Definition at line 471 of file qxlibclipboard.cpp.

Referenced by clipboardReadIncrementalProperty(), getDataInFormat(), and handleSelectionRequest().

472 {
473  int maxsize = maxSelectionIncr(screen()->display()->nativeDisplay());
474  ulong bytes_left; // bytes_after
475  ulong length; // nitems
476  uchar *data;
477  Atom dummy_type;
478  int dummy_format;
479  int r;
480 
481  if (!type) // allow null args
482  type = &dummy_type;
483  if (!format)
484  format = &dummy_format;
485 
486  // Don't read anything, just get the size of the property data
487  r = XGetWindowProperty(screen()->display()->nativeDisplay(), win, property, 0, 0, False,
488  AnyPropertyType, type, format,
489  &length, &bytes_left, &data);
490  if (r != Success || (type && *type == XNone)) {
491  buffer->resize(0);
492  return false;
493  }
494  XFree((char*)data);
495 
496  int offset = 0, buffer_offset = 0, format_inc = 1, proplen = bytes_left;
497 
498  switch (*format) {
499  case 8:
500  default:
501  format_inc = sizeof(char) / 1;
502  break;
503 
504  case 16:
505  format_inc = sizeof(short) / 2;
506  proplen *= sizeof(short) / 2;
507  break;
508 
509  case 32:
510  format_inc = sizeof(long) / 4;
511  proplen *= sizeof(long) / 4;
512  break;
513  }
514 
515  int newSize = proplen;
516  buffer->resize(newSize);
517 
518  bool ok = (buffer->size() == newSize);
519 
520  if (ok && newSize) {
521  // could allocate buffer
522 
523  while (bytes_left) {
524  // more to read...
525 
526  r = XGetWindowProperty(screen()->display()->nativeDisplay(), win, property, offset, maxsize/4,
527  False, AnyPropertyType, type, format,
528  &length, &bytes_left, &data);
529  if (r != Success || (type && *type == XNone))
530  break;
531 
532  offset += length / (32 / *format);
533  length *= format_inc * (*format) / 8;
534 
535  // Here we check if we get a buffer overflow and tries to
536  // recover -- this shouldn't normally happen, but it doesn't
537  // hurt to be defensive
538  if ((int)(buffer_offset + length) > buffer->size()) {
539  length = buffer->size() - buffer_offset;
540 
541  // escape loop
542  bytes_left = 0;
543  }
544 
545  memcpy(buffer->data() + buffer_offset, data, length);
546  buffer_offset += length;
547 
548  XFree((char*)data);
549  }
550 
552  // convert COMPOUND_TEXT to a multibyte string
553  XTextProperty textprop;
554  textprop.encoding = *type;
555  textprop.format = *format;
556  textprop.nitems = buffer_offset;
557  textprop.value = (unsigned char *) buffer->data();
558 
559  char **list_ret = 0;
560  int count;
561  if (XmbTextPropertyToTextList(screen()->display()->nativeDisplay(), &textprop, &list_ret,
562  &count) == Success && count && list_ret) {
563  offset = buffer_offset = strlen(list_ret[0]);
564  buffer->resize(offset);
565  memcpy(buffer->data(), list_ret[0], offset);
566  }
567  if (list_ret) XFreeStringList(list_ret);
568  }
569  }
570 
571  // correct size, not 0-term.
572  if (size)
573  *size = buffer_offset;
574 
575  if (deleteProperty)
576  XDeleteProperty(screen()->display()->nativeDisplay(), win, property);
577 
578  screen()->display()->flush();
579 
580  return ok;
581 }
int type
Definition: qmetatype.cpp:239
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
unsigned char uchar
Definition: qglobal.h:994
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
static const char * data(const QByteArray &arr)
unsigned long ulong
Definition: qglobal.h:997
QXlibScreen * screen() const
static int maxSelectionIncr(Display *dpy)
static Atom atom(X11Atom atom)
Q_GUI_EXPORT EGLNativeDisplayType nativeDisplay()
Definition: qegl_qpa.cpp:55
void resize(int size)
Sets the size of the byte array to size bytes.
const char * property
Definition: qwizard.cpp:138
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QXlibDisplay * display() const
void flush() const

◆ getDataInFormat()

QByteArray QXlibClipboard::getDataInFormat ( Atom  modeAtom,
Atom  fmtatom 
)

Definition at line 641 of file qxlibclipboard.cpp.

Referenced by QXlibClipboardMime::formats_sys().

642 {
643  QByteArray buf;
644 
645  Window win = requestor();
646 
647  XSelectInput(screen()->display()->nativeDisplay(), win, NoEventMask); // don't listen for any events
648 
650  XConvertSelection(screen()->display()->nativeDisplay(), modeAtom, fmtatom, QXlibStatic::atom(QXlibStatic::_QT_SELECTION), win, CurrentTime);
651  screen()->display()->sync();
652 
653  XEvent xevent;
654  if (!screen()->waitForClipboardEvent(win,SelectionNotify,&xevent,clipboard_timeout) ||
655  xevent.xselection.property == XNone) {
656  return buf;
657  }
658 
659  Atom type;
660  XSelectInput(screen()->display()->nativeDisplay(), win, PropertyChangeMask);
661 
662  if (clipboardReadProperty(win, QXlibStatic::atom(QXlibStatic::_QT_SELECTION), true, &buf, 0, &type, 0)) {
663  if (type == QXlibStatic::atom(QXlibStatic::INCR)) {
664  int nbytes = buf.size() >= 4 ? *((int*)buf.data()) : 0;
666  }
667  }
668 
669  XSelectInput(screen()->display()->nativeDisplay(), win, NoEventMask);
670 
671 
672  return buf;
673 }
int type
Definition: qmetatype.cpp:239
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QByteArray clipboardReadIncrementalProperty(Window win, Atom property, int nbytes, bool nullterm)
bool clipboardReadProperty(Window win, Atom property, bool deleteProperty, QByteArray *buffer, int *size, Atom *type, int *format) const
static const int clipboard_timeout
union _XEvent XEvent
Definition: qwindowdefs.h:116
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
QXlibScreen * screen() const
static Atom atom(X11Atom atom)
Q_GUI_EXPORT EGLNativeDisplayType nativeDisplay()
Definition: qegl_qpa.cpp:55
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
Window requestor() const
QXlibDisplay * display() const
void sync() const

◆ handleSelectionRequest()

void QXlibClipboard::handleSelectionRequest ( XEvent event)

Definition at line 348 of file qxlibclipboard.cpp.

Referenced by QXlibScreen::handleSelectionRequest().

349 {
350  XSelectionRequestEvent *req = &xevent->xselectionrequest;
351 
352  if (requestor() && req->requestor == requestor()) {
353  qDebug() << "This should be caught before";
354  return;
355  }
356 
357  XEvent event;
358  event.xselection.type = SelectionNotify;
359  event.xselection.display = req->display;
360  event.xselection.requestor = req->requestor;
361  event.xselection.selection = req->selection;
362  event.xselection.target = req->target;
363  event.xselection.property = XNone;
364  event.xselection.time = req->time;
365 
366  QMimeData *d;
367  if (req->selection == XA_PRIMARY) {
368  d = m_clientSelection;
369  } else if (req->selection == QXlibStatic::atom(QXlibStatic::CLIPBOARD)) {
370  d = m_clientClipboard;
371  } else {
372  qWarning("QClipboard: Unknown selection '%lx'", req->selection);
373  XSendEvent(screen()->display()->nativeDisplay(), req->requestor, False, NoEventMask, &event);
374  return;
375  }
376 
377  if (!d) {
378  qWarning("QClipboard: Cannot transfer data, no data available");
379  XSendEvent(screen()->display()->nativeDisplay(), req->requestor, False, NoEventMask, &event);
380  return;
381  }
382 
386 
387  struct AtomPair { Atom target; Atom property; } *multi = 0;
388  Atom multi_type = XNone;
389  int multi_format = 0;
390  int nmulti = 0;
391  int imulti = -1;
392  bool multi_writeback = false;
393 
394  if (req->target == xa_multiple) {
395  QByteArray multi_data;
396  if (req->property == XNone
397  || !clipboardReadProperty(req->requestor, req->property, false, &multi_data,
398  0, &multi_type, &multi_format)
399  || multi_format != 32) {
400  // MULTIPLE property not formatted correctly
401  XSendEvent(screen()->display()->nativeDisplay(), req->requestor, False, NoEventMask, &event);
402  return;
403  }
404  nmulti = multi_data.size()/sizeof(*multi);
405  multi = new AtomPair[nmulti];
406  memcpy(multi,multi_data.data(),multi_data.size());
407  imulti = 0;
408  }
409 
410  for (; imulti < nmulti; ++imulti) {
411  Atom target;
412  Atom property;
413 
414  if (multi) {
415  target = multi[imulti].target;
416  property = multi[imulti].property;
417  } else {
418  target = req->target;
419  property = req->property;
420  if (property == XNone) // obsolete client
421  property = target;
422  }
423 
424  Atom ret = XNone;
425  if (target == XNone || property == XNone) {
426  ;
427  } else if (target == xa_timestamp) {
428 // if (d->timestamp != CurrentTime) {
429 // XChangeProperty(screen()->display()->nativeDisplay(), req->requestor, property, XA_INTEGER, 32,
430 // PropModeReplace, CurrentTime, 1);
431 // ret = property;
432 // } else {
433 // qWarning("QClipboard: Invalid data timestamp");
434 // }
435  } else if (target == xa_targets) {
436  ret = sendTargetsSelection(d, req->requestor, property);
437  } else {
438  ret = sendSelection(d, target, req->requestor, property);
439  }
440 
441  if (nmulti > 0) {
442  if (ret == XNone) {
443  multi[imulti].property = XNone;
444  multi_writeback = true;
445  }
446  } else {
447  event.xselection.property = ret;
448  break;
449  }
450  }
451 
452  if (nmulti > 0) {
453  if (multi_writeback) {
454  // according to ICCCM 2.6.2 says to put None back
455  // into the original property on the requestor window
456  XChangeProperty(screen()->display()->nativeDisplay(), req->requestor, req->property, multi_type, 32,
457  PropModeReplace, (uchar *) multi, nmulti * 2);
458  }
459 
460  delete [] multi;
461  event.xselection.property = req->property;
462  }
463 
464  // send selection notify to requestor
465  XSendEvent(screen()->display()->nativeDisplay(), req->requestor, False, NoEventMask, &event);
466 }
double d
Definition: qnumeric_p.h:62
EventRef event
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
Atom sendSelection(QMimeData *d, Atom target, Window window, Atom property)
QMimeData * m_clientClipboard
bool clipboardReadProperty(Window win, Atom property, bool deleteProperty, QByteArray *buffer, int *size, Atom *type, int *format) const
union _XEvent XEvent
Definition: qwindowdefs.h:116
Q_CORE_EXPORT void qDebug(const char *,...)
unsigned char uchar
Definition: qglobal.h:994
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
Q_CORE_EXPORT void qWarning(const char *,...)
Atom sendTargetsSelection(QMimeData *d, Window window, Atom property)
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
QXlibScreen * screen() const
static Atom atom(X11Atom atom)
Q_GUI_EXPORT EGLNativeDisplayType nativeDisplay()
Definition: qegl_qpa.cpp:55
const char * property
Definition: qwizard.cpp:138
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
Window requestor() const
QMimeData * m_clientSelection

◆ mimeData()

QMimeData * QXlibClipboard::mimeData ( QClipboard::Mode  mode)
virtual

Reimplemented from QPlatformClipboard.

Definition at line 164 of file qxlibclipboard.cpp.

165 {
166  if (mode == QClipboard::Clipboard) {
167  if (!m_xClipboard) {
168  m_xClipboard = new QXlibClipboardMime(mode, this);
169  }
170  Window clipboardOwner = XGetSelectionOwner(screen()->display()->nativeDisplay(),QXlibStatic::atom(QXlibStatic::CLIPBOARD));
171  if (clipboardOwner == owner()) {
172  return m_clientClipboard;
173  } else {
174  return m_xClipboard;
175  }
176  } else if (mode == QClipboard::Selection) {
177  if (!m_xSelection) {
178  m_xSelection = new QXlibClipboardMime(mode, this);
179  }
180  Window clipboardOwner = XGetSelectionOwner(screen()->display()->nativeDisplay(),XA_PRIMARY);
181  if (clipboardOwner == owner()) {
182  return m_clientSelection;
183  } else {
184  return m_xSelection;
185  }
186  }
187  return 0;
188 }
Window owner() const
QMimeData * m_clientClipboard
QMimeData * m_xClipboard
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
QXlibScreen * screen() const
static Atom atom(X11Atom atom)
Q_GUI_EXPORT EGLNativeDisplayType nativeDisplay()
Definition: qegl_qpa.cpp:55
QMimeData * m_clientSelection
QMimeData * m_xSelection

◆ owner()

Window QXlibClipboard::owner ( ) const

Definition at line 262 of file qxlibclipboard.cpp.

Referenced by mimeData(), and setMimeData().

263 {
264  if (!m_owner) {
265  int x = 0, y = 0, w = 3, h = 3;
266  QXlibClipboard *that = const_cast<QXlibClipboard *>(this);
267  Window window = XCreateSimpleWindow(m_screen->display()->nativeDisplay(), m_screen->rootWindow(),
268  x, y, w, h, 0 /*border_width*/,
270  that->setOwner(window);
271  }
272  return m_owner;
273 }
unsigned long whitePixel()
Window rootWindow()
Display * nativeDisplay() const
void setOwner(Window window)
NSWindow * window
QXlibScreen * m_screen
QXlibDisplay * display() const
unsigned long blackPixel()

◆ requestor()

Window QXlibClipboard::requestor ( ) const

Definition at line 241 of file qxlibclipboard.cpp.

Referenced by getDataInFormat(), and handleSelectionRequest().

242 {
243  if (!m_requestor) {
244  int x = 0, y = 0, w = 3, h = 3;
245  QXlibClipboard *that = const_cast<QXlibClipboard *>(this);
246  Window window = XCreateSimpleWindow(m_screen->display()->nativeDisplay(), m_screen->rootWindow(),
247  x, y, w, h, 0 /*border_width*/,
249  that->setRequestor(window);
250  }
251  return m_requestor;
252 }
unsigned long whitePixel()
Window rootWindow()
Display * nativeDisplay() const
NSWindow * window
void setRequestor(Window window)
QXlibScreen * m_screen
QXlibDisplay * display() const
unsigned long blackPixel()

◆ screen()

QXlibScreen * QXlibClipboard::screen ( ) const

◆ sendSelection()

Atom QXlibClipboard::sendSelection ( QMimeData d,
Atom  target,
Window  window,
Atom  property 
)
private

Definition at line 304 of file qxlibclipboard.cpp.

Referenced by handleSelectionRequest().

305 {
306  Atom atomFormat = target;
307  int dataFormat = 0;
309 
311  if (fmt.isEmpty()) { // Not a MIME type we have
312  qDebug() << "QClipboard: send_selection(): converting to type '%s' is not supported" << fmt.data();
313  return XNone;
314  }
315  qDebug() << "QClipboard: send_selection(): converting to type '%s'" << fmt.data();
316 
317  if (QXlibMime::mimeDataForAtom(screen()->display()->nativeDisplay(),target, d, &data, &atomFormat, &dataFormat)) {
318 
319  // don't allow INCR transfers when using MULTIPLE or to
320  // Motif clients (since Motif doesn't support INCR)
321  static Atom motif_clip_temporary = QXlibStatic::atom(QXlibStatic::CLIP_TEMPORARY);
322  bool allow_incr = property != motif_clip_temporary;
323 
324  // X_ChangeProperty protocol request is 24 bytes
325  const int increment = (XMaxRequestSize(screen()->display()->nativeDisplay()) * 4) - 24;
326  if (data.size() > increment && allow_incr) {
327  long bytes = data.size();
328  XChangeProperty(screen()->display()->nativeDisplay(), window, property,
329  QXlibStatic::atom(QXlibStatic::INCR), 32, PropModeReplace, (uchar *) &bytes, 1);
330 
331 // (void)new QClipboardINCRTransaction(window, property, atomFormat, dataFormat, data, increment);
332  qDebug() << "not implemented INCRT just YET!";
333  return property;
334  }
335 
336  // make sure we can perform the XChangeProperty in a single request
337  if (data.size() > increment)
338  return XNone; // ### perhaps use several XChangeProperty calls w/ PropModeAppend?
339  int dataSize = data.size() / (dataFormat / 8);
340  // use a single request to transfer data
341  XChangeProperty(screen()->display()->nativeDisplay(), window, property, atomFormat,
342  dataFormat, PropModeReplace, (uchar *) data.data(),
343  dataSize);
344  }
345  return property;
346 }
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
static QString mimeAtomToString(Display *display, Atom a)
Definition: qxlibmime.cpp:62
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static bool mimeDataForAtom(Display *display, Atom a, QMimeData *mimeData, QByteArray *data, Atom *atomFormat, int *dataFormat)
Definition: qxlibmime.cpp:107
The QString class provides a Unicode character string.
Definition: qstring.h:83
QChar * data()
Returns a pointer to the data stored in the QString.
Definition: qstring.h:710
Q_CORE_EXPORT void qDebug(const char *,...)
unsigned char uchar
Definition: qglobal.h:994
NSWindow * window
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static const char * data(const QByteArray &arr)
QXlibScreen * screen() const
static Atom atom(X11Atom atom)
Q_GUI_EXPORT EGLNativeDisplayType nativeDisplay()
Definition: qegl_qpa.cpp:55
const char * property
Definition: qwizard.cpp:138
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402

◆ sendTargetsSelection()

Atom QXlibClipboard::sendTargetsSelection ( QMimeData d,
Window  window,
Atom  property 
)
private

Definition at line 283 of file qxlibclipboard.cpp.

Referenced by handleSelectionRequest().

284 {
287  for (int i = 0; i < formats.size(); ++i) {
289  for (int j = 0; j < atoms.size(); ++j) {
290  if (!types.contains(atoms.at(j)))
291  types.append(atoms.at(j));
292  }
293  }
298 
299  XChangeProperty(screen()->display()->nativeDisplay(), window, property, XA_ATOM, 32,
300  PropModeReplace, (uchar *) types.data(), types.size());
301  return property;
302 }
static QStringList formatsHelper(const QMimeData *data)
Definition: qdnd.cpp:414
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
unsigned char uchar
Definition: qglobal.h:994
NSWindow * window
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
QXlibScreen * screen() const
static Atom atom(X11Atom atom)
static const struct @32 types[]
Q_GUI_EXPORT EGLNativeDisplayType nativeDisplay()
Definition: qegl_qpa.cpp:55
static QList< Atom > mimeAtomsForFormat(Display *display, const QString &format)
Definition: qxlibmime.cpp:168
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
const char * property
Definition: qwizard.cpp:138
bool contains(const T &t) const
Returns true if the vector contains an occurrence of value; otherwise returns false.
Definition: qvector.h:731
T * data()
Returns a pointer to the data stored in the vector.
Definition: qvector.h:152
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ setMimeData()

void QXlibClipboard::setMimeData ( QMimeData data,
QClipboard::Mode  mode 
)
virtual

Reimplemented from QPlatformClipboard.

Definition at line 190 of file qxlibclipboard.cpp.

191 {
192  Atom modeAtom;
193  QMimeData **d;
194  switch (mode) {
196  modeAtom = XA_PRIMARY;
197  d = &m_clientSelection;
198  break;
199 
202  d = &m_clientClipboard;
203  break;
204 
205  default:
206  qWarning("QClipboard::setMimeData: unsupported mode '%d'", mode);
207  return;
208  }
209 
210  Window newOwner;
211 
212  if (! data) { // no data, clear clipboard contents
213  newOwner = XNone;
214  } else {
215  newOwner = owner();
216 
217  *d = data;
218  }
219 
220  XSetSelectionOwner(m_screen->display()->nativeDisplay(), modeAtom, newOwner, CurrentTime);
221 
222  if (XGetSelectionOwner(m_screen->display()->nativeDisplay(), modeAtom) != newOwner) {
223  qWarning("QClipboard::setData: Cannot set X11 selection owner");
224  }
225 
226 }
double d
Definition: qnumeric_p.h:62
Window owner() const
Display * nativeDisplay() const
QMimeData * m_clientClipboard
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
static Atom atom(X11Atom atom)
QMimeData * m_clientSelection
QXlibScreen * m_screen
QXlibDisplay * display() const

◆ setOwner()

void QXlibClipboard::setOwner ( Window  window)
private

Definition at line 275 of file qxlibclipboard.cpp.

Referenced by owner().

276 {
277  if (m_owner != XNone){
278  XDestroyWindow(m_screen->display()->nativeDisplay(),m_owner);
279  }
280  m_owner = window;
281 }
Display * nativeDisplay() const
NSWindow * window
QXlibScreen * m_screen
QXlibDisplay * display() const

◆ setRequestor()

void QXlibClipboard::setRequestor ( Window  window)

Definition at line 254 of file qxlibclipboard.cpp.

Referenced by clipboardReadIncrementalProperty(), and requestor().

255 {
256  if (m_requestor != XNone) {
257  XDestroyWindow(m_screen->display()->nativeDisplay(),m_requestor);
258  }
260 }
Display * nativeDisplay() const
NSWindow * window
QXlibScreen * m_screen
QXlibDisplay * display() const

◆ supportsMode()

bool QXlibClipboard::supportsMode ( QClipboard::Mode  mode) const
virtual

Reimplemented from QPlatformClipboard.

Definition at line 228 of file qxlibclipboard.cpp.

229 {
230  if (mode == QClipboard::Clipboard || mode == QClipboard::Selection)
231  return true;
232  return false;
233 }

Properties

◆ clipboard_timeout

const int QXlibClipboard::clipboard_timeout = 5000
staticprivate

Definition at line 90 of file qxlibclipboard.h.

Referenced by clipboardReadIncrementalProperty(), and getDataInFormat().

◆ m_clientClipboard

QMimeData* QXlibClipboard::m_clientClipboard
private

Definition at line 82 of file qxlibclipboard.h.

Referenced by handleSelectionRequest(), mimeData(), and setMimeData().

◆ m_clientSelection

QMimeData* QXlibClipboard::m_clientSelection
private

Definition at line 85 of file qxlibclipboard.h.

Referenced by handleSelectionRequest(), mimeData(), and setMimeData().

◆ m_owner

Window QXlibClipboard::m_owner
private

Definition at line 88 of file qxlibclipboard.h.

Referenced by owner(), and setOwner().

◆ m_requestor

Window QXlibClipboard::m_requestor
private

Definition at line 87 of file qxlibclipboard.h.

Referenced by requestor(), and setRequestor().

◆ m_screen

QXlibScreen* QXlibClipboard::m_screen
private

Definition at line 79 of file qxlibclipboard.h.

Referenced by owner(), requestor(), screen(), setMimeData(), setOwner(), and setRequestor().

◆ m_xClipboard

QMimeData* QXlibClipboard::m_xClipboard
private

Definition at line 81 of file qxlibclipboard.h.

Referenced by mimeData().

◆ m_xSelection

QMimeData* QXlibClipboard::m_xSelection
private

Definition at line 84 of file qxlibclipboard.h.

Referenced by mimeData().


The documentation for this class was generated from the following files: