Skip to content

Commit 7c9a833

Browse files
authored
fix: full height video player crashes the app on Linux on snap (#1366)
Fixes #1345
1 parent 67f08e9 commit 7c9a833

File tree

9 files changed

+159
-77
lines changed

9 files changed

+159
-77
lines changed

.fvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"flutter": "3.35.4"
2+
"flutter": "3.35.5"
33
}

.metadata

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This file should be version controlled and should not be manually edited.
55

66
version:
7-
revision: "80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819"
7+
revision: "ac4e799d237041cf905519190471f657b657155a"
88
channel: "stable"
99

1010
project_type: app
@@ -13,11 +13,11 @@ project_type: app
1313
migration:
1414
platforms:
1515
- platform: root
16-
create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819
17-
base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819
18-
- platform: android
19-
create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819
20-
base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819
16+
create_revision: ac4e799d237041cf905519190471f657b657155a
17+
base_revision: ac4e799d237041cf905519190471f657b657155a
18+
- platform: linux
19+
create_revision: ac4e799d237041cf905519190471f657b657155a
20+
base_revision: ac4e799d237041cf905519190471f657b657155a
2121

2222
# User provided section
2323

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"yaml.schemaStore.enable": false,
3-
"dart.flutterSdkPath": ".fvm/versions/3.35.4"
3+
"dart.flutterSdkPath": ".fvm/versions/3.35.5"
44
}

linux/CMakeLists.txt

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
1-
cmake_minimum_required(VERSION 3.10)
1+
# Project-level configuration.
2+
cmake_minimum_required(VERSION 3.13)
23
project(runner LANGUAGES CXX)
34

5+
# The name of the executable created for the application. Change this to change
6+
# the on-disk name of your application.
47
set(BINARY_NAME "musicpod")
5-
set(APPLICATION_ID "org.feichtmeier.Musicpod")
8+
# The unique GTK application identifier for this application. See:
9+
# https://wiki.gnome.org/HowDoI/ChooseApplicationID
10+
set(APPLICATION_ID "org.feichtmeier.apps.musicpod")
611

12+
# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
13+
# versions of CMake.
714
cmake_policy(SET CMP0063 NEW)
815

16+
# Load bundled libraries from the lib/ directory relative to the binary.
917
set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
1018

11-
# Configure build options.
19+
# Root filesystem for cross-building.
20+
if(FLUTTER_TARGET_PLATFORM_SYSROOT)
21+
set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT})
22+
set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
23+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
24+
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
25+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
26+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
27+
endif()
28+
29+
# Define build configuration options.
1230
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
1331
set(CMAKE_BUILD_TYPE "Debug" CACHE
1432
STRING "Flutter build mode" FORCE)
@@ -17,34 +35,31 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
1735
endif()
1836

1937
# Compilation settings that should be applied to most targets.
38+
#
39+
# Be cautious about adding new options here, as plugins use this function by
40+
# default. In most cases, you should add new options to specific targets instead
41+
# of modifying this function.
2042
function(APPLY_STANDARD_SETTINGS TARGET)
2143
target_compile_features(${TARGET} PUBLIC cxx_std_14)
2244
target_compile_options(${TARGET} PRIVATE -Wall -Werror)
2345
target_compile_options(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:-O3>")
2446
target_compile_definitions(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:NDEBUG>")
2547
endfunction()
2648

27-
set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
28-
2949
# Flutter library and tool build rules.
50+
set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
3051
add_subdirectory(${FLUTTER_MANAGED_DIR})
3152

3253
# System-level dependencies.
3354
find_package(PkgConfig REQUIRED)
3455
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
3556

36-
add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")
57+
# Application build; see runner/CMakeLists.txt.
58+
add_subdirectory("runner")
3759

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)
60+
# Run the Flutter tool portions of the build. This must not be removed.
4761
add_dependencies(${BINARY_NAME} flutter_assemble)
62+
4863
# Only the install-generated bundle's copy of the executable will launch
4964
# correctly, since the resources must in the right relative locations. To avoid
5065
# people trying to run the unbundled copy, put it in a subdirectory instead of
@@ -54,11 +69,11 @@ set_target_properties(${BINARY_NAME}
5469
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run"
5570
)
5671

72+
5773
# Generated plugin build rules, which manage building the plugins and adding
5874
# them to the application.
5975
include(flutter/generated_plugins.cmake)
6076

61-
target_link_libraries(${BINARY_NAME} PRIVATE ${MIMALLOC_LIB})
6277

6378
# === Installation ===
6479
# By default, "installing" just makes a relocatable bundle in the build
@@ -85,11 +100,17 @@ install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}
85100
install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
86101
COMPONENT Runtime)
87102

88-
if(PLUGIN_BUNDLED_LIBRARIES)
89-
install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
103+
foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES})
104+
install(FILES "${bundled_library}"
90105
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
91106
COMPONENT Runtime)
92-
endif()
107+
endforeach(bundled_library)
108+
109+
# Copy the native assets provided by the build.dart from all packages.
110+
set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/")
111+
install(DIRECTORY "${NATIVE_ASSETS_DIR}"
112+
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
113+
COMPONENT Runtime)
93114

94115
# Fully re-copy the assets directory on each build to avoid having stale files
95116
# from a previous install.
@@ -104,4 +125,4 @@ install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
104125
if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")
105126
install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
106127
COMPONENT Runtime)
107-
endif()
128+
endif()

linux/runner/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
project(runner LANGUAGES CXX)
3+
4+
# Define the application target. To change its name, change BINARY_NAME in the
5+
# top-level CMakeLists.txt, not the value here, or `flutter run` will no longer
6+
# work.
7+
#
8+
# Any new source files that you add to the application should be added here.
9+
add_executable(${BINARY_NAME}
10+
"main.cc"
11+
"my_application.cc"
12+
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
13+
)
14+
15+
# Apply the standard set of build settings. This can be removed for applications
16+
# that need different build settings.
17+
apply_standard_settings(${BINARY_NAME})
18+
19+
# Add preprocessor definitions for the application ID.
20+
add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")
21+
22+
# Add dependency libraries. Add any application-specific dependencies here.
23+
target_link_libraries(${BINARY_NAME} PRIVATE flutter)
24+
target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
25+
26+
target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
File renamed without changes.

linux/my_application.cc renamed to linux/runner/my_application.cc

Lines changed: 70 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,34 @@
77

88
#include "flutter/generated_plugin_registrant.h"
99

10-
struct _MyApplication {
10+
struct _MyApplication
11+
{
1112
GtkApplication parent_instance;
12-
char** dart_entrypoint_arguments;
13+
char **dart_entrypoint_arguments;
1314
};
1415

1516
G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)
1617

17-
// Implements GApplication::activate.
18-
static void my_application_activate(GApplication* application) {
19-
MyApplication* self = MY_APPLICATION(application);
18+
// Called when first Flutter frame received.
19+
static void first_frame_cb(MyApplication *self, FlView *view)
20+
{
21+
gtk_widget_show(gtk_widget_get_toplevel(GTK_WIDGET(view)));
22+
}
2023

21-
GList* windows = gtk_application_get_windows(GTK_APPLICATION(application));
22-
if (windows) {
23-
gtk_window_present(GTK_WINDOW(windows->data));
24-
return;
24+
// Implements GApplication::activate.
25+
static void my_application_activate(GApplication *application)
26+
{
27+
MyApplication *self = MY_APPLICATION(application);
28+
29+
GList *windows = gtk_application_get_windows(GTK_APPLICATION(application));
30+
if (windows)
31+
{
32+
gtk_window_present(GTK_WINDOW(windows->data));
33+
return;
2534
}
2635

27-
GtkWindow* window =
36+
GtkWindow *window =
2837
GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));
29-
3038
// Use a header bar when running in GNOME as this is the common style used
3139
// by applications and is the setup most users will be using (e.g. Ubuntu
3240
// desktop).
@@ -36,19 +44,24 @@ static void my_application_activate(GApplication* application) {
3644
// if future cases occur).
3745
gboolean use_header_bar = TRUE;
3846
#ifdef GDK_WINDOWING_X11
39-
GdkScreen* screen = gtk_window_get_screen(window);
40-
if (GDK_IS_X11_SCREEN(screen)) {
41-
const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen);
42-
if (g_strcmp0(wm_name, "GNOME Shell") != 0) {
47+
GdkScreen *screen = gtk_window_get_screen(window);
48+
if (GDK_IS_X11_SCREEN(screen))
49+
{
50+
const gchar *wm_name = gdk_x11_screen_get_window_manager_name(screen);
51+
if (g_strcmp0(wm_name, "GNOME Shell") != 0)
52+
{
4353
use_header_bar = FALSE;
4454
}
4555
}
4656
#endif
47-
if (use_header_bar) {
48-
49-
} else {
57+
if (use_header_bar)
58+
{
59+
}
60+
else
61+
{
5062
gtk_window_set_title(window, "MusicPod");
5163
}
64+
5265
GdkGeometry geometry_min;
5366
geometry_min.min_width = 500;
5467
geometry_min.min_height = 700;
@@ -58,27 +71,38 @@ static void my_application_activate(GApplication* application) {
5871
g_autoptr(FlDartProject) project = fl_dart_project_new();
5972
fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments);
6073

61-
FlView* view = fl_view_new(project);
74+
FlView *view = fl_view_new(project);
6275
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
6376

6477
fl_register_plugins(FL_PLUGIN_REGISTRY(view));
78+
// Background defaults to black, override it here if necessary, e.g. #00000000 for transparent.
79+
GdkRGBA background_color;
80+
gdk_rgba_parse(&background_color, "#00000000");
81+
fl_view_set_background_color(view, &background_color);
82+
83+
// Show the window when Flutter renders.
84+
// Requires the view to be realized so we can start rendering.
85+
g_signal_connect_swapped(view, "first-frame", G_CALLBACK(first_frame_cb), self);
86+
gtk_widget_realize(GTK_WIDGET(view));
6587

66-
gtk_widget_show(GTK_WIDGET(window));
6788
gtk_widget_show(GTK_WIDGET(view));
89+
6890
gtk_widget_grab_focus(GTK_WIDGET(view));
6991
}
7092

7193
// Implements GApplication::local_command_line.
72-
static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) {
73-
MyApplication* self = MY_APPLICATION(application);
94+
static gboolean my_application_local_command_line(GApplication *application, gchar ***arguments, int *exit_status)
95+
{
96+
MyApplication *self = MY_APPLICATION(application);
7497
// Strip out the first argument as it is the binary name.
7598
self->dart_entrypoint_arguments = g_strdupv(*arguments + 1);
7699

77100
g_autoptr(GError) error = nullptr;
78-
if (!g_application_register(application, nullptr, &error)) {
79-
g_warning("Failed to register: %s", error->message);
80-
*exit_status = 1;
81-
return TRUE;
101+
if (!g_application_register(application, nullptr, &error))
102+
{
103+
g_warning("Failed to register: %s", error->message);
104+
*exit_status = 1;
105+
return TRUE;
82106
}
83107

84108
g_application_activate(application);
@@ -88,41 +112,52 @@ static gboolean my_application_local_command_line(GApplication* application, gch
88112
}
89113

90114
// Implements GApplication::startup.
91-
static void my_application_startup(GApplication* application) {
92-
//MyApplication* self = MY_APPLICATION(object);
115+
static void my_application_startup(GApplication *application)
116+
{
117+
// MyApplication* self = MY_APPLICATION(object);
93118

94119
// Perform any actions required at application startup.
95120

96121
G_APPLICATION_CLASS(my_application_parent_class)->startup(application);
97122
}
98123

99124
// Implements GApplication::shutdown.
100-
static void my_application_shutdown(GApplication* application) {
101-
//MyApplication* self = MY_APPLICATION(object);
125+
static void my_application_shutdown(GApplication *application)
126+
{
127+
// MyApplication* self = MY_APPLICATION(object);
102128

103129
// Perform any actions required at application shutdown.
104130

105131
G_APPLICATION_CLASS(my_application_parent_class)->shutdown(application);
106132
}
107133

108134
// Implements GObject::dispose.
109-
static void my_application_dispose(GObject* object) {
110-
MyApplication* self = MY_APPLICATION(object);
135+
static void my_application_dispose(GObject *object)
136+
{
137+
MyApplication *self = MY_APPLICATION(object);
111138
g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev);
112139
G_OBJECT_CLASS(my_application_parent_class)->dispose(object);
113140
}
114141

115-
static void my_application_class_init(MyApplicationClass* klass) {
142+
static void my_application_class_init(MyApplicationClass *klass)
143+
{
116144
G_APPLICATION_CLASS(klass)->activate = my_application_activate;
117145
G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line;
118146
G_APPLICATION_CLASS(klass)->startup = my_application_startup;
119147
G_APPLICATION_CLASS(klass)->shutdown = my_application_shutdown;
120148
G_OBJECT_CLASS(klass)->dispose = my_application_dispose;
121149
}
122150

123-
static void my_application_init(MyApplication* self) {}
151+
static void my_application_init(MyApplication *self) {}
152+
153+
MyApplication *my_application_new()
154+
{
155+
// Set the program name to the application ID, which helps various systems
156+
// like GTK and desktop environments map this running application to its
157+
// corresponding .desktop file. This ensures better integration by allowing
158+
// the application to be recognized beyond its binary name.
159+
g_set_prgname(APPLICATION_ID);
124160

125-
MyApplication* my_application_new() {
126161
return MY_APPLICATION(g_object_new(
127162
my_application_get_type(), "application-id", APPLICATION_ID, "flags",
128163
G_APPLICATION_HANDLES_COMMAND_LINE | G_APPLICATION_HANDLES_OPEN,
File renamed without changes.

0 commit comments

Comments
 (0)