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 14 enum 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 25 struct 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 33 struct 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 49 struct 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 password_submit_on_touch; 80 uint32_t password_grace_period; 81 bool password_grace_no_mouse; 82 bool password_grace_no_touch; 83 }; 84 85 struct swaylock_password { 86 size_t len; 87 char buffer[1024]; 88 }; 89 90 struct swaylock_state { 91 struct loop *eventloop; 92 struct loop_timer *clear_indicator_timer; // clears the indicator 93 struct loop_timer *clear_password_timer; // clears the password buffer 94 struct wl_display *display; 95 struct wl_compositor *compositor; 96 struct wl_subcompositor *subcompositor; 97 struct zwlr_layer_shell_v1 *layer_shell; 98 struct zwlr_input_inhibit_manager_v1 *input_inhibit_manager; 99 struct zwlr_screencopy_manager_v1 *screencopy_manager; 100 struct wl_shm *shm; 101 struct wl_list surfaces; 102 struct wl_list images; 103 struct swaylock_args args; 104 struct swaylock_password password; 105 struct swaylock_xkb xkb; 106 enum auth_state auth_state; 107 bool indicator_dirty; 108 int render_randnum; 109 int failed_attempts; 110 size_t n_screenshots_done; 111 bool run_display; 112 struct zxdg_output_manager_v1 *zxdg_output_manager; 113 }; 114 115 struct swaylock_surface { 116 cairo_surface_t *image; 117 struct { 118 uint32_t format, width, height, stride; 119 enum wl_output_transform transform; 120 void *data; 121 struct swaylock_image *image; 122 } screencopy; 123 struct swaylock_state *state; 124 struct wl_output *output; 125 uint32_t output_global_name; 126 struct zxdg_output_v1 *xdg_output; 127 struct wl_surface *surface; 128 struct wl_surface *child; // surface made into subsurface 129 struct wl_subsurface *subsurface; 130 struct zwlr_layer_surface_v1 *layer_surface; 131 struct zwlr_screencopy_frame_v1 *screencopy_frame; 132 struct pool_buffer buffers[2]; 133 struct pool_buffer indicator_buffers[2]; 134 struct pool_buffer *current_buffer; 135 struct swaylock_fade fade; 136 int events_pending; 137 bool frame_pending, dirty; 138 uint32_t width, height; 139 uint32_t indicator_width, indicator_height; 140 int32_t scale; 141 enum wl_output_subpixel subpixel; 142 enum wl_output_transform transform; 143 char *output_name; 144 struct wl_list link; 145 }; 146 147 // There is exactly one swaylock_image for each -i argument 148 struct swaylock_image { 149 char *path; 150 char *output_name; 151 cairo_surface_t *cairo_surface; 152 struct wl_list link; 153 }; 154 155 void swaylock_handle_key(struct swaylock_state *state, 156 xkb_keysym_t keysym, uint32_t codepoint); 157 void swaylock_handle_mouse(struct swaylock_state *state); 158 void swaylock_handle_touch(struct swaylock_state *state); 159 void render_frame_background(struct swaylock_surface *surface); 160 void render_background_fade(struct swaylock_surface *surface, uint32_t time); 161 void render_background_fade_prepare(struct swaylock_surface *surface, struct pool_buffer *buffer); 162 void render_frame(struct swaylock_surface *surface); 163 void render_frames(struct swaylock_state *state); 164 void damage_surface(struct swaylock_surface *surface); 165 void damage_state(struct swaylock_state *state); 166 void clear_password_buffer(struct swaylock_password *pw); 167 void schedule_indicator_clear(struct swaylock_state *state); 168 169 void initialize_pw_backend(int argc, char **argv); 170 void run_pw_backend_child(void); 171 void clear_buffer(char *buf, size_t size); 172 173 #endif 174