mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-22 12:55:58 +01:00
example compositor: loop through xwayland surfaces
This commit is contained in:
parent
f912316d9b
commit
1458a95e65
5 changed files with 32 additions and 28 deletions
|
@ -36,7 +36,7 @@ struct sample_state {
|
||||||
struct wlr_data_device_manager *data_device_manager;
|
struct wlr_data_device_manager *data_device_manager;
|
||||||
struct wl_resource *focus;
|
struct wl_resource *focus;
|
||||||
struct wl_listener keyboard_bound;
|
struct wl_listener keyboard_bound;
|
||||||
struct wlr_xwayland *wlr_xwayland;
|
struct wlr_xwayland *xwayland;
|
||||||
int keymap_fd;
|
int keymap_fd;
|
||||||
size_t keymap_size;
|
size_t keymap_size;
|
||||||
uint32_t serial;
|
uint32_t serial;
|
||||||
|
@ -85,6 +85,10 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
|
||||||
wl_list_for_each(xdg_surface, &sample->xdg_shell->surfaces, link) {
|
wl_list_for_each(xdg_surface, &sample->xdg_shell->surfaces, link) {
|
||||||
output_frame_handle_surface(sample, wlr_output, ts, xdg_surface->surface);
|
output_frame_handle_surface(sample, wlr_output, ts, xdg_surface->surface);
|
||||||
}
|
}
|
||||||
|
struct wlr_x11_window *x11_window;
|
||||||
|
wl_list_for_each(x11_window, &sample->xwayland->displayable_windows, link) {
|
||||||
|
output_frame_handle_surface(sample, wlr_output, ts, x11_window->surface);
|
||||||
|
}
|
||||||
|
|
||||||
wlr_renderer_end(sample->renderer);
|
wlr_renderer_end(sample->renderer);
|
||||||
wlr_output_swap_buffers(wlr_output);
|
wlr_output_swap_buffers(wlr_output);
|
||||||
|
@ -178,13 +182,13 @@ int main() {
|
||||||
free(keymap);
|
free(keymap);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
state.wlr_xwayland = wlr_xwayland_create(compositor.display, state.wlr_compositor);
|
state.xwayland = wlr_xwayland_create(compositor.display, state.wlr_compositor);
|
||||||
|
|
||||||
compositor.keyboard_key_cb = handle_keyboard_key;
|
compositor.keyboard_key_cb = handle_keyboard_key;
|
||||||
|
|
||||||
wl_display_run(compositor.display);
|
wl_display_run(compositor.display);
|
||||||
|
|
||||||
wlr_xwayland_destroy(state.wlr_xwayland);
|
wlr_xwayland_destroy(state.xwayland);
|
||||||
close(state.keymap_fd);
|
close(state.keymap_fd);
|
||||||
wlr_seat_destroy(state.wl_seat);
|
wlr_seat_destroy(state.wl_seat);
|
||||||
wlr_data_device_manager_destroy(state.data_device_manager);
|
wlr_data_device_manager_destroy(state.data_device_manager);
|
||||||
|
|
|
@ -4,20 +4,34 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <wlr/types/wlr_compositor.h>
|
#include <wlr/types/wlr_compositor.h>
|
||||||
|
#include <xcb/xcb.h>
|
||||||
|
|
||||||
struct wlr_xwm;
|
struct wlr_xwm;
|
||||||
|
|
||||||
struct wlr_xwayland {
|
struct wlr_xwayland {
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int display;
|
int display;
|
||||||
int x_fd[2], wl_fd[2], wm_fd[2];
|
int x_fd[2], wl_fd[2], wm_fd[2];
|
||||||
struct wl_client *client;
|
struct wl_client *client;
|
||||||
struct wl_display *wl_display;
|
struct wl_display *wl_display;
|
||||||
struct wlr_compositor *compositor;
|
struct wlr_compositor *compositor;
|
||||||
time_t server_start;
|
time_t server_start;
|
||||||
|
|
||||||
struct wl_event_source *sigusr1_source;
|
struct wl_event_source *sigusr1_source;
|
||||||
struct wlr_xwm *xwm;
|
struct wlr_xwm *xwm;
|
||||||
|
struct wl_list displayable_windows;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct wlr_x11_window {
|
||||||
|
xcb_window_t window_id;
|
||||||
|
uint32_t surface_id;
|
||||||
|
struct wl_list link;
|
||||||
|
|
||||||
|
struct wl_resource *surface;
|
||||||
|
struct wl_listener surface_destroy_listener;
|
||||||
|
int16_t x, y;
|
||||||
|
uint16_t width, height;
|
||||||
|
bool override_redirect;
|
||||||
};
|
};
|
||||||
|
|
||||||
void wlr_xwayland_destroy(struct wlr_xwayland *wlr_xwayland);
|
void wlr_xwayland_destroy(struct wlr_xwayland *wlr_xwayland);
|
||||||
|
|
|
@ -161,6 +161,7 @@ static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland,
|
||||||
wlr_xwayland->x_fd[0] = wlr_xwayland->x_fd[1] = -1;
|
wlr_xwayland->x_fd[0] = wlr_xwayland->x_fd[1] = -1;
|
||||||
wlr_xwayland->wl_fd[0] = wlr_xwayland->wl_fd[1] = -1;
|
wlr_xwayland->wl_fd[0] = wlr_xwayland->wl_fd[1] = -1;
|
||||||
wlr_xwayland->wm_fd[0] = wlr_xwayland->wm_fd[1] = -1;
|
wlr_xwayland->wm_fd[0] = wlr_xwayland->wm_fd[1] = -1;
|
||||||
|
wl_list_init(&wlr_xwayland->displayable_windows);
|
||||||
|
|
||||||
wlr_xwayland->display = open_display_sockets(wlr_xwayland->x_fd);
|
wlr_xwayland->display = open_display_sockets(wlr_xwayland->x_fd);
|
||||||
if (wlr_xwayland->display < 0) {
|
if (wlr_xwayland->display < 0) {
|
||||||
|
|
|
@ -19,7 +19,7 @@ static struct wlr_x11_window *lookup_window(struct wl_list *list, xcb_window_t w
|
||||||
}
|
}
|
||||||
static struct wlr_x11_window *lookup_window_any(struct wlr_xwm *xwm, xcb_window_t window_id) {
|
static struct wlr_x11_window *lookup_window_any(struct wlr_xwm *xwm, xcb_window_t window_id) {
|
||||||
struct wlr_x11_window *window;
|
struct wlr_x11_window *window;
|
||||||
if ((window = lookup_window(&xwm->paired_windows, window_id)) ||
|
if ((window = lookup_window(&xwm->xwayland->displayable_windows, window_id)) ||
|
||||||
(window = lookup_window(&xwm->unpaired_windows, window_id)) ||
|
(window = lookup_window(&xwm->unpaired_windows, window_id)) ||
|
||||||
(window = lookup_window(&xwm->new_windows, window_id))) {
|
(window = lookup_window(&xwm->new_windows, window_id))) {
|
||||||
return window;
|
return window;
|
||||||
|
@ -71,10 +71,10 @@ static void map_shell_surface(struct wlr_xwm *xwm, struct wlr_x11_window *window
|
||||||
struct wlr_surface *surface) {
|
struct wlr_surface *surface) {
|
||||||
|
|
||||||
// get xcb geometry for depth = alpha channel
|
// get xcb geometry for depth = alpha channel
|
||||||
// TODO link to compositor somehow
|
window->surface = surface->resource;
|
||||||
|
|
||||||
wl_list_remove(&window->link);
|
wl_list_remove(&window->link);
|
||||||
wl_list_insert(&xwm->paired_windows, &window->link);
|
wl_list_insert(&xwm->xwayland->displayable_windows, &window->link);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* xcb event handlers */
|
/* xcb event handlers */
|
||||||
|
@ -96,7 +96,7 @@ static void handle_destroy_notify(struct wlr_xwm *xwm, xcb_destroy_notify_event_
|
||||||
static void handle_configure_request(struct wlr_xwm *xwm, xcb_configure_request_event_t *ev) {
|
static void handle_configure_request(struct wlr_xwm *xwm, xcb_configure_request_event_t *ev) {
|
||||||
struct wlr_x11_window *window;
|
struct wlr_x11_window *window;
|
||||||
wlr_log(L_DEBUG, "XCB_CONFIGURE_REQUEST (%u) [%ux%u+%d,%d]", ev->window,
|
wlr_log(L_DEBUG, "XCB_CONFIGURE_REQUEST (%u) [%ux%u+%d,%d]", ev->window,
|
||||||
ev->width, ev->height, ev->x, ev->y);
|
ev->width, ev->height, ev->x, ev->y);
|
||||||
if (!(window = lookup_window_any(xwm, ev->window))) {
|
if (!(window = lookup_window_any(xwm, ev->window))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -211,7 +211,7 @@ static int x11_event_handler(int fd, uint32_t mask, void *data) {
|
||||||
static void create_surface_handler(struct wl_listener *listener, void *data)
|
static void create_surface_handler(struct wl_listener *listener, void *data)
|
||||||
{
|
{
|
||||||
struct wlr_surface *surface = data;
|
struct wlr_surface *surface = data;
|
||||||
struct wlr_xwm *xwm = wl_container_of(listener, xwm, surface_create_listener);
|
struct wlr_xwm *xwm = wl_container_of(listener, xwm, surface_create_listener);
|
||||||
struct wlr_x11_window *window;
|
struct wlr_x11_window *window;
|
||||||
uint32_t surface_id;
|
uint32_t surface_id;
|
||||||
|
|
||||||
|
@ -308,7 +308,6 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) {
|
||||||
xwm->xwayland = wlr_xwayland;
|
xwm->xwayland = wlr_xwayland;
|
||||||
wl_list_init(&xwm->new_windows);
|
wl_list_init(&xwm->new_windows);
|
||||||
wl_list_init(&xwm->unpaired_windows);
|
wl_list_init(&xwm->unpaired_windows);
|
||||||
wl_list_init(&xwm->paired_windows);
|
|
||||||
|
|
||||||
xwm->xcb_conn = xcb_connect_to_fd(wlr_xwayland->wm_fd[0], NULL);
|
xwm->xcb_conn = xcb_connect_to_fd(wlr_xwayland->wm_fd[0], NULL);
|
||||||
if ((rc = xcb_connection_has_error(xwm->xcb_conn))) {
|
if ((rc = xcb_connection_has_error(xwm->xcb_conn))) {
|
||||||
|
@ -317,7 +316,7 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wl_event_loop *event_loop = wl_display_get_event_loop(wlr_xwayland->wl_display);
|
struct wl_event_loop *event_loop = wl_display_get_event_loop(wlr_xwayland->wl_display);
|
||||||
xwm->event_source = wl_event_loop_add_fd(event_loop, wlr_xwayland->wm_fd[0],
|
xwm->event_source = wl_event_loop_add_fd(event_loop, wlr_xwayland->wm_fd[0],
|
||||||
WL_EVENT_READABLE, x11_event_handler, xwm);
|
WL_EVENT_READABLE, x11_event_handler, xwm);
|
||||||
// probably not needed
|
// probably not needed
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#ifndef XWAYLAND_INTERNALS_H
|
#ifndef XWAYLAND_INTERNALS_H
|
||||||
#define XWAYLAND_INTERNALS_H
|
#define XWAYLAND_INTERNALS_H
|
||||||
#include <xcb/xcb.h>
|
|
||||||
#include <wayland-server-core.h>
|
#include <wayland-server-core.h>
|
||||||
#include <wlr/xwayland.h>
|
#include <wlr/xwayland.h>
|
||||||
|
|
||||||
|
@ -65,18 +64,6 @@ static const char * const atom_map[ATOM_LAST] = {
|
||||||
"_NET_WM_STATE",
|
"_NET_WM_STATE",
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wlr_x11_window {
|
|
||||||
xcb_window_t window_id;
|
|
||||||
uint32_t surface_id;
|
|
||||||
struct wl_list link;
|
|
||||||
|
|
||||||
struct wl_resource *surface;
|
|
||||||
struct wl_listener surface_destroy_listener;
|
|
||||||
int16_t x, y;
|
|
||||||
uint16_t width, height;
|
|
||||||
bool override_redirect;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct wlr_xwm {
|
struct wlr_xwm {
|
||||||
struct wlr_xwayland *xwayland;
|
struct wlr_xwayland *xwayland;
|
||||||
struct wl_event_source *event_source;
|
struct wl_event_source *event_source;
|
||||||
|
@ -89,7 +76,6 @@ struct wlr_xwm {
|
||||||
|
|
||||||
struct wl_list new_windows;
|
struct wl_list new_windows;
|
||||||
struct wl_list unpaired_windows;
|
struct wl_list unpaired_windows;
|
||||||
struct wl_list paired_windows;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void xwm_destroy(struct wlr_xwm *xwm);
|
void xwm_destroy(struct wlr_xwm *xwm);
|
||||||
|
|
Loading…
Reference in a new issue