Cleanups and omissions

This commit is contained in:
Keith Bowes 2022-03-08 19:23:52 -05:00
parent 553096a611
commit df38ee39e0
14 changed files with 85 additions and 63 deletions

View file

@ -17,7 +17,7 @@ If you already have your own pull request habits, feel free to use them. If you
don't, however, allow me to make a suggestion: feature branches pulled from don't, however, allow me to make a suggestion: feature branches pulled from
upstream. Try this: upstream. Try this:
1. Fork waybox 1. Fork Waybox
2. `git clone https://github.com/username/waybox && cd waybox` 2. `git clone https://github.com/username/waybox && cd waybox`
3. `git remote add upstream https://github.com/wizbright/waybox` 3. `git remote add upstream https://github.com/wizbright/waybox`
@ -87,7 +87,7 @@ process is:
## Style Reference ## Style Reference
waybox is written in C with a style similar to the [kernel Waybox is written in C with a style similar to the [kernel
style](https://www.kernel.org/doc/Documentation/process/coding-style.rst), but style](https://www.kernel.org/doc/Documentation/process/coding-style.rst), but
with a few notable differences. with a few notable differences.

View file

@ -21,7 +21,7 @@
#export ECORE_IMF_MODULE=uim #export ECORE_IMF_MODULE=uim
# Current compositor. Needed for Wayland security negotiation. # Current compositor. Needed for Wayland security negotiation.
export XDG_CURRENT_DESKTOP=waybox export XDG_CURRENT_DESKTOP=Waybox
export XDG_SESSION_TYPE=wayland export XDG_SESSION_TYPE=wayland
# Make sure to run the X initialization if started through a display manager # Make sure to run the X initialization if started through a display manager

View file

@ -43,14 +43,23 @@
<!-- Keybindings for window switching --> <!-- Keybindings for window switching -->
<keybind key="A-Tab"> <keybind key="A-Tab">
<action name="NextWindow"> <action name="NextWindow">
<finalactions>
<action name="Unshade"/>
</finalactions>
</action> </action>
</keybind> </keybind>
<keybind key="A-S-ISO_Left_Tab"> <keybind key="A-S-ISO_Left_Tab">
<action name="PreviousWindow"> <action name="PreviousWindow">
<finalactions>
<action name="Unshade"/>
</finalactions>
</action> </action>
</keybind> </keybind>
<keybind key="C-A-Tab"> <keybind key="C-A-Tab">
<action name="NextWindow"> <action name="NextWindow">
<finalactions>
<action name="Unshade"/>
</finalactions>
</action> </action>
</keybind> </keybind>
<!-- Keybindings for running applications --> <!-- Keybindings for running applications -->
@ -64,6 +73,11 @@
<execute>grim "$(xdg-user-dir PICTURES)/$(date +'%Y-%m-%d-%H%M%S_grim_fs.png')"</execute> <execute>grim "$(xdg-user-dir PICTURES)/$(date +'%Y-%m-%d-%H%M%S_grim_fs.png')"</execute>
</action> </action>
</keybind> </keybind>
<keybind key="A-Sys_Req">
<action name="Execute">
<execute>grim -g "$(slurp -d)" "$(xdg-user-dir PICTURES)/$(date +'%Y-%m-%d-%H%M%S_grim_sel.png')"</execute>
</action>
</keybind>
<keybind key="A-F2"> <keybind key="A-F2">
<action name="Execute"> <action name="Execute">
<execute>obrun l</execute> <execute>obrun l</execute>

View file

@ -4,11 +4,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/render/wlr_texture.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_xdg_output_v1.h>
#include "waybox/server.h" #include "waybox/server.h"
struct wb_output { struct wb_output {

View file

@ -1,13 +1,8 @@
#ifndef _WB_SEAT_H #ifndef _WB_SEAT_H
#define _WB_SEAT_H #define _WB_SEAT_H
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_primary_selection.h>
#include <wlr/types/wlr_primary_selection_v1.h>
#include <wlr/types/wlr_seat.h> #include <wlr/types/wlr_seat.h>
struct wb_server;
struct wb_seat { struct wb_seat {
struct wlr_seat *seat; struct wlr_seat *seat;
@ -24,6 +19,7 @@ struct wb_keyboard {
struct wb_server *server; struct wb_server *server;
struct wlr_input_device *device; struct wlr_input_device *device;
struct wl_listener destroy;
struct wl_listener modifiers; struct wl_listener modifiers;
struct wl_listener key; struct wl_listener key;
}; };

View file

@ -1,26 +1,27 @@
#ifndef _WB_SERVER_H #ifndef _WB_SERVER_H
#define _WB_SERVER_H #define _WB_SERVER_H
#include <stdio.h>
#define MAX(a, b) ((a > b) ? (a) : (b)) #define MAX(a, b) ((a > b) ? (a) : (b))
#define MIN(a, b) ((a < b) ? (a) : (b)) #define MIN(a, b) ((a < b) ? (a) : (b))
#define TITLEBAR_HEIGHT 8 /* TODO: Get this from the theme */
#include <wlr/version.h> #include <wlr/version.h>
#define WLR_CHECK_VERSION(major, minor, micro) (WLR_VERSION_NUM >= ((major << 16) | (minor << 8) | (micro))) #define WLR_CHECK_VERSION(major, minor, micro) (WLR_VERSION_NUM >= ((major << 16) | (minor << 8) | (micro)))
#include <wlr/backend.h> #include <wlr/backend.h>
#include <wlr/render/allocator.h> #include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
#include <wlr/render/wlr_texture.h>
#include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_data_device.h> #include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_idle.h>
#include <wlr/types/wlr_screencopy_v1.h>
#include <wlr/types/wlr_gamma_control_v1.h> #include <wlr/types/wlr_gamma_control_v1.h>
#include <wlr/types/wlr_idle.h>
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_screencopy_v1.h>
#if WLR_CHECK_VERSION(0, 16, 0) #if WLR_CHECK_VERSION(0, 16, 0)
#include <wlr/types/wlr_subcompositor.h> #include <wlr/types/wlr_subcompositor.h>
#endif #endif
#include <wlr/types/wlr_xdg_output_v1.h>
#include <wlr/types/wlr_xdg_shell.h> #include <wlr/types/wlr_xdg_shell.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
@ -77,8 +78,8 @@ struct wb_server {
struct wl_list outputs; /* wb_output::link */ struct wl_list outputs; /* wb_output::link */
}; };
bool wb_create_backend(struct wb_server* server); bool wb_create_backend(struct wb_server *server);
bool wb_start_server(struct wb_server* server); bool wb_start_server(struct wb_server *server);
bool wb_terminate(struct wb_server* server); bool wb_terminate(struct wb_server *server);
#endif /* server.h */ #endif /* server.h */

View file

@ -4,16 +4,16 @@
#include "waybox/server.h" #include "waybox/server.h"
enum action_type { enum action_type {
ACTION_EXECUTE = 1<<0, ACTION_EXIT = 1 << 0,
ACTION_EXIT = 1<<1, ACTION_NEXT_WINDOW = 1 << 1,
ACTION_NEXT_WINDOW = 1<<2, ACTION_EXECUTE = 1 << 2,
ACTION_PREVIOUS_WINDOW = 1<<3, ACTION_PREVIOUS_WINDOW = 1 << 3,
ACTION_CLOSE = 1<<4, ACTION_CLOSE = 1 << 4,
ACTION_RECONFIGURE = 1<<5, ACTION_RECONFIGURE = 1 << 5,
ACTION_ICONIFY = 1<<6, ACTION_TOGGLE_MAXIMIZE = 1 << 6,
ACTION_TOGGLE_MAXIMIZE = 1<<7, ACTION_ICONIFY = 1 << 7,
ACTION_SHADE = 1<<8, ACTION_SHADE = 1 << 8,
ACTION_UNSHADE = 1<<9, ACTION_UNSHADE = 1 << 9,
}; };
struct wb_config { struct wb_config {

View file

@ -1,13 +1,12 @@
#include <stdlib.h>
#include "waybox/cursor.h" #include "waybox/cursor.h"
#include "waybox/xdg_shell.h" #include "waybox/xdg_shell.h"
static void process_cursor_move(struct wb_server *server) { static void process_cursor_move(struct wb_server *server) {
/* Move the grabbed view to the new position. */ /* Move the grabbed view to the new position. */
struct wb_view *view = server->grabbed_view; struct wb_view *view = server->grabbed_view;
view->current_position.x = server->cursor->cursor->x - server->grab_x;
view->current_position.y = server->cursor->cursor->y - server->grab_y;
if (view->scene_node->parent->type == WLR_SCENE_NODE_ROOT) { if (view->scene_node->parent->type == WLR_SCENE_NODE_ROOT) {
view->current_position.x = server->cursor->cursor->x - server->grab_x;
view->current_position.y = server->cursor->cursor->y - server->grab_y;
wlr_scene_node_set_position(view->scene_node, wlr_scene_node_set_position(view->scene_node,
view->current_position.x, view->current_position.y); view->current_position.x, view->current_position.y);
} }

View file

@ -45,7 +45,7 @@ void assign_scene_descriptor(struct wlr_scene_node *node,
node->data = desc; node->data = desc;
} }
static void arrange_surface (struct wb_output *output, struct wlr_box *full_area, static void arrange_surface(struct wb_output *output, struct wlr_box *full_area,
struct wlr_box *usable_area, struct wlr_scene_node *scene_node) { struct wlr_box *usable_area, struct wlr_scene_node *scene_node) {
struct wlr_scene_node *node; struct wlr_scene_node *node;
wl_list_for_each(node, &scene_node->state.children, state.link) { wl_list_for_each(node, &scene_node->state.children, state.link) {
@ -75,24 +75,22 @@ void arrange_layers(struct wb_output *output) {
arrange_surface(output, &full_area, &usable_area, output->layers.shell_overlay); arrange_surface(output, &full_area, &usable_area, output->layers.shell_overlay);
} }
#if WLR_CHECK_VERSION(0, 16, 0)
static struct wlr_scene_node *wb_layer_get_scene(struct wb_output *output, static struct wlr_scene_node *wb_layer_get_scene(struct wb_output *output,
enum zwlr_layer_shell_v1_layer type) { enum zwlr_layer_shell_v1_layer type) {
switch (type) { switch (type) {
case ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND: case ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND:
return output->layers.shell_background; return output->layers.shell_background;
case ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM: case ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM:
return output->layers.shell_bottom; return output->layers.shell_bottom;
case ZWLR_LAYER_SHELL_V1_LAYER_TOP: case ZWLR_LAYER_SHELL_V1_LAYER_TOP:
return output->layers.shell_top; return output->layers.shell_top;
case ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY: case ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY:
return output->layers.shell_overlay; return output->layers.shell_overlay;
} }
/* Unreachable */ /* Unreachable */
return NULL; return NULL;
} }
#endif
static struct wb_layer_surface *wb_layer_surface_create( static struct wb_layer_surface *wb_layer_surface_create(
#if WLR_CHECK_VERSION(0, 16, 0) #if WLR_CHECK_VERSION(0, 16, 0)
@ -120,7 +118,6 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) {
return; return;
} }
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_layer_surface_v1 *layer_surface = surface->scene->layer_surface; struct wlr_layer_surface_v1 *layer_surface = surface->scene->layer_surface;
uint32_t committed = layer_surface->current.committed; uint32_t committed = layer_surface->current.committed;
@ -141,22 +138,19 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) {
wlr_surface_send_frame_done(layer_surface->surface, &now); wlr_surface_send_frame_done(layer_surface->surface, &now);
} }
if (surface->scene->layer_surface->current.layer != if (layer_surface->current.layer != ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND) {
ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND) {
wlr_scene_node_raise_to_top(output_layer); wlr_scene_node_raise_to_top(output_layer);
} }
if (layer_surface == surface->server->seat->focused_layer) { if (layer_surface == surface->server->seat->focused_layer) {
seat_focus_surface(surface->server->seat, layer_surface->surface); seat_focus_surface(surface->server->seat, layer_surface->surface);
} }
#endif
} }
static void handle_map(struct wl_listener *listener, void *data) { static void handle_map(struct wl_listener *listener, void *data) {
struct wb_layer_surface *surface = wl_container_of(listener, struct wb_layer_surface *surface = wl_container_of(listener,
surface, map); surface, map);
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_layer_surface_v1 *layer_surface = struct wlr_layer_surface_v1 *layer_surface =
surface->scene->layer_surface; surface->scene->layer_surface;
@ -173,19 +167,16 @@ static void handle_map(struct wl_listener *listener, void *data) {
} }
arrange_layers(surface->output); arrange_layers(surface->output);
} }
#endif
} }
static void handle_unmap(struct wl_listener *listener, void *data) { static void handle_unmap(struct wl_listener *listener, void *data) {
struct wb_layer_surface *surface = wl_container_of( struct wb_layer_surface *surface = wl_container_of(
listener, surface, unmap); listener, surface, unmap);
#if WLR_CHECK_VERSION(0, 16, 0)
struct wb_seat *seat = surface->server->seat; struct wb_seat *seat = surface->server->seat;
if (seat->focused_layer == surface->scene->layer_surface) { if (seat->focused_layer == surface->scene->layer_surface) {
seat_set_focus_layer(seat, NULL); seat_set_focus_layer(seat, NULL);
} }
#endif
struct wb_view *view = wl_container_of(surface->server->views.next, view, link); struct wb_view *view = wl_container_of(surface->server->views.next, view, link);
if (view) { if (view) {
@ -310,11 +301,9 @@ static void popup_handle_new_popup(struct wl_listener *listener, void *data) {
static void handle_new_popup(struct wl_listener *listener, void *data) { static void handle_new_popup(struct wl_listener *listener, void *data) {
struct wb_layer_surface *wb_layer_surface = struct wb_layer_surface *wb_layer_surface =
wl_container_of(listener, wb_layer_surface, new_popup); wl_container_of(listener, wb_layer_surface, new_popup);
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_xdg_popup *wlr_popup = data; struct wlr_xdg_popup *wlr_popup = data;
create_popup(wlr_popup, wb_layer_surface->scene->node); create_popup(wlr_popup, wb_layer_surface->scene->node);
#endif
} }
void handle_layer_shell_surface(struct wl_listener *listener, void *data) { void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
@ -333,10 +322,10 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
} }
#if WLR_CHECK_VERSION(0, 16, 0)
enum zwlr_layer_shell_v1_layer layer_type = layer_surface->pending.layer; enum zwlr_layer_shell_v1_layer layer_type = layer_surface->pending.layer;
struct wlr_scene_node *output_layer = wb_layer_get_scene( struct wlr_scene_node *output_layer = wb_layer_get_scene(
output, layer_type); output, layer_type);
#if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_scene_layer_surface_v1 *scene_surface = struct wlr_scene_layer_surface_v1 *scene_surface =
wlr_scene_layer_surface_v1_create(output_layer, layer_surface); wlr_scene_layer_surface_v1_create(output_layer, layer_surface);
if (!scene_surface) { if (!scene_surface) {
@ -348,6 +337,9 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
#else #else
struct wb_layer_surface *surface = struct wb_layer_surface *surface =
wb_layer_surface_create(layer_surface); wb_layer_surface_create(layer_surface);
surface->scene = calloc(1, sizeof(*surface->scene));
surface->scene->layer_surface = layer_surface;
surface->scene->node = output_layer;
#endif #endif
if (!surface) { if (!surface) {
wlr_layer_surface_v1_destroy(layer_surface); wlr_layer_surface_v1_destroy(layer_surface);

View file

@ -10,6 +10,11 @@ struct wb_layer_surface {
#if WLR_CHECK_VERSION(0, 16, 0) #if WLR_CHECK_VERSION(0, 16, 0)
struct wlr_scene_layer_surface_v1 *scene; struct wlr_scene_layer_surface_v1 *scene;
#else
struct {
struct wlr_layer_surface_v1 *layer_surface;
struct wlr_scene_node *node;
} *scene;
#endif #endif
bool mapped; bool mapped;

View file

@ -113,6 +113,7 @@ int main(int argc, char **argv) {
sigaction(SIGTERM, &sa, NULL); sigaction(SIGTERM, &sa, NULL);
sigaction(SIGUSR1, &sa, NULL); sigaction(SIGUSR1, &sa, NULL);
sigaction(SIGUSR2, &sa, NULL); sigaction(SIGUSR2, &sa, NULL);
wl_display_run(server.wl_display); wl_display_run(server.wl_display);
wb_terminate(&server); wb_terminate(&server);

View file

@ -33,9 +33,9 @@ void output_frame_notify(struct wl_listener *listener, void *data) {
void output_destroy_notify(struct wl_listener *listener, void *data) { void output_destroy_notify(struct wl_listener *listener, void *data) {
struct wb_output *output = wl_container_of(listener, output, destroy); struct wb_output *output = wl_container_of(listener, output, destroy);
wl_list_remove(&output->link);
wl_list_remove(&output->destroy.link); wl_list_remove(&output->destroy.link);
wl_list_remove(&output->frame.link); wl_list_remove(&output->frame.link);
wl_list_remove(&output->link);
/* Frees the layers */ /* Frees the layers */
size_t num_layers = sizeof(output->layers) / sizeof(struct wlr_scene_node *); size_t num_layers = sizeof(output->layers) / sizeof(struct wlr_scene_node *);

View file

@ -1,5 +1,8 @@
#include <unistd.h> #include <unistd.h>
#include <wlr/types/wlr_primary_selection.h>
#include <wlr/types/wlr_primary_selection_v1.h>
#include "waybox/seat.h" #include "waybox/seat.h"
#include "waybox/xdg_shell.h" #include "waybox/xdg_shell.h"
@ -107,8 +110,7 @@ static bool handle_keybinding(struct wb_server *server, xkb_keysym_t sym, uint32
if (view->scene_node->state.enabled) { if (view->scene_node->state.enabled) {
struct wlr_box geo_box; struct wlr_box geo_box;
wlr_xdg_surface_get_geometry(view->xdg_toplevel->base, &geo_box); wlr_xdg_surface_get_geometry(view->xdg_toplevel->base, &geo_box);
/* TODO: Get the minimum height from the theme rather than hard-coded. */ int decoration_height = MAX(geo_box.y - view->current_position.y, TITLEBAR_HEIGHT);
int decoration_height = MAX(geo_box.y - view->current_position.y, 8);
view->previous_position = view->current_position; view->previous_position = view->current_position;
#if WLR_CHECK_VERSION(0, 16, 0) #if WLR_CHECK_VERSION(0, 16, 0)
@ -144,6 +146,19 @@ static bool handle_keybinding(struct wb_server *server, xkb_keysym_t sym, uint32
return false; return false;
} }
static void keyboard_handle_destroy(struct wl_listener *listener, void *data) {
/* This event is raised by the keyboard base wlr_input_device to signal
* the destruction of the wlr_keyboard. It will no longer receive events
* and should be destroyed.
*/
struct wb_keyboard *keyboard = wl_container_of(listener, keyboard, destroy);
wl_list_remove(&keyboard->destroy.link);
wl_list_remove(&keyboard->key.link);
wl_list_remove(&keyboard->modifiers.link);
wl_list_remove(&keyboard->link);
free(keyboard);
}
static void keyboard_handle_modifiers( static void keyboard_handle_modifiers(
struct wl_listener *listener, void *data) { struct wl_listener *listener, void *data) {
/* This event is raised when a modifier key, such as shift or alt, is /* This event is raised when a modifier key, such as shift or alt, is
@ -234,6 +249,8 @@ static void handle_new_keyboard(struct wb_server *server,
xkb_context_unref(context); xkb_context_unref(context);
/* Here we set up listeners for keyboard events. */ /* Here we set up listeners for keyboard events. */
keyboard->destroy.notify = keyboard_handle_destroy;
wl_signal_add(&device->events.destroy, &keyboard->destroy);
keyboard->modifiers.notify = keyboard_handle_modifiers; keyboard->modifiers.notify = keyboard_handle_modifiers;
wl_signal_add(&device->keyboard->events.modifiers, &keyboard->modifiers); wl_signal_add(&device->keyboard->events.modifiers, &keyboard->modifiers);
keyboard->key.notify = keyboard_handle_key; keyboard->key.notify = keyboard_handle_key;

View file

@ -53,7 +53,9 @@ void focus_view(struct wb_view *view, struct wlr_surface *surface) {
#endif #endif
} }
/* Move the view to the front */ /* Move the view to the front */
wlr_scene_node_raise_to_top(view->scene_node); if (!server->seat->focused_layer) {
wlr_scene_node_raise_to_top(view->scene_node);
}
wl_list_remove(&view->link); wl_list_remove(&view->link);
wl_list_insert(&server->views, &view->link); wl_list_insert(&server->views, &view->link);
/* Activate the new surface */ /* Activate the new surface */
@ -113,9 +115,8 @@ static void xdg_toplevel_map(struct wl_listener *listener, void *data) {
} }
/* A view no larger than a title bar shouldn't be sized or focused */ /* A view no larger than a title bar shouldn't be sized or focused */
/* TODO: Get the title bar height from the theme */ if (view->current_position.height > TITLEBAR_HEIGHT &&
if (view->current_position.height > 9 && view->current_position.height > TITLEBAR_HEIGHT *
view->current_position.height > 9 *
(usable_area.width / usable_area.height)) { (usable_area.width / usable_area.height)) {
#if WLR_CHECK_VERSION(0, 16, 0) #if WLR_CHECK_VERSION(0, 16, 0)
wlr_xdg_toplevel_set_size(view->xdg_toplevel, wlr_xdg_toplevel_set_size(view->xdg_toplevel,
@ -280,6 +281,7 @@ static void handle_new_popup(struct wl_listener *listener, void *data) {
view->server->output_layout, view->server->output_layout,
view->current_position.x + popup->geometry.x, view->current_position.x + popup->geometry.x,
view->current_position.y + popup->geometry.y); view->current_position.y + popup->geometry.y);
if (!wlr_output) return;
struct wb_output *output = wlr_output->data; struct wb_output *output = wlr_output->data;
struct wlr_box output_toplevel_box = { struct wlr_box output_toplevel_box = {