summaryrefslogtreecommitdiff
path: root/platform/x11
diff options
context:
space:
mode:
Diffstat (limited to 'platform/x11')
-rw-r--r--platform/x11/SCsub2
-rw-r--r--platform/x11/context_gl_x11.h4
-rw-r--r--platform/x11/crash_handler_x11.cpp10
-rw-r--r--platform/x11/detect.py25
-rw-r--r--platform/x11/godot_x11.cpp5
-rw-r--r--platform/x11/joypad_linux.h4
-rw-r--r--platform/x11/key_mapping_x11.h2
-rw-r--r--platform/x11/os_x11.cpp115
-rw-r--r--platform/x11/os_x11.h14
-rw-r--r--platform/x11/platform_config.h4
-rw-r--r--platform/x11/power_x11.h6
11 files changed, 130 insertions, 61 deletions
diff --git a/platform/x11/SCsub b/platform/x11/SCsub
index d3901eb798..97d3d1b514 100644
--- a/platform/x11/SCsub
+++ b/platform/x11/SCsub
@@ -1,8 +1,8 @@
#!/usr/bin/env python
-import os
Import('env')
+import os
from platform_methods import run_in_subprocess
import platform_x11_builders
diff --git a/platform/x11/context_gl_x11.h b/platform/x11/context_gl_x11.h
index b8f3eb95d4..be3083d957 100644
--- a/platform/x11/context_gl_x11.h
+++ b/platform/x11/context_gl_x11.h
@@ -38,8 +38,8 @@
#if defined(OPENGL_ENABLED)
+#include "core/os/os.h"
#include "drivers/gl_context/context_gl.h"
-#include "os/os.h"
#include <X11/Xlib.h>
#include <X11/extensions/Xrender.h>
@@ -79,7 +79,7 @@ public:
virtual bool is_using_vsync() const;
ContextGL_X11(::Display *p_x11_display, ::Window &p_x11_window, const OS::VideoMode &p_default_video_mode, ContextType p_context_type);
- ~ContextGL_X11();
+ virtual ~ContextGL_X11();
};
#endif
diff --git a/platform/x11/crash_handler_x11.cpp b/platform/x11/crash_handler_x11.cpp
index 960105271b..79c3d9aece 100644
--- a/platform/x11/crash_handler_x11.cpp
+++ b/platform/x11/crash_handler_x11.cpp
@@ -33,9 +33,9 @@
#endif
#include "crash_handler_x11.h"
+#include "core/os/os.h"
+#include "core/project_settings.h"
#include "main/main.h"
-#include "os/os.h"
-#include "project_settings.h"
#ifdef CRASH_HANDLER_ENABLED
#include <cxxabi.h>
@@ -45,8 +45,9 @@
#include <stdlib.h>
static void handle_crash(int sig) {
- if (OS::get_singleton() == NULL)
- return;
+ if (OS::get_singleton() == NULL) {
+ abort();
+ }
void *bt_buffer[256];
size_t size = backtrace(bt_buffer, 256);
@@ -119,6 +120,7 @@ CrashHandler::CrashHandler() {
}
CrashHandler::~CrashHandler() {
+ disable();
}
void CrashHandler::disable() {
diff --git a/platform/x11/detect.py b/platform/x11/detect.py
index 6a7a426804..524c8448bc 100644
--- a/platform/x11/detect.py
+++ b/platform/x11/detect.py
@@ -1,6 +1,7 @@
import os
import platform
import sys
+from compat import decode_utf8
def is_active():
@@ -86,7 +87,7 @@ def configure(env):
env.Prepend(CCFLAGS=['-O3', '-ffast-math'])
else: #optimize for size
env.Prepend(CCFLAGS=['-Os'])
-
+
if (env["debug_symbols"] == "yes"):
env.Prepend(CCFLAGS=['-g1'])
if (env["debug_symbols"] == "full"):
@@ -115,12 +116,12 @@ def configure(env):
## Compiler configuration
- if 'CXX' in env and 'clang' in env['CXX']:
+ if 'CXX' in env and 'clang' in os.path.basename(env['CXX']):
# Convenience check to enforce the use_llvm overrides when CXX is clang(++)
env['use_llvm'] = True
if env['use_llvm']:
- if ('clang++' not in env['CXX']):
+ if ('clang++' not in os.path.basename(env['CXX'])):
env["CC"] = "clang"
env["CXX"] = "clang++"
env["LINK"] = "clang++"
@@ -149,6 +150,19 @@ def configure(env):
env.Append(CCFLAGS=['-pipe'])
env.Append(LINKFLAGS=['-pipe'])
+ # Check for gcc version > 5 before adding -no-pie
+ import re
+ import subprocess
+ proc = subprocess.Popen([env['CXX'], '--version'], stdout=subprocess.PIPE)
+ (stdout, _) = proc.communicate()
+ stdout = decode_utf8(stdout)
+ match = re.search('[0-9][0-9.]*', stdout)
+ if match is not None:
+ version = match.group().split('.')
+ if (version[0] > '5'):
+ env.Append(CCFLAGS=['-fpie'])
+ env.Append(LINKFLAGS=['-no-pie'])
+
## Dependencies
env.ParseConfig('pkg-config x11 --cflags --libs')
@@ -250,7 +264,8 @@ def configure(env):
if (os.system("pkg-config --exists alsa") == 0): # 0 means found
print("Enabling ALSA")
env.Append(CPPFLAGS=["-DALSA_ENABLED", "-DALSAMIDI_ENABLED"])
- env.ParseConfig('pkg-config alsa --cflags --libs')
+ # Don't parse --cflags, we don't need to add /usr/include/alsa to include path
+ env.ParseConfig('pkg-config alsa --libs')
else:
print("ALSA libraries not found, disabling driver")
@@ -278,7 +293,7 @@ def configure(env):
env.ParseConfig('pkg-config zlib --cflags --libs')
env.Append(CPPPATH=['#platform/x11'])
- env.Append(CPPFLAGS=['-DX11_ENABLED', '-DUNIX_ENABLED', '-DOPENGL_ENABLED', '-DGLES_ENABLED', '-DGLES_OVER_GL'])
+ env.Append(CPPFLAGS=['-DX11_ENABLED', '-DUNIX_ENABLED', '-DOPENGL_ENABLED', '-DGLES_ENABLED'])
env.Append(LIBS=['GL', 'pthread'])
if (platform.system() == "Linux"):
diff --git a/platform/x11/godot_x11.cpp b/platform/x11/godot_x11.cpp
index 3241cbcbf9..21148f8e86 100644
--- a/platform/x11/godot_x11.cpp
+++ b/platform/x11/godot_x11.cpp
@@ -43,7 +43,7 @@ int main(int argc, char *argv[]) {
setlocale(LC_CTYPE, "");
char *cwd = (char *)malloc(PATH_MAX);
- getcwd(cwd, PATH_MAX);
+ char *ret = getcwd(cwd, PATH_MAX);
Error err = Main::setup(argv[0], argc - 1, &argv[1]);
if (err != OK) {
@@ -55,7 +55,8 @@ int main(int argc, char *argv[]) {
os.run(); // it is actually the OS that decides how to run
Main::cleanup();
- chdir(cwd);
+ if (ret)
+ chdir(cwd);
free(cwd);
return os.get_exit_code();
diff --git a/platform/x11/joypad_linux.h b/platform/x11/joypad_linux.h
index 1187acac23..34b240abf1 100644
--- a/platform/x11/joypad_linux.h
+++ b/platform/x11/joypad_linux.h
@@ -33,9 +33,9 @@
#define JOYPAD_LINUX_H
#ifdef JOYDEV_ENABLED
+#include "core/os/mutex.h"
+#include "core/os/thread.h"
#include "main/input_default.h"
-#include "os/mutex.h"
-#include "os/thread.h"
struct input_absinfo;
diff --git a/platform/x11/key_mapping_x11.h b/platform/x11/key_mapping_x11.h
index 62dfcf3a4d..6f05941c19 100644
--- a/platform/x11/key_mapping_x11.h
+++ b/platform/x11/key_mapping_x11.h
@@ -41,7 +41,7 @@
#define XK_XKB_KEYS
#include <X11/keysymdef.h>
-#include "os/keyboard.h"
+#include "core/os/keyboard.h"
class KeyMappingX11 {
KeyMappingX11(){};
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index a62bd714d2..04854e93b6 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -29,12 +29,12 @@
/*************************************************************************/
#include "os_x11.h"
+#include "core/os/dir_access.h"
+#include "core/print_string.h"
#include "drivers/gles2/rasterizer_gles2.h"
#include "drivers/gles3/rasterizer_gles3.h"
#include "errno.h"
#include "key_mapping_x11.h"
-#include "os/dir_access.h"
-#include "print_string.h"
#include "servers/visual/visual_server_raster.h"
#include "servers/visual/visual_server_wrap_mt.h"
@@ -267,6 +267,10 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
// maybe contextgl wants to be in charge of creating the window
#if defined(OPENGL_ENABLED)
+ // Set DRI_PRIME if not set. This means that Godot should default to a higher-power GPU if it exists.
+ // Note: Due to the final '0' parameter to setenv any existing DRI_PRIME environment variables will not
+ // be overwritten.
+ setenv("DRI_PRIME", "1", 0);
ContextGL_X11::ContextType opengl_api_type = ContextGL_X11::GLES_3_0_COMPATIBLE;
@@ -342,12 +346,12 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
context_gl->set_use_vsync(current_videomode.use_vsync);
#endif
- visual_server = memnew(VisualServerRaster);
+ visual_server = memnew(VisualServerRaster);
if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) {
-
visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD));
}
+
if (current_videomode.maximized) {
current_videomode.maximized = false;
set_window_maximized(true);
@@ -365,7 +369,7 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
}
// disable resizable window
- if (!current_videomode.resizable) {
+ if (!current_videomode.resizable && !current_videomode.fullscreen) {
XSizeHints *xsh;
xsh = XAllocSizeHints();
xsh->flags = PMinSize | PMaxSize;
@@ -581,6 +585,8 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
}
}
+ update_real_mouse_position();
+
return OK;
}
@@ -742,12 +748,15 @@ void OS_X11::set_mouse_mode(MouseMode p_mode) {
ERR_PRINT("NO GRAB");
}
- center.x = current_videomode.width / 2;
- center.y = current_videomode.height / 2;
- XWarpPointer(x11_display, None, x11_window,
- 0, 0, 0, 0, (int)center.x, (int)center.y);
+ if (mouse_mode == MOUSE_MODE_CAPTURED) {
+ center.x = current_videomode.width / 2;
+ center.y = current_videomode.height / 2;
+
+ XWarpPointer(x11_display, None, x11_window,
+ 0, 0, 0, 0, (int)center.x, (int)center.y);
- input->set_mouse_position(center);
+ input->set_mouse_position(center);
+ }
} else {
do_mouse_warp = false;
}
@@ -1050,6 +1059,7 @@ Point2 OS_X11::get_window_position() const {
void OS_X11::set_window_position(const Point2 &p_position) {
XMoveWindow(x11_display, x11_window, p_position.x, p_position.y);
+ update_real_mouse_position();
}
Size2 OS_X11::get_window_size() const {
@@ -1079,8 +1089,18 @@ Size2 OS_X11::get_real_window_size() const {
}
void OS_X11::set_window_size(const Size2 p_size) {
+
+ if (current_videomode.width == p_size.width && current_videomode.height == p_size.height)
+ return;
+
+ XWindowAttributes xwa;
+ XSync(x11_display, False);
+ XGetWindowAttributes(x11_display, x11_window, &xwa);
+ int old_w = xwa.width;
+ int old_h = xwa.height;
+
// If window resizable is disabled we need to update the attributes first
- if (is_window_resizable() == false) {
+ if (!is_window_resizable()) {
XSizeHints *xsh;
xsh = XAllocSizeHints();
xsh->flags = PMinSize | PMaxSize;
@@ -1098,6 +1118,16 @@ void OS_X11::set_window_size(const Size2 p_size) {
// Update our videomode width and height
current_videomode.width = p_size.x;
current_videomode.height = p_size.y;
+
+ for (int timeout = 0; timeout < 50; ++timeout) {
+ XSync(x11_display, False);
+ XGetWindowAttributes(x11_display, x11_window, &xwa);
+
+ if (old_w != xwa.width || old_h != xwa.height)
+ break;
+
+ usleep(10000);
+ }
}
void OS_X11::set_window_fullscreen(bool p_enabled) {
@@ -1662,7 +1692,7 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) {
}
} else {
//ignore
- if (last_is_pressed == false) {
+ if (!last_is_pressed) {
return;
}
}
@@ -1969,15 +1999,9 @@ void OS_X11::process_xevents() {
} break;
case MotionNotify: {
- // FUCK YOU X11 API YOU SERIOUSLY GROSS ME OUT
- // YOU ARE AS GROSS AS LOOKING AT A PUTRID PILE
- // OF POOP STICKING OUT OF A CLOGGED TOILET
- // HOW THE FUCK I AM SUPPOSED TO KNOW WHICH ONE
- // OF THE MOTION NOTIFY EVENTS IS THE ONE GENERATED
- // BY WARPING THE MOUSE POINTER?
- // YOU ARE FORCING ME TO FILTER ONE BY ONE TO FIND IT
- // PLEASE DO ME A FAVOR AND DIE DROWNED IN A FECAL
- // MOUNTAIN BECAUSE THAT'S WHERE YOU BELONG.
+ // The X11 API requires filtering one-by-one through the motion
+ // notify events, in order to figure out which event is the one
+ // generated by warping the mouse pointer.
while (true) {
if (mouse_mode == MOUSE_MODE_CAPTURED && event.xmotion.x == current_videomode.width / 2 && event.xmotion.y == current_videomode.height / 2) {
@@ -2044,6 +2068,10 @@ void OS_X11::process_xevents() {
Point2i rel = pos - last_mouse_pos;
+ if (mouse_mode == MOUSE_MODE_CAPTURED) {
+ pos = Point2i(current_videomode.width / 2, current_videomode.height / 2);
+ }
+
Ref<InputEventMouseMotion> mm;
mm.instance();
@@ -2071,7 +2099,7 @@ void OS_X11::process_xevents() {
last_timestamp = event.xkey.time;
// key event is a little complex, so
- // it will be handled in it's own function.
+ // it will be handled in its own function.
handle_key_event((XKeyEvent *)&event);
} break;
case SelectionRequest: {
@@ -2494,13 +2522,16 @@ void OS_X11::set_cursor_shape(CursorShape p_shape) {
ERR_FAIL_INDEX(p_shape, CURSOR_MAX);
- if (p_shape == current_cursor)
+ if (p_shape == current_cursor) {
return;
- if (mouse_mode == MOUSE_MODE_VISIBLE && mouse_mode != MOUSE_MODE_CONFINED) {
- if (cursors[p_shape] != None)
+ }
+
+ if (mouse_mode == MOUSE_MODE_VISIBLE || mouse_mode == MOUSE_MODE_CONFINED) {
+ if (cursors[p_shape] != None) {
XDefineCursor(x11_display, x11_window, cursors[p_shape]);
- else if (cursors[CURSOR_ARROW] != None)
+ } else if (cursors[CURSOR_ARROW] != None) {
XDefineCursor(x11_display, x11_window, cursors[CURSOR_ARROW]);
+ }
}
current_cursor = p_shape;
@@ -2534,7 +2565,9 @@ void OS_X11::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
}
ERR_FAIL_COND(!texture.is_valid());
+ ERR_FAIL_COND(p_hotspot.x < 0 || p_hotspot.y < 0);
ERR_FAIL_COND(texture_size.width > 256 || texture_size.height > 256);
+ ERR_FAIL_COND(p_hotspot.x > texture_size.width || p_hotspot.y > texture_size.height);
image = texture->get_data();
@@ -2574,8 +2607,10 @@ void OS_X11::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
// Save it for a further usage
cursors[p_shape] = XcursorImageLoadCursor(x11_display, cursor_image);
- if (p_shape == CURSOR_ARROW) {
- XDefineCursor(x11_display, x11_window, cursors[p_shape]);
+ if (p_shape == current_cursor) {
+ if (mouse_mode == MOUSE_MODE_VISIBLE || mouse_mode == MOUSE_MODE_CONFINED) {
+ XDefineCursor(x11_display, x11_window, cursors[p_shape]);
+ }
}
memfree(cursor_image->pixels);
@@ -2586,8 +2621,9 @@ void OS_X11::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
cursors[p_shape] = XcursorImageLoadCursor(x11_display, img[p_shape]);
}
+ CursorShape c = current_cursor;
current_cursor = CURSOR_MAX;
- set_cursor_shape(p_shape);
+ set_cursor_shape(c);
}
}
@@ -2782,7 +2818,7 @@ void OS_X11::run() {
#ifdef JOYDEV_ENABLED
joypad->process_joypads();
#endif
- if (Main::iteration() == true)
+ if (Main::iteration())
break;
};
@@ -2970,6 +3006,25 @@ OS::LatinKeyboardVariant OS_X11::get_latin_keyboard_variant() const {
return LATIN_KEYBOARD_QWERTY;
}
+void OS_X11::update_real_mouse_position() {
+ Window root_return, child_return;
+ int root_x, root_y, win_x, win_y;
+ unsigned int mask_return;
+
+ Bool xquerypointer_result = XQueryPointer(x11_display, x11_window, &root_return, &child_return, &root_x, &root_y,
+ &win_x, &win_y, &mask_return);
+
+ if (xquerypointer_result) {
+ if (win_x > 0 && win_y > 0 && win_x <= current_videomode.width && win_y <= current_videomode.height) {
+
+ last_mouse_pos.x = win_x;
+ last_mouse_pos.y = win_y;
+ last_mouse_pos_valid = true;
+ input->set_mouse_position(last_mouse_pos);
+ }
+ }
+}
+
OS_X11::OS_X11() {
#ifdef PULSEAUDIO_ENABLED
diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h
index 44455a2d8d..bb8411e213 100644
--- a/platform/x11/os_x11.h
+++ b/platform/x11/os_x11.h
@@ -32,19 +32,19 @@
#define OS_X11_H
#include "context_gl_x11.h"
+#include "core/os/input.h"
#include "crash_handler_x11.h"
-#include "drivers/unix/os_unix.h"
-#include "os/input.h"
-#include "servers/visual_server.h"
-//#include "servers/visual/visual_server_wrap_mt.h"
#include "drivers/alsa/audio_driver_alsa.h"
#include "drivers/alsamidi/alsa_midi.h"
#include "drivers/pulseaudio/audio_driver_pulseaudio.h"
+#include "drivers/unix/os_unix.h"
#include "joypad_linux.h"
#include "main/input_default.h"
#include "power_x11.h"
#include "servers/audio_server.h"
#include "servers/visual/rasterizer.h"
+#include "servers/visual_server.h"
+//#include "servers/visual/visual_server_wrap_mt.h"
#include <X11/Xcursor/Xcursor.h>
#include <X11/Xlib.h>
@@ -145,7 +145,6 @@ class OS_X11 : public OS_Unix {
void handle_key_event(XKeyEvent *p_event, bool p_echo = false);
void process_xevents();
virtual void delete_main_loop();
- IP_Unix *ip_unix;
bool force_quit;
bool minimized;
@@ -177,8 +176,6 @@ class OS_X11 : public OS_Unix {
AudioDriverPulseAudio driver_pulseaudio;
#endif
- Atom net_wm_icon;
-
PowerX11 *power_manager;
bool layered_window;
@@ -186,8 +183,6 @@ class OS_X11 : public OS_Unix {
CrashHandler crash_handler;
int video_driver_index;
- int audio_driver_index;
- unsigned int capture_idle;
bool maximized;
//void set_wm_border(bool p_enabled);
void set_wm_fullscreen(bool p_enabled);
@@ -313,6 +308,7 @@ public:
virtual LatinKeyboardVariant get_latin_keyboard_variant() const;
+ void update_real_mouse_position();
OS_X11();
};
diff --git a/platform/x11/platform_config.h b/platform/x11/platform_config.h
index b757be49c3..f6d7f5a8cd 100644
--- a/platform/x11/platform_config.h
+++ b/platform/x11/platform_config.h
@@ -36,5 +36,5 @@
#define PTHREAD_BSD_SET_NAME
#endif
-#define GLES3_INCLUDE_H "glad/glad.h"
-#define GLES2_INCLUDE_H "glad/glad.h"
+#define GLES3_INCLUDE_H "thirdparty/glad/glad/glad.h"
+#define GLES2_INCLUDE_H "thirdparty/glad/glad/glad.h"
diff --git a/platform/x11/power_x11.h b/platform/x11/power_x11.h
index 4077887998..d0805b6f8a 100644
--- a/platform/x11/power_x11.h
+++ b/platform/x11/power_x11.h
@@ -31,9 +31,9 @@
#ifndef X11_POWER_H_
#define X11_POWER_H_
-#include "os/dir_access.h"
-#include "os/file_access.h"
-#include "os/os.h"
+#include "core/os/dir_access.h"
+#include "core/os/file_access.h"
+#include "core/os/os.h"
class PowerX11 {