From 9fd9fd10e85e31c21472c06680649a5d160a9d07 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 29 Nov 2015 03:34:09 +0100 Subject: [PATCH] Create input_x11_common --- Makefile.common | 3 +- gfx/common/x11_common.c | 6 ++-- griffin/griffin.c | 4 +++ input/common/input_x11_common.c | 51 +++++++++++++++++++++++++++++++++ input/common/input_x11_common.h | 31 ++++++++++++++++++++ input/drivers/x11_input.c | 32 ++------------------- 6 files changed, 93 insertions(+), 34 deletions(-) create mode 100644 input/common/input_x11_common.c create mode 100644 input/common/input_x11_common.h diff --git a/Makefile.common b/Makefile.common index d59f2009e3..bd687cc9ce 100644 --- a/Makefile.common +++ b/Makefile.common @@ -507,7 +507,8 @@ ifeq ($(HAVE_XINPUT), 1) endif ifeq ($(HAVE_X11), 1) - OBJ += input/drivers/x11_input.o \ + OBJ += input/common/input_x11_common.o \ + input/drivers/x11_input.o \ gfx/common/x11_common.o \ input/drivers_keyboard/keyboard_event_x11.o diff --git a/gfx/common/x11_common.c b/gfx/common/x11_common.c index e4dc55e831..b4f958c1bf 100644 --- a/gfx/common/x11_common.c +++ b/gfx/common/x11_common.c @@ -24,6 +24,7 @@ #include #include "x11_common.h" +#include "../../input/common/input_x11_common.h" #include "../../general.h" #include "../../verbosity.h" @@ -382,12 +383,9 @@ bool x11_get_metrics(void *data, return true; } -void x_input_poll_wheel(void *data, XButtonEvent *event, bool latch); - bool x11_alive(void *data) { XEvent event; - driver_t *driver = driver_get_ptr(); while (XPending(g_x11_dpy)) { @@ -421,7 +419,7 @@ bool x11_alive(void *data) break; case ButtonPress: - x_input_poll_wheel(driver->input_data, &event.xbutton, true); + x_input_poll_wheel(&event.xbutton, true); break; case ButtonRelease: diff --git a/griffin/griffin.c b/griffin/griffin.c index e4a71dd612..9909051395 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -320,6 +320,10 @@ INPUT #include "../tasks/task_overlay.c" #endif +#ifdef HAVE_X11 +#include "../input/common/x11_input_common.c" +#endif + #if defined(__CELLOS_LV2__) #include "../input/drivers/ps3_input.c" #include "../input/drivers_joypad/ps3_joypad.c" diff --git a/input/common/input_x11_common.c b/input/common/input_x11_common.c new file mode 100644 index 0000000000..5d9fe5e387 --- /dev/null +++ b/input/common/input_x11_common.c @@ -0,0 +1,51 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - 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 . + */ + +#include "input_x11_common.h" + +static bool x11_mouse_wu; +static bool x11_mouse_wd; + +int16_t x_mouse_state_wheel(unsigned id) +{ + int16_t ret = 0; + + switch (id) + { + case RETRO_DEVICE_ID_MOUSE_WHEELUP: + ret = x11_mouse_wu; + x11_mouse_wu = 0; + return ret; + case RETRO_DEVICE_ID_MOUSE_WHEELDOWN: + ret = x11_mouse_wd; + x11_mouse_wd = 0; + return ret; + } + + return 0; +} + +void x_input_poll_wheel(XButtonEvent *event, bool latch) +{ + switch (event->button) + { + case 4: + x11_mouse_wu = 1; + break; + case 5: + x11_mouse_wd = 1; + break; + } +} diff --git a/input/common/input_x11_common.h b/input/common/input_x11_common.h new file mode 100644 index 0000000000..830da67fb9 --- /dev/null +++ b/input/common/input_x11_common.h @@ -0,0 +1,31 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - 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 _INPUT_X11_COMMON_H +#define _INPUT_X11_COMMON_H + +#include + +#include + +#include + +#include "../../driver.h" + +int16_t x_mouse_state_wheel(unsigned id); + +void x_input_poll_wheel(XButtonEvent *event, bool latch); + +#endif diff --git a/input/drivers/x11_input.c b/input/drivers/x11_input.c index d5be3ef89d..e2affb9b8c 100644 --- a/input/drivers/x11_input.c +++ b/input/drivers/x11_input.c @@ -16,7 +16,6 @@ #include #include -#include #include #include @@ -27,6 +26,7 @@ #include "../input_keymaps.h" #include "../../gfx/video_driver.h" +#include "../common/input_x11_common.h" #include "../../driver.h" #include "../../general.h" @@ -41,7 +41,7 @@ typedef struct x11_input Window win; char state[32]; - bool mouse_l, mouse_r, mouse_m, mouse_wu, mouse_wd; + bool mouse_l, mouse_r, mouse_m; int mouse_x, mouse_y; int mouse_last_x, mouse_last_y; @@ -150,17 +150,8 @@ static int16_t x_mouse_state(x11_input_t *x11, unsigned id) case RETRO_DEVICE_ID_MOUSE_RIGHT: return x11->mouse_r; case RETRO_DEVICE_ID_MOUSE_WHEELUP: - { - int16_t ret = x11->mouse_wu; - x11->mouse_wu = 0; - return ret; - } case RETRO_DEVICE_ID_MOUSE_WHEELDOWN: - { - int16_t ret = x11->mouse_wd; - x11->mouse_wd = 0; - return ret; - } + return x_mouse_state_wheel(id); case RETRO_DEVICE_ID_MOUSE_MIDDLE: return x11->mouse_m; } @@ -342,23 +333,6 @@ static void x_input_poll_mouse(x11_input_t *x11) } } -void x_input_poll_wheel(void *data, XButtonEvent *event, bool latch) -{ - x11_input_t *x11 = (x11_input_t*)data; - - if (!x11) - return; - - switch (event->button) - { - case 4: - x11->mouse_wu = 1; - break; - case 5: - x11->mouse_wd = 1; - break; - } -} static void x_input_poll(void *data) {