summaryrefslogtreecommitdiff
path: root/platform/linuxbsd
diff options
context:
space:
mode:
Diffstat (limited to 'platform/linuxbsd')
-rw-r--r--platform/linuxbsd/SCsub2
-rw-r--r--platform/linuxbsd/context_gl_x11.cpp257
-rw-r--r--platform/linuxbsd/crash_handler_linuxbsd.cpp2
-rw-r--r--platform/linuxbsd/detect.py28
-rw-r--r--platform/linuxbsd/detect_prime_x11.cpp4
-rw-r--r--platform/linuxbsd/detect_prime_x11.h2
-rw-r--r--platform/linuxbsd/display_server_x11.cpp720
-rw-r--r--platform/linuxbsd/display_server_x11.h27
-rw-r--r--platform/linuxbsd/freedesktop_screensaver.cpp4
-rw-r--r--platform/linuxbsd/gl_manager_x11.cpp384
-rw-r--r--platform/linuxbsd/gl_manager_x11.h (renamed from platform/linuxbsd/context_gl_x11.h)86
-rw-r--r--platform/linuxbsd/joypad_linux.cpp14
-rw-r--r--platform/linuxbsd/joypad_linux.h2
-rw-r--r--platform/linuxbsd/key_mapping_x11.cpp498
-rw-r--r--platform/linuxbsd/key_mapping_x11.h6
-rw-r--r--platform/linuxbsd/platform_config.h2
16 files changed, 1316 insertions, 722 deletions
diff --git a/platform/linuxbsd/SCsub b/platform/linuxbsd/SCsub
index 8aebd57fd2..cec8706fbc 100644
--- a/platform/linuxbsd/SCsub
+++ b/platform/linuxbsd/SCsub
@@ -14,7 +14,7 @@ common_linuxbsd = [
if "x11" in env and env["x11"]:
common_linuxbsd += [
- "context_gl_x11.cpp",
+ "gl_manager_x11.cpp",
"detect_prime_x11.cpp",
"display_server_x11.cpp",
"key_mapping_x11.cpp",
diff --git a/platform/linuxbsd/context_gl_x11.cpp b/platform/linuxbsd/context_gl_x11.cpp
deleted file mode 100644
index 1f92370ab7..0000000000
--- a/platform/linuxbsd/context_gl_x11.cpp
+++ /dev/null
@@ -1,257 +0,0 @@
-/*************************************************************************/
-/* context_gl_x11.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-
-#include "context_gl_x11.h"
-
-#ifdef X11_ENABLED
-#if defined(OPENGL_ENABLED)
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#define GLX_GLXEXT_PROTOTYPES
-#include <GL/glx.h>
-#include <GL/glxext.h>
-
-#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
-#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
-
-typedef GLXContext (*GLXCREATECONTEXTATTRIBSARBPROC)(Display *, GLXFBConfig, GLXContext, Bool, const int *);
-
-struct ContextGL_X11_Private {
- ::GLXContext glx_context;
-};
-
-void ContextGL_X11::release_current() {
- glXMakeCurrent(x11_display, None, nullptr);
-}
-
-void ContextGL_X11::make_current() {
- glXMakeCurrent(x11_display, x11_window, p->glx_context);
-}
-
-void ContextGL_X11::swap_buffers() {
- glXSwapBuffers(x11_display, x11_window);
-}
-
-static bool ctxErrorOccurred = false;
-static int ctxErrorHandler(Display *dpy, XErrorEvent *ev) {
- ctxErrorOccurred = true;
- return 0;
-}
-
-static void set_class_hint(Display *p_display, Window p_window) {
- XClassHint *classHint;
-
- /* set the name and class hints for the window manager to use */
- classHint = XAllocClassHint();
- if (classHint) {
- classHint->res_name = (char *)"Godot_Engine";
- classHint->res_class = (char *)"Godot";
- }
- XSetClassHint(p_display, p_window, classHint);
- XFree(classHint);
-}
-
-Error ContextGL_X11::initialize() {
- //const char *extensions = glXQueryExtensionsString(x11_display, DefaultScreen(x11_display));
-
- GLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = (GLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress((const GLubyte *)"glXCreateContextAttribsARB");
-
- ERR_FAIL_COND_V(!glXCreateContextAttribsARB, ERR_UNCONFIGURED);
-
- static int visual_attribs[] = {
- GLX_RENDER_TYPE, GLX_RGBA_BIT,
- GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
- GLX_DOUBLEBUFFER, true,
- GLX_RED_SIZE, 1,
- GLX_GREEN_SIZE, 1,
- GLX_BLUE_SIZE, 1,
- GLX_DEPTH_SIZE, 24,
- None
- };
-
- static int visual_attribs_layered[] = {
- GLX_RENDER_TYPE, GLX_RGBA_BIT,
- GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
- GLX_DOUBLEBUFFER, true,
- GLX_RED_SIZE, 8,
- GLX_GREEN_SIZE, 8,
- GLX_BLUE_SIZE, 8,
- GLX_ALPHA_SIZE, 8,
- GLX_DEPTH_SIZE, 24,
- None
- };
-
- int fbcount;
- GLXFBConfig fbconfig = 0;
- XVisualInfo *vi = nullptr;
-
- XSetWindowAttributes swa;
- swa.event_mask = StructureNotifyMask;
- swa.border_pixel = 0;
- unsigned long valuemask = CWBorderPixel | CWColormap | CWEventMask;
-
- if (OS::get_singleton()->is_layered_allowed()) {
- GLXFBConfig *fbc = glXChooseFBConfig(x11_display, DefaultScreen(x11_display), visual_attribs_layered, &fbcount);
- ERR_FAIL_COND_V(!fbc, ERR_UNCONFIGURED);
-
- for (int i = 0; i < fbcount; i++) {
- vi = (XVisualInfo *)glXGetVisualFromFBConfig(x11_display, fbc[i]);
- if (!vi)
- continue;
-
- XRenderPictFormat *pict_format = XRenderFindVisualFormat(x11_display, vi->visual);
- if (!pict_format) {
- XFree(vi);
- vi = nullptr;
- continue;
- }
-
- fbconfig = fbc[i];
- if (pict_format->direct.alphaMask > 0) {
- break;
- }
- }
- XFree(fbc);
- ERR_FAIL_COND_V(!fbconfig, ERR_UNCONFIGURED);
-
- swa.background_pixmap = None;
- swa.background_pixel = 0;
- swa.border_pixmap = None;
- valuemask |= CWBackPixel;
-
- } else {
- GLXFBConfig *fbc = glXChooseFBConfig(x11_display, DefaultScreen(x11_display), visual_attribs, &fbcount);
- ERR_FAIL_COND_V(!fbc, ERR_UNCONFIGURED);
-
- vi = glXGetVisualFromFBConfig(x11_display, fbc[0]);
-
- fbconfig = fbc[0];
- XFree(fbc);
- }
-
- int (*oldHandler)(Display *, XErrorEvent *) = XSetErrorHandler(&ctxErrorHandler);
-
- switch (context_type) {
- case GLES_2_0_COMPATIBLE: {
- p->glx_context = glXCreateNewContext(x11_display, fbconfig, GLX_RGBA_TYPE, 0, true);
- ERR_FAIL_COND_V(!p->glx_context, ERR_UNCONFIGURED);
- } break;
- }
-
- swa.colormap = XCreateColormap(x11_display, RootWindow(x11_display, vi->screen), vi->visual, AllocNone);
- x11_window = XCreateWindow(x11_display, RootWindow(x11_display, vi->screen), 0, 0, OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height, 0, vi->depth, InputOutput, vi->visual, valuemask, &swa);
- XStoreName(x11_display, x11_window, "Godot Engine");
-
- ERR_FAIL_COND_V(!x11_window, ERR_UNCONFIGURED);
- set_class_hint(x11_display, x11_window);
- XMapWindow(x11_display, x11_window);
-
- XSync(x11_display, False);
- XSetErrorHandler(oldHandler);
-
- glXMakeCurrent(x11_display, x11_window, p->glx_context);
-
- XFree(vi);
-
- return OK;
-}
-
-int ContextGL_X11::get_window_width() {
- XWindowAttributes xwa;
- XGetWindowAttributes(x11_display, x11_window, &xwa);
-
- return xwa.width;
-}
-
-int ContextGL_X11::get_window_height() {
- XWindowAttributes xwa;
- XGetWindowAttributes(x11_display, x11_window, &xwa);
-
- return xwa.height;
-}
-
-void ContextGL_X11::set_use_vsync(bool p_use) {
- static bool setup = false;
- static PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT = nullptr;
- static PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalMESA = nullptr;
- static PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI = nullptr;
-
- if (!setup) {
- setup = true;
- String extensions = glXQueryExtensionsString(x11_display, DefaultScreen(x11_display));
- if (extensions.find("GLX_EXT_swap_control") != -1)
- glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB((const GLubyte *)"glXSwapIntervalEXT");
- if (extensions.find("GLX_MESA_swap_control") != -1)
- glXSwapIntervalMESA = (PFNGLXSWAPINTERVALSGIPROC)glXGetProcAddressARB((const GLubyte *)"glXSwapIntervalMESA");
- if (extensions.find("GLX_SGI_swap_control") != -1)
- glXSwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)glXGetProcAddressARB((const GLubyte *)"glXSwapIntervalSGI");
- }
- int val = p_use ? 1 : 0;
- if (glXSwapIntervalMESA) {
- glXSwapIntervalMESA(val);
- } else if (glXSwapIntervalSGI) {
- glXSwapIntervalSGI(val);
- } else if (glXSwapIntervalEXT) {
- GLXDrawable drawable = glXGetCurrentDrawable();
- glXSwapIntervalEXT(x11_display, drawable, val);
- } else
- return;
- use_vsync = p_use;
-}
-
-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, ContextType p_context_type) :
- x11_window(p_x11_window) {
- default_video_mode = p_default_video_mode;
- x11_display = p_x11_display;
-
- context_type = p_context_type;
-
- double_buffer = false;
- direct_render = false;
- glx_minor = glx_major = 0;
- p = memnew(ContextGL_X11_Private);
- p->glx_context = 0;
- use_vsync = false;
-}
-
-ContextGL_X11::~ContextGL_X11() {
- release_current();
- glXDestroyContext(x11_display, p->glx_context);
- memdelete(p);
-}
-
-#endif
-#endif
diff --git a/platform/linuxbsd/crash_handler_linuxbsd.cpp b/platform/linuxbsd/crash_handler_linuxbsd.cpp
index 0e98af71fa..9b24b24cb4 100644
--- a/platform/linuxbsd/crash_handler_linuxbsd.cpp
+++ b/platform/linuxbsd/crash_handler_linuxbsd.cpp
@@ -115,7 +115,7 @@ static void handle_crash(int sig) {
int ret;
Error err = OS::get_singleton()->execute(String("addr2line"), args, &output, &ret);
if (err == OK) {
- output.erase(output.length() - 1, 1);
+ output = output.substr(0, output.length() - 1);
}
fprintf(stderr, "[%ld] %s (%s)\n", (long int)i, fname, output.utf8().get_data());
diff --git a/platform/linuxbsd/detect.py b/platform/linuxbsd/detect.py
index 8eb22c1c72..07e16a982b 100644
--- a/platform/linuxbsd/detect.py
+++ b/platform/linuxbsd/detect.py
@@ -105,14 +105,12 @@ def configure(env):
env.Prepend(CCFLAGS=["-O2"])
elif env["optimize"] == "size": # optimize for size
env.Prepend(CCFLAGS=["-Os"])
- env.Prepend(CPPDEFINES=["DEBUG_ENABLED"])
if env["debug_symbols"]:
env.Prepend(CCFLAGS=["-g2"])
elif env["target"] == "debug":
env.Prepend(CCFLAGS=["-g3"])
- env.Prepend(CPPDEFINES=["DEBUG_ENABLED"])
env.Append(LINKFLAGS=["-rdynamic"])
## Architecture
@@ -121,6 +119,21 @@ def configure(env):
if env["bits"] == "default":
env["bits"] = "64" if is64 else "32"
+ machines = {
+ "riscv64": "rv64",
+ "ppc64le": "ppc64",
+ "ppc64": "ppc64",
+ "ppcle": "ppc",
+ "ppc": "ppc",
+ }
+
+ if env["arch"] == "" and platform.machine() in machines:
+ env["arch"] = machines[platform.machine()]
+
+ if env["arch"] == "rv64":
+ # G = General-purpose extensions, C = Compression extension (very common).
+ env.Append(CCFLAGS=["-march=rv64gc"])
+
## Compiler configuration
if "CXX" in env and "clang" in os.path.basename(env["CXX"]):
@@ -290,17 +303,10 @@ def configure(env):
if any(platform.machine() in s for s in list_of_x86):
env["x86_libtheora_opt_gcc"] = True
- if not env["builtin_libvpx"]:
- env.ParseConfig("pkg-config vpx --cflags --libs")
-
if not env["builtin_libvorbis"]:
env["builtin_libogg"] = False # Needed to link against system libvorbis
env.ParseConfig("pkg-config vorbis vorbisfile --cflags --libs")
- if not env["builtin_opus"]:
- env["builtin_libogg"] = False # Needed to link against system opus
- env.ParseConfig("pkg-config opus opusfile --cflags --libs")
-
if not env["builtin_libogg"]:
env.ParseConfig("pkg-config ogg --cflags --libs")
@@ -383,8 +389,8 @@ def configure(env):
# No pkgconfig file for glslang so far
env.Append(LIBS=["glslang", "SPIRV"])
- # env.Append(CPPDEFINES=['OPENGL_ENABLED'])
- env.Append(LIBS=["GL"])
+ env.Append(CPPDEFINES=["GLES3_ENABLED"])
+ env.Append(LIBS=["GL"])
env.Append(LIBS=["pthread"])
diff --git a/platform/linuxbsd/detect_prime_x11.cpp b/platform/linuxbsd/detect_prime_x11.cpp
index da1c95a593..c775546f15 100644
--- a/platform/linuxbsd/detect_prime_x11.cpp
+++ b/platform/linuxbsd/detect_prime_x11.cpp
@@ -29,9 +29,9 @@
/*************************************************************************/
#ifdef X11_ENABLED
-#if defined(OPENGL_ENABLED)
+#if defined(GLES3_ENABLED)
-#include "detect_prime.h"
+#include "detect_prime_x11.h"
#include "core/string/print_string.h"
#include "core/string/ustring.h"
diff --git a/platform/linuxbsd/detect_prime_x11.h b/platform/linuxbsd/detect_prime_x11.h
index 0b548b849e..88d00b3acd 100644
--- a/platform/linuxbsd/detect_prime_x11.h
+++ b/platform/linuxbsd/detect_prime_x11.h
@@ -29,7 +29,7 @@
/*************************************************************************/
#ifdef X11_ENABLED
-#if defined(OPENGL_ENABLED)
+#if defined(GLES3_ENABLED)
int detect_prime();
diff --git a/platform/linuxbsd/display_server_x11.cpp b/platform/linuxbsd/display_server_x11.cpp
index f2cd336b39..2a62780410 100644
--- a/platform/linuxbsd/display_server_x11.cpp
+++ b/platform/linuxbsd/display_server_x11.cpp
@@ -34,6 +34,7 @@
#include "core/config/project_settings.h"
#include "core/string/print_string.h"
+#include "core/string/ustring.h"
#include "detect_prime_x11.h"
#include "key_mapping_x11.h"
#include "main/main.h"
@@ -43,6 +44,10 @@
#include "servers/rendering/renderer_rd/renderer_compositor_rd.h"
#endif
+#if defined(GLES3_ENABLED)
+#include "drivers/gles3/rasterizer_gles3.h"
+#endif
+
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
@@ -124,6 +129,7 @@ bool DisplayServerX11::has_feature(Feature p_feature) const {
#ifdef DBUS_ENABLED
case FEATURE_KEEP_SCREEN_ON:
#endif
+ case FEATURE_CLIPBOARD_PRIMARY:
return true;
default: {
}
@@ -406,6 +412,20 @@ void DisplayServerX11::clipboard_set(const String &p_text) {
XSetSelectionOwner(x11_display, XInternAtom(x11_display, "CLIPBOARD", 0), windows[MAIN_WINDOW_ID].x11_window, CurrentTime);
}
+void DisplayServerX11::clipboard_set_primary(const String &p_text) {
+ _THREAD_SAFE_METHOD_
+ if (!p_text.is_empty()) {
+ {
+ // The clipboard content can be accessed while polling for events.
+ MutexLock mutex_lock(events_mutex);
+ internal_clipboard_primary = p_text;
+ }
+
+ XSetSelectionOwner(x11_display, XA_PRIMARY, windows[MAIN_WINDOW_ID].x11_window, CurrentTime);
+ XSetSelectionOwner(x11_display, XInternAtom(x11_display, "PRIMARY", 0), windows[MAIN_WINDOW_ID].x11_window, CurrentTime);
+ }
+}
+
Bool DisplayServerX11::_predicate_clipboard_selection(Display *display, XEvent *event, XPointer arg) {
if (event->type == SelectionNotify && event->xselection.requestor == *(Window *)arg) {
return True;
@@ -427,7 +447,12 @@ String DisplayServerX11::_clipboard_get_impl(Atom p_source, Window x11_window, A
Window selection_owner = XGetSelectionOwner(x11_display, p_source);
if (selection_owner == x11_window) {
- return internal_clipboard;
+ static const char *target_type = "PRIMARY";
+ if (p_source != None && String(XGetAtomName(x11_display, p_source)) == target_type) {
+ return internal_clipboard_primary;
+ } else {
+ return internal_clipboard;
+ }
}
if (selection_owner != None) {
@@ -580,10 +605,23 @@ String DisplayServerX11::clipboard_get() const {
return ret;
}
+String DisplayServerX11::clipboard_get_primary() const {
+ _THREAD_SAFE_METHOD_
+
+ String ret;
+ ret = _clipboard_get(XInternAtom(x11_display, "PRIMARY", 0), windows[MAIN_WINDOW_ID].x11_window);
+
+ if (ret.is_empty()) {
+ ret = _clipboard_get(XA_PRIMARY, windows[MAIN_WINDOW_ID].x11_window);
+ }
+
+ return ret;
+}
+
Bool DisplayServerX11::_predicate_clipboard_save_targets(Display *display, XEvent *event, XPointer arg) {
if (event->xany.window == *(Window *)arg) {
return (event->type == SelectionRequest) ||
- (event->type == SelectionNotify);
+ (event->type == SelectionNotify);
} else {
return False;
}
@@ -650,35 +688,59 @@ int DisplayServerX11::get_screen_count() const {
return count;
}
-Point2i DisplayServerX11::screen_get_position(int p_screen) const {
- _THREAD_SAFE_METHOD_
+Rect2i DisplayServerX11::_screen_get_rect(int p_screen) const {
+ Rect2i rect(0, 0, 0, 0);
if (p_screen == SCREEN_OF_MAIN_WINDOW) {
p_screen = window_get_current_screen();
}
- // Using Xinerama Extension
+ ERR_FAIL_COND_V(p_screen < 0, rect);
+
+ // Using Xinerama Extension.
int event_base, error_base;
- const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base);
- if (!ext_okay) {
- return Point2i(0, 0);
+ if (XineramaQueryExtension(x11_display, &event_base, &error_base)) {
+ int count;
+ XineramaScreenInfo *xsi = XineramaQueryScreens(x11_display, &count);
+
+ // Check if screen is valid.
+ if (p_screen < count) {
+ rect.position.x = xsi[p_screen].x_org;
+ rect.position.y = xsi[p_screen].y_org;
+ rect.size.width = xsi[p_screen].width;
+ rect.size.height = xsi[p_screen].height;
+ } else {
+ ERR_PRINT("Invalid screen index: " + itos(p_screen) + "(count: " + itos(count) + ").");
+ }
+
+ if (xsi) {
+ XFree(xsi);
+ }
}
- int count;
- XineramaScreenInfo *xsi = XineramaQueryScreens(x11_display, &count);
+ return rect;
+}
- // Check if screen is valid
- ERR_FAIL_INDEX_V(p_screen, count, Point2i(0, 0));
+Point2i DisplayServerX11::screen_get_position(int p_screen) const {
+ _THREAD_SAFE_METHOD_
- Point2i position = Point2i(xsi[p_screen].x_org, xsi[p_screen].y_org);
+ return _screen_get_rect(p_screen).position;
+}
- XFree(xsi);
+Size2i DisplayServerX11::screen_get_size(int p_screen) const {
+ _THREAD_SAFE_METHOD_
- return position;
+ return _screen_get_rect(p_screen).size;
}
-Size2i DisplayServerX11::screen_get_size(int p_screen) const {
- return screen_get_usable_rect(p_screen).size;
+bool g_bad_window = false;
+int bad_window_error_handler(Display *display, XErrorEvent *error) {
+ if (error->error_code == BadWindow) {
+ g_bad_window = true;
+ } else {
+ ERR_PRINT("Unhandled XServer error code: " + itos(error->error_code));
+ }
+ return 0;
}
Rect2i DisplayServerX11::screen_get_usable_rect(int p_screen) const {
@@ -688,21 +750,276 @@ Rect2i DisplayServerX11::screen_get_usable_rect(int p_screen) const {
p_screen = window_get_current_screen();
}
- // Using Xinerama Extension
- int event_base, error_base;
- const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base);
- if (!ext_okay) {
- return Rect2i(0, 0, 0, 0);
+ int screen_count = get_screen_count();
+
+ // Check if screen is valid.
+ ERR_FAIL_INDEX_V(p_screen, screen_count, Rect2i(0, 0, 0, 0));
+
+ bool is_multiscreen = screen_count > 1;
+
+ // Use full monitor size as fallback.
+ Rect2i rect = _screen_get_rect(p_screen);
+
+ // There's generally only one screen reported by xlib even in multi-screen setup,
+ // in this case it's just one virtual screen composed of all physical monitors.
+ int x11_screen_count = ScreenCount(x11_display);
+ Window x11_window = RootWindow(x11_display, p_screen < x11_screen_count ? p_screen : 0);
+
+ Atom type;
+ int format = 0;
+ unsigned long remaining = 0;
+
+ // Find active desktop for the root window.
+ unsigned int desktop_index = 0;
+ Atom desktop_prop = XInternAtom(x11_display, "_NET_CURRENT_DESKTOP", True);
+ if (desktop_prop != None) {
+ unsigned long desktop_len = 0;
+ unsigned char *desktop_data = nullptr;
+ if (XGetWindowProperty(x11_display, x11_window, desktop_prop, 0, LONG_MAX, False, XA_CARDINAL, &type, &format, &desktop_len, &remaining, &desktop_data) == Success) {
+ if ((format == 32) && (desktop_len > 0) && desktop_data) {
+ desktop_index = (unsigned int)desktop_data[0];
+ }
+ if (desktop_data) {
+ XFree(desktop_data);
+ }
+ }
}
- int count;
- XineramaScreenInfo *xsi = XineramaQueryScreens(x11_display, &count);
+ bool use_simple_method = true;
+
+ // First check for GTK work area, which is more accurate for multi-screen setup.
+ if (is_multiscreen) {
+ // Use already calculated work area when available.
+ Atom gtk_workareas_prop = XInternAtom(x11_display, "_GTK_WORKAREAS", False);
+ if (gtk_workareas_prop != None) {
+ char gtk_workarea_prop_name[32];
+ snprintf(gtk_workarea_prop_name, 32, "_GTK_WORKAREAS_D%d", desktop_index);
+ Atom gtk_workarea_prop = XInternAtom(x11_display, gtk_workarea_prop_name, True);
+ if (gtk_workarea_prop != None) {
+ unsigned long workarea_len = 0;
+ unsigned char *workarea_data = nullptr;
+ if (XGetWindowProperty(x11_display, x11_window, gtk_workarea_prop, 0, LONG_MAX, False, XA_CARDINAL, &type, &format, &workarea_len, &remaining, &workarea_data) == Success) {
+ if ((format == 32) && (workarea_len % 4 == 0) && workarea_data) {
+ long *rect_data = (long *)workarea_data;
+ for (uint32_t data_offset = 0; data_offset < workarea_len; data_offset += 4) {
+ Rect2i workarea_rect;
+ workarea_rect.position.x = rect_data[data_offset];
+ workarea_rect.position.y = rect_data[data_offset + 1];
+ workarea_rect.size.x = rect_data[data_offset + 2];
+ workarea_rect.size.y = rect_data[data_offset + 3];
+
+ // Intersect with actual monitor size to find the correct area,
+ // because areas are not in the same order as screens from Xinerama.
+ if (rect.grow(-1).intersects(workarea_rect)) {
+ rect = rect.intersection(workarea_rect);
+ XFree(workarea_data);
+ return rect;
+ }
+ }
+ }
+ }
+ if (workarea_data) {
+ XFree(workarea_data);
+ }
+ }
+ }
- // Check if screen is valid
- ERR_FAIL_INDEX_V(p_screen, count, Rect2i(0, 0, 0, 0));
+ // Fallback to calculating work area by hand from struts.
+ Atom client_list_prop = XInternAtom(x11_display, "_NET_CLIENT_LIST", True);
+ if (client_list_prop != None) {
+ unsigned long clients_len = 0;
+ unsigned char *clients_data = nullptr;
+ if (XGetWindowProperty(x11_display, x11_window, client_list_prop, 0, LONG_MAX, False, XA_WINDOW, &type, &format, &clients_len, &remaining, &clients_data) == Success) {
+ if ((format == 32) && (clients_len > 0) && clients_data) {
+ Window *windows_data = (Window *)clients_data;
+
+ Rect2i desktop_rect;
+ bool desktop_valid = false;
+
+ // Get full desktop size.
+ {
+ Atom desktop_geometry_prop = XInternAtom(x11_display, "_NET_DESKTOP_GEOMETRY", True);
+ if (desktop_geometry_prop != None) {
+ unsigned long geom_len = 0;
+ unsigned char *geom_data = nullptr;
+ if (XGetWindowProperty(x11_display, x11_window, desktop_geometry_prop, 0, LONG_MAX, False, XA_CARDINAL, &type, &format, &geom_len, &remaining, &geom_data) == Success) {
+ if ((format == 32) && (geom_len >= 2) && geom_data) {
+ desktop_valid = true;
+ long *size_data = (long *)geom_data;
+ desktop_rect.size.x = size_data[0];
+ desktop_rect.size.y = size_data[1];
+ }
+ }
+ if (geom_data) {
+ XFree(geom_data);
+ }
+ }
+ }
+
+ // Get full desktop position.
+ if (desktop_valid) {
+ Atom desktop_viewport_prop = XInternAtom(x11_display, "_NET_DESKTOP_VIEWPORT", True);
+ if (desktop_viewport_prop != None) {
+ unsigned long viewport_len = 0;
+ unsigned char *viewport_data = nullptr;
+ if (XGetWindowProperty(x11_display, x11_window, desktop_viewport_prop, 0, LONG_MAX, False, XA_CARDINAL, &type, &format, &viewport_len, &remaining, &viewport_data) == Success) {
+ if ((format == 32) && (viewport_len >= 2) && viewport_data) {
+ desktop_valid = true;
+ long *pos_data = (long *)viewport_data;
+ desktop_rect.position.x = pos_data[0];
+ desktop_rect.position.y = pos_data[1];
+ }
+ }
+ if (viewport_data) {
+ XFree(viewport_data);
+ }
+ }
+ }
+
+ if (desktop_valid) {
+ use_simple_method = false;
+
+ // Handle bad window errors silently because there's no other way to check
+ // that one of the windows has been destroyed in the meantime.
+ int (*oldHandler)(Display *, XErrorEvent *) = XSetErrorHandler(&bad_window_error_handler);
+
+ for (unsigned long win_index = 0; win_index < clients_len; ++win_index) {
+ g_bad_window = false;
+
+ // Remove strut size from desktop size to get a more accurate result.
+ bool strut_found = false;
+ unsigned long strut_len = 0;
+ unsigned char *strut_data = nullptr;
+ Atom strut_partial_prop = XInternAtom(x11_display, "_NET_WM_STRUT_PARTIAL", True);
+ if (strut_partial_prop != None) {
+ if (XGetWindowProperty(x11_display, windows_data[win_index], strut_partial_prop, 0, LONG_MAX, False, XA_CARDINAL, &type, &format, &strut_len, &remaining, &strut_data) == Success) {
+ strut_found = true;
+ }
+ }
+ // Fallback to older strut property.
+ if (!g_bad_window && !strut_found) {
+ Atom strut_prop = XInternAtom(x11_display, "_NET_WM_STRUT", True);
+ if (strut_prop != None) {
+ if (XGetWindowProperty(x11_display, windows_data[win_index], strut_prop, 0, LONG_MAX, False, XA_CARDINAL, &type, &format, &strut_len, &remaining, &strut_data) == Success) {
+ strut_found = true;
+ }
+ }
+ }
+ if (!g_bad_window && strut_found && (format == 32) && (strut_len >= 4) && strut_data) {
+ long *struts = (long *)strut_data;
+
+ long left = struts[0];
+ long right = struts[1];
+ long top = struts[2];
+ long bottom = struts[3];
+
+ long left_start_y, left_end_y, right_start_y, right_end_y;
+ long top_start_x, top_end_x, bottom_start_x, bottom_end_x;
+
+ if (strut_len >= 12) {
+ left_start_y = struts[4];
+ left_end_y = struts[5];
+ right_start_y = struts[6];
+ right_end_y = struts[7];
+ top_start_x = struts[8];
+ top_end_x = struts[9];
+ bottom_start_x = struts[10];
+ bottom_end_x = struts[11];
+ } else {
+ left_start_y = 0;
+ left_end_y = desktop_rect.size.y;
+ right_start_y = 0;
+ right_end_y = desktop_rect.size.y;
+ top_start_x = 0;
+ top_end_x = desktop_rect.size.x;
+ bottom_start_x = 0;
+ bottom_end_x = desktop_rect.size.x;
+ }
+
+ const Point2i &pos = desktop_rect.position;
+ const Size2i &size = desktop_rect.size;
+
+ Rect2i left_rect(pos.x, pos.y + left_start_y, left, left_end_y - left_start_y);
+ if (left_rect.size.x > 0) {
+ Rect2i intersection = rect.intersection(left_rect);
+ if (!intersection.has_no_area() && intersection.size.x < rect.size.x) {
+ rect.position.x = left_rect.size.x;
+ rect.size.x = rect.size.x - intersection.size.x;
+ }
+ }
+
+ Rect2i right_rect(pos.x + size.x - right, pos.y + right_start_y, right, right_end_y - right_start_y);
+ if (right_rect.size.x > 0) {
+ Rect2i intersection = rect.intersection(right_rect);
+ if (!intersection.has_no_area() && right_rect.size.x < rect.size.x) {
+ rect.size.x = intersection.position.x - rect.position.x;
+ }
+ }
+
+ Rect2i top_rect(pos.x + top_start_x, pos.y, top_end_x - top_start_x, top);
+ if (top_rect.size.y > 0) {
+ Rect2i intersection = rect.intersection(top_rect);
+ if (!intersection.has_no_area() && intersection.size.y < rect.size.y) {
+ rect.position.y = top_rect.size.y;
+ rect.size.y = rect.size.y - intersection.size.y;
+ }
+ }
+
+ Rect2i bottom_rect(pos.x + bottom_start_x, pos.y + size.y - bottom, bottom_end_x - bottom_start_x, bottom);
+ if (bottom_rect.size.y > 0) {
+ Rect2i intersection = rect.intersection(bottom_rect);
+ if (!intersection.has_no_area() && right_rect.size.y < rect.size.y) {
+ rect.size.y = intersection.position.y - rect.position.y;
+ }
+ }
+ }
+ if (strut_data) {
+ XFree(strut_data);
+ }
+ }
+
+ // Restore default error handler.
+ XSetErrorHandler(oldHandler);
+ }
+ }
+ }
+ if (clients_data) {
+ XFree(clients_data);
+ }
+ }
+ }
+
+ // Single screen or fallback for multi screen.
+ if (use_simple_method) {
+ // Get desktop available size from the global work area.
+ Atom workarea_prop = XInternAtom(x11_display, "_NET_WORKAREA", True);
+ if (workarea_prop != None) {
+ unsigned long workarea_len = 0;
+ unsigned char *workarea_data = nullptr;
+ if (XGetWindowProperty(x11_display, x11_window, workarea_prop, 0, LONG_MAX, False, XA_CARDINAL, &type, &format, &workarea_len, &remaining, &workarea_data) == Success) {
+ if ((format == 32) && (workarea_len >= ((desktop_index + 1) * 4)) && workarea_data) {
+ long *rect_data = (long *)workarea_data;
+ int data_offset = desktop_index * 4;
+ Rect2i workarea_rect;
+ workarea_rect.position.x = rect_data[data_offset];
+ workarea_rect.position.y = rect_data[data_offset + 1];
+ workarea_rect.size.x = rect_data[data_offset + 2];
+ workarea_rect.size.y = rect_data[data_offset + 3];
+
+ // Intersect with actual monitor size to get a proper approximation in multi-screen setup.
+ if (!is_multiscreen) {
+ rect = workarea_rect;
+ } else if (rect.intersects(workarea_rect)) {
+ rect = rect.intersection(workarea_rect);
+ }
+ }
+ }
+ if (workarea_data) {
+ XFree(workarea_data);
+ }
+ }
+ }
- Rect2i rect = Rect2i(xsi[p_screen].x_org, xsi[p_screen].y_org, xsi[p_screen].width, xsi[p_screen].height);
- XFree(xsi);
return rect;
}
@@ -837,6 +1154,12 @@ void DisplayServerX11::delete_sub_window(WindowID p_id) {
context_vulkan->window_destroy(p_id);
}
#endif
+#ifdef GLES3_ENABLED
+ if (gl_manager) {
+ gl_manager->window_destroy(p_id);
+ }
+#endif
+
XUnmapWindow(x11_display, wd.x11_window);
XDestroyWindow(x11_display, wd.x11_window);
if (wd.xic) {
@@ -978,22 +1301,38 @@ void DisplayServerX11::window_set_drop_files_callback(const Callable &p_callable
int DisplayServerX11::window_get_current_screen(WindowID p_window) const {
_THREAD_SAFE_METHOD_
- ERR_FAIL_COND_V(!windows.has(p_window), -1);
+ int count = get_screen_count();
+ if (count < 2) {
+ // Early exit with single monitor.
+ return 0;
+ }
+
+ ERR_FAIL_COND_V(!windows.has(p_window), 0);
const WindowData &wd = windows[p_window];
- int x, y;
- Window child;
- XTranslateCoordinates(x11_display, wd.x11_window, DefaultRootWindow(x11_display), 0, 0, &x, &y, &child);
+ const Rect2i window_rect(wd.position, wd.size);
- int count = get_screen_count();
+ // Find which monitor has the largest overlap with the given window.
+ int screen_index = 0;
+ int max_area = 0;
for (int i = 0; i < count; i++) {
- Point2i pos = screen_get_position(i);
- Size2i size = screen_get_size(i);
- if ((x >= pos.x && x < pos.x + size.width) && (y >= pos.y && y < pos.y + size.height)) {
- return i;
+ Rect2i screen_rect = _screen_get_rect(i);
+ Rect2i intersection = screen_rect.intersection(window_rect);
+ int area = intersection.get_area();
+ if (area > max_area) {
+ max_area = area;
+ screen_index = i;
}
}
- return 0;
+
+ return screen_index;
+}
+
+void DisplayServerX11::gl_window_make_current(DisplayServer::WindowID p_window_id) {
+#if defined(GLES3_ENABLED)
+ if (gl_manager)
+ gl_manager->window_make_current(p_window_id);
+#endif
}
void DisplayServerX11::window_set_current_screen(int p_screen, WindowID p_window) {
@@ -2069,9 +2408,9 @@ String DisplayServerX11::keyboard_get_layout_name(int p_index) const {
}
Key DisplayServerX11::keyboard_get_keycode_from_physical(Key p_keycode) const {
- unsigned int modifiers = p_keycode & KEY_MODIFIER_MASK;
- unsigned int keycode_no_mod = p_keycode & KEY_CODE_MASK;
- unsigned int xkeycode = KeyMappingX11::get_xlibcode((Key)keycode_no_mod);
+ Key modifiers = p_keycode & KeyModifierMask::MODIFIER_MASK;
+ Key keycode_no_mod = p_keycode & KeyModifierMask::CODE_MASK;
+ unsigned int xkeycode = KeyMappingX11::get_xlibcode(keycode_no_mod);
KeySym xkeysym = XkbKeycodeToKeysym(x11_display, xkeycode, 0, 0);
if (xkeysym >= 'a' && xkeysym <= 'z') {
xkeysym -= ('a' - 'A');
@@ -2080,7 +2419,7 @@ Key DisplayServerX11::keyboard_get_keycode_from_physical(Key p_keycode) const {
Key key = KeyMappingX11::get_keycode(xkeysym);
// If not found, fallback to QWERTY.
// This should match the behavior of the event pump
- if (key == KEY_NONE) {
+ if (key == Key::NONE) {
return p_keycode;
}
return (Key)(key | modifiers);
@@ -2154,12 +2493,12 @@ void DisplayServerX11::_get_key_modifier_state(unsigned int p_x11_state, Ref<Inp
}
MouseButton DisplayServerX11::_get_mouse_button_state(MouseButton p_x11_button, int p_x11_type) {
- MouseButton mask = MouseButton(1 << (p_x11_button - 1));
+ MouseButton mask = mouse_button_to_mask(p_x11_button);
if (p_x11_type == ButtonPress) {
last_button_state |= mask;
} else {
- last_button_state &= MouseButton(~mask);
+ last_button_state &= ~mask;
}
return last_button_state;
@@ -2226,9 +2565,9 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event,
if (status == XLookupChars) {
bool keypress = xkeyevent->type == KeyPress;
Key keycode = KeyMappingX11::get_keycode(keysym_keycode);
- unsigned int physical_keycode = KeyMappingX11::get_scancode(xkeyevent->keycode);
+ Key physical_keycode = KeyMappingX11::get_scancode(xkeyevent->keycode);
- if (keycode >= 'a' && keycode <= 'z') {
+ if (keycode >= Key::A + 32 && keycode <= Key::Z + 32) {
keycode -= 'a' - 'A';
}
@@ -2237,11 +2576,11 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event,
for (int i = 0; i < tmp.length(); i++) {
Ref<InputEventKey> k;
k.instantiate();
- if (physical_keycode == 0 && keycode == 0 && tmp[i] == 0) {
+ if (physical_keycode == Key::NONE && keycode == Key::NONE && tmp[i] == 0) {
continue;
}
- if (keycode == 0) {
+ if (keycode == Key::NONE) {
keycode = (Key)physical_keycode;
}
@@ -2258,10 +2597,10 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event,
k->set_echo(false);
- if (k->get_keycode() == KEY_BACKTAB) {
+ if (k->get_keycode() == Key::BACKTAB) {
//make it consistent across platforms.
- k->set_keycode(KEY_TAB);
- k->set_physical_keycode(KEY_TAB);
+ k->set_keycode(Key::TAB);
+ k->set_physical_keycode(Key::TAB);
k->set_shift_pressed(true);
}
@@ -2290,7 +2629,7 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event,
// keysym, so it works in all platforms the same.
Key keycode = KeyMappingX11::get_keycode(keysym_keycode);
- unsigned int physical_keycode = KeyMappingX11::get_scancode(xkeyevent->keycode);
+ Key physical_keycode = KeyMappingX11::get_scancode(xkeyevent->keycode);
/* Phase 3, obtain a unicode character from the keysym */
@@ -2310,11 +2649,11 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event,
bool keypress = xkeyevent->type == KeyPress;
- if (physical_keycode == 0 && keycode == KEY_NONE && unicode == 0) {
+ if (physical_keycode == Key::NONE && keycode == Key::NONE && unicode == 0) {
return;
}
- if (keycode == KEY_NONE) {
+ if (keycode == Key::NONE) {
keycode = (Key)physical_keycode;
}
@@ -2377,7 +2716,7 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event,
k->set_pressed(keypress);
- if (keycode >= 'a' && keycode <= 'z') {
+ if (keycode >= Key::A + 32 && keycode <= Key::Z + 32) {
keycode -= int('a' - 'A');
}
@@ -2386,23 +2725,23 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event,
k->set_unicode(unicode);
k->set_echo(p_echo);
- if (k->get_keycode() == KEY_BACKTAB) {
+ if (k->get_keycode() == Key::BACKTAB) {
//make it consistent across platforms.
- k->set_keycode(KEY_TAB);
- k->set_physical_keycode(KEY_TAB);
+ k->set_keycode(Key::TAB);
+ k->set_physical_keycode(Key::TAB);
k->set_shift_pressed(true);
}
//don't set mod state if modifier keys are released by themselves
//else event.is_action() will not work correctly here
if (!k->is_pressed()) {
- if (k->get_keycode() == KEY_SHIFT) {
+ if (k->get_keycode() == Key::SHIFT) {
k->set_shift_pressed(false);
- } else if (k->get_keycode() == KEY_CTRL) {
+ } else if (k->get_keycode() == Key::CTRL) {
k->set_ctrl_pressed(false);
- } else if (k->get_keycode() == KEY_ALT) {
+ } else if (k->get_keycode() == Key::ALT) {
k->set_alt_pressed(false);
- } else if (k->get_keycode() == KEY_META) {
+ } else if (k->get_keycode() == Key::META) {
k->set_meta_pressed(false);
}
}
@@ -2417,7 +2756,7 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event,
Input::get_singleton()->parse_input_event(k);
}
-Atom DisplayServerX11::_process_selection_request_target(Atom p_target, Window p_requestor, Atom p_property) const {
+Atom DisplayServerX11::_process_selection_request_target(Atom p_target, Window p_requestor, Atom p_property, Atom p_selection) const {
if (p_target == XInternAtom(x11_display, "TARGETS", 0)) {
// Request to list all supported targets.
Atom data[9];
@@ -2452,14 +2791,20 @@ Atom DisplayServerX11::_process_selection_request_target(Atom p_target, Window p
0);
return p_property;
} else if (p_target == XInternAtom(x11_display, "UTF8_STRING", 0) ||
- p_target == XInternAtom(x11_display, "COMPOUND_TEXT", 0) ||
- p_target == XInternAtom(x11_display, "TEXT", 0) ||
- p_target == XA_STRING ||
- p_target == XInternAtom(x11_display, "text/plain;charset=utf-8", 0) ||
- p_target == XInternAtom(x11_display, "text/plain", 0)) {
+ p_target == XInternAtom(x11_display, "COMPOUND_TEXT", 0) ||
+ p_target == XInternAtom(x11_display, "TEXT", 0) ||
+ p_target == XA_STRING ||
+ p_target == XInternAtom(x11_display, "text/plain;charset=utf-8", 0) ||
+ p_target == XInternAtom(x11_display, "text/plain", 0)) {
// Directly using internal clipboard because we know our window
// is the owner during a selection request.
- CharString clip = internal_clipboard.utf8();
+ CharString clip;
+ static const char *target_type = "PRIMARY";
+ if (p_selection != None && String(XGetAtomName(x11_display, p_selection)) == target_type) {
+ clip = internal_clipboard_primary.utf8();
+ } else {
+ clip = internal_clipboard.utf8();
+ }
XChangeProperty(x11_display,
p_requestor,
p_property,
@@ -2497,7 +2842,7 @@ void DisplayServerX11::_handle_selection_request_event(XSelectionRequestEvent *p
for (uint64_t i = 0; i < len; i += 2) {
Atom target = targets[i];
Atom &property = targets[i + 1];
- property = _process_selection_request_target(target, p_event->requestor, property);
+ property = _process_selection_request_target(target, p_event->requestor, property, p_event->selection);
}
XChangeProperty(x11_display,
@@ -2515,7 +2860,7 @@ void DisplayServerX11::_handle_selection_request_event(XSelectionRequestEvent *p
}
} else {
// Request for target conversion.
- respond.xselection.property = _process_selection_request_target(p_event->target, p_event->requestor, p_event->property);
+ respond.xselection.property = _process_selection_request_target(p_event->target, p_event->requestor, p_event->property, p_event->selection);
}
respond.xselection.type = SelectionNotify;
@@ -2586,6 +2931,11 @@ void DisplayServerX11::_window_changed(XEvent *event) {
context_vulkan->window_resize(window_id, wd.size.width, wd.size.height);
}
#endif
+#if defined(GLES3_ENABLED)
+ if (gl_manager) {
+ gl_manager->window_resize(window_id, wd.size.width, wd.size.height);
+ }
+#endif
if (!wd.rect_changed_callback.is_null()) {
Rect2i r = new_rect;
@@ -2686,27 +3036,34 @@ void DisplayServerX11::_poll_events() {
{
MutexLock mutex_lock(events_mutex);
- // Non-blocking wait for next event and remove it from the queue.
- XEvent ev;
- while (XCheckIfEvent(x11_display, &ev, _predicate_all_events, nullptr)) {
- // Check if the input manager wants to process the event.
- if (XFilterEvent(&ev, None)) {
- // Event has been filtered by the Input Manager,
- // it has to be ignored and a new one will be received.
- continue;
- }
+ _check_pending_events(polled_events);
+ }
+ }
+}
- // Handle selection request events directly in the event thread, because
- // communication through the x server takes several events sent back and forth
- // and we don't want to block other programs while processing only one each frame.
- if (ev.type == SelectionRequest) {
- _handle_selection_request_event(&(ev.xselectionrequest));
- continue;
- }
+void DisplayServerX11::_check_pending_events(LocalVector<XEvent> &r_events) {
+ // Flush to make sure to gather all pending events.
+ XFlush(x11_display);
- polled_events.push_back(ev);
- }
+ // Non-blocking wait for next event and remove it from the queue.
+ XEvent ev;
+ while (XCheckIfEvent(x11_display, &ev, _predicate_all_events, nullptr)) {
+ // Check if the input manager wants to process the event.
+ if (XFilterEvent(&ev, None)) {
+ // Event has been filtered by the Input Manager,
+ // it has to be ignored and a new one will be received.
+ continue;
+ }
+
+ // Handle selection request events directly in the event thread, because
+ // communication through the x server takes several events sent back and forth
+ // and we don't want to block other programs while processing only one each frame.
+ if (ev.type == SelectionRequest) {
+ _handle_selection_request_event(&(ev.xselectionrequest));
+ continue;
}
+
+ r_events.push_back(ev);
}
}
@@ -2759,6 +3116,9 @@ void DisplayServerX11::process_events() {
MutexLock mutex_lock(events_mutex);
events = polled_events;
polled_events.clear();
+
+ // Check for more pending events to avoid an extra frame delay.
+ _check_pending_events(events);
}
for (uint32_t event_index = 0; event_index < events.size(); ++event_index) {
@@ -2818,7 +3178,7 @@ void DisplayServerX11::process_events() {
if (pen_pressure_range != Vector2()) {
xi.pressure_supported = true;
xi.pressure = (*values - pen_pressure_range[0]) /
- (pen_pressure_range[1] - pen_pressure_range[0]);
+ (pen_pressure_range[1] - pen_pressure_range[0]);
}
}
@@ -2877,10 +3237,7 @@ void DisplayServerX11::process_events() {
xi.last_relative_time = raw_event->time;
} break;
#ifdef TOUCH_ENABLED
- 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_TouchBegin:
case XI_TouchEnd: {
bool is_begin = event_data->evtype == XI_TouchBegin;
@@ -3112,10 +3469,10 @@ void DisplayServerX11::process_events() {
mb->set_window_id(window_id);
_get_key_modifier_state(event.xbutton.state, mb);
mb->set_button_index((MouseButton)event.xbutton.button);
- if (mb->get_button_index() == MOUSE_BUTTON_RIGHT) {
- mb->set_button_index(MOUSE_BUTTON_MIDDLE);
- } else if (mb->get_button_index() == MOUSE_BUTTON_MIDDLE) {
- mb->set_button_index(MOUSE_BUTTON_RIGHT);
+ if (mb->get_button_index() == MouseButton::RIGHT) {
+ mb->set_button_index(MouseButton::MIDDLE);
+ } else if (mb->get_button_index() == MouseButton::MIDDLE) {
+ mb->set_button_index(MouseButton::RIGHT);
}
mb->set_button_mask(_get_mouse_button_state(mb->get_button_index(), event.xbutton.type));
mb->set_position(Vector2(event.xbutton.x, event.xbutton.y));
@@ -3141,11 +3498,11 @@ void DisplayServerX11::process_events() {
if (diff < 400 && Vector2(last_click_pos).distance_to(Vector2(event.xbutton.x, event.xbutton.y)) < 5) {
last_click_ms = 0;
last_click_pos = Point2i(-100, -100);
- last_click_button_index = -1;
+ last_click_button_index = MouseButton::NONE;
mb->set_double_click(true);
}
- } else if (mb->get_button_index() < 4 || mb->get_button_index() > 7) {
+ } else if (mb->get_button_index() < MouseButton::WHEEL_UP || mb->get_button_index() > MouseButton::WHEEL_RIGHT) {
last_click_button_index = mb->get_button_index();
}
@@ -3278,12 +3635,12 @@ void DisplayServerX11::process_events() {
if (xi.pressure_supported) {
mm->set_pressure(xi.pressure);
} else {
- mm->set_pressure((mouse_get_button_state() & MOUSE_BUTTON_MASK_LEFT) ? 1.0f : 0.0f);
+ mm->set_pressure(bool(mouse_get_button_state() & MouseButton::MASK_LEFT) ? 1.0f : 0.0f);
}
mm->set_tilt(xi.tilt);
_get_key_modifier_state(event.xmotion.state, mm);
- mm->set_button_mask(mouse_get_button_state());
+ mm->set_button_mask((MouseButton)mouse_get_button_state());
mm->set_position(pos);
mm->set_global_position(pos);
Input::get_singleton()->set_mouse_position(pos);
@@ -3328,11 +3685,18 @@ void DisplayServerX11::process_events() {
} break;
case KeyPress:
case KeyRelease: {
+#ifdef DISPLAY_SERVER_X11_DEBUG_LOGS_ENABLED
+ if (event.type == KeyPress) {
+ DEBUG_LOG_X11("[%u] KeyPress window=%lu (%u), keycode=%u, time=%lu \n", frame, event.xkey.window, window_id, event.xkey.keycode, event.xkey.time);
+ } else {
+ DEBUG_LOG_X11("[%u] KeyRelease window=%lu (%u), keycode=%u, time=%lu \n", frame, event.xkey.window, window_id, event.xkey.keycode, event.xkey.time);
+ }
+#endif
last_timestamp = event.xkey.time;
// key event is a little complex, so
// it will be handled in its own function.
- _handle_key_event(window_id, (XKeyEvent *)&event, events, event_index);
+ _handle_key_event(window_id, &event.xkey, events, event_index);
} break;
case SelectionNotify:
@@ -3455,12 +3819,23 @@ void DisplayServerX11::process_events() {
}
void DisplayServerX11::release_rendering_thread() {
+#if defined(GLES3_ENABLED)
+// gl_manager->release_current();
+#endif
}
void DisplayServerX11::make_rendering_thread() {
+#if defined(GLES3_ENABLED)
+// gl_manager->make_current();
+#endif
}
void DisplayServerX11::swap_buffers() {
+#if defined(GLES3_ENABLED)
+ if (gl_manager) {
+ gl_manager->swap_buffers();
+ }
+#endif
}
void DisplayServerX11::_update_context(WindowData &wd) {
@@ -3602,17 +3977,31 @@ void DisplayServerX11::set_icon(const Ref<Image> &p_icon) {
void DisplayServerX11::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window) {
_THREAD_SAFE_METHOD_
#if defined(VULKAN_ENABLED)
- context_vulkan->set_vsync_mode(p_window, p_vsync_mode);
+ if (context_vulkan) {
+ context_vulkan->set_vsync_mode(p_window, p_vsync_mode);
+ }
+#endif
+
+#if defined(GLES3_ENABLED)
+ if (gl_manager) {
+ gl_manager->set_use_vsync(p_vsync_mode == DisplayServer::VSYNC_ENABLED);
+ }
#endif
}
DisplayServer::VSyncMode DisplayServerX11::window_get_vsync_mode(WindowID p_window) const {
_THREAD_SAFE_METHOD_
#if defined(VULKAN_ENABLED)
- return context_vulkan->get_vsync_mode(p_window);
-#else
- return DisplayServer::VSYNC_ENABLED;
+ if (context_vulkan) {
+ return context_vulkan->get_vsync_mode(p_window);
+ }
#endif
+#if defined(GLES3_ENABLED)
+ if (gl_manager) {
+ return gl_manager->is_using_vsync() ? DisplayServer::VSYNC_ENABLED : DisplayServer::VSYNC_DISABLED;
+ }
+#endif
+ return DisplayServer::VSYNC_ENABLED;
}
Vector<String> DisplayServerX11::get_rendering_drivers_func() {
@@ -3621,8 +4010,8 @@ Vector<String> DisplayServerX11::get_rendering_drivers_func() {
#ifdef VULKAN_ENABLED
drivers.push_back("vulkan");
#endif
-#ifdef OPENGL_ENABLED
- drivers.push_back("opengl");
+#ifdef GLES3_ENABLED
+ drivers.push_back("opengl3");
#endif
return drivers;
@@ -3631,7 +4020,7 @@ Vector<String> DisplayServerX11::get_rendering_drivers_func() {
DisplayServer *DisplayServerX11::create_func(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) {
DisplayServer *ds = memnew(DisplayServerX11(p_rendering_driver, p_mode, p_vsync_mode, p_flags, p_resolution, r_error));
if (r_error != OK) {
- OS::get_singleton()->alert("Your video card driver does not support any of the supported Vulkan versions.\n"
+ OS::get_singleton()->alert("Your video card driver does not support any of the supported Vulkan or OpenGL versions.\n"
"Please update your drivers or if you have a very old or integrated GPU, upgrade it.\n"
"If you have updated your graphics drivers recently, try rebooting.",
"Unable to initialize Video driver");
@@ -3707,18 +4096,18 @@ DisplayServerX11::WindowID DisplayServerX11::_create_window(WindowMode p_mode, V
XSetWindowAttributes new_attr;
new_attr.event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask |
- ButtonReleaseMask | EnterWindowMask |
- LeaveWindowMask | PointerMotionMask |
- Button1MotionMask |
- Button2MotionMask | Button3MotionMask |
- Button4MotionMask | Button5MotionMask |
- ButtonMotionMask | KeymapStateMask |
- ExposureMask | VisibilityChangeMask |
- StructureNotifyMask |
- SubstructureNotifyMask | SubstructureRedirectMask |
- FocusChangeMask | PropertyChangeMask |
- ColormapChangeMask | OwnerGrabButtonMask |
- im_event_mask;
+ ButtonReleaseMask | EnterWindowMask |
+ LeaveWindowMask | PointerMotionMask |
+ Button1MotionMask |
+ Button2MotionMask | Button3MotionMask |
+ Button4MotionMask | Button5MotionMask |
+ ButtonMotionMask | KeymapStateMask |
+ ExposureMask | VisibilityChangeMask |
+ StructureNotifyMask |
+ SubstructureNotifyMask | SubstructureRedirectMask |
+ FocusChangeMask | PropertyChangeMask |
+ ColormapChangeMask | OwnerGrabButtonMask |
+ im_event_mask;
XChangeWindowAttributes(x11_display, wd.x11_window, CWEventMask, &new_attr);
@@ -3807,6 +4196,12 @@ DisplayServerX11::WindowID DisplayServerX11::_create_window(WindowMode p_mode, V
ERR_FAIL_COND_V_MSG(err != OK, INVALID_WINDOW_ID, "Can't create a Vulkan window");
}
#endif
+#ifdef GLES3_ENABLED
+ if (gl_manager) {
+ Error err = gl_manager->window_create(id, wd.x11_window, x11_display, p_rect.size.width, p_rect.size.height);
+ ERR_FAIL_COND_V_MSG(err != OK, INVALID_WINDOW_ID, "Can't create an OpenGL window");
+ }
+#endif
//set_class_hint(x11_display, wd.x11_window);
XFlush(x11_display);
@@ -3856,7 +4251,7 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode
xmbstring = nullptr;
last_click_ms = 0;
- last_click_button_index = -1;
+ last_click_button_index = MouseButton::NONE;
last_click_pos = Point2i(-100, -100);
last_timestamp = 0;
@@ -3988,14 +4383,10 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode
xdnd_selection = XInternAtom(x11_display, "XdndSelection", False);
//!!!!!!!!!!!!!!!!!!!!!!!!!!
- //TODO - do Vulkan and GLES2 support checks, driver selection and fallback
+ //TODO - do Vulkan and OpenGL support checks, driver selection and fallback
rendering_driver = p_rendering_driver;
-#ifndef _MSC_VER
-#warning Forcing vulkan rendering driver because OpenGL not implemented yet
-#endif
- rendering_driver = "vulkan";
-
+ bool driver_found = false;
#if defined(VULKAN_ENABLED)
if (rendering_driver == "vulkan") {
context_vulkan = memnew(VulkanContextX11);
@@ -4005,11 +4396,12 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode
r_error = ERR_CANT_CREATE;
ERR_FAIL_MSG("Could not initialize Vulkan");
}
+ driver_found = true;
}
#endif
- // Init context and rendering device
-#if defined(OPENGL_ENABLED)
- if (rendering_driver == "opengl_es") {
+ // Initialize context and rendering device.
+#if defined(GLES3_ENABLED)
+ if (rendering_driver == "opengl3") {
if (getenv("DRI_PRIME") == nullptr) {
int use_prime = -1;
@@ -4051,28 +4443,37 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode
}
}
- ContextGL_X11::ContextType opengl_api_type = ContextGL_X11::GLES_2_0_COMPATIBLE;
+ GLManager_X11::ContextType opengl_api_type = GLManager_X11::GLES_3_0_COMPATIBLE;
- context_gles2 = memnew(ContextGL_X11(x11_display, x11_window, current_videomode, opengl_api_type));
+ gl_manager = memnew(GLManager_X11(p_resolution, opengl_api_type));
- if (context_gles2->initialize() != OK) {
- memdelete(context_gles2);
- context_gles2 = nullptr;
- ERR_FAIL_V(ERR_UNAVAILABLE);
+ if (gl_manager->initialize() != OK) {
+ memdelete(gl_manager);
+ gl_manager = nullptr;
+ r_error = ERR_UNAVAILABLE;
+ return;
}
+ driver_found = true;
- context_gles2->set_use_vsync(current_videomode.use_vsync);
+ // gl_manager->set_use_vsync(current_videomode.use_vsync);
- if (RasterizerGLES2::is_viable() == OK) {
- RasterizerGLES2::register_config();
- RasterizerGLES2::make_current();
+ if (true) {
+ // if (RasterizerGLES3::is_viable() == OK) {
+ // RasterizerGLES3::register_config();
+ RasterizerGLES3::make_current();
} else {
- memdelete(context_gles2);
- context_gles2 = nullptr;
- ERR_FAIL_V(ERR_UNAVAILABLE);
+ memdelete(gl_manager);
+ gl_manager = nullptr;
+ r_error = ERR_UNAVAILABLE;
+ return;
}
}
#endif
+ if (!driver_found) {
+ r_error = ERR_UNAVAILABLE;
+ ERR_FAIL_MSG("Video driver not found");
+ }
+
Point2i window_position(
(screen_get_size(0).width - p_resolution.width) / 2,
(screen_get_size(0).height - p_resolution.height) / 2);
@@ -4088,7 +4489,6 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode
}
show_window(main_window);
-//create RenderingDevice if used
#if defined(VULKAN_ENABLED)
if (rendering_driver == "vulkan") {
//temporary
@@ -4099,13 +4499,6 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode
}
#endif
- /*
- rendering_server = memnew(RenderingServerDefault);
- if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) {
- rendering_server = memnew(RenderingServerWrapMT(rendering_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD));
- }
- */
-
{
//set all event master mask
XIEventMask all_master_event_mask;
@@ -4118,15 +4511,6 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode
XISelectEvents(x11_display, DefaultRootWindow(x11_display), &all_master_event_mask, 1);
}
- // Disabled by now since grabbing also blocks mouse events
- // (they are received as extended events instead of standard events)
- /*XIClearMask(xi.touch_event_mask.mask, XI_TouchOwnership);
-
- // Grab touch devices to avoid OS gesture interference
- for (int i = 0; i < xi.touch_devices.size(); ++i) {
- XIGrabDevice(x11_display, xi.touch_devices[i], x11_window, CurrentTime, None, XIGrabModeAsync, XIGrabModeAsync, False, &xi.touch_event_mask);
- }*/
-
cursor_size = XcursorGetDefaultSize(x11_display);
cursor_theme = XcursorGetTheme(x11_display);
@@ -4292,6 +4676,11 @@ DisplayServerX11::~DisplayServerX11() {
context_vulkan->window_destroy(E.key);
}
#endif
+#ifdef GLES3_ENABLED
+ if (rendering_driver == "opengl3") {
+ gl_manager->window_destroy(E.key);
+ }
+#endif
WindowData &wd = E.value;
if (wd.xic) {
@@ -4316,6 +4705,13 @@ DisplayServerX11::~DisplayServerX11() {
}
#endif
+#ifdef GLES3_ENABLED
+ if (gl_manager) {
+ memdelete(gl_manager);
+ gl_manager = nullptr;
+ }
+#endif
+
if (xrandr_handle) {
dlclose(xrandr_handle);
}
diff --git a/platform/linuxbsd/display_server_x11.h b/platform/linuxbsd/display_server_x11.h
index 1887c7105b..3587d587d6 100644
--- a/platform/linuxbsd/display_server_x11.h
+++ b/platform/linuxbsd/display_server_x11.h
@@ -31,6 +31,8 @@
#ifndef DISPLAY_SERVER_X11_H
#define DISPLAY_SERVER_X11_H
+#include "drivers/gles3/rasterizer_platforms.h"
+
#ifdef X11_ENABLED
#include "servers/display_server.h"
@@ -46,8 +48,8 @@
#include "servers/rendering/renderer_compositor.h"
#include "servers/rendering_server.h"
-#if defined(OPENGL_ENABLED)
-#include "context_gl_x11.h"
+#if defined(GLES3_ENABLED)
+#include "gl_manager_x11.h"
#endif
#if defined(VULKAN_ENABLED)
@@ -99,12 +101,12 @@ class DisplayServerX11 : public DisplayServer {
Atom requested;
int xdnd_version;
-#if defined(OPENGL_ENABLED)
- ContextGL_X11 *context_gles2;
+#if defined(GLES3_ENABLED)
+ GLManager_X11 *gl_manager = nullptr;
#endif
#if defined(VULKAN_ENABLED)
- VulkanContextX11 *context_vulkan;
- RenderingDeviceVulkan *rendering_device_vulkan;
+ VulkanContextX11 *context_vulkan = nullptr;
+ RenderingDeviceVulkan *rendering_device_vulkan = nullptr;
#endif
#if defined(DBUS_ENABLED)
@@ -155,6 +157,7 @@ class DisplayServerX11 : public DisplayServer {
WindowID _create_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect);
String internal_clipboard;
+ String internal_clipboard_primary;
Window xdnd_source_window;
::Display *x11_display;
char *xmbstring;
@@ -170,8 +173,8 @@ class DisplayServerX11 : public DisplayServer {
bool last_mouse_pos_valid;
Point2i last_click_pos;
uint64_t last_click_ms;
- int last_click_button_index;
- MouseButton last_button_state = MOUSE_BUTTON_NONE;
+ MouseButton last_click_button_index = MouseButton::NONE;
+ MouseButton last_button_state = MouseButton::NONE;
bool app_focused = false;
uint64_t time_since_no_focus = 0;
@@ -196,6 +199,8 @@ class DisplayServerX11 : public DisplayServer {
bool _refresh_device_info();
+ Rect2i _screen_get_rect(int p_screen) const;
+
MouseButton _get_mouse_button_state(MouseButton p_x11_button, int p_x11_type);
void _get_key_modifier_state(unsigned int p_x11_state, Ref<InputEventWithModifiers> state);
void _flush_mouse_motion();
@@ -205,7 +210,7 @@ class DisplayServerX11 : public DisplayServer {
void _handle_key_event(WindowID p_window, XKeyEvent *p_event, LocalVector<XEvent> &p_events, uint32_t &p_event_index, bool p_echo = false);
- Atom _process_selection_request_target(Atom p_target, Window p_requestor, Atom p_property) const;
+ Atom _process_selection_request_target(Atom p_target, Window p_requestor, Atom p_property, Atom p_selection) const;
void _handle_selection_request_event(XSelectionRequestEvent *p_event) const;
String _clipboard_get_impl(Atom p_source, Window x11_window, Atom target) const;
@@ -267,6 +272,7 @@ class DisplayServerX11 : public DisplayServer {
static void _poll_events_thread(void *ud);
bool _wait_for_events() const;
void _poll_events();
+ void _check_pending_events(LocalVector<XEvent> &r_events);
static Bool _predicate_all_events(Display *display, XEvent *event, XPointer arg);
static Bool _predicate_clipboard_selection(Display *display, XEvent *event, XPointer arg);
@@ -290,6 +296,8 @@ public:
virtual void clipboard_set(const String &p_text) override;
virtual String clipboard_get() const override;
+ virtual void clipboard_set_primary(const String &p_text) override;
+ virtual String clipboard_get_primary() const override;
virtual int get_screen_count() const override;
virtual Point2i screen_get_position(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
@@ -331,6 +339,7 @@ public:
virtual void window_set_max_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override;
virtual Size2i window_get_max_size(WindowID p_window = MAIN_WINDOW_ID) const override;
+ virtual void gl_window_make_current(DisplayServer::WindowID p_window_id) override;
virtual void window_set_transient(WindowID p_window, WindowID p_parent) override;
diff --git a/platform/linuxbsd/freedesktop_screensaver.cpp b/platform/linuxbsd/freedesktop_screensaver.cpp
index a6a3b27d76..3973d43d49 100644
--- a/platform/linuxbsd/freedesktop_screensaver.cpp
+++ b/platform/linuxbsd/freedesktop_screensaver.cpp
@@ -50,6 +50,7 @@ void FreeDesktopScreenSaver::inhibit() {
DBusConnection *bus = dbus_bus_get(DBUS_BUS_SESSION, &error);
if (dbus_error_is_set(&error)) {
+ dbus_error_free(&error);
unsupported = true;
return;
}
@@ -72,6 +73,7 @@ void FreeDesktopScreenSaver::inhibit() {
DBusMessage *reply = dbus_connection_send_with_reply_and_block(bus, message, 50, &error);
dbus_message_unref(message);
if (dbus_error_is_set(&error)) {
+ dbus_error_free(&error);
dbus_connection_unref(bus);
unsupported = false;
return;
@@ -96,6 +98,7 @@ void FreeDesktopScreenSaver::uninhibit() {
DBusConnection *bus = dbus_bus_get(DBUS_BUS_SESSION, &error);
if (dbus_error_is_set(&error)) {
+ dbus_error_free(&error);
unsupported = true;
return;
}
@@ -110,6 +113,7 @@ void FreeDesktopScreenSaver::uninhibit() {
DBusMessage *reply = dbus_connection_send_with_reply_and_block(bus, message, 50, &error);
if (dbus_error_is_set(&error)) {
+ dbus_error_free(&error);
dbus_connection_unref(bus);
unsupported = true;
return;
diff --git a/platform/linuxbsd/gl_manager_x11.cpp b/platform/linuxbsd/gl_manager_x11.cpp
new file mode 100644
index 0000000000..e069e92ee6
--- /dev/null
+++ b/platform/linuxbsd/gl_manager_x11.cpp
@@ -0,0 +1,384 @@
+/*************************************************************************/
+/* gl_manager_x11.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#include "gl_manager_x11.h"
+
+#ifdef X11_ENABLED
+#if defined(GLES3_ENABLED)
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#define GLX_GLXEXT_PROTOTYPES
+#include <GL/glx.h>
+#include <GL/glxext.h>
+
+#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
+#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
+
+typedef GLXContext (*GLXCREATECONTEXTATTRIBSARBPROC)(Display *, GLXFBConfig, GLXContext, Bool, const int *);
+
+struct GLManager_X11_Private {
+ ::GLXContext glx_context;
+};
+
+GLManager_X11::GLDisplay::~GLDisplay() {
+ if (context) {
+ //release_current();
+ glXDestroyContext(x11_display, context->glx_context);
+ memdelete(context);
+ context = nullptr;
+ }
+}
+
+static bool ctxErrorOccurred = false;
+static int ctxErrorHandler(Display *dpy, XErrorEvent *ev) {
+ ctxErrorOccurred = true;
+ return 0;
+}
+
+int GLManager_X11::_find_or_create_display(Display *p_x11_display) {
+ for (unsigned int n = 0; n < _displays.size(); n++) {
+ const GLDisplay &d = _displays[n];
+ if (d.x11_display == p_x11_display)
+ return n;
+ }
+
+ // create
+ GLDisplay d_temp;
+ d_temp.x11_display = p_x11_display;
+ _displays.push_back(d_temp);
+ int new_display_id = _displays.size() - 1;
+
+ // create context
+ GLDisplay &d = _displays[new_display_id];
+
+ d.context = memnew(GLManager_X11_Private);
+ ;
+ d.context->glx_context = 0;
+
+ //Error err = _create_context(d);
+ _create_context(d);
+ return new_display_id;
+}
+
+Error GLManager_X11::_create_context(GLDisplay &gl_display) {
+ // some aliases
+ ::Display *x11_display = gl_display.x11_display;
+
+ //const char *extensions = glXQueryExtensionsString(x11_display, DefaultScreen(x11_display));
+
+ GLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = (GLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress((const GLubyte *)"glXCreateContextAttribsARB");
+
+ ERR_FAIL_COND_V(!glXCreateContextAttribsARB, ERR_UNCONFIGURED);
+
+ static int visual_attribs[] = {
+ GLX_RENDER_TYPE, GLX_RGBA_BIT,
+ GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
+ GLX_DOUBLEBUFFER, true,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ GLX_DEPTH_SIZE, 24,
+ None
+ };
+
+ static int visual_attribs_layered[] = {
+ GLX_RENDER_TYPE, GLX_RGBA_BIT,
+ GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
+ GLX_DOUBLEBUFFER, true,
+ GLX_RED_SIZE, 8,
+ GLX_GREEN_SIZE, 8,
+ GLX_BLUE_SIZE, 8,
+ GLX_ALPHA_SIZE, 8,
+ GLX_DEPTH_SIZE, 24,
+ None
+ };
+
+ int fbcount;
+ GLXFBConfig fbconfig = 0;
+ XVisualInfo *vi = nullptr;
+
+ gl_display.x_swa.event_mask = StructureNotifyMask;
+ gl_display.x_swa.border_pixel = 0;
+ gl_display.x_valuemask = CWBorderPixel | CWColormap | CWEventMask;
+
+ if (OS::get_singleton()->is_layered_allowed()) {
+ GLXFBConfig *fbc = glXChooseFBConfig(x11_display, DefaultScreen(x11_display), visual_attribs_layered, &fbcount);
+ ERR_FAIL_COND_V(!fbc, ERR_UNCONFIGURED);
+
+ for (int i = 0; i < fbcount; i++) {
+ vi = (XVisualInfo *)glXGetVisualFromFBConfig(x11_display, fbc[i]);
+ if (!vi)
+ continue;
+
+ XRenderPictFormat *pict_format = XRenderFindVisualFormat(x11_display, vi->visual);
+ if (!pict_format) {
+ XFree(vi);
+ vi = nullptr;
+ continue;
+ }
+
+ fbconfig = fbc[i];
+ if (pict_format->direct.alphaMask > 0) {
+ break;
+ }
+ }
+ XFree(fbc);
+
+ ERR_FAIL_COND_V(!fbconfig, ERR_UNCONFIGURED);
+
+ gl_display.x_swa.background_pixmap = None;
+ gl_display.x_swa.background_pixel = 0;
+ gl_display.x_swa.border_pixmap = None;
+ gl_display.x_valuemask |= CWBackPixel;
+
+ } else {
+ GLXFBConfig *fbc = glXChooseFBConfig(x11_display, DefaultScreen(x11_display), visual_attribs, &fbcount);
+ ERR_FAIL_COND_V(!fbc, ERR_UNCONFIGURED);
+
+ vi = glXGetVisualFromFBConfig(x11_display, fbc[0]);
+
+ fbconfig = fbc[0];
+ XFree(fbc);
+ }
+
+ int (*oldHandler)(Display *, XErrorEvent *) = XSetErrorHandler(&ctxErrorHandler);
+
+ switch (context_type) {
+ 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
+ };
+
+ gl_display.context->glx_context = glXCreateContextAttribsARB(x11_display, fbconfig, nullptr, true, context_attribs);
+ ERR_FAIL_COND_V(ctxErrorOccurred || !gl_display.context->glx_context, ERR_UNCONFIGURED);
+ } break;
+ }
+
+ gl_display.x_swa.colormap = XCreateColormap(x11_display, RootWindow(x11_display, vi->screen), vi->visual, AllocNone);
+
+ XSync(x11_display, False);
+ XSetErrorHandler(oldHandler);
+
+ // make our own copy of the vi data
+ // for later creating windows using this display
+ if (vi) {
+ gl_display.x_vi = *vi;
+ }
+
+ XFree(vi);
+
+ return OK;
+}
+
+Error GLManager_X11::window_create(DisplayServer::WindowID p_window_id, ::Window p_window, Display *p_display, int p_width, int p_height) {
+ // make sure vector is big enough...
+ // we can mirror the external vector, it is simpler
+ // to keep the IDs identical for fast lookup
+ if (p_window_id >= (int)_windows.size()) {
+ _windows.resize(p_window_id + 1);
+ }
+
+ GLWindow &win = _windows[p_window_id];
+ win.in_use = true;
+ win.window_id = p_window_id;
+ win.width = p_width;
+ win.height = p_height;
+ win.x11_window = p_window;
+ win.gldisplay_id = _find_or_create_display(p_display);
+
+ // the display could be invalid .. check NYI
+ GLDisplay &gl_display = _displays[win.gldisplay_id];
+ //const XVisualInfo &vi = gl_display.x_vi;
+ //XSetWindowAttributes &swa = gl_display.x_swa;
+ ::Display *x11_display = gl_display.x11_display;
+ ::Window &x11_window = win.x11_window;
+
+ if (!glXMakeCurrent(x11_display, x11_window, gl_display.context->glx_context)) {
+ ERR_PRINT("glXMakeCurrent failed");
+ }
+
+ _internal_set_current_window(&win);
+
+ return OK;
+}
+
+void GLManager_X11::_internal_set_current_window(GLWindow *p_win) {
+ _current_window = p_win;
+
+ // quick access to x info
+ _x_windisp.x11_window = _current_window->x11_window;
+ const GLDisplay &disp = get_current_display();
+ _x_windisp.x11_display = disp.x11_display;
+}
+
+void GLManager_X11::window_resize(DisplayServer::WindowID p_window_id, int p_width, int p_height) {
+ get_window(p_window_id).width = p_width;
+ get_window(p_window_id).height = p_height;
+}
+
+void GLManager_X11::window_destroy(DisplayServer::WindowID p_window_id) {
+ GLWindow &win = get_window(p_window_id);
+ win.in_use = false;
+
+ if (_current_window == &win) {
+ _current_window = nullptr;
+ _x_windisp.x11_display = nullptr;
+ _x_windisp.x11_window = -1;
+ }
+}
+
+void GLManager_X11::release_current() {
+ if (!_current_window)
+ return;
+ glXMakeCurrent(_x_windisp.x11_display, None, nullptr);
+}
+
+void GLManager_X11::window_make_current(DisplayServer::WindowID p_window_id) {
+ if (p_window_id == -1)
+ return;
+
+ GLWindow &win = _windows[p_window_id];
+ if (!win.in_use)
+ return;
+
+ // noop
+ if (&win == _current_window)
+ return;
+
+ const GLDisplay &disp = get_display(win.gldisplay_id);
+
+ glXMakeCurrent(disp.x11_display, win.x11_window, disp.context->glx_context);
+
+ _internal_set_current_window(&win);
+}
+
+void GLManager_X11::make_current() {
+ if (!_current_window)
+ return;
+ if (!_current_window->in_use) {
+ WARN_PRINT("current window not in use!");
+ return;
+ }
+ const GLDisplay &disp = get_current_display();
+ glXMakeCurrent(_x_windisp.x11_display, _x_windisp.x11_window, disp.context->glx_context);
+}
+
+void GLManager_X11::swap_buffers() {
+ // NO NEED TO CALL SWAP BUFFERS for each window...
+ // see https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glXSwapBuffers.xml
+
+ if (!_current_window)
+ return;
+ if (!_current_window->in_use) {
+ WARN_PRINT("current window not in use!");
+ return;
+ }
+
+ // print_line("\tswap_buffers");
+
+ // only for debugging without drawing anything
+ // glClearColor(Math::randf(), 0, 1, 1);
+ //glClear(GL_COLOR_BUFFER_BIT);
+
+ //const GLDisplay &disp = get_current_display();
+ glXSwapBuffers(_x_windisp.x11_display, _x_windisp.x11_window);
+}
+
+Error GLManager_X11::initialize() {
+ return OK;
+}
+
+void GLManager_X11::set_use_vsync(bool p_use) {
+ static bool setup = false;
+ static PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT = nullptr;
+ static PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalMESA = nullptr;
+ static PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI = nullptr;
+
+ // force vsync in the editor for now, as a safety measure
+ bool is_editor = Engine::get_singleton()->is_editor_hint();
+ if (is_editor) {
+ p_use = true;
+ }
+
+ // we need an active window to get a display to set the vsync
+ if (!_current_window)
+ return;
+ const GLDisplay &disp = get_current_display();
+
+ if (!setup) {
+ setup = true;
+ String extensions = glXQueryExtensionsString(disp.x11_display, DefaultScreen(disp.x11_display));
+ if (extensions.find("GLX_EXT_swap_control") != -1)
+ glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB((const GLubyte *)"glXSwapIntervalEXT");
+ if (extensions.find("GLX_MESA_swap_control") != -1)
+ glXSwapIntervalMESA = (PFNGLXSWAPINTERVALSGIPROC)glXGetProcAddressARB((const GLubyte *)"glXSwapIntervalMESA");
+ if (extensions.find("GLX_SGI_swap_control") != -1)
+ glXSwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)glXGetProcAddressARB((const GLubyte *)"glXSwapIntervalSGI");
+ }
+ int val = p_use ? 1 : 0;
+ if (glXSwapIntervalMESA) {
+ glXSwapIntervalMESA(val);
+ } else if (glXSwapIntervalSGI) {
+ glXSwapIntervalSGI(val);
+ } else if (glXSwapIntervalEXT) {
+ GLXDrawable drawable = glXGetCurrentDrawable();
+ glXSwapIntervalEXT(disp.x11_display, drawable, val);
+ } else
+ return;
+ use_vsync = p_use;
+}
+
+bool GLManager_X11::is_using_vsync() const {
+ return use_vsync;
+}
+
+GLManager_X11::GLManager_X11(const Vector2i &p_size, ContextType p_context_type) {
+ context_type = p_context_type;
+
+ double_buffer = false;
+ direct_render = false;
+ glx_minor = glx_major = 0;
+ use_vsync = false;
+ _current_window = nullptr;
+}
+
+GLManager_X11::~GLManager_X11() {
+ release_current();
+}
+
+#endif
+#endif
diff --git a/platform/linuxbsd/context_gl_x11.h b/platform/linuxbsd/gl_manager_x11.h
index d089886f4d..fa2c8a9c84 100644
--- a/platform/linuxbsd/context_gl_x11.h
+++ b/platform/linuxbsd/gl_manager_x11.h
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* context_gl_x11.h */
+/* gl_manager_x11.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -28,53 +28,103 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef CONTEXT_GL_X11_H
-#define CONTEXT_GL_X11_H
+#ifndef GL_MANAGER_X11_H
+#define GL_MANAGER_X11_H
#ifdef X11_ENABLED
-#if defined(OPENGL_ENABLED)
+#include "drivers/gles3/rasterizer_platforms.h"
+
+#ifdef GLES3_ENABLED
#include "core/os/os.h"
+#include "core/templates/local_vector.h"
+#include "servers/display_server.h"
#include <X11/Xlib.h>
#include <X11/extensions/Xrender.h>
-struct ContextGL_X11_Private;
+struct GLManager_X11_Private;
-class ContextGL_X11 {
+class GLManager_X11 {
public:
enum ContextType {
- GLES_2_0_COMPATIBLE,
+ GLES_3_0_COMPATIBLE,
};
private:
- ContextGL_X11_Private *p;
- OS::VideoMode default_video_mode;
- ::Display *x11_display;
- ::Window &x11_window;
+ // any data specific to the window
+ struct GLWindow {
+ GLWindow() { in_use = false; }
+ bool in_use;
+
+ // the external ID .. should match the GL window number .. unused I think
+ DisplayServer::WindowID window_id;
+ int width;
+ int height;
+ ::Window x11_window;
+ int gldisplay_id;
+ };
+
+ struct GLDisplay {
+ GLDisplay() { context = nullptr; }
+ ~GLDisplay();
+ GLManager_X11_Private *context;
+ ::Display *x11_display;
+ XVisualInfo x_vi;
+ XSetWindowAttributes x_swa;
+ unsigned long x_valuemask;
+ };
+
+ // just for convenience, window and display struct
+ struct XWinDisp {
+ ::Window x11_window;
+ ::Display *x11_display;
+ } _x_windisp;
+
+ LocalVector<GLWindow> _windows;
+ LocalVector<GLDisplay> _displays;
+
+ GLWindow *_current_window;
+
+ void _internal_set_current_window(GLWindow *p_win);
+
+ GLWindow &get_window(unsigned int id) { return _windows[id]; }
+ const GLWindow &get_window(unsigned int id) const { return _windows[id]; }
+
+ const GLDisplay &get_current_display() const { return _displays[_current_window->gldisplay_id]; }
+ const GLDisplay &get_display(unsigned int id) { return _displays[id]; }
+
bool double_buffer;
bool direct_render;
int glx_minor, glx_major;
bool use_vsync;
ContextType context_type;
+private:
+ int _find_or_create_display(Display *p_x11_display);
+ Error _create_context(GLDisplay &gl_display);
+
public:
+ Error window_create(DisplayServer::WindowID p_window_id, ::Window p_window, Display *p_display, int p_width, int p_height);
+ void window_destroy(DisplayServer::WindowID p_window_id);
+ void window_resize(DisplayServer::WindowID p_window_id, int p_width, int p_height);
+
void release_current();
void make_current();
void swap_buffers();
- int get_window_width();
- int get_window_height();
+
+ void window_make_current(DisplayServer::WindowID p_window_id);
Error initialize();
void set_use_vsync(bool p_use);
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();
+ GLManager_X11(const Vector2i &p_size, ContextType p_context_type);
+ ~GLManager_X11();
};
-#endif
+#endif // GLES3_ENABLED
+#endif // X11_ENABLED
-#endif
-#endif
+#endif // GL_MANAGER_X11_H
diff --git a/platform/linuxbsd/joypad_linux.cpp b/platform/linuxbsd/joypad_linux.cpp
index 8b6dbc4c20..1c6afabfab 100644
--- a/platform/linuxbsd/joypad_linux.cpp
+++ b/platform/linuxbsd/joypad_linux.cpp
@@ -59,7 +59,7 @@ JoypadLinux::Joypad::~Joypad() {
}
void JoypadLinux::Joypad::reset() {
- dpad = 0;
+ dpad = HatMask::CENTER;
fd = -1;
Input::JoyAxisValue jx;
@@ -484,12 +484,12 @@ void JoypadLinux::process_joypads() {
case ABS_HAT0X:
if (ev.value != 0) {
if (ev.value < 0) {
- joy->dpad = (HatMask)((joy->dpad | HatMask::HAT_MASK_LEFT) & ~HatMask::HAT_MASK_RIGHT);
+ joy->dpad = (HatMask)((joy->dpad | HatMask::LEFT) & ~HatMask::RIGHT);
} else {
- joy->dpad = (HatMask)((joy->dpad | HatMask::HAT_MASK_RIGHT) & ~HatMask::HAT_MASK_LEFT);
+ joy->dpad = (HatMask)((joy->dpad | HatMask::RIGHT) & ~HatMask::LEFT);
}
} else {
- joy->dpad &= ~(HatMask::HAT_MASK_LEFT | HatMask::HAT_MASK_RIGHT);
+ joy->dpad &= ~(HatMask::LEFT | HatMask::RIGHT);
}
input->joy_hat(i, (HatMask)joy->dpad);
@@ -498,12 +498,12 @@ void JoypadLinux::process_joypads() {
case ABS_HAT0Y:
if (ev.value != 0) {
if (ev.value < 0) {
- joy->dpad = (HatMask)((joy->dpad | HatMask::HAT_MASK_UP) & ~HatMask::HAT_MASK_DOWN);
+ joy->dpad = (HatMask)((joy->dpad | HatMask::UP) & ~HatMask::DOWN);
} else {
- joy->dpad = (HatMask)((joy->dpad | HatMask::HAT_MASK_DOWN) & ~HatMask::HAT_MASK_UP);
+ joy->dpad = (HatMask)((joy->dpad | HatMask::DOWN) & ~HatMask::UP);
}
} else {
- joy->dpad &= ~(HatMask::HAT_MASK_UP | HatMask::HAT_MASK_DOWN);
+ joy->dpad &= ~(HatMask::UP | HatMask::DOWN);
}
input->joy_hat(i, (HatMask)joy->dpad);
diff --git a/platform/linuxbsd/joypad_linux.h b/platform/linuxbsd/joypad_linux.h
index 177d7a51ce..12b9046d64 100644
--- a/platform/linuxbsd/joypad_linux.h
+++ b/platform/linuxbsd/joypad_linux.h
@@ -56,7 +56,7 @@ private:
Input::JoyAxisValue curr_axis[MAX_ABS];
int key_map[MAX_KEY];
int abs_map[MAX_ABS];
- int dpad = 0;
+ HatMask dpad = HatMask::CENTER;
int fd = -1;
String devpath;
diff --git a/platform/linuxbsd/key_mapping_x11.cpp b/platform/linuxbsd/key_mapping_x11.cpp
index 829feda40a..16c2392859 100644
--- a/platform/linuxbsd/key_mapping_x11.cpp
+++ b/platform/linuxbsd/key_mapping_x11.cpp
@@ -40,266 +40,266 @@ struct _XTranslatePair {
static _XTranslatePair _xkeysym_to_keycode[] = {
// misc keys
- { XK_Escape, KEY_ESCAPE },
- { XK_Tab, KEY_TAB },
- { XK_ISO_Left_Tab, KEY_BACKTAB },
- { XK_BackSpace, KEY_BACKSPACE },
- { XK_Return, KEY_ENTER },
- { XK_Insert, KEY_INSERT },
- { XK_Delete, KEY_DELETE },
- { XK_Clear, KEY_DELETE },
- { XK_Pause, KEY_PAUSE },
- { XK_Print, KEY_PRINT },
- { XK_Home, KEY_HOME },
- { XK_End, KEY_END },
- { XK_Left, KEY_LEFT },
- { XK_Up, KEY_UP },
- { XK_Right, KEY_RIGHT },
- { XK_Down, KEY_DOWN },
- { XK_Prior, KEY_PAGEUP },
- { XK_Next, KEY_PAGEDOWN },
- { XK_Shift_L, KEY_SHIFT },
- { XK_Shift_R, KEY_SHIFT },
- { XK_Shift_Lock, KEY_SHIFT },
- { XK_Control_L, KEY_CTRL },
- { XK_Control_R, KEY_CTRL },
- { XK_Meta_L, KEY_META },
- { XK_Meta_R, KEY_META },
- { XK_Alt_L, KEY_ALT },
- { XK_Alt_R, KEY_ALT },
- { XK_Caps_Lock, KEY_CAPSLOCK },
- { XK_Num_Lock, KEY_NUMLOCK },
- { XK_Scroll_Lock, KEY_SCROLLLOCK },
- { XK_Super_L, KEY_SUPER_L },
- { XK_Super_R, KEY_SUPER_R },
- { XK_Menu, KEY_MENU },
- { XK_Hyper_L, KEY_HYPER_L },
- { XK_Hyper_R, KEY_HYPER_R },
- { XK_Help, KEY_HELP },
- { XK_KP_Space, KEY_SPACE },
- { XK_KP_Tab, KEY_TAB },
- { XK_KP_Enter, KEY_KP_ENTER },
- { XK_Home, KEY_HOME },
- { XK_Left, KEY_LEFT },
- { XK_Up, KEY_UP },
- { XK_Right, KEY_RIGHT },
- { XK_Down, KEY_DOWN },
- { XK_Prior, KEY_PAGEUP },
- { XK_Next, KEY_PAGEDOWN },
- { XK_End, KEY_END },
- { XK_Begin, KEY_CLEAR },
- { XK_Insert, KEY_INSERT },
- { XK_Delete, KEY_DELETE },
- //{ XK_KP_Equal, KEY_EQUAL },
- //{ XK_KP_Separator, KEY_COMMA },
- { XK_KP_Decimal, KEY_KP_PERIOD },
- { XK_KP_Delete, KEY_KP_PERIOD },
- { XK_KP_Multiply, KEY_KP_MULTIPLY },
- { XK_KP_Divide, KEY_KP_DIVIDE },
- { XK_KP_Subtract, KEY_KP_SUBTRACT },
- { XK_KP_Add, KEY_KP_ADD },
- { XK_KP_0, KEY_KP_0 },
- { XK_KP_1, KEY_KP_1 },
- { XK_KP_2, KEY_KP_2 },
- { XK_KP_3, KEY_KP_3 },
- { XK_KP_4, KEY_KP_4 },
- { XK_KP_5, KEY_KP_5 },
- { XK_KP_6, KEY_KP_6 },
- { XK_KP_7, KEY_KP_7 },
- { XK_KP_8, KEY_KP_8 },
- { XK_KP_9, KEY_KP_9 },
+ { XK_Escape, Key::ESCAPE },
+ { XK_Tab, Key::TAB },
+ { XK_ISO_Left_Tab, Key::BACKTAB },
+ { XK_BackSpace, Key::BACKSPACE },
+ { XK_Return, Key::ENTER },
+ { XK_Insert, Key::INSERT },
+ { XK_Delete, Key::KEY_DELETE },
+ { XK_Clear, Key::KEY_DELETE },
+ { XK_Pause, Key::PAUSE },
+ { XK_Print, Key::PRINT },
+ { XK_Home, Key::HOME },
+ { XK_End, Key::END },
+ { XK_Left, Key::LEFT },
+ { XK_Up, Key::UP },
+ { XK_Right, Key::RIGHT },
+ { XK_Down, Key::DOWN },
+ { XK_Prior, Key::PAGEUP },
+ { XK_Next, Key::PAGEDOWN },
+ { XK_Shift_L, Key::SHIFT },
+ { XK_Shift_R, Key::SHIFT },
+ { XK_Shift_Lock, Key::SHIFT },
+ { XK_Control_L, Key::CTRL },
+ { XK_Control_R, Key::CTRL },
+ { XK_Meta_L, Key::META },
+ { XK_Meta_R, Key::META },
+ { XK_Alt_L, Key::ALT },
+ { XK_Alt_R, Key::ALT },
+ { XK_Caps_Lock, Key::CAPSLOCK },
+ { XK_Num_Lock, Key::NUMLOCK },
+ { XK_Scroll_Lock, Key::SCROLLLOCK },
+ { XK_Super_L, Key::SUPER_L },
+ { XK_Super_R, Key::SUPER_R },
+ { XK_Menu, Key::MENU },
+ { XK_Hyper_L, Key::HYPER_L },
+ { XK_Hyper_R, Key::HYPER_R },
+ { XK_Help, Key::HELP },
+ { XK_KP_Space, Key::SPACE },
+ { XK_KP_Tab, Key::TAB },
+ { XK_KP_Enter, Key::KP_ENTER },
+ { XK_Home, Key::HOME },
+ { XK_Left, Key::LEFT },
+ { XK_Up, Key::UP },
+ { XK_Right, Key::RIGHT },
+ { XK_Down, Key::DOWN },
+ { XK_Prior, Key::PAGEUP },
+ { XK_Next, Key::PAGEDOWN },
+ { XK_End, Key::END },
+ { XK_Begin, Key::CLEAR },
+ { XK_Insert, Key::INSERT },
+ { XK_Delete, Key::KEY_DELETE },
+ //{ XK_KP_Equal, Key::EQUAL },
+ //{ XK_KP_Separator, Key::COMMA },
+ { XK_KP_Decimal, Key::KP_PERIOD },
+ { XK_KP_Delete, Key::KP_PERIOD },
+ { XK_KP_Multiply, Key::KP_MULTIPLY },
+ { XK_KP_Divide, Key::KP_DIVIDE },
+ { XK_KP_Subtract, Key::KP_SUBTRACT },
+ { XK_KP_Add, Key::KP_ADD },
+ { XK_KP_0, Key::KP_0 },
+ { XK_KP_1, Key::KP_1 },
+ { XK_KP_2, Key::KP_2 },
+ { XK_KP_3, Key::KP_3 },
+ { XK_KP_4, Key::KP_4 },
+ { XK_KP_5, Key::KP_5 },
+ { XK_KP_6, Key::KP_6 },
+ { XK_KP_7, Key::KP_7 },
+ { XK_KP_8, Key::KP_8 },
+ { XK_KP_9, Key::KP_9 },
// same but with numlock
- { XK_KP_Insert, KEY_KP_0 },
- { XK_KP_End, KEY_KP_1 },
- { XK_KP_Down, KEY_KP_2 },
- { XK_KP_Page_Down, KEY_KP_3 },
- { XK_KP_Left, KEY_KP_4 },
- { XK_KP_Begin, KEY_KP_5 },
- { XK_KP_Right, KEY_KP_6 },
- { XK_KP_Home, KEY_KP_7 },
- { XK_KP_Up, KEY_KP_8 },
- { XK_KP_Page_Up, KEY_KP_9 },
- { XK_F1, KEY_F1 },
- { XK_F2, KEY_F2 },
- { XK_F3, KEY_F3 },
- { XK_F4, KEY_F4 },
- { XK_F5, KEY_F5 },
- { XK_F6, KEY_F6 },
- { XK_F7, KEY_F7 },
- { XK_F8, KEY_F8 },
- { XK_F9, KEY_F9 },
- { XK_F10, KEY_F10 },
- { XK_F11, KEY_F11 },
- { XK_F12, KEY_F12 },
- { XK_F13, KEY_F13 },
- { XK_F14, KEY_F14 },
- { XK_F15, KEY_F15 },
- { XK_F16, KEY_F16 },
+ { XK_KP_Insert, Key::KP_0 },
+ { XK_KP_End, Key::KP_1 },
+ { XK_KP_Down, Key::KP_2 },
+ { XK_KP_Page_Down, Key::KP_3 },
+ { XK_KP_Left, Key::KP_4 },
+ { XK_KP_Begin, Key::KP_5 },
+ { XK_KP_Right, Key::KP_6 },
+ { XK_KP_Home, Key::KP_7 },
+ { XK_KP_Up, Key::KP_8 },
+ { XK_KP_Page_Up, Key::KP_9 },
+ { XK_F1, Key::F1 },
+ { XK_F2, Key::F2 },
+ { XK_F3, Key::F3 },
+ { XK_F4, Key::F4 },
+ { XK_F5, Key::F5 },
+ { XK_F6, Key::F6 },
+ { XK_F7, Key::F7 },
+ { XK_F8, Key::F8 },
+ { XK_F9, Key::F9 },
+ { XK_F10, Key::F10 },
+ { XK_F11, Key::F11 },
+ { XK_F12, Key::F12 },
+ { XK_F13, Key::F13 },
+ { XK_F14, Key::F14 },
+ { XK_F15, Key::F15 },
+ { XK_F16, Key::F16 },
// media keys
- { XF86XK_Back, KEY_BACK },
- { XF86XK_Forward, KEY_FORWARD },
- { XF86XK_Stop, KEY_STOP },
- { XF86XK_Refresh, KEY_REFRESH },
- { XF86XK_Favorites, KEY_FAVORITES },
- { XF86XK_AudioMedia, KEY_LAUNCHMEDIA },
- { XF86XK_OpenURL, KEY_OPENURL },
- { XF86XK_HomePage, KEY_HOMEPAGE },
- { XF86XK_Search, KEY_SEARCH },
- { XF86XK_AudioLowerVolume, KEY_VOLUMEDOWN },
- { XF86XK_AudioMute, KEY_VOLUMEMUTE },
- { XF86XK_AudioRaiseVolume, KEY_VOLUMEUP },
- { XF86XK_AudioPlay, KEY_MEDIAPLAY },
- { XF86XK_AudioStop, KEY_MEDIASTOP },
- { XF86XK_AudioPrev, KEY_MEDIAPREVIOUS },
- { XF86XK_AudioNext, KEY_MEDIANEXT },
- { XF86XK_AudioRecord, KEY_MEDIARECORD },
+ { XF86XK_Back, Key::BACK },
+ { XF86XK_Forward, Key::FORWARD },
+ { XF86XK_Stop, Key::STOP },
+ { XF86XK_Refresh, Key::REFRESH },
+ { XF86XK_Favorites, Key::FAVORITES },
+ { XF86XK_AudioMedia, Key::LAUNCHMEDIA },
+ { XF86XK_OpenURL, Key::OPENURL },
+ { XF86XK_HomePage, Key::HOMEPAGE },
+ { XF86XK_Search, Key::SEARCH },
+ { XF86XK_AudioLowerVolume, Key::VOLUMEDOWN },
+ { XF86XK_AudioMute, Key::VOLUMEMUTE },
+ { XF86XK_AudioRaiseVolume, Key::VOLUMEUP },
+ { XF86XK_AudioPlay, Key::MEDIAPLAY },
+ { XF86XK_AudioStop, Key::MEDIASTOP },
+ { XF86XK_AudioPrev, Key::MEDIAPREVIOUS },
+ { XF86XK_AudioNext, Key::MEDIANEXT },
+ { XF86XK_AudioRecord, Key::MEDIARECORD },
// launch keys
- { XF86XK_Mail, KEY_LAUNCHMAIL },
- { XF86XK_MyComputer, KEY_LAUNCH0 },
- { XF86XK_Calculator, KEY_LAUNCH1 },
- { XF86XK_Standby, KEY_STANDBY },
+ { XF86XK_Mail, Key::LAUNCHMAIL },
+ { XF86XK_MyComputer, Key::LAUNCH0 },
+ { XF86XK_Calculator, Key::LAUNCH1 },
+ { XF86XK_Standby, Key::STANDBY },
- { XF86XK_Launch0, KEY_LAUNCH2 },
- { XF86XK_Launch1, KEY_LAUNCH3 },
- { XF86XK_Launch2, KEY_LAUNCH4 },
- { XF86XK_Launch3, KEY_LAUNCH5 },
- { XF86XK_Launch4, KEY_LAUNCH6 },
- { XF86XK_Launch5, KEY_LAUNCH7 },
- { XF86XK_Launch6, KEY_LAUNCH8 },
- { XF86XK_Launch7, KEY_LAUNCH9 },
- { XF86XK_Launch8, KEY_LAUNCHA },
- { XF86XK_Launch9, KEY_LAUNCHB },
- { XF86XK_LaunchA, KEY_LAUNCHC },
- { XF86XK_LaunchB, KEY_LAUNCHD },
- { XF86XK_LaunchC, KEY_LAUNCHE },
- { XF86XK_LaunchD, KEY_LAUNCHF },
+ { XF86XK_Launch0, Key::LAUNCH2 },
+ { XF86XK_Launch1, Key::LAUNCH3 },
+ { XF86XK_Launch2, Key::LAUNCH4 },
+ { XF86XK_Launch3, Key::LAUNCH5 },
+ { XF86XK_Launch4, Key::LAUNCH6 },
+ { XF86XK_Launch5, Key::LAUNCH7 },
+ { XF86XK_Launch6, Key::LAUNCH8 },
+ { XF86XK_Launch7, Key::LAUNCH9 },
+ { XF86XK_Launch8, Key::LAUNCHA },
+ { XF86XK_Launch9, Key::LAUNCHB },
+ { XF86XK_LaunchA, Key::LAUNCHC },
+ { XF86XK_LaunchB, Key::LAUNCHD },
+ { XF86XK_LaunchC, Key::LAUNCHE },
+ { XF86XK_LaunchD, Key::LAUNCHF },
- { 0, KEY_NONE }
+ { 0, Key::NONE }
};
struct _TranslatePair {
- unsigned int keysym;
+ Key keysym;
unsigned int keycode;
};
static _TranslatePair _scancode_to_keycode[] = {
- { KEY_ESCAPE, 0x09 },
- { KEY_1, 0x0A },
- { KEY_2, 0x0B },
- { KEY_3, 0x0C },
- { KEY_4, 0x0D },
- { KEY_5, 0x0E },
- { KEY_6, 0x0F },
- { KEY_7, 0x10 },
- { KEY_8, 0x11 },
- { KEY_9, 0x12 },
- { KEY_0, 0x13 },
- { KEY_MINUS, 0x14 },
- { KEY_EQUAL, 0x15 },
- { KEY_BACKSPACE, 0x16 },
- { KEY_TAB, 0x17 },
- { KEY_Q, 0x18 },
- { KEY_W, 0x19 },
- { KEY_E, 0x1A },
- { KEY_R, 0x1B },
- { KEY_T, 0x1C },
- { KEY_Y, 0x1D },
- { KEY_U, 0x1E },
- { KEY_I, 0x1F },
- { KEY_O, 0x20 },
- { KEY_P, 0x21 },
- { KEY_BRACELEFT, 0x22 },
- { KEY_BRACERIGHT, 0x23 },
- { KEY_ENTER, 0x24 },
- { KEY_CTRL, 0x25 },
- { KEY_A, 0x26 },
- { KEY_S, 0x27 },
- { KEY_D, 0x28 },
- { KEY_F, 0x29 },
- { KEY_G, 0x2A },
- { KEY_H, 0x2B },
- { KEY_J, 0x2C },
- { KEY_K, 0x2D },
- { KEY_L, 0x2E },
- { KEY_SEMICOLON, 0x2F },
- { KEY_APOSTROPHE, 0x30 },
- { KEY_QUOTELEFT, 0x31 },
- { KEY_SHIFT, 0x32 },
- { KEY_BACKSLASH, 0x33 },
- { KEY_Z, 0x34 },
- { KEY_X, 0x35 },
- { KEY_C, 0x36 },
- { KEY_V, 0x37 },
- { KEY_B, 0x38 },
- { KEY_N, 0x39 },
- { KEY_M, 0x3A },
- { KEY_COMMA, 0x3B },
- { KEY_PERIOD, 0x3C },
- { KEY_SLASH, 0x3D },
- { KEY_SHIFT, 0x3E },
- { KEY_KP_MULTIPLY, 0x3F },
- { KEY_ALT, 0x40 },
- { KEY_SPACE, 0x41 },
- { KEY_CAPSLOCK, 0x42 },
- { KEY_F1, 0x43 },
- { KEY_F2, 0x44 },
- { KEY_F3, 0x45 },
- { KEY_F4, 0x46 },
- { KEY_F5, 0x47 },
- { KEY_F6, 0x48 },
- { KEY_F7, 0x49 },
- { KEY_F8, 0x4A },
- { KEY_F9, 0x4B },
- { KEY_F10, 0x4C },
- { KEY_NUMLOCK, 0x4D },
- { KEY_SCROLLLOCK, 0x4E },
- { KEY_KP_7, 0x4F },
- { KEY_KP_8, 0x50 },
- { KEY_KP_9, 0x51 },
- { KEY_KP_SUBTRACT, 0x52 },
- { KEY_KP_4, 0x53 },
- { KEY_KP_5, 0x54 },
- { KEY_KP_6, 0x55 },
- { KEY_KP_ADD, 0x56 },
- { KEY_KP_1, 0x57 },
- { KEY_KP_2, 0x58 },
- { KEY_KP_3, 0x59 },
- { KEY_KP_0, 0x5A },
- { KEY_KP_PERIOD, 0x5B },
- //{ KEY_???, 0x5E }, //NON US BACKSLASH
- { KEY_F11, 0x5F },
- { KEY_F12, 0x60 },
- { KEY_KP_ENTER, 0x68 },
- { KEY_CTRL, 0x69 },
- { KEY_KP_DIVIDE, 0x6A },
- { KEY_PRINT, 0x6B },
- { KEY_ALT, 0x6C },
- { KEY_ENTER, 0x6D },
- { KEY_HOME, 0x6E },
- { KEY_UP, 0x6F },
- { KEY_PAGEUP, 0x70 },
- { KEY_LEFT, 0x71 },
- { KEY_RIGHT, 0x72 },
- { KEY_END, 0x73 },
- { KEY_DOWN, 0x74 },
- { KEY_PAGEDOWN, 0x75 },
- { KEY_INSERT, 0x76 },
- { KEY_DELETE, 0x77 },
- { KEY_VOLUMEMUTE, 0x79 },
- { KEY_VOLUMEDOWN, 0x7A },
- { KEY_VOLUMEUP, 0x7B },
- { KEY_PAUSE, 0x7F },
- { KEY_SUPER_L, 0x85 },
- { KEY_SUPER_R, 0x86 },
- { KEY_MENU, 0x87 },
- { KEY_UNKNOWN, 0 }
+ { Key::ESCAPE, 0x09 },
+ { Key::KEY_1, 0x0A },
+ { Key::KEY_2, 0x0B },
+ { Key::KEY_3, 0x0C },
+ { Key::KEY_4, 0x0D },
+ { Key::KEY_5, 0x0E },
+ { Key::KEY_6, 0x0F },
+ { Key::KEY_7, 0x10 },
+ { Key::KEY_8, 0x11 },
+ { Key::KEY_9, 0x12 },
+ { Key::KEY_0, 0x13 },
+ { Key::MINUS, 0x14 },
+ { Key::EQUAL, 0x15 },
+ { Key::BACKSPACE, 0x16 },
+ { Key::TAB, 0x17 },
+ { Key::Q, 0x18 },
+ { Key::W, 0x19 },
+ { Key::E, 0x1A },
+ { Key::R, 0x1B },
+ { Key::T, 0x1C },
+ { Key::Y, 0x1D },
+ { Key::U, 0x1E },
+ { Key::I, 0x1F },
+ { Key::O, 0x20 },
+ { Key::P, 0x21 },
+ { Key::BRACELEFT, 0x22 },
+ { Key::BRACERIGHT, 0x23 },
+ { Key::ENTER, 0x24 },
+ { Key::CTRL, 0x25 },
+ { Key::A, 0x26 },
+ { Key::S, 0x27 },
+ { Key::D, 0x28 },
+ { Key::F, 0x29 },
+ { Key::G, 0x2A },
+ { Key::H, 0x2B },
+ { Key::J, 0x2C },
+ { Key::K, 0x2D },
+ { Key::L, 0x2E },
+ { Key::SEMICOLON, 0x2F },
+ { Key::APOSTROPHE, 0x30 },
+ { Key::QUOTELEFT, 0x31 },
+ { Key::SHIFT, 0x32 },
+ { Key::BACKSLASH, 0x33 },
+ { Key::Z, 0x34 },
+ { Key::X, 0x35 },
+ { Key::C, 0x36 },
+ { Key::V, 0x37 },
+ { Key::B, 0x38 },
+ { Key::N, 0x39 },
+ { Key::M, 0x3A },
+ { Key::COMMA, 0x3B },
+ { Key::PERIOD, 0x3C },
+ { Key::SLASH, 0x3D },
+ { Key::SHIFT, 0x3E },
+ { Key::KP_MULTIPLY, 0x3F },
+ { Key::ALT, 0x40 },
+ { Key::SPACE, 0x41 },
+ { Key::CAPSLOCK, 0x42 },
+ { Key::F1, 0x43 },
+ { Key::F2, 0x44 },
+ { Key::F3, 0x45 },
+ { Key::F4, 0x46 },
+ { Key::F5, 0x47 },
+ { Key::F6, 0x48 },
+ { Key::F7, 0x49 },
+ { Key::F8, 0x4A },
+ { Key::F9, 0x4B },
+ { Key::F10, 0x4C },
+ { Key::NUMLOCK, 0x4D },
+ { Key::SCROLLLOCK, 0x4E },
+ { Key::KP_7, 0x4F },
+ { Key::KP_8, 0x50 },
+ { Key::KP_9, 0x51 },
+ { Key::KP_SUBTRACT, 0x52 },
+ { Key::KP_4, 0x53 },
+ { Key::KP_5, 0x54 },
+ { Key::KP_6, 0x55 },
+ { Key::KP_ADD, 0x56 },
+ { Key::KP_1, 0x57 },
+ { Key::KP_2, 0x58 },
+ { Key::KP_3, 0x59 },
+ { Key::KP_0, 0x5A },
+ { Key::KP_PERIOD, 0x5B },
+ //{ Key::???, 0x5E }, //NON US BACKSLASH
+ { Key::F11, 0x5F },
+ { Key::F12, 0x60 },
+ { Key::KP_ENTER, 0x68 },
+ { Key::CTRL, 0x69 },
+ { Key::KP_DIVIDE, 0x6A },
+ { Key::PRINT, 0x6B },
+ { Key::ALT, 0x6C },
+ { Key::ENTER, 0x6D },
+ { Key::HOME, 0x6E },
+ { Key::UP, 0x6F },
+ { Key::PAGEUP, 0x70 },
+ { Key::LEFT, 0x71 },
+ { Key::RIGHT, 0x72 },
+ { Key::END, 0x73 },
+ { Key::DOWN, 0x74 },
+ { Key::PAGEDOWN, 0x75 },
+ { Key::INSERT, 0x76 },
+ { Key::KEY_DELETE, 0x77 },
+ { Key::VOLUMEMUTE, 0x79 },
+ { Key::VOLUMEDOWN, 0x7A },
+ { Key::VOLUMEUP, 0x7B },
+ { Key::PAUSE, 0x7F },
+ { Key::SUPER_L, 0x85 },
+ { Key::SUPER_R, 0x86 },
+ { Key::MENU, 0x87 },
+ { Key::UNKNOWN, 0 }
};
-unsigned int KeyMappingX11::get_scancode(unsigned int p_code) {
- unsigned int keycode = KEY_UNKNOWN;
- for (int i = 0; _scancode_to_keycode[i].keysym != KEY_UNKNOWN; i++) {
+Key KeyMappingX11::get_scancode(unsigned int p_code) {
+ Key keycode = Key::UNKNOWN;
+ for (int i = 0; _scancode_to_keycode[i].keysym != Key::UNKNOWN; i++) {
if (_scancode_to_keycode[i].keycode == p_code) {
keycode = _scancode_to_keycode[i].keysym;
break;
@@ -309,9 +309,9 @@ unsigned int KeyMappingX11::get_scancode(unsigned int p_code) {
return keycode;
}
-unsigned int KeyMappingX11::get_xlibcode(unsigned int p_keysym) {
+unsigned int KeyMappingX11::get_xlibcode(Key p_keysym) {
unsigned int code = 0;
- for (int i = 0; _scancode_to_keycode[i].keysym != KEY_UNKNOWN; i++) {
+ for (int i = 0; _scancode_to_keycode[i].keysym != Key::UNKNOWN; i++) {
if (_scancode_to_keycode[i].keysym == p_keysym) {
code = _scancode_to_keycode[i].keycode;
break;
@@ -335,13 +335,13 @@ Key KeyMappingX11::get_keycode(KeySym p_keysym) {
}
}
- return KEY_NONE;
+ return Key::NONE;
}
KeySym KeyMappingX11::get_keysym(Key p_code) {
// kinda bruteforce.. could optimize.
- if (p_code < 0x100) { // Latin 1, maps 1-1
+ if (p_code < Key::END_LATIN1) { // Latin 1, maps 1-1
return (KeySym)p_code;
}
@@ -352,7 +352,7 @@ KeySym KeyMappingX11::get_keysym(Key p_code) {
}
}
- return (KeySym)KEY_NONE;
+ return (KeySym)Key::NONE;
}
/***** UNICODE CONVERSION ******/
diff --git a/platform/linuxbsd/key_mapping_x11.h b/platform/linuxbsd/key_mapping_x11.h
index d4f1554671..5f61197abe 100644
--- a/platform/linuxbsd/key_mapping_x11.h
+++ b/platform/linuxbsd/key_mapping_x11.h
@@ -45,11 +45,11 @@ class KeyMappingX11 {
public:
static Key get_keycode(KeySym p_keysym);
- static unsigned int get_xlibcode(unsigned int p_keysym);
- static unsigned int get_scancode(unsigned int p_code);
+ static unsigned int get_xlibcode(Key p_keysym);
+ static Key get_scancode(unsigned int p_code);
static KeySym get_keysym(Key p_code);
static unsigned int get_unicode_from_keysym(KeySym p_keysym);
static KeySym get_keysym_from_unicode(unsigned int p_unicode);
};
-#endif
+#endif // KEY_MAPPING_X11_H
diff --git a/platform/linuxbsd/platform_config.h b/platform/linuxbsd/platform_config.h
index 3195d08935..aa78b48bb0 100644
--- a/platform/linuxbsd/platform_config.h
+++ b/platform/linuxbsd/platform_config.h
@@ -43,3 +43,5 @@
#define PTHREAD_BSD_SET_NAME
#endif
#endif
+
+#define OPENGL_INCLUDE_H "thirdparty/glad/glad/glad.h"