summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
Diffstat (limited to 'platform')
-rw-r--r--platform/android/build.gradle.template2
-rw-r--r--platform/android/java/src/org/godotengine/godot/Godot.java18
-rw-r--r--platform/iphone/os_iphone.cpp4
-rw-r--r--platform/iphone/os_iphone.h2
-rw-r--r--platform/osx/os_osx.h1
-rw-r--r--platform/server/os_server.h1
-rw-r--r--platform/windows/detect.py11
-rw-r--r--platform/windows/os_windows.cpp65
-rw-r--r--platform/windows/os_windows.h7
-rw-r--r--platform/windows/stream_peer_winsock.cpp4
-rw-r--r--platform/x11/detect.py9
-rw-r--r--platform/x11/os_x11.cpp160
-rw-r--r--platform/x11/os_x11.h11
13 files changed, 250 insertions, 45 deletions
diff --git a/platform/android/build.gradle.template b/platform/android/build.gradle.template
index 11c49fbb50..4a44d1c5f9 100644
--- a/platform/android/build.gradle.template
+++ b/platform/android/build.gradle.template
@@ -31,7 +31,7 @@ android {
disable 'MissingTranslation'
}
- compileSdkVersion 24
+ compileSdkVersion 26
buildToolsVersion "26.0.1"
useLibrary 'org.apache.http.legacy'
diff --git a/platform/android/java/src/org/godotengine/godot/Godot.java b/platform/android/java/src/org/godotengine/godot/Godot.java
index 41dcba5c2c..4daf06142d 100644
--- a/platform/android/java/src/org/godotengine/godot/Godot.java
+++ b/platform/android/java/src/org/godotengine/godot/Godot.java
@@ -970,7 +970,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
boolean indeterminate;
switch (newState) {
case IDownloaderClient.STATE_IDLE:
- Log.d("GODOT", "STATE IDLE");
+ Log.d("GODOT", "DOWNLOAD STATE IDLE");
// STATE_IDLE means the service is listening, so it's
// safe to start making calls via mRemoteService.
paused = false;
@@ -978,13 +978,13 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
break;
case IDownloaderClient.STATE_CONNECTING:
case IDownloaderClient.STATE_FETCHING_URL:
- Log.d("GODOT", "STATE CONNECTION / FETCHING URL");
+ Log.d("GODOT", "DOWNLOAD STATE CONNECTION / FETCHING URL");
showDashboard = true;
paused = false;
indeterminate = true;
break;
case IDownloaderClient.STATE_DOWNLOADING:
- Log.d("GODOT", "STATE DOWNLOADING");
+ Log.d("GODOT", "DOWNLOAD STATE DOWNLOADING");
paused = false;
showDashboard = true;
indeterminate = false;
@@ -994,14 +994,14 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
case IDownloaderClient.STATE_FAILED:
case IDownloaderClient.STATE_FAILED_FETCHING_URL:
case IDownloaderClient.STATE_FAILED_UNLICENSED:
- Log.d("GODOT", "MANY TYPES OF FAILING");
+ Log.d("GODOT", "DOWNLOAD STATE: FAILED, CANCELLED, UNLICENSED OR FAILED TO FETCH URL");
paused = true;
showDashboard = false;
indeterminate = false;
break;
case IDownloaderClient.STATE_PAUSED_NEED_CELLULAR_PERMISSION:
case IDownloaderClient.STATE_PAUSED_WIFI_DISABLED_NEED_CELLULAR_PERMISSION:
- Log.d("GODOT", "PAUSED FOR SOME STUPID REASON");
+ Log.d("GODOT", "DOWNLOAD STATE: PAUSED BY MISSING CELLULAR PERMISSION");
showDashboard = false;
paused = true;
indeterminate = false;
@@ -1009,18 +1009,18 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
break;
case IDownloaderClient.STATE_PAUSED_BY_REQUEST:
- Log.d("GODOT", "PAUSED BY STUPID USER");
+ Log.d("GODOT", "DOWNLOAD STATE: PAUSED BY USER");
paused = true;
indeterminate = false;
break;
case IDownloaderClient.STATE_PAUSED_ROAMING:
case IDownloaderClient.STATE_PAUSED_SDCARD_UNAVAILABLE:
- Log.d("GODOT", "PAUSED BY ROAMING WTF!?");
+ Log.d("GODOT", "DOWNLOAD STATE: PAUSED BY ROAMING OR SDCARD UNAVAILABLE");
paused = true;
indeterminate = false;
break;
case IDownloaderClient.STATE_COMPLETED:
- Log.d("GODOT", "COMPLETED");
+ Log.d("GODOT", "DOWNLOAD STATE: COMPLETED");
showDashboard = false;
paused = false;
indeterminate = false;
@@ -1028,7 +1028,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
initializeGodot();
return;
default:
- Log.d("GODOT", "DEFAULT ????");
+ Log.d("GODOT", "DOWNLOAD STATE: DEFAULT");
paused = true;
indeterminate = true;
showDashboard = true;
diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp
index fbe3bd310d..f06657cd7b 100644
--- a/platform/iphone/os_iphone.cpp
+++ b/platform/iphone/os_iphone.cpp
@@ -394,12 +394,12 @@ void OSIPhone::alert(const String &p_alert, const String &p_title) {
iOS::alert(utf8_alert.get_data(), utf8_title.get_data());
}
-Error OSIPhone::open_dynamic_library(const String p_path, void *&p_library_handle) {
+Error OSIPhone::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) {
if (p_path.length() == 0) {
p_library_handle = RTLD_SELF;
return OK;
}
- return OS_Unix::open_dynamic_library(p_path, p_library_handle);
+ return OS_Unix::open_dynamic_library(p_path, p_library_handle, p_also_set_library_path);
}
Error OSIPhone::close_dynamic_library(void *p_library_handle) {
diff --git a/platform/iphone/os_iphone.h b/platform/iphone/os_iphone.h
index 1ef673765a..3f989b49be 100644
--- a/platform/iphone/os_iphone.h
+++ b/platform/iphone/os_iphone.h
@@ -155,7 +155,7 @@ public:
virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
- virtual Error open_dynamic_library(const String p_path, void *&p_library_handle);
+ virtual Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false);
virtual Error close_dynamic_library(void *p_library_handle);
virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle, bool p_optional = false);
diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h
index 9a740a7bea..6543ca7dd2 100644
--- a/platform/osx/os_osx.h
+++ b/platform/osx/os_osx.h
@@ -43,7 +43,6 @@
#include "servers/visual_server.h"
#include <ApplicationServices/ApplicationServices.h>
-//bitch
#undef CursorShape
/**
@author Juan Linietsky <reduzio@gmail.com>
diff --git a/platform/server/os_server.h b/platform/server/os_server.h
index 03f7c2a6c8..40b10c019f 100644
--- a/platform/server/os_server.h
+++ b/platform/server/os_server.h
@@ -38,7 +38,6 @@
#include "servers/visual/rasterizer.h"
#include "servers/visual_server.h"
-//bitch
#undef CursorShape
/**
@author Juan Linietsky <reduzio@gmail.com>
diff --git a/platform/windows/detect.py b/platform/windows/detect.py
index fbb02c9d1b..890decf962 100644
--- a/platform/windows/detect.py
+++ b/platform/windows/detect.py
@@ -64,6 +64,10 @@ def get_opts():
return [
('mingw_prefix_32', 'MinGW prefix (Win32)', mingw32),
('mingw_prefix_64', 'MinGW prefix (Win64)', mingw64),
+ # Targeted Windows version: 7 (and later), minimum supported version
+ # XP support dropped after EOL due to missing API for IPv6 and other issues
+ # Vista support dropped after EOL due to GH-10243
+ ('target_win_version', 'Targeted Windows version, >= 0x0601 (Windows 7)', '0x0601'),
EnumVariable('debug_symbols', 'Add debug symbols to release version', 'yes', ('yes', 'no', 'full')),
]
@@ -97,11 +101,6 @@ def configure(env):
env.Append(CPPPATH=['#platform/windows'])
- # Targeted Windows version: 7 (and later), minimum supported version
- # XP support dropped after EOL due to missing API for IPv6 and other issues
- # Vista support dropped after EOL due to GH-10243
- winver = "0x0601"
-
if (os.name == "nt" and os.getenv("VCINSTALLDIR")): # MSVC
env['ENV']['TMP'] = os.environ['TMP']
@@ -175,7 +174,7 @@ def configure(env):
env.Append(CCFLAGS=['/DWASAPI_ENABLED'])
env.Append(CCFLAGS=['/DTYPED_METHOD_BIND'])
env.Append(CCFLAGS=['/DWIN32'])
- env.Append(CCFLAGS=['/DWINVER=%s' % winver, '/D_WIN32_WINNT=%s' % winver])
+ env.Append(CCFLAGS=['/DWINVER=%s' % env['target_win_version'], '/D_WIN32_WINNT=%s' % env['target_win_version']])
if env["bits"] == "64":
env.Append(CCFLAGS=['/D_WIN64'])
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index 9bcbb6ddb6..79a760f055 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -73,22 +73,17 @@ static String format_error_message(DWORD id) {
LPWSTR messageBuffer = NULL;
size_t size = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL, id, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&messageBuffer, 0, NULL);
+ NULL, id, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&messageBuffer, 0, NULL);
- String msg = "Error "+itos(id)+": "+String(messageBuffer,size);
+ String msg = "Error " + itos(id) + ": " + String(messageBuffer, size);
LocalFree(messageBuffer);
return msg;
-
}
-
-
extern HINSTANCE godot_hinstance;
-
-
void RedirectIOToConsole() {
int hConHandle;
@@ -228,7 +223,17 @@ bool OS_Windows::can_draw() const {
#define SIGNATURE_MASK 0xFFFFFF00
#define IsPenEvent(dw) (((dw)&SIGNATURE_MASK) == MI_WP_SIGNATURE)
-void OS_Windows::_touch_event(bool p_pressed, int p_x, int p_y, int idx) {
+void OS_Windows::_touch_event(bool p_pressed, float p_x, float p_y, int idx) {
+
+ // Defensive
+ if (touch_state.has(idx) == p_pressed)
+ return;
+
+ if (p_pressed) {
+ touch_state.insert(idx, Vector2(p_x, p_y));
+ } else {
+ touch_state.erase(idx);
+ }
Ref<InputEventScreenTouch> event;
event.instance();
@@ -241,7 +246,17 @@ void OS_Windows::_touch_event(bool p_pressed, int p_x, int p_y, int idx) {
}
};
-void OS_Windows::_drag_event(int p_x, int p_y, int idx) {
+void OS_Windows::_drag_event(float p_x, float p_y, int idx) {
+
+ Map<int, Vector2>::Element *curr = touch_state.find(idx);
+ // Defensive
+ if (!curr)
+ return;
+
+ if (curr->get() == Vector2(p_x, p_y))
+ return;
+
+ curr->get() = Vector2(p_x, p_y);
Ref<InputEventScreenDrag> event;
event.instance();
@@ -271,6 +286,13 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED) {
ReleaseCapture();
}
+
+ // Release every touch to avoid sticky points
+ for (Map<int, Vector2>::Element *E = touch_state.front(); E; E = E->next()) {
+ _touch_event(false, E->get().x, E->get().y, E->key());
+ }
+ touch_state.clear();
+
break;
}
case WM_ACTIVATE: // Watch For Window Activate Message
@@ -674,7 +696,6 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
print_line("input lang change");
} break;
-#if WINVER >= 0x0601 // for windows 7
case WM_TOUCH: {
BOOL bHandled = FALSE;
@@ -687,10 +708,10 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
//do something with each touch input entry
if (ti.dwFlags & TOUCHEVENTF_MOVE) {
- _drag_event(ti.x / 100, ti.y / 100, ti.dwID);
+ _drag_event(ti.x / 100.0f, ti.y / 100.0f, ti.dwID);
} else if (ti.dwFlags & (TOUCHEVENTF_UP | TOUCHEVENTF_DOWN)) {
- _touch_event(ti.dwFlags & TOUCHEVENTF_DOWN != 0, ti.x / 100, ti.y / 100, ti.dwID);
+ _touch_event(ti.dwFlags & TOUCHEVENTF_DOWN, ti.x / 100.0f, ti.y / 100.0f, ti.dwID);
};
}
bHandled = TRUE;
@@ -708,7 +729,6 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
} break;
-#endif
case WM_DEVICECHANGE: {
joypad->probe_joypads();
@@ -1092,7 +1112,7 @@ void OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
tme.dwHoverTime = HOVER_DEFAULT;
TrackMouseEvent(&tme);
- //RegisterTouchWindow(hWnd, 0); // Windows 7
+ RegisterTouchWindow(hWnd, 0);
_ensure_user_data_dir();
@@ -1206,6 +1226,7 @@ void OS_Windows::finalize() {
memdelete(joypad);
memdelete(input);
+ touch_state.clear();
visual_server->finish();
memdelete(visual_server);
@@ -1608,17 +1629,23 @@ void OS_Windows::_update_window_style(bool repaint) {
Error OS_Windows::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) {
+ typedef DLL_DIRECTORY_COOKIE(WINAPI * PAddDllDirectory)(PCWSTR);
+ typedef BOOL(WINAPI * PRemoveDllDirectory)(DLL_DIRECTORY_COOKIE);
+
+ PAddDllDirectory add_dll_directory = (PAddDllDirectory)GetProcAddress(GetModuleHandle("kernel32.dll"), "AddDllDirectory");
+ PRemoveDllDirectory remove_dll_directory = (PRemoveDllDirectory)GetProcAddress(GetModuleHandle("kernel32.dll"), "RemoveDllDirectory");
+ bool has_dll_directory_api = ((add_dll_directory != NULL) && (remove_dll_directory != NULL));
DLL_DIRECTORY_COOKIE cookie;
- if (p_also_set_library_path) {
- cookie = AddDllDirectory(p_path.get_base_dir().c_str());
+ if (p_also_set_library_path && has_dll_directory_api) {
+ cookie = add_dll_directory(p_path.get_base_dir().c_str());
}
- p_library_handle = (void *)LoadLibraryExW(p_path.c_str(), NULL, p_also_set_library_path ? LOAD_LIBRARY_SEARCH_DEFAULT_DIRS : 0);
+ p_library_handle = (void *)LoadLibraryExW(p_path.c_str(), NULL, (p_also_set_library_path && has_dll_directory_api) ? LOAD_LIBRARY_SEARCH_DEFAULT_DIRS : 0);
- if (p_also_set_library_path) {
- RemoveDllDirectory(cookie);
+ if (p_also_set_library_path && has_dll_directory_api) {
+ remove_dll_directory(cookie);
}
if (!p_library_handle) {
diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h
index e98f8277df..af1ccd4446 100644
--- a/platform/windows/os_windows.h
+++ b/platform/windows/os_windows.h
@@ -117,6 +117,7 @@ class OS_Windows : public OS {
InputDefault *input;
JoypadWindows *joypad;
+ Map<int, Vector2> touch_state;
PowerWindows *power_manager;
@@ -132,8 +133,8 @@ class OS_Windows : public OS {
CrashHandler crash_handler;
- void _drag_event(int p_x, int p_y, int idx);
- void _touch_event(bool p_pressed, int p_x, int p_y, int idx);
+ void _drag_event(float p_x, float p_y, int idx);
+ void _touch_event(bool p_pressed, float p_x, float p_y, int idx);
void _update_window_style(bool repaint = true);
@@ -212,7 +213,7 @@ public:
virtual void set_borderless_window(int p_borderless);
virtual bool get_borderless_window();
- virtual Error open_dynamic_library(const String p_path, void *&p_library_handle,bool p_also_set_library_path=false);
+ virtual Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false);
virtual Error close_dynamic_library(void *p_library_handle);
virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle, bool p_optional = false);
diff --git a/platform/windows/stream_peer_winsock.cpp b/platform/windows/stream_peer_winsock.cpp
index a9d9cb9373..8b83215325 100644
--- a/platform/windows/stream_peer_winsock.cpp
+++ b/platform/windows/stream_peer_winsock.cpp
@@ -141,7 +141,7 @@ Error StreamPeerWinsock::write(const uint8_t *p_data, int p_bytes, int &r_sent,
if (WSAGetLastError() != WSAEWOULDBLOCK) {
- perror("shit?");
+ perror("Nothing sent");
disconnect_from_host();
ERR_PRINT("Server disconnected!\n");
return FAILED;
@@ -197,7 +197,7 @@ Error StreamPeerWinsock::read(uint8_t *p_buffer, int p_bytes, int &r_received, b
if (WSAGetLastError() != WSAEWOULDBLOCK) {
- perror("shit?");
+ perror("Nothing read");
disconnect_from_host();
ERR_PRINT("Server disconnected!\n");
return FAILED;
diff --git a/platform/x11/detect.py b/platform/x11/detect.py
index 3d07851c4f..d7dbe71da4 100644
--- a/platform/x11/detect.py
+++ b/platform/x11/detect.py
@@ -55,6 +55,7 @@ def get_opts():
BoolVariable('pulseaudio', 'Detect & use pulseaudio', True),
BoolVariable('udev', 'Use udev for gamepad connection callbacks', False),
EnumVariable('debug_symbols', 'Add debug symbols to release version', 'yes', ('yes', 'no', 'full')),
+ BoolVariable('touch', 'Enable touch events', True),
]
@@ -141,6 +142,14 @@ def configure(env):
env.ParseConfig('pkg-config xinerama --cflags --libs')
env.ParseConfig('pkg-config xrandr --cflags --libs')
+ if (env['touch']):
+ x11_error = os.system("pkg-config xi --modversion > /dev/null ")
+ if (x11_error):
+ print("xi not found.. cannot build with touch. Aborting.")
+ sys.exit(255)
+ env.ParseConfig('pkg-config xi --cflags --libs')
+ env.Append(CPPFLAGS=['-DTOUCH_ENABLED'])
+
# FIXME: Check for existence of the libs before parsing their flags with pkg-config
if not env['builtin_openssl']:
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index d1aa129e77..bf63921b06 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -178,6 +178,50 @@ void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
}
}
+#ifdef TOUCH_ENABLED
+ if (!XQueryExtension(x11_display, "XInputExtension", &touch.opcode, &event_base, &error_base)) {
+ fprintf(stderr, "XInput extension not available");
+ } else {
+ // 2.2 is the first release with multitouch
+ int xi_major = 2;
+ int xi_minor = 2;
+ if (XIQueryVersion(x11_display, &xi_major, &xi_minor) != Success) {
+ fprintf(stderr, "XInput 2.2 not available (server supports %d.%d)\n", xi_major, xi_minor);
+ touch.opcode = 0;
+ } else {
+ int dev_count;
+ XIDeviceInfo *info = XIQueryDevice(x11_display, XIAllDevices, &dev_count);
+
+ for (int i = 0; i < dev_count; i++) {
+ XIDeviceInfo *dev = &info[i];
+ if (!dev->enabled)
+ continue;
+ /*if (dev->use != XIMasterPointer)
+ continue;*/
+
+ bool direct_touch = false;
+ for (int j = 0; j < dev->num_classes; j++) {
+ if (dev->classes[j]->type == XITouchClass && ((XITouchClassInfo *)dev->classes[j])->mode == XIDirectTouch) {
+ direct_touch = true;
+ printf("%d) %d %s\n", i, dev->attachment, dev->name);
+ break;
+ }
+ }
+ if (direct_touch) {
+ touch.devices.push_back(dev->deviceid);
+ fprintf(stderr, "Using touch device: %s\n", dev->name);
+ }
+ }
+
+ XIFreeDeviceInfo(info);
+
+ if (!touch.devices.size()) {
+ fprintf(stderr, "No suitable touch device found\n");
+ }
+ }
+ }
+#endif
+
xim = XOpenIM(x11_display, NULL, NULL, NULL);
if (xim == NULL) {
@@ -308,6 +352,32 @@ void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
XChangeWindowAttributes(x11_display, x11_window, CWEventMask, &new_attr);
+#ifdef TOUCH_ENABLED
+ if (touch.devices.size()) {
+
+ // Must be alive after this block
+ static unsigned char mask_data[XIMaskLen(XI_LASTEVENT)] = {};
+
+ touch.event_mask.deviceid = XIAllMasterDevices;
+ touch.event_mask.mask_len = sizeof(mask_data);
+ touch.event_mask.mask = mask_data;
+
+ XISetMask(touch.event_mask.mask, XI_TouchBegin);
+ XISetMask(touch.event_mask.mask, XI_TouchUpdate);
+ XISetMask(touch.event_mask.mask, XI_TouchEnd);
+ XISetMask(touch.event_mask.mask, XI_TouchOwnership);
+
+ XISelectEvents(x11_display, x11_window, &touch.event_mask, 1);
+
+ XIClearMask(touch.event_mask.mask, XI_TouchOwnership);
+
+ // Grab touch devices to avoid OS gesture interference
+ for (int i = 0; i < touch.devices.size(); ++i) {
+ XIGrabDevice(x11_display, touch.devices[i], x11_window, CurrentTime, None, XIGrabModeAsync, XIGrabModeAsync, False, &touch.event_mask);
+ }
+ }
+#endif
+
/* set the titlebar name */
XStoreName(x11_display, x11_window, "Godot");
@@ -487,6 +557,10 @@ void OS_X11::finalize() {
#ifdef JOYDEV_ENABLED
memdelete(joypad);
#endif
+#ifdef TOUCH_ENABLED
+ touch.devices.clear();
+ touch.state.clear();
+#endif
memdelete(input);
visual_server->finish();
@@ -1435,6 +1509,69 @@ void OS_X11::process_xevents() {
continue;
}
+#ifdef TOUCH_ENABLED
+ if (XGetEventData(x11_display, &event.xcookie)) {
+
+ if (event.xcookie.extension == touch.opcode) {
+
+ XIDeviceEvent *event_data = (XIDeviceEvent *)event.xcookie.data;
+ int index = event_data->detail;
+ Vector2 pos = Vector2(event_data->event_x, event_data->event_y);
+
+ switch (event_data->evtype) {
+
+ case XI_TouchBegin: // Fall-through
+ XIAllowTouchEvents(x11_display, event_data->deviceid, event_data->detail, x11_window, XIAcceptTouch);
+
+ case XI_TouchEnd: {
+
+ bool is_begin = event_data->evtype == XI_TouchBegin;
+
+ Ref<InputEventScreenTouch> st;
+ st.instance();
+ st->set_index(index);
+ st->set_position(pos);
+ st->set_pressed(is_begin);
+
+ if (is_begin) {
+ if (touch.state.has(index)) // Defensive
+ break;
+ touch.state[index] = pos;
+ input->parse_input_event(st);
+ } else {
+ if (!touch.state.has(index)) // Defensive
+ break;
+ touch.state.erase(index);
+ input->parse_input_event(st);
+ }
+ } break;
+
+ case XI_TouchUpdate: {
+
+ Map<int, Vector2>::Element *curr_pos_elem = touch.state.find(index);
+ if (!curr_pos_elem) { // Defensive
+ break;
+ }
+
+ if (curr_pos_elem->value() != pos) {
+
+ Ref<InputEventScreenDrag> sd;
+ sd.instance();
+ sd->set_index(index);
+ sd->set_position(pos);
+ sd->set_relative(pos - curr_pos_elem->value());
+ input->parse_input_event(sd);
+
+ curr_pos_elem->value() = pos;
+ }
+ } break;
+ }
+ }
+
+ XFreeEventData(x11_display, &event.xcookie);
+ }
+#endif
+
switch (event.type) {
case Expose:
Main::force_redraw();
@@ -1477,6 +1614,12 @@ void OS_X11::process_xevents() {
ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
GrabModeAsync, GrabModeAsync, x11_window, None, CurrentTime);
}
+#ifdef TOUCH_ENABLED
+ // Grab touch devices to avoid OS gesture interference
+ for (int i = 0; i < touch.devices.size(); ++i) {
+ XIGrabDevice(x11_display, touch.devices[i], x11_window, CurrentTime, None, XIGrabModeAsync, XIGrabModeAsync, False, &touch.event_mask);
+ }
+#endif
if (xic) {
XSetICFocus(xic);
}
@@ -1493,6 +1636,23 @@ void OS_X11::process_xevents() {
}
XUngrabPointer(x11_display, CurrentTime);
}
+#ifdef TOUCH_ENABLED
+ // Ungrab touch devices so input works as usual while we are unfocused
+ for (int i = 0; i < touch.devices.size(); ++i) {
+ XIUngrabDevice(x11_display, touch.devices[i], CurrentTime);
+ }
+
+ // Release every pointer to avoid sticky points
+ for (Map<int, Vector2>::Element *E = touch.state.front(); E; E = E->next()) {
+
+ Ref<InputEventScreenTouch> st;
+ st.instance();
+ st->set_index(E->key());
+ st->set_position(E->get());
+ input->parse_input_event(st);
+ }
+ touch.state.clear();
+#endif
if (xic) {
XUnsetICFocus(xic);
}
diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h
index a74e6ee5f3..84dff2e089 100644
--- a/platform/x11/os_x11.h
+++ b/platform/x11/os_x11.h
@@ -48,6 +48,9 @@
#include <X11/Xlib.h>
#include <X11/extensions/Xrandr.h>
#include <X11/keysym.h>
+#ifdef TOUCH_ENABLED
+#include <X11/extensions/XInput2.h>
+#endif
// Hints for X11 fullscreen
typedef struct {
@@ -117,6 +120,14 @@ class OS_X11 : public OS_Unix {
Point2i last_click_pos;
uint64_t last_click_ms;
uint32_t last_button_state;
+#ifdef TOUCH_ENABLED
+ struct {
+ int opcode;
+ Vector<int> devices;
+ XIEventMask event_mask;
+ Map<int, Vector2> state;
+ } touch;
+#endif
unsigned int get_mouse_button_state(unsigned int p_x11_state);
void get_key_modifier_state(unsigned int p_x11_state, Ref<InputEventWithModifiers> state);