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
This commit is contained in:
Charles Kerr
2020-04-23 12:50:09 -05:00
committed by GitHub
parent 45174dfc19
commit 3d8b2af151
2 changed files with 7 additions and 5 deletions

View File

@@ -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_);
}

View File

@@ -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;