Focus layer-shell
This commit is contained in:
parent
c0b0418af8
commit
96484a75f8
9 changed files with 111 additions and 48 deletions
|
@ -18,7 +18,6 @@ struct kiwmi_desktop {
|
||||||
struct wlr_data_device_manager *data_device_manager;
|
struct wlr_data_device_manager *data_device_manager;
|
||||||
struct wlr_output_layout *output_layout;
|
struct wlr_output_layout *output_layout;
|
||||||
struct wl_list outputs; // struct kiwmi_output::link
|
struct wl_list outputs; // struct kiwmi_output::link
|
||||||
struct kiwmi_view *focused_view;
|
|
||||||
struct wl_list views; // struct kiwmi_view::link
|
struct wl_list views; // struct kiwmi_view::link
|
||||||
|
|
||||||
struct wl_listener xdg_shell_new_surface;
|
struct wl_listener xdg_shell_new_surface;
|
||||||
|
|
|
@ -9,16 +9,27 @@
|
||||||
#define KIWMI_INPUT_SEAT_H
|
#define KIWMI_INPUT_SEAT_H
|
||||||
|
|
||||||
#include <wayland-server.h>
|
#include <wayland-server.h>
|
||||||
|
#include <wlr/types/wlr_surface.h>
|
||||||
|
|
||||||
|
#include "desktop/layer_shell.h"
|
||||||
|
#include "desktop/view.h"
|
||||||
#include "input/input.h"
|
#include "input/input.h"
|
||||||
|
|
||||||
struct kiwmi_seat {
|
struct kiwmi_seat {
|
||||||
struct kiwmi_input *input;
|
struct kiwmi_input *input;
|
||||||
struct wlr_seat *seat;
|
struct wlr_seat *seat;
|
||||||
|
|
||||||
|
struct kiwmi_view *focused_view;
|
||||||
|
struct kiwmi_layer *focused_layer;
|
||||||
|
|
||||||
struct wl_listener request_set_cursor;
|
struct wl_listener request_set_cursor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
seat_focus_surface(struct kiwmi_seat *seat, struct wlr_surface *wlr_surface);
|
||||||
|
void seat_focus_layer(struct kiwmi_seat *seat, struct kiwmi_layer *layer);
|
||||||
|
void seat_focus_view(struct kiwmi_seat *seat, struct kiwmi_view *view);
|
||||||
|
|
||||||
struct kiwmi_seat *seat_create(struct kiwmi_input *input);
|
struct kiwmi_seat *seat_create(struct kiwmi_input *input);
|
||||||
void seat_destroy(struct kiwmi_seat *seat);
|
void seat_destroy(struct kiwmi_seat *seat);
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ bool
|
||||||
desktop_init(struct kiwmi_desktop *desktop, struct wlr_renderer *renderer)
|
desktop_init(struct kiwmi_desktop *desktop, struct wlr_renderer *renderer)
|
||||||
{
|
{
|
||||||
struct kiwmi_server *server = wl_container_of(desktop, server, desktop);
|
struct kiwmi_server *server = wl_container_of(desktop, server, desktop);
|
||||||
|
|
||||||
desktop->compositor = wlr_compositor_create(server->wl_display, renderer);
|
desktop->compositor = wlr_compositor_create(server->wl_display, renderer);
|
||||||
desktop->data_device_manager =
|
desktop->data_device_manager =
|
||||||
wlr_data_device_manager_create(server->wl_display);
|
wlr_data_device_manager_create(server->wl_display);
|
||||||
|
@ -49,8 +50,6 @@ desktop_init(struct kiwmi_desktop *desktop, struct wlr_renderer *renderer)
|
||||||
&desktop->layer_shell->events.new_surface,
|
&desktop->layer_shell->events.new_surface,
|
||||||
&desktop->layer_shell_new_surface);
|
&desktop->layer_shell_new_surface);
|
||||||
|
|
||||||
desktop->focused_view = NULL;
|
|
||||||
|
|
||||||
wl_list_init(&desktop->outputs);
|
wl_list_init(&desktop->outputs);
|
||||||
wl_list_init(&desktop->views);
|
wl_list_init(&desktop->views);
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
|
|
||||||
#include "desktop/desktop.h"
|
#include "desktop/desktop.h"
|
||||||
#include "wayland-util.h"
|
#include "input/seat.h"
|
||||||
#include "wlr-layer-shell-unstable-v1-protocol.h"
|
#include "server.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
kiwmi_layer_destroy_notify(struct wl_listener *listener, void *UNUSED(data))
|
kiwmi_layer_destroy_notify(struct wl_listener *listener, void *UNUSED(data))
|
||||||
|
@ -27,6 +27,8 @@ kiwmi_layer_destroy_notify(struct wl_listener *listener, void *UNUSED(data))
|
||||||
|
|
||||||
wlr_layer_surface_v1_close(layer->layer_surface);
|
wlr_layer_surface_v1_close(layer->layer_surface);
|
||||||
|
|
||||||
|
arrange_layers(layer->output);
|
||||||
|
|
||||||
free(layer);
|
free(layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,7 +293,11 @@ arrange_layers(struct kiwmi_output *output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: focus topmost
|
struct kiwmi_desktop *desktop = output->desktop;
|
||||||
|
struct kiwmi_server *server = wl_container_of(desktop, server, desktop);
|
||||||
|
struct kiwmi_seat *seat = server->input.seat;
|
||||||
|
|
||||||
|
seat_focus_layer(seat, topmost);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -81,41 +81,6 @@ view_surface_at(
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
view_focus(struct kiwmi_view *view)
|
|
||||||
{
|
|
||||||
if (!view) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct kiwmi_desktop *desktop = view->desktop;
|
|
||||||
struct kiwmi_server *server = wl_container_of(desktop, server, desktop);
|
|
||||||
struct wlr_seat *seat = server->input.seat->seat;
|
|
||||||
|
|
||||||
if (view == desktop->focused_view) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (desktop->focused_view) {
|
|
||||||
view_set_activated(desktop->focused_view, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat);
|
|
||||||
|
|
||||||
// move view to front
|
|
||||||
wl_list_remove(&view->link);
|
|
||||||
wl_list_insert(&desktop->views, &view->link);
|
|
||||||
|
|
||||||
desktop->focused_view = view;
|
|
||||||
view_set_activated(view, true);
|
|
||||||
wlr_seat_keyboard_notify_enter(
|
|
||||||
seat,
|
|
||||||
view->wlr_surface,
|
|
||||||
keyboard->keycodes,
|
|
||||||
keyboard->num_keycodes,
|
|
||||||
&keyboard->modifiers);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
surface_at(
|
surface_at(
|
||||||
struct kiwmi_view *view,
|
struct kiwmi_view *view,
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
#include "desktop/desktop.h"
|
#include "desktop/desktop.h"
|
||||||
#include "desktop/view.h"
|
#include "desktop/view.h"
|
||||||
|
#include "input/input.h"
|
||||||
|
#include "input/seat.h"
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -38,9 +40,11 @@ xdg_surface_destroy_notify(struct wl_listener *listener, void *UNUSED(data))
|
||||||
{
|
{
|
||||||
struct kiwmi_view *view = wl_container_of(listener, view, destroy);
|
struct kiwmi_view *view = wl_container_of(listener, view, destroy);
|
||||||
struct kiwmi_desktop *desktop = view->desktop;
|
struct kiwmi_desktop *desktop = view->desktop;
|
||||||
|
struct kiwmi_server *server = wl_container_of(desktop, server, desktop);
|
||||||
|
struct kiwmi_seat *seat = server->input.seat;
|
||||||
|
|
||||||
if (desktop->focused_view == view) {
|
if (seat->focused_view == view) {
|
||||||
desktop->focused_view = NULL;
|
seat->focused_view = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
wl_list_remove(&view->link);
|
wl_list_remove(&view->link);
|
||||||
|
|
|
@ -9,14 +9,82 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <wayland-server.h>
|
|
||||||
#include <wlr/types/wlr_cursor.h>
|
#include <wlr/types/wlr_cursor.h>
|
||||||
|
#include <wlr/types/wlr_layer_shell_v1.h>
|
||||||
#include <wlr/types/wlr_seat.h>
|
#include <wlr/types/wlr_seat.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
|
|
||||||
|
#include "desktop/layer_shell.h"
|
||||||
|
#include "desktop/view.h"
|
||||||
#include "input/cursor.h"
|
#include "input/cursor.h"
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
seat_focus_surface(struct kiwmi_seat *seat, struct wlr_surface *wlr_surface)
|
||||||
|
{
|
||||||
|
if (seat->focused_layer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->seat);
|
||||||
|
if (!keyboard) {
|
||||||
|
wlr_seat_keyboard_enter(seat->seat, wlr_surface, NULL, 0, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
wlr_seat_keyboard_enter(
|
||||||
|
seat->seat,
|
||||||
|
wlr_surface,
|
||||||
|
keyboard->keycodes,
|
||||||
|
keyboard->num_keycodes,
|
||||||
|
&keyboard->modifiers);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
seat_focus_view(struct kiwmi_seat *seat, struct kiwmi_view *view)
|
||||||
|
{
|
||||||
|
if (!view) {
|
||||||
|
seat_focus_surface(seat, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct kiwmi_desktop *desktop = view->desktop;
|
||||||
|
|
||||||
|
if (seat->focused_view) {
|
||||||
|
view_set_activated(seat->focused_view, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// move view to front
|
||||||
|
wl_list_remove(&view->link);
|
||||||
|
wl_list_insert(&desktop->views, &view->link);
|
||||||
|
|
||||||
|
seat->focused_view = view;
|
||||||
|
view_set_activated(view, true);
|
||||||
|
seat_focus_surface(seat, view->wlr_surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
seat_focus_layer(struct kiwmi_seat *seat, struct kiwmi_layer *layer)
|
||||||
|
{
|
||||||
|
if (!layer) {
|
||||||
|
if (seat->focused_layer) {
|
||||||
|
seat_focus_surface(seat, NULL);
|
||||||
|
seat_focus_surface(
|
||||||
|
seat, seat->focused_layer->layer_surface->surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (seat->focused_layer == layer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
seat->focused_layer = NULL;
|
||||||
|
|
||||||
|
seat_focus_surface(seat, layer->layer_surface->surface);
|
||||||
|
|
||||||
|
seat->focused_layer = layer;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
request_set_cursor_notify(struct wl_listener *listener, void *data)
|
request_set_cursor_notify(struct wl_listener *listener, void *data)
|
||||||
{
|
{
|
||||||
|
@ -57,6 +125,9 @@ seat_create(struct kiwmi_input *input)
|
||||||
seat->input = input;
|
seat->input = input;
|
||||||
seat->seat = wlr_seat_create(server->wl_display, "seat-0");
|
seat->seat = wlr_seat_create(server->wl_display, "seat-0");
|
||||||
|
|
||||||
|
seat->focused_view = NULL;
|
||||||
|
seat->focused_layer = NULL;
|
||||||
|
|
||||||
seat->request_set_cursor.notify = request_set_cursor_notify;
|
seat->request_set_cursor.notify = request_set_cursor_notify;
|
||||||
wl_signal_add(
|
wl_signal_add(
|
||||||
&seat->seat->events.request_set_cursor, &seat->request_set_cursor);
|
&seat->seat->events.request_set_cursor, &seat->request_set_cursor);
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
#include "desktop/view.h"
|
#include "desktop/view.h"
|
||||||
#include "input/cursor.h"
|
#include "input/cursor.h"
|
||||||
|
#include "input/input.h"
|
||||||
|
#include "input/seat.h"
|
||||||
#include "luak/kiwmi_cursor.h"
|
#include "luak/kiwmi_cursor.h"
|
||||||
#include "luak/kiwmi_keyboard.h"
|
#include "luak/kiwmi_keyboard.h"
|
||||||
#include "luak/kiwmi_lua_callback.h"
|
#include "luak/kiwmi_lua_callback.h"
|
||||||
|
@ -47,12 +49,12 @@ l_kiwmi_server_focused_view(lua_State *L)
|
||||||
struct kiwmi_server *server =
|
struct kiwmi_server *server =
|
||||||
*(struct kiwmi_server **)luaL_checkudata(L, 1, "kiwmi_server");
|
*(struct kiwmi_server **)luaL_checkudata(L, 1, "kiwmi_server");
|
||||||
|
|
||||||
if (!server->desktop.focused_view) {
|
if (!server->input.seat->focused_view) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_pushcfunction(L, luaK_kiwmi_view_new);
|
lua_pushcfunction(L, luaK_kiwmi_view_new);
|
||||||
lua_pushlightuserdata(L, server->desktop.focused_view);
|
lua_pushlightuserdata(L, server->input.seat->focused_view);
|
||||||
if (lua_pcall(L, 1, 1, 0)) {
|
if (lua_pcall(L, 1, 1, 0)) {
|
||||||
wlr_log(WLR_ERROR, "%s", lua_tostring(L, -1));
|
wlr_log(WLR_ERROR, "%s", lua_tostring(L, -1));
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -10,10 +10,12 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <lauxlib.h>
|
#include <lauxlib.h>
|
||||||
|
#include <wayland-server.h>
|
||||||
#include <wlr/util/edges.h>
|
#include <wlr/util/edges.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
|
|
||||||
#include "desktop/view.h"
|
#include "desktop/view.h"
|
||||||
|
#include "input/seat.h"
|
||||||
#include "luak/kiwmi_lua_callback.h"
|
#include "luak/kiwmi_lua_callback.h"
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|
||||||
|
@ -34,7 +36,11 @@ l_kiwmi_view_focus(lua_State *L)
|
||||||
struct kiwmi_view *view =
|
struct kiwmi_view *view =
|
||||||
*(struct kiwmi_view **)luaL_checkudata(L, 1, "kiwmi_view");
|
*(struct kiwmi_view **)luaL_checkudata(L, 1, "kiwmi_view");
|
||||||
|
|
||||||
view_focus(view);
|
struct kiwmi_desktop *desktop = view->desktop;
|
||||||
|
struct kiwmi_server *server = wl_container_of(desktop, server, desktop);
|
||||||
|
struct kiwmi_seat *seat = server->input.seat;
|
||||||
|
|
||||||
|
seat_focus_view(seat, view);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue