summaryrefslogtreecommitdiff
path: root/src/libsystemd-terminal/idev.h
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2014-08-27 18:17:27 +0200
committerDavid Herrmann <dh.herrmann@gmail.com>2014-08-27 18:42:28 +0200
commite202fa31fb2d60084e7b2ab7976a81c138184d40 (patch)
tree2b78acd6bba9f6b2d756899af3dfb51e9a533fee /src/libsystemd-terminal/idev.h
parent7ed3a638b2e4ffb5e76a0cf1a008e1c7233edb75 (diff)
terminal: add input interface
The idev-interface provides input drivers for all libsystemd-terminal based applications. It is split into 4 main objects: idev_context: The context object tracks global state of the input interface. This will include data like system-keymaps, xkb contexts and more. idev_session: A session serves as controller for a set of devices. Each session on an idev-context is independent of each other. The session is also the main notification object. All events raised via idev are reported through the session interface. Apart of that, the session is a pretty dumb object that just contains devices. idev_element: Elements provide real hardware in the idev stack. For each hardware device, one element is added. Elements have no knowledge of higher-level device types, they only provide raw input data to the upper levels. For example, each evdev device is represented by a different element in an idev session. idev_device: Devices are objects that the application deals with. An application is usually not interested in elements (and those are hidden to applications), instead, they want high-level input devices like keyboard, touchpads, mice and more. Device are the high-level interface provided by idev. Each device might be fed by a set of elements. Elements drive the device. If elements are removed, devices are destroyed. If elements are added, suitable devices are created. Applications should monitor the system for sessions and hardware devices. For each session they want to operate on, they create an idev_session object and add hardware to that object. The idev interface requires the application to monitor the system (preferably via sysview_*, but not required) for hardware devices. Whenever hardware is added to the idev session, new devices *might* be created. The relationship between hardware and high-level idev-devices is hidden in the idev-session and not exposed. Internally, the idev elements and devices are virtual objects. Each real hardware and device type inherits those virtual objects and provides real elements and devices. Those types will be added in follow-up commits. Data flow from hardware to the application is done via idev_*_feed() functions. Data flow from applications to hardware is done via idev_*_feedback() functions. Feedback is usually used for LEDs, FF and similar operations.
Diffstat (limited to 'src/libsystemd-terminal/idev.h')
-rw-r--r--src/libsystemd-terminal/idev.h133
1 files changed, 133 insertions, 0 deletions
diff --git a/src/libsystemd-terminal/idev.h b/src/libsystemd-terminal/idev.h
new file mode 100644
index 0000000000..6f618f37af
--- /dev/null
+++ b/src/libsystemd-terminal/idev.h
@@ -0,0 +1,133 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright (C) 2014 David Herrmann <dh.herrmann@gmail.com>
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+/*
+ * IDev
+ */
+
+#pragma once
+
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <systemd/sd-bus.h>
+#include <systemd/sd-event.h>
+#include "util.h"
+
+typedef struct idev_data idev_data;
+
+typedef struct idev_event idev_event;
+typedef struct idev_device idev_device;
+typedef struct idev_session idev_session;
+typedef struct idev_context idev_context;
+
+/*
+ * Types
+ */
+
+enum {
+ IDEV_ELEMENT_CNT
+};
+
+enum {
+ IDEV_DEVICE_CNT
+};
+
+/*
+ * Data Packets
+ */
+
+enum {
+ IDEV_DATA_RESYNC,
+ IDEV_DATA_CNT
+};
+
+struct idev_data {
+ unsigned int type;
+ bool resync : 1;
+};
+
+/*
+ * Events
+ */
+
+enum {
+ IDEV_EVENT_DEVICE_ADD,
+ IDEV_EVENT_DEVICE_REMOVE,
+ IDEV_EVENT_DEVICE_DATA,
+ IDEV_EVENT_CNT
+};
+
+struct idev_event {
+ unsigned int type;
+ union {
+ struct {
+ idev_device *device;
+ } device_add, device_remove;
+
+ struct {
+ idev_device *device;
+ idev_data data;
+ } device_data;
+ };
+};
+
+typedef int (*idev_event_fn) (idev_session *s, void *userdata, idev_event *ev);
+
+/*
+ * Devices
+ */
+
+void idev_device_enable(idev_device *d);
+void idev_device_disable(idev_device *d);
+
+/*
+ * Sessions
+ */
+
+enum {
+ IDEV_SESSION_CUSTOM = (1 << 0),
+ IDEV_SESSION_MANAGED = (1 << 1),
+};
+
+int idev_session_new(idev_session **out,
+ idev_context *c,
+ unsigned int flags,
+ const char *name,
+ idev_event_fn event_fn,
+ void *userdata);
+idev_session *idev_session_free(idev_session *s);
+
+DEFINE_TRIVIAL_CLEANUP_FUNC(idev_session*, idev_session_free);
+
+bool idev_session_is_enabled(idev_session *s);
+void idev_session_enable(idev_session *s);
+void idev_session_disable(idev_session *s);
+
+/*
+ * Contexts
+ */
+
+int idev_context_new(idev_context **out, sd_event *event, sd_bus *sysbus);
+idev_context *idev_context_ref(idev_context *c);
+idev_context *idev_context_unref(idev_context *c);
+
+DEFINE_TRIVIAL_CLEANUP_FUNC(idev_context*, idev_context_unref);