aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorepoch <epoch@hacking.allowed.org>2020-07-17 04:00:45 -0500
committerepoch <epoch@hacking.allowed.org>2020-07-17 04:00:45 -0500
commit086db581230d0f795f92dbaef637cd19d8538da9 (patch)
treec03374df61b13337896bb260181a496e9efec54b
parent76c2983c0d1ce48321310ebb60b1c81f4dcbbf44 (diff)
downloadhackvr-086db581230d0f795f92dbaef637cd19d8538da9.tar.gz
hackvr-086db581230d0f795f92dbaef637cd19d8538da9.zip
switched to using named constants instead of magic values. right now to configure mouse buttons you need to edit these files.
-rw-r--r--src/mouse_die.c57
-rw-r--r--src/mouse_x11.c50
2 files changed, 80 insertions, 27 deletions
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 <unistd.h>
#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<<i);
+ for(i=0;i<3;i++) {//we need to loop over all buttons each event. :/
+ butt=ie.type & 0x07 & (1<<i);//lowest 3 bits are possible mouse button states
+ m=die2map(i);
+ if(m == -1) {
+ continue;//not gonna even try.
+ }
if(butt) {//this button is down
fprintf(stderr,"# mouse button %d is down.\n",butt-1);
- if(gra_global.mousemap[butt-1] != 1) {//freshly down. save coords and set it to down.
- gra_global.dragstart[butt-1]=gra_global.mouse;
- gra_global.mousemap[butt-1]=1;
- redrawplzkthx=1;
- }
+ if(gra_global.mousemap[m] != 1) {//freshly down. save coords and set it to down.
+ gra_global.dragstart[m]=gra_global.mouse;
+ gra_global.mousemap[m]=1;
+ redrawplzkthx=1;
+ }
} else {
- if(gra_global.mousemap[(1<<i)-1]) {//only if it was pressed we mark it as "released"
+ if(gra_global.mousemap[m]) {//only if it was pressed we mark it as "released"
fprintf(stderr,"# mouse button %d is being marked as released.\n",(1<<i)-1);
- gra_global.mousemap[(1<<i)-1]=-1;
- if((1<<i)-1 == 1) {//do this for right-click only.
+ gra_global.mousemap[m]=-1;
+ if(m == MOUSE_SECONDARY) {//do this for secondary button release
gra_global.oldcamera = global.camera.r;//we're done dragging, so set this as where the camera points at for next drag around
}
redrawplzkthx=1;
@@ -72,11 +93,15 @@ int mouse_event_handler() {
if(ie.dx || ie.dy) {
fprintf(stderr,"# mouse debug: type:\t%d\tdx:%d\tdy:%d\n",ie.type,ie.dx,ie.dy);
gra_global.mouse.x+=ie.dx;
+ if(gra_global.mouse.x < LEFT) gra_global.mouse.x = LEFT;
+ if(gra_global.mouse.x > 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;
}
diff --git a/src/mouse_x11.c b/src/mouse_x11.c
index 719940e..8218c98 100644
--- a/src/mouse_x11.c
+++ b/src/mouse_x11.c
@@ -4,6 +4,7 @@
#include "graphics_c3.h"
#include "graphics_c2.h"
#include "graphics_x11.h"
+#include "mouse.h"
extern struct hvr_global global;
extern struct gra_global gra_global;
@@ -13,8 +14,27 @@ int mouse_init() {
return x11_global.fd;
}
+#define X11_MOUSE_PRIMARY 1
+#define X11_MOUSE_SECONDARY 2
+#define X11_MOUSE_TERTIARY 3
+#define X11_MOUSE_SCROLLUP 4
+#define X11_MOUSE_SCROLLDOWN 5
+
+char x112map(char x) {
+ switch(x) {
+ case X11_MOUSE_PRIMARY: return MOUSE_PRIMARY;
+ case X11_MOUSE_TERTIARY: return MOUSE_TERTIARY;//middle-click
+ case X11_MOUSE_SECONDARY: return MOUSE_SECONDARY;
+ case X11_MOUSE_SCROLLUP: return MOUSE_SCROLLUP;
+ case X11_MOUSE_SCROLLDOWN: return MOUSE_SCROLLDOWN;
+ default: return -1;
+ }
+ return -1;
+}
+
int mouse_event_handler() {//this returns HVM_ key + for buttondown and - for buttonup... set the mousex and mousey in here?
XEvent e;
+ c3_group_rel_t *gr;
Window root,child;//just dimmies
unsigned int mask;//just dummies
char motion_notify=0;
@@ -26,14 +46,17 @@ int mouse_event_handler() {//this returns HVM_ key + for buttondown and - for bu
while(XCheckMaskEvent(x11_global.dpy,HV_MOUSE_X11_EVENT_MASK,&e)) {//we want to collapse mouse stuff to one for each loop.
switch(e.type) {
case ButtonPress: //e.xbutton.button == 1 for first button. we don't need to start at 1. let's start at 0 with the -1 //scroll wheel up is 3, down is 4
- butt=e.xbutton.button-1;
- if(butt == 3) {//scroll wheel up
+ if((butt=x112map(e.xbutton.button)) == -1) {
+ continue;//we don't know how to handle this button. :/
+ }
+ fprintf(stderr,"# x11 button: %d is %d in hackvr\n",e.xbutton.button,butt);
+ if(butt == MOUSE_SCROLLUP) {//scroll wheel up
selfcommand("epoch move forward\n");//need to implement this syntax in hackvr
}
- if(butt == 4) {//scroll wheel down
+ if(butt == MOUSE_SCROLLDOWN) {//scroll wheel down
selfcommand("epoch move backward\n");
}
- if(butt == 1) {//middle-click
+ if(butt == MOUSE_TERTIARY) {//middle-click
gra_global.input_mode ^= 1;
printf("# gra_global.input_mode == %d\n",gra_global.input_mode);
}
@@ -43,9 +66,10 @@ int mouse_event_handler() {//this returns HVM_ key + for buttondown and - for bu
redrawplzkthx=1;
break;
case ButtonRelease:
- printf("# button release %d\n",e.xbutton.button-1);
- gra_global.mousemap[e.xbutton.button-1]=-1;//we can trigger on -1 or on 1 then set back to 0 to prevent double-trigger
- gra_global.oldcamera=global.camera.r;
+ printf("# button release %d\n",butt);
+ gra_global.mousemap[butt]=-1;//we can trigger on -1 or on 1 then set back to 0 to prevent double-trigger
+ gr=get_group_relative(global.user);
+ gra_global.oldcamera=gr->r;
redrawplzkthx=1;
break;
case MotionNotify:
@@ -68,10 +92,14 @@ int mouse_event_handler() {//this returns HVM_ key + for buttondown and - for bu
//snprintf(cmd,sizeof(cmd),"%s rotate +%d +%d +%d\n",global.user,3,11,1);
//selfcommand(cmd);
//global.camera.r.x.d=(gra_global.height - gra_global.mouse.y);//up and down camera controls backwards
- //fprintf(stderr,"# mouse.x: %f mouse.y: %f\n# width: %u height: %u\n",gra_global.mouse.x,gra_global.mouse.y,gra_global.width,gra_global.height);
- if(gra_global.mousemap[2] == 1) {//if "right" click is held down
- global.camera.r.x.d=gra_global.oldcamera.x.d + (gra_global.mouse.y - gra_global.dragstart[2].y);
- global.camera.r.y.d=gra_global.oldcamera.y.d + (gra_global.mouse.x - gra_global.dragstart[2].x);
+ //fprintf(stderr,"# mouse.x: %f mouse.y: %f\n# width: %u height: %u\n",gra_glo bal.mouse.x,gra_global.mouse.y,gra_global.width,gra_global.height);
+ //this /was/ using a 2 for the mousemap index... so 2 is "right" in hackvr.
+ if(gra_global.mousemap[MOUSE_SECONDARY] == 1) {//if "right" click is held down
+ gr=get_group_relative(global.user);
+ gr->r.x.d=gra_global.oldcamera.x.d + (gra_global.mouse.y - gra_global.dragstart[2].y);
+ gr->r.y.d=gra_global.oldcamera.y.d + (gra_global.mouse.x - gra_global.dragstart[2].x);
+ //global.camera.r.x.d=gra_global.oldcamera.x.d + (gra_global.mouse.y - gra_global.dragstart[2].y);
+ //global.camera.r.y.d=gra_global.oldcamera.y.d + (gra_global.mouse.x - gra_global.dragstart[2].x);
}
//do we need to redraw on mouse movement?
//probably.