}
- if (display_conf.input_support)
- if (CHECK_OPS(keyfilter_ops, init))
- keyfilter_ops->init();
-
set_display_init_direction(display_conf.display_init_direction);
}
}
/* timeout is not needed */
display_state_transition_reset_state_transition_timeout(TIMEOUT_NONE);
- if (CHECK_OPS(keyfilter_ops, exit))
- keyfilter_ops->exit();
-
unregister_kernel_uevent_control(&lcd_uevent_ops);
display_ops_exit(NULL);
#include "power/power-suspend.h"
#include "led/touch-key.h"
#include "display-lock.h"
+#include "input/input.h"
#ifndef KEY_SCREENLOCK
#define KEY_SCREENLOCK 0x98
}
}
-static int check_key(struct input_event *pinput, int fd)
+static int check_key(struct input_event *pinput)
{
int ignore = true;
return ignore;
}
-static int check_key_filter(void *data, int fd)
+static void check_key_filter(struct timeval time, unsigned short type, unsigned short keycode, unsigned int keyvalue)
{
- struct input_event *pinput = data;
+ struct input_event *pinput = &(struct input_event) {
+ .time = time,
+ .type = type,
+ .code = keycode,
+ .value = keyvalue
+ };
int ignore = true;
- static int old_fd, code, value;
+ static int code, value;
assert(pinput);
if (pinput->code == BTN_TOUCH && !current_state_in_on())
break;
if (pinput->code == code && pinput->value == value) {
- _E("Same key(%d, %d) is polled [%d,%d]",
- code, value, old_fd, fd);
+ _E("Same key(%d, %d) is polled", code, value);
}
gdbus_signal_emit(NULL,
DEVICED_PATH_INPUT,
"key",
g_variant_new("(iiii)", pinput->code, pinput->value, pinput->time.tv_sec, pinput->time.tv_usec));
- old_fd = fd;
code = pinput->code;
value = pinput->value;
update_vital_state(pinput);
- ignore = check_key(pinput, fd);
+ ignore = check_key(pinput);
restore_custom_brightness();
break;
ignore = false;
break;
case EV_ABS:
+ if (touch_event_blocked()
+ && !g_display_plugin.config->touch_wakeup
+ && pinput->value == KEY_BEING_PRESSED)
+ return;
+
update_vital_state(pinput);
if (pinput->value == KEY_PRESSED) {
switch_on_lcd(LCD_ON_BY_TOUCH);
}
if (ignore)
- return 1;
+ return;
- return 0;
+ /* lcd on or update lcd timeout */
+ poll_callback(INPUT_POLL_EVENT, NULL);
}
static int delayed_init_done(void *data)
.caps = DISPLAY_CAPA_LCDON,
};
-static void keyfilter_init(void)
-{
- display_add_actor(&display_powerkey_actor);
- display_add_actor(&display_menukey_actor);
-
- register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done);
- register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb);
-}
-
-static const struct display_keyfilter_ops normal_keyfilter_ops = {
- .init = keyfilter_init,
- .check = check_key_filter,
-};
-
-const struct display_keyfilter_ops *keyfilter_ops = &normal_keyfilter_ops;
-
static void __CONSTRUCTOR__ initialize(void)
{
disp_plgn = get_var_display_plugin();
- if (!disp_plgn) {
+ if (!disp_plgn)
_E("Failed to get display plugin variable.");
- }
backlight_ops = get_var_backlight_ops();
if (!backlight_ops)
_E("Failed to get backlight operator variable.");
+
+ display_add_actor(&display_powerkey_actor);
+ display_add_actor(&display_menukey_actor);
+
+ register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done);
+ register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb);
+
+ input_register_event_callback(check_key_filter, NULL, NULL, NULL);
}
#include "shared/device-notifier.h"
#include "shared/log.h"
#include "shared/event.h"
-#include "input/input-interface.h"
#include "input-config.h"
#include "input-dbus.h"
+#include "input/input.h"
-#define KEYVALUE_PRESS 1
-#define KEYVALUE_RELEASE 0
+static int input_event_handler_id;
static gboolean level_event_detected(gpointer data)
{
}
}
-static void input_handler_process_key(int keycode, int keyvalue)
+static void input_handler_process_key(struct timeval time, unsigned short type, unsigned short keycode, unsigned int keyvalue)
{
struct input_config *ic;
+ if (type != EV_KEY)
+ return;
+
_D("Key input: code=%d, value=%d", keycode, keyvalue);
/* acquire tmplock on pressing key */
- if (keyvalue == KEYVALUE_PRESS)
+ if (keyvalue == KEY_PRESSED)
device_notify(DEVICE_NOTIFIER_KEY_PRESS, (void *)(intptr_t) keycode);
/* process all registered event to the keycode */
ic = find_input_config(keycode);
- if (ic && keyvalue == KEYVALUE_PRESS)
+ if (ic && keyvalue == KEY_PRESSED)
start_event_timer(ic);
- else if (ic && keyvalue == KEYVALUE_RELEASE)
+ else if (ic && keyvalue == KEY_RELEASED)
stop_event_timer(ic);
/* release tmplock on releasing key */
- if (keyvalue == KEYVALUE_RELEASE)
+ if (keyvalue == KEY_RELEASED)
device_notify(DEVICE_NOTIFIER_KEY_RELEASE, (void *)(intptr_t) keycode);
}
-static int input_handler_execute(void *data)
+static void input_handler_init(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 0;
-
- ek = libinput_event_get_keyboard_event(e);
- keycode = libinput_event_keyboard_get_key(ek);
- keyvalue = libinput_event_keyboard_get_key_state(ek);
-
- input_handler_process_key(keycode, keyvalue);
-
- return 0;
+ init_input_config();
+ input_register_event_callback(input_handler_process_key, NULL, NULL, &input_event_handler_id);
}
-static struct input_ops input_handler_ops = {
- .input_handler_process_key = input_handler_process_key,
-};
-
-static void input_handler_init(void *data)
+static void input_handler_exit(void *data)
{
- init_input_config();
- *(struct input_ops**)data = &input_handler_ops;
+ input_unregister_event_callback(input_event_handler_id);
}
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, /* initialized by core input module */
+ .exit = input_handler_exit,
};
DEVICE_OPS_REGISTER(&input_handler_device_ops)
}
- if (display_conf.input_support)
- if (CHECK_OPS(keyfilter_ops, init))
- keyfilter_ops->init();
-
set_display_init_direction(display_conf.display_init_direction);
}
}
/* timeout is not needed */
display_state_transition_reset_state_transition_timeout(TIMEOUT_NONE);
- if (CHECK_OPS(keyfilter_ops, exit))
- keyfilter_ops->exit();
-
unregister_kernel_uevent_control(&lcd_uevent_ops);
display_ops_exit(NULL);
#include "power/power-suspend.h"
#include "led/touch-key.h"
#include "display-lock.h"
+#include "input/input.h"
#ifndef KEY_SCREENLOCK
#define KEY_SCREENLOCK 0x98
}
}
-static int check_key(struct input_event *pinput, int fd)
+static int check_key(struct input_event *pinput)
{
int ignore = true;
return ignore;
}
-static int check_key_filter(void *data, int fd)
+static void check_key_filter(struct timeval time, unsigned short type, unsigned short keycode, unsigned int keyvalue)
{
- struct input_event *pinput = data;
+ struct input_event *pinput = &(struct input_event) {
+ .time = time,
+ .type = type,
+ .code = keycode,
+ .value = keyvalue
+ };
int ignore = true;
- static int old_fd, code, value;
+ static int code, value;
assert(pinput);
if (pinput->code == BTN_TOUCH && !current_state_in_on())
break;
if (pinput->code == code && pinput->value == value) {
- _E("Same key(%d, %d) is polled [%d,%d]",
- code, value, old_fd, fd);
+ _E("Same key(%d, %d) is polled", code, value);
}
- old_fd = fd;
code = pinput->code;
value = pinput->value;
update_vital_state(pinput);
- ignore = check_key(pinput, fd);
+ ignore = check_key(pinput);
restore_custom_brightness();
break;
ignore = false;
break;
case EV_ABS:
+ if (touch_event_blocked()
+ && !g_display_plugin.config->touch_wakeup
+ && pinput->value == KEY_BEING_PRESSED)
+ return;
+
update_vital_state(pinput);
if (pinput->value == KEY_PRESSED) {
switch_on_lcd(LCD_ON_BY_TOUCH);
}
if (ignore)
- return 1;
+ return;
- return 0;
+ /* lcd on or update lcd timeout */
+ poll_callback(INPUT_POLL_EVENT, NULL);
}
static int delayed_init_done(void *data)
.caps = DISPLAY_CAPA_LCDON,
};
-static void keyfilter_init(void)
-{
- display_add_actor(&display_powerkey_actor);
- display_add_actor(&display_menukey_actor);
-
- register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done);
- register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb);
-}
-
-static const struct display_keyfilter_ops normal_keyfilter_ops = {
- .init = keyfilter_init,
- .check = check_key_filter,
-};
-
-const struct display_keyfilter_ops *keyfilter_ops = &normal_keyfilter_ops;
-
static void __CONSTRUCTOR__ initialize(void)
{
disp_plgn = get_var_display_plugin();
- if (!disp_plgn) {
+ if (!disp_plgn)
_E("Failed to get display plugin variable.");
- }
backlight_ops = get_var_backlight_ops();
if (!backlight_ops)
_E("Failed to get backlight operator variable.");
+
+ display_add_actor(&display_powerkey_actor);
+ display_add_actor(&display_menukey_actor);
+
+ register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done);
+ register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb);
+
+ input_register_event_callback(check_key_filter, NULL, NULL, NULL);
}
}
- if (display_conf.input_support)
- if (CHECK_OPS(keyfilter_ops, init))
- keyfilter_ops->init();
-
set_display_init_direction(display_conf.display_init_direction);
}
}
/* timeout is not needed */
display_state_transition_reset_state_transition_timeout(TIMEOUT_NONE);
- if (CHECK_OPS(keyfilter_ops, exit))
- keyfilter_ops->exit();
-
unregister_kernel_uevent_control(&lcd_uevent_ops);
display_ops_exit(NULL);
#include "power/power-suspend.h"
#include "led/touch-key.h"
#include "display-lock.h"
+#include "input/input.h"
#ifndef KEY_SCREENLOCK
#define KEY_SCREENLOCK 0x98
}
}
-static int check_key(struct input_event *pinput, int fd)
+static int check_key(struct input_event *pinput)
{
int ignore = true;
return ignore;
}
-static int check_key_filter(void *data, int fd)
+static void check_key_filter(struct timeval time, unsigned short type, unsigned short keycode, unsigned int keyvalue)
{
- struct input_event *pinput = data;
+ struct input_event *pinput = &(struct input_event) {
+ .time = time,
+ .type = type,
+ .code = keycode,
+ .value = keyvalue
+ };
int ignore = true;
- static int old_fd, code, value;
+ static int code, value;
assert(pinput);
if (pinput->code == BTN_TOUCH && !current_state_in_on())
break;
if (pinput->code == code && pinput->value == value) {
- _E("Same key(%d, %d) is polled [%d,%d]",
- code, value, old_fd, fd);
+ _E("Same key(%d, %d) is polled", code, value);
}
- old_fd = fd;
code = pinput->code;
value = pinput->value;
update_vital_state(pinput);
- ignore = check_key(pinput, fd);
+ ignore = check_key(pinput);
restore_custom_brightness();
break;
ignore = false;
break;
case EV_ABS:
+ if (touch_event_blocked()
+ && !g_display_plugin.config->touch_wakeup
+ && pinput->value == KEY_BEING_PRESSED)
+ return;
+
update_vital_state(pinput);
if (pinput->value == KEY_PRESSED) {
switch_on_lcd(LCD_ON_BY_TOUCH);
}
if (ignore)
- return 1;
+ return;
- return 0;
+ /* lcd on or update lcd timeout */
+ poll_callback(INPUT_POLL_EVENT, NULL);
}
static int delayed_init_done(void *data)
.caps = DISPLAY_CAPA_LCDON,
};
-static void keyfilter_init(void)
-{
- display_add_actor(&display_powerkey_actor);
- display_add_actor(&display_menukey_actor);
-
- register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done);
- register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb);
-}
-
-static const struct display_keyfilter_ops normal_keyfilter_ops = {
- .init = keyfilter_init,
- .check = check_key_filter,
-};
-
-const struct display_keyfilter_ops *keyfilter_ops = &normal_keyfilter_ops;
-
static void __CONSTRUCTOR__ initialize(void)
{
disp_plgn = get_var_display_plugin();
- if (!disp_plgn) {
+ if (!disp_plgn)
_E("Failed to get display plugin variable.");
- }
backlight_ops = get_var_backlight_ops();
if (!backlight_ops)
_E("Failed to get backlight operator variable.");
+
+ display_add_actor(&display_powerkey_actor);
+ display_add_actor(&display_menukey_actor);
+
+ register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done);
+ register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb);
+
+ input_register_event_callback(check_key_filter, NULL, NULL, NULL);
}
}
- if (display_conf.input_support)
- if (CHECK_OPS(keyfilter_ops, init))
- keyfilter_ops->init();
-
set_display_init_direction(display_conf.display_init_direction);
}
}
/* timeout is not needed */
display_state_transition_reset_state_transition_timeout(TIMEOUT_NONE);
- if (CHECK_OPS(keyfilter_ops, exit))
- keyfilter_ops->exit();
-
unregister_kernel_uevent_control(&lcd_uevent_ops);
unregister_kernel_uevent_control(&sec_dsim_uevent_ops);
#include "power/power-off.h"
#include "power/power-suspend.h"
#include "display-lock.h"
+#include "input/input.h"
#ifndef KEY_SCREENLOCK
#define KEY_SCREENLOCK 0x98
}
}
-static int check_key(struct input_event *pinput, int fd)
+static int check_key(struct input_event *pinput)
{
int ignore = true;
return ignore;
}
-static int check_key_filter(void *data, int fd)
+static void check_key_filter(struct timeval time, unsigned short type, unsigned short keycode, unsigned int keyvalue)
{
- struct input_event *pinput = data;
+ struct input_event *pinput = &(struct input_event) {
+ .time = time,
+ .type = type,
+ .code = keycode,
+ .value = keyvalue
+ };
int ignore = true;
- static int old_fd, code, value;
+ static int code, value;
assert(pinput);
if (pinput->code == BTN_TOUCH && !current_state_in_on())
break;
if (pinput->code == code && pinput->value == value) {
- _E("Same key(%d, %d) is polled [%d,%d]",
- code, value, old_fd, fd);
+ _E("Same key(%d, %d) is polled", code, value);
}
- old_fd = fd;
code = pinput->code;
value = pinput->value;
update_vital_state(pinput);
- ignore = check_key(pinput, fd);
+ ignore = check_key(pinput);
restore_custom_brightness();
break;
ignore = false;
break;
case EV_ABS:
+ if (touch_event_blocked() && !ambient_get_state()
+ && !g_display_plugin.config->touch_wakeup
+ && pinput->value == KEY_BEING_PRESSED)
+ return;
+
update_vital_state(pinput);
if (pinput->value == KEY_PRESSED) {
switch_on_lcd(LCD_ON_BY_TOUCH);
}
if (ignore)
- return 1;
+ return;
- return 0;
+ /* lcd on or update lcd timeout */
+ poll_callback(INPUT_POLL_EVENT, NULL);
}
static int delayed_init_done(void *data)
.caps = DISPLAY_CAPA_LCDON,
};
-static void keyfilter_init(void)
-{
- display_add_actor(&display_powerkey_actor);
- display_add_actor(&display_menukey_actor);
-
- register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done);
- register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb);
-}
-
-static const struct display_keyfilter_ops normal_keyfilter_ops = {
- .init = keyfilter_init,
- .check = check_key_filter,
-};
-
-const struct display_keyfilter_ops *keyfilter_ops = &normal_keyfilter_ops;
-
static void __CONSTRUCTOR__ initialize(void)
{
disp_plgn = get_var_display_plugin();
backlight_ops = get_var_backlight_ops();
if (!backlight_ops)
_E("Failed to get backlight operator variable.");
+
+ display_add_actor(&display_powerkey_actor);
+ display_add_actor(&display_menukey_actor);
+
+ register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done);
+ register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb);
+
+ input_register_event_callback(check_key_filter, NULL, NULL, NULL);
}
extern struct display_function_info display_info;
-struct display_keyfilter_ops {
- void (*init)(void);
- void (*exit)(void);
- int (*check)(void *, int);
-};
-
-extern const struct display_keyfilter_ops *keyfilter_ops;
-
typedef struct {
pid_t pid;
unsigned int cond;
+++ /dev/null
-/*
- * deviced
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <stdio.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <linux/input.h>
-#include <libinput.h>
-
-#include "util.h"
-#include "core.h"
-#include "poll.h"
-#include "ambient-mode.h"
-#include "display-plugin.h"
-
-#define SEAT_NAME "seat0"
-
-static void process_input(struct libinput_event *ev)
-{
- static const struct device_ops *display_device_ops;
- struct input_event input;
- struct libinput *li;
- struct libinput_event_keyboard *k;
- unsigned int time;
- int fd = 0;
- if(!g_display_plugin.config) {
- _E("Failed to get display configuration variable.");
- return;
- }
-
- if (!display_device_ops) {
- display_device_ops = find_device("display");
- if (check_default(display_device_ops))
- return;
- }
-
- /* do not operate when display stops */
- if (device_get_status(display_device_ops)
- != DEVICE_OPS_STATUS_START) {
- _E("display status is stop");
- return;
- }
-
- switch (libinput_event_get_type(ev)) {
- case LIBINPUT_EVENT_KEYBOARD_KEY:
- k = libinput_event_get_keyboard_event(ev);
- time = libinput_event_keyboard_get_time(k);
- li = libinput_event_get_context(ev);
-
- input.time.tv_sec = MSEC_TO_SEC(time);
- input.time.tv_usec = MSEC_TO_USEC(time % 1000);
- input.type = EV_KEY;
- input.code = libinput_event_keyboard_get_key(k);
- input.value = libinput_event_keyboard_get_key_state(k);
-
- fd = libinput_get_fd(li);
- _D("time %ld.%06ld type %d code %d value %d fd %d",
- input.time.tv_sec, input.time.tv_usec, input.type,
- input.code, input.value, fd);
- break;
- case LIBINPUT_EVENT_POINTER_MOTION:
- case LIBINPUT_EVENT_POINTER_BUTTON:
- input.type = EV_REL;
- break;
- case LIBINPUT_EVENT_TOUCH_DOWN:
- input.type = EV_ABS;
- input.value = KEY_PRESSED;
- break;
- case LIBINPUT_EVENT_TOUCH_UP:
- input.type = EV_ABS;
- input.value = KEY_RELEASED;
- break;
- case LIBINPUT_EVENT_TOUCH_MOTION:
- case LIBINPUT_EVENT_TOUCH_FRAME:
- if (touch_event_blocked() && !ambient_get_state() && !g_display_plugin.config->touch_wakeup)
- return;
- input.type = EV_ABS;
- input.value = KEY_BEING_PRESSED;
- break;
- default:
- return;
- }
-
- if (CHECK_OPS(keyfilter_ops, check) &&
- keyfilter_ops->check(&input, fd) != 0)
- return;
-
- /* lcd on or update lcd timeout */
- poll_callback(INPUT_POLL_EVENT, NULL);
-}
-
-static int input_handler_execute(void *data)
-{
- if (!data)
- return 0;
-
- process_input(data);
-
- return 0;
-}
-
-static void input_handler_init(void *data)
-{
-}
-
-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_handler_device_ops)
INTERNAL_LOCK_OVERCOOL,
};
-#define KEY_RELEASED 0
-#define KEY_PRESSED 1
-#define KEY_BEING_PRESSED 2
-
#define SIGNAL_NAME_LCD_CONTROL "lcdcontol"
#define LCD_NORMAL 0x01 /**< NORMAL state */
#include "shared/common.h"
#include "input.h"
#include "input-dbus.h"
-#include "input-interface.h"
#include "input-device-manager.h"
/* FIXME: input.keyboard feature check should be added and return DEVICE_ERROR_NOT_SUPPORTED */
g_variant_get(param, "(ii)", &keycode, &keyvalue);
- input_handler_process_key(keycode, keyvalue);
+ // temporarily disabled
+ //input_handler_process_key(keycode, keyvalue);
return gdbus_new_g_variant_tuple();
}
return ret;
}
return 0;
-}
\ No newline at end of file
+}
+++ /dev/null
-/*
- * deviced
- *
- * Copyright (c) 2023 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * @file input-interface.h
- * @brief input interface module header
- */
-#ifndef __INPUT_INTERFACE_H__
-#define __INPUT_INTERFACE_H__
-
-struct input_ops {
- void (*input_handler_process_key)(int keycode, int keyvalue);
-};
-
-#endif /* __INPUT_INTERFACE_H__ */
\ No newline at end of file
#include <stdio.h>
+#include <assert.h>
#include <fcntl.h>
#include <stdbool.h>
#include <errno.h>
#include "input.h"
#include "input-dbus.h"
#include "input-parser.h"
-#include "input-interface.h"
#include "input-device-manager.h"
#define SEAT_NAME "seat0"
static struct input_ops *input_plugin_ops;
static guint efd;
-static const struct device_ops *input_handler;
+struct input_event_handler {
+ int id;
+ input_event_callback cb;
+ input_destroy_callback destroy_cb;
+ void *udata;
+};
+
+static GList *input_event_handler_list;
+
+static void invoke_input_event_callback(gpointer data, gpointer udata)
+{
+ struct input_event_handler *h = (struct input_event_handler *) data;
+ struct input_event *event = (struct input_event *) udata;
+
+ assert(h);
+ assert(h->cb);
+ assert(event);
+
+ /**
+ * TODO: At this point, system maybe just woken up for a while due to input interrupt.
+ * How can we guarantee all those callbacks are totally executed without system
+ * falling into suspend again? Autosleep may make system go suspend right after
+ * the key interrupt, that is, in the middle of the below callback execution.
+ */
+ h->cb(event->time, event->type, event->code, event->value);
+}
+
+static int convert_libinput_to_event(struct libinput_event *li_event, struct input_event *event)
+{
+ if (!li_event || !event)
+ return -EINVAL;
+
+ switch (libinput_event_get_type(li_event)) {
+ case LIBINPUT_EVENT_KEYBOARD_KEY:
+ {
+ struct libinput *li = libinput_event_get_context(li_event);
+ struct libinput_event_keyboard *k = libinput_event_get_keyboard_event(li_event);
+ unsigned int time;
+ int fd;
+
+ assert(li);
+ assert(k);
+
+ time = libinput_event_keyboard_get_time(k);
+
+ event->time.tv_sec = (time / 1000);
+ event->time.tv_usec = MSEC_TO_USEC(time % 1000);
+ event->type = EV_KEY;
+ event->code = libinput_event_keyboard_get_key(k);
+ event->value = libinput_event_keyboard_get_key_state(k);
+
+ fd = libinput_get_fd(li);
+ _D("time %ld.%06ld type %d code %d value %d fd %d",
+ event->time.tv_sec, event->time.tv_usec, event->type,
+ event->code, event->value, fd);
+ return 0;
+ }
+ case LIBINPUT_EVENT_POINTER_MOTION:
+ case LIBINPUT_EVENT_POINTER_BUTTON:
+ event->type = EV_REL;
+ return 0;
+ case LIBINPUT_EVENT_TOUCH_DOWN:
+ event->type = EV_ABS;
+ event->value = KEY_PRESSED;
+ return 0;
+ case LIBINPUT_EVENT_TOUCH_UP:
+ event->type = EV_ABS;
+ event->value = KEY_RELEASED;
+ return 0;
+ case LIBINPUT_EVENT_TOUCH_MOTION:
+ case LIBINPUT_EVENT_TOUCH_FRAME:
+ event->type = EV_ABS;
+ event->value = KEY_BEING_PRESSED;
+ return 0;
+ default:
+ return -EINVAL;
+ }
+
+ // unreachable
+ return -EINVAL;
+}
static gboolean input_callback(gint fd, GIOCondition cond, void *data)
{
- struct libinput_event *ev;
- struct libinput *input = (struct libinput *) data;
+ struct libinput *li = (struct libinput *) data;
+ struct libinput_event *li_event = NULL;
- if (!input_handler)
- return G_SOURCE_REMOVE;
+ if (!input_event_handler_list)
+ return G_SOURCE_CONTINUE;
- if (!input)
+ if (!li)
return G_SOURCE_CONTINUE;
- libinput_dispatch(input);
+ libinput_dispatch(li);
- while ((ev = libinput_get_event(input))) {
- input_handler->execute(ev);
- libinput_event_destroy(ev);
- libinput_dispatch(input);
+ while ((li_event = libinput_get_event(li))) {
+ struct input_event event = { 0 , };
+
+ if (convert_libinput_to_event(li_event, &event) == 0)
+ g_list_foreach(input_event_handler_list, invoke_input_event_callback, &event);
+
+ libinput_event_destroy(li_event);
+ libinput_dispatch(li);
}
return G_SOURCE_CONTINUE;
.close_restricted = close_restricted,
};
-void input_handler_process_key(int keycode, int keyvalue)
+static int alloc_unique_id(void)
{
- if (input_plugin_ops && input_plugin_ops->input_handler_process_key)
- input_plugin_ops->input_handler_process_key(keycode, keyvalue);
+ static int id = 0;
+
+ return ++id;
}
-static void input_init(void *data)
+int input_register_event_callback(input_event_callback cb, input_destroy_callback destroy_cb, void *udata, int *cb_id)
{
- int ret;
- int fd;
+ struct input_event_handler *h = NULL;
+
+ if (!cb)
+ return -EINVAL;
+
+ h = calloc(1, sizeof(struct input_event_handler));
+ if (!h)
+ return -ENOMEM;
- /* load plugin input handler */
- input_handler = find_device("input-handler");
- if (check_default(input_handler) || input_handler->execute == NULL) {
- input_handler = NULL;
+ *h = (struct input_event_handler) {
+ .id = alloc_unique_id(),
+ .cb = cb,
+ .destroy_cb = destroy_cb,
+ .udata = udata,
+ };
+
+ input_event_handler_list = g_list_append(input_event_handler_list, h);
+
+ if (cb_id)
+ *cb_id = h->id;
+
+ return 0;
+}
+
+static int find_handler_by_id(gconstpointer data, gconstpointer udata)
+{
+ struct input_event_handler *h = (struct input_event_handler *) data;
+ int id = *(int *) udata;
+
+ if (h->id == id)
+ return 0;
+
+ return -1;
+}
+
+void input_unregister_event_callback(int cb_id)
+{
+ struct input_event_handler *h = NULL;
+ GList *l = NULL;
+
+ l = g_list_find_custom(input_event_handler_list, &cb_id, find_handler_by_id);
+ if (!l || !l->data)
return;
- }
- if (input_handler->init)
- input_handler->init(&input_plugin_ops);
+ input_event_handler_list = g_list_remove_link(input_event_handler_list, l);
+ h = l->data;
+
+ if (h->destroy_cb)
+ h->destroy_cb(h->udata);
+
+ free(h);
+ g_list_free(l);
+}
+
+static void input_init(void *data)
+{
+ int ret;
+ int fd;
if (input_plugin_ops == NULL)
_E("Failed to init input_ops");
if (udev)
udev_unref(udev);
- if (input_handler && input_handler->exit)
- input_handler->exit(NULL);
-
- input_handler = NULL;
-
input_devman_exit();
}
#ifndef __INPUT_H__
#define __INPUT_H__
-void input_handler_process_key(int keycode, int keyvalue);
+#include <time.h>
-#endif /* __INPUT_H__ */
\ No newline at end of file
+#define KEY_RELEASED 0
+#define KEY_PRESSED 1
+#define KEY_BEING_PRESSED 2
+
+typedef void (*input_event_callback) (struct timeval, unsigned short type, unsigned short code, unsigned int value);
+typedef void (*input_destroy_callback) (void *udata);
+int input_register_event_callback(input_event_callback cb, input_destroy_callback destroy_cb, void *udata, int *cb_id);
+void input_unregister_event_callback(int cb_id);
+
+#endif /* __INPUT_H__ */