Skip to content

Commit

Permalink
remove unneeded unsignedness
Browse files Browse the repository at this point in the history
  • Loading branch information
expikr committed Nov 9, 2024
1 parent fd8b487 commit e227c3b
Showing 1 changed file with 25 additions and 28 deletions.
53 changes: 25 additions & 28 deletions src/video/windows/SDL_windowsmouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ struct SDL_CursorData

typedef struct SDL_MouseData
{
unsigned long long xs[5];
unsigned long long ys[5];
long long xs[5];
long long ys[5];
int last_node;
int ptrspeed;
int ptrscale;
int ptrdenom;
bool enhanced;
Expand Down Expand Up @@ -557,11 +556,11 @@ static void WIN_TransformMouse(void *internal, SDL_Window *window, float *x, flo
return;
}

unsigned long long *xs = &(data->xs[0]);
unsigned long long *ys = &(data->ys[0]);
unsigned int absx = SDL_abs(ix);
unsigned int absy = SDL_abs(iy);
unsigned int speed = SDL_max(absx, absy) + (SDL_min(absx, absy) >> 1); // super cursed approximation used by Windows
long long *xs = data->xs;
long long *ys = data->ys;
long long absx = SDL_abs(ix);
long long absy = SDL_abs(iy);
long long speed = SDL_max(absx, absy) + (SDL_min(absx, absy) >> 1); // super cursed approximation used by Windows
if (speed == 0) return;

int i, j, k;
Expand All @@ -570,7 +569,7 @@ static void WIN_TransformMouse(void *internal, SDL_Window *window, float *x, flo
if (speed < xs[j]) break;
}

unsigned long long slope = ((ys[j] - ys[j-1]) << 16) / (xs[j] - xs[j-1]);
long long slope = ((ys[j] - ys[j-1]) << 16) / (xs[j] - xs[j-1]);
long long inter = ys[i-1] - ((xs[i-1] * slope) >> 16);
long long scale = slope + (inter << 16) / speed;

Expand Down Expand Up @@ -632,25 +631,25 @@ void WIN_QuitMouse(SDL_VideoDevice *_this)
}
}

static bool WIN_SetEnhancedMouseScale(SDL_MouseData *data)
static bool WIN_SetEnhancedMouseScale(int v, long long xs[5], long long ys[5])
{
bool valid = false;
HKEY open_handle;
if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Control Panel\\Mouse", 0, KEY_READ, &open_handle) == ERROR_SUCCESS) {
unsigned long long xs[5];
unsigned long long ys[5];
DWORD xsize = sizeof(xs);
DWORD ysize = sizeof(ys);
if (RegQueryValueExW(open_handle, L"SmoothMouseXCurve", NULL, NULL, (BYTE*)xs, &xsize) == ERROR_SUCCESS &&
RegQueryValueExW(open_handle, L"SmoothMouseYCurve", NULL, NULL, (BYTE*)ys, &ysize) == ERROR_SUCCESS) {
data->xs[0] = 0; // first node must always be origin
data->ys[0] = 0; // first node must always be origin
DWORD xbuff[10];
DWORD ybuff[10];
DWORD xsize = sizeof(xbuff);
DWORD ysize = sizeof(ybuff);
if (RegQueryValueExW(open_handle, L"SmoothMouseXCurve", NULL, NULL, (BYTE*)xbuff, &xsize) == ERROR_SUCCESS &&
RegQueryValueExW(open_handle, L"SmoothMouseYCurve", NULL, NULL, (BYTE*)ybuff, &ysize) == ERROR_SUCCESS) {
xs[0] = 0; // first node must always be origin
ys[0] = 0; // first node must always be origin
valid = true; // we have successfully queried, assume valid curve until checked otherwise
int i;
for (i = 1; i < 5; i++) {
data->xs[i] = ((0xffffffff & xs[i]) * 7) >> 1; // scale domain by 3.5
data->ys[i] = ((0xffffffff & ys[i]) * data->ptrspeed); // scale range by ptrspeed
if (data->xs[i] <= data->xs[i-1]) valid = false; // x is out of order, curve is invalid
xs[i] = (7 * (long long)xbuff[i*2]) >> 1; // scale domain by 3.5
ys[i] = (v * (long long)ybuff[i*2]); // scale range by ptrspeed
if (xs[i] <= xs[i-1]) valid = false; // x is out of order, curve is invalid
}
}
RegCloseKey(open_handle);
Expand All @@ -673,17 +672,15 @@ void WIN_UpdateMouseSystemScale(void)
SDL_MouseData *data = (SDL_MouseData *)mouse->internal;
data->ptrdenom = 10 * 120; // TODO: 10 * (is_win8_or_above ? 120 : 150);
data->ptrscale = 1 << 5;
data->ptrspeed = 10;
data->enhanced = false;

int x;
int v;
int params[3];
if (SystemParametersInfo(SPI_GETMOUSESPEED, 0, &x, 0) &&
if (SystemParametersInfo(SPI_GETMOUSESPEED, 0, &v, 0) &&
SystemParametersInfo(SPI_GETMOUSE, 0, &params, 0)) {
x = SDL_max(1, SDL_min(x, 20));
data->ptrspeed = x;
data->ptrscale = SDL_max(SDL_max(x, (x - 2) << 2), (x - 6) << 3);
data->enhanced = params[2] ? WIN_SetEnhancedMouseScale(data) : false;
v = SDL_max(1, SDL_min(v, 20));
data->ptrscale = SDL_max(SDL_max(v, (v - 2) << 2), (v - 6) << 3);
data->enhanced = params[2] ? WIN_SetEnhancedMouseScale(v, data->xs, data->ys) : false;
}
}

Expand Down

0 comments on commit e227c3b

Please sign in to comment.