summaryrefslogtreecommitdiff
path: root/src/mouse_die.c
blob: 6729a942f651ef6f715362d9b8b53e077ca4ad29 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include <string.h>
#include <linux/input.h>
#include <fcntl.h>
#include <unistd.h>


//#define MOUSEDEV "/dev/input/mouse0" //just one of the many possibly connected mice. (just in case you want to use one mouse for one thing and another mouse for something else)
#define MOUSEDEV "/dev/input/mice" //all the mice connected act as one.

int mfd = -1;

//#define "mouse.h" //I guess

struct wtf {
  unsigned char type;
  char dx;
  char dy;
};

int mouse_event_handler() {
  struct wtf ie;
  int l;
  memset(&ie,0,sizeof(ie));
  if(mfd == -1) {
    mfd=open(MOUSEDEV,O_RDWR);
    fcntl(mfd,F_SETFL,O_NONBLOCK);
  }
  if(mfd == -1) {
    fprintf(stderr,"# mouse shit fucked up.\n");
    return 1;
  }
  if((l=read(mfd,&ie,sizeof(ie))) > 0) {
    //type == 8 and a or of some bits to say which direction.
    fprintf(stderr,"# mouse debug: type:\t%d\tdx:%d\tdy:%d\n",ie.type,ie.dx,ie.dy);
  }
  return 0;
}