refactor: precache atoms in window-state-watcher (#27575)
This commit is contained in:
parent
6b744171b1
commit
72127b2916
2 changed files with 22 additions and 17 deletions
|
@ -15,7 +15,13 @@ namespace electron {
|
||||||
WindowStateWatcher::WindowStateWatcher(NativeWindowViews* window)
|
WindowStateWatcher::WindowStateWatcher(NativeWindowViews* window)
|
||||||
: window_(window),
|
: window_(window),
|
||||||
widget_(window->GetAcceleratedWidget()),
|
widget_(window->GetAcceleratedWidget()),
|
||||||
window_state_atom_(x11::GetAtom("_NET_WM_STATE")) {
|
net_wm_state_atom_(x11::GetAtom("_NET_WM_STATE")),
|
||||||
|
net_wm_state_hidden_atom_(x11::GetAtom("_NET_WM_STATE_HIDDEN")),
|
||||||
|
net_wm_state_maximized_vert_atom_(
|
||||||
|
x11::GetAtom("_NET_WM_STATE_MAXIMIZED_VERT")),
|
||||||
|
net_wm_state_maximized_horz_atom_(
|
||||||
|
x11::GetAtom("_NET_WM_STATE_MAXIMIZED_HORZ")),
|
||||||
|
net_wm_state_fullscreen_atom_(x11::GetAtom("_NET_WM_STATE_FULLSCREEN")) {
|
||||||
ui::X11EventSource::GetInstance()->connection()->AddEventObserver(this);
|
ui::X11EventSource::GetInstance()->connection()->AddEventObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,25 +31,20 @@ WindowStateWatcher::~WindowStateWatcher() {
|
||||||
|
|
||||||
void WindowStateWatcher::OnEvent(const x11::Event& x11_event) {
|
void WindowStateWatcher::OnEvent(const x11::Event& x11_event) {
|
||||||
if (IsWindowStateEvent(x11_event)) {
|
if (IsWindowStateEvent(x11_event)) {
|
||||||
bool was_minimized_ = window_->IsMinimized();
|
const bool was_minimized_ = window_->IsMinimized();
|
||||||
bool was_maximized_ = window_->IsMaximized();
|
const bool was_maximized_ = window_->IsMaximized();
|
||||||
|
|
||||||
std::vector<x11::Atom> wm_states;
|
std::vector<x11::Atom> wm_states;
|
||||||
|
|
||||||
if (GetArrayProperty(
|
if (GetArrayProperty(
|
||||||
static_cast<x11::Window>(window_->GetAcceleratedWidget()),
|
static_cast<x11::Window>(window_->GetAcceleratedWidget()),
|
||||||
x11::GetAtom("_NET_WM_STATE"), &wm_states)) {
|
net_wm_state_atom_, &wm_states)) {
|
||||||
auto props =
|
const auto props =
|
||||||
base::flat_set<x11::Atom>(std::begin(wm_states), std::end(wm_states));
|
base::flat_set<x11::Atom>(std::begin(wm_states), std::end(wm_states));
|
||||||
bool is_minimized =
|
const bool is_minimized = props.contains(net_wm_state_hidden_atom_);
|
||||||
props.find(x11::GetAtom("_NET_WM_STATE_HIDDEN")) != props.end();
|
const bool is_maximized =
|
||||||
bool is_maximized =
|
props.contains(net_wm_state_maximized_vert_atom_) &&
|
||||||
props.find(x11::GetAtom("_NET_WM_STATE_MAXIMIZED_VERT")) !=
|
props.contains(net_wm_state_maximized_horz_atom_);
|
||||||
props.end() &&
|
const bool is_fullscreen = props.contains(net_wm_state_fullscreen_atom_);
|
||||||
props.find(x11::GetAtom("_NET_WM_STATE_MAXIMIZED_HORZ")) !=
|
|
||||||
props.end();
|
|
||||||
bool is_fullscreen =
|
|
||||||
props.find(x11::GetAtom("_NET_WM_STATE_FULLSCREEN")) != props.end();
|
|
||||||
|
|
||||||
if (is_minimized != was_minimized_) {
|
if (is_minimized != was_minimized_) {
|
||||||
if (is_minimized)
|
if (is_minimized)
|
||||||
|
@ -72,7 +73,7 @@ void WindowStateWatcher::OnEvent(const x11::Event& x11_event) {
|
||||||
|
|
||||||
bool WindowStateWatcher::IsWindowStateEvent(const x11::Event& x11_event) const {
|
bool WindowStateWatcher::IsWindowStateEvent(const x11::Event& x11_event) const {
|
||||||
auto* property = x11_event.As<x11::PropertyNotifyEvent>();
|
auto* property = x11_event.As<x11::PropertyNotifyEvent>();
|
||||||
return (property && property->atom == window_state_atom_ &&
|
return (property && property->atom == net_wm_state_atom_ &&
|
||||||
static_cast<uint32_t>(property->window) == widget_);
|
static_cast<uint32_t>(property->window) == widget_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,11 @@ class WindowStateWatcher : public x11::EventObserver {
|
||||||
|
|
||||||
NativeWindowViews* window_;
|
NativeWindowViews* window_;
|
||||||
gfx::AcceleratedWidget widget_;
|
gfx::AcceleratedWidget widget_;
|
||||||
const x11::Atom window_state_atom_;
|
const x11::Atom net_wm_state_atom_;
|
||||||
|
const x11::Atom net_wm_state_hidden_atom_;
|
||||||
|
const x11::Atom net_wm_state_maximized_vert_atom_;
|
||||||
|
const x11::Atom net_wm_state_maximized_horz_atom_;
|
||||||
|
const x11::Atom net_wm_state_fullscreen_atom_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(WindowStateWatcher);
|
DISALLOW_COPY_AND_ASSIGN(WindowStateWatcher);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue