Skip to content

Commit

Permalink
engine: client: fix inconsistent mouse state caused by mis-use of tou…
Browse files Browse the repository at this point in the history
…ch_emulate by cs16-client
  • Loading branch information
a1batross committed Feb 23, 2025
1 parent 8b9a40f commit ccf342f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
29 changes: 10 additions & 19 deletions engine/client/in_touch.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ static CVAR_DEFINE_AUTO( touch_dpad_radius, "1.0", FCVAR_FILTERABLE, "dpad radiu
static CVAR_DEFINE_AUTO( touch_joy_radius, "1.0", FCVAR_FILTERABLE, "joy radius multiplier" );
static CVAR_DEFINE_AUTO( touch_move_indicator, "0.0", FCVAR_FILTERABLE, "indicate move events (0 to disable)" );
static CVAR_DEFINE_AUTO( touch_joy_texture, "touch_default/joy", FCVAR_FILTERABLE, "texture for move indicator");
static CVAR_DEFINE_AUTO( touch_emulate, "0", FCVAR_PRIVILEGED, "emulate touch with mouse" );
static CVAR_DEFINE( touch_emulate, "_touch_emulate", "0", FCVAR_PRIVILEGED, "emulate touch with mouse" );
CVAR_DEFINE_AUTO( touch_enable, DEFAULT_TOUCH_ENABLE, FCVAR_ARCHIVE | FCVAR_FILTERABLE, "enable touch controls" );

// code looks smaller with it
Expand Down Expand Up @@ -536,9 +536,15 @@ void Touch_SetClientOnly( byte state )
touch.forward = touch.side = 0;

if( state )
{
Platform_SetCursorType( dc_arrow );
IN_DeactivateMouse();
}
else
{
Platform_SetCursorType( dc_none );
IN_ActivateMouse();
}
}

static void Touch_SetClientOnly_f( void )
Expand Down Expand Up @@ -2182,14 +2188,8 @@ void Touch_KeyEvent( int key, int down )
float x, y;
int finger, xi, yi;

if( !Touch_Emulated( ))
{
if( touch_enable.value )
return;

if( !touch.clientonly )
return;
}
if( !Touch_WantVisibleCursor( ))
return;

if( !key )
{
Expand All @@ -2214,10 +2214,6 @@ void Touch_KeyEvent( int key, int down )
}
}

// don't deactivate mouse in game
// checking a case when mouse and touchscreen
// can be used simultaneously
Platform_SetCursorType( dc_arrow );
Platform_GetMousePos( &xi, &yi );

x = xi / (float)refState.width;
Expand All @@ -2233,12 +2229,7 @@ void Touch_KeyEvent( int key, int down )

qboolean Touch_WantVisibleCursor( void )
{
return ( touch_enable.value && touch_emulate.value ) || touch.clientonly;
}

qboolean Touch_Emulated( void )
{
return touch_emulate.value || touch_in_menu.value;
return ( touch_enable.value && touch_emulate.value ) || touch.clientonly || touch_in_menu.value;
}

void Touch_Shutdown( void )
Expand Down
4 changes: 2 additions & 2 deletions engine/client/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ static void IN_MouseMove( void )
if( !in_mouseinitialized )
return;

if( Touch_Emulated( ))
if( Touch_WantVisibleCursor( ))
{
// touch emulation overrides all input
Touch_KeyEvent( 0, 0 );
Expand Down Expand Up @@ -363,7 +363,7 @@ void IN_MouseEvent( int key, int down )
else ClearBits( in_mstate, BIT( key ));

// touch emulation overrides all input
if( Touch_Emulated( ))
if( Touch_WantVisibleCursor( ))
{
Touch_KeyEvent( K_MOUSE1 + key, down );
}
Expand Down
1 change: 0 additions & 1 deletion engine/client/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ void Touch_ResetDefaultButtons( void );
int IN_TouchEvent( touchEventType type, int fingerID, float x, float y, float dx, float dy );
void Touch_KeyEvent( int key, int down );
qboolean Touch_WantVisibleCursor( void );
qboolean Touch_Emulated( void );
void Touch_NotifyResize( void );

//
Expand Down
2 changes: 1 addition & 1 deletion engine/platform/sdl/in_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ void Platform_SetCursorType( VGUI_DefaultCursor type )
}

// never disable cursor in touch emulation mode
if( !visible && Touch_Emulated( ))
if( !visible && Touch_WantVisibleCursor( ))
return;

host.mouse_visible = visible;
Expand Down

0 comments on commit ccf342f

Please sign in to comment.