Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
## 1.0.1

* **Linux (`GDK3`)**: Attach the default `GdkSeat` pointer device via `gdk_event_set_device` to synthesized `GDK_BUTTON_RELEASE` events inside `releaseLinuxMouseButtonAfterGrab` before dispatching `gtk_widget_event`, eliminating `Gdk-CRITICAL: gdk_device_get_axis: assertion 'GDK_IS_DEVICE (device)' failed` warnings after interactive caption-bar window dragging on Linux GTK3/Wayland and X11.
* Added deterministic unit tests and a live Linux `libgdk-3.so.0` FFI probe verifying `gdk_event_set_device` and `gdk_event_get_device` symbol resolution and lifecycle safety.
OS-isolated window lifecycle, macOS Dock/close-button responsiveness, and Linux Wayland presentation & GDK3 pointer event fixes (with zero modifications to the Windows adapter).

### macOS (`platform/macos/`)
* **Immediate Close-to-Tray Response on Traffic-Light `[X]` Click**: Wake Flutter's macOS `CFRunLoop` / Dart microtask queue (`Timer.run` + `ensureVisualUpdate` / `scheduleFrame`) immediately inside `NativeCoreWindowDelegate.windowShouldClose:` when a close request is cancelled, so hiding the window no longer waits for the pointer to leave AppKit's red close button.
* **Automatic Dock Running Indicator Policy (`Regular` ↔ `Accessory`)**: When `MacOSWindowAdapter.hide()` hides the last visible app window while an active `NSStatusItem` (`NSStatusBarWindow` with `isVisible == true`) is present, automatically switch `NSApplication` to `Accessory (1)` so the Dock dot disappears while the menu bar icon stays alive; restore `Regular (0)` before activation on `show()`, `focus()`, or native reopen (`NSWindowDidBecomeKeyNotification`).
* **Clean Dock Quit / `Cmd+Q` Termination**: Stop forwarding `WidgetsBindingObserver.didRequestAppExit` to `WindowCloseRequestedEvent` on macOS and Linux (preserving Windows `WM_CLOSE` forwarding intact), and automatically release single-instance Unix sockets via `NSApplicationWillTerminateNotification` (`MacOSAppLifecycleObserver`) and `Application.quit()`.

### Linux (`platform/linux/`)
* **Wayland Unmapped Presentation & Mutter `"<App>" is ready` Fix**: Remove raw `gdk_window_show` and `gdk_window_focus` calls from `LinuxWindowAdapter._presentWindow`, and resolve X11 vs Wayland presentation via `resolveLinuxPresentAction` so unmapped Wayland startup/restore uses `gtk_window_deiconify` + `gtk_widget_show` without firing premature `gtk_window_present_with_time(0)`.
* **GTK3 Pre-Map Geometry, Native Centering, Maximized State, and Close Wakeup**: Apply `gtk_window_set_default_size` + `gdk_window_resize` before map in `setSize()` / `bounds =`, delegate `Window.center()` to `gtk_window_set_position(GTK_WIN_POS_CENTER)`, check `GDK_WINDOW_STATE_MAXIMIZED` alongside `gtk_window_is_maximized`, and wake Flutter's event loop when `delete-event` cancels close.
* **Synthesized `GDK_BUTTON_RELEASE` Pointer Device Binding**: Bind `gdk_event_set_device` and `gdk_event_get_device` from `libgdk-3.so.0` and attach the default `GdkSeat` pointer device inside `releaseLinuxMouseButtonAfterGrab` before dispatching `gtk_widget_event`, eliminating `Gdk-CRITICAL: gdk_device_get_axis: assertion 'GDK_IS_DEVICE (device)' failed` warnings after interactive caption-bar window dragging on Wayland and X11.

## 1.0.0

Expand Down
32 changes: 32 additions & 0 deletions lib/src/application.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'diagnostics.dart';
import 'main_window.dart';
import 'platform/linux/linux_headerbar_grab.dart';
import 'platform/linux/linux_window_adapter.dart';
import 'platform/macos/macos_appkit_bindings.dart';
import 'platform/unix_single_instance.dart';
import 'platform/windows/windows_single_instance.dart';
import 'platform/windows/windows_win32_bindings.dart';
Expand Down Expand Up @@ -84,6 +85,11 @@ class Application {

if (isPrimary) {
_coordinatorsByToken[token] = coordinator;
if (Platform.isMacOS) {
MacOSAppLifecycleObserver.instance.registerWillTerminate(
releaseSingleInstanceSync,
);
}
return true;
}

Expand All @@ -102,18 +108,43 @@ class Application {
if (coordinator != null) {
await coordinator.release();
}
if (_coordinatorsByToken.isEmpty && Platform.isMacOS) {
MacOSAppLifecycleObserver.instance.unregisterWillTerminate(
releaseSingleInstanceSync,
);
}
return;
}

final active = List<SingleInstanceCoordinator>.of(
_coordinatorsByToken.values,
);
_coordinatorsByToken.clear();
if (Platform.isMacOS) {
MacOSAppLifecycleObserver.instance.unregisterWillTerminate(
releaseSingleInstanceSync,
);
}
for (final coordinator in active) {
await coordinator.release();
}
}

/// Best-effort synchronous release of all held Unix single-instance sockets
/// during OS termination (`NSApplicationWillTerminateNotification` or
/// [quit]).
void releaseSingleInstanceSync() {
final active = List<SingleInstanceCoordinator>.of(
_coordinatorsByToken.values,
);
_coordinatorsByToken.clear();
for (final coordinator in active) {
if (coordinator is UnixSingleInstanceCoordinator) {
coordinator.releaseSync();
}
}
}

static void _activatePrimaryMainWindow() {
try {
final window = mainWindow;
Expand Down Expand Up @@ -146,6 +177,7 @@ class Application {
/// Terminates the native desktop application event loop and exits the process
/// with [exitCode].
void quit([int exitCode = 0]) {
releaseSingleInstanceSync();
if (Platform.isLinux) {
quitLinuxApplication();
} else if (Platform.isWindows) {
Expand Down
53 changes: 38 additions & 15 deletions lib/src/platform/linux/linux_gtk_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ const int kGtkWindowToplevel = 0;
/// (`1 << 1 == 0x02`).
const int kGdkWindowStateIconified = 0x02;

/// `GdkWindowState` bit flag indicating a maximized window (`1 << 2 == 0x04`).
const int kGdkWindowStateMaximized = 0x04;

/// `GtkWindowPosition` value requesting compositor/WM centering
/// (`GTK_WIN_POS_CENTER == 1`).
const int kGtkWinPosCenter = 1;

/// Doubly-linked list node (`GList`) returned by GLib/GTK list APIs.
final class GList extends ffi.Struct {
/// Element payload pointer.
Expand Down Expand Up @@ -115,8 +122,7 @@ class LinuxGtkBindings {
required this.gdkSeatGetPointer,
required this.gdkDeviceGetPosition,
required this.gdkWindowGetState,
required this.gdkWindowShow,
required this.gdkWindowFocus,
required this.gdkWindowResize,
required this.gdkEventNew,
required this.gdkEventSetDevice,
required this.gdkEventGetDevice,
Expand All @@ -136,6 +142,8 @@ class LinuxGtkBindings {
required this.gtkWindowFullscreen,
required this.gtkWindowUnfullscreen,
required this.gtkWindowPresentWithTime,
required this.gtkWindowSetDefaultSize,
required this.gtkWindowSetPosition,
required this.gtkWindowResize,
required this.gtkWindowMove,
required this.gtkWindowGetPosition,
Expand All @@ -146,6 +154,7 @@ class LinuxGtkBindings {
required this.gtkGetCurrentEventTime,
required this.gtkWidgetInDestruction,
required this.gtkWidgetGetRealized,
required this.gtkWidgetGetMapped,
required this.gtkWidgetGetVisible,
required this.gtkWidgetSetVisible,
required this.gtkWidgetShow,
Expand Down Expand Up @@ -264,14 +273,10 @@ class LinuxGtkBindings {
ffi.Uint32 Function(ffi.Pointer<ffi.Void>),
int Function(ffi.Pointer<ffi.Void>)
>('gdk_window_get_state'),
gdkWindowShow: gdk.lookupFunction<
ffi.Void Function(ffi.Pointer<ffi.Void>),
void Function(ffi.Pointer<ffi.Void>)
>('gdk_window_show'),
gdkWindowFocus: gdk.lookupFunction<
ffi.Void Function(ffi.Pointer<ffi.Void>, ffi.Uint32),
void Function(ffi.Pointer<ffi.Void>, int)
>('gdk_window_focus'),
gdkWindowResize: gdk.lookupFunction<
ffi.Void Function(ffi.Pointer<ffi.Void>, ffi.Int32, ffi.Int32),
void Function(ffi.Pointer<ffi.Void>, int, int)
>('gdk_window_resize'),
gdkEventNew: gdk.lookupFunction<
ffi.Pointer<GdkEventButton> Function(ffi.Int32),
ffi.Pointer<GdkEventButton> Function(int)
Expand Down Expand Up @@ -342,6 +347,14 @@ class LinuxGtkBindings {
ffi.Void Function(ffi.Pointer<ffi.Void>, ffi.Uint32),
void Function(ffi.Pointer<ffi.Void>, int)
>('gtk_window_present_with_time'),
gtkWindowSetDefaultSize: gtk.lookupFunction<
ffi.Void Function(ffi.Pointer<ffi.Void>, ffi.Int32, ffi.Int32),
void Function(ffi.Pointer<ffi.Void>, int, int)
>('gtk_window_set_default_size'),
gtkWindowSetPosition: gtk.lookupFunction<
ffi.Void Function(ffi.Pointer<ffi.Void>, ffi.Int32),
void Function(ffi.Pointer<ffi.Void>, int)
>('gtk_window_set_position'),
gtkWindowResize: gtk.lookupFunction<
ffi.Void Function(ffi.Pointer<ffi.Void>, ffi.Int32, ffi.Int32),
void Function(ffi.Pointer<ffi.Void>, int, int)
Expand Down Expand Up @@ -404,6 +417,10 @@ class LinuxGtkBindings {
ffi.Int32 Function(ffi.Pointer<ffi.Void>),
int Function(ffi.Pointer<ffi.Void>)
>('gtk_widget_get_realized'),
gtkWidgetGetMapped: gtk.lookupFunction<
ffi.Int32 Function(ffi.Pointer<ffi.Void>),
int Function(ffi.Pointer<ffi.Void>)
>('gtk_widget_get_mapped'),
gtkWidgetGetVisible: gtk.lookupFunction<
ffi.Int32 Function(ffi.Pointer<ffi.Void>),
int Function(ffi.Pointer<ffi.Void>)
Expand Down Expand Up @@ -550,11 +567,8 @@ class LinuxGtkBindings {
/// `gdk_window_get_state`.
final int Function(ffi.Pointer<ffi.Void>) gdkWindowGetState;

/// `gdk_window_show`.
final void Function(ffi.Pointer<ffi.Void>) gdkWindowShow;

/// `gdk_window_focus`.
final void Function(ffi.Pointer<ffi.Void>, int) gdkWindowFocus;
/// `gdk_window_resize`.
final void Function(ffi.Pointer<ffi.Void>, int, int) gdkWindowResize;

/// `gdk_event_new`.
final ffi.Pointer<GdkEventButton> Function(int) gdkEventNew;
Expand Down Expand Up @@ -616,6 +630,12 @@ class LinuxGtkBindings {
/// `gtk_window_present_with_time`.
final void Function(ffi.Pointer<ffi.Void>, int) gtkWindowPresentWithTime;

/// `gtk_window_set_default_size`.
final void Function(ffi.Pointer<ffi.Void>, int, int) gtkWindowSetDefaultSize;

/// `gtk_window_set_position`.
final void Function(ffi.Pointer<ffi.Void>, int) gtkWindowSetPosition;

/// `gtk_window_resize`.
final void Function(ffi.Pointer<ffi.Void>, int, int) gtkWindowResize;

Expand Down Expand Up @@ -658,6 +678,9 @@ class LinuxGtkBindings {
/// `gtk_widget_get_realized`.
final int Function(ffi.Pointer<ffi.Void>) gtkWidgetGetRealized;

/// `gtk_widget_get_mapped`.
final int Function(ffi.Pointer<ffi.Void>) gtkWidgetGetMapped;

/// `gtk_widget_get_visible`.
final int Function(ffi.Pointer<ffi.Void>) gtkWidgetGetVisible;

Expand Down
Loading
Loading