diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/window/window.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/window/window.c b/src/window/window.c index 440eecb..4523471 100644 --- a/src/window/window.c +++ b/src/window/window.c @@ -397,11 +397,11 @@ static mgl_key x11_keysym_to_mgl_key(KeySym key_sym) { static mgl_mouse_button x11_button_to_mgl_button(unsigned int button) { switch(button) { - case 1: return MGL_BUTTON_LEFT; - case 2: return MGL_BUTTON_MIDDLE; - case 3: return MGL_BUTTON_RIGHT; - case 8: return MGL_BUTTON_XBUTTON1; - case 9: return MGL_BUTTON_XBUTTON2; + case Button1: return MGL_BUTTON_LEFT; + case Button2: return MGL_BUTTON_MIDDLE; + case Button3: return MGL_BUTTON_RIGHT; + case 8: return MGL_BUTTON_XBUTTON1; + case 9: return MGL_BUTTON_XBUTTON2; } return MGL_BUTTON_UNKNOWN; } @@ -470,10 +470,24 @@ static void mgl_window_on_receive_event(mgl_window *self, XEvent *xev, mgl_event return; } case ButtonPress: { - event->type = MGL_EVENT_MOUSE_BUTTON_PRESSED; - event->mouse_button.button = x11_button_to_mgl_button(xev->xbutton.button); - event->mouse_button.x = xev->xbutton.x; - event->mouse_button.y = xev->xbutton.y; + if(xev->xbutton.button == Button4) { + /* Mouse scroll up */ + event->type = MGL_EVENT_MOUSE_WHEEL_SCROLLED; + event->mouse_wheel_scroll.delta = 1; + event->mouse_wheel_scroll.x = xev->xbutton.x; + event->mouse_wheel_scroll.y = xev->xbutton.y; + } else if(xev->xbutton.button == Button5) { + /* Mouse scroll down */ + event->type = MGL_EVENT_MOUSE_WHEEL_SCROLLED; + event->mouse_wheel_scroll.delta = -1; + event->mouse_wheel_scroll.x = xev->xbutton.x; + event->mouse_wheel_scroll.y = xev->xbutton.y; + } else { + event->type = MGL_EVENT_MOUSE_BUTTON_PRESSED; + event->mouse_button.button = x11_button_to_mgl_button(xev->xbutton.button); + event->mouse_button.x = xev->xbutton.x; + event->mouse_button.y = xev->xbutton.y; + } return; } case ButtonRelease: { |