Commit f53b220e authored by deuce's avatar deuce
Browse files

New mouse API!

parent 4a455b7a
......@@ -23,6 +23,8 @@ CIOLIB_LDFLAGS += ${PTHREAD_LDFLAGS}
CIOLIB_CFLAGS += $(PTHREAD_CFLAGS)
CIOLIB_OBJS += $(LIBODIR)/ansi_cio.o $(LIBODIR)/threadwrap.o
CIOLIB_OBJS += $(LIBODIR)/curs_cio.o $(LIBODIR)/ciolib.o
CIOLIB_OBJS += $(LIBODIR)/mouse.o $(LIBODIR)/semwrap.o
CIOLIB_OBJS += $(LIBODIR)/genwrap.o $(PTHREAD_OBJS)
CIOLIB_CFLAGS += -I$(UIFC_SRC)
# Curses Stuff
......
......@@ -68,7 +68,7 @@ int try_x_init(int mode)
{
if(!console_init()) {
cio_api.mode=CIOLIB_MODE_X;
cio_api.mouse=0;
cio_api.mouse=1;
cio_api.puttext=x_puttext;
cio_api.gettext=x_gettext;
cio_api.textattr=x_textattr;
......@@ -83,7 +83,6 @@ int try_x_init(int mode)
cio_api.getch=x_getch;
cio_api.getche=x_getche;
cio_api.textmode=x_textmode;
cio_api.getmouse=NULL;
cio_api.showmouse=NULL;
cio_api.hidemouse=NULL;
cio_api.settitle=x_settitle;
......@@ -112,7 +111,6 @@ int try_curses_init(int mode)
cio_api.getch=curs_getch;
cio_api.getche=curs_getche;
cio_api.textmode=curs_textmode;
cio_api.getmouse=curs_getmouse;
cio_api.showmouse=curs_showmouse;
cio_api.hidemouse=curs_hidemouse;
cio_api.settitle=NULL;
......@@ -142,7 +140,6 @@ int try_ansi_init(int mode)
cio_api.getch=ansi_getch;
cio_api.getche=ansi_getche;
cio_api.textmode=ansi_textmode;
cio_api.getmouse=NULL;
cio_api.showmouse=NULL;
cio_api.hidemouse=NULL;
cio_api.settitle=NULL;
......@@ -175,7 +172,6 @@ int try_conio_init(int mode)
cio_api.getch=win32_getch;
cio_api.getche=win32_getche;
cio_api.textmode=win32_textmode;
cio_api.getmouse=win32_getmouse;
cio_api.showmouse=win32_showmouse;
cio_api.hidemouse=win32_hidemouse;
cio_api.settitle=win32_settitle;
......@@ -232,6 +228,7 @@ int initciolib(int mode)
cio_textinfo.winright=cio_textinfo.screenwidth;
cio_textinfo.winbottom=cio_textinfo.screenheight;
cio_textinfo.normattr=7;
_beginthread(ciolib_mouse_thread,0,NULL);
return(0);
}
......@@ -240,6 +237,8 @@ int ciolib_kbhit(void)
CIOLIB_INIT();
if(ungotch)
return(1);
if(mouse_pending())
return(1);
return(cio_api.kbhit());
}
......@@ -754,14 +753,6 @@ void ciolib_setcursortype(int a)
cio_api.setcursortype(a);
}
int ciolib_getmouse(struct cio_mouse_event *mevent) {
CIOLIB_INIT();
if(cio_api.getmouse!=NULL)
return(cio_api.getmouse(mevent));
return(-1);
}
int ciolib_showmouse(void) {
CIOLIB_INIT();
......
......@@ -3,6 +3,8 @@
#ifndef _CIOLIB_H_
#define _CIOLIB_H_
#include <mouse.h>
enum {
CIOLIB_MODE_AUTO
,CIOLIB_MODE_CURSES
......@@ -81,12 +83,6 @@ struct text_info {
unsigned char cury; /* y-coordinate in current window */
};
struct cio_mouse_event {
int x;
int y;
int button;
};
typedef struct {
int mode;
int mouse;
......@@ -123,7 +119,7 @@ typedef struct {
int (*cputs) (char *);
void (*textbackground) (int);
void (*textcolor) (int);
int (*getmouse) (struct cio_mouse_event *mevent);
int (*getmouse) (struct mouse_event *mevent);
int (*hidemouse) (void);
int (*showmouse) (void);
void (*settitle) (const char *);
......
......@@ -47,6 +47,9 @@
#include "console.h"
#include "vparams.h"
#include "keys.h"
#include "mouse.h"
/* Console definition variables */
BYTE VideoMode;
int FW, FH, FD;
......@@ -561,58 +564,67 @@ static int
video_event(XEvent *ev)
{
switch (ev->type) {
case MotionNotify: {
XMotionEvent *me = (XMotionEvent *)ev;
me->x -= 2;
me->y -= 2;
mouse_status.x = (me->x < mouse_status.range.x)
? mouse_status.range.x
: (me->x > mouse_status.range.w)
? mouse_status.range.w : me->x;
mouse_status.y = (me->y < mouse_status.range.y)
? mouse_status.range.y
: (me->y > mouse_status.range.h)
? mouse_status.range.h : me->y;
break;
}
case ButtonRelease: {
XButtonEvent *be = (XButtonEvent *)ev;
be->x -= 2;
be->y -= 2;
if (be->button < 3)
mouse_status.ups[be->button]++;
mouse_status.x = (be->x < mouse_status.range.x)
? mouse_status.range.x
: (be->x > mouse_status.range.w)
? mouse_status.range.w : be->x;
mouse_status.y = (be->y < mouse_status.range.y)
? mouse_status.range.y
: (be->y > mouse_status.range.h)
? mouse_status.range.h : be->y;
break;
}
case ButtonPress: {
XButtonEvent *be = (XButtonEvent *)ev;
be->x -= 2;
be->y -= 2;
if (be->button < 3)
mouse_status.downs[be->button]++;
mouse_status.x = (be->x < mouse_status.range.x)
? mouse_status.range.x
: (be->x > mouse_status.range.w)
? mouse_status.range.w : be->x;
mouse_status.y = (be->y < mouse_status.range.y)
? mouse_status.range.y
: (be->y > mouse_status.range.h)
? mouse_status.range.h : be->y;
break;
}
case MotionNotify: {
XMotionEvent *me = (XMotionEvent *)ev;
me->x -= 2;
me->y -= 8;
me->x/=FW;
me->y/=FH;
me->x++;
me->y++;
if(me->x<1)
me->x=1;
if(me->y<1)
me->y=1;
if(me->x>DpyCols)
me->x=DpyCols;
if(me->y>DpyRows+1)
me->y=DpyRows+1;
ciomouse_gotevent(CIOLIB_MOUSE_MOVE,me->x,me->y);
break;
}
case ButtonRelease: {
XButtonEvent *be = (XButtonEvent *)ev;
be->x -= 2;
be->y -= 8;
be->x/=FW;
be->y/=FH;
be->x++;
be->y++;
if(be->x<1)
be->x=1;
if(be->y<1)
be->y=1;
if(be->x>DpyCols)
be->x=DpyCols;
if(be->y>DpyRows+1)
be->y=DpyRows+1;
if (be->button <= 3) {
ciomouse_gotevent(CIOLIB_BUTTON_RELEASE(be->button),be->x,be->y);
}
break;
}
case ButtonPress: {
XButtonEvent *be = (XButtonEvent *)ev;
be->x -= 2;
be->y -= 8;
be->x/=FW;
be->y/=FH;
be->x++;
be->y++;
if(be->x<1)
be->x=1;
if(be->y<1)
be->y=1;
if(be->x>DpyCols)
be->x=DpyCols;
if(be->y>DpyRows+1)
be->y=DpyRows+1;
if (be->button <= 3) {
ciomouse_gotevent(CIOLIB_BUTTON_PRESS(be->button),be->x,be->y);
}
break;
}
case NoExpose:
break;
case GraphicsExpose:
......@@ -1334,20 +1346,26 @@ tty_read(int flag)
return(r & 0xff);
}
if (KbdEmpty()) {
if (KbdEmpty() && !mouse_pending()) {
if (flag & TTYF_BLOCK) {
while (KbdEmpty())
while (KbdEmpty() && !mouse_pending())
tty_pause();
} else {
return(-1);
}
}
r = KbdRead();
if ((r & 0xff) == 0)
x_nextchar = r >> 8;
r &= 0xff;
return(r & 0xff);
if(mouse_pending()) {
x_nextchar=CIO_KEY_MOUSE>>8;
return(CIO_KEY_MOUSE&0xff);
}
else {
r = KbdRead();
if ((r & 0xff) == 0)
x_nextchar = r >> 8;
r &= 0xff;
return(r & 0xff);
}
}
int
......
......@@ -8,6 +8,7 @@
#include "ciolib.h"
#include "curs_cio.h"
#include "keys.h"
#include "mouse.h"
static unsigned char curs_nextgetch=0;
const int curs_tabs[10]={9,17,25,33,41,49,57,65,73,80};
......@@ -401,6 +402,8 @@ int curs_kbhit(void)
if(curs_nextgetch)
return(1);
if(mouse_pending())
return(1);
timeout.tv_sec=0;
timeout.tv_usec=0;
FD_ZERO(&rfds);
......@@ -639,6 +642,7 @@ int curs_initciolib(long inmode)
keypad(stdscr, TRUE);
scrollok(stdscr,FALSE);
raw();
halfdelay(1);
atexit(call_endwin);
/* Set up color pairs */
......@@ -649,8 +653,10 @@ int curs_initciolib(long inmode)
}
mode = inmode;
#ifdef NCURSES_VERSION_MAJOR
if(mousemask(BUTTON1_CLICKED|BUTTON3_CLICKED,NULL)==BUTTON1_CLICKED|BUTTON3_CLICKED)
if(mousemask(BUTTON1_PRESSED|BUTTON1_RELEASED|BUTTON2_PRESSED|BUTTON2_RELEASED|BUTTON3_PRESSED|BUTTON3_RELEASED|REPORT_MOUSE_POSITION,NULL)==BUTTON1_PRESSED|BUTTON1_RELEASED|BUTTON2_PRESSED|BUTTON2_RELEASED|BUTTON3_PRESSED|BUTTON3_RELEASED|REPORT_MOUSE_POSITION) {
mouseinterval(0);
cio_api.mouse=1;
}
else
mousemask(0,NULL);
#endif
......@@ -761,190 +767,220 @@ int curs_putch(int c)
int curs_getch(void)
{
int ch;
MEVENT mevnt;
if(curs_nextgetch) {
ch=curs_nextgetch;
curs_nextgetch=0;
}
else {
while((ch=getch())==ERR) {
delay(1);
while((ch=getch())==ERR && !mouse_pending());
if(mouse_pending()) {
curs_nextgetch=CIO_KEY_MOUSE>>8;
ch=CIO_KEY_MOUSE & 0xff;
}
if(ch > 255) {
switch(ch) {
case KEY_DOWN: /* Down-arrow */
curs_nextgetch=0x50;
ch=0;
break;
case KEY_UP: /* Up-arrow */
curs_nextgetch=0x48;
ch=0;
break;
case KEY_LEFT: /* Left-arrow */
curs_nextgetch=0x4b;
ch=0;
break;
case KEY_RIGHT: /* Right-arrow */
curs_nextgetch=0x4d;
ch=0;
break;
case KEY_HOME: /* Home key (upward+left arrow) */
curs_nextgetch=0x47;
ch=0;
break;
case KEY_BACKSPACE: /* Backspace (unreliable) */
ch=8;
break;
case KEY_F(1): /* Function Key */
curs_nextgetch=0x3b;
ch=0;
break;
case KEY_F(2): /* Function Key */
curs_nextgetch=0x3c;
ch=0;
break;
case KEY_F(3): /* Function Key */
curs_nextgetch=0x3d;
ch=0;
break;
case KEY_F(4): /* Function Key */
curs_nextgetch=0x3e;
ch=0;
break;
case KEY_F(5): /* Function Key */
curs_nextgetch=0x3f;
ch=0;
break;
case KEY_F(6): /* Function Key */
curs_nextgetch=0x40;
ch=0;
break;
case KEY_F(7): /* Function Key */
curs_nextgetch=0x41;
ch=0;
break;
case KEY_F(8): /* Function Key */
curs_nextgetch=0x42;
ch=0;
break;
case KEY_F(9): /* Function Key */
curs_nextgetch=0x43;
ch=0;
break;
case KEY_F(10): /* Function Key */
curs_nextgetch=0x44;
ch=0;
break;
case KEY_F(11): /* Function Key */
curs_nextgetch=0x57;
ch=0;
break;
case KEY_F(12): /* Function Key */
curs_nextgetch=0x58;
ch=0;
break;
case KEY_DC: /* Delete character */
curs_nextgetch=0x53;
ch=0;
break;
case KEY_IC: /* Insert char or enter insert mode */
curs_nextgetch=0x52;
ch=0;
break;
case KEY_EIC: /* Exit insert char mode */
curs_nextgetch=0x52;
ch=0;
break;
case KEY_NPAGE: /* Next page */
curs_nextgetch=0x51;
ch=0;
break;
case KEY_PPAGE: /* Previous page */
curs_nextgetch=0x49;
ch=0;
break;
case KEY_ENTER: /* Enter or send (unreliable) */
curs_nextgetch=0x0d;
ch=0;
break;
case KEY_A1: /* Upper left of keypad */
curs_nextgetch=0x47;
ch=0;
break;
case KEY_A3: /* Upper right of keypad */
curs_nextgetch=0x49;
ch=0;
break;
case KEY_B2: /* Center of keypad */
curs_nextgetch=0x4c;
ch=0;
break;
case KEY_C1: /* Lower left of keypad */
curs_nextgetch=0x4f;
ch=0;
break;
case KEY_C3: /* Lower right of keypad */
curs_nextgetch=0x51;
ch=0;
break;
case KEY_BEG: /* Beg (beginning) */
curs_nextgetch=0x47;
ch=0;
break;
case KEY_CANCEL: /* Cancel */
curs_nextgetch=0x03;
ch=0;
break;
case KEY_END: /* End */
curs_nextgetch=0x4f;
ch=0;
break;
case KEY_SELECT: /* Select - Is "End" in X */
curs_nextgetch=0x4f;
ch=0;
break;
case KEY_MOUSE: /* Mouse stuff */
ch=CIO_KEY_MOUSE>>8;
curs_nextgetch=CIO_KEY_MOUSE&0xff;
break;
default:
curs_nextgetch=0xff;
ch=0;
break;
else {
if(ch > 255) {
switch(ch) {
case KEY_DOWN: /* Down-arrow */
curs_nextgetch=0x50;
ch=0;
break;
case KEY_UP: /* Up-arrow */
curs_nextgetch=0x48;
ch=0;
break;
case KEY_LEFT: /* Left-arrow */
curs_nextgetch=0x4b;
ch=0;
break;
case KEY_RIGHT: /* Right-arrow */
curs_nextgetch=0x4d;
ch=0;
break;
case KEY_HOME: /* Home key (upward+left arrow) */
curs_nextgetch=0x47;
ch=0;
break;
case KEY_BACKSPACE: /* Backspace (unreliable) */
ch=8;
break;
case KEY_F(1): /* Function Key */
curs_nextgetch=0x3b;
ch=0;
break;
case KEY_F(2): /* Function Key */
curs_nextgetch=0x3c;
ch=0;
break;
case KEY_F(3): /* Function Key */
curs_nextgetch=0x3d;
ch=0;
break;
case KEY_F(4): /* Function Key */
curs_nextgetch=0x3e;
ch=0;
break;
case KEY_F(5): /* Function Key */
curs_nextgetch=0x3f;
ch=0;
break;
case KEY_F(6): /* Function Key */
curs_nextgetch=0x40;
ch=0;
break;
case KEY_F(7): /* Function Key */
curs_nextgetch=0x41;
ch=0;
break;
case KEY_F(8): /* Function Key */
curs_nextgetch=0x42;
ch=0;
break;
case KEY_F(9): /* Function Key */
curs_nextgetch=0x43;
ch=0;
break;
case KEY_F(10): /* Function Key */
curs_nextgetch=0x44;
ch=0;
break;
case KEY_F(11): /* Function Key */
curs_nextgetch=0x57;
ch=0;
break;
case KEY_F(12): /* Function Key */
curs_nextgetch=0x58;
ch=0;
break;
case KEY_DC: /* Delete character */
curs_nextgetch=0x53;
ch=0;
break;
case KEY_IC: /* Insert char or enter insert mode */
curs_nextgetch=0x52;
ch=0;
break;
case KEY_EIC: /* Exit insert char mode */
curs_nextgetch=0x52;
ch=0;
break;
case KEY_NPAGE: /* Next page */
curs_nextgetch=0x51;
ch=0;
break;
case KEY_PPAGE: /* Previous page */
curs_nextgetch=0x49;
ch=0;
break;
case KEY_ENTER: /* Enter or send (unreliable) */
curs_nextgetch=0x0d;
ch=0;
break;
case KEY_A1: /* Upper left of keypad */
curs_nextgetch=0x47;
ch=0;
break;