mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
[XProto] Replace usages of XID and ::Window with x11::Window
https://chromium-review.googlesource.com/c/chromium/src/+/2249389
This commit is contained in:
@@ -24,18 +24,18 @@ GlobalMenuBarRegistrarX11* GlobalMenuBarRegistrarX11::GetInstance() {
|
||||
return base::Singleton<GlobalMenuBarRegistrarX11>::get();
|
||||
}
|
||||
|
||||
void GlobalMenuBarRegistrarX11::OnWindowMapped(unsigned long xid) {
|
||||
live_xids_.insert(xid);
|
||||
void GlobalMenuBarRegistrarX11::OnWindowMapped(x11::Window window) {
|
||||
live_windows_.insert(window);
|
||||
|
||||
if (registrar_proxy_)
|
||||
RegisterXID(xid);
|
||||
RegisterXWindow(window);
|
||||
}
|
||||
|
||||
void GlobalMenuBarRegistrarX11::OnWindowUnmapped(unsigned long xid) {
|
||||
void GlobalMenuBarRegistrarX11::OnWindowUnmapped(x11::Window window) {
|
||||
if (registrar_proxy_)
|
||||
UnregisterXID(xid);
|
||||
UnregisterXWindow(window);
|
||||
|
||||
live_xids_.erase(xid);
|
||||
live_windows_.erase(window);
|
||||
}
|
||||
|
||||
GlobalMenuBarRegistrarX11::GlobalMenuBarRegistrarX11()
|
||||
@@ -63,9 +63,9 @@ GlobalMenuBarRegistrarX11::~GlobalMenuBarRegistrarX11() {
|
||||
}
|
||||
}
|
||||
|
||||
void GlobalMenuBarRegistrarX11::RegisterXID(unsigned long xid) {
|
||||
void GlobalMenuBarRegistrarX11::RegisterXWindow(x11::Window window) {
|
||||
DCHECK(registrar_proxy_);
|
||||
std::string path = electron::GlobalMenuBarX11::GetPathForWindow(xid);
|
||||
std::string path = electron::GlobalMenuBarX11::GetPathForWindow(window);
|
||||
|
||||
ANNOTATE_SCOPED_MEMORY_LEAK; // http://crbug.com/314087
|
||||
// TODO(erg): The mozilla implementation goes to a lot of callback trouble
|
||||
@@ -76,13 +76,13 @@ void GlobalMenuBarRegistrarX11::RegisterXID(unsigned long xid) {
|
||||
// I don't see any reason why we should care if "RegisterWindow" completes or
|
||||
// not.
|
||||
g_dbus_proxy_call(registrar_proxy_, "RegisterWindow",
|
||||
g_variant_new("(uo)", xid, path.c_str()),
|
||||
g_variant_new("(uo)", window, path.c_str()),
|
||||
G_DBUS_CALL_FLAGS_NONE, -1, nullptr, nullptr, nullptr);
|
||||
}
|
||||
|
||||
void GlobalMenuBarRegistrarX11::UnregisterXID(unsigned long xid) {
|
||||
void GlobalMenuBarRegistrarX11::UnregisterXWindow(x11::Window window) {
|
||||
DCHECK(registrar_proxy_);
|
||||
std::string path = electron::GlobalMenuBarX11::GetPathForWindow(xid);
|
||||
std::string path = electron::GlobalMenuBarX11::GetPathForWindow(window);
|
||||
|
||||
ANNOTATE_SCOPED_MEMORY_LEAK; // http://crbug.com/314087
|
||||
// TODO(erg): The mozilla implementation goes to a lot of callback trouble
|
||||
@@ -93,7 +93,7 @@ void GlobalMenuBarRegistrarX11::UnregisterXID(unsigned long xid) {
|
||||
// I don't see any reason why we should care if "UnregisterWindow" completes
|
||||
// or not.
|
||||
g_dbus_proxy_call(registrar_proxy_, "UnregisterWindow",
|
||||
g_variant_new("(u)", xid), G_DBUS_CALL_FLAGS_NONE, -1,
|
||||
g_variant_new("(u)", window), G_DBUS_CALL_FLAGS_NONE, -1,
|
||||
nullptr, nullptr, nullptr);
|
||||
}
|
||||
|
||||
@@ -120,10 +120,10 @@ void GlobalMenuBarRegistrarX11::OnProxyCreated(GObject* source,
|
||||
|
||||
void GlobalMenuBarRegistrarX11::OnNameOwnerChanged(GObject* /* ignored */,
|
||||
GParamSpec* /* ignored */) {
|
||||
// If the name owner changed, we need to reregister all the live xids with
|
||||
// the system.
|
||||
for (std::set<unsigned long>::const_iterator it = live_xids_.begin();
|
||||
it != live_xids_.end(); ++it) {
|
||||
RegisterXID(*it);
|
||||
// If the name owner changed, we need to reregister all the live x11::Window
|
||||
// with the system.
|
||||
for (std::set<x11::Window>::const_iterator it = live_windows_.begin();
|
||||
it != live_windows_.end(); ++it) {
|
||||
RegisterXWindow(*it);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,19 +12,20 @@
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/memory/singleton.h"
|
||||
#include "ui/base/glib/glib_signal.h"
|
||||
#include "ui/gfx/x/xproto.h"
|
||||
|
||||
// Advertises our menu bars to Unity.
|
||||
//
|
||||
// GlobalMenuBarX11 is responsible for managing the DbusmenuServer for each
|
||||
// XID. We need a separate object to own the dbus channel to
|
||||
// x11::Window. We need a separate object to own the dbus channel to
|
||||
// com.canonical.AppMenu.Registrar and to register/unregister the mapping
|
||||
// between a XID and the DbusmenuServer instance we are offering.
|
||||
// between a x11::Window and the DbusmenuServer instance we are offering.
|
||||
class GlobalMenuBarRegistrarX11 {
|
||||
public:
|
||||
static GlobalMenuBarRegistrarX11* GetInstance();
|
||||
|
||||
void OnWindowMapped(unsigned long xid);
|
||||
void OnWindowUnmapped(unsigned long xid);
|
||||
void OnWindowMapped(x11::Window window);
|
||||
void OnWindowUnmapped(x11::Window window);
|
||||
|
||||
private:
|
||||
friend struct base::DefaultSingletonTraits<GlobalMenuBarRegistrarX11>;
|
||||
@@ -33,8 +34,8 @@ class GlobalMenuBarRegistrarX11 {
|
||||
~GlobalMenuBarRegistrarX11();
|
||||
|
||||
// Sends the actual message.
|
||||
void RegisterXID(unsigned long xid);
|
||||
void UnregisterXID(unsigned long xid);
|
||||
void RegisterXWindow(x11::Window window);
|
||||
void UnregisterXWindow(x11::Window window);
|
||||
|
||||
CHROMEG_CALLBACK_1(GlobalMenuBarRegistrarX11,
|
||||
void,
|
||||
@@ -49,9 +50,9 @@ class GlobalMenuBarRegistrarX11 {
|
||||
|
||||
GDBusProxy* registrar_proxy_;
|
||||
|
||||
// Window XIDs which want to be registered, but haven't yet been because
|
||||
// x11::Window which want to be registered, but haven't yet been because
|
||||
// we're waiting for the proxy to become available.
|
||||
std::set<unsigned long> live_xids_;
|
||||
std::set<x11::Window> live_windows_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(GlobalMenuBarRegistrarX11);
|
||||
};
|
||||
|
||||
@@ -659,10 +659,11 @@ bool NativeWindowViews::MoveAbove(const std::string& sourceId) {
|
||||
0, 0, 0,
|
||||
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
|
||||
#elif defined(USE_X11)
|
||||
if (!IsWindowValid(id.id))
|
||||
if (!IsWindowValid(static_cast<x11::Window>(id.id)))
|
||||
return false;
|
||||
|
||||
electron::MoveWindowAbove(GetAcceleratedWidget(), id.id);
|
||||
electron::MoveWindowAbove(GetAcceleratedWidget(),
|
||||
static_cast<x11::Window>(id.id));
|
||||
#endif
|
||||
|
||||
return true;
|
||||
@@ -956,12 +957,14 @@ void NativeWindowViews::SetIgnoreMouseEvents(bool ignore, bool forward) {
|
||||
#elif defined(USE_X11)
|
||||
if (ignore) {
|
||||
XRectangle r = {0, 0, 1, 1};
|
||||
XShapeCombineRectangles(gfx::GetXDisplay(), GetAcceleratedWidget(),
|
||||
XShapeCombineRectangles(gfx::GetXDisplay(),
|
||||
static_cast<uint32_t>(GetAcceleratedWidget()),
|
||||
ShapeInput, 0, 0, &r, 1, ShapeSet,
|
||||
static_cast<int>(x11::ClipOrdering::YXBanded));
|
||||
} else {
|
||||
XShapeCombineMask(gfx::GetXDisplay(), GetAcceleratedWidget(), ShapeInput, 0,
|
||||
0, x11::None, ShapeSet);
|
||||
XShapeCombineMask(gfx::GetXDisplay(),
|
||||
static_cast<uint32_t>(GetAcceleratedWidget()), ShapeInput,
|
||||
0, 0, x11::None, ShapeSet);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1070,8 +1073,9 @@ void NativeWindowViews::SetParentWindow(NativeWindow* parent) {
|
||||
#if defined(USE_X11)
|
||||
XDisplay* xdisplay = gfx::GetXDisplay();
|
||||
XSetTransientForHint(
|
||||
xdisplay, GetAcceleratedWidget(),
|
||||
parent ? parent->GetAcceleratedWidget() : DefaultRootWindow(xdisplay));
|
||||
xdisplay, static_cast<uint32_t>(GetAcceleratedWidget()),
|
||||
static_cast<uint32_t>(parent ? parent->GetAcceleratedWidget()
|
||||
: ui::GetX11RootWindow()));
|
||||
#elif defined(OS_WIN)
|
||||
// To set parentship between windows into Windows is better to play with the
|
||||
// owner instead of the parent, as Windows natively seems to do if a parent
|
||||
@@ -1164,7 +1168,7 @@ content::DesktopMediaID NativeWindowViews::GetDesktopMediaID() const {
|
||||
window_handle =
|
||||
reinterpret_cast<content::DesktopMediaID::Id>(accelerated_widget);
|
||||
#elif defined(USE_X11)
|
||||
window_handle = accelerated_widget;
|
||||
window_handle = static_cast<uint32_t>(accelerated_widget);
|
||||
#endif
|
||||
aura::WindowTreeHost* const host =
|
||||
aura::WindowTreeHost::GetForAcceleratedWidget(accelerated_widget);
|
||||
|
||||
@@ -172,24 +172,24 @@ std::string GetMenuModelStatus(ElectronMenuModel* model) {
|
||||
|
||||
GlobalMenuBarX11::GlobalMenuBarX11(NativeWindowViews* window)
|
||||
: window_(window),
|
||||
xid_(window_->GetNativeWindow()->GetHost()->GetAcceleratedWidget()) {
|
||||
xwindow_(window_->GetNativeWindow()->GetHost()->GetAcceleratedWidget()) {
|
||||
EnsureMethodsLoaded();
|
||||
if (server_new)
|
||||
InitServer(xid_);
|
||||
InitServer(xwindow_);
|
||||
|
||||
GlobalMenuBarRegistrarX11::GetInstance()->OnWindowMapped(xid_);
|
||||
GlobalMenuBarRegistrarX11::GetInstance()->OnWindowMapped(xwindow_);
|
||||
}
|
||||
|
||||
GlobalMenuBarX11::~GlobalMenuBarX11() {
|
||||
if (IsServerStarted())
|
||||
g_object_unref(server_);
|
||||
|
||||
GlobalMenuBarRegistrarX11::GetInstance()->OnWindowUnmapped(xid_);
|
||||
GlobalMenuBarRegistrarX11::GetInstance()->OnWindowUnmapped(xwindow_);
|
||||
}
|
||||
|
||||
// static
|
||||
std::string GlobalMenuBarX11::GetPathForWindow(gfx::AcceleratedWidget xid) {
|
||||
return base::StringPrintf("/com/canonical/menu/%lX", xid);
|
||||
std::string GlobalMenuBarX11::GetPathForWindow(x11::Window window) {
|
||||
return base::StringPrintf("/com/canonical/menu/%X", window);
|
||||
}
|
||||
|
||||
void GlobalMenuBarX11::SetMenu(ElectronMenuModel* menu_model) {
|
||||
@@ -211,17 +211,17 @@ bool GlobalMenuBarX11::IsServerStarted() const {
|
||||
return server_;
|
||||
}
|
||||
|
||||
void GlobalMenuBarX11::InitServer(gfx::AcceleratedWidget xid) {
|
||||
std::string path = GetPathForWindow(xid);
|
||||
void GlobalMenuBarX11::InitServer(x11::Window window) {
|
||||
std::string path = GetPathForWindow(window);
|
||||
server_ = server_new(path.c_str());
|
||||
}
|
||||
|
||||
void GlobalMenuBarX11::OnWindowMapped() {
|
||||
GlobalMenuBarRegistrarX11::GetInstance()->OnWindowMapped(xid_);
|
||||
GlobalMenuBarRegistrarX11::GetInstance()->OnWindowMapped(xwindow_);
|
||||
}
|
||||
|
||||
void GlobalMenuBarX11::OnWindowUnmapped() {
|
||||
GlobalMenuBarRegistrarX11::GetInstance()->OnWindowUnmapped(xid_);
|
||||
GlobalMenuBarRegistrarX11::GetInstance()->OnWindowUnmapped(xwindow_);
|
||||
}
|
||||
|
||||
void GlobalMenuBarX11::BuildMenuFromModel(ElectronMenuModel* model,
|
||||
|
||||
@@ -40,8 +40,8 @@ class GlobalMenuBarX11 {
|
||||
explicit GlobalMenuBarX11(NativeWindowViews* window);
|
||||
virtual ~GlobalMenuBarX11();
|
||||
|
||||
// Creates the object path for DbusmenuServer which is attached to |xid|.
|
||||
static std::string GetPathForWindow(gfx::AcceleratedWidget xid);
|
||||
// Creates the object path for DbusmenuServer which is attached to |window|.
|
||||
static std::string GetPathForWindow(x11::Window window);
|
||||
|
||||
void SetMenu(ElectronMenuModel* menu_model);
|
||||
bool IsServerStarted() const;
|
||||
@@ -52,7 +52,7 @@ class GlobalMenuBarX11 {
|
||||
|
||||
private:
|
||||
// Creates a DbusmenuServer.
|
||||
void InitServer(gfx::AcceleratedWidget xid);
|
||||
void InitServer(x11::Window window);
|
||||
|
||||
// Create a menu from menu model.
|
||||
void BuildMenuFromModel(ElectronMenuModel* model, DbusmenuMenuitem* parent);
|
||||
@@ -69,7 +69,7 @@ class GlobalMenuBarX11 {
|
||||
CHROMEG_CALLBACK_0(GlobalMenuBarX11, void, OnSubMenuShow, DbusmenuMenuitem*);
|
||||
|
||||
NativeWindowViews* window_;
|
||||
gfx::AcceleratedWidget xid_;
|
||||
x11::Window xwindow_;
|
||||
|
||||
DbusmenuServer* server_ = nullptr;
|
||||
|
||||
|
||||
@@ -57,7 +57,8 @@ void WindowStateWatcher::DidProcessXEvent(x11::Event* x11_event) {
|
||||
bool WindowStateWatcher::IsWindowStateEvent(x11::Event* x11_event) const {
|
||||
XEvent* xev = &x11_event->xlib_event();
|
||||
return (static_cast<x11::Atom>(xev->xproperty.atom) == window_state_atom_ &&
|
||||
xev->type == PropertyNotify && xev->xproperty.window == widget_);
|
||||
xev->type == PropertyNotify &&
|
||||
xev->xproperty.window == static_cast<uint32_t>(widget_));
|
||||
}
|
||||
|
||||
} // namespace electron
|
||||
|
||||
@@ -18,11 +18,11 @@
|
||||
|
||||
namespace electron {
|
||||
|
||||
void SetWMSpecState(::Window xwindow, bool enabled, x11::Atom state) {
|
||||
void SetWMSpecState(x11::Window window, bool enabled, x11::Atom state) {
|
||||
XEvent xclient;
|
||||
memset(&xclient, 0, sizeof(xclient));
|
||||
xclient.type = ClientMessage;
|
||||
xclient.xclient.window = xwindow;
|
||||
xclient.xclient.window = static_cast<uint32_t>(window);
|
||||
xclient.xclient.message_type =
|
||||
static_cast<uint32_t>(gfx::GetAtom("_NET_WM_STATE"));
|
||||
xclient.xclient.format = 32;
|
||||
@@ -37,10 +37,10 @@ void SetWMSpecState(::Window xwindow, bool enabled, x11::Atom state) {
|
||||
SubstructureRedirectMask | SubstructureNotifyMask, &xclient);
|
||||
}
|
||||
|
||||
void SetWindowType(::Window xwindow, const std::string& type) {
|
||||
void SetWindowType(x11::Window window, const std::string& type) {
|
||||
std::string type_prefix = "_NET_WM_WINDOW_TYPE_";
|
||||
x11::Atom window_type = gfx::GetAtom(type_prefix + base::ToUpperASCII(type));
|
||||
ui::SetProperty(xwindow, gfx::GetAtom("_NET_WM_WINDOW_TYPE"), x11::Atom::ATOM,
|
||||
ui::SetProperty(window, gfx::GetAtom("_NET_WM_WINDOW_TYPE"), x11::Atom::ATOM,
|
||||
window_type);
|
||||
}
|
||||
|
||||
@@ -82,23 +82,23 @@ bool ShouldUseGlobalMenuBar() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void MoveWindowToForeground(::Window xwindow) {
|
||||
MoveWindowAbove(xwindow, 0);
|
||||
void MoveWindowToForeground(x11::Window window) {
|
||||
MoveWindowAbove(window, static_cast<x11::Window>(0));
|
||||
}
|
||||
|
||||
void MoveWindowAbove(::Window xwindow, ::Window other_xwindow) {
|
||||
void MoveWindowAbove(x11::Window window, x11::Window other_window) {
|
||||
XDisplay* xdisplay = gfx::GetXDisplay();
|
||||
XEvent xclient;
|
||||
memset(&xclient, 0, sizeof(xclient));
|
||||
|
||||
xclient.type = ClientMessage;
|
||||
xclient.xclient.display = xdisplay;
|
||||
xclient.xclient.window = xwindow;
|
||||
xclient.xclient.window = static_cast<uint32_t>(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[1] = static_cast<uint32_t>(other_window);
|
||||
xclient.xclient.data.l[2] = static_cast<uint32_t>(x11::StackMode::Above);
|
||||
xclient.xclient.data.l[3] = 0;
|
||||
xclient.xclient.data.l[4] = 0;
|
||||
@@ -108,9 +108,10 @@ void MoveWindowAbove(::Window xwindow, ::Window other_xwindow) {
|
||||
XFlush(xdisplay);
|
||||
}
|
||||
|
||||
bool IsWindowValid(::Window xwindow) {
|
||||
bool IsWindowValid(x11::Window window) {
|
||||
XWindowAttributes attrs;
|
||||
return XGetWindowAttributes(gfx::GetXDisplay(), xwindow, &attrs);
|
||||
return XGetWindowAttributes(gfx::GetXDisplay(), static_cast<uint32_t>(window),
|
||||
&attrs);
|
||||
}
|
||||
|
||||
} // namespace electron
|
||||
|
||||
@@ -13,22 +13,22 @@ namespace electron {
|
||||
|
||||
// Sends a message to the x11 window manager, enabling or disabling the |state|
|
||||
// for _NET_WM_STATE.
|
||||
void SetWMSpecState(::Window xwindow, bool enabled, x11::Atom state);
|
||||
void SetWMSpecState(x11::Window window, bool enabled, x11::Atom state);
|
||||
|
||||
// Sets the _NET_WM_WINDOW_TYPE of window.
|
||||
void SetWindowType(::Window xwindow, const std::string& type);
|
||||
void SetWindowType(x11::Window window, const std::string& type);
|
||||
|
||||
// Returns true if the bus name "com.canonical.AppMenu.Registrar" is available.
|
||||
bool ShouldUseGlobalMenuBar();
|
||||
|
||||
// Bring the given window to the front regardless of focus.
|
||||
void MoveWindowToForeground(::Window xwindow);
|
||||
void MoveWindowToForeground(x11::Window window);
|
||||
|
||||
// Move a given window above the other one.
|
||||
void MoveWindowAbove(::Window xwindow, ::Window other_xwindow);
|
||||
void MoveWindowAbove(x11::Window window, x11::Window other_window);
|
||||
|
||||
// Return true is the given window exists, false otherwise.
|
||||
bool IsWindowValid(::Window xwindow);
|
||||
bool IsWindowValid(x11::Window window);
|
||||
|
||||
} // namespace electron
|
||||
|
||||
|
||||
Reference in New Issue
Block a user