Skip to content

Commit

Permalink
Mouse wheel events return 'correct' coordinates on SDLn, X11, VT, and…
Browse files Browse the repository at this point in the history
… WinGUI, instead of (-1,-1). See wmcbrine issue 88. DOS, DOSVGA, WinCon, OS/2 (i.e., all other platforms) to follow.
  • Loading branch information
Bill-Gray committed May 12, 2020
1 parent 0036992 commit f4d3037
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 32 deletions.
11 changes: 3 additions & 8 deletions sdl1/pdckbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,13 @@ static int _process_mouse_event(void)
if (keymods & KMOD_ALT)
shift_flags |= BUTTON_ALT;

SP->mouse_status.x = (event.motion.x - pdc_xoffset) / pdc_fwidth;
SP->mouse_status.y = (event.motion.y - pdc_yoffset) / pdc_fheight;

if (event.type == SDL_MOUSEMOTION)
{
int i;

SP->mouse_status.x = (event.motion.x - pdc_xoffset) / pdc_fwidth;
SP->mouse_status.y = (event.motion.y - pdc_yoffset) / pdc_fheight;

if (!event.motion.state ||
(SP->mouse_status.x == old_mouse_status.x &&
SP->mouse_status.y == old_mouse_status.y))
Expand All @@ -250,8 +250,6 @@ static int _process_mouse_event(void)

if ((btn >= 4 && btn <= 7) && action == BUTTON_RELEASED)
{
SP->mouse_status.x = SP->mouse_status.y = -1;

switch (btn)
{
case 4:
Expand Down Expand Up @@ -291,9 +289,6 @@ static int _process_mouse_event(void)
}
}

SP->mouse_status.x = (event.button.x - pdc_xoffset) / pdc_fwidth;
SP->mouse_status.y = (event.button.y - pdc_yoffset) / pdc_fheight;

btn--;

SP->mouse_status.button[btn] = action | shift_flags;
Expand Down
14 changes: 6 additions & 8 deletions sdl2/pdckbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,16 @@ static int _process_mouse_event(void)
if (keymods & KMOD_ALT)
shift_flags |= BUTTON_ALT;

if (event.type == SDL_MOUSEWHEEL)
SDL_GetMouseState( &event.motion.x, &event.motion.y);

SP->mouse_status.x = (event.motion.x - pdc_xoffset) / pdc_fwidth;
SP->mouse_status.y = (event.motion.y - pdc_yoffset) / pdc_fheight;

if (event.type == SDL_MOUSEMOTION)
{
int i;

SP->mouse_status.x = (event.motion.x - pdc_xoffset) / pdc_fwidth;
SP->mouse_status.y = (event.motion.y - pdc_yoffset) / pdc_fheight;

if (!event.motion.state ||
(SP->mouse_status.x == old_mouse_status.x &&
SP->mouse_status.y == old_mouse_status.y))
Expand All @@ -344,8 +347,6 @@ static int _process_mouse_event(void)
}
else if (event.type == SDL_MOUSEWHEEL)
{
SP->mouse_status.x = SP->mouse_status.y = -1;

if (event.wheel.y > 0)
SP->mouse_status.changes = PDC_MOUSE_WHEEL_UP;
else if (event.wheel.y < 0)
Expand Down Expand Up @@ -386,9 +387,6 @@ static int _process_mouse_event(void)
}
}

SP->mouse_status.x = (event.button.x - pdc_xoffset) / pdc_fwidth;
SP->mouse_status.y = (event.button.y - pdc_yoffset) / pdc_fheight;

btn--;

SP->mouse_status.button[btn] = action | shift_flags;
Expand Down
25 changes: 12 additions & 13 deletions wingui/pdcscrn.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,11 +657,6 @@ static int set_mouse( const int button_index, const int button_state,
SP->mouse_status.changes |= PDC_MOUSE_WHEEL_LEFT;
}
}
/* I think it may be that for wheel events, we */
/* return x = y = -1, rather than getting the */
/* actual mouse position. I don't like this, but */
/* I like messing up existing apps even less. */
pt.x = pt.y = -1;
}
}
SP->mouse_status.x = pt.x;
Expand Down Expand Up @@ -1847,15 +1842,19 @@ static LRESULT ALIGN_STACK CALLBACK WndProc (const HWND hwnd,
return 0 ;

case WM_MOUSEWHEEL:
debug_printf( "Mouse wheel: %x %lx\n", wParam, lParam);
modified_key_to_return = 0;
set_mouse( VERTICAL_WHEEL_EVENT, (short)( HIWORD(wParam)), 0, 0);
break;

case WM_MOUSEHWHEEL:
debug_printf( "Mouse horiz wheel: %x %lx\n", wParam, lParam);
modified_key_to_return = 0;
set_mouse( HORIZONTAL_WHEEL_EVENT, (short)( HIWORD(wParam)), 0, 0);
{
POINT pt;

pt.x = LOWORD( lParam);
pt.y = HIWORD( lParam);
ScreenToClient( hwnd, &pt);
debug_printf( "Mouse wheel: %u %x %lx\n", message, wParam, lParam);
modified_key_to_return = 0;
set_mouse( (message == WM_MOUSEWHEEL)
? VERTICAL_WHEEL_EVENT : HORIZONTAL_WHEEL_EVENT,
(short)( HIWORD(wParam)), pt.x / PDC_cxChar, pt.y / PDC_cyChar);
}
break;

case WM_MOUSEMOVE:
Expand Down
4 changes: 1 addition & 3 deletions x11/pdckbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ static unsigned long _process_mouse_event( const XEvent *event)
{
/* Send the KEY_MOUSE to curses program */

memset(&SP->mouse_status, 0, sizeof(SP->mouse_status));
memset(&SP->mouse_status.button, 0, sizeof(SP->mouse_status.button));

switch(button_no)
{
Expand All @@ -384,8 +384,6 @@ static unsigned long _process_mouse_event( const XEvent *event)
SP->mouse_status.changes = PDC_MOUSE_WHEEL_RIGHT;
}

SP->mouse_status.x = SP->mouse_status.y = -1;

SP->key_code = TRUE;
return KEY_MOUSE;
}
Expand Down

0 comments on commit f4d3037

Please sign in to comment.