Skip to content

Commit 005cb20

Browse files
committed
wayland: Use defines for timer rollover constants
"static const" being treated as constant in C is an extension that is not always supported, so use defines instead.
1 parent c6935f9 commit 005cb20

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/video/wayland/SDL_waylandevents.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@
8989
// Focus clickthrough timeout
9090
#define WAYLAND_FOCUS_CLICK_TIMEOUT_NS SDL_MS_TO_NS(10)
9191

92+
// Timer rollover detection thresholds
93+
#define WAYLAND_TIMER_ROLLOVER_INTERVAL_LOW (SDL_MAX_UINT32 / 16U)
94+
#define WAYLAND_TIMER_ROLLOVER_INTERVAL_HIGH (WAYLAND_TIMER_ROLLOVER_INTERVAL_LOW * 15U)
95+
9296
// Scoped function declarations
9397
static void Wayland_SeatUpdateKeyboardGrab(SDL_WaylandSeat *seat);
9498

@@ -215,15 +219,12 @@ static Uint64 Wayland_AdjustEventTimestampBase(Uint64 nsTimestamp)
215219
*/
216220
static Uint64 Wayland_EventTimestampMSToNS(Uint32 wl_timestamp_ms)
217221
{
218-
static const Uint32 ROLLOVER_INTERVAL_LOW = SDL_MAX_UINT32 / 16;
219-
static const Uint32 ROLLOVER_INTERVAL_HIGH = ROLLOVER_INTERVAL_LOW * 15;
220-
221222
static Uint64 timestamp_offset = 0;
222223
static Uint32 last = 0;
223224
Uint64 timestamp = SDL_MS_TO_NS(wl_timestamp_ms) + timestamp_offset;
224225

225226
if (wl_timestamp_ms >= last) {
226-
if (timestamp_offset && last < ROLLOVER_INTERVAL_LOW && wl_timestamp_ms > ROLLOVER_INTERVAL_HIGH) {
227+
if (timestamp_offset && last < WAYLAND_TIMER_ROLLOVER_INTERVAL_LOW && wl_timestamp_ms > WAYLAND_TIMER_ROLLOVER_INTERVAL_HIGH) {
227228
// A time that crossed backwards across zero was received. Subtract the increased time base offset.
228229
timestamp -= SDL_MS_TO_NS(SDL_UINT64_C(0x100000000));
229230
} else {
@@ -233,7 +234,7 @@ static Uint64 Wayland_EventTimestampMSToNS(Uint32 wl_timestamp_ms)
233234
/* Only increment the base time offset if the timer actually crossed forward across 0,
234235
* and not if this is just a timestamp from a slightly older event.
235236
*/
236-
if (wl_timestamp_ms < ROLLOVER_INTERVAL_LOW && last > ROLLOVER_INTERVAL_HIGH) {
237+
if (wl_timestamp_ms < WAYLAND_TIMER_ROLLOVER_INTERVAL_LOW && last > WAYLAND_TIMER_ROLLOVER_INTERVAL_HIGH) {
237238
timestamp_offset += SDL_MS_TO_NS(SDL_UINT64_C(0x100000000));
238239
timestamp += SDL_MS_TO_NS(SDL_UINT64_C(0x100000000));
239240
last = wl_timestamp_ms;

0 commit comments

Comments
 (0)