From 91b1889873781b39fe148930f9d5b8cd1a68affc Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 3 Oct 2016 06:50:00 +0200 Subject: [PATCH] (X11) Mouse input is no longer registered when we are on the titlebar of the window or we are no longer inside the window --- gfx/common/x11_common.c | 9 +++++++ gfx/drivers_context/x_ctx.c | 1 + input/drivers/x11_input.c | 47 ++++++++++++++++++++----------------- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/gfx/common/x11_common.c b/gfx/common/x11_common.c index a950629460..41bc6ac077 100644 --- a/gfx/common/x11_common.c +++ b/gfx/common/x11_common.c @@ -56,6 +56,7 @@ static bool g_x11_has_focus; static XIM g_x11_xim; static XIC g_x11_xic; static bool g_x11_true_full; +bool g_x11_entered = false; unsigned g_x11_screen; @@ -647,6 +648,14 @@ bool x11_alive(void *data) } break; + case EnterNotify: + g_x11_entered = true; + break; + + case LeaveNotify: + g_x11_entered = false; + break; + case ButtonRelease: break; diff --git a/gfx/drivers_context/x_ctx.c b/gfx/drivers_context/x_ctx.c index 30ad512fda..a2a65c3a5a 100644 --- a/gfx/drivers_context/x_ctx.c +++ b/gfx/drivers_context/x_ctx.c @@ -481,6 +481,7 @@ static bool gfx_ctx_x_set_video_mode(void *data, swa.colormap = g_x11_cmap = XCreateColormap(g_x11_dpy, RootWindow(g_x11_dpy, vi->screen), vi->visual, AllocNone); swa.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask | + LeaveWindowMask | EnterWindowMask | ButtonReleaseMask | ButtonPressMask; swa.override_redirect = fullscreen ? True : False; diff --git a/input/drivers/x11_input.c b/input/drivers/x11_input.c index 78b185ceb2..73ceb6aac1 100644 --- a/input/drivers/x11_input.c +++ b/input/drivers/x11_input.c @@ -300,6 +300,8 @@ static void x_input_free(void *data) free(x11); } +extern bool g_x11_entered; + static void x_input_poll_mouse(x11_input_t *x11) { unsigned mask; @@ -316,31 +318,34 @@ static void x_input_poll_mouse(x11_input_t *x11) &win_x, &win_y, &mask); - x11->mouse_x = win_x; - x11->mouse_y = win_y; - x11->mouse_l = mask & Button1Mask; - x11->mouse_m = mask & Button2Mask; - x11->mouse_r = mask & Button3Mask; - - /* Somewhat hacky, but seem to do the job. */ - if (x11->grab_mouse && video_driver_is_focused()) + if (g_x11_entered) { - int mid_w, mid_h; - struct video_viewport vp = {0}; + x11->mouse_x = win_x; + x11->mouse_y = win_y; + x11->mouse_l = mask & Button1Mask; + x11->mouse_m = mask & Button2Mask; + x11->mouse_r = mask & Button3Mask; - video_driver_get_viewport_info(&vp); - - mid_w = vp.full_width >> 1; - mid_h = vp.full_height >> 1; - - if (x11->mouse_x != mid_w || x11->mouse_y != mid_h) + /* Somewhat hacky, but seem to do the job. */ + if (x11->grab_mouse && video_driver_is_focused()) { - XWarpPointer(x11->display, None, - x11->win, 0, 0, 0, 0, - mid_w, mid_h); + int mid_w, mid_h; + struct video_viewport vp = {0}; + + video_driver_get_viewport_info(&vp); + + mid_w = vp.full_width >> 1; + mid_h = vp.full_height >> 1; + + if (x11->mouse_x != mid_w || x11->mouse_y != mid_h) + { + XWarpPointer(x11->display, None, + x11->win, 0, 0, 0, 0, + mid_w, mid_h); + } + x11->mouse_last_x = mid_w; + x11->mouse_last_y = mid_h; } - x11->mouse_last_x = mid_w; - x11->mouse_last_y = mid_h; } }