Commit 6f8bf37b authored by Tom Anderson's avatar Tom Anderson Committed by Commit Bot

[XProto] Remove usage of XCreateWindow/XDestroyWindow

BUG=1066670
R=sky

Change-Id: I143ec40265e7b9787c948be67f3695fce79634d7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2412472
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807606}
parent f5fefca2
......@@ -24,6 +24,7 @@ if ((is_linux || is_chromeos) && use_x11 && current_cpu != "arm") {
deps = [
"//base",
"//ui/base/x",
"//ui/gfx/x",
"//ui/gl",
"//ui/gl/init",
......
include_rules = [
"+ui/base/x",
]
......@@ -34,15 +34,16 @@
#include "gpu/tools/compositor_model_bench/render_model_utils.h"
#include "gpu/tools/compositor_model_bench/render_models.h"
#include "gpu/tools/compositor_model_bench/render_tree.h"
#include "ui/base/x/x11_util.h"
#include "ui/gfx/x/connection.h"
#include "ui/gfx/x/x11.h"
#include "ui/gfx/x/xproto.h"
#include "ui/gfx/x/xproto_util.h"
#include "ui/gl/init/gl_factory.h"
using base::TimeTicks;
using base::DirectoryExists;
using base::PathExists;
using base::TimeTicks;
using std::string;
struct SimulationSpecification {
......@@ -64,7 +65,6 @@ class Simulator {
: output_path_(output_path),
seconds_per_test_(seconds_per_test),
display_(nullptr),
window_(0),
gl_context_(nullptr),
window_width_(WINDOW_WIDTH),
window_height_(WINDOW_HEIGHT) {}
......@@ -75,7 +75,7 @@ class Simulator {
glXDestroyContext(display_, gl_context_);
// Destroy window and display.
XDestroyWindow(display_, window_);
connection_->DestroyWindow({window_});
XCloseDisplay(display_);
}
......@@ -87,8 +87,9 @@ class Simulator {
// name, but that's not really harmful (we'll still warn about it though.)
spec.simulation_name = path.BaseName().RemoveExtension().MaybeAsASCII();
if (spec.simulation_name.empty()) {
LOG(WARNING) << "Simulation for path " << path.LossyDisplayName() <<
" will have a blank simulation name, since the file name isn't ASCII";
LOG(WARNING) << "Simulation for path " << path.LossyDisplayName()
<< " will have a blank simulation name, since the file name "
"isn't ASCII";
}
spec.input_path = path;
spec.model_under_test = ForwardRenderModel;
......@@ -155,21 +156,31 @@ class Simulator {
return false;
}
// Get properties of the screen.
int screen = XDefaultScreen(display_);
int root_window = XDefaultRootWindow(display_);
// Creates the window.
window_ = XCreateSimpleWindow(
display_, root_window, 1, 1, window_width_, window_height_, 0,
XBlackPixel(display_, screen), XBlackPixel(display_, screen));
XStoreName(display_, window_, "Compositor Model Bench");
XSelectInput(display_, window_,
ExposureMask | KeyPressMask | StructureNotifyMask);
XMapWindow(display_, window_);
XResizeWindow(display_, window_, WINDOW_WIDTH, WINDOW_HEIGHT);
auto black_pixel = connection_->default_screen().black_pixel;
window_ = connection_->GenerateId<x11::Window>();
connection_->CreateWindow({
.wid = window_,
.parent = connection_->default_root(),
.x = 1,
.y = 1,
.width = window_width_,
.height = window_height_,
.background_pixel = black_pixel,
.border_pixel = black_pixel,
.event_mask = x11::EventMask::Exposure | x11::EventMask::KeyPress |
x11::EventMask::StructureNotify,
});
ui::SetStringProperty(window_, x11::Atom::WM_NAME, x11::Atom::STRING,
"Compositor Model Bench");
connection_->MapWindow({window_});
connection_->ConfigureWindow({
.window = window_,
.width = WINDOW_WIDTH,
.height = WINDOW_HEIGHT,
});
return true;
}
......@@ -181,10 +192,9 @@ class Simulator {
return false;
}
XWindowAttributes attributes;
XGetWindowAttributes(display_, window_, &attributes);
XVisualInfo visual_info_template;
visual_info_template.visualid = XVisualIDFromVisual(attributes.visual);
if (auto reply = connection_->GetWindowAttributes({window_}).Sync())
visual_info_template.visualid = static_cast<uint32_t>(reply->visual);
int visual_info_count = 0;
constexpr int kVisualIdMask = 1;
XVisualInfo* visual_info_list = XGetVisualInfo(
......@@ -200,7 +210,8 @@ class Simulator {
return false;
}
if (!glXMakeCurrent(display_, window_, gl_context_)) {
if (!glXMakeCurrent(display_, static_cast<uint32_t>(window_),
gl_context_)) {
glXDestroyContext(display_, gl_context_);
gl_context_ = nullptr;
return false;
......@@ -239,7 +250,7 @@ class Simulator {
if (current_sim_)
current_sim_->Update();
glXSwapBuffers(display_, window_);
glXSwapBuffers(display_, static_cast<uint32_t>(window_));
auto window = static_cast<x11::Window>(window_);
x11::ExposeEvent ev{
......@@ -276,8 +287,7 @@ class Simulator {
"\t\t\t\"render_model\":\"%s\",\n"
"\t\t\t\"frames_drawn\":%d\n"
"\t\t},\n",
i.simulation_name.c_str(),
ModelToString(i.model_under_test),
i.simulation_name.c_str(), ModelToString(i.model_under_test),
i.frames_rendered);
sims_completed_.pop();
}
......@@ -334,7 +344,7 @@ class Simulator {
// GUI data
std::unique_ptr<x11::Connection> connection_;
Display* display_;
Window window_;
x11::Window window_ = x11::Window::None;
GLXContext gl_context_;
int window_width_;
int window_height_;
......@@ -346,9 +356,10 @@ int main(int argc, char* argv[]) {
const base::CommandLine* cl = base::CommandLine::ForCurrentProcess();
if (argc != 3 && argc != 4) {
LOG(INFO) << "Usage: \n" <<
cl->GetProgram().BaseName().LossyDisplayName() <<
"--in=[input path] --out=[output path] (duration=[seconds])\n"
LOG(INFO)
<< "Usage: \n"
<< cl->GetProgram().BaseName().LossyDisplayName()
<< "--in=[input path] --out=[output path] (duration=[seconds])\n"
"The input path specifies either a JSON configuration file or\n"
"a directory containing only these files\n"
"(if a directory is specified, simulations will be run for\n"
......
......@@ -47,38 +47,40 @@ class VulkanSurfaceX11::ExposeEventForwarder : public ui::XEventDispatcher {
std::unique_ptr<VulkanSurfaceX11> VulkanSurfaceX11::Create(
VkInstance vk_instance,
x11::Window parent_window) {
XDisplay* display = gfx::GetXDisplay();
XWindowAttributes attributes;
if (!XGetWindowAttributes(display, static_cast<uint32_t>(parent_window),
&attributes)) {
LOG(ERROR) << "XGetWindowAttributes failed for window "
auto* connection = x11::Connection::Get();
auto geometry = connection->GetGeometry({parent_window}).Sync();
if (!geometry) {
LOG(ERROR) << "GetGeometry failed for window "
<< static_cast<uint32_t>(parent_window) << ".";
return nullptr;
}
Window window = XCreateWindow(
display, static_cast<uint32_t>(parent_window), 0, 0, attributes.width,
attributes.height, 0, static_cast<int>(x11::WindowClass::CopyFromParent),
static_cast<int>(x11::WindowClass::InputOutput), nullptr, 0, nullptr);
if (!window) {
LOG(ERROR) << "XCreateWindow failed.";
auto window = connection->GenerateId<x11::Window>();
connection->CreateWindow({
.wid = window,
.parent = parent_window,
.width = geometry->width,
.height = geometry->height,
.c_class = x11::WindowClass::InputOutput,
});
if (connection->MapWindow({window}).Sync().error) {
LOG(ERROR) << "Failed to create or map window.";
return nullptr;
}
XMapWindow(display, window);
XFlush(display);
VkSurfaceKHR vk_surface;
VkXlibSurfaceCreateInfoKHR surface_create_info = {
VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
surface_create_info.dpy = display;
surface_create_info.window = window;
surface_create_info.dpy = connection->display();
surface_create_info.window = static_cast<uint32_t>(window);
VkResult result = vkCreateXlibSurfaceKHR(vk_instance, &surface_create_info,
nullptr, &vk_surface);
if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkCreateXlibSurfaceKHR() failed: " << result;
return nullptr;
}
return std::make_unique<VulkanSurfaceX11>(
vk_instance, vk_surface, parent_window, static_cast<x11::Window>(window));
return std::make_unique<VulkanSurfaceX11>(vk_instance, vk_surface,
parent_window, window);
}
VulkanSurfaceX11::VulkanSurfaceX11(VkInstance vk_instance,
......@@ -99,10 +101,10 @@ void VulkanSurfaceX11::Destroy() {
VulkanSurface::Destroy();
expose_event_forwarder_.reset();
if (window_ != x11::Window::None) {
Display* display = gfx::GetXDisplay();
XDestroyWindow(display, static_cast<uint32_t>(window_));
auto* connection = x11::Connection::Get();
connection->DestroyWindow({window_});
window_ = x11::Window::None;
XFlush(display);
connection->Flush();
}
}
......
......@@ -10,6 +10,7 @@
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "ui/events/x/x11_window_event_manager.h"
#include "ui/gfx/x/xproto.h"
namespace ui {
......@@ -26,23 +27,24 @@ TestCompositorHostX11::TestCompositorHostX11(
TestCompositorHostX11::~TestCompositorHostX11() = default;
void TestCompositorHostX11::Show() {
XDisplay* display = gfx::GetXDisplay();
XSetWindowAttributes swa;
swa.override_redirect = true;
window_ = static_cast<x11::Window>(XCreateWindow(
display, XDefaultRootWindow(display), // parent
bounds_.x(), bounds_.y(), bounds_.width(), bounds_.height(),
0, // border width
static_cast<int>(x11::WindowClass::CopyFromParent), // depth
static_cast<int>(x11::WindowClass::InputOutput),
nullptr, // visual
CWOverrideRedirect, &swa));
auto* connection = x11::Connection::Get();
window_ = connection->GenerateId<x11::Window>();
connection->CreateWindow({
.wid = window_,
.parent = connection->default_root(),
.x = bounds_.x(),
.y = bounds_.y(),
.width = bounds_.width(),
.height = bounds_.height(),
.c_class = x11::WindowClass::InputOutput,
.override_redirect = x11::Bool32(true),
});
window_events_ =
std::make_unique<XScopedEventSelector>(window_, ExposureMask);
XMapWindow(display, static_cast<uint32_t>(window_));
connection->MapWindow({window_});
// Since this window is override-redirect, syncing is sufficient
// to ensure the map is complete.
XSync(display, false);
connection->Sync();
allocator_.GenerateId();
compositor_.SetAcceleratedWidget(
static_cast<gfx::AcceleratedWidget>(window_));
......
......@@ -297,28 +297,6 @@ int XGrabKey(Display*, int, unsigned int, Window, Bool, int, int);
int XUngrabKey(Display*, int, unsigned int, Window);
int XSelectInput(Display*, Window, long);
int XSetWindowBackgroundPixmap(Display*, Window, Pixmap);
Window XCreateWindow(Display*,
Window,
int,
int,
unsigned int,
unsigned int,
unsigned int,
int,
unsigned int,
Visual*,
unsigned long,
XSetWindowAttributes*);
Window XCreateSimpleWindow(Display*,
Window,
int,
int,
unsigned int,
unsigned int,
unsigned int,
unsigned long,
unsigned long);
int XDestroyWindow(Display*, Window);
Status XGetWindowAttributes(Display*, Window, XWindowAttributes*);
VisualID XVisualIDFromVisual(Visual*);
int XResizeWindow(Display*, Window, unsigned int, unsigned int);
......
......@@ -6,9 +6,11 @@
#include "base/memory/scoped_refptr.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/x/connection.h"
#include "ui/gfx/x/x11.h"
#include "ui/gfx/x/x11_error_tracker.h"
#include "ui/gfx/x/x11_types.h"
#include "ui/gfx/x/xproto.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_surface_glx_x11.h"
#include "ui/gl/init/gl_factory.h"
......@@ -26,28 +28,26 @@ namespace gl {
#endif
TEST(GLContextGLXTest, MAYBE_DoNotDestroyOnFailedMakeCurrent) {
auto* xdisplay = gfx::GetXDisplay();
ASSERT_TRUE(xdisplay);
auto* connection = x11::Connection::Get();
ASSERT_TRUE(connection && connection->Ready());
gfx::X11ErrorTracker error_tracker;
XSetWindowAttributes swa;
memset(&swa, 0, sizeof(swa));
swa.background_pixmap = 0;
swa.override_redirect = true;
auto xwindow = static_cast<x11::Window>(XCreateWindow(
xdisplay, XDefaultRootWindow(xdisplay), 0, 0, 10,
10, // x, y, width, height
0, // border width
static_cast<int>(x11::WindowClass::CopyFromParent), // depth
static_cast<int>(x11::WindowClass::InputOutput),
nullptr, // visual
CWBackPixmap | CWOverrideRedirect, &swa));
auto xwindow = connection->GenerateId<x11::Window>();
connection->CreateWindow({
.wid = xwindow,
.parent = connection->default_root(),
.width = 10,
.height = 10,
.c_class = x11::WindowClass::InputOutput,
.background_pixmap = x11::Pixmap::None,
.override_redirect = x11::Bool32(true),
});
XMapWindow(xdisplay, static_cast<uint32_t>(xwindow));
connection->MapWindow({xwindow});
// Since this window is override-redirect, syncing is sufficient
// to ensure the map is complete.
XSync(xdisplay, false);
connection->Sync();
GLImageTestSupport::InitializeGL(base::nullopt);
auto surface = gl::InitializeGLSurface(base::MakeRefCounted<GLSurfaceGLXX11>(
......@@ -61,10 +61,10 @@ TEST(GLContextGLXTest, MAYBE_DoNotDestroyOnFailedMakeCurrent) {
EXPECT_TRUE(context->GetHandle());
context->ReleaseCurrent(surface.get());
XDestroyWindow(xdisplay, static_cast<uint32_t>(xwindow));
connection->DestroyWindow({xwindow});
// Since this window is override-redirect, syncing is sufficient
// to ensure the window is destroyed and unmapped.
XSync(xdisplay, false);
connection->Sync();
ASSERT_FALSE(error_tracker.FoundNewError());
if (context->MakeCurrent(surface.get())) {
......@@ -83,7 +83,8 @@ TEST(GLContextGLXTest, MAYBE_DoNotDestroyOnFailedMakeCurrent) {
// not destroyed.
ASSERT_TRUE(context->GetHandle());
surface = nullptr;
XSync(xdisplay, true);
connection->Sync();
connection->events().clear();
}
} // namespace gl
......@@ -19,7 +19,7 @@ namespace {
class XrandrIntervalOnlyVSyncProvider : public gfx::VSyncProvider {
public:
explicit XrandrIntervalOnlyVSyncProvider(Display* display)
explicit XrandrIntervalOnlyVSyncProvider()
: interval_(base::TimeDelta::FromSeconds(1 / 60.)) {}
void GetVSyncParameters(UpdateVSyncCallback callback) override {
......@@ -86,8 +86,9 @@ gfx::SwapResult NativeViewGLSurfaceEGLX11::SwapBuffers(
// views::DesktopWindowTreeHostX11::InitX11Window back to None for the
// XWindow associated to this surface after the first SwapBuffers has
// happened, to avoid showing a weird white background while resizing.
if (GetXNativeDisplay() && !has_swapped_buffers_) {
XSetWindowBackgroundPixmap(GetXNativeDisplay(), window_, 0);
if (GetXNativeConnection()->display() && !has_swapped_buffers_) {
XSetWindowBackgroundPixmap(GetXNativeConnection()->display(), window_, 0);
GetXNativeConnection()->Flush();
has_swapped_buffers_ = true;
}
return result;
......@@ -97,13 +98,13 @@ NativeViewGLSurfaceEGLX11::~NativeViewGLSurfaceEGLX11() {
Destroy();
}
Display* NativeViewGLSurfaceEGLX11::GetXNativeDisplay() const {
return reinterpret_cast<Display*>(GetNativeDisplay());
x11::Connection* NativeViewGLSurfaceEGLX11::GetXNativeConnection() const {
return x11::Connection::Get();
}
std::unique_ptr<gfx::VSyncProvider>
NativeViewGLSurfaceEGLX11::CreateVsyncProviderInternal() {
return std::make_unique<XrandrIntervalOnlyVSyncProvider>(GetXNativeDisplay());
return std::make_unique<XrandrIntervalOnlyVSyncProvider>();
}
bool NativeViewGLSurfaceEGLX11::DispatchXEvent(x11::Event* x11_event) {
......
......@@ -35,7 +35,7 @@ class GL_EXPORT NativeViewGLSurfaceEGLX11 : public NativeViewGLSurfaceEGL,
protected:
~NativeViewGLSurfaceEGLX11() override;
Display* GetXNativeDisplay() const;
x11::Connection* GetXNativeConnection() const;
private:
// NativeViewGLSurfaceEGL overrides:
......
......@@ -6,6 +6,7 @@
#include "ui/base/x/x11_util.h"
#include "ui/gfx/x/x11.h"
#include "ui/gfx/x/xproto.h"
#include "ui/gfx/x/xproto_util.h"
#include "ui/gl/egl_util.h"
......@@ -19,33 +20,33 @@ NativeViewGLSurfaceEGLX11GLES2::NativeViewGLSurfaceEGLX11GLES2(
: NativeViewGLSurfaceEGLX11(x11::Window::None), parent_window_(window) {}
bool NativeViewGLSurfaceEGLX11GLES2::InitializeNativeWindow() {
Display* x11_display = GetXNativeDisplay();
XWindowAttributes attributes;
if (!XGetWindowAttributes(x11_display, static_cast<uint32_t>(parent_window_),
&attributes)) {
LOG(ERROR) << "XGetWindowAttributes failed for window "
auto* connection = GetXNativeConnection();
auto geometry = connection->GetGeometry({parent_window_}).Sync();
if (!geometry) {
LOG(ERROR) << "GetGeometry failed for window "
<< static_cast<uint32_t>(parent_window_) << ".";
return false;
}
size_ = gfx::Size(attributes.width, attributes.height);
size_ = gfx::Size(geometry->width, geometry->height);
// Create a child window, with a CopyFromParent visual (to avoid inducing
// extra blits in the driver), that we can resize exactly in Resize(),
// correctly ordered with GL, so that we don't have invalid transient states.
// See https://crbug.com/326995.
XSetWindowAttributes swa;
memset(&swa, 0, sizeof(swa));
swa.background_pixmap = 0;
swa.bit_gravity = NorthWestGravity;
window_ = XCreateWindow(x11_display, static_cast<uint32_t>(parent_window_), 0,
0, size_.width(), size_.height(), 0,
static_cast<int>(x11::WindowClass::CopyFromParent),
static_cast<int>(x11::WindowClass::InputOutput),
nullptr, CWBackPixmap | CWBitGravity, &swa);
XMapWindow(x11_display, window_);
XSelectInput(x11_display, window_, ExposureMask);
XFlush(x11_display);
set_window(connection->GenerateId<x11::Window>());
connection->CreateWindow({
.wid = window(),
.parent = parent_window_,
.width = size_.width(),
.height = size_.height(),
.c_class = x11::WindowClass::InputOutput,
.background_pixmap = x11::Pixmap::None,
.bit_gravity = x11::Gravity::NorthWest,
.event_mask = x11::EventMask::Exposure,
});
connection->MapWindow({window()});
connection->Flush();
return true;
}
......@@ -54,10 +55,10 @@ void NativeViewGLSurfaceEGLX11GLES2::Destroy() {
NativeViewGLSurfaceEGLX11::Destroy();
if (window_) {
Display* x11_display = GetXNativeDisplay();
XDestroyWindow(x11_display, window_);
auto* connection = GetXNativeConnection();
connection->DestroyWindow({window()});
window_ = 0;
XFlush(x11_display);
connection->Flush();
}
}
......@@ -65,10 +66,10 @@ EGLConfig NativeViewGLSurfaceEGLX11GLES2::GetConfig() {
if (!config_) {
// Get a config compatible with the window
DCHECK(window_);
XWindowAttributes win_attribs;
if (!XGetWindowAttributes(GetXNativeDisplay(), window_, &win_attribs)) {
auto* connection = GetXNativeConnection();
auto geometry = connection->GetGeometry({window()}).Sync();
if (!geometry)
return nullptr;
}
// Try matching the window depth with an alpha channel,
// because we're worried the destination alpha width could
......@@ -90,7 +91,7 @@ EGLConfig NativeViewGLSurfaceEGLX11GLES2::GetConfig() {
EGL_SURFACE_TYPE,
EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
EGL_NONE};
config_attribs[kBufferSizeOffset] = win_attribs.depth;
config_attribs[kBufferSizeOffset] = geometry->depth;
EGLDisplay display = GetHardwareDisplay();
EGLint num_configs;
......@@ -109,7 +110,7 @@ EGLConfig NativeViewGLSurfaceEGLX11GLES2::GetConfig() {
return nullptr;
}
if (config_depth == win_attribs.depth) {
if (config_depth == geometry->depth) {
return config_;
}
}
......@@ -140,7 +141,13 @@ bool NativeViewGLSurfaceEGLX11GLES2::Resize(const gfx::Size& size,
size_ = size;
eglWaitGL();
XResizeWindow(GetXNativeDisplay(), window_, size.width(), size.height());
auto* connection = GetXNativeConnection();
connection->ConfigureWindow({
.window = window(),
.width = size.width(),
.height = size.height(),
});
connection->Flush();
eglWaitNative(EGL_CORE_NATIVE_ENGINE);
return true;
......
......@@ -34,6 +34,11 @@ class GL_EXPORT NativeViewGLSurfaceEGLX11GLES2
protected:
~NativeViewGLSurfaceEGLX11GLES2() override;
x11::Window window() const { return static_cast<x11::Window>(window_); }
void set_window(x11::Window window) {
window_ = static_cast<uint32_t>(window);
}
private:
// XEventDispatcher:
bool DispatchXEvent(x11::Event* xev) override;
......
This diff is collapsed.
......@@ -106,7 +106,9 @@ class GL_EXPORT NativeViewGLSurfaceGLX : public GLSurfaceGLX {
// Checks if event is Expose for child window.
bool CanHandleEvent(x11::Event* xevent);
gfx::AcceleratedWidget window() const { return window_; }
gfx::AcceleratedWidget window() const {
return static_cast<gfx::AcceleratedWidget>(window_);
}
private:
// The handle for the drawable to make current or swap.
......@@ -116,7 +118,7 @@ class GL_EXPORT NativeViewGLSurfaceGLX : public GLSurfaceGLX {
gfx::AcceleratedWidget parent_window_;
// Child window, used to control resizes so that they're in-order with GL.
gfx::AcceleratedWidget window_;
x11::Window window_;
// GLXDrawable for the window.
GLXWindow glx_window_;
......@@ -155,7 +157,7 @@ class GL_EXPORT UnmappedNativeViewGLSurfaceGLX : public GLSurfaceGLX {
gfx::Size size_;
GLXFBConfig config_;
// Unmapped dummy window, used to provide a compatible surface.
gfx::AcceleratedWidget window_;
x11::Window window_;
// GLXDrawable for the window.
GLXWindow glx_window_;
......
......@@ -24,6 +24,7 @@
#include "ui/gfx/x/x11.h"
#include "ui/gfx/x/x11_atom_cache.h"
#include "ui/gfx/x/x11_path.h"
#include "ui/gfx/x/xproto.h"
#include "ui/views/test/widget_test.h"
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_linux.h"
......@@ -144,11 +145,13 @@ class X11TopmostWindowFinderTest : public test::DesktopWidgetTestInteractive {
// Creates and shows an X window with |bounds|.
x11::Window CreateAndShowXWindow(const gfx::Rect& bounds) {
x11::Window root = ui::GetX11RootWindow();
x11::Window window = static_cast<x11::Window>(
XCreateSimpleWindow(xdisplay(), static_cast<uint32_t>(root), 0, 0, 1, 1,
0, // border_width
0, // border
0)); // background
auto window = connection()->GenerateId<x11::Window>();
connection()->CreateWindow({
.wid = window,
.parent = root,
.width = 1,
.height = 1,
});
ui::SetUseOSWindowFrame(window, false);
ShowAndSetXWindowBounds(window, bounds);
......@@ -168,6 +171,7 @@ class X11TopmostWindowFinderTest : public test::DesktopWidgetTestInteractive {
CWX | CWY | CWWidth | CWHeight, &changes);
}
x11::Connection* connection() { return x11::Connection::Get(); }
Display* xdisplay() { return gfx::GetXDisplay(); }
// Returns the topmost X window at the passed in screen position.
......@@ -261,7 +265,7 @@ TEST_F(X11TopmostWindowFinderTest, Basic) {
EXPECT_EQ(window1,
FindTopmostLocalProcessWindowWithIgnore(150, 195, window3));
XDestroyWindow(xdisplay(), static_cast<uint32_t>(x11_window2));
connection()->DestroyWindow({x11_window2});
}
// Test that the minimized state is properly handled.
......@@ -298,7 +302,7 @@ TEST_F(X11TopmostWindowFinderTest, Minimized) {
EXPECT_NE(x11_window1, FindTopmostXWindowAt(350, 150));
EXPECT_NE(x11_window2, FindTopmostXWindowAt(350, 150));
XDestroyWindow(xdisplay(), static_cast<uint32_t>(x11_window2));
connection()->DestroyWindow({x11_window2});
}
// Test that non-rectangular windows are properly handled.
......@@ -342,7 +346,7 @@ TEST_F(X11TopmostWindowFinderTest, NonRectangular) {
EXPECT_NE(window1, FindTopmostXWindowAt(305, 105));
EXPECT_NE(window2, FindTopmostXWindowAt(305, 105));
XDestroyWindow(xdisplay(), static_cast<uint32_t>(window2));
connection()->DestroyWindow({window2});
}
// Test that a window with an empty shape are properly handled.
......@@ -399,19 +403,19 @@ TEST_F(X11TopmostWindowFinderTest, DISABLED_Menu) {
x11::Window window = CreateAndShowXWindow(gfx::Rect(100, 100, 100, 100));
x11::Window root = ui::GetX11RootWindow();
XSetWindowAttributes swa;
swa.override_redirect = true;
x11::Window menu_window = static_cast<x11::Window>(XCreateWindow(
xdisplay(), static_cast<uint32_t>(root), 0, 0, 1, 1,
0, // border width
static_cast<int>(x11::WindowClass::CopyFromParent), // depth
static_cast<int>(x11::WindowClass::InputOutput),
nullptr, // visual
CWOverrideRedirect, &swa));
{
auto menu_window = connection()->GenerateId<x11::Window>();
connection()->CreateWindow({
.wid = menu_window,
.parent = root,
.width = 1,
.height = 1,
.c_class = x11::WindowClass::CopyFromParent,
.override_redirect = x11::Bool32(true),
});
ui::SetAtomProperty(menu_window, "_NET_WM_WINDOW_TYPE", "ATOM",
gfx::GetAtom("_NET_WM_WINDOW_TYPE_MENU"));
}
ui::SetUseOSWindowFrame(menu_window, false);
ShowAndSetXWindowBounds(menu_window, gfx::Rect(140, 110, 100, 100));
ui::X11EventSource::GetInstance()->DispatchXEvents();
......@@ -425,8 +429,8 @@ TEST_F(X11TopmostWindowFinderTest, DISABLED_Menu) {
EXPECT_EQ(menu_window, FindTopmostXWindowAt(150, 120));
EXPECT_EQ(menu_window, FindTopmostXWindowAt(210, 120));
XDestroyWindow(xdisplay(), static_cast<uint32_t>(window));
XDestroyWindow(xdisplay(), static_cast<uint32_t>(menu_window));
connection()->DestroyWindow({window});
connection()->DestroyWindow({menu_window});
}
} // namespace views
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment