diff options
author | Po Lu <luangruo@yahoo.com> | 2022-09-30 14:54:15 +0800 |
---|---|---|
committer | Po Lu <luangruo@yahoo.com> | 2022-09-30 14:54:24 +0800 |
commit | 12a78711c94ccf5c46dd4e9653596c87b6fe0a18 (patch) | |
tree | 0b071cec0b9fe1b8dbcb183cfc71fe8fb8e14332 /src/xterm.c | |
parent | b7a3770ecc5da938c37cfcc50a69902aa57bf2bf (diff) | |
download | emacs-12a78711c94ccf5c46dd4e9653596c87b6fe0a18.tar.gz emacs-12a78711c94ccf5c46dd4e9653596c87b6fe0a18.tar.bz2 emacs-12a78711c94ccf5c46dd4e9653596c87b6fe0a18.zip |
Fix calculation of frame times when X server time overflows
* etc/TODO: Add TODO about frame synchronization and animations.
* src/xterm.c (x_display_set_last_user_time): Handle cases when
the monotonic time is not the server time due to the latter
overflowing.
Diffstat (limited to 'src/xterm.c')
-rw-r--r-- | src/xterm.c | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/xterm.c b/src/xterm.c index cb5d540dd3f..947cf7edb54 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -7607,6 +7607,11 @@ static void x_display_set_last_user_time (struct x_display_info *dpyinfo, Time time, bool send_event) { +#if defined HAVE_XSYNC && !defined USE_GTK && defined HAVE_CLOCK_GETTIME + uint_fast64_t monotonic_time; + uint_fast64_t monotonic_ms; + int_fast64_t diff_ms; +#endif #ifndef USE_GTK struct frame *focus_frame; Time old_time; @@ -7627,9 +7632,8 @@ x_display_set_last_user_time (struct x_display_info *dpyinfo, Time time, { /* See if the current CLOCK_MONOTONIC time is reasonably close to the X server time. */ - uint_fast64_t monotonic_time = x_sync_current_monotonic_time (); - uint_fast64_t monotonic_ms = monotonic_time / 1000; - int_fast64_t diff_ms; + monotonic_time = x_sync_current_monotonic_time (); + monotonic_ms = monotonic_time / 1000; dpyinfo->server_time_monotonic_p = (monotonic_time != 0 @@ -7647,6 +7651,27 @@ x_display_set_last_user_time (struct x_display_info *dpyinfo, Time time, monotonic_time, &dpyinfo->server_time_offset)) dpyinfo->server_time_offset = 0; + + /* If the server time is reasonably close to the monotonic + time after the latter is truncated to CARD32, simply make + the offset that between the server time in ms and the + actual time in ms. */ + + monotonic_ms = monotonic_ms & 0xffffffff; + if (!INT_SUBTRACT_WRAPV (time, monotonic_ms, &diff_ms) + && -500 < diff_ms && diff_ms < 500) + { + /* The server timestamp overflowed. Make the time + offset exactly how much it overflowed by. */ + + if (INT_SUBTRACT_WRAPV (monotonic_time / 1000, monotonic_ms, + &dpyinfo->server_time_offset) + || INT_MULTIPLY_WRAPV (dpyinfo->server_time_offset, + 1000, &dpyinfo->server_time_offset) + || INT_SUBTRACT_WRAPV (0, dpyinfo->server_time_offset, + &dpyinfo->server_time_offset)) + dpyinfo->server_time_offset = 0; + } } } #endif |