Merge pull request #44 from tiosgz/wlr-0.15

This commit is contained in:
buffet 2022-03-15 18:29:20 +00:00 committed by GitHub
commit db09dcae77
13 changed files with 54 additions and 119 deletions

View file

@ -31,7 +31,7 @@ $ kiwmic 'return kiwmi:focused_view():id()'
The dependencies required are: The dependencies required are:
- [wlroots](https://github.com/swaywm/wlroots) - [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots)
- lua or luajit - lua or luajit
- pixman - pixman
- meson (build) - meson (build)

View file

@ -9,7 +9,6 @@
#define KIWMI_DESKTOP_DESKTOP_H #define KIWMI_DESKTOP_DESKTOP_H
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/render/wlr_renderer.h>
struct kiwmi_desktop { struct kiwmi_desktop {
struct wlr_compositor *compositor; struct wlr_compositor *compositor;
@ -35,7 +34,7 @@ struct kiwmi_desktop {
} events; } events;
}; };
bool desktop_init(struct kiwmi_desktop *desktop, struct wlr_renderer *renderer); bool desktop_init(struct kiwmi_desktop *desktop);
void desktop_fini(struct kiwmi_desktop *desktop); void desktop_fini(struct kiwmi_desktop *desktop);
struct kiwmi_server; struct kiwmi_server;

View file

@ -11,8 +11,8 @@
#include <stdbool.h> #include <stdbool.h>
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/types/wlr_box.h>
#include <wlr/types/wlr_surface.h> #include <wlr/types/wlr_surface.h>
#include <wlr/util/box.h>
#include "desktop/output.h" #include "desktop/output.h"

View file

@ -9,7 +9,7 @@
#define KIWMI_DESKTOP_OUTPUT_H #define KIWMI_DESKTOP_OUTPUT_H
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/types/wlr_box.h> #include <wlr/util/box.h>
struct kiwmi_output { struct kiwmi_output {
struct wl_list link; struct wl_list link;

View file

@ -71,7 +71,7 @@ struct kiwmi_view {
struct kiwmi_view_impl { struct kiwmi_view_impl {
void (*close)(struct kiwmi_view *view); void (*close)(struct kiwmi_view *view);
void (*for_each_mapped_surface)( void (*for_each_surface)(
struct kiwmi_view *view, struct kiwmi_view *view,
wlr_surface_iterator_func_t callback, wlr_surface_iterator_func_t callback,
void *user_data); void *user_data);
@ -131,7 +131,7 @@ struct kiwmi_request_resize_event {
}; };
void view_close(struct kiwmi_view *view); void view_close(struct kiwmi_view *view);
void view_for_each_mapped_surface( void view_for_each_surface(
struct kiwmi_view *view, struct kiwmi_view *view,
wlr_surface_iterator_func_t callback, wlr_surface_iterator_func_t callback,
void *user_data); void *user_data);

View file

@ -17,6 +17,9 @@ struct kiwmi_server {
struct wl_display *wl_display; struct wl_display *wl_display;
struct wl_event_loop *wl_event_loop; struct wl_event_loop *wl_event_loop;
struct wlr_backend *backend; struct wlr_backend *backend;
struct wlr_renderer *renderer;
struct wlr_allocator *allocator;
const char *socket; const char *socket;
char *config_path; char *config_path;
struct kiwmi_lua *lua; struct kiwmi_lua *lua;

View file

@ -30,11 +30,12 @@
#include "server.h" #include "server.h"
bool bool
desktop_init(struct kiwmi_desktop *desktop, struct wlr_renderer *renderer) desktop_init(struct kiwmi_desktop *desktop)
{ {
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, server->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);
desktop->output_layout = wlr_output_layout_create(); desktop->output_layout = wlr_output_layout_create();

View file

@ -29,8 +29,6 @@ kiwmi_layer_destroy_notify(struct wl_listener *listener, void *UNUSED(data))
wl_list_remove(&layer->map.link); wl_list_remove(&layer->map.link);
wl_list_remove(&layer->unmap.link); wl_list_remove(&layer->unmap.link);
wlr_layer_surface_v1_close(layer->layer_surface);
arrange_layers(layer->output); arrange_layers(layer->output);
free(layer); free(layer);
@ -44,7 +42,9 @@ kiwmi_layer_commit_notify(struct wl_listener *listener, void *UNUSED(data))
struct wlr_box old_geom = layer->geom; struct wlr_box old_geom = layer->geom;
if (layer->layer_surface->current.committed != 0) {
arrange_layers(output); arrange_layers(output);
}
bool layer_changed = layer->layer != layer->layer_surface->current.layer; bool layer_changed = layer->layer != layer->layer_surface->current.layer;
bool geom_changed = memcmp(&old_geom, &layer->geom, sizeof(old_geom)) != 0; bool geom_changed = memcmp(&old_geom, &layer->geom, sizeof(old_geom)) != 0;
@ -237,7 +237,7 @@ arrange_layer(
"Bad width/height: %d, %d", "Bad width/height: %d, %d",
arranged_area.width, arranged_area.width,
arranged_area.height); arranged_area.height);
wlr_layer_surface_v1_close(layer_surface); wlr_layer_surface_v1_destroy(layer_surface);
continue; continue;
} }
@ -404,7 +404,7 @@ layer_shell_new_surface_notify(struct wl_listener *listener, void *data)
WLR_ERROR, WLR_ERROR,
"Bad layer surface layer '%d'", "Bad layer surface layer '%d'",
layer_surface->current.layer); layer_surface->current.layer);
wlr_layer_surface_v1_close(layer_surface); wlr_layer_surface_v1_destroy(layer_surface);
free(layer); free(layer);
return; return;
} }
@ -427,10 +427,10 @@ layer_shell_new_surface_notify(struct wl_listener *listener, void *data)
wl_list_insert(&output->layers[layer->layer], &layer->link); wl_list_insert(&output->layers[layer->layer], &layer->link);
// Temporarily set the layer's current state to client_pending // Temporarily set the layer's current state to pending
// So that we can easily arrange it // So that we can easily arrange it
struct wlr_layer_surface_v1_state old_state = layer_surface->current; struct wlr_layer_surface_v1_state old_state = layer_surface->current;
layer_surface->current = layer_surface->client_pending; layer_surface->current = layer_surface->pending;
arrange_layers(output); arrange_layers(output);
layer_surface->current = old_state; layer_surface->current = old_state;
} }

View file

@ -12,6 +12,7 @@
#include <pixman.h> #include <pixman.h>
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/backend.h> #include <wlr/backend.h>
#include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_layer_shell_v1.h> #include <wlr/types/wlr_layer_shell_v1.h>
#include <wlr/types/wlr_matrix.h> #include <wlr/types/wlr_matrix.h>
@ -178,8 +179,7 @@ output_frame_notify(struct wl_listener *listener, void *data)
struct kiwmi_view *view; struct kiwmi_view *view;
wl_list_for_each (view, &desktop->views, link) { wl_list_for_each (view, &desktop->views, link) {
view_for_each_mapped_surface( view_for_each_surface(view, send_frame_done_to_surface, &now);
view, send_frame_done_to_surface, &now);
} }
if (render_cursors(wlr_output)) { if (render_cursors(wlr_output)) {
@ -191,8 +191,8 @@ output_frame_notify(struct wl_listener *listener, void *data)
} }
struct wlr_output_layout *output_layout = desktop->output_layout; struct wlr_output_layout *output_layout = desktop->output_layout;
struct wlr_renderer *renderer = struct kiwmi_server *server = wl_container_of(desktop, server, desktop);
wlr_backend_get_renderer(wlr_output->backend); struct wlr_renderer *renderer = server->renderer;
int width; int width;
int height; int height;
@ -226,7 +226,7 @@ output_frame_notify(struct wl_listener *listener, void *data)
rdata.data = view; rdata.data = view;
wl_signal_emit(&view->events.pre_render, &rdata); wl_signal_emit(&view->events.pre_render, &rdata);
view_for_each_mapped_surface(view, render_surface, &rdata); view_for_each_surface(view, render_surface, &rdata);
wl_signal_emit(&view->events.post_render, &rdata); wl_signal_emit(&view->events.post_render, &rdata);
} }
@ -334,9 +334,10 @@ new_output_notify(struct wl_listener *listener, void *data)
wlr_log(WLR_DEBUG, "New output %p: %s", wlr_output, wlr_output->name); wlr_log(WLR_DEBUG, "New output %p: %s", wlr_output, wlr_output->name);
if (!wl_list_empty(&wlr_output->modes)) { wlr_output_init_render(wlr_output, server->allocator, server->renderer);
struct wlr_output_mode *mode =
wl_container_of(wlr_output->modes.prev, mode, link); struct wlr_output_mode *mode = wlr_output_preferred_mode(wlr_output);
if (mode) {
wlr_output_set_mode(wlr_output, mode); wlr_output_set_mode(wlr_output, mode);
if (!wlr_output_commit(wlr_output)) { if (!wlr_output_commit(wlr_output)) {

View file

@ -24,13 +24,13 @@ view_close(struct kiwmi_view *view)
} }
void void
view_for_each_mapped_surface( view_for_each_surface(
struct kiwmi_view *view, struct kiwmi_view *view,
wlr_surface_iterator_func_t callback, wlr_surface_iterator_func_t callback,
void *user_data) void *user_data)
{ {
if (view->impl->for_each_mapped_surface) { if (view->impl->for_each_surface) {
view->impl->for_each_mapped_surface(view, callback, user_data); view->impl->for_each_surface(view, callback, user_data);
} }
} }
@ -262,10 +262,12 @@ view_init_subsurfaces(struct kiwmi_view_child *child, struct kiwmi_view *view)
} }
struct wlr_subsurface *subsurface; struct wlr_subsurface *subsurface;
wl_list_for_each (subsurface, &surface->subsurfaces_below, parent_link) { wl_list_for_each (
subsurface, &surface->current.subsurfaces_below, current.link) {
view_child_subsurface_create(child, view, subsurface); view_child_subsurface_create(child, view, subsurface);
} }
wl_list_for_each (subsurface, &surface->subsurfaces_above, parent_link) { wl_list_for_each (
subsurface, &surface->current.subsurfaces_above, current.link) {
view_child_subsurface_create(child, view, subsurface); view_child_subsurface_create(child, view, subsurface);
} }
} }

View file

@ -294,87 +294,12 @@ xdg_shell_view_close(struct kiwmi_view *view)
} }
static void static void
surface_for_each_mapped_surface( xdg_shell_view_for_each_surface(
struct wlr_surface *surface,
int x,
int y,
wlr_surface_iterator_func_t callback,
void *user_data)
{
struct wlr_subsurface *subsurface;
wl_list_for_each (subsurface, &surface->subsurfaces_below, parent_link) {
if (!subsurface->mapped) {
continue;
}
surface_for_each_mapped_surface(
subsurface->surface,
x + subsurface->current.x,
y + subsurface->current.y,
callback,
user_data);
}
callback(surface, x, y, user_data);
wl_list_for_each (subsurface, &surface->subsurfaces_above, parent_link) {
if (!subsurface->mapped) {
continue;
}
surface_for_each_mapped_surface(
subsurface->surface,
x + subsurface->current.x,
y + subsurface->current.y,
callback,
user_data);
}
}
static void
xdg_surface_for_each_mapped_popup_surface(
struct wlr_xdg_surface *surface,
int x,
int y,
wlr_surface_iterator_func_t callback,
void *user_data)
{
struct wlr_xdg_popup *popup;
wl_list_for_each (popup, &surface->popups, link) {
struct wlr_xdg_surface *popup_surface = popup->base;
if (!popup_surface->configured || !popup_surface->mapped) {
continue;
}
double popup_sx, popup_sy;
wlr_xdg_popup_get_position(popup, &popup_sx, &popup_sy);
surface_for_each_mapped_surface(
popup_surface->surface,
x + popup_sx,
y + popup_sy,
callback,
user_data);
xdg_surface_for_each_mapped_popup_surface(
popup_surface, x + popup_sx, y + popup_sy, callback, user_data);
}
}
static void
xdg_shell_view_for_each_mapped_surface(
struct kiwmi_view *view, struct kiwmi_view *view,
wlr_surface_iterator_func_t callback, wlr_surface_iterator_func_t callback,
void *user_data) void *user_data)
{ {
if (!view->mapped) { wlr_xdg_surface_for_each_surface(view->xdg_surface, callback, user_data);
return;
}
// Have to copy over the wlroots implementation with only small changes
surface_for_each_mapped_surface(
view->xdg_surface->surface, 0, 0, callback, user_data);
xdg_surface_for_each_mapped_popup_surface(
view->xdg_surface, 0, 0, callback, user_data);
} }
static pid_t static pid_t
@ -437,7 +362,7 @@ xdg_shell_view_surface_at(
static const struct kiwmi_view_impl xdg_shell_view_impl = { static const struct kiwmi_view_impl xdg_shell_view_impl = {
.close = xdg_shell_view_close, .close = xdg_shell_view_close,
.for_each_mapped_surface = xdg_shell_view_for_each_mapped_surface, .for_each_surface = xdg_shell_view_for_each_surface,
.get_pid = xdg_shell_view_get_pid, .get_pid = xdg_shell_view_get_pid,
.get_string_prop = xdg_shell_view_get_string_prop, .get_string_prop = xdg_shell_view_get_string_prop,
.set_activated = xdg_shell_view_set_activated, .set_activated = xdg_shell_view_set_activated,
@ -534,7 +459,7 @@ xdg_decoration_request_mode_notify(
wl_container_of(listener, decoration, request_mode); wl_container_of(listener, decoration, request_mode);
enum wlr_xdg_toplevel_decoration_v1_mode mode = enum wlr_xdg_toplevel_decoration_v1_mode mode =
decoration->wlr_decoration->client_pending_mode; decoration->wlr_decoration->requested_mode;
if (mode == WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_NONE) { if (mode == WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_NONE) {
mode = WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE; mode = WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE;
} }

View file

@ -8,9 +8,9 @@
#include "luak/kiwmi_output.h" #include "luak/kiwmi_output.h"
#include <lauxlib.h> #include <lauxlib.h>
#include <wlr/types/wlr_box.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
#include <wlr/util/box.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "desktop/output.h" #include "desktop/output.h"

View file

@ -14,6 +14,7 @@
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/backend.h> #include <wlr/backend.h>
#include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_data_control_v1.h> #include <wlr/types/wlr_data_control_v1.h>
#include <wlr/types/wlr_gamma_control_v1.h> #include <wlr/types/wlr_gamma_control_v1.h>
@ -43,12 +44,15 @@ server_init(struct kiwmi_server *server, char *config_path)
return false; return false;
} }
struct wlr_renderer *renderer = wlr_backend_get_renderer(server->backend); server->renderer = wlr_renderer_autocreate(server->backend);
wlr_renderer_init_wl_display(renderer, server->wl_display); wlr_renderer_init_wl_display(server->renderer, server->wl_display);
server->allocator =
wlr_allocator_autocreate(server->backend, server->renderer);
wl_signal_init(&server->events.destroy); wl_signal_init(&server->events.destroy);
if (!desktop_init(&server->desktop, renderer)) { if (!desktop_init(&server->desktop)) {
wlr_log(WLR_ERROR, "Failed to initialize desktop"); wlr_log(WLR_ERROR, "Failed to initialize desktop");
wl_display_destroy(server->wl_display); wl_display_destroy(server->wl_display);
return false; return false;