summaryrefslogtreecommitdiff
path: root/common
AgeCommit message (Collapse)AuthorLines
2023-02-28Use format_str() throughoutFurkan Sahin-16/+4
2023-02-28common/gesture: use format_str()Furkan Sahin-24/+7
We already had a similar function in there.
2023-02-28Add format_str() and vformat_str()Furkan Sahin-0/+33
Simple helpers to allocate and format a string.
2022-07-01Reuse parsed PangoFontDescriptionFurkan Sahin-7/+5
Avoids parsing the configured font each time text is rendered.
2022-06-29Reject font values that are invalid for pangoFurkan Sahin-3/+1
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-04-23sway: add bindgesture commandFurkan Sahin-0/+351
Co-authored-by: Michael Weiser <michael.weiser@gmx.de>
2022-01-09Add safety assert in parse_movement_unitFurkan Sahin-0/+6
Let's add this just in case a caller passes argc == 0. References: https://github.com/swaywm/sway/issues/6737#issuecomment-1008082540
2021-09-17Avoid unecessary font metric calculationsFurkan Sahin-3/+1
Prior to 7ade2c9f, 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-13Rename pango_printf to render_textFurkan Sahin-1/+1
This avoids using the pango_ prefix, reserved for functions coming from the Pango library.
2021-08-18Use fixed titlebar heightsFurkan Sahin-0/+18
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-06-20input: Move get_current_time_msec in from utilFurkan Sahin-6/+0
get_current_time_msec is only used in cursor.c, so we can move it in and make it static. This is primarily intended to avoid a symbol collision with wlroots, which we unfortunately do not have a good solution for yet.
2021-05-07cairo: Replace <cairo/cairo.h> by <cairo.h>Furkan Sahin-5/+5
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.
2020-12-10common/log: write log importanceFurkan Sahin-0/+9
When colors aren't used, write the log importance to stderr. This makes it easier to grep for errors and avoids mistaking error messages for debug messages. This is [1] ported to Sway. [1]: https://github.com/swaywm/wlroots/pull/2149
2020-12-03common: make 'lenient_strcmp' arguments constFurkan Sahin-1/+1
Prevents build failures when calling the function with 'const char *' arguments. This is also more accurate since the function is not expected to modify the args.
2020-06-15common/loop: check return of reallocFurkan Sahin-3/+9
2020-06-04ipc: fix aligment issue of data bufferFurkan Sahin-7/+5
The pointer `data` is cast to a more strictly aligned pointer type. To prevent issues, the `data32` buffer is removed and its occurrences are replaced with an offset from the `data` buffer.
2020-07-16moved and renamed movement-unit parsing to commonFurkan Sahin-0/+34
2020-06-05common/util: fix `get_current_time_msec` returning microsecondsFurkan Sahin-1/+7
This commit makes `get_current_time_msec` correctly return milliseconds as opposed to microseconds. It also considers the value of `tv_sec`, so we don't lose occasionally go back in time by one second. Finally, the function is moved into `util.c` so that it can be reused elsewhere without having to consider these pitfalls.
2020-06-06Add wayland_client dependency to commonFurkan Sahin-1/+2
2020-05-23common/log: use bright black rather than black for SWAY_DEBUGFurkan Sahin-1/+1
On some terminals under default settings, black is truly rendered as `#000`, making it unreadable when the background is also black. Closes #5141.
2020-03-07common/log: bump POSIX version used after f98a89f3f1caFurkan Sahin-1/+1
../common/log.c:63:16: error: use of undeclared identifier 'CLOCK_MONOTONIC' clock_gettime(CLOCK_MONOTONIC, &start_time); ^ ../common/log.c:75:16: error: use of undeclared identifier 'CLOCK_MONOTONIC' clock_gettime(CLOCK_MONOTONIC, &ts); ^
2020-03-05common/log: improve time prefixFurkan Sahin-8/+30
Same as [1]. [1]: https://github.com/swaywm/wlroots/pull/2052
2019-12-27cmd_client_*: refactor duplicated codeFurkan Sahin-0/+7
This is the second in a series of commits to refactor the color handling in sway. This removes the duplicated color parsing code in sway/commands/client.c. Additionally, this combines the parsing of colors to float arrays with that in sway/config.c and introduces a color_to_rgba function in commom/util.c. As an added bonus, this also makes it so non of the colors in a border color class will be changed unless all of the colors specified are valid. This ensures that an invalid command does not get partially applied.
2019-12-27parse_color: return success + drop fallback colorFurkan Sahin-9/+10
This is the first in a series of commits to refactor the color handling in sway. This changes parse_color to return whether it was success and no longer uses 0xFFFFFFFF as the fallback color. This also verifies that the string actually contains a valid hexadecimal number along with the length checks. In the process of altering the calls to parse_color, I also took the opportunity to heavily refactor swaybar's ipc_parse_colors function. This allowed for several lines of duplicated code to be removed.
2019-11-23Amend typosFurkan Sahin-1/+1
2019-11-20input_cmd_xkb_file: allow shell path expansionFurkan Sahin-0/+19
This allows for shell path expansion for input_cmd_xkb_file. The logic has been extracted from output_cmd_background
2019-10-28Rename symbol set_cloexec to sway_set_cloexec, remove duplicates.Furkan Sahin-1/+1
set_cloexec is defined by both sway and wlroots (and who-knows-else), so rename the sway one for supporting static linkage. We also remove the duplicate version of this in client/. Fixes: https://github.com/swaywm/sway/issues/4677
2019-08-07ipc-client: remove useless free for failed mallocFurkan Sahin-1/+0
2019-06-22Use -fmacro-prefix-map to strip build pathFurkan Sahin-17/+0
Because meson does not provide a simple way to get the relative build path, it is computed with a pair of foreach loops. As meson does not have a simple way to compute string length (except via underscorify and 63 split operations), the build script uses a shell command instead. If the compiler does not suppot -fmacro-prefix-map, then fall back to passing in the relative path prefix, and use its length to offset the uses of __FILE__ in log messages so that the build path is at least still not included in the logs. This is significantly more efficient than calling _sway_strip_path.
2019-06-11Fix segfaults caused by faulty command parsingFurkan Sahin-16/+40
This patch fixes faulty command parsing introduced by 482bcb78e6fa356c28d685552e2409e4c9c66714. When that commit allowed criteria reset on ';' delimeters in commands lists, it failed to account for its inner ','-parsing loop eating threw the entire rest of the string. This patch refactors argsep to use a list of multiple separators, and (optionally) return the separator that it matched against in this iteration via a pointer. This allows it to hint at the command parser which separator was used at the end of the last command, allowing it to trigger a potential secondary read of the criteria. Fixes #4239
2019-05-27common/ipc-client: remove ipc recv timeout logFurkan Sahin-2/+0
This just removes the ipc recv timeout log statement in `ipc_recv_set_timeout`. The `tv_sec` field of `struct timeval` has varying types and/or sizes depending on the platform and architecture. On some of these, the current format string will cause compilation errors. Additionally, the log statement is not extremely useful and the function is currently only used by swaymsg, which has a hardcoded log level that will prevent it from even being shown, so there is no point in even keeping it.
2019-04-25swaybg: split into standalone projectFurkan Sahin-99/+100
The new upstream is https://github.com/swaywm/swaybg This commit also refactors our use of gdk-pixbuf a bit, since the only remaining reverse dependency is swaybar tray support.
2019-04-17swaymsg: add timeout and type checksFurkan Sahin-0/+10
This adds a 3 second timeout to the initial reply in swaymsg. This prevents swaymsg from hanging when `swaymsg -t get_{inputs,seats}` is used in i3. The timeout is removed when waiting for a subscribed event or monitoring for subscribed events. This also adds type checks to commands where i3 does not reply with all of the properties that sway does (such as `modes` in `get_outputs`). This is mostly just a behavioral adjustment since swaymsg should run on i3. When running under i3, some command reply's (such as the one for `get_outputs) may have more useful information in the raw json than the pretty printed version.
2019-04-14Spawn swaynag as a wayland clientFurkan Sahin-0/+19
This spawns swaynag as a wayland client similar to how swaybar and swaybg are already done
2019-02-10Add support for manually setting subpixel hinting on outputs.Furkan Sahin-0/+21
Many laptop screens report unknown subpixel order. Allow users to manually set subpixel hinting to work around this. Addresses https://github.com/swaywm/sway/issues/3163
2019-01-17stringop.c: refactor a few functionsFurkan Sahin-8/+5
2019-01-17stringop.c: clean up headersFurkan Sahin-5/+5
2019-01-17stringop.c: remove unused functionsFurkan Sahin-115/+0
The only use of `join_list` in swaybar/tray/icon.c has been rewritten.
2019-02-05output_cmd_background: fix no file + valid modeFurkan Sahin-0/+3
If output_cmd_background is given a valid mode as the first argument, then there is no file given and an error should be returned. join_args should not be called with an argc of zero since it sets the last character to the null terminator. With an argc of zero, the length is zero causing a heap buffer overflow when setting the byte before the start of argv to '\0'. This probably will not ever generate a segfault, but may cause data corruption to whatever is directly before it in memory. To make other such cases easier to detect, this also adds a sway_assert in join_args when argc is zero.
2019-01-22background-image.c: remove stdbool headerFurkan Sahin-2/+1
2019-01-22util.c: remove numlen functionFurkan Sahin-9/+0
Its uses have been replaced by snprintf, which is more in line with its usage.
2019-01-21Removed unused wlroots dependency for sway(bg|bar|msg|nag)Furkan Sahin-2/+1
Also remove direct libm dependency where unused.
2019-01-21Fix edge case bug in numlen, dropping use of math.h functionsFurkan Sahin-4/+5
(Specifically, numlen when called with INT_MIN gave an incorrect result, because abs(INT_MIN) == INT_MIN < 0.)
2019-01-21Move sway-specific functions in common/util.c into sway/Furkan Sahin-105/+0
Modifier handling functions were moved into sway/input/keyboard.c; opposite_direction for enum wlr_direction into sway/tree/output.c; and get_parent_pid into sway/tree/root.c .
2019-01-20Replace wlr_log with sway_logFurkan Sahin-18/+99
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-20Allocate minimum size necessary in pango text functions. (#3473)Furkan Sahin-12/+22
* Allocate minimum size necessary in pango text functions. * Handle malloc failure.
2019-01-19Fix backup methods in get_socketpath for IPC clientFurkan Sahin-4/+12
Previously, the success of `getline` was tested by checking if the buffer it allocates is nonempty and has a nonzero first byte. As `getline` does not explicitly zero out its memory buffer, this may fail (e.g., with AddressSanitizer). Instead, we check that at least one character was returned on standard output. Also, trailing newlines (if present) are now removed.
2019-01-17Remove unicode.cFurkan Sahin-102/+0
2019-01-16Use static arrays where possible.Furkan Sahin-18/+13
2019-01-16Remove usage of VLAs.Furkan Sahin-6/+15