input, xkb: port to new kbd object

This commit ports the XKB handling to the new kbd interface, and makes
the input subsystem use it without any direct knowledge of XKB.

Some code is moved around but there are no functional changes.

Signed-off-by: Ran Benita <ran234@gmail.com>
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
Ran Benita 2012-01-17 23:57:11 +02:00 committed by David Herrmann
parent 7cf93b8930
commit 9b75aa0b9d
5 changed files with 873 additions and 871 deletions

View File

@ -47,10 +47,10 @@ libkmscon_core_la_SOURCES = \
src/eloop.c src/eloop.h \
src/vt.c src/vt.h \
src/input.c src/input.h \
src/input_xkb.c src/input_xkb.h \
external/imKStoUCS.c external\imKStoUCS.h \
src/vte.c src/vte.h \
src/terminal.c src/terminal.h
src/terminal.c src/terminal.h \
src/kbd_xkb.c src/kbd.h \
external/imKStoUCS.c external\imKStoUCS.h
if USE_PANGO
libkmscon_core_la_SOURCES += \

View File

@ -50,7 +50,7 @@
#include "eloop.h"
#include "input.h"
#include "input_xkb.h"
#include "kbd.h"
#include "log.h"
enum input_state {
@ -67,7 +67,7 @@ struct kmscon_input_device {
char *devnode;
struct kmscon_fd *fd;
struct xkb_state xkb_state;
struct kmscon_kbd *kbd;
};
struct kmscon_input {
@ -83,7 +83,7 @@ struct kmscon_input {
struct udev_monitor *monitor;
struct kmscon_fd *monitor_fd;
struct xkb_desc *xkb_desc;
struct kmscon_kbd_desc *desc;
};
static void remove_device(struct kmscon_input *input, const char *node);
@ -91,18 +91,20 @@ static void remove_device(struct kmscon_input *input, const char *node);
static void notify_key(struct kmscon_input_device *device,
uint16_t type, uint16_t code, int32_t value)
{
int ret;
struct kmscon_input_event ev;
bool has_event;
struct kmscon_input *input;
if (type != EV_KEY)
return;
input = device->input;
has_event = kmscon_xkb_process_evdev_key(input->xkb_desc,
&device->xkb_state, value, code, &ev);
ret = kmscon_kbd_process_key(device->kbd, value, code, &ev);
if (has_event)
if (ret && ret != -ENOKEY)
return;
if (ret != -ENOKEY && input->cb)
input->cb(input, &ev, input->data);
}
@ -155,9 +157,8 @@ int kmscon_input_device_wake_up(struct kmscon_input_device *device)
return -errno;
}
/* this rediscovers the xkb state if sth changed during sleep */
kmscon_xkb_reset_state(device->input->xkb_desc, &device->xkb_state,
device->rfd);
/* this rediscovers the keyboard state if sth changed during sleep */
kmscon_kbd_reset(device->kbd, device->rfd);
ret = kmscon_eloop_new_fd(device->input->eloop, &device->fd,
device->rfd, KMSCON_READABLE, device_data_arrived, device);
@ -187,6 +188,7 @@ void kmscon_input_device_sleep(struct kmscon_input_device *device)
static int kmscon_input_device_new(struct kmscon_input_device **out,
struct kmscon_input *input, const char *devnode)
{
int ret;
struct kmscon_input_device *device;
if (!out || !input)
@ -207,6 +209,13 @@ static int kmscon_input_device_new(struct kmscon_input_device **out,
return -ENOMEM;
}
ret = kmscon_kbd_new(&device->kbd, input->desc);
if (ret) {
free(device->devnode);
free(device);
return ret;
}
device->input = input;
device->rfd = -1;
@ -214,13 +223,13 @@ static int kmscon_input_device_new(struct kmscon_input_device **out,
return 0;
}
static void kmscon_input_device_ref(struct kmscon_input_device *device)
{
if (!device)
return;
/* static void kmscon_input_device_ref(struct kmscon_input_device *device) */
/* { */
/* if (!device) */
/* return; */
++device->ref;
}
/* ++device->ref; */
/* } */
static void kmscon_input_device_unref(struct kmscon_input_device *device)
{
@ -231,6 +240,7 @@ static void kmscon_input_device_unref(struct kmscon_input_device *device)
return;
kmscon_input_device_sleep(device);
kmscon_kbd_unref(device->kbd);
log_debug("input: destroying input device %s\n", device->devnode);
free(device->devnode);
free(device);
@ -260,7 +270,7 @@ int kmscon_input_new(struct kmscon_input **out)
variant = getenv("KMSCON_XKB_VARIANT") ?: "";
options = getenv("KMSCON_XKB_OPTIONS") ?: "";
ret = kmscon_xkb_new_desc(layout, variant, options, &input->xkb_desc);
ret = kmscon_kbd_desc_new(&input->desc, layout, variant, options);
if (ret) {
log_warning("input: cannot create xkb description\n");
goto err_free;
@ -303,7 +313,7 @@ err_monitor:
err_udev:
udev_unref(input->udev);
err_xkb:
kmscon_xkb_free_desc(input->xkb_desc);
kmscon_kbd_desc_unref(input->desc);
err_free:
free(input);
return ret;
@ -328,7 +338,7 @@ void kmscon_input_unref(struct kmscon_input *input)
kmscon_input_disconnect_eloop(input);
udev_monitor_unref(input->monitor);
udev_unref(input->udev);
kmscon_xkb_free_desc(input->xkb_desc);
kmscon_kbd_desc_unref(input->desc);
free(input);
log_debug("input: destroying input object\n");
}

View File

@ -77,17 +77,6 @@ struct kmscon_input_event {
typedef void (*kmscon_input_cb) (struct kmscon_input *input,
struct kmscon_input_event *ev, void *data);
/*
* These are the values sent by the kernel in the /value/ field of the
* /input_event/ struct.
* See Documentation/input/event-codes.txt in the kernel tree.
*/
enum kmscon_key_state {
KMSCON_KEY_RELEASED = 0,
KMSCON_KEY_PRESSED = 1,
KMSCON_KEY_REPEATED = 2,
};
int kmscon_input_new(struct kmscon_input **out);
void kmscon_input_ref(struct kmscon_input *input);
void kmscon_input_unref(struct kmscon_input *input);

View File

@ -1,48 +0,0 @@
/*
* kmscon - udev input hotplug and evdev handling
*
* Copyright (c) 2011 Ran Benita <ran234@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef KMSCON_INPUT_XKB_H
#define KMSCON_INPUT_XKB_H
#include <inttypes.h>
#include <X11/extensions/XKBcommon.h>
#include "input.h"
int kmscon_xkb_new_desc(const char *layout, const char *variant,
const char *options,
struct xkb_desc **out);
void kmscon_xkb_free_desc(struct xkb_desc *desc);
void kmscon_xkb_reset_state(struct xkb_desc *desc,
struct xkb_state *state,
int evdev_fd);
bool kmscon_xkb_process_evdev_key(struct xkb_desc *desc,
struct xkb_state *state,
enum kmscon_key_state key_state,
uint16_t code,
struct kmscon_input_event *out);
#endif /* KMSCON_INPUT_XKB_H */

File diff suppressed because it is too large Load Diff