2014-05-23 19:47:07 +02:00
|
|
|
// Copyright 2014 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright 2014 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "libcef/browser/native/window_x11.h"
|
2020-08-29 00:39:23 +02:00
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
#include "libcef/browser/alloy/alloy_browser_host_impl.h"
|
|
|
|
#include "libcef/browser/browser_host_base.h"
|
2014-05-23 19:47:07 +02:00
|
|
|
#include "libcef/browser/thread_util.h"
|
|
|
|
|
2014-06-06 21:04:21 +02:00
|
|
|
#include "ui/base/x/x11_util.h"
|
2016-03-16 03:55:59 +01:00
|
|
|
#include "ui/events/platform/platform_event_source.h"
|
2021-01-28 00:13:12 +01:00
|
|
|
#include "ui/events/platform/x11/x11_event_source.h"
|
2020-03-30 22:13:42 +02:00
|
|
|
#include "ui/events/x/x11_event_translation.h"
|
2020-10-08 21:54:42 +02:00
|
|
|
#include "ui/gfx/x/connection.h"
|
2021-01-28 00:13:12 +01:00
|
|
|
#include "ui/gfx/x/x11_window_event_manager.h"
|
2020-10-08 21:54:42 +02:00
|
|
|
#include "ui/gfx/x/xproto_util.h"
|
2020-06-09 19:48:00 +02:00
|
|
|
#include "ui/platform_window/x11/x11_topmost_window_finder.h"
|
2020-08-29 00:39:23 +02:00
|
|
|
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_linux.h"
|
2019-07-16 22:09:04 +02:00
|
|
|
|
2014-05-23 19:47:07 +02:00
|
|
|
namespace {
|
|
|
|
|
2014-07-09 00:37:06 +02:00
|
|
|
const char kNetWMPid[] = "_NET_WM_PID";
|
2014-09-11 20:23:10 +02:00
|
|
|
const char kNetWMPing[] = "_NET_WM_PING";
|
|
|
|
const char kNetWMState[] = "_NET_WM_STATE";
|
2020-10-08 21:54:42 +02:00
|
|
|
const char kNetWMStateKeepAbove[] = "_NET_WM_STATE_KEEP_ABOVE";
|
|
|
|
const char kWMDeleteWindow[] = "WM_DELETE_WINDOW";
|
|
|
|
const char kWMProtocols[] = "WM_PROTOCOLS";
|
2014-07-09 00:37:06 +02:00
|
|
|
const char kXdndProxy[] = "XdndProxy";
|
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
x11::Window FindChild(x11::Window window) {
|
|
|
|
auto query_tree = x11::Connection::Get()->QueryTree({window}).Sync();
|
|
|
|
if (query_tree && query_tree->children.size() == 1U) {
|
|
|
|
return query_tree->children[0];
|
|
|
|
}
|
2020-07-08 19:23:29 +02:00
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
return x11::Window::None;
|
2020-07-08 19:23:29 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
x11::Window FindToplevelParent(x11::Window window) {
|
|
|
|
x11::Window top_level_window = window;
|
2014-05-23 19:47:07 +02:00
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
do {
|
|
|
|
auto query_tree = x11::Connection::Get()->QueryTree({window}).Sync();
|
|
|
|
if (!query_tree)
|
|
|
|
break;
|
2014-10-27 23:20:11 +01:00
|
|
|
|
|
|
|
top_level_window = window;
|
2021-01-28 00:13:12 +01:00
|
|
|
if (!ui::PropertyExists(query_tree->parent, x11::GetAtom(kNetWMPid)) ||
|
2020-10-08 21:54:42 +02:00
|
|
|
query_tree->parent == query_tree->root) {
|
2014-10-27 23:20:11 +01:00
|
|
|
break;
|
|
|
|
}
|
2020-10-08 21:54:42 +02:00
|
|
|
|
|
|
|
window = query_tree->parent;
|
|
|
|
} while (true);
|
|
|
|
|
2014-10-27 23:20:11 +01:00
|
|
|
return top_level_window;
|
|
|
|
}
|
2017-07-27 01:19:27 +02:00
|
|
|
|
2014-05-23 19:47:07 +02:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
CEF_EXPORT XDisplay* cef_get_xdisplay() {
|
|
|
|
if (!CEF_CURRENTLY_ON(CEF_UIT))
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2020-12-02 23:31:49 +01:00
|
|
|
return x11::Connection::Get()->GetXlibDisplay();
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
CefWindowX11::CefWindowX11(CefRefPtr<CefBrowserHostBase> browser,
|
2020-10-08 21:54:42 +02:00
|
|
|
x11::Window parent_xwindow,
|
2019-02-27 20:18:16 +01:00
|
|
|
const gfx::Rect& bounds,
|
|
|
|
const std::string& title)
|
2017-05-17 11:29:28 +02:00
|
|
|
: browser_(browser),
|
2020-10-08 21:54:42 +02:00
|
|
|
connection_(x11::Connection::Get()),
|
2017-05-17 11:29:28 +02:00
|
|
|
parent_xwindow_(parent_xwindow),
|
|
|
|
bounds_(bounds),
|
|
|
|
weak_ptr_factory_(this) {
|
2020-10-08 21:54:42 +02:00
|
|
|
if (parent_xwindow_ == x11::Window::None)
|
|
|
|
parent_xwindow_ = ui::GetX11RootWindow();
|
|
|
|
|
|
|
|
x11::VisualId visual;
|
|
|
|
uint8_t depth;
|
|
|
|
x11::ColorMap colormap;
|
|
|
|
ui::XVisualManager::GetInstance()->ChooseVisualForWindow(
|
|
|
|
/*want_argb_visual=*/false, &visual, &depth, &colormap,
|
|
|
|
/*visual_has_alpha=*/nullptr);
|
|
|
|
|
|
|
|
xwindow_ = connection_->GenerateId<x11::Window>();
|
|
|
|
connection_->CreateWindow({
|
|
|
|
.depth = depth,
|
|
|
|
.wid = xwindow_,
|
|
|
|
.parent = parent_xwindow_,
|
|
|
|
.x = bounds.x(),
|
|
|
|
.y = bounds.y(),
|
|
|
|
.width = bounds.width(),
|
|
|
|
.height = bounds.height(),
|
|
|
|
.c_class = x11::WindowClass::InputOutput,
|
|
|
|
.visual = visual,
|
|
|
|
.background_pixel = 0,
|
|
|
|
.border_pixel = 0,
|
|
|
|
.override_redirect = x11::Bool32(false),
|
|
|
|
.event_mask = x11::EventMask::FocusChange |
|
|
|
|
x11::EventMask::StructureNotify |
|
|
|
|
x11::EventMask::PropertyChange,
|
|
|
|
.colormap = colormap,
|
|
|
|
});
|
|
|
|
|
|
|
|
connection_->Flush();
|
2014-05-23 19:47:07 +02:00
|
|
|
|
2020-03-30 22:13:42 +02:00
|
|
|
DCHECK(ui::X11EventSource::HasInstance());
|
2021-01-28 00:13:12 +01:00
|
|
|
connection_->AddEventObserver(this);
|
|
|
|
ui::X11EventSource::GetInstance()->AddPlatformEventDispatcher(this);
|
2014-05-23 19:47:07 +02:00
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
std::vector<x11::Atom> protocols = {
|
2021-01-28 00:13:12 +01:00
|
|
|
x11::GetAtom(kWMDeleteWindow),
|
|
|
|
x11::GetAtom(kNetWMPing),
|
2020-10-08 21:54:42 +02:00
|
|
|
};
|
2021-01-28 00:13:12 +01:00
|
|
|
x11::SetArrayProperty(xwindow_, x11::GetAtom(kWMProtocols), x11::Atom::ATOM,
|
|
|
|
protocols);
|
2014-05-23 19:47:07 +02:00
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
// We need a WM_CLIENT_MACHINE value so we integrate with the desktop
|
|
|
|
// environment.
|
2021-01-28 00:13:12 +01:00
|
|
|
x11::SetStringProperty(xwindow_, x11::Atom::WM_CLIENT_MACHINE,
|
|
|
|
x11::Atom::STRING, net::GetHostName());
|
2014-05-23 19:47:07 +02:00
|
|
|
|
|
|
|
// Likewise, the X server needs to know this window's pid so it knows which
|
|
|
|
// program to kill if the window hangs.
|
|
|
|
// XChangeProperty() expects "pid" to be long.
|
2020-10-08 21:54:42 +02:00
|
|
|
static_assert(sizeof(uint32_t) >= sizeof(pid_t),
|
|
|
|
"pid_t should not be larger than uint32_t");
|
|
|
|
uint32_t pid = getpid();
|
2021-01-28 00:13:12 +01:00
|
|
|
x11::SetProperty(xwindow_, x11::GetAtom(kNetWMPid), x11::Atom::CARDINAL, pid);
|
2019-02-27 20:18:16 +01:00
|
|
|
|
|
|
|
// Set the initial window name, if provided.
|
|
|
|
if (!title.empty()) {
|
2021-01-28 00:13:12 +01:00
|
|
|
x11::SetStringProperty(xwindow_, x11::Atom::WM_NAME, x11::Atom::STRING,
|
|
|
|
title);
|
|
|
|
x11::SetStringProperty(xwindow_, x11::Atom::WM_ICON_NAME, x11::Atom::STRING,
|
|
|
|
title);
|
2019-02-27 20:18:16 +01:00
|
|
|
}
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefWindowX11::~CefWindowX11() {
|
2020-10-08 21:54:42 +02:00
|
|
|
DCHECK_EQ(xwindow_, x11::Window::None);
|
2020-03-30 22:13:42 +02:00
|
|
|
DCHECK(ui::X11EventSource::HasInstance());
|
2021-01-28 00:13:12 +01:00
|
|
|
connection_->RemoveEventObserver(this);
|
|
|
|
ui::X11EventSource::GetInstance()->RemovePlatformEventDispatcher(this);
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowX11::Close() {
|
2020-10-08 21:54:42 +02:00
|
|
|
if (xwindow_ == x11::Window::None)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ui::SendClientMessage(
|
2021-01-28 00:13:12 +01:00
|
|
|
xwindow_, xwindow_, x11::GetAtom(kWMProtocols),
|
|
|
|
{static_cast<uint32_t>(x11::GetAtom(kWMDeleteWindow)),
|
2020-10-08 21:54:42 +02:00
|
|
|
static_cast<uint32_t>(x11::Time::CurrentTime), 0, 0, 0},
|
|
|
|
x11::EventMask::NoEvent);
|
2020-01-27 23:02:13 +01:00
|
|
|
|
|
|
|
auto host = GetHost();
|
|
|
|
if (host)
|
|
|
|
host->Close();
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowX11::Show() {
|
2020-10-08 21:54:42 +02:00
|
|
|
if (xwindow_ == x11::Window::None)
|
2014-05-23 19:47:07 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!window_mapped_) {
|
|
|
|
// Before we map the window, set size hints. Otherwise, some window managers
|
|
|
|
// will ignore toplevel XMoveWindow commands.
|
2020-10-08 21:54:42 +02:00
|
|
|
ui::SizeHints size_hints;
|
|
|
|
memset(&size_hints, 0, sizeof(size_hints));
|
|
|
|
ui::GetWmNormalHints(xwindow_, &size_hints);
|
|
|
|
size_hints.flags |= ui::SIZE_HINT_P_POSITION;
|
2014-05-23 19:47:07 +02:00
|
|
|
size_hints.x = bounds_.x();
|
|
|
|
size_hints.y = bounds_.y();
|
2020-10-08 21:54:42 +02:00
|
|
|
ui::SetWmNormalHints(xwindow_, size_hints);
|
2014-05-23 19:47:07 +02:00
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
connection_->MapWindow({xwindow_});
|
2014-05-23 19:47:07 +02:00
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
// TODO(thomasanderson): Find out why this flush is necessary.
|
2020-10-08 21:54:42 +02:00
|
|
|
connection_->Flush();
|
2014-05-23 19:47:07 +02:00
|
|
|
window_mapped_ = true;
|
2014-10-27 23:20:11 +01:00
|
|
|
|
|
|
|
// Setup the drag and drop proxy on the top level window of the application
|
|
|
|
// to be the child of this window.
|
2020-10-08 21:54:42 +02:00
|
|
|
auto child = FindChild(xwindow_);
|
|
|
|
auto toplevel_window = FindToplevelParent(xwindow_);
|
|
|
|
DCHECK_NE(toplevel_window, x11::Window::None);
|
|
|
|
if (child != x11::Window::None && toplevel_window != x11::Window::None) {
|
2014-10-27 23:20:11 +01:00
|
|
|
// Configure the drag&drop proxy property for the top-most window so
|
|
|
|
// that all drag&drop-related messages will be sent to the child
|
2020-08-29 00:39:23 +02:00
|
|
|
// DesktopWindowTreeHostLinux. The proxy property is referenced by
|
2014-10-27 23:20:11 +01:00
|
|
|
// DesktopDragDropClientAuraX11::FindWindowFor.
|
2020-07-08 19:23:29 +02:00
|
|
|
x11::Window window = x11::Window::None;
|
2021-01-28 00:13:12 +01:00
|
|
|
auto dndproxy_atom = x11::GetAtom(kXdndProxy);
|
|
|
|
x11::GetProperty(toplevel_window, dndproxy_atom, &window);
|
2014-10-27 23:20:11 +01:00
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
if (window != child) {
|
2014-10-27 23:20:11 +01:00
|
|
|
// Set the proxy target for the top-most window.
|
2021-01-28 00:13:12 +01:00
|
|
|
x11::SetProperty(toplevel_window, dndproxy_atom, x11::Atom::WINDOW,
|
|
|
|
child);
|
2014-10-27 23:20:11 +01:00
|
|
|
// Do the same for the proxy target per the spec.
|
2021-01-28 00:13:12 +01:00
|
|
|
x11::SetProperty(child, dndproxy_atom, x11::Atom::WINDOW, child);
|
2014-10-27 23:20:11 +01:00
|
|
|
}
|
|
|
|
}
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowX11::Hide() {
|
2020-10-08 21:54:42 +02:00
|
|
|
if (xwindow_ == x11::Window::None)
|
2014-05-23 19:47:07 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (window_mapped_) {
|
2020-10-08 21:54:42 +02:00
|
|
|
ui::WithdrawWindow(xwindow_);
|
2014-05-23 19:47:07 +02:00
|
|
|
window_mapped_ = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-06 21:04:21 +02:00
|
|
|
void CefWindowX11::Focus() {
|
2020-10-08 21:54:42 +02:00
|
|
|
if (xwindow_ == x11::Window::None || !window_mapped_)
|
2014-06-06 21:04:21 +02:00
|
|
|
return;
|
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
x11::Window focus_target = xwindow_;
|
|
|
|
|
2014-09-27 01:48:19 +02:00
|
|
|
if (browser_.get()) {
|
2020-10-08 21:54:42 +02:00
|
|
|
auto child = FindChild(xwindow_);
|
|
|
|
if (child != x11::Window::None && ui::IsWindowVisible(child)) {
|
2020-08-29 00:39:23 +02:00
|
|
|
// Give focus to the child DesktopWindowTreeHostLinux.
|
2020-10-08 21:54:42 +02:00
|
|
|
focus_target = child;
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
2014-06-06 21:04:21 +02:00
|
|
|
}
|
2020-10-08 21:54:42 +02:00
|
|
|
|
|
|
|
// Directly ask the X server to give focus to the window. Note that the call
|
|
|
|
// would have raised an X error if the window is not mapped.
|
|
|
|
connection_
|
|
|
|
->SetInputFocus(
|
|
|
|
{x11::InputFocus::Parent, focus_target, x11::Time::CurrentTime})
|
|
|
|
.IgnoreError();
|
2014-06-06 21:04:21 +02:00
|
|
|
}
|
|
|
|
|
2014-05-23 19:47:07 +02:00
|
|
|
void CefWindowX11::SetBounds(const gfx::Rect& bounds) {
|
2020-10-08 21:54:42 +02:00
|
|
|
if (xwindow_ == x11::Window::None)
|
2014-05-23 19:47:07 +02:00
|
|
|
return;
|
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
x11::ConfigureWindowRequest req{.window = xwindow_};
|
|
|
|
|
2014-05-23 19:47:07 +02:00
|
|
|
bool origin_changed = bounds_.origin() != bounds.origin();
|
|
|
|
bool size_changed = bounds_.size() != bounds.size();
|
|
|
|
|
|
|
|
if (size_changed) {
|
2020-10-08 21:54:42 +02:00
|
|
|
req.width = bounds.width();
|
|
|
|
req.height = bounds.height();
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (origin_changed) {
|
2020-10-08 21:54:42 +02:00
|
|
|
req.x = bounds.x();
|
|
|
|
req.y = bounds.y();
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
if (origin_changed || size_changed) {
|
|
|
|
connection_->ConfigureWindow(req);
|
|
|
|
}
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Rect CefWindowX11::GetBoundsInScreen() {
|
2020-10-08 21:54:42 +02:00
|
|
|
if (auto coords =
|
|
|
|
connection_
|
|
|
|
->TranslateCoordinates({xwindow_, ui::GetX11RootWindow(), 0, 0})
|
|
|
|
.Sync()) {
|
|
|
|
return gfx::Rect(gfx::Point(coords->dst_x, coords->dst_y), bounds_.size());
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
2020-10-08 21:54:42 +02:00
|
|
|
|
2014-05-23 19:47:07 +02:00
|
|
|
return gfx::Rect();
|
|
|
|
}
|
|
|
|
|
2020-08-29 00:39:23 +02:00
|
|
|
views::DesktopWindowTreeHostLinux* CefWindowX11::GetHost() {
|
2014-10-29 19:14:47 +01:00
|
|
|
if (browser_.get()) {
|
2020-10-08 21:54:42 +02:00
|
|
|
auto child = FindChild(xwindow_);
|
|
|
|
if (child != x11::Window::None) {
|
2020-08-29 00:39:23 +02:00
|
|
|
return static_cast<views::DesktopWindowTreeHostLinux*>(
|
2020-07-08 19:23:29 +02:00
|
|
|
views::DesktopWindowTreeHostLinux::GetHostForWidget(
|
2020-08-29 00:39:23 +02:00
|
|
|
static_cast<gfx::AcceleratedWidget>(child)));
|
2019-11-12 17:11:44 +01:00
|
|
|
}
|
2014-10-29 19:14:47 +01:00
|
|
|
}
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2014-10-29 19:14:47 +01:00
|
|
|
}
|
|
|
|
|
2014-05-23 19:47:07 +02:00
|
|
|
bool CefWindowX11::CanDispatchEvent(const ui::PlatformEvent& event) {
|
2021-01-28 00:13:12 +01:00
|
|
|
auto* dispatching_event = connection_->dispatching_event();
|
|
|
|
return dispatching_event && dispatching_event->window() == xwindow_;
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t CefWindowX11::DispatchEvent(const ui::PlatformEvent& event) {
|
2020-10-08 21:54:42 +02:00
|
|
|
DCHECK_NE(xwindow_, x11::Window::None);
|
2020-03-30 22:13:42 +02:00
|
|
|
DCHECK(event);
|
|
|
|
|
2021-01-28 00:13:12 +01:00
|
|
|
auto* current_xevent = connection_->dispatching_event();
|
|
|
|
ProcessXEvent(*current_xevent);
|
2020-03-30 22:13:42 +02:00
|
|
|
return ui::POST_DISPATCH_STOP_PROPAGATION;
|
|
|
|
}
|
|
|
|
|
2021-01-28 00:13:12 +01:00
|
|
|
void CefWindowX11::OnEvent(const x11::Event& event) {
|
|
|
|
if (event.window() != xwindow_)
|
|
|
|
return;
|
|
|
|
ProcessXEvent(event);
|
2020-03-30 22:13:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowX11::ContinueFocus() {
|
|
|
|
if (!focus_pending_)
|
|
|
|
return;
|
|
|
|
if (browser_.get())
|
|
|
|
browser_->SetFocus(true);
|
|
|
|
focus_pending_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefWindowX11::TopLevelAlwaysOnTop() const {
|
2020-10-08 21:54:42 +02:00
|
|
|
auto toplevel_window = FindToplevelParent(xwindow_);
|
|
|
|
if (toplevel_window == x11::Window::None)
|
|
|
|
return false;
|
2020-03-30 22:13:42 +02:00
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
std::vector<x11::Atom> wm_states;
|
2021-01-28 00:13:12 +01:00
|
|
|
if (x11::GetArrayProperty(toplevel_window, x11::GetAtom(kNetWMState),
|
|
|
|
&wm_states)) {
|
|
|
|
x11::Atom keep_above_atom = x11::GetAtom(kNetWMStateKeepAbove);
|
2020-10-08 21:54:42 +02:00
|
|
|
if (base::Contains(wm_states, keep_above_atom))
|
|
|
|
return true;
|
2020-03-30 22:13:42 +02:00
|
|
|
}
|
2020-10-08 21:54:42 +02:00
|
|
|
return false;
|
2020-03-30 22:13:42 +02:00
|
|
|
}
|
|
|
|
|
2021-01-28 00:13:12 +01:00
|
|
|
void CefWindowX11::ProcessXEvent(const x11::Event& event) {
|
|
|
|
if (auto* configure = event.As<x11::ConfigureNotifyEvent>()) {
|
2020-10-08 21:54:42 +02:00
|
|
|
DCHECK_EQ(xwindow_, configure->event);
|
|
|
|
DCHECK_EQ(xwindow_, configure->window);
|
2020-08-29 00:39:23 +02:00
|
|
|
// It's possible that the X window may be resized by some other means
|
|
|
|
// than from within Aura (e.g. the X window manager can change the
|
|
|
|
// size). Make sure the root window size is maintained properly.
|
|
|
|
bounds_ = gfx::Rect(configure->x, configure->y, configure->width,
|
|
|
|
configure->height);
|
|
|
|
|
|
|
|
if (browser_.get()) {
|
2020-10-08 21:54:42 +02:00
|
|
|
auto child = FindChild(xwindow_);
|
|
|
|
if (child != x11::Window::None) {
|
2020-08-29 00:39:23 +02:00
|
|
|
// Resize the child DesktopWindowTreeHostLinux to match this window.
|
2020-10-08 21:54:42 +02:00
|
|
|
x11::ConfigureWindowRequest req{
|
|
|
|
.window = child,
|
|
|
|
.width = bounds_.width(),
|
|
|
|
.height = bounds_.height(),
|
|
|
|
};
|
|
|
|
connection_->ConfigureWindow(req);
|
2020-08-29 00:39:23 +02:00
|
|
|
|
|
|
|
browser_->NotifyMoveOrResizeStarted();
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
|
|
|
}
|
2021-01-28 00:13:12 +01:00
|
|
|
} else if (auto* client = event.As<x11::ClientMessageEvent>()) {
|
|
|
|
if (client->type == x11::GetAtom(kWMProtocols)) {
|
2020-08-29 00:39:23 +02:00
|
|
|
x11::Atom protocol = static_cast<x11::Atom>(client->data.data32[0]);
|
2021-01-28 00:13:12 +01:00
|
|
|
if (protocol == x11::GetAtom(kWMDeleteWindow)) {
|
2020-08-29 00:39:23 +02:00
|
|
|
// We have received a close message from the window manager.
|
|
|
|
if (!browser_ || browser_->TryCloseBrowser()) {
|
|
|
|
// Allow the close.
|
2020-10-08 21:54:42 +02:00
|
|
|
connection_->DestroyWindow({xwindow_});
|
|
|
|
xwindow_ = x11::Window::None;
|
2020-08-29 00:39:23 +02:00
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
if (browser_) {
|
2020-08-29 00:39:23 +02:00
|
|
|
// Force the browser to be destroyed and release the reference
|
|
|
|
// added in PlatformCreateWindow().
|
2020-09-25 03:40:47 +02:00
|
|
|
static_cast<AlloyBrowserHostImpl*>(browser_.get())
|
|
|
|
->WindowDestroyed();
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
2020-08-29 00:39:23 +02:00
|
|
|
|
|
|
|
delete this;
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
2021-01-28 00:13:12 +01:00
|
|
|
} else if (protocol == x11::GetAtom(kNetWMPing)) {
|
2020-08-29 00:39:23 +02:00
|
|
|
x11::ClientMessageEvent reply_event = *client;
|
2020-10-08 21:54:42 +02:00
|
|
|
reply_event.window = parent_xwindow_;
|
|
|
|
x11::SendEvent(reply_event, reply_event.window,
|
|
|
|
x11::EventMask::SubstructureNotify |
|
|
|
|
x11::EventMask::SubstructureRedirect);
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
|
|
|
}
|
2021-01-28 00:13:12 +01:00
|
|
|
} else if (auto* focus = event.As<x11::FocusEvent>()) {
|
2020-08-29 00:39:23 +02:00
|
|
|
if (focus->opcode == x11::FocusEvent::In) {
|
2014-10-27 23:20:11 +01:00
|
|
|
// This message is received first followed by a "_NET_ACTIVE_WINDOW"
|
2014-05-23 19:47:07 +02:00
|
|
|
// message sent to the root window. When X11DesktopHandler handles the
|
|
|
|
// "_NET_ACTIVE_WINDOW" message it will erroneously mark the WebView
|
2020-08-29 00:39:23 +02:00
|
|
|
// (hosted in a DesktopWindowTreeHostLinux) as unfocused. Use a delayed
|
2014-05-23 19:47:07 +02:00
|
|
|
// task here to restore the WebView's focus state.
|
2014-06-06 21:04:21 +02:00
|
|
|
if (!focus_pending_) {
|
|
|
|
focus_pending_ = true;
|
|
|
|
CEF_POST_DELAYED_TASK(CEF_UIT,
|
2017-05-17 11:29:28 +02:00
|
|
|
base::Bind(&CefWindowX11::ContinueFocus,
|
|
|
|
weak_ptr_factory_.GetWeakPtr()),
|
|
|
|
100);
|
2014-06-06 21:04:21 +02:00
|
|
|
}
|
2020-08-29 00:39:23 +02:00
|
|
|
} else {
|
2014-06-06 21:04:21 +02:00
|
|
|
// Cancel the pending focus change if some other window has gained focus
|
|
|
|
// while waiting for the async task to run. Otherwise we can get stuck in
|
|
|
|
// a focus change loop.
|
|
|
|
if (focus_pending_)
|
|
|
|
focus_pending_ = false;
|
2020-08-29 00:39:23 +02:00
|
|
|
}
|
2021-01-28 00:13:12 +01:00
|
|
|
} else if (auto* property = event.As<x11::PropertyNotifyEvent>()) {
|
|
|
|
const auto& wm_state_atom = x11::GetAtom(kNetWMState);
|
|
|
|
if (property->atom == wm_state_atom) {
|
2020-08-29 00:39:23 +02:00
|
|
|
// State change event like minimize/maximize.
|
|
|
|
if (browser_.get()) {
|
2020-10-08 21:54:42 +02:00
|
|
|
auto child = FindChild(xwindow_);
|
|
|
|
if (child != x11::Window::None) {
|
2020-08-29 00:39:23 +02:00
|
|
|
// Forward the state change to the child DesktopWindowTreeHostLinux
|
|
|
|
// window so that resource usage will be reduced while the window is
|
2020-10-08 21:54:42 +02:00
|
|
|
// minimized. |atom_list| may be empty.
|
2020-08-29 00:39:23 +02:00
|
|
|
std::vector<x11::Atom> atom_list;
|
2021-01-28 00:13:12 +01:00
|
|
|
x11::GetArrayProperty(xwindow_, wm_state_atom, &atom_list);
|
|
|
|
x11::SetArrayProperty(child, wm_state_atom, x11::Atom::ATOM,
|
|
|
|
atom_list);
|
2014-09-11 20:23:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
2018-02-28 05:47:36 +01:00
|
|
|
}
|