Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 295163 | Differences between
and this patch

Collapse All | Expand All

(-)src/freeglut_window.c (+3 lines)
Lines 934-939 Link Here
934
        window->Window.Context
934
        window->Window.Context
935
    );
935
    );
936
936
937
    /* register extension events _before_ window is mapped */
938
    fgRegisterDevices( fgDisplay.Display, &(window->Window.Handle) );
939
937
    XMapWindow( fgDisplay.Display, window->Window.Handle );
940
    XMapWindow( fgDisplay.Display, window->Window.Handle );
938
941
939
    XFree(visualInfo);
942
    XFree(visualInfo);
(-)src/freeglut_callbacks.c (+36 lines)
Lines 358-361 Link Here
358
    SET_CALLBACK( TabletButton );
358
    SET_CALLBACK( TabletButton );
359
}
359
}
360
360
361
/*
362
 * Sets the multi-pointer entry callback for the current window
363
 */
364
void FGAPIENTRY glutXExtensionEntryFunc( void (* callback)(int, int ) )
365
{
366
    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutXExtensionEntryFunc" );
367
    SET_CALLBACK( XExtensionEntry );
368
}
369
370
/*
371
 * Sets the multi-pointer button callback for the current window
372
 */
373
void FGAPIENTRY glutXExtensionButtonFunc( void (* callback)(int, int, int, int, int ) )
374
{
375
    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutXExtensionButtonFunc" );
376
    SET_CALLBACK( XExtensionButton );
377
}
378
379
/*
380
 * Sets the multi-pointer motion callback for the current window
381
 */
382
void FGAPIENTRY glutXExtensionMotionFunc( void (* callback)(int, int, int ) )
383
{
384
    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutXExtensionMotionFunc" );
385
    SET_CALLBACK( XExtensionMotion );
386
}
387
388
/*
389
 * Sets the multi-pointer passive motion callback for the current window
390
 */
391
void FGAPIENTRY glutXExtensionPassiveFunc( void (* callback)(int, int, int ) )
392
{
393
    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutXExtensionPassiveFunc" );
394
    SET_CALLBACK( XExtensionPassive );
395
}
396
361
/*** END OF FILE ***/
397
/*** END OF FILE ***/
(-)src/freeglut_internal.h (-1 / +18 lines)
Lines 227-232 Link Here
227
typedef void (* FGCBTabletButton  )( int, int, int, int );
227
typedef void (* FGCBTabletButton  )( int, int, int, int );
228
typedef void (* FGCBDestroy       )( void );
228
typedef void (* FGCBDestroy       )( void );
229
229
230
typedef void (* FGCBXExtensionEntry   )( int, int );
231
typedef void (* FGCBXExtensionButton  )( int, int, int, int, int );
232
typedef void (* FGCBXExtensionMotion  )( int, int, int );
233
typedef void (* FGCBXExtensionPassive )( int, int, int );
234
230
/* The global callbacks type definitions */
235
/* The global callbacks type definitions */
231
typedef void (* FGCBIdle          )( void );
236
typedef void (* FGCBIdle          )( void );
232
typedef void (* FGCBTimer         )( int );
237
typedef void (* FGCBTimer         )( int );
Lines 561-566 Link Here
561
    CB_Joystick,
566
    CB_Joystick,
562
    CB_Destroy,
567
    CB_Destroy,
563
568
569
    /* MPX-related */
570
    CB_XExtensionEntry,
571
    CB_XExtensionButton,
572
    CB_XExtensionMotion,
573
    CB_XExtensionPassive,
574
564
    /* Presently ignored */
575
    /* Presently ignored */
565
    CB_Select,
576
    CB_Select,
566
    CB_OverlayDisplay,
577
    CB_OverlayDisplay,
Lines 925-935 Link Here
925
void fgError( const char *fmt, ... );
936
void fgError( const char *fmt, ... );
926
void fgWarning( const char *fmt, ... );
937
void fgWarning( const char *fmt, ... );
927
938
939
#if TARGET_HOST_POSIX_X11
940
928
/*
941
/*
929
 * Check if "hint" is present in "property" for "window".  See freeglut_init.c
942
 * Check if "hint" is present in "property" for "window".  See freeglut_init.c
930
 */
943
 */
931
#if TARGET_HOST_POSIX_X11
932
int fgHintPresent(Window window, Atom property, Atom hint);
944
int fgHintPresent(Window window, Atom property, Atom hint);
945
946
/* Handler for X extension Events */
947
void fgHandleExtensionEvents( XEvent * ev );
948
void fgRegisterDevices( Display* dpy, Window* win );
949
933
#endif
950
#endif
934
951
935
SFG_Proc fghGetProcAddress( const char *procName );
952
SFG_Proc fghGetProcAddress( const char *procName );
(-)src/freeglut_main.c (-2 / +3 lines)
Lines 483-489 Link Here
483
/*
483
/*
484
 * Returns GLUT modifier mask for the state field of an X11 event.
484
 * Returns GLUT modifier mask for the state field of an X11 event.
485
 */
485
 */
486
static int fghGetXModifiers( int state )
486
int fghGetXModifiers( int state )
487
{
487
{
488
    int ret = 0;
488
    int ret = 0;
489
489
Lines 1405-1411 Link Here
1405
            break;
1405
            break;
1406
1406
1407
        default:
1407
        default:
1408
            fgWarning ("Unknown X event type: %d\n", event.type);
1408
            /* enter handling of Extension Events here */
1409
            fgHandleExtensionEvents( &event );
1409
            break;
1410
            break;
1410
        }
1411
        }
1411
    }
1412
    }
(-)src/freeglut_xinput.c (+225 lines)
Line 0 Link Here
1
/* Written for XI1 by Nikolas Doerfler <doerflen@in.tum.de> (c) 2008 *
2
 * Rewritten for XI2 by Florian Echtler <echtler@in.tum.de> (c) 2009 */
3
4
#include <GL/freeglut.h>
5
6
#include "freeglut_internal.h"
7
8
#if TARGET_HOST_POSIX_X11 && HAVE_X11_EXTENSIONS_XINPUT2_H
9
10
#include <errno.h>
11
#include <stdarg.h>
12
13
#include <X11/Xlib.h>
14
#include <X11/extensions/XInput2.h>
15
16
/* import function from freeglut_main.c */
17
int fghGetXModifiers( int state );
18
19
/* extension opcode for XInput */
20
int xi_opcode = -1;
21
22
/**
23
 * \brief Sets window up for XI2 events.
24
 */
25
void fgRegisterDevices( Display* dpy, Window* win ) {
26
27
	XIEventMask mask;
28
	unsigned char flags[2] = { 0, 0 };
29
	int event, error;
30
31
	/*Display* dpy = fgDisplay.Display;
32
	Window* win = glutGetXWindow();*/
33
34
	/* get XInput extension opcode */
35
	if (!XQueryExtension( dpy, "XInputExtension", &xi_opcode, &event, &error )) { xi_opcode = -1; }
36
37
	/* Select for motion events */
38
	mask.deviceid = XIAllMasterDevices;
39
	mask.mask_len = 2;
40
	mask.mask = flags;
41
42
	XISetMask(mask.mask, XI_Enter);
43
	XISetMask(mask.mask, XI_Motion);
44
	XISetMask(mask.mask, XI_ButtonPress);
45
	XISetMask(mask.mask, XI_ButtonRelease);
46
	XISetMask(mask.mask, XI_Leave);
47
	/*XISetMask(mask.mask, XI_KeyPress);
48
	XISetMask(mask.mask, XI_KeyRelease);
49
	XISetMask(mask.mask, XI_DeviceChanged);
50
	XISetMask(mask.mask, XI_RawEvent);
51
	XISetMask(mask.mask, XI_FocusIn);
52
	XISetMask(mask.mask, XI_FocusOut);
53
	XISetMask(mask.mask, XI_HierarchyChanged);*/
54
55
	XISelectEvents( dpy, *win, &mask, 1 );
56
}
57
58
59
void fgPrintXILeaveEvent(XILeaveEvent* event)
60
{
61
    char* mode = "";
62
		char* detail = "";
63
    int i;
64
65
    printf("    windows: root 0x%lx event 0x%lx child 0x%ld\n",
66
            event->root, event->event, event->child);
67
    switch(event->mode)
68
    {
69
        case NotifyNormal:       mode = "NotifyNormal"; break;
70
        case NotifyGrab:         mode = "NotifyGrab"; break;
71
        case NotifyUngrab:       mode = "NotifyUngrab"; break;
72
        case NotifyWhileGrabbed: mode = "NotifyWhileGrabbed"; break;
73
    }
74
    switch (event->detail)
75
    {
76
        case NotifyAncestor: detail = "NotifyAncestor"; break;
77
        case NotifyVirtual: detail = "NotifyVirtual"; break;
78
        case NotifyInferior: detail = "NotifyInferior"; break;
79
        case NotifyNonlinear: detail = "NotifyNonlinear"; break;
80
        case NotifyNonlinearVirtual: detail = "NotifyNonlinearVirtual"; break;
81
        case NotifyPointer: detail = "NotifyPointer"; break;
82
        case NotifyPointerRoot: detail = "NotifyPointerRoot"; break;
83
        case NotifyDetailNone: detail = "NotifyDetailNone"; break;
84
    }
85
    printf("    mode: %s (detail %s)\n", mode, detail);
86
    printf("    flags: %s %s\n", event->focus ? "[focus]" : "",
87
                                 event->same_screen ? "[same screen]" : "");
88
    printf("    buttons:");
89
    for (i = 0; i < event->buttons.mask_len * 8; i++)
90
        if (XIMaskIsSet(event->buttons.mask, i))
91
            printf(" %d", i);
92
    printf("\n");
93
94
    printf("    modifiers: locked 0x%x latched 0x%x base 0x%x\n",
95
            event->mods.locked, event->mods.latched,
96
            event->mods.base);
97
    printf("    group: locked 0x%x latched 0x%x base 0x%x\n",
98
            event->group.locked, event->group.latched,
99
            event->group.base);
100
101
    printf("    root x/y:  %.2f / %.2f\n", event->root_x, event->root_y);
102
    printf("    event x/y: %.2f / %.2f\n", event->event_x, event->event_y);
103
104
}
105
106
107
void fgPrintXIDeviceEvent(XIDeviceEvent* event)
108
{
109
    double *val;
110
    int i;
111
112
    printf("    device: %d (%d)\n", event->deviceid, event->sourceid);
113
    printf("    detail: %d\n", event->detail);
114
    printf("    buttons:");
115
 	  for (i = 0; i < event->buttons.mask_len * 8; i++)
116
   	    if (XIMaskIsSet(event->buttons.mask, i))
117
     	      printf(" %d", i);
118
    printf("\n");
119
120
    printf("    modifiers: locked 0x%x latched 0x%x base 0x%x\n",
121
            event->mods.locked, event->mods.latched,
122
            event->mods.base);
123
    printf("    group: locked 0x%x latched 0x%x base 0x%x\n",
124
            event->group.locked, event->group.latched,
125
            event->group.base);
126
    printf("    valuators:");
127
128
    val = event->valuators.values;
129
    for (i = 0; i < event->valuators.mask_len * 8; i++)
130
        if (XIMaskIsSet(event->valuators.mask, i))
131
            printf(" %d: %.2f", i, *val++);
132
    printf("\n");
133
134
    printf("    windows: root 0x%lx event 0x%lx child 0x%ld\n",
135
            event->root, event->event, event->child);
136
    printf("    root x/y:  %.2f / %.2f\n", event->root_x, event->root_y);
137
    printf("    event x/y: %.2f / %.2f\n", event->event_x, event->event_y);
138
139
}
140
141
142
/**
143
 * \brief This function is called when an Extension Event is received
144
 * and calls the corresponding callback functions for these events.
145
 */
146
void fgHandleExtensionEvents( XEvent* base_ev ) {
147
148
	int i, button = 0;
149
	XGenericEventCookie* cookie = (XGenericEventCookie*)&(base_ev->xcookie);
150
151
	if ( XGetEventData( fgDisplay.Display, cookie ) && (cookie->type == GenericEvent) && (cookie->extension == xi_opcode) ) {
152
153
		XIDeviceEvent* event = (XIDeviceEvent*)(cookie->data);
154
		/*printf("XI2 event type: %d - %d\n", cookie->evtype, event->type );*/
155
156
		SFG_Window* window = fgWindowByHandle( event->event );
157
		if (!window) return;
158
159
		switch (cookie->evtype) {
160
161
			case XI_Enter:
162
			case XI_Leave:
163
				fgState.Modifiers = fghGetXModifiers( ((XIEnterEvent*)event)->mods.base );
164
				INVOKE_WCB( *window, XExtensionEntry, (
165
					event->deviceid, 
166
					(event->evtype == XI_Enter ? GLUT_ENTERED : GLUT_LEFT)
167
				));
168
				#if _DEBUG
169
					fgPrintXILeaveEvent((XILeaveEvent*)event);
170
				#endif
171
				break;
172
173
			case XI_ButtonPress:
174
			case XI_ButtonRelease:
175
				fgState.Modifiers = fghGetXModifiers( event->mods.base );
176
				INVOKE_WCB( *window, XExtensionButton, (
177
					event->deviceid, 
178
					event->event_x,
179
					event->event_y,
180
					(event->detail)-1, 
181
					(event->evtype == XI_ButtonPress ? GLUT_DOWN : GLUT_UP)
182
				));
183
				INVOKE_WCB( *window, Mouse, (
184
					(event->detail)-1, 
185
					(event->evtype == XI_ButtonPress ? GLUT_DOWN : GLUT_UP),
186
					event->event_x,
187
					event->event_y
188
				));
189
				break;
190
191
			case XI_Motion:
192
				fgState.Modifiers = fghGetXModifiers( event->mods.base );
193
				for (i = 0; i < event->buttons.mask_len; i++) if (event->buttons.mask[i]) button = 1;
194
				if (button) {
195
					INVOKE_WCB( *window, XExtensionMotion,  ( event->deviceid, event->event_x, event->event_y ) );
196
					INVOKE_WCB( *window,           Motion,  (                  event->event_x, event->event_y ) );
197
				} else {
198
					INVOKE_WCB( *window, XExtensionPassive, ( event->deviceid, event->event_x, event->event_y ) );
199
					INVOKE_WCB( *window,           Passive, (                  event->event_x, event->event_y ) );
200
				}
201
				#if _DEBUG
202
					fgPrintXIDeviceEvent(event);
203
				#endif
204
				break;
205
206
			default:
207
				#if _DEBUG
208
					fgWarning( "Unknown XI2 device event:" );
209
					fgPrintXIDeviceEvent( event );
210
				#endif
211
				break;
212
		}
213
		fgState.Modifiers = INVALID_MODIFIERS;
214
	}
215
	XFreeEventData( fgDisplay.Display, cookie );
216
}
217
218
#else
219
220
/* empty stubs for non-MPX platforms */
221
void fgRegisterDevices( Display* dpy, Window* win ) { }
222
void fgHandleExtensionEvents( XEvent* ev ) { }
223
224
#endif
225
(-)src/Makefile.am (-1 / +2 lines)
Lines 37-43 Link Here
37
			 freeglut_structure.c \
37
			 freeglut_structure.c \
38
			 freeglut_teapot.c \
38
			 freeglut_teapot.c \
39
			 freeglut_videoresize.c \
39
			 freeglut_videoresize.c \
40
			 freeglut_window.c
40
			 freeglut_window.c \
41
			 freeglut_xinput.c
41
42
42
#
43
#
43
# Additional linker flags
44
# Additional linker flags
(-)src/freeglut_ext.c (+4 lines)
Lines 85-90 Link Here
85
    CHECK_NAME(glutReshapeFunc);
85
    CHECK_NAME(glutReshapeFunc);
86
    CHECK_NAME(glutKeyboardFunc);
86
    CHECK_NAME(glutKeyboardFunc);
87
    CHECK_NAME(glutMouseFunc);
87
    CHECK_NAME(glutMouseFunc);
88
    CHECK_NAME(glutXExtensionEntryFunc);
89
    CHECK_NAME(glutXExtensionMotionFunc);
90
    CHECK_NAME(glutXExtensionButtonFunc);
91
    CHECK_NAME(glutXExtensionPassiveFunc);
88
    CHECK_NAME(glutMotionFunc);
92
    CHECK_NAME(glutMotionFunc);
89
    CHECK_NAME(glutPassiveMotionFunc);
93
    CHECK_NAME(glutPassiveMotionFunc);
90
    CHECK_NAME(glutEntryFunc);
94
    CHECK_NAME(glutEntryFunc);
(-)configure.ac (+1 lines)
Lines 50-55 Link Here
50
AC_HEADER_TIME
50
AC_HEADER_TIME
51
AC_CHECK_HEADERS([X11/extensions/xf86vmode.h], [], [], [#include <X11/Xlib.h>])
51
AC_CHECK_HEADERS([X11/extensions/xf86vmode.h], [], [], [#include <X11/Xlib.h>])
52
AC_CHECK_HEADERS([X11/extensions/XI.h X11/extensions/XInput.h])
52
AC_CHECK_HEADERS([X11/extensions/XI.h X11/extensions/XInput.h])
53
AC_CHECK_HEADERS([X11/extensions/XInput2.h])
53
CPPFLAGS="$save_CPPFLAGS"
54
CPPFLAGS="$save_CPPFLAGS"
54
55
55
# Checks for library functions.
56
# Checks for library functions.
(-)include/GL/freeglut_ext.h (+11 lines)
Lines 167-172 Link Here
167
FGAPI GLUTproc FGAPIENTRY glutGetProcAddress( const char *procName );
167
FGAPI GLUTproc FGAPIENTRY glutGetProcAddress( const char *procName );
168
168
169
/*
169
/*
170
 * MPX extensions, see freeglut_xinput.c
171
 */
172
173
#define GLUT_HAS_MPX 1
174
175
FGAPI void FGAPIENTRY glutXExtensionEntryFunc( void (* callback)( int, int ) );
176
FGAPI void FGAPIENTRY glutXExtensionButtonFunc( void (* callback)( int, int, int, int, int ) );
177
FGAPI void FGAPIENTRY glutXExtensionMotionFunc( void (* callback)( int, int, int ) );
178
FGAPI void FGAPIENTRY glutXExtensionPassiveFunc( void (* callback)( int, int, int ) );
179
180
/*
170
 * Joystick functions, see freeglut_joystick.c
181
 * Joystick functions, see freeglut_joystick.c
171
 */
182
 */
172
/* USE OF THESE FUNCTIONS IS DEPRECATED !!!!! */
183
/* USE OF THESE FUNCTIONS IS DEPRECATED !!!!! */

Return to bug 295163