summaryrefslogtreecommitdiff
path: root/modules/evdev
diff options
context:
space:
mode:
authorAlfred E. Heggestad <aeh@db.org>2014-10-19 01:23:57 +0200
committerAlfred E. Heggestad <aeh@db.org>2014-10-19 01:23:57 +0200
commit76db3b6d9fabb4c9460c917bfc4405a50897658e (patch)
tree77a97667796553fc40a6e89654772d60eb496d85 /modules/evdev
parentad3905c989d13b5a216643437d2152f8c0629bde (diff)
ui: update UI-module API
- change from multiple-instances to single-instance (multiple-instances was never used) - remove ui/input config parameters from the "core" config, moved to each specific module (cons and evdev) - modules updated: stdio, cons, evdev, wincons - this patch solves the reported crash, that module-functions are called after the module was unloaded.
Diffstat (limited to 'modules/evdev')
-rw-r--r--modules/evdev/evdev.c63
1 files changed, 38 insertions, 25 deletions
diff --git a/modules/evdev/evdev.c b/modules/evdev/evdev.c
index ba924f4..962cdc9 100644
--- a/modules/evdev/evdev.c
+++ b/modules/evdev/evdev.c
@@ -14,22 +14,26 @@
#include "print.h"
-/* Note:
+/**
+ * @defgroup evdev evdev
+ *
+ * User-Interface (UI) module using the Linux input subsystem.
*
- * KEY_NUMERIC_xyz added in linux kernel 2.6.28
+ * The following options can be configured:
+ *
+ \verbatim
+ evdev_device /dev/input/event0 # Name of the input device to use
+ \endverbatim
*/
struct ui_st {
- struct ui *ui; /* base class */
int fd;
- ui_input_h *h;
- void *arg;
};
-static struct ui *evdev;
-static char evdev_device[64] = "/dev/event0";
+static struct ui_st *evdev;
+static char evdev_device[64] = "/dev/input/event0";
static void evdev_close(struct ui_st *st)
@@ -48,7 +52,6 @@ static void evdev_destructor(void *arg)
struct ui_st *st = arg;
evdev_close(st);
- mem_deref(st->ui);
}
@@ -160,14 +163,10 @@ static int stderr_handler(const char *p, size_t sz, void *arg)
static void reportkey(struct ui_st *st, int ascii)
{
- struct re_printf pf;
-
- pf.vph = stderr_handler;
+ static struct re_printf pf_stderr = {stderr_handler, NULL};
+ (void)st;
- if (!st->h)
- return;
-
- st->h(ascii, &pf, st->arg);
+ ui_input_key(ascii, &pf_stderr);
}
@@ -221,10 +220,8 @@ static void evdev_fd_handler(int flags, void *arg)
}
-static int evdev_alloc(struct ui_st **stp, struct ui_prm *prm,
- ui_input_h *uih, void *arg)
+static int evdev_alloc(struct ui_st **stp, const char *dev)
{
- const char *dev = str_isset(prm->device) ? prm->device : evdev_device;
struct ui_st *st;
int err = 0;
@@ -235,10 +232,10 @@ static int evdev_alloc(struct ui_st **stp, struct ui_prm *prm,
if (!st)
return ENOMEM;
- st->ui = mem_ref(evdev);
st->fd = open(dev, O_RDWR);
if (st->fd < 0) {
err = errno;
+ warning("evdev: failed to open device '%s' (%m)\n", dev, err);
goto out;
}
@@ -259,9 +256,6 @@ static int evdev_alloc(struct ui_st **stp, struct ui_prm *prm,
if (err)
goto out;
- st->h = uih;
- st->arg = arg;
-
out:
if (err)
mem_deref(st);
@@ -290,11 +284,12 @@ static int buzz(const struct ui_st *st, int value)
}
-static int evdev_output(struct ui_st *st, const char *str)
+static int evdev_output(const char *str)
{
+ struct ui_st *st = evdev;
int err = 0;
- if (!str)
+ if (!st || !str)
return EINVAL;
while (*str) {
@@ -314,14 +309,32 @@ static int evdev_output(struct ui_st *st, const char *str)
}
+static struct ui ui_evdev = {
+ .name = "evdev",
+ .outputh = evdev_output
+};
+
+
static int module_init(void)
{
- return ui_register(&evdev, "evdev", evdev_alloc, evdev_output);
+ int err;
+
+ conf_get_str(conf_cur(), "evdev_device",
+ evdev_device, sizeof(evdev_device));
+
+ err = evdev_alloc(&evdev, evdev_device);
+ if (err)
+ return err;
+
+ ui_unregister(&ui_evdev);
+
+ return 0;
}
static int module_close(void)
{
+ ui_unregister(&ui_evdev);
evdev = mem_deref(evdev);
return 0;
}