@@ -2061,21 +2061,21 @@ static void ConfigureEvdevDevice(char *device)
20612061 {
20622062 bool prioritize = false;
20632063
2064- // Priority logic: Touchscreens override Mice.
2065- // 1. No device set yet? Take it.
2064+ // Priority logic: touchscreens override Mice
2065+ // 1. No device set yet? Take it
20662066 if (platform .mouseFd == -1 ) prioritize = true;
2067- // 2. Current is Mouse, New is Touch ? Upgrade to Touch.
2067+ // 2. Current is mouse, new is touch ? Upgrade to touch
20682068 else if (isTouch && !platform .mouseIsTouch ) prioritize = true;
2069- // 3. Current is Touch, New is Touch ? Use the new one (Last one found wins, standard behavior).
2069+ // 3. Current is touch, new is touch ? Use the new one (last one found wins, standard behavior)
20702070 else if (isTouch && platform .mouseIsTouch ) prioritize = true;
2071- // 4. Current is Mouse, New is Mouse ? Use the new one.
2071+ // 4. Current is mouse, new is mouse ? Use the new one
20722072 else if (!isTouch && !platform .mouseIsTouch ) prioritize = true;
2073- // 5. Current is Touch, New is Mouse? IGNORE the mouse. Keep the touchscreen.
2073+ // 5. Current is touch, new is mouse? Ignore the mouse, keep the touchscreen
20742074 else prioritize = false;
20752075
20762076 if (prioritize )
20772077 {
2078- deviceKindStr = isTouch ? "touchscreen" : "mouse" ;
2078+ deviceKindStr = isTouch ? "touchscreen" : "mouse" ;
20792079
20802080 if (platform .mouseFd != -1 )
20812081 {
@@ -2172,18 +2172,15 @@ static void PollKeyboardEvents(void)
21722172 // If the event was a key, we know a working keyboard is connected, so disable the SSH keyboard
21732173 platform .eventKeyboardMode = true;
21742174#endif
2175-
21762175 // Keyboard keys appear for codes 1 to 255, ignore everthing else
21772176 if ((event .code >= 1 ) && (event .code <= 255 ))
21782177 {
2179-
21802178 // Lookup the scancode in the keymap to get a keycode
21812179 keycode = linuxToRaylibMap [event .code ];
21822180
21832181 // Make sure we got a valid keycode
21842182 if ((keycode > 0 ) && (keycode < MAX_KEYBOARD_KEYS ))
21852183 {
2186-
21872184 // WARNING: https://www.kernel.org/doc/Documentation/input/input.txt
21882185 // Event interface: 'value' is the value the event carries. Either a relative change for EV_REL,
21892186 // absolute new value for EV_ABS (joysticks ...), or 0 for EV_KEY for release, 1 for keypress and 2 for autorepeat
@@ -2232,16 +2229,15 @@ static void PollGamepadEvents(void)
22322229 {
22332230 if (event .code < KEYMAP_SIZE )
22342231 {
2235- short keycodeRaylib = linuxToRaylibMap [event .code ];
2232+ short keycode = linuxToRaylibMap [event .code ]; // raylib keycode
22362233
2237- TRACELOG (LOG_DEBUG , "INPUT: Gamepad %2i: KEY_%s Keycode(linux): %4i Keycode(raylib): %4i" , i , (event .value == 0 )? "UP" : "DOWN" , event .code , keycodeRaylib );
2234+ TRACELOG (LOG_DEBUG , "INPUT: Gamepad %2i: KEY_%s Keycode(linux): %4i Keycode(raylib): %4i" , i , (event .value == 0 )? "UP" : "DOWN" , event .code , keycode );
22382235
2239- if ((keycodeRaylib != 0 ) && (keycodeRaylib < MAX_GAMEPAD_BUTTONS ))
2236+ if ((keycode != 0 ) && (keycode < MAX_GAMEPAD_BUTTONS ))
22402237 {
22412238 // 1 - button pressed, 0 - button released
2242- CORE .Input .Gamepad .currentButtonState [i ][keycodeRaylib ] = event .value ;
2243-
2244- CORE .Input .Gamepad .lastButtonPressed = (event .value == 1 )? keycodeRaylib : GAMEPAD_BUTTON_UNKNOWN ;
2239+ CORE .Input .Gamepad .currentButtonState [i ][keycode ] = event .value ;
2240+ CORE .Input .Gamepad .lastButtonPressed = (event .value == 1 )? keycode : GAMEPAD_BUTTON_UNKNOWN ;
22452241 }
22462242 }
22472243 }
@@ -2323,7 +2319,7 @@ static void PollMouseEvents(void)
23232319 CORE .Input .Mouse .currentPosition .x = (event .value - platform .absRange .x )* CORE .Window .screen .width /platform .absRange .width ; // Scale according to absRange
23242320
23252321 // Update single touch position only if it's active and no MT events are being used
2326- if (( platform .touchActive [0 ]) && ( !isMultitouch ) )
2322+ if (platform .touchActive [0 ] && !isMultitouch )
23272323 {
23282324 platform .touchPosition [0 ].x = (event .value - platform .absRange .x )* CORE .Window .screen .width /platform .absRange .width ;
23292325 if (touchAction == -1 ) touchAction = 2 ; // TOUCH_ACTION_MOVE
@@ -2335,24 +2331,24 @@ static void PollMouseEvents(void)
23352331 CORE .Input .Mouse .currentPosition .y = (event .value - platform .absRange .y )* CORE .Window .screen .height /platform .absRange .height ; // Scale according to absRange
23362332
23372333 // Update single touch position only if it's active and no MT events are being used
2338- if (( platform .touchActive [0 ]) && ( !isMultitouch ) )
2334+ if (platform .touchActive [0 ] && !isMultitouch )
23392335 {
23402336 platform .touchPosition [0 ].y = (event .value - platform .absRange .y )* CORE .Window .screen .height /platform .absRange .height ;
23412337 if (touchAction == -1 ) touchAction = 2 ; // TOUCH_ACTION_MOVE
23422338 }
23432339 }
23442340
23452341 // Multitouch movement
2346- if (( event .code ) == ( ABS_MT_SLOT ) )
2342+ if (event .code == ABS_MT_SLOT )
23472343 {
23482344 platform .touchSlot = event .value ;
23492345 isMultitouch = true;
23502346 }
23512347
2352- if (( event .code ) == ( ABS_MT_POSITION_X ) )
2348+ if (event .code == ABS_MT_POSITION_X )
23532349 {
23542350 isMultitouch = true;
2355- if (( platform .touchSlot ) < ( MAX_TOUCH_POINTS ))
2351+ if (platform .touchSlot < MAX_TOUCH_POINTS )
23562352 {
23572353 platform .touchPosition [platform .touchSlot ].x = (event .value - platform .absRange .x )* CORE .Window .screen .width /platform .absRange .width ;
23582354
@@ -2362,9 +2358,9 @@ static void PollMouseEvents(void)
23622358 }
23632359 }
23642360
2365- if (( event .code ) == ( ABS_MT_POSITION_Y ) )
2361+ if (event .code == ABS_MT_POSITION_Y )
23662362 {
2367- if (( platform .touchSlot ) < ( MAX_TOUCH_POINTS ))
2363+ if (platform .touchSlot < MAX_TOUCH_POINTS )
23682364 {
23692365 platform .touchPosition [platform .touchSlot ].y = (event .value - platform .absRange .y )* CORE .Window .screen .height /platform .absRange .height ;
23702366
@@ -2374,17 +2370,17 @@ static void PollMouseEvents(void)
23742370 }
23752371 }
23762372
2377- if (( event .code ) == ( ABS_MT_TRACKING_ID ) )
2373+ if (event .code == ABS_MT_TRACKING_ID )
23782374 {
2379- if (( platform .touchSlot ) < ( MAX_TOUCH_POINTS ) )
2375+ if (platform .touchSlot < MAX_TOUCH_POINTS )
23802376 {
23812377 if (event .value >= 0 )
23822378 {
23832379
23842380 platform .touchActive [platform .touchSlot ] = true;
23852381 platform .touchId [platform .touchSlot ] = event .value ; // Use Tracking ID for unique IDs
23862382
2387- touchAction = 1 ; // TOUCH_ACTION_DOWN
2383+ touchAction = 1 ; // TOUCH_ACTION_DOWN
23882384 }
23892385 else
23902386 {
@@ -2396,49 +2392,47 @@ static void PollMouseEvents(void)
23962392
23972393 // Force UP action if we haven't already set a DOWN action
23982394 // (DOWN takes priority over UP if both happen in one frame, though rare)
2399- if (touchAction != 1 ) touchAction = 0 ; // TOUCH_ACTION_UP
2395+ if (touchAction != 1 ) touchAction = 0 ; // TOUCH_ACTION_UP
24002396 }
24012397 }
24022398 }
24032399
24042400 // Handle ABS_MT_PRESSURE (0x3a) if available, as some devices use it for lift-off
24052401 #ifndef ABS_MT_PRESSURE
2406- #define ABS_MT_PRESSURE 0x3a
2402+ #define ABS_MT_PRESSURE 0x3a
24072403 #endif
2408- if (( event .code ) == ( ABS_MT_PRESSURE ) )
2404+ if (event .code == ABS_MT_PRESSURE )
24092405 {
2410- if (( platform .touchSlot ) < ( MAX_TOUCH_POINTS ) )
2406+ if (platform .touchSlot < MAX_TOUCH_POINTS )
24112407 {
24122408 if (event .value <= 0 ) // Pressure 0 means lift
24132409 {
24142410 platform .touchActive [platform .touchSlot ] = false;
24152411 platform .touchPosition [platform .touchSlot ].x = -1 ;
24162412 platform .touchPosition [platform .touchSlot ].y = -1 ;
24172413 platform .touchId [platform .touchSlot ] = -1 ;
2418- if (touchAction != 1 ) touchAction = 0 ; // TOUCH_ACTION_UP
2414+ if (touchAction != 1 ) touchAction = 0 ; // TOUCH_ACTION_UP
24192415 }
24202416 }
24212417 }
24222418
24232419 // Touchscreen tap
2424- if (( event .code ) == ( ABS_PRESSURE ) )
2420+ if (event .code == ABS_PRESSURE )
24252421 {
24262422 int previousMouseLeftButtonState = platform .currentButtonStateEvdev [MOUSE_BUTTON_LEFT ];
24272423
2428- if (( !event .value ) && ( previousMouseLeftButtonState ) )
2424+ if (!event .value && previousMouseLeftButtonState )
24292425 {
24302426 platform .currentButtonStateEvdev [MOUSE_BUTTON_LEFT ] = 0 ;
2431-
2432- if (touchAction != 1 ) touchAction = 0 ; // TOUCH_ACTION_UP
2427+ if (touchAction != 1 ) touchAction = 0 ; // TOUCH_ACTION_UP
24332428 }
24342429
2435- if (( event .value ) && ( !previousMouseLeftButtonState ) )
2430+ if (event .value && !previousMouseLeftButtonState )
24362431 {
24372432 platform .currentButtonStateEvdev [MOUSE_BUTTON_LEFT ] = 1 ;
2438- touchAction = 1 ; // TOUCH_ACTION_DOWN
2433+ touchAction = 1 ; // TOUCH_ACTION_DOWN
24392434 }
24402435 }
2441-
24422436 }
24432437
24442438 // Button parsing
@@ -2453,16 +2447,15 @@ static void PollMouseEvents(void)
24532447 {
24542448 bool activateSlot0 = false;
24552449
2456- if (event .code == BTN_LEFT )
2457- {
2458- activateSlot0 = true; // Mouse click always activates
2459- }
2450+ if (event .code == BTN_LEFT ) activateSlot0 = true; // Mouse click always activates
24602451 else if (event .code == BTN_TOUCH )
24612452 {
24622453 bool anyActive = false;
2463- for (int i = 0 ; i < MAX_TOUCH_POINTS ; i ++ ) {
2454+ for (int i = 0 ; i < MAX_TOUCH_POINTS ; i ++ )
2455+ {
24642456 if (platform .touchActive [i ]) { anyActive = true; break ; }
24652457 }
2458+
24662459 if (!anyActive ) activateSlot0 = true;
24672460 }
24682461
@@ -2472,7 +2465,7 @@ static void PollMouseEvents(void)
24722465 platform .touchId [0 ] = 0 ;
24732466 }
24742467
2475- touchAction = 1 ; // TOUCH_ACTION_DOWN
2468+ touchAction = 1 ; // TOUCH_ACTION_DOWN
24762469 }
24772470 else
24782471 {
@@ -2483,10 +2476,8 @@ static void PollMouseEvents(void)
24832476 platform .touchPosition [0 ].x = -1 ;
24842477 platform .touchPosition [0 ].y = -1 ;
24852478 }
2486- else if (event .code == BTN_TOUCH )
2487- {
2488- platform .touchSlot = 0 ; // Reset slot index to 0
2489- }
2479+ else if (event .code == BTN_TOUCH ) platform .touchSlot = 0 ; // Reset slot index to 0
2480+
24902481 touchAction = 0 ; // TOUCH_ACTION_UP
24912482 }
24922483 }
@@ -2503,10 +2494,12 @@ static void PollMouseEvents(void)
25032494 if (!CORE .Input .Mouse .cursorLocked )
25042495 {
25052496 if (CORE .Input .Mouse .currentPosition .x < 0 ) CORE .Input .Mouse .currentPosition .x = 0 ;
2506- if (CORE .Input .Mouse .currentPosition .x > CORE .Window .screen .width /CORE .Input .Mouse .scale .x ) CORE .Input .Mouse .currentPosition .x = CORE .Window .screen .width /CORE .Input .Mouse .scale .x ;
2497+ if (CORE .Input .Mouse .currentPosition .x > CORE .Window .screen .width /CORE .Input .Mouse .scale .x )
2498+ CORE .Input .Mouse .currentPosition .x = CORE .Window .screen .width /CORE .Input .Mouse .scale .x ;
25072499
25082500 if (CORE .Input .Mouse .currentPosition .y < 0 ) CORE .Input .Mouse .currentPosition .y = 0 ;
2509- if (CORE .Input .Mouse .currentPosition .y > CORE .Window .screen .height /CORE .Input .Mouse .scale .y ) CORE .Input .Mouse .currentPosition .y = CORE .Window .screen .height /CORE .Input .Mouse .scale .y ;
2501+ if (CORE .Input .Mouse .currentPosition .y > CORE .Window .screen .height /CORE .Input .Mouse .scale .y )
2502+ CORE .Input .Mouse .currentPosition .y = CORE .Window .screen .height /CORE .Input .Mouse .scale .y ;
25102503 }
25112504
25122505 // Repack active touches into CORE.Input.Touch
@@ -2520,6 +2513,7 @@ static void PollMouseEvents(void)
25202513 k ++ ;
25212514 }
25222515 }
2516+
25232517 CORE .Input .Touch .pointCount = k ;
25242518
25252519 // Clear remaining slots
@@ -2529,20 +2523,11 @@ static void PollMouseEvents(void)
25292523 CORE .Input .Touch .position [i ].y = -1 ;
25302524 CORE .Input .Touch .pointId [i ] = -1 ;
25312525 }
2532-
2533- // Debug logging
2534- static int lastTouchCount = 0 ;
2535- if (CORE .Input .Touch .pointCount != lastTouchCount && (touchAction == 0 || touchAction == 1 ))
2536- {
2537- TRACELOG (LOG_DEBUG , "TOUCH: Count changed from %d to %d (action: %d)" , lastTouchCount , CORE .Input .Touch .pointCount , touchAction );
2538- lastTouchCount = CORE .Input .Touch .pointCount ;
2539- }
25402526
25412527#if defined(SUPPORT_GESTURES_SYSTEM )
25422528 if (touchAction > -1 )
25432529 {
25442530 GestureEvent gestureEvent = { 0 };
2545-
25462531 gestureEvent .touchAction = touchAction ;
25472532 gestureEvent .pointCount = CORE .Input .Touch .pointCount ;
25482533
@@ -2553,7 +2538,6 @@ static void PollMouseEvents(void)
25532538 }
25542539
25552540 ProcessGestureEvent (gestureEvent );
2556-
25572541 touchAction = -1 ;
25582542 }
25592543#endif
0 commit comments