aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/background-image.c8
-rw-r--r--common/cairo.c6
-rw-r--r--common/util.c12
3 files changed, 19 insertions, 7 deletions
diff --git a/common/background-image.c b/common/background-image.c
index 5ede55e3..72f39a79 100644
--- a/common/background-image.c
+++ b/common/background-image.c
@@ -24,7 +24,7 @@ enum background_mode parse_background_mode(const char *mode) {
cairo_surface_t *load_background_image(const char *path) {
cairo_surface_t *image;
-#ifdef HAVE_GDK_PIXBUF
+#if HAVE_GDK_PIXBUF
GError *err = NULL;
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, &err);
if (!pixbuf) {
@@ -36,17 +36,17 @@ cairo_surface_t *load_background_image(const char *path) {
g_object_unref(pixbuf);
#else
image = cairo_image_surface_create_from_png(path);
-#endif //HAVE_GDK_PIXBUF
+#endif // HAVE_GDK_PIXBUF
if (!image) {
wlr_log(WLR_ERROR, "Failed to read background image.");
return NULL;
}
if (cairo_surface_status(image) != CAIRO_STATUS_SUCCESS) {
wlr_log(WLR_ERROR, "Failed to read background image: %s."
-#ifndef HAVE_GDK_PIXBUF
+#if !HAVE_GDK_PIXBUF
"\nSway was compiled without gdk_pixbuf support, so only"
"\nPNG images can be loaded. This is the likely cause."
-#endif //HAVE_GDK_PIXBUF
+#endif // !HAVE_GDK_PIXBUF
, cairo_status_to_string(cairo_surface_status(image)));
return NULL;
}
diff --git a/common/cairo.c b/common/cairo.c
index e8231484..f2ad54c1 100644
--- a/common/cairo.c
+++ b/common/cairo.c
@@ -1,7 +1,7 @@
#include <stdint.h>
#include <cairo/cairo.h>
#include "cairo.h"
-#ifdef HAVE_GDK_PIXBUF
+#if HAVE_GDK_PIXBUF
#include <gdk-pixbuf/gdk-pixbuf.h>
#endif
@@ -46,7 +46,7 @@ cairo_surface_t *cairo_image_surface_scale(cairo_surface_t *image,
return new;
}
-#ifdef HAVE_GDK_PIXBUF
+#if HAVE_GDK_PIXBUF
cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf(const GdkPixbuf *gdkbuf) {
int chan = gdk_pixbuf_get_n_channels(gdkbuf);
if (chan < 3) {
@@ -140,4 +140,4 @@ cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf(const GdkPixbuf *gdk
cairo_surface_mark_dirty(cs);
return cs;
}
-#endif //HAVE_GDK_PIXBUF
+#endif // HAVE_GDK_PIXBUF
diff --git a/common/util.c b/common/util.c
index abaca17f..40c64230 100644
--- a/common/util.c
+++ b/common/util.c
@@ -3,6 +3,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <float.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
@@ -141,6 +142,17 @@ bool parse_boolean(const char *boolean, bool current) {
return false;
}
+float parse_float(const char *value) {
+ errno = 0;
+ char *end;
+ float flt = strtof(value, &end);
+ if (*end || errno) {
+ wlr_log(WLR_DEBUG, "Invalid float value '%s', defaulting to NAN", value);
+ return NAN;
+ }
+ return flt;
+}
+
enum wlr_direction opposite_direction(enum wlr_direction d) {
switch (d) {
case WLR_DIRECTION_UP: