add dummy event
This commit is contained in:
parent
21260fbfdf
commit
e2013f94df
5 changed files with 42 additions and 6 deletions
10
src/event.c
10
src/event.c
|
@ -23,6 +23,16 @@ void init_event(event *event, char is_pressed)
|
|||
if (is_pressed) event->infos = 0x80;
|
||||
}
|
||||
|
||||
void dummy_event(event *event)
|
||||
{
|
||||
event->infos |= DUMMY;
|
||||
}
|
||||
|
||||
int is_dummy(event *event)
|
||||
{
|
||||
return (event->infos & DUMMY) == DUMMY;
|
||||
}
|
||||
|
||||
void mouse_event(event *event, mouse_button button)
|
||||
{
|
||||
init_event(event, 0);
|
||||
|
|
15
src/event.h
15
src/event.h
|
@ -1,15 +1,18 @@
|
|||
#ifndef EVENT_USER
|
||||
#define EVENT_USER
|
||||
|
||||
#define DUMMY 0x80
|
||||
|
||||
/*
|
||||
* Structure containing informations about events.
|
||||
*/
|
||||
typedef struct {
|
||||
/*
|
||||
* X00T 00ZZ
|
||||
* XD0T 00ZZ
|
||||
*
|
||||
* Where:
|
||||
* * X = press (1) or release (0)
|
||||
* * D = dummy, ignore this event (1)
|
||||
* * T = keyboard (1) or mouse (0)
|
||||
* * ZZ (only for mouse events) = button
|
||||
* * left (01)
|
||||
|
@ -48,6 +51,16 @@ void reset(event *event);
|
|||
*/
|
||||
void init_event(event *event, char is_pressed);
|
||||
|
||||
/*
|
||||
* Make a dummy event.
|
||||
*/
|
||||
void dummy_event(event *event);
|
||||
|
||||
/*
|
||||
* Check if an event is dummy or not.
|
||||
*/
|
||||
int is_dummy(event *event);
|
||||
|
||||
/*
|
||||
* Init a mouse event and set if the button is pressed or not.
|
||||
* The caller must indicate coordonates.
|
||||
|
|
|
@ -8,12 +8,13 @@
|
|||
#include "event.h"
|
||||
#include "read_events.h"
|
||||
|
||||
args_cancel_thread_read* init_args_read(int fd, event *user_event, Display *display)
|
||||
args_cancel_thread_read* init_args_read(int fd, event *user_event, Display *display, FILE *file)
|
||||
{
|
||||
args_cancel_thread_read *ret = (args_cancel_thread_read *) malloc(sizeof(args_cancel_thread_read));
|
||||
ret->fd = fd;
|
||||
ret->user_event = user_event;
|
||||
ret->display = display;
|
||||
ret->file = file;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -21,11 +22,20 @@ args_cancel_thread_read* init_args_read(int fd, event *user_event, Display *disp
|
|||
void cancel_read_events(args_cancel_thread_read *arg)
|
||||
{
|
||||
int fd = arg->fd;
|
||||
FILE *file = arg->file;
|
||||
|
||||
/* flush the middle button */
|
||||
unsigned char data[3];
|
||||
read(fd, data, sizeof(data));
|
||||
read(fd, data, sizeof(data));
|
||||
|
||||
if (file != NULL)
|
||||
{
|
||||
dummy_event(arg->user_event);
|
||||
fseek(file, -1 * sizeof(event), SEEK_END);
|
||||
write_event(arg->user_event, file);
|
||||
}
|
||||
|
||||
free(arg->user_event);
|
||||
close(fd);
|
||||
XCloseDisplay(arg->display);
|
||||
|
@ -62,7 +72,7 @@ int listen(FILE *file)
|
|||
return -1;
|
||||
}
|
||||
|
||||
pthread_cleanup_push(cancel_read_events, init_args_read(fd, user_event, display));
|
||||
pthread_cleanup_push(cancel_read_events, init_args_read(fd, user_event, display, file));
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
|
|
@ -11,9 +11,10 @@ typedef struct {
|
|||
int fd;
|
||||
event *user_event;
|
||||
Display *display;
|
||||
FILE *file;
|
||||
} args_cancel_thread_read;
|
||||
|
||||
args_cancel_thread_read * init_args_read(int fd, event *user_event, Display *display);
|
||||
args_cancel_thread_read * init_args_read(int fd, event *user_event, Display *display, FILE *file);
|
||||
|
||||
void write_event(event *new_event, FILE *file);
|
||||
|
||||
|
|
|
@ -32,6 +32,8 @@ void readfile(args_readfile *args)
|
|||
break;
|
||||
}
|
||||
|
||||
if (is_dummy(current_event)) continue;
|
||||
|
||||
left = (current_event->infos & M_LEFT) == M_LEFT;
|
||||
right = (current_event->infos & M_RIGHT) == M_RIGHT;
|
||||
middle = (current_event->infos & M_MIDDLE) == M_MIDDLE ;
|
||||
|
|
Loading…
Reference in a new issue