Commit 2221cee8 authored by cutealien's avatar cutealien

- IOSOperator::getTextFromClipboard returns now const c8* instead of c8*

- Support for copy&paste on linux (X11) added (fixing bug 2804014 found by Pan)


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2430 dfc29bdd-3216-0410-991c-e03cc46cb475
parent da870385
Changes in 1.6 Changes in 1.6
- IOSOperator::getTextFromClipboard returns now const c8* instead of c8*
- Support for copy&paste on linux (X11) added (fixing bug 2804014 found by Pan)
- bugfix for 2795321 found by egrath: Don't rely anymore on broken XkbSetDetectableAutoRepeat. - bugfix for 2795321 found by egrath: Don't rely anymore on broken XkbSetDetectableAutoRepeat.
- bugfix: Use make_lower throughout for spritebank filenames (found and patched by Ion Dune) - bugfix: Use make_lower throughout for spritebank filenames (found and patched by Ion Dune)
......
...@@ -26,7 +26,7 @@ public: ...@@ -26,7 +26,7 @@ public:
//! Get text from the clipboard //! Get text from the clipboard
/** \return Returns 0 if no string is in there. */ /** \return Returns 0 if no string is in there. */
virtual c8* getTextFromClipboard() const = 0; virtual const c8* getTextFromClipboard() const = 0;
//! Get the processor speed in megahertz //! Get the processor speed in megahertz
/** \param MHz The integer variable to store the speed in. /** \param MHz The integer variable to store the speed in.
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "CColorConverter.h" #include "CColorConverter.h"
#include "SIrrCreationParameters.h" #include "SIrrCreationParameters.h"
#include <X11/XKBlib.h> #include <X11/XKBlib.h>
#include <X11/Xatom.h>
#if defined _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ #if defined _IRR_COMPILE_WITH_JOYSTICK_EVENTS_
#include <fcntl.h> #include <fcntl.h>
...@@ -43,7 +44,13 @@ namespace irr ...@@ -43,7 +44,13 @@ namespace irr
} }
} // end namespace irr } // end namespace irr
namespace
{
Atom X_ATOM_CLIPBOARD;
Atom X_ATOM_TARGETS;
Atom X_ATOM_UTF8_STRING;
Atom X_ATOM_TEXT;
};
namespace irr namespace irr
{ {
...@@ -82,7 +89,7 @@ CIrrDeviceLinux::CIrrDeviceLinux(const SIrrlichtCreationParameters& param) ...@@ -82,7 +89,7 @@ CIrrDeviceLinux::CIrrDeviceLinux(const SIrrlichtCreationParameters& param)
linuxversion += " "; linuxversion += " ";
linuxversion += LinuxInfo.machine; linuxversion += LinuxInfo.machine;
Operator = new COSOperator(linuxversion.c_str()); Operator = new COSOperator(linuxversion.c_str(), this);
os::Printer::log(linuxversion.c_str(), ELL_INFORMATION); os::Printer::log(linuxversion.c_str(), ELL_INFORMATION);
// create keymap // create keymap
...@@ -658,6 +665,8 @@ bool CIrrDeviceLinux::createWindow() ...@@ -658,6 +665,8 @@ bool CIrrDeviceLinux::createWindow()
SoftwareImage->data = (char*) malloc(SoftwareImage->bytes_per_line * SoftwareImage->height * sizeof(char)); SoftwareImage->data = (char*) malloc(SoftwareImage->bytes_per_line * SoftwareImage->height * sizeof(char));
} }
initXAtoms();
#endif // #ifdef _IRR_COMPILE_WITH_X11_ #endif // #ifdef _IRR_COMPILE_WITH_X11_
return true; return true;
} }
...@@ -918,6 +927,53 @@ bool CIrrDeviceLinux::run() ...@@ -918,6 +927,53 @@ bool CIrrDeviceLinux::run()
} }
break; break;
case SelectionRequest:
{
XEvent respond;
XSelectionRequestEvent *req = &(event.xselectionrequest);
Atom target = req->target; // debugging
if ( req->target == XA_STRING)
{
XChangeProperty (display,
req->requestor,
req->property, req->target,
8, // format
PropModeReplace,
(unsigned char*) Clipboard.c_str(),
Clipboard.size());
respond.xselection.property = req->property;
}
else if ( req->target == X_ATOM_TARGETS )
{
long data[2];
data[0] = X_ATOM_TEXT;
data[1] = XA_STRING;
XChangeProperty (display, req->requestor,
req->property, req->target,
8, PropModeReplace, (unsigned char *) &data,
sizeof (data));
respond.xselection.property = req->property;
}
else
{
char * name = XGetAtomName(display, req->target); // debugging
XFree(name);
respond.xselection.property= None;
}
respond.xselection.type= SelectionNotify;
respond.xselection.display= req->display;
respond.xselection.requestor= req->requestor;
respond.xselection.selection=req->selection;
respond.xselection.target= req->target;
respond.xselection.time = req->time;
XSendEvent (display, req->requestor,0,0,&respond);
XFlush (display);
}
break;
default: default:
break; break;
} // end switch } // end switch
...@@ -1496,6 +1552,79 @@ void CIrrDeviceLinux::pollJoysticks() ...@@ -1496,6 +1552,79 @@ void CIrrDeviceLinux::pollJoysticks()
#endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ #endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_
} }
//! gets text from the clipboard
//! \return Returns 0 if no string is in there.
const c8* CIrrDeviceLinux::getTextFromClipboard() const
{
#if defined(_IRR_COMPILE_WITH_X11_)
Window ownerWindow = XGetSelectionOwner (display, X_ATOM_CLIPBOARD);
if ( ownerWindow == window )
{
return Clipboard.c_str();
}
Clipboard = "";
if (ownerWindow != None )
{
XConvertSelection (display, X_ATOM_CLIPBOARD, XA_STRING, None, ownerWindow, CurrentTime);
XFlush (display);
// check for data
Atom type;
int format;
unsigned long numItems, bytesLeft, dummy;
unsigned char *data;
XGetWindowProperty (display, ownerWindow,
XA_STRING, // property name
0, // offset
0, // length (we only check for data, so 0)
0, // Delete 0==false
AnyPropertyType, // AnyPropertyType or property identifier
&type, // return type
&format, // return format
&numItems, // number items
&bytesLeft, // remaining bytes for partial reads
&data); // data
if ( bytesLeft > 0 )
{
// there is some data to get
int result = XGetWindowProperty (display, ownerWindow, XA_STRING, 0,
bytesLeft, 0, AnyPropertyType, &type, &format,
&numItems, &dummy, &data);
if (result == Success)
Clipboard = (irr::c8*)data;
XFree (data);
}
}
return Clipboard.c_str();
#else
return 0;
#endif
}
//! copies text to the clipboard
void CIrrDeviceLinux::copyToClipboard(const c8* text) const
{
#if defined(_IRR_COMPILE_WITH_X11_)
// 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 (display, X_ATOM_CLIPBOARD, window, CurrentTime);
XFlush (display);
#endif
}
void CIrrDeviceLinux::initXAtoms()
{
#ifdef _IRR_COMPILE_WITH_X11_
X_ATOM_CLIPBOARD = XInternAtom(display, "CLIPBOARD", False);
X_ATOM_TARGETS = XInternAtom(display, "TARGETS", False);
X_ATOM_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
X_ATOM_TEXT = XInternAtom (display, "TEXT", False);
#endif
}
extern "C" IRRLICHT_API IrrlichtDevice* IRRCALLCONV createDeviceEx(const SIrrlichtCreationParameters& param) extern "C" IRRLICHT_API IrrlichtDevice* IRRCALLCONV createDeviceEx(const SIrrlichtCreationParameters& param)
{ {
......
...@@ -96,6 +96,14 @@ namespace irr ...@@ -96,6 +96,14 @@ namespace irr
//! Activate any joysticks, and generate events for them. //! Activate any joysticks, and generate events for them.
virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo); virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo);
//! gets text from the clipboard
//! \return Returns 0 if no string is in there.
virtual const c8* getTextFromClipboard() const;
//! copies text to the clipboard
//! This sets the clipboard selection and _not_ the primary selection which you have on X on the middle mouse button.
virtual void copyToClipboard(const c8* text) const;
private: private:
//! create the driver //! create the driver
...@@ -107,6 +115,8 @@ namespace irr ...@@ -107,6 +115,8 @@ namespace irr
void pollJoysticks(); void pollJoysticks();
void initXAtoms();
//! Implementation of the linux cursor control //! Implementation of the linux cursor control
class CCursorControl : public gui::ICursorControl class CCursorControl : public gui::ICursorControl
{ {
...@@ -310,6 +320,7 @@ namespace irr ...@@ -310,6 +320,7 @@ namespace irr
XSetWindowAttributes attributes; XSetWindowAttributes attributes;
XSizeHints* StdHints; XSizeHints* StdHints;
XImage* SoftwareImage; XImage* SoftwareImage;
mutable core::stringc Clipboard;
#ifdef _IRR_LINUX_X11_VIDMODE_ #ifdef _IRR_LINUX_X11_VIDMODE_
XF86VidModeModeInfo oldVideoMode; XF86VidModeModeInfo oldVideoMode;
#endif #endif
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
// For conditions of distribution and use, see copyright notice in irrlicht.h // For conditions of distribution and use, see copyright notice in irrlicht.h
#include "COSOperator.h" #include "COSOperator.h"
#include "IrrCompileConfig.h"
#ifdef _IRR_WINDOWS_API_ #ifdef _IRR_WINDOWS_API_
#ifdef _IRR_XBOX_PLATFORM_ #ifdef _IRR_XBOX_PLATFORM_
...@@ -22,10 +21,21 @@ ...@@ -22,10 +21,21 @@
#endif #endif
#endif #endif
#if defined(_IRR_USE_LINUX_DEVICE_)
#include "CIrrDeviceLinux.h"
#endif
namespace irr namespace irr
{ {
#if defined(_IRR_USE_LINUX_DEVICE_)
// constructor linux
COSOperator::COSOperator(const c8* osversion, CIrrDeviceLinux* device)
: IrrDeviceLinux(device)
{
}
#else // not linux
// constructor // constructor
COSOperator::COSOperator(const c8* osVersion) : OperatingSystem(osVersion) COSOperator::COSOperator(const c8* osVersion) : OperatingSystem(osVersion)
{ {
...@@ -33,7 +43,7 @@ COSOperator::COSOperator(const c8* osVersion) : OperatingSystem(osVersion) ...@@ -33,7 +43,7 @@ COSOperator::COSOperator(const c8* osVersion) : OperatingSystem(osVersion)
setDebugName("COSOperator"); setDebugName("COSOperator");
#endif #endif
} }
#endif
//! returns the current operating system version as string. //! returns the current operating system version as string.
const wchar_t* COSOperator::getOperationSystemVersion() const const wchar_t* COSOperator::getOperationSystemVersion() const
...@@ -72,16 +82,19 @@ void COSOperator::copyToClipboard(const c8* text) const ...@@ -72,16 +82,19 @@ void COSOperator::copyToClipboard(const c8* text) const
#elif defined(_IRR_USE_OSX_DEVICE_) #elif defined(_IRR_USE_OSX_DEVICE_)
OSXCopyToClipboard(text); OSXCopyToClipboard(text);
#elif defined(_IRR_USE_LINUX_DEVICE_)
if ( IrrDeviceLinux )
IrrDeviceLinux->copyToClipboard(text);
#else #else
// todo: Linux version
#endif #endif
} }
//! gets text from the clipboard //! gets text from the clipboard
//! \return Returns 0 if no string is in there. //! \return Returns 0 if no string is in there.
c8* COSOperator::getTextFromClipboard() const const c8* COSOperator::getTextFromClipboard() const
{ {
#if defined(_IRR_XBOX_PLATFORM_) #if defined(_IRR_XBOX_PLATFORM_)
return 0; return 0;
...@@ -99,9 +112,13 @@ c8* COSOperator::getTextFromClipboard() const ...@@ -99,9 +112,13 @@ c8* COSOperator::getTextFromClipboard() const
#elif defined(_IRR_USE_OSX_DEVICE_) #elif defined(_IRR_USE_OSX_DEVICE_)
return (OSXCopyFromClipboard()); return (OSXCopyFromClipboard());
#else
// todo: Linux version #elif defined(_IRR_USE_LINUX_DEVICE_)
if ( IrrDeviceLinux )
return IrrDeviceLinux->getTextFromClipboard();
return 0;
#else
return 0; return 0;
#endif #endif
......
...@@ -7,17 +7,24 @@ ...@@ -7,17 +7,24 @@
#include "IOSOperator.h" #include "IOSOperator.h"
#include "irrString.h" #include "irrString.h"
#include "IrrCompileConfig.h"
namespace irr namespace irr
{ {
class CIrrDeviceLinux;
//! The Operating system operator provides operation system specific methods and informations. //! The Operating system operator provides operation system specific methods and informations.
class COSOperator : public IOSOperator class COSOperator : public IOSOperator
{ {
public: public:
// constructor // constructor
#if defined(_IRR_USE_LINUX_DEVICE_)
COSOperator(const c8* osversion, CIrrDeviceLinux* device);
#else
COSOperator(const c8* osversion); COSOperator(const c8* osversion);
#endif
//! returns the current operation system version as string. //! returns the current operation system version as string.
virtual const wchar_t* getOperationSystemVersion() const; virtual const wchar_t* getOperationSystemVersion() const;
...@@ -27,7 +34,7 @@ public: ...@@ -27,7 +34,7 @@ public:
//! gets text from the clipboard //! gets text from the clipboard
//! \return Returns 0 if no string is in there. //! \return Returns 0 if no string is in there.
virtual c8* getTextFromClipboard() const; virtual const c8* getTextFromClipboard() const;
//! gets the processor speed in megahertz //! gets the processor speed in megahertz
//! \param Mhz: //! \param Mhz:
...@@ -43,6 +50,11 @@ public: ...@@ -43,6 +50,11 @@ public:
private: private:
core::stringw OperatingSystem; core::stringw OperatingSystem;
#if defined(_IRR_USE_LINUX_DEVICE_)
CIrrDeviceLinux * IrrDeviceLinux;
#endif
}; };
} // end namespace } // end namespace
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment