Skip to content
Snippets Groups Projects
Commit 5d54c91a authored by deuce's avatar deuce
Browse files

Initial add of generalized mouse API for ciolib... this is not complete, working,

or otherwise usefull at this time.
parent 33cb42fa
No related branches found
No related tags found
No related merge requests found
#include <genwrap.h>
#include <semwrap.h>
#include "mouse.h"
static pthread_mutex_t in_mutex;
static int in_mutex_initialized=0;
sem_t in_sem;
struct in_mouse_event {
int event;
int x;
int y;
clock_t ts;
void *nextevent;
};
struct out_mouse_event {
int event;
int bstate;
int kbsm; /* Known button state mask */
int startx;
int starty;
int endx;
int endy;
void *nextevent;
};
struct mouse_state {
int buttonstate; /* Current state of all buttons */
int knownbuttonstatemask; /* Mask of buttons that have done something since */
* We started watching... the rest are actually in
* an unknown state */
int curx; /* Current X position */
int cury; /* Current Y position */
int events; /* Currently enabled events */
int click_timeout; /* Timeout between press and release events for a click (ms) */
int multi_timeout; /* Timeout after a click for detection of multi clicks (ms) */
int click_drift; /* Allowed "drift" during a click event */
struct in_mouse_event *events_in; /* Pointer to recevied events stack */
struct out_mouse_event *events_out; /* Pointer to output events stack */
};
struct mouse_state state;
void init_mouse(void)
{
state.buttonstate=0;
state.knownbuttonstatemask=0;
state.curx=0;
state.cury=0;
state.events=0;
state.click_timeout=200;
state.multi_timeout=300;
state.events_in=(struct in_mouse_event *)NULL;
state.events_out=(struct out_mouse_event *)NULL;
pthread_mutex_init(&in_mutex,NULL);
sem_init(&in_sem,0,0);
}
int ciomouse_setevents(int events)
{
state.events=events;
return state.events;
}
int ciomouse_addevents(int events)
{
state.events |= events;
return state.events;
}
int ciomouse_delevents(int events)
{
state.events &= ~events;
return state.events;
}
static void ciomouse_gotevent(int event, int x, int y)
{
struct in_mouse_event *ime;
struct in_mouse_event **lastevent;
/* If you're not handling any mouse events, it doesn't matter what happens */
/* though this COULD be used to build up correct current mouse state data */
if(!state.events)
return;
ime=(struct in_mouse_event *)malloc(sizeof(struct in_mouse_event));
ime->ts=msclock();
ime->event=event;
ime->x=x;
ime->y=y;
ime->nextevent=NULL;
pthread_mutex_lock(&in_mutex);
for(lastevent=&state.events_in;*lastevent != NULL;lastevnet=&(lastevent->nextevent));
*lastevent=ime;
pthread_mutex_unlock(&in_mutex);
sem_post(&in_sem);
}
static void coilib_mouse_thread(void *data)
{
int use_timeout=0;
struct timespec timeout;
init_mouse();
while(1) {
if(use_timeout)
sem_timedwait(&in_sem,&timeout);
else
sem_wait(&in_sem);
/* Check for a timeout rather than a sem_post() */
switch(state.events_in->event) {
case CIOLIB_MOUSE_MOVE:
/* Needs to check if currently dragging/clicking/etc */
/* This can result in MULTIPLE events hitting the output */
/* Stack */
break;
case CIOLIB_BUTTON_1_PRESS:
/* No current event should affect a press event */
break;
case CIOLIB_BUTTON_1_RELEASE:
/* Needs to check if currently dragging/clicking/etc */
break;
case CIOLIB_BUTTON_2_PRESS:
/* No current event should affect a press event */
break;
case CIOLIB_BUTTON_2_RELEASE:
/* Needs to check if currently dragging/clicking/etc */
break;
case CIOLIB_BUTTON_3_PRESS:
/* No current event should affect a press event */
break;
case CIOLIB_BUTTON_3_RELEASE:
/* Needs to check if currently dragging/clicking/etc */
break;
}
}
}
#ifndef _CIOLIB_MOUSE_H_
#define _CIOLIB_MOUSE_H_
struct mouse_event {
int event;
int bstate;
int startx;
int starty;
int endx;
int endy;
};
#define CIOLIB_BUTTON_1 1
#define CIOLIB_BUTTON_2 2
#define CIOLIB_BUTTON_3 4
enum {
CIOLIB_MOUSE_MOVE
,CIOLIB_BUTTON_1_PRESS
,CIOLIB_BUTTON_1_RELEASE
,CIOLIB_BUTTON_1_CLICK
,CIOLIB_BUTTON_1_DBL_CLICK
,CIOLIB_BUTTON_1_TRPL_CLICK
,CIOLIB_BUTTON_1_QUAD_CLICK
,CIOLIB_BUTTON_1_DRAG_START
,CIOLIB_BUTTON_1_DRAG_MOVE
,CIOLIB_BUTTON_1_DRAG_END
,CIOLIB_BUTTON_2_PRESS
,CIOLIB_BUTTON_2_RELEASE
,CIOLIB_BUTTON_2_CLICK
,CIOLIB_BUTTON_2_DBL_CLICK
,CIOLIB_BUTTON_2_TRPL_CLICK
,CIOLIB_BUTTON_2_QUAD_CLICK
,CIOLIB_BUTTON_2_DRAG_START
,CIOLIB_BUTTON_2_DRAG_MOVE
,CIOLIB_BUTTON_2_DRAG_END
,CIOLIB_BUTTON_3_PRESS
,CIOLIB_BUTTON_3_RELEASE
,CIOLIB_BUTTON_3_CLICK
,CIOLIB_BUTTON_3_DBL_CLICK
,CIOLIB_BUTTON_3_TRPL_CLICK
,CIOLIB_BUTTON_3_QUAD_CLICK
,CIOLIB_BUTTON_3_DRAG_START
,CIOLIB_BUTTON_3_DRAG_MOVE
,CIOLIB_BUTTON_3_DRAG_END
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment