Skip to content

Commit

Permalink
Merge branch 'main' of github.com:neoz-technologies/window_manager in…
Browse files Browse the repository at this point in the history
…to neoz-technologies-main
  • Loading branch information
lijy91 committed Jul 1, 2023
2 parents 88f2842 + 129980f commit 72aeb98
Show file tree
Hide file tree
Showing 7 changed files with 321 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/src/window_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ abstract class WindowListener {
/// Emitted when the window leaves a full-screen state.
void onWindowLeaveFullScreen() {}

/// Emitted when the window entered a docked state.
void onWindowDocked() {}

/// Emitted when the window leaves a docked state.
void onWindowUndocked() {}

/// Emitted all events.
void onWindowEvent(String eventName) {}
}
36 changes: 36 additions & 0 deletions lib/src/window_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ const kWindowEventMoved = 'moved';
const kWindowEventEnterFullScreen = 'enter-full-screen';
const kWindowEventLeaveFullScreen = 'leave-full-screen';

const kWindowEventDocked = 'docked';
const kWindowEventUndocked = 'undocked';

enum DockSide { LEFT, RIGHT }

// WindowManager
class WindowManager {
WindowManager._() {
Expand Down Expand Up @@ -64,6 +69,8 @@ class WindowManager {
kWindowEventMoved: listener.onWindowMoved,
kWindowEventEnterFullScreen: listener.onWindowEnterFullScreen,
kWindowEventLeaveFullScreen: listener.onWindowLeaveFullScreen,
kWindowEventDocked: listener.onWindowDocked,
kWindowEventUndocked: listener.onWindowUndocked,
};
funcMap[eventName]?.call();
}
Expand Down Expand Up @@ -261,6 +268,35 @@ class WindowManager {
}
}

/// Returns `bool` - Whether the window is dockable or not.
Future<bool> isDockable() async {
return await _channel.invokeMethod('isDockable');
}

/// Returns `bool` - Whether the window is docked.
Future<DockSide?> isDocked() async {
int? docked = await _channel.invokeMethod('isDocked');
if (docked == 0) return null;
if (docked == 1) return DockSide.LEFT;
if (docked == 2) return DockSide.RIGHT;
return null;
}

/// Docks the window. only works on Windows
Future<void> dock({required DockSide side, required int width}) async {
final Map<String, dynamic> arguments = {
'left': side == DockSide.LEFT,
'right': side == DockSide.RIGHT,
'width': width,
};
await _channel.invokeMethod('dock', arguments);
}

/// Undocks the window. only works on Windows
Future<bool> undock() async {
return await _channel.invokeMethod('undock');
}

/// This will make a window maintain an aspect ratio.
Future<void> setAspectRatio(double aspectRatio) async {
final Map<String, dynamic> arguments = {
Expand Down
29 changes: 29 additions & 0 deletions linux/window_manager_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,27 @@ static FlMethodResponse* minimize(WindowManagerPlugin* self) {
return FL_METHOD_RESPONSE(fl_method_success_response_new(result));
}

static FlMethodResponse* is_dockable(WindowManagerPlugin* self) {
bool is_docked = false;
g_autoptr(FlValue) result = fl_value_new_bool(is_docked);
return FL_METHOD_RESPONSE(fl_method_success_response_new(result));
}

static FlMethodResponse* is_docked(WindowManagerPlugin* self) {
g_autoptr(FlValue) result = fl_value_new_null();
return FL_METHOD_RESPONSE(fl_method_success_response_new(result));
}

static FlMethodResponse* dock(WindowManagerPlugin* self) {
g_autoptr(FlValue) result = fl_value_new_bool(true);
return FL_METHOD_RESPONSE(fl_method_success_response_new(result));
}

static FlMethodResponse* undock(WindowManagerPlugin* self) {
g_autoptr(FlValue) result = fl_value_new_bool(true);
return FL_METHOD_RESPONSE(fl_method_success_response_new(result));
}

static FlMethodResponse* restore(WindowManagerPlugin* self) {
gtk_window_deiconify(get_window(self));
gtk_window_present(get_window(self));
Expand Down Expand Up @@ -830,6 +851,14 @@ static void window_manager_plugin_handle_method_call(
response = minimize(self);
} else if (g_strcmp0(method, "restore") == 0) {
response = restore(self);
} else if (g_strcmp0(method, "isDockable") == 0) {
response = is_dockable(self);
} else if (g_strcmp0(method, "isDocked") == 0) {
response = is_docked(self);
} else if (g_strcmp0(method, "dock") == 0) {
response = dock(self);
} else if (g_strcmp0(method, "undock") == 0) {
response = undock(self);
} else if (g_strcmp0(method, "isFullScreen") == 0) {
response = is_full_screen(self);
} else if (g_strcmp0(method, "setFullScreen") == 0) {
Expand Down
16 changes: 16 additions & 0 deletions macos/Classes/WindowManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,22 @@ public class WindowManager: NSObject, NSWindowDelegate {
public func restore() {
mainWindow.deminiaturize(nil)
}

public func isDockable() -> Bool {
return false
}

public func isDocked() -> Int {
return 0;
}

public func dock(_ args: [String: Any]) {
if (isDockable()) {}
}

public func undock() {
if (isDockable()) {}
}

public func isFullScreen() -> Bool {
return mainWindow.styleMask.contains(.fullScreen)
Expand Down
14 changes: 14 additions & 0 deletions macos/Classes/WindowManagerPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ public class WindowManagerPlugin: NSObject, FlutterPlugin {
windowManager.restore()
result(true)
break
case "isDockable":
result(windowManager.isDockable())
break
case "isDocked":
result(windowManager.isDocked())
break
case "dock":
windowManager.dock(args)
result(true)
break
case "undock":
windowManager.undock()
result(true)
break
case "isFullScreen":
result(windowManager.isFullScreen())
break
Expand Down
Loading

0 comments on commit 72aeb98

Please sign in to comment.