aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-02-12 00:47:41 -0700
committerJosh Rahm <joshuarahm@gmail.com>2024-02-12 00:47:41 -0700
commitd065af8c16bcb8ef54024c0f2082d827f83f37f9 (patch)
tree2f9bf7bab530858d48d42a305d7c030bebd79002
parentbfcdd442de82eb0e554b0e6b21aedad6615f4367 (diff)
downloadwetterhorn-d065af8c16bcb8ef54024c0f2082d827f83f37f9.tar.gz
wetterhorn-d065af8c16bcb8ef54024c0f2082d827f83f37f9.tar.bz2
wetterhorn-d065af8c16bcb8ef54024c0f2082d827f83f37f9.zip
add clang-format
-rw-r--r--.clang-format1
-rw-r--r--harness/include/plugin.h8
-rw-r--r--harness/src/plugin.c20
-rw-r--r--harness/src/wl.c117
-rw-r--r--src/harness_adapter.c4
5 files changed, 96 insertions, 54 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..1ef3556
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1 @@
+BreakBeforeBraces: Stroustrup
diff --git a/harness/include/plugin.h b/harness/include/plugin.h
index 7cee511..615c3db 100644
--- a/harness/include/plugin.h
+++ b/harness/include/plugin.h
@@ -91,9 +91,9 @@ typedef struct PLUGIN {
/*
* Handles a surface being mapped, unmapped or destroyed.
*/
- EXPORT(opqst_t (*plugin_handle_surface_map)(void* surface, opqst_t));
- EXPORT(opqst_t (*plugin_handle_surface_unmap)(void* surface, opqst_t));
- EXPORT(opqst_t (*plugin_handle_surface_destroy)(void* surface, opqst_t));
+ EXPORT(opqst_t (*plugin_handle_surface_map)(void *surface, opqst_t));
+ EXPORT(opqst_t (*plugin_handle_surface_unmap)(void *surface, opqst_t));
+ EXPORT(opqst_t (*plugin_handle_surface_destroy)(void *surface, opqst_t));
} plugin_t;
@@ -107,7 +107,7 @@ int load_plugin_from_dl(dlhandle_t library, plugin_t *out);
* This function will call dlclose on the plugin's library handle if it is not
* the same as 'library'.
*/
-int plugin_hot_reload(int argc, char **argv, const char* filepath,
+int plugin_hot_reload(int argc, char **argv, const char *filepath,
plugin_t *plugin);
/* Reads a plugin from a filename. */
diff --git a/harness/src/plugin.c b/harness/src/plugin.c
index 6344f4a..bb32b02 100644
--- a/harness/src/plugin.c
+++ b/harness/src/plugin.c
@@ -5,13 +5,15 @@
#include <stdio.h>
#include <stdlib.h>
-static void shx(uint8_t *state, uint32_t sz) {
+static void shx(uint8_t *state, uint32_t sz)
+{
uint32_t i = 0;
while (i < sz) {
for (int j = 0; j < 16; ++j) {
if (i < sz) {
printf("%02x ", (unsigned int)state[i]);
- } else {
+ }
+ else {
printf(" ");
}
++i;
@@ -25,10 +27,12 @@ static void shx(uint8_t *state, uint32_t sz) {
if (i < sz) {
if (isprint(state[i]) && !isspace(state[i])) {
printf("%c", state[i]);
- } else {
+ }
+ else {
printf(".");
}
- } else {
+ }
+ else {
printf(" ");
}
++i;
@@ -37,7 +41,8 @@ static void shx(uint8_t *state, uint32_t sz) {
}
}
-int load_plugin_from_file(const char *filename, plugin_t *plugin) {
+int load_plugin_from_file(const char *filename, plugin_t *plugin)
+{
dlhandle_t lib = dlopen(filename, RTLD_LAZY);
if (!lib) {
@@ -49,8 +54,9 @@ int load_plugin_from_file(const char *filename, plugin_t *plugin) {
return load_plugin_from_dl(lib, plugin);
}
-int plugin_hot_reload(int argc, char **argv, const char* filepath,
- plugin_t *plugin) {
+int plugin_hot_reload(int argc, char **argv, const char *filepath,
+ plugin_t *plugin)
+{
int ec = 0;
uint32_t sz = 0;
uint8_t *marshalled_state = NULL;
diff --git a/harness/src/wl.c b/harness/src/wl.c
index 5fa1395..7e89c21 100644
--- a/harness/src/wl.c
+++ b/harness/src/wl.c
@@ -115,7 +115,8 @@ struct tinywl_keyboard {
struct wl_listener key;
};
-static void focus_view(struct tinywl_view *view, struct wlr_surface *surface) {
+static void focus_view(struct tinywl_view *view, struct wlr_surface *surface)
+{
/* Note: this function only deals with keyboard focus. */
if (view == NULL) {
return;
@@ -153,8 +154,8 @@ static void focus_view(struct tinywl_view *view, struct wlr_surface *surface) {
&keyboard->modifiers);
}
-static void keyboard_handle_modifiers(struct wl_listener *listener,
- void *data) {
+static void keyboard_handle_modifiers(struct wl_listener *listener, void *data)
+{
/* This event is raised when a modifier key, such as shift or alt, is
* pressed. We simply communicate this to the client. */
struct tinywl_keyboard *keyboard =
@@ -171,7 +172,8 @@ static void keyboard_handle_modifiers(struct wl_listener *listener,
&keyboard->device->keyboard->modifiers);
}
-static bool handle_keybinding(struct tinywl_server *server, xkb_keysym_t sym) {
+static bool handle_keybinding(struct tinywl_server *server, xkb_keysym_t sym)
+{
plugin_call_update_state(server->plugin, plugin_handle_keybinding, sym);
/*
* Here we handle compositor keybindings. This is when the compositor is
@@ -209,7 +211,8 @@ static bool handle_keybinding(struct tinywl_server *server, xkb_keysym_t sym) {
return true;
}
-static void keyboard_handle_key(struct wl_listener *listener, void *data) {
+static void keyboard_handle_key(struct wl_listener *listener, void *data)
+{
/* This event is raised when a key is pressed or released. */
struct tinywl_keyboard *keyboard = wl_container_of(listener, keyboard, key);
struct tinywl_server *server = keyboard->server;
@@ -243,7 +246,8 @@ static void keyboard_handle_key(struct wl_listener *listener, void *data) {
}
static void server_new_keyboard(struct tinywl_server *server,
- struct wlr_input_device *device) {
+ struct wlr_input_device *device)
+{
struct tinywl_keyboard *keyboard = calloc(1, sizeof(struct tinywl_keyboard));
keyboard->server = server;
keyboard->device = device;
@@ -272,7 +276,8 @@ static void server_new_keyboard(struct tinywl_server *server,
}
static void server_new_pointer(struct tinywl_server *server,
- struct wlr_input_device *device) {
+ struct wlr_input_device *device)
+{
/* We don't do anything special with pointers. All of our pointer handling
* is proxied through wlr_cursor. On another compositor, you might take this
* opportunity to do libinput configuration on the device to set
@@ -280,7 +285,8 @@ static void server_new_pointer(struct tinywl_server *server,
wlr_cursor_attach_input_device(server->cursor, device);
}
-static void server_new_input(struct wl_listener *listener, void *data) {
+static void server_new_input(struct wl_listener *listener, void *data)
+{
/* This event is raised by the backend when a new input device becomes
* available. */
struct tinywl_server *server = wl_container_of(listener, server, new_input);
@@ -305,7 +311,8 @@ static void server_new_input(struct wl_listener *listener, void *data) {
wlr_seat_set_capabilities(server->seat, caps);
}
-static void seat_request_cursor(struct wl_listener *listener, void *data) {
+static void seat_request_cursor(struct wl_listener *listener, void *data)
+{
struct tinywl_server *server =
wl_container_of(listener, server, request_cursor);
/* This event is raised by the seat when a client provides a cursor image */
@@ -324,8 +331,8 @@ static void seat_request_cursor(struct wl_listener *listener, void *data) {
}
}
-static void seat_request_set_selection(struct wl_listener *listener,
- void *data) {
+static void seat_request_set_selection(struct wl_listener *listener, void *data)
+{
/* This event is raised by the seat when a client wants to set the selection,
* usually when the user copies something. wlroots allows compositors to
* ignore such requests if they so choose, but in tinywl we always honor
@@ -337,7 +344,8 @@ static void seat_request_set_selection(struct wl_listener *listener,
}
static bool view_at(struct tinywl_view *view, double lx, double ly,
- struct wlr_surface **surface, double *sx, double *sy) {
+ struct wlr_surface **surface, double *sx, double *sy)
+{
/*
* XDG toplevels may have nested surfaces, such as popup windows for context
* menus or tooltips. This function tests if any of those are underneath the
@@ -366,11 +374,13 @@ static bool view_at(struct tinywl_view *view, double lx, double ly,
static struct tinywl_view *desktop_view_at(struct tinywl_server *server,
double lx, double ly,
struct wlr_surface **surface,
- double *sx, double *sy) {
+ double *sx, double *sy)
+{
/* This iterates over all of our surfaces and attempts to find one under the
* cursor. This relies on server->views being ordered from top-to-bottom. */
struct tinywl_view *view;
- wl_list_for_each(view, &server->views, link) {
+ wl_list_for_each(view, &server->views, link)
+ {
if (view_at(view, lx, ly, surface, sx, sy)) {
return view;
}
@@ -378,13 +388,15 @@ static struct tinywl_view *desktop_view_at(struct tinywl_server *server,
return NULL;
}
-static void process_cursor_move(struct tinywl_server *server, uint32_t time) {
+static void process_cursor_move(struct tinywl_server *server, uint32_t time)
+{
/* Move the grabbed view to the new position. */
server->grabbed_view->x = server->cursor->x - server->grab_x;
server->grabbed_view->y = server->cursor->y - server->grab_y;
}
-static void process_cursor_resize(struct tinywl_server *server, uint32_t time) {
+static void process_cursor_resize(struct tinywl_server *server, uint32_t time)
+{
/*
* Resizing the grabbed view can be a little bit complicated, because we
* could be resizing from any corner or edge. This not only resizes the view
@@ -408,7 +420,8 @@ static void process_cursor_resize(struct tinywl_server *server, uint32_t time) {
if (new_top >= new_bottom) {
new_top = new_bottom - 1;
}
- } else if (server->resize_edges & WLR_EDGE_BOTTOM) {
+ }
+ else if (server->resize_edges & WLR_EDGE_BOTTOM) {
new_bottom = border_y;
if (new_bottom <= new_top) {
new_bottom = new_top + 1;
@@ -419,7 +432,8 @@ static void process_cursor_resize(struct tinywl_server *server, uint32_t time) {
if (new_left >= new_right) {
new_left = new_right - 1;
}
- } else if (server->resize_edges & WLR_EDGE_RIGHT) {
+ }
+ else if (server->resize_edges & WLR_EDGE_RIGHT) {
new_right = border_x;
if (new_right <= new_left) {
new_right = new_left + 1;
@@ -436,12 +450,14 @@ static void process_cursor_resize(struct tinywl_server *server, uint32_t time) {
wlr_xdg_toplevel_set_size(view->xdg_surface, new_width, new_height);
}
-static void process_cursor_motion(struct tinywl_server *server, uint32_t time) {
+static void process_cursor_motion(struct tinywl_server *server, uint32_t time)
+{
/* If the mode is non-passthrough, delegate to those functions. */
if (server->cursor_mode == TINYWL_CURSOR_MOVE) {
process_cursor_move(server, time);
return;
- } else if (server->cursor_mode == TINYWL_CURSOR_RESIZE) {
+ }
+ else if (server->cursor_mode == TINYWL_CURSOR_RESIZE) {
process_cursor_resize(server, time);
return;
}
@@ -473,14 +489,16 @@ static void process_cursor_motion(struct tinywl_server *server, uint32_t time) {
*/
wlr_seat_pointer_notify_enter(seat, surface, sx, sy);
wlr_seat_pointer_notify_motion(seat, time, sx, sy);
- } else {
+ }
+ else {
/* Clear pointer focus so future button events and such are not sent to
* the last client to have the cursor over it. */
wlr_seat_pointer_clear_focus(seat);
}
}
-static void server_cursor_motion(struct wl_listener *listener, void *data) {
+static void server_cursor_motion(struct wl_listener *listener, void *data)
+{
/* This event is forwarded by the cursor when a pointer emits a _relative_
* pointer motion event (i.e. a delta) */
struct tinywl_server *server =
@@ -497,7 +515,8 @@ static void server_cursor_motion(struct wl_listener *listener, void *data) {
}
static void server_cursor_motion_absolute(struct wl_listener *listener,
- void *data) {
+ void *data)
+{
/* This event is forwarded by the cursor when a pointer emits an _absolute_
* motion event, from 0..1 on each axis. This happens, for example, when
* wlroots is running under a Wayland window rather than KMS+DRM, and you
@@ -511,7 +530,8 @@ static void server_cursor_motion_absolute(struct wl_listener *listener,
process_cursor_motion(server, event->time_msec);
}
-static void server_cursor_button(struct wl_listener *listener, void *data) {
+static void server_cursor_button(struct wl_listener *listener, void *data)
+{
/* This event is forwarded by the cursor when a pointer emits a button
* event. */
struct tinywl_server *server =
@@ -527,13 +547,15 @@ static void server_cursor_button(struct wl_listener *listener, void *data) {
if (event->state == WLR_BUTTON_RELEASED) {
/* If you released any buttons, we exit interactive move/resize mode. */
server->cursor_mode = TINYWL_CURSOR_PASSTHROUGH;
- } else {
+ }
+ else {
/* Focus that client if the button was _pressed_ */
focus_view(view, surface);
}
}
-static void server_cursor_axis(struct wl_listener *listener, void *data) {
+static void server_cursor_axis(struct wl_listener *listener, void *data)
+{
/* This event is forwarded by the cursor when a pointer emits an axis event,
* for example when you move the scroll wheel. */
struct tinywl_server *server = wl_container_of(listener, server, cursor_axis);
@@ -544,7 +566,8 @@ static void server_cursor_axis(struct wl_listener *listener, void *data) {
event->delta_discrete, event->source);
}
-static void server_cursor_frame(struct wl_listener *listener, void *data) {
+static void server_cursor_frame(struct wl_listener *listener, void *data)
+{
/* This event is forwarded by the cursor when a pointer emits an frame
* event. Frame events are sent after regular pointer events to group
* multiple events together. For instance, two axis events may happen at the
@@ -565,7 +588,8 @@ struct render_data {
};
static void render_surface(struct wlr_surface *surface, int sx, int sy,
- void *data) {
+ void *data)
+{
/* This function is called for every surface that needs to be rendered. */
struct render_data *rdata = data;
struct tinywl_view *view = rdata->view;
@@ -624,7 +648,8 @@ static void render_surface(struct wlr_surface *surface, int sx, int sy,
wlr_surface_send_frame_done(surface, rdata->when);
}
-static void output_frame(struct wl_listener *listener, void *data) {
+static void output_frame(struct wl_listener *listener, void *data)
+{
/* This function is called every time an output is ready to display a frame,
* generally at the output's refresh rate (e.g. 60Hz). */
struct tinywl_output *output = wl_container_of(listener, output, frame);
@@ -649,7 +674,8 @@ static void output_frame(struct wl_listener *listener, void *data) {
/* Each subsequent window we render is rendered on top of the last. Because
* our view list is ordered front-to-back, we iterate over it backwards. */
struct tinywl_view *view;
- wl_list_for_each_reverse(view, &output->server->views, link) {
+ wl_list_for_each_reverse(view, &output->server->views, link)
+ {
if (!view->mapped) {
/* An unmapped view should not be rendered. */
continue;
@@ -679,7 +705,8 @@ static void output_frame(struct wl_listener *listener, void *data) {
wlr_output_commit(output->wlr_output);
}
-static void server_new_output(struct wl_listener *listener, void *data) {
+static void server_new_output(struct wl_listener *listener, void *data)
+{
/* This event is raised by the backend when a new output (aka a display or
* monitor) becomes available. */
struct tinywl_server *server = wl_container_of(listener, server, new_output);
@@ -720,7 +747,8 @@ static void server_new_output(struct wl_listener *listener, void *data) {
wlr_output_layout_add_auto(server->output_layout, wlr_output);
}
-static void xdg_surface_map(struct wl_listener *listener, void *data) {
+static void xdg_surface_map(struct wl_listener *listener, void *data)
+{
/* Called when the surface is mapped, or ready to display on-screen. */
struct tinywl_view *view = wl_container_of(listener, view, map);
plugin_call_update_state(view->server->plugin, plugin_handle_surface_map,
@@ -729,7 +757,8 @@ static void xdg_surface_map(struct wl_listener *listener, void *data) {
focus_view(view, view->xdg_surface->surface);
}
-static void xdg_surface_unmap(struct wl_listener *listener, void *data) {
+static void xdg_surface_unmap(struct wl_listener *listener, void *data)
+{
/* Called when the surface is unmapped, and should no longer be shown. */
struct tinywl_view *view = wl_container_of(listener, view, unmap);
plugin_call_update_state(view->server->plugin, plugin_handle_surface_unmap,
@@ -737,7 +766,8 @@ static void xdg_surface_unmap(struct wl_listener *listener, void *data) {
view->mapped = false;
}
-static void xdg_surface_destroy(struct wl_listener *listener, void *data) {
+static void xdg_surface_destroy(struct wl_listener *listener, void *data)
+{
/* Called when the surface is destroyed and should never be shown again. */
struct tinywl_view *view = wl_container_of(listener, view, destroy);
plugin_call_update_state(view->server->plugin, plugin_handle_surface_destroy,
@@ -747,7 +777,8 @@ static void xdg_surface_destroy(struct wl_listener *listener, void *data) {
}
static void begin_interactive(struct tinywl_view *view,
- enum tinywl_cursor_mode mode, uint32_t edges) {
+ enum tinywl_cursor_mode mode, uint32_t edges)
+{
/* This function sets up an interactive move or resize operation, where the
* compositor stops propegating pointer events to clients and instead
* consumes them itself, to move or resize windows. */
@@ -764,7 +795,8 @@ static void begin_interactive(struct tinywl_view *view,
if (mode == TINYWL_CURSOR_MOVE) {
server->grab_x = server->cursor->x - view->x;
server->grab_y = server->cursor->y - view->y;
- } else {
+ }
+ else {
struct wlr_box geo_box;
wlr_xdg_surface_get_geometry(view->xdg_surface, &geo_box);
@@ -783,8 +815,8 @@ static void begin_interactive(struct tinywl_view *view,
}
}
-static void xdg_toplevel_request_move(struct wl_listener *listener,
- void *data) {
+static void xdg_toplevel_request_move(struct wl_listener *listener, void *data)
+{
/* This event is raised when a client would like to begin an interactive
* move, typically because the user clicked on their client-side
* decorations. Note that a more sophisticated compositor should check the
@@ -795,7 +827,8 @@ static void xdg_toplevel_request_move(struct wl_listener *listener,
}
static void xdg_toplevel_request_resize(struct wl_listener *listener,
- void *data) {
+ void *data)
+{
/* This event is raised when a client would like to begin an interactive
* resize, typically because the user clicked on their client-side
* decorations. Note that a more sophisticated compositor should check the
@@ -806,7 +839,8 @@ static void xdg_toplevel_request_resize(struct wl_listener *listener,
begin_interactive(view, TINYWL_CURSOR_RESIZE, event->edges);
}
-static void server_new_xdg_surface(struct wl_listener *listener, void *data) {
+static void server_new_xdg_surface(struct wl_listener *listener, void *data)
+{
/* This event is raised when wlr_xdg_shell receives a new xdg surface from a
* client, either a toplevel (application window) or popup. */
struct tinywl_server *server =
@@ -840,7 +874,8 @@ static void server_new_xdg_surface(struct wl_listener *listener, void *data) {
wl_list_insert(&server->views, &view->link);
}
-int main(int argc, char *argv[]) {
+int main(int argc, char *argv[])
+{
wlr_log_init(WLR_DEBUG, NULL);
char *startup_cmd = NULL;
char *plugin = NULL;
diff --git a/src/harness_adapter.c b/src/harness_adapter.c
index 3223251..9684921 100644
--- a/src/harness_adapter.c
+++ b/src/harness_adapter.c
@@ -21,8 +21,8 @@ static const char msg[] =
"That will allow you to see how this compositor works in all its glory!\n";
static const int msg_sz = sizeof(msg);
-
-__attribute__((naked)) void _start() {
+__attribute__((naked)) void _start()
+{
// Make system call to print the message
asm(