From 21014e606b9b28d792b98cf363f20c7df2136723 Mon Sep 17 00:00:00 2001 From: progandy Date: Sun, 20 Dec 2015 17:37:52 +0100 Subject: [PATCH] make gdk-pixbuf dependency really optional --- CMake/FindGdkPixbuf.cmake | 3 +++ CMakeLists.txt | 24 ++++++++++++++++++------ include/client/cairo.h | 2 ++ swaybg/CMakeLists.txt | 11 +++++++++-- swaybg/main.c | 4 ++++ swaylock/CMakeLists.txt | 11 +++++++++-- swaylock/main.c | 4 ++++ wayland/CMakeLists.txt | 11 +++++++++-- wayland/cairo.c | 5 ++++- 9 files changed, 62 insertions(+), 13 deletions(-) diff --git a/CMake/FindGdkPixbuf.cmake b/CMake/FindGdkPixbuf.cmake index 53bb0501..4ea1d5b9 100644 --- a/CMake/FindGdkPixbuf.cmake +++ b/CMake/FindGdkPixbuf.cmake @@ -29,6 +29,7 @@ IF(NOT GDK_PIXBUF_FOUND AND NOT PKG_CONFIG_FOUND) # Report results IF(GDK_PIXBUF_LIBRARIES AND GDK_PIXBUF_INCLUDE_DIRS) SET(GDK_PIXBUF_FOUND 1) + SET(GdkPixbuf_FOUND 1) IF(NOT GdkPixbuf_FIND_QUIETLY) MESSAGE(STATUS "Found GdkPixbuf: ${GDK_PIXBUF_LIBRARIES}") ENDIF(NOT GdkPixbuf_FIND_QUIETLY) @@ -41,6 +42,8 @@ IF(NOT GDK_PIXBUF_FOUND AND NOT PKG_CONFIG_FOUND) ENDIF(NOT GdkPixbuf_FIND_QUIETLY) ENDIF(GdkPixbuf_FIND_REQUIRED) ENDIF(GDK_PIXBUF_LIBRARIES AND GDK_PIXBUF_INCLUDE_DIRS) +ELSE(NOT GDK_PIXBUF_FOUND AND NOT PKG_CONFIG_FOUND) + SET(GdkPixbuf_FOUND 1) ENDIF(NOT GDK_PIXBUF_FOUND AND NOT PKG_CONFIG_FOUND) # Hide advanced variables from CMake GUIs diff --git a/CMakeLists.txt b/CMakeLists.txt index 31e79ca4..5cd9c67b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,7 @@ option(enable-swaybg "Enables the wallpaper utility" YES) option(enable-swaybar "Enables the swaybar utility" YES) option(enable-swaygrab "Enables the swaygrab utility" YES) option(enable-swaymsg "Enables the swaymsg utility" YES) +option(enable-gdk-pixbuf "Use Pixbuf to support more image formats" YES) find_package(JsonC REQUIRED) find_package(PCRE REQUIRED) @@ -60,6 +61,17 @@ find_package(PAM) include(FeatureSummary) include(Manpage) +if (enable-gdk-pixbuf) + if (GDK_PIXBUF_FOUND) + set(WITH_GDK_PIXBUF YES) + add_definitions(-DWITH_GDK_PIXBUF) + else() + message(WARNING "gdk-pixbuf required but not found, only png images supported.") + endif() +else() + message(STATUS "Building without gdk-pixbuf, only png images supported.") +endif() + include_directories(include) add_subdirectory(protocols) @@ -68,10 +80,10 @@ add_subdirectory(wayland) add_subdirectory(sway) if(enable-swaybg) - if(CAIRO_FOUND AND PANGO_FOUND AND GDK_PIXBUF_FOUND) + if(CAIRO_FOUND AND PANGO_FOUND) add_subdirectory(swaybg) else() - message(WARNING "Not building swaybg - cairo, pango, and gdk-pixbuf are required.") + message(WARNING "Not building swaybg - cairo, and pango are required.") endif() endif() if(enable-swaymsg) @@ -81,17 +93,17 @@ if(enable-swaygrab) add_subdirectory(swaygrab) endif() if(enable-swaybar) - if(CAIRO_FOUND AND PANGO_FOUND AND GDK_PIXBUF_FOUND) + if(CAIRO_FOUND AND PANGO_FOUND) add_subdirectory(swaybar) else() - message(WARNING "Not building swaybar - cairo, pango, and gdk-pixbuf are required.") + message(WARNING "Not building swaybar - cairo, and pango are required.") endif() endif() if(enable-swaylock) - if(CAIRO_FOUND AND PANGO_FOUND AND GDK_PIXBUF_FOUND AND PAM_FOUND) + if(CAIRO_FOUND AND PANGO_FOUND AND PAM_FOUND) add_subdirectory(swaylock) else() - message(WARNING "Not building swaylock - cairo, pango, gdk-pixbuf, and PAM are required.") + message(WARNING "Not building swaylock - cairo, pango, and PAM are required.") endif() endif() diff --git a/include/client/cairo.h b/include/client/cairo.h index 98ced907..ad8390c4 100644 --- a/include/client/cairo.h +++ b/include/client/cairo.h @@ -1,8 +1,10 @@ #ifndef _SWAY_CAIRO_H #define _SWAY_CAIRO_H +#ifdef WITH_GDK_PIXBUF #include cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf(const GdkPixbuf *gdkbuf); +#endif //WITH_GDK_PIXBUF #endif diff --git a/swaybg/CMakeLists.txt b/swaybg/CMakeLists.txt index 4dc961ff..68098370 100644 --- a/swaybg/CMakeLists.txt +++ b/swaybg/CMakeLists.txt @@ -3,7 +3,6 @@ include_directories( ${WAYLAND_CLIENT_INCLUDE_DIR} ${CAIRO_INCLUDE_DIRS} ${PANGO_INCLUDE_DIRS} - ${GDK_PIXBUF_INCLUDE_DIRS} ) add_executable(swaybg @@ -17,10 +16,18 @@ target_link_libraries(swaybg ${WAYLAND_CURSOR_LIBRARIES} ${CAIRO_LIBRARIES} ${PANGO_LIBRARIES} - ${GDK_PIXBUF_LIBRARIES} m ) +if (WITH_GDK_PIXBUF) + include_directories( + ${GDK_PIXBUF_INCLUDE_DIRS} + ) + target_link_libraries(swaybg + ${GDK_PIXBUF_LIBRARIES} + ) +endif() + install( TARGETS swaybg RUNTIME diff --git a/swaybg/main.c b/swaybg/main.c index 2ae06c6f..b936be2b 100644 --- a/swaybg/main.c +++ b/swaybg/main.c @@ -56,6 +56,7 @@ int main(int argc, const char **argv) { desktop_shell_set_background(registry->desktop_shell, output->output, window->surface); list_add(surfaces, window); +#ifdef WITH_GDK_PIXBUF GError *err = NULL; GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(argv[2], &err); if (!pixbuf) { @@ -63,6 +64,9 @@ int main(int argc, const char **argv) { } cairo_surface_t *image = gdk_cairo_image_surface_create_from_pixbuf(pixbuf); g_object_unref(pixbuf); +#else + cairo_surface_t *image = cairo_image_surface_create_from_png(argv[2]); +#endif //WITH_GDK_PIXBUF if (!image) { sway_abort("Failed to read background image."); } diff --git a/swaylock/CMakeLists.txt b/swaylock/CMakeLists.txt index 306be80e..950a170d 100644 --- a/swaylock/CMakeLists.txt +++ b/swaylock/CMakeLists.txt @@ -2,7 +2,6 @@ include_directories( ${PROTOCOLS_INCLUDE_DIRS} ${WAYLAND_CLIENT_INCLUDE_DIR} ${CAIRO_INCLUDE_DIRS} - ${GDK_PIXBUF_INCLUDE_DIRS} ${PANGO_INCLUDE_DIRS} ${PAM_INCLUDE_DIRS} ) @@ -17,12 +16,20 @@ target_link_libraries(swaylock ${WAYLAND_CLIENT_LIBRARIES} ${WAYLAND_CURSOR_LIBRARIES} ${CAIRO_LIBRARIES} - ${GDK_PIXBUF_LIBRARIES} ${PANGO_LIBRARIES} ${PAM_LIBRARIES} m ) +if (WITH_GDK_PIXBUF) + include_directories( + ${GDK_PIXBUF_INCLUDE_DIRS} + ) + target_link_libraries(swaylock + ${GDK_PIXBUF_LIBRARIES} + ) +endif() + install( TARGETS swaylock RUNTIME diff --git a/swaylock/main.c b/swaylock/main.c index 82b88731..eccb902e 100644 --- a/swaylock/main.c +++ b/swaylock/main.c @@ -113,6 +113,7 @@ int main(int argc, char **argv) { registry->input->notify = notify_key; +#ifdef WITH_GDK_PIXBUF GError *err = NULL; GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(argv[1], &err); // TODO: Parse i3lock arguments if (!pixbuf) { @@ -120,6 +121,9 @@ int main(int argc, char **argv) { } cairo_surface_t *image = gdk_cairo_image_surface_create_from_pixbuf(pixbuf); g_object_unref(pixbuf); +#else + cairo_surface_t *image = cairo_image_surface_create_from_png(argv[1]); +#endif //WITH_GDK_PIXBUF if (!image) { sway_abort("Failed to read background image."); } diff --git a/wayland/CMakeLists.txt b/wayland/CMakeLists.txt index 6519cd7d..282ea1aa 100644 --- a/wayland/CMakeLists.txt +++ b/wayland/CMakeLists.txt @@ -1,7 +1,6 @@ include_directories( ${PROTOCOLS_INCLUDE_DIRS} ${PANGO_INCLUDE_DIRS} - ${GDK_PIXBUF_INCLUDE_DIRS} ${XKBCOMMON_INCLUDE_DIRS} ) @@ -17,6 +16,14 @@ target_link_libraries(sway-wayland sway-common sway-protocols ${PANGO_LIBRARIES} - ${GDK_PIXBUF_LIBRARIES} ${XKBCOMMON_LIBRARIES} ) + +if (WITH_GDK_PIXBUF) + include_directories( + ${GDK_PIXBUF_INCLUDE_DIRS} + ) + target_link_libraries(sway-wayland + ${GDK_PIXBUF_LIBRARIES} + ) +endif() diff --git a/wayland/cairo.c b/wayland/cairo.c index 10a15f40..7462b10a 100644 --- a/wayland/cairo.c +++ b/wayland/cairo.c @@ -1,7 +1,9 @@ -#include #include #include "client/cairo.h" +#ifdef WITH_GDK_PIXBUF +#include + #ifndef GDK_PIXBUF_CHECK_VERSION #define GDK_PIXBUF_CHECK_VERSION(major,minor,micro) \ (GDK_PIXBUF_MAJOR > (major) || \ @@ -103,3 +105,4 @@ cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf(const GdkPixbuf *gdk cairo_surface_mark_dirty(cs); return cs; } +#endif //WITH_GDK_PIXBUF