aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2018-11-19 08:58:19 +0100
committerHanspeter Portner <dev@open-music-kontrollers.ch>2018-11-19 08:58:19 +0100
commit61911b8e7a1e6b6c01d9913f43856c23813e3441 (patch)
tree371eb30053485d8b52905c1d5202b08b74270dd4
parentecc325430495dedab27926008f671c8e2b0e2d91 (diff)
downloadd2tk-61911b8e7a1e6b6c01d9913f43856c23813e3441.tar.xz
uinput: migrate fake keyboard into example.
-rw-r--r--VERSION2
-rw-r--r--d2tk/frontend_fbdev.h6
-rw-r--r--example/d2tk_fbdev.c6
-rw-r--r--example/d2tk_pugl.c6
-rw-r--r--example/example.c146
-rw-r--r--example/example.h10
-rw-r--r--meson.build6
-rw-r--r--src/frontend_fbdev.c78
8 files changed, 161 insertions, 99 deletions
diff --git a/VERSION b/VERSION
index 1162c99..759f8fc 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.409
+0.1.411
diff --git a/d2tk/frontend_fbdev.h b/d2tk/frontend_fbdev.h
index d4829ea..af55f0a 100644
--- a/d2tk/frontend_fbdev.h
+++ b/d2tk/frontend_fbdev.h
@@ -53,12 +53,6 @@ d2tk_fbdev_run(d2tk_fbdev_t *fbdev, const sig_atomic_t *done);
D2TK_API d2tk_base_t *
d2tk_fbdev_get_base(d2tk_fbdev_t *fbdev);
-D2TK_API void
-d2tk_fbdev_fake_key_down(d2tk_fbdev_t *fbdev, uint32_t keycode);
-
-D2TK_API void
-d2tk_fbdev_fake_key_up(d2tk_fbdev_t *fbdev, uint32_t keycode);
-
#ifdef __cplusplus
}
#endif
diff --git a/example/d2tk_fbdev.c b/example/d2tk_fbdev.c
index e546719..9fec456 100644
--- a/example/d2tk_fbdev.c
+++ b/example/d2tk_fbdev.c
@@ -50,7 +50,7 @@ _expose(void *data, d2tk_coord_t w, d2tk_coord_t h)
d2tk_fbdev_t *fbdev = app->fbdev;
d2tk_base_t *base = d2tk_fbdev_get_base(fbdev);
- d2tk_example(base, w, h);
+ d2tk_example_run(base, w, h);
return EXIT_SUCCESS;
}
@@ -200,10 +200,14 @@ main(int argc, char **argv)
_find_by_format_foreach("/sys/class/vtconsole", "vtcon%"SCNu32, &num,
_unbind);
+ d2tk_example_init();
+
d2tk_fbdev_run(app.fbdev, &done);
d2tk_fbdev_free(app.fbdev);
+ d2tk_example_deinit();
+
_find_by_format_foreach("/sys/class/vtconsole", "vtcon%"SCNu32, &num,
_bind);
diff --git a/example/d2tk_pugl.c b/example/d2tk_pugl.c
index b0f3d15..f9e457b 100644
--- a/example/d2tk_pugl.c
+++ b/example/d2tk_pugl.c
@@ -45,7 +45,7 @@ _expose(void *data, d2tk_coord_t w, d2tk_coord_t h)
d2tk_pugl_t *dpugl = app->dpugl;
d2tk_base_t *base = d2tk_pugl_get_base(dpugl);
- d2tk_example(base, w, h);
+ d2tk_example_run(base, w, h);
return EXIT_SUCCESS;
}
@@ -104,10 +104,14 @@ main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
app.dpugl = d2tk_pugl_new(&config, NULL);
if(app.dpugl)
{
+ d2tk_example_init();
+
d2tk_pugl_run(app.dpugl, &done);
d2tk_pugl_free(app.dpugl);
+ d2tk_example_deinit();
+
return EXIT_SUCCESS;
}
diff --git a/example/example.c b/example/example.c
index 2e8c551..aa25cdd 100644
--- a/example/example.c
+++ b/example/example.c
@@ -22,6 +22,23 @@
#include <d2tk/frontend_pugl.h>
#include "example/example.h"
+#if !defined(_WIN32) && !defined(__APPLE__)
+# include <libevdev/libevdev.h>
+# include <libevdev/libevdev-uinput.h>
+
+typedef struct _fake_t fake_t;
+
+struct _fake_t {
+ struct libevdev *dev;
+ struct libevdev_uinput *uidev;
+};
+
+static fake_t fake = {
+ .dev = NULL,
+ .uidev = NULL
+};
+#endif
+
typedef union _val_t val_t;
union _val_t {
@@ -39,17 +56,19 @@ typedef enum _bar_t {
BAR_SCROLL,
BAR_PANE,
BAR_FLOWMATRIX,
+ BAR_KEYBOARD,
BAR_MAX
} bar_t;
static bar_t bar = BAR_MIX;
static const char *bar_lbl [BAR_MAX] = {
- [BAR_MIX] = "Mix of many",
- [BAR_SEQ] = "Sequencer",
- [BAR_SCROLL] = "Scrollbar",
- [BAR_PANE] = "Pane",
- [BAR_FLOWMATRIX] = "Flowmatrix"
+ [BAR_MIX] = "Mix of many",
+ [BAR_SEQ] = "Sequencer",
+ [BAR_SCROLL] = "Scrollbar",
+ [BAR_PANE] = "Pane",
+ [BAR_FLOWMATRIX] = "Flowmatrix",
+ [BAR_KEYBOARD] = "Keyboard"
};
static inline void
@@ -365,8 +384,117 @@ _render_c_flowmatrix(d2tk_base_t *base, const d2tk_rect_t *rect)
#undef N
}
-void
-d2tk_example(d2tk_base_t *base, d2tk_coord_t w, d2tk_coord_t h)
+static void
+_fake_event(unsigned type, unsigned code, int value)
+{
+#if !defined(_WIN32) && !defined(__APPLE__)
+ libevdev_uinput_write_event(fake.uidev, type, code, value);
+#endif
+}
+
+static void
+_fake_key_down(unsigned keycode)
+{
+#if !defined(_WIN32) && !defined(__APPLE__)
+ _fake_event(EV_KEY, keycode, 1);
+ _fake_event(EV_SYN, SYN_REPORT, 0);
+#endif
+}
+
+static void
+_fake_key_up(unsigned keycode)
+{
+#if !defined(_WIN32) && !defined(__APPLE__)
+ _fake_event(EV_KEY, keycode, 0);
+ _fake_event(EV_SYN, SYN_REPORT, 0);
+#endif
+}
+
+static inline void
+_render_c_keyboard(d2tk_base_t *base, const d2tk_rect_t *rect)
+{
+ //FIXME
+}
+
+D2TK_API int
+d2tk_example_init(void)
+{
+#if !defined(_WIN32) && !defined(__APPLE__)
+ fake.dev = libevdev_new();
+ if(!fake.dev)
+ {
+ fprintf(stderr, "Error: libevdev_new\n");
+ return EXIT_FAILURE;;
+ }
+ libevdev_set_name(fake.dev, "Fake keyboard");
+ libevdev_enable_event_type(fake.dev, EV_SYN);
+ libevdev_enable_event_code(fake.dev, EV_SYN, SYN_REPORT, NULL);
+ libevdev_enable_event_type(fake.dev, EV_KEY);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_LEFTSHIFT, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_RIGHTSHIFT, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_LEFTCTRL, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_RIGHTCTRL, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_LEFTALT, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_RIGHTALT, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_LEFT, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_RIGHT, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_UP, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_DOWN, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_ENTER, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_KPENTER, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_DELETE, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_BACKSPACE, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_MINUS, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_KPMINUS, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_KPPLUS, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_1, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_KP1, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_2, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_KP2, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_3, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_KP3, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_4, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_KP4, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_5, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_KP5, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_6, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_KP6, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_7, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_KP7, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_8, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_KP8, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_9, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_KP9, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_0, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_KP0, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_Y, NULL);
+ libevdev_enable_event_code(fake.dev, EV_KEY, KEY_Z, NULL);
+ //FIXME support more keycodes
+
+ libevdev_uinput_create_from_device(fake.dev, LIBEVDEV_UINPUT_OPEN_MANAGED,
+ &fake.uidev);
+ if(!fake.uidev)
+ {
+ fprintf(stderr, "Error: libevdev_uinput_create_from_device\n");
+ libevdev_free(fake.dev);
+ return EXIT_FAILURE;
+ }
+#endif
+
+ return EXIT_SUCCESS;
+}
+
+D2TK_API void
+d2tk_example_deinit(void)
+{
+#if !defined(_WIN32) && !defined(__APPLE__)
+ libevdev_uinput_destroy(fake.uidev);
+ libevdev_free(fake.dev);
+#endif
+}
+
+D2TK_API void
+d2tk_example_run(d2tk_base_t *base, d2tk_coord_t w, d2tk_coord_t h)
{
const d2tk_coord_t bw = w / BAR_MAX;
const d2tk_coord_t bh = h / 20;
@@ -409,6 +537,10 @@ d2tk_example(d2tk_base_t *base, d2tk_coord_t w, d2tk_coord_t h)
{
_render_c_flowmatrix(base, &rect);
} break;
+ case BAR_KEYBOARD:
+ {
+ _render_c_keyboard(base, &rect);
+ } break;
case BAR_MAX:
// fall-through
diff --git a/example/example.h b/example/example.h
index 477b386..e3d5736 100644
--- a/example/example.h
+++ b/example/example.h
@@ -24,8 +24,14 @@
extern "C" {
#endif
-void
-d2tk_example(d2tk_base_t *base, d2tk_coord_t w, d2tk_coord_t h);
+D2TK_API int
+d2tk_example_init(void);
+
+D2TK_API void
+d2tk_example_deinit();
+
+D2TK_API void
+d2tk_example_run(d2tk_base_t *base, d2tk_coord_t w, d2tk_coord_t h);
#ifdef __cplusplus
}
diff --git a/meson.build b/meson.build
index 3335cca..271f793 100644
--- a/meson.build
+++ b/meson.build
@@ -23,7 +23,7 @@ input_dep = dependency('libinput', version : '>=1.12.0',
udev_dep = dependency('libudev', version : '>=239',
static : static_link, required: false)
-deps = [m_dep]
+deps = [m_dep, evdev_dep]
links = []
pugl_inc = include_directories('pugl')
@@ -109,12 +109,12 @@ if pixman_dep.found() and cairo_dep.found() and (host_machine.system() == 'linux
install : true,
install_dir : get_option('bindir'))
- if evdev_dep.found() and input_dep.found() and udev_dep.found()
+ if input_dep.found() and udev_dep.found()
cairo_srcs += join_paths('src', 'frontend_fbdev.c')
d2tk_fbdev = declare_dependency(
include_directories : inc_dir,
- dependencies : [deps, pixman_dep, cairo_dep, evdev_dep, input_dep, udev_dep],
+ dependencies : [deps, pixman_dep, cairo_dep, input_dep, udev_dep],
link_args : links,
sources : cairo_srcs)
diff --git a/src/frontend_fbdev.c b/src/frontend_fbdev.c
index ad56201..cc5c52d 100644
--- a/src/frontend_fbdev.c
+++ b/src/frontend_fbdev.c
@@ -24,7 +24,6 @@
#include <errno.h>
#include <libevdev/libevdev.h>
-#include <libevdev/libevdev-uinput.h>
#include <libudev.h>
#include <libinput.h>
@@ -41,10 +40,6 @@ struct _d2tk_fbdev_t {
struct udev *udev;
struct libinput *li;
struct {
- struct libevdev *dev;
- struct libevdev_uinput *uidev;
- } fake;
- struct {
int fb;
} fd;
uint8_t *data;
@@ -111,8 +106,6 @@ _d2tk_fbdev_destroy(void *data)
fbdev->data = NULL;
close(fbdev->fd.fb);
- libevdev_uinput_destroy(fbdev->fake.uidev);
- libevdev_free(fbdev->fake.dev);
libinput_unref(fbdev->li);
udev_unref(fbdev->udev);
}
@@ -137,63 +130,6 @@ _d2tk_fbdev_create(d2tk_fbdev_t *fbdev, const char *fb_device)
}
libinput_udev_assign_seat(fbdev->li, "seat0");
- fbdev->fake.dev = libevdev_new();
- if(!fbdev->fake.dev)
- {
- fprintf(stderr, "Error: libevdev_new\n");
- goto handle_allocate_error;
- }
- libevdev_set_name(fbdev->fake.dev, "Fake keyboard");
- libevdev_enable_event_type(fbdev->fake.dev, EV_KEY);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_LEFTSHIFT, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_RIGHTSHIFT, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_LEFTCTRL, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_RIGHTCTRL, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_LEFTALT, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_RIGHTALT, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_LEFT, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_RIGHT, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_UP, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_DOWN, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_ENTER, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_KPENTER, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_DELETE, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_BACKSPACE, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_MINUS, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_KPMINUS, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_KPPLUS, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_1, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_KP1, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_2, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_KP2, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_3, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_KP3, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_4, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_KP4, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_5, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_KP5, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_6, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_KP6, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_7, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_KP7, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_8, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_KP8, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_9, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_KP9, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_0, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_KP0, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_Y, NULL);
- libevdev_enable_event_code(fbdev->fake.dev, EV_KEY, KEY_Z, NULL);
- //FIXME support more keycodes
-
- libevdev_uinput_create_from_device(fbdev->fake.dev, LIBEVDEV_UINPUT_OPEN_MANAGED,
- &fbdev->fake.uidev);
- if(!fbdev->fake.uidev)
- {
- fprintf(stderr, "Error: libevdev_uinput_create_from_device\n");
- goto handle_allocate_error;
- }
-
// Open the file for reading and writing
fbdev->fd.fb = open(fb_device, O_RDWR);
if(fbdev->fd.fb == -1) {
@@ -237,8 +173,6 @@ _d2tk_fbdev_create(d2tk_fbdev_t *fbdev, const char *fb_device)
handle_ioctl_error:
close(fbdev->fd.fb);
- libevdev_uinput_destroy(fbdev->fake.uidev);
- libevdev_free(fbdev->fake.dev);
libinput_unref(fbdev->li);
udev_unref(fbdev->udev);
handle_allocate_error:
@@ -801,15 +735,3 @@ d2tk_fbdev_get_base(d2tk_fbdev_t *fbdev)
{
return fbdev->base;
}
-
-D2TK_API void
-d2tk_fbdev_fake_key_down(d2tk_fbdev_t *fbdev, uint32_t keycode)
-{
- libevdev_uinput_write_event(fbdev->fake.uidev, EV_KEY, keycode, 1);
-}
-
-D2TK_API void
-d2tk_fbdev_fake_key_up(d2tk_fbdev_t *fbdev, uint32_t keycode)
-{
- libevdev_uinput_write_event(fbdev->fake.uidev, EV_KEY, keycode, 0);
-}