Skip to content

Commit

Permalink
onepad: fix keyboard on 2nd pad
Browse files Browse the repository at this point in the history
There is only a single event queue, so you need to detect the pad based
on the configuration

Mouse/Wiimote is limited to first pad

Related to issue #1441
  • Loading branch information
gregory38 committed Jul 8, 2016
1 parent eefe3e8 commit 8b3e04d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
11 changes: 8 additions & 3 deletions plugins/onepad/Linux/linux.cpp
Expand Up @@ -172,13 +172,18 @@ EXPORT_C_(void) PADupdate(int pad)

// Actually PADupdate is always call with pad == 0. So you need to update both
// pads -- Gregory

// Poll keyboard/mouse event. There is currently no way to separate pad0 from pad1 event.
// So we will populate both pad in the same time
for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++) {
// Poll keyboard/mouse event
key_status->keyboard_state_acces(cpad);
PollForX11KeyboardInput(cpad);
}
PollForX11KeyboardInput();

// Get joystick state
// Get joystick state + Commit
for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++) {
key_status->joystick_state_acces(cpad);

PollForJoystickInput(cpad);

key_status->commit_status(cpad);
Expand Down
19 changes: 14 additions & 5 deletions plugins/onepad/keyboard.cpp
Expand Up @@ -56,10 +56,19 @@ 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;
void AnalyzeKeyEvent(int pad, keyEvent &evt)
void AnalyzeKeyEvent(keyEvent &evt)
{
KeySym key = (KeySym)evt.key;
int index = get_keyboard_key(pad, key);
int pad = 0;
int index = -1;

for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++) {
int tmp_index = get_keyboard_key(cpad, key);
if (tmp_index != -1) {
pad = cpad;
index = tmp_index;
}
}

switch (evt.evt)
{
Expand Down Expand Up @@ -194,14 +203,14 @@ void AnalyzeKeyEvent(int pad, keyEvent &evt)
}
}

void PollForX11KeyboardInput(int pad)
void PollForX11KeyboardInput()
{
keyEvent evt;
XEvent E;

// Keyboard input send by PCSX2
while (!ev_fifo.empty()) {
AnalyzeKeyEvent(pad, ev_fifo.front());
AnalyzeKeyEvent(ev_fifo.front());
pthread_spin_lock(&mutex_KeyEvent);
ev_fifo.pop();
pthread_spin_unlock(&mutex_KeyEvent);
Expand All @@ -227,7 +236,7 @@ void PollForX11KeyboardInput(int pad)
evt.key = (int)XLookupKeysym(&E.xkey, 0);
}

AnalyzeKeyEvent(pad, evt);
AnalyzeKeyEvent(evt);
}
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/onepad/keyboard.h
Expand Up @@ -29,7 +29,7 @@
#include "Linux/linux.h"

extern Display *GSdsp;
extern void PollForX11KeyboardInput(int pad);
extern void PollForX11KeyboardInput();
extern bool PollX11KeyboardMouseEvent(u32 &pkey);
extern Window GSwin;

Expand Down

0 comments on commit 8b3e04d

Please sign in to comment.