GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat(infra): listen for window move/resize in event hook
Lars Bergerbb04f05ecd15
diff --git a/GlazeWM.Infrastructure/WindowsApi/Enums/EventConstant.cs b/GlazeWM.Infrastructure/WindowsApi/Enums/EventConstant.csindex 87f68d4f..91f085df 100644--- a/GlazeWM.Infrastructure/WindowsApi/Enums/EventConstant.cs+++ b/GlazeWM.Infrastructure/WindowsApi/Enums/EventConstant.cs@@ -8,6 +8,7 @@EVENT_SYSTEM_FOREGROUND = 0x0003,EVENT_SYSTEM_MINIMIZESTART = 0x0016,EVENT_SYSTEM_MINIMIZEEND = 0x0017,+ EVENT_SYSTEM_MOVESIZEEND = 0x000B,EVENT_OBJECT_DESTROY = 0x8001,EVENT_OBJECT_SHOW = 0x8002,EVENT_OBJECT_HIDE = 0x8003,diff --git a/GlazeWM.Infrastructure/WindowsApi/WindowEventService.cs b/GlazeWM.Infrastructure/WindowsApi/WindowEventService.csindex 930b6683..2622cf84 100644--- a/GlazeWM.Infrastructure/WindowsApi/WindowEventService.cs+++ b/GlazeWM.Infrastructure/WindowsApi/WindowEventService.cs@@ -28,18 +28,17 @@ namespace GlazeWM.Infrastructure.WindowsApiprivate void CreateWindowEventHook(){SetWinEventHook(EventConstant.EVENT_OBJECT_DESTROY, EventConstant.EVENT_OBJECT_HIDE, IntPtr.Zero, WindowEventHookProc, 0, 0, 0);- SetWinEventHook(EventConstant.EVENT_OBJECT_CLOAKED, EventConstant.EVENT_OBJECT_UNCLOAKED, IntPtr.Zero, WindowEventHookProc, 0, 0, 0);SetWinEventHook(EventConstant.EVENT_SYSTEM_MINIMIZESTART, EventConstant.EVENT_SYSTEM_MINIMIZEEND, IntPtr.Zero, WindowEventHookProc, 0, 0, 0);+ SetWinEventHook(EventConstant.EVENT_SYSTEM_MOVESIZEEND, EventConstant.EVENT_SYSTEM_MOVESIZEEND, IntPtr.Zero, WindowEventHookProc, 0, 0, 0);SetWinEventHook(EventConstant.EVENT_SYSTEM_FOREGROUND, EventConstant.EVENT_SYSTEM_FOREGROUND, IntPtr.Zero, WindowEventHookProc, 0, 0, 0);- // `SetWindowsHookEx` requires a message loop within the thread that is executing the code.+ // `SetWinEventHook` requires a message loop within the thread that is executing the code.Application.Run();}private void WindowEventHookProc(IntPtr hWinEventHook, EventConstant eventType, IntPtr hwnd, ObjectIdentifier idObject, int idChild, uint dwEventThread, uint dwmsEventTime){- // Whether the window event is actually associated with a window object (instead of a UI- // control, for example).+ // Whether the event is actually associated with a window object (instead of a UI control).var isWindowEvent = idChild == CHILDID_SELF && idObject == ObjectIdentifier.OBJID_WINDOW&& hwnd != IntPtr.Zero;@@ -63,6 +62,9 @@ namespace GlazeWM.Infrastructure.WindowsApicase EventConstant.EVENT_SYSTEM_MINIMIZEEND:_bus.RaiseEvent(new WindowMinimizeEndedEvent(hwnd));break;+ case EventConstant.EVENT_SYSTEM_MOVESIZEEND:+ _bus.RaiseEvent(new WindowMovedOrResizedEvent(hwnd));+ break;case EventConstant.EVENT_SYSTEM_FOREGROUND:_bus.RaiseEvent(new WindowFocusedEvent(hwnd));break;