1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
/*
* Copyright (C) 2021 Red Hat Inc.
*
* This library 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 of the License, or (at your option) any later version.
*
* This library 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 this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "mdk-keyboard.h"
#include <linux/input-event-codes.h>
#include "mdk-stream.h"
struct _MdkKeyboard
{
MdkDevice parent;
gboolean key_pressed[KEY_CNT];
};
G_DEFINE_FINAL_TYPE (MdkKeyboard, mdk_keyboard, MDK_TYPE_DEVICE)
static void
mdk_keyboard_class_init (MdkKeyboardClass *klass)
{
}
static void
mdk_keyboard_init (MdkKeyboard *keyboard)
{
}
MdkKeyboard *
mdk_keyboard_new (MdkSeat *seat,
struct ei_device *ei_device)
{
return g_object_new (MDK_TYPE_KEYBOARD,
"seat", seat,
"ei-device", ei_device,
NULL);
}
void
mdk_keyboard_release_all (MdkKeyboard *keyboard)
{
int i;
g_debug ("Releasing pressed keyboard keys");
for (i = 0; i < G_N_ELEMENTS (keyboard->key_pressed); i++)
{
if (!keyboard->key_pressed[i])
continue;
mdk_keyboard_notify_key (keyboard, i, 0);
}
}
void
mdk_keyboard_notify_key (MdkKeyboard *keyboard,
int32_t key,
int state)
{
MdkDevice *device = MDK_DEVICE (keyboard);
struct ei_device *ei_device = mdk_device_get_ei_device (device);
if (key > G_N_ELEMENTS (keyboard->key_pressed))
{
g_warning ("Unknown key code 0x%x, ignoring", key);
return;
}
if (state)
{
g_return_if_fail (!keyboard->key_pressed[key]);
keyboard->key_pressed[key] = TRUE;
}
else
{
if (!keyboard->key_pressed[key])
return;
keyboard->key_pressed[key] = FALSE;
}
g_debug ("Emit keyboard key event, key: 0x%x, state: %s",
key, state ? "press" : "release");
ei_device_keyboard_key (ei_device, key, state);
ei_device_frame (ei_device, g_get_monotonic_time ());
}
|