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;
|
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)
|
void mouse_event(event *event, mouse_button button)
|
||||||
{
|
{
|
||||||
init_event(event, 0);
|
init_event(event, 0);
|
||||||
|
|
15
src/event.h
15
src/event.h
|
@ -1,15 +1,18 @@
|
||||||
#ifndef EVENT_USER
|
#ifndef EVENT_USER
|
||||||
#define EVENT_USER
|
#define EVENT_USER
|
||||||
|
|
||||||
|
#define DUMMY 0x80
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Structure containing informations about events.
|
* Structure containing informations about events.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/*
|
/*
|
||||||
* X00T 00ZZ
|
* XD0T 00ZZ
|
||||||
*
|
*
|
||||||
* Where:
|
* Where:
|
||||||
* * X = press (1) or release (0)
|
* * X = press (1) or release (0)
|
||||||
|
* * D = dummy, ignore this event (1)
|
||||||
* * T = keyboard (1) or mouse (0)
|
* * T = keyboard (1) or mouse (0)
|
||||||
* * ZZ (only for mouse events) = button
|
* * ZZ (only for mouse events) = button
|
||||||
* * left (01)
|
* * left (01)
|
||||||
|
@ -48,6 +51,16 @@ void reset(event *event);
|
||||||
*/
|
*/
|
||||||
void init_event(event *event, char is_pressed);
|
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.
|
* Init a mouse event and set if the button is pressed or not.
|
||||||
* The caller must indicate coordonates.
|
* The caller must indicate coordonates.
|
||||||
|
|
|
@ -8,12 +8,13 @@
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
#include "read_events.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));
|
args_cancel_thread_read *ret = (args_cancel_thread_read *) malloc(sizeof(args_cancel_thread_read));
|
||||||
ret->fd = fd;
|
ret->fd = fd;
|
||||||
ret->user_event = user_event;
|
ret->user_event = user_event;
|
||||||
ret->display = display;
|
ret->display = display;
|
||||||
|
ret->file = file;
|
||||||
|
|
||||||
return ret;
|
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)
|
void cancel_read_events(args_cancel_thread_read *arg)
|
||||||
{
|
{
|
||||||
int fd = arg->fd;
|
int fd = arg->fd;
|
||||||
|
FILE *file = arg->file;
|
||||||
|
|
||||||
/* flush the middle button */
|
/* flush the middle button */
|
||||||
unsigned char data[3];
|
unsigned char data[3];
|
||||||
read(fd, data, sizeof(data));
|
read(fd, data, sizeof(data));
|
||||||
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);
|
free(arg->user_event);
|
||||||
close(fd);
|
close(fd);
|
||||||
XCloseDisplay(arg->display);
|
XCloseDisplay(arg->display);
|
||||||
|
@ -62,7 +72,7 @@ int listen(FILE *file)
|
||||||
return -1;
|
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)
|
while (1)
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,9 +11,10 @@ typedef struct {
|
||||||
int fd;
|
int fd;
|
||||||
event *user_event;
|
event *user_event;
|
||||||
Display *display;
|
Display *display;
|
||||||
|
FILE *file;
|
||||||
} args_cancel_thread_read;
|
} 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);
|
void write_event(event *new_event, FILE *file);
|
||||||
|
|
||||||
|
|
|
@ -32,9 +32,11 @@ void readfile(args_readfile *args)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_dummy(current_event)) continue;
|
||||||
|
|
||||||
left = (current_event->infos & M_LEFT) == M_LEFT;
|
left = (current_event->infos & M_LEFT) == M_LEFT;
|
||||||
right =(current_event->infos & M_RIGHT) == M_RIGHT;
|
right = (current_event->infos & M_RIGHT) == M_RIGHT;
|
||||||
middle=(current_event->infos & M_MIDDLE) == M_MIDDLE ;
|
middle = (current_event->infos & M_MIDDLE) == M_MIDDLE ;
|
||||||
|
|
||||||
x = current_event->x;
|
x = current_event->x;
|
||||||
y = current_event->y;
|
y = current_event->y;
|
||||||
|
|
Loading…
Reference in a new issue