aboutsummaryrefslogtreecommitdiff
path: root/source/Irrlicht/CIrrDeviceLinux.cpp
diff options
context:
space:
mode:
authornumzero <numzer0@yandex.ru>2023-03-25 10:42:11 +0300
committernumzero <numzer0@yandex.ru>2023-03-25 10:42:47 +0300
commitd97d1708d68a98c039db8a06c4110bfc961d3fb1 (patch)
tree1a90cd7a34793982aa9376468feb41e67d2b7cdc /source/Irrlicht/CIrrDeviceLinux.cpp
parentba77d01c91a363ad932ecd26c3eaba82ddf7a6f0 (diff)
parent799c8b936f9a2cc4f3a8bc56237fb9a8dedf853e (diff)
downloadirrlicht-d97d1708d68a98c039db8a06c4110bfc961d3fb1.tar.xz
Resolve conflicts with master
Diffstat (limited to 'source/Irrlicht/CIrrDeviceLinux.cpp')
-rw-r--r--source/Irrlicht/CIrrDeviceLinux.cpp110
1 files changed, 76 insertions, 34 deletions
diff --git a/source/Irrlicht/CIrrDeviceLinux.cpp b/source/Irrlicht/CIrrDeviceLinux.cpp
index b447015..0efc8f4 100644
--- a/source/Irrlicht/CIrrDeviceLinux.cpp
+++ b/source/Irrlicht/CIrrDeviceLinux.cpp
@@ -287,26 +287,26 @@ void IrrPrintXGrabError(int grabResult, const c8 * grabCommand )
{
if ( grabResult == GrabSuccess )
{
-// os::Printer::log(grabCommand, ": GrabSuccess", ELL_INFORMATION);
+// os::Printer::log(grabCommand, "GrabSuccess", ELL_INFORMATION);
return;
}
switch ( grabResult )
{
case AlreadyGrabbed:
- os::Printer::log(grabCommand, ": AlreadyGrabbed", ELL_WARNING);
+ os::Printer::log(grabCommand, "AlreadyGrabbed", ELL_WARNING);
break;
case GrabNotViewable:
- os::Printer::log(grabCommand, ": GrabNotViewable", ELL_WARNING);
+ os::Printer::log(grabCommand, "GrabNotViewable", ELL_WARNING);
break;
case GrabFrozen:
- os::Printer::log(grabCommand, ": GrabFrozen", ELL_WARNING);
+ os::Printer::log(grabCommand, "GrabFrozen", ELL_WARNING);
break;
case GrabInvalidTime:
- os::Printer::log(grabCommand, ": GrabInvalidTime", ELL_WARNING);
+ os::Printer::log(grabCommand, "GrabInvalidTime", ELL_WARNING);
break;
default:
- os::Printer::log(grabCommand, ": grab failed with unknown problem", ELL_WARNING);
+ os::Printer::log(grabCommand, "grab failed with unknown problem", ELL_WARNING);
break;
}
}
@@ -380,7 +380,7 @@ bool CIrrDeviceLinux::createWindow()
}
#ifdef _DEBUG
else
- os::Printer::log("Visual chosen: ", core::stringc(static_cast<u32>(VisualInfo->visualid)).c_str(), ELL_DEBUG);
+ os::Printer::log("Visual chosen", core::stringc(static_cast<u32>(VisualInfo->visualid)).c_str(), ELL_DEBUG);
#endif
// create color map
@@ -1000,12 +1000,15 @@ bool CIrrDeviceLinux::run()
send_response(req->property);
};
- if (req->selection != X_ATOM_CLIPBOARD ||
+ if ((req->selection != X_ATOM_CLIPBOARD &&
+ req->selection != XA_PRIMARY) ||
req->owner != XWindow) {
// we are not the owner, refuse request
send_response_refuse();
break;
}
+ const core::stringc &text_buffer = req->selection == X_ATOM_CLIPBOARD ?
+ Clipboard : PrimarySelection;
// for debugging:
//~ {
@@ -1026,8 +1029,8 @@ bool CIrrDeviceLinux::run()
req->target, X_ATOM_UTF8_STRING,
8, // format = 8-bit
PropModeReplace,
- (unsigned char *)Clipboard.c_str(),
- Clipboard.size());
+ (unsigned char *)text_buffer.c_str(),
+ text_buffer.size());
send_response(req->target);
break;
}
@@ -1052,8 +1055,8 @@ bool CIrrDeviceLinux::run()
set_property_and_notify(
X_ATOM_UTF8_STRING,
8,
- Clipboard.c_str(),
- Clipboard.size()
+ text_buffer.c_str(),
+ text_buffer.size()
);
} else {
@@ -1676,47 +1679,49 @@ void CIrrDeviceLinux::pollJoysticks()
}
+#if defined(_IRR_COMPILE_WITH_X11_)
//! gets text from the clipboard
//! \return Returns 0 if no string is in there, otherwise utf-8 text.
-const c8 *CIrrDeviceLinux::getTextFromClipboard() const
+const c8 *CIrrDeviceLinux::getTextFromSelection(Atom selection, core::stringc &text_buffer) const
{
-#if defined(_IRR_COMPILE_WITH_X11_)
- Window ownerWindow = XGetSelectionOwner(XDisplay, X_ATOM_CLIPBOARD);
+ Window ownerWindow = XGetSelectionOwner(XDisplay, selection);
if (ownerWindow == XWindow) {
- return Clipboard.c_str();
+ return text_buffer.c_str();
}
- Clipboard = "";
+ text_buffer = "";
if (ownerWindow == None) {
- return Clipboard.c_str();
+ return text_buffer.c_str();
}
// delete the property to be set beforehand
XDeleteProperty(XDisplay, XWindow, XA_PRIMARY);
- XConvertSelection(XDisplay, X_ATOM_CLIPBOARD, X_ATOM_UTF8_STRING, XA_PRIMARY,
+ XConvertSelection(XDisplay, selection, X_ATOM_UTF8_STRING, XA_PRIMARY,
XWindow, CurrentTime);
XFlush(XDisplay);
// wait for event via a blocking call
XEvent event_ret;
+ std::pair<Window, Atom> args(XWindow, selection);
XIfEvent(XDisplay, &event_ret, [](Display *_display, XEvent *event, XPointer arg) {
+ auto p = reinterpret_cast<std::pair<Window, Atom> *>(arg);
return (Bool) (event->type == SelectionNotify &&
- event->xselection.requestor == *(Window *)arg &&
- event->xselection.selection == X_ATOM_CLIPBOARD &&
+ event->xselection.requestor == p->first &&
+ event->xselection.selection == p->second &&
event->xselection.target == X_ATOM_UTF8_STRING);
- }, (XPointer)&XWindow);
+ }, (XPointer)&args);
_IRR_DEBUG_BREAK_IF(!(event_ret.type == SelectionNotify &&
event_ret.xselection.requestor == XWindow &&
- event_ret.xselection.selection == X_ATOM_CLIPBOARD &&
+ event_ret.xselection.selection == selection &&
event_ret.xselection.target == X_ATOM_UTF8_STRING));
Atom property_set = event_ret.xselection.property;
if (event_ret.xselection.property == None) {
// request failed => empty string
- return Clipboard.c_str();
+ return text_buffer.c_str();
}
// check for data
@@ -1743,15 +1748,15 @@ const c8 *CIrrDeviceLinux::getTextFromClipboard() const
// for debugging:
//~ {
//~ char *type_name = XGetAtomName(XDisplay, type);
- //~ fprintf(stderr, "CIrrDeviceLinux::getTextFromClipboard: actual type: %s (=%ld)\n",
+ //~ fprintf(stderr, "CIrrDeviceLinux::getTextFromSelection: actual type: %s (=%ld)\n",
//~ type_name, type);
//~ XFree(type_name);
//~ }
if (type != X_ATOM_UTF8_STRING && type != X_ATOM_UTF8_MIME_TYPE) {
- os::Printer::log("CIrrDeviceLinux::getTextFromClipboard: did not get utf-8 string",
+ os::Printer::log("CIrrDeviceLinux::getTextFromSelection: did not get utf-8 string",
ELL_WARNING);
- return Clipboard.c_str();
+ return text_buffer.c_str();
}
if (bytesLeft > 0) {
@@ -1760,20 +1765,49 @@ const c8 *CIrrDeviceLinux::getTextFromClipboard() const
bytesLeft, 0, AnyPropertyType, &type, &format,
&numItems, &dummy, &data);
if (result == Success)
- Clipboard = (irr::c8 *)data;
+ text_buffer = (irr::c8 *)data;
XFree (data);
}
// delete the property again, to inform the owner about the successful transfer
XDeleteProperty(XDisplay, XWindow, property_set);
- return Clipboard.c_str();
+ return text_buffer.c_str();
+}
+#endif
+//! gets text from the clipboard
+//! \return Returns 0 if no string is in there, otherwise utf-8 text.
+const c8 *CIrrDeviceLinux::getTextFromClipboard() const
+{
+#if defined(_IRR_COMPILE_WITH_X11_)
+ return getTextFromSelection(X_ATOM_CLIPBOARD, Clipboard);
#else
return nullptr;
#endif
}
+//! gets text from the primary selection
+//! \return Returns 0 if no string is in there, otherwise utf-8 text.
+const c8 *CIrrDeviceLinux::getTextFromPrimarySelection() const
+{
+#if defined(_IRR_COMPILE_WITH_X11_)
+ return getTextFromSelection(XA_PRIMARY, PrimarySelection);
+#else
+ return nullptr;
+#endif
+}
+
+#if defined(_IRR_COMPILE_WITH_X11_)
+bool CIrrDeviceLinux::becomeSelectionOwner(Atom selection) const
+{
+ XSetSelectionOwner (XDisplay, selection, XWindow, CurrentTime);
+ XFlush (XDisplay);
+ Window owner = XGetSelectionOwner(XDisplay, selection);
+ return owner == XWindow;
+}
+#endif
+
//! copies text to the clipboard
void CIrrDeviceLinux::copyToClipboard(const c8 *text) const
{
@@ -1781,22 +1815,30 @@ void CIrrDeviceLinux::copyToClipboard(const c8 *text) const
// Actually there is no clipboard on X but applications just say they own the clipboard and return text when asked.
// Which btw. also means that on X you lose clipboard content when closing applications.
Clipboard = text;
- XSetSelectionOwner (XDisplay, X_ATOM_CLIPBOARD, XWindow, CurrentTime);
- XFlush (XDisplay);
- Window owner = XGetSelectionOwner(XDisplay, X_ATOM_CLIPBOARD);
- if (owner != XWindow) {
+ if (!becomeSelectionOwner(X_ATOM_CLIPBOARD)) {
os::Printer::log("CIrrDeviceLinux::copyToClipboard: failed to set owner", ELL_WARNING);
}
#endif
}
+//! copies text to the primary selection
+void CIrrDeviceLinux::copyToPrimarySelection(const c8 *text) const
+{
+#if defined(_IRR_COMPILE_WITH_X11_)
+ PrimarySelection = text;
+ if (!becomeSelectionOwner(XA_PRIMARY)) {
+ os::Printer::log("CIrrDeviceLinux::copyToPrimarySelection: failed to set owner", ELL_WARNING);
+ }
+#endif
+}
+
#ifdef _IRR_COMPILE_WITH_X11_
// return true if the passed event has the type passed in parameter arg
Bool PredicateIsEventType(Display *display, XEvent *event, XPointer arg)
{
if ( event && event->type == *(int*)arg )
{
-// os::Printer::log("remove event:", core::stringc((int)arg).c_str(), ELL_INFORMATION);
+// os::Printer::log("remove event", core::stringc((int)arg).c_str(), ELL_INFORMATION);
return True;
}
return False;