Skip to content

Commit

Permalink
fix(meson): able to build on standard platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
jtheoof committed Dec 28, 2019
1 parent c5ec285 commit 8abc5d5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
5 changes: 1 addition & 4 deletions include/notification.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#ifndef _NOTIFICATION_H
#define _NOTIFICATION_H
#pragma once

void notification_send(char *title, char *message);

#endif
15 changes: 11 additions & 4 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -49,7 +57,6 @@ executable(
cairo,
client_protos,
gtk,
gtk_layer_shell,
libnotify,
math,
realtime,
Expand Down
13 changes: 6 additions & 7 deletions src/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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",
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/notification.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#include "notification.h"

#ifdef HAVE_LIBNOTIFY
#include <libnotify/notify.h>
#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
}

0 comments on commit 8abc5d5

Please sign in to comment.