summaryrefslogtreecommitdiff
path: root/platform/x11
diff options
context:
space:
mode:
Diffstat (limited to 'platform/x11')
-rw-r--r--platform/x11/detect.py25
-rw-r--r--platform/x11/export/export.cpp3
-rw-r--r--platform/x11/os_x11.cpp96
-rw-r--r--platform/x11/os_x11.h2
4 files changed, 87 insertions, 39 deletions
diff --git a/platform/x11/detect.py b/platform/x11/detect.py
index b5f6359d21..89cf639114 100644
--- a/platform/x11/detect.py
+++ b/platform/x11/detect.py
@@ -61,6 +61,7 @@ def get_opts():
('use_static_cpp', 'link stdc++ statically', 'no'),
('use_sanitizer', 'Use llvm compiler sanitize address', 'no'),
('use_leak_sanitizer', 'Use llvm compiler sanitize memory leaks', 'no'),
+ ('use_lto', 'Use link time optimization', 'no'),
('pulseaudio', 'Detect & Use pulseaudio', 'yes'),
('udev', 'Use udev for gamepad connection callbacks', 'no'),
('debug_release', 'Add debug symbols to release version', 'no'),
@@ -97,12 +98,12 @@ def configure(env):
env.extra_suffix = ".llvm"
if (env["use_sanitizer"] == "yes"):
- env.Append(CXXFLAGS=['-fsanitize=address', '-fno-omit-frame-pointer'])
+ env.Append(CCFLAGS=['-fsanitize=address', '-fno-omit-frame-pointer'])
env.Append(LINKFLAGS=['-fsanitize=address'])
env.extra_suffix += "s"
if (env["use_leak_sanitizer"] == "yes"):
- env.Append(CXXFLAGS=['-fsanitize=address', '-fno-omit-frame-pointer'])
+ env.Append(CCFLAGS=['-fsanitize=address', '-fno-omit-frame-pointer'])
env.Append(LINKFLAGS=['-fsanitize=address'])
env.extra_suffix += "s"
@@ -111,22 +112,28 @@ def configure(env):
# env['OBJSUFFIX'] = ".nt"+env['OBJSUFFIX']
# env['LIBSUFFIX'] = ".nt"+env['LIBSUFFIX']
- if (env["target"] == "release"):
+ if (env["use_lto"] == "yes"):
+ env.Append(CCFLAGS=['-flto'])
+ env.Append(LINKFLAGS=['-flto'])
+
+
+ env.Append(CCFLAGS=['-pipe'])
+ env.Append(LINKFLAGS=['-pipe'])
+ if (env["target"] == "release"):
+ env.Prepend(CCFLAGS=['-Ofast'])
if (env["debug_release"] == "yes"):
- env.Append(CCFLAGS=['-g2'])
- else:
- env.Append(CCFLAGS=['-O3', '-ffast-math'])
+ env.Prepend(CCFLAGS=['-g2'])
elif (env["target"] == "release_debug"):
- env.Append(CCFLAGS=['-O2', '-ffast-math', '-DDEBUG_ENABLED'])
+ env.Prepend(CCFLAGS=['-O2', '-ffast-math', '-DDEBUG_ENABLED'])
if (env["debug_release"] == "yes"):
- env.Append(CCFLAGS=['-g2'])
+ env.Prepend(CCFLAGS=['-g2'])
elif (env["target"] == "debug"):
- env.Append(CCFLAGS=['-g2', '-Wall', '-DDEBUG_ENABLED', '-DDEBUG_MEMORY_ENABLED'])
+ env.Prepend(CCFLAGS=['-g2', '-Wall', '-DDEBUG_ENABLED', '-DDEBUG_MEMORY_ENABLED'])
env.ParseConfig('pkg-config x11 --cflags --libs')
env.ParseConfig('pkg-config xinerama --cflags --libs')
diff --git a/platform/x11/export/export.cpp b/platform/x11/export/export.cpp
index c1af323453..5a4751b387 100644
--- a/platform/x11/export/export.cpp
+++ b/platform/x11/export/export.cpp
@@ -30,7 +30,7 @@
#include "platform/x11/logo.h"
#include "tools/editor/editor_import_export.h"
#include "scene/resources/texture.h"
-
+#if 0
void register_x11_exporter() {
Image img(_x11_logo);
@@ -50,3 +50,4 @@ void register_x11_exporter() {
}
}
+#endif
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index 41746c2431..e792d0465e 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -295,6 +295,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
}
+
ERR_FAIL_COND(!visual_server);
ERR_FAIL_COND(x11_window==0);
@@ -449,6 +450,8 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
physics_2d_server->init();
input = memnew( InputDefault );
+
+ window_has_focus = true; // Set focus to true at init
#ifdef JOYDEV_ENABLED
joypad = memnew( JoypadLinux(input));
#endif
@@ -517,17 +520,21 @@ void OS_X11::set_mouse_mode(MouseMode p_mode) {
if (p_mode==mouse_mode)
return;
- if (mouse_mode==MOUSE_MODE_CAPTURED)
+ if (mouse_mode==MOUSE_MODE_CAPTURED || mouse_mode==MOUSE_MODE_CONFINED)
XUngrabPointer(x11_display, CurrentTime);
- if (mouse_mode!=MOUSE_MODE_VISIBLE && p_mode==MOUSE_MODE_VISIBLE)
- XUndefineCursor(x11_display,x11_window);
- if (p_mode!=MOUSE_MODE_VISIBLE && mouse_mode==MOUSE_MODE_VISIBLE) {
- XDefineCursor(x11_display,x11_window,null_cursor);
+
+ // The only modes that show a cursor are VISIBLE and CONFINED
+ bool showCursor = (p_mode == MOUSE_MODE_VISIBLE || p_mode == MOUSE_MODE_CONFINED);
+
+ if (showCursor) {
+ XUndefineCursor(x11_display,x11_window); // show cursor
+ } else {
+ XDefineCursor(x11_display,x11_window,null_cursor); // hide cursor
}
mouse_mode=p_mode;
- if (mouse_mode==MOUSE_MODE_CAPTURED) {
+ if (mouse_mode==MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED) {
while(true) {
//flush pending motion events
@@ -768,13 +775,31 @@ void OS_X11::set_window_position(const Point2& p_position) {
}
Size2 OS_X11::get_window_size() const {
- XWindowAttributes xwa;
- XGetWindowAttributes(x11_display, x11_window, &xwa);
- return Size2i(xwa.width, xwa.height);
+ // Use current_videomode width and height instead of XGetWindowAttributes
+ // since right after a XResizeWindow the attributes may not be updated yet
+ return Size2i(current_videomode.width, current_videomode.height);
}
void OS_X11::set_window_size(const Size2 p_size) {
+ // If window resizable is disabled we need to update the attributes first
+ if (is_window_resizable() == false) {
+ XSizeHints *xsh;
+ xsh = XAllocSizeHints();
+ xsh->flags = PMinSize | PMaxSize;
+ xsh->min_width = p_size.x;
+ xsh->max_width = p_size.x;
+ xsh->min_height = p_size.y;
+ xsh->max_height = p_size.y;
+ XSetWMNormalHints(x11_display, x11_window, xsh);
+ XFree(xsh);
+ }
+
+ // Resize the window
XResizeWindow(x11_display, x11_window, p_size.x, p_size.y);
+
+ // Update our videomode width and height
+ current_videomode.width = p_size.x;
+ current_videomode.height = p_size.y;
}
void OS_X11::set_window_fullscreen(bool p_enabled) {
@@ -788,15 +813,15 @@ bool OS_X11::is_window_fullscreen() const {
void OS_X11::set_window_resizable(bool p_enabled) {
XSizeHints *xsh;
+ Size2 size = get_window_size();
+
xsh = XAllocSizeHints();
xsh->flags = p_enabled ? 0L : PMinSize | PMaxSize;
if(!p_enabled) {
- XWindowAttributes xwa;
- XGetWindowAttributes(x11_display,x11_window,&xwa);
- xsh->min_width = xwa.width;
- xsh->max_width = xwa.width;
- xsh->min_height = xwa.height;
- xsh->max_height = xwa.height;
+ xsh->min_width = size.x;
+ xsh->max_width = size.x;
+ xsh->min_height = size.y;
+ xsh->max_height = size.y;
}
XSetWMNormalHints(x11_display, x11_window, xsh);
XFree(xsh);
@@ -1253,6 +1278,10 @@ void OS_X11::process_xevents() {
do_mouse_warp=false;
+
+ // Is the current mouse mode one where it needs to be grabbed.
+ bool mouse_mode_grab = mouse_mode==MOUSE_MODE_CAPTURED || mouse_mode==MOUSE_MODE_CONFINED;
+
while (XPending(x11_display) > 0) {
XEvent event;
XNextEvent(x11_display, &event);
@@ -1271,35 +1300,45 @@ void OS_X11::process_xevents() {
minimized = (visibility->state == VisibilityFullyObscured);
} break;
case LeaveNotify: {
-
- if (main_loop && mouse_mode!=MOUSE_MODE_CAPTURED)
+ if (main_loop && !mouse_mode_grab)
main_loop->notification(MainLoop::NOTIFICATION_WM_MOUSE_EXIT);
if (input)
input->set_mouse_in_window(false);
} break;
case EnterNotify: {
-
- if (main_loop && mouse_mode!=MOUSE_MODE_CAPTURED)
+ if (main_loop && !mouse_mode_grab)
main_loop->notification(MainLoop::NOTIFICATION_WM_MOUSE_ENTER);
if (input)
input->set_mouse_in_window(true);
} break;
case FocusIn:
minimized = false;
+ window_has_focus = true;
main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN);
- if (mouse_mode==MOUSE_MODE_CAPTURED) {
+ if (mouse_mode_grab) {
+ // Show and update the cursor if confined and the window regained focus.
+ if (mouse_mode==MOUSE_MODE_CONFINED)
+ XUndefineCursor(x11_display, x11_window);
+ else if (mouse_mode==MOUSE_MODE_CAPTURED) // or re-hide it in captured mode
+ XDefineCursor(x11_display, x11_window, null_cursor);
+
XGrabPointer(
- x11_display, x11_window, True,
+ x11_display, x11_window, True,
ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
GrabModeAsync, GrabModeAsync, x11_window, None, CurrentTime);
}
break;
case FocusOut:
+ window_has_focus = false;
main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT);
- if (mouse_mode==MOUSE_MODE_CAPTURED) {
+ if (mouse_mode_grab) {
//dear X11, I try, I really try, but you never work, you do whathever you want.
+ if (mouse_mode==MOUSE_MODE_CAPTURED) {
+ // Show the cursor if we're in captured mode so it doesn't look weird.
+ XUndefineCursor(x11_display, x11_window);
+ }
XUngrabPointer(x11_display, CurrentTime);
}
break;
@@ -1319,7 +1358,7 @@ void OS_X11::process_xevents() {
/* exit in case of a mouse button press */
last_timestamp=event.xbutton.time;
- if (mouse_mode==MOUSE_MODE_CAPTURED) {
+ if (mouse_mode == MOUSE_MODE_CAPTURED) {
event.xbutton.x=last_mouse_pos.x;
event.xbutton.y=last_mouse_pos.y;
}
@@ -1342,7 +1381,6 @@ void OS_X11::process_xevents() {
mouse_event.mouse_button.pressed=(event.type==ButtonPress);
-
if (event.type==ButtonPress && event.xbutton.button==1) {
uint64_t diff = get_ticks_usec()/1000 - last_click_ms;
@@ -1376,7 +1414,6 @@ void OS_X11::process_xevents() {
// PLEASE DO ME A FAVOR AND DIE DROWNED IN A FECAL
// MOUNTAIN BECAUSE THAT'S WHERE YOU BELONG.
-
while(true) {
if (mouse_mode==MOUSE_MODE_CAPTURED && event.xmotion.x==current_videomode.width/2 && event.xmotion.y==current_videomode.height/2) {
//this is likely the warp event since it was warped here
@@ -1418,7 +1455,7 @@ void OS_X11::process_xevents() {
Point2i new_center = pos;
pos = last_mouse_pos + ( pos - center );
center=new_center;
- do_mouse_warp=true;
+ do_mouse_warp=window_has_focus; // warp the cursor if we're focused in
#else
//Dear X11, thanks for making my life miserable
@@ -1461,8 +1498,11 @@ void OS_X11::process_xevents() {
last_mouse_pos=pos;
// printf("rel: %d,%d\n", rel.x, rel.y );
-
- input->parse_input_event( motion_event);
+ // Don't propagate the motion event unless we have focus
+ // this is so that the relative motion doesn't get messed up
+ // after we regain focus.
+ if (window_has_focus || !mouse_mode_grab)
+ input->parse_input_event( motion_event);
} break;
case KeyPress:
diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h
index 3245df32c6..3ec358f103 100644
--- a/platform/x11/os_x11.h
+++ b/platform/x11/os_x11.h
@@ -134,7 +134,7 @@ class OS_X11 : public OS_Unix {
bool force_quit;
bool minimized;
-
+ bool window_has_focus;
bool do_mouse_warp;
const char *cursor_theme;