Skip to content

Commit

Permalink
Window Manager fix for Linux (#44)
Browse files Browse the repository at this point in the history
* Fix "No method isFocused" error for Linux Flet client

Fix #42

* AppBar.elevation added

Fix #43

* window_manager 0.2.5
  • Loading branch information
FeodorFitsner authored Jul 4, 2022
1 parent 0e617fe commit 2f53942
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 5 deletions.
2 changes: 2 additions & 0 deletions client/lib/controls/app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class AppBarControl extends StatelessWidget implements PreferredSizeWidget {
var actionCtrls = children.where((c) => c.name == "action" && c.isVisible);

var leadingWidth = control.attrDouble("leadingWidth");
var elevation = control.attrDouble("elevation");
var centerTitle = control.attrBool("centerTitle", false)!;
var color = HexColor.fromString(theme, control.attrString("color", "")!);
var bgcolor =
Expand All @@ -49,6 +50,7 @@ class AppBarControl extends StatelessWidget implements PreferredSizeWidget {
toolbarHeight: preferredSize.height,
foregroundColor: color,
backgroundColor: bgcolor,
elevation: elevation,
actions: actionCtrls
.map((c) => createControl(control, c.id, control.isDisabled))
.toList(),
Expand Down
18 changes: 15 additions & 3 deletions client/lib/utils/desktop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,17 @@ Future unmaximizeWindow() async {
}

Future focusWindow() async {
if (isDesktop() && !await windowManager.isFocused()) {
if (isDesktop() &&
(Platform.isWindows || Platform.isMacOS) &&
!await windowManager.isFocused()) {
await windowManager.focus();
}
}

Future blurWindow() async {
if (isDesktop() && await windowManager.isFocused()) {
if (isDesktop() &&
(Platform.isWindows || Platform.isMacOS) &&
await windowManager.isFocused()) {
await windowManager.blur();
}
}
Expand All @@ -134,12 +138,20 @@ Future centerWindow() async {
}
}

Future isFocused() async {
if (isDesktop() && (Platform.isWindows || Platform.isMacOS)) {
return await windowManager.isFocused();
} else {
return false;
}
}

Future<WindowMediaData> getWindowMediaData() async {
var m = WindowMediaData();
if (isDesktop()) {
m.isMaximized = await windowManager.isMaximized();
m.isMinimized = await windowManager.isMinimized();
m.isFocused = await windowManager.isFocused();
m.isFocused = await isFocused();
m.isTitleBarHidden = false;
var size = await windowManager.getSize();
m.width = size.width;
Expand Down
4 changes: 4 additions & 0 deletions client/linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

#include "generated_plugin_registrant.h"

#include <screen_retriever/screen_retriever_plugin.h>
#include <window_manager/window_manager_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
g_autoptr(FlPluginRegistrar) window_manager_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin");
window_manager_plugin_register_with_registrar(window_manager_registrar);
Expand Down
1 change: 1 addition & 0 deletions client/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
screen_retriever
window_manager
)

Expand Down
2 changes: 2 additions & 0 deletions client/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import FlutterMacOS
import Foundation

import screen_retriever
import window_manager

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
}
9 changes: 8 additions & 1 deletion client/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.0"
screen_retriever:
dependency: transitive
description:
name: screen_retriever
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -260,7 +267,7 @@ packages:
name: window_manager
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.1"
version: "0.2.5"
xml:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion client/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dependencies:
flutter_redux: ^0.10.0
equatable: ^2.0.3
web_socket_channel: ^2.1.0
window_manager: ^0.2.1
window_manager: ^0.2.5
http: ^0.13.3

dev_dependencies:
Expand Down
3 changes: 3 additions & 0 deletions client/windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@

#include "generated_plugin_registrant.h"

#include <screen_retriever/screen_retriever_plugin.h>
#include <window_manager/window_manager_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
ScreenRetrieverPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ScreenRetrieverPlugin"));
WindowManagerPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("WindowManagerPlugin"));
}
1 change: 1 addition & 0 deletions client/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
screen_retriever
window_manager
)

Expand Down
12 changes: 12 additions & 0 deletions sdk/python/flet/app_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(
toolbar_height: OptionalNumber = None,
color: str = None,
bgcolor: str = None,
elevation: OptionalNumber = None,
actions: List[Control] = None,
):
Control.__init__(self, ref=ref)
Expand All @@ -33,6 +34,7 @@ def __init__(
self.toolbar_height = toolbar_height
self.color = color
self.bgcolor = bgcolor
self.elevation = elevation
self.actions = actions

def _get_control_name(self):
Expand Down Expand Up @@ -119,6 +121,16 @@ def bgcolor(self):
def bgcolor(self, value):
self._set_attr("bgcolor", value)

# elevation
@property
def elevation(self) -> OptionalNumber:
return self._get_attr("elevation")

@elevation.setter
@beartype
def elevation(self, value: OptionalNumber):
self._set_attr("elevation", value)

# actions
@property
def actions(self):
Expand Down

0 comments on commit 2f53942

Please sign in to comment.