summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/background-image.h20
-rw-r--r--include/cairo.h25
-rw-r--r--include/list.h35
-rw-r--r--include/loop.h54
-rw-r--r--include/meson.build1
-rw-r--r--include/pool-buffer.h24
-rw-r--r--include/seat.h21
-rw-r--r--include/swaylock.h112
-rw-r--r--include/unicode.h33
9 files changed, 325 insertions, 0 deletions
diff --git a/include/background-image.h b/include/background-image.h
new file mode 100644
index 0000000..15935ff
--- /dev/null
+++ b/include/background-image.h
@@ -0,0 +1,20 @@
+#ifndef _SWAY_BACKGROUND_IMAGE_H
+#define _SWAY_BACKGROUND_IMAGE_H
+#include "cairo.h"
+
+enum background_mode {
+ BACKGROUND_MODE_STRETCH,
+ BACKGROUND_MODE_FILL,
+ BACKGROUND_MODE_FIT,
+ BACKGROUND_MODE_CENTER,
+ BACKGROUND_MODE_TILE,
+ BACKGROUND_MODE_SOLID_COLOR,
+ BACKGROUND_MODE_INVALID,
+};
+
+enum background_mode parse_background_mode(const char *mode);
+cairo_surface_t *load_background_image(const char *path);
+void render_background_image(cairo_t *cairo, cairo_surface_t *image,
+ enum background_mode mode, int buffer_width, int buffer_height);
+
+#endif
diff --git a/include/cairo.h b/include/cairo.h
new file mode 100644
index 0000000..15664cd
--- /dev/null
+++ b/include/cairo.h
@@ -0,0 +1,25 @@
+#ifndef _SWAY_CAIRO_H
+#define _SWAY_CAIRO_H
+
+#include "config.h"
+#include <stdint.h>
+#include <cairo/cairo.h>
+#include <wayland-client.h>
+#if HAVE_GDK_PIXBUF
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#endif
+
+void cairo_set_source_u32(cairo_t *cairo, uint32_t color);
+cairo_subpixel_order_t to_cairo_subpixel_order(enum wl_output_subpixel subpixel);
+
+cairo_surface_t *cairo_image_surface_scale(cairo_surface_t *image,
+ int width, int height);
+
+#if HAVE_GDK_PIXBUF
+
+cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf(
+ const GdkPixbuf *gdkbuf);
+
+#endif // HAVE_GDK_PIXBUF
+
+#endif
diff --git a/include/list.h b/include/list.h
new file mode 100644
index 0000000..895f6cc
--- /dev/null
+++ b/include/list.h
@@ -0,0 +1,35 @@
+#ifndef _SWAY_LIST_H
+#define _SWAY_LIST_H
+
+typedef struct {
+ int capacity;
+ int length;
+ void **items;
+} list_t;
+
+list_t *create_list(void);
+void list_free(list_t *list);
+void list_add(list_t *list, void *item);
+void list_insert(list_t *list, int index, void *item);
+void list_del(list_t *list, int index);
+void list_cat(list_t *list, list_t *source);
+// See qsort. Remember to use *_qsort functions as compare functions,
+// because they dereference the left and right arguments first!
+void list_qsort(list_t *list, int compare(const void *left, const void *right));
+// Return index for first item in list that returns 0 for given compare
+// function or -1 if none matches.
+int list_seq_find(list_t *list, int compare(const void *item, const void *cmp_to), const void *cmp_to);
+int list_find(list_t *list, const void *item);
+// stable sort since qsort is not guaranteed to be stable
+void list_stable_sort(list_t *list, int compare(const void *a, const void *b));
+// swap two elements in a list
+void list_swap(list_t *list, int src, int dest);
+// move item to end of list
+void list_move_to_end(list_t *list, void *item);
+
+/* Calls `free` for each item in the list, then frees the list.
+ * Do not use this to free lists of primitives or items that require more
+ * complicated deallocation code.
+ */
+void list_free_items_and_destroy(list_t *list);
+#endif
diff --git a/include/loop.h b/include/loop.h
new file mode 100644
index 0000000..2f608ed
--- /dev/null
+++ b/include/loop.h
@@ -0,0 +1,54 @@
+#ifndef _SWAY_LOOP_H
+#define _SWAY_LOOP_H
+#include <stdbool.h>
+
+/**
+ * This is an event loop system designed for sway clients, not sway itself.
+ *
+ * The loop consists of file descriptors and timers. Typically the Wayland
+ * display's file descriptor will be one of the fds in the loop.
+ */
+
+struct loop;
+struct loop_timer;
+
+/**
+ * Create an event loop.
+ */
+struct loop *loop_create(void);
+
+/**
+ * Destroy the event loop (eg. on program termination).
+ */
+void loop_destroy(struct loop *loop);
+
+/**
+ * Poll the event loop. This will block until one of the fds has data.
+ */
+void loop_poll(struct loop *loop);
+
+/**
+ * Add a file descriptor to the loop.
+ */
+void loop_add_fd(struct loop *loop, int fd, short mask,
+ void (*func)(int fd, short mask, void *data), void *data);
+
+/**
+ * Add a timer to the loop.
+ *
+ * When the timer expires, the timer will be removed from the loop and freed.
+ */
+struct loop_timer *loop_add_timer(struct loop *loop, int ms,
+ void (*callback)(void *data), void *data);
+
+/**
+ * Remove a file descriptor from the loop.
+ */
+bool loop_remove_fd(struct loop *loop, int fd);
+
+/**
+ * Remove a timer from the loop.
+ */
+bool loop_remove_timer(struct loop *loop, struct loop_timer *timer);
+
+#endif
diff --git a/include/meson.build b/include/meson.build
new file mode 100644
index 0000000..65ed027
--- /dev/null
+++ b/include/meson.build
@@ -0,0 +1 @@
+configure_file(output: 'config.h', configuration: conf_data)
diff --git a/include/pool-buffer.h b/include/pool-buffer.h
new file mode 100644
index 0000000..54f5be0
--- /dev/null
+++ b/include/pool-buffer.h
@@ -0,0 +1,24 @@
+#ifndef _SWAY_BUFFERS_H
+#define _SWAY_BUFFERS_H
+#include <cairo/cairo.h>
+#include <pango/pangocairo.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <wayland-client.h>
+
+struct pool_buffer {
+ struct wl_buffer *buffer;
+ cairo_surface_t *surface;
+ cairo_t *cairo;
+ PangoContext *pango;
+ uint32_t width, height;
+ void *data;
+ size_t size;
+ bool busy;
+};
+
+struct pool_buffer *get_next_buffer(struct wl_shm *shm,
+ struct pool_buffer pool[static 2], uint32_t width, uint32_t height);
+void destroy_buffer(struct pool_buffer *buffer);
+
+#endif
diff --git a/include/seat.h b/include/seat.h
new file mode 100644
index 0000000..c79afcd
--- /dev/null
+++ b/include/seat.h
@@ -0,0 +1,21 @@
+#ifndef _SWAYLOCK_SEAT_H
+#define _SWAYLOCK_SEAT_H
+#include <xkbcommon/xkbcommon.h>
+
+struct swaylock_xkb {
+ bool caps_lock;
+ bool control;
+ struct xkb_state *state;
+ struct xkb_context *context;
+ struct xkb_keymap *keymap;
+};
+
+struct swaylock_seat {
+ struct swaylock_state *state;
+ struct wl_pointer *pointer;
+ struct wl_keyboard *keyboard;
+};
+
+extern const struct wl_seat_listener seat_listener;
+
+#endif
diff --git a/include/swaylock.h b/include/swaylock.h
new file mode 100644
index 0000000..f089a54
--- /dev/null
+++ b/include/swaylock.h
@@ -0,0 +1,112 @@
+#ifndef _SWAYLOCK_H
+#define _SWAYLOCK_H
+#include <stdbool.h>
+#include <stdint.h>
+#include <wayland-client.h>
+#include "background-image.h"
+#include "cairo.h"
+#include "pool-buffer.h"
+#include "seat.h"
+#include "wlr-layer-shell-unstable-v1-client-protocol.h"
+
+enum auth_state {
+ AUTH_STATE_IDLE,
+ AUTH_STATE_CLEAR,
+ AUTH_STATE_INPUT,
+ AUTH_STATE_INPUT_NOP,
+ AUTH_STATE_BACKSPACE,
+ AUTH_STATE_VALIDATING,
+ AUTH_STATE_INVALID,
+};
+
+struct swaylock_colorset {
+ uint32_t input;
+ uint32_t cleared;
+ uint32_t verifying;
+ uint32_t wrong;
+};
+
+struct swaylock_colors {
+ uint32_t background;
+ uint32_t bs_highlight;
+ uint32_t key_highlight;
+ uint32_t separator;
+ struct swaylock_colorset inside;
+ struct swaylock_colorset line;
+ struct swaylock_colorset ring;
+ struct swaylock_colorset text;
+};
+
+struct swaylock_args {
+ struct swaylock_colors colors;
+ enum background_mode mode;
+ char *font;
+ uint32_t radius;
+ uint32_t thickness;
+ bool ignore_empty;
+ bool show_indicator;
+ bool daemonize;
+};
+
+struct swaylock_password {
+ size_t len;
+ char buffer[1024];
+};
+
+struct swaylock_state {
+ struct loop *eventloop;
+ struct loop_timer *clear_indicator_timer; // clears the indicator
+ struct loop_timer *clear_password_timer; // clears the password buffer
+ struct loop_timer *verify_password_timer;
+ struct wl_display *display;
+ struct wl_compositor *compositor;
+ struct zwlr_layer_shell_v1 *layer_shell;
+ struct zwlr_input_inhibit_manager_v1 *input_inhibit_manager;
+ struct wl_shm *shm;
+ struct wl_list surfaces;
+ struct wl_list images;
+ struct swaylock_args args;
+ struct swaylock_password password;
+ struct swaylock_xkb xkb;
+ enum auth_state auth_state;
+ bool run_display;
+ struct zxdg_output_manager_v1 *zxdg_output_manager;
+};
+
+struct swaylock_surface {
+ cairo_surface_t *image;
+ struct swaylock_state *state;
+ struct wl_output *output;
+ uint32_t output_global_name;
+ struct zxdg_output_v1 *xdg_output;
+ struct wl_surface *surface;
+ struct zwlr_layer_surface_v1 *layer_surface;
+ struct pool_buffer buffers[2];
+ struct pool_buffer *current_buffer;
+ bool frame_pending, dirty;
+ uint32_t width, height;
+ int32_t scale;
+ enum wl_output_subpixel subpixel;
+ char *output_name;
+ struct wl_list link;
+};
+
+// There is exactly one swaylock_image for each -i argument
+struct swaylock_image {
+ char *path;
+ char *output_name;
+ cairo_surface_t *cairo_surface;
+ struct wl_list link;
+};
+
+void swaylock_handle_key(struct swaylock_state *state,
+ xkb_keysym_t keysym, uint32_t codepoint);
+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 initialize_pw_backend(void);
+bool attempt_password(struct swaylock_password *pw);
+void clear_password_buffer(struct swaylock_password *pw);
+
+#endif
diff --git a/include/unicode.h b/include/unicode.h
new file mode 100644
index 0000000..e2ee958
--- /dev/null
+++ b/include/unicode.h
@@ -0,0 +1,33 @@
+#ifndef _SWAY_UNICODE_H
+#define _SWAY_UNICODE_H
+#include <stddef.h>
+#include <stdint.h>
+
+// Technically UTF-8 supports up to 6 byte codepoints, but Unicode itself
+// doesn't really bother with more than 4.
+#define UTF8_MAX_SIZE 4
+
+#define UTF8_INVALID 0x80
+
+/**
+ * Grabs the next UTF-8 character and advances the string pointer
+ */
+uint32_t utf8_decode(const char **str);
+
+/**
+ * Encodes a character as UTF-8 and returns the length of that character.
+ */
+size_t utf8_encode(char *str, uint32_t ch);
+
+/**
+ * Returns the size of the next UTF-8 character
+ */
+int utf8_size(const char *str);
+
+/**
+ * Returns the size of a UTF-8 character
+ */
+size_t utf8_chsize(uint32_t ch);
+
+#endif
+