From d74ac69f7b932a8833527a41351e3310ad391d7c Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 7 Dec 2017 11:19:43 -0500 Subject: bring edges into wlr --- include/wlr/types/wlr_xcursor_manager.h | 7 +++++++ include/wlr/util/edges.h | 12 ++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 include/wlr/util/edges.h (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_xcursor_manager.h b/include/wlr/types/wlr_xcursor_manager.h index c78a6e8d..63eb5386 100644 --- a/include/wlr/types/wlr_xcursor_manager.h +++ b/include/wlr/types/wlr_xcursor_manager.h @@ -4,6 +4,7 @@ #include #include #include +#include /** * A scaled XCursor theme. @@ -50,4 +51,10 @@ struct wlr_xcursor *wlr_xcursor_manager_get_xcursor( void wlr_xcursor_manager_set_cursor_image(struct wlr_xcursor_manager *manager, const char *name, struct wlr_cursor *cursor); +/** + * Get the name of the cursor image for the given edges. + */ +const char *wlr_xcursor_manager_get_resize_name(enum wlr_edges edges); + + #endif diff --git a/include/wlr/util/edges.h b/include/wlr/util/edges.h new file mode 100644 index 00000000..53268323 --- /dev/null +++ b/include/wlr/util/edges.h @@ -0,0 +1,12 @@ +#ifndef WLR_UTIL_EDGES_H +#define WLR_UTIL_EDGES_H + +enum wlr_edges { + WLR_EDGE_NONE = 0, + WLR_EDGE_TOP = 1, + WLR_EDGE_BOTTOM = 2, + WLR_EDGE_LEFT = 4, + WLR_EDGE_RIGHT = 8, +}; + +#endif -- cgit v1.2.3 From 4c60072be584a7ed5b97de325994217a9e96bbd4 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Fri, 8 Dec 2017 06:08:06 -0500 Subject: move get_resize_name to xcursor --- include/wlr/types/wlr_xcursor_manager.h | 7 ------- include/wlr/xcursor.h | 6 ++++++ rootston/seat.c | 2 +- types/wlr_xcursor_manager.c | 23 ----------------------- xcursor/wlr_xcursor.c | 23 +++++++++++++++++++++++ 5 files changed, 30 insertions(+), 31 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_xcursor_manager.h b/include/wlr/types/wlr_xcursor_manager.h index 63eb5386..c78a6e8d 100644 --- a/include/wlr/types/wlr_xcursor_manager.h +++ b/include/wlr/types/wlr_xcursor_manager.h @@ -4,7 +4,6 @@ #include #include #include -#include /** * A scaled XCursor theme. @@ -51,10 +50,4 @@ struct wlr_xcursor *wlr_xcursor_manager_get_xcursor( void wlr_xcursor_manager_set_cursor_image(struct wlr_xcursor_manager *manager, const char *name, struct wlr_cursor *cursor); -/** - * Get the name of the cursor image for the given edges. - */ -const char *wlr_xcursor_manager_get_resize_name(enum wlr_edges edges); - - #endif diff --git a/include/wlr/xcursor.h b/include/wlr/xcursor.h index b6362b06..42fcedb9 100644 --- a/include/wlr/xcursor.h +++ b/include/wlr/xcursor.h @@ -32,6 +32,7 @@ #define WLR_XCURSOR_H #include +#include struct wlr_xcursor_image { uint32_t width; /* actual width */ @@ -65,4 +66,9 @@ struct wlr_xcursor *wlr_xcursor_theme_get_cursor( int wlr_xcursor_frame(struct wlr_xcursor *cursor, uint32_t time); +/** + * Get the name of the resize cursor image for the given edges. + */ +const char *wlr_xcursor_get_resize_name(enum wlr_edges edges); + #endif diff --git a/rootston/seat.c b/rootston/seat.c index f6473581..1fa09ad6 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -661,7 +661,7 @@ void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view, view_maximize(view, false); wlr_seat_pointer_clear_focus(seat->seat); - const char *resize_name = wlr_xcursor_manager_get_resize_name(edges); + const char *resize_name = wlr_xcursor_get_resize_name(edges); wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager, resize_name, seat->cursor->cursor); } diff --git a/types/wlr_xcursor_manager.c b/types/wlr_xcursor_manager.c index 9350d721..f32a96bc 100644 --- a/types/wlr_xcursor_manager.c +++ b/types/wlr_xcursor_manager.c @@ -82,26 +82,3 @@ void wlr_xcursor_manager_set_cursor_image(struct wlr_xcursor_manager *manager, theme->scale); } } - -const char *wlr_xcursor_manager_get_resize_name(enum wlr_edges edges) { - if (edges & WLR_EDGE_TOP) { - if (edges & WLR_EDGE_RIGHT) { - return "ne-resize"; - } else if (edges & WLR_EDGE_LEFT) { - return "nw-resize"; - } - return "n-resize"; - } else if (edges & WLR_EDGE_BOTTOM) { - if (edges & WLR_EDGE_RIGHT) { - return "se-resize"; - } else if (edges & WLR_EDGE_LEFT) { - return "sw-resize"; - } - return "s-resize"; - } else if (edges & WLR_EDGE_RIGHT) { - return "e-resize"; - } else if (edges & WLR_EDGE_LEFT) { - return "w-resize"; - } - return "se-resize"; // fallback -} diff --git a/xcursor/wlr_xcursor.c b/xcursor/wlr_xcursor.c index fdebe1af..b1678223 100644 --- a/xcursor/wlr_xcursor.c +++ b/xcursor/wlr_xcursor.c @@ -326,3 +326,26 @@ static int wlr_xcursor_frame_and_duration(struct wlr_xcursor *cursor, int wlr_xcursor_frame(struct wlr_xcursor *_cursor, uint32_t time) { return wlr_xcursor_frame_and_duration(_cursor, time, NULL); } + +const char *wlr_xcursor_get_resize_name(enum wlr_edges edges) { + if (edges & WLR_EDGE_TOP) { + if (edges & WLR_EDGE_RIGHT) { + return "ne-resize"; + } else if (edges & WLR_EDGE_LEFT) { + return "nw-resize"; + } + return "n-resize"; + } else if (edges & WLR_EDGE_BOTTOM) { + if (edges & WLR_EDGE_RIGHT) { + return "se-resize"; + } else if (edges & WLR_EDGE_LEFT) { + return "sw-resize"; + } + return "s-resize"; + } else if (edges & WLR_EDGE_RIGHT) { + return "e-resize"; + } else if (edges & WLR_EDGE_LEFT) { + return "w-resize"; + } + return "se-resize"; // fallback +} -- cgit v1.2.3 From c5fa415a0373e0fbd974d4a8aee94014050b93f2 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 8 Dec 2017 14:23:33 +0100 Subject: Send wl_surface.{enter,leave} to cursor surfaces --- include/rootston/xcursor.h | 2 +- include/wlr/types/wlr_output.h | 4 +++ types/wlr_output.c | 75 +++++++++++++++++++++++++++++------------- 3 files changed, 58 insertions(+), 23 deletions(-) (limited to 'include/wlr') diff --git a/include/rootston/xcursor.h b/include/rootston/xcursor.h index 285db78d..a7d2b960 100644 --- a/include/rootston/xcursor.h +++ b/include/rootston/xcursor.h @@ -3,7 +3,7 @@ #include -#define ROOTS_XCURSOR_SIZE 16 +#define ROOTS_XCURSOR_SIZE 24 #define ROOTS_XCURSOR_DEFAULT "left_ptr" #define ROOTS_XCURSOR_MOVE "grabbing" diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 42c46233..895536e1 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -16,6 +16,7 @@ struct wlr_output_cursor { struct wlr_output *output; double x, y; bool enabled; + bool visible; uint32_t width, height; int32_t hotspot_x, hotspot_y; struct wl_list link; @@ -98,6 +99,9 @@ void wlr_output_set_fullscreen_surface(struct wlr_output *output, struct wlr_surface *surface); struct wlr_output_cursor *wlr_output_cursor_create(struct wlr_output *output); +/** + * Sets the cursor image. The image must be already scaled for the output. + */ bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, const uint8_t *pixels, int32_t stride, uint32_t width, uint32_t height, int32_t hotspot_x, int32_t hotspot_y); diff --git a/types/wlr_output.c b/types/wlr_output.c index ed74004d..3141e9ef 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -316,6 +316,11 @@ static void output_cursor_get_box(struct wlr_output_cursor *cursor, box->y = cursor->y - cursor->hotspot_y; box->width = cursor->width; box->height = cursor->height; + + if (cursor->surface != NULL) { + box->x += cursor->surface->current->sx; + box->y += cursor->surface->current->sy; + } } static void output_cursor_render(struct wlr_output_cursor *cursor, @@ -331,36 +336,29 @@ static void output_cursor_render(struct wlr_output_cursor *cursor, return; } - struct wlr_box output_box; - output_box.x = output_box.y = 0; - wlr_output_effective_resolution(cursor->output, &output_box.width, - &output_box.height); - output_box.width *= cursor->output->scale; - output_box.height *= cursor->output->scale; + glViewport(0, 0, cursor->output->width, cursor->output->height); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); struct wlr_box cursor_box; output_cursor_get_box(cursor, &cursor_box); - struct wlr_box intersection; - struct wlr_box *intersection_ptr = &intersection; - if (!wlr_box_intersection(&output_box, &cursor_box, &intersection_ptr)) { - return; - } - - glViewport(0, 0, cursor->output->width, cursor->output->height); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + float translate[16]; + wlr_matrix_translate(&translate, cursor_box.x, cursor_box.y, 0); - int x = cursor->x - cursor->hotspot_x; - int y = cursor->y - cursor->hotspot_y; + // Assume cursors without a surface are already scaled for the output if (cursor->surface != NULL) { - x += cursor->surface->current->sx; - y += cursor->surface->current->sy; + cursor_box.width *= cursor->output->scale; + cursor_box.height *= cursor->output->scale; } + float scale[16]; + wlr_matrix_scale(&scale, cursor_box.width, cursor_box.height, 1); + float matrix[16]; - wlr_texture_get_matrix(texture, &matrix, &cursor->output->transform_matrix, - x, y); + wlr_matrix_mul(&translate, &scale, &matrix); + wlr_matrix_mul(&cursor->output->transform_matrix, &matrix, &matrix); + wlr_render_with_matrix(renderer, texture, &matrix); if (cursor->surface != NULL) { @@ -381,7 +379,8 @@ void wlr_output_swap_buffers(struct wlr_output *output) { struct wlr_output_cursor *cursor; wl_list_for_each(cursor, &output->cursors, link) { - if (!cursor->enabled || output->hardware_cursor == cursor) { + if (!cursor->enabled || !cursor->visible || + output->hardware_cursor == cursor) { continue; } output_cursor_render(cursor, &now); @@ -516,6 +515,34 @@ bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, stride, width, height, pixels); } +static void output_cursor_update_visible(struct wlr_output_cursor *cursor) { + struct wlr_box output_box; + output_box.x = output_box.y = 0; + wlr_output_effective_resolution(cursor->output, &output_box.width, + &output_box.height); + output_box.width *= cursor->output->scale; + output_box.height *= cursor->output->scale; + + struct wlr_box cursor_box; + output_cursor_get_box(cursor, &cursor_box); + + struct wlr_box intersection; + struct wlr_box *intersection_ptr = &intersection; + bool visible = + wlr_box_intersection(&output_box, &cursor_box, &intersection_ptr); + + if (cursor->surface != NULL) { + if (cursor->visible && !visible) { + wlr_surface_send_leave(cursor->surface, cursor->output); + } + if (!cursor->visible && visible) { + wlr_surface_send_enter(cursor->surface, cursor->output); + } + } + + cursor->visible = visible; +} + static void output_cursor_commit(struct wlr_output_cursor *cursor) { // Some clients commit a cursor surface with a NULL buffer to hide it. cursor->enabled = wlr_surface_has_buffer(cursor->surface); @@ -584,6 +611,9 @@ void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor, wl_signal_add(&surface->events.commit, &cursor->surface_commit); wl_signal_add(&surface->events.destroy, &cursor->surface_destroy); output_cursor_commit(cursor); + + cursor->visible = false; + output_cursor_update_visible(cursor); } else { cursor->enabled = false; cursor->width = 0; @@ -599,6 +629,7 @@ bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, y *= cursor->output->scale; cursor->x = x; cursor->y = y; + output_cursor_update_visible(cursor); if (cursor->output->hardware_cursor != cursor) { cursor->output->needs_swap = true; -- cgit v1.2.3 From a3c0f9781073a29c020d8f5c992b8019264dc219 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 8 Dec 2017 17:03:05 +0100 Subject: Make keyboard repeat info configurable --- include/rootston/config.h | 1 + include/wlr/types/wlr_keyboard.h | 8 ++++++++ include/wlr/types/wlr_seat.h | 1 + rootston/config.c | 4 ++++ rootston/keyboard.c | 13 +++++++++++-- types/wlr_keyboard.c | 15 +++++++++++++++ types/wlr_seat.c | 33 +++++++++++++++++++++++++++++---- 7 files changed, 69 insertions(+), 6 deletions(-) (limited to 'include/wlr') diff --git a/include/rootston/config.h b/include/rootston/config.h index de20fb8e..233692dc 100644 --- a/include/rootston/config.h +++ b/include/rootston/config.h @@ -42,6 +42,7 @@ struct roots_keyboard_config { char *layout; char *variant; char *options; + int repeat_rate, repeat_delay; struct wl_list link; }; diff --git a/include/wlr/types/wlr_keyboard.h b/include/wlr/types/wlr_keyboard.h index e2d50b03..c259189d 100644 --- a/include/wlr/types/wlr_keyboard.h +++ b/include/wlr/types/wlr_keyboard.h @@ -51,10 +51,16 @@ struct wlr_keyboard { xkb_mod_mask_t group; } modifiers; + struct { + int32_t rate; + int32_t delay; + } repeat_info; + struct { struct wl_signal key; struct wl_signal modifiers; struct wl_signal keymap; + struct wl_signal repeat_info; } events; void *data; @@ -74,6 +80,8 @@ struct wlr_event_keyboard_key { void wlr_keyboard_set_keymap(struct wlr_keyboard *kb, struct xkb_keymap *keymap); +void wlr_keyboard_set_repeat_info(struct wlr_keyboard *kb, int32_t rate, + int32_t delay); void wlr_keyboard_led_update(struct wlr_keyboard *keyboard, uint32_t leds); uint32_t wlr_keyboard_get_modifiers(struct wlr_keyboard *keyboard); diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index 6d59315b..6c04380e 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -146,6 +146,7 @@ struct wlr_seat_keyboard_state { struct wl_listener keyboard_destroy; struct wl_listener keyboard_keymap; + struct wl_listener keyboard_repeat_info; struct wl_listener surface_destroy; struct wl_listener resource_destroy; diff --git a/rootston/config.c b/rootston/config.c index 59adf13c..6e596852 100644 --- a/rootston/config.c +++ b/rootston/config.c @@ -213,6 +213,10 @@ static void config_handle_keyboard(struct roots_config *config, kc->variant = strdup(value); } else if (strcmp(name, "options") == 0) { kc->options = strdup(value); + } else if (strcmp(name, "repeat-rate") == 0) { + kc->repeat_rate = strtol(value, NULL, 10); + } else if (strcmp(name, "repeat-delay") == 0) { + kc->repeat_delay = strtol(value, NULL, 10); } else { wlr_log(L_ERROR, "got unknown keyboard config: %s", name); } diff --git a/rootston/keyboard.c b/rootston/keyboard.c index 85033613..4aaf2d48 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -306,6 +306,12 @@ static void keyboard_config_merge(struct roots_keyboard_config *config, if (config->name == NULL) { config->name = fallback->name; } + if (config->repeat_rate <= 0) { + config->repeat_rate = fallback->repeat_rate; + } + if (config->repeat_delay <= 0) { + config->repeat_delay = fallback->repeat_delay; + } } struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device, @@ -337,8 +343,7 @@ struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device, keyboard_config_merge(config, &env_config); keyboard->config = config; - struct xkb_rule_names rules; - memset(&rules, 0, sizeof(rules)); + struct xkb_rule_names rules = { 0 }; rules.rules = config->rules; rules.model = config->model; rules.layout = config->layout; @@ -353,6 +358,10 @@ struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS)); xkb_context_unref(context); + int repeat_rate = (config->repeat_rate > 0) ? config->repeat_rate : 25; + int repeat_delay = (config->repeat_delay > 0) ? config->repeat_delay : 600; + wlr_keyboard_set_repeat_info(device->keyboard, repeat_rate, repeat_delay); + return keyboard; } diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index c4f2ed52..c494b45d 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -102,6 +102,11 @@ void wlr_keyboard_init(struct wlr_keyboard *kb, wl_signal_init(&kb->events.key); wl_signal_init(&kb->events.modifiers); wl_signal_init(&kb->events.keymap); + wl_signal_init(&kb->events.repeat_info); + + // Sane defaults + kb->repeat_info.rate = 25; + kb->repeat_info.delay = 600; } void wlr_keyboard_destroy(struct wlr_keyboard *kb) { @@ -167,6 +172,16 @@ void wlr_keyboard_set_keymap(struct wlr_keyboard *kb, wl_signal_emit(&kb->events.keymap, kb); } +void wlr_keyboard_set_repeat_info(struct wlr_keyboard *kb, int32_t rate, + int32_t delay) { + if (kb->repeat_info.rate == rate && kb->repeat_info.delay == delay) { + return; + } + kb->repeat_info.rate = rate; + kb->repeat_info.delay = delay; + wl_signal_emit(&kb->events.repeat_info, kb); +} + uint32_t wlr_keyboard_get_modifiers(struct wlr_keyboard *kb) { xkb_mod_mask_t mask = kb->modifiers.depressed | kb->modifiers.latched; uint32_t modifiers = 0; diff --git a/types/wlr_seat.c b/types/wlr_seat.c index ff1cbf7f..ab3e990d 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -109,10 +109,18 @@ static void seat_client_send_keymap(struct wlr_seat_client *client, wl_keyboard_send_keymap(client->keyboard, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, keyboard->keymap_fd, keyboard->keymap_size); +} + +static void seat_client_send_repeat_info(struct wlr_seat_client *client, + struct wlr_keyboard *keyboard) { + if (!keyboard || !client->keyboard) { + return; + } if (wl_resource_get_version(client->keyboard) >= WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) { - wl_keyboard_send_repeat_info(client->keyboard, 25, 600); + wl_keyboard_send_repeat_info(client->keyboard, + keyboard->repeat_info.rate, keyboard->repeat_info.delay); } } @@ -138,8 +146,9 @@ static void wl_seat_get_keyboard(struct wl_client *client, wl_resource_set_implementation(seat_client->keyboard, &wl_keyboard_impl, seat_client, &wl_keyboard_destroy); - seat_client_send_keymap(seat_client, - seat_client->seat->keyboard_state.keyboard); + struct wlr_keyboard *keyboard = seat_client->seat->keyboard_state.keyboard; + seat_client_send_keymap(seat_client, keyboard); + seat_client_send_repeat_info(seat_client, keyboard); // TODO possibly handle the case where this keyboard needs an enter // right away @@ -695,6 +704,16 @@ static void handle_keyboard_keymap(struct wl_listener *listener, void *data) { } } +static void handle_keyboard_repeat_info(struct wl_listener *listener, + void *data) { + struct wlr_seat_keyboard_state *state = + wl_container_of(listener, state, keyboard_repeat_info); + struct wlr_seat_client *client; + wl_list_for_each(client, &state->seat->clients, link) { + seat_client_send_repeat_info(client, state->keyboard); + } +} + static void handle_keyboard_destroy(struct wl_listener *listener, void *data) { struct wlr_seat_keyboard_state *state = wl_container_of(listener, state, keyboard_destroy); @@ -713,22 +732,28 @@ void wlr_seat_set_keyboard(struct wlr_seat *seat, if (seat->keyboard_state.keyboard) { wl_list_remove(&seat->keyboard_state.keyboard_destroy.link); wl_list_remove(&seat->keyboard_state.keyboard_keymap.link); + wl_list_remove(&seat->keyboard_state.keyboard_repeat_info.link); seat->keyboard_state.keyboard = NULL; } if (device) { assert(device->type == WLR_INPUT_DEVICE_KEYBOARD); + wl_signal_add(&device->events.destroy, &seat->keyboard_state.keyboard_destroy); seat->keyboard_state.keyboard_destroy.notify = handle_keyboard_destroy; - wl_signal_add(&device->keyboard->events.keymap, &seat->keyboard_state.keyboard_keymap); seat->keyboard_state.keyboard_keymap.notify = handle_keyboard_keymap; + wl_signal_add(&device->keyboard->events.repeat_info, + &seat->keyboard_state.keyboard_repeat_info); + seat->keyboard_state.keyboard_repeat_info.notify = + handle_keyboard_repeat_info; struct wlr_seat_client *client; wl_list_for_each(client, &seat->clients, link) { seat_client_send_keymap(client, device->keyboard); + seat_client_send_repeat_info(client, device->keyboard); } seat->keyboard_state.keyboard = device->keyboard; -- cgit v1.2.3 From 2c6e52c164cfd19bac642d3507fb8584a0201845 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 8 Dec 2017 17:06:31 +0100 Subject: Add docs for wlr_keyboard_set_repeat_info --- include/wlr/types/wlr_keyboard.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_keyboard.h b/include/wlr/types/wlr_keyboard.h index c259189d..450cd473 100644 --- a/include/wlr/types/wlr_keyboard.h +++ b/include/wlr/types/wlr_keyboard.h @@ -80,6 +80,10 @@ struct wlr_event_keyboard_key { void wlr_keyboard_set_keymap(struct wlr_keyboard *kb, struct xkb_keymap *keymap); +/** + * Sets the keyboard repeat info. `rate` is in key repeats/second and delay is + * in milliseconds. + */ void wlr_keyboard_set_repeat_info(struct wlr_keyboard *kb, int32_t rate, int32_t delay); void wlr_keyboard_led_update(struct wlr_keyboard *keyboard, uint32_t leds); -- cgit v1.2.3 From 529675b7b04a2598f7701d2e05567d8249ea1cfb Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 11 Dec 2017 12:14:23 +0100 Subject: Add wlr_output_set_custom_mode --- backend/wayland/output.c | 10 ++++++++++ backend/x11/backend.c | 16 ++++++++++++++-- include/wlr/interfaces/wlr_output.h | 2 ++ include/wlr/types/wlr_output.h | 2 ++ rootston/output.c | 9 ++++++++- types/wlr_output.c | 17 +++++++++++++++++ 6 files changed, 53 insertions(+), 3 deletions(-) (limited to 'include/wlr') diff --git a/backend/wayland/output.c b/backend/wayland/output.c index c4301617..f6182dcd 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -28,6 +28,15 @@ static struct wl_callback_listener frame_listener = { .done = surface_frame_callback }; +static bool wlr_wl_output_set_custom_mode(struct wlr_output *_output, + int32_t width, int32_t height, int32_t refresh) { + struct wlr_wl_backend_output *output = (struct wlr_wl_backend_output *)_output; + wl_egl_window_resize(output->egl_window, width, height, 0, 0); + wlr_output_update_size(&output->wlr_output, width, height); + wl_signal_emit(&output->wlr_output.events.resolution, output); + return true; +} + static void wlr_wl_output_make_current(struct wlr_output *_output) { struct wlr_wl_backend_output *output = (struct wlr_wl_backend_output *)_output; if (!eglMakeCurrent(output->backend->egl.display, @@ -185,6 +194,7 @@ bool wlr_wl_output_move_cursor(struct wlr_output *_output, int x, int y) { } static struct wlr_output_impl output_impl = { + .set_custom_mode = wlr_wl_output_set_custom_mode, .transform = wlr_wl_output_transform, .destroy = wlr_wl_output_destroy, .make_current = wlr_wl_output_make_current, diff --git a/backend/x11/backend.c b/backend/x11/backend.c index b798daf6..5fb54ffd 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -267,8 +267,8 @@ static bool wlr_x11_backend_start(struct wlr_backend *backend) { snprintf(output->wlr_output.name, sizeof(output->wlr_output.name), "X11-1"); output->win = xcb_generate_id(x11->xcb_conn); - xcb_create_window(x11->xcb_conn, XCB_COPY_FROM_PARENT, output->win, x11->screen->root, - 0, 0, 1024, 768, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT, + xcb_create_window(x11->xcb_conn, XCB_COPY_FROM_PARENT, output->win, + x11->screen->root, 0, 0, 1024, 768, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT, x11->screen->root_visual, mask, values); output->surf = wlr_egl_create_surface(&x11->egl, &output->win); @@ -329,6 +329,17 @@ static struct wlr_backend_impl backend_impl = { .get_egl = wlr_x11_backend_get_egl, }; +static bool output_set_custom_mode(struct wlr_output *wlr_output, int32_t width, + int32_t height, int32_t refresh) { + struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; + struct wlr_x11_backend *x11 = output->x11; + + const uint32_t values[] = { width, height }; + xcb_configure_window(x11->xcb_conn, output->win, + XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, values); + return true; +} + static void output_transform(struct wlr_output *wlr_output, enum wl_output_transform transform) { struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; output->wlr_output.transform = transform; @@ -362,6 +373,7 @@ static void output_swap_buffers(struct wlr_output *wlr_output) { } static struct wlr_output_impl output_impl = { + .set_custom_mode = output_set_custom_mode, .transform = output_transform, .destroy = output_destroy, .make_current = output_make_current, diff --git a/include/wlr/interfaces/wlr_output.h b/include/wlr/interfaces/wlr_output.h index b4f39d35..dc2a867b 100644 --- a/include/wlr/interfaces/wlr_output.h +++ b/include/wlr/interfaces/wlr_output.h @@ -9,6 +9,8 @@ struct wlr_output_impl { void (*enable)(struct wlr_output *output, bool enable); bool (*set_mode)(struct wlr_output *output, struct wlr_output_mode *mode); + bool (*set_custom_mode)(struct wlr_output *output, int32_t width, + int32_t height, int32_t refresh); void (*transform)(struct wlr_output *output, enum wl_output_transform transform); bool (*set_cursor)(struct wlr_output *output, const uint8_t *buf, diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 895536e1..7f681ab7 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -83,6 +83,8 @@ struct wlr_surface; void wlr_output_enable(struct wlr_output *output, bool enable); bool wlr_output_set_mode(struct wlr_output *output, struct wlr_output_mode *mode); +bool wlr_output_set_custom_mode(struct wlr_output *output, int32_t width, + int32_t height, int32_t refresh); void wlr_output_transform(struct wlr_output *output, enum wl_output_transform transform); void wlr_output_set_position(struct wlr_output *output, int32_t lx, int32_t ly); diff --git a/rootston/output.c b/rootston/output.c index cf2ffdc3..b2d6554d 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -263,8 +263,15 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { static void set_mode(struct wlr_output *output, struct roots_output_config *oc) { - struct wlr_output_mode *mode, *best = NULL; int mhz = (int)(oc->mode.refresh_rate * 1000); + + if (wl_list_empty(&output->modes)) { + // Output has no mode, try setting a custom one + wlr_output_set_custom_mode(output, oc->mode.width, oc->mode.height, mhz); + return; + } + + struct wlr_output_mode *mode, *best = NULL; wl_list_for_each(mode, &output->modes, link) { if (mode->width == oc->mode.width && mode->height == oc->mode.height) { if (mode->refresh == mhz) { diff --git a/types/wlr_output.c b/types/wlr_output.c index f4ae7aaa..adade238 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -164,6 +164,23 @@ bool wlr_output_set_mode(struct wlr_output *output, return result; } +bool wlr_output_set_custom_mode(struct wlr_output *output, int32_t width, + int32_t height, int32_t refresh) { + if (!output->impl || !output->impl->set_custom_mode) { + return false; + } + bool result = output->impl->set_custom_mode(output, width, height, refresh); + if (result) { + wlr_output_update_matrix(output); + + struct wl_resource *resource; + wl_resource_for_each(resource, &output->wl_resources) { + wlr_output_send_current_mode_to_resource(resource); + } + } + return result; +} + void wlr_output_update_size(struct wlr_output *output, int32_t width, int32_t height) { if (output->width == width && output->height == height) { -- cgit v1.2.3