summaryrefslogtreecommitdiff
path: root/platform/x11
diff options
context:
space:
mode:
Diffstat (limited to 'platform/x11')
-rw-r--r--platform/x11/SCsub6
-rw-r--r--platform/x11/context_gl_x11.cpp51
-rw-r--r--platform/x11/context_gl_x11.h12
-rw-r--r--platform/x11/crash_handler_x11.cpp3
-rw-r--r--platform/x11/detect.py10
-rw-r--r--platform/x11/os_x11.cpp129
-rw-r--r--platform/x11/os_x11.h6
-rw-r--r--platform/x11/platform_config.h1
8 files changed, 134 insertions, 84 deletions
diff --git a/platform/x11/SCsub b/platform/x11/SCsub
index b18757337a..d0f77892ef 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.debugsymbols' % (target[0], target[0]))
- os.system('strip --strip-debug --strip-unneeded %s' % (target[0]))
- os.system('objcopy --add-gnu-debuglink=%s.debugsymbols %s' % (target[0], target[0]))
+ os.system('objcopy --only-keep-debug {0} {0}.debugsymbols'.format(target[0]))
+ os.system('strip --strip-debug --strip-unneeded {0}'.format(target[0]))
+ os.system('objcopy --add-gnu-debuglink={0}.debugsymbols {0}'.format(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 20f2212861..1a7cbc0d6d 100644
--- a/platform/x11/context_gl_x11.cpp
+++ b/platform/x11/context_gl_x11.cpp
@@ -146,20 +146,39 @@ Error ContextGL_X11::initialize() {
int (*oldHandler)(Display *, XErrorEvent *) =
XSetErrorHandler(&ctxErrorHandler);
- if (!opengl_3_context) {
- //oldstyle context:
- p->glx_context = glXCreateContext(x11_display, vi, 0, GL_TRUE);
- } else {
- static int context_attribs[] = {
- GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
- GLX_CONTEXT_MINOR_VERSION_ARB, 3,
- GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB /*|GLX_CONTEXT_DEBUG_BIT_ARB*/,
- None
- };
-
- p->glx_context = glXCreateContextAttribsARB(x11_display, fbc[0], NULL, true, context_attribs);
- ERR_EXPLAIN("Could not obtain an OpenGL 3.3 context!");
- ERR_FAIL_COND_V(ctxErrorOccurred || !p->glx_context, ERR_UNCONFIGURED);
+ switch (context_type) {
+ case GLES_2_0_COMPATIBLE:
+ case OLDSTYLE: {
+ p->glx_context = glXCreateContext(x11_display, vi, 0, GL_TRUE);
+ } break;
+ /*
+ case ContextType::GLES_2_0_COMPATIBLE: {
+
+ static int context_attribs[] = {
+ GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
+ GLX_CONTEXT_MINOR_VERSION_ARB, 0,
+ None
+ };
+
+ p->glx_context = glXCreateContextAttribsARB(x11_display, fbc[0], NULL, true, context_attribs);
+ ERR_EXPLAIN("Could not obtain an OpenGL 3.0 context!");
+ ERR_FAIL_COND_V(!p->glx_context, ERR_UNCONFIGURED);
+ } break;
+ */
+ case GLES_3_0_COMPATIBLE: {
+
+ static int context_attribs[] = {
+ GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
+ GLX_CONTEXT_MINOR_VERSION_ARB, 3,
+ GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
+ GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB /*|GLX_CONTEXT_DEBUG_BIT_ARB*/,
+ None
+ };
+
+ p->glx_context = glXCreateContextAttribsARB(x11_display, fbc[0], NULL, true, context_attribs);
+ ERR_EXPLAIN("Could not obtain an OpenGL 3.3 context!");
+ ERR_FAIL_COND_V(ctxErrorOccurred || !p->glx_context, ERR_UNCONFIGURED);
+ } break;
}
XSync(x11_display, False);
@@ -229,13 +248,13 @@ 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) :
+ContextGL_X11::ContextGL_X11(::Display *p_x11_display, ::Window &p_x11_window, const OS::VideoMode &p_default_video_mode, ContextType p_context_type) :
x11_window(p_x11_window) {
default_video_mode = p_default_video_mode;
x11_display = p_x11_display;
- opengl_3_context = p_opengl_3_context;
+ context_type = p_context_type;
double_buffer = false;
direct_render = false;
diff --git a/platform/x11/context_gl_x11.h b/platform/x11/context_gl_x11.h
index c969f0044d..b54cc84fac 100644
--- a/platform/x11/context_gl_x11.h
+++ b/platform/x11/context_gl_x11.h
@@ -46,6 +46,14 @@ struct ContextGL_X11_Private;
class ContextGL_X11 : public ContextGL {
+public:
+ enum ContextType {
+ OLDSTYLE,
+ GLES_2_0_COMPATIBLE,
+ GLES_3_0_COMPATIBLE
+ };
+
+private:
ContextGL_X11_Private *p;
OS::VideoMode default_video_mode;
//::Colormap x11_colormap;
@@ -54,8 +62,8 @@ class ContextGL_X11 : public ContextGL {
bool double_buffer;
bool direct_render;
int glx_minor, glx_major;
- bool opengl_3_context;
bool use_vsync;
+ ContextType context_type;
public:
virtual void release_current();
@@ -69,7 +77,7 @@ public:
virtual void set_use_vsync(bool p_use);
virtual bool is_using_vsync() const;
- ContextGL_X11(::Display *p_x11_display, ::Window &p_x11_window, const OS::VideoMode &p_default_video_mode, bool p_opengl_3_context);
+ ContextGL_X11(::Display *p_x11_display, ::Window &p_x11_window, const OS::VideoMode &p_default_video_mode, ContextType p_context_type);
~ContextGL_X11();
};
diff --git a/platform/x11/crash_handler_x11.cpp b/platform/x11/crash_handler_x11.cpp
index 43b9051ea7..d39fc33f81 100644
--- a/platform/x11/crash_handler_x11.cpp
+++ b/platform/x11/crash_handler_x11.cpp
@@ -32,8 +32,9 @@
#define CRASH_HANDLER_ENABLED 1
#endif
+#include "crash_handler_x11.h"
#include "main/main.h"
-#include "os_x11.h"
+#include "os/os.h"
#include "project_settings.h"
#ifdef CRASH_HANDLER_ENABLED
diff --git a/platform/x11/detect.py b/platform/x11/detect.py
index c5ef82150b..5820a926e9 100644
--- a/platform/x11/detect.py
+++ b/platform/x11/detect.py
@@ -49,7 +49,7 @@ def get_opts():
return [
BoolVariable('use_llvm', 'Use the LLVM compiler', False),
- BoolVariable('use_static_cpp', 'Link stdc++ statically', False),
+ BoolVariable('use_static_cpp', 'Link libgcc and libstdc++ statically for better portability', False),
BoolVariable('use_sanitizer', 'Use LLVM compiler address sanitizer', False),
BoolVariable('use_leak_sanitizer', 'Use LLVM compiler memory leaks sanitizer (implies use_sanitizer)', False),
BoolVariable('pulseaudio', 'Detect & use pulseaudio', True),
@@ -234,10 +234,10 @@ def configure(env):
print("ALSA libraries not found, disabling driver")
if env['pulseaudio']:
- if (os.system("pkg-config --exists libpulse-simple") == 0): # 0 means found
+ if (os.system("pkg-config --exists libpulse") == 0): # 0 means found
print("Enabling PulseAudio")
env.Append(CPPFLAGS=["-DPULSEAUDIO_ENABLED"])
- env.ParseConfig('pkg-config --cflags --libs libpulse-simple')
+ env.ParseConfig('pkg-config --cflags --libs libpulse')
else:
print("PulseAudio development libraries not found, disabling driver")
@@ -275,6 +275,6 @@ def configure(env):
env.Append(CPPFLAGS=['-m64'])
env.Append(LINKFLAGS=['-m64', '-L/usr/lib/i686-linux-gnu'])
-
+ # Link those statically for portability
if env['use_static_cpp']:
- env.Append(LINKFLAGS=['-static-libstdc++'])
+ env.Append(LINKFLAGS=['-static-libgcc', '-static-libstdc++'])
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index 2d8e32137f..338d13410f 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -29,9 +29,11 @@
/*************************************************************************/
#include "os_x11.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"
@@ -75,25 +77,6 @@
#include <X11/XKBlib.h>
-int OS_X11::get_video_driver_count() const {
- return 1;
-}
-
-const char *OS_X11::get_video_driver_name(int p_driver) const {
- return "GLES3";
-}
-
-int OS_X11::get_audio_driver_count() const {
- return AudioDriverManager::get_driver_count();
-}
-
-const char *OS_X11::get_audio_driver_name(int p_driver) const {
-
- AudioDriver *driver = AudioDriverManager::get_driver(p_driver);
- ERR_FAIL_COND_V(!driver, "");
- return AudioDriverManager::get_driver(p_driver)->get_name();
-}
-
void OS_X11::initialize_core() {
crash_handler.initialize();
@@ -282,12 +265,25 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
//print_line("def videomode "+itos(current_videomode.width)+","+itos(current_videomode.height));
#if defined(OPENGL_ENABLED)
- context_gl = memnew(ContextGL_X11(x11_display, x11_window, current_videomode, true));
- context_gl->initialize();
+ ContextGL_X11::ContextType opengl_api_type = ContextGL_X11::GLES_3_0_COMPATIBLE;
- RasterizerGLES3::register_config();
+ if (p_video_driver == VIDEO_DRIVER_GLES2) {
+ opengl_api_type = ContextGL_X11::GLES_2_0_COMPATIBLE;
+ }
- RasterizerGLES3::make_current();
+ context_gl = memnew(ContextGL_X11(x11_display, x11_window, current_videomode, opengl_api_type));
+ context_gl->initialize();
+
+ switch (opengl_api_type) {
+ case ContextGL_X11::GLES_2_0_COMPATIBLE: {
+ RasterizerGLES2::register_config();
+ RasterizerGLES2::make_current();
+ } break;
+ case ContextGL_X11::GLES_3_0_COMPATIBLE: {
+ RasterizerGLES3::register_config();
+ RasterizerGLES3::make_current();
+ } break;
+ }
context_gl->set_use_vsync(current_videomode.use_vsync);
@@ -730,6 +726,16 @@ void OS_X11::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen) con
}
void OS_X11::set_wm_fullscreen(bool p_enabled) {
+ if (p_enabled && !get_borderless_window()) {
+ // remove decorations if the window is not already borderless
+ Hints hints;
+ Atom property;
+ hints.flags = 2;
+ hints.decorations = 0;
+ property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True);
+ XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5);
+ }
+
if (p_enabled && !is_window_resizable()) {
// Set the window as resizable to prevent window managers to ignore the fullscreen state flag.
XSizeHints *xsh;
@@ -740,7 +746,7 @@ void OS_X11::set_wm_fullscreen(bool p_enabled) {
XFree(xsh);
}
- // Using EWMH -- Extened Window Manager Hints
+ // Using EWMH -- Extended Window Manager Hints
XEvent xev;
Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False);
Atom wm_fullscreen = XInternAtom(x11_display, "_NET_WM_STATE_FULLSCREEN", False);
@@ -1182,6 +1188,7 @@ bool OS_X11::is_window_maximized() const {
unsigned long len;
unsigned long remaining;
unsigned char *data = NULL;
+ bool retval = false;
int result = XGetWindowProperty(
x11_display,
@@ -1210,13 +1217,15 @@ bool OS_X11::is_window_maximized() const {
if (atoms[i] == wm_max_vert)
found_wm_max_vert = true;
- if (found_wm_max_horz && found_wm_max_vert)
- return true;
+ if (found_wm_max_horz && found_wm_max_vert) {
+ retval = true;
+ break;
+ }
}
- XFree(atoms);
}
- return false;
+ XFree(data);
+ return retval;
}
void OS_X11::set_window_always_on_top(bool p_enabled) {
@@ -2366,11 +2375,11 @@ void OS_X11::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
Ref<Texture> texture = p_cursor;
Ref<Image> image = texture->get_data();
- ERR_FAIL_COND(texture->get_width() != 32 || texture->get_height() != 32);
+ ERR_FAIL_COND(texture->get_width() > 256 || texture->get_height() > 256);
// Create the cursor structure
XcursorImage *cursor_image = XcursorImageCreate(texture->get_width(), texture->get_height());
- XcursorUInt image_size = 32 * 32;
+ XcursorUInt image_size = texture->get_width() * texture->get_height();
XcursorDim size = sizeof(XcursorPixel) * image_size;
cursor_image->version = 1;
@@ -2384,10 +2393,10 @@ void OS_X11::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
image->lock();
for (XcursorPixel index = 0; index < image_size; index++) {
- int column_index = floor(index / 32);
- int row_index = index % 32;
+ int row_index = floor(index / texture->get_width());
+ int column_index = index % texture->get_width();
- *(cursor_image->pixels + index) = image->get_pixel(row_index, column_index).to_argb32();
+ *(cursor_image->pixels + index) = image->get_pixel(column_index, row_index).to_argb32();
}
image->unlock();
@@ -2585,48 +2594,66 @@ static String get_mountpoint(const String &p_path) {
}
Error OS_X11::move_to_trash(const String &p_path) {
- String trashcan = "";
+ String trash_can = "";
String mnt = get_mountpoint(p_path);
+ // If there is a directory "[Mountpoint]/.Trash-[UID]/files", use it as the trash can.
if (mnt != "") {
String path(mnt + "/.Trash-" + itos(getuid()) + "/files");
struct stat s;
if (!stat(path.utf8().get_data(), &s)) {
- trashcan = path;
+ trash_can = path;
}
}
- if (trashcan == "") {
+ // Otherwise, if ${XDG_DATA_HOME} is defined, use "${XDG_DATA_HOME}/Trash/files" as the trash can.
+ if (trash_can == "") {
char *dhome = getenv("XDG_DATA_HOME");
if (dhome) {
- trashcan = String(dhome) + "/Trash/files";
+ trash_can = String(dhome) + "/Trash/files";
}
}
- if (trashcan == "") {
+ // Otherwise, if ${HOME} is defined, use "${HOME}/.local/share/Trash/files" as the trash can.
+ if (trash_can == "") {
char *home = getenv("HOME");
if (home) {
- trashcan = String(home) + "/.local/share/Trash/files";
+ trash_can = String(home) + "/.local/share/Trash/files";
}
}
- if (trashcan == "") {
- ERR_PRINTS("move_to_trash: Could not determine trashcan location");
+ // Issue an error if none of the previous locations is appropriate for the trash can.
+ if (trash_can == "") {
+ ERR_PRINTS("move_to_trash: Could not determine the trash can location");
return FAILED;
}
- List<String> args;
- args.push_back("-p");
- args.push_back(trashcan);
- Error err = execute("mkdir", args, true);
- if (err == OK) {
- List<String> args2;
- args2.push_back(p_path);
- args2.push_back(trashcan);
- err = execute("mv", args2, true);
+ // Create needed directories for decided trash can location.
+ DirAccess *dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+ Error err = dir_access->make_dir_recursive(trash_can);
+ memdelete(dir_access);
+
+ // Issue an error if trash can is not created proprely.
+ if (err != OK) {
+ ERR_PRINTS("move_to_trash: Could not create the trash can \"" + trash_can + "\"");
+ return err;
}
- return err;
+ // The trash can is successfully created, now move the given resource to it.
+ // Do not use DirAccess:rename() because it can't move files across multiple mountpoints.
+ List<String> mv_args;
+ mv_args.push_back(p_path);
+ mv_args.push_back(trash_can);
+ int retval;
+ err = execute("mv", mv_args, true, NULL, NULL, &retval);
+
+ // Issue an error if "mv" failed to move the given resource to the trash can.
+ if (err != OK || retval != 0) {
+ ERR_PRINTS("move_to_trash: Could not move the resource \"" + p_path + "\" to the trash can \"" + trash_can + "\"");
+ return FAILED;
+ }
+
+ return OK;
}
OS::LatinKeyboardVariant OS_X11::get_latin_keyboard_variant() const {
diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h
index 494845bc56..610dba0716 100644
--- a/platform/x11/os_x11.h
+++ b/platform/x11/os_x11.h
@@ -188,12 +188,6 @@ class OS_X11 : public OS_Unix {
Bool xrandr_ext_ok;
protected:
- virtual int get_video_driver_count() const;
- virtual const char *get_video_driver_name(int p_driver) const;
-
- virtual int get_audio_driver_count() const;
- virtual const char *get_audio_driver_name(int p_driver) const;
-
virtual void initialize_core();
virtual Error initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
virtual void finalize();
diff --git a/platform/x11/platform_config.h b/platform/x11/platform_config.h
index 58d6b210ee..b757be49c3 100644
--- a/platform/x11/platform_config.h
+++ b/platform/x11/platform_config.h
@@ -37,3 +37,4 @@
#endif
#define GLES3_INCLUDE_H "glad/glad.h"
+#define GLES2_INCLUDE_H "glad/glad.h"