Add keyboard input, move input device creation to compositor.
This commit is contained in:
parent
ec8ef722e9
commit
cddc0ad502
3
Makefile
3
Makefile
@ -14,7 +14,6 @@ wayland_objs = \
|
||||
wayland.o \
|
||||
event-loop.o \
|
||||
connection.o \
|
||||
evdev.o \
|
||||
wayland-util.o
|
||||
|
||||
wayland : CFLAGS += $(shell pkg-config --cflags libffi)
|
||||
@ -29,7 +28,7 @@ libwayland.so : $(libwayland_objs)
|
||||
|
||||
$(compositors) $(clients) : CFLAGS += $(shell pkg-config --cflags libdrm)
|
||||
|
||||
egl_compositor_objs = egl-compositor.o cairo-util.o
|
||||
egl_compositor_objs = egl-compositor.o evdev.o cairo-util.o
|
||||
egl-compositor.so : CFLAGS += $(EAGLE_CFLAGS) $(shell pkg-config --cflags libpng cairo gdk-pixbuf-2.0)
|
||||
egl-compositor.so : LDLIBS += $(EAGLE_LDLIBS) $(shell pkg-config --libs libpng cairo gdk-pixbuf-2.0) -rdynamic
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <glib.h>
|
||||
#include <png.h>
|
||||
#include <math.h>
|
||||
#include <linux/input.h>
|
||||
|
||||
#include "wayland.h"
|
||||
#include "cairo-util.h"
|
||||
@ -630,6 +631,16 @@ notify_pointer_motion(struct wl_compositor *compositor,
|
||||
schedule_repaint(ec);
|
||||
}
|
||||
|
||||
static void
|
||||
notify_key(struct wl_compositor *compositor,
|
||||
struct wl_object *source, uint32_t key, uint32_t state)
|
||||
{
|
||||
struct egl_compositor *ec = (struct egl_compositor *) compositor;
|
||||
|
||||
if (key == KEY_ESC)
|
||||
schedule_repaint(ec);
|
||||
}
|
||||
|
||||
static const struct wl_compositor_interface interface = {
|
||||
notify_surface_create,
|
||||
notify_surface_destroy,
|
||||
@ -637,9 +648,38 @@ static const struct wl_compositor_interface interface = {
|
||||
notify_surface_map,
|
||||
notify_surface_copy,
|
||||
notify_surface_damage,
|
||||
notify_pointer_motion
|
||||
notify_pointer_motion,
|
||||
notify_key
|
||||
};
|
||||
|
||||
static const char pointer_device_file[] =
|
||||
"/dev/input/by-id/usb-Apple__Inc._Apple_Internal_Keyboard_._Trackpad-event-mouse";
|
||||
static const char keyboard_device_file[] =
|
||||
"/dev/input/by-id/usb-Apple__Inc._Apple_Internal_Keyboard_._Trackpad-event-kbd";
|
||||
|
||||
static void
|
||||
create_input_devices(struct wl_display *display)
|
||||
{
|
||||
struct wl_object *obj;
|
||||
const char *path;
|
||||
|
||||
path = getenv("WAYLAND_POINTER");
|
||||
if (path == NULL)
|
||||
path = pointer_device_file;
|
||||
|
||||
obj = wl_input_device_create(display, path);
|
||||
if (obj != NULL)
|
||||
wl_display_add_object(display, obj);
|
||||
|
||||
path = getenv("WAYLAND_KEYBOARD");
|
||||
if (path == NULL)
|
||||
path = keyboard_device_file;
|
||||
|
||||
obj = wl_input_device_create(display, path);
|
||||
if (obj != NULL)
|
||||
wl_display_add_object(display, obj);
|
||||
}
|
||||
|
||||
static const char gem_device[] = "/dev/dri/card0";
|
||||
|
||||
WL_EXPORT struct wl_compositor *
|
||||
@ -701,7 +741,8 @@ wl_compositor_create(struct wl_display *display)
|
||||
glLoadIdentity();
|
||||
glOrtho(0, ec->width, ec->height, 0, 0, 1000.0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glClearColor(0.0, 0.05, 0.2, 0.0);
|
||||
|
||||
create_input_devices(display);
|
||||
|
||||
filename = getenv("WAYLAND_BACKGROUND");
|
||||
if (filename == NULL)
|
||||
|
10
evdev.c
10
evdev.c
@ -104,6 +104,11 @@ static void wl_input_device_data(int fd, uint32_t mask, void *data)
|
||||
wl_display_post_button_event(device->display,
|
||||
&device->base, 1, value);
|
||||
break;
|
||||
|
||||
default:
|
||||
wl_display_post_key_event(device->display,
|
||||
&device->base, e->code, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -117,9 +122,8 @@ static void wl_input_device_data(int fd, uint32_t mask, void *data)
|
||||
device->x, device->y);
|
||||
}
|
||||
|
||||
struct wl_object *
|
||||
wl_input_device_create(struct wl_display *display,
|
||||
const char *path, uint32_t id)
|
||||
WL_EXPORT struct wl_object *
|
||||
wl_input_device_create(struct wl_display *display, const char *path)
|
||||
{
|
||||
struct wl_input_device *device;
|
||||
struct wl_event_loop *loop;
|
||||
|
59
wayland.c
59
wayland.c
@ -511,27 +511,6 @@ static const struct wl_interface display_interface = {
|
||||
ARRAY_LENGTH(display_events), display_events,
|
||||
};
|
||||
|
||||
static const char input_device_file[] =
|
||||
"/dev/input/by-id/usb-Apple__Inc._Apple_Internal_Keyboard_._Trackpad-event-mouse";
|
||||
|
||||
static void
|
||||
wl_display_create_input_devices(struct wl_display *display)
|
||||
{
|
||||
const char *path;
|
||||
|
||||
path = getenv("WAYLAND_POINTER");
|
||||
if (path == NULL)
|
||||
path = input_device_file;
|
||||
|
||||
display->pointer = wl_input_device_create(display, path, 1);
|
||||
|
||||
if (display->pointer != NULL)
|
||||
wl_display_add_object(display, display->pointer);
|
||||
|
||||
display->pointer_x = 100;
|
||||
display->pointer_y = 100;
|
||||
}
|
||||
|
||||
static struct wl_display *
|
||||
wl_display_create(void)
|
||||
{
|
||||
@ -551,7 +530,8 @@ wl_display_create(void)
|
||||
wl_list_init(&display->client_list);
|
||||
wl_list_init(&display->global_list);
|
||||
|
||||
wl_display_create_input_devices(display);
|
||||
display->pointer_x = 100;
|
||||
display->pointer_y = 100;
|
||||
|
||||
display->client_id_range = 256; /* Gah, arbitrary... */
|
||||
|
||||
@ -604,10 +584,11 @@ wl_display_send_event(struct wl_display *display, uint32_t *data, size_t size)
|
||||
}
|
||||
}
|
||||
|
||||
#define WL_POINTER_MOTION 0
|
||||
#define WL_POINTER_BUTTON 1
|
||||
#define WL_INPUT_MOTION 0
|
||||
#define WL_INPUT_BUTTON 1
|
||||
#define WL_INPUT_KEY 2
|
||||
|
||||
void
|
||||
WL_EXPORT void
|
||||
wl_display_post_relative_event(struct wl_display *display,
|
||||
struct wl_object *source, int dx, int dy)
|
||||
{
|
||||
@ -622,14 +603,14 @@ wl_display_post_relative_event(struct wl_display *display,
|
||||
display->pointer_x, display->pointer_y);
|
||||
|
||||
p[0] = source->id;
|
||||
p[1] = (sizeof p << 16) | WL_POINTER_MOTION;
|
||||
p[1] = (sizeof p << 16) | WL_INPUT_MOTION;
|
||||
p[2] = display->pointer_x;
|
||||
p[3] = display->pointer_y;
|
||||
|
||||
wl_display_send_event(display, p, sizeof p);
|
||||
}
|
||||
|
||||
void
|
||||
WL_EXPORT void
|
||||
wl_display_post_absolute_event(struct wl_display *display,
|
||||
struct wl_object *source, int x, int y)
|
||||
{
|
||||
@ -644,27 +625,45 @@ wl_display_post_absolute_event(struct wl_display *display,
|
||||
display->pointer_x, display->pointer_y);
|
||||
|
||||
p[0] = source->id;
|
||||
p[1] = (sizeof p << 16) | WL_POINTER_MOTION;
|
||||
p[1] = (sizeof p << 16) | WL_INPUT_MOTION;
|
||||
p[2] = display->pointer_x;
|
||||
p[3] = display->pointer_y;
|
||||
|
||||
wl_display_send_event(display, p, sizeof p);
|
||||
}
|
||||
|
||||
void
|
||||
WL_EXPORT void
|
||||
wl_display_post_button_event(struct wl_display *display,
|
||||
struct wl_object *source, int button, int state)
|
||||
{
|
||||
uint32_t p[4];
|
||||
|
||||
p[0] = source->id;
|
||||
p[1] = (sizeof p << 16) | WL_POINTER_BUTTON;
|
||||
p[1] = (sizeof p << 16) | WL_INPUT_BUTTON;
|
||||
p[2] = button;
|
||||
p[3] = state;
|
||||
|
||||
wl_display_send_event(display, p, sizeof p);
|
||||
}
|
||||
|
||||
WL_EXPORT void
|
||||
wl_display_post_key_event(struct wl_display *display,
|
||||
struct wl_object *source, int key, int state)
|
||||
{
|
||||
const struct wl_compositor_interface *interface;
|
||||
uint32_t p[4];
|
||||
|
||||
interface = display->compositor->interface;
|
||||
interface->notify_key(display->compositor, source, key, state);
|
||||
|
||||
p[0] = source->id;
|
||||
p[1] = (sizeof p << 16) | WL_INPUT_KEY;
|
||||
p[2] = key;
|
||||
p[3] = state;
|
||||
|
||||
wl_display_send_event(display, p, sizeof p);
|
||||
}
|
||||
|
||||
void
|
||||
wl_display_set_compositor(struct wl_display *display,
|
||||
struct wl_compositor *compositor)
|
||||
|
11
wayland.h
11
wayland.h
@ -90,8 +90,8 @@ int wl_surface_iterator_next(struct wl_surface_iterator *iterator,
|
||||
void wl_surface_iterator_destroy(struct wl_surface_iterator *iterator);
|
||||
|
||||
struct wl_object *
|
||||
wl_input_device_create(struct wl_display *display,
|
||||
const char *path, uint32_t id);
|
||||
wl_input_device_create(struct wl_display *display, const char *path);
|
||||
|
||||
void
|
||||
wl_display_add_object(struct wl_display *display, struct wl_object *object);
|
||||
int
|
||||
@ -106,6 +106,9 @@ wl_display_post_absolute_event(struct wl_display *display,
|
||||
void
|
||||
wl_display_post_button_event(struct wl_display *display,
|
||||
struct wl_object *source, int button, int state);
|
||||
void
|
||||
wl_display_post_key_event(struct wl_display *display,
|
||||
struct wl_object *source, int key, int state);
|
||||
|
||||
struct wl_compositor {
|
||||
const struct wl_compositor_interface *interface;
|
||||
@ -137,7 +140,9 @@ struct wl_compositor_interface {
|
||||
void (*notify_pointer_motion)(struct wl_compositor *compositor,
|
||||
struct wl_object *source,
|
||||
int32_t x, int32_t y);
|
||||
|
||||
void (*notify_key)(struct wl_compositor *compositor,
|
||||
struct wl_object *source,
|
||||
uint32_t key, uint32_t state);
|
||||
};
|
||||
|
||||
void wl_display_set_compositor(struct wl_display *display,
|
||||
|
Loading…
Reference in New Issue
Block a user