Skip to content

Commit 7108cb9

Browse files
dkosmariDaniel K. O. (dkosmari)GaryOderNichts
authored
Wii U: Added SDL_Window to touch events, so they can be mapped to mouse events. (#92)
* Added SDL_Window to touch events, so they can mapped to mouse events. --HG-- branch : finger-window-hg * Added an extra check, in case there's no video device. --HG-- branch : finger-window-hg * Update src/joystick/wiiu/SDL_wiiujoystick.c Co-authored-by: GaryOderNichts <12049776+GaryOderNichts@users.noreply.github.com> --------- Co-authored-by: Daniel K. O. (dkosmari) <none@none> Co-authored-by: GaryOderNichts <12049776+GaryOderNichts@users.noreply.github.com>
1 parent 63173cd commit 7108cb9

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/joystick/wiiu/SDL_wiiujoystick.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "SDL_events.h"
4040

4141
#include "SDL_wiiujoystick.h"
42+
#include "../../video/SDL_sysvideo.h"
4243

4344
//index with device_index, get WIIU_DEVICE*
4445
static int deviceMap[MAX_CONTROLLERS];
@@ -65,6 +66,7 @@ static void WIIU_JoystickUpdate(SDL_Joystick *joystick);
6566
static void WIIU_JoystickClose(SDL_Joystick *joystick);
6667
static void WIIU_JoystickQuit(void);
6768
static SDL_bool WIIU_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping * out);
69+
static SDL_Window *WIIU_GetGamepadWindow(void);
6870

6971
static int WIIU_GetDeviceForIndex(int device_index) {
7072
return deviceMap[device_index];
@@ -110,6 +112,18 @@ static void WIIU_RemoveDevice(int wiiu_device) {
110112
}
111113
}
112114

115+
static SDL_Window *WIIU_GetGamepadWindow(void) {
116+
// Find first visible window that is not TV-exclusive.
117+
SDL_VideoDevice *dev = SDL_GetVideoDevice();
118+
if (!dev)
119+
return NULL;
120+
for (SDL_Window *win = dev->windows; win; win = win->next) {
121+
if ((win->flags & SDL_WINDOW_SHOWN) && !(win->flags & SDL_WINDOW_WIIU_TV_ONLY))
122+
return win;
123+
}
124+
return NULL;
125+
}
126+
113127
/* Function to scan the system for joysticks.
114128
* Joystick 0 should be the system default joystick.
115129
* This function should return 0, or -1 on an unrecoverable error.
@@ -465,15 +479,16 @@ static void WIIU_JoystickUpdate(SDL_Joystick *joystick)
465479
/* touchscreen */
466480
VPADGetTPCalibratedPoint(VPAD_CHAN_0, &tpdata, &vpad.tpNormal);
467481
if (tpdata.touched) {
482+
SDL_Window *window = WIIU_GetGamepadWindow();
468483
if (!last_touched) {
469484
/* Send an initial touch */
470-
SDL_SendTouch(0, 0, NULL, SDL_TRUE,
485+
SDL_SendTouch(0, 0, window, SDL_TRUE,
471486
(float) tpdata.x / 1280.0f,
472487
(float) tpdata.y / 720.0f, 1);
473488
}
474489

475490
/* Always send the motion */
476-
SDL_SendTouchMotion(0, 0, NULL,
491+
SDL_SendTouchMotion(0, 0, window,
477492
(float) tpdata.x / 1280.0f,
478493
(float) tpdata.y / 720.0f, 1);
479494

@@ -482,8 +497,9 @@ static void WIIU_JoystickUpdate(SDL_Joystick *joystick)
482497
last_touch_y = tpdata.y;
483498
last_touched = 1;
484499
} else if (last_touched) {
500+
SDL_Window *window = WIIU_GetGamepadWindow();
485501
/* Finger released from screen */
486-
SDL_SendTouch(0, 0, NULL, SDL_FALSE,
502+
SDL_SendTouch(0, 0, window, SDL_FALSE,
487503
(float) last_touch_x / 1280.0f,
488504
(float) last_touch_y / 720.0f, 1);
489505
last_touched = 0;

src/video/wiiu/SDL_wiiuvideo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ struct WIIU_VideoData
5151
void *drcScanBuffer;
5252
uint32_t drcScanBufferSize;
5353

54-
// did the keyboard code initialize properly?
55-
int kbd_init;
54+
// did the keyboard code initialize properly?
55+
int kbd_init;
5656
};
5757

5858
#endif /* SDL_VIDEO_DRIVER_WIIU */

0 commit comments

Comments
 (0)