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.
|
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/native/window_x11.h"
|
2020-08-29 00:39:23 +02:00
|
|
|
|
2023-11-21 20:17:55 +01:00
|
|
|
// Include first due to redefinition of x11::EventMask.
|
2024-04-30 17:45:07 +02:00
|
|
|
// clang-format off
|
2023-11-21 20:17:55 +01:00
|
|
|
#include "ui/base/x/x11_util.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
// clang-format on
|
2023-11-21 20:17:55 +01:00
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/alloy/alloy_browser_host_impl.h"
|
|
|
|
#include "cef/libcef/browser/browser_host_base.h"
|
|
|
|
#include "cef/libcef/browser/thread_util.h"
|
2021-06-04 03:34:56 +02:00
|
|
|
#include "net/base/network_interfaces.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"
|
2023-12-06 21:16:15 +01:00
|
|
|
#include "ui/gfx/x/visual_manager.h"
|
|
|
|
#include "ui/gfx/x/window_event_manager.h"
|
2023-11-21 20:17:55 +01:00
|
|
|
#include "ui/gfx/x/xinput.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";
|
|
|
|
|
2022-04-21 20:58:48 +02:00
|
|
|
// Return true if |window| has any property with |property_name|.
|
|
|
|
// Deleted from ui/base/x/x11_util.h in https://crrev.com/62fc260067.
|
2023-12-06 21:16:15 +01:00
|
|
|
bool PropertyExists(x11::Connection* connection,
|
|
|
|
x11::Window window,
|
|
|
|
x11::Atom property) {
|
|
|
|
auto response = connection
|
2022-04-21 20:58:48 +02:00
|
|
|
->GetProperty(x11::GetPropertyRequest{
|
|
|
|
.window = window,
|
|
|
|
.property = property,
|
|
|
|
.long_length = 1,
|
|
|
|
})
|
|
|
|
.Sync();
|
|
|
|
return response && response->format;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if |window| is visible.
|
|
|
|
// Deleted from ui/base/x/x11_util.h in https://crrev.com/62fc260067.
|
2023-12-06 21:16:15 +01:00
|
|
|
bool IsWindowVisible(x11::Connection* connection, x11::Window window) {
|
|
|
|
auto response = connection->GetWindowAttributes({window}).Sync();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!response || response->map_state != x11::MapState::Viewable) {
|
2022-04-21 20:58:48 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2022-04-21 20:58:48 +02:00
|
|
|
|
|
|
|
// Minimized windows are not visible.
|
|
|
|
std::vector<x11::Atom> wm_states;
|
2023-12-06 21:16:15 +01:00
|
|
|
if (connection->GetArrayProperty(window, x11::GetAtom("_NET_WM_STATE"),
|
|
|
|
&wm_states)) {
|
2022-04-21 20:58:48 +02:00
|
|
|
x11::Atom hidden_atom = x11::GetAtom("_NET_WM_STATE_HIDDEN");
|
2023-01-02 23:59:03 +01:00
|
|
|
if (base::Contains(wm_states, hidden_atom)) {
|
2022-04-21 20:58:48 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2022-04-21 20:58:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Do not check _NET_CURRENT_DESKTOP/_NET_WM_DESKTOP since some
|
|
|
|
// window managers (eg. i3) have per-monitor workspaces where more
|
|
|
|
// than one workspace can be visible at once, but only one will be
|
|
|
|
// "active".
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-12-06 21:16:15 +01:00
|
|
|
x11::Window FindChild(x11::Connection* connection, x11::Window window) {
|
|
|
|
auto query_tree = connection->QueryTree({window}).Sync();
|
2020-10-08 21:54:42 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-12-06 21:16:15 +01:00
|
|
|
x11::Window FindToplevelParent(x11::Connection* connection,
|
|
|
|
x11::Window window) {
|
2020-10-08 21:54:42 +02:00
|
|
|
x11::Window top_level_window = window;
|
2014-05-23 19:47:07 +02:00
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
do {
|
2023-12-06 21:16:15 +01:00
|
|
|
auto query_tree = connection->QueryTree({window}).Sync();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!query_tree) {
|
2020-10-08 21:54:42 +02:00
|
|
|
break;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-10-27 23:20:11 +01:00
|
|
|
|
|
|
|
top_level_window = window;
|
2023-12-06 21:16:15 +01:00
|
|
|
if (!PropertyExists(connection, 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() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!CEF_CURRENTLY_ON(CEF_UIT)) {
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
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) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (parent_xwindow_ == x11::Window::None) {
|
2020-10-08 21:54:42 +02:00
|
|
|
parent_xwindow_ = ui::GetX11RootWindow();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-10-08 21:54:42 +02:00
|
|
|
|
|
|
|
x11::VisualId visual;
|
|
|
|
uint8_t depth;
|
|
|
|
x11::ColorMap colormap;
|
2023-12-06 21:16:15 +01:00
|
|
|
connection_->GetOrCreateVisualManager().ChooseVisualForWindow(
|
2020-10-08 21:54:42 +02:00
|
|
|
/*want_argb_visual=*/false, &visual, &depth, &colormap,
|
|
|
|
/*visual_has_alpha=*/nullptr);
|
|
|
|
|
|
|
|
xwindow_ = connection_->GenerateId<x11::Window>();
|
2023-06-06 14:33:52 +02:00
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
connection_->CreateWindow({
|
|
|
|
.depth = depth,
|
|
|
|
.wid = xwindow_,
|
|
|
|
.parent = parent_xwindow_,
|
2021-07-23 18:40:13 +02:00
|
|
|
.x = static_cast<int16_t>(bounds.x()),
|
|
|
|
.y = static_cast<int16_t>(bounds.y()),
|
|
|
|
.width = static_cast<uint16_t>(bounds.width()),
|
|
|
|
.height = static_cast<uint16_t>(bounds.height()),
|
2020-10-08 21:54:42 +02:00
|
|
|
.c_class = x11::WindowClass::InputOutput,
|
|
|
|
.visual = visual,
|
|
|
|
.background_pixel = 0,
|
|
|
|
.border_pixel = 0,
|
|
|
|
.override_redirect = x11::Bool32(false),
|
|
|
|
.colormap = colormap,
|
|
|
|
});
|
|
|
|
|
2023-06-06 14:33:52 +02:00
|
|
|
auto event_mask = x11::EventMask::FocusChange |
|
|
|
|
x11::EventMask::StructureNotify |
|
|
|
|
x11::EventMask::PropertyChange;
|
2023-12-06 21:16:15 +01:00
|
|
|
xwindow_events_ = connection_->ScopedSelectEvent(xwindow_, event_mask);
|
2023-06-06 14:33:52 +02:00
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
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
|
|
|
};
|
2023-12-06 21:16:15 +01:00
|
|
|
connection_->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.
|
2023-12-06 21:16:15 +01:00
|
|
|
connection_->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();
|
2023-12-06 21:16:15 +01:00
|
|
|
connection_->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()) {
|
2023-12-06 21:16:15 +01:00
|
|
|
connection_->SetStringProperty(xwindow_, x11::Atom::WM_NAME,
|
|
|
|
x11::Atom::STRING, title);
|
|
|
|
connection_->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() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (xwindow_ == x11::Window::None) {
|
2020-10-08 21:54:42 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-10-08 21:54:42 +02:00
|
|
|
|
|
|
|
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();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (host) {
|
2020-01-27 23:02:13 +01:00
|
|
|
host->Close();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowX11::Show() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (xwindow_ == x11::Window::None) {
|
2014-05-23 19:47:07 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-05-23 19:47:07 +02:00
|
|
|
|
|
|
|
if (!window_mapped_) {
|
|
|
|
// Before we map the window, set size hints. Otherwise, some window managers
|
|
|
|
// will ignore toplevel XMoveWindow commands.
|
2023-12-06 21:16:15 +01:00
|
|
|
x11::SizeHints size_hints;
|
2020-10-08 21:54:42 +02:00
|
|
|
memset(&size_hints, 0, sizeof(size_hints));
|
2023-12-06 21:16:15 +01:00
|
|
|
connection_->GetWmNormalHints(xwindow_, &size_hints);
|
|
|
|
size_hints.flags |= x11::SIZE_HINT_P_POSITION;
|
2014-05-23 19:47:07 +02:00
|
|
|
size_hints.x = bounds_.x();
|
|
|
|
size_hints.y = bounds_.y();
|
2023-12-06 21:16:15 +01:00
|
|
|
connection_->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.
|
2023-12-06 21:16:15 +01:00
|
|
|
auto child = FindChild(connection_, xwindow_);
|
|
|
|
auto toplevel_window = FindToplevelParent(connection_, xwindow_);
|
2020-10-08 21:54:42 +02:00
|
|
|
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);
|
2023-12-06 21:16:15 +01:00
|
|
|
connection_->GetPropertyAs(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.
|
2023-12-06 21:16:15 +01:00
|
|
|
connection_->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.
|
2023-12-06 21:16:15 +01:00
|
|
|
connection_->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() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (xwindow_ == x11::Window::None) {
|
2014-05-23 19:47:07 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-05-23 19:47:07 +02:00
|
|
|
|
|
|
|
if (window_mapped_) {
|
2023-12-06 21:16:15 +01:00
|
|
|
connection_->WithdrawWindow(xwindow_);
|
2014-05-23 19:47:07 +02:00
|
|
|
window_mapped_ = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-06 21:04:21 +02:00
|
|
|
void CefWindowX11::Focus() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (xwindow_ == x11::Window::None || !window_mapped_) {
|
2014-06-06 21:04:21 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-06-06 21:04:21 +02:00
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
x11::Window focus_target = xwindow_;
|
|
|
|
|
2014-09-27 01:48:19 +02:00
|
|
|
if (browser_.get()) {
|
2023-12-06 21:16:15 +01:00
|
|
|
auto child = FindChild(connection_, xwindow_);
|
|
|
|
if (child != x11::Window::None && IsWindowVisible(connection_, 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) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (xwindow_ == x11::Window::None) {
|
2014-05-23 19:47:07 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-05-23 19:47:07 +02:00
|
|
|
|
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()) {
|
2023-12-06 21:16:15 +01:00
|
|
|
auto child = FindChild(connection_, xwindow_);
|
2020-10-08 21:54:42 +02:00
|
|
|
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();
|
2023-11-21 20:17:55 +01:00
|
|
|
return dispatching_event && IsTargetedBy(*dispatching_event);
|
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) {
|
2023-11-21 20:17:55 +01:00
|
|
|
if (!IsTargetedBy(event)) {
|
2021-01-28 00:13:12 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-01-28 00:13:12 +01:00
|
|
|
ProcessXEvent(event);
|
2020-03-30 22:13:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowX11::ContinueFocus() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!focus_pending_) {
|
2020-03-30 22:13:42 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (browser_.get()) {
|
2020-03-30 22:13:42 +02:00
|
|
|
browser_->SetFocus(true);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-03-30 22:13:42 +02:00
|
|
|
focus_pending_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefWindowX11::TopLevelAlwaysOnTop() const {
|
2023-12-06 21:16:15 +01:00
|
|
|
auto toplevel_window = FindToplevelParent(connection_, xwindow_);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (toplevel_window == x11::Window::None) {
|
2020-10-08 21:54:42 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-03-30 22:13:42 +02:00
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
std::vector<x11::Atom> wm_states;
|
2023-12-06 21:16:15 +01:00
|
|
|
if (connection_->GetArrayProperty(toplevel_window, x11::GetAtom(kNetWMState),
|
|
|
|
&wm_states)) {
|
2021-01-28 00:13:12 +01:00
|
|
|
x11::Atom keep_above_atom = x11::GetAtom(kNetWMStateKeepAbove);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (base::Contains(wm_states, keep_above_atom)) {
|
2020-10-08 21:54:42 +02:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
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>()) {
|
2023-04-26 21:55:59 +02:00
|
|
|
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()) {
|
2023-12-06 21:16:15 +01:00
|
|
|
auto child = FindChild(connection_, xwindow_);
|
2020-10-08 21:54:42 +02:00
|
|
|
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().
|
2024-04-17 18:01:26 +02:00
|
|
|
AlloyBrowserHostImpl::FromBaseChecked(browser_)->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_;
|
2023-12-06 21:16:15 +01:00
|
|
|
connection_->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,
|
2021-06-04 03:34:56 +02:00
|
|
|
base::BindOnce(&CefWindowX11::ContinueFocus,
|
|
|
|
weak_ptr_factory_.GetWeakPtr()),
|
2017-05-17 11:29:28 +02:00
|
|
|
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.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (focus_pending_) {
|
2014-06-06 21:04:21 +02:00
|
|
|
focus_pending_ = false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
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()) {
|
2023-12-06 21:16:15 +01:00
|
|
|
auto child = FindChild(connection_, xwindow_);
|
2020-10-08 21:54:42 +02:00
|
|
|
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;
|
2023-12-06 21:16:15 +01:00
|
|
|
connection_->GetArrayProperty(xwindow_, wm_state_atom, &atom_list);
|
|
|
|
connection_->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
|
|
|
}
|
2023-11-21 20:17:55 +01:00
|
|
|
|
|
|
|
bool CefWindowX11::IsTargetedBy(const x11::Event& xev) const {
|
|
|
|
if (auto* button = xev.As<x11::ButtonEvent>()) {
|
|
|
|
return button->event == xwindow_;
|
|
|
|
}
|
|
|
|
if (auto* key = xev.As<x11::KeyEvent>()) {
|
|
|
|
return key->event == xwindow_;
|
|
|
|
}
|
|
|
|
if (auto* motion = xev.As<x11::MotionNotifyEvent>()) {
|
|
|
|
return motion->event == xwindow_;
|
|
|
|
}
|
|
|
|
if (auto* xievent = xev.As<x11::Input::DeviceEvent>()) {
|
|
|
|
return xievent->event == xwindow_;
|
|
|
|
}
|
|
|
|
if (auto* motion = xev.As<x11::MotionNotifyEvent>()) {
|
|
|
|
return motion->event == xwindow_;
|
|
|
|
}
|
|
|
|
if (auto* crossing = xev.As<x11::CrossingEvent>()) {
|
|
|
|
return crossing->event == xwindow_;
|
|
|
|
}
|
|
|
|
if (auto* expose = xev.As<x11::ExposeEvent>()) {
|
|
|
|
return expose->window == xwindow_;
|
|
|
|
}
|
|
|
|
if (auto* focus = xev.As<x11::FocusEvent>()) {
|
|
|
|
return focus->event == xwindow_;
|
|
|
|
}
|
|
|
|
if (auto* configure = xev.As<x11::ConfigureNotifyEvent>()) {
|
|
|
|
return configure->window == xwindow_;
|
|
|
|
}
|
|
|
|
if (auto* crossing_input = xev.As<x11::Input::CrossingEvent>()) {
|
|
|
|
return crossing_input->event == xwindow_;
|
|
|
|
}
|
|
|
|
if (auto* map = xev.As<x11::MapNotifyEvent>()) {
|
|
|
|
return map->window == xwindow_;
|
|
|
|
}
|
|
|
|
if (auto* unmap = xev.As<x11::UnmapNotifyEvent>()) {
|
|
|
|
return unmap->window == xwindow_;
|
|
|
|
}
|
|
|
|
if (auto* client = xev.As<x11::ClientMessageEvent>()) {
|
|
|
|
return client->window == xwindow_;
|
|
|
|
}
|
|
|
|
if (auto* property = xev.As<x11::PropertyNotifyEvent>()) {
|
|
|
|
return property->window == xwindow_;
|
|
|
|
}
|
|
|
|
if (auto* selection = xev.As<x11::SelectionNotifyEvent>()) {
|
|
|
|
return selection->requestor == xwindow_;
|
|
|
|
}
|
|
|
|
if (auto* visibility = xev.As<x11::VisibilityNotifyEvent>()) {
|
|
|
|
return visibility->window == xwindow_;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|