Skip to content
Draft
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
17 changes: 17 additions & 0 deletions packages/nativeapi/lib/src/window_manager.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'dart:ffi' hide Size;
import 'dart:io';

import 'package:flutter/widgets.dart';
import 'package:nativeapi/src/foundation/cnativeapi_bindings_mixin.dart';
import 'package:nativeapi/src/foundation/event_emitter.dart';
Expand Down Expand Up @@ -174,13 +176,28 @@ class WindowManager with EventEmitter, CNativeApiBindingsMixin {
///
/// Returns the [Window] instance, or null if no window is active.
Window? getCurrent() {
if (_isWaylandSession) {
final windows = getAll();
return windows.isEmpty ? null : windows.first;
}

final nativeWindow = bindings.native_window_manager_get_current();
if (nativeWindow == nullptr) {
return null;
}
return Window(nativeWindow);
}

bool get _isWaylandSession {
if (!Platform.isLinux) {
return false;
}

final env = Platform.environment;
return env.containsKey('WAYLAND_DISPLAY') ||
env['XDG_SESSION_TYPE'] == 'wayland';
}

/// Shuts down the window manager and cleans up resources.
///
/// This should typically be called when the application is exiting.
Expand Down