From 06d22a8deac2acc465b9eb7264db3729d49f6edd Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Sun, 20 Mar 2022 21:08:14 +0000 Subject: [PATCH 1/4] Remove redundant function render_frames() --- include/swaylock.h | 1 - render.c | 7 ------- 2 files changed, 8 deletions(-) diff --git a/include/swaylock.h b/include/swaylock.h index b6daffcb..da6e3e90 100644 --- a/include/swaylock.h +++ b/include/swaylock.h @@ -126,7 +126,6 @@ void swaylock_handle_key(struct swaylock_state *state, xkb_keysym_t keysym, uint32_t codepoint); void render_frame_background(struct swaylock_surface *surface); void render_frame(struct swaylock_surface *surface); -void render_frames(struct swaylock_state *state); void damage_surface(struct swaylock_surface *surface); void damage_state(struct swaylock_state *state); void clear_password_buffer(struct swaylock_password *pw); diff --git a/render.c b/render.c index 3dec7436..6f6f99ae 100644 --- a/render.c +++ b/render.c @@ -331,10 +331,3 @@ void render_frame(struct swaylock_surface *surface) { wl_surface_commit(surface->surface); } - -void render_frames(struct swaylock_state *state) { - struct swaylock_surface *surface; - wl_list_for_each(surface, &state->surfaces, link) { - render_frame(surface); - } -} From 11030b73509f698973f81c0cd7b8d6c83598d867 Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Sun, 20 Mar 2022 20:59:17 +0000 Subject: [PATCH 2/4] Delete whole utf8 character on backspace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ...rather than just the last byte of the password buffer. Demostrate the need for this by taking the following steps: - Apply the patch below (before this commit). - Set keyboard layout to one where utf8 characters longer than one byte can be obtained, for example åäö using Swedish layout (XKB_DEFAULT_LAYOUT=se). - Type "åäö" then press backspace and observe that it takes two backspaces to delete each character fully, and therefore six backspaces to fully clear the password buffer. diff --git a/password.c b/password.c index e1a1d9a..b640cd3 100644 --- a/password.c +++ b/password.c @@ -29,6 +29,7 @@ void clear_password_buffer(struct swaylock_password *pw) { static bool backspace(struct swaylock_password *pw) { if (pw->len != 0) { pw->buffer[--pw->len] = 0; + fprintf(stderr, "%s\n", pw->buffer); return true; } return false; --- include/unicode.h | 8 ++++++++ password.c | 3 ++- unicode.c | 13 +++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/include/unicode.h b/include/unicode.h index e2ee9588..56a48f1b 100644 --- a/include/unicode.h +++ b/include/unicode.h @@ -9,6 +9,14 @@ #define UTF8_INVALID 0x80 +/** + * Gets the size in bytes of the last utf8 character in a NULL terminated string + * This function does not validate that the buffer contains correct utf8 data; + * it merely looks for the first byte that correctly denotes the beginning of a + * utf8 character. + */ +int utf8_last_size(const char *str); + /** * Grabs the next UTF-8 character and advances the string pointer */ diff --git a/password.c b/password.c index e1a1d9a2..6880ccb5 100644 --- a/password.c +++ b/password.c @@ -28,7 +28,8 @@ void clear_password_buffer(struct swaylock_password *pw) { static bool backspace(struct swaylock_password *pw) { if (pw->len != 0) { - pw->buffer[--pw->len] = 0; + pw->len -= utf8_last_size(pw->buffer); + pw->buffer[pw->len] = 0; return true; } return false; diff --git a/unicode.c b/unicode.c index 3d81a348..6d115a93 100644 --- a/unicode.c +++ b/unicode.c @@ -1,7 +1,20 @@ #include #include +#include #include "unicode.h" +int utf8_last_size(const char *str) { + int len = 0; + char *pos = strchr(str, '\0'); + while (pos > str) { + --pos; ++len; + if ((*pos & 0xc0) != 0x80) { + return len; + } + } + return 0; +} + size_t utf8_chsize(uint32_t ch) { if (ch < 0x80) { return 1; From 55394afe8f971d297b9fe907509b2a03375b0743 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=C4=9Fuz=20Ersen?= Date: Sun, 27 Mar 2022 08:58:46 +0000 Subject: [PATCH 3/4] bash-completion: localize variables --- completions/bash/swaylock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completions/bash/swaylock b/completions/bash/swaylock index 713fb4c0..4985922a 100644 --- a/completions/bash/swaylock +++ b/completions/bash/swaylock @@ -2,7 +2,7 @@ _swaylock() { - local cur prev + local cur prev short long scaling _get_comp_words_by_ref -n : cur prev short=( From fad5bc2f615bcee37b653887af0aebb334ec94b5 Mon Sep 17 00:00:00 2001 From: Rick van Schijndel Date: Mon, 25 Apr 2022 21:28:34 +0200 Subject: [PATCH 4/4] wayland-scanner: use native version to support cross-compilation Cross-compilation support was broken in https://github.com/swaywm/swaylock/commit/55c018a350d52efe7d0db168d15636b900dd9ce4 because wayland-scanner from the host system is used with that change. This patch changes it back to use wayland-scanner from the build system. For normal (non-cross) compilation this shouldn't change anything. Meson also uses the build machine wayland-scanner binary: - https://github.com/mesonbuild/meson/blob/c649a2b8c59c9f49affca9bd89c126bfa0f54449/mesonbuild/modules/unstable_wayland.py#L48-L53 --- meson.build | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index ff120c8e..b2e79441 100644 --- a/meson.build +++ b/meson.build @@ -38,7 +38,9 @@ endif wayland_client = dependency('wayland-client', version: '>=1.20.0') wayland_protos = dependency('wayland-protocols', version: '>=1.25', fallback: 'wayland-protocols') -wayland_scanner = dependency('wayland-scanner', version: '>=1.15.0') +# use native version of wayland-scanner when cross-compiling +# meson does this too: https://github.com/mesonbuild/meson/blob/c649a2b8c59c9f49affca9bd89c126bfa0f54449/mesonbuild/modules/unstable_wayland.py#L48-L53 +wayland_scanner = dependency('wayland-scanner', version: '>=1.15.0', native: true) xkbcommon = dependency('xkbcommon') cairo = dependency('cairo') gdk_pixbuf = dependency('gdk-pixbuf-2.0', required: get_option('gdk-pixbuf'))