diff options
| -rw-r--r-- | .build.yml | 1 | ||||
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | background-image.c | 3 | ||||
| -rw-r--r-- | include/pool-buffer.h | 2 | ||||
| -rw-r--r-- | main.c | 16 | ||||
| -rw-r--r-- | meson.build | 20 | ||||
| -rw-r--r-- | meson_options.txt | 18 | ||||
| -rw-r--r-- | pango.c | 145 | ||||
| -rw-r--r-- | pool-buffer.c | 5 | ||||
| -rw-r--r-- | render.c | 8 | ||||
| -rw-r--r-- | shadow.c | 1 | ||||
| -rw-r--r-- | swaylock.1.scd | 7 | ||||
| -rw-r--r-- | unicode.c | 35 |
13 files changed, 27 insertions, 235 deletions
@@ -1,7 +1,6 @@ image: alpine/edge packages: - meson - - pango-dev - cairo-dev - wayland-dev - wayland-protocols @@ -34,7 +34,6 @@ Install dependencies: * wayland * wayland-protocols \* * libxkbcommon -* pango * cairo * gdk-pixbuf2 \*\* * pam (optional) diff --git a/background-image.c b/background-image.c index d2ab03b..c765bdf 100644 --- a/background-image.c +++ b/background-image.c @@ -1,5 +1,4 @@ #include <assert.h> -#include <stdbool.h> #include "background-image.h" #include "cairo.h" #include "log.h" @@ -30,7 +29,7 @@ cairo_surface_t *load_background_image(const char *path) { if (!pixbuf) { swaylock_log(LOG_ERROR, "Failed to load background image (%s).", err->message); - return false; + return NULL; } image = gdk_cairo_image_surface_create_from_pixbuf(pixbuf); g_object_unref(pixbuf); diff --git a/include/pool-buffer.h b/include/pool-buffer.h index 54f5be0..0ebf787 100644 --- a/include/pool-buffer.h +++ b/include/pool-buffer.h @@ -1,7 +1,6 @@ #ifndef _SWAY_BUFFERS_H #define _SWAY_BUFFERS_H #include <cairo/cairo.h> -#include <pango/pangocairo.h> #include <stdbool.h> #include <stdint.h> #include <wayland-client.h> @@ -10,7 +9,6 @@ struct pool_buffer { struct wl_buffer *buffer; cairo_surface_t *surface; cairo_t *cairo; - PangoContext *pango; uint32_t width, height; void *data; size_t size; @@ -658,7 +658,6 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, case 'c': if (state) { state->args.colors.background = parse_color(optarg); - state->args.mode = BACKGROUND_MODE_SOLID_COLOR; } break; case 'd': @@ -882,18 +881,9 @@ static char *get_config_path(void) { SYSCONFDIR "/swaylock/config", }; - if (!getenv("XDG_CONFIG_HOME")) { - char *home = getenv("HOME"); - char *config_home = malloc(strlen(home) + strlen("/.config") + 1); - if (!config_home) { - swaylock_log(LOG_ERROR, "Unable to allocate $HOME/.config"); - } else { - strcpy(config_home, home); - strcat(config_home, "/.config"); - setenv("XDG_CONFIG_HOME", config_home, 1); - swaylock_log(LOG_DEBUG, "Set XDG_CONFIG_HOME to %s", config_home); - free(config_home); - } + char *config_home = getenv("XDG_CONFIG_HOME"); + if (!config_home || config_home[0] == '\0') { + config_paths[1] = "$HOME/.config/swaylock/config"; } wordexp_t p; diff --git a/meson.build b/meson.build index 32965e2..85dfe00 100644 --- a/meson.build +++ b/meson.build @@ -2,6 +2,7 @@ project( 'swaylock', 'c', license: 'MIT', + meson_version: '>=0.48.0', default_options: [ 'c_std=c11', 'warning_level=2', @@ -37,15 +38,13 @@ wayland_client = dependency('wayland-client') wayland_protos = dependency('wayland-protocols', version: '>=1.14') xkbcommon = dependency('xkbcommon') cairo = dependency('cairo') -pango = dependency('pango') -pangocairo = dependency('pangocairo') -gdk_pixbuf = dependency('gdk-pixbuf-2.0', required: false) -libpam = cc.find_library('pam', required: get_option('pam') == 'enabled') -crypt = cc.find_library('crypt', required: false) +gdk_pixbuf = dependency('gdk-pixbuf-2.0', required: get_option('gdk-pixbuf')) +libpam = cc.find_library('pam', required: get_option('pam')) +crypt = cc.find_library('crypt', required: not libpam.found()) math = cc.find_library('m') git = find_program('git', required: false) -scdoc = find_program('scdoc', required: false) +scdoc = find_program('scdoc', required: get_option('man-pages')) wayland_scanner = find_program('wayland-scanner') version = get_option('swaylock-version') @@ -119,8 +118,6 @@ dependencies = [ client_protos, gdk_pixbuf, math, - pango, - pangocairo, xkbcommon, wayland_client, ] @@ -132,7 +129,6 @@ sources = [ 'log.c', 'loop.c', 'main.c', - 'pango.c', 'password.c', 'pool-buffer.c', 'render.c', @@ -140,16 +136,14 @@ sources = [ 'unicode.c', ] -if libpam.found() and get_option('pam') != 'disabled' +if libpam.found() sources += ['pam.c'] dependencies += [libpam] else warning('The swaylock binary must be setuid when compiled without libpam') warning('You must do this manually post-install: chmod a+s /path/to/swaylock') sources += ['shadow.c'] - if crypt.found() - dependencies += [crypt] - endif + dependencies += [crypt] endif swaylock_inc = include_directories('include') diff --git a/meson_options.txt b/meson_options.txt index 2e58cd9..c870cb9 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,11 +1,7 @@ -option('swaylock-version', type : 'string', description: 'The version string reported in `swaylock --version`.') -option( - 'pam', - type: 'combo', - choices: ['auto', 'enabled', 'disabled'], - value: 'auto', - description: 'Use PAM instead of shadow.', -) -option('zsh-completions', type: 'boolean', value: true, description: 'Install zsh shell completions.') -option('bash-completions', type: 'boolean', value: true, description: 'Install bash shell completions.') -option('fish-completions', type: 'boolean', value: true, description: 'Install fish shell completions.') +option('swaylock-version', type : 'string', description: 'The version string reported in `swaylock --version`') +option('pam', type: 'feature', value: 'auto', description: 'Use PAM instead of shadow') +option('gdk-pixbuf', type: 'feature', value: 'auto', description: 'Enable support for more image formats') +option('man-pages', type: 'feature', value: 'auto', description: 'Generate and install man pages') +option('zsh-completions', type: 'boolean', value: true, description: 'Install zsh shell completions') +option('bash-completions', type: 'boolean', value: true, description: 'Install bash shell completions') +option('fish-completions', type: 'boolean', value: true, description: 'Install fish shell completions') diff --git a/pango.c b/pango.c deleted file mode 100644 index 8e80015..0000000 --- a/pango.c +++ /dev/null @@ -1,145 +0,0 @@ -#include <cairo/cairo.h> -#include <pango/pangocairo.h> -#include <stdarg.h> -#include <stdbool.h> -#include <stdint.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "cairo.h" -#include "log.h" - -static const char overflow[] = "[buffer overflow]"; -static const int max_chars = 16384; - -static char *lenient_strcat(char *dest, const char *src) { - if (dest && src) { - return strcat(dest, src); - } - return dest; -} - -size_t escape_markup_text(const char *src, char *dest) { - size_t length = 0; - if (dest) { - dest[0] = '\0'; - } - - while (src[0]) { - switch (src[0]) { - case '&': - length += 5; - lenient_strcat(dest, "&"); - break; - case '<': - length += 4; - lenient_strcat(dest, "<"); - break; - case '>': - length += 4; - lenient_strcat(dest, ">"); - break; - case '\'': - length += 6; - lenient_strcat(dest, "'"); - break; - case '"': - length += 6; - lenient_strcat(dest, """); - break; - default: - if (dest) { - dest[length] = *src; - dest[length + 1] = '\0'; - } - length += 1; - } - src++; - } - return length; -} - -PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, - const char *text, double scale, bool markup) { - PangoLayout *layout = pango_cairo_create_layout(cairo); - PangoAttrList *attrs; - if (markup) { - char *buf; - GError *error = NULL; - if (pango_parse_markup(text, -1, 0, &attrs, &buf, NULL, &error)) { - pango_layout_set_text(layout, buf, -1); - free(buf); - } else { - swaylock_log(LOG_ERROR, "pango_parse_markup '%s' -> error %s", - text, error->message); - g_error_free(error); - markup = false; // fallback to plain text - } - } - if (!markup) { - attrs = pango_attr_list_new(); - pango_layout_set_text(layout, text, -1); - } - - pango_attr_list_insert(attrs, pango_attr_scale_new(scale)); - PangoFontDescription *desc = pango_font_description_from_string(font); - pango_layout_set_font_description(layout, desc); - pango_layout_set_single_paragraph_mode(layout, 1); - pango_layout_set_attributes(layout, attrs); - pango_attr_list_unref(attrs); - pango_font_description_free(desc); - return layout; -} - -void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, - int *baseline, double scale, bool markup, const char *fmt, ...) { - char *buf = malloc(max_chars); - if (buf == NULL) { - swaylock_log(LOG_ERROR, "Failed to allocate memory"); - return; - } - - va_list args; - va_start(args, fmt); - if (vsnprintf(buf, max_chars, fmt, args) >= max_chars) { - strcpy(&buf[sizeof(buf) - sizeof(overflow)], overflow); - } - va_end(args); - - PangoLayout *layout = get_pango_layout(cairo, font, buf, scale, markup); - pango_cairo_update_layout(cairo, layout); - pango_layout_get_pixel_size(layout, width, height); - if (baseline) { - *baseline = pango_layout_get_baseline(layout) / PANGO_SCALE; - } - g_object_unref(layout); - - free(buf); -} - -void pango_printf(cairo_t *cairo, const char *font, - double scale, bool markup, const char *fmt, ...) { - char *buf = malloc(max_chars); - if (buf == NULL) { - swaylock_log(LOG_ERROR, "Failed to allocate memory"); - return; - } - - va_list args; - va_start(args, fmt); - if (vsnprintf(buf, max_chars, fmt, args) >= max_chars) { - strcpy(&buf[sizeof(buf) - sizeof(overflow)], overflow); - } - va_end(args); - - PangoLayout *layout = get_pango_layout(cairo, font, buf, scale, markup); - cairo_font_options_t *fo = cairo_font_options_create(); - cairo_get_font_options(cairo, fo); - pango_cairo_context_set_font_options(pango_layout_get_context(layout), fo); - cairo_font_options_destroy(fo); - pango_cairo_update_layout(cairo, layout); - pango_cairo_show_layout(cairo, layout); - g_object_unref(layout); - - free(buf); -} diff --git a/pool-buffer.c b/pool-buffer.c index 2eadb4f..b3f1ef2 100644 --- a/pool-buffer.c +++ b/pool-buffer.c @@ -2,7 +2,6 @@ #include <assert.h> #include <cairo/cairo.h> #include <fcntl.h> -#include <pango/pangocairo.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -93,7 +92,6 @@ static struct pool_buffer *create_buffer(struct wl_shm *shm, buf->surface = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, width, height, stride); buf->cairo = cairo_create(buf->surface); - buf->pango = pango_cairo_create_context(buf->cairo); wl_buffer_add_listener(buf->buffer, &buffer_listener, buf); return buf; @@ -109,9 +107,6 @@ void destroy_buffer(struct pool_buffer *buffer) { if (buffer->surface) { cairo_surface_destroy(buffer->surface); } - if (buffer->pango) { - g_object_unref(buffer->pango); - } if (buffer->data) { munmap(buffer->data, buffer->size); } @@ -59,10 +59,10 @@ void render_frame(struct swaylock_surface *surface) { cairo_save(cairo); cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE); - if (state->args.mode == BACKGROUND_MODE_SOLID_COLOR || !surface->image) { - cairo_set_source_u32(cairo, state->args.colors.background); - cairo_paint(cairo); - } else { + cairo_set_source_u32(cairo, state->args.colors.background); + cairo_paint(cairo); + if (surface->image && state->args.mode != BACKGROUND_MODE_SOLID_COLOR) { + cairo_set_operator(cairo, CAIRO_OPERATOR_OVER); render_background_image(cairo, surface->image, state->args.mode, buffer_width, buffer_height); } @@ -1,6 +1,7 @@ #define _XOPEN_SOURCE // for crypt #include <pwd.h> #include <shadow.h> +#include <stdlib.h> #include <stdbool.h> #include <sys/types.h> #include <unistd.h> diff --git a/swaylock.1.scd b/swaylock.1.scd index 593358b..9f7d88c 100644 --- a/swaylock.1.scd +++ b/swaylock.1.scd @@ -55,15 +55,16 @@ Locks your Wayland session. Show the current Caps Lock state also on the indicator. *-s, --scaling* - Scaling mode for images: _stretch_, _fill_, _fit_, _center_, or _tile_. + Scaling mode for images: _stretch_, _fill_, _fit_, _center_, or _tile_. Use + the additional mode _solid\_color_ to display only the background color, even + if a background image is specified. *-t, --tiling* Same as --scaling=tile. *-c, --color* <rrggbb[aa]> Turn the screen into the given color. If -i is used, this sets the - background of the image to the given color. Defaults to white (FFFFFF), or - transparent (00000000) if an image is in use. + background of the image to the given color. Defaults to white (FFFFFF). *--bs-hl-color* <rrggbb[aa]> Sets the color of backspace highlight segments. @@ -13,41 +13,6 @@ size_t utf8_chsize(uint32_t ch) { return 4; } -static const uint8_t masks[] = { - 0x7F, - 0x1F, - 0x0F, - 0x07, - 0x03, - 0x01 -}; - -uint32_t utf8_decode(const char **char_str) { - uint8_t **s = (uint8_t **)char_str; - - uint32_t cp = 0; - if (**s < 128) { - // shortcut - cp = **s; - ++*s; - return cp; - } - int size = utf8_size((char *)*s); - if (size == -1) { - ++*s; - return UTF8_INVALID; - } - uint8_t mask = masks[size - 1]; - cp = **s & mask; - ++*s; - while (--size) { - cp <<= 6; - cp |= **s & 0x3f; - ++*s; - } - return cp; -} - size_t utf8_encode(char *str, uint32_t ch) { size_t len = 0; uint8_t first; |
