mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-21 20:05:42 +02:00
Merge branch 'fcft-3'
This commit is contained in:
commit
b8ab8669cb
10 changed files with 124 additions and 21 deletions
|
@ -37,6 +37,10 @@ tasks:
|
||||||
pip install codespell
|
pip install codespell
|
||||||
cd yambar
|
cd yambar
|
||||||
~/.local/bin/codespell README.md CHANGELOG.md *.c *.h doc/*.scd
|
~/.local/bin/codespell README.md CHANGELOG.md *.c *.h doc/*.scd
|
||||||
|
- fcft: |
|
||||||
|
cd yambar/subprojects
|
||||||
|
git clone https://codeberg.org/dnkl/fcft.git
|
||||||
|
cd ../..
|
||||||
- setup: |
|
- setup: |
|
||||||
mkdir -p bld/debug bld/release bld/x11-only bld/wayland-only bld/plugs-are-shared
|
mkdir -p bld/debug bld/release bld/x11-only bld/wayland-only bld/plugs-are-shared
|
||||||
meson --buildtype=debug -Db_coverage=true yambar bld/debug
|
meson --buildtype=debug -Db_coverage=true yambar bld/debug
|
||||||
|
|
|
@ -27,6 +27,9 @@ versions:
|
||||||
debug:
|
debug:
|
||||||
stage: build
|
stage: build
|
||||||
script:
|
script:
|
||||||
|
- cd subprojects
|
||||||
|
- git clone https://codeberg.org/dnkl/fcft.git
|
||||||
|
- cd ..
|
||||||
- apk add gcovr
|
- apk add gcovr
|
||||||
- mkdir -p bld/debug
|
- mkdir -p bld/debug
|
||||||
- cd bld/debug
|
- cd bld/debug
|
||||||
|
@ -55,6 +58,9 @@ debug:
|
||||||
release:
|
release:
|
||||||
stage: build
|
stage: build
|
||||||
script:
|
script:
|
||||||
|
- cd subprojects
|
||||||
|
- git clone https://codeberg.org/dnkl/fcft.git
|
||||||
|
- cd ..
|
||||||
- mkdir -p bld/release
|
- mkdir -p bld/release
|
||||||
- cd bld/release
|
- cd bld/release
|
||||||
- meson --buildtype=minsize ../../
|
- meson --buildtype=minsize ../../
|
||||||
|
@ -64,6 +70,9 @@ release:
|
||||||
x11_only:
|
x11_only:
|
||||||
stage: build
|
stage: build
|
||||||
script:
|
script:
|
||||||
|
- cd subprojects
|
||||||
|
- git clone https://codeberg.org/dnkl/fcft.git
|
||||||
|
- cd ..
|
||||||
- mkdir -p bld/debug
|
- mkdir -p bld/debug
|
||||||
- cd bld/debug
|
- cd bld/debug
|
||||||
- meson --buildtype=debug -Dbackend-x11=enabled -Dbackend-wayland=disabled ../../
|
- meson --buildtype=debug -Dbackend-x11=enabled -Dbackend-wayland=disabled ../../
|
||||||
|
@ -73,6 +82,9 @@ x11_only:
|
||||||
wayland_only:
|
wayland_only:
|
||||||
stage: build
|
stage: build
|
||||||
script:
|
script:
|
||||||
|
- cd subprojects
|
||||||
|
- git clone https://codeberg.org/dnkl/fcft.git
|
||||||
|
- cd ..
|
||||||
- mkdir -p bld/debug
|
- mkdir -p bld/debug
|
||||||
- cd bld/debug
|
- cd bld/debug
|
||||||
- meson --buildtype=debug -Dbackend-x11=disabled -Dbackend-wayland=enabled ../../
|
- meson --buildtype=debug -Dbackend-x11=disabled -Dbackend-wayland=enabled ../../
|
||||||
|
@ -82,6 +94,9 @@ wayland_only:
|
||||||
plugins_as_shared_modules:
|
plugins_as_shared_modules:
|
||||||
stage: build
|
stage: build
|
||||||
script:
|
script:
|
||||||
|
- cd subprojects
|
||||||
|
- git clone https://codeberg.org/dnkl/fcft.git
|
||||||
|
- cd ..
|
||||||
- mkdir -p bld/debug
|
- mkdir -p bld/debug
|
||||||
- cd bld/debug
|
- cd bld/debug
|
||||||
- meson --buildtype=debug -Dcore-plugins-as-shared-libraries=true ../../
|
- meson --buildtype=debug -Dcore-plugins-as-shared-libraries=true ../../
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
* fcft >= 3.0 is now required.
|
||||||
* Made `libmpdclient` an optional dependency
|
* Made `libmpdclient` an optional dependency
|
||||||
* battery: unknown battery states are now mapped to ‘unknown’, instead
|
* battery: unknown battery states are now mapped to ‘unknown’, instead
|
||||||
of ‘discharging’.
|
of ‘discharging’.
|
||||||
|
@ -85,7 +86,6 @@
|
||||||
* network: `ssid`, `signal`, `rx-bitrate` and `rx-bitrate` tags.
|
* network: `ssid`, `signal`, `rx-bitrate` and `rx-bitrate` tags.
|
||||||
* network: `poll-interval` option (for the new `signal` and
|
* network: `poll-interval` option (for the new `signal` and
|
||||||
`*-bitrate` tags).
|
`*-bitrate` tags).
|
||||||
* tags: percentage formatter, for range tags: `{tag_name:%}`.
|
|
||||||
* tags: percentage tag formatter, for range tags: `{tag_name:%}`.
|
* tags: percentage tag formatter, for range tags: `{tag_name:%}`.
|
||||||
* tags: kb/mb/gb, and kib/mib/gib tag formatters.
|
* tags: kb/mb/gb, and kib/mib/gib tag formatters.
|
||||||
* clock: add a config option to show UTC time.
|
* clock: add a config option to show UTC time.
|
||||||
|
|
2
PKGBUILD
2
PKGBUILD
|
@ -15,7 +15,7 @@ depends=(
|
||||||
'libudev.so'
|
'libudev.so'
|
||||||
'json-c'
|
'json-c'
|
||||||
'libmpdclient'
|
'libmpdclient'
|
||||||
'fcft>=2.4.0')
|
'fcft>=3.0.0' 'fcft<4.0.0')
|
||||||
optdepends=('xcb-util-errors: better X error messages')
|
optdepends=('xcb-util-errors: better X error messages')
|
||||||
source=()
|
source=()
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ depends=(
|
||||||
'libudev.so'
|
'libudev.so'
|
||||||
'json-c'
|
'json-c'
|
||||||
'libmpdclient'
|
'libmpdclient'
|
||||||
'fcft>=2.4.0')
|
'fcft>=3.0.0' 'fcft<4.0.0')
|
||||||
source=()
|
source=()
|
||||||
|
|
||||||
pkgver() {
|
pkgver() {
|
||||||
|
|
78
char32.c
Normal file
78
char32.c
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
#include "char32.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
|
#define LOG_MODULE "char32"
|
||||||
|
#define LOG_ENABLE_DBG 0
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For now, assume we can map directly to the corresponding wchar_t
|
||||||
|
* functions. This is true if:
|
||||||
|
*
|
||||||
|
* - both data types have the same size
|
||||||
|
* - both use the same encoding (though we require that encoding to be UTF-32)
|
||||||
|
*/
|
||||||
|
|
||||||
|
_Static_assert(
|
||||||
|
sizeof(wchar_t) == sizeof(char32_t), "wchar_t vs. char32_t size mismatch");
|
||||||
|
|
||||||
|
#if !defined(__STDC_UTF_32__) || !__STDC_UTF_32__
|
||||||
|
#error "char32_t does not use UTF-32"
|
||||||
|
#endif
|
||||||
|
#if (!defined(__STDC_ISO_10646__) || !__STDC_ISO_10646__) && !defined(__FreeBSD__)
|
||||||
|
#error "wchar_t does not use UTF-32"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
size_t
|
||||||
|
c32len(const char32_t *s)
|
||||||
|
{
|
||||||
|
return wcslen((const wchar_t *)s);
|
||||||
|
}
|
||||||
|
|
||||||
|
char32_t *
|
||||||
|
ambstoc32(const char *src)
|
||||||
|
{
|
||||||
|
if (src == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
const size_t src_len = strlen(src);
|
||||||
|
|
||||||
|
char32_t *ret = malloc((src_len + 1) * sizeof(ret[0]));
|
||||||
|
if (ret == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
mbstate_t ps = {0};
|
||||||
|
char32_t *out = ret;
|
||||||
|
const char *in = src;
|
||||||
|
const char *const end = src + src_len + 1;
|
||||||
|
|
||||||
|
size_t chars = 0;
|
||||||
|
size_t rc;
|
||||||
|
|
||||||
|
while ((rc = mbrtoc32(out, in, end - in, &ps)) != 0) {
|
||||||
|
switch (rc) {
|
||||||
|
case (size_t)-1:
|
||||||
|
case (size_t)-2:
|
||||||
|
case (size_t)-3:
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
in += rc;
|
||||||
|
out++;
|
||||||
|
chars++;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out = U'\0';
|
||||||
|
|
||||||
|
ret = realloc(ret, (chars + 1) * sizeof(ret[0]));
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
err:
|
||||||
|
free(ret);
|
||||||
|
return NULL;
|
||||||
|
}
|
7
char32.h
Normal file
7
char32.h
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <uchar.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
size_t c32len(const char32_t *s);
|
||||||
|
char32_t *ambstoc32(const char *src);
|
5
main.c
5
main.c
|
@ -296,8 +296,9 @@ main(int argc, char *const *argv)
|
||||||
"fcft log level enum offset");
|
"fcft log level enum offset");
|
||||||
_Static_assert((int)LOG_COLORIZE_ALWAYS == (int)FCFT_LOG_COLORIZE_ALWAYS,
|
_Static_assert((int)LOG_COLORIZE_ALWAYS == (int)FCFT_LOG_COLORIZE_ALWAYS,
|
||||||
"fcft colorize enum mismatch");
|
"fcft colorize enum mismatch");
|
||||||
fcft_log_init(
|
fcft_init((enum fcft_log_colorize)log_colorize, log_syslog,
|
||||||
(enum fcft_log_colorize)log_colorize, log_syslog, (enum fcft_log_class)log_level);
|
(enum fcft_log_class)log_level);
|
||||||
|
atexit(&fcft_fini);
|
||||||
|
|
||||||
const struct sigaction sa = {.sa_handler = &signal_handler};
|
const struct sigaction sa = {.sa_handler = &signal_handler};
|
||||||
sigaction(SIGINT, &sa, NULL);
|
sigaction(SIGINT, &sa, NULL);
|
||||||
|
|
|
@ -71,7 +71,7 @@ backend_wayland = wayland_client.found() and wayland_cursor.found()
|
||||||
|
|
||||||
# "My" dependencies, fallback to subproject
|
# "My" dependencies, fallback to subproject
|
||||||
tllist = dependency('tllist', version: '>=1.0.1', fallback: 'tllist')
|
tllist = dependency('tllist', version: '>=1.0.1', fallback: 'tllist')
|
||||||
fcft = dependency('fcft', version: ['>=2.4.0', '<3.0.0'], fallback: 'fcft')
|
fcft = dependency('fcft', version: ['>=3.0.0', '<4.0.0'], fallback: 'fcft')
|
||||||
|
|
||||||
add_project_arguments(
|
add_project_arguments(
|
||||||
['-D_GNU_SOURCE'] +
|
['-D_GNU_SOURCE'] +
|
||||||
|
@ -111,6 +111,7 @@ version = custom_target(
|
||||||
|
|
||||||
yambar = executable(
|
yambar = executable(
|
||||||
'yambar',
|
'yambar',
|
||||||
|
'char32.c', 'char32.h',
|
||||||
'color.h',
|
'color.h',
|
||||||
'config-verify.c', 'config-verify.h',
|
'config-verify.c', 'config-verify.h',
|
||||||
'config.c', 'config.h',
|
'config.c', 'config.h',
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#define LOG_MODULE "string"
|
#define LOG_MODULE "string"
|
||||||
#define LOG_ENABLE_DBG 0
|
#define LOG_ENABLE_DBG 0
|
||||||
#include "../log.h"
|
#include "../log.h"
|
||||||
|
#include "../char32.h"
|
||||||
#include "../config.h"
|
#include "../config.h"
|
||||||
#include "../config-verify.h"
|
#include "../config-verify.h"
|
||||||
#include "../particle.h"
|
#include "../particle.h"
|
||||||
|
@ -149,7 +150,7 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
|
||||||
struct eprivate *e = calloc(1, sizeof(*e));
|
struct eprivate *e = calloc(1, sizeof(*e));
|
||||||
struct fcft_font *font = particle->font;
|
struct fcft_font *font = particle->font;
|
||||||
|
|
||||||
wchar_t *wtext = NULL;
|
char32_t *wtext = NULL;
|
||||||
char *text = tags_expand_template(p->text, tags);
|
char *text = tags_expand_template(p->text, tags);
|
||||||
|
|
||||||
e->glyphs = e->allocated_glyphs = NULL;
|
e->glyphs = e->allocated_glyphs = NULL;
|
||||||
|
@ -173,17 +174,13 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Not in cache - we need to rasterize it. First, convert to wchar */
|
/* Not in cache - we need to rasterize it. First, convert to char32_t */
|
||||||
size_t chars = mbstowcs(NULL, text, 0);
|
wtext = ambstoc32(text);
|
||||||
if (chars == (size_t)-1)
|
size_t chars = c32len(wtext);
|
||||||
goto done;
|
|
||||||
|
|
||||||
wtext = malloc((chars + 1) * sizeof(wtext[0]));
|
|
||||||
mbstowcs(wtext, text, chars + 1);
|
|
||||||
|
|
||||||
/* Truncate, if necessary */
|
/* Truncate, if necessary */
|
||||||
if (p->max_len > 0) {
|
if (p->max_len > 0) {
|
||||||
const size_t len = wcslen(wtext);
|
const size_t len = c32len(wtext);
|
||||||
if (len > p->max_len) {
|
if (len > p->max_len) {
|
||||||
|
|
||||||
size_t end = p->max_len;
|
size_t end = p->max_len;
|
||||||
|
@ -193,11 +190,11 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p->max_len > 1) {
|
if (p->max_len > 1) {
|
||||||
wtext[end] = L'…';
|
wtext[end] = U'…';
|
||||||
wtext[end + 1] = L'\0';
|
wtext[end + 1] = U'\0';
|
||||||
chars = end + 1;
|
chars = end + 1;
|
||||||
} else {
|
} else {
|
||||||
wtext[end] = L'\0';
|
wtext[end] = U'\0';
|
||||||
chars = 0;
|
chars = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,7 +203,7 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
|
||||||
e->kern_x = calloc(chars, sizeof(e->kern_x[0]));
|
e->kern_x = calloc(chars, sizeof(e->kern_x[0]));
|
||||||
|
|
||||||
if (fcft_capabilities() & FCFT_CAPABILITY_TEXT_RUN_SHAPING) {
|
if (fcft_capabilities() & FCFT_CAPABILITY_TEXT_RUN_SHAPING) {
|
||||||
struct fcft_text_run *run = fcft_text_run_rasterize(
|
struct fcft_text_run *run = fcft_rasterize_text_run_utf32(
|
||||||
font, chars, wtext, FCFT_SUBPIXEL_NONE);
|
font, chars, wtext, FCFT_SUBPIXEL_NONE);
|
||||||
|
|
||||||
if (run != NULL) {
|
if (run != NULL) {
|
||||||
|
@ -250,7 +247,7 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
|
||||||
|
|
||||||
/* Convert text to glyph masks/images. */
|
/* Convert text to glyph masks/images. */
|
||||||
for (size_t i = 0; i < chars; i++) {
|
for (size_t i = 0; i < chars; i++) {
|
||||||
const struct fcft_glyph *glyph = fcft_glyph_rasterize(
|
const struct fcft_glyph *glyph = fcft_rasterize_char_utf32(
|
||||||
font, wtext[i], FCFT_SUBPIXEL_NONE);
|
font, wtext[i], FCFT_SUBPIXEL_NONE);
|
||||||
|
|
||||||
if (glyph == NULL)
|
if (glyph == NULL)
|
||||||
|
|
Loading…
Add table
Reference in a new issue