[x11] Clamp barriers to the screen

It seems X11 does not like creating barriers entirely off the screen,
though the error seems to be a little unreliable (however, off the left
edge was definitely bad).
This commit is contained in:
Bill Currie 2021-11-25 20:01:13 +09:00
parent d1153be594
commit b01c38903d
3 changed files with 10 additions and 4 deletions

View File

@ -52,6 +52,8 @@ extern Window x_win;
extern Colormap x_cmap; extern Colormap x_cmap;
extern XVisualInfo *x_visinfo; extern XVisualInfo *x_visinfo;
extern int x_screen; extern int x_screen;
extern int x_width;
extern int x_height;
extern int x_shmeventtype; extern int x_shmeventtype;
extern Time x_time; extern Time x_time;
extern Time x_mouse_time; extern Time x_mouse_time;

View File

@ -82,6 +82,8 @@ static Cursor nullcursor = None;
Display *x_disp = NULL; Display *x_disp = NULL;
int x_screen; int x_screen;
int x_width;
int x_height;
Window x_root = None; Window x_root = None;
XVisualInfo *x_visinfo; XVisualInfo *x_visinfo;
Visual *x_vis; Visual *x_vis;
@ -283,6 +285,8 @@ X11_OpenDisplay (void)
False); False);
x_screen = DefaultScreen (x_disp); x_screen = DefaultScreen (x_disp);
x_width = DisplayWidth (x_disp, x_screen);
x_height = DisplayHeight (x_disp, x_screen);
x_root = RootWindow (x_disp, x_screen); x_root = RootWindow (x_disp, x_screen);
XSynchronize (x_disp, true); // only for debugging XSynchronize (x_disp, true); // only for debugging

View File

@ -1415,10 +1415,10 @@ in_x11_setup_barriers (int xpos, int ypos, int xlen, int ylen)
XFixesDestroyPointerBarrier (x_disp, x11_bottom_barrier); XFixesDestroyPointerBarrier (x_disp, x11_bottom_barrier);
} }
int lx = xpos; int lx = bound (0, xpos, x_width - 1);
int ty = ypos; int ty = bound (0, ypos, x_height - 1);
int rx = xpos + xlen - 1; int rx = bound (0, xpos + xlen - 1, x_width - 1);
int by = ypos + ylen - 1; int by = bound (0, ypos + ylen - 1, x_height - 1);
x11_left_barrier = XFixesCreatePointerBarrier (x_disp, x_root, x11_left_barrier = XFixesCreatePointerBarrier (x_disp, x_root,
lx, ty-1, lx, by+1, lx, ty-1, lx, by+1,
BarrierPositiveX, 0, 0); BarrierPositiveX, 0, 0);