Skip to content

Commit

Permalink
A lot.
Browse files Browse the repository at this point in the history
Add keyboard layouts and switching.
Add protocol definitions.
Always use software cursor, to avoid a bug (probably f-d up something).
Add proper minimize and maximize for views, fullscreen needs some work,
same for cursor, always jumping.
Resize doesn't work properly, should not be able to move window when
resizing.
  • Loading branch information
Luka Vilfan committed May 24, 2022
1 parent fcefb4b commit 73dae4b
Show file tree
Hide file tree
Showing 30 changed files with 3,787 additions and 66 deletions.
2 changes: 1 addition & 1 deletion bonsai/config/signal.c → bonsai/config/global.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <wlr/types/wlr_xdg_shell.h>

#include "bonsai/config/signal.h"
#include "bonsai/scene/view.h"
#include "bonsai/desktop/view.h"
#include "bonsai/server.h"

struct bsi_listeners*
Expand Down
74 changes: 62 additions & 12 deletions bonsai/config/input.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <assert.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <wayland-util.h>
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_keyboard.h>
Expand Down Expand Up @@ -66,7 +68,9 @@ bsi_inputs_keyboard_add(struct bsi_inputs* bsi_inputs,
++bsi_inputs->len_keyboards;
wl_list_insert(&bsi_inputs->keyboards, &bsi_input_keyboard->link);

bsi_input_keyboard_keymap_set(bsi_input_keyboard, NULL);
bsi_input_keyboard_keymap_set(bsi_input_keyboard,
bsi_input_keyboard_rules,
bsi_input_keyboard_rules_len);

wlr_seat_set_keyboard(bsi_inputs->wlr_seat,
bsi_input_keyboard->wlr_input_device);
Expand Down Expand Up @@ -158,13 +162,68 @@ bsi_input_keyboard_init(struct bsi_input_keyboard* bsi_input_keyboard,

void
bsi_input_keyboard_keymap_set(struct bsi_input_keyboard* bsi_input_keyboard,
const struct xkb_rule_names* xkb_rule_names)
const struct xkb_rule_names* xkb_rule_names,
const size_t xkb_rule_names_len)
{
assert(bsi_input_keyboard);

#define rs_len_max 50
size_t rs_len[] = { [4] = 0 };
char rules[rs_len_max] = { 0 }, models[rs_len_max] = { 0 },
layouts[rs_len_max] = { 0 }, variants[rs_len_max] = { 0 },
options[rs_len_max] = { 0 };

for (size_t i = 0; i < xkb_rule_names_len; ++i) {
const struct xkb_rule_names* rs = &xkb_rule_names[i];
if (rs->rules != NULL &&
rs_len[0] + strlen(rs->rules) < rs_len_max - 1) {
if (rs_len[0] != 0)
strcat(rules + strlen(rules), ",");
strcat(rules + strlen(rules), rs->rules);
rs_len[0] = strlen(rules);
}
if (rs->model != NULL &&
rs_len[1] + strlen(rs->model) < rs_len_max - 1) {
if (rs_len[1] != 0)
strcat(models + strlen(models), ",");
strcat(models + strlen(models), rs->model);
rs_len[1] = strlen(models);
}
if (rs->layout != NULL &&
rs_len[2] + strlen(rs->layout) < rs_len_max - 1) {
if (rs_len[2] != 0)
strcat(layouts + strlen(layouts), ",");
strcat(layouts + strlen(layouts), rs->layout);
rs_len[2] = strlen(layouts);
}
if (rs->variant != NULL &&
rs_len[3] + strlen(rs->variant) < rs_len_max - 1) {
if (rs_len[3] != 0)
strcat(variants + strlen(variants), ",");
strcat(variants + strlen(variants), rs->variant);
rs_len[3] = strlen(variants);
}
if (rs->options != NULL &&
rs_len[4] + strlen(rs->options) < rs_len_max - 1) {
if (rs_len[4] != 0)
strcat(options + strlen(options), ",");
strcat(options + strlen(options), rs->options);
rs_len[4] = strlen(options);
}
}
#undef rs_len_max

struct xkb_rule_names xkb_rules_all = {
.rules = rules,
.model = models,
.layout = layouts,
.variant = variants,
.options = options,
};

struct xkb_context* xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
struct xkb_keymap* xkb_keymap = xkb_keymap_new_from_names(
xkb_context, xkb_rule_names, XKB_KEYMAP_COMPILE_NO_FLAGS);
xkb_context, &xkb_rules_all, XKB_KEYMAP_COMPILE_NO_FLAGS);

wlr_keyboard_set_keymap(bsi_input_keyboard->wlr_input_device->keyboard,
xkb_keymap);
Expand All @@ -173,15 +232,6 @@ bsi_input_keyboard_keymap_set(struct bsi_input_keyboard* bsi_input_keyboard,
xkb_context_unref(xkb_context);
}

void
bsi_input_keyboard_layout_set(struct bsi_input_keyboard* bsi_input_keyboard,
const char* layout)
{
assert(bsi_input_keyboard);

// TODO: Wat do?
}

void
bsi_input_keyboard_destroy(struct bsi_input_keyboard* bsi_input_keyboard)
{
Expand Down
7 changes: 6 additions & 1 deletion bonsai/scene/cursor.c → bonsai/desktop/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#include <wlr/util/box.h>
#include <wlr/util/edges.h>

#include "bonsai/scene/cursor.h"
#include "bonsai/desktop/cursor.h"
#include "bonsai/desktop/view.h"
#include "bonsai/server.h"

struct bsi_cursor*
Expand Down Expand Up @@ -132,6 +133,10 @@ bsi_cursor_process_view_move(struct bsi_cursor* bsi_cursor,

bsi_view->x = bsi_server->wlr_cursor->x - bsi_cursor->grab_x;
bsi_view->y = bsi_server->wlr_cursor->y - bsi_cursor->grab_y;

if (bsi_view->maximized)
bsi_view_set_maximized(bsi_view, false);

wlr_scene_node_set_position(
bsi_view->wlr_scene_node, bsi_view->x, bsi_view->y);
}
Expand Down
Empty file added bonsai/desktop/layer.c
Empty file.
95 changes: 93 additions & 2 deletions bonsai/scene/view.c → bonsai/desktop/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_xdg_shell.h>
#include <wlr/util/box.h>
#include <wlr/util/edges.h>

#include "bonsai/scene/cursor.h"
#include "bonsai/scene/view.h"
#include "bonsai/config/output.h"
#include "bonsai/desktop/cursor.h"
#include "bonsai/desktop/view.h"
#include "bonsai/server.h"

struct bsi_views*
Expand Down Expand Up @@ -71,8 +73,14 @@ bsi_view_init(struct bsi_view* bsi_view,
bsi_view->bsi_workspace = bsi_workspace;
bsi_view->x = 0.0;
bsi_view->y = 0.0;
bsi_view->width = 0;
bsi_view->height = 0;
bsi_view->active_listeners = 0;
bsi_view->len_active_links = 0;
bsi_view->mapped = false;
bsi_view->maximized = false;
bsi_view->minimized = false;
bsi_view->fullscreen = false;

/* Create a new node from the root server node. */
bsi_view->wlr_scene_node = wlr_scene_xdg_surface_create(
Expand Down Expand Up @@ -194,6 +202,89 @@ bsi_view_interactive_begin(struct bsi_view* bsi_view,
}
}

void
bsi_view_set_maximized(struct bsi_view* bsi_view, bool maximized)
{
assert(bsi_view);

if (!maximized) {
bsi_view_restore_prev(bsi_view);
} else {
struct wlr_box box;
wlr_xdg_surface_get_geometry(bsi_view->wlr_xdg_surface, &box);
bsi_view->x = box.x;
bsi_view->y = box.y;
bsi_view->width = box.width;
bsi_view->height = box.height;
bsi_view->maximized = maximized;

struct bsi_server* server = bsi_view->bsi_server;
struct bsi_output* output = bsi_view->bsi_workspace->bsi_output;
struct wlr_box* output_box = wlr_output_layout_get_box(
server->wlr_output_layout, output->wlr_output);
wlr_scene_node_set_position(bsi_view->wlr_scene_node, 0, 0);
wlr_xdg_toplevel_set_size(
bsi_view->wlr_xdg_surface, output_box->width, output_box->height);
}
}

void
bsi_view_set_minimized(struct bsi_view* bsi_view, bool minimized)
{
assert(bsi_view);

if (!minimized) {
bsi_view_restore_prev(bsi_view);
} else {
struct wlr_box box;
wlr_xdg_surface_get_geometry(bsi_view->wlr_xdg_surface, &box);
bsi_view->x = box.x;
bsi_view->y = box.y;
bsi_view->width = box.width;
bsi_view->height = box.height;
bsi_view->minimized = minimized;

wlr_scene_node_set_enabled(bsi_view->wlr_scene_node, false);
}
}

void
bsi_view_set_fullscreen(struct bsi_view* bsi_view, bool fullscreen)
{
assert(bsi_view);

if (!fullscreen) {
bsi_view_restore_prev(bsi_view);
} else {
struct wlr_box box;
wlr_xdg_surface_get_geometry(bsi_view->wlr_xdg_surface, &box);
bsi_view->x = box.x;
bsi_view->y = box.y;
bsi_view->width = box.width;
bsi_view->height = box.height;
bsi_view->fullscreen = fullscreen;

// TODO: This should probably get rid of decorations to put the entire
// app fullscreen
struct bsi_server* server = bsi_view->bsi_server;
struct bsi_output* output = bsi_view->bsi_workspace->bsi_output;
struct wlr_box* output_box = wlr_output_layout_get_box(
server->wlr_output_layout, output->wlr_output);
wlr_scene_node_set_position(bsi_view->wlr_scene_node, 0, 0);
wlr_xdg_toplevel_set_size(
bsi_view->wlr_xdg_surface, output_box->width, output_box->height);
}
}

void
bsi_view_restore_prev(struct bsi_view* bsi_view)
{
wlr_xdg_toplevel_set_size(
bsi_view->wlr_xdg_surface, bsi_view->width, bsi_view->height);
wlr_scene_node_set_position(
bsi_view->wlr_scene_node, bsi_view->x, bsi_view->y);
}

void
bsi_view_listener_add(struct bsi_view* bsi_view,
enum bsi_view_listener_mask bsi_listener_type,
Expand Down
2 changes: 1 addition & 1 deletion bonsai/scene/workspace.c → bonsai/desktop/workspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <wayland-server-core.h>
#include <wayland-util.h>

#include "bonsai/scene/workspace.h"
#include "bonsai/desktop/workspace.h"
#include "bonsai/server.h"
#include "bonsai/util.h"

Expand Down
4 changes: 2 additions & 2 deletions bonsai/events/bsi-listeners.c → bonsai/events/evglobal.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

#include "bonsai/config/input.h"
#include "bonsai/config/signal.h"
#include "bonsai/desktop/view.h"
#include "bonsai/desktop/workspace.h"
#include "bonsai/events.h"
#include "bonsai/scene/view.h"
#include "bonsai/scene/workspace.h"
#include "bonsai/server.h"

#define GIMME_ALL_GLOBAL_EVENTS
Expand Down
5 changes: 3 additions & 2 deletions bonsai/events/bsi-input.c → bonsai/events/evinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#include <wlr/util/log.h>

#include "bonsai/config/input.h"
#include "bonsai/desktop/cursor.h"
#include "bonsai/desktop/view.h"
#include "bonsai/events.h"
#include "bonsai/scene/cursor.h"
#include "bonsai/scene/view.h"
#include "bonsai/server.h"

// #define GIMME_ALL_POINTER_EVENTS
Expand Down Expand Up @@ -306,6 +306,7 @@ bsi_input_keyboard_repeat_info_notify(struct wl_listener* listener, void* data)

// TODO: Wat do?
// TODO: Server is only handler?

#warning "Not implemented"
}

Expand Down
File renamed without changes.
44 changes: 35 additions & 9 deletions bonsai/events/bsi-view.c → bonsai/events/evview.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#include <wlr/types/wlr_xdg_shell.h>
#include <wlr/util/log.h>

#include "bonsai/desktop/cursor.h"
#include "bonsai/desktop/view.h"
#include "bonsai/desktop/workspace.h"
#include "bonsai/events.h"
#include "bonsai/scene/cursor.h"
#include "bonsai/scene/view.h"
#include "bonsai/scene/workspace.h"
#include "bonsai/server.h"

#define GIMME_ALL_VIEW_EVENTS
Expand Down Expand Up @@ -85,16 +85,23 @@ bsi_view_new_popup_notify(struct wl_listener* listener, void* data)
}

void
bsi_view_map_notify(struct wl_listener* listener,
__attribute__((unused)) void* data)
bsi_view_map_notify(struct wl_listener* listener, void* data)
{
#ifdef GIMME_ALL_VIEW_EVENTS
wlr_log(WLR_DEBUG, "Got event map from wlr_xdg_surface");
#endif

struct bsi_view* bsi_view = wl_container_of(listener, bsi_view, events.map);
struct bsi_views* bsi_views = &bsi_view->bsi_server->bsi_views;
struct wlr_xdg_surface* wlr_xdg_surface = data;

if (wlr_xdg_surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
struct wlr_xdg_toplevel_requested* requested =
&wlr_xdg_surface->toplevel->requested;
// TODO: Implement maximize for surface
}

bsi_view->mapped = true;
bsi_views_add(bsi_views, bsi_view);
bsi_view_focus(bsi_view);
}
Expand All @@ -111,6 +118,7 @@ bsi_view_unmap_notify(struct wl_listener* listener,
wl_container_of(listener, bsi_view, events.unmap);
struct bsi_views* bsi_views = &bsi_view->bsi_server->bsi_views;

bsi_view->mapped = false;
bsi_views_remove(bsi_views, bsi_view);
}

Expand Down Expand Up @@ -142,7 +150,15 @@ bsi_view_request_maximize_notify(struct wl_listener* listener, void* data)
// TODO: This should probably take into account the panels and such stuff.
// Also take a look at
// https://gitlab.freedesktop.org/wlroots/wlr-protocols/-/blob/master/unstable/wlr-layer-shell-unstable-v1.xml
#warning "Not implemented"

struct bsi_view* bsi_view =
wl_container_of(listener, bsi_view, events.request_maximize);
struct wlr_xdg_surface* surface = bsi_view->wlr_xdg_surface;
bool maximized = data;

bsi_view_set_maximized(bsi_view, maximized);
/* This surface should now consider itself */
wlr_xdg_toplevel_set_maximized(surface, maximized);
}

void
Expand All @@ -151,12 +167,18 @@ bsi_view_request_fullscreen_notify(struct wl_listener* listener, void* data)
#ifdef GIMME_ALL_VIEW_EVENTS
wlr_log(WLR_DEBUG, "Got event request_fullscreen from wlr_xdg_toplevel");
#endif
#warning "Not implemented"

struct bsi_view* bsi_view =
wl_container_of(listener, bsi_view, events.request_fullscreen);
struct wlr_xdg_toplevel_set_fullscreen_event* event = data;

bsi_view_set_fullscreen(bsi_view, event->fullscreen);
/* This surface should now consider itself (un-)fullscreen. */
wlr_xdg_toplevel_set_fullscreen(event->surface, event->fullscreen);
}

void
bsi_view_request_minimize_notify(struct wl_listener* listener,
__attribute__((unused)) void* data)
bsi_view_request_minimize_notify(struct wl_listener* listener, void* data)
{
#ifdef GIMME_ALL_VIEW_EVENTS
wlr_log(WLR_DEBUG, "Got event request_minimize from wlr_xdg_toplevel");
Expand All @@ -165,7 +187,11 @@ bsi_view_request_minimize_notify(struct wl_listener* listener,
struct bsi_view* bsi_view =
wl_container_of(listener, bsi_view, events.request_minimize);
struct bsi_views* bsi_views = &bsi_view->bsi_server->bsi_views;
bool minimized = data;

// TODO: Is this right? I have no clue.

bsi_view_set_minimized(bsi_view, minimized);
bsi_views_remove(bsi_views, bsi_view);
}

Expand Down
Loading

0 comments on commit 73dae4b

Please sign in to comment.