Skip to content

Commit c7025cf

Browse files
committed
Moved linux folder changes
1 parent 9732af1 commit c7025cf

File tree

333 files changed

+22823
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

333 files changed

+22823
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## 0.4.2 - 2024/10/29
2+
* windows: fix crash issue
3+
4+
5+
## 0.4.1 - 2024/10/04
6+
* macos: Use first window when mainWindow is nil
7+
8+
9+
## 0.4.0 - 2021/03/09
10+
* null safety
11+
12+
13+
## 0.3.0 - 2020/10/08
14+
* add Windows support
15+
16+
17+
## 0.2.0 - 2020/09/04
18+
* add Linux support
19+
* add getFullScreen and setFullScreen functions
20+
21+
22+
## 0.1.0 - 2020/05/25
23+
24+
* add setMaxWindowSize, setMinWindowSize
25+
* add toggleFullScreen
26+
27+
28+
## 0.0.1 - 2020/05/25
29+
30+
* initial release
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
import 'package:flutter/material.dart';
2+
import 'dart:async';
3+
4+
import 'package:desktop_window/desktop_window.dart';
5+
6+
void main() {
7+
runApp(MyApp());
8+
}
9+
10+
class MyApp extends StatefulWidget {
11+
@override
12+
_MyAppState createState() => _MyAppState();
13+
}
14+
15+
class _MyAppState extends State<MyApp> {
16+
String _windowSize = 'Unknown';
17+
18+
@override
19+
void initState() {
20+
super.initState();
21+
}
22+
23+
Future _getWindowSize() async {
24+
var size = await DesktopWindow.getWindowSize();
25+
setState(() {
26+
_windowSize = '${size.width} x ${size.height}';
27+
});
28+
}
29+
30+
@override
31+
Widget build(BuildContext context) {
32+
// MediaQuery.of(context).size;
33+
return MaterialApp(
34+
home: Scaffold(
35+
appBar: AppBar(
36+
title: const Text('desktop_window example app'),
37+
),
38+
body: Center(
39+
child: Column(
40+
mainAxisAlignment: MainAxisAlignment.center,
41+
children: [
42+
Text('$_windowSize\n'),
43+
ElevatedButton(
44+
child: Text("getWindowSize"),
45+
onPressed: _getWindowSize,
46+
),
47+
ElevatedButton(
48+
child: Text("setMinWindowSize(300,400)"),
49+
onPressed: () async {
50+
await DesktopWindow.setMinWindowSize(Size(300, 400));
51+
},
52+
),
53+
ElevatedButton(
54+
child: Text("setMaxWindowSize(800,800)"),
55+
onPressed: () async {
56+
await DesktopWindow.setMaxWindowSize(Size(800, 800));
57+
},
58+
),
59+
Wrap(
60+
children: [
61+
ElevatedButton(
62+
child: Text("Smaller"),
63+
onPressed: () async {
64+
var size = await DesktopWindow.getWindowSize();
65+
await DesktopWindow.setWindowSize(
66+
Size(size.width - 50, size.height - 50));
67+
await _getWindowSize();
68+
},
69+
),
70+
ElevatedButton(
71+
child: Text("Larger"),
72+
onPressed: () async {
73+
var size = await DesktopWindow.getWindowSize();
74+
await DesktopWindow.setWindowSize(
75+
Size(size.width + 50, size.height + 50));
76+
await _getWindowSize();
77+
},
78+
),
79+
],
80+
),
81+
Wrap(
82+
children: [
83+
ElevatedButton(
84+
child: Text("toggleFullScreen"),
85+
onPressed: () async {
86+
await DesktopWindow.resetMaxWindowSize();
87+
await DesktopWindow.toggleFullScreen();
88+
},
89+
),
90+
Builder(builder: (ctx) {
91+
return ElevatedButton(
92+
child: Text("getFullScreen"),
93+
onPressed: () async {
94+
final isFullScreen =
95+
await DesktopWindow.getFullScreen();
96+
ScaffoldMessenger.of(ctx).showSnackBar(SnackBar(
97+
content: Text('getFullScreen = $isFullScreen'),
98+
duration: Duration(seconds: 1)));
99+
},
100+
);
101+
}),
102+
ElevatedButton(
103+
child: Text("setFullScreen(true)"),
104+
onPressed: () async {
105+
await DesktopWindow.setFullScreen(true);
106+
},
107+
),
108+
ElevatedButton(
109+
child: Text("setFullScreen(false)"),
110+
onPressed: () async {
111+
await DesktopWindow.setFullScreen(false);
112+
},
113+
),
114+
],
115+
),
116+
Wrap(
117+
children: [
118+
ElevatedButton(
119+
child: Text("toggleBorders"),
120+
onPressed: () async {
121+
await DesktopWindow.toggleBorders();
122+
},
123+
),
124+
Builder(builder: (ctx) {
125+
return ElevatedButton(
126+
child: Text("setBorders(true)"),
127+
onPressed: () async {
128+
await DesktopWindow.setBorders(true);
129+
},
130+
);
131+
}),
132+
ElevatedButton(
133+
child: Text("setBorders(false)"),
134+
onPressed: () async {
135+
await DesktopWindow.setBorders(false);
136+
},
137+
),
138+
ElevatedButton(
139+
child: Text("hasBorders"),
140+
onPressed: () async {
141+
print('hasBorders: ' +
142+
(await DesktopWindow.hasBorders ? 'true' : 'false'));
143+
},
144+
),
145+
],
146+
),
147+
Wrap(
148+
children: [
149+
ElevatedButton(
150+
child: Text("focus"),
151+
onPressed: () {
152+
Timer(Duration(seconds: 3), () async {
153+
print('focus!!!');
154+
await DesktopWindow.focus();
155+
});
156+
},
157+
),
158+
ElevatedButton(
159+
child: Text("stayOnTop(true)"),
160+
onPressed: () async {
161+
print('stayOnTop(true)');
162+
await DesktopWindow.stayOnTop(true);
163+
},
164+
),
165+
ElevatedButton(
166+
child: Text("stayOnTop(false)"),
167+
onPressed: () async {
168+
print('stayOnTop(false)');
169+
await DesktopWindow.stayOnTop(false);
170+
},
171+
),
172+
],
173+
),
174+
],
175+
),
176+
),
177+
),
178+
);
179+
}
180+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
project(runner LANGUAGES CXX)
3+
4+
set(BINARY_NAME "desktop_window_example")
5+
set(APPLICATION_ID "com.example.desktop_window")
6+
7+
cmake_policy(SET CMP0063 NEW)
8+
9+
set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
10+
11+
# Configure build options.
12+
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
13+
set(CMAKE_BUILD_TYPE "Debug" CACHE
14+
STRING "Flutter build mode" FORCE)
15+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
16+
"Debug" "Profile" "Release")
17+
endif()
18+
19+
# Compilation settings that should be applied to most targets.
20+
function(APPLY_STANDARD_SETTINGS TARGET)
21+
target_compile_features(${TARGET} PUBLIC cxx_std_14)
22+
target_compile_options(${TARGET} PRIVATE -Wall -Werror)
23+
target_compile_options(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:-O3>")
24+
target_compile_definitions(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:NDEBUG>")
25+
endfunction()
26+
27+
set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
28+
29+
# Flutter library and tool build rules.
30+
add_subdirectory(${FLUTTER_MANAGED_DIR})
31+
32+
# System-level dependencies.
33+
find_package(PkgConfig REQUIRED)
34+
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
35+
36+
add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")
37+
38+
# Application build
39+
add_executable(${BINARY_NAME}
40+
"main.cc"
41+
"my_application.cc"
42+
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
43+
)
44+
apply_standard_settings(${BINARY_NAME})
45+
target_link_libraries(${BINARY_NAME} PRIVATE flutter)
46+
target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
47+
add_dependencies(${BINARY_NAME} flutter_assemble)
48+
49+
# Generated plugin build rules, which manage building the plugins and adding
50+
# them to the application.
51+
include(flutter/generated_plugins.cmake)
52+
53+
54+
# === Installation ===
55+
# By default, "installing" just makes a relocatable bundle in the build
56+
# directory.
57+
set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle")
58+
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
59+
set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
60+
endif()
61+
62+
# Start with a clean build bundle directory every time.
63+
install(CODE "
64+
file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\")
65+
" COMPONENT Runtime)
66+
67+
set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
68+
set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
69+
70+
install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
71+
COMPONENT Runtime)
72+
73+
install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
74+
COMPONENT Runtime)
75+
76+
install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
77+
COMPONENT Runtime)
78+
79+
if(PLUGIN_BUNDLED_LIBRARIES)
80+
install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
81+
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
82+
COMPONENT Runtime)
83+
endif()
84+
85+
# Fully re-copy the assets directory on each build to avoid having stale files
86+
# from a previous install.
87+
set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
88+
install(CODE "
89+
file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
90+
" COMPONENT Runtime)
91+
install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
92+
DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
93+
94+
# Install the AOT library on non-Debug builds only.
95+
if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")
96+
install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
97+
COMPONENT Runtime)
98+
endif()
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
3+
set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
4+
5+
# Configuration provided via flutter tool.
6+
include(${EPHEMERAL_DIR}/generated_config.cmake)
7+
8+
# TODO: Move the rest of this into files in ephemeral. See
9+
# https://github.com/flutter/flutter/issues/57146.
10+
11+
# Serves the same purpose as list(TRANSFORM ... PREPEND ...),
12+
# which isn't available in 3.10.
13+
function(list_prepend LIST_NAME PREFIX)
14+
set(NEW_LIST "")
15+
foreach(element ${${LIST_NAME}})
16+
list(APPEND NEW_LIST "${PREFIX}${element}")
17+
endforeach(element)
18+
set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE)
19+
endfunction()
20+
21+
# === Flutter Library ===
22+
# System-level dependencies.
23+
find_package(PkgConfig REQUIRED)
24+
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
25+
pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
26+
pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0)
27+
28+
set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so")
29+
30+
# Published to parent scope for install step.
31+
set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
32+
set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
33+
set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
34+
set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE)
35+
36+
list(APPEND FLUTTER_LIBRARY_HEADERS
37+
"fl_basic_message_channel.h"
38+
"fl_binary_codec.h"
39+
"fl_binary_messenger.h"
40+
"fl_dart_project.h"
41+
"fl_engine.h"
42+
"fl_json_message_codec.h"
43+
"fl_json_method_codec.h"
44+
"fl_message_codec.h"
45+
"fl_method_call.h"
46+
"fl_method_channel.h"
47+
"fl_method_codec.h"
48+
"fl_method_response.h"
49+
"fl_plugin_registrar.h"
50+
"fl_plugin_registry.h"
51+
"fl_standard_message_codec.h"
52+
"fl_standard_method_codec.h"
53+
"fl_string_codec.h"
54+
"fl_value.h"
55+
"fl_view.h"
56+
"flutter_linux.h"
57+
)
58+
list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/")
59+
add_library(flutter INTERFACE)
60+
target_include_directories(flutter INTERFACE
61+
"${EPHEMERAL_DIR}"
62+
)
63+
target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}")
64+
target_link_libraries(flutter INTERFACE
65+
PkgConfig::GTK
66+
PkgConfig::GLIB
67+
PkgConfig::GIO
68+
)
69+
add_dependencies(flutter flutter_assemble)
70+
71+
# === Flutter tool backend ===
72+
# _phony_ is a non-existent file to force this command to run every time,
73+
# since currently there's no way to get a full input/output list from the
74+
# flutter tool.
75+
add_custom_command(
76+
OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
77+
${CMAKE_CURRENT_BINARY_DIR}/_phony_
78+
COMMAND ${CMAKE_COMMAND} -E env
79+
${FLUTTER_TOOL_ENVIRONMENT}
80+
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh"
81+
linux-x64 ${CMAKE_BUILD_TYPE}
82+
)
83+
add_custom_target(flutter_assemble DEPENDS
84+
"${FLUTTER_LIBRARY}"
85+
${FLUTTER_LIBRARY_HEADERS}
86+
)

0 commit comments

Comments
 (0)