aboutsummaryrefslogtreecommitdiffstats
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) {
24 24
25cairo_surface_t *load_background_image(const char *path) { 25cairo_surface_t *load_background_image(const char *path) {
26 cairo_surface_t *image; 26 cairo_surface_t *image;
27#ifdef HAVE_GDK_PIXBUF 27#if HAVE_GDK_PIXBUF
28 GError *err = NULL; 28 GError *err = NULL;
29 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, &err); 29 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, &err);
30 if (!pixbuf) { 30 if (!pixbuf) {
@@ -36,17 +36,17 @@ cairo_surface_t *load_background_image(const char *path) {
36 g_object_unref(pixbuf); 36 g_object_unref(pixbuf);
37#else 37#else
38 image = cairo_image_surface_create_from_png(path); 38 image = cairo_image_surface_create_from_png(path);
39#endif //HAVE_GDK_PIXBUF 39#endif // HAVE_GDK_PIXBUF
40 if (!image) { 40 if (!image) {
41 wlr_log(WLR_ERROR, "Failed to read background image."); 41 wlr_log(WLR_ERROR, "Failed to read background image.");
42 return NULL; 42 return NULL;
43 } 43 }
44 if (cairo_surface_status(image) != CAIRO_STATUS_SUCCESS) { 44 if (cairo_surface_status(image) != CAIRO_STATUS_SUCCESS) {
45 wlr_log(WLR_ERROR, "Failed to read background image: %s." 45 wlr_log(WLR_ERROR, "Failed to read background image: %s."
46#ifndef HAVE_GDK_PIXBUF 46#if !HAVE_GDK_PIXBUF
47 "\nSway was compiled without gdk_pixbuf support, so only" 47 "\nSway was compiled without gdk_pixbuf support, so only"
48 "\nPNG images can be loaded. This is the likely cause." 48 "\nPNG images can be loaded. This is the likely cause."
49#endif //HAVE_GDK_PIXBUF 49#endif // !HAVE_GDK_PIXBUF
50 , cairo_status_to_string(cairo_surface_status(image))); 50 , cairo_status_to_string(cairo_surface_status(image)));
51 return NULL; 51 return NULL;
52 } 52 }
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 @@
1#include <stdint.h> 1#include <stdint.h>
2#include <cairo/cairo.h> 2#include <cairo/cairo.h>
3#include "cairo.h" 3#include "cairo.h"
4#ifdef HAVE_GDK_PIXBUF 4#if HAVE_GDK_PIXBUF
5#include <gdk-pixbuf/gdk-pixbuf.h> 5#include <gdk-pixbuf/gdk-pixbuf.h>
6#endif 6#endif
7 7
@@ -46,7 +46,7 @@ cairo_surface_t *cairo_image_surface_scale(cairo_surface_t *image,
46 return new; 46 return new;
47} 47}
48 48
49#ifdef HAVE_GDK_PIXBUF 49#if HAVE_GDK_PIXBUF
50cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf(const GdkPixbuf *gdkbuf) { 50cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf(const GdkPixbuf *gdkbuf) {
51 int chan = gdk_pixbuf_get_n_channels(gdkbuf); 51 int chan = gdk_pixbuf_get_n_channels(gdkbuf);
52 if (chan < 3) { 52 if (chan < 3) {
@@ -140,4 +140,4 @@ cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf(const GdkPixbuf *gdk
140 cairo_surface_mark_dirty(cs); 140 cairo_surface_mark_dirty(cs);
141 return cs; 141 return cs;
142} 142}
143#endif //HAVE_GDK_PIXBUF 143#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 @@
3#include <sys/types.h> 3#include <sys/types.h>
4#include <sys/stat.h> 4#include <sys/stat.h>
5#include <unistd.h> 5#include <unistd.h>
6#include <float.h>
6#include <math.h> 7#include <math.h>
7#include <stdint.h> 8#include <stdint.h>
8#include <stdio.h> 9#include <stdio.h>
@@ -141,6 +142,17 @@ bool parse_boolean(const char *boolean, bool current) {
141 return false; 142 return false;
142} 143}
143 144
145float parse_float(const char *value) {
146 errno = 0;
147 char *end;
148 float flt = strtof(value, &end);
149 if (*end || errno) {
150 wlr_log(WLR_DEBUG, "Invalid float value '%s', defaulting to NAN", value);
151 return NAN;
152 }
153 return flt;
154}
155
144enum wlr_direction opposite_direction(enum wlr_direction d) { 156enum wlr_direction opposite_direction(enum wlr_direction d) {
145 switch (d) { 157 switch (d) {
146 case WLR_DIRECTION_UP: 158 case WLR_DIRECTION_UP: