mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-12-22 18:09:49 +01:00
Establish rootston headers & main
This commit is contained in:
parent
06ae9e7c9f
commit
550748681d
11 changed files with 826 additions and 0 deletions
51
include/rootston/config.h
Normal file
51
include/rootston/config.h
Normal file
|
@ -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
|
33
include/rootston/desktop.h
Normal file
33
include/rootston/desktop.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
#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_data_device_manager.h>
|
||||
#include <wlr/types/wlr_gamma_control.h>
|
||||
#include "rootston/view.h"
|
||||
|
||||
struct roots_output {
|
||||
struct roots_desktop *desktop;
|
||||
struct wlr_output *output;
|
||||
struct wl_listener frame;
|
||||
struct wl_listener resolution;
|
||||
struct timespec last_frame;
|
||||
struct wl_list link;
|
||||
};
|
||||
|
||||
struct roots_desktop {
|
||||
struct wl_list outputs;
|
||||
struct wlr_output_layout *layout;
|
||||
struct wlr_compositor *wlr_compositor;
|
||||
struct wlr_wl_shell *wl_shell;
|
||||
struct wlr_xdg_shell_v6 *xdg_shell;
|
||||
struct wlr_data_device_manager *data_device_manager;
|
||||
struct wlr_gamma_control_manager *gamma_control_manager;
|
||||
};
|
||||
|
||||
#endif
|
93
include/rootston/ini.h
Normal file
93
include/rootston/ini.h
Normal file
|
@ -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__ */
|
91
include/rootston/input.h
Normal file
91
include/rootston/input.h
Normal file
|
@ -0,0 +1,91 @@
|
|||
#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/view.h"
|
||||
|
||||
struct roots_keyboard {
|
||||
struct roots_input *input;
|
||||
struct wlr_input_device *device;
|
||||
struct wl_listener key;
|
||||
struct wl_list link;
|
||||
struct xkb_keymap *keymap;
|
||||
struct xkb_state *xkb_state;
|
||||
xkb_led_index_t leds[WLR_LED_LAST];
|
||||
int keymap_fd;
|
||||
size_t keymap_size;
|
||||
};
|
||||
|
||||
struct roots_pointer {
|
||||
struct roots_input *input;
|
||||
struct wlr_input_device *device;
|
||||
struct wl_listener motion;
|
||||
struct wl_listener motion_absolute;
|
||||
struct wl_listener button;
|
||||
struct wl_listener axis;
|
||||
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,
|
||||
ROOTS_CURSOR_MOVE,
|
||||
ROOTS_CURSOR_RESIZE,
|
||||
ROOTS_CURSOR_ROTATE,
|
||||
};
|
||||
|
||||
struct roots_input_event {
|
||||
uint32_t serial;
|
||||
struct wlr_cursor *cursor;
|
||||
struct wlr_input_device *device;
|
||||
};
|
||||
|
||||
struct roots_input {
|
||||
// TODO: multiseat, multicursor
|
||||
struct wlr_cursor *cursor;
|
||||
struct wlr_xcursor *xcursor;
|
||||
struct wlr_seat *wl_seat;
|
||||
|
||||
enum roots_cursor_mode mode;
|
||||
struct roots_view *focused_view;
|
||||
struct roots_view *moving_view;
|
||||
struct roots_view *resizing_view;
|
||||
struct roots_view *rotating_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_list tablet_pads;
|
||||
};
|
||||
|
||||
#endif
|
31
include/rootston/server.h
Normal file
31
include/rootston/server.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
#ifndef _ROOTSTON_SERVER_H
|
||||
#define _ROOTSTON_SERVER_H
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/backend.h>
|
||||
#include <wlr/backend/session.h>
|
||||
#include <wlr/render.h>
|
||||
#include <wlr/xwayland.h>
|
||||
#include "rootston/config.h"
|
||||
#include "rootston/desktop.h"
|
||||
#include "rootston/input.h"
|
||||
|
||||
struct rootston {
|
||||
/* 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_session *session;
|
||||
struct wlr_renderer *renderer;
|
||||
struct wlr_xwayland *xwayland;
|
||||
};
|
||||
|
||||
extern struct rootston root;
|
||||
|
||||
#endif
|
41
include/rootston/view.h
Normal file
41
include/rootston/view.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
#ifndef _ROOTSTON_VIEW_H
|
||||
#define _ROOTSTON_VIEW_H
|
||||
|
||||
struct roots_wl_shell_surface {
|
||||
// TODO
|
||||
void *_placeholder;
|
||||
};
|
||||
|
||||
struct roots_xdg_surface_v6 {
|
||||
// TODO: Maybe destroy listener should go in roots_view
|
||||
struct wl_listener destroy_listener;
|
||||
struct wl_listener ping_timeout_listener;
|
||||
struct wl_listener request_minimize_listener;
|
||||
struct wl_listener request_move_listener;
|
||||
struct wl_listener request_resize_listener;
|
||||
struct wl_listener request_show_window_menu_listener;
|
||||
};
|
||||
|
||||
enum roots_view_type {
|
||||
ROOTS_WL_SHELL_VIEW,
|
||||
ROOTS_XDG_SHELL_V6_VIEW,
|
||||
ROOTS_XWAYLAND_VIEW,
|
||||
};
|
||||
|
||||
struct roots_view {
|
||||
double x, y;
|
||||
float rotation;
|
||||
// TODO: Something for roots-enforced width/height
|
||||
enum roots_view_type type;
|
||||
union {
|
||||
struct wlr_shell_surface *wl_shell_surface;
|
||||
struct xdg_shell_v6_surface *xdg_shell_v6_surface;
|
||||
};
|
||||
union {
|
||||
struct roots_wl_shell_surface *roots_wl_shell_surface;
|
||||
struct xdg_shell_v6_surface *roots_xdg_surface_v6;
|
||||
};
|
||||
struct wl_list link;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -111,4 +111,5 @@ wlroots = declare_dependency(
|
|||
include_directories: wlr_inc,
|
||||
)
|
||||
|
||||
subdir('rootston')
|
||||
subdir('examples')
|
||||
|
|
269
rootston/config.c
Normal file
269
rootston/config.c
Normal file
|
@ -0,0 +1,269 @@
|
|||
#ifndef _POSIX_C_SOURCE
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <getopt.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/param.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include <wlr/types/wlr_box.h>
|
||||
#include "rootston/config.h"
|
||||
#include "rootston/ini.h"
|
||||
|
||||
static void usage(const char *name, int ret) {
|
||||
fprintf(stderr,
|
||||
"usage: %s [-C <FILE>]\n"
|
||||
"\n"
|
||||
" -C <FILE> Path to the configuration file\n"
|
||||
" (default: rootston.ini).\n"
|
||||
" See `rootston.ini.example` for config\n"
|
||||
" file documentation.\n", name);
|
||||
|
||||
exit(ret);
|
||||
}
|
||||
|
||||
static struct wlr_box *parse_geometry(const char *str) {
|
||||
// format: {width}x{height}+{x}+{y}
|
||||
if (strlen(str) > 255) {
|
||||
wlr_log(L_ERROR, "cannot parse geometry string, too long");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *buf = strdup(str);
|
||||
struct wlr_box *box = calloc(1, sizeof(struct wlr_box));
|
||||
|
||||
bool has_width = false;
|
||||
bool has_height = false;
|
||||
bool has_x = false;
|
||||
bool has_y = false;
|
||||
|
||||
char *pch = strtok(buf, "x+");
|
||||
while (pch != NULL) {
|
||||
errno = 0;
|
||||
char *endptr;
|
||||
long val = strtol(pch, &endptr, 0);
|
||||
|
||||
if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) ||
|
||||
(errno != 0 && val == 0)) {
|
||||
goto invalid_input;
|
||||
}
|
||||
|
||||
if (endptr == pch) {
|
||||
goto invalid_input;
|
||||
}
|
||||
|
||||
if (!has_width) {
|
||||
box->width = val;
|
||||
has_width = true;
|
||||
} else if (!has_height) {
|
||||
box->height = val;
|
||||
has_height = true;
|
||||
} else if (!has_x) {
|
||||
box->x = val;
|
||||
has_x = true;
|
||||
} else if (!has_y) {
|
||||
box->y = val;
|
||||
has_y = true;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
pch = strtok(NULL, "x+");
|
||||
}
|
||||
|
||||
if (!has_width || !has_height) {
|
||||
goto invalid_input;
|
||||
}
|
||||
|
||||
free(buf);
|
||||
return box;
|
||||
|
||||
invalid_input:
|
||||
wlr_log(L_ERROR, "could not parse geometry string: %s", str);
|
||||
free(buf);
|
||||
free(box);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *output_prefix = "output:";
|
||||
static const char *device_prefix = "device:";
|
||||
|
||||
static int config_ini_handler(void *user, const char *section, const char *name,
|
||||
const char *value) {
|
||||
struct roots_config *config = user;
|
||||
if (strncmp(output_prefix, section, strlen(output_prefix)) == 0) {
|
||||
const char *output_name = section + strlen(output_prefix);
|
||||
struct output_config *oc;
|
||||
bool found = false;
|
||||
|
||||
wl_list_for_each(oc, &config->outputs, link) {
|
||||
if (strcmp(oc->name, output_name) == 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
oc = calloc(1, sizeof(struct output_config));
|
||||
oc->name = strdup(output_name);
|
||||
oc->transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
||||
wl_list_insert(&config->outputs, &oc->link);
|
||||
}
|
||||
|
||||
if (strcmp(name, "x") == 0) {
|
||||
oc->x = strtol(value, NULL, 10);
|
||||
} else if (strcmp(name, "y") == 0) {
|
||||
oc->y = strtol(value, NULL, 10);
|
||||
} else if (strcmp(name, "rotate") == 0) {
|
||||
if (strcmp(value, "90") == 0) {
|
||||
oc->transform = WL_OUTPUT_TRANSFORM_90;
|
||||
} else if (strcmp(value, "180") == 0) {
|
||||
oc->transform = WL_OUTPUT_TRANSFORM_180;
|
||||
} else if (strcmp(value, "270") == 0) {
|
||||
oc->transform = WL_OUTPUT_TRANSFORM_270;
|
||||
} else if (strcmp(value, "flipped") == 0) {
|
||||
oc->transform = WL_OUTPUT_TRANSFORM_FLIPPED;
|
||||
} else if (strcmp(value, "flipped-90") == 0) {
|
||||
oc->transform = WL_OUTPUT_TRANSFORM_FLIPPED_90;
|
||||
} else if (strcmp(value, "flipped-180") == 0) {
|
||||
oc->transform = WL_OUTPUT_TRANSFORM_FLIPPED_180;
|
||||
} else if (strcmp(value, "flipped-270") == 0) {
|
||||
oc->transform = WL_OUTPUT_TRANSFORM_FLIPPED_270;
|
||||
} else {
|
||||
wlr_log(L_ERROR, "got unknown transform value: %s", value);
|
||||
}
|
||||
}
|
||||
} else if (strcmp(section, "cursor") == 0) {
|
||||
if (strcmp(name, "map-to-output") == 0) {
|
||||
free(config->cursor.mapped_output);
|
||||
config->cursor.mapped_output = strdup(value);
|
||||
} else if (strcmp(name, "geometry") == 0) {
|
||||
free(config->cursor.mapped_box);
|
||||
config->cursor.mapped_box = parse_geometry(value);
|
||||
} else {
|
||||
wlr_log(L_ERROR, "got unknown cursor config: %s", name);
|
||||
}
|
||||
} else if (strncmp(device_prefix, section, strlen(device_prefix)) == 0) {
|
||||
const char *device_name = section + strlen(device_prefix);
|
||||
struct device_config *dc;
|
||||
bool found = false;
|
||||
|
||||
wl_list_for_each(dc, &config->devices, link) {
|
||||
if (strcmp(dc->name, device_name) == 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
dc = calloc(1, sizeof(struct device_config));
|
||||
dc->name = strdup(device_name);
|
||||
wl_list_insert(&config->devices, &dc->link);
|
||||
}
|
||||
|
||||
if (strcmp(name, "map-to-output") == 0) {
|
||||
free(dc->mapped_output);
|
||||
dc->mapped_output = strdup(value);
|
||||
} else if (strcmp(name, "geometry") == 0) {
|
||||
free(dc->mapped_box);
|
||||
dc->mapped_box = parse_geometry(value);
|
||||
} else {
|
||||
wlr_log(L_ERROR, "got unknown device config: %s", name);
|
||||
}
|
||||
} else {
|
||||
wlr_log(L_ERROR, "got unknown config section: %s", section);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct roots_config *parse_args(int argc, char *argv[]) {
|
||||
struct roots_config *config = calloc(1, sizeof(struct roots_config));
|
||||
wl_list_init(&config->outputs);
|
||||
wl_list_init(&config->devices);
|
||||
|
||||
int c;
|
||||
while ((c = getopt(argc, argv, "C:h")) != -1) {
|
||||
switch (c) {
|
||||
case 'C':
|
||||
config->config_path = strdup(optarg);
|
||||
break;
|
||||
case 'h':
|
||||
case '?':
|
||||
usage(argv[0], c != 'h');
|
||||
}
|
||||
}
|
||||
|
||||
if (!config->config_path) {
|
||||
// get the config path from the current directory
|
||||
char cwd[MAXPATHLEN];
|
||||
if (getcwd(cwd, sizeof(cwd)) != NULL) {
|
||||
char buf[MAXPATHLEN];
|
||||
snprintf(buf, MAXPATHLEN, "%s/%s", cwd, "rootston.ini");
|
||||
config->config_path = strdup(buf);
|
||||
} else {
|
||||
wlr_log(L_ERROR, "could not get cwd");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
int result = ini_parse(config->config_path, config_ini_handler, config);
|
||||
|
||||
if (result == -1) {
|
||||
wlr_log(L_DEBUG, "No config file found. Using empty config.");
|
||||
} else if (result == -2) {
|
||||
wlr_log(L_ERROR, "Could not allocate memory to parse config file");
|
||||
exit(1);
|
||||
} else if (result != 0) {
|
||||
wlr_log(L_ERROR, "Could not parse config file");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
void roots_config_destroy(struct roots_config *config) {
|
||||
struct output_config *oc, *otmp = NULL;
|
||||
wl_list_for_each_safe(oc, otmp, &config->outputs, link) {
|
||||
free(oc->name);
|
||||
free(oc);
|
||||
}
|
||||
|
||||
struct device_config *dc, *dtmp = NULL;
|
||||
wl_list_for_each_safe(dc, dtmp, &config->devices, link) {
|
||||
free(dc->name);
|
||||
free(dc->mapped_output);
|
||||
free(dc->mapped_box);
|
||||
free(dc);
|
||||
}
|
||||
|
||||
free(config->config_path);
|
||||
free(config->cursor.mapped_output);
|
||||
free(config->cursor.mapped_box);
|
||||
free(config);
|
||||
}
|
||||
|
||||
struct output_config *config_get_output(struct roots_config *config,
|
||||
struct wlr_output *output) {
|
||||
struct output_config *o_config;
|
||||
wl_list_for_each(o_config, &config->outputs, link) {
|
||||
if (strcmp(o_config->name, output->name) == 0) {
|
||||
return o_config;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct device_config *config_get_device(struct roots_config *config,
|
||||
struct wlr_input_device *device) {
|
||||
struct device_config *d_config;
|
||||
wl_list_for_each(d_config, &config->devices, link) {
|
||||
if (strcmp(d_config->name, device->name) == 0) {
|
||||
return d_config;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
195
rootston/ini.c
Normal file
195
rootston/ini.c
Normal file
|
@ -0,0 +1,195 @@
|
|||
/* 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
|
||||
|
||||
*/
|
||||
|
||||
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "rootston/ini.h"
|
||||
|
||||
#if !INI_USE_STACK
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#define MAX_SECTION 50
|
||||
#define MAX_NAME 50
|
||||
|
||||
/* Strip whitespace chars off end of given string, in place. Return s. */
|
||||
static char* rstrip(char* s)
|
||||
{
|
||||
char* p = s + strlen(s);
|
||||
while (p > s && isspace((unsigned char)(*--p)))
|
||||
*p = '\0';
|
||||
return s;
|
||||
}
|
||||
|
||||
/* Return pointer to first non-whitespace char in given string. */
|
||||
static char* lskip(const char* s)
|
||||
{
|
||||
while (*s && isspace((unsigned char)(*s)))
|
||||
s++;
|
||||
return (char*)s;
|
||||
}
|
||||
|
||||
/* Return pointer to first char (of chars) or inline comment in given string,
|
||||
or pointer to null at end of string if neither found. Inline comment must
|
||||
be prefixed by a whitespace character to register as a comment. */
|
||||
static char* find_chars_or_comment(const char* s, const char* chars)
|
||||
{
|
||||
#if INI_ALLOW_INLINE_COMMENTS
|
||||
int was_space = 0;
|
||||
while (*s && (!chars || !strchr(chars, *s)) &&
|
||||
!(was_space && strchr(INI_INLINE_COMMENT_PREFIXES, *s))) {
|
||||
was_space = isspace((unsigned char)(*s));
|
||||
s++;
|
||||
}
|
||||
#else
|
||||
while (*s && (!chars || !strchr(chars, *s))) {
|
||||
s++;
|
||||
}
|
||||
#endif
|
||||
return (char*)s;
|
||||
}
|
||||
|
||||
/* Version of strncpy that ensures dest (size bytes) is null-terminated. */
|
||||
static char* strncpy0(char* dest, const char* src, size_t size)
|
||||
{
|
||||
strncpy(dest, src, size);
|
||||
dest[size - 1] = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
/* See documentation in header file. */
|
||||
int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
|
||||
void* user)
|
||||
{
|
||||
/* Uses a fair bit of stack (use heap instead if you need to) */
|
||||
#if INI_USE_STACK
|
||||
char line[INI_MAX_LINE];
|
||||
#else
|
||||
char* line;
|
||||
#endif
|
||||
char section[MAX_SECTION] = "";
|
||||
char prev_name[MAX_NAME] = "";
|
||||
|
||||
char* start;
|
||||
char* end;
|
||||
char* name;
|
||||
char* value;
|
||||
int lineno = 0;
|
||||
int error = 0;
|
||||
|
||||
#if !INI_USE_STACK
|
||||
line = (char*)malloc(INI_MAX_LINE);
|
||||
if (!line) {
|
||||
return -2;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Scan through stream line by line */
|
||||
while (reader(line, INI_MAX_LINE, stream) != NULL) {
|
||||
lineno++;
|
||||
|
||||
start = line;
|
||||
#if INI_ALLOW_BOM
|
||||
if (lineno == 1 && (unsigned char)start[0] == 0xEF &&
|
||||
(unsigned char)start[1] == 0xBB &&
|
||||
(unsigned char)start[2] == 0xBF) {
|
||||
start += 3;
|
||||
}
|
||||
#endif
|
||||
start = lskip(rstrip(start));
|
||||
|
||||
if (*start == ';' || *start == '#') {
|
||||
/* Per Python configparser, allow both ; and # comments at the
|
||||
start of a line */
|
||||
}
|
||||
#if INI_ALLOW_MULTILINE
|
||||
else if (*prev_name && *start && start > line) {
|
||||
/* Non-blank line with leading whitespace, treat as continuation
|
||||
of previous name's value (as per Python configparser). */
|
||||
if (!handler(user, section, prev_name, start) && !error)
|
||||
error = lineno;
|
||||
}
|
||||
#endif
|
||||
else if (*start == '[') {
|
||||
/* A "[section]" line */
|
||||
end = find_chars_or_comment(start + 1, "]");
|
||||
if (*end == ']') {
|
||||
*end = '\0';
|
||||
strncpy0(section, start + 1, sizeof(section));
|
||||
*prev_name = '\0';
|
||||
}
|
||||
else if (!error) {
|
||||
/* No ']' found on section line */
|
||||
error = lineno;
|
||||
}
|
||||
}
|
||||
else if (*start) {
|
||||
/* Not a comment, must be a name[=:]value pair */
|
||||
end = find_chars_or_comment(start, "=:");
|
||||
if (*end == '=' || *end == ':') {
|
||||
*end = '\0';
|
||||
name = rstrip(start);
|
||||
value = lskip(end + 1);
|
||||
#if INI_ALLOW_INLINE_COMMENTS
|
||||
end = find_chars_or_comment(value, NULL);
|
||||
if (*end)
|
||||
*end = '\0';
|
||||
#endif
|
||||
rstrip(value);
|
||||
|
||||
/* Valid name[=:]value pair found, call handler */
|
||||
strncpy0(prev_name, name, sizeof(prev_name));
|
||||
if (!handler(user, section, name, value) && !error)
|
||||
error = lineno;
|
||||
memset(value, 0, strlen(value));
|
||||
}
|
||||
else if (!error) {
|
||||
/* No '=' or ':' found on name[=:]value line */
|
||||
error = lineno;
|
||||
}
|
||||
}
|
||||
|
||||
#if INI_STOP_ON_FIRST_ERROR
|
||||
if (error)
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !INI_USE_STACK
|
||||
free(line);
|
||||
#endif
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
/* See documentation in header file. */
|
||||
int ini_parse_file(FILE* file, ini_handler handler, void* user)
|
||||
{
|
||||
return ini_parse_stream((ini_reader)fgets, file, handler, user);
|
||||
}
|
||||
|
||||
/* See documentation in header file. */
|
||||
int ini_parse(const char* filename, ini_handler handler, void* user)
|
||||
{
|
||||
FILE* file;
|
||||
int error;
|
||||
|
||||
file = fopen(filename, "r");
|
||||
if (!file)
|
||||
return -1;
|
||||
error = ini_parse_file(file, handler, user);
|
||||
fclose(file);
|
||||
return error;
|
||||
}
|
14
rootston/main.c
Normal file
14
rootston/main.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include <wayland-server.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "rootston/config.h"
|
||||
#include "rootston/server.h"
|
||||
|
||||
struct rootston root = { 0 };
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
root.config = parse_args(argc, argv);
|
||||
root.wl_display = wl_display_create();
|
||||
root.wl_event_loop = wl_display_get_event_loop(root.wl_display);
|
||||
wl_display_init_shm(root.wl_display);
|
||||
return 0;
|
||||
}
|
7
rootston/meson.build
Normal file
7
rootston/meson.build
Normal file
|
@ -0,0 +1,7 @@
|
|||
executable(
|
||||
'rooston', [
|
||||
'main.c',
|
||||
'config.c',
|
||||
'ini.c',
|
||||
], dependencies: wlroots
|
||||
)
|
Loading…
Reference in a new issue