1
0
Fork 0

Import old version using libinput

This commit is contained in:
Reinout Meliesie 2021-02-27 14:39:41 +01:00
parent d55a2342a1
commit 1d8f5a637e
Signed by: zedfrigg
GPG key ID: 3AFCC06481308BC6
3 changed files with 117 additions and 0 deletions

22
CMakeLists.txt Normal file
View file

@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.17)
project(evdev_actions)
set(CMAKE_C_STANDARD 11)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake-modules")
add_executable(evdev_actions main.c)
find_package(Libinput REQUIRED)
if(NOT ${Libinput_FOUND})
message(FATAL_ERROR "libinput not found")
endif()
target_include_directories(evdev_actions PUBLIC ${Libinput_INCLUDE_DIRS})
target_link_libraries(evdev_actions ${Libinput_LIBRARIES})
find_package(udev REQUIRED)
if(NOT ${UDEV_FOUND})
message(FATAL_ERROR "libudev not found")
endif()
target_include_directories(evdev_actions PUBLIC ${UDEV_INCLUDE_DIRS})
target_link_libraries(evdev_actions ${UDEV_LIBRARIES})

1
cmake/cmake-modules Submodule

@ -0,0 +1 @@
Subproject commit 6a748896188fdf3f885820ccd686393ea5215dbf

94
main.c Normal file
View file

@ -0,0 +1,94 @@
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <libinput.h>
#include <libudev.h>
#include <stdio.h>
#include <unistd.h>
static int open_restricted(const char* path, int flags, void* user_data)
{
int fd = open(path, flags);
return fd < 0 ? -errno : fd;
}
static void close_restricted(int fd, void* user_data)
{
close(fd);
}
const static struct libinput_interface interface = {
.open_restricted = open_restricted,
.close_restricted = close_restricted,
};
void handle_device_added(struct libinput_event_device_notify* event)
{
assert(event != NULL);
}
void handle_button_press(struct libinput_event_switch* event)
{
assert(event != NULL);
}
int main(int argc, char* argv[])
{
struct udev* udev_context = udev_new();
struct libinput* libinput_context = libinput_udev_create_context(&interface, NULL, udev_context);
libinput_udev_assign_seat(libinput_context, "seat0");
int libinput_fd = libinput_get_fd(libinput_context);
struct libinput_event* event;
// Setup loop
libinput_dispatch(libinput_context);
while ((event = libinput_get_event(libinput_context)) != NULL) {
printf("Setup event occurred\n");
if (libinput_event_get_type(event) == LIBINPUT_EVENT_DEVICE_ADDED) {
handle_device_added(libinput_event_get_device_notify_event(event));
printf("\tDevice added event\n");
}
else {
printf("\tOther type of event\n");
}
libinput_event_destroy(event);
}
printf("No more setup events\n");
// Main loop
while (1) {
// TODO: use select/poll/epoll to block until fd has new data
// https://daniel.haxx.se/docs/poll-vs-select.html
// https://en.wikipedia.org/wiki/Epoll
// https://github.com/wayland-project/libinput/blob/master/tools/libinput-debug-events.c
// https://wayland.freedesktop.org/libinput/doc/latest/api/
libinput_dispatch(libinput_context);
while ((event = libinput_get_event(libinput_context)) != NULL) {
printf("Event occurred\n");
if (libinput_event_get_type(event) == LIBINPUT_EVENT_SWITCH_TOGGLE) {
handle_button_press(libinput_event_get_switch_event(event));
printf("\tSwitch toggle event\n");
}
else {
printf("\tOther type of event\n");
}
libinput_event_destroy(event);
libinput_dispatch(libinput_context);
}
}
printf("No more events\n");
return EXIT_SUCCESS;
}