Skip to content

Commit

Permalink
fix: Wayland general CSD fixes (#35207)
Browse files Browse the repository at this point in the history
* fix: broken wayland window decorations due to botched chromium update

The `GetTitlebarBounds().height()` is obviously intended to be placed in
the `top` parameter, which used to be the second one before upstream
removed multi-parameter `gfx::Rect::Inset`, but it's the first parameter
for `gfx::Insets::TLBR`, which was intended to replace the removed
`Inset` function. However, whoever updated Chromium kept the parameter
unchanged, causing the title bar height to be passed to the `left`
parameter, causing the window title bar to be unclickable.

* fix: wayland window top bar buttons unclickable

Use NonClientFrameView::TargetForRect for the ClientFrameViewLinux
implementation because the default inherited from FramelessView blocks
any non-HTCLIENT events.

* fix: add maximized parameter to LinuxUI::GetWindowFrameProvider

* fix: pass frame_->IsMaximized() to GetWindowFrameProvider

This ensures that the toolkit renders the window decorations in maximized mode
while the window is maximized to ensure that there is no empty space around the window.
  • Loading branch information
msizanoen1 committed Aug 4, 2022
1 parent a5cafd1 commit 4b48379
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 2 deletions.
1 change: 1 addition & 0 deletions patches/chromium/.patches
Expand Up @@ -125,3 +125,4 @@ keep_handling_scroll_update_if_you_can.patch
chore_add_electron_deps_to_gitignores.patch
chore_allow_chromium_to_handle_synthetic_mouse_events_for_touch.patch
disable_gpu_acceleration_on_vmware_on_linux.patch
add_maximized_parameter_to_linuxui_getwindowframeprovider.patch
@@ -0,0 +1,176 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: msizanoen1 <msizanoen@qtmlabs.xyz>
Date: Tue, 19 Jul 2022 05:11:06 +0200
Subject: Add maximized parameter to LinuxUI::GetWindowFrameProvider

This allows ClientFrameViewLinux to instruct the toolkit to draw the window
decorations in maximized mode where needed, preventing empty space caused
by decoration shadows and rounded titlebars around the window while maximized.

diff --git a/ui/gtk/gtk_ui.cc b/ui/gtk/gtk_ui.cc
index c037fa8db6d4a5ebeb7257627db206e9bab57ecc..14eddfd043e748400a9ee81ce5346a53f10ea03c 100644
--- a/ui/gtk/gtk_ui.cc
+++ b/ui/gtk/gtk_ui.cc
@@ -757,13 +757,15 @@ std::unique_ptr<views::NavButtonProvider> GtkUi::CreateNavButtonProvider() {
return nullptr;
}

-views::WindowFrameProvider* GtkUi::GetWindowFrameProvider(bool solid_frame) {
+views::WindowFrameProvider* GtkUi::GetWindowFrameProvider(bool solid_frame, bool maximized) {
if (!GtkCheckVersion(3, 14))
return nullptr;
auto& provider =
- solid_frame ? solid_frame_provider_ : transparent_frame_provider_;
+ maximized
+ ? (solid_frame ? solid_maximized_frame_provider_ : transparent_maximized_frame_provider_)
+ : (solid_frame ? solid_frame_provider_ : transparent_frame_provider_);
if (!provider)
- provider = std::make_unique<gtk::WindowFrameProviderGtk>(solid_frame);
+ provider = std::make_unique<gtk::WindowFrameProviderGtk>(solid_frame, maximized);
return provider.get();
}

diff --git a/ui/gtk/gtk_ui.h b/ui/gtk/gtk_ui.h
index 8e609b8311c6b69ef7b6753117542d9e60b2c8ab..a329822c3285599954d77dd5a8e33ccc10e5f626 100644
--- a/ui/gtk/gtk_ui.h
+++ b/ui/gtk/gtk_ui.h
@@ -107,7 +107,7 @@ class GtkUi : public views::LinuxUI {
bool PreferDarkTheme() const override;
bool AnimationsEnabled() const override;
std::unique_ptr<views::NavButtonProvider> CreateNavButtonProvider() override;
- views::WindowFrameProvider* GetWindowFrameProvider(bool solid_frame) override;
+ views::WindowFrameProvider* GetWindowFrameProvider(bool solid_frame, bool maximized) override;
base::flat_map<std::string, std::string> GetKeyboardLayoutMap() override;
std::string GetCursorThemeName() override;
int GetCursorThemeSize() override;
@@ -218,6 +218,8 @@ class GtkUi : public views::LinuxUI {
// while Chrome is running.
std::unique_ptr<views::WindowFrameProvider> solid_frame_provider_;
std::unique_ptr<views::WindowFrameProvider> transparent_frame_provider_;
+ std::unique_ptr<views::WindowFrameProvider> solid_maximized_frame_provider_;
+ std::unique_ptr<views::WindowFrameProvider> transparent_maximized_frame_provider_;
};

} // namespace gtk
diff --git a/ui/gtk/window_frame_provider_gtk.cc b/ui/gtk/window_frame_provider_gtk.cc
index e4dbdad327eb77994ffd7f068c67336a19897915..d3ae0636455489a7c7443df85cb769952c98aca2 100644
--- a/ui/gtk/window_frame_provider_gtk.cc
+++ b/ui/gtk/window_frame_provider_gtk.cc
@@ -38,16 +38,18 @@ std::string GetThemeName() {
return theme_string;
}

-GtkCssContext WindowContext(bool solid_frame, bool focused) {
+GtkCssContext WindowContext(bool solid_frame, bool maximized, bool focused) {
std::string selector = "#window.background.";
selector += solid_frame ? "solid-csd" : "csd";
+ if (maximized)
+ selector += ".maximized";
if (!focused)
selector += ":inactive";
return AppendCssNodeToStyleContext({}, selector);
}

-GtkCssContext DecorationContext(bool solid_frame, bool focused) {
- auto context = WindowContext(solid_frame, focused);
+GtkCssContext DecorationContext(bool solid_frame, bool maximized, bool focused) {
+ auto context = WindowContext(solid_frame, maximized, focused);
// GTK4 renders the decoration directly on the window.
if (!GtkCheckVersion(4))
context = AppendCssNodeToStyleContext(context, "#decoration");
@@ -64,8 +66,8 @@ GtkCssContext DecorationContext(bool solid_frame, bool focused) {
return context;
}

-GtkCssContext HeaderContext(bool solid_frame, bool focused) {
- auto context = WindowContext(solid_frame, focused);
+GtkCssContext HeaderContext(bool solid_frame, bool maximized, bool focused) {
+ auto context = WindowContext(solid_frame, maximized, focused);
context =
AppendCssNodeToStyleContext(context, "#headerbar.header-bar.titlebar");
if (!focused)
@@ -110,8 +112,8 @@ int ComputeTopCornerRadius() {
// need to experimentally determine the corner radius by rendering a sample.
// Additionally, in GTK4, the headerbar corners get clipped by the window
// rather than the headerbar having its own rounded corners.
- auto context = GtkCheckVersion(4) ? DecorationContext(false, false)
- : HeaderContext(false, false);
+ auto context = GtkCheckVersion(4) ? DecorationContext(false, false, false)
+ : HeaderContext(false, false, false);
ApplyCssToContext(context, R"(window, headerbar {
background-image: none;
background-color: black;
@@ -169,8 +171,8 @@ void WindowFrameProviderGtk::Asset::CloneFrom(
unfocused_bitmap = src.unfocused_bitmap;
}

-WindowFrameProviderGtk::WindowFrameProviderGtk(bool solid_frame)
- : solid_frame_(solid_frame) {}
+WindowFrameProviderGtk::WindowFrameProviderGtk(bool solid_frame, bool maximized)
+ : solid_frame_(solid_frame), maximized_(maximized) {}

WindowFrameProviderGtk::~WindowFrameProviderGtk() = default;

@@ -264,7 +266,7 @@ void WindowFrameProviderGtk::PaintWindowFrame(gfx::Canvas* canvas,
top_area_height_dip * scale - asset.frame_thickness_px.top();

auto header = PaintHeaderbar({client_bounds_px.width(), top_area_height_px},
- HeaderContext(solid_frame_, focused), scale);
+ HeaderContext(solid_frame_, maximized_, focused), scale);
image = gfx::ImageSkia::CreateFrom1xBitmap(header);
// In GTK4, the headerbar gets clipped by the window.
if (GtkCheckVersion(4)) {
@@ -296,7 +298,7 @@ void WindowFrameProviderGtk::MaybeUpdateBitmaps(float scale) {

gfx::Rect frame_bounds_dip(kMaxFrameSizeDip, kMaxFrameSizeDip,
2 * kMaxFrameSizeDip, 2 * kMaxFrameSizeDip);
- auto focused_context = DecorationContext(solid_frame_, true);
+ auto focused_context = DecorationContext(solid_frame_, maximized_, true);
frame_bounds_dip.Inset(-GtkStyleContextGetPadding(focused_context));
frame_bounds_dip.Inset(-GtkStyleContextGetBorder(focused_context));
gfx::Size bitmap_size(BitmapSizePx(asset), BitmapSizePx(asset));
@@ -304,7 +306,7 @@ void WindowFrameProviderGtk::MaybeUpdateBitmaps(float scale) {
PaintBitmap(bitmap_size, frame_bounds_dip, focused_context, scale);
asset.unfocused_bitmap =
PaintBitmap(bitmap_size, frame_bounds_dip,
- DecorationContext(solid_frame_, false), scale);
+ DecorationContext(solid_frame_, maximized_, false), scale);

// In GTK4, there's no way to obtain the frame thickness from CSS values
// directly, so we must determine it experimentally based on the drawn
diff --git a/ui/gtk/window_frame_provider_gtk.h b/ui/gtk/window_frame_provider_gtk.h
index d3039d73161378197557947aece88d2710c1e486..f7d4605938210b0b75517bb7bcab28b588a16520 100644
--- a/ui/gtk/window_frame_provider_gtk.h
+++ b/ui/gtk/window_frame_provider_gtk.h
@@ -14,7 +14,7 @@ namespace gtk {

class WindowFrameProviderGtk : public views::WindowFrameProvider {
public:
- explicit WindowFrameProviderGtk(bool solid_frame);
+ explicit WindowFrameProviderGtk(bool solid_frame, bool maximized);

WindowFrameProviderGtk(const WindowFrameProviderGtk&) = delete;
WindowFrameProviderGtk& operator=(const WindowFrameProviderGtk&) = delete;
@@ -69,6 +69,9 @@ class WindowFrameProviderGtk : public views::WindowFrameProvider {

// Cached bitmaps and metrics. The scale is rounded to percent.
base::flat_map<int, Asset> assets_;
+
+ // Whether to draw the window decorations as maximized.
+ bool maximized_;
};

} // namespace gtk
diff --git a/ui/views/linux_ui/linux_ui.h b/ui/views/linux_ui/linux_ui.h
index 5f312e01508c49033bf2d05b9dc083e524f37e5f..7590acd760ba4f36e5a77c1972afc5fc08e616ff 100644
--- a/ui/views/linux_ui/linux_ui.h
+++ b/ui/views/linux_ui/linux_ui.h
@@ -189,7 +189,7 @@ class VIEWS_EXPORT LinuxUI : public ui::LinuxInputMethodContextFactory,
// if transparency is unsupported and the frame should be rendered opaque.
// The returned object is not owned by the caller and will remain alive until
// the process ends.
- virtual WindowFrameProvider* GetWindowFrameProvider(bool solid_frame) = 0;
+ virtual WindowFrameProvider* GetWindowFrameProvider(bool solid_frame, bool maximized) = 0;

// Returns a map of KeyboardEvent code to KeyboardEvent key values.
virtual base::flat_map<std::string, std::string> GetKeyboardLayoutMap() = 0;
12 changes: 10 additions & 2 deletions shell/browser/ui/views/client_frame_view_linux.cc
Expand Up @@ -107,7 +107,7 @@ void ClientFrameViewLinux::Init(NativeWindowViews* window,
host_supports_client_frame_shadow_ = tree_host->SupportsClientFrameShadow();

frame_provider_ = views::LinuxUI::instance()->GetWindowFrameProvider(
!host_supports_client_frame_shadow_);
!host_supports_client_frame_shadow_, frame_->IsMaximized());

UpdateWindowTitle();

Expand Down Expand Up @@ -179,7 +179,7 @@ gfx::Rect ClientFrameViewLinux::GetBoundsForClientView() const {
if (!frame_->IsFullscreen()) {
client_bounds.Inset(GetBorderDecorationInsets());
client_bounds.Inset(
gfx::Insets::TLBR(0, GetTitlebarBounds().height(), 0, 0));
gfx::Insets::TLBR(GetTitlebarBounds().height(), 0, 0, 0));
}
return client_bounds;
}
Expand Down Expand Up @@ -251,6 +251,9 @@ void ClientFrameViewLinux::Layout() {
return;
}

frame_provider_ = views::LinuxUI::instance()->GetWindowFrameProvider(
!host_supports_client_frame_shadow_, frame_->IsMaximized());

UpdateButtonImages();
LayoutButtons();

Expand Down Expand Up @@ -461,4 +464,9 @@ gfx::Size ClientFrameViewLinux::SizeWithDecorations(gfx::Size size) const {
return size;
}

views::View* ClientFrameViewLinux::TargetForRect(views::View* root,
const gfx::Rect& rect) {
return views::NonClientFrameView::TargetForRect(root, rect);
}

} // namespace electron
3 changes: 3 additions & 0 deletions shell/browser/ui/views/client_frame_view_linux.h
Expand Up @@ -69,6 +69,9 @@ class ClientFrameViewLinux : public FramelessView,
void OnPaint(gfx::Canvas* canvas) override;
const char* GetClassName() const override;

// Overriden from views::ViewTargeterDelegate
views::View* TargetForRect(views::View* root, const gfx::Rect& rect) override;

private:
static constexpr int kNavButtonCount = 4;

Expand Down

0 comments on commit 4b48379

Please sign in to comment.