Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ packages:
- wayland
- wayland-protocols
- cairo
- pango
- libxkbcommon
sources:
- https://github.com/emerison/slurp
Expand Down
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ add_project_arguments('-Wno-unused-parameter', language: 'c')
cc = meson.get_compiler('c')

cairo = dependency('cairo')
pangocairo = dependency('pangocairo')
realtime = cc.find_library('rt')
wayland_client = dependency('wayland-client')
wayland_cursor = dependency('wayland-cursor')
Expand All @@ -30,6 +31,7 @@ executable(
],
dependencies: [
cairo,
pangocairo,
realtime,
wayland_client,
wayland_cursor,
Expand Down
25 changes: 15 additions & 10 deletions render.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <cairo/cairo.h>
#include <pango/pangocairo.h>
#include <stdio.h>
#include <stdlib.h>

#include "pool-buffer.h"
#include "render.h"
Expand Down Expand Up @@ -71,18 +71,23 @@ void render(struct slurp_output *output) {
cairo_stroke(cairo);

if (state->display_dimensions) {
cairo_select_font_face(cairo, state->font_family,
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(cairo, 14);
set_source_u32(cairo, state->colors.border);
// buffer of 12 can hold selections up to 99999x99999
char dimensions[12];
snprintf(dimensions, sizeof(dimensions), "%ix%i",
b.width, b.height);
cairo_move_to(cairo, b.x + b.width + 10,
b.y + b.height + 20);
cairo_show_text(cairo, dimensions);
snprintf(dimensions, sizeof(dimensions), "%ix%i", b.width, b.height);

PangoLayout *layout = pango_cairo_create_layout (cairo);
PangoFontDescription *desc = pango_font_description_new();
pango_font_description_set_family_static(desc, state->font_family);
pango_font_description_set_size(desc, 11 * PANGO_SCALE);
pango_font_description_set_style(desc, PANGO_STYLE_NORMAL);
pango_font_description_set_weight(desc, PANGO_WEIGHT_NORMAL);
pango_layout_set_font_description (layout, desc);
pango_font_description_free (desc);

cairo_move_to(cairo, b.x + b.width + 12, b.y + b.height + 8);
pango_layout_set_text (layout, dimensions, -1);
pango_cairo_show_layout (cairo, layout);
}
}
}