Merge branch 'master' into xwayland-dnd

This commit is contained in:
emersion 2018-04-03 10:38:46 -04:00
commit 58ac05c276
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
18 changed files with 230 additions and 27 deletions

View File

@ -17,7 +17,7 @@ static struct wl_compositor *compositor = NULL;
static struct wl_seat *seat = NULL;
static struct wl_shm *shm = NULL;
static struct wl_pointer *pointer = NULL;
//static struct wl_keyboard *keyboard = NULL;
static struct wl_keyboard *keyboard = NULL;
static struct zwlr_layer_shell_v1 *layer_shell = NULL;
struct zwlr_layer_surface_v1 *layer_surface;
static struct wl_output *wl_output = NULL;
@ -36,6 +36,7 @@ static int32_t margin_top = 0;
static double alpha = 1.0;
static bool run_display = true;
static bool animate = false;
static bool keyboard_interactive = false;
static double frame = 0;
static int cur_x = -1, cur_y = -1;
static int buttons = 0;
@ -211,6 +212,46 @@ struct wl_pointer_listener pointer_listener = {
.axis_discrete = wl_pointer_axis_discrete,
};
static void wl_keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard,
uint32_t format, int32_t fd, uint32_t size) {
// Who cares
}
static void wl_keyboard_enter(void *data, struct wl_keyboard *wl_keyboard,
uint32_t serial, struct wl_surface *surface, struct wl_array *keys) {
wlr_log(L_DEBUG, "Keyboard enter");
}
static void wl_keyboard_leave(void *data, struct wl_keyboard *wl_keyboard,
uint32_t serial, struct wl_surface *surface) {
wlr_log(L_DEBUG, "Keyboard leave");
}
static void wl_keyboard_key(void *data, struct wl_keyboard *wl_keyboard,
uint32_t serial, uint32_t time, uint32_t key, uint32_t state) {
wlr_log(L_DEBUG, "Key event: %d %d", key, state);
}
static void wl_keyboard_modifiers(void *data, struct wl_keyboard *wl_keyboard,
uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched,
uint32_t mods_locked, uint32_t group) {
// Who cares
}
static void wl_keyboard_repeat_info(void *data, struct wl_keyboard *wl_keyboard,
int32_t rate, int32_t delay) {
// Who cares
}
static struct wl_keyboard_listener keyboard_listener = {
.keymap = wl_keyboard_keymap,
.enter = wl_keyboard_enter,
.leave = wl_keyboard_leave,
.key = wl_keyboard_key,
.modifiers = wl_keyboard_modifiers,
.repeat_info = wl_keyboard_repeat_info,
};
static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
enum wl_seat_capability caps) {
if ((caps & WL_SEAT_CAPABILITY_POINTER)) {
@ -218,7 +259,8 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
wl_pointer_add_listener(pointer, &pointer_listener, NULL);
}
if ((caps & WL_SEAT_CAPABILITY_KEYBOARD)) {
// TODO
keyboard = wl_seat_get_keyboard(wl_seat);
wl_keyboard_add_listener(keyboard, &keyboard_listener, NULL);
}
}
@ -274,7 +316,7 @@ int main(int argc, char **argv) {
int32_t margin_right = 0, margin_bottom = 0, margin_left = 0;
bool found;
int c;
while ((c = getopt(argc, argv, "nw:h:o:l:a:x:m:t:")) != -1) {
while ((c = getopt(argc, argv, "knw:h:o:l:a:x:m:t:")) != -1) {
switch (c) {
case 'o':
output = atoi(optarg);
@ -354,6 +396,9 @@ int main(int argc, char **argv) {
case 'n':
animate = true;
break;
case 'k':
keyboard_interactive = true;
break;
default:
break;
}
@ -407,9 +452,10 @@ int main(int argc, char **argv) {
zwlr_layer_surface_v1_set_exclusive_zone(layer_surface, exclusive_zone);
zwlr_layer_surface_v1_set_margin(layer_surface,
margin_top, margin_right, margin_bottom, margin_left);
zwlr_layer_surface_v1_set_keyboard_interactivity(
layer_surface, keyboard_interactive);
zwlr_layer_surface_v1_add_listener(layer_surface,
&layer_surface_listener, layer_surface);
// TODO: interactivity
wl_surface_commit(wl_surface);
wl_display_roundtrip(display);

View File

@ -4,6 +4,7 @@
#include <wayland-server.h>
#include "rootston/input.h"
#include "rootston/keyboard.h"
#include "rootston/layers.h"
struct roots_seat {
struct roots_input *input;
@ -15,6 +16,9 @@ struct roots_seat {
int32_t touch_id;
double touch_x, touch_y;
// If the focused layer is set, views cannot receive keyboard focus
struct wlr_layer_surface *focused_layer;
struct wl_list views; // roots_seat_view::link
bool has_focus;
@ -100,6 +104,9 @@ struct roots_view *roots_seat_get_focus(struct roots_seat *seat);
void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view);
void roots_seat_set_focus_layer(struct roots_seat *seat,
struct wlr_layer_surface *layer);
void roots_seat_cycle_focus(struct roots_seat *seat);
void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view);

View File

@ -99,4 +99,9 @@ void wlr_layer_surface_configure(struct wlr_layer_surface *surface,
*/
void wlr_layer_surface_close(struct wlr_layer_surface *surface);
bool wlr_surface_is_layer_surface(struct wlr_surface *surface);
struct wlr_layer_surface *wlr_layer_surface_from_wlr_surface(
struct wlr_surface *surface);
#endif

View File

@ -150,4 +150,9 @@ struct wlr_wl_shell_surface *wlr_wl_shell_surface_popup_at(
struct wlr_wl_shell_surface *surface, double sx, double sy,
double *popup_sx, double *popup_sy);
bool wlr_surface_is_wl_shell_surface(struct wlr_surface *surface);
struct wlr_wl_surface *wlr_wl_shell_surface_from_wlr_surface(
struct wlr_surface *surface);
#endif

View File

@ -229,4 +229,9 @@ struct wlr_xdg_surface *wlr_xdg_surface_popup_at(
struct wlr_xdg_surface *surface, double sx, double sy,
double *popup_sx, double *popup_sy);
bool wlr_surface_is_xdg_surface(struct wlr_surface *surface);
struct wlr_xdg_surface *wlr_xdg_surface_from_wlr_surface(
struct wlr_surface *surface);
#endif

View File

@ -289,4 +289,9 @@ void wlr_positioner_v6_invert_x(
void wlr_positioner_v6_invert_y(
struct wlr_xdg_positioner_v6 *positioner);
bool wlr_surface_is_xdg_surface_v6(struct wlr_surface *surface);
struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_from_wlr_surface(
struct wlr_surface *surface);
#endif

View File

@ -185,4 +185,9 @@ void wlr_xwayland_set_seat(struct wlr_xwayland *xwayland,
bool wlr_xwayland_surface_is_unmanaged(
const struct wlr_xwayland_surface *surface);
bool wlr_surface_is_xwayland_surface(struct wlr_surface *surface);
struct wlr_xwayland_surface *wlr_xwayland_surface_from_wlr_surface(
struct wlr_surface *surface);
#endif

View File

@ -58,30 +58,30 @@ libinput = dependency('libinput', version: '>=1.7.0')
xkbcommon = dependency('xkbcommon')
udev = dependency('libudev')
pixman = dependency('pixman-1')
libcap = dependency('libcap', required: get_option('enable_libcap') == 'true')
systemd = dependency('libsystemd', required: get_option('enable_systemd') == 'true')
elogind = dependency('libelogind', required: get_option('enable_elogind') == 'true')
libcap = dependency('libcap', required: get_option('enable-libcap') == 'true')
systemd = dependency('libsystemd', required: get_option('enable-systemd') == 'true')
elogind = dependency('libelogind', required: get_option('enable-elogind') == 'true')
math = cc.find_library('m', required: false)
exclude_headers = []
wlr_parts = []
wlr_deps = []
if libcap.found() and get_option('enable_libcap') != 'false'
if libcap.found() and get_option('enable-libcap') != 'false'
conf_data.set('WLR_HAS_LIBCAP', true)
wlr_deps += libcap
endif
if systemd.found() and get_option('enable_systemd') != 'false'
if systemd.found() and get_option('enable-systemd') != 'false'
conf_data.set('WLR_HAS_SYSTEMD', true)
wlr_deps += systemd
endif
if elogind.found() and get_option('enable_elogind') != 'false'
if elogind.found() and get_option('enable-elogind') != 'false'
conf_data.set('WLR_HAS_ELOGIND', true)
endif
if get_option('enable_x11_backend') or get_option('enable_xwayland')
if get_option('enable-x11_backend') or get_option('enable-xwayland')
xcb = dependency('xcb')
xcb_composite = dependency('xcb-composite')
xcb_xfixes = dependency('xcb-xfixes')
@ -91,7 +91,7 @@ if get_option('enable_x11_backend') or get_option('enable_xwayland')
xcb_icccm = dependency('xcb-icccm', required: false)
xcb_xkb = dependency('xcb-xkb', required: false)
xcb_errors = dependency('xcb-errors', required: get_option('enable_xcb_errors') == 'true')
xcb_errors = dependency('xcb-errors', required: get_option('enable-xcb_errors') == 'true')
if xcb_icccm.found()
conf_data.set('WLR_HAS_XCB_ICCCM', true)
@ -101,7 +101,7 @@ if get_option('enable_x11_backend') or get_option('enable_xwayland')
conf_data.set('WLR_HAS_XCB_XKB', true)
endif
if xcb_errors.found() and get_option('enable_xcb_errors') != 'false'
if xcb_errors.found() and get_option('enable-xcb_errors') != 'false'
conf_data.set('WLR_HAS_XCB_ERRORS', true)
endif
@ -114,11 +114,11 @@ else
add_project_arguments('-DMESA_EGL_NO_X11_HEADERS', language: 'c')
endif
if get_option('enable_x11_backend')
if get_option('enable-x11_backend')
conf_data.set('WLR_HAS_X11_BACKEND', true)
endif
if get_option('enable_xwayland')
if get_option('enable-xwayland')
subdir('xwayland')
wlr_parts += [lib_wlr_xwayland]
conf_data.set('WLR_HAS_XWAYLAND', true)

View File

@ -1,6 +1,6 @@
option('enable_libcap', type: 'combo', choices: ['auto', 'true', 'false'], value: 'auto', description: 'Enable support for capabilities')
option('enable_systemd', type: 'combo', choices: ['auto', 'true', 'false'], value: 'auto', description: 'Enable support for logind')
option('enable_elogind', type: 'combo', choices: ['auto', 'true', 'false'], value: 'auto', description: 'Enable support for logind')
option('enable_xcb_errors', type: 'combo', choices: ['auto', 'true', 'false'], value: 'auto', description: 'Use xcb-errors util library')
option('enable_xwayland', type: 'boolean', value: true, description: 'Enable support X11 applications')
option('enable_x11_backend', type: 'boolean', value: true, description: 'Enable X11 backend')
option('enable-libcap', type: 'combo', choices: ['auto', 'true', 'false'], value: 'auto', description: 'Enable support for capabilities')
option('enable-systemd', type: 'combo', choices: ['auto', 'true', 'false'], value: 'auto', description: 'Enable support for logind')
option('enable-elogind', type: 'combo', choices: ['auto', 'true', 'false'], value: 'auto', description: 'Enable support for logind')
option('enable-xcb_errors', type: 'combo', choices: ['auto', 'true', 'false'], value: 'auto', description: 'Use xcb-errors util library')
option('enable-xwayland', type: 'boolean', value: true, description: 'Enable support X11 applications')
option('enable-x11_backend', type: 'boolean', value: true, description: 'Enable X11 backend')

View File

@ -271,6 +271,13 @@ static void roots_cursor_press_button(struct roots_cursor *cursor,
break;
case WLR_BUTTON_PRESSED:
roots_seat_set_focus(seat, view);
if (wlr_surface_is_layer_surface(surface)) {
struct wlr_layer_surface *layer =
wlr_layer_surface_from_wlr_surface(surface);
if (layer->current.keyboard_interactive) {
roots_seat_set_focus_layer(seat, layer);
}
}
break;
}
}

View File

@ -192,6 +192,33 @@ void arrange_layers(struct roots_output *output) {
arrange_layer(output->wlr_output,
&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND],
&usable_area, false);
// Find topmost keyboard interactive layer, if such a layer exists
uint32_t layers_above_shell[] = {
ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY,
ZWLR_LAYER_SHELL_V1_LAYER_TOP,
};
size_t nlayers = sizeof(layers_above_shell) / sizeof(layers_above_shell[0]);
struct roots_layer_surface *layer, *topmost = NULL;
for (size_t i = 0; i < nlayers; ++i) {
wl_list_for_each_reverse(layer,
&output->layers[layers_above_shell[i]], link) {
if (layer->layer_surface->current.keyboard_interactive) {
topmost = layer;
break;
}
}
if (topmost != NULL) {
break;
}
}
struct roots_input *input = output->desktop->server->input;
struct roots_seat *seat;
wl_list_for_each(seat, &input->seats, link) {
roots_seat_set_focus_layer(seat,
topmost ? topmost->layer_surface : NULL);
}
}
static void handle_output_destroy(struct wl_listener *listener, void *data) {

View File

@ -13,7 +13,7 @@ sources = [
'xdg_shell_v6.c',
'xdg_shell.c',
]
if get_option('enable_xwayland')
if get_option('enable-xwayland')
sources += ['xwayland.c']
endif
executable(

View File

@ -4,6 +4,7 @@
#include <wayland-server.h>
#include <wlr/config.h>
#include <wlr/types/wlr_idle.h>
#include <wlr/types/wlr_layer_shell.h>
#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/util/log.h>
#include "rootston/cursor.h"
@ -723,7 +724,6 @@ void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) {
wl_list_insert(&seat->input->server->desktop->views, &view->link);
}
bool unfullscreen = true;
#ifdef WLR_HAS_XWAYLAND
@ -781,14 +781,18 @@ void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) {
return;
}
view_activate(view, true);
seat->has_focus = true;
wl_list_remove(&seat_view->link);
wl_list_insert(&seat->views, &seat_view->link);
view_damage_whole(view);
if (seat->focused_layer) {
return;
}
view_activate(view, true);
seat->has_focus = true;
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->seat);
if (keyboard != NULL) {
wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface,
@ -800,6 +804,37 @@ void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) {
}
}
/**
* Focus semantics of layer surfaces are somewhat detached from the normal focus
* flow. For layers above the shell layer, for example, you cannot unfocus them.
* You also cannot alt-tab between layer surfaces and shell surfaces.
*/
void roots_seat_set_focus_layer(struct roots_seat *seat,
struct wlr_layer_surface *layer) {
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->seat);
if (!layer) {
seat->focused_layer = NULL;
return;
}
if (seat->has_focus) {
struct roots_view *prev_focus = roots_seat_get_focus(seat);
wlr_seat_keyboard_clear_focus(seat->seat);
view_activate(prev_focus, false);
}
seat->has_focus = false;
if (layer->layer >= ZWLR_LAYER_SHELL_V1_LAYER_TOP) {
seat->focused_layer = layer;
}
if (keyboard != NULL) {
wlr_seat_keyboard_notify_enter(seat->seat, layer->surface,
keyboard->keycodes, keyboard->num_keycodes,
&keyboard->modifiers);
} else {
wlr_seat_keyboard_notify_enter(seat->seat, layer->surface,
NULL, 0, NULL);
}
}
void roots_seat_cycle_focus(struct roots_seat *seat) {
if (wl_list_empty(&seat->views)) {
return;

View File

@ -34,6 +34,16 @@ static struct wlr_layer_surface *layer_surface_from_resource(
return wl_resource_get_user_data(resource);
}
bool wlr_surface_is_layer_surface(struct wlr_surface *surface) {
return strcmp(surface->role, zwlr_layer_surface_role) == 0;
}
struct wlr_layer_surface *wlr_layer_surface_from_wlr_surface(
struct wlr_surface *surface) {
assert(wlr_surface_is_layer_surface(surface));
return (struct wlr_layer_surface *)surface->role_data;
}
static void layer_surface_configure_destroy(
struct wlr_layer_surface_configure *configure) {
if (configure == NULL) {

View File

@ -12,6 +12,16 @@
static const char *wlr_wl_shell_surface_role = "wl-shell-surface";
bool wlr_surface_is_wl_shell_surface(struct wlr_surface *surface) {
return strcmp(surface->role, wlr_wl_shell_surface_role) == 0;
}
struct wlr_wl_surface *wlr_wl_shell_surface_from_wlr_surface(
struct wlr_surface *surface) {
assert(wlr_surface_is_wl_shell_surface(surface));
return (struct wlr_wl_surface *)surface->role_data;
}
static void shell_pointer_grab_end(struct wlr_seat_pointer_grab *grab) {
struct wlr_wl_shell_popup_grab *popup_grab = grab->data;

View File

@ -16,6 +16,17 @@
static const char *wlr_desktop_xdg_toplevel_role = "xdg_toplevel";
static const char *wlr_desktop_xdg_popup_role = "xdg_popup";
bool wlr_surface_is_xdg_surface(struct wlr_surface *surface) {
return strcmp(surface->role, wlr_desktop_xdg_toplevel_role) == 0 ||
strcmp(surface->role, wlr_desktop_xdg_popup_role) == 0;
}
struct wlr_xdg_surface *wlr_xdg_surface_from_wlr_surface(
struct wlr_surface *surface) {
assert(wlr_surface_is_xdg_surface(surface));
return (struct wlr_xdg_surface *)surface->role_data;
}
struct wlr_xdg_positioner {
struct wl_resource *resource;

View File

@ -16,6 +16,17 @@
static const char *wlr_desktop_xdg_toplevel_role = "xdg_toplevel_v6";
static const char *wlr_desktop_xdg_popup_role = "xdg_popup_v6";
bool wlr_surface_is_xdg_surface_v6(struct wlr_surface *surface) {
return strcmp(surface->role, wlr_desktop_xdg_toplevel_role) == 0 ||
strcmp(surface->role, wlr_desktop_xdg_popup_role) == 0;
}
struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_from_wlr_surface(
struct wlr_surface *surface) {
assert(wlr_surface_is_xdg_surface_v6(surface));
return (struct wlr_xdg_surface_v6 *)surface->role_data;
}
struct wlr_xdg_positioner_v6_resource {
struct wl_resource *resource;
struct wlr_xdg_positioner_v6 attrs;

View File

@ -1,6 +1,7 @@
#ifndef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200809L
#endif
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <wlr/config.h>
@ -73,6 +74,18 @@ const char *atom_map[ATOM_LAST] = {
"XdndActionPrivate",
};
const char *wlr_xwayland_surface_role = "wlr_xwayland_surface";
bool wlr_surface_is_xwayland_surface(struct wlr_surface *surface) {
return strcmp(surface->role, wlr_xwayland_surface_role) == 0;
}
struct wlr_xwayland_surface *wlr_xwayland_surface_from_wlr_surface(
struct wlr_surface *surface) {
assert(wlr_surface_is_xwayland_surface(surface));
return (struct wlr_xwayland_surface *)surface->role_data;
}
// TODO: replace this with hash table?
static struct wlr_xwayland_surface *lookup_surface(struct wlr_xwm *xwm,
xcb_window_t window_id) {
@ -606,6 +619,7 @@ static void xwm_map_shell_surface(struct wlr_xwm *xwm,
read_surface_property(xwm, xsurface, props[i]);
}
wlr_surface_set_role(xsurface->surface, wlr_xwayland_surface_role, NULL, 0);
wlr_surface_set_role_committed(xsurface->surface, handle_surface_commit,
xsurface);