Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.

Commit 0706cad

Browse files
committed
Synced latest upstream code
1 parent ac21b73 commit 0706cad

10 files changed

Lines changed: 108 additions & 22 deletions

File tree

README.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

description-pak

Lines changed: 0 additions & 1 deletion
This file was deleted.

include/libevdevc/libevdevc.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#include <libevdevc/libevdevc_event.h>
1111
#include <libevdevc/libevdevc_mt.h>
1212

13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
1317
#ifndef Success
1418
// from X.h
1519
#define Success 0
@@ -52,6 +56,7 @@ typedef struct EvdevInfo_ EvdevInfo, *EvdevInfoPtr;
5256
struct Evdev_ {
5357
syn_report_callback syn_report;
5458
void* syn_report_udata;
59+
int got_valid_event;
5560

5661
log_callback log;
5762
void* log_udata;
@@ -83,4 +88,8 @@ int EvdevWriteEventToFile(FILE* file, const struct input_event* event);
8388
int EvdevReadInfoFromFile(FILE* file, EvdevInfoPtr info);
8489
int EvdevReadEventFromFile(FILE* file, struct input_event* event);
8590

91+
#ifdef __cplusplus
92+
} // extern "C"
93+
#endif
94+
8695
#endif

include/libevdevc/libevdevc_event.h

100644100755
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#include <libevdevc/libevdevc_log.h>
1212
#include <libevdevc/libevdevc_mt.h>
1313

14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif
1417

1518
/* 1 MiB debug buffer of struct input_event objects */
1619
#define DEBUG_BUF_SIZE 65536
@@ -39,6 +42,8 @@ void Event_Free(EvdevPtr);
3942
void Event_Open(EvdevPtr);
4043
bool Event_Process(EvdevPtr, struct input_event*);
4144
void Event_Dump_Debug_Log(void *);
45+
void Event_Dump_Debug_Log_To(void *, const char*);
46+
void Event_Clear_Debug_Log(void *);
4247

4348
int Event_Get_Left(EvdevPtr);
4449
int Event_Get_Right(EvdevPtr);
@@ -57,9 +62,14 @@ int Event_Get_Slot_Count(EvdevPtr);
5762
int Event_Get_Button_Left(EvdevPtr);
5863
int Event_Get_Button_Middle(EvdevPtr);
5964
int Event_Get_Button_Right(EvdevPtr);
65+
int Event_Get_Button(EvdevPtr, int button);
6066
void Event_Sync_State(EvdevPtr);
6167
const char* Event_To_String(int type, int code);
6268
const char* Event_Type_To_String(int type);
6369
const char* Evdev_Get_Version();
6470

71+
#ifdef __cplusplus
72+
} // extern "C"
73+
#endif
74+
6575
#endif

include/libevdevc/libevdevc_log.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#include <stdlib.h>
1313
#include <string.h>
1414

15+
#ifdef __cplusplus
16+
extern "C" {
17+
#endif
18+
1519
struct Evdev_;
1620
typedef struct Evdev_ *EvdevPtr;
1721

@@ -32,5 +36,8 @@ typedef struct Evdev_ *EvdevPtr;
3236
(evdev)->log((evdev)->log_udata, LOGLEVEL_WARNING, \
3337
"%s():%d: " format, __FUNCTION__, __LINE__, ##__VA_ARGS__)
3438

39+
#ifdef __cplusplus
40+
} // extern "C"
41+
#endif
3542

3643
#endif

include/libevdevc/libevdevc_mt.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
#include <stdint.h>
1212
#include <libevdevc/libevdevc_log.h>
1313

14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif
17+
1418
/*
1519
* From include/linux/input.h
1620
* (as per linux-2.6.git:771d6d85667d68a17c24c452979f8d37cc628082)
@@ -55,4 +59,8 @@ void MT_Slot_Value_Set(MtSlotPtr, int, int);
5559

5660
void MT_Slot_Sync(EvdevPtr, MTSlotInfoPtr);
5761

62+
#ifdef __cplusplus
63+
} // extern "C"
64+
#endif
65+
5866
#endif

include/libevdevc/libevdevc_util.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#ifndef _LIBEVDEV_UTIL_H_
77
#define _LIBEVDEV_UTIL_H_
88

9+
#ifdef __cplusplus
10+
extern "C" {
11+
#endif
12+
913
// Helper for bit operations
1014
#define LONG_BITS (sizeof(long) * 8)
1115
#define NLONGS(x) (((x) + LONG_BITS - 1) / LONG_BITS)
@@ -25,5 +29,8 @@ static inline void AssignBit(unsigned long* array, int bit, int value)
2529
array[bit / LONG_BITS] &= ~mask;
2630
}
2731

32+
#ifdef __cplusplus
33+
} // extern "C"
34+
#endif
2835

2936
#endif

src/libevdevc.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,10 @@ int EvdevRead(EvdevPtr evdev) {
6565

6666
/* Read as many whole struct input_event objects as we can into the
6767
circular buffer */
68-
if (evstate->debug_buf) {
69-
for (i = 0; i < len / sizeof(*ev); i++) {
70-
evstate->debug_buf[evstate->debug_buf_tail] = ev[i];
71-
evstate->debug_buf_tail =
72-
(evstate->debug_buf_tail + 1) % DEBUG_BUF_SIZE;
73-
}
68+
for (i = 0; i < len / sizeof(*ev); i++) {
69+
evstate->debug_buf[evstate->debug_buf_tail] = ev[i];
70+
evstate->debug_buf_tail =
71+
(evstate->debug_buf_tail + 1) % DEBUG_BUF_SIZE;
7472
}
7573

7674
/* kernel always delivers complete events, so len must be sizeof *ev */
@@ -502,9 +500,6 @@ Absinfo_Print(EvdevPtr device, struct input_absinfo* absinfo)
502500
*/
503501
static EvdevClass EvdevProbeClass(EvdevInfoPtr info) {
504502
int bit;
505-
for (bit = 0; bit < BTN_MISC; bit++)
506-
if (TestBit(bit, info->key_bitmask))
507-
return EvdevClassKeyboard;
508503

509504
if (TestBit(REL_X, info->rel_bitmask) &&
510505
TestBit(REL_Y, info->rel_bitmask)) {
@@ -539,6 +534,10 @@ static EvdevClass EvdevProbeClass(EvdevInfoPtr info) {
539534
return EvdevClassTouchscreen;
540535
}
541536

537+
for (bit = 0; bit < BTN_MISC; bit++)
538+
if (TestBit(bit, info->key_bitmask))
539+
return EvdevClassKeyboard;
540+
542541
return EvdevClassUnknown;
543542
}
544543

src/libevdevc_event.c

100644100755
Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ static void Event_Rel(EvdevPtr, struct input_event*);
5353

5454
static void Event_Get_Time(struct timeval*, bool);
5555

56+
static int Event_Is_Valid(struct input_event*);
57+
5658
const char*
5759
Evdev_Get_Version() {
5860
return VCSID;
@@ -180,19 +182,25 @@ Event_Get_Slot_Count(EvdevPtr device)
180182
int
181183
Event_Get_Button_Left(EvdevPtr device)
182184
{
183-
return TestBit(BTN_LEFT, device->key_state_bitmask);
185+
return Event_Get_Button(device, BTN_LEFT);
184186
}
185187

186188
int
187189
Event_Get_Button_Middle(EvdevPtr device)
188190
{
189-
return TestBit(BTN_MIDDLE, device->key_state_bitmask);
191+
return Event_Get_Button(device, BTN_MIDDLE);
190192
}
191193

192194
int
193195
Event_Get_Button_Right(EvdevPtr device)
194196
{
195-
return TestBit(BTN_RIGHT, device->key_state_bitmask);
197+
return Event_Get_Button(device, BTN_RIGHT);
198+
}
199+
200+
int
201+
Event_Get_Button(EvdevPtr device, int button)
202+
{
203+
return TestBit(button, device->key_state_bitmask);
196204
}
197205

198206
#define CASE_RETURN(s) \
@@ -249,6 +257,10 @@ Event_To_String(int type, int code) {
249257
CASE_RETURN(BTN_LEFT);
250258
CASE_RETURN(BTN_RIGHT);
251259
CASE_RETURN(BTN_MIDDLE);
260+
CASE_RETURN(BTN_BACK);
261+
CASE_RETURN(BTN_FORWARD);
262+
CASE_RETURN(BTN_EXTRA);
263+
CASE_RETURN(BTN_SIDE);
252264
CASE_RETURN(BTN_TOUCH);
253265
CASE_RETURN(BTN_TOOL_FINGER);
254266
CASE_RETURN(BTN_TOOL_DOUBLETAP);
@@ -389,9 +401,11 @@ Event_Sync_State(EvdevPtr device)
389401
MT_Slot_Sync(device, &req);
390402
}
391403

392-
/* Get current slot id */
393-
if (EvdevProbeAbsinfo(device, ABS_MT_SLOT) == Success)
404+
/* Get current slot id for multi-touch devices*/
405+
if (TestBit(ABS_MT_SLOT, device->info.abs_bitmask) &&
406+
(EvdevProbeAbsinfo(device, ABS_MT_SLOT) == Success)) {
394407
MT_Slot_Set(device, device->info.absinfo[ABS_MT_SLOT].value);
408+
}
395409

396410
Event_Get_Time(&device->after_sync_time, device->info.is_monotonic);
397411

@@ -453,6 +467,12 @@ bool
453467
Event_Process(EvdevPtr device, struct input_event* ev)
454468
{
455469
Event_Print(device, ev);
470+
if (Event_Is_Valid(ev)) {
471+
if (!(ev->type == EV_SYN && ev->code == SYN_REPORT))
472+
device->got_valid_event = 1;
473+
} else {
474+
return false;
475+
}
456476

457477
switch (ev->type) {
458478
case EV_SYN:
@@ -480,14 +500,19 @@ Event_Process(EvdevPtr device, struct input_event* ev)
480500
* Dump the log of input events to disk
481501
*/
482502
void
483-
Event_Dump_Debug_Log(void* vinfo)
503+
Event_Dump_Debug_Log(void* vinfo) {
504+
Event_Dump_Debug_Log_To(vinfo, "/var/log/xorg/cmt_input_events.dat");
505+
}
506+
507+
void
508+
Event_Dump_Debug_Log_To(void* vinfo, const char* filename)
484509
{
485510
EvdevPtr device = (EvdevPtr) vinfo;
486511
size_t i;
487512
int ret;
488513
EventStatePtr evstate = device->evstate;
489514

490-
FILE* fp = fopen("/var/log/xorg/cmt_input_events.dat", "wb");
515+
FILE* fp = fopen(filename, "wb");
491516
if (!fp) {
492517
LOG_ERROR(device, "fopen() failed for debug log");
493518
return;
@@ -512,6 +537,19 @@ Event_Dump_Debug_Log(void* vinfo)
512537
fclose(fp);
513538
}
514539

540+
/**
541+
* Clear Debug Buffer
542+
*/
543+
void
544+
Event_Clear_Debug_Log(void* vinfo)
545+
{
546+
EvdevPtr device = (EvdevPtr) vinfo;
547+
EventStatePtr evstate = device->evstate;
548+
549+
memset(evstate->debug_buf, 0, sizeof(evstate->debug_buf));
550+
evstate->debug_buf_tail = 0;
551+
}
552+
515553
/**
516554
* Clear EV_REL event state. This function should be called after a EV_SYN
517555
* event is processed because EV_REL event state is not accumulative.
@@ -557,11 +595,13 @@ static void
557595
Event_Syn_Report(EvdevPtr device, struct input_event* ev)
558596
{
559597
EventStatePtr evstate = device->evstate;
560-
device->syn_report(device->syn_report_udata, evstate, &ev->time);
598+
if (device->got_valid_event)
599+
device->syn_report(device->syn_report_udata, evstate, &ev->time);
561600

562601
MT_Print_Slots(device);
563602

564603
Event_Clear_Ev_Rel_State(device);
604+
device->got_valid_event = 0;
565605
}
566606

567607
static void
@@ -656,3 +696,12 @@ Event_Rel(EvdevPtr device, struct input_event* ev)
656696
break;
657697
}
658698
}
699+
700+
static int Event_Is_Valid(struct input_event* ev)
701+
{
702+
/* Key repeats are invalid. They're handled by X anyway */
703+
if (ev->type == EV_KEY &&
704+
ev->value == 2)
705+
return 0;
706+
return 1;
707+
}

src/module.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ install-lib: CC_LIBRARY(src/libevdevc.so.0) CC_LIBRARY(src/libevdevc_hollow.so.0
2121
install -D -m 0755 src/libevdevc_hollow.so.0 \
2222
$(DESTDIR)$(LIBDIR)/libevdevc_hollow.so.0
2323
ln -f -s libevdevc_hollow.so.0 $(DESTDIR)$(LIBDIR)/libevdevc_hollow.so
24+
install -D -m 0644 $(SRC)/libevdevc-cros.pc \
25+
$(DESTDIR)$(LIBDIR)/pkgconfig/libevdevc-cros.pc
2426

2527
setup-lib-in-place:
2628
mkdir -p $(SRC)/in-place || true

0 commit comments

Comments
 (0)