Commit Graph

24 Commits

Author SHA1 Message Date
Simon Ser
08c1946d71 Use format_str() throughout 2023-04-14 18:34:54 +02:00
Hugo Osvaldo Barrera
80e386fd97 Reuse parsed PangoFontDescription
Avoids parsing the configured font each time text is rendered.
2022-07-01 13:05:58 +02:00
Hugo Osvaldo Barrera
75605491a5 Reject font values that are invalid for pango
Use pango to parse font configuration early, and reject the command as
invalid if the value is invalid for pango. Since we're already parsing
the font into a `PangoFontDescription`, keep that instance around and
avoid re-parsing the font each time we render text.

Fixes: https://github.com/swaywm/sway/issues/6805
2022-07-01 13:05:58 +02:00
Hugo Osvaldo Barrera
c16b2a26ed Avoid unecessary font metric calculations
Prior to 62d90a8e, titlebar's font height (and other related values)
would change any time any titlebar's content changed, so these values
were recalculated each time any titlebar's content changed (or a new
titlebar was created).

However, since the above was merge, these values no longer change so
often and we only need to recalculate them when the configured font
changes (and stop calling `config_update_font_height` each time
titlebars are rendered).

This commit removes all the unecessary calls to this function and avoids
all those unecessary calculations. Whenever the font strays from the
default value, the `font` command is called, and it calls
`config_update_font_height`, which is enough to keep the value always up
to date.

I've also added a default value to the `font_baseline` config, since
otherwise that's zero for setups that don't explicitly specify a font.
2021-09-20 09:25:47 +02:00
Simon Ser
3f7a04df22 Rename pango_printf to render_text
This avoids using the pango_ prefix, reserved for functions coming
from the Pango library.
2021-09-13 14:22:51 +02:00
Hugo Osvaldo Barrera
62d90a8e95 Use fixed titlebar heights
Use fixed titlebar heights. The default height is calculated based on
font metrics for the configured font and current locale.

Some testing with titles with emoji and CJK characters (which are
substantially higher in my setup) shows that the titlebars retain their
initial value, text does shift up or down, and all titlebars always
remain aligned.

Also drop some also now-unecessary title_height calculations.

Makes also needed to be updated, since they should be positioned with
the same rules.
2021-08-26 20:16:14 +02:00
Issam E. Maghni
d45623c2db cairo: Replace <cairo/cairo.h> by <cairo.h>
For full context, read
https://gitlab.freedesktop.org/cairo/cairo/-/issues/479
TL;DR, cairo’s pc file adds `/cairo` to CFLAGS.
So namespace cairo shouldn’t be used.
2021-05-10 10:28:32 +02:00
M Stoeckl
1211a81aad Replace wlr_log with sway_log
This commit mostly duplicates the wlr_log functions, although
with a sway_* prefix. (This is very similar to PR #2009.)
However, the logging function no longer needs to be replaceable,
so sway_log_init's second argument is used to set the exit
callback for sway_abort.

wlr_log_init is still invoked in sway/main.c

This commit makes it easier to remove the wlroots dependency for
the helper programs swaymsg, swaybg, swaybar, and swaynag.
2019-01-21 12:59:42 +01:00
Connor Edwards
9df3a9136c Allocate minimum size necessary in pango text functions. (#3473)
* Allocate minimum size necessary in pango text functions.

* Handle malloc failure.
2019-01-20 15:03:30 +01:00
Connor E
de6f5b3453 Use static arrays where possible. 2019-01-16 13:02:26 +01:00
Connor E
aa9d7d8ca1 Remove usage of VLAs. 2019-01-16 13:02:26 +01:00
Niccolò Scatena
8c86fff6dc
Fix stringop-overflow warnings 2018-10-17 13:00:12 +02:00
Connor E
cfc533aa9c Truncate message, append buffer overflow message if too long.
Increase buffer size, remove macros.

Make variables lowercase.

Some more feedback.
2018-10-16 20:20:45 +01:00
Geoff Greer
987e0054ac Call pango_cairo_context_set_font_options().
Call pango_cairo_context_set_font_options() before pango_cairo_update_layout() and pango_cairo_show_layout(). By default, Pango "merges" the Cario font options with its own, which doesn't enable full hinting.
2018-09-22 15:33:03 -07:00
Ryan Dwyer
2f36502828 Use pango_layout_set_text instead of pango_layout_set_markup 2018-09-22 18:40:19 +10:00
Ryan Dwyer
10ef118e09 Fix pango escaping and refactor escape_markup_text
Fixes #2674.

The cause of the issue was in get_pango_layout. When we call
pango_parse_markup, `text` is the escaped string, and the unescaped
string is then computed and written to `buf`. We were then passing the
unescaped string to pango_layout_set_markup, but this function needs the
escaped string. `buf` is not needed and has been removed.

The other part of this PR refactors escape_markup_text to remove the
dest_length argument and removes the -1 return value on error. It now
assumes that you've allocated dest to the correct length.
2018-09-22 18:33:28 +10:00
Ryan Dwyer
9215ca0f01 Align titles to baseline
This does the following:

* Adds a baseline argument to get_text_size (the baseline is the
distance from the top of the texture to the baseline).
* Stores the baseline in the container when calculating the title
height.
* Takes the baseline into account when calculating the config's max font
height.
* When rendering, pads the textures according to the baseline so they
line up.
2018-09-08 16:25:07 +10:00
emersion
63b4bf5000
Update for swaywm/wlroots#1126 2018-07-09 22:54:30 +01:00
Brian Ashworth
0944d3fd9c Change scale from int32_t to double for pango 2018-05-16 12:01:04 -04:00
emersion
6eda10e4ca
Fix pango markup
The condition checking if the markup is valid was inverted.

This commit also adds better error handling: if the markup cannot
be parsed, it fallbacks to plain text.
2018-05-13 16:52:02 +01:00
Heghedus Razvan
789a877b37 Fix crash when using pango markup font
The characters & < > ' " needs to be escaped when using pango markup

Signed-off-by: Heghedus Razvan <heghedus.razvan@gmail.com>
2018-05-13 17:53:45 +03:00
Drew DeVault
c507727ad2 Fix use-after-free with block hotspots 2018-04-02 11:53:56 -04:00
Drew DeVault
849c3515ab Use statically allocated text buffer 2018-03-29 22:11:08 -04:00
Drew DeVault
cab1352801 Start port of swaybar to layer shell
This starts up the event loop and wayland display and shims out the
basic top level rendering concepts. Also includes some changes to
incorporate pango into the 1.x codebase properly.
2018-03-29 22:11:08 -04:00