Merge branch 'master' into modifier-fixes

This commit is contained in:
Tony Crisci 2018-01-17 08:27:47 -05:00
commit 43896af90f
41 changed files with 765 additions and 103 deletions

View file

@ -6,6 +6,7 @@ lib_wlr_types = static_library(
'wlr_compositor.c',
'wlr_cursor.c',
'wlr_gamma_control.c',
'wlr_idle.c',
'wlr_input_device.c',
'wlr_keyboard.c',
'wlr_list.c',

190
types/wlr_idle.c Normal file
View file

@ -0,0 +1,190 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <wayland-server.h>
#include <wlr/types/wlr_idle.h>
#include <wlr/util/log.h>
#include "idle-protocol.h"
static void idle_timeout_destroy(struct wlr_idle_timeout *timer) {
wl_list_remove(&timer->input_listener.link);
wl_list_remove(&timer->seat_destroy.link);
wl_event_source_remove(timer->idle_source);
wl_list_remove(&timer->link);
wl_resource_set_user_data(timer->resource, NULL);
free(timer);
}
static int idle_notify(void *data) {
struct wlr_idle_timeout *timer = data;
timer->idle_state = true;
org_kde_kwin_idle_timeout_send_idle(timer->resource);
return 1;
}
static void handle_activity(struct wlr_idle_timeout *timer) {
// rearm the timer
wl_event_source_timer_update(timer->idle_source, timer->timeout);
// in case the previous state was sleeping send a resume event and switch state
if (timer->idle_state) {
timer->idle_state = false;
org_kde_kwin_idle_timeout_send_resumed(timer->resource);
}
}
static void handle_timer_resource_destroy(struct wl_resource *timer_resource) {
struct wlr_idle_timeout *timer = wl_resource_get_user_data(timer_resource);
if (timer != NULL) {
idle_timeout_destroy(timer);
}
}
static void handle_seat_destroy(struct wl_listener *listener, void *data) {
struct wlr_idle_timeout *timer = wl_container_of(listener, timer, seat_destroy);
if (timer != NULL) {
idle_timeout_destroy(timer);
}
}
static void release_idle_timeout(struct wl_client *client,
struct wl_resource *resource){
handle_timer_resource_destroy(resource);
}
static void simulate_activity(struct wl_client *client,
struct wl_resource *resource){
struct wlr_idle_timeout *timer = wl_resource_get_user_data(resource);
handle_activity(timer);
}
static struct org_kde_kwin_idle_timeout_interface idle_timeout_impl = {
.release = release_idle_timeout,
.simulate_user_activity = simulate_activity,
};
static void handle_input_notification(struct wl_listener *listener, void *data) {
struct wlr_idle_timeout *timer = wl_container_of(listener, timer, input_listener);
struct wlr_seat *seat = data;
if (timer->seat == seat) {
handle_activity(timer);
}
}
static void create_idle_timer(struct wl_client *client,
struct wl_resource *idle_resource,
uint32_t id,
struct wl_resource *seat_resource,
uint32_t timeout) {
struct wlr_idle *idle = wl_resource_get_user_data(idle_resource);
struct wlr_seat_client *client_seat =
wl_resource_get_user_data(seat_resource);
struct wlr_idle_timeout *timer =
calloc(1, sizeof(struct wlr_idle_timeout));
if (!timer) {
wl_resource_post_no_memory(idle_resource);
return;
}
timer->seat = client_seat->seat;
timer->timeout = timeout;
timer->idle_state = false;
timer->resource = wl_resource_create(client,
&org_kde_kwin_idle_timeout_interface,
wl_resource_get_version(idle_resource), id);
if (timer->resource == NULL) {
free(timer);
wl_resource_post_no_memory(idle_resource);
return;
}
wl_resource_set_implementation(timer->resource, &idle_timeout_impl, timer,
handle_timer_resource_destroy);
wl_list_insert(&idle->idle_timers, &timer->link);
timer->seat_destroy.notify = handle_seat_destroy;
wl_signal_add(&timer->seat->events.destroy, &timer->seat_destroy);
timer->input_listener.notify = handle_input_notification;
wl_signal_add(&idle->activity_notify, &timer->input_listener);
// create the timer
timer->idle_source =
wl_event_loop_add_timer(idle->event_loop, idle_notify, timer);
if (timer->idle_source == NULL) {
wl_list_remove(&timer->link);
wl_list_remove(&timer->input_listener.link);
wl_list_remove(&timer->seat_destroy.link);
wl_resource_set_user_data(timer->resource, NULL);
free(timer);
wl_resource_post_no_memory(idle_resource);
return;
}
// arm the timer
wl_event_source_timer_update(timer->idle_source, timer->timeout);
}
static struct org_kde_kwin_idle_interface idle_impl = {
.get_idle_timeout = create_idle_timer,
};
static void idle_bind(struct wl_client *wl_client, void *data,
uint32_t version, uint32_t id) {
struct wlr_idle *idle = data;
assert(wl_client && idle);
struct wl_resource *wl_resource = wl_resource_create(wl_client,
&org_kde_kwin_idle_interface, version, id);
if (wl_resource == NULL) {
wl_client_post_no_memory(wl_client);
return;
}
wl_resource_set_implementation(wl_resource, &idle_impl, idle, NULL);
}
void wlr_idle_destroy(struct wlr_idle *idle) {
if (!idle) {
return;
}
wl_list_remove(&idle->display_destroy.link);
struct wlr_idle_timeout *timer, *tmp;
wl_list_for_each_safe(timer, tmp, &idle->idle_timers, link) {
idle_timeout_destroy(timer);
}
wl_global_destroy(idle->wl_global);
free(idle);
}
static void handle_display_destroy(struct wl_listener *listener, void *data) {
struct wlr_idle *idle = wl_container_of(listener, idle, display_destroy);
wlr_idle_destroy(idle);
}
struct wlr_idle *wlr_idle_create(struct wl_display *display) {
struct wlr_idle *idle = calloc(1, sizeof(struct wlr_idle));
if (!idle) {
return NULL;
}
wl_list_init(&idle->idle_timers);
wl_signal_init(&idle->activity_notify);
idle->event_loop = wl_display_get_event_loop(display);
if (idle->event_loop == NULL) {
free(idle);
return NULL;
}
idle->display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(display, &idle->display_destroy);
idle->wl_global = wl_global_create(display, &org_kde_kwin_idle_interface,
1, idle, idle_bind);
if (idle->wl_global == NULL){
wl_list_remove(&idle->display_destroy.link);
free(idle);
return NULL;
}
wlr_log(L_DEBUG, "idle manager created");
return idle;
}
void wlr_idle_notify_activity(struct wlr_idle *idle, struct wlr_seat *seat) {
wl_signal_emit(&idle->activity_notify, seat);
}

View file

@ -113,38 +113,41 @@ static void wl_output_bind(struct wl_client *wl_client, void *data,
wl_output_send_to_resource(wl_resource);
}
static void handle_display_destroy(struct wl_listener *listener, void *data) {
struct wlr_output *output =
wl_container_of(listener, output, display_destroy);
wlr_output_destroy_global(output);
}
struct wl_global *wlr_output_create_global(struct wlr_output *wlr_output,
struct wl_display *display) {
if (wlr_output->wl_global != NULL) {
return wlr_output->wl_global;
}
struct wl_global *wl_global = wl_global_create(display,
&wl_output_interface, 3, wlr_output, wl_output_bind);
wlr_output->wl_global = wl_global;
wlr_output->display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(display, &wlr_output->display_destroy);
return wl_global;
}
void wlr_output_destroy_global(struct wlr_output *wlr_output) {
if (wlr_output->wl_global == NULL) {
static void wlr_output_create_global(struct wlr_output *output) {
if (output->wl_global != NULL) {
return;
}
struct wl_global *wl_global = wl_global_create(output->display,
&wl_output_interface, 3, output, wl_output_bind);
output->wl_global = wl_global;
}
static void wlr_output_destroy_global(struct wlr_output *output) {
if (output->wl_global == NULL) {
return;
}
wl_list_remove(&wlr_output->display_destroy.link);
struct wl_resource *resource, *tmp;
wl_resource_for_each_safe(resource, tmp, &wlr_output->wl_resources) {
wl_resource_for_each_safe(resource, tmp, &output->wl_resources) {
wl_resource_destroy(resource);
}
wl_global_destroy(wlr_output->wl_global);
wlr_output->wl_global = NULL;
wl_global_destroy(output->wl_global);
output->wl_global = NULL;
}
void wlr_output_update_enabled(struct wlr_output *output, bool enabled) {
if (output->enabled == enabled) {
return;
}
output->enabled = enabled;
if (enabled) {
wlr_output_create_global(output);
} else {
wlr_output_destroy_global(output);
}
wl_signal_emit(&output->events.enable, output);
}
static void wlr_output_update_matrix(struct wlr_output *output) {
@ -153,6 +156,10 @@ static void wlr_output_update_matrix(struct wlr_output *output) {
}
void wlr_output_enable(struct wlr_output *output, bool enable) {
if (output->enabled == enable) {
return;
}
if (output->impl->enable) {
output->impl->enable(output, enable);
}
@ -199,7 +206,7 @@ void wlr_output_update_custom_mode(struct wlr_output *output, int32_t width,
wlr_output_send_current_mode_to_resource(resource);
}
wl_signal_emit(&output->events.resolution, output);
wl_signal_emit(&output->events.mode, output);
}
void wlr_output_set_transform(struct wlr_output *output,
@ -248,11 +255,18 @@ void wlr_output_set_scale(struct wlr_output *output, float scale) {
wl_signal_emit(&output->events.scale, output);
}
static void handle_display_destroy(struct wl_listener *listener, void *data) {
struct wlr_output *output =
wl_container_of(listener, output, display_destroy);
wlr_output_destroy_global(output);
}
void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
const struct wlr_output_impl *impl) {
const struct wlr_output_impl *impl, struct wl_display *display) {
assert(impl->make_current && impl->swap_buffers && impl->transform);
output->backend = backend;
output->impl = impl;
output->display = display;
wl_list_init(&output->modes);
output->transform = WL_OUTPUT_TRANSFORM_NORMAL;
output->scale = 1;
@ -260,10 +274,14 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
wl_list_init(&output->wl_resources);
wl_signal_init(&output->events.frame);
wl_signal_init(&output->events.swap_buffers);
wl_signal_init(&output->events.resolution);
wl_signal_init(&output->events.enable);
wl_signal_init(&output->events.mode);
wl_signal_init(&output->events.scale);
wl_signal_init(&output->events.transform);
wl_signal_init(&output->events.destroy);
output->display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(display, &output->display_destroy);
}
void wlr_output_destroy(struct wlr_output *output) {
@ -271,6 +289,7 @@ void wlr_output_destroy(struct wlr_output *output) {
return;
}
wl_list_remove(&output->display_destroy.link);
wlr_output_destroy_global(output);
wlr_output_set_fullscreen_surface(output, NULL);

View file

@ -18,7 +18,7 @@ struct wlr_output_layout_output_state {
struct wlr_box _box; // should never be read directly, use the getter
bool auto_configured;
struct wl_listener resolution;
struct wl_listener mode;
struct wl_listener scale;
struct wl_listener transform;
struct wl_listener output_destroy;
@ -47,7 +47,7 @@ struct wlr_output_layout *wlr_output_layout_create() {
static void wlr_output_layout_output_destroy(
struct wlr_output_layout_output *l_output) {
wl_signal_emit(&l_output->events.destroy, l_output);
wl_list_remove(&l_output->state->resolution.link);
wl_list_remove(&l_output->state->mode.link);
wl_list_remove(&l_output->state->scale.link);
wl_list_remove(&l_output->state->transform.link);
wl_list_remove(&l_output->state->output_destroy.link);
@ -132,9 +132,9 @@ static void wlr_output_layout_reconfigure(struct wlr_output_layout *layout) {
wl_signal_emit(&layout->events.change, layout);
}
static void handle_output_resolution(struct wl_listener *listener, void *data) {
static void handle_output_mode(struct wl_listener *listener, void *data) {
struct wlr_output_layout_output_state *state =
wl_container_of(listener, state, resolution);
wl_container_of(listener, state, mode);
wlr_output_layout_reconfigure(state->layout);
}
@ -176,8 +176,8 @@ static struct wlr_output_layout_output *wlr_output_layout_output_create(
wl_signal_init(&l_output->events.destroy);
wl_list_insert(&layout->outputs, &l_output->link);
wl_signal_add(&output->events.resolution, &l_output->state->resolution);
l_output->state->resolution.notify = handle_output_resolution;
wl_signal_add(&output->events.mode, &l_output->state->mode);
l_output->state->mode.notify = handle_output_mode;
wl_signal_add(&output->events.scale, &l_output->state->scale);
l_output->state->scale.notify = handle_output_scale;
wl_signal_add(&output->events.transform, &l_output->state->transform);