Skip to content

Commit 7cf4bf9

Browse files
dkosmariDaniel K. O. (dkosmari)GaryOderNichts
committed
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 ebd703c commit 7cf4bf9

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

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];
@@ -67,6 +68,7 @@ static void WIIU_JoystickUpdate(SDL_Joystick *joystick);
6768
static void WIIU_JoystickClose(SDL_Joystick *joystick);
6869
static void WIIU_JoystickQuit(void);
6970
static SDL_bool WIIU_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping * out);
71+
static SDL_Window *WIIU_GetGamepadWindow(void);
7072

7173
static int WIIU_GetDeviceForIndex(int device_index) {
7274
return deviceMap[device_index];
@@ -112,6 +114,18 @@ static void WIIU_RemoveDevice(int wiiu_device) {
112114
}
113115
}
114116

117+
static SDL_Window *WIIU_GetGamepadWindow(void) {
118+
// Find first visible window that is not TV-exclusive.
119+
SDL_VideoDevice *dev = SDL_GetVideoDevice();
120+
if (!dev)
121+
return NULL;
122+
for (SDL_Window *win = dev->windows; win; win = win->next) {
123+
if ((win->flags & SDL_WINDOW_SHOWN) && !(win->flags & SDL_WINDOW_WIIU_TV_ONLY))
124+
return win;
125+
}
126+
return NULL;
127+
}
128+
115129
/* Function to scan the system for joysticks.
116130
* Joystick 0 should be the system default joystick.
117131
* This function should return 0, or -1 on an unrecoverable error.
@@ -472,15 +486,16 @@ static void WIIU_JoystickUpdate(SDL_Joystick *joystick)
472486
/* touchscreen */
473487
VPADGetTPCalibratedPoint(VPAD_CHAN_0, &tpdata, &vpad.tpNormal);
474488
if (tpdata.touched) {
489+
SDL_Window *window = WIIU_GetGamepadWindow();
475490
if (!last_touched) {
476491
/* Send an initial touch */
477-
SDL_SendTouch(0, 0, NULL, SDL_TRUE,
492+
SDL_SendTouch(0, 0, window, SDL_TRUE,
478493
(float) tpdata.x / 1280.0f,
479494
(float) tpdata.y / 720.0f, 1);
480495
}
481496

482497
/* Always send the motion */
483-
SDL_SendTouchMotion(0, 0, NULL,
498+
SDL_SendTouchMotion(0, 0, window,
484499
(float) tpdata.x / 1280.0f,
485500
(float) tpdata.y / 720.0f, 1);
486501

@@ -489,8 +504,9 @@ static void WIIU_JoystickUpdate(SDL_Joystick *joystick)
489504
last_touch_y = tpdata.y;
490505
last_touched = 1;
491506
} else if (last_touched) {
507+
SDL_Window *window = WIIU_GetGamepadWindow();
492508
/* Finger released from screen */
493-
SDL_SendTouch(0, 0, NULL, SDL_FALSE,
509+
SDL_SendTouch(0, 0, window, SDL_FALSE,
494510
(float) last_touch_x / 1280.0f,
495511
(float) last_touch_y / 720.0f, 1);
496512
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)