swc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/swc
Log | Files | Refs | README | LICENSE

commit 29e72e650963cf46ca55e802bbad43bdd50a7c53
parent e2449494107cb1a123cf9f2da35c188815c45f46
Author: Michael Forney <mforney@mforney.org>
Date:   Sat, 10 Aug 2013 13:42:58 -0700

Use swc_send_event helper

Diffstat:
Mdata_device.c | 11++++-------
Mdrm.c | 8+++-----
Mevent.h | 9+++++++++
Minput_focus.c | 7++-----
Mpointer.c | 6+-----
Mtty.c | 9++-------
6 files changed, 21 insertions(+), 29 deletions(-)

diff --git a/data_device.c b/data_device.c @@ -38,14 +38,11 @@ static void set_selection(struct wl_client * client, struct wl_resource * data_source, uint32_t serial) { struct swc_data_device * data_device = wl_resource_get_user_data(resource); - struct swc_event event; /* Check if this data source is already the current selection. */ if (data_source == data_device->selection) return; - event.type = SWC_DATA_DEVICE_EVENT_SELECTION_CHANGED; - if (data_device->selection) { wl_data_source_send_cancelled(data_device->selection); @@ -60,7 +57,8 @@ static void set_selection(struct wl_client * client, (data_source, &data_device->selection_destroy_listener); } - wl_signal_emit(&data_device->event_signal, &event); + swc_send_event(&data_device->event_signal, + SWC_DATA_DEVICE_EVENT_SELECTION_CHANGED, NULL); } struct wl_data_device_interface data_device_implementation = { @@ -72,11 +70,10 @@ static void handle_selection_destroy(struct wl_listener * listener, void * data) { struct swc_data_device * data_device = swc_container_of (listener, typeof(*data_device), selection_destroy_listener); - struct swc_event event; - event.type = SWC_DATA_DEVICE_EVENT_SELECTION_CHANGED; data_device->selection = NULL; - wl_signal_emit(&data_device->event_signal, &event); + swc_send_event(&data_device->event_signal, + SWC_DATA_DEVICE_EVENT_SELECTION_CHANGED, NULL); } bool swc_data_device_initialize(struct swc_data_device * data_device) diff --git a/drm.c b/drm.c @@ -139,15 +139,13 @@ static void handle_page_flip(int fd, unsigned int sequence, unsigned int sec, unsigned int usec, void * data) { struct swc_output * output = data; - struct swc_event event = { - .type = SWC_DRM_PAGE_FLIP, - .data = output - }; printf("page flip\n"); output->front_buffer ^= 1; - wl_signal_emit(&output->drm->event_signal, &event); + /* XXX: It doesn't make sense for multiple things to be listening for page + * flips (or does it?). Maybe this should be a callback instead? */ + swc_send_event(&output->drm->event_signal, SWC_DRM_PAGE_FLIP, output); } static drmEventContext event_context = { diff --git a/event.h b/event.h @@ -2,6 +2,7 @@ #define SWC_EVENT_H #include <stdint.h> +#include <wayland-server.h> struct swc_event { @@ -9,5 +10,13 @@ struct swc_event void * data; }; +static inline void swc_send_event(struct wl_signal * signal, uint32_t type, + void * event_data) +{ + struct swc_event event = { .type = type, .data = event_data }; + + wl_signal_emit(signal, &event); +} + #endif diff --git a/input_focus.c b/input_focus.c @@ -124,10 +124,6 @@ void swc_input_focus_set(struct swc_input_focus * input_focus, struct wl_resource * resource; uint32_t serial; struct swc_input_focus_event_data data; - struct swc_event event; - - event.type = SWC_INPUT_FOCUS_EVENT_CHANGED; - event.data = &data; if (surface == input_focus->surface) return; @@ -153,7 +149,8 @@ void swc_input_focus_set(struct swc_input_focus * input_focus, data.new = input_focus->surface; - wl_signal_emit(&input_focus->event_signal, &event); + swc_send_event(&input_focus->event_signal, SWC_INPUT_FOCUS_EVENT_CHANGED, + &data); return; } diff --git a/pointer.c b/pointer.c @@ -77,7 +77,6 @@ static void set_cursor(struct wl_client * client, { struct swc_pointer * pointer = wl_resource_get_user_data(resource); struct swc_surface * surface; - struct swc_event event; printf("set_cursor\n"); @@ -94,10 +93,7 @@ static void set_cursor(struct wl_client * client, pointer->cursor.hotspot_x = hotspot_x; pointer->cursor.hotspot_y = hotspot_y; - event.type = SWC_POINTER_CURSOR_CHANGED; - event.data = pointer; - - wl_signal_emit(&pointer->event_signal, &event); + swc_send_event(&pointer->event_signal, SWC_POINTER_CURSOR_CHANGED, pointer); } struct wl_pointer_interface pointer_implementation = { diff --git a/tty.c b/tty.c @@ -197,13 +197,10 @@ void restore_tty(struct swc_tty * tty) static int handle_vt_signal(int signal_number, void * data) { struct swc_tty * tty = data; - struct swc_event event; if (tty->active) { - event.type = SWC_TTY_VT_LEAVE; - wl_signal_emit(&tty->event_signal, &event); - + swc_send_event(&tty->event_signal, SWC_TTY_VT_LEAVE, NULL); ioctl(tty->fd, VT_RELDISP, 1); tty->active = false; } @@ -211,9 +208,7 @@ static int handle_vt_signal(int signal_number, void * data) { ioctl(tty->fd, VT_RELDISP, VT_ACKACQ); tty->active = true; - - event.type = SWC_TTY_VT_ENTER; - wl_signal_emit(&tty->event_signal, &event); + swc_send_event(&tty->event_signal, SWC_TTY_VT_ENTER, NULL); } return 1;