Skip to content

Commit

Permalink
sync: merge upstream master into forked master (#8)
Browse files Browse the repository at this point in the history
* root: Try to preserve relative positions of floating containers

This makes the behavior of floating containers more consistent with i3.
The coordinates of the container are scaled when the size of the
workspace it is on changes or when the container is moved
between workspaces on different outputs.

For scratchpad containers, add a new state that preserves the dimensions
of the last output the window appeared on. This is necessary because
after a container is hidden in the scratchpad, we expect it to be in the
same relative position on the output when it reappears. We can't just
use the container's attached workspace because that workspace's
dimensions might have been changed or the workspace as a whole could
have been destroyed.

* root: Set inactive focus when scratchpad is moved to new workspace

Fixes an issue where an already visible scratchpad window being moved due to
'scratchpad show' leaves the entire workspace at the top of the focus stack in
the old workspace. Moving by 'focus output' back to the old workspace would
focus the entire workspace instead of just the last active container.

* Init the damage_ring bounds on output creation

Otherwise the initial bounds would be `INT_MAX` until `handle_mode` or `handle_commit` is called :)

* man: deprecate seat cursor move/set/press/release

The Wayland protocol better serves this purpose, and is supported
by more compositors.

* Add a .mailmap file

* ipc: add LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM entry

This was introduced in the last libinput release.

Fixes the following error:

    ../sway/ipc-json.c:928:17: error: enumeration value 'LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM' not handled in switch [-Werror=switch]
      928 |                 switch (libinput_device_config_accel_get_profile(device)) {
          |                 ^~~~~~

* swaybar: Set opaque region properly

The opaque region is set incorrectly if updated on-the-fly if switching from an opaque to a non opaque background.

* swaybar: Lift background clearing out of main rendering function

This avoids us from using a bogus background_color value that
mutates as swaybar renders things and deciding opacity depending on
that.

Also remove a redundant full surface clear. Just directly write our
desired background color.

* Fix damage-ring bounds not being set when unplugging -> plugging in monitor

swaywm#7524 was a partial fix. Seems like this is still an issue when
unplugging and plugging the monitor back in.

Closes: swaywm#7528

* Remove duplicate wlr_damage_ring_set_bounds() call

We already do this in handle_commit().

* Chase wlroots!4067

* Pass version to wlr_compositor_create()

References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3696

* Skip direct scan-out commit when damage is empty

When there is no damage, no need to perform an output commit, even
when direct scan-out is used.

* Set output damage during direct scan-out

During direct scan-out, pass the damaged region to the wlroots
backend.

* Fix old style function definitions

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>

* Introduce output_match_name_or_id()

Reduces code duplication.

* Use all_output_by_name_or_id() in merge_id_on_name()

No need to iterate over the outputs manually.

* Use output_match_name_or_id() in apply_output_config_to_outputs()

* Use output_match_name_or_id() in workspace functions

* Add format_str() and vformat_str()

Simple helpers to allocate and format a string.

* pango: add printf attribute

This allows the compiler to catch mismatches between the format
string and the arguments passed in.

Need to add -Wno-format-zero-length because we pass an empty string
on purpose in swaybar/render.c.

* commands/floating_minmax_size: fix error strings

cmd_results_new() does not take the command name as argument.

* commands: add printf attribute to cmd_results_new()

And fix the resulting build failures.

* config: add printf attribute to config_add_swaynag_warning()

* swaynag: add printf attribute to swaynag_log()

* common/gesture: use format_str()

We already had a similar function in there.

* Use format_str() throughout

* xdg_shell: Fix crash if popup generates while toplevel is in the scratchpad

* render: pass rendering state together in a struct

This lets us easily add rendering state that we need in the future

* render: Don't pass matrix into render_texture

* render: Use wlr_render_pass

* Don't crash if there is no damage during render

* Add support for touch cancel events

* handle_touch_cancel: fix begin default

I forgot to call seatop_begin_default in
e8f7551.

* swaybar: always subscribe to mode and workspace

always subscribe to mode and workspace events, since we might need them
after bar config updates even if we don't need them initially.

* render: Apply clip to rendered texture correctly

The new wlr_render_pass API provides src_box, dst_box and clip
parameters for texture rendition. Rather than clipping the dst_box,
which control the projection matrix and leads to compression, intersect
the damage and clip box and pass these as a clip parameter.

Fixes: swaywm#7579
Regressed by: swaywm#7552

* render: Clear using wlr_output dimensions

Clear was done using sway_output's logical dimensions, instead of the
wlr_output physical dimensions. This meant that when output scaling was
applied, only a part of the screen would be cleared.

Use the wlr_output dimensions instead.

Regressed by: swaywm#7552

* render: fix titlebar texture clipping

We need to provide an unclipped dst_box.

Fixes: swaywm#7573
Regressed by: swaywm#7552

* seatop_down: Call seatop_begin_default after sending touch events

This is consistent with pointer tablet and button events.

Fixes swaywm#7577.

* Fix layer old damage not being offset by the monitor layout coords

* xwayland: don't rely on event source being data

This pattern is being slowly removed from wlroots.

* chore: chase wlroots map logic unification

* lock: listen to the correct map signal

* xwayland: fix mapped state check in OR handlers

* chase wlroots wlr_renderer_begin_buffer_pass change

https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4159

> ../sway/desktop/output.c:618:47: error: too few arguments to function 'wlr_renderer_begin_buffer_pass'
>   618 |         struct wlr_render_pass *render_pass = wlr_renderer_begin_buffer_pass(
>       |                                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* Add support for wlr-layer-shell ON_DEMAND keyboard interactivity

This allows for layer shell surfaces to receive focus while the surface is explicitly focused, i.e allowing
text fields to receive keyboard input just like a regular surface.

* Handle gamma-control-v1 set_gamma events

References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4046

* desktop/output: use detached output state for page-flips

This avoids relying on the implicit wlr_output.pending state.

* desktop/output: fix damage bitfield in wlr_output_state

* man: add --inhibited and --no-repeat to bindsym and bindcode usage

* Fix `bindsym --to-code` not respecting input configs

Fixes swaywm#7535

* gamma_control_v1: Reset dirty flag

* gamma_control_v1: handle destroyed output

In case a display is unplugged, the sway output may be removed from the
userdata before the gamma_control can be reset. In this case we can't
schedule a commit on the output, simply return within the function.

backtrace full:

  #0  handle_gamma_control_set_gamma (listener=0x4856a8 <server+616>, data=0x7ffce1ed59c0) at ../sway/desktop/output.c:1105
          server = 0x485440 <server>
          event = 0x7ffce1ed59c0
          output = 0x0
  #1  0x00007f430d1dca0c in wl_signal_emit_mutable ()
     from /nix/store/ky1g6ylzr2m4bq8fy0gzrnqmjr6948k5-wayland-1.22.0/lib/libwayland-server.so.0
  No symbol table info available.
  #2  0x00007f430d142370 in gamma_control_destroy (gamma_control=0x29eb9b0) at ../types/wlr_gamma_control_v1.c:37
          manager = 0x27e33e0
          output = 0x2a10770
          event = {output = 0x2a10770, control = 0x0}
  #3  0x00007f430d14239b in gamma_control_handle_output_destroy (listener=<optimized out>, data=<optimized out>)
      at ../types/wlr_gamma_control_v1.c:59
          gamma_control = <optimized out>
  #4  0x00007f430d1dca0c in wl_signal_emit_mutable ()
     from /nix/store/ky1g6ylzr2m4bq8fy0gzrnqmjr6948k5-wayland-1.22.0/lib/libwayland-server.so.0
  No symbol table info available.
  #5  0x00007f430d12a0e0 in wlr_output_destroy (output=output@entry=0x2a10770) at ../types/output/output.c:384
          cursor = <optimized out>
          tmp_cursor = <optimized out>
          layer = <optimized out>
          tmp_layer = <optimized out>
  #6  0x00007f430d114ecf in disconnect_drm_connector (conn=conn@entry=0x2a10770) at ../backend/drm/drm.c:1757
          __PRETTY_FUNCTION__ = "disconnect_drm_connector"
  #7  0x00007f430d117078 in scan_drm_connectors (drm=drm@entry=0x1eebab0, event=event@entry=0x7ffce1ed5c1c) at ../backend/drm/drm.c:1597
          c = <optimized out>
          wlr_conn = 0x2a10770
          drm_conn = 0x2e760d0
          conn_id = <optimized out>
          index = 4
          i = 4
          res = 0x2e761f0
          seen_len = 5
          seen = {true, true, true, true, true, false}
          new_outputs_len = 0
          new_outputs = 0x7ffce1ed5ab0
          conn = <optimized out>
          tmp_conn = <optimized out>
          index = <optimized out>
  #8  0x00007f430d113425 in handle_dev_change (listener=0x1eebbb0, data=0x7ffce1ed5c18) at ../backend/drm/backend.c:157
          drm = 0x1eebab0
          change = 0x7ffce1ed5c18
  #9  0x00007f430d1dca0c in wl_signal_emit_mutable ()
     from /nix/store/ky1g6ylzr2m4bq8fy0gzrnqmjr6948k5-wayland-1.22.0/lib/libwayland-server.so.0
  No symbol table info available.
  #10 0x00007f430d111696 in handle_udev_event (fd=<optimized out>, mask=<optimized out>, data=<optimized out>)
      at ../backend/session/session.c:213
          event = {type = WLR_DEVICE_HOTPLUG, {hotplug = {connector_id = 0, prop_id = 0}}}
          devnum = <optimized out>
          dev = 0x1ed9460
          session = <optimized out>
          udev_dev = 0x2e70db0
          sysname = 0x2e73c60 "card0"
          devnode = <optimized out>
          action = 0x7f430d6677b5 "change"
          seat = <optimized out>
          __PRETTY_FUNCTION__ = "handle_udev_event"
  #11 0x00007f430d1de8e2 in wl_event_loop_dispatch ()
     from /nix/store/ky1g6ylzr2m4bq8fy0gzrnqmjr6948k5-wayland-1.22.0/lib/libwayland-server.so.0
  No symbol table info available.
  #12 0x00007f430d1dc445 in wl_display_run () from /nix/store/ky1g6ylzr2m4bq8fy0gzrnqmjr6948k5-wayland-1.22.0/lib/libwayland-server.so.0
  No symbol table info available.
  #13 0x000000000041daa5 in server_run (server=server@entry=0x485440 <server>) at ../sway/server.c:338
  No locals.
  #14 0x000000000041cf4d in main (argc=<optimized out>, argv=0x7ffce1ed5fe8) at ../sway/main.c:415
          verbose = false
          debug = false
          validate = false
          allow_unsupported_gpu = false
          config_path = 0x0
        c = <optimized out>

where event->output->data is NULL:

  (gdb) p event->output->data
  $5 = (void *) 0x0

* input/libinput: add scroll_button_lock method

Closes swaywm#6987

Co-authored-by: JJGadgets <git@jjgadgets.tech>
Co-authored-by: DeltaWhy <mike5713@gmail.com>

* render: Use wlroots scale filter

* Use wlr_cursor_set_xcursor()

wlr_xcursor_manager_set_cursor_image() is deprecated.

References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4170

* Use wlr_cursor_unset_image()

A bit cleaner.

References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4209

* idle-inhibit-v1: simplify with server global

We only have a single running server, no need to keep track of
multiple server instances. Also no need to support multiple
idle inhibit managers.

* swaybar: remove the argument of StatusNotifierHostRegistered

According to
https://www.freedesktop.org/wiki/Specifications/StatusNotifierItem/StatusNotifierWatcher/
there is no argument for the StatusNotifierHostRegistered signal.

* Use "default" XCursor instead of "left_ptr"

"left_ptr" is the legacy XCursor name. "default" is the cursor
spec name.

* input: Move wlr_pointer_gestures_v1 to sway_input_manager

On multi-seat configurations a zwp_pointer_gestures_v1 global was
created for every seat.

Instead, create the global once in the input manager, to be shared
across all seats.

* swaybar: don't set current workspace as not visible

When `wrap_scroll yes` is configured and there's only one workspace
open, swaybar will mark it as not visible if the user scrolls on it and
eventually incorrectly fail the `active->visible` assert.
Fix this by making sure that new and current workspace aren't the same.

* swaybar: handle wayland-cursor failures

Updating the cursor is not essential, so this change prints
a warning when wl_cursor_theme_load or wl_cursor_theme_get_cursor
fail instead of crashing or exiting.

* Send wl_surface.preferred_buffer_scale

References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3696

* Calculate tiled resize amount relative to parent container

sway should shrinks/grows tiled windows according to parent container
for ppt unit for i3 compatibility.

Resolves: swaywm#7593

* chase wlroots 'presentation-time: add separate helper for zero-copy '

https://gitlab.freedesktop.org/wlroots/wlroots/-/commit/67447d6cb407ac5b6405b4dbae01a38567feb111

* swaynag: handle wayland-cursor failures

Same as 92244c8 ("swaybar: handle wayland-cursor failures")
but for swaynag.

Closes: swaywm#7671

* Deprecate seat idle_wake

Sway has two knobs to control idling:

- seat idle_inhibit: when the seat is active (ie. not idle), this
  extends the active state. When the seat is idle, this is
  ignored.
- seat idle_wake: when the seat is idle, this wakes up the seat.
  When the seat is active, this is ignored.

The motivation for the deprecation is two-fold:

- The concept of "seat idle state" is ill-defined. Each idle-notify-v1
  client will pass a different idle timeout. With the old logic, a
  seat was declared idle if and only if all idle-notify-v1 timeouts have
  expired. However, if only a portion of the timeouts have expired,
  then some clients would wake up, and the rest would stay active.
  This is inconsistent with the definition of idle_inhibit/idle_wake:
  idle_inhibit was used for clients which are waking up.
- It never worked properly with the new idle-notify-v1 protocol
  and no-one noticed. Only the legacy KDE idle protocol is taken
  into account, but that protocol is not used anymore.

* Add Georgian README

I am a native Georgian speaker.

I have translated sway's README.md

* fix crash when resizing tiled scratchpad windows

Splitting and then hiding a scratchpad container results in
a segfault.

fixes swaywm#6693

* Add support for cursor-shape-v1

References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4106

* swaybar: Implement wp_cursor_shape_v1

* swaynag: Implement wp_cursor_shape_v1

* desktop/output: drop logic to handle backend-applied mode

The wlroots backends no longer magically apply output modes behind
the compositor's back.

* desktop/output: drop handle_mode()

We already perform the exact same logic on transform/scale change.

* desktop/output: fix output manager enabled state

With recent wlroots changes, backends which don't support output
modes can now support being disabled.

We were always marking mode-less outputs as disabled. Stop doing
that, check whether the output takes up some space in the layout
instead.

* output: drop current_mode

This is now unused.

* Rebase all cursors in handle_surface_map

Fix swaylock showing transient cursor after locked.

* Move contrib/ to separate repository

User-contributed scripts are being moved over to this repository:
https://github.com/OctopusET/sway-contrib

* chase wlroots!4316

References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4316

* chore: chase wlroots xdg-surface role rework

* Fix typo

* Hide xwayland_shell_v1 from regular clients

Regular clients are not allowed to use this interface. wlroots
already sends a protocol error if a non-Xwayland client tries to
use this interface, but let's remove all temptation by hiding it
completely.

* view: update wlr_toplevel size on client resizes

If a floating client resizes itself, sway updates several of its
internal dimensions to match but not wlr_toplevel. This means that the
next time wlroots sends a toplevel configure event, it can have wrong
coordinates that resize the client back to its old size. To fix this,
let's just use wlr_xdg_toplevel_set_size so the wlr_toplevel has the
same dimensions as sway. Fixes swaywm#5266.

* Revert "view: update wlr_toplevel size on client resizes"

This isn't the right fix for this issue because the xwayland code also
uses this function and updating the wlr_toplevel there doesn't make
sense and also causes problems. Fixes swaywm#7722.

This reverts commit bf44690.

* xdg_shell: update wlr_toplevel size on client resizes

If a floating client resizes itself, sway updates several of its
internal dimensions to match but not wlr_toplevel. This means that the
next time wlroots sends a toplevel configure event, it can have wrong
coordinates that resize the client back to its old size. To fix this,
let's just use wlr_xdg_toplevel_set_size so the wlr_toplevel has the
same dimensions as sway.

Exactly the same as 0183b9d but the
logic is onlly applied to xdg_shell and not xwayland.

* Added support for 'set_from_resource' command

* Made fallback value for set_from_resource optional

* Replaced reference of 'resdb' with 'trawldb'

* Renamed sway to sway-regolith

* Add and adapt debian packaging from https://salsa.debian.org/swaywm-team/sway

* Package rename in changelog

* Remove applied patch

* Add libtrawldb dependency

---------

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Co-authored-by: Ankit Pandey <anpandey@protonmail.com>
Co-authored-by: Erik Reider <35975961+ErikReider@users.noreply.github.com>
Co-authored-by: Simon Ser <contact@emersion.fr>
Co-authored-by: Ronan Pigott <ronan@rjp.ie>
Co-authored-by: Alexander Orzechowski <orzechowski.alexander@gmail.com>
Co-authored-by: Elyes Haouas <ehaouas@noos.fr>
Co-authored-by: Alexander Orzechowski <alex@ozal.ski>
Co-authored-by: hrdl <31923882+hrdl-github@users.noreply.github.com>
Co-authored-by: Mukundan314 <30190448+Mukundan314@users.noreply.github.com>
Co-authored-by: Kenny Levinsen <kl@kl.wtf>
Co-authored-by: Kirill Primak <vyivel@eclair.cafe>
Co-authored-by: Artturin <Artturin@artturin.com>
Co-authored-by: Shaked Flur <fshaked@gmail.com>
Co-authored-by: 33KK <marko@pepega.club>
Co-authored-by: Rouven Czerwinski <rouven@czerwinskis.de>
Co-authored-by: Cezary Drożak <cezary@drozak.net>
Co-authored-by: JJGadgets <git@jjgadgets.tech>
Co-authored-by: DeltaWhy <mike5713@gmail.com>
Co-authored-by: Hodong <111117126+hodong-kim@users.noreply.github.com>
Co-authored-by: Mark Bolhuis <mark@bolhuis.dev>
Co-authored-by: llyyr <llyyr.public@gmail.com>
Co-authored-by: Manuel Stoeckl <code@mstoeckl.com>
Co-authored-by: nukoseer <uygarkoseer@gmail.com>
Co-authored-by: Nick Kipshidze <96648005+NickKipshidze@users.noreply.github.com>
Co-authored-by: bretello <bretello@distruzione.org>
Co-authored-by: ookami <mail@ookami.one>
Co-authored-by: Leonardo Hernández Hernández <leohdz172@proton.me>
Co-authored-by: luzpaz <luzpaz@users.noreply.github.com>
Co-authored-by: Dudemanguy <random342@airmail.cc>
Co-authored-by: Soumya Ranjan Patnaik <soumyaranjan1812@gmail.com>
Co-authored-by: Regolith Linux <regolith.linux@gmail.com>
  • Loading branch information
1 parent 00807e2 commit 504f33a
Show file tree
Hide file tree
Showing 97 changed files with 1,332 additions and 1,414 deletions.
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ronan Pigott <ronan@rjp.ie> <rpigott@berkeley.edu>
67 changes: 67 additions & 0 deletions README.ge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# sway

sway არის [i3]-თავსებადი [Wayland]-ის კომპოზიტორი. მეტი ინფორმაციისთვის იხილეთ
[FAQ]. დაუკავშირდით [IRC არხს][IRC channel] \(#sway irc.libera.chat-ზე).

## გამოშვების ხელმოწერები

გამოშვებები ხელმოწერილია [E88F5E48]-ით და გამოქვეყნებულია [GitHub-ზე][GitHub releases].

## ინსტალაცია

### რეპოზიტორიიდან

Sway არის ხელმისაწვდომი ბევრი დისტრიბუტაციისთვის. ცადეთ "sway" პაკეტის ინსტალაცია თქვენთვის.

### კოდის კომპილაცია

იხილეთ [ეს ვიკი გვერდი][Development setup] თუ გინდათ რომ ააწყოთ sway და wlroots სატესტოდ ან დეველოპმენტისთვის.

დააინსტალირეთ დამოკიდებულებები:

* meson \*
* [wlroots]
* wayland
* wayland-protocols \*
* pcre2
* json-c
* pango
* cairo
* gdk-pixbuf2 (ასევე არჩევითია: system tray)
* [scdoc] (ასევე არჩევითია: man pages) \*
* git (ასევე არჩევითია: version info) \*

_\* Compile-time dep_

გაუშვით ეს ბრძანებები:

meson build/
ninja -C build/
sudo ninja -C build/ install

სისტემებზე logind და seatd-ის გარეშე, გჭირდება suid გაუშვა sway binary-ზე:

sudo chmod a+s /usr/local/bin/sway

Sway შეწყვეტს root ნებართვებს მალევე ჩართვის შემდეგ.

## კონფიგურაცია

თუ უკვე იყენებთ i3-ს, მაშინ დააკოპირე i3 კონფიგურაცია და ჩასვი `~/.config/sway/config`
და უპრობლემოდ იმუშავებს პირდაპირ. წინააღმდეგ შემთხვევაში კონფიგურაციის ნიმუში ჩააკოპირეთ აქ: `~/.config/sway/config`. კომპიგურაციის ნიმუში ხშირ შემთხვევაში არის `/etc/sway/config`.
გაუშვი `man 5 sway` კონპიგურაციაზე ინფორმაციის მისაღებად.

## გაშვება

გაუშვი `sway` TTY-ისთვის. ზოგიერთმა ლოგინ მენეჯერმა შეიძლება იმუშავოს, მაგრამ არ
არის მხარდაჭერილი sway-სგან (როგორც წესი კარგად მუშაობს gdm).

[i3]: https://i3wm.org/
[Wayland]: http://wayland.freedesktop.org/
[FAQ]: https://github.com/swaywm/sway/wiki
[IRC channel]: https://web.libera.chat/gamja/?channels=#sway
[E88F5E48]: https://keys.openpgp.org/search?q=34FF9526CFEF0E97A340E2E40FDE7BE0E88F5E48
[GitHub releases]: https://github.com/swaywm/sway/releases
[Development setup]: https://github.com/swaywm/sway/wiki/Development-Setup
[wlroots]: https://gitlab.freedesktop.org/wlroots/wlroots
[scdoc]: https://git.sr.ht/~sircmpwn/scdoc
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# sway

**[English][en]** - [Česky][cs] - [Deutsch][de] - [Dansk][dk] - [Español][es] - [Français][fr] - [Ελληνικά][gr] - [हिन्दी][hi] - [Magyar][hu] - [فارسی][ir] - [Italiano][it] - [日本語][ja] - [한국어][ko] - [Nederlands][nl] - [Norsk][no] - [Polski][pl] - [Português][pt] - [Română][ro] - [Русский][ru] - [Svenska][sv] - [Türkçe][tr] - [Українська][uk] - [中文-简体][zh-CN] - [中文-繁體][zh-TW]
**[English][en]** - [Česky][cs] - [Deutsch][de] - [Dansk][dk] - [Español][es] - [Français][fr] - [ქართული][ge] - [Ελληνικά][gr] - [हिन्दी][hi] - [Magyar][hu] - [فارسی][ir] - [Italiano][it] - [日本語][ja] - [한국어][ko] - [Nederlands][nl] - [Norsk][no] - [Polski][pl] - [Português][pt] - [Română][ro] - [Русский][ru] - [Svenska][sv] - [Türkçe][tr] - [Українська][uk] - [中文-简体][zh-CN] - [中文-繁體][zh-TW]

sway is an [i3]-compatible [Wayland] compositor. Read the [FAQ]. Join the
[IRC channel] \(#sway on irc.libera.chat).
Expand Down Expand Up @@ -67,6 +67,7 @@ sway (gdm is known to work fairly well).
[dk]: README.dk.md
[es]: README.es.md
[fr]: README.fr.md
[ge]: README.ge.md
[gr]: README.gr.md
[hi]: README.hi.md
[hu]: README.hu.md
Expand Down
31 changes: 7 additions & 24 deletions common/gesture.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,6 @@

const uint8_t GESTURE_FINGERS_ANY = 0;

// Helper to easily allocate and format string
static char *strformat(const char *format, ...) {
va_list args;
va_start(args, format);
int length = vsnprintf(NULL, 0, format, args) + 1;
va_end(args);

char *result = malloc(length);
if (result) {
va_start(args, format);
vsnprintf(result, length, format, args);
va_end(args);
}

return result;
}

char *gesture_parse(const char *input, struct gesture *output) {
// Clear output in case of failure
output->type = GESTURE_TYPE_NONE;
Expand All @@ -38,7 +21,7 @@ char *gesture_parse(const char *input, struct gesture *output) {
// Split input type, fingers and directions
list_t *split = split_string(input, ":");
if (split->length < 1 || split->length > 3) {
return strformat(
return format_str(
"expected <gesture>[:<fingers>][:direction], got %s",
input);
}
Expand All @@ -51,8 +34,8 @@ char *gesture_parse(const char *input, struct gesture *output) {
} else if (strcmp(split->items[0], "swipe") == 0) {
output->type = GESTURE_TYPE_SWIPE;
} else {
return strformat("expected hold|pinch|swipe, got %s",
split->items[0]);
return format_str("expected hold|pinch|swipe, got %s",
(const char *)split->items[0]);
}

// Parse optional arguments
Expand All @@ -67,7 +50,7 @@ char *gesture_parse(const char *input, struct gesture *output) {
next = split->length == 3 ? split->items[2] : NULL;
} else if (split->length == 3) {
// Fail here if argument can only be finger count
return strformat("expected 1-9, got %s", next);
return format_str("expected 1-9, got %s", next);
}

// If there is an argument left, try to parse as direction
Expand Down Expand Up @@ -95,7 +78,7 @@ char *gesture_parse(const char *input, struct gesture *output) {
} else if (strcmp(item, "counterclockwise") == 0) {
output->directions |= GESTURE_DIRECTION_COUNTERCLOCKWISE;
} else {
return strformat("expected direction, got %s", item);
return format_str("expected direction, got %s", item);
}
}
list_free_items_and_destroy(directions);
Expand Down Expand Up @@ -163,7 +146,7 @@ static char *gesture_directions_to_string(uint32_t directions) {
if (!result) {
result = strdup(name);
} else {
char *new = strformat("%s+%s", result, name);
char *new = format_str("%s+%s", result, name);
free(result);
result = new;
}
Expand All @@ -179,7 +162,7 @@ static char *gesture_directions_to_string(uint32_t directions) {

char *gesture_to_string(struct gesture *gesture) {
char *directions = gesture_directions_to_string(gesture->directions);
char *result = strformat("%s:%u:%s",
char *result = format_str("%s:%u:%s",
gesture_type_string(gesture->type),
gesture->fingers, directions);
free(directions);
Expand Down
20 changes: 4 additions & 16 deletions common/pango.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,11 @@ void get_text_size(cairo_t *cairo, const PangoFontDescription *desc, int *width,
int *baseline, double scale, bool markup, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
// Add one since vsnprintf excludes null terminator.
int length = vsnprintf(NULL, 0, fmt, args) + 1;
char *buf = vformat_str(fmt, args);
va_end(args);

char *buf = malloc(length);
if (buf == NULL) {
sway_log(SWAY_ERROR, "Failed to allocate memory");
return;
}
va_start(args, fmt);
vsnprintf(buf, length, fmt, args);
va_end(args);

PangoLayout *layout = get_pango_layout(cairo, desc, buf, scale, markup);
pango_cairo_update_layout(cairo, layout);
Expand All @@ -104,6 +97,7 @@ void get_text_size(cairo_t *cairo, const PangoFontDescription *desc, int *width,
*baseline = pango_layout_get_baseline(layout) / PANGO_SCALE;
}
g_object_unref(layout);

free(buf);
}

Expand All @@ -125,18 +119,11 @@ void render_text(cairo_t *cairo, const PangoFontDescription *desc,
double scale, bool markup, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
// Add one since vsnprintf excludes null terminator.
int length = vsnprintf(NULL, 0, fmt, args) + 1;
char *buf = vformat_str(fmt, args);
va_end(args);

char *buf = malloc(length);
if (buf == NULL) {
sway_log(SWAY_ERROR, "Failed to allocate memory");
return;
}
va_start(args, fmt);
vsnprintf(buf, length, fmt, args);
va_end(args);

PangoLayout *layout = get_pango_layout(cairo, desc, buf, scale, markup);
cairo_font_options_t *fo = cairo_font_options_create();
Expand All @@ -146,5 +133,6 @@ void render_text(cairo_t *cairo, const PangoFontDescription *desc,
pango_cairo_update_layout(cairo, layout);
pango_cairo_show_layout(cairo, layout);
g_object_unref(layout);

free(buf);
}
33 changes: 33 additions & 0 deletions common/stringop.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#define _POSIX_C_SOURCE 200809L
#include <ctype.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -328,3 +329,35 @@ bool expand_path(char **path) {
wordfree(&p);
return true;
}

char *vformat_str(const char *fmt, va_list args) {
char *str = NULL;
va_list args_copy;
va_copy(args_copy, args);

int len = vsnprintf(NULL, 0, fmt, args);
if (len < 0) {
sway_log_errno(SWAY_ERROR, "vsnprintf(\"%s\") failed", fmt);
goto out;
}

str = malloc(len + 1);
if (str == NULL) {
sway_log_errno(SWAY_ERROR, "malloc() failed");
goto out;
}

vsnprintf(str, len + 1, fmt, args_copy);

out:
va_end(args_copy);
return str;
}

char *format_str(const char *fmt, ...) {
va_list args;
va_start(args, fmt);
char *str = vformat_str(fmt, args);
va_end(args);
return str;
}
124 changes: 0 additions & 124 deletions contrib/autoname-workspaces.py

This file was deleted.

Loading

0 comments on commit 504f33a

Please sign in to comment.