From 2f0f4c038428171244fd4e188a04df3aa07b241a Mon Sep 17 00:00:00 2001 From: "SND\\edgbla_cp" Date: Mon, 9 May 2011 05:38:48 +0000 Subject: dfinput, mouse (experimental). git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@66705 e17a0e51-4ae3-4d35-97c3-1a29b211df97 --- plugins/dfinput/cfg-gtk2.c | 50 ++++++++++++++++++++++++++------ plugins/dfinput/cfg.c | 6 +++- plugins/dfinput/dfinput.ui | 31 ++++++++++++++++---- plugins/dfinput/pad.c | 35 ++++++++++++++++------ plugins/dfinput/pad.h | 2 ++ plugins/dfinput/xkb.c | 72 ++++++++++++++++++++++++++++++++++++++++++---- 6 files changed, 167 insertions(+), 29 deletions(-) (limited to 'plugins/dfinput') diff --git a/plugins/dfinput/cfg-gtk2.c b/plugins/dfinput/cfg-gtk2.c index a3626873..7921f726 100644 --- a/plugins/dfinput/cfg-gtk2.c +++ b/plugins/dfinput/cfg-gtk2.c @@ -188,11 +188,18 @@ static void UpdateKeyList() { for (i = 0; i < 2; i++) { int total; - if (g.cfg.PadDef[i].Type == PSE_PAD_TYPE_ANALOGPAD) { - total = DKEY_TOTAL; - } else { - total = DKEY_TOTAL - 3; - } + switch(g.cfg.PadDef[i].Type) + { + case PSE_PAD_TYPE_MOUSE: + total = 0; + break; + case PSE_PAD_TYPE_STANDARD: + total = DKEY_TOTAL - 3; + break; + case PSE_PAD_TYPE_ANALOGPAD: + total = DKEY_TOTAL; + break; + } widget = gtk_builder_get_object(xml, widgetname[i]); @@ -299,7 +306,14 @@ static void OnDeviceChanged(GtkWidget *widget, gpointer user_data) { static void OnTypeChanged(GtkWidget *widget, gpointer user_data) { int n = (int)user_data, current = gtk_combo_box_get_active(GTK_COMBO_BOX(widget)); - g.cfg.PadDef[n].Type = (current == 0 ? PSE_PAD_TYPE_STANDARD : PSE_PAD_TYPE_ANALOGPAD); + + int padTypeList[] = { + PSE_PAD_TYPE_STANDARD, + PSE_PAD_TYPE_ANALOGPAD, + PSE_PAD_TYPE_MOUSE + }; + + g.cfg.PadDef[n].Type = padTypeList[current]; UpdateKeyList(); } @@ -308,6 +322,10 @@ static void OnThreadedToggled(GtkWidget *widget, gpointer user_data) { g.cfg.Threaded = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); } +static void OnHideCursorToggled(GtkWidget *widget, gpointer user_data) { + g.cfg.HideCursor = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); +} + static void ReadDKeyEvent(int padnum, int key) { SDL_Joystick *js; time_t t; @@ -641,6 +659,11 @@ long PADconfigure() { g_signal_connect_data(GTK_OBJECT(widget), "toggled", G_CALLBACK(OnThreadedToggled), NULL, NULL, G_CONNECT_AFTER); + widget = gtk_builder_get_object(xml, "checkcg"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), g.cfg.HideCursor); + g_signal_connect_data(GTK_OBJECT(widget), "toggled", + G_CALLBACK(OnHideCursorToggled), NULL, NULL, G_CONNECT_AFTER); + widget = gtk_builder_get_object(xml, "combodev1"); g_signal_connect_data(GTK_OBJECT(widget), "changed", G_CALLBACK(OnDeviceChanged), (gpointer)0, NULL, G_CONNECT_AFTER); @@ -649,15 +672,26 @@ long PADconfigure() { g_signal_connect_data(GTK_OBJECT(widget), "changed", G_CALLBACK(OnDeviceChanged), (gpointer)1, NULL, G_CONNECT_AFTER); + int padTypeList[] = { + 0, + 2, // PSE_PAD_TYPE_MOUSE + 0, // PSE_PAD_TYPE_NEGCON + 0, // PSE_PAD_TYPE_GUN + 0, // PSE_PAD_TYPE_STANDARD + 1, // PSE_PAD_TYPE_ANALOGJOY + 0, // PSE_PAD_TYPE_GUNCON + 1, //PSE_PAD_TYPE_ANALOGPAD + }; + widget = gtk_builder_get_object(xml, "combotype1"); gtk_combo_box_set_active(GTK_COMBO_BOX(widget), - g.cfg.PadDef[0].Type == PSE_PAD_TYPE_ANALOGPAD ? 1 : 0); + padTypeList[g.cfg.PadDef[0].Type]); g_signal_connect_data(GTK_OBJECT(widget), "changed", G_CALLBACK(OnTypeChanged), (gpointer)0, NULL, G_CONNECT_AFTER); widget = gtk_builder_get_object(xml, "combotype2"); gtk_combo_box_set_active(GTK_COMBO_BOX(widget), - g.cfg.PadDef[1].Type == PSE_PAD_TYPE_ANALOGPAD ? 1 : 0); + padTypeList[g.cfg.PadDef[1].Type]); g_signal_connect_data(GTK_OBJECT(widget), "changed", G_CALLBACK(OnTypeChanged), (gpointer)1, NULL, G_CONNECT_AFTER); diff --git a/plugins/dfinput/cfg.c b/plugins/dfinput/cfg.c index 64c60a2d..3ac9dfa8 100644 --- a/plugins/dfinput/cfg.c +++ b/plugins/dfinput/cfg.c @@ -26,6 +26,7 @@ static void SetDefaultConfig() { memset(&g.cfg, 0, sizeof(g.cfg)); g.cfg.Threaded = 1; + g.cfg.HideCursor = 0; g.cfg.PadDef[0].DevNum = 0; g.cfg.PadDef[1].DevNum = 1; @@ -128,7 +129,9 @@ void LoadPADConfig() { while (fgets(buf, 256, fp) != NULL) { if (strncmp(buf, "Threaded=", 9) == 0) { g.cfg.Threaded = atoi(&buf[9]); - } else if (strncmp(buf, "[PAD", 4) == 0) { + } else if (strncmp(buf, "HideCursor=", 11) == 0) { + g.cfg.HideCursor = atoi(&buf[11]); + } else if (strncmp(buf, "[PAD", 4) == 0) { current = atoi(&buf[4]) - 1; if (current < 0) { current = 0; @@ -281,6 +284,7 @@ void SavePADConfig() { fprintf(fp, "[CONFIG]\n"); fprintf(fp, "Threaded=%d\n", g.cfg.Threaded); + fprintf(fp, "HideCursor=%d\n", g.cfg.HideCursor); fprintf(fp, "\n"); for (i = 0; i < 2; i++) { diff --git a/plugins/dfinput/dfinput.ui b/plugins/dfinput/dfinput.ui index 144a14c8..5d3ef1ef 100644 --- a/plugins/dfinput/dfinput.ui +++ b/plugins/dfinput/dfinput.ui @@ -4,7 +4,7 @@ - + @@ -14,11 +14,14 @@ Analog Pad + + Mouse + - + @@ -28,6 +31,9 @@ Analog Pad + + Mouse + @@ -35,7 +41,6 @@ False center normal - False True @@ -456,8 +461,9 @@ True + 5 vertical - 20 + 5 Multi-Threaded (Recommended) @@ -468,11 +474,24 @@ False - False - 16 0 + + + Hide cursor + True + False + True + False + True + + + False + False + 1 + + 2 diff --git a/plugins/dfinput/pad.c b/plugins/dfinput/pad.c index a4cd908a..fcb86b5e 100644 --- a/plugins/dfinput/pad.c +++ b/plugins/dfinput/pad.c @@ -26,7 +26,7 @@ static void (*gpuVisualVibration)(uint32_t, uint32_t) = NULL; char *PSEgetLibName(void) { - return _("Gamepad/Keyboard Input"); + return _("Gamepad/Keyboard/Mouse Input"); } uint32_t PSEgetLibType(void) { @@ -34,13 +34,21 @@ uint32_t PSEgetLibType(void) { } uint32_t PSEgetLibVersion(void) { - return (1 << 16) | (1 << 8); + return (1 << 16) | (2 << 8); } +static int padDataLenght[] = {0, 2, 3, 1, 1, 3, 3, 3}; void PADsetMode(const int pad, const int mode) { g.PadState[pad].PadMode = mode; - g.PadState[pad].PadID = mode ? 0x73 : 0x41; - + + if (g.cfg.PadDef[pad].Type == PSE_PAD_TYPE_ANALOGPAD) { + g.PadState[pad].PadID = mode ? 0x73 : 0x41; + } + else { + g.PadState[pad].PadID = (g.cfg.PadDef[pad].Type << 4) | + padDataLenght[g.cfg.PadDef[pad].Type]; + } + g.PadState[pad].Vib0 = 0; g.PadState[pad].Vib1 = 0; g.PadState[pad].VibF[0] = 0; @@ -414,8 +422,6 @@ unsigned char PADpoll(unsigned char value) { case CMD_READ_DATA_AND_VIBRATE: default: - UpdateInput(); - n = g.PadState[CurPad].KeyStatus; n &= g.PadState[CurPad].JoyKeyStatus; @@ -429,7 +435,15 @@ unsigned char PADpoll(unsigned char value) { stdpar[CurPad][5] = g.PadState[CurPad].AnalogStatus[ANALOG_RIGHT][1]; stdpar[CurPad][6] = g.PadState[CurPad].AnalogStatus[ANALOG_LEFT][0]; stdpar[CurPad][7] = g.PadState[CurPad].AnalogStatus[ANALOG_LEFT][1]; - } else { + } + else if(g.PadState[CurPad].PadID == 0x12) + { + CmdLen = 6; + + stdpar[CurPad][4] = g.PadState[0].MouseAxis[0][0]; + stdpar[CurPad][5] = g.PadState[0].MouseAxis[0][1]; + } + else { CmdLen = 4; } @@ -595,8 +609,11 @@ long PADreadPort2(PadDataS *pad) { long PADkeypressed(void) { long s; - - CheckKeyboard(); + + static int frame = 0; + if( !frame ) + UpdateInput(); + frame ^= 1; s = g.KeyLeftOver; g.KeyLeftOver = 0; diff --git a/plugins/dfinput/pad.h b/plugins/dfinput/pad.h index 1ad35a43..06913c4c 100644 --- a/plugins/dfinput/pad.h +++ b/plugins/dfinput/pad.h @@ -121,6 +121,7 @@ typedef struct tagPadDef { typedef struct tagConfig { uint8_t Threaded; + uint8_t HideCursor; PADDEF PadDef[2]; } CONFIG; @@ -134,6 +135,7 @@ typedef struct tagPadState { volatile uint16_t JoyKeyStatus; volatile uint8_t AnalogStatus[ANALOG_TOTAL][2]; // 0-255 where 127 is center position volatile uint8_t AnalogKeyStatus[ANALOG_TOTAL][4]; + volatile int8_t MouseAxis[2][2]; uint8_t Vib0, Vib1; volatile uint8_t VibF[2]; #if SDL_VERSION_ATLEAST(1,3,0) diff --git a/plugins/dfinput/xkb.c b/plugins/dfinput/xkb.c index 687b150a..6a7a21bd 100644 --- a/plugins/dfinput/xkb.c +++ b/plugins/dfinput/xkb.c @@ -19,6 +19,9 @@ #include "pad.h" static Atom wmprotocols, wmdelwindow; +static int g_currentMouse_X; +static int g_currentMouse_Y; +static Window window; void InitKeyboard() { wmprotocols = XInternAtom(g.Disp, "WM_PROTOCOLS", 0); @@ -26,12 +29,27 @@ void InitKeyboard() { XkbSetDetectableAutoRepeat(g.Disp, 1, NULL); + if (g.cfg.PadDef[0].Type == PSE_PAD_TYPE_MOUSE || + g.cfg.PadDef[1].Type == PSE_PAD_TYPE_MOUSE) { + int revert_to; + XGetInputFocus(g.Disp, &window, &revert_to); + XGrabPointer(g.Disp, window, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, window, None, CurrentTime); + } + + g_currentMouse_X = 0; + g_currentMouse_Y = 0; + g.PadState[0].KeyStatus = 0xFFFF; g.PadState[1].KeyStatus = 0xFFFF; } void DestroyKeyboard() { XkbSetDetectableAutoRepeat(g.Disp, 0, NULL); + + if (g.cfg.PadDef[0].Type == PSE_PAD_TYPE_MOUSE || + g.cfg.PadDef[1].Type == PSE_PAD_TYPE_MOUSE) { + XUngrabPointer(g.Disp, CurrentTime); + } } static void bdown(int pad, int bit) @@ -53,10 +71,46 @@ void CheckKeyboard() { XEvent evt; XClientMessageEvent *xce; uint16_t Key; - + while (XPending(g.Disp)) { XNextEvent(g.Disp, &evt); switch (evt.type) { + case ButtonPress: + for(i = 0; i < 2; ++i) { + if(g.cfg.PadDef[i].Type == PSE_PAD_TYPE_MOUSE) { + switch(evt.xbutton.button) { + case 1: + bdown(i, 11); + break; + case 3: + bdown(i, 10); + break; + } + } + } + break; + case ButtonRelease: + for(i = 0; i < 2; ++i) { + if(g.cfg.PadDef[i].Type == PSE_PAD_TYPE_MOUSE) { + switch(evt.xbutton.button) { + case 1: + bup(i, 11); + break; + case 3: + bup(i, 10); + break; + } + } + } + break; + case MotionNotify: + g_currentMouse_X = evt.xmotion.x - 160; + g_currentMouse_Y = evt.xmotion.y - 120; + if( g_currentMouse_X < -128) g_currentMouse_X = -128; + if( g_currentMouse_X > 127) g_currentMouse_X = 127; + if( g_currentMouse_Y < -128) g_currentMouse_Y = -128; + if( g_currentMouse_Y > 127) g_currentMouse_Y = 127; + break; case KeyPress: Key = XLookupKeysym((XKeyEvent *)&evt, 0); found = 0; @@ -71,8 +125,7 @@ void CheckKeyboard() { if (!found && !AnalogKeyPressed(Key)) { g.KeyLeftOver = Key; } - return; - + break; case KeyRelease: Key = XLookupKeysym((XKeyEvent *)&evt, 0); found = 0; @@ -88,7 +141,6 @@ void CheckKeyboard() { g.KeyLeftOver = ((long)Key | 0x40000000); } break; - case ClientMessage: xce = (XClientMessageEvent *)&evt; if (xce->message_type == wmprotocols && (Atom)xce->data.l[0] == wmdelwindow) { @@ -98,5 +150,15 @@ void CheckKeyboard() { } break; } - } + } + + g.PadState[0].MouseAxis[0][0] = g_currentMouse_X; + g.PadState[0].MouseAxis[0][1] = g_currentMouse_Y; + g_currentMouse_X *= 0.7; + g_currentMouse_Y *= 0.7; + + if (g.cfg.PadDef[0].Type == PSE_PAD_TYPE_MOUSE || + g.cfg.PadDef[1].Type == PSE_PAD_TYPE_MOUSE) { + XWarpPointer(g.Disp, None, window, 0, 0, 0, 0, 160, 120); + } } -- cgit v1.2.3