Implemented SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH on X11

This commit is contained in:
Sam Lantinga 2016-09-29 16:05:29 -07:00
parent d285af2a96
commit 67bdbcca44
2 changed files with 25 additions and 5 deletions

View File

@ -35,6 +35,7 @@
#include "../../events/SDL_mouse_c.h" #include "../../events/SDL_mouse_c.h"
#include "../../events/SDL_touch_c.h" #include "../../events/SDL_touch_c.h"
#include "SDL_hints.h"
#include "SDL_timer.h" #include "SDL_timer.h"
#include "SDL_syswm.h" #include "SDL_syswm.h"
@ -523,9 +524,9 @@ X11_UpdateUserTime(SDL_WindowData *data, const unsigned long latest)
X11_XChangeProperty(display, data->xwindow, videodata->_NET_WM_USER_TIME, X11_XChangeProperty(display, data->xwindow, videodata->_NET_WM_USER_TIME,
XA_CARDINAL, 32, PropModeReplace, XA_CARDINAL, 32, PropModeReplace,
(const unsigned char *) &latest, 1); (const unsigned char *) &latest, 1);
#if DEBUG_XEVENTS #ifdef DEBUG_XEVENTS
printf("window %p: updating _NET_WM_USER_TIME to %lu\n", data, latest); printf("window %p: updating _NET_WM_USER_TIME to %lu\n", data, latest);
#endif #endif
data->user_time = latest; data->user_time = latest;
} }
} }
@ -711,6 +712,7 @@ X11_DispatchEvent(_THIS)
data->pending_focus = PENDING_FOCUS_IN; data->pending_focus = PENDING_FOCUS_IN;
data->pending_focus_time = SDL_GetTicks() + PENDING_FOCUS_TIME; data->pending_focus_time = SDL_GetTicks() + PENDING_FOCUS_TIME;
} }
data->last_focus_event_time = SDL_GetTicks();
} }
break; break;
@ -987,7 +989,7 @@ X11_DispatchEvent(_THIS)
SDL_Mouse *mouse = SDL_GetMouse(); SDL_Mouse *mouse = SDL_GetMouse();
if(!mouse->relative_mode || mouse->relative_mode_warp) { if(!mouse->relative_mode || mouse->relative_mode_warp) {
#ifdef DEBUG_MOTION #ifdef DEBUG_MOTION
printf("window %p: X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y); printf("window %p: X11 motion: %d,%d\n", data, xevent.xmotion.x, xevent.xmotion.y);
#endif #endif
SDL_SendMouseMotion(data->window, 0, 0, xevent.xmotion.x, xevent.xmotion.y); SDL_SendMouseMotion(data->window, 0, 0, xevent.xmotion.x, xevent.xmotion.y);
@ -997,9 +999,13 @@ X11_DispatchEvent(_THIS)
case ButtonPress:{ case ButtonPress:{
int xticks = 0, yticks = 0; int xticks = 0, yticks = 0;
#ifdef DEBUG_XEVENTS
printf("window %p: ButtonPress (X11 button = %d)\n", data, xevent.xbutton.button);
#endif
if (X11_IsWheelEvent(display,&xevent,&xticks, &yticks)) { if (X11_IsWheelEvent(display,&xevent,&xticks, &yticks)) {
SDL_SendMouseWheel(data->window, 0, xticks, yticks, SDL_MOUSEWHEEL_NORMAL); SDL_SendMouseWheel(data->window, 0, xticks, yticks, SDL_MOUSEWHEEL_NORMAL);
} else { } else {
SDL_bool ignore_click = SDL_FALSE;
int button = xevent.xbutton.button; int button = xevent.xbutton.button;
if(button == Button1) { if(button == Button1) {
if (ProcessHitTest(_this, data, &xevent)) { if (ProcessHitTest(_this, data, &xevent)) {
@ -1012,8 +1018,18 @@ X11_DispatchEvent(_THIS)
=> subtract (8-SDL_BUTTON_X1) to get value SDL expects */ => subtract (8-SDL_BUTTON_X1) to get value SDL expects */
button -= (8-SDL_BUTTON_X1); button -= (8-SDL_BUTTON_X1);
} }
if (data->last_focus_event_time) {
const int X11_FOCUS_CLICK_TIMEOUT = 10;
if (!SDL_TICKS_PASSED(SDL_GetTicks(), data->last_focus_event_time + X11_FOCUS_CLICK_TIMEOUT)) {
const char *hint = SDL_GetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH);
ignore_click = (!hint || *hint == '0');
}
data->last_focus_event_time = 0;
}
if (!ignore_click) {
SDL_SendMouseButton(data->window, 0, SDL_PRESSED, button); SDL_SendMouseButton(data->window, 0, SDL_PRESSED, button);
} }
}
X11_UpdateUserTime(data, xevent.xbutton.time); X11_UpdateUserTime(data, xevent.xbutton.time);
} }
break; break;
@ -1022,7 +1038,10 @@ X11_DispatchEvent(_THIS)
int button = xevent.xbutton.button; int button = xevent.xbutton.button;
/* The X server sends a Release event for each Press for wheels. Ignore them. */ /* The X server sends a Release event for each Press for wheels. Ignore them. */
int xticks = 0, yticks = 0; int xticks = 0, yticks = 0;
if (!X11_IsWheelEvent(display,&xevent,&xticks, &yticks)) { #ifdef DEBUG_XEVENTS
printf("window %p: ButtonRelease (X11 button = %d)\n", data, xevent.xbutton.button);
#endif
if (!X11_IsWheelEvent(display, &xevent, &xticks, &yticks)) {
if (button > 7) { if (button > 7) {
/* see explanation at case ButtonPress */ /* see explanation at case ButtonPress */
button -= (8-SDL_BUTTON_X1); button -= (8-SDL_BUTTON_X1);

View File

@ -60,6 +60,7 @@ typedef struct
int border_right; int border_right;
int border_top; int border_top;
int border_bottom; int border_bottom;
Uint32 last_focus_event_time;
PendingFocusEnum pending_focus; PendingFocusEnum pending_focus;
Uint32 pending_focus_time; Uint32 pending_focus_time;
XConfigureEvent last_xconfigure; XConfigureEvent last_xconfigure;