Merge branch 'svg-icons'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Daniel Eklöf · committed by Daniel Eklöf · parents 865d18d, 9d8e917 · Browse files · 7 files·+66 added−22 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+66 added−22 removed
- other:+66 added−22 removed
Provenance
- Commit
e8562b4- Tree
a215739- Author
Daniel Eklöf <daniel@ekloef.se>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent 1
865d18d- Parent 2
9d8e917
7 files changed+66 added−22 removed
modified:.gitlab-ci.yml+1 added-1 removed
8 unmodified lines910111213131415161713 unmodified lines8 unmodified linesbefore_script: - echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories - apk update - apk add musl-dev linux-headers cmake ninja gcc scdoc - apk add libxkbcommon-dev cairo-dev yaml-dev - apk add libxkbcommon-dev cairo-dev yaml-dev librsvg-dev - apk add wayland-dev wayland-protocols wlroots-dev
debug: stage: build13 unmodified linesmodified:application.h+8 added-1 removed
1 #pragma once2 3 #include <cairo.h>4+#include <librsvg/rsvg.h>5 6+struct icon {7+ cairo_surface_t *surface;8+ RsvgHandle *svg;9+};10+11 struct application {12 char *path;13 char *exec;14 char *title;15 char *comment;10- cairo_surface_t *icon;16+ //cairo_surface_t *icon;17+ struct icon icon;18 };modified:CMakeLists.txt+2 added
14 unmodified lines15 find_package(Threads REQUIRED)16 find_package(PkgConfig REQUIRED)17 pkg_check_modules(fontconfig REQUIRED IMPORTED_TARGET fontconfig)18 pkg_check_modules(cairo REQUIRED IMPORTED_TARGET cairo cairo-ft)19+pkg_check_modules(rsvg REQUIRED IMPORTED_TARGET librsvg-2.0)20 pkg_check_modules(wayland REQUIRED IMPORTED_TARGET21 wayland-client wayland-cursor wlroots)22 pkg_check_modules(xkb REQUIRED IMPORTED_TARGET xkbcommon)23 59 unmodified lines83 wayland-protocols84 ${CMAKE_THREAD_LIBS_INIT}85 PkgConfig::wayland86 PkgConfig::cairo87+ PkgConfig::rsvg88 PkgConfig::fontconfig89 PkgConfig::xkb)90 91 install(TARGETS f00sel DESTINATION bin)2 unmodified linesmodified:main.c+4 added-1 removed
1380 unmodified lines1381 free(it->item.path);1382 free(it->item.exec);1383 free(it->item.title);1384 free(it->item.comment);1385+ if (it->item.icon.surface != NULL)1385- cairo_surface_destroy(it->item.icon);1386+ cairo_surface_destroy(it->item.icon.surface);1387+ if (it->item.icon.svg != NULL)1388+ g_object_unref(it->item.icon.svg);1389 tll_remove(c.applications, it);1390 }1391 1392 free(c.matches);47 unmodified linesmodified:PKGBUILD+1 added-1 removed
7 unmodified lines8 makedepends=('scdoc')9 depends=(10 'libxkbcommon'11 'wayland' 'wlroots'12- 'freetype2' 'fontconfig' 'cairo')12+ 'freetype2' 'fontconfig' 'cairo' 'librsvg')13 source=()14 15 pkgver() {16 git describe --tags --long | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'10 unmodified linesmodified:render.c+29 added-9 removed
247 unmodified lines248 }249 250 double cur_x = border_size + x_margin;251 252- if (match->application->icon != NULL) {253- cairo_surface_t *surf = match->application->icon;254- double width = cairo_image_surface_get_width(surf);255- double height = cairo_image_surface_get_height(surf);256- double scale = 1.0;252+ if (match->application->icon.surface != NULL ||253+ match->application->icon.svg != NULL)254+ {255+ cairo_surface_t *surf = match->application->icon.surface;256+ RsvgHandle *svg = match->application->icon.svg;257 258+ /* Get SVG size */259+ RsvgDimensionData dim = {0};260+ if (svg != NULL)261+ rsvg_handle_get_dimensions(svg, &dim);262+263+ /* For SVGs, *we* set the final size and then scale264+ * it. For PNGs, we use the icon's size, and only scale it265+ * if necessary */266+ double width = svg != NULL267+ ? row_height - 4 : cairo_image_surface_get_width(surf);268+ double height = svg != NULL269+ ? row_height - 4 : cairo_image_surface_get_height(surf);270+ double scale = svg != NULL ? height / dim.height : 1.0;271+272+ /* Do we need to scale the PNG? */258- if (height > row_height) {273+ if (svg == NULL && height > row_height) {274 scale = (row_height - 2 * y_margin) / height;275 LOG_DBG("%s: scaling: %f (row-height: %f, size=%fx%f)",276 match->application->title, scale, row_height, width, height);277 3 unmodified lines281 282 cairo_save(buf->cairo);283 cairo_set_operator(buf->cairo, CAIRO_OPERATOR_OVER);284 270- /* Translate/scale - order matters! */285+ /* Translate + scale. Note: order matters! */286 cairo_translate(287 buf->cairo, cur_x,288 first_row + i * row_height + (row_height - height) / 2);289 cairo_scale(buf->cairo, scale, scale);290 291+ if (svg != NULL)292+ rsvg_handle_render_cairo(svg, buf->cairo);293+ else {276- cairo_set_source_surface(buf->cairo, surf, 0, 0);277- cairo_paint(buf->cairo);294+ cairo_set_source_surface(buf->cairo, surf, 0, 0);295+ cairo_paint(buf->cairo);296+ }297+298 cairo_restore(buf->cairo);299 }300 301 cur_x += row_height;30 unmodified linesmodified:xdg.c+21 added-9 removed
10 unmodified lines11 #include <dirent.h>12 #include <fcntl.h>13 #include <pwd.h>14 15+#include <librsvg/rsvg.h>16+17 #define LOG_MODULE "xdg"18 #define LOG_ENABLE_DBG 019 #include "log.h"20 #include "icon.h"21 20-static cairo_surface_t *22+static struct icon23 load_icon(const char *name, int icon_size, icon_theme_list_t themes)24 {25 if (name == NULL)24- return NULL;26+ return (struct icon){NULL, NULL};27 28 if (name[0] == '/') {29 cairo_surface_t *surf = cairo_image_surface_create_from_png(name);30 if (cairo_surface_status(surf) == CAIRO_STATUS_SUCCESS)29- return surf;31+ return (struct icon){surf, NULL};32 31- return NULL;33+ return (struct icon){NULL, NULL};34 }35 36 tll_foreach(themes, theme_it) {37 const struct icon_theme *theme = &theme_it->item;46 unmodified lines84 else85 LOG_DBG("%s: %s: nothing else matched", name, full_path);86 87 free(full_path);86- return surf;88+ return (struct icon){surf, NULL};89 }90 91 free(full_path);92 cairo_surface_destroy(surf);4 unmodified lines97 xdg_data_dirs_t dirs = xdg_data_dirs();98 tll_foreach(dirs, it) {99 char path[strlen(it->item) + 1 +100 strlen("pixmaps") + 1 +99- strlen(name) + strlen(".png") + 1];100- sprintf(path, "%s/pixmaps/%s.png", it->item, name);101+ strlen(name) + strlen(".svg") + 1];102 103+ /* Try SVG variant first */104+ sprintf(path, "%s/pixmaps/%s.svg", it->item, name);105+ RsvgHandle *svg = rsvg_handle_new_from_file(path, NULL);106+ if (svg != NULL) {107+ xdg_data_dirs_destroy(dirs);108+ return (struct icon){NULL, svg};109+ }110+111+ /* No SVG, look for PNG instead */112+ sprintf(path, "%s/pixmaps/%s.png", it->item, name);113 cairo_surface_t *surf = cairo_image_surface_create_from_png(path);114 if (cairo_surface_status(surf) == CAIRO_STATUS_SUCCESS) {115 xdg_data_dirs_destroy(dirs);105- return surf;116+ return (struct icon){surf, NULL};117 }118+ cairo_surface_destroy(surf);119 }120 xdg_data_dirs_destroy(dirs);121 110- return NULL;122+ return (struct icon){NULL, NULL};123 }124 125 static void126 parse_desktop_file(int fd, icon_theme_list_t themes, int icon_size,237 unmodified lines