Commit c5ae0723 authored by Alexander Dunaev's avatar Alexander Dunaev Committed by Commit Bot

[ozone/x11] Enabled idle time features.

The Linux implementation of //ui/base/idle was X11-only and was not
aware of Ozone.

This CL fixes that by moving the necessary pieces from //ui/base/idle to
//ui/base/x and extending the Screen and PlatformScreen interfaces with
two methods: IsScreenSaverActive() and CalculateIdleTime().

Bug: 1098201, 1098202
Change-Id: I5ab4dcde323562000b3b3870a778ba3515a774d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2504234
Commit-Queue: Alexander Dunaev <adunaev@igalia.com>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822537}
parent fe51630e
...@@ -89,6 +89,14 @@ void ScreenOzone::SetScreenSaverSuspended(bool suspend) { ...@@ -89,6 +89,14 @@ void ScreenOzone::SetScreenSaverSuspended(bool suspend) {
platform_screen_->SetScreenSaverSuspended(suspend); platform_screen_->SetScreenSaverSuspended(suspend);
} }
bool ScreenOzone::IsScreenSaverActive() const {
return platform_screen_->IsScreenSaverActive();
}
base::TimeDelta ScreenOzone::CalculateIdleTime() const {
return platform_screen_->CalculateIdleTime();
}
void ScreenOzone::AddObserver(display::DisplayObserver* observer) { void ScreenOzone::AddObserver(display::DisplayObserver* observer) {
platform_screen_->AddObserver(observer); platform_screen_->AddObserver(observer);
} }
......
...@@ -42,6 +42,8 @@ class AURA_EXPORT ScreenOzone : public display::Screen { ...@@ -42,6 +42,8 @@ class AURA_EXPORT ScreenOzone : public display::Screen {
const gfx::Rect& match_rect) const override; const gfx::Rect& match_rect) const override;
display::Display GetPrimaryDisplay() const override; display::Display GetPrimaryDisplay() const override;
void SetScreenSaverSuspended(bool suspend) override; void SetScreenSaverSuspended(bool suspend) override;
bool IsScreenSaverActive() const override;
base::TimeDelta CalculateIdleTime() const override;
void AddObserver(display::DisplayObserver* observer) override; void AddObserver(display::DisplayObserver* observer) override;
void RemoveObserver(display::DisplayObserver* observer) override; void RemoveObserver(display::DisplayObserver* observer) override;
std::string GetCurrentWorkspace() override; std::string GetCurrentWorkspace() override;
......
...@@ -55,12 +55,13 @@ component("idle") { ...@@ -55,12 +55,13 @@ component("idle") {
} }
if (use_x11 && !is_chromeos) { if (use_x11 && !is_chromeos) {
deps += [ "//ui/gfx/x" ] deps += [ "//ui/base/x" ]
sources += [ }
"idle_query_x11.cc",
"idle_query_x11.h", if (use_ozone) {
"screensaver_window_finder_x11.cc", deps += [
"screensaver_window_finder_x11.h", "//ui/base:features",
"//ui/display",
] ]
} }
......
...@@ -7,36 +7,56 @@ ...@@ -7,36 +7,56 @@
#include "ui/base/idle/idle_internal.h" #include "ui/base/idle/idle_internal.h"
#if defined(USE_X11) #if defined(USE_X11)
#include "ui/base/idle/idle_query_x11.h" #include "ui/base/x/x11_idle_query.h"
#include "ui/base/idle/screensaver_window_finder_x11.h" #include "ui/base/x/x11_screensaver_window_finder.h"
#endif
#if defined(USE_OZONE)
#include "ui/base/ui_base_features.h" #include "ui/base/ui_base_features.h"
#include "ui/display/screen.h"
#endif #endif
namespace ui { namespace ui {
int CalculateIdleTime() { int CalculateIdleTime() {
// TODO(https://crbug.com/1098201): calculate idle time for Ozone/Linux. #if defined(USE_OZONE)
#if defined(USE_X11) if (features::IsUsingOzonePlatform()) {
if (!features::IsUsingOzonePlatform()) { auto* const screen = display::Screen::GetScreen();
IdleQueryX11 idle_query; // The screen can be nullptr in tests.
return idle_query.IdleTime(); if (!screen)
return 0;
return screen->CalculateIdleTime().InSeconds();
} }
#endif #endif
#if defined(USE_X11)
IdleQueryX11 idle_query;
return idle_query.IdleTime();
#else
NOTIMPLEMENTED_LOG_ONCE();
return 0; return 0;
#endif
} }
bool CheckIdleStateIsLocked() { bool CheckIdleStateIsLocked() {
if (IdleStateForTesting().has_value()) if (IdleStateForTesting().has_value())
return IdleStateForTesting().value() == IDLE_STATE_LOCKED; return IdleStateForTesting().value() == IDLE_STATE_LOCKED;
// TODO(https://crbug.com/1098202): fix screensaver. #if defined(USE_OZONE)
#if defined(USE_X11) if (features::IsUsingOzonePlatform()) {
if (!features::IsUsingOzonePlatform()) { auto* const screen = display::Screen::GetScreen();
// Usually the screensaver is used to lock the screen. // The screen can be nullptr in tests.
return ScreensaverWindowFinder::ScreensaverWindowExists(); if (!screen)
return false;
return screen->IsScreenSaverActive();
} }
#endif #endif
#if defined(USE_X11)
// Usually the screensaver is used to lock the screen.
return ScreensaverWindowFinder::ScreensaverWindowExists();
#else
NOTIMPLEMENTED_LOG_ONCE();
return false; return false;
#endif
} }
} // namespace ui } // namespace ui
...@@ -26,6 +26,8 @@ component("x") { ...@@ -26,6 +26,8 @@ component("x") {
"x11_display_manager.h", "x11_display_manager.h",
"x11_display_util.cc", "x11_display_util.cc",
"x11_display_util.h", "x11_display_util.h",
"x11_idle_query.cc",
"x11_idle_query.h",
"x11_menu_list.cc", "x11_menu_list.cc",
"x11_menu_list.h", "x11_menu_list.h",
"x11_menu_registrar.cc", "x11_menu_registrar.cc",
...@@ -34,6 +36,8 @@ component("x") { ...@@ -34,6 +36,8 @@ component("x") {
"x11_move_loop_delegate.h", "x11_move_loop_delegate.h",
"x11_pointer_grab.cc", "x11_pointer_grab.cc",
"x11_pointer_grab.h", "x11_pointer_grab.h",
"x11_screensaver_window_finder.cc",
"x11_screensaver_window_finder.h",
"x11_shm_image_pool.cc", "x11_shm_image_pool.cc",
"x11_shm_image_pool.h", "x11_shm_image_pool.h",
"x11_software_bitmap_presenter.cc", "x11_software_bitmap_presenter.cc",
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "ui/base/idle/idle_query_x11.h" #include "ui/base/x/x11_idle_query.h"
#include "ui/gfx/x/connection.h" #include "ui/gfx/x/connection.h"
#include "ui/gfx/x/screensaver.h" #include "ui/gfx/x/screensaver.h"
......
...@@ -2,11 +2,10 @@ ...@@ -2,11 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef UI_BASE_IDLE_IDLE_QUERY_X11_H_ #ifndef UI_BASE_X_X11_IDLE_QUERY_H_
#define UI_BASE_IDLE_IDLE_QUERY_X11_H_ #define UI_BASE_X_X11_IDLE_QUERY_H_
#include <memory>
#include "base/component_export.h"
#include "base/macros.h" #include "base/macros.h"
namespace x11 { namespace x11 {
...@@ -15,7 +14,7 @@ class Connection; ...@@ -15,7 +14,7 @@ class Connection;
namespace ui { namespace ui {
class IdleQueryX11 { class COMPONENT_EXPORT(UI_BASE_X) IdleQueryX11 {
public: public:
IdleQueryX11(); IdleQueryX11();
~IdleQueryX11(); ~IdleQueryX11();
...@@ -30,4 +29,4 @@ class IdleQueryX11 { ...@@ -30,4 +29,4 @@ class IdleQueryX11 {
} // namespace ui } // namespace ui
#endif // UI_BASE_IDLE_IDLE_QUERY_X11_H_ #endif // UI_BASE_X_X11_IDLE_QUERY_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "ui/base/idle/screensaver_window_finder_x11.h" #include "ui/base/x/x11_screensaver_window_finder.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "ui/base/x/x11_util.h" #include "ui/base/x/x11_util.h"
...@@ -16,6 +16,7 @@ namespace ui { ...@@ -16,6 +16,7 @@ namespace ui {
ScreensaverWindowFinder::ScreensaverWindowFinder() : exists_(false) {} ScreensaverWindowFinder::ScreensaverWindowFinder() : exists_(false) {}
// static
bool ScreensaverWindowFinder::ScreensaverWindowExists() { bool ScreensaverWindowFinder::ScreensaverWindowExists() {
// Avoid calling into potentially missing X11 APIs in headless mode. // Avoid calling into potentially missing X11 APIs in headless mode.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kHeadless)) if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kHeadless))
......
...@@ -2,16 +2,17 @@ ...@@ -2,16 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef UI_BASE_IDLE_SCREENSAVER_WINDOW_FINDER_X11_H_ #ifndef UI_BASE_X_X11_SCREENSAVER_WINDOW_FINDER_H_
#define UI_BASE_IDLE_SCREENSAVER_WINDOW_FINDER_X11_H_ #define UI_BASE_X_X11_SCREENSAVER_WINDOW_FINDER_H_
#include "base/compiler_specific.h" #include "base/component_export.h"
#include "base/macros.h" #include "base/macros.h"
#include "ui/base/x/x11_util.h" #include "ui/base/x/x11_util.h"
namespace ui { namespace ui {
class ScreensaverWindowFinder : public ui::EnumerateWindowsDelegate { class COMPONENT_EXPORT(UI_BASE_X) ScreensaverWindowFinder
: public ui::EnumerateWindowsDelegate {
public: public:
static bool ScreensaverWindowExists(); static bool ScreensaverWindowExists();
...@@ -30,4 +31,4 @@ class ScreensaverWindowFinder : public ui::EnumerateWindowsDelegate { ...@@ -30,4 +31,4 @@ class ScreensaverWindowFinder : public ui::EnumerateWindowsDelegate {
} // namespace ui } // namespace ui
#endif // UI_BASE_IDLE_SCREENSAVER_WINDOW_FINDER_X11_H_ #endif // UI_BASE_X_X11_SCREENSAVER_WINDOW_FINDER_H_
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/check.h" #include "base/check.h"
#include "base/notreached.h" #include "base/notreached.h"
#include "base/time/time.h"
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/display/types/display_constants.h" #include "ui/display/types/display_constants.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
...@@ -67,6 +68,16 @@ void Screen::SetScreenSaverSuspended(bool suspend) { ...@@ -67,6 +68,16 @@ void Screen::SetScreenSaverSuspended(bool suspend) {
NOTIMPLEMENTED_LOG_ONCE(); NOTIMPLEMENTED_LOG_ONCE();
} }
bool Screen::IsScreenSaverActive() const {
NOTIMPLEMENTED_LOG_ONCE();
return false;
}
base::TimeDelta Screen::CalculateIdleTime() const {
NOTIMPLEMENTED_LOG_ONCE();
return base::TimeDelta::FromSeconds(0);
}
gfx::Rect Screen::ScreenToDIPRectInWindow(gfx::NativeWindow window, gfx::Rect Screen::ScreenToDIPRectInWindow(gfx::NativeWindow window,
const gfx::Rect& screen_rect) const { const gfx::Rect& screen_rect) const {
float scale = GetDisplayNearestWindow(window).device_scale_factor(); float scale = GetDisplayNearestWindow(window).device_scale_factor();
......
...@@ -15,10 +15,14 @@ ...@@ -15,10 +15,14 @@
#include "ui/gfx/gpu_extra_info.h" #include "ui/gfx/gpu_extra_info.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
namespace base {
class TimeDelta;
} // namespace base
namespace gfx { namespace gfx {
class Point; class Point;
class Rect; class Rect;
} } // namespace gfx
namespace display { namespace display {
class DisplayObserver; class DisplayObserver;
...@@ -101,6 +105,12 @@ class DISPLAY_EXPORT Screen { ...@@ -101,6 +105,12 @@ class DISPLAY_EXPORT Screen {
// Suspends the platform-specific screensaver, if applicable. // Suspends the platform-specific screensaver, if applicable.
virtual void SetScreenSaverSuspended(bool suspend); virtual void SetScreenSaverSuspended(bool suspend);
// Returns whether the screensaver is currently running.
virtual bool IsScreenSaverActive() const;
// Calculates idle time.
virtual base::TimeDelta CalculateIdleTime() const;
// Adds/Removes display observers. // Adds/Removes display observers.
virtual void AddObserver(DisplayObserver* observer) = 0; virtual void AddObserver(DisplayObserver* observer) = 0;
virtual void RemoveObserver(DisplayObserver* observer) = 0; virtual void RemoveObserver(DisplayObserver* observer) = 0;
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "ui/ozone/platform/x11/x11_screen_ozone.h" #include "ui/ozone/platform/x11/x11_screen_ozone.h"
#include "ui/base/x/x11_idle_query.h"
#include "ui/base/x/x11_screensaver_window_finder.h"
#include "ui/base/x/x11_util.h" #include "ui/base/x/x11_util.h"
#include "ui/display/display_finder.h" #include "ui/display/display_finder.h"
#include "ui/display/util/display_util.h" #include "ui/display/util/display_util.h"
...@@ -124,6 +126,16 @@ void X11ScreenOzone::SetScreenSaverSuspended(bool suspend) { ...@@ -124,6 +126,16 @@ void X11ScreenOzone::SetScreenSaverSuspended(bool suspend) {
SuspendX11ScreenSaver(suspend); SuspendX11ScreenSaver(suspend);
} }
bool X11ScreenOzone::IsScreenSaverActive() const {
// Usually the screensaver is used to lock the screen.
return ScreensaverWindowFinder::ScreensaverWindowExists();
}
base::TimeDelta X11ScreenOzone::CalculateIdleTime() const {
IdleQueryX11 idle_query;
return base::TimeDelta::FromSeconds(idle_query.IdleTime());
}
void X11ScreenOzone::AddObserver(display::DisplayObserver* observer) { void X11ScreenOzone::AddObserver(display::DisplayObserver* observer) {
x11_display_manager_->AddObserver(observer); x11_display_manager_->AddObserver(observer);
} }
......
...@@ -48,6 +48,8 @@ class X11ScreenOzone : public PlatformScreen, ...@@ -48,6 +48,8 @@ class X11ScreenOzone : public PlatformScreen,
display::Display GetDisplayMatching( display::Display GetDisplayMatching(
const gfx::Rect& match_rect_in_pixels) const override; const gfx::Rect& match_rect_in_pixels) const override;
void SetScreenSaverSuspended(bool suspend) override; void SetScreenSaverSuspended(bool suspend) override;
bool IsScreenSaverActive() const override;
base::TimeDelta CalculateIdleTime() const override;
void AddObserver(display::DisplayObserver* observer) override; void AddObserver(display::DisplayObserver* observer) override;
void RemoveObserver(display::DisplayObserver* observer) override; void RemoveObserver(display::DisplayObserver* observer) override;
std::string GetCurrentWorkspace() override; std::string GetCurrentWorkspace() override;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "ui/ozone/public/platform_screen.h" #include "ui/ozone/public/platform_screen.h"
#include "base/notreached.h" #include "base/notreached.h"
#include "base/time/time.h"
namespace ui { namespace ui {
...@@ -27,6 +28,16 @@ void PlatformScreen::SetScreenSaverSuspended(bool suspend) { ...@@ -27,6 +28,16 @@ void PlatformScreen::SetScreenSaverSuspended(bool suspend) {
NOTIMPLEMENTED_LOG_ONCE(); NOTIMPLEMENTED_LOG_ONCE();
} }
bool PlatformScreen::IsScreenSaverActive() const {
NOTIMPLEMENTED_LOG_ONCE();
return false;
}
base::TimeDelta PlatformScreen::CalculateIdleTime() const {
NOTIMPLEMENTED_LOG_ONCE();
return base::TimeDelta::FromSeconds(0);
}
base::Value PlatformScreen::GetGpuExtraInfoAsListValue( base::Value PlatformScreen::GetGpuExtraInfoAsListValue(
const gfx::GpuExtraInfo& gpu_extra_info) { const gfx::GpuExtraInfo& gpu_extra_info) {
return base::Value(base::Value::Type::LIST); return base::Value(base::Value::Type::LIST);
......
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
#include "ui/gfx/gpu_extra_info.h" #include "ui/gfx/gpu_extra_info.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
namespace base {
class TimeDelta;
} // namespace base
namespace display { namespace display {
class Display; class Display;
class DisplayObserver; class DisplayObserver;
...@@ -82,6 +86,12 @@ class COMPONENT_EXPORT(OZONE_BASE) PlatformScreen { ...@@ -82,6 +86,12 @@ class COMPONENT_EXPORT(OZONE_BASE) PlatformScreen {
// Suspends the platform-specific screensaver, if applicable. // Suspends the platform-specific screensaver, if applicable.
virtual void SetScreenSaverSuspended(bool suspend); virtual void SetScreenSaverSuspended(bool suspend);
// Returns whether the screensaver is currently running.
virtual bool IsScreenSaverActive() const;
// Calculates idle time.
virtual base::TimeDelta CalculateIdleTime() const;
// Adds/Removes display observers. // Adds/Removes display observers.
virtual void AddObserver(display::DisplayObserver* observer) = 0; virtual void AddObserver(display::DisplayObserver* observer) = 0;
virtual void RemoveObserver(display::DisplayObserver* observer) = 0; virtual void RemoveObserver(display::DisplayObserver* observer) = 0;
......
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