From 05d87c929ff8b3311cd5db111cd2f53a32c35a19 Mon Sep 17 00:00:00 2001 From: Jeremy Attali Date: Sat, 28 Dec 2019 17:02:50 -0500 Subject: [PATCH] fix(resources): compile resources and fix error management --- include/swappy.h | 1 - meson.build | 1 + res/meson.build | 8 ++------ res/swappy.gresource.xml | 8 ++++---- src/application.c | 42 ++++++++++++++++++++-------------------- src/main.c | 9 +++++++-- 6 files changed, 35 insertions(+), 34 deletions(-) diff --git a/include/swappy.h b/include/swappy.h index c097c79..17f56b0 100644 --- a/include/swappy.h +++ b/include/swappy.h @@ -102,7 +102,6 @@ struct swappy_state_ui { }; struct swappy_state { - GResource *resource; GtkApplication *app; struct swappy_state_ui *ui; diff --git a/meson.build b/meson.build index cd22ba4..6755b1d 100644 --- a/meson.build +++ b/meson.build @@ -41,6 +41,7 @@ subdir('protocol') executable( 'swappy', + swappy_resources, files([ 'src/main.c', 'src/notification.c', diff --git a/res/meson.build b/res/meson.build index 9436148..a1b73c6 100644 --- a/res/meson.build +++ b/res/meson.build @@ -1,12 +1,8 @@ -pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name()) - # Import the gnome module and use a GNOME function to ensure that application # resources will be compiled. gnome = import('gnome') -gnome.compile_resources('swappy', +swappy_resources = gnome.compile_resources('swappy', 'swappy.gresource.xml', - gresource_bundle: true, - install: true, - install_dir: pkgdatadir, + cname: 'swappy_resources' ) \ No newline at end of file diff --git a/res/swappy.gresource.xml b/res/swappy.gresource.xml index 2a313ed..31b783e 100644 --- a/res/swappy.gresource.xml +++ b/res/swappy.gresource.xml @@ -1,7 +1,7 @@ - - style/swappy.css - swappy.ui - + + style/swappy.css + swappy.ui + \ No newline at end of file diff --git a/src/application.c b/src/application.c index 7ff3cd3..652d2c1 100644 --- a/src/application.c +++ b/src/application.c @@ -164,7 +164,6 @@ void application_finish(struct swappy_state *state) { g_free(state->storage_path); g_free(state->geometry_str); g_free(state->geometry); - g_resources_unregister(state->resource); g_free(state->ui); g_object_unref(state->app); } @@ -447,11 +446,13 @@ static void apply_css(GtkWidget *widget, GtkStyleProvider *provider) { } } -static void load_css(struct swappy_state *state) { +static bool load_css(struct swappy_state *state) { GtkCssProvider *provider = gtk_css_provider_new(); - gtk_css_provider_load_from_resource(provider, "/swappy/style/swappy.css"); + gtk_css_provider_load_from_resource(provider, + "/me/jtheoof/swappy/style/swappy.css"); apply_css(GTK_WIDGET(state->ui->window), GTK_STYLE_PROVIDER(provider)); g_object_unref(provider); + return true; } static bool load_layout(struct swappy_state *state) { @@ -460,8 +461,8 @@ static bool load_layout(struct swappy_state *state) { /* Construct a GtkBuilder instance and load our UI description */ GtkBuilder *builder = gtk_builder_new(); - if (gtk_builder_add_from_resource(builder, "/swappy/swappy.ui", &error) == - 0) { + if (gtk_builder_add_from_resource(builder, "/me/jtheoof/swappy/swappy.ui", + &error) == 0) { g_printerr("Error loading file: %s", error->message); g_clear_error(&error); return false; @@ -521,14 +522,21 @@ static bool load_layout(struct swappy_state *state) { return true; } -static void init_gtk_window(struct swappy_state *state) { +static bool init_gtk_window(struct swappy_state *state) { g_info("activating application ----------"); - load_layout(state); - load_css(state); + if (!load_layout(state)) { + return false; + } + + if (!load_css(state)) { + return false; + } update_ui_stroke_size_widget(state); update_ui_undo_redo(state); + + return true; } static gboolean is_geometry_valid(struct swappy_state *state) { @@ -539,7 +547,7 @@ static gint command_line_handler(GtkApplication *app, GApplicationCommandLine *cmdline, struct swappy_state *state) { if (!is_geometry_valid(state)) { - g_warning("geometry parameter is missing"); + g_printerr("geometry parameter is missing\n"); return EXIT_FAILURE; } @@ -550,17 +558,18 @@ static gint command_line_handler(GtkApplication *app, } if (!screencopy_init(state)) { - g_warning("unable to initialize zwlr_screencopy_v1"); + g_printerr("unable to initialize zwlr_screencopy_v1\n"); return false; } - init_gtk_window(state); + if (!init_gtk_window(state)) { + return EXIT_FAILURE; + } return EXIT_SUCCESS; } bool application_init(struct swappy_state *state) { - GError *error = NULL; const GOptionEntry cli_options[] = { { .long_name = "geometry", @@ -582,17 +591,8 @@ bool application_init(struct swappy_state *state) { g_application_add_main_option_entries(G_APPLICATION(state->app), cli_options); - state->resource = g_resource_load("build/meson-out/swappy.gresource", &error); - - if (error != NULL) { - g_critical("unable to load swappy resource file: %s", error->message); - g_error_free(error); - } - state->ui = g_new(struct swappy_state_ui, 1); - g_resources_register(state->resource); - g_signal_connect(state->app, "command-line", G_CALLBACK(command_line_handler), state); diff --git a/src/main.c b/src/main.c index 4ba4891..14fc436 100644 --- a/src/main.c +++ b/src/main.c @@ -16,6 +16,7 @@ int main(int argc, char *argv[]) { struct swappy_state state = {0}; + int status; state.argc = argc; state.argv = argv; @@ -36,10 +37,14 @@ int main(int argc, char *argv[]) { exit(1); } - application_run(&state); + status = application_run(&state); - gtk_main(); + if (status == 0) { + gtk_main(); + } application_finish(&state); wayland_finish(&state); + + return status; }