0

[X11] Track window occlusion state

This allows different behavior for tab discarding if a window is fully
obscured by another window.

R=sky

Bug: 1240108
Change-Id: Ifb945639ee6a1150894fb91499ac70e980753029
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3101775
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/main@{#914939}
This commit is contained in:
Tom Anderson
2021-08-24 22:39:56 +00:00
committed by Chromium LUCI CQ
parent 2256222e05
commit 53dd19b3de
2 changed files with 37 additions and 16 deletions
ui/platform_window/x11

@ -1878,6 +1878,20 @@ void X11Window::AfterActivationStateChanged() {
OnXWindowIsActiveChanged(is_active);
}
void X11Window::MaybeUpdateOcclusionState() {
PlatformWindowOcclusionState occlusion_state =
is_occluded_ ? PlatformWindowOcclusionState::kOccluded
: PlatformWindowOcclusionState::kVisible;
if (!window_mapped_in_client_ || IsMinimized())
occlusion_state = PlatformWindowOcclusionState::kHidden;
if (occlusion_state != occlusion_state_) {
occlusion_state_ = occlusion_state;
platform_window_delegate_->OnOcclusionStateChanged(occlusion_state);
}
}
void X11Window::OnCrossingEvent(bool enter,
bool focus_in_window_or_ancestor,
x11::NotifyMode mode,
@ -2096,6 +2110,9 @@ void X11Window::HandleEvent(const x11::Event& xev) {
OnWorkspaceUpdated();
} else if (auto* selection = xev.As<x11::SelectionNotifyEvent>()) {
OnXWindowSelectionEvent(*selection);
} else if (auto* visibility = xev.As<x11::VisibilityNotifyEvent>()) {
is_occluded_ = visibility->state == x11::Visibility::FullyObscured;
MaybeUpdateOcclusionState();
}
}
@ -2196,8 +2213,6 @@ void X11Window::OnWMStateUpdated() {
void X11Window::UpdateWindowProperties(
const base::flat_set<x11::Atom>& new_window_properties) {
was_minimized_ = IsMinimized();
window_properties_ = new_window_properties;
// Ignore requests by the window manager to enter or exit fullscreen (e.g. as
@ -2208,6 +2223,7 @@ void X11Window::UpdateWindowProperties(
is_always_on_top_ = HasWMSpecProperty(window_properties_,
x11::GetAtom("_NET_WM_STATE_ABOVE"));
OnXWindowStateChanged();
MaybeUpdateOcclusionState();
ResetWindowRegion();
}

@ -41,18 +41,17 @@ class LocatedEvent;
class WorkspaceExtensionDelegate;
// PlatformWindow implementation for X11.
class X11_WINDOW_EXPORT X11Window
: public PlatformWindow,
public WmMoveResizeHandler,
public PlatformEventDispatcher,
public x11::EventObserver,
public WorkspaceExtension,
public X11Extension,
public WmDragHandler,
public XDragDropClient::Delegate,
public X11MoveLoopDelegate,
public WmMoveLoopHandler,
public X11DesktopWindowMoveClient::Delegate {
class X11_WINDOW_EXPORT X11Window : public PlatformWindow,
public WmMoveResizeHandler,
public PlatformEventDispatcher,
public x11::EventObserver,
public WorkspaceExtension,
public X11Extension,
public WmDragHandler,
public XDragDropClient::Delegate,
public X11MoveLoopDelegate,
public WmMoveLoopHandler,
public X11DesktopWindowMoveClient::Delegate {
public:
explicit X11Window(PlatformWindowDelegate* platform_window_delegate);
~X11Window() override;
@ -283,6 +282,8 @@ class X11_WINDOW_EXPORT X11Window
// Handle the state change since BeforeActivationStateChanged().
void AfterActivationStateChanged();
void MaybeUpdateOcclusionState();
void DelayedResize(const gfx::Rect& bounds_in_pixels);
// If mapped, sends a message to the window manager to enable or disable the
@ -387,6 +388,12 @@ class X11_WINDOW_EXPORT X11Window
// True if the window should stay on top of most other windows.
bool is_always_on_top_ = false;
// True if the window is fully obscured by another window.
bool is_occluded_ = false;
PlatformWindowOcclusionState occlusion_state_ =
PlatformWindowOcclusionState::kUnknown;
// Does |xwindow_| have the pointer grab (XI2 or normal)?
bool has_pointer_grab_ = false;
@ -420,8 +427,6 @@ class X11_WINDOW_EXPORT X11Window
bool had_pointer_grab_ = false;
bool had_window_focus_ = false;
bool was_minimized_ = false;
// Used for synchronizing between |xwindow_| and desktop compositor during
// resizing.
x11::Sync::Counter update_counter_{};