Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 52 additions & 12 deletions input/drivers/winraw_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,39 @@ typedef struct
unsigned mouse_cnt;
uint8_t kb_keys[SC_LAST];
uint8_t flags;
bool last_focus;
} winraw_input_t;

/* TODO/FIXME - static globals */
static winraw_mouse_t *g_mice = NULL;
static bool winraw_focus = false;

/* Sync internal mouse coordinates with the OS cursor position.
* Used after events such as window mode, size, and focus changes */
static bool winraw_sync_mouse_to_cursor(winraw_input_t *wr)
{
HWND wnd;
POINT p;
unsigned i;

if (!wr || !wr->mouse_cnt)
return false;

wnd = (HWND)video_driver_window_get();
if (!wnd || !GetCursorPos(&p))
return false;

ScreenToClient(wnd, &p);

for (i = 0; i < wr->mouse_cnt; ++i)
{
g_mice[i].x = (LONG)p.x;
g_mice[i].y = (LONG)p.y;
}

return true;
}

#define WINRAW_KEYBOARD_PRESSED(wr, key) (wr->kb_keys[rarch_keysym_lut[(enum retro_key)(key)]])

static HWND winraw_create_window(WNDPROC wnd_proc)
Expand Down Expand Up @@ -290,24 +317,31 @@ static bool winraw_mouse_button_pressed(
static void winraw_init_mouse_xy_mapping(winraw_input_t *wr)
{
struct video_viewport viewport;
int mouse_x;
int mouse_y;
unsigned i;

if (video_driver_get_viewport_info(&viewport))
{
unsigned i;
int center_x = viewport.x + viewport.width / 2;
int center_y = viewport.y + viewport.height / 2;
if (!video_driver_get_viewport_info(&viewport))
return;

for (i = 0; i < wr->mouse_cnt; ++i)
/* Default fallback: center of the viewport */
mouse_x = viewport.x + viewport.width / 2;
mouse_y = viewport.y + viewport.height / 2;

/* Sync to OS cursor position; fall back to center if it fails */
if (!winraw_sync_mouse_to_cursor(wr))
{
for (i = 0; i < wr->mouse_cnt; i++)
{
g_mice[i].x = center_x;
g_mice[i].y = center_y;
g_mice[i].x = mouse_x;
g_mice[i].y = mouse_y;
}
}

wr->view_abs_ratio_x = (double)viewport.full_width / 65535.0f;
wr->view_abs_ratio_y = (double)viewport.full_height / 65535.0f;
wr->view_abs_ratio_x = (double)viewport.full_width / 65535.0;
wr->view_abs_ratio_y = (double)viewport.full_height / 65535.0;

wr->flags |= WRAW_INP_FLG_MOUSE_XY_MAPPING_READY;
}
wr->flags |= WRAW_INP_FLG_MOUSE_XY_MAPPING_READY;
}

static void winraw_update_mouse_state(winraw_input_t *wr,
Expand Down Expand Up @@ -635,6 +669,12 @@ static void winraw_poll(void *data)
unsigned i;
winraw_input_t *wr = (winraw_input_t*)data;

/* Sync coordinates when window regains focus */
if (winraw_focus && !wr->last_focus)
winraw_sync_mouse_to_cursor(wr);

wr->last_focus = winraw_focus;

for (i = 0; i < wr->mouse_cnt; ++i)
{
/* Clear buttons when not focused */
Expand Down
Loading