From 086db581230d0f795f92dbaef637cd19d8538da9 Mon Sep 17 00:00:00 2001 From: epoch Date: Fri, 17 Jul 2020 04:00:45 -0500 Subject: switched to using named constants instead of magic values. right now to configure mouse buttons you need to edit these files. --- src/mouse_die.c | 57 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 16 deletions(-) (limited to 'src/mouse_die.c') diff --git a/src/mouse_die.c b/src/mouse_die.c index 4fddf5f..2258a08 100644 --- a/src/mouse_die.c +++ b/src/mouse_die.c @@ -5,6 +5,7 @@ #include #include "graphics_c3.h" +#include "mouse.h" extern struct hvr_global global; extern struct gra_global gra_global; @@ -29,11 +30,29 @@ int mouse_init() { return mfd; } +//buttons are: +//0 for left click, 1 for right click, 2 is middle-click + +//in the hackvr mouse map, right is 2, left is 0 and center is 1? +#define DIE_MOUSE_LEFT 0 +#define DIE_MOUSE_RIGHT 1 +#define DIE_MOUSE_CENTER 2 +//it doesn't care if you have X11 buttons swapped around ofc. +char die2map(char d) {//edit this function if you want to change your primary and secondary mouse button. + switch(d) { + case DIE_MOUSE_RIGHT: return MOUSE_PRIMARY; + case DIE_MOUSE_LEFT: return MOUSE_SECONDARY; + case DIE_MOUSE_CENTER: return MOUSE_TERTIARY; + default: return -1; + } +} + int mouse_event_handler() { struct wtf ie; int butt; int l; - int i; + int i;//this is a DIE_MOUSE value + unsigned char m;//this is a hackvr mouse map value. int redrawplzkthx=0; memset(&ie,0,sizeof(ie)); if(mfd == -1) { @@ -46,22 +65,24 @@ int mouse_event_handler() { return 1; } if((l=read(mfd,&ie,sizeof(ie))) > 0) { - //type == 8 and a or of some bits to say which direction. - //these types are movement: 8 40 56 24 - for(i=0;i<4;i++) {//we need to loop over all buttons each event. :/ - butt=ie.type & 0x07 & (1< RIGHT) gra_global.mouse.x = RIGHT; gra_global.mouse.y+=ie.dy; + if(gra_global.mouse.y < BOTTOM) gra_global.mouse.y = BOTTOM; + if(gra_global.mouse.y > TOP) gra_global.mouse.y = TOP; fprintf(stderr,"# mouse: x:%F y:%F\n",gra_global.mouse.x,gra_global.mouse.y); - if(gra_global.mousemap[1] == 1) {//if "right" click is held down - global.camera.r.x.d=gra_global.oldcamera.x.d + (gra_global.mouse.y - gra_global.dragstart[1].y); - global.camera.r.y.d=gra_global.oldcamera.y.d + (gra_global.mouse.x - gra_global.dragstart[1].x); + if(gra_global.mousemap[MOUSE_SECONDARY] == 1) {//if "right" click is held down... this is somehow primary click + global.camera.r.x.d=gra_global.oldcamera.x.d + (gra_global.mouse.y - gra_global.dragstart[MOUSE_SECONDARY].y); + global.camera.r.y.d=gra_global.oldcamera.y.d + (gra_global.mouse.x - gra_global.dragstart[MOUSE_SECONDARY].x); } redrawplzkthx=1; } -- cgit v1.2.3