diff options
Diffstat (limited to 'platform/x11')
-rw-r--r-- | platform/x11/SCsub | 4 | ||||
-rw-r--r-- | platform/x11/context_gl_x11.cpp | 4 | ||||
-rw-r--r-- | platform/x11/detect.py | 15 | ||||
-rw-r--r-- | platform/x11/export/export.cpp | 3 | ||||
-rw-r--r-- | platform/x11/os_x11.cpp | 190 | ||||
-rw-r--r-- | platform/x11/os_x11.h | 15 | ||||
-rw-r--r-- | platform/x11/power_x11.cpp | 6 |
7 files changed, 217 insertions, 20 deletions
diff --git a/platform/x11/SCsub b/platform/x11/SCsub index 6378553638..38dd2ddd88 100644 --- a/platform/x11/SCsub +++ b/platform/x11/SCsub @@ -4,9 +4,9 @@ import os Import('env') def make_debug(target, source, env): - os.system('objcopy --only-keep-debug %s %s.debug' % (target[0], target[0])) + os.system('objcopy --only-keep-debug %s %s.debugsymbols' % (target[0], target[0])) os.system('strip --strip-debug --strip-unneeded %s' % (target[0])) - os.system('objcopy --add-gnu-debuglink=%s.debug %s' % (target[0], target[0])) + os.system('objcopy --add-gnu-debuglink=%s.debugsymbols %s' % (target[0], target[0])) common_x11 = [ "context_gl_x11.cpp", diff --git a/platform/x11/context_gl_x11.cpp b/platform/x11/context_gl_x11.cpp index 4f9d4a84b9..61c6b3c9dd 100644 --- a/platform/x11/context_gl_x11.cpp +++ b/platform/x11/context_gl_x11.cpp @@ -228,8 +228,8 @@ bool ContextGL_X11::is_using_vsync() const { return use_vsync; } -ContextGL_X11::ContextGL_X11(::Display *p_x11_display, ::Window &p_x11_window, const OS::VideoMode &p_default_video_mode, bool p_opengl_3_context) - : x11_window(p_x11_window) { +ContextGL_X11::ContextGL_X11(::Display *p_x11_display, ::Window &p_x11_window, const OS::VideoMode &p_default_video_mode, bool p_opengl_3_context) : + x11_window(p_x11_window) { default_video_mode = p_default_video_mode; x11_display = p_x11_display; diff --git a/platform/x11/detect.py b/platform/x11/detect.py index 3d07851c4f..09bf57c5f1 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']: @@ -149,6 +158,7 @@ def configure(env): if not env['builtin_libwebp']: env.ParseConfig('pkg-config libwebp --cflags --libs') + # freetype depends on libpng and zlib, so bundling one of them while keeping others # as shared libraries leads to weird issues if env['builtin_freetype'] or env['builtin_libpng'] or env['builtin_zlib']: @@ -254,5 +264,10 @@ def configure(env): env.Append(CPPFLAGS=['-m64']) env.Append(LINKFLAGS=['-m64', '-L/usr/lib/i686-linux-gnu']) + + if env["openmp"]: + env.Append(CPPFLAGS=['-fopenmp']) + env.Append(LINKFLAGS=['-fopenmp']) + if env['use_static_cpp']: env.Append(LINKFLAGS=['-static-libstdc++']) diff --git a/platform/x11/export/export.cpp b/platform/x11/export/export.cpp index fdb43c9ae0..1baa3e127f 100644 --- a/platform/x11/export/export.cpp +++ b/platform/x11/export/export.cpp @@ -44,7 +44,8 @@ void register_x11_exporter() { logo->create_from_image(img); platform->set_logo(logo); platform->set_name("Linux/X11"); - platform->set_extension("bin"); + platform->set_extension("x86"); + platform->set_extension("x86_64", "binary_format/64_bits"); platform->set_release_32("linux_x11_32_release"); platform->set_debug_32("linux_x11_32_debug"); platform->set_release_64("linux_x11_64_release"); diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index d1aa129e77..0c0bc1a8a3 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -132,10 +132,9 @@ void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_au // Try to support IME if detectable auto-repeat is supported if (xkb_dar == True) { -// Xutf8LookupString will be used later instead of XmbLookupString before -// the multibyte sequences can be converted to unicode string. - #ifdef X_HAVE_UTF8_STRING + // Xutf8LookupString will be used later instead of XmbLookupString before + // the multibyte sequences can be converted to unicode string. modifiers = XSetLocaleModifiers(""); #endif } @@ -178,6 +177,49 @@ 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 || dev->use == XIFloatingSlave)) + 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; + 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 touch devices found\n"); + } + } + } +#endif + xim = XOpenIM(x11_display, NULL, NULL, NULL); if (xim == NULL) { @@ -243,6 +285,8 @@ void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_au RasterizerGLES3::make_current(); + context_gl->set_use_vsync(current_videomode.use_vsync); + #endif visual_server = memnew(VisualServerRaster); @@ -308,6 +352,34 @@ 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 = XIAllDevices; + 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); + + // Disabled by now since grabbing also blocks mouse events + // (they are received as extended events instead of standard events) + /*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"); @@ -441,15 +513,14 @@ void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_au power_manager = memnew(PowerX11); XEvent xevent; - while (XCheckIfEvent(x11_display, &xevent, _check_window_events, NULL)) { - _window_changed(&xevent); + while (XPending(x11_display) > 0) { + XNextEvent(x11_display, &xevent); + if (xevent.type == ConfigureNotify) { + _window_changed(&xevent); + } } } -int OS_X11::_check_window_events(Display *display, XEvent *event, char *arg) { - if (event->type == ConfigureNotify) return 1; - return 0; -} void OS_X11::xim_destroy_callback(::XIM im, ::XPointer client_data, ::XPointer call_data) { @@ -478,7 +549,7 @@ void OS_X11::finalize() { memdelete(main_loop); main_loop = NULL; -/* + /* if (debugger_connection_console) { memdelete(debugger_connection_console); } @@ -487,6 +558,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(); @@ -1023,7 +1098,7 @@ bool OS_X11::is_window_maximized() const { return false; } -void OS_X11::set_borderless_window(int p_borderless) { +void OS_X11::set_borderless_window(bool p_borderless) { if (current_videomode.borderless_window == p_borderless) return; @@ -1435,6 +1510,69 @@ void OS_X11::process_xevents() { continue; } +#ifdef TOUCH_ENABLED + if (XGetEventData(x11_display, &event.xcookie)) { + + if (event.xcookie.type == GenericEvent && 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 + // Disabled hand-in-hand with the grabbing + //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 +1615,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 +1637,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); } @@ -2103,6 +2264,13 @@ void OS_X11::set_icon(const Ref<Image> &p_icon) { XFlush(x11_display); } +void OS_X11::force_process_input() { + process_xevents(); // get rid of pending events +#ifdef JOYDEV_ENABLED + joypad->process_joypads(); +#endif +} + void OS_X11::run() { force_quit = false; diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index a74e6ee5f3..c8cea1e30c 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); @@ -188,7 +199,6 @@ protected: virtual void set_main_loop(MainLoop *p_main_loop); void _window_changed(XEvent *xevent); - static int _check_window_events(Display *display, XEvent *xevent, char *arg); public: virtual String get_name(); @@ -248,7 +258,7 @@ public: virtual bool is_window_maximized() const; virtual void request_attention(); - virtual void set_borderless_window(int p_borderless); + virtual void set_borderless_window(bool p_borderless); virtual bool get_borderless_window(); virtual void set_ime_position(const Point2 &p_pos); @@ -269,6 +279,7 @@ public: virtual bool _check_internal_feature_support(const String &p_feature); + virtual void force_process_input(); void run(); void disable_crash_handler(); diff --git a/platform/x11/power_x11.cpp b/platform/x11/power_x11.cpp index 76ff7f91fb..0ef2629cb0 100644 --- a/platform/x11/power_x11.cpp +++ b/platform/x11/power_x11.cpp @@ -542,8 +542,10 @@ bool PowerX11::UpdatePowerInfo() { return false; } -PowerX11::PowerX11() - : nsecs_left(-1), percent_left(-1), power_state(OS::POWERSTATE_UNKNOWN) { +PowerX11::PowerX11() : + nsecs_left(-1), + percent_left(-1), + power_state(OS::POWERSTATE_UNKNOWN) { } PowerX11::~PowerX11() { |