diff options
-rw-r--r-- | common/meson.build | 1 | ||||
-rw-r--r-- | common/unicode.c | 101 | ||||
-rw-r--r-- | include/swaylock/seat.h | 21 | ||||
-rw-r--r-- | include/swaylock/swaylock.h | 117 | ||||
-rw-r--r-- | include/unicode.h | 33 |
5 files changed, 0 insertions, 273 deletions
diff --git a/common/meson.build b/common/meson.build index 4ad872d1..3af1f1d5 100644 --- a/common/meson.build +++ b/common/meson.build | |||
@@ -9,7 +9,6 @@ lib_sway_common = static_library( | |||
9 | 'list.c', | 9 | 'list.c', |
10 | 'pango.c', | 10 | 'pango.c', |
11 | 'stringop.c', | 11 | 'stringop.c', |
12 | 'unicode.c', | ||
13 | 'util.c' | 12 | 'util.c' |
14 | ), | 13 | ), |
15 | dependencies: [ | 14 | dependencies: [ |
diff --git a/common/unicode.c b/common/unicode.c deleted file mode 100644 index 5070e083..00000000 --- a/common/unicode.c +++ /dev/null | |||
@@ -1,101 +0,0 @@ | |||
1 | #include <stdint.h> | ||
2 | #include <stddef.h> | ||
3 | #include "unicode.h" | ||
4 | |||
5 | size_t utf8_chsize(uint32_t ch) { | ||
6 | if (ch < 0x80) { | ||
7 | return 1; | ||
8 | } else if (ch < 0x800) { | ||
9 | return 2; | ||
10 | } else if (ch < 0x10000) { | ||
11 | return 3; | ||
12 | } | ||
13 | return 4; | ||
14 | } | ||
15 | |||
16 | static const uint8_t masks[] = { | ||
17 | 0x7F, | ||
18 | 0x1F, | ||
19 | 0x0F, | ||
20 | 0x07, | ||
21 | 0x03, | ||
22 | 0x01 | ||
23 | }; | ||
24 | |||
25 | uint32_t utf8_decode(const char **char_str) { | ||
26 | uint8_t **s = (uint8_t **)char_str; | ||
27 | |||
28 | uint32_t cp = 0; | ||
29 | if (**s < 128) { | ||
30 | // shortcut | ||
31 | cp = **s; | ||
32 | ++*s; | ||
33 | return cp; | ||
34 | } | ||
35 | int size = utf8_size((char *)*s); | ||
36 | if (size == -1) { | ||
37 | ++*s; | ||
38 | return UTF8_INVALID; | ||
39 | } | ||
40 | uint8_t mask = masks[size - 1]; | ||
41 | cp = **s & mask; | ||
42 | ++*s; | ||
43 | while (--size) { | ||
44 | cp <<= 6; | ||
45 | cp |= **s & 0x3f; | ||
46 | ++*s; | ||
47 | } | ||
48 | return cp; | ||
49 | } | ||
50 | |||
51 | size_t utf8_encode(char *str, uint32_t ch) { | ||
52 | size_t len = 0; | ||
53 | uint8_t first; | ||
54 | |||
55 | if (ch < 0x80) { | ||
56 | first = 0; | ||
57 | len = 1; | ||
58 | } else if (ch < 0x800) { | ||
59 | first = 0xc0; | ||
60 | len = 2; | ||
61 | } else if (ch < 0x10000) { | ||
62 | first = 0xe0; | ||
63 | len = 3; | ||
64 | } else { | ||
65 | first = 0xf0; | ||
66 | len = 4; | ||
67 | } | ||
68 | |||
69 | for (size_t i = len - 1; i > 0; --i) { | ||
70 | str[i] = (ch & 0x3f) | 0x80; | ||
71 | ch >>= 6; | ||
72 | } | ||
73 | |||
74 | str[0] = ch | first; | ||
75 | return len; | ||
76 | } | ||
77 | |||
78 | |||
79 | static const struct { | ||
80 | uint8_t mask; | ||
81 | uint8_t result; | ||
82 | int octets; | ||
83 | } sizes[] = { | ||
84 | { 0x80, 0x00, 1 }, | ||
85 | { 0xE0, 0xC0, 2 }, | ||
86 | { 0xF0, 0xE0, 3 }, | ||
87 | { 0xF8, 0xF0, 4 }, | ||
88 | { 0xFC, 0xF8, 5 }, | ||
89 | { 0xFE, 0xF8, 6 }, | ||
90 | { 0x80, 0x80, -1 }, | ||
91 | }; | ||
92 | |||
93 | int utf8_size(const char *s) { | ||
94 | uint8_t c = (uint8_t)*s; | ||
95 | for (size_t i = 0; i < sizeof(sizes) / sizeof(*sizes); ++i) { | ||
96 | if ((c & sizes[i].mask) == sizes[i].result) { | ||
97 | return sizes[i].octets; | ||
98 | } | ||
99 | } | ||
100 | return -1; | ||
101 | } | ||
diff --git a/include/swaylock/seat.h b/include/swaylock/seat.h deleted file mode 100644 index c79afcd0..00000000 --- a/include/swaylock/seat.h +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | #ifndef _SWAYLOCK_SEAT_H | ||
2 | #define _SWAYLOCK_SEAT_H | ||
3 | #include <xkbcommon/xkbcommon.h> | ||
4 | |||
5 | struct swaylock_xkb { | ||
6 | bool caps_lock; | ||
7 | bool control; | ||
8 | struct xkb_state *state; | ||
9 | struct xkb_context *context; | ||
10 | struct xkb_keymap *keymap; | ||
11 | }; | ||
12 | |||
13 | struct swaylock_seat { | ||
14 | struct swaylock_state *state; | ||
15 | struct wl_pointer *pointer; | ||
16 | struct wl_keyboard *keyboard; | ||
17 | }; | ||
18 | |||
19 | extern const struct wl_seat_listener seat_listener; | ||
20 | |||
21 | #endif | ||
diff --git a/include/swaylock/swaylock.h b/include/swaylock/swaylock.h deleted file mode 100644 index 516a56f4..00000000 --- a/include/swaylock/swaylock.h +++ /dev/null | |||
@@ -1,117 +0,0 @@ | |||
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 "swaylock/seat.h" | ||
10 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" | ||
11 | |||
12 | enum auth_state { | ||
13 | AUTH_STATE_IDLE, | ||
14 | AUTH_STATE_CLEAR, | ||
15 | AUTH_STATE_INPUT, | ||
16 | AUTH_STATE_INPUT_NOP, | ||
17 | AUTH_STATE_BACKSPACE, | ||
18 | AUTH_STATE_VALIDATING, | ||
19 | AUTH_STATE_INVALID, | ||
20 | }; | ||
21 | |||
22 | struct swaylock_colorset { | ||
23 | uint32_t input; | ||
24 | uint32_t cleared; | ||
25 | uint32_t caps_lock; | ||
26 | uint32_t verifying; | ||
27 | uint32_t wrong; | ||
28 | }; | ||
29 | |||
30 | struct swaylock_colors { | ||
31 | uint32_t background; | ||
32 | uint32_t bs_highlight; | ||
33 | uint32_t key_highlight; | ||
34 | uint32_t caps_lock_bs_highlight; | ||
35 | uint32_t caps_lock_key_highlight; | ||
36 | uint32_t separator; | ||
37 | struct swaylock_colorset inside; | ||
38 | struct swaylock_colorset line; | ||
39 | struct swaylock_colorset ring; | ||
40 | struct swaylock_colorset text; | ||
41 | }; | ||
42 | |||
43 | struct swaylock_args { | ||
44 | struct swaylock_colors colors; | ||
45 | enum background_mode mode; | ||
46 | char *font; | ||
47 | uint32_t radius; | ||
48 | uint32_t thickness; | ||
49 | bool ignore_empty; | ||
50 | bool show_indicator; | ||
51 | bool show_caps_lock_text; | ||
52 | bool show_caps_lock_indicator; | ||
53 | bool daemonize; | ||
54 | }; | ||
55 | |||
56 | struct swaylock_password { | ||
57 | size_t len; | ||
58 | char buffer[1024]; | ||
59 | }; | ||
60 | |||
61 | struct swaylock_state { | ||
62 | struct loop *eventloop; | ||
63 | struct loop_timer *clear_indicator_timer; // clears the indicator | ||
64 | struct loop_timer *clear_password_timer; // clears the password buffer | ||
65 | struct loop_timer *verify_password_timer; | ||
66 | struct wl_display *display; | ||
67 | struct wl_compositor *compositor; | ||
68 | struct zwlr_layer_shell_v1 *layer_shell; | ||
69 | struct zwlr_input_inhibit_manager_v1 *input_inhibit_manager; | ||
70 | struct wl_shm *shm; | ||
71 | struct wl_list surfaces; | ||
72 | struct wl_list images; | ||
73 | struct swaylock_args args; | ||
74 | struct swaylock_password password; | ||
75 | struct swaylock_xkb xkb; | ||
76 | enum auth_state auth_state; | ||
77 | bool run_display; | ||
78 | struct zxdg_output_manager_v1 *zxdg_output_manager; | ||
79 | }; | ||
80 | |||
81 | struct swaylock_surface { | ||
82 | cairo_surface_t *image; | ||
83 | struct swaylock_state *state; | ||
84 | struct wl_output *output; | ||
85 | uint32_t output_global_name; | ||
86 | struct zxdg_output_v1 *xdg_output; | ||
87 | struct wl_surface *surface; | ||
88 | struct zwlr_layer_surface_v1 *layer_surface; | ||
89 | struct pool_buffer buffers[2]; | ||
90 | struct pool_buffer *current_buffer; | ||
91 | bool frame_pending, dirty; | ||
92 | uint32_t width, height; | ||
93 | int32_t scale; | ||
94 | enum wl_output_subpixel subpixel; | ||
95 | char *output_name; | ||
96 | struct wl_list link; | ||
97 | }; | ||
98 | |||
99 | // There is exactly one swaylock_image for each -i argument | ||
100 | struct swaylock_image { | ||
101 | char *path; | ||
102 | char *output_name; | ||
103 | cairo_surface_t *cairo_surface; | ||
104 | struct wl_list link; | ||
105 | }; | ||
106 | |||
107 | void swaylock_handle_key(struct swaylock_state *state, | ||
108 | xkb_keysym_t keysym, uint32_t codepoint); | ||
109 | void render_frame(struct swaylock_surface *surface); | ||
110 | void render_frames(struct swaylock_state *state); | ||
111 | void damage_surface(struct swaylock_surface *surface); | ||
112 | void damage_state(struct swaylock_state *state); | ||
113 | void initialize_pw_backend(void); | ||
114 | bool attempt_password(struct swaylock_password *pw); | ||
115 | void clear_password_buffer(struct swaylock_password *pw); | ||
116 | |||
117 | #endif | ||
diff --git a/include/unicode.h b/include/unicode.h deleted file mode 100644 index e2ee9588..00000000 --- a/include/unicode.h +++ /dev/null | |||
@@ -1,33 +0,0 @@ | |||
1 | #ifndef _SWAY_UNICODE_H | ||
2 | #define _SWAY_UNICODE_H | ||
3 | #include <stddef.h> | ||
4 | #include <stdint.h> | ||
5 | |||
6 | // Technically UTF-8 supports up to 6 byte codepoints, but Unicode itself | ||
7 | // doesn't really bother with more than 4. | ||
8 | #define UTF8_MAX_SIZE 4 | ||
9 | |||
10 | #define UTF8_INVALID 0x80 | ||
11 | |||
12 | /** | ||
13 | * Grabs the next UTF-8 character and advances the string pointer | ||
14 | */ | ||
15 | uint32_t utf8_decode(const char **str); | ||
16 | |||
17 | /** | ||
18 | * Encodes a character as UTF-8 and returns the length of that character. | ||
19 | */ | ||
20 | size_t utf8_encode(char *str, uint32_t ch); | ||
21 | |||
22 | /** | ||
23 | * Returns the size of the next UTF-8 character | ||
24 | */ | ||
25 | int utf8_size(const char *str); | ||
26 | |||
27 | /** | ||
28 | * Returns the size of a UTF-8 character | ||
29 | */ | ||
30 | size_t utf8_chsize(uint32_t ch); | ||
31 | |||
32 | #endif | ||
33 | |||