2009-07-03 11:45:47 +00:00
|
|
|
/* OnePAD - author: arcum42(@gmail.com)
|
|
|
|
* Copyright (C) 2009
|
|
|
|
*
|
|
|
|
* Based on ZeroPAD, author zerofrog@gmail.com
|
|
|
|
* Copyright (C) 2006-2007
|
|
|
|
*
|
|
|
|
* This program 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 Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 this program; if not, write to the Free Software
|
2010-07-04 22:49:00 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2009-07-03 11:45:47 +00:00
|
|
|
*/
|
2009-09-08 21:41:46 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
/*
|
|
|
|
* Theoretically, this header is for anything to do with keyboard input.
|
|
|
|
* Pragmatically, event handing's going in here too.
|
|
|
|
*/
|
2014-12-16 21:24:35 +00:00
|
|
|
|
2010-06-05 11:03:12 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
#include "keyboard.h"
|
2009-09-08 21:41:46 +00:00
|
|
|
|
2014-08-03 18:11:22 +00:00
|
|
|
#ifndef __linux__
|
2009-07-03 11:45:47 +00:00
|
|
|
char* KeysymToChar(int keysym)
|
|
|
|
{
|
|
|
|
LPWORD temp;
|
|
|
|
|
|
|
|
ToAscii((UINT) keysym, NULL, NULL, temp, NULL);
|
|
|
|
return (char*)temp;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void SetAutoRepeat(bool autorep)
|
|
|
|
{
|
2014-08-03 18:11:22 +00:00
|
|
|
#ifdef __linux__
|
2009-12-26 00:01:30 +00:00
|
|
|
if (toggleAutoRepeat)
|
|
|
|
{
|
|
|
|
if (autorep)
|
|
|
|
XAutoRepeatOn(GSdsp);
|
|
|
|
else
|
|
|
|
XAutoRepeatOff(GSdsp);
|
|
|
|
}
|
2009-07-03 11:45:47 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-08-03 18:11:22 +00:00
|
|
|
#ifdef __linux__
|
2011-06-12 14:48:36 +00:00
|
|
|
static bool s_grab_input = false;
|
|
|
|
static bool s_Shift = false;
|
|
|
|
static unsigned int s_previous_mouse_x = 0;
|
|
|
|
static unsigned int s_previous_mouse_y = 0;
|
2011-06-28 21:30:06 +00:00
|
|
|
void AnalyzeKeyEvent(int pad, keyEvent &evt)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
2011-06-12 14:48:36 +00:00
|
|
|
KeySym key = (KeySym)evt.key;
|
2011-06-28 21:30:06 +00:00
|
|
|
int index = get_keyboard_key(pad, key);
|
2009-09-08 21:41:46 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
switch (evt.evt)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
2011-06-12 14:48:36 +00:00
|
|
|
case KeyPress:
|
|
|
|
// Shift F12 is not yet use by pcsx2. So keep it to grab/ungrab input
|
|
|
|
// I found it very handy vs the automatic fullscreen detection
|
|
|
|
// 1/ Does not need to detect full-screen
|
|
|
|
// 2/ Can use a debugger in full-screen
|
|
|
|
// 3/ Can grab input in window without the need of a pixelated full-screen
|
|
|
|
if (key == XK_Shift_R || key == XK_Shift_L) s_Shift = true;
|
|
|
|
if (key == XK_F12 && s_Shift) {
|
|
|
|
if(!s_grab_input) {
|
|
|
|
s_grab_input = true;
|
|
|
|
XGrabPointer(GSdsp, GSwin, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, GSwin, None, CurrentTime);
|
|
|
|
XGrabKeyboard(GSdsp, GSwin, True, GrabModeAsync, GrabModeAsync, CurrentTime);
|
|
|
|
} else {
|
|
|
|
s_grab_input = false;
|
|
|
|
XUngrabPointer(GSdsp, CurrentTime);
|
|
|
|
XUngrabKeyboard(GSdsp, CurrentTime);
|
|
|
|
}
|
|
|
|
}
|
2009-07-03 11:45:47 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
// Analog controls.
|
2011-06-28 21:30:06 +00:00
|
|
|
if (IsAnalogKey(index))
|
2011-06-12 14:48:36 +00:00
|
|
|
{
|
2011-06-28 21:30:06 +00:00
|
|
|
switch (index)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
|
|
|
case PAD_R_LEFT:
|
|
|
|
case PAD_R_UP:
|
|
|
|
case PAD_L_LEFT:
|
|
|
|
case PAD_L_UP:
|
2011-06-28 21:30:06 +00:00
|
|
|
key_status->press(pad, index, -MAX_ANALOG_VALUE);
|
2009-07-03 11:45:47 +00:00
|
|
|
break;
|
|
|
|
case PAD_R_RIGHT:
|
|
|
|
case PAD_R_DOWN:
|
|
|
|
case PAD_L_RIGHT:
|
|
|
|
case PAD_L_DOWN:
|
2011-06-28 21:30:06 +00:00
|
|
|
key_status->press(pad, index, MAX_ANALOG_VALUE);
|
2009-07-03 11:45:47 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-06-28 21:30:06 +00:00
|
|
|
} else if (index != -1)
|
|
|
|
key_status->press(pad, index);
|
2009-09-08 21:41:46 +00:00
|
|
|
|
2011-06-28 21:30:06 +00:00
|
|
|
//PAD_LOG("Key pressed:%d\n", index);
|
2009-07-03 11:45:47 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
event.evt = KEYPRESS;
|
|
|
|
event.key = key;
|
|
|
|
break;
|
2009-09-08 21:41:46 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
case KeyRelease:
|
|
|
|
if (key == XK_Shift_R || key == XK_Shift_L) s_Shift = false;
|
2009-07-03 11:45:47 +00:00
|
|
|
|
2011-06-28 21:30:06 +00:00
|
|
|
if (index != -1)
|
|
|
|
key_status->release(pad, index);
|
2011-06-12 14:48:36 +00:00
|
|
|
|
|
|
|
event.evt = KEYRELEASE;
|
|
|
|
event.key = key;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FocusIn:
|
2015-11-07 09:42:15 +00:00
|
|
|
//XAutoRepeatOff(GSdsp);
|
2011-06-12 14:48:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FocusOut:
|
2015-11-07 09:42:15 +00:00
|
|
|
//XAutoRepeatOn(GSdsp);
|
2015-11-07 09:44:58 +00:00
|
|
|
s_Shift = false;
|
2011-06-12 14:48:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ButtonPress:
|
2011-06-28 21:30:06 +00:00
|
|
|
if (index != -1)
|
|
|
|
key_status->press(pad, index);
|
2011-06-12 14:48:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ButtonRelease:
|
2011-06-28 21:30:06 +00:00
|
|
|
if (index != -1)
|
|
|
|
key_status->release(pad, index);
|
2011-06-12 14:48:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MotionNotify:
|
|
|
|
// FIXME: How to handle when the mouse does not move, no event generated!!!
|
|
|
|
// 1/ small move == no move. Cons : can not do small movement
|
|
|
|
// 2/ use a watchdog timer thread
|
|
|
|
// 3/ ??? idea welcome ;)
|
2015-10-14 11:11:09 +00:00
|
|
|
if (conf->pad_options[pad].mouse_l|conf->pad_options[pad].mouse_r) {
|
2011-06-12 14:48:36 +00:00
|
|
|
unsigned int pad_x;
|
|
|
|
unsigned int pad_y;
|
|
|
|
// Note when both PADOPTION_MOUSE_R and PADOPTION_MOUSE_L are set, take only the right one
|
2015-10-14 11:11:09 +00:00
|
|
|
if (conf->pad_options[pad].mouse_r) {
|
2011-06-12 14:48:36 +00:00
|
|
|
pad_x = PAD_R_RIGHT;
|
|
|
|
pad_y = PAD_R_UP;
|
|
|
|
} else {
|
|
|
|
pad_x = PAD_L_RIGHT;
|
|
|
|
pad_y = PAD_L_UP;
|
2009-07-03 11:45:47 +00:00
|
|
|
}
|
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
unsigned x = evt.key & 0xFFFF;
|
2013-11-01 21:05:59 +00:00
|
|
|
unsigned int value = (s_previous_mouse_x > x) ? s_previous_mouse_x - x : x - s_previous_mouse_x;
|
2015-10-14 11:11:09 +00:00
|
|
|
value *= conf->get_sensibility();
|
2009-07-03 11:45:47 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
if (x == 0)
|
2011-06-28 21:30:06 +00:00
|
|
|
key_status->press(pad, pad_x, -MAX_ANALOG_VALUE);
|
2011-06-12 14:48:36 +00:00
|
|
|
else if (x == 0xFFFF)
|
2011-06-28 21:30:06 +00:00
|
|
|
key_status->press(pad, pad_x, MAX_ANALOG_VALUE);
|
2011-06-12 14:48:36 +00:00
|
|
|
else if (x < (s_previous_mouse_x -2))
|
2011-06-28 21:30:06 +00:00
|
|
|
key_status->press(pad, pad_x, -value);
|
2011-06-12 14:48:36 +00:00
|
|
|
else if (x > (s_previous_mouse_x +2))
|
2011-06-28 21:30:06 +00:00
|
|
|
key_status->press(pad, pad_x, value);
|
2011-06-12 14:48:36 +00:00
|
|
|
else
|
2011-06-28 21:30:06 +00:00
|
|
|
key_status->release(pad, pad_x);
|
2009-07-03 11:45:47 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
|
|
|
|
unsigned y = evt.key >> 16;
|
2013-11-01 21:05:59 +00:00
|
|
|
value = (s_previous_mouse_y > y) ? s_previous_mouse_y - y : y - s_previous_mouse_y;
|
2015-10-14 11:11:09 +00:00
|
|
|
value *= conf->get_sensibility();
|
2011-06-12 14:48:36 +00:00
|
|
|
|
|
|
|
if (y == 0)
|
2011-06-28 21:30:06 +00:00
|
|
|
key_status->press(pad, pad_y, -MAX_ANALOG_VALUE);
|
2011-06-12 14:48:36 +00:00
|
|
|
else if (y == 0xFFFF)
|
2011-06-28 21:30:06 +00:00
|
|
|
key_status->press(pad, pad_y, MAX_ANALOG_VALUE);
|
2011-06-12 14:48:36 +00:00
|
|
|
else if (y < (s_previous_mouse_y -2))
|
2011-06-28 21:30:06 +00:00
|
|
|
key_status->press(pad, pad_y, -value);
|
2011-06-12 14:48:36 +00:00
|
|
|
else if (y > (s_previous_mouse_y +2))
|
2011-06-28 21:30:06 +00:00
|
|
|
key_status->press(pad, pad_y, value);
|
2011-06-12 14:48:36 +00:00
|
|
|
else
|
2011-06-28 21:30:06 +00:00
|
|
|
key_status->release(pad, pad_y);
|
2011-06-12 14:48:36 +00:00
|
|
|
|
|
|
|
s_previous_mouse_x = x;
|
|
|
|
s_previous_mouse_y = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-28 21:30:06 +00:00
|
|
|
void PollForX11KeyboardInput(int pad)
|
2011-06-12 14:48:36 +00:00
|
|
|
{
|
|
|
|
keyEvent evt;
|
|
|
|
XEvent E;
|
|
|
|
|
|
|
|
// Keyboard input send by PCSX2
|
|
|
|
while (!ev_fifo.empty()) {
|
2011-06-28 21:30:06 +00:00
|
|
|
AnalyzeKeyEvent(pad, ev_fifo.front());
|
|
|
|
pthread_spin_lock(&mutex_KeyEvent);
|
2011-06-12 14:48:36 +00:00
|
|
|
ev_fifo.pop();
|
2011-06-28 21:30:06 +00:00
|
|
|
pthread_spin_unlock(&mutex_KeyEvent);
|
2009-07-03 11:45:47 +00:00
|
|
|
}
|
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
// keyboard input
|
|
|
|
while (XPending(GSdsp) > 0)
|
|
|
|
{
|
|
|
|
XNextEvent(GSdsp, &E);
|
2014-12-16 21:24:35 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
// Change the format of the structure to be compatible with GSOpen2
|
|
|
|
// mode (event come from pcsx2 not X)
|
2014-12-16 21:24:35 +00:00
|
|
|
evt.evt = E.type;
|
|
|
|
switch (E.type) {
|
|
|
|
case MotionNotify:
|
|
|
|
evt.key = (E.xbutton.x & 0xFFFF) | (E.xbutton.y << 16);
|
|
|
|
break;
|
2011-06-12 14:48:36 +00:00
|
|
|
case ButtonRelease:
|
2014-12-16 21:24:35 +00:00
|
|
|
case ButtonPress:
|
|
|
|
evt.key = E.xbutton.button;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
evt.key = (int)XLookupKeysym(&E.xkey, 0);
|
2011-06-12 14:48:36 +00:00
|
|
|
}
|
2014-12-16 21:24:35 +00:00
|
|
|
|
2011-06-28 21:30:06 +00:00
|
|
|
AnalyzeKeyEvent(pad, evt);
|
2011-06-12 14:48:36 +00:00
|
|
|
}
|
2009-07-03 11:45:47 +00:00
|
|
|
}
|
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
bool PollX11KeyboardMouseEvent(u32 &pkey)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
|
|
|
GdkEvent *ev = gdk_event_get();
|
2009-09-08 21:41:46 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
if (ev != NULL)
|
|
|
|
{
|
2011-06-12 14:48:36 +00:00
|
|
|
if (ev->type == GDK_KEY_PRESS) {
|
2014-12-07 22:01:51 +00:00
|
|
|
pkey = ev->key.keyval != GDK_KEY_Escape ? ev->key.keyval : 0;
|
2009-07-03 11:45:47 +00:00
|
|
|
return true;
|
2011-06-12 14:48:36 +00:00
|
|
|
} else if(ev->type == GDK_BUTTON_PRESS) {
|
|
|
|
pkey = ev->button.button;
|
|
|
|
return true;
|
2009-07-03 11:45:47 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-08 21:41:46 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-06-12 14:48:36 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
#else
|
|
|
|
LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
static bool lbutton = false, rbutton = false;
|
2011-07-01 09:01:50 +00:00
|
|
|
key_status->keyboard_state_acces(cpad);
|
2009-07-03 11:45:47 +00:00
|
|
|
|
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
if (lParam & 0x40000000) return TRUE;
|
|
|
|
|
2016-02-27 19:04:06 +00:00
|
|
|
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
2009-07-10 06:07:32 +00:00
|
|
|
for (int i = 0; i < MAX_KEYS; i++)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
|
|
|
if (wParam == get_key(pad, i))
|
|
|
|
{
|
2011-07-01 09:01:50 +00:00
|
|
|
key_status->press(pad, i);
|
2009-07-03 11:45:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
event.evt = KEYPRESS;
|
|
|
|
event.key = wParam;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_KEYUP:
|
2016-02-27 19:04:06 +00:00
|
|
|
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
2009-07-10 06:07:32 +00:00
|
|
|
for (int i = 0; i < MAX_KEYS; i++)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
|
|
|
if (wParam == get_key(pad,i))
|
|
|
|
{
|
2011-07-01 09:01:50 +00:00
|
|
|
key_status->release(pad, i);
|
2009-07-03 11:45:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
event.evt = KEYRELEASE;
|
|
|
|
event.key = wParam;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_DESTROY:
|
|
|
|
case WM_QUIT:
|
|
|
|
event.evt = KEYPRESS;
|
|
|
|
event.key = VK_ESCAPE;
|
|
|
|
return GSwndProc(hWnd, msg, wParam, lParam);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return GSwndProc(hWnd, msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2016-02-27 19:04:06 +00:00
|
|
|
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad)
|
2011-07-01 09:01:50 +00:00
|
|
|
key_status->commit_status(pad);
|
2009-07-03 11:45:47 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|