Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger committed Sep 13, 2023
1 parent 900fd9b commit aac7cb7
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ private void SetWindowPosition(Window window)
SetWindowPosFlags.FrameChanged |
SetWindowPosFlags.NoActivate |
SetWindowPosFlags.NoCopyBits |
SetWindowPosFlags.NoSendChanging;
// SetWindowPosFlags.AsyncWindowPos;
SetWindowPosFlags.NoSendChanging |
SetWindowPosFlags.AsyncWindowPos;

var workspace = window.Ancestors.OfType<Workspace>().First();
var isWorkspaceDisplayed = workspace.IsDisplayed;
Expand Down
20 changes: 13 additions & 7 deletions GlazeWM.Domain/Windows/EventHandlers/WindowFocusedHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,24 @@ public void Handle(WindowFocusedEvent @event)
var window = _windowService.GetWindows()
.FirstOrDefault(window => window.Handle == @event.WindowHandle);

if (window is null)
if (window is null || window.DisplayState != DisplayState.Shown)
// if (window is null || window.DisplayState is DisplayState.Hidden)
return;

// if (window is null)
// return;

// TODO: Need to return early for other display states.
// TODO: Should this be moved to `WindowShownHandler`. Is show event
// emitted first, or foreground?
if (window.DisplayState is DisplayState.Hidden)
{
_logger.LogWindowEvent("Focusing off-screen window", window);
var workspace = WorkspaceService.GetWorkspaceFromChildContainer(window);
_bus.Invoke(new FocusWorkspaceCommand(workspace.Name));
}
// if (window.DisplayState is DisplayState.Hidden)
// {
// _logger.LogWindowEvent("Focusing off-screen window", window);
// var workspace = WorkspaceService.GetWorkspaceFromChildContainer(window);
// _bus.Invoke(new FocusWorkspaceCommand(workspace.Name));
// _bus.Emit(new FocusChangedEvent(window));
// return;
// }

_logger.LogWindowEvent("Window focused", window);

Expand Down
22 changes: 21 additions & 1 deletion GlazeWM.Domain/Windows/EventHandlers/WindowHiddenHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,28 @@ public void Handle(WindowHiddenEvent @event)
}

// Detach the hidden window from its parent.
if (window.DisplayState is DisplayState.Shown)
if (window.DisplayState is DisplayState.Shown && !WindowService.IsHandleVisible(window.Handle))
_bus.Invoke(new UnmanageWindowCommand(window));
}
}
}

// Scenario 1:
// window hiding (due to focus defocus)
// window showing (due to focus refocus)
// window hidden event
// window shown event

// Scenario 2:
// window hiding (due to focus defocus)
// window hidden event
// window showing (due to focus refocus)
// window shown event

// Scenario 3:
// window hiding (due to focus defocus)
// window showing (due to focus refocus)
// window hiding (due to focus defocus)
// window hidden event
// window shown event
// window hidden event
13 changes: 12 additions & 1 deletion GlazeWM.Domain/Windows/Window.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using GlazeWM.Domain.Common;
using GlazeWM.Domain.Common.Enums;
using GlazeWM.Domain.Containers;
Expand All @@ -17,7 +18,17 @@ public abstract class Window : Container
/// <summary>
/// Whether window is shown, hidden, or in an intermediary state.
/// </summary>
public DisplayState DisplayState { get; set; } = DisplayState.Shown;
private DisplayState _displayState = DisplayState.Shown;
public DisplayState DisplayState
{
get => _displayState;
set
{
var Asdf = Enum.GetName(value.GetType(), value);
Debug.WriteLine($"Display state changed {ProcessName} {Title}: {Asdf}");
_displayState = value;
}
}

/// <summary>
/// The placement of the window when floating. Initialized with window's placement on launch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,19 @@ public CommandResponse Handle(MoveWindowToWorkspaceCommand command)

var focusTarget = WindowService.GetFocusTargetAfterRemoval(windowToMove);

// Since the workspace that gets displayed is the last focused child, focus needs to be
// reassigned to the displayed workspace.
var targetMonitor = targetWorkspace.Parent as Monitor;
var focusResetTarget = targetWorkspace.IsDisplayed ? null : targetMonitor.LastFocusedDescendant;

if (windowToMove is TilingWindow)
MoveTilingWindowToWorkspace(windowToMove as TilingWindow, targetWorkspace);
else
_bus.Invoke(new MoveContainerWithinTreeCommand(windowToMove, targetWorkspace, false));

if (focusResetTarget is not null)
_bus.Invoke(new SetFocusedDescendantCommand(focusResetTarget));

// Reassign focus to descendant within the current workspace. Need to call
// `SetFocusedDescendantCommand` for when commands like `FocusWorkspaceCommand` are called
// immediately afterwards and they should behave as if `focusTarget` is the focused
Expand Down

0 comments on commit aac7cb7

Please sign in to comment.