11
2+ #include " nbl/ui/CClipboardManagerXCB.h"
23#include " nbl/ui/XCBConnection.h"
4+
35#include < mutex>
46#include < string>
57#include < vector>
6- #include < xcb/xproto.h>
7- #ifdef _NBL_PLATFORM_LINUX_
88
9- #include " nbl/ui/CClipboardManagerXCB.h "
9+ #include < xcb/xproto.h >
1010
1111namespace nbl ::ui
1212{
@@ -24,23 +24,14 @@ namespace nbl::ui
2424
2525 bool CClipboardManagerXCB::setClipboardText (const std::string_view& data) {
2626 std::lock_guard lk (m_clipboardMutex);
27- m_stagedClipboard.m_data = data;
28- m_stagedClipboard.m_formats = {
29- m_xcbConnection->resolveXCBAtom (m_formatUTF8_0),
30- m_xcbConnection->resolveXCBAtom (m_formatUTF8_1),
31- m_xcbConnection->resolveXCBAtom (m_formatUTF8_2),
32- m_xcbConnection->resolveXCBAtom (m_formatGTK),
33- m_xcbConnection->resolveXCBAtom (m_formatString),
34- m_xcbConnection->resolveXCBAtom (m_formatText),
35- m_xcbConnection->resolveXCBAtom (m_formatTextPlain)
36- };
27+ m_savedClipboard = data;
3728 return true ;
3829 }
3930
4031 void CClipboardManagerXCB::process (const IWindowXCB* window, xcb_generic_event_t * event) {
41- const auto & xcb = m_xcbConnection ->getXcbFunctionTable ();
32+ const auto & xcb = m_connection ->getXcbFunctionTable ();
4233
43- auto TARGETS = m_xcbConnection-> resolveXCBAtom (m_TARGETS);
34+ auto TARGETS = m_connection-> resolveAtom (m_TARGETS);
4435
4536 switch (event->response_type & ~0x80 ) {
4637 // XCB_ATOM
@@ -52,13 +43,21 @@ namespace nbl::ui
5243 std::vector<xcb_atom_t > targets;
5344 {
5445 std::lock_guard lk (m_clipboardMutex);
55- for (auto & format : m_stagedClipboard.m_formats ) {
46+ for (auto & format : {
47+ m_connection->resolveAtom (m_formatUTF8_0),
48+ m_connection->resolveAtom (m_formatUTF8_1),
49+ m_connection->resolveAtom (m_formatUTF8_2),
50+ m_connection->resolveAtom (m_formatGTK),
51+ m_connection->resolveAtom (m_formatString),
52+ m_connection->resolveAtom (m_formatText),
53+ m_connection->resolveAtom (m_formatTextPlain)
54+ }) {
5655 targets.push_back (format);
5756 }
5857 }
59- targets.push_back (m_xcbConnection-> resolveXCBAtom (m_TARGETS));
58+ targets.push_back (m_connection-> resolveAtom (m_TARGETS));
6059 xcb.pxcb_change_property (
61- m_xcbConnection ->getRawConnection (),
60+ m_connection ->getRawConnection (),
6261 XCB_PROP_MODE_REPLACE,
6362 sne->requestor ,
6463 sne->property ,
@@ -69,14 +68,14 @@ namespace nbl::ui
6968 } else {
7069 std::lock_guard lk (m_clipboardMutex);
7170 xcb.pxcb_change_property (
72- m_xcbConnection ->getRawConnection (),
71+ m_connection ->getRawConnection (),
7372 XCB_PROP_MODE_REPLACE,
7473 sne->requestor ,
7574 sne->property ,
7675 sne->target ,
7776 8 ,
78- m_stagedClipboard. m_data .size (),
79- m_stagedClipboard. m_data .data ());
77+ m_savedClipboard .size (),
78+ m_savedClipboard .data ());
8079 }
8180 }
8281
@@ -91,22 +90,21 @@ namespace nbl::ui
9190 notify.target = sne->target ;
9291 notify.property = sne->property ;
9392
94- xcb.pxcb_send_event (m_xcbConnection ->getRawConnection (), false ,
93+ xcb.pxcb_send_event (m_connection ->getRawConnection (), false ,
9594 sne->requestor ,
9695 XCB_EVENT_MASK_NO_EVENT, // SelectionNotify events go without mask
9796 (const char *)¬ify);
9897
99- xcb.pxcb_flush (m_xcbConnection ->getRawConnection ());
98+ xcb.pxcb_flush (m_connection ->getRawConnection ());
10099 break ;
101100 }
102101 // Someone else has new content in the clipboard, so is
103102 // notifying us that we should delete our data now.
104103 case XCB_SELECTION_CLEAR: {
105104 auto * sne = reinterpret_cast <xcb_selection_clear_event_t *>(event);
106- if (sne->selection == m_xcbConnection-> resolveXCBAtom (m_CLIPBOARD)) {
105+ if (sne->selection == m_connection-> resolveAtom (m_CLIPBOARD)) {
107106 std::lock_guard<std::mutex> lock (m_clipboardMutex);
108- m_stagedClipboard.m_formats = {};
109- m_stagedClipboard.m_data = std::string ();
107+ m_savedClipboard = std::string ();
110108 }
111109 break ;
112110 }
@@ -119,17 +117,17 @@ namespace nbl::ui
119117 if (sne->target != TARGETS) {
120118 fieldType = sne->target ;
121119 }
122- xcb_get_property_cookie_t cookie = xcb.pxcb_get_property (m_xcbConnection ->getRawConnection (), true ,
120+ xcb_get_property_cookie_t cookie = xcb.pxcb_get_property (m_connection ->getRawConnection (), true ,
123121 sne->requestor ,
124122 sne->property ,
125123 fieldType, 0 , 0x1fffffff ); // 0x1fffffff = INT32_MAX / 4
126124 if (xcb_get_property_reply_t * reply =
127- xcb.pxcb_get_property_reply (m_xcbConnection ->getRawConnection (), cookie, nullptr )) {
125+ xcb.pxcb_get_property_reply (m_connection ->getRawConnection (), cookie, nullptr )) {
128126 core::SRAIIBasedExiter exitReply ([reply]() -> void {
129127 free (reply);
130128 });
131129
132- if (reply->type == m_xcbConnection-> resolveXCBAtom (m_INCR)) {
130+ if (reply->type == m_connection-> resolveAtom (m_INCR)) {
133131 assert (false ); // TODO
134132 } else {
135133 const auto * src = reinterpret_cast <const char *>(xcb.pxcb_get_property_value (reply));
@@ -146,6 +144,4 @@ namespace nbl::ui
146144 }
147145 }
148146 }
149- }
150-
151- #endif
147+ }
0 commit comments