commit b9f6dd5120b4b7d80e1d51f0598f39a3dfc7555b
parent ae4bd8494a390fb97f00b0c857e8911aaab1ad1f
Author: Michael Forney <mforney@mforney.org>
Date: Sun, 30 Jun 2013 22:05:47 -0700
Rename input.{c,h} to input_focus.{c,h}
Diffstat:
M | Makefile.am | | | 2 | +- |
D | input.c | | | 108 | ------------------------------------------------------------------------------- |
D | input.h | | | 46 | ---------------------------------------------- |
A | input_focus.c | | | 128 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | input_focus.h | | | 66 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
M | keyboard.c | | | 20 | ++++++++++---------- |
M | keyboard.h | | | 6 | +++--- |
M | pointer.c | | | 26 | +++++++++++++------------- |
M | pointer.h | | | 6 | +++--- |
M | seat.c | | | 12 | ++++++------ |
10 files changed, 230 insertions(+), 190 deletions(-)
diff --git a/Makefile.am b/Makefile.am
@@ -13,7 +13,7 @@ libswc_la_SOURCES = \
surface.c surface.h \
region.c region.h \
renderer.c renderer.h \
- input.c input.h \
+ input_focus.c input_focus.h \
keyboard.c keyboard.h \
pointer.c pointer.h \
seat.c seat.h \
diff --git a/input.c b/input.c
@@ -1,108 +0,0 @@
-#include "input.h"
-#include "surface.h"
-
-#include <assert.h>
-
-#include "util.h"
-
-static inline void focus(struct swc_input * input,
- struct swc_surface * surface,
- struct wl_resource * resource)
-{
- if (resource)
- {
- input->handler->enter(input->handler, resource, surface);
- }
-
- input->focus.surface = surface;
- input->focus.resource = resource;
-}
-
-static inline void unfocus(struct swc_input * input)
-{
- if (input->focus.resource)
- {
- input->handler->leave(input->handler, input->focus.resource,
- input->focus.surface);
- }
-}
-
-bool swc_input_initialize(struct swc_input * input,
- struct swc_input_handler * handler)
-{
- input->focus.resource = NULL;
- input->focus.surface = NULL;
- input->handler = handler;
-
- wl_list_init(&input->resources);
-
- return true;
-}
-
-void swc_input_finish(struct swc_input * input)
-{
- /* XXX: Destroy resources? */
-}
-
-void swc_input_add_resource(struct swc_input * input,
- struct wl_resource * resource)
-{
- /* If this new input resource corresponds to our focus, set it as our
- * focus. */
- if (input->focus.surface)
- {
- struct wl_client * client, * surface_client;
-
- client = wl_resource_get_client(resource);
- surface_client = wl_resource_get_client(input->focus.surface->resource);
-
- if (client == surface_client)
- {
- unfocus(input);
- focus(input, input->focus.surface, resource);
- }
- }
-
- wl_list_insert(&input->resources, wl_resource_get_link(resource));
-}
-
-void swc_input_remove_resource(struct swc_input * input,
- struct wl_resource * resource)
-{
- if (resource == input->focus.resource)
- input->focus.resource = NULL;
-
- swc_remove_resource(resource);
-}
-
-void swc_input_set_focus(struct swc_input * input,
- struct swc_surface * surface)
-{
- struct wl_client * client;
- struct wl_display * display;
- struct wl_resource * resource;
- uint32_t serial;
-
- if (surface == input->focus.surface)
- return;
-
- /* Unfocus previously focused surface. */
- unfocus(input);
-
- /* Focus new surface, if given. */
- if (surface)
- {
- client = wl_resource_get_client(surface->resource);
- resource = wl_resource_find_for_client(&input->resources, client);
-
- focus(input, surface, resource);
- }
- else
- {
- input->focus.surface = NULL;
- input->focus.resource = NULL;
- }
-
- return;
-}
-
diff --git a/input.h b/input.h
@@ -1,46 +0,0 @@
-#ifndef SWC_INPUT_H
-#define SWC_INPUT_H 1
-
-#include <stdbool.h>
-#include <wayland-server.h>
-
-struct swc_surface;
-
-struct swc_input_handler
-{
- void (* enter)(struct swc_input_handler * handler,
- struct wl_resource * resource,
- struct swc_surface * surface);
- void (* leave)(struct swc_input_handler * handler,
- struct wl_resource * resource,
- struct swc_surface * surface);
-};
-
-struct swc_input
-{
- struct
- {
- struct wl_resource * resource;
- struct swc_surface * surface;
- } focus;
-
- struct swc_input_handler * handler;
- struct wl_list resources;
-};
-
-bool swc_input_initialize(struct swc_input * input,
- struct swc_input_handler * input_handler);
-
-void swc_input_finish(struct swc_input * input);
-
-void swc_input_add_resource(struct swc_input * input,
- struct wl_resource * resource);
-
-void swc_input_remove_resource(struct swc_input * input,
- struct wl_resource * resource);
-
-void swc_input_set_focus(struct swc_input * input,
- struct swc_surface * surface);
-
-#endif
-
diff --git a/input_focus.c b/input_focus.c
@@ -0,0 +1,128 @@
+/* swc: input_focus.c
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "input_focus.h"
+#include "surface.h"
+#include "util.h"
+
+static inline void focus(struct swc_input_focus * input_focus,
+ struct swc_surface * surface,
+ struct wl_resource * resource)
+{
+ if (resource)
+ {
+ input_focus->handler->enter(input_focus->handler, resource, surface);
+ }
+
+ input_focus->surface = surface;
+ input_focus->resource = resource;
+}
+
+static inline void unfocus(struct swc_input_focus * input_focus)
+{
+ if (input_focus->resource)
+ {
+ input_focus->handler->leave(input_focus->handler, input_focus->resource,
+ input_focus->surface);
+ }
+}
+
+bool swc_input_focus_initialize(struct swc_input_focus * input_focus,
+ struct swc_input_focus_handler * handler)
+{
+ input_focus->resource = NULL;
+ input_focus->surface = NULL;
+ input_focus->handler = handler;
+
+ wl_list_init(&input_focus->resources);
+
+ return true;
+}
+
+void swc_input_focus_finish(struct swc_input_focus * input_focus)
+{
+ /* XXX: Destroy resources? */
+}
+
+void swc_input_focus_add_resource(struct swc_input_focus * input_focus,
+ struct wl_resource * resource)
+{
+ /* If this new input resource corresponds to our focus, set it as our
+ * focus. */
+ if (input_focus->surface)
+ {
+ struct wl_client * client, * surface_client;
+
+ client = wl_resource_get_client(resource);
+ surface_client = wl_resource_get_client(input_focus->surface->resource);
+
+ if (client == surface_client)
+ {
+ unfocus(input_focus);
+ focus(input_focus, input_focus->surface, resource);
+ }
+ }
+
+ wl_list_insert(&input_focus->resources, wl_resource_get_link(resource));
+}
+
+void swc_input_focus_remove_resource(struct swc_input_focus * input_focus,
+ struct wl_resource * resource)
+{
+ if (resource == input_focus->resource)
+ input_focus->resource = NULL;
+
+ swc_remove_resource(resource);
+}
+
+void swc_input_focus_set(struct swc_input_focus * input_focus,
+ struct swc_surface * surface)
+{
+ struct wl_client * client;
+ struct wl_display * display;
+ struct wl_resource * resource;
+ uint32_t serial;
+
+ if (surface == input_focus->surface)
+ return;
+
+ /* Unfocus previously focused surface. */
+ unfocus(input_focus);
+
+ /* Focus new surface, if given. */
+ if (surface)
+ {
+ client = wl_resource_get_client(surface->resource);
+ resource = wl_resource_find_for_client(&input_focus->resources, client);
+
+ focus(input_focus, surface, resource);
+ }
+ else
+ {
+ input_focus->surface = NULL;
+ input_focus->resource = NULL;
+ }
+
+ return;
+}
+
diff --git a/input_focus.h b/input_focus.h
@@ -0,0 +1,66 @@
+/* swc: input_focus.h
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef SWC_INPUT_FOCUS_H
+#define SWC_INPUT_FOCUS_H 1
+
+#include <stdbool.h>
+#include <wayland-server.h>
+
+struct swc_surface;
+
+struct swc_input_focus_handler
+{
+ void (* enter)(struct swc_input_focus_handler * handler,
+ struct wl_resource * resource,
+ struct swc_surface * surface);
+ void (* leave)(struct swc_input_focus_handler * handler,
+ struct wl_resource * resource,
+ struct swc_surface * surface);
+};
+
+struct swc_input_focus
+{
+ struct wl_resource * resource;
+ struct swc_surface * surface;
+
+ struct swc_input_focus_handler * handler;
+ struct wl_list resources;
+};
+
+bool swc_input_focus_initialize(struct swc_input_focus * input_focus,
+ struct swc_input_focus_handler * input_handler);
+
+void swc_input_focus_finish(struct swc_input_focus * input_focus);
+
+void swc_input_focus_add_resource(struct swc_input_focus * input_focus,
+ struct wl_resource * resource);
+
+void swc_input_focus_remove_resource(struct swc_input_focus * input_focus,
+ struct wl_resource * resource);
+
+void swc_input_focus_set(struct swc_input_focus * input_focus,
+ struct swc_surface * surface);
+
+#endif
+
diff --git a/keyboard.c b/keyboard.c
@@ -3,7 +3,7 @@
#include <stdio.h>
-static void enter(struct swc_input_handler * handler,
+static void enter(struct swc_input_focus_handler * handler,
struct wl_resource * resource, struct swc_surface * surface)
{
struct swc_keyboard * keyboard;
@@ -11,7 +11,7 @@ static void enter(struct swc_input_handler * handler,
struct wl_display * display;
uint32_t serial;
- keyboard = wl_container_of(handler, keyboard, input_handler);
+ keyboard = wl_container_of(handler, keyboard, focus_handler);
client = wl_resource_get_client(resource);
display = wl_client_get_display(client);
serial = wl_display_next_serial(display);
@@ -20,7 +20,7 @@ static void enter(struct swc_input_handler * handler,
&keyboard->keys);
}
-static void leave(struct swc_input_handler * handler,
+static void leave(struct swc_input_focus_handler * handler,
struct wl_resource * resource, struct swc_surface * surface)
{
struct wl_client * client;
@@ -38,10 +38,10 @@ bool swc_keyboard_initialize(struct swc_keyboard * keyboard)
{
wl_array_init(&keyboard->keys);
- keyboard->input_handler.enter = &enter;
- keyboard->input_handler.leave = &leave;
+ keyboard->focus_handler.enter = &enter;
+ keyboard->focus_handler.leave = &leave;
- swc_input_initialize(&keyboard->input, &keyboard->input_handler);
+ swc_input_focus_initialize(&keyboard->focus, &keyboard->focus_handler);
return true;
}
@@ -49,7 +49,7 @@ bool swc_keyboard_initialize(struct swc_keyboard * keyboard)
void swc_keyboard_finish(struct swc_keyboard * keyboard)
{
wl_array_release(&keyboard->keys);
- swc_input_finish(&keyboard->input);
+ swc_input_focus_finish(&keyboard->focus);
}
/**
@@ -58,14 +58,14 @@ void swc_keyboard_finish(struct swc_keyboard * keyboard)
void swc_keyboard_set_focus(struct swc_keyboard * keyboard,
struct swc_surface * surface)
{
- swc_input_set_focus(&keyboard->input, surface);
+ swc_input_focus_set(&keyboard->focus, surface);
}
static void unbind(struct wl_resource * resource)
{
struct swc_keyboard * keyboard = wl_resource_get_user_data(resource);
- swc_input_remove_resource(&keyboard->input, resource);
+ swc_input_focus_remove_resource(&keyboard->focus, resource);
}
struct wl_resource * swc_keyboard_bind(struct swc_keyboard * keyboard,
@@ -76,7 +76,7 @@ struct wl_resource * swc_keyboard_bind(struct swc_keyboard * keyboard,
client_resource = wl_client_add_object(client, &wl_keyboard_interface,
NULL, id, keyboard);
wl_resource_set_destructor(client_resource, &unbind);
- swc_input_add_resource(&keyboard->input, client_resource);
+ swc_input_focus_add_resource(&keyboard->focus, client_resource);
return client_resource;
}
diff --git a/keyboard.h b/keyboard.h
@@ -2,7 +2,7 @@
#define SWC_KEYBOARD_H 1
#include "surface.h"
-#include "input.h"
+#include "input_focus.h"
#include <wayland-server.h>
@@ -19,8 +19,8 @@ struct swc_keyboard_handler
struct swc_keyboard
{
- struct swc_input input;
- struct swc_input_handler input_handler;
+ struct swc_input_focus focus;
+ struct swc_input_focus_handler focus_handler;
struct swc_keyboard_handler * handler;
diff --git a/pointer.c b/pointer.c
@@ -4,7 +4,7 @@
#include <stdio.h>
-static void enter(struct swc_input_handler * handler,
+static void enter(struct swc_input_focus_handler * handler,
struct wl_resource * resource, struct swc_surface * surface)
{
struct swc_pointer * pointer;
@@ -13,7 +13,7 @@ static void enter(struct swc_input_handler * handler,
uint32_t serial;
wl_fixed_t surface_x, surface_y;
- pointer = wl_container_of(handler, pointer, input_handler);
+ pointer = wl_container_of(handler, pointer, focus_handler);
client = wl_resource_get_client(resource);
display = wl_client_get_display(client);
serial = wl_display_next_serial(display);
@@ -26,7 +26,7 @@ static void enter(struct swc_input_handler * handler,
surface_x, surface_y);
}
-static void leave(struct swc_input_handler * handler,
+static void leave(struct swc_input_focus_handler * handler,
struct wl_resource * resource, struct swc_surface * surface)
{
struct wl_client * client;
@@ -49,7 +49,7 @@ static void handle_focus_surface_destroy(struct wl_listener * listener,
pointer = wl_container_of(listener, pointer,
focus_surface_destroy_listener);
- pointer->input.focus.surface = NULL;
+ pointer->focus.surface = NULL;
}
bool swc_pointer_initialize(struct swc_pointer * pointer)
@@ -59,20 +59,20 @@ bool swc_pointer_initialize(struct swc_pointer * pointer)
pointer->x = wl_fixed_from_int(0);
pointer->y = wl_fixed_from_int(0);
- pointer->input_handler.enter = &enter;
- pointer->input_handler.leave = &leave;
+ pointer->focus_handler.enter = &enter;
+ pointer->focus_handler.leave = &leave;
pointer->focus_surface_destroy_listener.notify
= &handle_focus_surface_destroy;
- swc_input_initialize(&pointer->input, &pointer->input_handler);
+ swc_input_focus_initialize(&pointer->focus, &pointer->focus_handler);
return true;
}
void swc_pointer_finish(struct swc_pointer * pointer)
{
- swc_input_finish(&pointer->input);
+ swc_input_focus_finish(&pointer->focus);
}
/**
@@ -81,9 +81,9 @@ void swc_pointer_finish(struct swc_pointer * pointer)
void swc_pointer_set_focus(struct swc_pointer * pointer,
struct swc_surface * surface)
{
- if (surface != pointer->input.focus.surface)
+ if (surface != pointer->focus.surface)
{
- if (pointer->input.focus.surface)
+ if (pointer->focus.surface)
wl_list_remove(&pointer->focus_surface_destroy_listener.link);
if (surface)
@@ -91,7 +91,7 @@ void swc_pointer_set_focus(struct swc_pointer * pointer,
(surface->resource, &pointer->focus_surface_destroy_listener);
}
- swc_input_set_focus(&pointer->input, surface);
+ swc_input_focus_set(&pointer->focus, surface);
}
static void set_cursor(struct wl_client * client,
@@ -132,7 +132,7 @@ static void unbind(struct wl_resource * resource)
{
struct swc_pointer * pointer = wl_resource_get_user_data(resource);
- swc_input_remove_resource(&pointer->input, resource);
+ swc_input_focus_remove_resource(&pointer->focus, resource);
}
struct wl_resource * swc_pointer_bind(struct swc_pointer * pointer,
@@ -145,7 +145,7 @@ struct wl_resource * swc_pointer_bind(struct swc_pointer * pointer,
client_resource = wl_client_add_object(client, &wl_pointer_interface,
&pointer_implementation, id, pointer);
wl_resource_set_destructor(client_resource, &unbind);
- swc_input_add_resource(&pointer->input, client_resource);
+ swc_input_focus_add_resource(&pointer->focus, client_resource);
return client_resource;
}
diff --git a/pointer.h b/pointer.h
@@ -2,7 +2,7 @@
#define SWC_POINTER_H 1
#include "surface.h"
-#include "input.h"
+#include "input_focus.h"
#include <wayland-server.h>
@@ -23,8 +23,8 @@ enum swc_pointer_event
struct swc_pointer
{
- struct swc_input input;
- struct swc_input_handler input_handler;
+ struct swc_input_focus focus;
+ struct swc_input_focus_handler focus_handler;
struct wl_listener focus_surface_destroy_listener;
struct wl_signal event_signal;
diff --git a/seat.c b/seat.c
@@ -27,10 +27,10 @@ static void handle_key(struct swc_seat * seat, uint32_t time, uint32_t key,
uint32_t serial;
enum xkb_key_direction direction;
- if (keyboard->input.focus.resource)
+ if (keyboard->focus.resource)
{
struct wl_client * client
- = wl_resource_get_client(keyboard->input.focus.resource);
+ = wl_resource_get_client(keyboard->focus.resource);
display = wl_client_get_display(client);
}
@@ -70,10 +70,10 @@ static void handle_key(struct swc_seat * seat, uint32_t time, uint32_t key,
if (!(keyboard->handler && keyboard->handler->key)
|| !keyboard->handler->key(keyboard, time, key, state))
{
- if (keyboard->input.focus.resource)
+ if (keyboard->focus.resource)
{
serial = wl_display_next_serial(display);
- wl_keyboard_send_key(keyboard->input.focus.resource, serial, time,
+ wl_keyboard_send_key(keyboard->focus.resource, serial, time,
key, state);
if (state == WL_KEYBOARD_KEY_STATE_PRESSED)
@@ -102,10 +102,10 @@ static void handle_key(struct swc_seat * seat, uint32_t time, uint32_t key,
|| mods_locked != keyboard->modifiers.mods_locked
|| group != keyboard->modifiers.group)
{
- if (keyboard->input.focus.resource)
+ if (keyboard->focus.resource)
{
serial = wl_display_next_serial(display);
- wl_keyboard_send_modifiers(keyboard->input.focus.resource,
+ wl_keyboard_send_modifiers(keyboard->focus.resource,
serial, mods_depressed, mods_latched,
mods_locked, group);
}