summaryrefslogtreecommitdiff
path: root/chromium/ui/views/widget/desktop_aura/desktop_screen_x11.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/ui/views/widget/desktop_aura/desktop_screen_x11.cc')
-rw-r--r--chromium/ui/views/widget/desktop_aura/desktop_screen_x11.cc121
1 files changed, 43 insertions, 78 deletions
diff --git a/chromium/ui/views/widget/desktop_aura/desktop_screen_x11.cc b/chromium/ui/views/widget/desktop_aura/desktop_screen_x11.cc
index 6ca1be4cc9e..0ffdc450043 100644
--- a/chromium/ui/views/widget/desktop_aura/desktop_screen_x11.cc
+++ b/chromium/ui/views/widget/desktop_aura/desktop_screen_x11.cc
@@ -4,6 +4,8 @@
#include "ui/views/widget/desktop_aura/desktop_screen_x11.h"
+#include <vector>
+
#include "base/command_line.h"
#include "base/trace_event/trace_event.h"
#include "ui/aura/window.h"
@@ -15,72 +17,41 @@
#include "ui/display/display.h"
#include "ui/display/display_finder.h"
#include "ui/display/util/display_util.h"
-#include "ui/events/platform/platform_event_source.h"
-#include "ui/events/platform/x11/x11_event_source.h"
#include "ui/gfx/font_render_params.h"
#include "ui/gfx/geometry/dip_util.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/switches.h"
-#include "ui/views/linux_ui/linux_ui.h"
#include "ui/views/widget/desktop_aura/desktop_screen.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
#include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h"
-namespace {
-
-float GetDeviceScaleFactor() {
- float device_scale_factor = 1.0f;
- if (views::LinuxUI::instance()) {
- device_scale_factor = views::LinuxUI::instance()->GetDeviceScaleFactor();
- } else if (display::Display::HasForceDeviceScaleFactor()) {
- device_scale_factor = display::Display::GetForcedDeviceScaleFactor();
- }
- return device_scale_factor;
-}
-
-} // namespace
-
namespace views {
-////////////////////////////////////////////////////////////////////////////////
-// DesktopScreenX11, public:
-
-DesktopScreenX11::DesktopScreenX11()
- : x11_display_manager_(std::make_unique<ui::XDisplayManager>(this)) {
- if (auto* linux_ui = views::LinuxUI::instance())
- linux_ui->AddDeviceScaleFactorObserver(this);
+DesktopScreenX11::DesktopScreenX11() {
+ if (LinuxUI::instance())
+ display_scale_factor_observer_.Add(LinuxUI::instance());
}
-DesktopScreenX11::~DesktopScreenX11() {
- if (auto* linux_ui = views::LinuxUI::instance())
- linux_ui->RemoveDeviceScaleFactorObserver(this);
- if (x11_display_manager_->IsXrandrAvailable() &&
- ui::PlatformEventSource::GetInstance()) {
- ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
- }
-}
+DesktopScreenX11::~DesktopScreenX11() = default;
void DesktopScreenX11::Init() {
if (x11_display_manager_->IsXrandrAvailable() &&
- ui::PlatformEventSource::GetInstance()) {
- ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
- }
+ ui::X11EventSource::HasInstance())
+ event_source_observer_.Add(ui::X11EventSource::GetInstance());
x11_display_manager_->Init();
}
-////////////////////////////////////////////////////////////////////////////////
-// DesktopScreenX11, display::Screen implementation:
-
gfx::Point DesktopScreenX11::GetCursorScreenPoint() {
TRACE_EVENT0("views", "DesktopScreenX11::GetCursorScreenPoint()");
- if (auto* event_source = ui::X11EventSource::GetInstance()) {
- auto point = event_source->GetRootCursorLocationFromCurrentEvent();
- if (point)
- return gfx::ConvertPointToDIP(GetDeviceScaleFactor(), point.value());
- }
- return gfx::ConvertPointToDIP(GetDeviceScaleFactor(),
- x11_display_manager_->GetCursorLocation());
+ base::Optional<gfx::Point> point;
+ if (const auto* const event_source = ui::X11EventSource::GetInstance())
+ point = event_source->GetRootCursorLocationFromCurrentEvent();
+ return gfx::ConvertPointToDIP(
+ GetXDisplayScaleFactor(),
+ // NB: Do NOT call value_or() here, since that would defeat the purpose of
+ // caching |point|.
+ point ? point.value() : x11_display_manager_->GetCursorLocation());
}
bool DesktopScreenX11::IsWindowUnderCursor(gfx::NativeWindow window) {
@@ -89,13 +60,12 @@ bool DesktopScreenX11::IsWindowUnderCursor(gfx::NativeWindow window) {
gfx::NativeWindow DesktopScreenX11::GetWindowAtScreenPoint(
const gfx::Point& point) {
- X11TopmostWindowFinder finder;
- return finder.FindLocalProcessWindowAt(
- gfx::ConvertPointToPixel(GetDeviceScaleFactor(), point), {});
+ return X11TopmostWindowFinder().FindLocalProcessWindowAt(
+ gfx::ConvertPointToPixel(GetXDisplayScaleFactor(), point), {});
}
int DesktopScreenX11::GetNumDisplays() const {
- return x11_display_manager_->displays().size();
+ return int{x11_display_manager_->displays().size()};
}
const std::vector<display::Display>& DesktopScreenX11::GetAllDisplays() const {
@@ -104,9 +74,6 @@ const std::vector<display::Display>& DesktopScreenX11::GetAllDisplays() const {
display::Display DesktopScreenX11::GetDisplayNearestWindow(
gfx::NativeView window) const {
- if (!window)
- return GetPrimaryDisplay();
-
// Getting screen bounds here safely is hard.
//
// You'd think we'd be able to just call window->GetBoundsInScreen(), but we
@@ -116,15 +83,14 @@ display::Display DesktopScreenX11::GetDisplayNearestWindow(
// created before we create the aura::WindowEventDispatcher. So we ask what
// the DRWHX11 believes the window bounds are instead of going through the
// aura::Window's screen bounds.
- aura::WindowTreeHost* host = window->GetHost();
- if (host) {
- auto* rwh = DesktopWindowTreeHostLinux::GetHostForWidget(
- host->GetAcceleratedWidget());
- if (rwh) {
- const gfx::Rect pixel_rect = rwh->GetBoundsInPixels();
- const gfx::Rect dip_rect =
- gfx::ConvertRectToDIP(GetDeviceScaleFactor(), pixel_rect);
- return GetDisplayMatching(dip_rect);
+ if (aura::WindowTreeHost* host = window ? window->GetHost() : nullptr) {
+ const auto* const desktop_host =
+ DesktopWindowTreeHostLinux::GetHostForWidget(
+ host->GetAcceleratedWidget());
+ if (desktop_host) {
+ const gfx::Rect pixel_rect = desktop_host->GetBoundsInPixels();
+ return GetDisplayMatching(
+ gfx::ConvertRectToDIP(GetXDisplayScaleFactor(), pixel_rect));
}
}
@@ -133,16 +99,15 @@ display::Display DesktopScreenX11::GetDisplayNearestWindow(
display::Display DesktopScreenX11::GetDisplayNearestPoint(
const gfx::Point& point) const {
- if (GetNumDisplays() <= 1)
- return GetPrimaryDisplay();
- return *FindDisplayNearestPoint(GetAllDisplays(), point);
+ return (GetNumDisplays() <= 1)
+ ? GetPrimaryDisplay()
+ : *FindDisplayNearestPoint(GetAllDisplays(), point);
}
display::Display DesktopScreenX11::GetDisplayMatching(
const gfx::Rect& match_rect) const {
- const display::Display* matching =
+ const display::Display* const matching =
display::FindDisplayWithBiggestIntersection(GetAllDisplays(), match_rect);
- // Fallback to the primary display if there is no matching display.
return matching ? *matching : GetPrimaryDisplay();
}
@@ -158,13 +123,13 @@ void DesktopScreenX11::RemoveObserver(display::DisplayObserver* observer) {
x11_display_manager_->RemoveObserver(observer);
}
-bool DesktopScreenX11::CanDispatchEvent(const ui::PlatformEvent& event) {
- return x11_display_manager_->CanProcessEvent(*event);
+std::string DesktopScreenX11::GetCurrentWorkspace() {
+ return x11_display_manager_->GetCurrentWorkspace();
}
-uint32_t DesktopScreenX11::DispatchEvent(const ui::PlatformEvent& event) {
- ignore_result(x11_display_manager_->ProcessEvent(event));
- return ui::POST_DISPATCH_NONE;
+bool DesktopScreenX11::DispatchXEvent(XEvent* event) {
+ return x11_display_manager_->CanProcessEvent(*event) &&
+ x11_display_manager_->ProcessEvent(event);
}
void DesktopScreenX11::OnDeviceScaleFactorChanged() {
@@ -173,21 +138,21 @@ void DesktopScreenX11::OnDeviceScaleFactorChanged() {
// static
void DesktopScreenX11::UpdateDeviceScaleFactorForTest() {
- DesktopScreenX11* screen =
- static_cast<DesktopScreenX11*>(display::Screen::GetScreen());
+ auto* screen = static_cast<DesktopScreenX11*>(display::Screen::GetScreen());
screen->x11_display_manager_->UpdateDisplayList();
}
-////////////////////////////////////////////////////////////////////////////////
-// DesktopScreenX11, private:
-
void DesktopScreenX11::OnXDisplayListUpdated() {
gfx::SetFontRenderParamsDeviceScaleFactor(
GetPrimaryDisplay().device_scale_factor());
}
-float DesktopScreenX11::GetXDisplayScaleFactor() {
- return GetDeviceScaleFactor();
+float DesktopScreenX11::GetXDisplayScaleFactor() const {
+ if (LinuxUI::instance())
+ return LinuxUI::instance()->GetDeviceScaleFactor();
+ return display::Display::HasForceDeviceScaleFactor()
+ ? display::Display::GetForcedDeviceScaleFactor()
+ : 1.0f;
}
////////////////////////////////////////////////////////////////////////////////