commit
38bb3b9608
@ -1,26 +1,112 @@
|
||||
#ifndef WLR_TYPES_WLR_WL_SHELL_H
|
||||
#define WLR_TYPES_WLR_WL_SHELL_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <wayland-server.h>
|
||||
|
||||
struct wlr_wl_shell {
|
||||
struct wl_global *wl_global;
|
||||
struct wl_list wl_resources;
|
||||
struct wl_list surfaces;
|
||||
uint32_t ping_timeout;
|
||||
|
||||
struct {
|
||||
struct wl_signal new_surface;
|
||||
} events;
|
||||
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct wlr_wl_shell_surface_transient_state {
|
||||
struct wlr_wl_shell_surface *parent;
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
uint32_t flags;
|
||||
};
|
||||
|
||||
struct wlr_wl_shell_surface_popup_state {
|
||||
struct wlr_seat_handle *seat_handle;
|
||||
uint32_t serial;
|
||||
};
|
||||
|
||||
enum wlr_wl_shell_surface_role {
|
||||
WLR_WL_SHELL_SURFACE_ROLE_NONE,
|
||||
WLR_WL_SHELL_SURFACE_ROLE_TOPLEVEL,
|
||||
WLR_WL_SHELL_SURFACE_ROLE_TRANSCIENT,
|
||||
WLR_WL_SHELL_SURFACE_ROLE_POPUP,
|
||||
};
|
||||
|
||||
struct wlr_wl_shell_surface {
|
||||
struct wl_resource *surface;
|
||||
struct wlr_texture *wlr_texture;
|
||||
struct wlr_wl_shell *shell;
|
||||
struct wl_client *client;
|
||||
struct wl_resource *resource;
|
||||
struct wlr_surface *surface;
|
||||
struct wl_list link;
|
||||
|
||||
uint32_t ping_serial;
|
||||
struct wl_event_source *ping_timer;
|
||||
|
||||
enum wlr_wl_shell_surface_role role;
|
||||
struct wlr_wl_shell_surface_transient_state *transient_state;
|
||||
struct wlr_wl_shell_surface_popup_state *popup_state;
|
||||
|
||||
char *title;
|
||||
char *class;
|
||||
|
||||
struct wl_listener surface_destroy_listener;
|
||||
|
||||
struct {
|
||||
struct wl_signal destroy;
|
||||
struct wl_signal ping_timeout;
|
||||
|
||||
struct wl_signal request_move;
|
||||
struct wl_signal request_resize;
|
||||
struct wl_signal request_set_fullscreen;
|
||||
struct wl_signal request_set_maximized;
|
||||
|
||||
struct wl_signal set_role;
|
||||
struct wl_signal set_title;
|
||||
struct wl_signal set_class;
|
||||
} events;
|
||||
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct wlr_wl_shell_surface_move_event {
|
||||
struct wl_client *client;
|
||||
struct wlr_wl_shell_surface *surface;
|
||||
struct wlr_seat_handle *seat_handle;
|
||||
uint32_t serial;
|
||||
};
|
||||
|
||||
struct wlr_wl_shell_surface_resize_event {
|
||||
struct wl_client *client;
|
||||
struct wlr_wl_shell_surface *surface;
|
||||
struct wlr_seat_handle *seat_handle;
|
||||
uint32_t serial;
|
||||
uint32_t edges;
|
||||
};
|
||||
|
||||
struct wlr_wl_shell_surface_set_fullscreen_event {
|
||||
struct wl_client *client;
|
||||
struct wlr_wl_shell_surface *surface;
|
||||
uint32_t method;
|
||||
uint32_t framerate;
|
||||
struct wlr_output *output;
|
||||
};
|
||||
|
||||
struct wlr_wl_shell_surface_set_maximized_event {
|
||||
struct wl_client *client;
|
||||
struct wlr_wl_shell_surface *surface;
|
||||
struct wlr_output *output;
|
||||
};
|
||||
|
||||
struct wlr_wl_shell *wlr_wl_shell_create(struct wl_display *display);
|
||||
void wlr_wl_shell_destroy(struct wlr_wl_shell *wlr_wl_shell);
|
||||
|
||||
void wlr_wl_shell_surface_ping(struct wlr_wl_shell_surface *surface);
|
||||
void wlr_wl_shell_surface_configure(struct wlr_wl_shell_surface *surface,
|
||||
uint32_t edges, int32_t width, int32_t height);
|
||||
void wlr_wl_shell_surface_popup_done(struct wlr_wl_shell_surface *surface);
|
||||
|
||||
#endif
|
||||
|
@ -0,0 +1,84 @@
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/types/wlr_box.h>
|
||||
#include <wlr/types/wlr_surface.h>
|
||||
#include <wlr/types/wlr_wl_shell.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "rootston/desktop.h"
|
||||
#include "rootston/server.h"
|
||||
#include "rootston/input.h"
|
||||
|
||||
static void handle_move(struct wl_listener *listener, void *data) {
|
||||
struct roots_wl_shell_surface *roots_surface =
|
||||
wl_container_of(listener, roots_surface, request_move);
|
||||
struct roots_view *view = roots_surface->view;
|
||||
struct roots_input *input = view->desktop->server->input;
|
||||
struct wlr_wl_shell_surface_move_event *e = data;
|
||||
|
||||
// TODO: Some of this might want to live in cursor.c I guess
|
||||
struct roots_input_event *event = NULL;
|
||||
size_t len = sizeof(input->input_events) / sizeof(*input->input_events);
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
if (input->input_events[i].cursor
|
||||
&& input->input_events[i].serial == e->serial) {
|
||||
event = &input->input_events[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!event || input->mode != ROOTS_CURSOR_PASSTHROUGH) {
|
||||
return;
|
||||
}
|
||||
input->mode = ROOTS_CURSOR_MOVE;
|
||||
input->offs_x = input->cursor->x - view->x;
|
||||
input->offs_y = input->cursor->y - view->y;
|
||||
wlr_seat_pointer_clear_focus(input->wl_seat);
|
||||
}
|
||||
|
||||
static void handle_destroy(struct wl_listener *listener, void *data) {
|
||||
struct roots_wl_shell_surface *roots_surface =
|
||||
wl_container_of(listener, roots_surface, destroy);
|
||||
wl_list_remove(&roots_surface->destroy.link);
|
||||
wl_list_remove(&roots_surface->ping_timeout.link);
|
||||
wl_list_remove(&roots_surface->request_move.link);
|
||||
wl_list_remove(&roots_surface->request_resize.link);
|
||||
wl_list_remove(&roots_surface->request_set_fullscreen.link);
|
||||
wl_list_remove(&roots_surface->request_set_maximized.link);
|
||||
view_destroy(roots_surface->view);
|
||||
free(roots_surface);
|
||||
}
|
||||
|
||||
void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
|
||||
struct roots_desktop *desktop =
|
||||
wl_container_of(listener, desktop, wl_shell_surface);
|
||||
|
||||
struct wlr_wl_shell_surface *surface = data;
|
||||
wlr_log(L_DEBUG, "new shell surface: title=%s, class=%s",
|
||||
surface->title, surface->class);
|
||||
wlr_wl_shell_surface_ping(surface); // TODO: segfaults
|
||||
|
||||
struct roots_wl_shell_surface *roots_surface =
|
||||
calloc(1, sizeof(struct roots_wl_shell_surface));
|
||||
// TODO: all of the trimmings
|
||||
wl_list_init(&roots_surface->destroy.link);
|
||||
roots_surface->destroy.notify = handle_destroy;
|
||||
wl_signal_add(&surface->events.destroy, &roots_surface->destroy);
|
||||
wl_list_init(&roots_surface->ping_timeout.link);
|
||||
wl_list_init(&roots_surface->request_move.link);
|
||||
roots_surface->request_move.notify = handle_move;
|
||||
wl_signal_add(&surface->events.request_move, &roots_surface->request_move);
|
||||
wl_list_init(&roots_surface->request_resize.link);
|
||||
wl_list_init(&roots_surface->request_set_fullscreen.link);
|
||||
wl_list_init(&roots_surface->request_set_maximized.link);
|
||||
|
||||
struct roots_view *view = calloc(1, sizeof(struct roots_view));
|
||||
view->type = ROOTS_WL_SHELL_VIEW;
|
||||
view->x = view->y = 200;
|
||||
view->wl_shell_surface = surface;
|
||||
view->roots_wl_shell_surface = roots_surface;
|
||||
view->wlr_surface = surface->surface;
|
||||
view->desktop = desktop;
|
||||
roots_surface->view = view;
|
||||
wl_list_insert(&desktop->views, &view->link);
|
||||
}
|
Loading…
Reference in new issue