First version X newmouse driver
This commit is contained in:
parent
67fdb1e0b8
commit
1298e3d635
1 changed files with 86 additions and 44 deletions
|
@ -10,10 +10,10 @@
|
||||||
#if GFX_USE_GDISP
|
#if GFX_USE_GDISP
|
||||||
|
|
||||||
#define GDISP_DRIVER_VMT GDISPVMT_X11
|
#define GDISP_DRIVER_VMT GDISPVMT_X11
|
||||||
#include "drivers/multiple/X/gdisp_lld_config.h"
|
#include "gdisp_lld_config.h"
|
||||||
#include "src/gdisp/driver.h"
|
#include "src/gdisp/driver.h"
|
||||||
|
|
||||||
#ifndef GDISP_FORCE_24BIT
|
#ifndef GDISP_FORCE_24BIT
|
||||||
#define GDISP_FORCE_24BIT FALSE
|
#define GDISP_FORCE_24BIT FALSE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -27,8 +27,45 @@
|
||||||
#define GDISP_FLG_READY (GDISP_FLG_DRIVER<<0)
|
#define GDISP_FLG_READY (GDISP_FLG_DRIVER<<0)
|
||||||
|
|
||||||
#if GINPUT_NEED_MOUSE
|
#if GINPUT_NEED_MOUSE
|
||||||
/* Include mouse support code */
|
// Include mouse support code
|
||||||
|
#define GMOUSE_DRIVER_VMT GMOUSEVMT_X11
|
||||||
#include "src/ginput/driver_mouse.h"
|
#include "src/ginput/driver_mouse.h"
|
||||||
|
|
||||||
|
// Forward definitions
|
||||||
|
static bool_t XMouseInit(GMouse *m, unsigned driverinstance);
|
||||||
|
static void XMouseRead(GMouse *m, GMouseReading *prd);
|
||||||
|
|
||||||
|
const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{
|
||||||
|
{
|
||||||
|
GDRIVER_TYPE_MOUSE,
|
||||||
|
GMOUSE_VFLG_NOPOLL|GMOUSE_VFLG_DYNAMICONLY,
|
||||||
|
// Extra flags for testing only
|
||||||
|
//GMOUSE_VFLG_TOUCH|GMOUSE_VFLG_SELFROTATION|GMOUSE_VFLG_DEFAULTFINGER
|
||||||
|
//GMOUSE_VFLG_CALIBRATE|GMOUSE_VFLG_CAL_EXTREMES|GMOUSE_VFLG_CAL_TEST|GMOUSE_VFLG_CAL_LOADFREE
|
||||||
|
//GMOUSE_VFLG_ONLY_DOWN|GMOUSE_VFLG_POORUPDOWN
|
||||||
|
sizeof(GMouse),
|
||||||
|
_gmouseInitDriver, _gmousePostInitDriver, _gmouseDeInitDriver
|
||||||
|
},
|
||||||
|
1, // z_max
|
||||||
|
0, // z_min
|
||||||
|
1, // z_touchon
|
||||||
|
0, // z_touchoff
|
||||||
|
{ // pen_jitter
|
||||||
|
0, // calibrate
|
||||||
|
0, // click
|
||||||
|
0 // move
|
||||||
|
},
|
||||||
|
{ // finger_jitter
|
||||||
|
0, // calibrate
|
||||||
|
2, // click
|
||||||
|
2 // move
|
||||||
|
},
|
||||||
|
XMouseInit, // init
|
||||||
|
0, // deinit
|
||||||
|
XMouseRead, // get
|
||||||
|
0, // calsave
|
||||||
|
0 // calload
|
||||||
|
}};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
@ -44,15 +81,16 @@ static XEvent evt;
|
||||||
static Colormap cmap;
|
static Colormap cmap;
|
||||||
static XVisualInfo vis;
|
static XVisualInfo vis;
|
||||||
static XContext cxt;
|
static XContext cxt;
|
||||||
#if GINPUT_NEED_MOUSE
|
|
||||||
static coord_t mousex, mousey;
|
|
||||||
static uint16_t mousebuttons;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct xPriv {
|
typedef struct xPriv {
|
||||||
Pixmap pix;
|
Pixmap pix;
|
||||||
GC gc;
|
GC gc;
|
||||||
Window win;
|
Window win;
|
||||||
|
#if GINPUT_NEED_MOUSE
|
||||||
|
coord_t mousex, mousey;
|
||||||
|
uint16_t buttons;
|
||||||
|
GMouse * mouse;
|
||||||
|
#endif
|
||||||
} xPriv;
|
} xPriv;
|
||||||
|
|
||||||
static void ProcessEvent(GDisplay *g, xPriv *priv) {
|
static void ProcessEvent(GDisplay *g, xPriv *priv) {
|
||||||
|
@ -68,42 +106,36 @@ static void ProcessEvent(GDisplay *g, xPriv *priv) {
|
||||||
case Expose:
|
case Expose:
|
||||||
XCopyArea(dis, priv->pix, evt.xexpose.window, priv->gc,
|
XCopyArea(dis, priv->pix, evt.xexpose.window, priv->gc,
|
||||||
evt.xexpose.x, evt.xexpose.y,
|
evt.xexpose.x, evt.xexpose.y,
|
||||||
evt.xexpose.width, evt.xexpose.height,
|
evt.xexpose.width, evt.xexpose.height,
|
||||||
evt.xexpose.x, evt.xexpose.y);
|
evt.xexpose.x, evt.xexpose.y);
|
||||||
break;
|
break;
|
||||||
#if GINPUT_NEED_MOUSE
|
#if GINPUT_NEED_MOUSE
|
||||||
case ButtonPress:
|
case ButtonPress:
|
||||||
mousex = evt.xbutton.x;
|
priv->mousex = evt.xbutton.x;
|
||||||
mousey = evt.xbutton.y;
|
priv->mousey = evt.xbutton.y;
|
||||||
switch(evt.xbutton.button){
|
switch(evt.xbutton.button){
|
||||||
case 1: mousebuttons |= GINPUT_MOUSE_BTN_LEFT; break;
|
case 1: priv->buttons |= GINPUT_MOUSE_BTN_LEFT; break;
|
||||||
case 2: mousebuttons |= GINPUT_MOUSE_BTN_MIDDLE; break;
|
case 2: priv->buttons |= GINPUT_MOUSE_BTN_MIDDLE; break;
|
||||||
case 3: mousebuttons |= GINPUT_MOUSE_BTN_RIGHT; break;
|
case 3: priv->buttons |= GINPUT_MOUSE_BTN_RIGHT; break;
|
||||||
case 4: mousebuttons |= GINPUT_MOUSE_BTN_4; break;
|
case 4: priv->buttons |= GINPUT_MOUSE_BTN_4; break;
|
||||||
}
|
}
|
||||||
#if GINPUT_MOUSE_POLL_PERIOD == TIME_INFINITE
|
_gmouseWakeup(priv->mouse);
|
||||||
ginputMouseWakeup();
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
case ButtonRelease:
|
case ButtonRelease:
|
||||||
mousex = evt.xbutton.x;
|
priv->mousex = evt.xbutton.x;
|
||||||
mousey = evt.xbutton.y;
|
priv->mousey = evt.xbutton.y;
|
||||||
switch(evt.xbutton.button){
|
switch(evt.xbutton.button){
|
||||||
case 1: mousebuttons &= ~GINPUT_MOUSE_BTN_LEFT; break;
|
case 1: priv->buttons &= ~GINPUT_MOUSE_BTN_LEFT; break;
|
||||||
case 2: mousebuttons &= ~GINPUT_MOUSE_BTN_MIDDLE; break;
|
case 2: priv->buttons &= ~GINPUT_MOUSE_BTN_MIDDLE; break;
|
||||||
case 3: mousebuttons &= ~GINPUT_MOUSE_BTN_RIGHT; break;
|
case 3: priv->buttons &= ~GINPUT_MOUSE_BTN_RIGHT; break;
|
||||||
case 4: mousebuttons &= ~GINPUT_MOUSE_BTN_4; break;
|
case 4: priv->buttons &= ~GINPUT_MOUSE_BTN_4; break;
|
||||||
}
|
}
|
||||||
#if GINPUT_MOUSE_POLL_PERIOD == TIME_INFINITE
|
_gmouseWakeup(priv->mouse);
|
||||||
ginputMouseWakeup();
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
case MotionNotify:
|
case MotionNotify:
|
||||||
mousex = evt.xmotion.x;
|
priv->mousex = evt.xmotion.x;
|
||||||
mousey = evt.xmotion.y;
|
priv->mousey = evt.xmotion.y;
|
||||||
#if GINPUT_MOUSE_POLL_PERIOD == TIME_INFINITE
|
_gmouseWakeup(priv->mouse);
|
||||||
ginputMouseWakeup();
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -125,7 +157,7 @@ static DECLARE_THREAD_FUNCTION(ThreadX, arg) {
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int FatalXIOError(Display *d) {
|
static int FatalXIOError(Display *d) {
|
||||||
(void) d;
|
(void) d;
|
||||||
|
|
||||||
|
@ -187,13 +219,13 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
|
||||||
xa.colormap = cmap;
|
xa.colormap = cmap;
|
||||||
xa.border_pixel = 0xFFFFFF;
|
xa.border_pixel = 0xFFFFFF;
|
||||||
xa.background_pixel = 0x000000;
|
xa.background_pixel = 0x000000;
|
||||||
|
|
||||||
priv->win = XCreateWindow(dis, RootWindow(dis, scr), 16, 16,
|
priv->win = XCreateWindow(dis, RootWindow(dis, scr), 16, 16,
|
||||||
GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT,
|
GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT,
|
||||||
0, vis.depth, InputOutput, vis.visual,
|
0, vis.depth, InputOutput, vis.visual,
|
||||||
CWBackPixel|CWColormap|CWBorderPixel, &xa);
|
CWBackPixel|CWColormap|CWBorderPixel, &xa);
|
||||||
XSync(dis, TRUE);
|
XSync(dis, TRUE);
|
||||||
|
|
||||||
XSaveContext(dis, priv->win, cxt, (XPointer)g);
|
XSaveContext(dis, priv->win, cxt, (XPointer)g);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -205,7 +237,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
|
||||||
XSetWMIconName(dis, priv->win, &WindowTitle);
|
XSetWMIconName(dis, priv->win, &WindowTitle);
|
||||||
XSync(dis, TRUE);
|
XSync(dis, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
pSH = XAllocSizeHints();
|
pSH = XAllocSizeHints();
|
||||||
pSH->flags = PSize | PMinSize | PMaxSize;
|
pSH->flags = PSize | PMinSize | PMaxSize;
|
||||||
pSH->min_width = pSH->max_width = pSH->base_width = GDISP_SCREEN_WIDTH;
|
pSH->min_width = pSH->max_width = pSH->base_width = GDISP_SCREEN_WIDTH;
|
||||||
|
@ -213,7 +245,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
|
||||||
XSetWMNormalHints(dis, priv->win, pSH);
|
XSetWMNormalHints(dis, priv->win, pSH);
|
||||||
XFree(pSH);
|
XFree(pSH);
|
||||||
XSync(dis, TRUE);
|
XSync(dis, TRUE);
|
||||||
|
|
||||||
priv->pix = XCreatePixmap(dis, priv->win,
|
priv->pix = XCreatePixmap(dis, priv->win,
|
||||||
GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT, vis.depth);
|
GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT, vis.depth);
|
||||||
XSync(dis, TRUE);
|
XSync(dis, TRUE);
|
||||||
|
@ -236,6 +268,12 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
|
||||||
g->g.Contrast = 50;
|
g->g.Contrast = 50;
|
||||||
g->g.Width = GDISP_SCREEN_WIDTH;
|
g->g.Width = GDISP_SCREEN_WIDTH;
|
||||||
g->g.Height = GDISP_SCREEN_HEIGHT;
|
g->g.Height = GDISP_SCREEN_HEIGHT;
|
||||||
|
|
||||||
|
// Create the associated mouse
|
||||||
|
#if GINPUT_NEED_MOUSE
|
||||||
|
priv->mouse = (GMouse *)gdriverRegister((const GDriverVMT const *)GMOUSE_DRIVER_VMT, g);
|
||||||
|
#endif
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,16 +350,20 @@ LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if GINPUT_NEED_MOUSE
|
#if GINPUT_NEED_MOUSE
|
||||||
|
static bool_t XMouseInit(GMouse *m, unsigned driverinstance) {
|
||||||
void ginput_lld_mouse_init(void) {}
|
(void) m;
|
||||||
|
(void) driverinstance;
|
||||||
void ginput_lld_mouse_get_reading(MouseReading *pt) {
|
return TRUE;
|
||||||
pt->x = mousex;
|
|
||||||
pt->y = mousey;
|
|
||||||
pt->z = (mousebuttons & GINPUT_MOUSE_BTN_LEFT) ? 100 : 0;
|
|
||||||
pt->buttons = mousebuttons;
|
|
||||||
}
|
}
|
||||||
|
static void XMouseRead(GMouse *m, GMouseReading *pt) {
|
||||||
|
xPriv * priv;
|
||||||
|
|
||||||
|
priv = m->display->priv;
|
||||||
|
pt->x = priv->mousex;
|
||||||
|
pt->y = priv->mousey;
|
||||||
|
pt->z = (priv->buttons & GINPUT_MOUSE_BTN_LEFT) ? 1 : 0;
|
||||||
|
pt->buttons = priv->buttons;
|
||||||
|
}
|
||||||
#endif /* GINPUT_NEED_MOUSE */
|
#endif /* GINPUT_NEED_MOUSE */
|
||||||
|
|
||||||
#endif /* GFX_USE_GDISP */
|
#endif /* GFX_USE_GDISP */
|
||||||
|
|
Loading…
Add table
Reference in a new issue