Browse Source

refactor: precache the IsWindowStateEvent() XAtom (#22706) (#23260)

* 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
Charles Kerr 5 years ago
parent
commit
3d8b2af151

+ 5 - 4
shell/browser/ui/x/window_state_watcher.cc

@@ -10,7 +10,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);
 }
 
@@ -54,9 +56,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_);
 }
 

+ 2 - 1
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;