Commit 999f4a23 authored by onny's avatar onny

code cleanup

parent a6be144e
all:
gcc libinput-bindkeys.c -o libinput-bindkeys -I. -I/usr/include/ -linput -ludev
clean:
rm -rf .libs _libs
test -z "libshared.la" || rm -f libshared.la
rm -f ./so_locations
rm -f libinput-bindkeys
rm -f *.o
rm -f *.lo
rm -rf .libs _libs
test -z "libshared.la" || rm -f libshared.la
rm -f ./so_locations
rm -f event-debug event-gui
rm -f *.o
rm -f *.lo
......@@ -32,6 +32,9 @@
#include <libudev.h>
#include "linux/input.h"
#include <sys/ioctl.h>
#include <config.h>
#include <getopt.h>
#include <stdlib.h>
#include <libinput.h>
......@@ -43,6 +46,269 @@ static const uint32_t screen_height = 100;
struct tools_options options;
static unsigned int stop = 0;
/* START */
enum options {
OPT_DEVICE,
OPT_UDEV,
OPT_HELP,
OPT_VERBOSE,
OPT_TAP_ENABLE,
OPT_TAP_DISABLE,
OPT_NATURAL_SCROLL_ENABLE,
OPT_NATURAL_SCROLL_DISABLE,
OPT_LEFT_HANDED_ENABLE,
OPT_LEFT_HANDED_DISABLE,
OPT_CLICK_METHOD,
};
int
tools_parse_args(int argc, char **argv, struct tools_options *options)
{
while (1) {
int c;
int option_index = 0;
static struct option opts[] = {
{ "device", 1, 0, OPT_DEVICE },
{ "udev", 0, 0, OPT_UDEV },
{ "help", 0, 0, OPT_HELP },
{ "verbose", 0, 0, OPT_VERBOSE },
{ "enable-tap", 0, 0, OPT_TAP_ENABLE },
{ "disable-tap", 0, 0, OPT_TAP_DISABLE },
{ "enable-natural-scrolling", 0, 0, OPT_NATURAL_SCROLL_ENABLE },
{ "disable-natural-scrolling", 0, 0, OPT_NATURAL_SCROLL_DISABLE },
{ "enable-left-handed", 0, 0, OPT_LEFT_HANDED_ENABLE },
{ "disable-left-handed", 0, 0, OPT_LEFT_HANDED_DISABLE },
{ "set-click-method", 1, 0, OPT_CLICK_METHOD },
{ 0, 0, 0, 0}
};
c = getopt_long(argc, argv, "h", opts, &option_index);
if (c == -1)
break;
switch(c) {
case 'h': /* --help */
case OPT_HELP:
tools_usage();
exit(0);
case OPT_DEVICE: /* --device */
options->backend = BACKEND_DEVICE;
if (!optarg) {
tools_usage();
return 1;
}
options->device = optarg;
break;
case OPT_UDEV: /* --udev */
options->backend = BACKEND_UDEV;
if (optarg)
options->seat = optarg;
break;
case OPT_VERBOSE: /* --verbose */
options->verbose = 1;
break;
case OPT_TAP_ENABLE:
options->tapping = 1;
break;
case OPT_TAP_DISABLE:
options->tapping = 0;
break;
case OPT_NATURAL_SCROLL_ENABLE:
options->natural_scroll = 1;
break;
case OPT_NATURAL_SCROLL_DISABLE:
options->natural_scroll = 0;
break;
case OPT_LEFT_HANDED_ENABLE:
options->left_handed = 1;
break;
case OPT_LEFT_HANDED_DISABLE:
options->left_handed = 0;
break;
case OPT_CLICK_METHOD:
if (!optarg) {
tools_usage();
return 1;
}
if (strcmp(optarg, "none") == 0) {
options->click_method =
LIBINPUT_CONFIG_CLICK_METHOD_NONE;
} else if (strcmp(optarg, "clickfinger") == 0) {
options->click_method =
LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
} else if (strcmp(optarg, "buttonareas") == 0) {
options->click_method =
LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
} else {
tools_usage();
return 1;
}
break;
default:
tools_usage();
return 1;
}
}
if (optind < argc) {
tools_usage();
return 1;
}
return 0;
}
static void
log_handler(struct libinput *li,
enum libinput_log_priority priority,
const char *format,
va_list args)
{
vprintf(format, args);
}
void
tools_usage()
{
printf("Usage: %s [options] [--udev [<seat>]|--device /dev/input/event0]\n"
"--udev <seat>.... Use udev device discovery (default).\n"
" Specifying a seat ID is optional.\n"
"--device /path/to/device .... open the given device only\n"
"\n"
"Features:\n"
"--enable-tap\n"
"--disable-tap.... enable/disable tapping\n"
"--enable-natural-scrolling\n"
"--disable-natural-scrolling.... enable/disable natural scrolling\n"
"--enable-left-handed\n"
"--disable-left-handed.... enable/disable left-handed button configuration\n"
"--set-click-method=[none|clickfinger|buttonareas] .... set the desired click method\n"
"\n"
"These options apply to all applicable devices, if a feature\n"
"is not explicitly specified it is left at each device's default.\n"
"\n"
"Other options:\n"
"--verbose ....... Print debugging output.\n"
"--help .......... Print this help.\n",
program_invocation_short_name);
}
void
tools_init_options(struct tools_options *options)
{
memset(options, 0, sizeof(*options));
options->tapping = -1;
options->natural_scroll = -1;
options->left_handed = -1;
options->click_method = -1;
options->backend = BACKEND_UDEV;
options->seat = "seat0";
}
static struct libinput *
open_udev(const struct libinput_interface *interface,
void *userdata,
const char *seat,
int verbose)
{
struct libinput *li;
struct udev *udev = udev_new();
if (!udev) {
fprintf(stderr, "Failed to initialize udev\n");
return NULL;
}
li = libinput_udev_create_context(interface, userdata, udev);
if (!li) {
fprintf(stderr, "Failed to initialize context from udev\n");
goto out;
}
if (verbose) {
libinput_log_set_handler(li, log_handler);
libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG);
}
if (libinput_udev_assign_seat(li, seat)) {
fprintf(stderr, "Failed to set seat\n");
libinput_unref(li);
li = NULL;
goto out;
}
out:
udev_unref(udev);
return li;
}
static struct libinput *
open_device(const struct libinput_interface *interface,
void *userdata,
const char *path,
int verbose)
{
struct libinput_device *device;
struct libinput *li;
li = libinput_path_create_context(interface, userdata);
if (!li) {
fprintf(stderr, "Failed to initialize context from %s\n", path);
return NULL;
}
if (verbose) {
libinput_log_set_handler(li, log_handler);
libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG);
}
device = libinput_path_add_device(li, path);
if (!device) {
fprintf(stderr, "Failed to initialized device %s\n", path);
libinput_unref(li);
li = NULL;
}
return li;
}
struct libinput *
tools_open_backend(struct tools_options *options,
void *userdata,
const struct libinput_interface *interface)
{
struct libinput *li = NULL;
if (options->backend == BACKEND_UDEV) {
li = open_udev(interface, userdata, options->seat, options->verbose);
} else if (options->backend == BACKEND_DEVICE) {
li = open_device(interface, userdata, options->device, options->verbose);
} else
abort();
return li;
}
void
tools_device_apply_config(struct libinput_device *device,
struct tools_options *options)
{
if (options->tapping != -1)
libinput_device_config_tap_set_enabled(device, options->tapping);
if (options->natural_scroll != -1)
libinput_device_config_scroll_set_natural_scroll_enabled(device,
options->natural_scroll);
if (options->left_handed != -1)
libinput_device_config_left_handed_set(device, options->left_handed);
if (options->click_method != -1)
libinput_device_config_click_set_method(device, options->click_method);
}
/* END */
static int
open_restricted(const char *path, int flags, void *user_data)
{
......
......@@ -2,7 +2,7 @@
Description=Libinput bindkeys
[Service]
ExecStart=/home/onny/projects/libinput-bindkeys/event-debug
ExecStart=/home/onny/projects/libinput-bindkeys/libinput-bindkeys
[Install]
WantedBy=multi-user.target
{
"folders":
[
{
"follow_symlinks": true,
"path": "."
}
]
}
{
"auto_complete":
{
"selected_items":
[
[
"error",
"error_message"
],
[
"ebay",
"ebaykleinanzeigen"
],
[
"pub",
"published_parsed"
],
[
"ard",
"ardmediathek_getmedia"
]
]
},
"buffers":
[
],
"build_system": "Packages/Python/Python.sublime-build",
"command_palette":
{
"height": 72.0,
"selected_items":
[
[
"package inst",
"Package Control: Install Package"
],
[
"git add",
"Git: Quick Add"
],
[
"git push",
"Git: Push"
],
[
"git commi",
"Git: Commit"
],
[
"git commit",
"Git: Amend Commit"
],
[
"git ini",
"Git: Init"
],
[
"Package Control: Install Package",
"Package Control: Install Package"
]
],
"width": 449.0
},
"console":
{
"height": 243.0,
"history":
[
]
},
"distraction_free":
{
"menu_visible": true,
"show_minimap": false,
"show_open_files": false,
"show_tabs": false,
"side_bar_visible": false,
"status_bar_visible": false
},
"expanded_folders":
[
"/home/onny/projects/libinput-bindkeys"
],
"file_history":
[
"/home/onny/projects/py-feeds/feeds.py",
"/var/www/feeds/testapp.py",
"/var/www/feeds/test.py",
"/var/www/feeds/test_working.py",
"/var/www/feeds/plugins/owncloudapps.py",
"/var/www/feeds/plugins/kitmarkt.py",
"/var/www/feeds/plugins/ardmediathek.py",
"/var/www/feeds/plugins/quoka_test.py",
"/var/www/feeds/plugins/studentenwerk.py",
"/var/www/feeds/plugins/ebaykleinanzeigen.py",
"/var/www/feeds/feeds.py",
"/var/www/feeds/plugins/artemediathek.py",
"/var/www/feeds/plugins/feeds.py",
"/var/www/feeds/ebaykleinanzeigen/ebaykleinanzeigen.py",
"/var/www/feeds/studentenwerk/studentenwerk.py",
"/var/www/feeds/owncloud-apps/owncloud-apps.py",
"/var/www/feeds/kitmarkt/kitmarkt.py",
"/var/www/feeds/ardmediathek/ardmediathek.py",
"/var/www/feeds/owncloud-apps/.owncloud-apps.py.swp",
"/var/www/feeds/ardmediathek/.ardmediathek.py.swp",
"/var/www/feeds/zapp/zapp.py",
"/home/onny/projects/py-pkgcheck/pkgcheck-main.py",
"/home/onny/projects/django-test/tango_with_django_project/templates/rango/about.html",
"/home/onny/projects/django-test/tango_with_django_project/static/test.txt",
"/home/onny/projects/django-test/tango_with_django_project/templates/rango/index.html",
"/home/onny/projects/django-test/tango_with_django_project/rango/admin.py",
"/home/onny/projects/django-test/tango_with_django_project/rango/tests.py"
],
"find":
{
"height": 23.0
},
"find_in_files":
{
"height": 0.0,
"where_history":
[
]
},
"find_state":
{
"case_sensitive": false,
"find_history":
[
"ardmediathek_media",
"ardmediathek",
"()\n",
"5",
"print",
"re.",
"re",
"count",
"image",
"uri",
"maxent",
"minPrice=",
"app",
"request",
"os",
"app",
" \n",
"datetime",
"datetim",
"sys",
"print",
"description",
"os",
"id",
"publish",
"search",
"STATIC",
"template"
],
"highlight": true,
"in_selection": false,
"preserve_case": false,
"regex": false,
"replace_history":
[
],
"reverse": false,
"show_context": true,
"use_buffer2": true,
"whole_word": false,
"wrap": true
},
"groups":
[
{
"sheets":
[
]
}
],
"incremental_find":
{
"height": 23.0
},
"input":
{
"height": 31.0
},
"layout":
{
"cells":
[
[
0,
0,
1,
1
]
],
"cols":
[
0.0,
1.0
],
"rows":
[
0.0,
1.0
]
},
"menu_visible": true,
"output.exec":
{
"height": 252.0
},
"output.find_results":
{
"height": 0.0
},
"output.git-commit":
{
"height": 100.0
},
"output.git-push":
{
"height": 100.0
},
"project": "libinput-bindkeys.sublime-project",
"replace":
{
"height": 42.0
},
"save_all_on_build": true,
"select_file":
{
"height": 0.0,
"selected_items":
[
],
"width": 0.0
},
"select_project":
{
"height": 500.0,
"selected_items":
[
],
"width": 380.0
},
"select_symbol":
{
"height": 0.0,
"selected_items":
[
],
"width": 0.0
},
"selected_group": 0,
"settings":
{
},
"show_minimap": false,
"show_open_files": false,
"show_tabs": true,
"side_bar_visible": true,
"side_bar_width": 138.0,
"status_bar_visible": true,
"template_settings":
{
}
}
libtool --tag=CC --mode=compile gcc -std=gnu99 -DHAVE_CONFIG_H -I. -I/usr/include -D_FORTIFY_SOURCE=2 -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong --param=ssp-buffer-size=4 -MT shared.lo -MD -MP -MF .deps/shared.Tpo -c -o shared.lo shared.c
mv -f .deps/shared.Tpo .deps/shared.Plo
libtool --tag=CC --mode=link gcc -std=gnu99 -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong --param=ssp-buffer-size=4 -Wl,-O1,--sort-common,--as-needed,-z,relro -o libshared.la shared.lo -lrt -lm
gcc -DHAVE_CONFIG_H -I. -I/usr/include -D_FORTIFY_SOURCE=2 -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong --param=ssp-buffer-size=4 -MT event_debug-event-debug.o -MD -MP -MF .deps/event_debug-event-debug.Tpo -c -o event_debug-event-debug.o `test -f 'event-debug.c' || echo './'`event-debug.c
mv -f .deps/event_debug-event-debug.Tpo .deps/event_debug-event-debug.Po
rm -f event-debug
libtool --tag=CC --mode=link gcc -std=gnu99 -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong --param=ssp-buffer-size=4 -no-install -Wl,-O1,--sort-common,--as-needed,-z,relro -o event-debug event_debug-event-debug.o libshared.la -linput -ludev -lrt -lm
/*
* Copyright © 2014 Red Hat, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
* that the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of the copyright holders not be used in
* advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. The copyright holders make
* no representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#define _GNU_SOURCE
#include <config.h>
#include <errno.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libudev.h>
#include "shared.h"
enum options {
OPT_DEVICE,
OPT_UDEV,
OPT_HELP,
OPT_VERBOSE,
OPT_TAP_ENABLE,
OPT_TAP_DISABLE,
OPT_NATURAL_SCROLL_ENABLE,
OPT_NATURAL_SCROLL_DISABLE,
OPT_LEFT_HANDED_ENABLE,
OPT_LEFT_HANDED_DISABLE,
OPT_CLICK_METHOD,
};
static void
log_handler(struct libinput *li,
enum libinput_log_priority priority,
const char *format,
va_list args)
{
vprintf(format, args);
}
void
tools_usage()
{
printf("Usage: %s [options] [--udev [<seat>]|--device /dev/input/event0]\n"
"--udev <seat>.... Use udev device discovery (default).\n"
" Specifying a seat ID is optional.\n"
"--device /path/to/device .... open the given device only\n"
"\n"
"Features:\n"
"--enable-tap\n"
"--disable-tap.... enable/disable tapping\n"
"--enable-natural-scrolling\n"
"--disable-natural-scrolling.... enable/disable natural scrolling\n"
"--enable-left-handed\n"
"--disable-left-handed.... enable/disable left-handed button configuration\n"
"--set-click-method=[none|clickfinger|buttonareas] .... set the desired click method\n"
"\n"
"These options apply to all applicable devices, if a feature\n"
"is not explicitly specified it is left at each device's default.\n"
"\n"
"Other options:\n"
"--verbose ....... Print debugging output.\n"
"--help .......... Print this help.\n",
program_invocation_short_name);
}
void
tools_init_options(struct tools_options *options)
{
memset(options, 0, sizeof(*options));
options->tapping = -1;
options->natural_scroll = -1;
options->left_handed = -1;
options->click_method = -1;
options->backend = BACKEND_UDEV;
options->seat = "seat0";
}
int
tools_parse_args(int argc, char **argv, struct tools_options *options)
{
while (1) {
int c;
int option_index = 0;
static struct option opts[] = {
{ "device", 1, 0, OPT_DEVICE },
{ "udev", 0, 0, OPT_UDEV },
{ "help", 0, 0, OPT_HELP },
{ "verbose", 0, 0, OPT_VERBOSE },
{ "enable-tap", 0, 0, OPT_TAP_ENABLE },
{ "disable-tap", 0, 0, OPT_TAP_DISABLE },
{ "enable-natural-scrolling", 0, 0, OPT_NATURAL_SCROLL_ENABLE },
{ "disable-natural-scrolling", 0, 0, OPT_NATURAL_SCROLL_DISABLE },
{ "enable-left-handed", 0, 0, OPT_LEFT_HANDED_ENABLE },
{ "disable-left-handed", 0, 0, OPT_LEFT_HANDED_DISABLE },
{ "set-click-method", 1, 0, OPT_CLICK_METHOD },
{ 0, 0, 0, 0}
};
c = getopt_long(argc, argv, "h", opts, &option_index);
if (c == -1)
break;
switch(c) {
case 'h': /* --help */
case OPT_HELP:
tools_usage();
exit(0);
case OPT_DEVICE: /* --device */
options->backend = BACKEND_DEVICE;
if (!optarg) {
tools_usage();
return 1;
}
options->device = optarg;
break;
case OPT_UDEV: /* --udev */
options->backend = BACKEND_UDEV;
if (optarg)
options->seat = optarg;
break;
case OPT_VERBOSE: /* --verbose */
options->verbose = 1;
break;
case OPT_TAP_ENABLE:
options->tapping = 1;
break;
case OPT_TAP_DISABLE:
options->tapping = 0;
break;
case OPT_NATURAL_SCROLL_ENABLE:
options->natural_scroll = 1;
break;
case OPT_NATURAL_SCROLL_DISABLE:
options->natural_scroll = 0;
break;
case OPT_LEFT_HANDED_ENABLE:
options->left_handed = 1;
break;
case OPT_LEFT_HANDED_DISABLE:
options->left_handed = 0;
break;
case OPT_CLICK_METHOD:
if (!optarg) {
tools_usage();
return 1;
}
if (strcmp(optarg, "none") == 0) {