[XProto] Replace XAtom with x11::Atom

https://chromium-review.googlesource.com/c/chromium/src/+/2202789
This commit is contained in:
deepak1556
2020-05-21 00:08:37 -07:00
parent 8b9ea9cd2b
commit 143110105a
5 changed files with 33 additions and 42 deletions

View File

@@ -55,6 +55,7 @@
#include "shell/browser/ui/x/window_state_watcher.h"
#include "shell/browser/ui/x/x_window_utils.h"
#include "ui/base/x/x11_util.h"
#include "ui/gfx/x/x11_atom_cache.h"
#include "ui/gfx/x/x11_types.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
#include "ui/views/window/native_frame_view.h"
@@ -220,15 +221,15 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options,
// Before the window is mapped the SetWMSpecState can not work, so we have
// to manually set the _NET_WM_STATE.
std::vector<::Atom> state_atom_list;
std::vector<x11::Atom> state_atom_list;
bool skip_taskbar = false;
if (options.Get(options::kSkipTaskbar, &skip_taskbar) && skip_taskbar) {
state_atom_list.push_back(GetAtom("_NET_WM_STATE_SKIP_TASKBAR"));
state_atom_list.push_back(gfx::GetAtom("_NET_WM_STATE_SKIP_TASKBAR"));
}
// Before the window is mapped, there is no SHOW_FULLSCREEN_STATE.
if (fullscreen) {
state_atom_list.push_back(GetAtom("_NET_WM_STATE_FULLSCREEN"));
state_atom_list.push_back(gfx::GetAtom("_NET_WM_STATE_FULLSCREEN"));
}
if (parent) {
@@ -237,7 +238,7 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options,
window_type = "dialog";
// Modal window needs the _NET_WM_STATE_MODAL hint.
if (is_modal())
state_atom_list.push_back(GetAtom("_NET_WM_STATE_MODAL"));
state_atom_list.push_back(gfx::GetAtom("_NET_WM_STATE_MODAL"));
}
if (!state_atom_list.empty())
@@ -863,7 +864,7 @@ void NativeWindowViews::SetSkipTaskbar(bool skip) {
}
#elif defined(USE_X11)
SetWMSpecState(GetAcceleratedWidget(), skip,
GetAtom("_NET_WM_STATE_SKIP_TASKBAR"));
gfx::GetAtom("_NET_WM_STATE_SKIP_TASKBAR"));
#endif
}
@@ -955,8 +956,9 @@ void NativeWindowViews::SetIgnoreMouseEvents(bool ignore, bool forward) {
#elif defined(USE_X11)
if (ignore) {
XRectangle r = {0, 0, 1, 1};
XShapeCombineRectangles(gfx::GetXDisplay(), GetAcceleratedWidget(),
ShapeInput, 0, 0, &r, 1, ShapeSet, YXBanded);
XShapeCombineRectangles(
gfx::GetXDisplay(), GetAcceleratedWidget(), ShapeInput, 0, 0, &r, 1,
ShapeSet, static_cast<int>(x11::XProto::ClipOrdering::YXBanded));
} else {
XShapeCombineMask(gfx::GetXDisplay(), GetAcceleratedWidget(), ShapeInput, 0,
0, x11::None, ShapeSet);
@@ -1145,8 +1147,8 @@ bool NativeWindowViews::IsVisibleOnAllWorkspaces() {
#if defined(USE_X11)
// Use the presence/absence of _NET_WM_STATE_STICKY in _NET_WM_STATE to
// determine whether the current window is visible on all workspaces.
XAtom sticky_atom = GetAtom("_NET_WM_STATE_STICKY");
std::vector<XAtom> wm_states;
x11::Atom sticky_atom = gfx::GetAtom("_NET_WM_STATE_STICKY");
std::vector<x11::Atom> wm_states;
ui::GetAtomArrayProperty(GetAcceleratedWidget(), "_NET_WM_STATE", &wm_states);
return std::find(wm_states.begin(), wm_states.end(), sticky_atom) !=
wm_states.end();
@@ -1274,19 +1276,14 @@ void NativeWindowViews::SetIcon(const gfx::ImageSkia& icon) {
#if defined(USE_X11)
void NativeWindowViews::SetGTKDarkThemeEnabled(bool use_dark_theme) {
XDisplay* xdisplay = gfx::GetXDisplay();
if (use_dark_theme) {
XChangeProperty(xdisplay, GetAcceleratedWidget(),
XInternAtom(xdisplay, "_GTK_THEME_VARIANT", x11::False),
XInternAtom(xdisplay, "UTF8_STRING", x11::False), 8,
PropModeReplace,
reinterpret_cast<const unsigned char*>("dark"), 4);
ui::SetStringProperty(GetAcceleratedWidget(),
gfx::GetAtom("_GTK_THEME_VARIANT"),
gfx::GetAtom("UTF8_STRING"), "dark");
} else {
XChangeProperty(xdisplay, GetAcceleratedWidget(),
XInternAtom(xdisplay, "_GTK_THEME_VARIANT", x11::False),
XInternAtom(xdisplay, "UTF8_STRING", x11::False), 8,
PropModeReplace,
reinterpret_cast<const unsigned char*>("light"), 5);
ui::SetStringProperty(GetAcceleratedWidget(),
gfx::GetAtom("_GTK_THEME_VARIANT"),
gfx::GetAtom("UTF8_STRING"), "light");
}
}
#endif

View File

@@ -3,7 +3,6 @@
// found in the LICENSE file.
#include "shell/browser/ui/x/window_state_watcher.h"
#include "ui/gfx/x/x11.h"
#include "ui/gfx/x/x11_atom_cache.h"
namespace electron {
@@ -56,7 +55,7 @@ void WindowStateWatcher::DidProcessXEvent(XEvent* xev) {
}
bool WindowStateWatcher::IsWindowStateEvent(XEvent* xev) const {
return (xev->xproperty.atom == window_state_atom_ &&
return (static_cast<x11::Atom>(xev->xproperty.atom) == window_state_atom_ &&
xev->type == PropertyNotify && xev->xproperty.window == widget_);
}

View File

@@ -6,6 +6,7 @@
#define SHELL_BROWSER_UI_X_WINDOW_STATE_WATCHER_H_
#include "ui/events/platform/x11/x11_event_source.h"
#include "ui/gfx/x/x11.h"
#include "shell/browser/native_window_views.h"
@@ -26,7 +27,7 @@ class WindowStateWatcher : public ui::XEventObserver {
NativeWindowViews* window_;
gfx::AcceleratedWidget widget_;
const ::XAtom window_state_atom_;
const x11::Atom window_state_atom_;
bool was_minimized_ = false;
bool was_maximized_ = false;

View File

@@ -14,22 +14,20 @@
#include "dbus/message.h"
#include "dbus/object_proxy.h"
#include "ui/base/x/x11_util.h"
#include "ui/gfx/x/x11_atom_cache.h"
namespace electron {
::Atom GetAtom(const char* name) {
return XInternAtom(gfx::GetXDisplay(), name, false);
}
void SetWMSpecState(::Window xwindow, bool enabled, ::Atom state) {
void SetWMSpecState(::Window xwindow, bool enabled, x11::Atom state) {
XEvent xclient;
memset(&xclient, 0, sizeof(xclient));
xclient.type = ClientMessage;
xclient.xclient.window = xwindow;
xclient.xclient.message_type = GetAtom("_NET_WM_STATE");
xclient.xclient.message_type =
static_cast<uint32_t>(gfx::GetAtom("_NET_WM_STATE"));
xclient.xclient.format = 32;
xclient.xclient.data.l[0] = enabled ? 1 : 0;
xclient.xclient.data.l[1] = state;
xclient.xclient.data.l[1] = static_cast<uint32_t>(state);
xclient.xclient.data.l[2] = x11::None;
xclient.xclient.data.l[3] = 1;
xclient.xclient.data.l[4] = 0;
@@ -40,14 +38,10 @@ void SetWMSpecState(::Window xwindow, bool enabled, ::Atom state) {
}
void SetWindowType(::Window xwindow, const std::string& type) {
XDisplay* xdisplay = gfx::GetXDisplay();
std::string type_prefix = "_NET_WM_WINDOW_TYPE_";
::Atom window_type = XInternAtom(
xdisplay, (type_prefix + base::ToUpperASCII(type)).c_str(), x11::False);
XChangeProperty(xdisplay, xwindow,
XInternAtom(xdisplay, "_NET_WM_WINDOW_TYPE", x11::False),
XA_ATOM, 32, PropModeReplace,
reinterpret_cast<unsigned char*>(&window_type), 1);
x11::Atom window_type = gfx::GetAtom(type_prefix + base::ToUpperASCII(type));
ui::SetProperty(xwindow, gfx::GetAtom("_NET_WM_WINDOW_TYPE"), x11::Atom::ATOM,
window_type);
}
bool ShouldUseGlobalMenuBar() {
@@ -100,11 +94,13 @@ void MoveWindowAbove(::Window xwindow, ::Window other_xwindow) {
xclient.type = ClientMessage;
xclient.xclient.display = xdisplay;
xclient.xclient.window = xwindow;
xclient.xclient.message_type = GetAtom("_NET_RESTACK_WINDOW");
xclient.xclient.message_type =
static_cast<uint32_t>(gfx::GetAtom("_NET_RESTACK_WINDOW"));
xclient.xclient.format = 32;
xclient.xclient.data.l[0] = 2;
xclient.xclient.data.l[1] = other_xwindow;
xclient.xclient.data.l[2] = Above;
xclient.xclient.data.l[2] =
static_cast<uint32_t>(x11::Connection::StackMode::Above);
xclient.xclient.data.l[3] = 0;
xclient.xclient.data.l[4] = 0;

View File

@@ -11,11 +11,9 @@
namespace electron {
::Atom GetAtom(const char* name);
// Sends a message to the x11 window manager, enabling or disabling the |state|
// for _NET_WM_STATE.
void SetWMSpecState(::Window xwindow, bool enabled, ::Atom state);
void SetWMSpecState(::Window xwindow, bool enabled, x11::Atom state);
// Sets the _NET_WM_WINDOW_TYPE of window.
void SetWindowType(::Window xwindow, const std::string& type);