ENDFOREACH(flag)
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIE -rdynamic")
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions -D_GNU_SOURCE")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
SET(CMAKE_EXE_LINKER_FLAGS "-pie")
static int input_init_handler(void)
{
if (!display_conf.input_support)
- return 0;
-
- g_idle_add(display_input_init, NULL);
+ remove_device_by_devname("input");
return 0;
}
unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed);
unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed);
- display_input_exit();
break;
}
}
#include <linux/input.h>
#include <glib.h>
+#include "shared/common.h"
#include "shared/devices.h"
#include "shared/log.h"
#define LONGPRESS_INTERVAL 10000 /* milisecond */
+static int longpress_interval = LONGPRESS_INTERVAL;
static guint longpress_timer_id;
static gboolean longpressed_cb(void *data)
longpress_timer_id = 0;
}
- longpress_timer_id = g_timeout_add(LONGPRESS_INTERVAL, longpressed_cb, NULL);
+ longpress_timer_id = g_timeout_add(longpress_interval, longpressed_cb, NULL);
}
static void stop_longpress_timer(void)
}
}
-/* poweroff if power button is pressed longer than LONGPRESS_INTERVAL */
-static void input_event_handler(struct libinput_event *e)
+static int input_handler_execute(void *data)
{
+ struct libinput_event *e;
struct libinput_event_keyboard *ek;
int keycode, keyvalue;
+ if (!data)
+ return 0;
+
+ e = (struct libinput_event *) data;
+
if (libinput_event_get_type(e) != LIBINPUT_EVENT_KEYBOARD_KEY)
- return;
+ return 0;
ek = libinput_event_get_keyboard_event(e);
keycode = libinput_event_keyboard_get_key(ek);
else if (keyvalue == KEYVALUE_RELEASE)
stop_longpress_timer();
}
-}
-static void input_event_handler_init(void *data)
-{
- const struct device_ops *input_device;
-
- input_device = find_device("input");
- if (check_default(input_device)) {
- _E("There is no input device");
- return;
- }
-
- if (input_device->init) {
- _D("[%s] Initialization.", input_device->name);
- input_device->init(input_event_handler);
- }
+ return 0;
}
-static void input_event_handler_exit(void *data)
+static void input_handler_init(void *data)
{
- const struct device_ops *input_device;
-
- input_device = find_device("input");
- if (check_default(input_device)) {
- _E("There is no input device");
- return;
- }
-
- if (input_device->exit)
- input_device->exit(NULL);
+ // TODO: parse system config, which set holding time of short/long key
}
-static const struct device_ops input_event_handler_device_ops = {
- DECLARE_NAME_LEN("input-event-handler"),
- .init = input_event_handler_init,
- .exit = input_event_handler_exit,
+static const struct device_ops input_handler_device_ops = {
+ DECLARE_NAME_LEN("input-handler"),
+ .init = input_handler_init,
+ .execute = input_handler_execute,
+ .disable_auto_init = true,
};
-DEVICE_OPS_REGISTER(&input_event_handler_device_ops);
+DEVICE_OPS_REGISTER(&input_handler_device_ops)
static int input_init_handler(void)
{
if (!display_conf.input_support)
- return 0;
-
- g_idle_add(display_input_init, NULL);
+ remove_device_by_devname("input");
return 0;
}
unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed);
unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed);
- display_input_exit();
break;
}
}
static int input_init_handler(void)
{
if (!display_conf.input_support)
- return 0;
-
- g_idle_add(display_input_init, NULL);
+ remove_device_by_devname("input");
return 0;
}
unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed);
unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed);
- display_input_exit();
break;
}
}
static int input_init_handler(void)
{
if (!display_conf.input_support)
- return 0;
-
- g_idle_add(display_input_init, NULL);
+ remove_device_by_devname("input");
return 0;
}
unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed);
unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed);
- display_input_exit();
break;
}
}
#define SEAT_NAME "seat0"
-static void process_event(struct libinput_event *ev)
+static void process_input(struct libinput_event *ev)
{
static const struct device_ops *display_device_ops;
struct input_event input;
poll_callback(INPUT_POLL_EVENT, NULL);
}
-gboolean display_input_init(gpointer data)
+static int input_handler_execute(void *data)
{
- static const struct device_ops *input_device;
-
- input_device = find_device("input");
- if (check_default(input_device))
- return G_SOURCE_REMOVE;
+ if (!data)
+ return 0;
- _D("[%s] Initialization.", input_device->name);
- if (input_device->init)
- input_device->init(process_event);
+ process_input(data);
- return G_SOURCE_REMOVE;
+ return 0;
}
-int display_input_exit(void)
+static void input_handler_init(void *data)
{
- static const struct device_ops *input_device;
-
- input_device = find_device("input");
- if (check_default(input_device))
- return 0;
+}
- input_device->exit(NULL);
+static const struct device_ops input_handler_device_ops = {
+ DECLARE_NAME_LEN("input-handler"),
+ .init = input_handler_init,
+ .execute = input_handler_execute,
+ .disable_auto_init = true,
+};
- return 0;
-}
+DEVICE_OPS_REGISTER(&input_handler_device_ops)
#define RESET_TIMER_STR "resettimer"
#define KEEP_TIMER_STR "keeptimer"
-gboolean display_input_init(gpointer data);
-int display_input_exit(void);
-
/**
* @}
*/
#include <sys/stat.h>
#include <linux/input.h>
#include <libinput.h>
+#include <dlfcn.h>
#include "shared/devices.h"
#include "shared/log.h"
static struct libinput *li;
static guint efd;
-static void (*input_event_handler) (struct libinput_event *);
+static const struct device_ops *input_handler;
-static gboolean input_handler(gint fd, GIOCondition cond, void *data)
+static gboolean input_callback(gint fd, GIOCondition cond, void *data)
{
struct libinput_event *ev;
- struct libinput *input = (struct libinput *)data;
+ struct libinput *input = (struct libinput *) data;
- if (!input || !input_event_handler)
+ if (!input_handler)
+ return G_SOURCE_REMOVE;
+
+ if (!input)
return G_SOURCE_CONTINUE;
libinput_dispatch(input);
while ((ev = libinput_get_event(input))) {
- input_event_handler(ev);
-
+ input_handler->execute(ev);
libinput_event_destroy(ev);
libinput_dispatch(input);
}
int ret;
int fd;
- if (!data) {
- _E("there is no handler for input event");
+ /* load plugin input handler */
+ input_handler = find_device("input-handler");
+ if (check_default(input_handler) || input_handler->execute == NULL) {
+ input_handler = NULL;
return;
}
- /* registering input event handler */
- input_event_handler = data;
+ if (input_handler->init)
+ input_handler->init(NULL);
udev = udev_new();
if (!udev) {
return;
}
- /* add to poll handler */
+ /* add poll callback */
efd = g_unix_fd_add(fd, G_IO_IN,
- input_handler,
+ input_callback,
(void *)((intptr_t)li));
if (!efd) {
_E("fail to g_unix_fd_add");
if (udev)
udev_unref(udev);
- input_event_handler = NULL;
+ if (input_handler && input_handler->exit)
+ input_handler->exit(NULL);
+
+ input_handler = NULL;
}
-/* input module parse and transfer
- * input event to input event handler */
static const struct device_ops input_device_ops = {
DECLARE_NAME_LEN("input"),
.init = input_init,
.exit = input_exit,
- .disable_auto_init = true,
+ .priority = -1, /* initialize at last */
};
DEVICE_OPS_REGISTER(&input_device_ops)
* limitations under the License.
*/
-#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
SYS_G_LIST_REMOVE(dev_head, dev);
}
+void remove_device_by_devname(const char *devname)
+{
+ const struct device_ops *dev = find_device(devname);
+
+ if (check_default(dev))
+ return;
+
+ _D("remove device=%s", devname);
+ remove_device(dev);
+}
+
const struct device_ops *find_device(const char *name)
{
GList *elem;
extern GList *dev_head;
void add_device(const struct device_ops *dev);
void remove_device(const struct device_ops *dev);
+void remove_device_by_devname(const char *devname);
const struct device_ops *find_device(const char *name);
int check_default(const struct device_ops *dev);
* limitations under the License.
*/
-#define _GNU_SOURCE
-
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
* limitations under the License.
*/
-#define _GNU_SOURCE
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define FUSE_USE_VERSION 26
-#define _GNU_SOURCE
#include <semaphore.h>
#include <fuse.h>
#include <stdio.h>
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#define _GNU_SOURCE
-
#include <stdio.h>
#include <stdint.h>
#include <limits.h>