Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
2026-11-11 Daniel Boyd <danieljboyd@icloud.com>

* Source/win32/w32_movesize.m:
* Source/win32/WIN32Server.m:
* Headers/win32/WIN32Server.h:
Fire the run loop's timers and redisplay windows while a window is
moved or sized. Windows runs its own modal loop inside DefWindowProc
for the whole drag, so timers stopped and a progress indicator froze.
A Win32 timer set on WM_ENTERSIZEMOVE and killed on WM_EXITSIZEMOVE
now fires the due timers in the run loop's current mode and displays
windows that need it. A timer that starts a nested event loop (a
modal panel) cancels the drag first, so the drag can't lose its input.
* Tests/win32/GNUmakefile.preamble:
* Tests/win32/TestInfo:
* Tests/win32/sizemove.m:
New win32 backend tests: timers during a move loop, and a modal panel
started by a timer during one.

2026-07-22 Richard Frith-Macdonald <rfm@gnu.org>

* Source/x11/XGServerEvent.m:
Expand Down
2 changes: 2 additions & 0 deletions Headers/win32/WIN32Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ typedef struct w32serverFlags
- (void) decodeWM_WINDOWPOSCHANGEDParams: (WPARAM)wParam : (LPARAM)lParam : (HWND)hwnd;
- (LRESULT) decodeWM_GETMINMAXINFOParams: (WPARAM)wParam : (LPARAM)lParam : (HWND)hwnd;
- (LRESULT) decodeWM_ENTERSIZEMOVEParams: (WPARAM)wParam : (LPARAM)lParam : (HWND)hwnd;
- (BOOL) decodeWM_TIMERParams: (WPARAM)wParam : (LPARAM)lParam : (HWND)hwnd;
- (void) cancelSizeMoveForNestedEventLoop;
- (LRESULT) decodeWM_EXITSIZEMOVEParams: (WPARAM)wParam : (LPARAM)lParam : (HWND)hwnd;
- (LRESULT) decodeWM_MOVINGParams: (HWND)hwnd : (WPARAM)wParam : (LPARAM)lParam;
- (LRESULT) decodeWM_SIZINGParams: (HWND)hwnd : (WPARAM)wParam : (LPARAM)lParam;
Expand Down
6 changes: 6 additions & 0 deletions Source/win32/WIN32Server.m
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ - (NSEvent*) getEventMatchingMask: (unsigned)mask
dequeue: (BOOL)flag
{
// [self callback: nil];
/* A nested event loop started from the move/size loop's timer. */
[self cancelSizeMoveForNestedEventLoop];
return [super getEventMatchingMask: mask
beforeDate: limit
inMode: mode
Expand Down Expand Up @@ -1231,6 +1233,10 @@ - (LRESULT) windowEventProc: (HWND)hwnd : (UINT)uMsg
case WM_ENTERSIZEMOVE:
return [self decodeWM_ENTERSIZEMOVEParams: wParam : lParam : hwnd];
break;
case WM_TIMER:
if ([self decodeWM_TIMERParams: wParam : lParam : hwnd])
return 0;
break;
case WM_EXITSIZEMOVE:
return [self decodeWM_EXITSIZEMOVEParams: wParam : lParam : hwnd];
break;
Expand Down
96 changes: 96 additions & 0 deletions Source/win32/w32_movesize.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

#include <AppKit/NSEvent.h>
#include <AppKit/NSWindow.h>
#include <AppKit/NSApplication.h>
#include <Foundation/NSRunLoop.h>
#include <Foundation/NSException.h>
#include <Foundation/NSAutoreleasePool.h>
#include "win32/WIN32Server.h"
#include "win32/WIN32Geometry.h"

Expand Down Expand Up @@ -298,16 +302,108 @@ - (LRESULT) decodeWM_GETMINMAXINFOParams: (WPARAM)wParam : (LPARAM)lParam : (HWN
return 0;
}

/* While a window is moved or sized, Windows runs its own modal loop inside
DefWindowProc (WM_SYSCOMMAND SC_MOVE / SC_SIZE) until the drag ends, so
the GNUstep run loop doesn't run in any mode: timers stop and nothing is
redisplayed (a progress indicator freezes, threaded or not). A Win32
timer for the length of the loop fires the run loop's due timers in its
current mode and redisplays the windows that need it. Only timers
fire: -limitDateForMode: doesn't poll input sources, so the modal loop
keeps its own messages. Not covered: work queued for the main thread
(-performSelectorOnMainThread:, so a threaded progress indicator's
redisplay), which only -acceptInputForMode: runs.

A timer may start a nested event loop of its own (a modal panel, say).
That loop would take the drag's input from under Windows' loop, so a
later Escape or button-up never reaches the drag. Before the nested
loop asks for its first event, the drag is cancelled (WM_CANCELMODE, as
if Escape were pressed) and Windows' loop ends once the timer returns. */
#define GS_SIZEMOVE_TIMER_ID 0x4753
#define GS_SIZEMOVE_TIMER_MS 15

/* The window being moved or sized while the timer pumps the run loop. */
static HWND pumpingWindow = NULL;

- (LRESULT) decodeWM_ENTERSIZEMOVEParams: (WPARAM)wParam : (LPARAM)lParam : (HWND)hwnd
{
SetTimer(hwnd, GS_SIZEMOVE_TIMER_ID, GS_SIZEMOVE_TIMER_MS, NULL);
return DefWindowProc(hwnd, WM_ENTERSIZEMOVE, wParam, lParam);
}

- (LRESULT) decodeWM_EXITSIZEMOVEParams: (WPARAM)wParam : (LPARAM)lParam : (HWND)hwnd
{
KillTimer(hwnd, GS_SIZEMOVE_TIMER_ID);
return DefWindowProc(hwnd, WM_EXITSIZEMOVE, wParam, lParam);
}

- (void) cancelSizeMoveForNestedEventLoop
{
HWND hwnd = pumpingWindow;

if (hwnd != NULL)
{
/* Once is enough: the drag is over, Windows' loop just hasn't
returned yet. */
pumpingWindow = NULL;
KillTimer(hwnd, GS_SIZEMOVE_TIMER_ID);
SendMessage(hwnd, WM_CANCELMODE, 0, 0);
}
}

/* YES if it was the move/size loop's timer. */
- (BOOL) decodeWM_TIMERParams: (WPARAM)wParam : (LPARAM)lParam : (HWND)hwnd
{
static BOOL pumping = NO;
NSRunLoop *loop;
NSEnumerator *windows;
NSWindow *window;

if (wParam != GS_SIZEMOVE_TIMER_ID)
{
return NO;
}
if (pumping)
{
return YES;
}
pumping = YES;
pumpingWindow = hwnd;
NS_DURING
{
CREATE_AUTORELEASE_POOL(pool);

NSString *mode;

/* The mode the run loop was in when it dispatched the message that
started the drag: the default mode, or a modal panel's during a
modal session, so timers of other modes stay quiet. */
loop = [NSRunLoop currentRunLoop];
mode = [loop currentMode];
if (mode == nil)
{
mode = NSDefaultRunLoopMode;
}
[loop limitDateForMode: mode];
windows = [[NSApp windows] objectEnumerator];
while ((window = [windows nextObject]) != nil)
{
if ([window isVisible] && [window viewsNeedDisplay])
{
[window displayIfNeeded];
}
}
[pool drain];
}
NS_HANDLER
{
NSLog(@"exception in the move/size loop's timer: %@", localException);
}
NS_ENDHANDLER
pumpingWindow = NULL;
pumping = NO;
return YES;
}

- (LRESULT) decodeWM_SIZINGParams:(HWND)hwnd : (WPARAM)wParam : (LPARAM)lParam
{
[EVENT_WINDOW(hwnd) displayIfNeeded];
Expand Down
18 changes: 18 additions & 0 deletions Tests/win32/GNUmakefile.preamble
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Extra build settings for the win32 backend tests.
#
# config.make names the backend being built (BUILD_SERVER); the tests carry a
# matching source-level guard (via config.h) so they still build -- and
# skip -- on every other backend.

# config.h (used by the source-level guard) sits at the top of the (build) tree.
ADDITIONAL_INCLUDE_DIRS += -I$(GNUSTEP_BUILD_DIR)/../.. -I../..

-include $(GNUSTEP_BUILD_DIR)/../../config.make
-include ../../config.make

# The tests open windows through the gui library.
ADDITIONAL_TOOL_LIBS += -lgnustep-gui

ifeq ($(BUILD_SERVER),win32)
ADDITIONAL_TOOL_LIBS += -luser32
endif
Empty file added Tests/win32/TestInfo
Empty file.
Loading