summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoel@teichroeb.net <none@none>2010-12-06 18:20:33 -0800
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2012-02-28 08:29:08 +0100
commite6afc9a084d8dd96fec9c12ec324962a0bc8548d (patch)
tree8ffdeaac2d94249ce4d17b31183415b5d64f9864
parent4884cafb56f0b89fd6ea3a25b0f19ff3e6e6ffcd (diff)
Added some code for input but it still does not work.
Some cleanups.
-rw-r--r--src/video/wayland/SDL_waylandevents.c168
-rw-r--r--src/video/wayland/SDL_waylandevents_c.h20
-rw-r--r--src/video/wayland/SDL_waylandgl.c21
-rw-r--r--src/video/wayland/SDL_waylandgl.h2
-rw-r--r--src/video/wayland/SDL_waylandvideo.c9
-rw-r--r--src/video/wayland/SDL_waylandvideo.h2
-rw-r--r--src/video/wayland/SDL_waylandwindow.c1
-rw-r--r--src/video/wayland/SDL_waylandwindow.h3
8 files changed, 200 insertions, 26 deletions
diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c
index 1219ae47..e88ff9aa 100644
--- a/src/video/wayland/SDL_waylandevents.c
+++ b/src/video/wayland/SDL_waylandevents.c
@@ -21,19 +21,179 @@
*/
#include "SDL_config.h"
-/* Being a null driver, there's no event stream. We just define stubs for
- most of the API. */
-
#include "../../events/SDL_sysevents.h"
#include "../../events/SDL_events_c.h"
#include "SDL_waylandvideo.h"
#include "SDL_waylandevents_c.h"
+#include "SDL_waylandwindow.h"
+#include <X11/extensions/XKBcommon.h>
+
+
+const char *option_xkb_layout = "us";
+const char *option_xkb_variant = "";
+const char *option_xkb_options = "";
+
+void
+Wayland_init_xkb(SDL_WaylandData *d)
+{
+ struct xkb_rule_names names;
+
+ names.rules = "evdev";
+ names.model = "pc105";
+ names.layout = option_xkb_layout;
+ names.variant = option_xkb_variant;
+ names.options = option_xkb_options;
+
+ d->xkb = xkb_compile_keymap_from_rules(&names);
+ if (!d->xkb) {
+ fprintf(stderr, "Failed to compile keymap\n");
+ exit(1);
+ }
+}
void
Wayland_PumpEvents(_THIS)
{
- /* do nothing. */
+ /* actually get the events... */
+}
+
+static void
+window_handle_motion(void *data, struct wl_input_device *input_device,
+ uint32_t time,
+ int32_t x, int32_t y, int32_t sx, int32_t sy)
+{
+ struct SDL_WaylandInput *input = data;
+ SDL_WaylandWindow *window = input->pointer_focus;
+ //int location, pointer = POINTER_LEFT_PTR;
+
+ input->x = x;
+ input->y = y;
+ input->sx = sx;
+ input->sy = sy;
+
+ //location = get_pointer_location(window, input->sx, input->sy);
+
+ //set_pointer_image(input, time, pointer);
+}
+
+static void
+window_handle_button(void *data,
+ struct wl_input_device *input_device,
+ uint32_t time, uint32_t button, uint32_t state)
+{
+ struct SDL_WaylandInput *input = data;
+ SDL_WaylandWindow *window = input->pointer_focus;
+ printf("Button pressed\n");
+}
+
+static void
+window_handle_key(void *data, struct wl_input_device *input_device,
+ uint32_t time, uint32_t key, uint32_t state)
+{
+ struct SDL_WaylandInput *input = data;
+ SDL_WaylandWindow *window = input->keyboard_focus;
+ SDL_WaylandData *d = window->waylandData;
+ uint32_t code, sym, level;
+
+ code = key + d->xkb->min_key_code;
+ if (window->keyboard_device != input)
+ return;
+
+/* level = 0;
+ if (input->modifiers & WINDOW_MODIFIER_SHIFT &&
+ XkbKeyGroupWidth(d->xkb, code, 0) > 1)
+ level = 1;
+*/
+ sym = XkbKeySymEntry(d->xkb, code, level, 0);
+
+ if (state)
+ input->modifiers |= d->xkb->map->modmap[code];
+ else
+ input->modifiers &= ~d->xkb->map->modmap[code];
+
+}
+
+static void
+window_handle_pointer_focus(void *data,
+ struct wl_input_device *input_device,
+ uint32_t time, struct wl_surface *surface,
+ int32_t x, int32_t y, int32_t sx, int32_t sy)
+{
+ struct SDL_WaylandInput *input = data;
+ SDL_WaylandWindow *window;
+ int pointer;
+
+ if (surface) {
+ input->pointer_focus = wl_surface_get_user_data(surface);
+ window = input->pointer_focus;
+
+ /*pointer = POINTER_LEFT_PTR;
+
+ set_pointer_image(input, time, pointer);*/
+ } else {
+ input->pointer_focus = NULL;
+ //input->current_pointer_image = POINTER_UNSET;
+ }
+}
+
+static void
+window_handle_keyboard_focus(void *data,
+ struct wl_input_device *input_device,
+ uint32_t time,
+ struct wl_surface *surface,
+ struct wl_array *keys)
+{
+ struct SDL_WaylandInput *input = data;
+ SDL_WaylandWindow *window = input->keyboard_focus;
+ SDL_WaylandData *d = input->display;
+ uint32_t *k, *end;
+
+ window = input->keyboard_focus;
+ if (window)
+ window->keyboard_device = NULL;
+
+ if (surface)
+ input->keyboard_focus = wl_surface_get_user_data(surface);
+ else
+ input->keyboard_focus = NULL;
+
+ end = keys->data + keys->size;
+ for (k = keys->data; k < end; k++)
+ input->modifiers |= d->xkb->map->modmap[*k];
+
+ window = input->keyboard_focus;
+ if (window)
+ window->keyboard_device = input;
+
+}
+
+static const struct wl_input_device_listener input_device_listener = {
+ window_handle_motion,
+ window_handle_button,
+ window_handle_key,
+ window_handle_pointer_focus,
+ window_handle_keyboard_focus,
+};
+
+void
+Wayland_display_add_input(SDL_WaylandData *d, uint32_t id)
+{
+ struct SDL_WaylandInput *input;
+ printf("Add input device\n");
+ input = malloc(sizeof *input);
+ if (input == NULL)
+ return;
+
+ memset(input, 0, sizeof *input);
+ input->display = d;
+ input->input_device = wl_input_device_create(d->display, id);
+ input->pointer_focus = NULL;
+ input->keyboard_focus = NULL;
+
+ wl_input_device_add_listener(input->input_device,
+ &input_device_listener, input);
+ wl_input_device_set_user_data(input->input_device, input);
}
/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/wayland/SDL_waylandevents_c.h b/src/video/wayland/SDL_waylandevents_c.h
index 92ce0ad2..74131f7e 100644
--- a/src/video/wayland/SDL_waylandevents_c.h
+++ b/src/video/wayland/SDL_waylandevents_c.h
@@ -21,8 +21,28 @@
*/
#include "SDL_config.h"
+#ifndef _SDL_waylandevents_h
+#define _SDL_waylandevents_h
+
#include "SDL_waylandvideo.h"
+#include "SDL_waylandwindow.h"
+
+struct SDL_WaylandInput {
+ SDL_WaylandData *display;
+ struct wl_input_device *input_device;
+ SDL_WaylandWindow *pointer_focus;
+ SDL_WaylandWindow *keyboard_focus;
+ uint32_t current_pointer_image;
+ uint32_t modifiers;
+ int32_t x, y, sx, sy;
+};
+
+extern void Wayland_init_xkb(SDL_WaylandData *d);
extern void Wayland_PumpEvents(_THIS);
+extern void Wayland_display_add_input(SDL_WaylandData *d, uint32_t id);
+
+#endif
+
/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/wayland/SDL_waylandgl.c b/src/video/wayland/SDL_waylandgl.c
index e49dd578..5809b978 100644
--- a/src/video/wayland/SDL_waylandgl.c
+++ b/src/video/wayland/SDL_waylandgl.c
@@ -6,7 +6,7 @@
void Wayland_GL_SwapWindow(_THIS, SDL_Window * window)
{
- printf("Wayland_GL_SwapWindow\n");
+ //printf("Wayland_GL_SwapWindow\n");
SDL_WaylandWindow *data = window->driverdata;
data->current ^= 1;
@@ -52,7 +52,7 @@ Wayland_GL_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
GL_COLOR_ATTACHMENT0_EXT,
GL_RENDERBUFFER_EXT,
wind->rbo[wind->current]);
- fprintf(stderr, "framebuffer complete: %d\n",
+ printf("framebuffer complete: %d\n",
glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT) == GL_FRAMEBUFFER_COMPLETE);
return 1;
@@ -132,23 +132,6 @@ Wayland_GL_LoadLibrary(_THIS, const char *path)
eglBindAPI(EGL_OPENGL_API);
-/* if (!eglBindAPI(EGL_OPENGL_ES_API)) {
- fprintf(stderr, "failed to bind EGL_OPENGL_ES_API\n");
- return -1;
- }
-
- data->context = eglCreateContext(data->edpy, NULL,
- EGL_NO_CONTEXT, context_attribs);
- if (data->context == NULL) {
- fprintf(stderr, "failed to create context\n");
- return -1;
- }
-
- if (!eglMakeCurrent(data->edpy, EGL_NO_SURFACE,
- EGL_NO_SURFACE, data->context)) {
- fprintf(stderr, "failed to make context current\n");
- return -1;
- }*/
return 0;
}
diff --git a/src/video/wayland/SDL_waylandgl.h b/src/video/wayland/SDL_waylandgl.h
index b566cbf5..6cbf6f24 100644
--- a/src/video/wayland/SDL_waylandgl.h
+++ b/src/video/wayland/SDL_waylandgl.h
@@ -3,7 +3,7 @@
#ifndef _SDL_waylandgl_h
#define _SDL_waylandgl_h
#include "SDL_waylandwindow.h"
-#include </home/joel/install/include/wayland-client-protocol.h>
+#include <wayland-client-protocol.h>
void Wayland_GL_SwapWindow(_THIS, SDL_Window * window);
int Wayland_GL_GetSwapInterval(_THIS);
diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c
index 78796e07..3462a4c3 100644
--- a/src/video/wayland/SDL_waylandvideo.c
+++ b/src/video/wayland/SDL_waylandvideo.c
@@ -82,6 +82,8 @@ Wayland_CreateDevice(int devindex)
device->VideoInit = Wayland_VideoInit;
device->VideoQuit = Wayland_VideoQuit;
device->SetDisplayMode = Wayland_SetDisplayMode;
+
+
device->PumpEvents = Wayland_PumpEvents;
device->GL_SwapWindow = Wayland_GL_SwapWindow;
@@ -159,6 +161,7 @@ static const struct wl_drm_listener drm_listener = {
};
+
static void
display_handle_global(struct wl_display *display, uint32_t id,
const char *interface, uint32_t version, void *data)
@@ -171,7 +174,7 @@ display_handle_global(struct wl_display *display, uint32_t id,
d->output = wl_output_create(display, id);
wl_output_add_listener(d->output, &output_listener, d);
} else if (strcmp(interface, "input_device") == 0) {
- //display_add_input(d, id);
+ Wayland_display_add_input(d, id);
} else if (strcmp(interface, "shell") == 0) {
d->shell = wl_shell_create(display, id);
wl_shell_add_listener(d->shell, &shell_listener, d);
@@ -187,7 +190,7 @@ static int update_event_mask(uint32_t mask, void *data)
SDL_WaylandData *d = data;
d->event_mask = mask;
- printf("updated event_mask: %d\n", mask);
+ //printf("updated event_mask: %d\n", mask);
#if 0
if (mask & WL_DISPLAY_READABLE)
@@ -247,6 +250,8 @@ Wayland_VideoInit(_THIS)
data->event_fd = wl_display_get_fd(data->display, update_event_mask, data);
+ Wayland_init_xkb(data);
+
SDL_VideoDisplay display;
SDL_DisplayMode mode;
diff --git a/src/video/wayland/SDL_waylandvideo.h b/src/video/wayland/SDL_waylandvideo.h
index a7f0d7cf..5274c97c 100644
--- a/src/video/wayland/SDL_waylandvideo.h
+++ b/src/video/wayland/SDL_waylandvideo.h
@@ -53,6 +53,8 @@ typedef struct
EGLDisplay edpy;
GLuint fbo;
+
+ struct xkb_desc *xkb;
int event_fd;
int event_mask;
diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c
index 02524cba..9e195056 100644
--- a/src/video/wayland/SDL_waylandwindow.c
+++ b/src/video/wayland/SDL_waylandwindow.c
@@ -30,6 +30,7 @@ int Wayland_CreateWindow(_THIS, SDL_Window * window)
window->driverdata = data;
struct wl_visual *visual;
int i;
+ data->waylandData = c;
EGLint name, stride, attribs[] = {
EGL_WIDTH, 0,
EGL_HEIGHT, 0,
diff --git a/src/video/wayland/SDL_waylandwindow.h b/src/video/wayland/SDL_waylandwindow.h
index 59b8dcfb..99aad6d0 100644
--- a/src/video/wayland/SDL_waylandwindow.h
+++ b/src/video/wayland/SDL_waylandwindow.h
@@ -9,6 +9,7 @@
typedef struct
{
+ SDL_WaylandData *waylandData;
struct wl_surface *surface;
struct wl_buffer *buffer[2];
@@ -16,6 +17,8 @@ typedef struct
GLuint rbo[2];
uint32_t fb_id[2];
uint32_t current;
+
+ struct SDL_WaylandInput *keyboard_device;
EGLContext context;