Only allow keyboard input when in focus int x_input.

This commit is contained in:
Themaister 2012-09-16 01:27:32 +02:00
parent 282346572d
commit 6d2c0cdb17
6 changed files with 110 additions and 47 deletions

View File

@ -21,11 +21,14 @@
#include "../gfx_context.h"
#include "../gl_common.h"
#include "../gfx_common.h"
#include "../../input/x11_input.h"
#include <signal.h>
#include <stdint.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
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)

View File

@ -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;

View File

@ -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,

View File

@ -23,6 +23,7 @@
#include "fonts/fonts.h"
#endif
#include "gfx_common.h"
#include "../input/x11_input.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
@ -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);

View File

@ -13,25 +13,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "driver.h"
#include "SDL.h"
#include "../boolean.h"
#include "general.h"
#include <stdint.h>
#include <stdlib.h>
#include "rarch_sdl_input.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
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);
}

46
input/x11_input.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef X11_INPUT_H__
#define X11_INPUT_H__
#include "../driver.h"
#include "SDL.h"
#include "../boolean.h"
#include "../general.h"
#include <stdint.h>
#include <stdlib.h>
#include "rarch_sdl_input.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
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