mirror of
https://github.com/minetest/irrlicht.git
synced 2024-11-04 17:30:38 +01:00
Add optional multitouch support to X11.
Thanks @TheBrokenRail for a patch proposal based on example code from esjeon (patch #322). See https://sourceforge.net/p/irrlicht/patches/322 Original example code here: https://github.com/esjeon/xinput2-touch Users have to enable _IRR_LINUX_X11_XINPUT2_ in IrrCompileConfig and link with Xi to make this work. I rewrote the patch a bit and have no system for testing here, so this still needs some testing. I also backported EET_TOUCH_INPUT_EVENT for this from the ogl-es branch. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6178 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
parent
0e56aca052
commit
e92ed55afa
|
@ -1,5 +1,6 @@
|
|||
--------------------------
|
||||
Changes in 1.9 (not yet released)
|
||||
- Add optional multitouch support to X11 (but disabled in IrrCompileConfig by default). Thanks @TheBrokenRail for a patch proposal based on example code from esjeon (patch #322).
|
||||
- Slightly changed close window handling on X11 (optimized and avoids problems on some shells). Thanks @TheBrokenRail for a patch (was part of patch #322).
|
||||
- Add getActiveColor functions to IGUIStaticText and IGUIButton (get currently used color).
|
||||
- Add IGUIEnvironment::addToDeletionQueue to allow save removal of gui elements while iterating over them (like the same named function in ISceneManager).
|
||||
|
|
|
@ -34,6 +34,9 @@ namespace irr
|
|||
IrrlichtDevice::postEventFromUser. They take the same path as mouse events. */
|
||||
EET_KEY_INPUT_EVENT,
|
||||
|
||||
//! A touch input event.
|
||||
EET_TOUCH_INPUT_EVENT,
|
||||
|
||||
//! A joystick (joypad, gamepad) input event.
|
||||
/** Joystick events are created by polling all connected joysticks once per
|
||||
device run() and then passing the events to IrrlichtDevice::postEventFromUser.
|
||||
|
@ -142,6 +145,22 @@ namespace irr
|
|||
EMBSM_FORCE_32_BIT = 0x7fffffff
|
||||
};
|
||||
|
||||
//! Enumeration for all touch input events
|
||||
enum ETOUCH_INPUT_EVENT
|
||||
{
|
||||
//! Touch was pressed down.
|
||||
ETIE_PRESSED_DOWN = 0,
|
||||
|
||||
//! Touch was left up.
|
||||
ETIE_LEFT_UP,
|
||||
|
||||
//! The touch changed its position.
|
||||
ETIE_MOVED,
|
||||
|
||||
//! No real event. Just for convenience to get number of events
|
||||
ETIE_COUNT
|
||||
};
|
||||
|
||||
namespace gui
|
||||
{
|
||||
|
||||
|
@ -275,6 +294,22 @@ struct SEvent
|
|||
|
||||
};
|
||||
|
||||
//! Any kind of touch event.
|
||||
struct STouchInput
|
||||
{
|
||||
// Touch ID.
|
||||
size_t ID;
|
||||
|
||||
// X position of simple touch.
|
||||
s32 X;
|
||||
|
||||
// Y position of simple touch.
|
||||
s32 Y;
|
||||
|
||||
//! Type of touch event.
|
||||
ETOUCH_INPUT_EVENT Event;
|
||||
};
|
||||
|
||||
//! Any kind of mouse event.
|
||||
struct SMouseInput
|
||||
{
|
||||
|
@ -331,6 +366,7 @@ struct SEvent
|
|||
bool Control:1;
|
||||
};
|
||||
|
||||
|
||||
//! A joystick event.
|
||||
/** Unlike other events, joystick events represent the result of polling
|
||||
* each connected joystick once per run() of the device. Joystick events will
|
||||
|
@ -417,6 +453,7 @@ struct SEvent
|
|||
struct SGUIEvent GUIEvent;
|
||||
struct SMouseInput MouseInput;
|
||||
struct SKeyInput KeyInput;
|
||||
struct STouchInput TouchInput;
|
||||
struct SJoystickEvent JoystickEvent;
|
||||
struct SLogEvent LogEvent;
|
||||
struct SUserEvent UserEvent;
|
||||
|
|
|
@ -216,18 +216,22 @@ define out. */
|
|||
#undef _IRR_COMPILE_WITH_X11_
|
||||
#endif
|
||||
|
||||
//! On some Linux systems the XF86 vidmode extension or X11 RandR are missing. Use these flags
|
||||
//! to remove the dependencies such that Irrlicht will compile on those systems, too.
|
||||
//! If you don't need colored cursors you can also disable the Xcursor extension
|
||||
//! On some Linux systems the XF86 vidmode extension, X11 RandR, or XInput2 are missing.
|
||||
//! Use these defines to add/remove support for those dependencies as needed.
|
||||
//! XInput2 (library called Xi) is currently only used to support touch-input.
|
||||
#if defined(_IRR_LINUX_PLATFORM_) && defined(_IRR_COMPILE_WITH_X11_)
|
||||
#define _IRR_LINUX_X11_VIDMODE_
|
||||
//#define _IRR_LINUX_X11_RANDR_
|
||||
//#define _IRR_LINUX_X11_XINPUT2_
|
||||
#ifdef NO_IRR_LINUX_X11_VIDMODE_
|
||||
#undef _IRR_LINUX_X11_VIDMODE_
|
||||
#endif
|
||||
#ifdef NO_IRR_LINUX_X11_RANDR_
|
||||
#undef _IRR_LINUX_X11_RANDR_
|
||||
#endif
|
||||
#ifdef NO_IRR_LINUX_X11_XINPUT2_
|
||||
#undef _IRR_LINUX_X11_XINPUT2_
|
||||
#endif
|
||||
|
||||
//! X11 has by default only monochrome cursors, but using the Xcursor library we can also get color cursor support.
|
||||
//! If you have the need for custom color cursors on X11 then enable this and make sure you also link
|
||||
|
|
|
@ -441,6 +441,7 @@ bool CGUIListBox::OnEvent(const SEvent& event)
|
|||
}
|
||||
}
|
||||
break;
|
||||
case EET_TOUCH_INPUT_EVENT:
|
||||
case EET_LOG_TEXT_EVENT:
|
||||
case EET_USER_EVENT:
|
||||
case EET_JOYSTICK_INPUT_EVENT:
|
||||
|
|
|
@ -25,6 +25,10 @@
|
|||
#include <X11/XKBlib.h>
|
||||
#include <X11/Xatom.h>
|
||||
|
||||
#if defined(_IRR_LINUX_X11_XINPUT2_)
|
||||
#include <X11/extensions/XInput2.h>
|
||||
#endif
|
||||
|
||||
#if defined(_IRR_COMPILE_WITH_OPENGL_)
|
||||
#include "CGLXManager.h"
|
||||
#endif
|
||||
|
@ -74,6 +78,10 @@ namespace
|
|||
Atom X_ATOM_NETWM_STATE;
|
||||
|
||||
Atom X_ATOM_WM_DELETE_WINDOW;
|
||||
|
||||
#if defined(_IRR_LINUX_X11_XINPUT2_)
|
||||
int XI_EXTENSIONS_OPCODE;
|
||||
#endif
|
||||
};
|
||||
|
||||
namespace irr
|
||||
|
@ -568,6 +576,8 @@ bool CIrrDeviceLinux::createWindow()
|
|||
if (WMCheck != None)
|
||||
HasNetWM = true;
|
||||
|
||||
initXInput2();
|
||||
|
||||
#endif // #ifdef _IRR_COMPILE_WITH_X11_
|
||||
return true;
|
||||
}
|
||||
|
@ -1055,6 +1065,29 @@ bool CIrrDeviceLinux::run()
|
|||
XFlush (XDisplay);
|
||||
}
|
||||
break;
|
||||
#if defined(_IRR_LINUX_X11_XINPUT2_)
|
||||
case GenericEvent:
|
||||
{
|
||||
XGenericEventCookie *cookie = &event.xcookie;
|
||||
if (XGetEventData(XDisplay, cookie) && cookie->extension == XI_EXTENSIONS_OPCODE && XI_EXTENSIONS_OPCODE
|
||||
&& (cookie->evtype == XI_TouchUpdate || cookie->evtype == XI_TouchBegin || cookie->evtype == XI_TouchEnd))
|
||||
{
|
||||
XIDeviceEvent *de = (XIDeviceEvent *) cookie->data;
|
||||
|
||||
SEvent ret_event;
|
||||
ret_event.EventType = EET_TOUCH_INPUT_EVENT;
|
||||
|
||||
ret_event.TouchInput.Event = cookie->evtype == XI_TouchUpdate ? ETIE_MOVED : (cookie->evtype == XI_TouchBegin ? ETIE_PRESSED_DOWN : ETIE_LEFT_UP);
|
||||
|
||||
ret_event.TouchInput.ID = de->detail;
|
||||
ret_event.TouchInput.X = de->event_x;
|
||||
ret_event.TouchInput.Y = de->event_y;
|
||||
|
||||
postEventFromUser(ret_event);
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
break;
|
||||
|
@ -1940,6 +1973,62 @@ void CIrrDeviceLinux::initXAtoms()
|
|||
#endif
|
||||
}
|
||||
|
||||
void CIrrDeviceLinux::initXInput2()
|
||||
{
|
||||
#if defined(_IRR_LINUX_X11_XINPUT2_)
|
||||
int ev=0;
|
||||
int err=0;
|
||||
if (!XQueryExtension(XDisplay, "XInputExtension", &XI_EXTENSIONS_OPCODE, &ev, &err))
|
||||
{
|
||||
os::Printer::log("X Input extension not available.", ELL_WARNING);
|
||||
return;
|
||||
}
|
||||
|
||||
int major = 2;
|
||||
int minor = 3;
|
||||
int rc = XIQueryVersion(XDisplay, &major, &minor);
|
||||
if ( rc != Success )
|
||||
{
|
||||
os::Printer::log("No XI2 support.", ELL_WARNING);
|
||||
return;
|
||||
}
|
||||
|
||||
int cnt = 0;
|
||||
XIDeviceInfo *di = XIQueryDevice(XDisplay, XIAllDevices, &cnt);
|
||||
if ( di )
|
||||
{
|
||||
for (int i = 0; i < cnt; ++i)
|
||||
{
|
||||
bool hasTouchClass = false;
|
||||
XIDeviceInfo *dev = &di[i];
|
||||
for (int j = 0; j < dev->num_classes; ++j)
|
||||
{
|
||||
if (dev->classes[j]->type == XITouchClass)
|
||||
{
|
||||
hasTouchClass = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( hasTouchClass )
|
||||
{
|
||||
XIEventMask eventMask;
|
||||
unsigned char mask[XIMaskLen(XI_TouchEnd)];
|
||||
memset(mask, 0, sizeof(mask));
|
||||
eventMask.deviceid = dev->deviceid;
|
||||
eventMask.mask_len = sizeof(mask);
|
||||
eventMask.mask = mask;
|
||||
XISetMask(eventMask.mask, XI_TouchBegin);
|
||||
XISetMask(eventMask.mask, XI_TouchUpdate);
|
||||
XISetMask(eventMask.mask, XI_TouchEnd);
|
||||
|
||||
XISelectEvents(XDisplay, XWindow, &eventMask, 1);
|
||||
}
|
||||
}
|
||||
XIFreeDeviceInfo(di);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifdef _IRR_COMPILE_WITH_X11_
|
||||
|
||||
|
|
|
@ -155,6 +155,8 @@ namespace irr
|
|||
|
||||
void initXAtoms();
|
||||
|
||||
void initXInput2();
|
||||
|
||||
bool switchToFullscreen(bool reset=false);
|
||||
|
||||
#ifdef _IRR_COMPILE_WITH_X11_
|
||||
|
|
Loading…
Reference in New Issue
Block a user