Commit graph

56 commits

Author SHA1 Message Date
Delgan
b85ba99980 Apply "clang-format" preferences globally 2024-04-07 10:05:10 +02:00
kotyk
176ed4a6f3
particles/string: rewrite truncation code, show three dots only for max>3 2024-01-03 15:17:51 +01:00
Stanislav Ochotnický
c0e0702a6c Update Font Awesome 5 to 6
This makes it less likely that new users will get confused and
accidentally use fallback fonts.
2022-12-21 17:06:25 +01:00
Daniel Eklöf
605a6a9ede
particle/string: don’t try to call c32len() on a NULL string 2022-06-13 12:07:24 +02:00
Daniel Eklöf
1b03bd6bc0
particle/string: simplify; no need to call c32len(wtext) twice 2022-06-13 12:06:59 +02:00
Daniel Eklöf
ffccabbb13
config: add inheritable option “font-shaping”
This patch adds an inheritable option, “font-shaping”, that controls
whether a particle that renders text should enable font-shaping or
not.

The option works similar to the ‘font’ option: one can set it at the
top-level, and it gets inherited down through all modules and to their
particles.

Or, you can set it on a module and it gets inherited to all its
particles, but not to other modules’ particles.

Finally, you can set it on individual particles, in which case it only
applies to them (or “child” particles).

When font-shaping is enabled (the default), the string particle shapes
full text runs using the fcft_rasterize_text_run_utf32() API. In fcft,
this results in HarfBuzz being used to shape the string.

When disabled, the string particle instead uses the simpler
fcft_rasterize_char_utf32() API, which rasterizes individual
characters.

This gives user greater control over the font rendering. One example
is bitmap fonts, which HarfBuzz often doesn’t get right.

Closes #159
2022-02-23 18:43:13 +01:00
Daniel Eklöf
ff238e62ba
fcft: adapt to API changes in fcft-3.x 2022-02-05 12:51:08 +01:00
Daniel Eklöf
4f0d27bc7e
particles: verify: use conf_verify_unsigned() for options that should be >= 0 2021-11-15 18:17:52 +01:00
Daniel Eklöf
8187d60193
particle/string: use HORIZONTAL ELLIPSIS as truncation character
First, apply max-len to the converted wide character string, instead
of the UTF-8 string. This is better, and more correct, since UTF-8 is
multibyte, and applying max-len to that results in strings _shorter_
than max-len.

Second, use HORIZONTAL ELLIPSIS (…) instead of three regular
periods (...) as truncation character. This “saves” 2 characters.

To be able to do this, the conversion to a wide character, and glyph
rasterization is now done when the exposable is instantiated, instead
of in begin_expose().

Closes #73
2021-07-19 12:30:21 +02:00
Daniel Eklöf
c79ffbe057
Add support binding on-click handlers to other buttons than LEFT
One can now bind the left/middle/right mouse buttons to on-click. In
fact, you can have all three buttons bound to different handlers for
the same particle. The new syntax is

    on-click:
        left: <command>
        middle: <command>
        right: <command>

Leaving one out is the same thing as not mapping it at
all. Furthermore,

    on-click: <command>

is still valid, and is a shorthand for

    on-click:
        left: <commsnd>
2021-07-01 17:15:53 +02:00
Daniel Eklöf
15ed0e043b
particle/string: don’t thrash the text-run cache
a5bbf0b769 introduced text-run
shaping.

Do avoid having to re-shape non-changing strings every time the bar is
refreshed, the *particle* (i.e. not the exposable) caches the last
shaped text-run.

Then, in expose(), it then assumes that that cached text-run is
the *same* text-run as returned from begin_expose().

This is true in most cases, but *not* when a single particle is
re-used to instantiate multiple exposables, as is commonly done by
modules generating dynlists. For example, the i3/sway module.

This fixes it, by making the cache growable, and by adding a “lock” to
each cache entry.

The lock is set in begin_expose(), to indicate that this particular
cache entry is needed in expose().

If we can’t find a matching cache entry, we first try to find a free
“slot” by searching for either unused, or used-but-not-locked cache
entries.

If that fails, we grow the cache and add a new entry.

In expose(), we unset the lock.

Closes #47
2021-05-25 21:36:14 +02:00
Daniel Eklöf
a5bbf0b769
particle/string: use fcft_text_run_rasterize() when available
This enables support for text shaping, and is required to render
e.g. 👩‍👩‍👧‍👧 correctly.

Since text-shaping is a fairly expensive operation, and since many
times the text is unchanged, we cache the last *rendered* string.

That is, we hash the instantiated string, and cache it along with the
text-run from fcft in the *particle* object (i.e. not the exposable).

This means two things:

* we only need to call fcft_text_run_rasterize() once per string
* if the string is the same as last time, we don’t have to call it at
  all.
2021-05-24 17:38:43 +02:00
Daniel Eklöf
234a787859
fcft: fcft_glyph_for_wc() has been renamed to fcft_glyph_rasterize() 2020-04-24 10:54:15 +02:00
Daniel Eklöf
e5ef81a064
fcft: max/space advance fields have been renamed 2020-04-23 11:57:50 +02:00
Daniel Eklöf
03a5c8746f
fcft: adjust to fcft-2.0 API changes
* font_*() -> fcft_*()
* struct font -> struct fcft_font
* struct glyph -> struct fcft_glyph
* enum subpixel_order -> enum fcft_subpixel
2020-04-22 11:50:29 +02:00
Daniel Eklöf
8294eb5a80
fcft: update to 1.0.0
Allow/disallow subpixel antialiasing in font_glyph_for_wc(), not using
font_enable_subpixel_antialias().
2020-01-19 12:35:29 +01:00
Daniel Eklöf
b644c75586
particle/string: apply font kerning 2020-01-18 09:27:27 +01:00
Daniel Eklöf
8a4d9137ff
particle/string: remove useless debug log 2019-12-01 19:29:27 +01:00
Daniel Eklöf
2d343755ce
particle/string: mbstowcs() may fail. When it does, don't crash 2019-11-29 23:32:27 +01:00
Daniel Eklöf
b48365aa86
font: remove the fextents sub-struct 2019-11-27 21:38:49 +01:00
Daniel Eklöf
c11fee4ce3
cairo: replace cairo with pixman in decos, particles and modules
All decoration, particle and module interfaces now takes a
pixman_image_t parameter, and all drawing is done using pixman APIs.

The wayland/xcb backends implement a new interface functions,
get_pixman_image(), that should return a pixman image instance that is
suitable for rendering.

In the wayland backend, the image uses the same backing data as the
cairo surface.

In the XCB backend, we create a new image each time, and then blit it
to the cairo surface at commit time.
2019-09-22 01:56:58 +02:00
Daniel Eklöf
95385863ae
particle: remove cairo context from begin_expose() 2019-09-22 00:55:06 +02:00
Daniel Eklöf
b3a5e0b5d7
font: initial port from cairo scaled fonts to raw freetype + pixman 2019-09-22 00:50:11 +02:00
Daniel Eklöf
cf680573c2 particle/string: improve font centering
* Use ascent+descent instead of 'height'
* Center around 'ascent', except when 'descent' is negative
2019-03-01 17:55:05 +01:00
Daniel Eklöf
611b5b551c particle/string: use *font* extents to calculate font baseline 2019-02-28 20:10:54 +01:00
Daniel Eklöf
ea38ab3b2f particle/module: pass a cairo context to all begin_expose() 2019-02-28 20:10:26 +01:00
Daniel Eklöf
6bba9200cf particles: use calloc() instead of malloc()
In cases where it makes sense, use calloc() instead of malloc():

* When allocating large objects with many members, many for which
  NULL/0 is a good default value.
* Arrays etc where we explicitly initialize to NULL anyway.
2019-02-09 11:05:12 +01:00
Daniel Eklöf
452c4b6015 plugins: export a const function pointer interface struct 2019-01-26 18:32:04 +01:00
Daniel Eklöf
498a3e3d78 particle/string: free glyphs and clusters in destroy() 2019-01-20 10:06:17 +01:00
Daniel Eklöf
5a0d192ec1 particle/string: re-use glyphs calculated in begin_expose()
In begin_expose(), we call cairo_scaled_font_text_to_glyphs()
with (x,y) = (0,0), in order to calculate the glyph extents (needed
for width calculation).

Then, in expose(), we called it again, but with correct (x,y) offsets.

Simplify this, by caching the glyphs from begin_expose(). Then, in
expose(), simply adjust the glyph offsets before calling
cairo_show_text_glyphs().
2019-01-20 10:02:13 +01:00
Daniel Eklöf
04f7f3485f particle/string: don't cut in the middle of an utf-8 multibyte
When limiting a string (due to it exceeding it's max length), make
sure not to cut it in the middle of an utf-8 multibyte, as this
results in an invalid utf-8 string.
2019-01-17 20:44:51 +01:00
Daniel Eklöf
09270c4670 particle/string: handle conversion failures in cairo_scaled_font_text_to_glyphs()
In particular, use cairo_scaled_font_text_to_glyphs() to calculate the
extents, since the cairo_scaled_font_text_extents() will leave the
scaled font in an error state, which is impossible to recuperate from.
2019-01-17 20:18:46 +01:00
Daniel Eklöf
8f58e161bc particle/string: disable debug 2019-01-15 19:15:48 +01:00
Daniel Eklöf
0d591fe5a1 allow plugins to be compiled into the f00bar main binary 2019-01-14 20:57:03 +01:00
Daniel Eklöf
4a26664d8d particles: remove config-verify.h from particle.h 2019-01-13 17:41:39 +01:00
Daniel Eklöf
07b1615a41 particles: get rid of struct particle_info
Since this struct only contained function pointers, make all particles
export those functions directly.

The plugin manager now defines a particle interface struct, and fills
it it by dlsym:ing the functions that used to be in particle_info.
2019-01-13 17:03:35 +01:00
Daniel Eklöf
74b0722d2f particles: remove header files 2019-01-13 16:49:46 +01:00
Daniel Eklöf
7776135454 particles: caller of from_conf() must provide base particle instance 2019-01-13 13:25:14 +01:00
Daniel Eklöf
8bc6a0b783 oarticles: don't assume particle content is a dictionary
This is done by having each particle implement a top-level verifier
function.
2019-01-13 12:47:20 +01:00
Daniel Eklöf
71515e4079 config: conf_verify_dict() now assumes attr list is NULL-terminated 2019-01-13 11:37:05 +01:00
Daniel Eklöf
307a1f5ec8 particles: all particles can have a decoration 2019-01-13 11:16:52 +01:00
Daniel Eklöf
47018104da particles: compile as shared libraries (plugins) 2019-01-13 11:13:47 +01:00
Daniel Eklöf
7b98ea2b7c particle/string: expose info through the new struct particle_info struct 2019-01-13 10:49:10 +01:00
Daniel Eklöf
f6977417e0 font: use font-config to load font
This allows us to a) move away from cairo's "toy" API, and b) let the
user specify font options in a single font "name" string:

  Serif:size=10:weight=bold:slant=italic

This also allows us to simplify the font code significantly (except
for the fontconfig parts...); the font no longer sets itself in a
cairo surface - font users do that; the font simply returns a
cairo_scaled_font_t.

Furthermore, font_clone() has now been simplified to basically just
refcount the scaled font. I.e. there's no need to run the full
constructor and lookup and instantiate the cairo scaled font again.
2019-01-09 18:50:16 +01:00
Daniel Eklöf
22507ae26c particle: add utility function to render a particle's decoration 2018-12-29 21:00:03 +01:00
Daniel Eklöf
7da09530b8 particle/string: tags_expand_template() now returns NULL if template is NULL 2018-12-29 17:12:11 +01:00
Daniel Eklöf
85801a5deb particle/string: expand on_click handler before passing to exposable 2018-12-29 17:10:10 +01:00
Daniel Eklöf
ab67d036ae tags: break out string formatting from particle/string 2018-12-29 17:03:41 +01:00
Daniel Eklöf
9e5dbfe27d particle/string: constructor now takes an 'on_click_template' 2018-12-29 14:38:10 +01:00
Daniel Eklöf
e8d8bf70d3 exposable: add a "common" constructor and default destructor 2018-12-29 12:51:31 +01:00