summaryrefslogtreecommitdiff
path: root/plat.c
diff options
context:
space:
mode:
Diffstat (limited to 'plat.c')
-rw-r--r--plat.c74
1 files changed, 70 insertions, 4 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;
}
}