Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use non-blocking window messaging APIs #462

Merged
merged 3 commits into from
Dec 19, 2023
Merged
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
3 changes: 1 addition & 2 deletions GlazeWM.App.Watcher/WatcherStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ private static async Task<IEnumerable<IntPtr>> GetInitialHandles(IpcClient clien
private static void RestoreHandles(List<IntPtr> handles)
{
foreach (var handle in handles)
// TODO: Change this.
ShowWindow(handle, ShowWindowFlags.ShowDefault);
ShowWindowAsync(handle, ShowWindowFlags.ShowNoActivate);
}
}
}
12 changes: 11 additions & 1 deletion GlazeWM.App.WindowManager/WmStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public sealed class WmStartup
{
private readonly Bus _bus;
private readonly KeybindingService _keybindingService;
private readonly WindowService _windowService;
private readonly WindowEventService _windowEventService;
private readonly UserConfigService _userConfigService;

Expand All @@ -27,11 +28,13 @@ public sealed class WmStartup
public WmStartup(
Bus bus,
KeybindingService keybindingService,
WindowService windowService,
WindowEventService windowEventService,
UserConfigService userConfigService)
{
_bus = bus;
_keybindingService = keybindingService;
_windowService = windowService;
_windowEventService = windowEventService;
_userConfigService = userConfigService;
}
Expand Down Expand Up @@ -132,9 +135,16 @@ windowAnimations is WindowAnimations.True

private void OnApplicationExit()
{
_bus.Invoke(new ShowAllWindowsCommand());
// Show all windows regardless of whether their workspace is displayed.
foreach (var window in _windowService.GetWindows())
ShowWindowAsync(window.Handle, ShowWindowFlags.ShowNoActivate);

// Clear border on the active window.
_bus.Invoke(new SetActiveWindowBorderCommand(null));

// Destroy the system tray icon.
_systemTrayIcon?.Remove();

System.Windows.Forms.Application.Exit();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public CommandResponse Handle(RedrawContainersCommand command)

// Restore minimized/maximized windows. Needed to be able to move and resize them.
foreach (var window in windowsToRestore)
ShowWindow(window.Handle, ShowWindowFlags.Restore);
ShowWindowAsync(window.Handle, ShowWindowFlags.Restore);

foreach (var window in windowsToRedraw)
{
Expand Down
1 change: 0 additions & 1 deletion GlazeWM.Domain/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public static IServiceCollection AddDomainServices(this IServiceCollection servi
services.AddSingleton<ICommandHandler<SetMinimizedCommand>, SetMinimizedHandler>();
services.AddSingleton<ICommandHandler<SetTilingCommand>, SetTilingHandler>();
services.AddSingleton<ICommandHandler<SetWindowSizeCommand>, SetWindowSizeHandler>();
services.AddSingleton<ICommandHandler<ShowAllWindowsCommand>, ShowAllWindowsHandler>();
services.AddSingleton<ICommandHandler<ToggleFloatingCommand>, ToggleFloatingHandler>();
services.AddSingleton<ICommandHandler<ToggleMaximizedCommand>, ToggleMaximizedHandler>();
services.AddSingleton<ICommandHandler<UnmanageWindowCommand>, UnmanageWindowHandler>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public CommandResponse Handle(CloseWindowCommand command)
{
var windowToClose = command.WindowToClose;

SendMessage(windowToClose.Handle, SendMessageType.Close, IntPtr.Zero, IntPtr.Zero);
SendNotifyMessage(windowToClose.Handle, SendMessageType.Close, IntPtr.Zero, IntPtr.Zero);

return CommandResponse.Ok;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public CommandResponse Handle(SetMaximizedCommand command)
{
var window = command.Window;

ShowWindow(window.Handle, ShowWindowFlags.Maximize);
ShowWindowAsync(window.Handle, ShowWindowFlags.Maximize);

return CommandResponse.Ok;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public CommandResponse Handle(SetMinimizedCommand command)
{
var window = command.Window;

ShowWindow(window.Handle, ShowWindowFlags.Minimize);
ShowWindowAsync(window.Handle, ShowWindowFlags.Minimize);

return CommandResponse.Ok;
}
Expand Down
39 changes: 0 additions & 39 deletions GlazeWM.Domain/Windows/CommandHandlers/ShowAllWindowsHandler.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public CommandResponse Handle(ToggleMaximizedCommand command)
var window = command.Window;

if (window.HasWindowStyle(WindowStyles.Maximize))
ShowWindow(window.Handle, ShowWindowFlags.Restore);
ShowWindowAsync(window.Handle, ShowWindowFlags.Restore);
else
ShowWindow(window.Handle, ShowWindowFlags.Maximize);
ShowWindowAsync(window.Handle, ShowWindowFlags.Maximize);

return CommandResponse.Ok;
}
Expand Down
8 changes: 0 additions & 8 deletions GlazeWM.Domain/Windows/Commands/ShowAllWindowsCommand.cs

This file was deleted.

7 changes: 4 additions & 3 deletions GlazeWM.Infrastructure/WindowsApi/WindowsApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,13 @@ public enum ShowWindowFlags : uint
{
Minimize = 2,
Maximize = 3,
ShowDefault = 10,
ShowNoActivate = 8,
Restore = 9,
ShowDefault = 10,
}

[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, ShowWindowFlags flags);
public static extern bool ShowWindowAsync(IntPtr hWnd, ShowWindowFlags flags);

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int GetWindowTextLength(IntPtr hWnd);
Expand Down Expand Up @@ -399,7 +400,7 @@ public enum SendMessageType : uint
}

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, SendMessageType msg, IntPtr wParam, IntPtr lParam);
public static extern IntPtr SendNotifyMessage(IntPtr hWnd, SendMessageType msg, IntPtr wParam, IntPtr lParam);

[DllImport("user32.dll", SetLastError = true)]
public static extern bool IsProcessDPIAware();
Expand Down