Skip to content

Commit

Permalink
Fix Linux app for our now-modern Flutter versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
saurik committed Apr 7, 2024
1 parent 45a6837 commit a928ac9
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 7 deletions.
1 change: 1 addition & 0 deletions app-flutter.mk
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ create: $(pwd/flutter)/packages/flutter/pubspec.lock

builds :=
builds += apk
builds += linux
builds += macos
builds += ios

Expand Down
6 changes: 6 additions & 0 deletions app-linux/i3layout.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"border": "pixel", "current_border_width": 2,
"type": "con", "floating": "auto_off",
"percent": 0.393,
"name": "Orchid", "swallows": [{"class": "^Orchid$"}]
}
13 changes: 12 additions & 1 deletion app-linux/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ signed :=
.PHONY: all
all: $(output)/$(name).tgz

.PHONY: app
app: $(signed)

source += $(wildcard $(pwd)/source/*.cpp)

cflags/$(pwd)/source/main.cpp += -Wno-unused-function
Expand Down Expand Up @@ -56,9 +59,15 @@ lflags += $(output)/sysroot/usr/lib/$(host/x86_64)/libgtk-3.so
lflags += $(output)/sysroot/usr/lib/$(host/x86_64)/libgio-2.0.so
lflags += $(output)/sysroot/usr/lib/$(host/x86_64)/libgobject-2.0.so

shareds := $(pwd/gui)/linux/flutter/ephemeral/.plugin_symlinks/*/linux/shared
$(output)/package/lib/%: $$(wildcard $(shareds)/%)
@mkdir -p $(dir $@)
cp -af $< $@
signed += $(patsubst %,$(output)/package/lib/%,$(notdir $(wildcard $(shareds)/*.so)))

$(output)/package/$(name)$(exe): $(patsubst %,$(output)/$(machine)/%,$(object) $(linked))
@echo [LD] $@
@set -o pipefail; $(cxx) $(more/$(machine)) $(wflags) -o $@ $(filter %.o,$^) $(filter %.a,$^) $(filter %.lib,$^) $(lflags) -Wl,-rpath,. 2>&1 | nl
@set -o pipefail; $(cxx) $(more/$(machine)) $(wflags) -o $@ $(filter %.o,$^) $(filter %.a,$^) $(filter %.lib,$^) $(lflags) -Wl,-rpath,'$$ORIGIN' 2>&1 | nl
@openssl sha256 -r $@
@ls -la $@
signed += $(output)/package/$(name)$(exe)
Expand All @@ -69,4 +78,6 @@ $(output)/$(name).tgz: $(signed)

.PHONY: test
test: $(signed)
xdotool windowkill "$$(i3-msg -t get_tree | jq 'recurse(.nodes[]?)|select(.name=="Orchid")|.window')"
i3-msg "append_layout ${PWD}/i3layout.json"
$(output)/package/$(name)$(exe)
53 changes: 47 additions & 6 deletions app-linux/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,46 @@

#include <gtk/gtk.h>
#include <flutter_linux/flutter_linux.h>
#include <gdk/gdkx.h>
#include "flutter/generated_plugin_registrant.h"

G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, GtkApplication)

struct _MyApplication {
GtkApplication parent_instance;
char **dart_entrypoint_arguments;
};

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables,performance-no-int-to-ptr)
G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)

static void my_application_activate(GApplication *application) {
const auto self(MY_APPLICATION(application));
const auto window(GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))));
const auto header(GTK_HEADER_BAR(gtk_header_bar_new()));
gtk_widget_show(GTK_WIDGET(header));
gtk_header_bar_set_title(header, "Orchid");
gtk_header_bar_set_show_close_button(header, TRUE);
gtk_window_set_titlebar(window, GTK_WIDGET(header));

bool use_header_bar(true);
if (const auto screen(gtk_window_get_screen(window)); GDK_IS_X11_SCREEN(screen)) {
const auto wm_name(gdk_x11_screen_get_window_manager_name(screen));
if (g_strcmp0(wm_name, "GNOME Shell") != 0)
use_header_bar = false;
}

if (use_header_bar) {
const auto header(GTK_HEADER_BAR(gtk_header_bar_new()));
gtk_widget_show(GTK_WIDGET(header));
gtk_header_bar_set_title(header, "Orchid");
gtk_header_bar_set_show_close_button(header, TRUE);
gtk_window_set_titlebar(window, GTK_WIDGET(header));
} else {
gtk_window_set_title(window, "Orchid");
}

gtk_window_set_default_size(window, 360, 640);
gtk_widget_show(GTK_WIDGET(window));

const auto project = fl_dart_project_new();
const auto project(fl_dart_project_new());
fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments);

const auto view(fl_view_new(project));
gtk_widget_show(GTK_WIDGET(view));
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
Expand All @@ -52,8 +70,31 @@ static void my_application_activate(GApplication *application) {
gtk_widget_grab_focus(GTK_WIDGET(view));
}

static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) {
const auto self(MY_APPLICATION(application));
self->dart_entrypoint_arguments = g_strdupv(*arguments + 1);

g_autoptr(GError) error = nullptr;
if (!g_application_register(application, nullptr, &error)) {
g_warning("Failed to register: %s", error->message);
*exit_status = 1;
return TRUE;
}

g_application_activate(application);
*exit_status = 0;
return TRUE;
}

static void my_application_dispose(GObject *object) {
const auto self(MY_APPLICATION(object));
g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev);
G_OBJECT_CLASS(my_application_parent_class)->dispose(object);
}

static void my_application_class_init(MyApplicationClass *klass) {
G_APPLICATION_CLASS(klass)->activate = my_application_activate;
G_OBJECT_CLASS(klass)->dispose = my_application_dispose;
}

static void my_application_init(MyApplication *self) {
Expand Down

0 comments on commit a928ac9

Please sign in to comment.