summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plat.c74
-rw-r--r--plat.h11
2 files changed, 80 insertions, 5 deletions
diff --git a/plat.c b/plat.c
index 6c10b29..16144b4 100644
--- a/plat.c
+++ b/plat.c
@@ -488,16 +488,21 @@ void app_begin(App* a) {
Window w = i->wi;
int j;
i->begin = get_timer();
- for (j = 0; j < key_count; j++) {
+ for (j = 0; j < key_count; j++)
a->key_states[j] &= ~(
key_state_just_pressed | key_state_just_released
);
- }
+ for (j = 0; j < mbtn_count; j++)
+ a->mbtn_states[j] &= ~(
+ key_state_just_pressed | key_state_just_released
+ );
+ a->scrollx = a->scrolly = 0;
while (XPending(d)) {
XEvent e;
XWindowAttributes wa;
KeySym sym;
Key key;
+ int btn;
XNextEvent(d, &e);
switch (e.type) {
case ClientMessage:
@@ -523,6 +528,52 @@ void app_begin(App* a) {
a->my = e.xmotion.y / a->s;
}
break;
+ case ButtonPress:
+ switch (e.xbutton.button) {
+ case 1:
+ case 2:
+ case 3:
+ a->mbtn_states[e.xbutton.button - 1] |=
+ key_state_pressed |
+ key_state_just_pressed;
+ break;
+ case 4:
+ a->scrolly++;
+ break;
+ case 5:
+ a->scrolly--;
+ break;
+ case 6:
+ a->scrollx++;
+ break;
+ case 7:
+ a->scrollx--;
+ break;
+ }
+ break;
+ case ButtonRelease:
+ switch (e.xbutton.button) {
+ case 1:
+ case 2:
+ case 3:
+ btn = e.xbutton.button - 1;
+ a->mbtn_states[btn] &= ~key_state_pressed;
+ a->mbtn_states[btn] |= key_state_just_released;
+ break;
+ case 4:
+ a->scrolly++;
+ break;
+ case 5:
+ a->scrolly--;
+ break;
+ case 6:
+ a->scrollx++;
+ break;
+ case 7:
+ a->scrollx--;
+ break;
+ }
+ break;
case KeyPress:
sym = XLookupKeysym(&e.xkey, 0);
key = key_from_xkey(sym);
@@ -551,8 +602,8 @@ void app_begin(App* a) {
if (XIMaskIsSet(re->valuators.mask, 1)) {
i->rmy += (int)values[1];
}
- a->mx = i->rmx / a->s;
- a->my = i->rmy / a->s;
+ a->mx = i->rmx;
+ a->my = i->rmy;
}
XFreeEventData(d, &e.xcookie);
}
@@ -678,8 +729,23 @@ void cfg_mouse(App* a, int show) {
em.mask = mask;
XISetMask(mask, XI_RawMotion);
XISelectEvents(d, DefaultRootWindow(d), &em, 1);
+ XWarpPointer(
+ d,
+ i->wi,
+ i->wi,
+ 0,
+ 0,
+ 0,
+ 0,
+ i->w / 2,
+ i->h / 2
+ );
+ a->mx = i->w / 2;
+ a->my = i->h / 2;
i->rmx = a->mx;
i->rmy = a->my;
+ i->omx = a->mx;
+ i->omy = a->my;
}
}
diff --git a/plat.h b/plat.h
index 70fdf36..190c011 100644
--- a/plat.h
+++ b/plat.h
@@ -143,20 +143,29 @@ typedef enum {
} Key;
typedef enum {
+ mbtn_left,
+ mbtn_middle,
+ mbtn_right,
+ mbtn_count
+} Mbtn;
+
+typedef enum {
key_state_pressed = 1 << 0,
key_state_just_pressed = 1 << 1,
key_state_just_released = 1 << 2
} Key_State;
-typedef struct {
+typedef struct App {
int w, h, s, o, mpf;
int fps;
int mx, my;
+ int scrollx, scrolly;
int dmx, dmy;
Error err;
Colour* fb;
Heap* heap;
unsigned char key_states[key_count];
+ unsigned char mbtn_states[mbtn_count];
} App;
App* new_app(Heap* mem, int w, int h, const char* n);