commit: 2432e695a0c7fa8d450ccd7c6d67735c05edb4f4
parent 29896a2e0f8fe42564d4eb949d6e874b69fa3a56
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Wed, 2 Dec 2020 05:08:24 +0100
extract keybinding commands to commands.c
Diffstat:
M | Makefile | 11 | +++-------- |
M | README | 2 | +- |
A | commands.c | 68 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
M | inaban.c | 62 | ++------------------------------------------------------------ |
M | inaban.h | 6 | ++++-- |
5 files changed, 78 insertions(+), 71 deletions(-)
diff --git a/Makefile b/Makefile
@@ -19,6 +19,7 @@ PKGCONFIG ?= pkg-config
DEPS = xkbcommon wlroots wayland-server
EXE = inaban
TRANS =
+SRC = commands.c inaban.c
CDEPS = -DDATADIR=\"$(DATADIR)\" -DPACKAGE=\"$(PACKAGE)\" -D_POSIX_C_SOURCE=200809L -DWLR_USE_UNSTABLE -I.
CDEPS += `pkg-config --cflags $(DEPS)`
@@ -29,14 +30,8 @@ WAYLAND_SCANNER=`pkg-config --variable=wayland_scanner wayland-scanner`
all: xdg-shell-protocol.c $(EXE) $(TRANS)
-inaban: inaban.c inaban.h config.h
- $(CC) -std=c99 $(CFLAGS) $(CDEPS) -o $@ $< $(LDFLAGS) $(LIBS)
-
-.c:
- $(CC) -std=c99 $(CFLAGS) $(CDEPS) -o $@ $< $(LDFLAGS) $(LIBS)
-
-.c.o:
- $(CC) -std=c99 $(CFLAGS) $(CDEPS) -c -o $@ $<
+inaban: $(SRC) inaban.h config.h
+ $(CC) -std=c99 $(CFLAGS) $(CDEPS) -o $@ $(SRC) $(LDFLAGS) $(LIBS)
xdg-shell-protocol.h:
$(WAYLAND_SCANNER) server-header $(WAYLAND_PROTOCOLS)/stable/xdg-shell/xdg-shell.xml $@
diff --git a/README b/README
@@ -26,4 +26,4 @@ The usual `make ; make install` works. Running inaban as root (setuid included)
- Tiling should be powerful (like XMonad) yet simple (unlike i3)
## Non-Goals
-- XWayland as anything but a separated Wayland client (would recommend cage or rootston for this)
+- XWayland as anything but a separated Wayland client (would recommend cage for this)
diff --git a/commands.c b/commands.c
@@ -0,0 +1,68 @@
+// Copyright 2019-2020 Haelwenn (lanodan) Monnier <contact+inaban@hacktivis.me>
+// SPDX-License-Identifier: BSD-3-Clause
+
+#include "inaban.h"
+
+#include <stdlib.h>
+#include <unistd.h> /* fork(), execvp() */
+
+// defined in inaban.c
+extern struct inaban_server server;
+
+void
+spawn(const Arg *arg)
+{
+ if(fork() == 0)
+ {
+ setsid();
+ execvp(((char **)arg->v)[0], (char **)arg->v);
+ fprintf(stderr, "execvp %s", ((char **)arg->v)[0]);
+ perror(" failed");
+ exit(EXIT_SUCCESS);
+ }
+}
+
+void
+focus_view(struct inaban_view *view, struct wlr_surface *surface)
+{
+ /* Note: this function only deals with keyboard focus. */
+ if(view == NULL) return;
+ struct inaban_server *server = view->server;
+ struct wlr_seat *seat = server->seat;
+ struct wlr_surface *prev_surface = seat->keyboard_state.focused_surface;
+ if(prev_surface == surface) return; /* Don't re-focus an already focused surface. */
+ if(prev_surface)
+ {
+ /*
+ * Deactivate the previously focused surface. This lets the client know
+ * it no longer has focus and the client will repaint accordingly, e.g.
+ * stop displaying a caret.
+ */
+ struct wlr_xdg_surface *previous =
+ wlr_xdg_surface_from_wlr_surface(seat->keyboard_state.focused_surface);
+ wlr_xdg_toplevel_set_activated(previous, false);
+ }
+ struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat);
+ /* Move the view to the front */
+ wl_list_remove(&view->link);
+ wl_list_insert(&server->views, &view->link);
+ /* Activate the new surface */
+ wlr_xdg_toplevel_set_activated(view->xdg_surface, true);
+ /*
+ * Tell the seat to have the keyboard enter this surface. wlroots will keep
+ * track of this and automatically send key events to the appropriate
+ * clients without additional work on your part.
+ */
+ wlr_seat_keyboard_notify_enter(seat,
+ view->xdg_surface->surface,
+ keyboard->keycodes,
+ keyboard->num_keycodes,
+ &keyboard->modifiers);
+}
+
+void
+quit(const Arg *arg)
+{
+ (void)arg;
+ wl_display_terminate(server.wl_display);
+}
diff --git a/inaban.c b/inaban.c
@@ -18,57 +18,6 @@
struct inaban_server server = {0};
-void
-spawn(const Arg *arg)
-{
- if(fork() == 0)
- {
- setsid();
- execvp(((char **)arg->v)[0], (char **)arg->v);
- fprintf(stderr, "execvp %s", ((char **)arg->v)[0]);
- perror(" failed");
- exit(EXIT_SUCCESS);
- }
-}
-
-static void
-focus_view(struct inaban_view *view, struct wlr_surface *surface)
-{
- /* Note: this function only deals with keyboard focus. */
- if(view == NULL) return;
- struct inaban_server *server = view->server;
- struct wlr_seat *seat = server->seat;
- struct wlr_surface *prev_surface = seat->keyboard_state.focused_surface;
- if(prev_surface == surface) return; /* Don't re-focus an already focused surface. */
- if(prev_surface)
- {
- /*
- * Deactivate the previously focused surface. This lets the client know
- * it no longer has focus and the client will repaint accordingly, e.g.
- * stop displaying a caret.
- */
- struct wlr_xdg_surface *previous =
- wlr_xdg_surface_from_wlr_surface(seat->keyboard_state.focused_surface);
- wlr_xdg_toplevel_set_activated(previous, false);
- }
- struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat);
- /* Move the view to the front */
- wl_list_remove(&view->link);
- wl_list_insert(&server->views, &view->link);
- /* Activate the new surface */
- wlr_xdg_toplevel_set_activated(view->xdg_surface, true);
- /*
- * Tell the seat to have the keyboard enter this surface. wlroots will keep
- * track of this and automatically send key events to the appropriate
- * clients without additional work on your part.
- */
- wlr_seat_keyboard_notify_enter(seat,
- view->xdg_surface->surface,
- keyboard->keycodes,
- keyboard->num_keycodes,
- &keyboard->modifiers);
-}
-
/* This event is raised when a modifier key, such as shift or alt, is pressed.
* We simply communicate this to the client. */
static void
@@ -336,7 +285,7 @@ server_cursor_button(struct wl_listener *listener, void *data)
/* Notify the client with pointer focus that a button press has occurred */
wlr_seat_pointer_notify_button(server->seat, event->time_msec, event->button, event->state);
double sx, sy;
- struct wlr_surface *surface;
+ struct wlr_surface *surface; // TODO: initialize
struct inaban_view *view =
desktop_view_at(server, server->cursor->x, server->cursor->y, &surface, &sx, &sy);
focus_view(view, surface); /* Focus that client if the button was _pressed_ */
@@ -592,13 +541,6 @@ server_new_xdg_surface(struct wl_listener *listener, void *data)
}
void
-quit(const Arg *arg)
-{
- (void)arg;
- wl_display_terminate(server.wl_display);
-}
-
-void
sigterm_handler(int signal)
{
(void)signal;
@@ -620,7 +562,7 @@ main(int argc, char *argv[])
struct wlr_server_decoration_manager *server_decoration_manager = NULL;
- if((getuid()*geteuid()*getgid()*getegid()) == 0)
+ if((getuid() * geteuid() * getgid() * getegid()) == 0)
{
wlr_log(WLR_ERROR, "running as root, refusing to continue");
return 1;
diff --git a/inaban.h b/inaban.h
@@ -1,4 +1,4 @@
-// Copyright 2019 Haelwenn (lanodan) Monnier
+// Copyright 2019-2020 Haelwenn (lanodan) Monnier
// Distributed under the terms of the BSD License
// Based on wlroots's TinyWL which is distributed under CC0
#ifndef INABAN_H
@@ -93,7 +93,8 @@ struct render_data
struct timespec *when;
};
-typedef union {
+typedef union
+{
int i;
unsigned int ui;
float f;
@@ -109,5 +110,6 @@ typedef struct
} Shortcut;
void spawn(const Arg *arg);
+void focus_view(struct inaban_view *view, struct wlr_surface *surface);
void quit(const Arg *arg);
#endif /* INABAN_H */