Skip to content

Commit f6061d0

Browse files
Improve initial size and placement logic for popups and tooltips on Linux (#189994)
## Why? The initial sizing of popup and tooltip windows on Linux was broken such that windows that calculated their initial size too slowly would have their content overflowing off the edge of the screen. Because they never reposition themselves, this content would be lost forever. This PR fixes that initial sizing such that we wait for the convergence of initial sizes between the embedder and the framework before showing the popup/tooltip. ## What's new? - Add a new `on_size_changed` callback to the `FlViewMonitor` that notifies us when the view's size changes - Tooltips and popups on Linux are now _only_ shown when the first frame has arrived **AND** the size of the view in the Linux embedder agrees with the size of the content in the framework - This essentially spins until they converge to the same size, with a timeout of 250ms. - Made it so that X11 windows can be repositoned whereas Wayland windows cannot This fix consistently manages to place my windows correctly, which is very awesome. ## How it works <img width="4688" height="3840" alt="mermaid-diagram-2026-07-24T19-27-31" src="https://github.com/user-attachments/assets/5a5e4c2c-1f63-49f2-acc7-061d50d2e6ef" /> ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. --------- Co-authored-by: Robert Ancell <[email protected]>
1 parent 45b3e37 commit f6061d0

3 files changed

Lines changed: 242 additions & 27 deletions

File tree

‎engine/src/flutter/shell/platform/linux/fl_view_monitor.cc‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ struct _FlViewMonitor {
1818

1919
// Callbacks.
2020
void (*on_first_frame)(void);
21+
void (*on_size_changed)(int width, int height);
2122
};
2223

2324
G_DEFINE_TYPE(FlViewMonitor, fl_view_monitor, G_TYPE_OBJECT)
@@ -29,6 +30,13 @@ static void first_frame_cb(FlViewMonitor* self) {
2930
}
3031
}
3132

33+
static void size_allocate_cb(FlViewMonitor* self, GtkAllocation* allocation) {
34+
flutter::IsolateScope scope(self->isolate);
35+
if (self->on_size_changed) {
36+
self->on_size_changed(allocation->width, allocation->height);
37+
}
38+
}
39+
3240
static void fl_view_monitor_dispose(GObject* object) {
3341
FlViewMonitor* self = FL_VIEW_MONITOR(object);
3442

@@ -45,15 +53,19 @@ static void fl_view_monitor_init(FlViewMonitor* self) {}
4553

4654
G_MODULE_EXPORT FlViewMonitor* fl_view_monitor_new(
4755
FlView* view,
48-
void (*on_first_frame)(void)) {
56+
void (*on_first_frame)(void),
57+
void (*on_size_changed)(int width, int height)) {
4958
FlViewMonitor* self =
5059
FL_VIEW_MONITOR(g_object_new(fl_view_monitor_get_type(), nullptr));
5160

5261
self->view = FL_VIEW(g_object_ref(view));
5362
self->isolate = flutter::Isolate::Current();
5463
self->on_first_frame = on_first_frame;
64+
self->on_size_changed = on_size_changed;
5565
g_signal_connect_object(view, "first-frame", G_CALLBACK(first_frame_cb), self,
5666
G_CONNECT_SWAPPED);
67+
g_signal_connect_object(view, "size-allocate", G_CALLBACK(size_allocate_cb),
68+
self, G_CONNECT_SWAPPED);
5769

5870
return self;
5971
}

‎engine/src/flutter/shell/platform/linux/fl_view_monitor.h‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@ G_DECLARE_FINAL_TYPE(FlViewMonitor, fl_view_monitor, FL, VIEW_MONITOR, GObject);
1515
* fl_view_monitor_new:
1616
* @view: the view being monitored.
1717
* @on_first_frame: the function to call when the first frame is rendered.
18+
* @on_size_changed: the function to call when the view is allocated a size,
19+
* with the width and height in logical pixels.
1820
*
1921
* Helper class to allow the Flutter engine to monitor a FlView using FFI.
2022
* Callbacks are called in the isolate this class was created with.
2123
*
2224
* Returns: a new #FlViewMonitor.
2325
*/
24-
FlViewMonitor* fl_view_monitor_new(FlView* view, void (*on_first_frame)(void));
26+
FlViewMonitor* fl_view_monitor_new(FlView* view,
27+
void (*on_first_frame)(void),
28+
void (*on_size_changed)(int width,
29+
int height));
2530

2631
G_END_DECLS
2732

0 commit comments

Comments
 (0)