summaryrefslogtreecommitdiffstats
path: root/ui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ui.cpp')
-rw-r--r--ui.cpp37
1 files changed, 28 insertions, 9 deletions
diff --git a/ui.cpp b/ui.cpp
index 27ecc2805..042da2eb7 100644
--- a/ui.cpp
+++ b/ui.cpp
@@ -47,7 +47,8 @@ static RecoveryUI* self = NULL;
RecoveryUI::RecoveryUI() :
key_queue_len(0),
- key_last_down(-1) {
+ key_last_down(-1),
+ key_down_time(0) {
pthread_mutex_init(&key_queue_mutex, NULL);
pthread_cond_init(&key_queue_cond, NULL);
self = this;
@@ -111,19 +112,29 @@ int RecoveryUI::input_callback(int fd, short revents, void* data)
// updown == 1 for key down events; 0 for key up events
void RecoveryUI::process_key(int key_code, int updown) {
bool register_key = false;
+ bool long_press = false;
+
+ const long long_threshold = CLOCKS_PER_SEC * 750 / 1000;
pthread_mutex_lock(&key_queue_mutex);
key_pressed[key_code] = updown;
if (updown) {
key_last_down = key_code;
+ key_down_time = clock();
} else {
- if (key_last_down == key_code)
+ if (key_last_down == key_code) {
+ long duration = clock() - key_down_time;
+ if (duration > long_threshold) {
+ long_press = true;
+ }
register_key = true;
+ }
key_last_down = -1;
}
pthread_mutex_unlock(&key_queue_mutex);
if (register_key) {
+ NextCheckKeyIsLong(long_press);
switch (CheckKey(key_code)) {
case RecoveryUI::IGNORE:
break;
@@ -139,18 +150,23 @@ void RecoveryUI::process_key(int key_code, int updown) {
break;
case RecoveryUI::ENQUEUE:
- pthread_mutex_lock(&key_queue_mutex);
- const int queue_max = sizeof(key_queue) / sizeof(key_queue[0]);
- if (key_queue_len < queue_max) {
- key_queue[key_queue_len++] = key_code;
- pthread_cond_signal(&key_queue_cond);
- }
- pthread_mutex_unlock(&key_queue_mutex);
+ EnqueueKey(key_code);
break;
}
}
}
+void RecoveryUI::EnqueueKey(int key_code) {
+ pthread_mutex_lock(&key_queue_mutex);
+ const int queue_max = sizeof(key_queue) / sizeof(key_queue[0]);
+ if (key_queue_len < queue_max) {
+ key_queue[key_queue_len++] = key_code;
+ pthread_cond_signal(&key_queue_cond);
+ }
+ pthread_mutex_unlock(&key_queue_mutex);
+}
+
+
// Reads input events, handles special hot keys, and adds to the key queue.
void* RecoveryUI::input_thread(void *cookie)
{
@@ -227,3 +243,6 @@ void RecoveryUI::FlushKeys() {
RecoveryUI::KeyAction RecoveryUI::CheckKey(int key) {
return RecoveryUI::ENQUEUE;
}
+
+void RecoveryUI::NextCheckKeyIsLong(bool is_long_press) {
+}