summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuentin Glidic <sardemff7+git@sardemff7.net>2017-06-01 13:36:11 +0200
committerQuentin Glidic <sardemff7+git@sardemff7.net>2017-06-01 13:36:11 +0200
commit1d99363ce99d3412f20604ea93a49c7e3ee02340 (patch)
tree67e01edae4e4c8fd73576feefcb7355938c30177
parent93cb04e30f1c512a1744709f70f55faa080dbb70 (diff)
helper: Move cairo_image_surface_create_from_svg to helper.c
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
-rw-r--r--include/helper.h13
-rw-r--r--include/xcb.h8
-rw-r--r--source/helper.c26
-rw-r--r--source/xcb.c24
4 files changed, 39 insertions, 32 deletions
diff --git a/include/helper.h b/include/helper.h
index 85034288..ab7fa1c2 100644
--- a/include/helper.h
+++ b/include/helper.h
@@ -27,6 +27,9 @@
#ifndef ROFI_HELPER_H
#define ROFI_HELPER_H
+
+#include <cairo.h>
+
/**
* @defgroup HELPERS Helpers
*/
@@ -265,4 +268,14 @@ int utf8_strncmp ( const char *a, const char* b, size_t n ) __attribute__( ( non
* @returns FALSE On failure, TRUE on success
*/
int helper_execute_command ( const char *wd, const char *cmd, int run_in_term );
+
+/**
+ * @param file The file path
+ * @param height The wanted height
+ * Gets a surface from an svg path
+ *
+ * @returns a cairo surface from an svg path
+ */
+cairo_surface_t *cairo_image_surface_create_from_svg ( const gchar* file, int height );
+
#endif // ROFI_HELPER_H
diff --git a/include/xcb.h b/include/xcb.h
index aaa6981a..bca40cd8 100644
--- a/include/xcb.h
+++ b/include/xcb.h
@@ -28,6 +28,7 @@
#ifndef ROFI_XCB_H
#define ROFI_XCB_H
+#include <xcb/xcb.h>
#include <cairo.h>
/**
@@ -201,13 +202,6 @@ cairo_surface_t * x11_helper_get_bg_surface ( void );
cairo_surface_t *x11_helper_get_screenshot_surface ( void );
/**
- * Gets a surface from an svg path
- *
- * @returns a cairo surface from an svg path
- */
-cairo_surface_t *cairo_image_surface_create_from_svg ( const gchar* file, int height );
-
-/**
* Creates an internal represenation of the available monitors.
* Used for positioning rofi.
*/
diff --git a/source/helper.c b/source/helper.c
index a75e8413..e0a0563e 100644
--- a/source/helper.c
+++ b/source/helper.c
@@ -43,10 +43,10 @@
#include <sys/stat.h>
#include <pwd.h>
#include <ctype.h>
-#include <xcb/xcb.h>
#include <pango/pango.h>
#include <pango/pango-fontmap.h>
#include <pango/pangocairo.h>
+#include <librsvg/rsvg.h>
#include "xcb.h"
#include "helper.h"
#include "helper-theme.h"
@@ -1024,3 +1024,27 @@ char *helper_get_theme_path ( const char *file )
}
return filename;
}
+
+cairo_surface_t* cairo_image_surface_create_from_svg ( const gchar* file, int height )
+{
+ cairo_surface_t *surface;
+ cairo_t *cr;
+ RsvgHandle * handle;
+ RsvgDimensionData dimensions;
+
+ handle = rsvg_handle_new_from_file ( file, NULL );
+ rsvg_handle_get_dimensions ( handle, &dimensions );
+ double scale = (double) height / dimensions.height;
+ surface = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32,
+ (double) dimensions.width * scale,
+ (double) dimensions.height * scale );
+ cr = cairo_create ( surface );
+ cairo_scale ( cr, scale, scale );
+ rsvg_handle_render_cairo ( handle, cr );
+ cairo_destroy ( cr );
+
+ rsvg_handle_close ( handle, NULL );
+ g_object_unref ( handle );
+
+ return surface;
+}
diff --git a/source/xcb.c b/source/xcb.c
index 58fff7c0..60e8bd6e 100644
--- a/source/xcb.c
+++ b/source/xcb.c
@@ -135,30 +135,6 @@ cairo_surface_t * x11_helper_get_bg_surface ( void )
xcb->screen->width_in_pixels, xcb->screen->height_in_pixels );
}
-cairo_surface_t* cairo_image_surface_create_from_svg ( const gchar* file, int height )
-{
- cairo_surface_t *surface;
- cairo_t *cr;
- RsvgHandle * handle;
- RsvgDimensionData dimensions;
-
- handle = rsvg_handle_new_from_file ( file, NULL );
- rsvg_handle_get_dimensions ( handle, &dimensions );
- double scale = (double) height / dimensions.height;
- surface = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32,
- (double) dimensions.width * scale,
- (double) dimensions.height * scale );
- cr = cairo_create ( surface );
- cairo_scale ( cr, scale, scale );
- rsvg_handle_render_cairo ( handle, cr );
- cairo_destroy ( cr );
-
- rsvg_handle_close ( handle, NULL );
- g_object_unref ( handle );
-
- return surface;
-}
-
// retrieve a text property from a window
// technically we could use window_get_prop(), but this is better for character set support
char* window_get_text_prop ( xcb_window_t w, xcb_atom_t atom )