1
1
#include " my_application.h"
2
2
3
3
#include < flutter_linux/flutter_linux.h>
4
- #include < handy.h>
4
+ #ifdef GDK_WINDOWING_X11
5
+ #include < gdk/gdkx.h>
6
+ #endif
5
7
6
8
#include " flutter/generated_plugin_registrant.h"
7
9
@@ -15,31 +17,42 @@ G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)
15
17
// Implements GApplication::activate.
16
18
static void my_application_activate(GApplication* application) {
17
19
MyApplication* self = MY_APPLICATION (application);
18
-
19
- GList* windows = gtk_application_get_windows (GTK_APPLICATION (application));
20
- if (windows) {
21
- gtk_window_present (GTK_WINDOW (windows->data ));
22
- return ;
20
+ GtkWindow* window =
21
+ GTK_WINDOW (gtk_application_window_new (GTK_APPLICATION (application)));
22
+
23
+ // Use a header bar when running in GNOME as this is the common style used
24
+ // by applications and is the setup most users will be using (e.g. Ubuntu
25
+ // desktop).
26
+ // If running on X and not using GNOME then just use a traditional title bar
27
+ // in case the window manager does more exotic layout, e.g. tiling.
28
+ // If running on Wayland assume the header bar will work (may need changing
29
+ // if future cases occur).
30
+ gboolean use_header_bar = TRUE ;
31
+ #ifdef GDK_WINDOWING_X11
32
+ GdkScreen* screen = gtk_window_get_screen (window);
33
+ if (GDK_IS_X11_SCREEN (screen)) {
34
+ const gchar* wm_name = gdk_x11_screen_get_window_manager_name (screen);
35
+ if (g_strcmp0 (wm_name, " GNOME Shell" ) != 0 ) {
36
+ use_header_bar = FALSE ;
37
+ }
23
38
}
24
- GtkWindow* window = GTK_WINDOW (hdy_application_window_new ());
25
- gtk_window_set_application (window, GTK_APPLICATION (application));
26
-
27
- GtkBox* box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 0 ));
28
- gtk_widget_show (GTK_WIDGET (box));
29
- gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (box));
39
+ #endif
40
+ if (use_header_bar) {
30
41
42
+ } else {
43
+ gtk_window_set_title (window, " MusicPod" );
44
+ }
31
45
GdkGeometry geometry_min;
32
46
geometry_min.min_width = 500 ;
33
47
geometry_min.min_height = 700 ;
34
48
gtk_window_set_geometry_hints (window, nullptr , &geometry_min, GDK_HINT_MIN_SIZE);
35
49
gtk_window_set_default_size (window, 950 , 820 );
36
50
37
51
g_autoptr (FlDartProject) project = fl_dart_project_new ();
38
- fl_dart_project_set_dart_entrypoint_arguments (
39
- project, self->dart_entrypoint_arguments );
52
+ fl_dart_project_set_dart_entrypoint_arguments (project, self->dart_entrypoint_arguments );
40
53
41
54
FlView* view = fl_view_new (project);
42
- gtk_box_pack_end ( GTK_BOX (box ), GTK_WIDGET (view), true , true , 0 );
55
+ gtk_container_add ( GTK_CONTAINER (window ), GTK_WIDGET (view));
43
56
44
57
fl_register_plugins (FL_PLUGIN_REGISTRY (view));
45
58
@@ -48,18 +61,41 @@ static void my_application_activate(GApplication* application) {
48
61
gtk_widget_grab_focus (GTK_WIDGET (view));
49
62
}
50
63
51
- static gint my_application_command_line (GApplication *application, GApplicationCommandLine *command_line) {
52
- MyApplication *self = MY_APPLICATION (application);
53
- gchar **arguments = g_application_command_line_get_arguments (command_line, nullptr );
54
- self->dart_entrypoint_arguments = g_strdupv (arguments + 1 );
64
+ // Implements GApplication::local_command_line.
65
+ static gboolean my_application_local_command_line (GApplication* application, gchar*** arguments, int * exit_status) {
66
+ MyApplication* self = MY_APPLICATION (application);
67
+ // Strip out the first argument as it is the binary name.
68
+ self->dart_entrypoint_arguments = g_strdupv (*arguments + 1 );
55
69
56
70
g_autoptr (GError) error = nullptr ;
57
71
if (!g_application_register (application, nullptr , &error)) {
58
- g_warning (" Failed to register: %s" , error->message );
59
- return 1 ;
72
+ g_warning (" Failed to register: %s" , error->message );
73
+ *exit_status = 1 ;
74
+ return TRUE ;
60
75
}
76
+
61
77
g_application_activate (application);
62
- return 0 ;
78
+ *exit_status = 0 ;
79
+
80
+ return TRUE ;
81
+ }
82
+
83
+ // Implements GApplication::startup.
84
+ static void my_application_startup (GApplication* application) {
85
+ // MyApplication* self = MY_APPLICATION(object);
86
+
87
+ // Perform any actions required at application startup.
88
+
89
+ G_APPLICATION_CLASS (my_application_parent_class)->startup (application);
90
+ }
91
+
92
+ // Implements GApplication::shutdown.
93
+ static void my_application_shutdown (GApplication* application) {
94
+ // MyApplication* self = MY_APPLICATION(object);
95
+
96
+ // Perform any actions required at application shutdown.
97
+
98
+ G_APPLICATION_CLASS (my_application_parent_class)->shutdown (application);
63
99
}
64
100
65
101
// Implements GObject::dispose.
@@ -71,15 +107,17 @@ static void my_application_dispose(GObject* object) {
71
107
72
108
static void my_application_class_init (MyApplicationClass* klass) {
73
109
G_APPLICATION_CLASS (klass)->activate = my_application_activate;
74
- G_APPLICATION_CLASS (klass)->command_line = my_application_command_line;
110
+ G_APPLICATION_CLASS (klass)->local_command_line = my_application_local_command_line;
111
+ G_APPLICATION_CLASS (klass)->startup = my_application_startup;
112
+ G_APPLICATION_CLASS (klass)->shutdown = my_application_shutdown;
75
113
G_OBJECT_CLASS (klass)->dispose = my_application_dispose;
76
114
}
77
115
78
116
static void my_application_init (MyApplication* self) {}
79
117
80
118
MyApplication* my_application_new () {
81
- return MY_APPLICATION (g_object_new (
82
- my_application_get_type (), " application-id" , APPLICATION_ID, " flags " ,
83
- G_APPLICATION_HANDLES_COMMAND_LINE | G_APPLICATION_HANDLES_OPEN ,
84
- nullptr ));
85
- }
119
+ return MY_APPLICATION (g_object_new (my_application_get_type (),
120
+ " application-id" , APPLICATION_ID,
121
+ " flags " , G_APPLICATION_NON_UNIQUE ,
122
+ nullptr ));
123
+ }
0 commit comments