diff options
-rw-r--r-- | CMake/FindGdkPixbuf.cmake | 3 | ||||
-rw-r--r-- | CMakeLists.txt | 61 | ||||
-rw-r--r-- | README.md | 14 | ||||
-rw-r--r-- | include/client/cairo.h | 2 | ||||
-rw-r--r-- | sway/config.c | 6 | ||||
-rw-r--r-- | swaybar/main.c | 49 | ||||
-rw-r--r-- | swaybg/CMakeLists.txt | 11 | ||||
-rw-r--r-- | swaybg/main.c | 4 | ||||
-rw-r--r-- | swaylock/CMakeLists.txt | 11 | ||||
-rw-r--r-- | swaylock/main.c | 4 | ||||
-rw-r--r-- | wayland/CMakeLists.txt | 11 | ||||
-rw-r--r-- | wayland/cairo.c | 5 |
12 files changed, 139 insertions, 42 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 2a9ffde9..5cd9c67b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,18 +41,37 @@ add_definitions(-DSWAY_GIT_BRANCH=\"${GIT_BRANCH}\") string(TIMESTAMP CURRENT_DATE "%Y-%m-%d" UTC) add_definitions(-DSWAY_VERSION_DATE=\"${CURRENT_DATE}\") -find_package(Cairo REQUIRED) +option(enable-swaylock "Enables the swaylock utility" YES) +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) -find_package(Pango REQUIRED) find_package(WLC REQUIRED) find_package(Wayland REQUIRED) find_package(XKBCommon REQUIRED) -find_package(GdkPixbuf REQUIRED) -find_package(PAM REQUIRED) +find_package(Cairo) +find_package(Pango) +find_package(GdkPixbuf) +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) @@ -60,14 +79,38 @@ add_subdirectory(common) add_subdirectory(wayland) add_subdirectory(sway) -add_subdirectory(swaybg) -add_subdirectory(swaymsg) -add_subdirectory(swaygrab) -add_subdirectory(swaybar) -add_subdirectory(swaylock) +if(enable-swaybg) + if(CAIRO_FOUND AND PANGO_FOUND) + add_subdirectory(swaybg) + else() + message(WARNING "Not building swaybg - cairo, and pango are required.") + endif() +endif() +if(enable-swaymsg) + add_subdirectory(swaymsg) +endif() +if(enable-swaygrab) + add_subdirectory(swaygrab) +endif() +if(enable-swaybar) + if(CAIRO_FOUND AND PANGO_FOUND) + add_subdirectory(swaybar) + else() + message(WARNING "Not building swaybar - cairo, and pango are required.") + endif() +endif() +if(enable-swaylock) + if(CAIRO_FOUND AND PANGO_FOUND AND PAM_FOUND) + add_subdirectory(swaylock) + else() + message(WARNING "Not building swaylock - cairo, pango, and PAM are required.") + endif() +endif() install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/sway.desktop DESTINATION share/wayland-sessions COMPONENT data ) + +feature_summary(WHAT ALL) @@ -6,7 +6,7 @@ Read the [FAQ](https://github.com/SirCmpwn/sway/wiki). Join the [IRC channel](http://webchat.freenode.net/?channels=sway&uio=d4) (#sway on irc.freenode.net). -![](https://sr.ht/_qNU.png) +![](https://sr.ht/NCx_.png) ## Rationale @@ -41,10 +41,14 @@ Install dependencies: * asciidoc * pcre * json-c -* pango -* cairo -* gdk-pixbuf2 -* pam +* pango * +* cairo * +* gdk-pixbuf2 * +* pam ** + +_\*Only required for swaybar, swaybg, and swaylock_ + +_\*\*Only required for swaylock_ Run these commands: 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 <gdk-pixbuf/gdk-pixbuf.h> cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf(const GdkPixbuf *gdkbuf); +#endif //WITH_GDK_PIXBUF #endif diff --git a/sway/config.c b/sway/config.c index faa3e387..4b1bf01a 100644 --- a/sway/config.c +++ b/sway/config.c @@ -53,7 +53,9 @@ static void free_bar(struct bar_config *bar) { } list_free(bar->bindings); - free_flat_list(bar->outputs); + if (bar->outputs) { + free_flat_list(bar->outputs); + } free(bar); } @@ -450,7 +452,7 @@ void load_swaybars(swayc_t *output, int output_idx) { int j; for (j = 0; j < bar->outputs->length; ++j) { char *o = bar->outputs->items[j]; - if (strcmp(o, "*") || strcasecmp(o, output->name)) { + if (!strcmp(o, "*") || !strcasecmp(o, output->name)) { apply = true; break; } diff --git a/swaybar/main.c b/swaybar/main.c index 243ef2a9..5b8ba45d 100644 --- a/swaybar/main.c +++ b/swaybar/main.c @@ -18,8 +18,6 @@ #include "stringop.h" #include "log.h" -#define MARGIN 5 - struct box_colors { uint32_t border; uint32_t background; @@ -188,6 +186,11 @@ uint32_t parse_position(const char *position) { } } +static int margin = 3; +static const int ws_hor_padding = 5; +static double ws_ver_padding = 1.5; +static const int ws_spacing = 1; + void bar_ipc_init(int outputi, const char *bar_id) { uint32_t len = 0; char *res = ipc_single_command(socketfd, IPC_GET_OUTPUTS, NULL, &len); @@ -229,6 +232,17 @@ void bar_ipc_init(int outputi, const char *bar_id) { desktop_shell_set_panel_position(registry->desktop_shell, parse_position(json_object_get_string(position))); } + if (bar_height) { + int width, height; + get_text_size(window, &width, &height, "Test string for measuring purposes"); + int bar_height_value = json_object_get_int(bar_height); + if (bar_height_value > 0) { + margin = (bar_height_value - height) / 2; + ws_ver_padding = margin - 1.5; + } + window->height = height + margin * 2; + } + if (_colors) { json_object *background, *statusline, *separator; json_object *focused_workspace_border, *focused_workspace_bg, *focused_workspace_text; @@ -321,12 +335,12 @@ void render() { int width, height; get_text_size(window, &width, &height, "%s", line); - cairo_move_to(window->cairo, window->width - MARGIN - width, MARGIN); + cairo_move_to(window->cairo, window->width - margin - width, margin); pango_printf(window, "%s", line); // Workspaces - cairo_set_line_width(window->cairo, 2.0); - int x = 1; + cairo_set_line_width(window->cairo, 1.0); + double x = 0.5; int i; for (i = 0; i < workspaces->length; ++i) { struct workspace *ws = workspaces->items[i]; @@ -341,19 +355,20 @@ void render() { } else { box_colors = colors.inactive_workspace; } + cairo_set_source_u32(window->cairo, box_colors.background); - cairo_rectangle(window->cairo, x, 0, width + MARGIN * 2, window->height); + cairo_rectangle(window->cairo, x, 1.5, width + ws_hor_padding * 2 - 1, height + ws_ver_padding * 2); cairo_fill(window->cairo); cairo_set_source_u32(window->cairo, box_colors.border); - cairo_rectangle(window->cairo, x, 2, width + MARGIN * 2, window->height - 4); + cairo_rectangle(window->cairo, x, 1.5, width + ws_hor_padding * 2 - 1, height + ws_ver_padding * 2); cairo_stroke(window->cairo); cairo_set_source_u32(window->cairo, box_colors.text); - cairo_move_to(window->cairo, x + MARGIN, MARGIN); + cairo_move_to(window->cairo, (int)x + ws_hor_padding, margin); pango_printf(window, "%s", ws->name); - x += width + MARGIN * 2 + MARGIN; + x += width + ws_hor_padding * 2 + ws_spacing; } } @@ -467,6 +482,12 @@ int main(int argc, char **argv) { int desired_output = atoi(argv[optind]); struct output_state *output = registry->outputs->items[desired_output]; + window = window_setup(registry, output->width, 30, false); + if (!window) { + sway_abort("Failed to create window."); + } + desktop_shell_set_panel(registry->desktop_shell, output->output, window->surface); + bar_ipc_init(desired_output, bar_id); if (status_command) { @@ -491,16 +512,6 @@ int main(int argc, char **argv) { line[0] = '\0'; } - window = window_setup(registry, output->width, 30, false); - if (!window) { - sway_abort("Failed to create window."); - } - desktop_shell_set_panel(registry->desktop_shell, output->output, window->surface); - - int width, height; - get_text_size(window, &width, &height, "Test string for measuring purposes"); - window->height = height + MARGIN * 2; - poll_for_update(); window_teardown(window); 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 <gdk-pixbuf/gdk-pixbuf.h> #include <cairo/cairo.h> #include "client/cairo.h" +#ifdef WITH_GDK_PIXBUF +#include <gdk-pixbuf/gdk-pixbuf.h> + #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 |