main
44ceea7 ยท 1 month ago 7 commits
  1#ifndef _SWAYLOCK_H
  2#define _SWAYLOCK_H
  3#include <stdbool.h>
  4#include <stdint.h>
  5#include <wayland-client.h>
  6#include "background-image.h"
  7#include "cairo.h"
  8#include "pool-buffer.h"
  9#include "seat.h"
 10#include "effects.h"
 11#include "fade.h"
 12#include "wlr-layer-shell-unstable-v1-client-protocol.h"
 13
 14enum auth_state {
 15	AUTH_STATE_IDLE,
 16	AUTH_STATE_CLEAR,
 17	AUTH_STATE_INPUT,
 18	AUTH_STATE_INPUT_NOP,
 19	AUTH_STATE_BACKSPACE,
 20	AUTH_STATE_VALIDATING,
 21	AUTH_STATE_INVALID,
 22	AUTH_STATE_GRACE,
 23};
 24
 25struct swaylock_colorset {
 26	uint32_t input;
 27	uint32_t cleared;
 28	uint32_t caps_lock;
 29	uint32_t verifying;
 30	uint32_t wrong;
 31};
 32
 33struct swaylock_colors {
 34	uint32_t background;
 35	uint32_t bs_highlight;
 36	uint32_t key_highlight;
 37	uint32_t caps_lock_bs_highlight;
 38	uint32_t caps_lock_key_highlight;
 39	uint32_t separator;
 40	uint32_t layout_background;
 41	uint32_t layout_border;
 42	uint32_t layout_text;
 43	struct swaylock_colorset inside;
 44	struct swaylock_colorset line;
 45	struct swaylock_colorset ring;
 46	struct swaylock_colorset text;
 47};
 48
 49struct swaylock_args {
 50	struct swaylock_colors colors;
 51	enum background_mode mode;
 52	char *font;
 53	uint32_t font_size;
 54	uint32_t radius;
 55	uint32_t thickness;
 56	uint32_t indicator_x_position;
 57	uint32_t indicator_y_position;
 58	bool override_indicator_x_position;
 59	bool override_indicator_y_position;
 60	bool ignore_empty;
 61	bool show_indicator;
 62	bool show_caps_lock_text;
 63	bool show_caps_lock_indicator;
 64	bool show_keyboard_layout;
 65	bool hide_keyboard_layout;
 66	bool show_failed_attempts;
 67	bool daemonize;
 68	bool indicator_idle_visible;
 69
 70	bool screenshots;
 71	struct swaylock_effect *effects;
 72	int effects_count;
 73	bool time_effects;
 74	bool indicator;
 75	bool clock;
 76	char *timestr;
 77	char *datestr;
 78	uint32_t fade_in;
 79	bool allow_fade;
 80	bool password_submit_on_touch;
 81	uint32_t password_grace_period;
 82	bool password_grace_no_mouse;
 83	bool password_grace_no_touch;
 84
 85	char *text_cleared;
 86	char *text_caps_lock;
 87	char *text_verifying;
 88	char *text_wrong;
 89};
 90
 91struct swaylock_password {
 92	size_t len;
 93	size_t buffer_len;
 94	char *buffer;
 95};
 96
 97struct swaylock_state {
 98	struct loop *eventloop;
 99	struct loop_timer *clear_indicator_timer; // clears the indicator
100	struct loop_timer *clear_password_timer;  // clears the password buffer
101	struct wl_display *display;
102	struct wl_compositor *compositor;
103	struct wl_subcompositor *subcompositor;
104	struct zwlr_layer_shell_v1 *layer_shell;
105	struct zwlr_input_inhibit_manager_v1 *input_inhibit_manager;
106	struct zwlr_screencopy_manager_v1 *screencopy_manager;
107	struct wl_shm *shm;
108	struct wl_list surfaces;
109	struct wl_list images;
110	cairo_surface_t *indicator_image;
111	struct swaylock_args args;
112	struct swaylock_password password;
113	struct swaylock_xkb xkb;
114	enum auth_state auth_state;
115	bool indicator_dirty;
116	int render_randnum;
117	int failed_attempts;
118	size_t n_screenshots_done;
119	bool run_display;
120	struct ext_session_lock_manager_v1 *ext_session_lock_manager_v1;
121	struct ext_session_lock_v1 *ext_session_lock_v1;
122};
123
124struct swaylock_surface {
125	cairo_surface_t *image;
126	cairo_surface_t *scaled_image;
127	struct {
128		uint32_t format, width, height, stride;
129		enum wl_output_transform transform;
130		void *data;
131		cairo_surface_t *original_image;
132		cairo_surface_t *scaled_image;
133		struct swaylock_image *image;
134	} screencopy;
135	struct swaylock_state *state;
136	struct wl_output *output;
137	uint32_t output_global_name;
138	struct wl_surface *surface;
139	struct wl_surface *child; // surface made into subsurface
140	struct wl_subsurface *subsurface;
141	struct zwlr_layer_surface_v1 *layer_surface;
142	struct zwlr_screencopy_frame_v1 *screencopy_frame;
143	struct ext_session_lock_surface_v1 *ext_session_lock_surface_v1;
144	struct pool_buffer buffers[2];
145	struct pool_buffer indicator_buffers[2];
146	struct swaylock_fade fade;
147	int events_pending;
148	bool configured;
149	bool frame_pending, dirty;
150	uint32_t width, height;
151	uint32_t indicator_width, indicator_height;
152	int32_t scale;
153	enum wl_output_subpixel subpixel;
154	enum wl_output_transform transform;
155	char *output_name;
156	struct wl_list link;
157};
158
159// There is exactly one swaylock_image for each -i argument
160struct swaylock_image {
161	char *path;
162	char *output_name;
163	cairo_surface_t *cairo_surface;
164	struct wl_list link;
165};
166
167void swaylock_handle_key(struct swaylock_state *state,
168		xkb_keysym_t keysym, uint32_t codepoint);
169void swaylock_handle_mouse(struct swaylock_state *state);
170void swaylock_handle_touch(struct swaylock_state *state);
171void render_frame_background(struct swaylock_surface *surface, bool commit);
172void render_background_fade(struct swaylock_surface *surface, uint32_t time);
173void render_frame(struct swaylock_surface *surface);
174void damage_surface(struct swaylock_surface *surface);
175void damage_state(struct swaylock_state *state);
176void clear_password_buffer(struct swaylock_password *pw);
177void schedule_indicator_clear(struct swaylock_state *state);
178
179void initialize_pw_backend(int argc, char **argv);
180void run_pw_backend_child(void);
181void clear_buffer(char *buf, size_t size);
182
183#endif