aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-01-13 21:29:12 -0500
committerDrew DeVault <sir@cmpwn.com>2019-01-13 21:40:26 -0500
commit3fca8b8d22ee51a934fa3b8704c5aee8a5de7689 (patch)
treeabdec67233e7453274f6561c4a207a6d7d6c6d39
parent4879d40695047a4c493bd8871d810c543978a869 (diff)
Split swaylock into separate project
-rw-r--r--README.bg.md9
-rw-r--r--README.de.md5
-rw-r--r--README.el.md5
-rw-r--r--README.fr.md5
-rw-r--r--README.it.md5
-rw-r--r--README.ja.md3
-rw-r--r--README.md3
-rw-r--r--README.pt.md5
-rw-r--r--README.ru.md9
-rw-r--r--README.uk.md5
-rw-r--r--completions/bash/swaylock66
-rw-r--r--completions/fish/swaylock.fish39
-rw-r--r--completions/zsh/_swaylock40
-rw-r--r--meson.build5
-rw-r--r--swaylock/main.c1057
-rw-r--r--swaylock/meson.build55
-rw-r--r--swaylock/pam.c62
-rw-r--r--swaylock/pam/swaylock.freebsd6
-rw-r--r--swaylock/pam/swaylock.linux6
-rw-r--r--swaylock/password.c190
-rw-r--r--swaylock/render.c189
-rw-r--r--swaylock/seat.c178
-rw-r--r--swaylock/shadow.c155
-rw-r--r--swaylock/swaylock.1.scd167
24 files changed, 14 insertions, 2255 deletions
diff --git a/README.bg.md b/README.bg.md
index 87a15bed..dcdefc7e 100644
--- a/README.bg.md
+++ b/README.bg.md
@@ -45,16 +45,13 @@ Sway съществува в репотата (хранилищата) на мн
* pango
* cairo
* gdk-pixbuf2 *
-* pam **
-* dbus >= 1.10 ***
+* dbus >= 1.10 **
* [scdoc](https://git.sr.ht/~sircmpwn/scdoc) (Нужен за man страници)
* git
-_\*Нужен само за swaybar, swaybg и swaylock_
+_\*Нужен само за swaybar, swaybg_
-_\*\*Нужен само за swaylock_
-
-_\*\*\*Нужен само за tray_
+_\*\*Нужен само за tray_
Изпълнете следните команди:
diff --git a/README.de.md b/README.de.md
index bf92b196..e8198013 100644
--- a/README.de.md
+++ b/README.de.md
@@ -56,13 +56,10 @@ Abhängigkeiten:
* pango
* cairo
* gdk-pixbuf2 *
-* pam **
* [scdoc](https://git.sr.ht/~sircmpwn/scdoc) (erforderlich für man pages)
* git
-_\*Nur erforderlich für swaybar, swaybg, und swaylock_
-
-_\*\*Nur erforderlich für swaylock_
+_\*Nur erforderlich für swaybar, swaybg_
Führe diese Befehle aus:
diff --git a/README.el.md b/README.el.md
index 79acd422..bc2360ca 100644
--- a/README.el.md
+++ b/README.el.md
@@ -48,13 +48,10 @@ To username μου στο Freenode είναι kon14 και θα με βρείτ
* pango
* cairo
* gdk-pixbuf2 *
-* pam **
* [scdoc](https://git.sr.ht/~sircmpwn/scdoc) (required for man pages)
* git
-_\*Απαιτείται μόνο για swaybar, swaybg, and swaylock_
-
-_\*\*Απαιτείται μόνο για swaylock_
+_\*Απαιτείται μόνο για swaybar, swaybg_
Εκτελέστε αυτές τις εντολές:
diff --git a/README.fr.md b/README.fr.md
index 8ad4d3b6..ad627ba5 100644
--- a/README.fr.md
+++ b/README.fr.md
@@ -50,13 +50,10 @@ Installez les dépendances :
* pango
* cairo
* gdk-pixbuf2 *
-* pam **
* [scdoc](https://git.sr.ht/~sircmpwn/scdoc) (requis pour les pages man)
* git
-_\*Uniquement requis pour swaybar, swaybg, and swaylock_
-
-_\*\*Uniquement requis pour swaylock_
+_\*Uniquement requis pour swaybar, swaybg_
Exécutez ces commandes :
diff --git a/README.it.md b/README.it.md
index 8a83bc78..bfe09920 100644
--- a/README.it.md
+++ b/README.it.md
@@ -50,13 +50,10 @@ Installa queste dipendenze:
* pango
* cairo
* gdk-pixbuf2 *
-* pam **
* [scdoc](https://git.sr.ht/~sircmpwn/scdoc) (rrichiesto per man pages)
* git
-_\*Richiesto solo per swaybar, swaybg, e swaylock_
-
-_\*\*Richiesto solo per swaylock_
+_\*Richiesto solo per swaybar, swaybg_
Esegui questi comandi:
diff --git a/README.ja.md b/README.ja.md
index d82e78b2..a4e4a6ee 100644
--- a/README.ja.md
+++ b/README.ja.md
@@ -37,13 +37,12 @@ Swayは沢山のディストリビューションで提供されています。"
* pango
* cairo
* gdk-pixbuf2 \*\*
-* pam (オプション: swaylockとPAMで必要)
* [scdoc](https://git.sr.ht/~sircmpwn/scdoc) (manで必要です) \*
* git \*
_\*コンパイルの時_
-_\*\*オプション: swaybgとswaylockでのみ必要です_
+_\*\*オプション: swaybgでのみ必要です_
次のコマンドを実行してください:
diff --git a/README.md b/README.md
index 1deb9a4c..8d2e2444 100644
--- a/README.md
+++ b/README.md
@@ -41,13 +41,12 @@ Install dependencies:
* pango
* cairo
* gdk-pixbuf2 \*\*
-* pam (optional: PAM support for swaylock)
* [scdoc](https://git.sr.ht/~sircmpwn/scdoc) (optional: man pages) \*
* git \*
_\*Compile-time dep_
-_\*\*optional: required for swaybg and swaylock_
+_\*\*optional: required for swaybg_
Run these commands:
diff --git a/README.pt.md b/README.pt.md
index 8cdfa548..0f2a3cd4 100644
--- a/README.pt.md
+++ b/README.pt.md
@@ -57,13 +57,10 @@ Antes de iniciar a compilação, instale as dependências:
* pango
* cairo
* gdk-pixbuf2 *
-* pam **
* [scdoc](https://git.sr.ht/~sircmpwn/scdoc) (man pages)
* git
-_\*Dependência apenas de swaybar, swaybg, e swaylock_
-
-_\*\*Dependência apenas de swaylock_
+_\*Dependência apenas de swaybar, swaybg_
Para compilar, execute estes comandos:
diff --git a/README.ru.md b/README.ru.md
index 255e36aa..c66976e5 100644
--- a/README.ru.md
+++ b/README.ru.md
@@ -50,16 +50,13 @@ Sway доступен во многих дистрибутивах и наход
* pango
* cairo
* gdk-pixbuf2 *
-* pam **
-* dbus >= 1.10 ***
+* dbus >= 1.10 **
* [scdoc](https://git.sr.ht/~sircmpwn/scdoc) (required for man pages)
* git
-_\*Требуется только для swaybar, swaybg и swaylock_
+_\*Требуется только для swaybar, swaybg_
-_\*\*Требуется только для swaylock_
-
-_\*\*\*Требуется только для tray_
+_\*\*Требуется только для tray_
Выполните следующие команды:
diff --git a/README.uk.md b/README.uk.md
index 5e9345b3..4c378a89 100644
--- a/README.uk.md
+++ b/README.uk.md
@@ -57,13 +57,10 @@ Sway доступний у багатьох дистрибутивах Linux (а
* pango
* cairo
* gdk-pixbuf2 *
-* pam **
* [scdoc](https://git.sr.ht/~sircmpwn/scdoc) (required for man pages)
* git
-_\*Лише для swaybar, swaybg та swaylock_
-
-_\*\*Лише для swaylock_
+_\*Лише для swaybar, swaybg_
Виконайте ці команди:
diff --git a/completions/bash/swaylock b/completions/bash/swaylock
deleted file mode 100644
index 33925480..00000000
--- a/completions/bash/swaylock
+++ /dev/null
@@ -1,66 +0,0 @@
-# swaylock(1) completion
-
-_swaylock()
-{
- local cur prev
- _get_comp_words_by_ref -n : cur prev
-
- short=(
- -h
- -c
- -s
- -t
- -v
- -i
- -u
- -f
- )
-
- long=(
- --help
- --color
- --scaling
- --tiling
- --version
- --image
- --no-unlock-indicator
- --daemonize
- )
-
- scaling=(
- 'stretch'
- 'fill'
- 'fit'
- 'center'
- 'tile'
- )
-
- case $prev in
- -c|--color)
- return
- ;;
- --scaling)
- COMPREPLY=($(compgen -W "${scaling[*]}" -- "$cur"))
- return
- ;;
- -i|--image)
- if grep -q : <<< "$cur"; then
- output="${cur%%:*}:"
- cur="${cur#*:}"
- else
- output=
- fi
- COMPREPLY=($(compgen -f -- "$cur"))
- return
- ;;
- esac
-
- if [[ $cur == --* ]]; then
- COMPREPLY=($(compgen -W "${long[*]}" -- "$cur"))
- else
- COMPREPLY=($(compgen -W "${short[*]}" -- "$cur"))
- COMPREPLY+=($(compgen -W "${long[*]}" -- "$cur"))
- fi
-
-} &&
-complete -F _swaylock swaylock
diff --git a/completions/fish/swaylock.fish b/completions/fish/swaylock.fish
deleted file mode 100644
index 99dff48f..00000000
--- a/completions/fish/swaylock.fish
+++ /dev/null
@@ -1,39 +0,0 @@
-# swaylock(1) completion
-
-complete -c swaylock -s C -l config --description 'The config file to use. Default: $HOME/.swaylock/config, $XDG_CONFIG_HOME/swaylock/config, and SYSCONFDIR/swaylock/config.'
-complete -c swaylock -s h -l help --description "Show help message and quit."
-complete -c swaylock -s f -l daemonize --description "Fork into the background after spawning. Note: this is the default bahavior of i3lock."
-complete -c swaylock -s v -l version --description "Show the version number and quit."
-complete -c swaylock -s s -l socket --description "Use the specified socket path. Otherwise, swaymsg will as sway where the socket is (which is the value of $SWAYSOCK, then of $I350CK)."
-complete -c swaylock -s e -l ignore-empty-password --description 'When an empty password is provided by the user, do not validate it.'
-
-# Appearance
-complete -c swaylock -s u -l no-unlock-indicator --description "Disable the unlock indicator."
-complete -c swaylock -s i -l image --description "Display the given image, optionally on the given output. Use -c to set a background color."
-complete -c swaylock -s s -l scaling --description "Scaling mode for images: stretch, fill, fit, center, or tile."
-complete -c swaylock -s t -l tiling --description "Same as --scaling=tile."
-complete -c swaylock -s c -l color --description "Turn the screen into the given color. If -i is used, this sets the background of the image into the given color. Defaults to white (ffffff), or transparent (00000000) if an image is in use."
-complete -c swaylock -l bs-hl-color --description 'Sets the color of backspace highlight segments.'
-complete -c swaylock -l font --description 'Sets the font of the text inside the indicator.'
-complete -c swaylock -l indicator-radius --description 'Sets the radius of the indicator to radius pixels. Default: 50'
-complete -c swaylock -l indicator-thickness --description 'Sets the thickness of the indicator to thickness pixels. Default: 10'
-complete -c swaylock -l inside-color --description 'Sets the color of the inside of the indicator when typing or idle.'
-complete -c swaylock -l inside-clear-color --description 'Sets the color of the inside of the indicator when cleared.'
-complete -c swaylock -l inside-ver-color --description 'Sets the color of the inside of the indicator when verifying.'
-complete -c swaylock -l inside-wrong-color --description 'Sets the color of the inside of the indicator when invalid.'
-complete -c swaylock -l key-hl-color --description 'Sets the color of key press highlight segments.'
-complete -c swaylock -l line-color --description 'Sets the color of the lines that separate the inside and outside of the indicator when typing or idle.'
-complete -c swaylock -l line-clear-color --description 'Sets the color of the lines that separate the inside and outside of the indicator when cleared.'
-complete -c swaylock -l line-ver-color --description 'Sets the color of the lines that separate the inside and outside of the indicator when verifying.'
-complete -c swaylock -l line-wrong-color --description 'Sets the color of the lines that separate the inside and outside of the indicator when invalid.'
-complete -c swaylock -s n -l line-uses-inside --description 'Use the color of the inside of the indicator for the line separating the inside and outside of the indicator.'
-complete -c swaylock -s r -l line-uses-ring --description 'Use the outer ring\'s color for the line separating the inside and outside of the indicator.'
-complete -c swaylock -l ring-color --description 'Sets the color of the outside of the indicator when typing or idle.'
-complete -c swaylock -l ring-clear-color --description 'Sets the color of the outside of the indicator when cleared.'
-complete -c swaylock -l ring-ver-color --description 'Sets the color of the outside of the indicator when verifying.'
-complete -c swaylock -l ring-wrong-color --description 'Sets the color of the outside of the indicator when invalid.'
-complete -c swaylock -l separator-color --description 'Sets the color of the lines that separate highlight segments.'
-complete -c swaylock -l text-color --description 'Sets the color of the text inside the indicator when typing or idle.'
-complete -c swaylock -l text-clear-color --description 'Sets the color of the text inside the indicator when cleared.'
-complete -c swaylock -l text-ver-color --description 'Sets the color of the text inside the indicator when verifying.'
-complete -c swaylock -l text-wrong-color --description 'Sets the color of the text inside the indicator when invalid.'
diff --git a/completions/zsh/_swaylock b/completions/zsh/_swaylock
deleted file mode 100644
index 9bc84ec9..00000000
--- a/completions/zsh/_swaylock
+++ /dev/null
@@ -1,40 +0,0 @@
-#compdef swaylock
-#
-# Completion script for swaylock
-#
-
-_arguments -s \
- '(-C --config)'{-C,--config}'[Path to the config file]:filename:_files' \
- '(-c --color)'{-c,--color}'[Turn the screen into the given color instead of white]:color:' \
- '(-e --ignore-empty-password)'{-e,--ignore-empty-password}'[When an empty password is provided, do not validate it]' \
- '(-f --daemonize)'{-f,--daemonize}'[Detach from the controlling terminal after locking]' \
- '(-h --help)'{-h,--help}'[Show help message and quit]' \
- '(-i --image)'{-i,--image}'[Display an image]:filename:_files' \
- '(-s --scaling)'{-s,--scaling}'[Scaling mode]:mode:(stretch fill fit center tile)' \
- '(-t --tiling)'{-t,--tiling}'[Same as --scaling=tile]' \
- '(-u --no-unlock-indicator)'{-u,--no-unlock-indicator}'[Disable the unlock indicator]' \
- '(-v --version)'{-v,--version}'[Show the version number and quit]' \
- '(--bs-hl-color)'--bs-hl-color'[Sets the color of backspace highlights segments]:color:' \
- '(--font)'--font'[Sets the font of the text]:font:' \
- '(--indicator-radius)'--indicator-radius'[Sets the indicator radius]:radius:' \
- '(--indicator-thickness)'--indicator-thickness'[Sets the indicator thickness]:thickness:' \
- '(--inside-color)'--inside-color'[Sets the color of the inside of the indicator]:color:' \
- '(--inside-clear-color)'--inside-clear-color'[Sets the color of the inside of the indicator when cleared]:color:' \
- '(--inside-clear-color)'--inside-clear-color'[Sets the color of the inside of the indicator when verifying]:color:' \
- '(--inside-wrong-color)'--inside-wrong-color'[Sets the color of the inside of the indicator when invalid]:color:' \
- '(--key-hl-color)'--key-hl-color'[Sets the color of the key press highlight segments]:color:' \
- '(--line-color)'--line-color'[Sets the color of the line between the inside and ring]:color:' \
- '(--line-clear-color)'--line-clear-color'[Sets the color of the line between the inside and ring when cleared]:color:' \
- '(--line-ver-color)'--line-ver-color'[Sets the color of the line between the inside and ring when verifying]:color:' \
- '(--line-wrong-color)'--line-wrong-color'[Sets the color of the line between the inside and ring when invalid]:color:' \
- '(-n --line-uses-inside)'{-n,--line-uses-inside}'[Use the inside color for the line between the inside and ring]' \
- '(-r --line-uses-ring)'{-r,--line--uses-ring}'[Use the ring color for the line between the inside and ring]' \
- '(--ring-color)'--ring-color'[Sets the color of the ring of the indicator]:color:' \
- '(--ring-clear-color)'--ring-clear-color'[Sets the color of the ring of the indicator when cleared]:color:' \
- '(--ring-ver-color)'--ring-ver-color'[Sets the color of the ring of the indicator when verifying]:color:' \
- '(--ring-wrong-color)'--ring-wrong-color'[Sets the color of the ring of the indicator when invalid]:color:' \
- '(--separator-color)'--separator-color'[Sets the color of the lines that separate highlight segments]:color:' \
- '(--text-color)'--text-color'[Sets the color of the text]:color:' \
- '(--text-clear-color)'--text-clear-color'[Sets the color of the text when cleared]:color:' \
- '(--text-ver-color)'--text-ver-color'[Sets the color of the text when verifying]:color:' \
- '(--text-wrong-color)'--text-wrong-color'[Sets the color of the text when invalid]:color:' \ No newline at end of file
diff --git a/meson.build b/meson.build
index bffbe312..520a87ad 100644
--- a/meson.build
+++ b/meson.build
@@ -84,7 +84,6 @@ if scdoc.found()
'sway/sway-bar.5.scd',
'sway/sway-input.5.scd',
'sway/sway-output.5.scd',
- 'swaylock/swaylock.1.scd',
'swaymsg/swaymsg.1.scd',
'swaynag/swaynag.1.scd',
'swaynag/swaynag.5.scd',
@@ -146,7 +145,6 @@ subdir('client')
subdir('swaybg')
subdir('swaybar')
subdir('swaynag')
-subdir('swaylock')
config = configuration_data()
config.set('datadir', join_paths(prefix, datadir))
@@ -200,7 +198,6 @@ endif
if (get_option('zsh-completions'))
zsh_files = files(
'completions/zsh/_sway',
- 'completions/zsh/_swaylock',
'completions/zsh/_swaymsg',
)
zsh_install_dir = datadir + '/zsh/site-functions'
@@ -212,7 +209,6 @@ if (get_option('bash-completions'))
bash_files = files(
'completions/bash/sway',
'completions/bash/swaybar',
- 'completions/bash/swaylock',
'completions/bash/swaymsg',
)
bash_install_dir = datadir + '/bash-completion/completions'
@@ -223,7 +219,6 @@ endif
if (get_option('fish-completions'))
fish_files = files(
'completions/fish/sway.fish',
- 'completions/fish/swaylock.fish',
'completions/fish/swaymsg.fish',
'completions/fish/swaynag.fish',
)
diff --git a/swaylock/main.c b/swaylock/main.c
deleted file mode 100644
index 0b167da1..00000000
--- a/swaylock/main.c
+++ /dev/null
@@ -1,1057 +0,0 @@
-#define _POSIX_C_SOURCE 200809L
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <getopt.h>
-#include <poll.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <time.h>
-#include <unistd.h>
-#include <wayland-client.h>
-#include <wordexp.h>
-#include <wlr/util/log.h>
-#include "swaylock/seat.h"
-#include "swaylock/swaylock.h"
-#include "background-image.h"
-#include "pool-buffer.h"
-#include "cairo.h"
-#include "log.h"
-#include "loop.h"
-#include "stringop.h"
-#include "util.h"
-#include "wlr-input-inhibitor-unstable-v1-client-protocol.h"
-#include "wlr-layer-shell-unstable-v1-client-protocol.h"
-#include "xdg-output-unstable-v1-client-protocol.h"
-
-void sway_terminate(int exit_code) {
- exit(exit_code);
-}
-
-static void daemonize(void) {
- int fds[2];
- if (pipe(fds) != 0) {
- wlr_log(WLR_ERROR, "Failed to pipe");
- exit(1);
- }
- if (fork() == 0) {
- setsid();
- close(fds[0]);
- int devnull = open("/dev/null", O_RDWR);
- dup2(STDOUT_FILENO, devnull);
- dup2(STDERR_FILENO, devnull);
- close(devnull);
- uint8_t success = 0;
- if (chdir("/") != 0) {
- write(fds[1], &success, 1);
- exit(1);
- }
- success = 1;
- if (write(fds[1], &success, 1) != 1) {
- exit(1);
- }
- close(fds[1]);
- } else {
- close(fds[1]);
- uint8_t success;
- if (read(fds[0], &success, 1) != 1 || !success) {
- wlr_log(WLR_ERROR, "Failed to daemonize");
- exit(1);
- }
- close(fds[0]);
- exit(0);
- }
-}
-
-static void destroy_surface(struct swaylock_surface *surface) {
- wl_list_remove(&surface->link);
- if (surface->layer_surface != NULL) {
- zwlr_layer_surface_v1_destroy(surface->layer_surface);
- }
- if (surface->surface != NULL) {
- wl_surface_destroy(surface->surface);
- }
- destroy_buffer(&surface->buffers[0]);
- destroy_buffer(&surface->buffers[1]);
- wl_output_destroy(surface->output);
- free(surface);
-}
-
-static const struct zwlr_layer_surface_v1_listener layer_surface_listener;
-
-static cairo_surface_t *select_image(struct swaylock_state *state,
- struct swaylock_surface *surface);
-
-static bool surface_is_opaque(struct swaylock_surface *surface) {
- if (surface->image) {
- return cairo_surface_get_content(surface->image) == CAIRO_CONTENT_COLOR;
- }
- return (surface->state->args.colors.background & 0xff) == 0xff;
-}
-
-static void create_layer_surface(struct swaylock_surface *surface) {
- struct swaylock_state *state = surface->state;
-
- surface->image = select_image(state, surface);
-
- surface->surface = wl_compositor_create_surface(state->compositor);
- assert(surface->surface);
-
- surface->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
- state->layer_shell, surface->surface, surface->output,
- ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY, "lockscreen");
- assert(surface->layer_surface);
-
- zwlr_layer_surface_v1_set_size(surface->layer_surface, 0, 0);
- zwlr_layer_surface_v1_set_anchor(surface->layer_surface,
- ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |
- ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT |
- ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM |
- ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT);
- zwlr_layer_surface_v1_set_exclusive_zone(surface->layer_surface, -1);
- zwlr_layer_surface_v1_set_keyboard_interactivity(
- surface->layer_surface, true);
- zwlr_layer_surface_v1_add_listener(surface->layer_surface,
- &layer_surface_listener, surface);
-
- if (surface_is_opaque(surface) &&
- surface->state->args.mode != BACKGROUND_MODE_CENTER &&
- surface->state->args.mode != BACKGROUND_MODE_FIT) {
- struct wl_region *region =
- wl_compositor_create_region(surface->state->compositor);
- wl_region_add(region, 0, 0, INT32_MAX, INT32_MAX);
- wl_surface_set_opaque_region(surface->surface, region);
- wl_region_destroy(region);
- }
-
- wl_surface_commit(surface->surface);
-}
-
-static void layer_surface_configure(void *data,
- struct zwlr_layer_surface_v1 *layer_surface,
- uint32_t serial, uint32_t width, uint32_t height) {
- struct swaylock_surface *surface = data;
- surface->width = width;
- surface->height = height;
- zwlr_layer_surface_v1_ack_configure(layer_surface, serial);
- render_frame(surface);
-}
-
-static void layer_surface_closed(void *data,
- struct zwlr_layer_surface_v1 *layer_surface) {
- struct swaylock_surface *surface = data;
- destroy_surface(surface);
-}
-
-static const struct zwlr_layer_surface_v1_listener layer_surface_listener = {
- .configure = layer_surface_configure,
- .closed = layer_surface_closed,
-};
-
-static const struct wl_callback_listener surface_frame_listener;
-
-static void surface_frame_handle_done(void *data, struct wl_callback *callback,
- uint32_t time) {
- struct swaylock_surface *surface = data;
-
- wl_callback_destroy(callback);
- surface->frame_pending = false;
-
- if (surface->dirty) {
- // Schedule a frame in case the surface is damaged again
- struct wl_callback *callback = wl_surface_frame(surface->surface);
- wl_callback_add_listener(callback, &surface_frame_listener, surface);
- surface->frame_pending = true;
-
- render_frame(surface);
- surface->dirty = false;
- }
-}
-
-static const struct wl_callback_listener surface_frame_listener = {
- .done = surface_frame_handle_done,
-};
-
-void damage_surface(struct swaylock_surface *surface) {
- surface->dirty = true;
- if (surface->frame_pending) {
- return;
- }
-
- struct wl_callback *callback = wl_surface_frame(surface->surface);
- wl_callback_add_listener(callback, &surface_frame_listener, surface);
- surface->frame_pending = true;
- wl_surface_commit(surface->surface);
-}
-
-void damage_state(struct swaylock_state *state) {
- struct swaylock_surface *surface;
- wl_list_for_each(surface, &state->surfaces, link) {
- damage_surface(surface);
- }
-}
-
-static void handle_wl_output_geometry(void *data, struct wl_output *wl_output,
- int32_t x, int32_t y, int32_t width_mm, int32_t height_mm,
- int32_t subpixel, const char *make, const char *model,
- int32_t transform) {
- struct swaylock_surface *surface = data;
- surface->subpixel = subpixel;
- if (surface->state->run_display) {
- damage_surface(surface);
- }
-}
-
-static void handle_wl_output_mode(void *data, struct wl_output *output,
- uint32_t flags, int32_t width, int32_t height, int32_t refresh) {
- // Who cares
-}
-
-static void handle_wl_output_done(void *data, struct wl_output *output) {
- // Who cares
-}
-
-static void handle_wl_output_scale(void *data, struct wl_output *output,
- int32_t factor) {
- struct swaylock_surface *surface = data;
- surface->scale = factor;
- if (surface->state->run_display) {
- damage_surface(surface);
- }
-}
-
-struct wl_output_listener _wl_output_listener = {
- .geometry = handle_wl_output_geometry,
- .mode = handle_wl_output_mode,
- .done = handle_wl_output_done,
- .scale = handle_wl_output_scale,
-};
-
-static void handle_xdg_output_logical_size(void *data, struct zxdg_output_v1 *output,
- int width, int height) {
- // Who cares
-}
-
-static void handle_xdg_output_logical_position(void *data,
- struct zxdg_output_v1 *output, int x, int y) {
- // Who cares
-}
-
-static void handle_xdg_output_name(void *data, struct zxdg_output_v1 *output,
- const char *name) {
- wlr_log(WLR_DEBUG, "output name is %s", name);
- struct swaylock_surface *surface = data;
- surface->xdg_output = output;
- surface->output_name = strdup(name);
-}
-
-static void handle_xdg_output_description(void *data, struct zxdg_output_v1 *output,
- const char *description) {
- // Who cares
-}
-
-static void handle_xdg_output_done(void *data, struct zxdg_output_v1 *output) {
- // Who cares
-}
-
-struct zxdg_output_v1_listener _xdg_output_listener = {
- .logical_position = handle_xdg_output_logical_position,
- .logical_size = handle_xdg_output_logical_size,
- .done = handle_xdg_output_done,
- .name = handle_xdg_output_name,
- .description = handle_xdg_output_description,
-};
-
-static void handle_global(void *data, struct wl_registry *registry,
- uint32_t name, const char *interface, uint32_t version) {
- struct swaylock_state *state = data;
- if (strcmp(interface, wl_compositor_interface.name) == 0) {
- state->compositor = wl_registry_bind(registry, name,
- &wl_compositor_interface, 3);
- } else if (strcmp(interface, wl_shm_interface.name) == 0) {
- state->shm = wl_registry_bind(registry, name,
- &wl_shm_interface, 1);
- } else if (strcmp(interface, wl_seat_interface.name) == 0) {
- struct wl_seat *seat = wl_registry_bind(
- registry, name, &wl_seat_interface, 3);
- struct swaylock_seat *swaylock_seat =
- calloc(1, sizeof(struct swaylock_seat));
- swaylock_seat->state = state;
- wl_seat_add_listener(seat, &seat_listener, swaylock_seat);
- } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
- state->layer_shell = wl_registry_bind(
- registry, name, &zwlr_layer_shell_v1_interface, 1);
- } else if (strcmp(interface, zwlr_input_inhibit_manager_v1_interface.name) == 0) {
- state->input_inhibit_manager = wl_registry_bind(
- registry, name, &zwlr_input_inhibit_manager_v1_interface, 1);
- } else if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0) {
- state->zxdg_output_manager = wl_registry_bind(
- registry, name, &zxdg_output_manager_v1_interface, 2);
- } else if (strcmp(interface, wl_output_interface.name) == 0) {
- struct swaylock_surface *surface =
- calloc(1, sizeof(struct swaylock_surface));
- surface->state = state;
- surface->output = wl_registry_bind(registry, name,
- &wl_output_interface, 3);
- surface->output_global_name = name;
- wl_output_add_listener(surface->output, &_wl_output_listener, surface);
- wl_list_insert(&state->surfaces, &surface->link);
-
- if (state->run_display) {
- create_layer_surface(surface);
- wl_display_roundtrip(state->display);
- }
- }
-}
-
-static void handle_global_remove(void *data, struct wl_registry *registry,
- uint32_t name) {
- struct swaylock_state *state = data;
- struct swaylock_surface *surface;
- wl_list_for_each(surface, &state->surfaces, link) {
- if (surface->output_global_name == name) {
- destroy_surface(surface);
- break;
- }
- }
-}
-
-static const struct wl_registry_listener registry_listener = {
- .global = handle_global,
- .global_remove = handle_global_remove,
-};
-
-static cairo_surface_t *select_image(struct swaylock_state *state,
- struct swaylock_surface *surface) {
- struct swaylock_image *image;
- cairo_surface_t *default_image = NULL;
- wl_list_for_each(image, &state->images, link) {
- if (lenient_strcmp(image->output_name, surface->output_name) == 0) {
- return image->cairo_surface;
- } else if (!image->output_name) {
- default_image = image->cairo_surface;
- }
- }
- return default_image;
-}
-
-static void load_image(char *arg, struct swaylock_state *state) {
- // [<output>:]<path>
- struct swaylock_image *image = calloc(1, sizeof(struct swaylock_image));
- char *separator = strchr(arg, ':');
- if (separator) {
- *separator = '\0';
- image->output_name = strdup(arg);
- image->path = strdup(separator + 1);
- } else {
- image->output_name = NULL;
- image->path = strdup(arg);
- }
-
- struct swaylock_image *iter_image, *temp;
- wl_list_for_each_safe(iter_image, temp, &state->images, link) {
- if (lenient_strcmp(iter_image->output_name, image->output_name) == 0) {
- if (image->output_name) {
- wlr_log(WLR_DEBUG,
- "Replacing image defined for output %s with %s",
- image->output_name, image->path);
- } else {
- wlr_log(WLR_DEBUG, "Replacing default image with %s",
- image->path);
- }
- wl_list_remove(&iter_image->link);
- free(iter_image->cairo_surface);
- free(iter_image->output_name);
- free(iter_image->path);
- free(iter_image);
- break;
- }
- }
-
- // Bash doesn't replace the ~ with $HOME if the output name is supplied
- wordexp_t p;
- if (wordexp(image->path, &p, 0) == 0) {
- free(image->path);
- image->path = strdup(p.we_wordv[0]);
- wordfree(&p);
- }
-
- // Load the actual image
- image->cairo_surface = load_background_image(image->path);
- if (!image->cairo_surface) {
- free(image);
- return;
- }
- wl_list_insert(&state->images, &image->link);
- wlr_log(WLR_DEBUG, "Loaded image %s for output %s",
- image->path, image->output_name ? image->output_name : "*");
-}
-
-static void set_default_colors(struct swaylock_colors *colors) {
- colors->background = 0xFFFFFFFF;
- colors->bs_highlight = 0xDB3300FF;
- colors->key_highlight = 0x33DB00FF;
- colo