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"
|
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"
|
2020-03-30 22:13:42 +02:00
|
|
|
#include "ui/events/x/x11_event_translation.h"
|
2020-06-09 19:48:00 +02:00
|
|
|
#include "ui/platform_window/x11/x11_topmost_window_finder.h"
|
2014-07-09 00:37:06 +02:00
|
|
|
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
|
2014-05-23 19:47:07 +02:00
|
|
|
|
2019-07-16 22:09:04 +02:00
|
|
|
#include <X11/Xatom.h>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/extensions/XInput2.h>
|
|
|
|
|
2014-05-23 19:47:07 +02:00
|
|
|
namespace {
|
|
|
|
|
2020-07-08 19:23:29 +02:00
|
|
|
// Restore Xlib constants that were #undef'ed by gen/ui/gfx/x/xproto.h.
|
|
|
|
constexpr int CopyFromParent = 0;
|
|
|
|
constexpr int InputOutput = 1;
|
|
|
|
|
2014-09-11 20:23:10 +02:00
|
|
|
const char kAtom[] = "ATOM";
|
2014-07-09 00:37:06 +02:00
|
|
|
const char kWMDeleteWindow[] = "WM_DELETE_WINDOW";
|
|
|
|
const char kWMProtocols[] = "WM_PROTOCOLS";
|
2019-02-27 20:18:16 +01:00
|
|
|
const char kNetWMName[] = "_NET_WM_NAME";
|
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";
|
2014-07-09 00:37:06 +02:00
|
|
|
const char kXdndProxy[] = "XdndProxy";
|
2019-02-27 20:18:16 +01:00
|
|
|
const char kUTF8String[] = "UTF8_STRING";
|
2014-07-09 00:37:06 +02:00
|
|
|
|
2020-07-08 19:23:29 +02:00
|
|
|
// See https://crbug.com/1066670#c57 for background.
|
|
|
|
inline x11::Window ToX11Window(::Window window) {
|
|
|
|
return static_cast<x11::Window>(window);
|
|
|
|
}
|
|
|
|
inline ::Window ToWindow(x11::Window window) {
|
|
|
|
return static_cast<::Window>(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
// See https://crbug.com/1066670#c29 for background.
|
|
|
|
inline ::Atom GetAtom(const std::string& atom_name) {
|
|
|
|
return static_cast<::Atom>(gfx::GetAtom(atom_name));
|
|
|
|
}
|
|
|
|
|
2014-05-23 19:47:07 +02:00
|
|
|
::Window FindChild(::Display* display, ::Window window) {
|
|
|
|
::Window root;
|
|
|
|
::Window parent;
|
|
|
|
::Window* children;
|
2017-12-07 22:44:24 +01:00
|
|
|
::Window child_window = x11::None;
|
2014-05-23 19:47:07 +02:00
|
|
|
unsigned int nchildren;
|
2019-10-01 15:55:16 +02:00
|
|
|
if (XQueryTree(display, window, &root, &parent, &children, &nchildren) &&
|
|
|
|
nchildren == 1) {
|
2014-10-27 23:20:11 +01:00
|
|
|
child_window = children[0];
|
|
|
|
XFree(children);
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
2014-10-27 23:20:11 +01:00
|
|
|
return child_window;
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
|
|
|
|
2014-10-27 23:20:11 +01:00
|
|
|
::Window FindToplevelParent(::Display* display, ::Window window) {
|
|
|
|
::Window top_level_window = window;
|
2017-12-07 22:44:24 +01:00
|
|
|
::Window root = x11::None;
|
|
|
|
::Window parent = x11::None;
|
2020-01-15 14:36:24 +01:00
|
|
|
::Window* children = nullptr;
|
2014-10-27 23:20:11 +01:00
|
|
|
unsigned int nchildren = 0;
|
|
|
|
// Enumerate all parents of "window" to find the highest level window
|
|
|
|
// that either:
|
|
|
|
// - has a parent that does not contain the _NET_WM_PID property
|
|
|
|
// - has a parent that is the root window.
|
|
|
|
while (XQueryTree(display, window, &root, &parent, &children, &nchildren)) {
|
|
|
|
if (children) {
|
|
|
|
XFree(children);
|
|
|
|
}
|
|
|
|
|
|
|
|
top_level_window = window;
|
2020-07-08 19:23:29 +02:00
|
|
|
if (!ui::PropertyExists(ToX11Window(parent), kNetWMPid) || parent == root) {
|
2014-10-27 23:20:11 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
window = parent;
|
|
|
|
}
|
|
|
|
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;
|
2014-05-23 19:47:07 +02:00
|
|
|
return gfx::GetXDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefWindowX11::CefWindowX11(CefRefPtr<CefBrowserHostImpl> browser,
|
|
|
|
::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),
|
|
|
|
xdisplay_(gfx::GetXDisplay()),
|
|
|
|
parent_xwindow_(parent_xwindow),
|
|
|
|
xwindow_(0),
|
|
|
|
window_mapped_(false),
|
|
|
|
bounds_(bounds),
|
|
|
|
focus_pending_(false),
|
|
|
|
weak_ptr_factory_(this) {
|
2017-12-07 22:44:24 +01:00
|
|
|
if (parent_xwindow_ == x11::None)
|
2014-05-23 19:47:07 +02:00
|
|
|
parent_xwindow_ = DefaultRootWindow(xdisplay_);
|
|
|
|
|
|
|
|
XSetWindowAttributes swa;
|
|
|
|
memset(&swa, 0, sizeof(swa));
|
2017-12-07 22:44:24 +01:00
|
|
|
swa.background_pixmap = x11::None;
|
2014-05-23 19:47:07 +02:00
|
|
|
swa.override_redirect = false;
|
2017-05-17 11:29:28 +02:00
|
|
|
xwindow_ = XCreateWindow(xdisplay_, parent_xwindow_, bounds.x(), bounds.y(),
|
|
|
|
bounds.width(), bounds.height(),
|
|
|
|
0, // border width
|
|
|
|
CopyFromParent, // depth
|
|
|
|
InputOutput,
|
2020-07-08 19:23:29 +02:00
|
|
|
nullptr, // visual
|
2017-05-17 11:29:28 +02:00
|
|
|
CWBackPixmap | CWOverrideRedirect, &swa);
|
2018-09-20 15:00:14 +02:00
|
|
|
CHECK(xwindow_);
|
2014-05-23 19:47:07 +02:00
|
|
|
|
2020-03-30 22:13:42 +02:00
|
|
|
DCHECK(ui::X11EventSource::HasInstance());
|
|
|
|
ui::X11EventSource::GetInstance()->AddXEventDispatcher(this);
|
2014-05-23 19:47:07 +02:00
|
|
|
|
|
|
|
long event_mask = FocusChangeMask | StructureNotifyMask | PropertyChangeMask;
|
|
|
|
XSelectInput(xdisplay_, xwindow_, event_mask);
|
|
|
|
XFlush(xdisplay_);
|
|
|
|
|
|
|
|
// TODO(erg): We currently only request window deletion events. We also
|
|
|
|
// should listen for activation events and anything else that GTK+ listens
|
|
|
|
// for, and do something useful.
|
|
|
|
::Atom protocols[2];
|
2020-07-08 19:23:29 +02:00
|
|
|
protocols[0] = GetAtom(kWMDeleteWindow);
|
|
|
|
protocols[1] = GetAtom(kNetWMPing);
|
2014-05-23 19:47:07 +02:00
|
|
|
XSetWMProtocols(xdisplay_, xwindow_, protocols, 2);
|
|
|
|
|
|
|
|
// We need a WM_CLIENT_MACHINE and WM_LOCALE_NAME value so we integrate with
|
|
|
|
// the desktop environment.
|
|
|
|
XSetWMProperties(xdisplay_, xwindow_, NULL, NULL, NULL, 0, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
// 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.
|
2015-12-09 17:10:16 +01:00
|
|
|
static_assert(sizeof(long) >= sizeof(pid_t),
|
|
|
|
"pid_t should not be larger than long");
|
2014-05-23 19:47:07 +02:00
|
|
|
long pid = getpid();
|
2020-07-08 19:23:29 +02:00
|
|
|
XChangeProperty(xdisplay_, xwindow_, GetAtom(kNetWMPid), XA_CARDINAL, 32,
|
2017-07-27 01:19:27 +02:00
|
|
|
PropModeReplace, reinterpret_cast<unsigned char*>(&pid), 1);
|
2019-02-27 20:18:16 +01:00
|
|
|
|
|
|
|
// Set the initial window name, if provided.
|
|
|
|
if (!title.empty()) {
|
2020-07-08 19:23:29 +02:00
|
|
|
XChangeProperty(xdisplay_, xwindow_, GetAtom(kNetWMName),
|
|
|
|
GetAtom(kUTF8String), 8, PropModeReplace,
|
2019-02-27 20:18:16 +01:00
|
|
|
reinterpret_cast<const unsigned char*>(title.c_str()),
|
|
|
|
title.size());
|
|
|
|
}
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefWindowX11::~CefWindowX11() {
|
|
|
|
DCHECK(!xwindow_);
|
2020-03-30 22:13:42 +02:00
|
|
|
DCHECK(ui::X11EventSource::HasInstance());
|
|
|
|
ui::X11EventSource::GetInstance()->RemoveXEventDispatcher(this);
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowX11::Close() {
|
|
|
|
XEvent ev = {0};
|
|
|
|
ev.xclient.type = ClientMessage;
|
|
|
|
ev.xclient.window = xwindow_;
|
2020-07-08 19:23:29 +02:00
|
|
|
ev.xclient.message_type = GetAtom(kWMProtocols);
|
2014-05-23 19:47:07 +02:00
|
|
|
ev.xclient.format = 32;
|
2020-07-08 19:23:29 +02:00
|
|
|
ev.xclient.data.l[0] = GetAtom(kWMDeleteWindow);
|
2017-12-07 22:44:24 +01:00
|
|
|
ev.xclient.data.l[1] = x11::CurrentTime;
|
|
|
|
XSendEvent(xdisplay_, xwindow_, false, NoEventMask, &ev);
|
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() {
|
2017-12-07 22:44:24 +01:00
|
|
|
if (xwindow_ == x11::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.
|
|
|
|
XSizeHints size_hints;
|
|
|
|
size_hints.flags = PPosition | PWinGravity;
|
|
|
|
size_hints.x = bounds_.x();
|
|
|
|
size_hints.y = bounds_.y();
|
|
|
|
// Set StaticGravity so that the window position is not affected by the
|
|
|
|
// frame width when running with window manager.
|
|
|
|
size_hints.win_gravity = StaticGravity;
|
|
|
|
XSetWMNormalHints(xdisplay_, xwindow_, &size_hints);
|
|
|
|
|
|
|
|
XMapWindow(xdisplay_, xwindow_);
|
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
// TODO(thomasanderson): Find out why this flush is necessary.
|
|
|
|
XFlush(xdisplay_);
|
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.
|
|
|
|
::Window child = FindChild(xdisplay_, xwindow_);
|
|
|
|
::Window toplevel_window = FindToplevelParent(xdisplay_, xwindow_);
|
|
|
|
DCHECK(toplevel_window);
|
|
|
|
if (child && toplevel_window) {
|
|
|
|
// Configure the drag&drop proxy property for the top-most window so
|
|
|
|
// that all drag&drop-related messages will be sent to the child
|
|
|
|
// DesktopWindowTreeHostX11. The proxy property is referenced by
|
|
|
|
// DesktopDragDropClientAuraX11::FindWindowFor.
|
2020-07-08 19:23:29 +02:00
|
|
|
x11::Window window = x11::Window::None;
|
|
|
|
ui::GetProperty(ToX11Window(toplevel_window), gfx::GetAtom(kXdndProxy),
|
|
|
|
&window);
|
|
|
|
::Window proxy_target = ToWindow(window);
|
2014-10-27 23:20:11 +01:00
|
|
|
|
|
|
|
if (proxy_target != child) {
|
|
|
|
// Set the proxy target for the top-most window.
|
2020-07-08 19:23:29 +02:00
|
|
|
XChangeProperty(xdisplay_, toplevel_window, GetAtom(kXdndProxy),
|
2017-07-27 01:19:27 +02:00
|
|
|
XA_WINDOW, 32, PropModeReplace,
|
2017-05-17 11:29:28 +02:00
|
|
|
reinterpret_cast<unsigned char*>(&child), 1);
|
2014-10-27 23:20:11 +01:00
|
|
|
// Do the same for the proxy target per the spec.
|
2020-07-08 19:23:29 +02:00
|
|
|
XChangeProperty(xdisplay_, child, GetAtom(kXdndProxy), XA_WINDOW, 32,
|
|
|
|
PropModeReplace,
|
2017-05-17 11:29:28 +02:00
|
|
|
reinterpret_cast<unsigned char*>(&child), 1);
|
2014-10-27 23:20:11 +01:00
|
|
|
}
|
|
|
|
}
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowX11::Hide() {
|
2017-12-07 22:44:24 +01:00
|
|
|
if (xwindow_ == x11::None)
|
2014-05-23 19:47:07 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (window_mapped_) {
|
|
|
|
XWithdrawWindow(xdisplay_, xwindow_, 0);
|
|
|
|
window_mapped_ = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-06 21:04:21 +02:00
|
|
|
void CefWindowX11::Focus() {
|
2017-12-07 22:44:24 +01:00
|
|
|
if (xwindow_ == x11::None || !window_mapped_)
|
2014-06-06 21:04:21 +02:00
|
|
|
return;
|
|
|
|
|
2014-09-27 01:48:19 +02:00
|
|
|
if (browser_.get()) {
|
2014-07-01 00:30:29 +02:00
|
|
|
::Window child = FindChild(xdisplay_, xwindow_);
|
2020-07-08 19:23:29 +02:00
|
|
|
if (child && ui::IsWindowVisible(ToX11Window(child))) {
|
2014-07-01 00:30:29 +02:00
|
|
|
// Give focus to the child DesktopWindowTreeHostX11.
|
2017-12-07 22:44:24 +01:00
|
|
|
XSetInputFocus(xdisplay_, child, RevertToParent, x11::CurrentTime);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
} else {
|
2017-12-07 22:44:24 +01:00
|
|
|
XSetInputFocus(xdisplay_, xwindow_, RevertToParent, x11::CurrentTime);
|
2014-06-06 21:04:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-23 19:47:07 +02:00
|
|
|
void CefWindowX11::SetBounds(const gfx::Rect& bounds) {
|
2017-12-07 22:44:24 +01:00
|
|
|
if (xwindow_ == x11::None)
|
2014-05-23 19:47:07 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
bool origin_changed = bounds_.origin() != bounds.origin();
|
|
|
|
bool size_changed = bounds_.size() != bounds.size();
|
|
|
|
XWindowChanges changes = {0};
|
|
|
|
unsigned value_mask = 0;
|
|
|
|
|
|
|
|
if (size_changed) {
|
|
|
|
changes.width = bounds.width();
|
|
|
|
changes.height = bounds.height();
|
|
|
|
value_mask = CWHeight | CWWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (origin_changed) {
|
|
|
|
changes.x = bounds.x();
|
|
|
|
changes.y = bounds.y();
|
|
|
|
value_mask |= CWX | CWY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value_mask)
|
|
|
|
XConfigureWindow(xdisplay_, xwindow_, value_mask, &changes);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Rect CefWindowX11::GetBoundsInScreen() {
|
|
|
|
int x, y;
|
|
|
|
Window child;
|
|
|
|
if (XTranslateCoordinates(xdisplay_, xwindow_, DefaultRootWindow(xdisplay_),
|
|
|
|
0, 0, &x, &y, &child)) {
|
|
|
|
return gfx::Rect(gfx::Point(x, y), bounds_.size());
|
|
|
|
}
|
|
|
|
return gfx::Rect();
|
|
|
|
}
|
|
|
|
|
2014-10-29 19:14:47 +01:00
|
|
|
views::DesktopWindowTreeHostX11* CefWindowX11::GetHost() {
|
|
|
|
if (browser_.get()) {
|
|
|
|
::Window child = FindChild(xdisplay_, xwindow_);
|
2019-11-12 17:11:44 +01:00
|
|
|
if (child) {
|
|
|
|
return static_cast<views::DesktopWindowTreeHostX11*>(
|
2020-07-08 19:23:29 +02:00
|
|
|
views::DesktopWindowTreeHostLinux::GetHostForWidget(
|
|
|
|
ToX11Window(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) {
|
2020-03-30 22:13:42 +02:00
|
|
|
DCHECK_NE(xwindow_, x11::None);
|
|
|
|
return !!current_xevent_;
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t CefWindowX11::DispatchEvent(const ui::PlatformEvent& event) {
|
2020-03-30 22:13:42 +02:00
|
|
|
DCHECK_NE(xwindow_, x11::None);
|
|
|
|
DCHECK(event);
|
|
|
|
DCHECK(current_xevent_);
|
|
|
|
|
|
|
|
ProcessXEvent(current_xevent_);
|
|
|
|
return ui::POST_DISPATCH_STOP_PROPAGATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called by X11EventSourceLibevent to determine whether this XEventDispatcher
|
|
|
|
// implementation is able to process the next translated event sent by it.
|
2020-07-08 19:23:29 +02:00
|
|
|
void CefWindowX11::CheckCanDispatchNextPlatformEvent(x11::Event* x11_event) {
|
|
|
|
XEvent* xev = &x11_event->xlib_event();
|
|
|
|
current_xevent_ = IsTargetedBy(*x11_event) ? xev : nullptr;
|
2020-03-30 22:13:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowX11::PlatformEventDispatchFinished() {
|
|
|
|
current_xevent_ = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
ui::PlatformEventDispatcher* CefWindowX11::GetPlatformEventDispatcher() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2020-07-08 19:23:29 +02:00
|
|
|
bool CefWindowX11::DispatchXEvent(x11::Event* x11_event) {
|
|
|
|
if (!IsTargetedBy(*x11_event))
|
2020-03-30 22:13:42 +02:00
|
|
|
return false;
|
2020-07-08 19:23:29 +02:00
|
|
|
XEvent* xev = &x11_event->xlib_event();
|
2020-03-30 22:13:42 +02:00
|
|
|
ProcessXEvent(xev);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowX11::ContinueFocus() {
|
|
|
|
if (!focus_pending_)
|
|
|
|
return;
|
|
|
|
if (browser_.get())
|
|
|
|
browser_->SetFocus(true);
|
|
|
|
focus_pending_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefWindowX11::TopLevelAlwaysOnTop() const {
|
|
|
|
::Window toplevel_window = FindToplevelParent(xdisplay_, xwindow_);
|
|
|
|
|
2020-07-08 19:23:29 +02:00
|
|
|
Atom state_atom = GetAtom("_NET_WM_STATE");
|
|
|
|
Atom state_keep_above = GetAtom("_NET_WM_STATE_KEEP_ABOVE");
|
2020-03-30 22:13:42 +02:00
|
|
|
Atom* states;
|
|
|
|
|
|
|
|
Atom actual_type;
|
|
|
|
int actual_format;
|
|
|
|
unsigned long num_items;
|
|
|
|
unsigned long bytes_after;
|
|
|
|
|
|
|
|
XGetWindowProperty(xdisplay_, toplevel_window, state_atom, 0, 1024,
|
|
|
|
x11::False, XA_ATOM, &actual_type, &actual_format,
|
|
|
|
&num_items, &bytes_after,
|
|
|
|
reinterpret_cast<unsigned char**>(&states));
|
|
|
|
|
|
|
|
bool always_on_top = false;
|
|
|
|
|
|
|
|
for (unsigned long i = 0; i < num_items; ++i) {
|
|
|
|
if (states[i] == state_keep_above) {
|
|
|
|
always_on_top = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XFree(states);
|
|
|
|
|
|
|
|
return always_on_top;
|
|
|
|
}
|
|
|
|
|
2020-07-08 19:23:29 +02:00
|
|
|
bool CefWindowX11::IsTargetedBy(const x11::Event& x11_event) const {
|
|
|
|
const XEvent& xev = x11_event.xlib_event();
|
2020-03-30 22:13:42 +02:00
|
|
|
::Window target_window =
|
2020-07-08 19:23:29 +02:00
|
|
|
xev.type == x11::GeGenericEvent::opcode
|
2020-03-30 22:13:42 +02:00
|
|
|
? static_cast<XIDeviceEvent*>(xev.xcookie.data)->event
|
|
|
|
: xev.xany.window;
|
|
|
|
return target_window == xwindow_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowX11::ProcessXEvent(XEvent* xev) {
|
2014-05-23 19:47:07 +02:00
|
|
|
switch (xev->type) {
|
|
|
|
case ConfigureNotify: {
|
|
|
|
DCHECK_EQ(xwindow_, xev->xconfigure.event);
|
|
|
|
DCHECK_EQ(xwindow_, xev->xconfigure.window);
|
|
|
|
// 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.
|
|
|
|
gfx::Rect bounds(xev->xconfigure.x, xev->xconfigure.y,
|
2017-05-17 11:29:28 +02:00
|
|
|
xev->xconfigure.width, xev->xconfigure.height);
|
2014-05-23 19:47:07 +02:00
|
|
|
bounds_ = bounds;
|
|
|
|
|
2014-09-27 01:48:19 +02:00
|
|
|
if (browser_.get()) {
|
2014-07-01 00:30:29 +02:00
|
|
|
::Window child = FindChild(xdisplay_, xwindow_);
|
|
|
|
if (child) {
|
|
|
|
// Resize the child DesktopWindowTreeHostX11 to match this window.
|
|
|
|
XWindowChanges changes = {0};
|
|
|
|
changes.width = bounds.width();
|
|
|
|
changes.height = bounds.height();
|
|
|
|
XConfigureWindow(xdisplay_, child, CWHeight | CWWidth, &changes);
|
2014-07-09 00:37:06 +02:00
|
|
|
|
2014-10-29 19:14:47 +01:00
|
|
|
browser_->NotifyMoveOrResizeStarted();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ClientMessage: {
|
2014-07-09 00:37:06 +02:00
|
|
|
Atom message_type = xev->xclient.message_type;
|
2020-07-08 19:23:29 +02:00
|
|
|
if (message_type == GetAtom(kWMProtocols)) {
|
2014-07-09 00:37:06 +02:00
|
|
|
Atom protocol = static_cast<Atom>(xev->xclient.data.l[0]);
|
2020-07-08 19:23:29 +02:00
|
|
|
if (protocol == GetAtom(kWMDeleteWindow)) {
|
2014-07-09 00:37:06 +02:00
|
|
|
// We have received a close message from the window manager.
|
2016-01-19 21:09:01 +01:00
|
|
|
if (!browser_ || browser_->TryCloseBrowser()) {
|
2014-07-09 00:37:06 +02:00
|
|
|
// Allow the close.
|
|
|
|
XDestroyWindow(xdisplay_, xwindow_);
|
2017-09-21 16:04:30 +02:00
|
|
|
|
2017-12-07 22:44:24 +01:00
|
|
|
xwindow_ = x11::None;
|
2017-09-21 16:04:30 +02:00
|
|
|
|
|
|
|
if (browser_.get()) {
|
|
|
|
// Force the browser to be destroyed and release the reference
|
|
|
|
// added in PlatformCreateWindow().
|
|
|
|
browser_->WindowDestroyed();
|
|
|
|
}
|
|
|
|
|
|
|
|
delete this;
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
2020-07-08 19:23:29 +02:00
|
|
|
} else if (protocol == GetAtom(kNetWMPing)) {
|
2014-07-09 00:37:06 +02:00
|
|
|
XEvent reply_event = *xev;
|
|
|
|
reply_event.xclient.window = parent_xwindow_;
|
|
|
|
|
2017-12-07 22:44:24 +01:00
|
|
|
XSendEvent(xdisplay_, reply_event.xclient.window, false,
|
2014-07-09 00:37:06 +02:00
|
|
|
SubstructureRedirectMask | SubstructureNotifyMask,
|
|
|
|
&reply_event);
|
|
|
|
XFlush(xdisplay_);
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-03-20 21:15:08 +01:00
|
|
|
case x11::FocusIn:
|
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
|
|
|
|
// (hosted in a DesktopWindowTreeHostX11) as unfocused. Use a delayed
|
|
|
|
// 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
|
|
|
}
|
|
|
|
break;
|
2018-03-20 21:15:08 +01:00
|
|
|
case x11::FocusOut:
|
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;
|
2014-05-23 19:47:07 +02:00
|
|
|
break;
|
2014-09-11 20:23:10 +02:00
|
|
|
case PropertyNotify: {
|
|
|
|
::Atom changed_atom = xev->xproperty.atom;
|
2020-07-08 19:23:29 +02:00
|
|
|
if (changed_atom == GetAtom(kNetWMState)) {
|
2014-09-11 20:23:10 +02:00
|
|
|
// State change event like minimize/maximize.
|
2014-09-27 01:48:19 +02:00
|
|
|
if (browser_.get()) {
|
2014-09-11 20:23:10 +02:00
|
|
|
::Window child = FindChild(xdisplay_, xwindow_);
|
|
|
|
if (child) {
|
|
|
|
// Forward the state change to the child DesktopWindowTreeHostX11
|
|
|
|
// window so that resource usage will be reduced while the window is
|
|
|
|
// minimized.
|
2020-07-08 19:23:29 +02:00
|
|
|
std::vector<x11::Atom> atom_list;
|
|
|
|
if (ui::GetAtomArrayProperty(ToX11Window(xwindow_), kNetWMState,
|
|
|
|
&atom_list) &&
|
2014-09-11 20:23:10 +02:00
|
|
|
!atom_list.empty()) {
|
2020-07-08 19:23:29 +02:00
|
|
|
ui::SetAtomArrayProperty(ToX11Window(child), kNetWMState, "ATOM",
|
|
|
|
atom_list);
|
2014-09-11 20:23:10 +02:00
|
|
|
} else {
|
|
|
|
// Set an empty list of property values to pass the check in
|
|
|
|
// DesktopWindowTreeHostX11::OnWMStateUpdated().
|
2017-05-17 11:29:28 +02:00
|
|
|
XChangeProperty(xdisplay_, child,
|
2020-07-08 19:23:29 +02:00
|
|
|
GetAtom(kNetWMState), // name
|
|
|
|
GetAtom(kAtom), // type
|
2014-09-11 20:23:10 +02:00
|
|
|
32, // size in bits of items in 'value'
|
2017-05-17 11:29:28 +02:00
|
|
|
PropModeReplace, NULL,
|
2014-09-11 20:23:10 +02:00
|
|
|
0); // num items
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-05-23 19:47:07 +02:00
|
|
|
}
|
2018-02-28 05:47:36 +01:00
|
|
|
}
|