Skip to content

win32: fire timers and redisplay while a window is moved or sized - #255

Open
danjboyd wants to merge 1 commit into
gnustep:masterfrom
danjboyd:win32-sizemove-timers-upstream
Open

danjboyd wants to merge 1 commit into
gnustep:masterfrom
danjboyd:win32-sizemove-timers-upstream

Conversation

@danjboyd

Copy link
Copy Markdown
Contributor

Upstream policy: checked gnustep/libs-back for contribution documents. It has no CONTRIBUTING, code of conduct, issue or PR template (GitHub community profile: https://github.com/gnustep/libs-back/community; README: https://github.com/gnustep/libs-back/blob/master/README). Two GNUstep-wide documents apply:

How this complies:

  • Copyright assignment: my FSF assignment for GNUstep is pending, not yet final. The contribution page says patches can sometimes be accepted before final approval if we talk to you first, so I'm asking here: can this be reviewed and accepted while the assignment completes, or would you rather wait for it?
  • AI policy:
    • The change includes a test (Tests/win32/sizemove.m) with what it tests, why that is enough, and what it guards against. The test fails without the change and passes with it.
    • The code is GCC-safe: no blocks, literals, dot syntax or @autoreleasepool, and a GCC syntax check is clean.
    • The commit message and this description disclose AI assistance.
    • Every number below comes from runs made for this item.
  • Form: a ChangeLog entry is included, as libs-back's history uses, and it is one commit on current master.

On Windows, moving or sizing a window runs Windows' own modal loop inside DefWindowProc (WM_SYSCOMMAND SC_MOVE/SC_SIZE) until the drag ends. For that whole time the GNUstep run loop doesn't run in any mode: NSTimers don't fire and nothing is redisplayed. So an indeterminate NSProgressIndicator, or any timer-driven animation, freezes while the user drags or resizes a window.

Change

  • On WM_ENTERSIZEMOVE, start a 15 ms Win32 timer for the window; on WM_EXITSIZEMOVE, kill it.
  • On that WM_TIMER:
    • fire the run loop's due timers in its current mode with -limitDateForMode:, which polls no input sources, so Windows' loop keeps its own messages;
    • then -displayIfNeeded the visible windows that need it.
  • The timer is guarded against reentry, and an exception from a timer is logged rather than unwinding through DefWindowProc.
  • A timer may start a nested event loop (a modal panel). That loop would take the drag's input from under Windows' loop. So when a nested loop first asks for an event (-getEventMatchingMask:...) while the timer is pumping, the drag is cancelled with WM_CANCELMODE, as Escape would, and Windows' loop ends once the timer returns.
  • ChangeLog entry included.

Testing

New Tests/win32/sizemove.m. The directory's GNUmakefile.preamble and source guard skip it on every other backend. The test posts its window WM_SYSCOMMAND SC_MOVE (a keyboard move, so no mouse is needed) from a second thread, watches GetGUIThreadInfo's GUI_INMOVESIZE, and ends the loop with Escape. It skips when Windows doesn't enter the loop (no interactive desktop).

  • timers during a move loop: the window stays in the loop for a second, a 20 ms default-mode timer fires at least 25 times there, and Escape still ends the loop. This guards against timers stopping during a drag, and against the timer taking the loop's own input.
  • a modal panel started by a timer during a move loop: a timer opens a modal panel only while the window is in the loop. The panel must run and return, the drag must be over once it has, and no loop may be left running. This guards against a nested loop taking the drag's input.

On master (2c7d5f1), 4 of the 7 checks fail; with this change, all 7 pass. Both runs were on Windows 11 build 26300, MSYS2 CLANG64, clang 21.1.8, against libs-base master 220f7bdce and libs-gui master 662f89071. The test fails rather than hangs without the change. Results of the whole libs-back suite (make check) on that stack:

  • master: 248 passed, 1 failed test, 1 failed file;
  • with the change: 255 passed, 1 failed test, 1 failed file.
    The +7 are the new checks. The failures are the same in both: pdfps.m times out, and surfacedevice.m:64.

A separate test program measured 3 s in each loop, at 96 DPI, on libs-gui 0.32.0 with the same change applied to a 0.32.0 backend. A timer-driven progress indicator drew once without the change and 37 times with it, the same as outside the loop. In 20 runs where a timer opened a modal panel in the middle of a drag, there were no hangs and no lost Escape, and every drag ended before the Escape was sent.

GCC (MinGW GCC 16.2, Objective-C front end, syntax only) reports nothing new in the changed files.

Not covered

  • An indicator using threaded animation still freezes. Its -setNeedsDisplay: reaches the main thread as a queued -performSelectorOnMainThread:, which only -acceptInputForMode: runs, and that would also poll Windows' input. Covering it would need a way to run main-thread performers without polling input (libs-base), which is left for later.
  • A mouse-driven drag (ended by button-up) isn't in the test, which can't press a button; the keyboard move runs the same loop.

AI assistance: this change, its test and this description were written with Claude (Anthropic's Claude Code).

Moving or sizing a window runs Windows' own modal loop inside
DefWindowProc (WM_SYSCOMMAND SC_MOVE/SC_SIZE) until the drag ends.  For
that whole time the run loop doesn't run in any mode: NSTimers don't
fire and nothing is redisplayed, so an indeterminate NSProgressIndicator
or any timer-driven animation freezes while the user drags or resizes a
window.

A Win32 timer, set on WM_ENTERSIZEMOVE and killed on WM_EXITSIZEMOVE,
now fires the run loop's due timers in its current mode
(-limitDateForMode:, which polls no input sources, so Windows' loop
keeps its own messages) and redisplays the windows that need it.  It is
guarded against reentry, and an exception from a timer is logged rather
than unwinding through DefWindowProc.

A timer may itself start a nested event loop (a modal panel, say).  That
loop would take the drag's input from under Windows' loop, so a later
Escape or button-up never reached the drag.  When a nested loop first
asks for an event (-getEventMatchingMask:...) while the timer is
pumping, the drag is cancelled with WM_CANCELMODE, as if Escape were
pressed; Windows' loop ends once the timer returns.

Testing: Tests/win32/sizemove.m (new; the directory's tests skip on
every other backend).  It posts its window WM_SYSCOMMAND SC_MOVE, a
keyboard move that needs no mouse, from a second thread, which watches
GetGUIThreadInfo's GUI_INMOVESIZE flag and ends the loop with Escape.
It skips when Windows doesn't enter the loop (no interactive desktop).
- "timers during a move loop": the window stays in the loop for a
  second, a 20 ms default-mode timer fires at least 25 times in it, and
  Escape still ends it.  This guards against timers stopping during a
  drag, and against the timer taking the loop's own input.
- "a modal panel started by a timer during a move loop": a timer opens
  a modal panel only while the window is in the loop.  The panel must
  run and return, the drag must be over once it has, and no loop may be
  left running.  This guards against a nested loop taking the drag's
  input.
On master (2c7d5f1) 4 of the 7 checks fail: no ticks in the loop, so
no panel during the drag; with this change all 7 pass.  Both runs were
on Windows 11 build 26300, MSYS2 CLANG64, clang 21.1.8, against
libs-base master 220f7bdce and libs-gui master 662f89071.  The test is
written to fail rather than hang without the change.

Measured with a separate test program over 3 s in each loop, at 96 DPI,
on libs-gui 0.32.0 with the same change applied to the 0.32.0.5 backend
we ship: a timer-driven progress indicator drew once without the change
and 37 times with it, the same as outside the loop.  In 20 runs where a
timer opened a modal panel in the middle of a drag: no hangs, no lost
Escape, and every drag ended before the Escape was sent.

Not covered: an indicator using threaded animation still freezes.  Its
-setNeedsDisplay: reaches the main thread as a queued
-performSelectorOnMainThread:, which only -acceptInputForMode: runs, and
that would also poll Windows' input.  A mouse-driven drag, which
Windows ends on button-up, isn't tested, as the test can't press a
button; the keyboard move runs the same loop.

AI assistance: this change, its test and this description were written
with Claude (Anthropic's Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@danjboyd
danjboyd requested a review from fredkiefer as a code owner November 12, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant