Re: [AD] horizontal mouse wheel |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
- To: Coordination of admins/developers of the game programming library Allegro <alleg-developers@xxxxxxxxxx>
- Subject: Re: [AD] horizontal mouse wheel
- From: Elias Pschernig <elias@xxxxxxxxxx>
- Date: Sat, 24 Mar 2007 14:25:13 +0100
On Wed, 2007-03-21 at 12:16 +0100, Elias Pschernig wrote:
> I'd like to add support for horizontal mouse wheels to the X11 driver.
> It's very simple to add, like Button4 and Button5 are mapped to change
> mouse_z, Button6 and Button7 act for the horizontal direction. (I
> couldn't find a document stating this, but it works in KDE/Gnome for
> horizontal scrolling in all windows.)
>
> So, the obvious way to add this to the API would be to add a mouse_w
> variable which behaves just like mouse_z.
>
> Add the same time, my new mouse also has a 4th regular button, so I'd
> also make the X11 driver use another bit in mouse_b for this extra
> button.. so "if (mouse_b & 8)" would check for it.
Patch against 4.2 attached. I also updated exmouse to show the
horizontal wheel position and additional buttons.
--
Elias Pschernig
Index: src/x/xmouse.c
===================================================================
--- src/x/xmouse.c (revision 7781)
+++ src/x/xmouse.c (working copy)
@@ -93,7 +93,7 @@
/* _xwin_mousedrv_handler:
* Mouse "interrupt" handler for mickey-mode driver.
*/
-static void _xwin_mousedrv_handler(int x, int y, int z, int buttons)
+static void _xwin_mousedrv_handler(int x, int y, int z, int w, int buttons)
{
_mouse_b = buttons;
@@ -103,6 +103,7 @@
_mouse_x += x;
_mouse_y += y;
_mouse_z += z;
+ _mouse_w += w;
if ((_mouse_x < mouse_minx) || (_mouse_x > mouse_maxx)
|| (_mouse_y < mouse_miny) || (_mouse_y > mouse_maxy)) {
Index: src/x/xdga2.c
===================================================================
--- src/x/xdga2.c (revision 7781)
+++ src/x/xdga2.c (working copy)
@@ -340,7 +340,7 @@
else if (cur_event->xbutton.button == Button5)
dz = -1;
if (_xwin_mouse_interrupt)
- (*_xwin_mouse_interrupt)(0, 0, dz, mouse_buttons);
+ (*_xwin_mouse_interrupt)(0, 0, dz, 0, mouse_buttons);
break;
case ButtonRelease:
@@ -351,14 +351,14 @@
else if (cur_event->xbutton.button == Button2)
mouse_buttons &= ~4;
if (_xwin_mouse_interrupt)
- (*_xwin_mouse_interrupt)(0, 0, 0, mouse_buttons);
+ (*_xwin_mouse_interrupt)(0, 0, 0, 0, mouse_buttons);
break;
case MotionNotify:
dx = cur_event->xmotion.dx;
dy = cur_event->xmotion.dy;
if (((dx != 0) || (dy != 0)) && _xwin_mouse_interrupt) {
- (*_xwin_mouse_interrupt)(dx, dy, 0, mouse_buttons);
+ (*_xwin_mouse_interrupt)(dx, dy, 0, 0, mouse_buttons);
}
break;
Index: src/x/xwin.c
===================================================================
--- src/x/xwin.c (revision 7781)
+++ src/x/xwin.c (working copy)
@@ -2295,7 +2295,7 @@
*/
static void _xwin_private_process_event(XEvent *event)
{
- int dx, dy, dz = 0;
+ int dx, dy, dz = 0, dw = 0;
static int mouse_buttons = 0;
static int mouse_savedx = 0;
static int mouse_savedy = 0;
@@ -2325,12 +2325,24 @@
mouse_buttons |= 2;
else if (event->xbutton.button == Button2)
mouse_buttons |= 4;
- else if (event->xbutton.button == Button4)
+ else if (event->xbutton.button == Button4) {
dz = 1;
- else if (event->xbutton.button == Button5)
- dz = -1;
+ }
+ else if (event->xbutton.button == Button5) {
+ dz = -1;
+ }
+ else if (event->xbutton.button == 6) {
+ dw = -1;
+ }
+ else if (event->xbutton.button == 7) {
+ dw = 1;
+ }
+ else if (event->xbutton.button == 8)
+ mouse_buttons |= 8;
+ else if (event->xbutton.button == 9)
+ mouse_buttons |= 16;
if (_xwin_mouse_interrupt)
- (*_xwin_mouse_interrupt)(0, 0, dz, mouse_buttons);
+ (*_xwin_mouse_interrupt)(0, 0, dz, dw, mouse_buttons);
break;
case ButtonRelease:
/* Mouse button released. */
@@ -2340,8 +2352,12 @@
mouse_buttons &= ~2;
else if (event->xbutton.button == Button2)
mouse_buttons &= ~4;
+ else if (event->xbutton.button == 8)
+ mouse_buttons &= ~8;
+ else if (event->xbutton.button == 9)
+ mouse_buttons &= ~16;
if (_xwin_mouse_interrupt)
- (*_xwin_mouse_interrupt)(0, 0, 0, mouse_buttons);
+ (*_xwin_mouse_interrupt)(0, 0, 0, 0, mouse_buttons);
break;
case MotionNotify:
/* Mouse moved. */
@@ -2369,7 +2385,7 @@
mouse_savedx, mouse_savedy);
}
/* Move Allegro cursor. */
- (*_xwin_mouse_interrupt)(dx, dy, 0, mouse_buttons);
+ (*_xwin_mouse_interrupt)(dx, dy, 0, 0, mouse_buttons);
}
break;
case EnterNotify:
@@ -2384,15 +2400,15 @@
dx = event->xcrossing.x - (_mouse_x - (_xwin_mouse_extended_range ? _xwin.scroll_x : 0));
dy = event->xcrossing.y - (_mouse_y - (_xwin_mouse_extended_range ? _xwin.scroll_y : 0));
if (((dx != 0) || (dy != 0)) && _xwin_mouse_interrupt)
- (*_xwin_mouse_interrupt)(dx, dy, 0, mouse_buttons);
+ (*_xwin_mouse_interrupt)(dx, dy, 0, 0, mouse_buttons);
}
else if (_xwin_mouse_interrupt)
- (*_xwin_mouse_interrupt)(0, 0, 0, mouse_buttons);
+ (*_xwin_mouse_interrupt)(0, 0, 0, 0, mouse_buttons);
break;
case LeaveNotify:
_mouse_on = FALSE;
if (_xwin_mouse_interrupt)
- (*_xwin_mouse_interrupt)(0, 0, 0, mouse_buttons);
+ (*_xwin_mouse_interrupt)(0, 0, 0, 0, mouse_buttons);
_xwin_mouse_leave_notify();
break;
case Expose:
Index: src/x/xsystem.c
===================================================================
--- src/x/xsystem.c (revision 7781)
+++ src/x/xsystem.c (working copy)
@@ -32,7 +32,7 @@
void (*_xwin_keyboard_interrupt)(int pressed, int code) = 0;
void (*_xwin_keyboard_focused)(int focused, int state) = 0;
-void (*_xwin_mouse_interrupt)(int x, int y, int z, int buttons) = 0;
+void (*_xwin_mouse_interrupt)(int x, int y, int z, int w, int buttons) = 0;
static int _xwin_sysdrv_init(void);
Index: src/mouse.c
===================================================================
--- src/mouse.c (revision 7781)
+++ src/mouse.c (working copy)
@@ -47,12 +47,14 @@
volatile int mouse_x = 0; /* user-visible position */
volatile int mouse_y = 0;
volatile int mouse_z = 0;
-volatile int mouse_b = 0;
-volatile int mouse_pos = 0;
+volatile int mouse_w = 0;
+volatile int mouse_b = 0;
+volatile int mouse_pos = 0;
int _mouse_x = 0; /* internal position */
int _mouse_y = 0;
int _mouse_z = 0;
+int _mouse_w = 0;
int _mouse_b = 0;
int _mouse_on = TRUE;
@@ -258,7 +260,7 @@
*/
static void update_mouse(void)
{
- int x, y, z, b, flags = 0;
+ int x, y, z, w, b, flags = 0;
if (freeze_mouse_flag) {
x = mx;
@@ -270,6 +272,7 @@
}
z = _mouse_z;
+ w = _mouse_w;
b = _mouse_b;
if (emulate_three) {
@@ -277,9 +280,10 @@
b = 4;
}
- if ((mouse_x != x) ||
+ if ((mouse_x != x) ||
(mouse_y != y) ||
(mouse_z != z) ||
+ (mouse_w != w) ||
(mouse_b != b)) {
if (mouse_callback) {
@@ -289,6 +293,9 @@
if (mouse_z != z)
flags |= MOUSE_FLAG_MOVE_Z;
+ if (mouse_w != w)
+ flags |= MOUSE_FLAG_MOVE_W;
+
if ((b & 1) && !(mouse_b & 1))
flags |= MOUSE_FLAG_LEFT_DOWN;
else if (!(b & 1) && (mouse_b & 1))
@@ -307,6 +314,7 @@
mouse_x = x;
mouse_y = y;
mouse_z = z;
+ mouse_w = w;
mouse_b = b;
mouse_pos = ((x & 0xFFFF) << 16) | (y & 0xFFFF);
@@ -316,6 +324,7 @@
mouse_x = x;
mouse_y = y;
mouse_z = z;
+ mouse_w = w;
mouse_b = b;
mouse_pos = ((x & 0xFFFF) << 16) | (y & 0xFFFF);
}
@@ -824,6 +833,20 @@
+/* position_mouse_w:
+ * Sets the mouse third axis to position z.
+ */
+void position_mouse_w(int w)
+{
+ if (!mouse_driver)
+ return;
+
+ _mouse_w = w;
+ update_mouse();
+}
+
+
+
/* set_mouse_range:
* Sets the screen area within which the mouse can move. Pass the top left
* corner and the bottom right corner (inclusive). If you don't call this
@@ -1007,11 +1030,13 @@
LOCK_VARIABLE(mouse_x);
LOCK_VARIABLE(mouse_y);
LOCK_VARIABLE(mouse_z);
+ LOCK_VARIABLE(mouse_w);
LOCK_VARIABLE(mouse_b);
LOCK_VARIABLE(mouse_pos);
LOCK_VARIABLE(_mouse_x);
LOCK_VARIABLE(_mouse_y);
LOCK_VARIABLE(_mouse_z);
+ LOCK_VARIABLE(_mouse_w);
LOCK_VARIABLE(_mouse_b);
LOCK_VARIABLE(_mouse_on);
LOCK_VARIABLE(mon);
@@ -1143,6 +1168,7 @@
mouse_x = mouse_y = _mouse_x = _mouse_y = 0;
mouse_z = _mouse_z = 0;
+ mouse_w = _mouse_w = 0;
mouse_b = _mouse_b = 0;
mouse_pos = 0;
Index: include/allegro/platform/aintunix.h
===================================================================
--- include/allegro/platform/aintunix.h (revision 7781)
+++ include/allegro/platform/aintunix.h (working copy)
@@ -86,7 +86,7 @@
#ifdef ALLEGRO_WITH_XWINDOWS
AL_FUNCPTR(void, _xwin_keyboard_interrupt, (int pressed, int code));
AL_FUNCPTR(void, _xwin_keyboard_focused, (int focused, int state));
- AL_FUNCPTR(void, _xwin_mouse_interrupt, (int x, int y, int z, int buttons));
+ AL_FUNCPTR(void, _xwin_mouse_interrupt, (int x, int y, int z, int w, int buttons));
AL_FUNCPTR(void, _xwin_timer_interrupt, (unsigned long interval));
AL_ARRAY(_DRIVER_INFO, _xwin_gfx_driver_list);
Index: include/allegro/internal/aintern.h
===================================================================
--- include/allegro/internal/aintern.h (revision 7781)
+++ include/allegro/internal/aintern.h (working copy)
@@ -149,6 +149,7 @@
AL_VAR(int, _mouse_x);
AL_VAR(int, _mouse_y);
AL_VAR(int, _mouse_z);
+AL_VAR(int, _mouse_w);
AL_VAR(int, _mouse_b);
AL_VAR(int, _mouse_on);
Index: include/allegro/mouse.h
===================================================================
--- include/allegro/mouse.h (revision 7781)
+++ include/allegro/mouse.h (working copy)
@@ -78,6 +78,7 @@
AL_VAR(volatile int, mouse_x);
AL_VAR(volatile int, mouse_y);
AL_VAR(volatile int, mouse_z);
+AL_VAR(volatile int, mouse_w);
AL_VAR(volatile int, mouse_b);
AL_VAR(volatile int, mouse_pos);
@@ -91,6 +92,7 @@
#define MOUSE_FLAG_MIDDLE_DOWN 32
#define MOUSE_FLAG_MIDDLE_UP 64
#define MOUSE_FLAG_MOVE_Z 128
+#define MOUSE_FLAG_MOVE_W 256
AL_FUNCPTR(void, mouse_callback, (int flags));
@@ -100,6 +102,7 @@
AL_FUNC(void, unscare_mouse, (void));
AL_FUNC(void, position_mouse, (int x, int y));
AL_FUNC(void, position_mouse_z, (int z));
+AL_FUNC(void, position_mouse_w, (int w));
AL_FUNC(void, set_mouse_range, (int x1, int y_1, int x2, int y2));
AL_FUNC(void, set_mouse_speed, (int xspeed, int yspeed));
AL_FUNC(void, select_mouse_cursor, (int cursor));
Index: examples/exmouse.c
===================================================================
--- examples/exmouse.c (revision 7781)
+++ examples/exmouse.c (working copy)
@@ -19,6 +19,24 @@
+static void print_all_buttons(void)
+{
+ int i;
+ int fc = makecol(0, 0, 0);
+ int bc = makecol(255, 255, 255);
+ textprintf_right_ex(screen, font, 320, 50, fc, bc, "buttons");
+ for (i = 0; i < 8; i++) {
+ int x = 320;
+ int y = 60 + i * 10;
+ if (mouse_b & (1 << i))
+ textprintf_right_ex(screen, font, x, y, fc, bc, "%2d", 1 + i);
+ else
+ textprintf_right_ex(screen, font, x, y, fc, bc, " ");
+ }
+}
+
+
+
int main(void)
{
int mickeyx = 0;
@@ -109,8 +127,10 @@
/* the wheel position is stored in the variable mouse_z */
textprintf_ex(screen, font, 16, 184, makecol(0, 0, 0),
- makecol(255, 255, 255), "mouse_z = %-5d", mouse_z);
+ makecol(255, 255, 255), "mouse_z = %-5d mouse_w = %-5d", mouse_z, mouse_w);
+ print_all_buttons();
+
release_screen();
vsync();