From 6d2c0cdb177c13d0d1d09d72262ee63e87929139 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 16 Sep 2012 01:27:32 +0200 Subject: [PATCH] Only allow keyboard input when in focus int x_input. --- gfx/context/xegl_ctx.c | 53 +++++++++++++++++++++++------------------- gfx/fonts/freetype.c | 4 ++-- gfx/gl.c | 3 +++ gfx/xvideo.c | 4 ++++ input/x11_input.c | 47 ++++++++++++++++++++----------------- input/x11_input.h | 46 ++++++++++++++++++++++++++++++++++++ 6 files changed, 110 insertions(+), 47 deletions(-) create mode 100644 input/x11_input.h diff --git a/gfx/context/xegl_ctx.c b/gfx/context/xegl_ctx.c index 7823fc4dda..05b22dcacd 100644 --- a/gfx/context/xegl_ctx.c +++ b/gfx/context/xegl_ctx.c @@ -21,11 +21,14 @@ #include "../gfx_context.h" #include "../gl_common.h" #include "../gfx_common.h" +#include "../../input/x11_input.h" #include #include #include #include +#include +#include static Display *g_dpy; static Window g_win; @@ -211,6 +214,15 @@ bool gfx_ctx_init(void) if (g_inited) return false; + const EGLint egl_attribs[] = { + EGL_RED_SIZE, 1, + EGL_GREEN_SIZE, 1, + EGL_BLUE_SIZE, 1, + EGL_DEPTH_SIZE, 1, + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL_NONE, + }; + g_quit = 0; g_dpy = XOpenDisplay(NULL); @@ -227,15 +239,6 @@ bool gfx_ctx_init(void) RARCH_LOG("[X/EGL]: EGL version: %d.%d\n", egl_major, egl_minor); - const EGLint egl_attribs[] = { - EGL_RED_SIZE, 1, - EGL_GREEN_SIZE, 1, - EGL_BLUE_SIZE, 1, - EGL_DEPTH_SIZE, 1, - EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, - EGL_NONE, - }; - EGLint num_configs; if (!eglChooseConfig(g_egl_dpy, egl_attribs, &g_config, 1, &num_configs) || num_configs == 0 || !g_config) @@ -253,26 +256,34 @@ bool gfx_ctx_set_video_mode( unsigned bits, bool fullscreen) { (void)bits; + + struct sigaction sa = {{0}}; + sa.sa_handler = sighandler; + sa.sa_flags = SA_RESTART; + sigemptyset(&sa.sa_mask); + sigaction(SIGINT, &sa, NULL); + sigaction(SIGTERM, &sa, NULL); + + XVisualInfo temp = {0}; + XSetWindowAttributes swa = {0}; + XVisualInfo *vi = NULL; + const EGLint egl_ctx_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, }; - XVisualInfo *vi = NULL; - EGLint vid; if (!eglGetConfigAttrib(g_egl_dpy, g_config, EGL_NATIVE_VISUAL_ID, &vid)) goto error; - XVisualInfo template = {0}; - template.visualid = vid; + temp.visualid = vid; EGLint num_visuals; - vi = XGetVisualInfo(g_dpy, VisualIDMask, &template, &num_visuals); + vi = XGetVisualInfo(g_dpy, VisualIDMask, &temp, &num_visuals); if (!vi) goto error; - XSetWindowAttributes swa = {0}; swa.colormap = g_cmap = XCreateColormap(g_dpy, RootWindow(g_dpy, vi->screen), vi->visual, AllocNone); swa.event_mask = StructureNotifyMask; @@ -307,15 +318,6 @@ bool gfx_ctx_set_video_mode( if (g_quit_atom) XSetWMProtocols(g_dpy, g_win, &g_quit_atom, 1); - // Catch signals. - struct sigaction sa = { - .sa_handler = sighandler, - .sa_flags = SA_RESTART, - }; - sigemptyset(&sa.sa_mask); - sigaction(SIGINT, &sa, NULL); - sigaction(SIGTERM, &sa, NULL); - XFree(vi); g_has_focus = true; g_inited = true; @@ -377,6 +379,9 @@ void gfx_ctx_input_driver(const input_driver_t **input, void **input_data) void *xinput = input_x.init(); *input = xinput ? &input_x : NULL; *input_data = xinput; + + if (xinput) + x_input_set_disp_win((x11_input_t*)xinput, g_dpy, g_win); } void gfx_ctx_set_projection(gl_t *gl, const struct gl_ortho *ortho, bool allow_rotate) diff --git a/gfx/fonts/freetype.c b/gfx/fonts/freetype.c index 3e6e960035..edcdb5a4bb 100644 --- a/gfx/fonts/freetype.c +++ b/gfx/fonts/freetype.c @@ -169,10 +169,10 @@ static void copy_glyph(const struct font_output *head, const struct font_rect *g y = 0; } - if (x + font_width > width) + if (x + font_width > (int)width) font_width = width - x; - if (y + font_height > height) + if (y + font_height > (int)height) font_height = height - y; uint16_t *dst = buffer + y * width + x; diff --git a/gfx/gl.c b/gfx/gl.c index 7aa7a5ff57..d02927f035 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -44,6 +44,9 @@ #include "shader_glsl.h" #endif +extern const GLfloat vertexes_flipped[]; +extern const GLfloat white_color[]; + // Used for the last pass when rendering to the back buffer. const GLfloat vertexes_flipped[] = { 0, 1, diff --git a/gfx/xvideo.c b/gfx/xvideo.c index 2f8d1afc99..46c8e46258 100644 --- a/gfx/xvideo.c +++ b/gfx/xvideo.c @@ -23,6 +23,7 @@ #include "fonts/fonts.h" #endif #include "gfx_common.h" +#include "../input/x11_input.h" #include #include @@ -539,6 +540,9 @@ static void *xv_init(const video_info_t *video, const input_driver_t **input, vo else *input = NULL; + if (xinput) + x_input_set_disp_win((x11_input_t*)xinput, xv->display, xv->window); + init_yuv_tables(xv); xv_init_font(xv, g_settings.video.font_path, g_settings.video.font_size); diff --git a/input/x11_input.c b/input/x11_input.c index d50f80a60a..08b0bcffe1 100644 --- a/input/x11_input.c +++ b/input/x11_input.c @@ -13,25 +13,7 @@ * If not, see . */ -#include "driver.h" - -#include "SDL.h" -#include "../boolean.h" -#include "general.h" -#include -#include -#include "rarch_sdl_input.h" - -#include -#include -#include - -typedef struct x11_input -{ - sdl_input_t *sdl; - Display *display; - char state[32]; -} x11_input_t; +#include "x11_input.h" struct key_bind { @@ -39,6 +21,17 @@ struct key_bind enum retro_key sk; }; +void x_input_set_disp_win(x11_input_t *x11, Display *dpy, Window win) +{ + if (x11->display && !x11->inherit_disp) + { + x11->inherit_disp = true; + XCloseDisplay(x11->display); + x11->display = dpy; + x11->win = win; + } +} + static unsigned keysym_lut[RETROK_LAST]; static const struct key_bind lut_binds[] = { { XK_Left, RETROK_LEFT }, @@ -269,14 +262,26 @@ static void x_input_free(void *data) { x11_input_t *x11 = (x11_input_t*)data; input_sdl.free(x11->sdl); - XCloseDisplay(x11->display); + + if (!x11->inherit_disp) + XCloseDisplay(x11->display); + free(data); } static void x_input_poll(void *data) { x11_input_t *x11 = (x11_input_t*)data; - XQueryKeymap(x11->display, x11->state); + + Window win; + int rev; + XGetInputFocus(x11->display, &win, &rev); + + if (win == x11->win) + XQueryKeymap(x11->display, x11->state); + else + memset(x11->state, 0, sizeof(x11->state)); + input_sdl.poll(x11->sdl); } diff --git a/input/x11_input.h b/input/x11_input.h new file mode 100644 index 0000000000..1cd8bec132 --- /dev/null +++ b/input/x11_input.h @@ -0,0 +1,46 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#ifndef X11_INPUT_H__ +#define X11_INPUT_H__ + +#include "../driver.h" + +#include "SDL.h" +#include "../boolean.h" +#include "../general.h" +#include +#include +#include "rarch_sdl_input.h" + +#include +#include +#include + +typedef struct x11_input +{ + sdl_input_t *sdl; + + bool inherit_disp; + Display *display; + Window win; + + char state[32]; +} x11_input_t; + +void x_input_set_disp_win(x11_input_t *x11, Display *dpy, Window win); + +#endif +