Skip to content

Commit eaae5cf

Browse files
author
Hidenori Matsubayashi
authored
[wayland] Fix operations of the max button in the window decorations (sony#225)
- Add restore original window size support (unset maximize-window) - Fix the window decorations will be hidden after pressing the max-button
1 parent f65dac5 commit eaae5cf

File tree

4 files changed

+63
-7
lines changed

4 files changed

+63
-7
lines changed

src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,15 @@ const xdg_surface_listener ELinuxWindowWayland::kXdgSurfaceListener = {
6464
.configure =
6565
[](void* data, xdg_surface* xdg_surface, uint32_t serial) {
6666
auto self = reinterpret_cast<ELinuxWindowWayland*>(data);
67-
xdg_surface_set_window_geometry(xdg_surface, 0, 0,
67+
constexpr int32_t x = 0;
68+
int32_t y = 0;
69+
if (self->view_properties_.use_window_decoration) {
70+
// TODO: Moves the window to the bottom to show the window
71+
// decorations, but the bottom area of the window will be hidden
72+
// because of this shifting.
73+
y = -self->window_decorations_->Height();
74+
}
75+
xdg_surface_set_window_geometry(xdg_surface, x, y,
6876
self->view_properties_.width,
6977
self->view_properties_.height);
7078
xdg_surface_ack_configure(xdg_surface, serial);
@@ -75,18 +83,51 @@ const xdg_toplevel_listener ELinuxWindowWayland::kXdgToplevelListener = {
7583
.configure =
7684
[](void* data, xdg_toplevel* xdg_toplevel, int32_t width,
7785
int32_t height, wl_array* states) {
78-
if (!width || !height) {
79-
return;
86+
auto is_maximized = false;
87+
auto is_resizing = false;
88+
uint32_t* state = static_cast<uint32_t*>(states->data);
89+
for (auto i = 0; i < states->size; i++) {
90+
switch (*state) {
91+
case XDG_TOPLEVEL_STATE_MAXIMIZED:
92+
is_maximized = true;
93+
break;
94+
case XDG_TOPLEVEL_STATE_RESIZING:
95+
is_resizing = true;
96+
break;
97+
case XDG_TOPLEVEL_STATE_ACTIVATED:
98+
case XDG_TOPLEVEL_STATE_FULLSCREEN:
99+
default:
100+
break;
101+
}
102+
state++;
80103
}
81104

82105
auto self = reinterpret_cast<ELinuxWindowWayland*>(data);
83-
self->view_properties_.width = width;
84-
self->view_properties_.height = height;
106+
int32_t next_width = 0;
107+
int32_t next_height = 0;
108+
if (is_maximized || is_resizing) {
109+
next_width = width;
110+
next_height = height;
111+
} else if (self->restore_window_required_) {
112+
self->restore_window_required_ = false;
113+
next_width = self->restore_window_width_;
114+
next_height = self->restore_window_height_;
115+
}
116+
117+
if (!next_width || !next_height ||
118+
(self->view_properties_.width == next_width &&
119+
self->view_properties_.height == next_height)) {
120+
return;
121+
}
122+
123+
self->view_properties_.width = next_width;
124+
self->view_properties_.height = next_height;
85125
if (self->window_decorations_) {
86-
self->window_decorations_->Resize(width, height);
126+
self->window_decorations_->Resize(next_width, next_height);
87127
}
88128
if (self->binding_handler_delegate_) {
89-
self->binding_handler_delegate_->OnWindowSizeChanged(width, height);
129+
self->binding_handler_delegate_->OnWindowSizeChanged(next_width,
130+
next_height);
90131
}
91132
},
92133
.close =
@@ -263,7 +304,15 @@ const wl_pointer_listener ELinuxWindowWayland::kWlPointerListener = {
263304
WindowDecoration::DecorationType::MAXIMISE_BUTTON)) {
264305
if (self->maximised_) {
265306
xdg_toplevel_unset_maximized(self->xdg_toplevel_);
307+
308+
// Requests to return to the original window size before maximizing.
309+
self->restore_window_required_ = true;
266310
} else {
311+
// Stores original window size.
312+
self->restore_window_width_ = self->view_properties_.width;
313+
self->restore_window_height_ = self->view_properties_.height;
314+
self->restore_window_required_ = false;
315+
267316
xdg_toplevel_set_maximized(self->xdg_toplevel_);
268317
}
269318
self->maximised_ = !self->maximised_;

src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler {
122122
std::unique_ptr<WindowDecorationsWayland> window_decorations_;
123123
wl_surface* wl_current_surface_;
124124
wl_subcompositor* wl_subcompositor_;
125+
bool restore_window_required_ = false;
126+
int32_t restore_window_width_;
127+
int32_t restore_window_height_;
125128

126129
bool display_valid_;
127130
bool running_;

src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,6 @@ void WindowDecorationsWayland::DestroyContext() {
114114
}
115115
}
116116

117+
int32_t WindowDecorationsWayland::Height() const { return kTitleBarHeight; }
118+
117119
} // namespace flutter

src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class WindowDecorationsWayland {
3939
bool IsMatched(wl_surface* surface,
4040
WindowDecoration::DecorationType decoration_type) const;
4141

42+
int32_t Height() const;
43+
4244
private:
4345
void DestroyContext();
4446

0 commit comments

Comments
 (0)