From 83d5833b4f5f287ceb78dce0b0c167f4bf6e0b4b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 17 Mar 2020 19:30:58 -0500 Subject: [PATCH] refactor: precache the IsWindowStateEvent() XAtom (#22706) * refactor: precache the IsWindowStateEvent() atom XAtoms never change after creation so we can perload the atoms we need. This is useful in WindowStateWatcher's XEvent handler, which is called on every XEvent, e.g. mouse movement... * empty commit for ci --- shell/browser/ui/x/window_state_watcher.cc | 9 +++++---- shell/browser/ui/x/window_state_watcher.h | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/shell/browser/ui/x/window_state_watcher.cc b/shell/browser/ui/x/window_state_watcher.cc index 6d4ca95dc720..2fd88cb7426d 100644 --- a/shell/browser/ui/x/window_state_watcher.cc +++ b/shell/browser/ui/x/window_state_watcher.cc @@ -9,7 +9,9 @@ namespace electron { WindowStateWatcher::WindowStateWatcher(NativeWindowViews* window) - : window_(window), widget_(window->GetAcceleratedWidget()) { + : window_(window), + widget_(window->GetAcceleratedWidget()), + window_state_atom_(gfx::GetAtom("_NET_WM_STATE")) { ui::X11EventSource::GetInstance()->AddXEventObserver(this); } @@ -53,9 +55,8 @@ void WindowStateWatcher::DidProcessXEvent(XEvent* xev) { } } -bool WindowStateWatcher::IsWindowStateEvent(XEvent* xev) { - ::Atom changed_atom = xev->xproperty.atom; - return (changed_atom == gfx::GetAtom("_NET_WM_STATE") && +bool WindowStateWatcher::IsWindowStateEvent(XEvent* xev) const { + return (xev->xproperty.atom == window_state_atom_ && xev->type == PropertyNotify && xev->xproperty.window == widget_); } diff --git a/shell/browser/ui/x/window_state_watcher.h b/shell/browser/ui/x/window_state_watcher.h index 420e5c1ca197..c271ff8be265 100644 --- a/shell/browser/ui/x/window_state_watcher.h +++ b/shell/browser/ui/x/window_state_watcher.h @@ -22,10 +22,11 @@ class WindowStateWatcher : public ui::XEventObserver { void DidProcessXEvent(XEvent* xev) override; private: - bool IsWindowStateEvent(XEvent* xev); + bool IsWindowStateEvent(XEvent* xev) const; NativeWindowViews* window_; gfx::AcceleratedWidget widget_; + const ::XAtom window_state_atom_; bool was_minimized_ = false; bool was_maximized_ = false;