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
This commit is contained in:
Charles Kerr 2020-03-17 19:30:58 -05:00 committed by GitHub
parent 5e4e50c5eb
commit 83d5833b4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View file

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

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;