From 8abc5d52ec2962a111c6d44cdb5e9e209ac219c7 Mon Sep 17 00:00:00 2001 From: Jeremy Attali Date: Fri, 27 Dec 2019 19:55:34 -0500 Subject: [PATCH] fix(meson): able to build on standard platforms --- include/notification.h | 5 +---- meson.build | 15 +++++++++++---- src/application.c | 13 ++++++------- src/notification.c | 4 ++++ 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/include/notification.h b/include/notification.h index a34fee6..aac2929 100644 --- a/include/notification.h +++ b/include/notification.h @@ -1,6 +1,3 @@ -#ifndef _NOTIFICATION_H -#define _NOTIFICATION_H +#pragma once void notification_send(char *title, char *message); - -#endif \ No newline at end of file diff --git a/meson.build b/meson.build index 68ee78e..cd22ba4 100644 --- a/meson.build +++ b/meson.build @@ -12,22 +12,30 @@ project( ) add_project_arguments('-Wno-unused-parameter', language: 'c') -#add_project_arguments('-Wno-format-truncation', language: 'c') swappy_inc = include_directories('include') cc = meson.get_compiler('c') +if cc.get_id() == 'clang' + message('clang') + add_global_arguments('-Wno-missing-field-initializers', language: 'c') +endif + cairo = dependency('cairo') math = cc.find_library('m') realtime = cc.find_library('rt') gtk = dependency('gtk+-wayland-3.0', version: '>=3.22.0') -gtk_layer_shell = dependency('gtk-layer-shell-0', version: '>= 0.1.0') -libnotify = dependency('libnotify') wayland_client = dependency('wayland-client') wayland_cursor = dependency('wayland-cursor') wayland_protos = dependency('wayland-protocols', version: '>=1.14') +libnotify = dependency('libnotify', required: false) + +if libnotify.found() + add_project_arguments('-DHAVE_LIBNOTIFY', language: 'c') +endif + subdir('res') subdir('protocol') @@ -49,7 +57,6 @@ executable( cairo, client_protos, gtk, - gtk_layer_shell, libnotify, math, realtime, diff --git a/src/application.c b/src/application.c index 63f34db..7ff3cd3 100644 --- a/src/application.c +++ b/src/application.c @@ -190,17 +190,19 @@ static void action_save_area_to_file(struct swappy_state *state) { char path[MAX_PATH]; snprintf(path, MAX_PATH, "%s/%s %s", state->storage_path, "Swappshot", c_time_string); - g_info("saving swappshot to: \"%s\"", path); gdk_pixbuf_savev(pixbuf, path, "png", NULL, NULL, &error); if (error != NULL) { - g_error("unable to save drawing area to pixbuf: %s", error->message); + g_critical("unable to save drawing area to pixbuf: %s", error->message); g_error_free(error); } - char message[MAX_PATH]; - snprintf(message, MAX_PATH, "Saved Swappshot to: %s\n", path); + char *msg = "Saved Swappshot to: "; + size_t len = strlen(msg) + strlen(path) + 1; + char *message = g_new(char, len); + snprintf(message, len, "%s%s", msg, path); notification_send("Swappy", message); + g_free(message); } void save_clicked_handler(GtkWidget *widget, struct swappy_state *state) { @@ -559,8 +561,6 @@ static gint command_line_handler(GtkApplication *app, bool application_init(struct swappy_state *state) { GError *error = NULL; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wmissing-field-initializers" const GOptionEntry cli_options[] = { { .long_name = "geometry", @@ -571,7 +571,6 @@ bool application_init(struct swappy_state *state) { "Set the region to capture. (Can be an output of slurp)", }, {NULL}}; -#pragma clang diagnostic pop state->app = gtk_application_new("me.jtheoof.swappy", G_APPLICATION_HANDLES_COMMAND_LINE); diff --git a/src/notification.c b/src/notification.c index 4e72892..7b2a467 100644 --- a/src/notification.c +++ b/src/notification.c @@ -1,12 +1,16 @@ #include "notification.h" +#ifdef HAVE_LIBNOTIFY #include +#endif void notification_send(char *title, char *message) { +#ifdef HAVE_LIBNOTIFY notify_init("Hello world!"); NotifyNotification *notification = notify_notification_new(title, message, "dialog-information"); notify_notification_show(notification, NULL); g_object_unref(G_OBJECT(notification)); notify_uninit(); +#endif } \ No newline at end of file