Merge branch 'master' into feature/xdg-popup

This commit is contained in:
Tony Crisci 2017-10-06 07:04:27 -04:00
commit 4657f10dd2
20 changed files with 374 additions and 56 deletions

View File

@ -34,8 +34,8 @@ static void wlr_drm_backend_destroy(struct wlr_backend *backend) {
wlr_output_destroy(&conn->output);
}
wlr_drm_renderer_finish(&drm->renderer);
wlr_drm_resources_free(drm);
wlr_drm_renderer_finish(&drm->renderer);
wlr_session_close_file(drm->session, drm->fd);
wl_event_source_remove(drm->drm_event);
list_free(drm->outputs);

View File

@ -169,6 +169,19 @@ void wlr_drm_resources_free(struct wlr_drm_backend *drm) {
drmModeDestroyPropertyBlob(drm->fd, crtc->mode_id);
}
}
for (size_t i = 0; i < drm->num_planes; ++i) {
struct wlr_drm_plane *plane = &drm->planes[i];
if (plane->cursor_bo) {
gbm_bo_destroy(plane->cursor_bo);
}
if (plane->wlr_tex) {
wlr_texture_destroy(plane->wlr_tex);
}
if (plane->wlr_rend) {
wlr_renderer_destroy(plane->wlr_rend);
}
}
free(drm->crtcs);
free(drm->planes);
}

View File

@ -33,6 +33,10 @@ struct roots_config {
struct wlr_box *mapped_box;
} cursor;
struct {
uint32_t meta_key;
} keyboard;
struct wl_list outputs;
struct wl_list devices;
struct wl_list bindings;

View File

@ -16,7 +16,6 @@ struct roots_output {
struct roots_desktop *desktop;
struct wlr_output *wlr_output;
struct wl_listener frame;
struct wl_listener resolution;
struct timespec last_frame;
struct wl_list link;
};

View File

@ -76,6 +76,7 @@ struct roots_input {
// TODO: multiseat, multicursor
struct wlr_cursor *cursor;
struct wlr_xcursor_theme *theme;
struct wlr_xcursor *xcursor;
struct wlr_seat *wl_seat;
@ -83,6 +84,7 @@ struct roots_input {
struct roots_view *active_view;
int offs_x, offs_y;
int view_x, view_y, view_width, view_height;
float view_rotation;
uint32_t resize_edges;
// Ring buffer of input events that could trigger move/resize/rotate

View File

@ -6,6 +6,10 @@
#include <wlr/types/wlr_compositor.h>
#include <xcb/xcb.h>
#ifdef HAS_XCB_ICCCM
#include <xcb/xcb_icccm.h>
#endif
struct wlr_xwm;
struct wlr_xwayland {
@ -29,6 +33,36 @@ struct wlr_xwayland {
void *data;
};
enum wlr_xwayland_surface_decorations {
WLR_XWAYLAND_SURFACE_DECORATIONS_ALL = 0,
WLR_XWAYLAND_SURFACE_DECORATIONS_NO_BORDER = 1,
WLR_XWAYLAND_SURFACE_DECORATIONS_NO_TITLE = 2,
};
struct wlr_xwayland_surface_hints {
uint32_t flags;
uint32_t input;
int32_t initial_state;
xcb_pixmap_t icon_pixmap;
xcb_window_t icon_window;
int32_t icon_x, icon_y;
xcb_pixmap_t icon_mask;
xcb_window_t window_group;
};
struct wlr_xwayland_surface_size_hints {
uint32_t flags;
int32_t x, y;
int32_t width, height;
int32_t min_width, min_height;
int32_t max_width, max_height;
int32_t width_inc, height_inc;
int32_t base_width, base_height;
int32_t min_aspect_num, min_aspect_den;
int32_t max_aspect_num, max_aspect_den;
uint32_t win_gravity;
};
struct wlr_xwayland_surface {
xcb_window_t window_id;
uint32_t surface_id;
@ -53,6 +87,11 @@ struct wlr_xwayland_surface {
xcb_atom_t *protocols;
size_t protocols_len;
uint32_t decorations;
struct wlr_xwayland_surface_hints *hints;
uint32_t hints_urgency;
struct wlr_xwayland_surface_size_hints *size_hints;
struct {
struct wl_signal destroy;

View File

@ -45,12 +45,17 @@ udev = dependency('libudev')
pixman = dependency('pixman-1')
xcb = dependency('xcb')
xcb_composite = dependency('xcb-composite')
xcb_icccm = dependency('xcb-icccm', required: false)
x11_xcb = dependency('x11-xcb')
libcap = dependency('libcap', required: false)
systemd = dependency('libsystemd', required: false)
elogind = dependency('libelogind', required: false)
math = cc.find_library('m', required: false)
if xcb_icccm.found()
add_project_arguments('-DHAS_XCB_ICCCM', language: 'c')
endif
if libcap.found() and get_option('enable_libcap')
add_project_arguments('-DHAS_LIBCAP', language: 'c')
endif

View File

@ -95,6 +95,7 @@ static void init_default_shaders() {
}
wlr_log(L_DEBUG, "Compiled default shaders");
shaders.initialized = true;
return;
error:
wlr_log(L_ERROR, "Failed to set up default shaders!");

View File

@ -86,6 +86,28 @@ invalid_input:
return NULL;
}
static uint32_t parse_modifier(const char *symname) {
if (strcmp(symname, "Shift") == 0) {
return WLR_MODIFIER_SHIFT;
} else if (strcmp(symname, "Caps") == 0) {
return WLR_MODIFIER_CAPS;
} else if (strcmp(symname, "Ctrl") == 0) {
return WLR_MODIFIER_CTRL;
} else if (strcmp(symname, "Alt") == 0) {
return WLR_MODIFIER_ALT;
} else if (strcmp(symname, "Mod2") == 0) {
return WLR_MODIFIER_MOD2;
} else if (strcmp(symname, "Mod3") == 0) {
return WLR_MODIFIER_MOD3;
} else if (strcmp(symname, "Logo") == 0) {
return WLR_MODIFIER_LOGO;
} else if (strcmp(symname, "Mod5") == 0) {
return WLR_MODIFIER_MOD5;
} else {
return 0;
}
}
static const char *output_prefix = "output:";
static const char *device_prefix = "device:";
@ -171,6 +193,15 @@ static int config_ini_handler(void *user, const char *section, const char *name,
} else {
wlr_log(L_ERROR, "got unknown device config: %s", name);
}
} else if (strcmp(section, "keyboard") == 0) {
if (strcmp(name, "meta-key") == 0) {
config->keyboard.meta_key = parse_modifier(value);
if (config->keyboard.meta_key == 0) {
wlr_log(L_ERROR, "got unknown meta key: %s", name);
}
} else {
wlr_log(L_ERROR, "got unknown keyboard config: %s", name);
}
} else if (strcmp(section, "bindings") == 0) {
struct binding_config *bc = calloc(1, sizeof(struct binding_config));
wl_list_insert(&config->bindings, &bc->link);
@ -190,22 +221,9 @@ static int config_ini_handler(void *user, const char *section, const char *name,
bc->keysyms = calloc(1, keysyms_len * sizeof(xkb_keysym_t));
char *symname = symnames;
for (size_t i = 0; i < keysyms_len; i++) {
if (strcmp(symname, "Shift") == 0) {
bc->modifiers |= WLR_MODIFIER_SHIFT;
} else if (strcmp(symname, "Caps") == 0) {
bc->modifiers |= WLR_MODIFIER_CAPS;
} else if (strcmp(symname, "Ctrl") == 0) {
bc->modifiers |= WLR_MODIFIER_CTRL;
} else if (strcmp(symname, "Alt") == 0) {
bc->modifiers |= WLR_MODIFIER_ALT;
} else if (strcmp(symname, "Mod2") == 0) {
bc->modifiers |= WLR_MODIFIER_MOD2;
} else if (strcmp(symname, "Mod3") == 0) {
bc->modifiers |= WLR_MODIFIER_MOD3;
} else if (strcmp(symname, "Logo") == 0) {
bc->modifiers |= WLR_MODIFIER_LOGO;
} else if (strcmp(symname, "Mod5") == 0) {
bc->modifiers |= WLR_MODIFIER_MOD5;
uint32_t modifier = parse_modifier(symname);
if (modifier != 0) {
bc->modifiers |= modifier;
} else {
xkb_keysym_t sym = xkb_keysym_from_name(symname,
XKB_KEYSYM_NO_FLAGS);

View File

@ -1,5 +1,8 @@
#define _XOPEN_SOURCE 500
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
// TODO: BSD et al
#include <linux/input-event-codes.h>
#include <wayland-server.h>
@ -24,15 +27,16 @@ const struct roots_input_event *get_input_event(struct roots_input *input,
void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor,
struct roots_view *view) {
input->mode = ROOTS_CURSOR_MOVE;
input->offs_x = cursor->x - view->x;
input->offs_y = cursor->y - view->y;
input->offs_x = cursor->x;
input->offs_y = cursor->y;
input->view_x = view->x;
input->view_y = view->y;
wlr_seat_pointer_clear_focus(input->wl_seat);
}
void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor,
struct roots_view *view, uint32_t edges) {
input->mode = ROOTS_CURSOR_RESIZE;
wlr_log(L_DEBUG, "begin resize");
input->offs_x = cursor->x;
input->offs_y = cursor->y;
input->view_x = view->x;
@ -45,6 +49,15 @@ void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor,
wlr_seat_pointer_clear_focus(input->wl_seat);
}
void view_begin_rotate(struct roots_input *input, struct wlr_cursor *cursor,
struct roots_view *view) {
input->mode = ROOTS_CURSOR_ROTATE;
input->offs_x = cursor->x;
input->offs_y = cursor->y;
input->view_rotation = view->rotation;
wlr_seat_pointer_clear_focus(input->wl_seat);
}
void cursor_update_position(struct roots_input *input, uint32_t time) {
struct roots_desktop *desktop = input->server->desktop;
struct roots_view *view;
@ -63,16 +76,18 @@ void cursor_update_position(struct roots_input *input, uint32_t time) {
break;
case ROOTS_CURSOR_MOVE:
if (input->active_view) {
input->active_view->x = input->cursor->x - input->offs_x;
input->active_view->y = input->cursor->y - input->offs_y;
int dx = input->cursor->x - input->offs_x,
dy = input->cursor->y - input->offs_y;
input->active_view->x = input->view_x + dx;
input->active_view->y = input->view_y + dy;
}
break;
case ROOTS_CURSOR_RESIZE:
if (input->active_view) {
int dx = input->cursor->x - input->offs_x;
int dy = input->cursor->y - input->offs_y;
int width = input->view_width;
int height = input->view_height;
int dx = input->cursor->x - input->offs_x,
dy = input->cursor->y - input->offs_y;
int width = input->view_width,
height = input->view_height;
if (input->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) {
input->active_view->y = input->view_y + dy;
height -= dy;
@ -91,6 +106,19 @@ void cursor_update_position(struct roots_input *input, uint32_t time) {
}
break;
case ROOTS_CURSOR_ROTATE:
if (input->active_view) {
struct roots_view *view = input->active_view;
int ox = view->x + view->wlr_surface->current->width/2,
oy = view->y + view->wlr_surface->current->height/2;
int ux = input->offs_x - ox,
uy = input->offs_y - oy;
int vx = input->cursor->x - ox,
vy = input->cursor->y - oy;
float angle = atan2(vx*uy - vy*ux, vx*ux + vy*uy);
int steps = 12;
angle = round(angle/M_PI*steps) / (steps/M_PI);
view->rotation = input->view_rotation + angle;
}
break;
}
}
@ -100,6 +128,12 @@ static void set_view_focus(struct roots_input *input,
if (input->active_view == view) {
return;
}
input->active_view = view;
input->mode = ROOTS_CURSOR_PASSTHROUGH;
if (!view) {
return;
}
size_t index = 0;
for (size_t i = 0; i < desktop->views->length; ++i) {
struct roots_view *_view = desktop->views->items[i];
@ -108,8 +142,6 @@ static void set_view_focus(struct roots_input *input,
index = i;
}
}
input->active_view = view;
input->mode = ROOTS_CURSOR_PASSTHROUGH;
// TODO: list_swap
list_del(desktop->views, index);
list_add(desktop->views, view);
@ -141,6 +173,23 @@ static void handle_cursor_axis(struct wl_listener *listener, void *data) {
event->orientation, event->delta);
}
static bool is_meta_pressed(struct roots_input *input) {
uint32_t meta_key = input->server->config->keyboard.meta_key;
if (meta_key == 0) {
return false;
}
struct roots_keyboard *keyboard;
wl_list_for_each(keyboard, &input->keyboards, link) {
uint32_t modifiers =
wlr_keyboard_get_modifiers(keyboard->device->keyboard);
if ((modifiers ^ meta_key) == 0) {
return true;
}
}
return false;
}
static void do_cursor_button_press(struct roots_input *input,
struct wlr_cursor *cursor, struct wlr_input_device *device,
uint32_t time, uint32_t button, uint32_t state) {
@ -148,14 +197,33 @@ static void do_cursor_button_press(struct roots_input *input,
struct wlr_surface *surface;
double sx, sy;
struct roots_view *view = view_at(desktop,
input->cursor->x, input->cursor->y, &surface, &sx, &sy);
uint32_t serial = wlr_seat_pointer_notify_button(
input->wl_seat, time, button, state);
input->cursor->x, input->cursor->y, &surface, &sx, &sy);
if (state == WLR_BUTTON_PRESSED && view && is_meta_pressed(input)) {
set_view_focus(input, desktop, view);
switch (button) {
case BTN_LEFT:
view_begin_move(input, cursor, view);
break;
case BTN_RIGHT:
view_begin_resize(input, cursor, view,
ROOTS_CURSOR_RESIZE_EDGE_RIGHT |
ROOTS_CURSOR_RESIZE_EDGE_BOTTOM);
break;
case BTN_MIDDLE:
view_begin_rotate(input, cursor, view);
}
return;
}
uint32_t serial = wlr_seat_pointer_notify_button(input->wl_seat, time, button,
state);
int i;
switch (state) {
case WLR_BUTTON_RELEASED:
input->active_view = NULL;
input->mode = ROOTS_CURSOR_PASSTHROUGH;
set_view_focus(input, desktop, NULL);
break;
case WLR_BUTTON_PRESSED:
i = input->input_events_idx;

View File

@ -2,6 +2,7 @@
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <math.h>
#include <wlr/types/wlr_box.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_cursor.h>
@ -131,7 +132,21 @@ struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly,
double view_sx = lx - view->x;
double view_sy = ly - view->y;
struct wlr_box box;
view_get_input_bounds(view, &box);
if (view->rotation != 0.0) {
// Coordinates relative to the center of the view
double ox = view_sx - (double)box.width/2,
oy = view_sy - (double)box.height/2;
// Rotated coordinates
double rx = cos(view->rotation)*ox - sin(view->rotation)*oy,
ry = cos(view->rotation)*oy + sin(view->rotation)*ox;
view_sx = rx + (double)box.width/2;
view_sy = ry + (double)box.height/2;
}
if (view->type == ROOTS_XDG_SHELL_V6_VIEW) {
// TODO: test if this works with rotated views
double popup_sx, popup_sy;
struct wlr_xdg_surface_v6 *popup =
xdg_v6_popup_at(view->xdg_surface_v6, view_sx, view_sy,
@ -148,7 +163,6 @@ struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly,
double sub_x, sub_y;
struct wlr_subsurface *subsurface =
subsurface_at(view->wlr_surface, view_sx, view_sy, &sub_x, &sub_y);
if (subsurface) {
*sx = view_sx - sub_x;
*sy = view_sy - sub_y;
@ -156,11 +170,7 @@ struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly,
return view;
}
struct wlr_box box;
view_get_input_bounds(view, &box);
box.x += view->x;
box.y += view->y;
if (wlr_box_contains_point(&box, lx, ly)) {
if (wlr_box_contains_point(&box, view_sx, view_sy)) {
*sx = view_sx;
*sy = view_sy;
*surface = view->wlr_surface;

View File

@ -79,9 +79,8 @@ struct roots_input *input_create(struct roots_server *server,
input->config = config;
input->server = server;
struct wlr_xcursor_theme *theme;
assert(theme = wlr_xcursor_theme_load("default", 16));
assert(input->xcursor = wlr_xcursor_theme_get_cursor(theme, "left_ptr"));
assert(input->theme = wlr_xcursor_theme_load("default", 16));
assert(input->xcursor = wlr_xcursor_theme_get_cursor(input->theme, "left_ptr"));
assert(input->wl_seat = wlr_seat_create(server->wl_display, "seat0"));
wlr_seat_set_capabilities(input->wl_seat, WL_SEAT_CAPABILITY_KEYBOARD

View File

@ -43,5 +43,6 @@ int main(int argc, char **argv) {
setenv("WAYLAND_DISPLAY", socket, true);
wl_display_run(server.wl_display);
wlr_backend_destroy(server.backend);
return 0;
}

View File

@ -18,7 +18,7 @@ static inline int64_t timespec_to_msec(const struct timespec *a) {
static void render_surface(struct wlr_surface *surface,
struct roots_desktop *desktop, struct wlr_output *wlr_output,
struct timespec *when, double lx, double ly) {
struct timespec *when, double lx, double ly, float rotation) {
wlr_surface_flush_damage(surface);
if (surface->texture->valid) {
int width = surface->current->buffer_width;
@ -27,10 +27,19 @@ static void render_surface(struct wlr_surface *surface,
wlr_output_layout_output_coords(desktop->layout, wlr_output, &ox, &oy);
if (wlr_output_layout_intersects(desktop->layout, wlr_output,
lx, ly, lx + width, ly + height)) {
lx, ly, lx + width, ly + height)) {
float matrix[16];
float translate_origin[16];
wlr_matrix_translate(&translate_origin,
(int)ox + width / 2, (int)oy + height / 2, 0);
float rotate[16];
wlr_matrix_rotate(&rotate, rotation);
float translate_center[16];
wlr_matrix_translate(&translate_center, -width / 2, -height / 2, 0);
float transform[16];
wlr_matrix_translate(&transform, ox, oy, 0);
wlr_matrix_mul(&translate_origin, &rotate, &transform);
wlr_matrix_mul(&transform, &translate_center, &transform);
wlr_surface_get_matrix(surface, &matrix,
&wlr_output->transform_matrix, &transform);
wlr_render_with_matrix(desktop->server->renderer,
@ -46,16 +55,33 @@ static void render_surface(struct wlr_surface *surface,
struct wlr_subsurface *subsurface;
wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
double sx = subsurface->surface->current->subsurface_position.x,
sy = subsurface->surface->current->subsurface_position.y;
double sw = subsurface->surface->current->buffer_width,
sh = subsurface->surface->current->buffer_height;
if (rotation != 0.0) {
// Coordinates relative to the center of the subsurface
double ox = sx - (double)width/2 + sw/2,
oy = sy - (double)height/2 + sh/2;
// Rotated coordinates
double rx = cos(-rotation)*ox - sin(-rotation)*oy,
ry = cos(-rotation)*oy + sin(-rotation)*ox;
sx = rx + (double)width/2 - sw/2;
sy = ry + (double)height/2 - sh/2;
}
render_surface(subsurface->surface, desktop, wlr_output, when,
lx + subsurface->surface->current->subsurface_position.x,
ly + subsurface->surface->current->subsurface_position.y);
lx + sx,
ly + sy,
rotation);
}
}
}
static void render_xdg_v6_popups(struct wlr_xdg_surface_v6 *surface,
struct roots_desktop *desktop, struct wlr_output *wlr_output,
struct timespec *when, double base_x, double base_y) {
struct timespec *when, double base_x, double base_y, float rotation) {
// TODO: make sure this works with view rotation
struct wlr_xdg_surface_v6 *popup;
wl_list_for_each(popup, &surface->popups, popup_link) {
if (!popup->configured) {
@ -67,18 +93,18 @@ static void render_xdg_v6_popups(struct wlr_xdg_surface_v6 *surface,
double popup_y = base_y + surface->geometry->y +
popup->popup_state->geometry.y - popup->geometry->y;
render_surface(popup->surface, desktop, wlr_output, when, popup_x,
popup_y);
render_xdg_v6_popups(popup, desktop, wlr_output, when, popup_x, popup_y);
popup_y, rotation);
render_xdg_v6_popups(popup, desktop, wlr_output, when, popup_x, popup_y, rotation);
}
}
static void render_view(struct roots_view *view, struct roots_desktop *desktop,
struct wlr_output *wlr_output, struct timespec *when) {
render_surface(view->wlr_surface, desktop, wlr_output, when,
view->x, view->y);
view->x, view->y, view->rotation);
if (view->type == ROOTS_XDG_SHELL_V6_VIEW) {
render_xdg_v6_popups(view->xdg_surface_v6, desktop, wlr_output,
when, view->x, view->y);
when, view->x, view->y, view->rotation);
}
}
@ -170,6 +196,5 @@ void output_remove_notify(struct wl_listener *listener, void *data) {
// sample->compositor);
wl_list_remove(&output->link);
wl_list_remove(&output->frame.link);
wl_list_remove(&output->resolution.link);
free(output);
}

View File

@ -25,8 +25,11 @@ map-to-output = VGA-1
# Restrict cursor movements for this mouse to concrete rectangle
geometry = 2500x800
[keyboard]
meta-key = Logo
# Keybindings
# Maps key combinations with commands to execute
# The special command "exit" stops the compositor
[bindings]
Logo+q=exit
Logo+q = exit

View File

@ -306,6 +306,8 @@ static void pointer_surface_destroy_notify(struct wl_listener *listener,
void *data) {
struct wlr_seat_pointer_state *state = wl_container_of(
listener, state, surface_destroy);
wl_list_remove(&state->surface_destroy.link);
wl_list_init(&state->surface_destroy.link);
state->focused_surface = NULL;
wlr_seat_pointer_clear_focus(state->wlr_seat);
}
@ -314,6 +316,8 @@ static void pointer_resource_destroy_notify(struct wl_listener *listener,
void *data) {
struct wlr_seat_pointer_state *state = wl_container_of(
listener, state, resource_destroy);
wl_list_remove(&state->resource_destroy.link);
wl_list_init(&state->resource_destroy.link);
state->focused_surface = NULL;
wlr_seat_pointer_clear_focus(state->wlr_seat);
}
@ -579,6 +583,8 @@ static void keyboard_surface_destroy_notify(struct wl_listener *listener,
void *data) {
struct wlr_seat_keyboard_state *state = wl_container_of(
listener, state, surface_destroy);
wl_list_remove(&state->surface_destroy.link);
wl_list_init(&state->surface_destroy.link);
state->focused_surface = NULL;
wlr_seat_keyboard_clear_focus(state->wlr_seat);
}
@ -587,6 +593,8 @@ static void keyboard_resource_destroy_notify(struct wl_listener *listener,
void *data) {
struct wlr_seat_keyboard_state *state = wl_container_of(
listener, state, resource_destroy);
wl_list_remove(&state->resource_destroy.link);
wl_list_init(&state->resource_destroy.link);
state->focused_surface = NULL;
wlr_seat_keyboard_clear_focus(state->wlr_seat);
}

View File

@ -6,5 +6,5 @@ lib_wlr_xwayland = static_library(
'xwm.c',
),
include_directories: wlr_inc,
dependencies: [wayland_server, xcb, xcb_composite, pixman],
dependencies: [wayland_server, xcb, xcb_composite, xcb_icccm, pixman],
)

View File

@ -215,6 +215,10 @@ static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland,
wlr_xwayland_finish(wlr_xwayland);
return false;
}
// unset $DISPLAY while XWayland starts
unsetenv("DISPLAY");
wlr_xwayland->wl_fd[0] = -1; /* not ours anymore */
wlr_xwayland->destroy_listener.notify = xwayland_destroy_event;

View File

@ -8,10 +8,18 @@
#include "wlr/xwayland.h"
#include "xwm.h"
#ifdef HAS_XCB_ICCCM
#include <xcb/xcb_icccm.h>
#endif
const char *atom_map[ATOM_LAST] = {
"WL_SURFACE_ID",
"WM_DELETE_WINDOW",
"WM_HINTS",
"WM_PROTOCOLS",
"WM_NORMAL_HINTS",
"WM_SIZE_HINTS",
"_MOTIF_WM_HINTS",
"UTF8_STRING",
"WM_S0",
"_NET_SUPPORTED",
@ -81,8 +89,14 @@ static void wlr_xwayland_surface_destroy(struct wlr_xwayland_surface *surface) {
for (size_t i = 0; i < surface->state->length; i++) {
free(surface->state->items[i]);
}
free(surface->title);
free(surface->class);
free(surface->instance);
list_free(surface->state);
free(surface->window_type);
free(surface->protocols);
free(surface->hints);
free(surface->size_hints);
free(surface);
}
@ -265,6 +279,98 @@ static void read_surface_protocols(struct wlr_xwm *xwm,
wlr_log(L_DEBUG, "WM_PROTOCOLS (%zu)", atoms_len);
}
#ifdef HAS_XCB_ICCCM
static void read_surface_hints(struct wlr_xwm *xwm,
struct wlr_xwayland_surface *surface, xcb_get_property_reply_t *reply) {
// According to the docs, reply->type == xwm->atoms[WM_HINTS]
// In practice, reply->type == XCB_ATOM_ATOM
if (reply->value_len == 0) {
return;
}
xcb_icccm_wm_hints_t hints;
xcb_icccm_get_wm_hints_from_reply(&hints, reply);
free(surface->hints);
surface->hints = calloc(1, sizeof(struct wlr_xwayland_surface_hints));
if (surface->hints == NULL) {
return;
}
memcpy(surface->hints, &hints, sizeof(struct wlr_xwayland_surface_hints));
surface->hints_urgency = xcb_icccm_wm_hints_get_urgency(&hints);
wlr_log(L_DEBUG, "WM_HINTS (%d)", reply->value_len);
}
#else
static void read_surface_hints(struct wlr_xwm *xwm,
struct wlr_xwayland_surface *surface, xcb_get_property_reply_t *reply) {
// Do nothing
}
#endif
#ifdef HAS_XCB_ICCCM
static void read_surface_normal_hints(struct wlr_xwm *xwm,
struct wlr_xwayland_surface *surface, xcb_get_property_reply_t *reply) {
if (reply->type != xwm->atoms[WM_SIZE_HINTS] || reply->value_len == 0) {
return;
}
xcb_size_hints_t size_hints;
xcb_icccm_get_wm_size_hints_from_reply(&size_hints, reply);
free(surface->size_hints);
surface->size_hints =
calloc(1, sizeof(struct wlr_xwayland_surface_size_hints));
if (surface->size_hints == NULL) {
return;
}
memcpy(surface->size_hints, &size_hints,
sizeof(struct wlr_xwayland_surface_size_hints));
wlr_log(L_DEBUG, "WM_NORMAL_HINTS (%d)", reply->value_len);
}
#else
static void read_surface_normal_hints(struct wlr_xwm *xwm,
struct wlr_xwayland_surface *surface, xcb_get_property_reply_t *reply) {
// Do nothing
}
#endif
#define MWM_HINTS_FLAGS_FIELD 0
#define MWM_HINTS_DECORATIONS_FIELD 2
#define MWM_HINTS_DECORATIONS (1 << 1)
#define MWM_DECOR_ALL (1 << 0)
#define MWM_DECOR_BORDER (1 << 1)
#define MWM_DECOR_TITLE (1 << 3)
static void read_surface_motif_hints(struct wlr_xwm *xwm,
struct wlr_xwayland_surface *surface, xcb_get_property_reply_t *reply) {
if (reply->value_len < 5) {
return;
}
uint32_t *motif_hints = xcb_get_property_value(reply);
if (motif_hints[MWM_HINTS_FLAGS_FIELD] & MWM_HINTS_DECORATIONS) {
surface->decorations = WLR_XWAYLAND_SURFACE_DECORATIONS_ALL;
uint32_t decorations = motif_hints[MWM_HINTS_DECORATIONS_FIELD];
if ((decorations & MWM_DECOR_ALL) == 0) {
if ((decorations & MWM_DECOR_BORDER) == 0) {
surface->decorations |=
WLR_XWAYLAND_SURFACE_DECORATIONS_NO_BORDER;
}
if ((decorations & MWM_DECOR_TITLE) == 0) {
surface->decorations |=
WLR_XWAYLAND_SURFACE_DECORATIONS_NO_TITLE;
}
}
}
wlr_log(L_DEBUG, "MOTIF_WM_HINTS (%d)", reply->value_len);
}
static void read_surface_property(struct wlr_xwm *xwm,
struct wlr_xwayland_surface *surface, xcb_atom_t property) {
xcb_get_property_cookie_t cookie = xcb_get_property(xwm->xcb_conn, 0,
@ -290,6 +396,12 @@ static void read_surface_property(struct wlr_xwm *xwm,
read_surface_protocols(xwm, surface, reply);
} else if (property == xwm->atoms[NET_WM_STATE]) {
read_surface_state(xwm, surface, reply);
} else if (property == xwm->atoms[WM_HINTS]) {
read_surface_hints(xwm, surface, reply);
} else if (property == xwm->atoms[WM_NORMAL_HINTS]) {
read_surface_normal_hints(xwm, surface, reply);
} else if (property == xwm->atoms[MOTIF_WM_HINTS]) {
read_surface_motif_hints(xwm, surface, reply);
} else {
wlr_log(L_DEBUG, "unhandled x11 property %u", property);
}
@ -309,6 +421,9 @@ static void map_shell_surface(struct wlr_xwm *xwm,
XCB_ATOM_WM_NAME,
XCB_ATOM_WM_TRANSIENT_FOR,
xwm->atoms[WM_PROTOCOLS],
xwm->atoms[WM_HINTS],
xwm->atoms[WM_NORMAL_HINTS],
xwm->atoms[MOTIF_WM_HINTS],
xwm->atoms[NET_WM_STATE],
xwm->atoms[NET_WM_WINDOW_TYPE],
xwm->atoms[NET_WM_NAME],

View File

@ -49,6 +49,10 @@ enum atom_name {
WL_SURFACE_ID,
WM_DELETE_WINDOW,
WM_PROTOCOLS,
WM_HINTS,
WM_NORMAL_HINTS,
WM_SIZE_HINTS,
MOTIF_WM_HINTS,
UTF8_STRING,
WM_S0,
NET_SUPPORTED,