Skip to content
Myr

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

7 files+66 added−22 removed

modified:.gitlab-ci.yml+1 added-1 removed
modified:application.h+8 added-1 removed
1#pragma once23#include <cairo.h>4#include <librsvg/rsvg.h>56struct icon {7 cairo_surface_t *surface;8 RsvgHandle *svg;9};1011struct 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 lines
15find_package(Threads REQUIRED)16find_package(PkgConfig REQUIRED)17pkg_check_modules(fontconfig REQUIRED IMPORTED_TARGET fontconfig)18pkg_check_modules(cairo REQUIRED IMPORTED_TARGET cairo cairo-ft)19pkg_check_modules(rsvg REQUIRED IMPORTED_TARGET librsvg-2.0)20pkg_check_modules(wayland REQUIRED IMPORTED_TARGET21 wayland-client wayland-cursor wlroots)22pkg_check_modules(xkb REQUIRED IMPORTED_TARGET xkbcommon)23
59 unmodified lines
83 wayland-protocols84 ${CMAKE_THREAD_LIBS_INIT}85 PkgConfig::wayland86 PkgConfig::cairo87 PkgConfig::rsvg88 PkgConfig::fontconfig89 PkgConfig::xkb)9091install(TARGETS f00sel DESTINATION bin)
2 unmodified lines
modified:main.c+4 added-1 removed
1380 unmodified lines
1381 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 }13911392 free(c.matches);
47 unmodified lines
modified:PKGBUILD+1 added-1 removed
7 unmodified lines
8makedepends=('scdoc')9depends=(10 'libxkbcommon'11 'wayland' 'wlroots'12 'freetype2' 'fontconfig' 'cairo')12 'freetype2' 'fontconfig' 'cairo' 'librsvg')13source=()1415pkgver() {16 git describe --tags --long | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
10 unmodified lines
modified:render.c+29 added-9 removed
247 unmodified lines
248 }249250 double cur_x = border_size + x_margin;251252 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;257258 /* Get SVG size */259 RsvgDimensionData dim = {0};260 if (svg != NULL)261 rsvg_handle_get_dimensions(svg, &dim);262263 /* 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;271272 /* 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 lines
281282 cairo_save(buf->cairo);283 cairo_set_operator(buf->cairo, CAIRO_OPERATOR_OVER);284270 /* 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);290291 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 }297298 cairo_restore(buf->cairo);299 }300301 cur_x += row_height;
30 unmodified lines
modified:xdg.c+21 added-9 removed
10 unmodified lines
11#include <dirent.h>12#include <fcntl.h>13#include <pwd.h>1415#include <librsvg/rsvg.h>1617#define LOG_MODULE "xdg"18#define LOG_ENABLE_DBG 019#include "log.h"20#include "icon.h"2120static cairo_surface_t *22static struct icon23load_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};2728 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};3231 return NULL;33 return (struct icon){NULL, NULL};34 }3536 tll_foreach(themes, theme_it) {37 const struct icon_theme *theme = &theme_it->item;
46 unmodified lines
84 else85 LOG_DBG("%s: %s: nothing else matched", name, full_path);8687 free(full_path);86 return surf;88 return (struct icon){surf, NULL};89 }9091 free(full_path);92 cairo_surface_destroy(surf);
4 unmodified lines
97 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];102103 /* 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 }110111 /* 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);121110 return NULL;122 return (struct icon){NULL, NULL};123}124125static void126parse_desktop_file(int fd, icon_theme_list_t themes, int icon_size,
237 unmodified lines