diff options
Diffstat (limited to 'include/rootston')
-rw-r--r-- | include/rootston/config.h | 51 | ||||
-rw-r--r-- | include/rootston/desktop.h | 64 | ||||
-rw-r--r-- | include/rootston/ini.h | 93 | ||||
-rw-r--r-- | include/rootston/input.h | 110 | ||||
-rw-r--r-- | include/rootston/server.h | 33 | ||||
-rw-r--r-- | include/rootston/view.h | 71 |
6 files changed, 422 insertions, 0 deletions
diff --git a/include/rootston/config.h b/include/rootston/config.h new file mode 100644 index 00000000..0832d88d --- /dev/null +++ b/include/rootston/config.h @@ -0,0 +1,51 @@ +#ifndef _ROOTSTON_CONFIG_H +#define _ROOTSTON_CONFIG_H +#include <wlr/types/wlr_output_layout.h> +#include <wlr/types/wlr_input_device.h> +#include <wlr/types/wlr_cursor.h> + +struct output_config { + char *name; + enum wl_output_transform transform; + int x, y; + struct wl_list link; +}; + +struct device_config { + char *name; + char *mapped_output; + struct wlr_box *mapped_box; + struct wl_list link; +}; + +struct roots_config { + // TODO: Multiple cursors, multiseat + struct { + char *mapped_output; + struct wlr_box *mapped_box; + } cursor; + + struct wl_list outputs; + struct wl_list devices; + char *config_path; +}; + +struct roots_config *parse_args(int argc, char *argv[]); + +void roots_config_destroy(struct roots_config *config); + +/** + * Get configuration for the output. If the output is not configured, returns + * NULL. + */ +struct output_config *config_get_output(struct roots_config *config, + struct wlr_output *output); + +/** + * Get configuration for the device. If the device is not configured, returns + * NULL. + */ +struct device_config *config_get_device(struct roots_config *config, + struct wlr_input_device *device); + +#endif diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h new file mode 100644 index 00000000..5e138c11 --- /dev/null +++ b/include/rootston/desktop.h @@ -0,0 +1,64 @@ +#ifndef _ROOTSTON_DESKTOP_H +#define _ROOTSTON_DESKTOP_H +#include <time.h> +#include <wayland-server.h> +#include <wlr/types/wlr_output.h> +#include <wlr/types/wlr_output_layout.h> +#include <wlr/types/wlr_compositor.h> +#include <wlr/types/wlr_wl_shell.h> +#include <wlr/types/wlr_xdg_shell_v6.h> +#include <wlr/types/wlr_gamma_control.h> +#include "rootston/view.h" +#include "rootston/config.h" + +struct roots_output { + struct roots_desktop *desktop; + struct wlr_output *wlr_output; + struct wl_listener frame; + struct wl_listener resolution; + struct timespec last_frame; + struct wl_list link; +}; + +struct roots_desktop { + struct wl_list views; + + struct wl_list outputs; + struct timespec last_frame; + + struct roots_server *server; + struct roots_config *config; + + struct wlr_output_layout *layout; + + struct wlr_compositor *compositor; + struct wlr_wl_shell *wl_shell; + struct wlr_xdg_shell_v6 *xdg_shell_v6; + struct wlr_xwayland *xwayland; + struct wlr_gamma_control_manager *gamma_control_manager; + + struct wl_listener output_add; + struct wl_listener output_remove; + struct wl_listener xdg_shell_v6_surface; + struct wl_listener xwayland_surface; + struct wl_listener wl_shell_surface; +}; + +struct roots_server; + +struct roots_desktop *desktop_create(struct roots_server *server, + struct roots_config *config); +void desktop_destroy(struct roots_desktop *desktop); + +void view_destroy(struct roots_view *view); +struct roots_view *view_at(struct roots_desktop *desktop, int x, int y); +void view_activate(struct roots_view *view, bool activate); + +void output_add_notify(struct wl_listener *listener, void *data); +void output_remove_notify(struct wl_listener *listener, void *data); + +void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data); +void handle_wl_shell_surface(struct wl_listener *listener, void *data); +void handle_xwayland_surface(struct wl_listener *listener, void *data); + +#endif diff --git a/include/rootston/ini.h b/include/rootston/ini.h new file mode 100644 index 00000000..2804255b --- /dev/null +++ b/include/rootston/ini.h @@ -0,0 +1,93 @@ +/* inih -- simple .INI file parser + +inih is released under the New BSD license (see LICENSE.txt). Go to the project +home page for more info: + +https://github.com/benhoyt/inih + +*/ + +#ifndef __INI_H__ +#define __INI_H__ + +/* Make this header file easier to include in C++ code */ +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdio.h> + +/* Typedef for prototype of handler function. */ +typedef int (*ini_handler)(void* user, const char* section, + const char* name, const char* value); + +/* Typedef for prototype of fgets-style reader function. */ +typedef char* (*ini_reader)(char* str, int num, void* stream); + +/* Parse given INI-style file. May have [section]s, name=value pairs + (whitespace stripped), and comments starting with ';' (semicolon). Section + is "" if name=value pair parsed before any section heading. name:value + pairs are also supported as a concession to Python's configparser. + + For each name=value pair parsed, call handler function with given user + pointer as well as section, name, and value (data only valid for duration + of handler call). Handler should return nonzero on success, zero on error. + + Returns 0 on success, line number of first error on parse error (doesn't + stop on first error), -1 on file open error, or -2 on memory allocation + error (only when INI_USE_STACK is zero). +*/ +int ini_parse(const char* filename, ini_handler handler, void* user); + +/* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't + close the file when it's finished -- the caller must do that. */ +int ini_parse_file(FILE* file, ini_handler handler, void* user); + +/* Same as ini_parse(), but takes an ini_reader function pointer instead of + filename. Used for implementing custom or string-based I/O. */ +int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler, + void* user); + +/* Nonzero to allow multi-line value parsing, in the style of Python's + configparser. If allowed, ini_parse() will call the handler with the same + name for each subsequent line parsed. */ +#ifndef INI_ALLOW_MULTILINE +#define INI_ALLOW_MULTILINE 1 +#endif + +/* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of + the file. See http://code.google.com/p/inih/issues/detail?id=21 */ +#ifndef INI_ALLOW_BOM +#define INI_ALLOW_BOM 1 +#endif + +/* Nonzero to allow inline comments (with valid inline comment characters + specified by INI_INLINE_COMMENT_PREFIXES). Set to 0 to turn off and match + Python 3.2+ configparser behaviour. */ +#ifndef INI_ALLOW_INLINE_COMMENTS +#define INI_ALLOW_INLINE_COMMENTS 1 +#endif +#ifndef INI_INLINE_COMMENT_PREFIXES +#define INI_INLINE_COMMENT_PREFIXES ";" +#endif + +/* Nonzero to use stack, zero to use heap (malloc/free). */ +#ifndef INI_USE_STACK +#define INI_USE_STACK 1 +#endif + +/* Stop parsing on first error (default is to keep parsing). */ +#ifndef INI_STOP_ON_FIRST_ERROR +#define INI_STOP_ON_FIRST_ERROR 0 +#endif + +/* Maximum line length for any line in INI file. */ +#ifndef INI_MAX_LINE +#define INI_MAX_LINE 2000 +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __INI_H__ */ diff --git a/include/rootston/input.h b/include/rootston/input.h new file mode 100644 index 00000000..0ace6cd1 --- /dev/null +++ b/include/rootston/input.h @@ -0,0 +1,110 @@ +#ifndef _ROOTSTON_INPUT_H +#define _ROOTSTON_INPUT_H +#include <xkbcommon/xkbcommon.h> +#include <wayland-server.h> +#include <wlr/types/wlr_input_device.h> +#include <wlr/types/wlr_cursor.h> +#include <wlr/types/wlr_seat.h> +#include <wlr/xcursor.h> +#include "rootston/config.h" +#include "rootston/view.h" +#include "rootston/server.h" + +struct roots_keyboard { + struct roots_input *input; + struct wlr_input_device *device; + struct wl_listener key; + struct wl_list link; +}; + +struct roots_pointer { + struct roots_input *input; + struct wlr_input_device *device; + // We don't listen to any pointer events directly - they go through + // wlr_cursor + struct wl_list link; +}; + +struct roots_touch { + struct roots_input *input; + struct wlr_input_device *device; + struct wl_listener down; + struct wl_listener up; + struct wl_listener motion; + struct wl_listener cancel; + struct wl_list link; +}; + +// TODO: tablet pad +struct roots_tablet_tool { + struct roots_input *input; + struct wlr_input_device *device; + struct wl_listener axis; + struct wl_listener proximity; + struct wl_listener tip; + struct wl_listener button; + struct wl_list link; +}; + +enum roots_cursor_mode { + ROOTS_CURSOR_PASSTHROUGH = 0, + ROOTS_CURSOR_MOVE = 1, + ROOTS_CURSOR_RESIZE = 2, + ROOTS_CURSOR_ROTATE = 3, +}; + +struct roots_input_event { + uint32_t serial; + struct wlr_cursor *cursor; + struct wlr_input_device *device; +}; + +struct roots_input { + struct roots_config *config; + struct roots_server *server; + + // TODO: multiseat, multicursor + struct wlr_cursor *cursor; + struct wlr_xcursor *xcursor; + struct wlr_seat *wl_seat; + + enum roots_cursor_mode mode; + struct roots_view *active_view; + int offs_x, offs_y; + + // Ring buffer of input events that could trigger move/resize/rotate + int input_events_idx; + struct roots_input_event input_events[16]; + + struct wl_list keyboards; + struct wl_list pointers; + struct wl_list touch; + struct wl_list tablet_tools; + + struct wl_listener input_add; + struct wl_listener input_remove; + + struct wl_listener cursor_motion; + struct wl_listener cursor_motion_absolute; + struct wl_listener cursor_button; + struct wl_listener cursor_axis; + struct wl_listener cursor_tool_axis; + struct wl_listener cursor_tool_tip; +}; + +struct roots_input *input_create(struct roots_server *server, + struct roots_config *config); +void input_destroy(struct roots_input *input); + +void pointer_add(struct wlr_input_device *device, struct roots_input *input); +void pointer_remove(struct wlr_input_device *device, struct roots_input *input); +void keyboard_add(struct wlr_input_device *device, struct roots_input *input); +void keyboard_remove(struct wlr_input_device *device, struct roots_input *input); + +void cursor_initialize(struct roots_input *input); +void cursor_load_config(struct roots_config *config, + struct wlr_cursor *cursor, + struct roots_input *input, + struct roots_desktop *desktop); + +#endif diff --git a/include/rootston/server.h b/include/rootston/server.h new file mode 100644 index 00000000..15e3a4ee --- /dev/null +++ b/include/rootston/server.h @@ -0,0 +1,33 @@ +#ifndef _ROOTSTON_SERVER_H +#define _ROOTSTON_SERVER_H +#include <wayland-server.h> +#include <wlr/backend.h> +#include <wlr/backend/session.h> +#include <wlr/types/wlr_data_device_manager.h> +#include <wlr/render.h> +#include <wlr/xwayland.h> +#include "rootston/config.h" +#include "rootston/desktop.h" +#include "rootston/input.h" + +struct roots_server { + /* Rootston resources */ + struct roots_config *config; + struct roots_desktop *desktop; + struct roots_input *input; + + /* Wayland resources */ + struct wl_display *wl_display; + struct wl_event_loop *wl_event_loop; + + /* WLR tools */ + struct wlr_backend *backend; + struct wlr_renderer *renderer; + + /* Global resources */ + struct wlr_data_device_manager *data_device_manager; +}; + +extern struct roots_server server; + +#endif diff --git a/include/rootston/view.h b/include/rootston/view.h new file mode 100644 index 00000000..9cc2fe04 --- /dev/null +++ b/include/rootston/view.h @@ -0,0 +1,71 @@ +#ifndef _ROOTSTON_VIEW_H +#define _ROOTSTON_VIEW_H +#include <stdbool.h> +#include <wlr/types/wlr_box.h> +#include <wlr/types/wlr_surface.h> +#include <wlr/types/wlr_xdg_shell_v6.h> + +struct roots_wl_shell_surface { + struct roots_view *view; + // TODO: Maybe destroy listener should go in roots_view + struct wl_listener destroy; + struct wl_listener ping_timeout; + struct wl_listener request_move; + struct wl_listener request_resize; + struct wl_listener request_set_fullscreen; + struct wl_listener request_set_maximized; +}; + +struct roots_xdg_surface_v6 { + struct roots_view *view; + // TODO: Maybe destroy listener should go in roots_view + struct wl_listener destroy; + struct wl_listener ping_timeout; + struct wl_listener request_minimize; + struct wl_listener request_move; + struct wl_listener request_resize; + struct wl_listener request_show_window_menu; +}; + +struct roots_xwayland_surface { + struct roots_view *view; + // TODO: Maybe destroy listener should go in roots_view + struct wl_listener destroy; +}; + +enum roots_view_type { + ROOTS_WL_SHELL_VIEW, + ROOTS_XDG_SHELL_V6_VIEW, + ROOTS_XWAYLAND_VIEW, +}; + +struct roots_view { + struct roots_desktop *desktop; + double x, y; + float rotation; + // TODO: Something for roots-enforced width/height + enum roots_view_type type; + union { + struct wlr_wl_shell_surface *wl_shell_surface; + struct wlr_xdg_surface_v6 *xdg_surface_v6; + struct wlr_xwayland_surface *xwayland_surface; + }; + union { + struct roots_wl_shell_surface *roots_wl_shell_surface; + struct roots_xdg_surface_v6 *roots_xdg_surface_v6; + struct roots_xwayland_surface *roots_xwayland_surface; + }; + struct wlr_surface *wlr_surface; + struct wl_list link; + // TODO: This would probably be better as a field that's updated on a + // configure event from the xdg_shell + // If not then this should follow the typical type/impl pattern we use + // elsewhere + void (*get_input_bounds)(struct roots_view *view, struct wlr_box *box); + void (*activate)(struct roots_view *view, bool active); +}; + +void view_get_input_bounds(struct roots_view *view, struct wlr_box *box); +void view_activate(struct roots_view *view, bool active); + +#endif |