summaryrefslogtreecommitdiff
path: root/platform/x11
diff options
context:
space:
mode:
Diffstat (limited to 'platform/x11')
-rw-r--r--platform/x11/SCsub8
-rw-r--r--platform/x11/context_gl_x11.cpp76
-rw-r--r--platform/x11/crash_handler_x11.cpp4
-rw-r--r--platform/x11/detect.py18
-rw-r--r--platform/x11/logo.pngbin2061 -> 1679 bytes
-rw-r--r--platform/x11/os_x11.cpp273
-rw-r--r--platform/x11/os_x11.h8
-rw-r--r--platform/x11/platform_x11_builders.py17
8 files changed, 283 insertions, 121 deletions
diff --git a/platform/x11/SCsub b/platform/x11/SCsub
index d0f77892ef..d3901eb798 100644
--- a/platform/x11/SCsub
+++ b/platform/x11/SCsub
@@ -3,10 +3,8 @@
import os
Import('env')
-def make_debug(target, source, env):
- 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]))
+from platform_methods import run_in_subprocess
+import platform_x11_builders
common_x11 = [
"context_gl_x11.cpp",
@@ -20,4 +18,4 @@ common_x11 = [
prog = env.add_program('#bin/godot', ['godot_x11.cpp'] + common_x11)
if (env["debug_symbols"] == "full" or env["debug_symbols"] == "yes") and env["separate_debug_symbols"]:
- env.AddPostAction(prog, make_debug)
+ env.AddPostAction(prog, run_in_subprocess(platform_x11_builders.make_debug_x11))
diff --git a/platform/x11/context_gl_x11.cpp b/platform/x11/context_gl_x11.cpp
index cd76667c64..8c1869a1f1 100644
--- a/platform/x11/context_gl_x11.cpp
+++ b/platform/x11/context_gl_x11.cpp
@@ -65,19 +65,6 @@ void ContextGL_X11::swap_buffers() {
glXSwapBuffers(x11_display, x11_window);
}
-/*
-static GLWrapperFuncPtr wrapper_get_proc_address(const char* p_function) {
-
- //print_line(String()+"getting proc of: "+p_function);
- GLWrapperFuncPtr func=(GLWrapperFuncPtr)glXGetProcAddress( (const GLubyte*) p_function);
- if (!func) {
- print_line("Couldn't find function: "+String(p_function));
- }
-
- return func;
-
-}*/
-
static bool ctxErrorOccurred = false;
static int ctxErrorHandler(Display *dpy, XErrorEvent *ev) {
ctxErrorOccurred = true;
@@ -129,9 +116,14 @@ Error ContextGL_X11::initialize() {
};
int fbcount;
- GLXFBConfig fbconfig;
+ GLXFBConfig fbconfig = 0;
XVisualInfo *vi = NULL;
+ 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);
@@ -155,16 +147,10 @@ Error ContextGL_X11::initialize() {
}
ERR_FAIL_COND_V(!fbconfig, ERR_UNCONFIGURED);
- XSetWindowAttributes swa;
-
- swa.colormap = XCreateColormap(x11_display, RootWindow(x11_display, vi->screen), vi->visual, AllocNone);
- swa.border_pixel = 0;
swa.background_pixmap = None;
swa.background_pixel = 0;
swa.border_pixmap = None;
- swa.event_mask = StructureNotifyMask;
-
- 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, CWBorderPixel | CWColormap | CWEventMask | CWBackPixel, &swa);
+ valuemask |= CWBackPixel;
} else {
GLXFBConfig *fbc = glXChooseFBConfig(x11_display, DefaultScreen(x11_display), visual_attribs, &fbcount);
@@ -173,42 +159,21 @@ Error ContextGL_X11::initialize() {
vi = glXGetVisualFromFBConfig(x11_display, fbc[0]);
fbconfig = fbc[0];
-
- XSetWindowAttributes swa;
-
- swa.colormap = XCreateColormap(x11_display, RootWindow(x11_display, vi->screen), vi->visual, AllocNone);
- swa.border_pixel = 0;
- swa.event_mask = StructureNotifyMask;
-
- 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, CWBorderPixel | CWColormap | CWEventMask, &swa);
}
- ERR_FAIL_COND_V(!x11_window, ERR_UNCONFIGURED);
- set_class_hint(x11_display, x11_window);
- XMapWindow(x11_display, x11_window);
-
- int (*oldHandler)(Display *, XErrorEvent *) =
- XSetErrorHandler(&ctxErrorHandler);
+ int (*oldHandler)(Display *, XErrorEvent *) = XSetErrorHandler(&ctxErrorHandler);
switch (context_type) {
- case GLES_2_0_COMPATIBLE:
case OLDSTYLE: {
+
p->glx_context = glXCreateContext(x11_display, vi, 0, GL_TRUE);
+ ERR_FAIL_COND_V(!p->glx_context, ERR_UNCONFIGURED);
} break;
- /*
- case ContextType::GLES_2_0_COMPATIBLE: {
-
- static int context_attribs[] = {
- GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
- GLX_CONTEXT_MINOR_VERSION_ARB, 0,
- None
- };
+ case GLES_2_0_COMPATIBLE: {
- p->glx_context = glXCreateContextAttribsARB(x11_display, fbconfig, NULL, true, context_attribs);
- ERR_EXPLAIN("Could not obtain an OpenGL 3.0 context!");
+ p->glx_context = glXCreateNewContext(x11_display, fbconfig, GLX_RGBA_TYPE, 0, true);
ERR_FAIL_COND_V(!p->glx_context, ERR_UNCONFIGURED);
} break;
- */
case GLES_3_0_COMPATIBLE: {
static int context_attribs[] = {
@@ -220,24 +185,22 @@ Error ContextGL_X11::initialize() {
};
p->glx_context = glXCreateContextAttribsARB(x11_display, fbconfig, 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;
}
+ 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);
+
+ 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);
- /*
- glWrapperInit(wrapper_get_proc_address);
- glFlush();
-
- glXSwapBuffers(x11_display,x11_window);
-*/
- //glXMakeCurrent(x11_display, None, NULL);
-
XFree(vi);
return OK;
@@ -310,7 +273,6 @@ ContextGL_X11::ContextGL_X11(::Display *p_x11_display, ::Window &p_x11_window, c
ContextGL_X11::~ContextGL_X11() {
release_current();
glXDestroyContext(x11_display, p->glx_context);
-
memdelete(p);
}
diff --git a/platform/x11/crash_handler_x11.cpp b/platform/x11/crash_handler_x11.cpp
index d39fc33f81..960105271b 100644
--- a/platform/x11/crash_handler_x11.cpp
+++ b/platform/x11/crash_handler_x11.cpp
@@ -55,6 +55,10 @@ static void handle_crash(int sig) {
// Dump the backtrace to stderr with a message to the user
fprintf(stderr, "%s: Program crashed with signal %d\n", __FUNCTION__, sig);
+
+ if (OS::get_singleton()->get_main_loop())
+ OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_CRASH);
+
fprintf(stderr, "Dumping the backtrace. %ls\n", msg.c_str());
char **strings = backtrace_symbols(bt_buffer, size);
if (strings) {
diff --git a/platform/x11/detect.py b/platform/x11/detect.py
index 09e16ad078..6a7a426804 100644
--- a/platform/x11/detect.py
+++ b/platform/x11/detect.py
@@ -62,6 +62,7 @@ def get_opts():
EnumVariable('debug_symbols', 'Add debugging symbols to release builds', 'yes', ('yes', 'no', 'full')),
BoolVariable('separate_debug_symbols', 'Create a separate file containing debugging symbols', False),
BoolVariable('touch', 'Enable touch events', True),
+ BoolVariable('execinfo', 'Use libexecinfo on systems where glibc is not available', False),
]
@@ -81,14 +82,22 @@ def configure(env):
if (env["target"] == "release"):
# -O3 -ffast-math is identical to -Ofast. We need to split it out so we can selectively disable
# -ffast-math in code for which it generates wrong results.
- env.Prepend(CCFLAGS=['-O3', '-ffast-math'])
+ if (env["optimize"] == "speed"): #optimize for speed (default)
+ env.Prepend(CCFLAGS=['-O3', '-ffast-math'])
+ else: #optimize for size
+ env.Prepend(CCFLAGS=['-Os'])
+
if (env["debug_symbols"] == "yes"):
env.Prepend(CCFLAGS=['-g1'])
if (env["debug_symbols"] == "full"):
env.Prepend(CCFLAGS=['-g2'])
elif (env["target"] == "release_debug"):
- env.Prepend(CCFLAGS=['-O2', '-ffast-math', '-DDEBUG_ENABLED'])
+ if (env["optimize"] == "speed"): #optimize for speed (default)
+ env.Prepend(CCFLAGS=['-O2', '-ffast-math', '-DDEBUG_ENABLED'])
+ else: #optimize for size
+ env.Prepend(CCFLAGS=['-Os', '-DDEBUG_ENABLED'])
+
if (env["debug_symbols"] == "yes"):
env.Prepend(CCFLAGS=['-g1'])
if (env["debug_symbols"] == "full"):
@@ -240,7 +249,7 @@ def configure(env):
if (os.system("pkg-config --exists alsa") == 0): # 0 means found
print("Enabling ALSA")
- env.Append(CPPFLAGS=["-DALSA_ENABLED"])
+ env.Append(CPPFLAGS=["-DALSA_ENABLED", "-DALSAMIDI_ENABLED"])
env.ParseConfig('pkg-config alsa --cflags --libs')
else:
print("ALSA libraries not found, disabling driver")
@@ -276,6 +285,9 @@ def configure(env):
env.Append(LIBS=['dl'])
if (platform.system().find("BSD") >= 0):
+ env["execinfo"] = True
+
+ if env["execinfo"]:
env.Append(LIBS=['execinfo'])
## Cross-compilation
diff --git a/platform/x11/logo.png b/platform/x11/logo.png
index 1cc93b46ac..078654b757 100644
--- a/platform/x11/logo.png
+++ b/platform/x11/logo.png
Binary files differ
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index 2bc85f76c9..a57a8c6bb9 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -84,6 +84,10 @@ void OS_X11::initialize_core() {
OS_Unix::initialize_core();
}
+int OS_X11::get_current_video_driver() const {
+ return video_driver_index;
+}
+
Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
long im_event_mask = 0;
@@ -166,13 +170,13 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
#ifdef TOUCH_ENABLED
if (!XQueryExtension(x11_display, "XInputExtension", &touch.opcode, &event_base, &error_base)) {
- fprintf(stderr, "XInput extension not available");
+ print_verbose("XInput extension not available, touch support disabled.");
} else {
// 2.2 is the first release with multitouch
int xi_major = 2;
int xi_minor = 2;
if (XIQueryVersion(x11_display, &xi_major, &xi_minor) != Success) {
- fprintf(stderr, "XInput 2.2 not available (server supports %d.%d)\n", xi_major, xi_minor);
+ print_verbose(vformat("XInput 2.2 not available (server supports %d.%d), touch support disabled.", xi_major, xi_minor));
touch.opcode = 0;
} else {
int dev_count;
@@ -194,14 +198,14 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
}
if (direct_touch) {
touch.devices.push_back(dev->deviceid);
- fprintf(stderr, "Using touch device: %s\n", dev->name);
+ print_verbose("XInput: Using touch device: " + String(dev->name));
}
}
XIFreeDeviceInfo(info);
- if (is_stdout_verbose() && !touch.devices.size()) {
- fprintf(stderr, "No touch devices found\n");
+ if (!touch.devices.size()) {
+ print_verbose("XInput: No touch devices found.");
}
}
}
@@ -262,7 +266,6 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
*/
// maybe contextgl wants to be in charge of creating the window
-//print_line("def videomode "+itos(current_videomode.width)+","+itos(current_videomode.height));
#if defined(OPENGL_ENABLED)
ContextGL_X11::ContextType opengl_api_type = ContextGL_X11::GLES_3_0_COMPATIBLE;
@@ -271,20 +274,71 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
opengl_api_type = ContextGL_X11::GLES_2_0_COMPATIBLE;
}
- context_gl = memnew(ContextGL_X11(x11_display, x11_window, current_videomode, opengl_api_type));
- context_gl->initialize();
+ bool editor = Engine::get_singleton()->is_editor_hint();
+ bool gl_initialization_error = false;
- 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 = NULL;
+ while (!context_gl) {
+ context_gl = memnew(ContextGL_X11(x11_display, x11_window, current_videomode, opengl_api_type));
+
+ if (context_gl->initialize() != OK) {
+ memdelete(context_gl);
+ context_gl = NULL;
+
+ if (GLOBAL_GET("rendering/quality/driver/driver_fallback") == "Best" || editor) {
+ if (p_video_driver == VIDEO_DRIVER_GLES2) {
+ gl_initialization_error = true;
+ break;
+ }
+
+ p_video_driver = VIDEO_DRIVER_GLES2;
+ opengl_api_type = ContextGL_X11::GLES_2_0_COMPATIBLE;
+ } else {
+ gl_initialization_error = true;
+ break;
+ }
+ }
}
+ while (true) {
+ if (opengl_api_type == ContextGL_X11::GLES_3_0_COMPATIBLE) {
+ if (RasterizerGLES3::is_viable() == OK) {
+ RasterizerGLES3::register_config();
+ RasterizerGLES3::make_current();
+ break;
+ } else {
+ if (GLOBAL_GET("rendering/quality/driver/driver_fallback") == "Best" || editor) {
+ p_video_driver = VIDEO_DRIVER_GLES2;
+ opengl_api_type = ContextGL_X11::GLES_2_0_COMPATIBLE;
+ continue;
+ } else {
+ gl_initialization_error = true;
+ break;
+ }
+ }
+ }
+
+ if (opengl_api_type == ContextGL_X11::GLES_2_0_COMPATIBLE) {
+ if (RasterizerGLES2::is_viable() == OK) {
+ RasterizerGLES2::register_config();
+ RasterizerGLES2::make_current();
+ break;
+ } else {
+ gl_initialization_error = true;
+ break;
+ }
+ }
+ }
+
+ if (gl_initialization_error) {
+ OS::get_singleton()->alert("Your video card driver does not support any of the supported OpenGL versions.\n"
+ "Please update your drivers or if you have a very old or integrated GPU upgrade it.",
+ "Unable to initialize Video driver");
+ return ERR_UNAVAILABLE;
+ }
+
+ video_driver_index = p_video_driver;
+
context_gl->set_use_vsync(current_videomode.use_vsync);
#endif
@@ -334,8 +388,6 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
set_window_always_on_top(true);
}
- AudioDriverManager::initialize(p_audio_driver);
-
ERR_FAIL_COND_V(!visual_server, ERR_UNAVAILABLE);
ERR_FAIL_COND_V(x11_window == 0, ERR_UNAVAILABLE);
@@ -417,9 +469,7 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
cursor_theme = XcursorGetTheme(x11_display);
if (!cursor_theme) {
- if (is_stdout_verbose()) {
- print_line("XcursorGetTheme could not get cursor theme");
- }
+ print_verbose("XcursorGetTheme could not get cursor theme");
cursor_theme = "default";
}
@@ -432,7 +482,6 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
current_cursor = CURSOR_ARROW;
if (cursor_theme) {
- //print_line("cursor theme: "+String(cursor_theme));
for (int i = 0; i < CURSOR_MAX; i++) {
static const char *cursor_file[] = {
@@ -458,10 +507,8 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
img[i] = XcursorLibraryLoadImage(cursor_file[i], cursor_theme, cursor_size);
if (img[i]) {
cursors[i] = XcursorImageLoadCursor(x11_display, img[i]);
- //print_line("found cursor: "+String(cursor_file[i])+" id "+itos(cursors[i]));
} else {
- if (OS::is_stdout_verbose())
- print_line("failed cursor: " + String(cursor_file[i]));
+ print_verbose("Failed loading custom cursor: " + String(cursor_file[i]));
}
}
}
@@ -510,6 +557,8 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
visual_server->init();
+ AudioDriverManager::initialize(p_audio_driver);
+
input = memnew(InputDefault);
window_has_focus = true; // Set focus to true at init
@@ -600,6 +649,9 @@ void OS_X11::finalize() {
memdelete(debugger_connection_console);
}
*/
+#ifdef ALSAMIDI_ENABLED
+ driver_alsamidi.close();
+#endif
#ifdef JOYDEV_ENABLED
memdelete(joypad);
@@ -1326,7 +1378,7 @@ void OS_X11::request_attention() {
//
// Sets the _NET_WM_STATE_DEMANDS_ATTENTION atom for WM_STATE
// Will be unset by the window manager after user react on the request for attention
- //
+
XEvent xev;
Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False);
Atom wm_attention = XInternAtom(x11_display, "_NET_WM_STATE_DEMANDS_ATTENTION", False);
@@ -1340,6 +1392,7 @@ void OS_X11::request_attention() {
xev.xclient.data.l[1] = wm_attention;
XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
+ XFlush(x11_display);
}
void OS_X11::get_key_modifier_state(unsigned int p_x11_state, Ref<InputEventWithModifiers> state) {
@@ -1502,7 +1555,6 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) {
// KeyMappingX11 also translates keysym to unicode.
// It does a binary search on a table to translate
// most properly.
- //print_line("keysym_unicode: "+rtos(keysym_unicode));
unsigned int unicode = keysym_unicode > 0 ? KeyMappingX11::get_unicode_from_keysym(keysym_unicode) : 0;
/* Phase 4, determine if event must be filtered */
@@ -1525,7 +1577,7 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) {
// know Mod1 was ALT and Mod4 was META (applekey/winkey)
// just tried Mods until i found them.
- //print_line("mod1: "+itos(xkeyevent->state&Mod1Mask)+" mod 5: "+itos(xkeyevent->state&Mod5Mask));
+ //print_verbose("mod1: "+itos(xkeyevent->state&Mod1Mask)+" mod 5: "+itos(xkeyevent->state&Mod5Mask));
Ref<InputEventKey> k;
k.instance();
@@ -1825,8 +1877,8 @@ void OS_X11::process_xevents() {
GrabModeAsync, GrabModeAsync, x11_window, None, CurrentTime);
}
#ifdef TOUCH_ENABLED
- // Grab touch devices to avoid OS gesture interference
- /*for (int i = 0; i < touch.devices.size(); ++i) {
+ // Grab touch devices to avoid OS gesture interference
+ /*for (int i = 0; i < touch.devices.size(); ++i) {
XIGrabDevice(x11_display, touch.devices[i], x11_window, CurrentTime, None, XIGrabModeAsync, XIGrabModeAsync, False, &touch.event_mask);
}*/
#endif
@@ -2092,7 +2144,7 @@ void OS_X11::process_xevents() {
Vector<String> files = String((char *)p.data).split("\n", false);
for (int i = 0; i < files.size(); i++) {
- files[i] = files[i].replace("file://", "").replace("%20", " ").strip_escapes();
+ files.write[i] = files[i].replace("file://", "").replace("%20", " ").strip_escapes();
}
main_loop->drop_files(files);
@@ -2330,7 +2382,7 @@ Error OS_X11::shell_open(String p_uri) {
bool OS_X11::_check_internal_feature_support(const String &p_feature) {
- return p_feature == "pc" || p_feature == "s3tc";
+ return p_feature == "pc" || p_feature == "s3tc" || p_feature == "bptc";
}
String OS_X11::get_config_path() const {
@@ -2423,7 +2475,19 @@ String OS_X11::get_system_dir(SystemDir p_dir) const {
void OS_X11::move_window_to_foreground() {
- XRaiseWindow(x11_display, x11_window);
+ XEvent xev;
+ Atom net_active_window = XInternAtom(x11_display, "_NET_ACTIVE_WINDOW", False);
+
+ memset(&xev, 0, sizeof(xev));
+ xev.type = ClientMessage;
+ xev.xclient.window = x11_window;
+ xev.xclient.message_type = net_active_window;
+ xev.xclient.format = 32;
+ xev.xclient.data.l[0] = 1;
+ xev.xclient.data.l[1] = CurrentTime;
+
+ XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
+ XFlush(x11_display);
}
void OS_X11::set_cursor_shape(CursorShape p_shape) {
@@ -2470,7 +2534,9 @@ void OS_X11::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
}
ERR_FAIL_COND(!texture.is_valid());
+ ERR_FAIL_COND(p_hotspot.x < 0 || p_hotspot.y < 0);
ERR_FAIL_COND(texture_size.width > 256 || texture_size.height > 256);
+ ERR_FAIL_COND(p_hotspot.x > texture_size.width || p_hotspot.y > texture_size.height);
image = texture->get_data();
@@ -2549,51 +2615,146 @@ void OS_X11::swap_buffers() {
}
void OS_X11::alert(const String &p_alert, const String &p_title) {
+ const char *message_programs[] = { "zenity", "kdialog", "Xdialog", "xmessage" };
+
+ String path = get_environment("PATH");
+ Vector<String> path_elems = path.split(":", false);
+ String program;
+
+ for (int i = 0; i < path_elems.size(); i++) {
+ for (unsigned int k = 0; k < sizeof(message_programs) / sizeof(char *); k++) {
+ String tested_path = path_elems[i] + "/" + message_programs[k];
+
+ if (FileAccess::exists(tested_path)) {
+ program = tested_path;
+ break;
+ }
+ }
+
+ if (program.length())
+ break;
+ }
List<String> args;
- args.push_back("-center");
- args.push_back("-title");
- args.push_back(p_title);
- args.push_back(p_alert);
- execute("xmessage", args, true);
+ if (program.ends_with("zenity")) {
+ args.push_back("--error");
+ args.push_back("--width");
+ args.push_back("500");
+ args.push_back("--title");
+ args.push_back(p_title);
+ args.push_back("--text");
+ args.push_back(p_alert);
+ }
+
+ if (program.ends_with("kdialog")) {
+ args.push_back("--error");
+ args.push_back(p_alert);
+ args.push_back("--title");
+ args.push_back(p_title);
+ }
+
+ if (program.ends_with("Xdialog")) {
+ args.push_back("--title");
+ args.push_back(p_title);
+ args.push_back("--msgbox");
+ args.push_back(p_alert);
+ args.push_back("0");
+ args.push_back("0");
+ }
+
+ if (program.ends_with("xmessage")) {
+ args.push_back("-center");
+ args.push_back("-title");
+ args.push_back(p_title);
+ args.push_back(p_alert);
+ }
+
+ if (program.length()) {
+ execute(program, args, true);
+ } else {
+ print_line(p_alert);
+ }
+
+ return;
+}
+
+bool g_set_icon_error = false;
+int set_icon_errorhandler(Display *dpy, XErrorEvent *ev) {
+ g_set_icon_error = true;
+ return 0;
}
void OS_X11::set_icon(const Ref<Image> &p_icon) {
+ int (*oldHandler)(Display *, XErrorEvent *) = XSetErrorHandler(&set_icon_errorhandler);
+
Atom net_wm_icon = XInternAtom(x11_display, "_NET_WM_ICON", False);
if (p_icon.is_valid()) {
Ref<Image> img = p_icon->duplicate();
img->convert(Image::FORMAT_RGBA8);
- int w = img->get_width();
- int h = img->get_height();
+ while (true) {
+ int w = img->get_width();
+ int h = img->get_height();
- // We're using long to have wordsize (32Bit build -> 32 Bits, 64 Bit build -> 64 Bits
- Vector<long> pd;
+ if (g_set_icon_error) {
+ g_set_icon_error = false;
- pd.resize(2 + w * h);
+ WARN_PRINT("Icon too large, attempting to resize icon.");
- pd[0] = w;
- pd[1] = h;
+ int new_width, new_height;
+ if (w > h) {
+ new_width = w / 2;
+ new_height = h * new_width / w;
+ } else {
+ new_height = h / 2;
+ new_width = w * new_height / h;
+ }
- PoolVector<uint8_t>::Read r = img->get_data().read();
+ w = new_width;
+ h = new_height;
- long *wr = &pd[2];
- uint8_t const *pr = r.ptr();
+ if (!w || !h) {
+ WARN_PRINT("Unable to set icon.");
+ break;
+ }
- for (int i = 0; i < w * h; i++) {
- long v = 0;
- // A R G B
- v |= pr[3] << 24 | pr[0] << 16 | pr[1] << 8 | pr[2];
- *wr++ = v;
- pr += 4;
+ img->resize(w, h, Image::INTERPOLATE_CUBIC);
+ }
+
+ // We're using long to have wordsize (32Bit build -> 32 Bits, 64 Bit build -> 64 Bits
+ Vector<long> pd;
+
+ pd.resize(2 + w * h);
+
+ pd.write[0] = w;
+ pd.write[1] = h;
+
+ PoolVector<uint8_t>::Read r = img->get_data().read();
+
+ long *wr = &pd.write[2];
+ uint8_t const *pr = r.ptr();
+
+ for (int i = 0; i < w * h; i++) {
+ long v = 0;
+ // A R G B
+ v |= pr[3] << 24 | pr[0] << 16 | pr[1] << 8 | pr[2];
+ *wr++ = v;
+ pr += 4;
+ }
+
+ XChangeProperty(x11_display, x11_window, net_wm_icon, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)pd.ptr(), pd.size());
+
+ if (!g_set_icon_error)
+ break;
}
- XChangeProperty(x11_display, x11_window, net_wm_icon, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)pd.ptr(), pd.size());
} else {
XDeleteProperty(x11_display, x11_window, net_wm_icon);
}
+
XFlush(x11_display);
+ XSetErrorHandler(oldHandler);
}
void OS_X11::force_process_input() {
diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h
index 8cab23fe63..44455a2d8d 100644
--- a/platform/x11/os_x11.h
+++ b/platform/x11/os_x11.h
@@ -38,6 +38,7 @@
#include "servers/visual_server.h"
//#include "servers/visual/visual_server_wrap_mt.h"
#include "drivers/alsa/audio_driver_alsa.h"
+#include "drivers/alsamidi/alsa_midi.h"
#include "drivers/pulseaudio/audio_driver_pulseaudio.h"
#include "joypad_linux.h"
#include "main/input_default.h"
@@ -168,6 +169,10 @@ class OS_X11 : public OS_Unix {
AudioDriverALSA driver_alsa;
#endif
+#ifdef ALSAMIDI_ENABLED
+ MIDIDriverALSAMidi driver_alsamidi;
+#endif
+
#ifdef PULSEAUDIO_ENABLED
AudioDriverPulseAudio driver_pulseaudio;
#endif
@@ -180,6 +185,7 @@ class OS_X11 : public OS_Unix {
CrashHandler crash_handler;
+ int video_driver_index;
int audio_driver_index;
unsigned int capture_idle;
bool maximized;
@@ -195,6 +201,8 @@ class OS_X11 : public OS_Unix {
Bool xrandr_ext_ok;
protected:
+ virtual int get_current_video_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_x11_builders.py b/platform/x11/platform_x11_builders.py
new file mode 100644
index 0000000000..5ff0c6fb14
--- /dev/null
+++ b/platform/x11/platform_x11_builders.py
@@ -0,0 +1,17 @@
+"""Functions used to generate source files during build time
+
+All such functions are invoked in a subprocess on Windows to prevent build flakiness.
+
+"""
+import os
+from platform_methods import subprocess_main
+
+
+def make_debug_x11(target, source, env):
+ 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]))
+
+
+if __name__ == '__main__':
+ subprocess_main(globals())