From 6f71e9eb80573a1a231491a6bbc05b2e3ed63e7c Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 31 Aug 2006 00:36:23 +0000 Subject: [PATCH] wheel_up/down --- panda/src/glxdisplay/config_glxdisplay.cxx | 13 +++++++++- panda/src/glxdisplay/config_glxdisplay.h | 4 +++ panda/src/glxdisplay/glxGraphicsWindow.cxx | 29 +++++++++++++++++----- panda/src/glxdisplay/glxGraphicsWindow.h | 3 ++- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/panda/src/glxdisplay/config_glxdisplay.cxx b/panda/src/glxdisplay/config_glxdisplay.cxx index 421a690288..f3c8b30cc1 100644 --- a/panda/src/glxdisplay/config_glxdisplay.cxx +++ b/panda/src/glxdisplay/config_glxdisplay.cxx @@ -51,7 +51,18 @@ ConfigVariableBool glx_get_os_address "directly using standard operating system calls to locate " "addresses of extension functions. This will be done only " "if glxGetProcAddress() cannot be used for some reason.")); - + +ConfigVariableInt glx_wheel_up_button +("glx-wheel-up-button", 4, + PRC_DESC("This is the mouse button index of the wheel_up event: which " + "mouse button number does the system report when the mouse wheel " + "is rolled one notch up?")); + +ConfigVariableInt glx_wheel_down_button +("glx-wheel-down-button", 5, + PRC_DESC("This is the mouse button index of the wheel_down event: which " + "mouse button number does the system report when the mouse wheel " + "is rolled one notch down?")); //////////////////////////////////////////////////////////////////// // Function: init_libglxdisplay diff --git a/panda/src/glxdisplay/config_glxdisplay.h b/panda/src/glxdisplay/config_glxdisplay.h index 059361863c..1698085264 100644 --- a/panda/src/glxdisplay/config_glxdisplay.h +++ b/panda/src/glxdisplay/config_glxdisplay.h @@ -23,6 +23,7 @@ #include "notifyCategoryProxy.h" #include "configVariableString.h" #include "configVariableBool.h" +#include "configVariableInt.h" NotifyCategoryDecl(glxdisplay, EXPCL_PANDAGL, EXPTP_PANDAGL); @@ -33,4 +34,7 @@ extern ConfigVariableBool glx_error_abort; extern ConfigVariableBool glx_get_proc_address; extern ConfigVariableBool glx_get_os_address; +extern ConfigVariableInt glx_wheel_up_button; +extern ConfigVariableInt glx_wheel_down_button; + #endif /* __CONFIG_GLXDISPLAY_H__ */ diff --git a/panda/src/glxdisplay/glxGraphicsWindow.cxx b/panda/src/glxdisplay/glxGraphicsWindow.cxx index 6297e5f718..8c08f831b7 100644 --- a/panda/src/glxdisplay/glxGraphicsWindow.cxx +++ b/panda/src/glxdisplay/glxGraphicsWindow.cxx @@ -301,13 +301,13 @@ process_events() { case ButtonPress: // This refers to the mouse buttons. - button = MouseButton::button(event.xbutton.button - 1); + button = get_mouse_button(event.xbutton); _input_devices[0].set_pointer_in_window(event.xbutton.x, event.xbutton.y); _input_devices[0].button_down(button); break; case ButtonRelease: - button = MouseButton::button(event.xbutton.button - 1); + button = get_mouse_button(event.xbutton); _input_devices[0].set_pointer_in_window(event.xbutton.x, event.xbutton.y); _input_devices[0].button_up(button); break; @@ -903,7 +903,7 @@ handle_keypress(XKeyEvent &event) { _input_devices[0].set_pointer_in_window(event.x, event.y); // Now get the raw unshifted button. - ButtonHandle button = get_button(&event); + ButtonHandle button = get_button(event); if (button != ButtonHandle::none()) { _input_devices[0].button_down(button); } @@ -920,7 +920,7 @@ handle_keyrelease(XKeyEvent &event) { _input_devices[0].set_pointer_in_window(event.x, event.y); // Now get the raw unshifted button. - ButtonHandle button = get_button(&event); + ButtonHandle button = get_button(event); if (button != ButtonHandle::none()) { _input_devices[0].button_up(button); } @@ -933,8 +933,8 @@ handle_keyrelease(XKeyEvent &event) { // keyboard button indicated by the given key event. //////////////////////////////////////////////////////////////////// ButtonHandle glxGraphicsWindow:: -get_button(XKeyEvent *key_event) { - KeySym key = XLookupKeysym(key_event, 0); +get_button(XKeyEvent &key_event) { + KeySym key = XLookupKeysym(&key_event, 0); switch (key) { case XK_BackSpace: @@ -1210,6 +1210,23 @@ get_button(XKeyEvent *key_event) { return ButtonHandle::none(); } +//////////////////////////////////////////////////////////////////// +// Function: glxGraphicsWindow::get_mouse_button +// Access: Private +// Description: Returns the Panda ButtonHandle corresponding to the +// mouse button indicated by the given button event. +//////////////////////////////////////////////////////////////////// +ButtonHandle glxGraphicsWindow:: +get_mouse_button(XButtonEvent &button_event) { + int index = button_event.button; + if (index == glx_wheel_up_button) { + return MouseButton::wheel_up(); + } else if (index == glx_wheel_down_button) { + return MouseButton::wheel_down(); + } else { + return MouseButton::button(index - 1); + } +} //////////////////////////////////////////////////////////////////// // Function: glxGraphicsWindow::check_event // Access: Private, Static diff --git a/panda/src/glxdisplay/glxGraphicsWindow.h b/panda/src/glxdisplay/glxGraphicsWindow.h index 4e156036c6..6bf7c2fd01 100644 --- a/panda/src/glxdisplay/glxGraphicsWindow.h +++ b/panda/src/glxdisplay/glxGraphicsWindow.h @@ -64,7 +64,8 @@ private: void handle_keypress(XKeyEvent &event); void handle_keyrelease(XKeyEvent &event); - ButtonHandle get_button(XKeyEvent *key_event); + ButtonHandle get_button(XKeyEvent &key_event); + ButtonHandle get_mouse_button(XButtonEvent &button_event); static Bool check_event(Display *display, XEvent *event, char *arg);